OSDN Git Service

* ja.po: Update.
[pf3gnuchains/gcc-fork.git] / gcc / c-parser.c
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4    Free Software Foundation, Inc.
5
6    Parser actions based on the old Bison parser; structure somewhat
7    influenced by and fragments based on the C++ parser.
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3.  If not see
23 <http://www.gnu.org/licenses/>.  */
24
25 /* TODO:
26
27    Make sure all relevant comments, and all relevant code from all
28    actions, brought over from old parser.  Verify exact correspondence
29    of syntax accepted.
30
31    Add testcases covering every input symbol in every state in old and
32    new parsers.
33
34    Include full syntax for GNU C, including erroneous cases accepted
35    with error messages, in syntax productions in comments.
36
37    Make more diagnostics in the front end generally take an explicit
38    location rather than implicitly using input_location.  */
39
40 #include "config.h"
41 #include "system.h"
42 #include "coretypes.h"
43 #include "tm.h"                 /* For rtl.h: needs enum reg_class.  */
44 #include "tree.h"
45 #include "langhooks.h"
46 #include "input.h"
47 #include "cpplib.h"
48 #include "timevar.h"
49 #include "c-family/c-pragma.h"
50 #include "c-tree.h"
51 #include "flags.h"
52 #include "output.h"
53 #include "ggc.h"
54 #include "c-family/c-common.h"
55 #include "c-family/c-objc.h"
56 #include "vec.h"
57 #include "target.h"
58 #include "cgraph.h"
59 #include "plugin.h"
60
61 \f
62 /* Initialization routine for this file.  */
63
64 void
65 c_parse_init (void)
66 {
67   /* The only initialization required is of the reserved word
68      identifiers.  */
69   unsigned int i;
70   tree id;
71   int mask = 0;
72
73   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74      the c_token structure.  */
75   gcc_assert (RID_MAX <= 255);
76
77   mask |= D_CXXONLY;
78   if (!flag_isoc99)
79     mask |= D_C99;
80   if (flag_no_asm)
81     {
82       mask |= D_ASM | D_EXT;
83       if (!flag_isoc99)
84         mask |= D_EXT89;
85     }
86   if (!c_dialect_objc ())
87     mask |= D_OBJC | D_CXX_OBJC;
88
89   ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
90   for (i = 0; i < num_c_common_reswords; i++)
91     {
92       /* If a keyword is disabled, do not enter it into the table
93          and so create a canonical spelling that isn't a keyword.  */
94       if (c_common_reswords[i].disable & mask)
95         {
96           if (warn_cxx_compat
97               && (c_common_reswords[i].disable & D_CXXWARN))
98             {
99               id = get_identifier (c_common_reswords[i].word);
100               C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
101               C_IS_RESERVED_WORD (id) = 1;
102             }
103           continue;
104         }
105
106       id = get_identifier (c_common_reswords[i].word);
107       C_SET_RID_CODE (id, c_common_reswords[i].rid);
108       C_IS_RESERVED_WORD (id) = 1;
109       ridpointers [(int) c_common_reswords[i].rid] = id;
110     }
111 }
112 \f
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114    and the C parser.  Unlike the C++ lexer, the parser structure
115    stores the lexer information instead of using a separate structure.
116    Identifiers are separated into ordinary identifiers, type names,
117    keywords and some other Objective-C types of identifiers, and some
118    look-ahead is maintained.
119
120    ??? It might be a good idea to lex the whole file up front (as for
121    C++).  It would then be possible to share more of the C and C++
122    lexer code, if desired.  */
123
124 /* The following local token type is used.  */
125
126 /* A keyword.  */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
128
129 /* More information about the type of a CPP_NAME token.  */
130 typedef enum c_id_kind {
131   /* An ordinary identifier.  */
132   C_ID_ID,
133   /* An identifier declared as a typedef name.  */
134   C_ID_TYPENAME,
135   /* An identifier declared as an Objective-C class name.  */
136   C_ID_CLASSNAME,
137   /* An address space identifier.  */
138   C_ID_ADDRSPACE,
139   /* Not an identifier.  */
140   C_ID_NONE
141 } c_id_kind;
142
143 /* A single C token after string literal concatenation and conversion
144    of preprocessing tokens to tokens.  */
145 typedef struct GTY (()) c_token {
146   /* The kind of token.  */
147   ENUM_BITFIELD (cpp_ttype) type : 8;
148   /* If this token is a CPP_NAME, this value indicates whether also
149      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
150   ENUM_BITFIELD (c_id_kind) id_kind : 8;
151   /* If this token is a keyword, this value indicates which keyword.
152      Otherwise, this value is RID_MAX.  */
153   ENUM_BITFIELD (rid) keyword : 8;
154   /* If this token is a CPP_PRAGMA, this indicates the pragma that
155      was seen.  Otherwise it is PRAGMA_NONE.  */
156   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
157   /* The location at which this token was found.  */
158   location_t location;
159   /* The value associated with this token, if any.  */
160   tree value;
161 } c_token;
162
163 /* A parser structure recording information about the state and
164    context of parsing.  Includes lexer information with up to two
165    tokens of look-ahead; more are not needed for C.  */
166 typedef struct GTY(()) c_parser {
167   /* The look-ahead tokens.  */
168   c_token tokens[2];
169   /* How many look-ahead tokens are available (0, 1 or 2).  */
170   short tokens_avail;
171   /* True if a syntax error is being recovered from; false otherwise.
172      c_parser_error sets this flag.  It should clear this flag when
173      enough tokens have been consumed to recover from the error.  */
174   BOOL_BITFIELD error : 1;
175   /* True if we're processing a pragma, and shouldn't automatically
176      consume CPP_PRAGMA_EOL.  */
177   BOOL_BITFIELD in_pragma : 1;
178   /* True if we're parsing the outermost block of an if statement.  */
179   BOOL_BITFIELD in_if_block : 1;
180   /* True if we want to lex an untranslated string.  */
181   BOOL_BITFIELD lex_untranslated_string : 1;
182
183   /* Objective-C specific parser/lexer information.  */
184
185   /* True if we are in a context where the Objective-C "PQ" keywords
186      are considered keywords.  */
187   BOOL_BITFIELD objc_pq_context : 1;
188   /* True if we are parsing a (potential) Objective-C foreach
189      statement.  This is set to true after we parsed 'for (' and while
190      we wait for 'in' or ';' to decide if it's a standard C for loop or an
191      Objective-C foreach loop.  */
192   BOOL_BITFIELD objc_could_be_foreach_context : 1;
193   /* The following flag is needed to contextualize Objective-C lexical
194      analysis.  In some cases (e.g., 'int NSObject;'), it is
195      undesirable to bind an identifier to an Objective-C class, even
196      if a class with that name exists.  */
197   BOOL_BITFIELD objc_need_raw_identifier : 1;
198   /* True if we are in a context where the Objective-C "Property attribute"
199      keywords are valid.  */
200   BOOL_BITFIELD objc_property_attr_context : 1;
201 } c_parser;
202
203
204 /* The actual parser and external interface.  ??? Does this need to be
205    garbage-collected?  */
206
207 static GTY (()) c_parser *the_parser;
208
209 /* Read in and lex a single token, storing it in *TOKEN.  */
210
211 static void
212 c_lex_one_token (c_parser *parser, c_token *token)
213 {
214   timevar_push (TV_LEX);
215
216   token->type = c_lex_with_flags (&token->value, &token->location, NULL,
217                                   (parser->lex_untranslated_string
218                                    ? C_LEX_STRING_NO_TRANSLATE : 0));
219   token->id_kind = C_ID_NONE;
220   token->keyword = RID_MAX;
221   token->pragma_kind = PRAGMA_NONE;
222
223   switch (token->type)
224     {
225     case CPP_NAME:
226       {
227         tree decl;
228
229         bool objc_force_identifier = parser->objc_need_raw_identifier;
230         if (c_dialect_objc ())
231           parser->objc_need_raw_identifier = false;
232
233         if (C_IS_RESERVED_WORD (token->value))
234           {
235             enum rid rid_code = C_RID_CODE (token->value);
236
237             if (rid_code == RID_CXX_COMPAT_WARN)
238               {
239                 warning_at (token->location,
240                             OPT_Wc___compat,
241                             "identifier %qE conflicts with C++ keyword",
242                             token->value);
243               }
244             else if (rid_code >= RID_FIRST_ADDR_SPACE
245                      && rid_code <= RID_LAST_ADDR_SPACE)
246               {
247                 token->id_kind = C_ID_ADDRSPACE;
248                 token->keyword = rid_code;
249                 break;
250               }
251             else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
252               {
253                 /* We found an Objective-C "pq" keyword (in, out,
254                    inout, bycopy, byref, oneway).  They need special
255                    care because the interpretation depends on the
256                    context.  */
257                 if (parser->objc_pq_context)
258                   {
259                     token->type = CPP_KEYWORD;
260                     token->keyword = rid_code;
261                     break;
262                   }
263                 else if (parser->objc_could_be_foreach_context
264                          && rid_code == RID_IN)
265                   {
266                     /* We are in Objective-C, inside a (potential)
267                        foreach context (which means after having
268                        parsed 'for (', but before having parsed ';'),
269                        and we found 'in'.  We consider it the keyword
270                        which terminates the declaration at the
271                        beginning of a foreach-statement.  Note that
272                        this means you can't use 'in' for anything else
273                        in that context; in particular, in Objective-C
274                        you can't use 'in' as the name of the running
275                        variable in a C for loop.  We could potentially
276                        try to add code here to disambiguate, but it
277                        seems a reasonable limitation.  */
278                     token->type = CPP_KEYWORD;
279                     token->keyword = rid_code;
280                     break;
281                   }
282                 /* Else, "pq" keywords outside of the "pq" context are
283                    not keywords, and we fall through to the code for
284                    normal tokens.  */
285               }
286             else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
287               {
288                 /* We found an Objective-C "property attribute"
289                    keyword (getter, setter, readonly, etc). These are
290                    only valid in the property context.  */
291                 if (parser->objc_property_attr_context)
292                   {
293                     token->type = CPP_KEYWORD;
294                     token->keyword = rid_code;
295                     break;
296                   }
297                 /* Else they are not special keywords.
298                 */
299               }
300             else if (c_dialect_objc () 
301                      && (OBJC_IS_AT_KEYWORD (rid_code)
302                          || OBJC_IS_CXX_KEYWORD (rid_code)))
303               {
304                 /* We found one of the Objective-C "@" keywords (defs,
305                    selector, synchronized, etc) or one of the
306                    Objective-C "cxx" keywords (class, private,
307                    protected, public, try, catch, throw) without a
308                    preceding '@' sign.  Do nothing and fall through to
309                    the code for normal tokens (in C++ we would still
310                    consider the CXX ones keywords, but not in C).  */
311                 ;
312               }
313             else
314               {
315                 token->type = CPP_KEYWORD;
316                 token->keyword = rid_code;
317                 break;
318               }
319           }
320
321         decl = lookup_name (token->value);
322         if (decl)
323           {
324             if (TREE_CODE (decl) == TYPE_DECL)
325               {
326                 token->id_kind = C_ID_TYPENAME;
327                 break;
328               }
329           }
330         else if (c_dialect_objc ())
331           {
332             tree objc_interface_decl = objc_is_class_name (token->value);
333             /* Objective-C class names are in the same namespace as
334                variables and typedefs, and hence are shadowed by local
335                declarations.  */
336             if (objc_interface_decl
337                 && (global_bindings_p ()
338                     || (!objc_force_identifier && !decl)))
339               {
340                 token->value = objc_interface_decl;
341                 token->id_kind = C_ID_CLASSNAME;
342                 break;
343               }
344           }
345         token->id_kind = C_ID_ID;
346       }
347       break;
348     case CPP_AT_NAME:
349       /* This only happens in Objective-C; it must be a keyword.  */
350       token->type = CPP_KEYWORD;
351       switch (C_RID_CODE (token->value))
352         {
353           /* Replace 'class' with '@class', 'private' with '@private',
354              etc.  This prevents confusion with the C++ keyword
355              'class', and makes the tokens consistent with other
356              Objective-C 'AT' keywords.  For example '@class' is
357              reported as RID_AT_CLASS which is consistent with
358              '@synchronized', which is reported as
359              RID_AT_SYNCHRONIZED.
360           */
361         case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
362         case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
363         case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
364         case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
365         case RID_THROW:     token->keyword = RID_AT_THROW; break;
366         case RID_TRY:       token->keyword = RID_AT_TRY; break;
367         case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
368         default:            token->keyword = C_RID_CODE (token->value);
369         }
370       break;
371     case CPP_COLON:
372     case CPP_COMMA:
373     case CPP_CLOSE_PAREN:
374     case CPP_SEMICOLON:
375       /* These tokens may affect the interpretation of any identifiers
376          following, if doing Objective-C.  */
377       if (c_dialect_objc ())
378         parser->objc_need_raw_identifier = false;
379       break;
380     case CPP_PRAGMA:
381       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
382       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
383       token->value = NULL;
384       break;
385     default:
386       break;
387     }
388   timevar_pop (TV_LEX);
389 }
390
391 /* Return a pointer to the next token from PARSER, reading it in if
392    necessary.  */
393
394 static inline c_token *
395 c_parser_peek_token (c_parser *parser)
396 {
397   if (parser->tokens_avail == 0)
398     {
399       c_lex_one_token (parser, &parser->tokens[0]);
400       parser->tokens_avail = 1;
401     }
402   return &parser->tokens[0];
403 }
404
405 /* Return true if the next token from PARSER has the indicated
406    TYPE.  */
407
408 static inline bool
409 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
410 {
411   return c_parser_peek_token (parser)->type == type;
412 }
413
414 /* Return true if the next token from PARSER does not have the
415    indicated TYPE.  */
416
417 static inline bool
418 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
419 {
420   return !c_parser_next_token_is (parser, type);
421 }
422
423 /* Return true if the next token from PARSER is the indicated
424    KEYWORD.  */
425
426 static inline bool
427 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
428 {
429   return c_parser_peek_token (parser)->keyword == keyword;
430 }
431
432 /* Return a pointer to the next-but-one token from PARSER, reading it
433    in if necessary.  The next token is already read in.  */
434
435 static c_token *
436 c_parser_peek_2nd_token (c_parser *parser)
437 {
438   if (parser->tokens_avail >= 2)
439     return &parser->tokens[1];
440   gcc_assert (parser->tokens_avail == 1);
441   gcc_assert (parser->tokens[0].type != CPP_EOF);
442   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
443   c_lex_one_token (parser, &parser->tokens[1]);
444   parser->tokens_avail = 2;
445   return &parser->tokens[1];
446 }
447
448 /* Return true if TOKEN can start a type name,
449    false otherwise.  */
450 static bool
451 c_token_starts_typename (c_token *token)
452 {
453   switch (token->type)
454     {
455     case CPP_NAME:
456       switch (token->id_kind)
457         {
458         case C_ID_ID:
459           return false;
460         case C_ID_ADDRSPACE:
461           return true;
462         case C_ID_TYPENAME:
463           return true;
464         case C_ID_CLASSNAME:
465           gcc_assert (c_dialect_objc ());
466           return true;
467         default:
468           gcc_unreachable ();
469         }
470     case CPP_KEYWORD:
471       switch (token->keyword)
472         {
473         case RID_UNSIGNED:
474         case RID_LONG:
475         case RID_INT128:
476         case RID_SHORT:
477         case RID_SIGNED:
478         case RID_COMPLEX:
479         case RID_INT:
480         case RID_CHAR:
481         case RID_FLOAT:
482         case RID_DOUBLE:
483         case RID_VOID:
484         case RID_DFLOAT32:
485         case RID_DFLOAT64:
486         case RID_DFLOAT128:
487         case RID_BOOL:
488         case RID_ENUM:
489         case RID_STRUCT:
490         case RID_UNION:
491         case RID_TYPEOF:
492         case RID_CONST:
493         case RID_VOLATILE:
494         case RID_RESTRICT:
495         case RID_ATTRIBUTE:
496         case RID_FRACT:
497         case RID_ACCUM:
498         case RID_SAT:
499           return true;
500         default:
501           return false;
502         }
503     case CPP_LESS:
504       if (c_dialect_objc ())
505         return true;
506       return false;
507     default:
508       return false;
509     }
510 }
511
512 enum c_lookahead_kind {
513   /* Always treat unknown identifiers as typenames.  */
514   cla_prefer_type,
515
516   /* Could be parsing a nonabstract declarator.  Only treat an identifier
517      as a typename if followed by another identifier or a star.  */
518   cla_nonabstract_decl,
519
520   /* Never treat identifiers as typenames.  */
521   cla_prefer_id
522 };
523
524 /* Return true if the next token from PARSER can start a type name,
525    false otherwise.  LA specifies how to do lookahead in order to
526    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
527
528 static inline bool
529 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
530 {
531   c_token *token = c_parser_peek_token (parser);
532   if (c_token_starts_typename (token))
533     return true;
534
535   /* Try a bit harder to detect an unknown typename.  */
536   if (la != cla_prefer_id
537       && token->type == CPP_NAME
538       && token->id_kind == C_ID_ID
539
540       /* Do not try too hard when we could have "object in array".  */
541       && !parser->objc_could_be_foreach_context
542
543       && (la == cla_prefer_type
544           || c_parser_peek_2nd_token (parser)->type == CPP_NAME
545           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
546
547       /* Only unknown identifiers.  */
548       && !lookup_name (token->value))
549     return true;
550
551   return false;
552 }
553
554 /* Return true if TOKEN is a type qualifier, false otherwise.  */
555 static bool
556 c_token_is_qualifier (c_token *token)
557 {
558   switch (token->type)
559     {
560     case CPP_NAME:
561       switch (token->id_kind)
562         {
563         case C_ID_ADDRSPACE:
564           return true;
565         default:
566           return false;
567         }
568     case CPP_KEYWORD:
569       switch (token->keyword)
570         {
571         case RID_CONST:
572         case RID_VOLATILE:
573         case RID_RESTRICT:
574         case RID_ATTRIBUTE:
575           return true;
576         default:
577           return false;
578         }
579     case CPP_LESS:
580       return false;
581     default:
582       gcc_unreachable ();
583     }
584 }
585
586 /* Return true if the next token from PARSER is a type qualifier,
587    false otherwise.  */
588 static inline bool
589 c_parser_next_token_is_qualifier (c_parser *parser)
590 {
591   c_token *token = c_parser_peek_token (parser);
592   return c_token_is_qualifier (token);
593 }
594
595 /* Return true if TOKEN can start declaration specifiers, false
596    otherwise.  */
597 static bool
598 c_token_starts_declspecs (c_token *token)
599 {
600   switch (token->type)
601     {
602     case CPP_NAME:
603       switch (token->id_kind)
604         {
605         case C_ID_ID:
606           return false;
607         case C_ID_ADDRSPACE:
608           return true;
609         case C_ID_TYPENAME:
610           return true;
611         case C_ID_CLASSNAME:
612           gcc_assert (c_dialect_objc ());
613           return true;
614         default:
615           gcc_unreachable ();
616         }
617     case CPP_KEYWORD:
618       switch (token->keyword)
619         {
620         case RID_STATIC:
621         case RID_EXTERN:
622         case RID_REGISTER:
623         case RID_TYPEDEF:
624         case RID_INLINE:
625         case RID_AUTO:
626         case RID_THREAD:
627         case RID_UNSIGNED:
628         case RID_LONG:
629         case RID_INT128:
630         case RID_SHORT:
631         case RID_SIGNED:
632         case RID_COMPLEX:
633         case RID_INT:
634         case RID_CHAR:
635         case RID_FLOAT:
636         case RID_DOUBLE:
637         case RID_VOID:
638         case RID_DFLOAT32:
639         case RID_DFLOAT64:
640         case RID_DFLOAT128:
641         case RID_BOOL:
642         case RID_ENUM:
643         case RID_STRUCT:
644         case RID_UNION:
645         case RID_TYPEOF:
646         case RID_CONST:
647         case RID_VOLATILE:
648         case RID_RESTRICT:
649         case RID_ATTRIBUTE:
650         case RID_FRACT:
651         case RID_ACCUM:
652         case RID_SAT:
653           return true;
654         default:
655           return false;
656         }
657     case CPP_LESS:
658       if (c_dialect_objc ())
659         return true;
660       return false;
661     default:
662       return false;
663     }
664 }
665
666
667 /* Return true if TOKEN can start declaration specifiers or a static
668    assertion, false otherwise.  */
669 static bool
670 c_token_starts_declaration (c_token *token)
671 {
672   if (c_token_starts_declspecs (token)
673       || token->keyword == RID_STATIC_ASSERT)
674     return true;
675   else
676     return false;
677 }
678
679 /* Return true if the next token from PARSER can start declaration
680    specifiers, false otherwise.  */
681 static inline bool
682 c_parser_next_token_starts_declspecs (c_parser *parser)
683 {
684   c_token *token = c_parser_peek_token (parser);
685
686   /* In Objective-C, a classname normally starts a declspecs unless it
687      is immediately followed by a dot.  In that case, it is the
688      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
689      setter/getter on the class.  c_token_starts_declspecs() can't
690      differentiate between the two cases because it only checks the
691      current token, so we have a special check here.  */
692   if (c_dialect_objc () 
693       && token->type == CPP_NAME
694       && token->id_kind == C_ID_CLASSNAME 
695       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
696     return false;
697
698   return c_token_starts_declspecs (token);
699 }
700
701 /* Return true if the next tokens from PARSER can start declaration
702    specifiers or a static assertion, false otherwise.  */
703 static inline bool
704 c_parser_next_tokens_start_declaration (c_parser *parser)
705 {
706   c_token *token = c_parser_peek_token (parser);
707
708   /* Same as above.  */
709   if (c_dialect_objc () 
710       && token->type == CPP_NAME
711       && token->id_kind == C_ID_CLASSNAME 
712       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
713     return false;
714
715   /* Labels do not start declarations.  */
716   if (token->type == CPP_NAME
717       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
718     return false;
719
720   if (c_token_starts_declaration (token))
721     return true;
722
723   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
724     return true;
725
726   return false;
727 }
728
729 /* Consume the next token from PARSER.  */
730
731 static void
732 c_parser_consume_token (c_parser *parser)
733 {
734   gcc_assert (parser->tokens_avail >= 1);
735   gcc_assert (parser->tokens[0].type != CPP_EOF);
736   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
737   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
738   if (parser->tokens_avail == 2)
739     parser->tokens[0] = parser->tokens[1];
740   parser->tokens_avail--;
741 }
742
743 /* Expect the current token to be a #pragma.  Consume it and remember
744    that we've begun parsing a pragma.  */
745
746 static void
747 c_parser_consume_pragma (c_parser *parser)
748 {
749   gcc_assert (!parser->in_pragma);
750   gcc_assert (parser->tokens_avail >= 1);
751   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
752   if (parser->tokens_avail == 2)
753     parser->tokens[0] = parser->tokens[1];
754   parser->tokens_avail--;
755   parser->in_pragma = true;
756 }
757
758 /* Update the globals input_location and in_system_header from
759    TOKEN.  */
760 static inline void
761 c_parser_set_source_position_from_token (c_token *token)
762 {
763   if (token->type != CPP_EOF)
764     {
765       input_location = token->location;
766     }
767 }
768
769 /* Issue a diagnostic of the form
770       FILE:LINE: MESSAGE before TOKEN
771    where TOKEN is the next token in the input stream of PARSER.
772    MESSAGE (specified by the caller) is usually of the form "expected
773    OTHER-TOKEN".
774
775    Do not issue a diagnostic if still recovering from an error.
776
777    ??? This is taken from the C++ parser, but building up messages in
778    this way is not i18n-friendly and some other approach should be
779    used.  */
780
781 static void
782 c_parser_error (c_parser *parser, const char *gmsgid)
783 {
784   c_token *token = c_parser_peek_token (parser);
785   if (parser->error)
786     return;
787   parser->error = true;
788   if (!gmsgid)
789     return;
790   /* This diagnostic makes more sense if it is tagged to the line of
791      the token we just peeked at.  */
792   c_parser_set_source_position_from_token (token);
793   c_parse_error (gmsgid,
794                  /* Because c_parse_error does not understand
795                     CPP_KEYWORD, keywords are treated like
796                     identifiers.  */
797                  (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
798                  /* ??? The C parser does not save the cpp flags of a
799                     token, we need to pass 0 here and we will not get
800                     the source spelling of some tokens but rather the
801                     canonical spelling.  */
802                  token->value, /*flags=*/0);
803 }
804
805 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
806    issue the error MSGID.  If MSGID is NULL then a message has already
807    been produced and no message will be produced this time.  Returns
808    true if found, false otherwise.  */
809
810 static bool
811 c_parser_require (c_parser *parser,
812                   enum cpp_ttype type,
813                   const char *msgid)
814 {
815   if (c_parser_next_token_is (parser, type))
816     {
817       c_parser_consume_token (parser);
818       return true;
819     }
820   else
821     {
822       c_parser_error (parser, msgid);
823       return false;
824     }
825 }
826
827 /* If the next token is the indicated keyword, consume it.  Otherwise,
828    issue the error MSGID.  Returns true if found, false otherwise.  */
829
830 static bool
831 c_parser_require_keyword (c_parser *parser,
832                           enum rid keyword,
833                           const char *msgid)
834 {
835   if (c_parser_next_token_is_keyword (parser, keyword))
836     {
837       c_parser_consume_token (parser);
838       return true;
839     }
840   else
841     {
842       c_parser_error (parser, msgid);
843       return false;
844     }
845 }
846
847 /* Like c_parser_require, except that tokens will be skipped until the
848    desired token is found.  An error message is still produced if the
849    next token is not as expected.  If MSGID is NULL then a message has
850    already been produced and no message will be produced this
851    time.  */
852
853 static void
854 c_parser_skip_until_found (c_parser *parser,
855                            enum cpp_ttype type,
856                            const char *msgid)
857 {
858   unsigned nesting_depth = 0;
859
860   if (c_parser_require (parser, type, msgid))
861     return;
862
863   /* Skip tokens until the desired token is found.  */
864   while (true)
865     {
866       /* Peek at the next token.  */
867       c_token *token = c_parser_peek_token (parser);
868       /* If we've reached the token we want, consume it and stop.  */
869       if (token->type == type && !nesting_depth)
870         {
871           c_parser_consume_token (parser);
872           break;
873         }
874
875       /* If we've run out of tokens, stop.  */
876       if (token->type == CPP_EOF)
877         return;
878       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
879         return;
880       if (token->type == CPP_OPEN_BRACE
881           || token->type == CPP_OPEN_PAREN
882           || token->type == CPP_OPEN_SQUARE)
883         ++nesting_depth;
884       else if (token->type == CPP_CLOSE_BRACE
885                || token->type == CPP_CLOSE_PAREN
886                || token->type == CPP_CLOSE_SQUARE)
887         {
888           if (nesting_depth-- == 0)
889             break;
890         }
891       /* Consume this token.  */
892       c_parser_consume_token (parser);
893     }
894   parser->error = false;
895 }
896
897 /* Skip tokens until the end of a parameter is found, but do not
898    consume the comma, semicolon or closing delimiter.  */
899
900 static void
901 c_parser_skip_to_end_of_parameter (c_parser *parser)
902 {
903   unsigned nesting_depth = 0;
904
905   while (true)
906     {
907       c_token *token = c_parser_peek_token (parser);
908       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
909           && !nesting_depth)
910         break;
911       /* If we've run out of tokens, stop.  */
912       if (token->type == CPP_EOF)
913         return;
914       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
915         return;
916       if (token->type == CPP_OPEN_BRACE
917           || token->type == CPP_OPEN_PAREN
918           || token->type == CPP_OPEN_SQUARE)
919         ++nesting_depth;
920       else if (token->type == CPP_CLOSE_BRACE
921                || token->type == CPP_CLOSE_PAREN
922                || token->type == CPP_CLOSE_SQUARE)
923         {
924           if (nesting_depth-- == 0)
925             break;
926         }
927       /* Consume this token.  */
928       c_parser_consume_token (parser);
929     }
930   parser->error = false;
931 }
932
933 /* Expect to be at the end of the pragma directive and consume an
934    end of line marker.  */
935
936 static void
937 c_parser_skip_to_pragma_eol (c_parser *parser)
938 {
939   gcc_assert (parser->in_pragma);
940   parser->in_pragma = false;
941
942   if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
943     while (true)
944       {
945         c_token *token = c_parser_peek_token (parser);
946         if (token->type == CPP_EOF)
947           break;
948         if (token->type == CPP_PRAGMA_EOL)
949           {
950             c_parser_consume_token (parser);
951             break;
952           }
953         c_parser_consume_token (parser);
954       }
955
956   parser->error = false;
957 }
958
959 /* Skip tokens until we have consumed an entire block, or until we
960    have consumed a non-nested ';'.  */
961
962 static void
963 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
964 {
965   unsigned nesting_depth = 0;
966   bool save_error = parser->error;
967
968   while (true)
969     {
970       c_token *token;
971
972       /* Peek at the next token.  */
973       token = c_parser_peek_token (parser);
974
975       switch (token->type)
976         {
977         case CPP_EOF:
978           return;
979
980         case CPP_PRAGMA_EOL:
981           if (parser->in_pragma)
982             return;
983           break;
984
985         case CPP_SEMICOLON:
986           /* If the next token is a ';', we have reached the
987              end of the statement.  */
988           if (!nesting_depth)
989             {
990               /* Consume the ';'.  */
991               c_parser_consume_token (parser);
992               goto finished;
993             }
994           break;
995
996         case CPP_CLOSE_BRACE:
997           /* If the next token is a non-nested '}', then we have
998              reached the end of the current block.  */
999           if (nesting_depth == 0 || --nesting_depth == 0)
1000             {
1001               c_parser_consume_token (parser);
1002               goto finished;
1003             }
1004           break;
1005
1006         case CPP_OPEN_BRACE:
1007           /* If it the next token is a '{', then we are entering a new
1008              block.  Consume the entire block.  */
1009           ++nesting_depth;
1010           break;
1011
1012         case CPP_PRAGMA:
1013           /* If we see a pragma, consume the whole thing at once.  We
1014              have some safeguards against consuming pragmas willy-nilly.
1015              Normally, we'd expect to be here with parser->error set,
1016              which disables these safeguards.  But it's possible to get
1017              here for secondary error recovery, after parser->error has
1018              been cleared.  */
1019           c_parser_consume_pragma (parser);
1020           c_parser_skip_to_pragma_eol (parser);
1021           parser->error = save_error;
1022           continue;
1023
1024         default:
1025           break;
1026         }
1027
1028       c_parser_consume_token (parser);
1029     }
1030
1031  finished:
1032   parser->error = false;
1033 }
1034
1035 /* CPP's options (initialized by c-opts.c).  */
1036 extern cpp_options *cpp_opts;
1037
1038 /* Save the warning flags which are controlled by __extension__.  */
1039
1040 static inline int
1041 disable_extension_diagnostics (void)
1042 {
1043   int ret = (pedantic
1044              | (warn_pointer_arith << 1)
1045              | (warn_traditional << 2)
1046              | (flag_iso << 3)
1047              | (warn_long_long << 4)
1048              | (warn_cxx_compat << 5));
1049   cpp_opts->cpp_pedantic = pedantic = 0;
1050   warn_pointer_arith = 0;
1051   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1052   flag_iso = 0;
1053   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1054   warn_cxx_compat = 0;
1055   return ret;
1056 }
1057
1058 /* Restore the warning flags which are controlled by __extension__.
1059    FLAGS is the return value from disable_extension_diagnostics.  */
1060
1061 static inline void
1062 restore_extension_diagnostics (int flags)
1063 {
1064   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1065   warn_pointer_arith = (flags >> 1) & 1;
1066   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1067   flag_iso = (flags >> 3) & 1;
1068   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1069   warn_cxx_compat = (flags >> 5) & 1;
1070 }
1071
1072 /* Possibly kinds of declarator to parse.  */
1073 typedef enum c_dtr_syn {
1074   /* A normal declarator with an identifier.  */
1075   C_DTR_NORMAL,
1076   /* An abstract declarator (maybe empty).  */
1077   C_DTR_ABSTRACT,
1078   /* A parameter declarator: may be either, but after a type name does
1079      not redeclare a typedef name as an identifier if it can
1080      alternatively be interpreted as a typedef name; see DR#009,
1081      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1082      following DR#249.  For example, given a typedef T, "int T" and
1083      "int *T" are valid parameter declarations redeclaring T, while
1084      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1085      abstract declarators rather than involving redundant parentheses;
1086      the same applies with attributes inside the parentheses before
1087      "T".  */
1088   C_DTR_PARM
1089 } c_dtr_syn;
1090
1091 static void c_parser_external_declaration (c_parser *);
1092 static void c_parser_asm_definition (c_parser *);
1093 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1094                                            bool, bool, tree *);
1095 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1096 static void c_parser_static_assert_declaration (c_parser *);
1097 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1098                                 bool, enum c_lookahead_kind);
1099 static struct c_typespec c_parser_enum_specifier (c_parser *);
1100 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1101 static tree c_parser_struct_declaration (c_parser *);
1102 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1103 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1104                                                  bool *);
1105 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1106                                                         c_dtr_syn, bool *);
1107 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1108                                                               bool,
1109                                                               struct c_declarator *);
1110 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1111 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1112 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1113 static tree c_parser_simple_asm_expr (c_parser *);
1114 static tree c_parser_attributes (c_parser *);
1115 static struct c_type_name *c_parser_type_name (c_parser *);
1116 static struct c_expr c_parser_initializer (c_parser *);
1117 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1118 static void c_parser_initelt (c_parser *, struct obstack *);
1119 static void c_parser_initval (c_parser *, struct c_expr *,
1120                               struct obstack *);
1121 static tree c_parser_compound_statement (c_parser *);
1122 static void c_parser_compound_statement_nostart (c_parser *);
1123 static void c_parser_label (c_parser *);
1124 static void c_parser_statement (c_parser *);
1125 static void c_parser_statement_after_labels (c_parser *);
1126 static void c_parser_if_statement (c_parser *);
1127 static void c_parser_switch_statement (c_parser *);
1128 static void c_parser_while_statement (c_parser *);
1129 static void c_parser_do_statement (c_parser *);
1130 static void c_parser_for_statement (c_parser *);
1131 static tree c_parser_asm_statement (c_parser *);
1132 static tree c_parser_asm_operands (c_parser *, bool);
1133 static tree c_parser_asm_goto_operands (c_parser *);
1134 static tree c_parser_asm_clobbers (c_parser *);
1135 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1136 static struct c_expr c_parser_conditional_expression (c_parser *,
1137                                                       struct c_expr *);
1138 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1139 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1140 static struct c_expr c_parser_unary_expression (c_parser *);
1141 static struct c_expr c_parser_sizeof_expression (c_parser *);
1142 static struct c_expr c_parser_alignof_expression (c_parser *);
1143 static struct c_expr c_parser_postfix_expression (c_parser *);
1144 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1145                                                                    struct c_type_name *,
1146                                                                    location_t);
1147 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1148                                                                 location_t loc,
1149                                                                 struct c_expr);
1150 static struct c_expr c_parser_expression (c_parser *);
1151 static struct c_expr c_parser_expression_conv (c_parser *);
1152 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1153                                          VEC(tree,gc) **);
1154 static void c_parser_omp_construct (c_parser *);
1155 static void c_parser_omp_threadprivate (c_parser *);
1156 static void c_parser_omp_barrier (c_parser *);
1157 static void c_parser_omp_flush (c_parser *);
1158 static void c_parser_omp_taskwait (c_parser *);
1159
1160 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1161 static bool c_parser_pragma (c_parser *, enum pragma_context);
1162
1163 /* These Objective-C parser functions are only ever called when
1164    compiling Objective-C.  */
1165 static void c_parser_objc_class_definition (c_parser *, tree);
1166 static void c_parser_objc_class_instance_variables (c_parser *);
1167 static void c_parser_objc_class_declaration (c_parser *);
1168 static void c_parser_objc_alias_declaration (c_parser *);
1169 static void c_parser_objc_protocol_definition (c_parser *, tree);
1170 static bool c_parser_objc_method_type (c_parser *);
1171 static void c_parser_objc_method_definition (c_parser *);
1172 static void c_parser_objc_methodprotolist (c_parser *);
1173 static void c_parser_objc_methodproto (c_parser *);
1174 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
1175 static tree c_parser_objc_type_name (c_parser *);
1176 static tree c_parser_objc_protocol_refs (c_parser *);
1177 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1178 static void c_parser_objc_synchronized_statement (c_parser *);
1179 static tree c_parser_objc_selector (c_parser *);
1180 static tree c_parser_objc_selector_arg (c_parser *);
1181 static tree c_parser_objc_receiver (c_parser *);
1182 static tree c_parser_objc_message_args (c_parser *);
1183 static tree c_parser_objc_keywordexpr (c_parser *);
1184 static void c_parser_objc_at_property_declaration (c_parser *);
1185 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1186 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1187 static bool c_parser_objc_diagnose_bad_element_prefix
1188   (c_parser *, struct c_declspecs *);
1189
1190 /* Parse a translation unit (C90 6.7, C99 6.9).
1191
1192    translation-unit:
1193      external-declarations
1194
1195    external-declarations:
1196      external-declaration
1197      external-declarations external-declaration
1198
1199    GNU extensions:
1200
1201    translation-unit:
1202      empty
1203 */
1204
1205 static void
1206 c_parser_translation_unit (c_parser *parser)
1207 {
1208   if (c_parser_next_token_is (parser, CPP_EOF))
1209     {
1210       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1211                "ISO C forbids an empty translation unit");
1212     }
1213   else
1214     {
1215       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1216       mark_valid_location_for_stdc_pragma (false);
1217       do
1218         {
1219           ggc_collect ();
1220           c_parser_external_declaration (parser);
1221           obstack_free (&parser_obstack, obstack_position);
1222         }
1223       while (c_parser_next_token_is_not (parser, CPP_EOF));
1224     }
1225 }
1226
1227 /* Parse an external declaration (C90 6.7, C99 6.9).
1228
1229    external-declaration:
1230      function-definition
1231      declaration
1232
1233    GNU extensions:
1234
1235    external-declaration:
1236      asm-definition
1237      ;
1238      __extension__ external-declaration
1239
1240    Objective-C:
1241
1242    external-declaration:
1243      objc-class-definition
1244      objc-class-declaration
1245      objc-alias-declaration
1246      objc-protocol-definition
1247      objc-method-definition
1248      @end
1249 */
1250
1251 static void
1252 c_parser_external_declaration (c_parser *parser)
1253 {
1254   int ext;
1255   switch (c_parser_peek_token (parser)->type)
1256     {
1257     case CPP_KEYWORD:
1258       switch (c_parser_peek_token (parser)->keyword)
1259         {
1260         case RID_EXTENSION:
1261           ext = disable_extension_diagnostics ();
1262           c_parser_consume_token (parser);
1263           c_parser_external_declaration (parser);
1264           restore_extension_diagnostics (ext);
1265           break;
1266         case RID_ASM:
1267           c_parser_asm_definition (parser);
1268           break;
1269         case RID_AT_INTERFACE:
1270         case RID_AT_IMPLEMENTATION:
1271           gcc_assert (c_dialect_objc ());
1272           c_parser_objc_class_definition (parser, NULL_TREE);
1273           break;
1274         case RID_AT_CLASS:
1275           gcc_assert (c_dialect_objc ());
1276           c_parser_objc_class_declaration (parser);
1277           break;
1278         case RID_AT_ALIAS:
1279           gcc_assert (c_dialect_objc ());
1280           c_parser_objc_alias_declaration (parser);
1281           break;
1282         case RID_AT_PROTOCOL:
1283           gcc_assert (c_dialect_objc ());
1284           c_parser_objc_protocol_definition (parser, NULL_TREE);
1285           break;
1286         case RID_AT_PROPERTY:
1287           gcc_assert (c_dialect_objc ());
1288           c_parser_objc_at_property_declaration (parser);
1289           break;
1290         case RID_AT_SYNTHESIZE:
1291           gcc_assert (c_dialect_objc ());
1292           c_parser_objc_at_synthesize_declaration (parser);
1293           break;
1294         case RID_AT_DYNAMIC:
1295           gcc_assert (c_dialect_objc ());
1296           c_parser_objc_at_dynamic_declaration (parser);
1297           break;
1298         case RID_AT_END:
1299           gcc_assert (c_dialect_objc ());
1300           c_parser_consume_token (parser);
1301           objc_finish_implementation ();
1302           break;
1303         default:
1304           goto decl_or_fndef;
1305         }
1306       break;
1307     case CPP_SEMICOLON:
1308       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1309                "ISO C does not allow extra %<;%> outside of a function");
1310       c_parser_consume_token (parser);
1311       break;
1312     case CPP_PRAGMA:
1313       mark_valid_location_for_stdc_pragma (true);
1314       c_parser_pragma (parser, pragma_external);
1315       mark_valid_location_for_stdc_pragma (false);
1316       break;
1317     case CPP_PLUS:
1318     case CPP_MINUS:
1319       if (c_dialect_objc ())
1320         {
1321           c_parser_objc_method_definition (parser);
1322           break;
1323         }
1324       /* Else fall through, and yield a syntax error trying to parse
1325          as a declaration or function definition.  */
1326     default:
1327     decl_or_fndef:
1328       /* A declaration or a function definition (or, in Objective-C,
1329          an @interface or @protocol with prefix attributes).  We can
1330          only tell which after parsing the declaration specifiers, if
1331          any, and the first declarator.  */
1332       c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1333       break;
1334     }
1335 }
1336
1337 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1338    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1339    accepted; otherwise (old-style parameter declarations) only other
1340    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1341    assertion is accepted; otherwise (old-style parameter declarations)
1342    it is not.  If NESTED is true, we are inside a function or parsing
1343    old-style parameter declarations; any functions encountered are
1344    nested functions and declaration specifiers are required; otherwise
1345    we are at top level and functions are normal functions and
1346    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1347    declarations are OK (subject to all other constraints); otherwise
1348    (old-style parameter declarations) they are diagnosed.  If
1349    START_ATTR_OK is true, the declaration specifiers may start with
1350    attributes; otherwise they may not.
1351    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1352    declaration when parsing an Objective-C foreach statement.
1353
1354    declaration:
1355      declaration-specifiers init-declarator-list[opt] ;
1356      static_assert-declaration
1357
1358    function-definition:
1359      declaration-specifiers[opt] declarator declaration-list[opt]
1360        compound-statement
1361
1362    declaration-list:
1363      declaration
1364      declaration-list declaration
1365
1366    init-declarator-list:
1367      init-declarator
1368      init-declarator-list , init-declarator
1369
1370    init-declarator:
1371      declarator simple-asm-expr[opt] attributes[opt]
1372      declarator simple-asm-expr[opt] attributes[opt] = initializer
1373
1374    GNU extensions:
1375
1376    nested-function-definition:
1377      declaration-specifiers declarator declaration-list[opt]
1378        compound-statement
1379
1380    Objective-C:
1381      attributes objc-class-definition
1382      attributes objc-category-definition
1383      attributes objc-protocol-definition
1384
1385    The simple-asm-expr and attributes are GNU extensions.
1386
1387    This function does not handle __extension__; that is handled in its
1388    callers.  ??? Following the old parser, __extension__ may start
1389    external declarations, declarations in functions and declarations
1390    at the start of "for" loops, but not old-style parameter
1391    declarations.
1392
1393    C99 requires declaration specifiers in a function definition; the
1394    absence is diagnosed through the diagnosis of implicit int.  In GNU
1395    C we also allow but diagnose declarations without declaration
1396    specifiers, but only at top level (elsewhere they conflict with
1397    other syntax).
1398
1399    In Objective-C, declarations of the looping variable in a foreach
1400    statement are exceptionally terminated by 'in' (for example, 'for
1401    (NSObject *object in array) { ... }').
1402
1403    OpenMP:
1404
1405    declaration:
1406      threadprivate-directive  */
1407
1408 static void
1409 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1410                                bool static_assert_ok, bool empty_ok,
1411                                bool nested, bool start_attr_ok,
1412                                tree *objc_foreach_object_declaration)
1413 {
1414   struct c_declspecs *specs;
1415   tree prefix_attrs;
1416   tree all_prefix_attrs;
1417   bool diagnosed_no_specs = false;
1418   location_t here = c_parser_peek_token (parser)->location;
1419
1420   if (static_assert_ok
1421       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1422     {
1423       c_parser_static_assert_declaration (parser);
1424       return;
1425     }
1426   specs = build_null_declspecs ();
1427
1428   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1429   if (c_parser_peek_token (parser)->type == CPP_NAME
1430       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1431       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1432           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1433       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1434     {
1435       error_at (here, "unknown type name %qE",
1436                 c_parser_peek_token (parser)->value);
1437
1438       /* Parse declspecs normally to get a correct pointer type, but avoid
1439          a further "fails to be a type name" error.  Refuse nested functions
1440          since it is not how the user likely wants us to recover.  */
1441       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1442       c_parser_peek_token (parser)->keyword = RID_VOID;
1443       c_parser_peek_token (parser)->value = error_mark_node;
1444       fndef_ok = !nested;
1445     }
1446
1447   c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1448   if (parser->error)
1449     {
1450       c_parser_skip_to_end_of_block_or_statement (parser);
1451       return;
1452     }
1453   if (nested && !specs->declspecs_seen_p)
1454     {
1455       c_parser_error (parser, "expected declaration specifiers");
1456       c_parser_skip_to_end_of_block_or_statement (parser);
1457       return;
1458     }
1459   finish_declspecs (specs);
1460   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1461     {
1462       if (empty_ok)
1463         shadow_tag (specs);
1464       else
1465         {
1466           shadow_tag_warned (specs, 1);
1467           pedwarn (here, 0, "empty declaration");
1468         }
1469       c_parser_consume_token (parser);
1470       return;
1471     }
1472
1473   /* Provide better error recovery.  Note that a type name here is usually
1474      better diagnosed as a redeclaration.  */
1475   if (empty_ok
1476       && specs->typespec_kind == ctsk_tagdef
1477       && c_parser_next_token_starts_declspecs (parser)
1478       && !c_parser_next_token_is (parser, CPP_NAME))
1479     {
1480       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1481       parser->error = false;
1482       shadow_tag_warned (specs, 1);
1483       return;
1484     }
1485   else if (c_dialect_objc ())
1486     {
1487       /* Prefix attributes are an error on method decls.  */
1488       switch (c_parser_peek_token (parser)->type)
1489         {
1490           case CPP_PLUS:
1491           case CPP_MINUS:
1492             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1493               return;
1494             if (specs->attrs)
1495               {
1496                 warning_at (c_parser_peek_token (parser)->location, 
1497                             OPT_Wattributes,
1498                             "prefix attributes are ignored for methods");
1499                 specs->attrs = NULL_TREE;
1500               }
1501             if (fndef_ok)
1502               c_parser_objc_method_definition (parser);
1503             else
1504               c_parser_objc_methodproto (parser);
1505             return;
1506             break;
1507           default:
1508             break;
1509         }
1510       /* This is where we parse 'attributes @interface ...',
1511          'attributes @implementation ...', 'attributes @protocol ...'
1512          (where attributes could be, for example, __attribute__
1513          ((deprecated)).
1514       */
1515       switch (c_parser_peek_token (parser)->keyword)
1516         {
1517         case RID_AT_INTERFACE:
1518           {
1519             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1520               return;
1521             c_parser_objc_class_definition (parser, specs->attrs);
1522             return;
1523           }
1524           break;
1525         case RID_AT_IMPLEMENTATION:
1526           {
1527             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1528               return;
1529             if (specs->attrs)
1530               {
1531                 warning_at (c_parser_peek_token (parser)->location, 
1532                         OPT_Wattributes,
1533                         "prefix attributes are ignored for implementations");
1534                 specs->attrs = NULL_TREE;
1535               }
1536             c_parser_objc_class_definition (parser, NULL_TREE);     
1537             return;
1538           }
1539           break;
1540         case RID_AT_PROTOCOL:
1541           {
1542             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1543               return;
1544             c_parser_objc_protocol_definition (parser, specs->attrs);
1545             return;
1546           }
1547           break;
1548         case RID_AT_ALIAS:
1549         case RID_AT_CLASS:
1550         case RID_AT_END:
1551         case RID_AT_PROPERTY:
1552           if (specs->attrs)
1553             {
1554               c_parser_error (parser, "unexpected attribute");
1555               specs->attrs = NULL;
1556             }
1557           break;
1558         default:
1559           break;
1560         }
1561     }
1562   
1563   pending_xref_error ();
1564   prefix_attrs = specs->attrs;
1565   all_prefix_attrs = prefix_attrs;
1566   specs->attrs = NULL_TREE;
1567   while (true)
1568     {
1569       struct c_declarator *declarator;
1570       bool dummy = false;
1571       tree fnbody;
1572       /* Declaring either one or more declarators (in which case we
1573          should diagnose if there were no declaration specifiers) or a
1574          function definition (in which case the diagnostic for
1575          implicit int suffices).  */
1576       declarator = c_parser_declarator (parser, 
1577                                         specs->typespec_kind != ctsk_none,
1578                                         C_DTR_NORMAL, &dummy);
1579       if (declarator == NULL)
1580         {
1581           c_parser_skip_to_end_of_block_or_statement (parser);
1582           return;
1583         }
1584       if (c_parser_next_token_is (parser, CPP_EQ)
1585           || c_parser_next_token_is (parser, CPP_COMMA)
1586           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1587           || c_parser_next_token_is_keyword (parser, RID_ASM)
1588           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1589           || c_parser_next_token_is_keyword (parser, RID_IN))
1590         {
1591           tree asm_name = NULL_TREE;
1592           tree postfix_attrs = NULL_TREE;
1593           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1594             {
1595               diagnosed_no_specs = true;
1596               pedwarn (here, 0, "data definition has no type or storage class");
1597             }
1598           /* Having seen a data definition, there cannot now be a
1599              function definition.  */
1600           fndef_ok = false;
1601           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1602             asm_name = c_parser_simple_asm_expr (parser);
1603           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1604             postfix_attrs = c_parser_attributes (parser);
1605           if (c_parser_next_token_is (parser, CPP_EQ))
1606             {
1607               tree d;
1608               struct c_expr init;
1609               location_t init_loc;
1610               c_parser_consume_token (parser);
1611               /* The declaration of the variable is in effect while
1612                  its initializer is parsed.  */
1613               d = start_decl (declarator, specs, true,
1614                               chainon (postfix_attrs, all_prefix_attrs));
1615               if (!d)
1616                 d = error_mark_node;
1617               start_init (d, asm_name, global_bindings_p ());
1618               init_loc = c_parser_peek_token (parser)->location;
1619               init = c_parser_initializer (parser);
1620               finish_init ();
1621               if (d != error_mark_node)
1622                 {
1623                   maybe_warn_string_init (TREE_TYPE (d), init);
1624                   finish_decl (d, init_loc, init.value,
1625                                init.original_type, asm_name);
1626                 }
1627             }
1628           else
1629             {
1630               tree d = start_decl (declarator, specs, false,
1631                                    chainon (postfix_attrs,
1632                                             all_prefix_attrs));
1633               if (d)
1634                 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1635                              NULL_TREE, asm_name);
1636               
1637               if (c_parser_next_token_is_keyword (parser, RID_IN))
1638                 {
1639                   if (d)
1640                     *objc_foreach_object_declaration = d;
1641                   else
1642                     *objc_foreach_object_declaration = error_mark_node;             
1643                 }
1644             }
1645           if (c_parser_next_token_is (parser, CPP_COMMA))
1646             {
1647               c_parser_consume_token (parser);
1648               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1649                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1650                                             prefix_attrs);
1651               else
1652                 all_prefix_attrs = prefix_attrs;
1653               continue;
1654             }
1655           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1656             {
1657               c_parser_consume_token (parser);
1658               return;
1659             }
1660           else if (c_parser_next_token_is_keyword (parser, RID_IN))
1661             {
1662               /* This can only happen in Objective-C: we found the
1663                  'in' that terminates the declaration inside an
1664                  Objective-C foreach statement.  Do not consume the
1665                  token, so that the caller can use it to determine
1666                  that this indeed is a foreach context.  */
1667               return;
1668             }
1669           else
1670             {
1671               c_parser_error (parser, "expected %<,%> or %<;%>");
1672               c_parser_skip_to_end_of_block_or_statement (parser);
1673               return;
1674             }
1675         }
1676       else if (!fndef_ok)
1677         {
1678           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1679                           "%<asm%> or %<__attribute__%>");
1680           c_parser_skip_to_end_of_block_or_statement (parser);
1681           return;
1682         }
1683       /* Function definition (nested or otherwise).  */
1684       if (nested)
1685         {
1686           pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1687           c_push_function_context ();
1688         }
1689       if (!start_function (specs, declarator, all_prefix_attrs))
1690         {
1691           /* This can appear in many cases looking nothing like a
1692              function definition, so we don't give a more specific
1693              error suggesting there was one.  */
1694           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1695                           "or %<__attribute__%>");
1696           if (nested)
1697             c_pop_function_context ();
1698           break;
1699         }
1700       /* Parse old-style parameter declarations.  ??? Attributes are
1701          not allowed to start declaration specifiers here because of a
1702          syntax conflict between a function declaration with attribute
1703          suffix and a function definition with an attribute prefix on
1704          first old-style parameter declaration.  Following the old
1705          parser, they are not accepted on subsequent old-style
1706          parameter declarations either.  However, there is no
1707          ambiguity after the first declaration, nor indeed on the
1708          first as long as we don't allow postfix attributes after a
1709          declarator with a nonempty identifier list in a definition;
1710          and postfix attributes have never been accepted here in
1711          function definitions either.  */
1712       while (c_parser_next_token_is_not (parser, CPP_EOF)
1713              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1714         c_parser_declaration_or_fndef (parser, false, false, false,
1715                                        true, false, NULL);
1716       store_parm_decls ();
1717       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1718         = c_parser_peek_token (parser)->location;
1719       fnbody = c_parser_compound_statement (parser);
1720       if (nested)
1721         {
1722           tree decl = current_function_decl;
1723           /* Mark nested functions as needing static-chain initially.
1724              lower_nested_functions will recompute it but the
1725              DECL_STATIC_CHAIN flag is also used before that happens,
1726              by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1727           DECL_STATIC_CHAIN (decl) = 1;
1728           add_stmt (fnbody);
1729           finish_function ();
1730           c_pop_function_context ();
1731           add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1732         }
1733       else
1734         {
1735           add_stmt (fnbody);
1736           finish_function ();
1737         }
1738       break;
1739     }
1740 }
1741
1742 /* Parse an asm-definition (asm() outside a function body).  This is a
1743    GNU extension.
1744
1745    asm-definition:
1746      simple-asm-expr ;
1747 */
1748
1749 static void
1750 c_parser_asm_definition (c_parser *parser)
1751 {
1752   tree asm_str = c_parser_simple_asm_expr (parser);
1753   if (asm_str)
1754     cgraph_add_asm_node (asm_str);
1755   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1756 }
1757
1758 /* Parse a static assertion (C1X N1425 6.7.10).
1759
1760    static_assert-declaration:
1761      static_assert-declaration-no-semi ;
1762 */
1763
1764 static void
1765 c_parser_static_assert_declaration (c_parser *parser)
1766 {
1767   c_parser_static_assert_declaration_no_semi (parser);
1768   if (parser->error
1769       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1770     c_parser_skip_to_end_of_block_or_statement (parser);
1771 }
1772
1773 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1774    semicolon.
1775
1776    static_assert-declaration-no-semi:
1777      _Static_assert ( constant-expression , string-literal )
1778 */
1779
1780 static void
1781 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1782 {
1783   location_t assert_loc, value_loc;
1784   tree value;
1785   tree string;
1786
1787   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1788   assert_loc = c_parser_peek_token (parser)->location;
1789   if (!flag_isoc1x)
1790     {
1791       if (flag_isoc99)
1792         pedwarn (assert_loc, OPT_pedantic,
1793                  "ISO C99 does not support %<_Static_assert%>");
1794       else
1795         pedwarn (assert_loc, OPT_pedantic,
1796                  "ISO C90 does not support %<_Static_assert%>");
1797     }
1798   c_parser_consume_token (parser);
1799   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1800     return;
1801   value_loc = c_parser_peek_token (parser)->location;
1802   value = c_parser_expr_no_commas (parser, NULL).value;
1803   parser->lex_untranslated_string = true;
1804   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1805     {
1806       parser->lex_untranslated_string = false;
1807       return;
1808     }
1809   switch (c_parser_peek_token (parser)->type)
1810     {
1811     case CPP_STRING:
1812     case CPP_STRING16:
1813     case CPP_STRING32:
1814     case CPP_WSTRING:
1815     case CPP_UTF8STRING:
1816       string = c_parser_peek_token (parser)->value;
1817       c_parser_consume_token (parser);
1818       parser->lex_untranslated_string = false;
1819       break;
1820     default:
1821       c_parser_error (parser, "expected string literal");
1822       parser->lex_untranslated_string = false;
1823       return;
1824     }
1825   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1826
1827   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1828     {
1829       error_at (value_loc, "expression in static assertion is not an integer");
1830       return;
1831     }
1832   if (TREE_CODE (value) != INTEGER_CST)
1833     {
1834       value = c_fully_fold (value, false, NULL);
1835       if (TREE_CODE (value) == INTEGER_CST)
1836         pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1837                  "is not an integer constant expression");
1838     }
1839   if (TREE_CODE (value) != INTEGER_CST)
1840     {
1841       error_at (value_loc, "expression in static assertion is not constant");
1842       return;
1843     }
1844   constant_expression_warning (value);
1845   if (integer_zerop (value))
1846     error_at (assert_loc, "static assertion failed: %E", string);
1847 }
1848
1849 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1850    6.7), adding them to SPECS (which may already include some).
1851    Storage class specifiers are accepted iff SCSPEC_OK; type
1852    specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1853    the start iff START_ATTR_OK.
1854
1855    declaration-specifiers:
1856      storage-class-specifier declaration-specifiers[opt]
1857      type-specifier declaration-specifiers[opt]
1858      type-qualifier declaration-specifiers[opt]
1859      function-specifier declaration-specifiers[opt]
1860
1861    Function specifiers (inline) are from C99, and are currently
1862    handled as storage class specifiers, as is __thread.
1863
1864    C90 6.5.1, C99 6.7.1:
1865    storage-class-specifier:
1866      typedef
1867      extern
1868      static
1869      auto
1870      register
1871
1872    C99 6.7.4:
1873    function-specifier:
1874      inline
1875
1876    C90 6.5.2, C99 6.7.2:
1877    type-specifier:
1878      void
1879      char
1880      short
1881      int
1882      long
1883      float
1884      double
1885      signed
1886      unsigned
1887      _Bool
1888      _Complex
1889      [_Imaginary removed in C99 TC2]
1890      struct-or-union-specifier
1891      enum-specifier
1892      typedef-name
1893
1894    (_Bool and _Complex are new in C99.)
1895
1896    C90 6.5.3, C99 6.7.3:
1897
1898    type-qualifier:
1899      const
1900      restrict
1901      volatile
1902      address-space-qualifier
1903
1904    (restrict is new in C99.)
1905
1906    GNU extensions:
1907
1908    declaration-specifiers:
1909      attributes declaration-specifiers[opt]
1910
1911    type-qualifier:
1912      address-space
1913
1914    address-space:
1915      identifier recognized by the target
1916
1917    storage-class-specifier:
1918      __thread
1919
1920    type-specifier:
1921      typeof-specifier
1922      __int128
1923      _Decimal32
1924      _Decimal64
1925      _Decimal128
1926      _Fract
1927      _Accum
1928      _Sat
1929
1930   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1931    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1932
1933    Objective-C:
1934
1935    type-specifier:
1936      class-name objc-protocol-refs[opt]
1937      typedef-name objc-protocol-refs
1938      objc-protocol-refs
1939 */
1940
1941 static void
1942 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1943                     bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1944                     enum c_lookahead_kind la)
1945 {
1946   bool attrs_ok = start_attr_ok;
1947   bool seen_type = specs->typespec_kind != ctsk_none;
1948
1949   if (!typespec_ok)
1950     gcc_assert (la == cla_prefer_id);
1951
1952   while (c_parser_next_token_is (parser, CPP_NAME)
1953          || c_parser_next_token_is (parser, CPP_KEYWORD)
1954          || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1955     {
1956       struct c_typespec t;
1957       tree attrs;
1958       location_t loc = c_parser_peek_token (parser)->location;
1959
1960       /* If we cannot accept a type, exit if the next token must start
1961          one.  Also, if we already have seen a tagged definition,
1962          a typename would be an error anyway and likely the user
1963          has simply forgotten a semicolon, so we exit.  */
1964       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1965           && c_parser_next_tokens_start_typename (parser, la)
1966           && !c_parser_next_token_is_qualifier (parser))
1967         break;
1968
1969       if (c_parser_next_token_is (parser, CPP_NAME))
1970         {
1971           tree value = c_parser_peek_token (parser)->value;
1972           c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1973
1974           if (kind == C_ID_ADDRSPACE)
1975             {
1976               addr_space_t as
1977                 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1978               declspecs_add_addrspace (specs, as);
1979               c_parser_consume_token (parser);
1980               attrs_ok = true;
1981               continue;
1982             }
1983
1984           gcc_assert (!c_parser_next_token_is_qualifier (parser));
1985
1986           /* If we cannot accept a type, and the next token must start one,
1987              exit.  Do the same if we already have seen a tagged definition,
1988              since it would be an error anyway and likely the user has simply
1989              forgotten a semicolon.  */
1990           if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
1991             break;
1992
1993           /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
1994              a C_ID_CLASSNAME.  */
1995           c_parser_consume_token (parser);
1996           seen_type = true;
1997           attrs_ok = true;
1998           if (kind == C_ID_ID)
1999             {
2000               error ("unknown type name %qE", value);
2001               t.kind = ctsk_typedef;
2002               t.spec = error_mark_node;
2003             }
2004           else if (kind == C_ID_TYPENAME
2005                    && (!c_dialect_objc ()
2006                        || c_parser_next_token_is_not (parser, CPP_LESS)))
2007             {
2008               t.kind = ctsk_typedef;
2009               /* For a typedef name, record the meaning, not the name.
2010                  In case of 'foo foo, bar;'.  */
2011               t.spec = lookup_name (value);
2012             }
2013           else
2014             {
2015               tree proto = NULL_TREE;
2016               gcc_assert (c_dialect_objc ());
2017               t.kind = ctsk_objc;
2018               if (c_parser_next_token_is (parser, CPP_LESS))
2019                 proto = c_parser_objc_protocol_refs (parser);
2020               t.spec = objc_get_protocol_qualified_type (value, proto);
2021             }
2022           t.expr = NULL_TREE;
2023           t.expr_const_operands = true;
2024           declspecs_add_type (loc, specs, t);
2025           continue;
2026         }
2027       if (c_parser_next_token_is (parser, CPP_LESS))
2028         {
2029           /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2030              nisse@lysator.liu.se.  */
2031           tree proto;
2032           gcc_assert (c_dialect_objc ());
2033           if (!typespec_ok || seen_type)
2034             break;
2035           proto = c_parser_objc_protocol_refs (parser);
2036           t.kind = ctsk_objc;
2037           t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2038           t.expr = NULL_TREE;
2039           t.expr_const_operands = true;
2040           declspecs_add_type (loc, specs, t);
2041           continue;
2042         }
2043       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2044       switch (c_parser_peek_token (parser)->keyword)
2045         {
2046         case RID_STATIC:
2047         case RID_EXTERN:
2048         case RID_REGISTER:
2049         case RID_TYPEDEF:
2050         case RID_INLINE:
2051         case RID_AUTO:
2052         case RID_THREAD:
2053           if (!scspec_ok)
2054             goto out;
2055           attrs_ok = true;
2056           /* TODO: Distinguish between function specifiers (inline)
2057              and storage class specifiers, either here or in
2058              declspecs_add_scspec.  */
2059           declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2060           c_parser_consume_token (parser);
2061           break;
2062         case RID_UNSIGNED:
2063         case RID_LONG:
2064         case RID_INT128:
2065         case RID_SHORT:
2066         case RID_SIGNED:
2067         case RID_COMPLEX:
2068         case RID_INT:
2069         case RID_CHAR:
2070         case RID_FLOAT:
2071         case RID_DOUBLE:
2072         case RID_VOID:
2073         case RID_DFLOAT32:
2074         case RID_DFLOAT64:
2075         case RID_DFLOAT128:
2076         case RID_BOOL:
2077         case RID_FRACT:
2078         case RID_ACCUM:
2079         case RID_SAT:
2080           if (!typespec_ok)
2081             goto out;
2082           attrs_ok = true;
2083           seen_type = true;
2084           if (c_dialect_objc ())
2085             parser->objc_need_raw_identifier = true;
2086           t.kind = ctsk_resword;
2087           t.spec = c_parser_peek_token (parser)->value;
2088           t.expr = NULL_TREE;
2089           t.expr_const_operands = true;
2090           declspecs_add_type (loc, specs, t);
2091           c_parser_consume_token (parser);
2092           break;
2093         case RID_ENUM:
2094           if (!typespec_ok)
2095             goto out;
2096           attrs_ok = true;
2097           seen_type = true;
2098           t = c_parser_enum_specifier (parser);
2099           declspecs_add_type (loc, specs, t);
2100           break;
2101         case RID_STRUCT:
2102         case RID_UNION:
2103           if (!typespec_ok)
2104             goto out;
2105           attrs_ok = true;
2106           seen_type = true;
2107           t = c_parser_struct_or_union_specifier (parser);
2108           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2109           declspecs_add_type (loc, specs, t);
2110           break;
2111         case RID_TYPEOF:
2112           /* ??? The old parser rejected typeof after other type
2113              specifiers, but is a syntax error the best way of
2114              handling this?  */
2115           if (!typespec_ok || seen_type)
2116             goto out;
2117           attrs_ok = true;
2118           seen_type = true;
2119           t = c_parser_typeof_specifier (parser);
2120           declspecs_add_type (loc, specs, t);
2121           break;
2122         case RID_CONST:
2123         case RID_VOLATILE:
2124         case RID_RESTRICT:
2125           attrs_ok = true;
2126           declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2127           c_parser_consume_token (parser);
2128           break;
2129         case RID_ATTRIBUTE:
2130           if (!attrs_ok)
2131             goto out;
2132           attrs = c_parser_attributes (parser);
2133           declspecs_add_attrs (specs, attrs);
2134           break;
2135         default:
2136           goto out;
2137         }
2138     }
2139  out: ;
2140 }
2141
2142 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2143
2144    enum-specifier:
2145      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2146      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2147      enum attributes[opt] identifier
2148
2149    The form with trailing comma is new in C99.  The forms with
2150    attributes are GNU extensions.  In GNU C, we accept any expression
2151    without commas in the syntax (assignment expressions, not just
2152    conditional expressions); assignment expressions will be diagnosed
2153    as non-constant.
2154
2155    enumerator-list:
2156      enumerator
2157      enumerator-list , enumerator
2158
2159    enumerator:
2160      enumeration-constant
2161      enumeration-constant = constant-expression
2162 */
2163
2164 static struct c_typespec
2165 c_parser_enum_specifier (c_parser *parser)
2166 {
2167   struct c_typespec ret;
2168   tree attrs;
2169   tree ident = NULL_TREE;
2170   location_t enum_loc;
2171   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2172   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2173   enum_loc = c_parser_peek_token (parser)->location;
2174   c_parser_consume_token (parser);
2175   attrs = c_parser_attributes (parser);
2176   enum_loc = c_parser_peek_token (parser)->location;
2177   /* Set the location in case we create a decl now.  */
2178   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2179   if (c_parser_next_token_is (parser, CPP_NAME))
2180     {
2181       ident = c_parser_peek_token (parser)->value;
2182       ident_loc = c_parser_peek_token (parser)->location;
2183       enum_loc = ident_loc;
2184       c_parser_consume_token (parser);
2185     }
2186   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2187     {
2188       /* Parse an enum definition.  */
2189       struct c_enum_contents the_enum;
2190       tree type = start_enum (enum_loc, &the_enum, ident);
2191       tree postfix_attrs;
2192       /* We chain the enumerators in reverse order, then put them in
2193          forward order at the end.  */
2194       tree values = NULL_TREE;
2195       c_parser_consume_token (parser);
2196       while (true)
2197         {
2198           tree enum_id;
2199           tree enum_value;
2200           tree enum_decl;
2201           bool seen_comma;
2202           c_token *token;
2203           location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2204           location_t decl_loc, value_loc;
2205           if (c_parser_next_token_is_not (parser, CPP_NAME))
2206             {
2207               c_parser_error (parser, "expected identifier");
2208               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2209               values = error_mark_node;
2210               break;
2211             }
2212           token = c_parser_peek_token (parser);
2213           enum_id = token->value;
2214           /* Set the location in case we create a decl now.  */
2215           c_parser_set_source_position_from_token (token);
2216           decl_loc = value_loc = token->location;
2217           c_parser_consume_token (parser);
2218           if (c_parser_next_token_is (parser, CPP_EQ))
2219             {
2220               c_parser_consume_token (parser);
2221               value_loc = c_parser_peek_token (parser)->location;
2222               enum_value = c_parser_expr_no_commas (parser, NULL).value;
2223             }
2224           else
2225             enum_value = NULL_TREE;
2226           enum_decl = build_enumerator (decl_loc, value_loc,
2227                                         &the_enum, enum_id, enum_value);
2228           TREE_CHAIN (enum_decl) = values;
2229           values = enum_decl;
2230           seen_comma = false;
2231           if (c_parser_next_token_is (parser, CPP_COMMA))
2232             {
2233               comma_loc = c_parser_peek_token (parser)->location;
2234               seen_comma = true;
2235               c_parser_consume_token (parser);
2236             }
2237           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2238             {
2239               if (seen_comma && !flag_isoc99)
2240                 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2241               c_parser_consume_token (parser);
2242               break;
2243             }
2244           if (!seen_comma)
2245             {
2246               c_parser_error (parser, "expected %<,%> or %<}%>");
2247               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2248               values = error_mark_node;
2249               break;
2250             }
2251         }
2252       postfix_attrs = c_parser_attributes (parser);
2253       ret.spec = finish_enum (type, nreverse (values),
2254                               chainon (attrs, postfix_attrs));
2255       ret.kind = ctsk_tagdef;
2256       ret.expr = NULL_TREE;
2257       ret.expr_const_operands = true;
2258       return ret;
2259     }
2260   else if (!ident)
2261     {
2262       c_parser_error (parser, "expected %<{%>");
2263       ret.spec = error_mark_node;
2264       ret.kind = ctsk_tagref;
2265       ret.expr = NULL_TREE;
2266       ret.expr_const_operands = true;
2267       return ret;
2268     }
2269   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2270   /* In ISO C, enumerated types can be referred to only if already
2271      defined.  */
2272   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2273     {
2274       gcc_assert (ident);
2275       pedwarn (enum_loc, OPT_pedantic,
2276                "ISO C forbids forward references to %<enum%> types");
2277     }
2278   return ret;
2279 }
2280
2281 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2282
2283    struct-or-union-specifier:
2284      struct-or-union attributes[opt] identifier[opt]
2285        { struct-contents } attributes[opt]
2286      struct-or-union attributes[opt] identifier
2287
2288    struct-contents:
2289      struct-declaration-list
2290
2291    struct-declaration-list:
2292      struct-declaration ;
2293      struct-declaration-list struct-declaration ;
2294
2295    GNU extensions:
2296
2297    struct-contents:
2298      empty
2299      struct-declaration
2300      struct-declaration-list struct-declaration
2301
2302    struct-declaration-list:
2303      struct-declaration-list ;
2304      ;
2305
2306    (Note that in the syntax here, unlike that in ISO C, the semicolons
2307    are included here rather than in struct-declaration, in order to
2308    describe the syntax with extra semicolons and missing semicolon at
2309    end.)
2310
2311    Objective-C:
2312
2313    struct-declaration-list:
2314      @defs ( class-name )
2315
2316    (Note this does not include a trailing semicolon, but can be
2317    followed by further declarations, and gets a pedwarn-if-pedantic
2318    when followed by a semicolon.)  */
2319
2320 static struct c_typespec
2321 c_parser_struct_or_union_specifier (c_parser *parser)
2322 {
2323   struct c_typespec ret;
2324   tree attrs;
2325   tree ident = NULL_TREE;
2326   location_t struct_loc;
2327   location_t ident_loc = UNKNOWN_LOCATION;
2328   enum tree_code code;
2329   switch (c_parser_peek_token (parser)->keyword)
2330     {
2331     case RID_STRUCT:
2332       code = RECORD_TYPE;
2333       break;
2334     case RID_UNION:
2335       code = UNION_TYPE;
2336       break;
2337     default:
2338       gcc_unreachable ();
2339     }
2340   struct_loc = c_parser_peek_token (parser)->location;
2341   c_parser_consume_token (parser);
2342   attrs = c_parser_attributes (parser);
2343
2344   /* Set the location in case we create a decl now.  */
2345   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2346
2347   if (c_parser_next_token_is (parser, CPP_NAME))
2348     {
2349       ident = c_parser_peek_token (parser)->value;
2350       ident_loc = c_parser_peek_token (parser)->location;
2351       struct_loc = ident_loc;
2352       c_parser_consume_token (parser);
2353     }
2354   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2355     {
2356       /* Parse a struct or union definition.  Start the scope of the
2357          tag before parsing components.  */
2358       struct c_struct_parse_info *struct_info;
2359       tree type = start_struct (struct_loc, code, ident, &struct_info);
2360       tree postfix_attrs;
2361       /* We chain the components in reverse order, then put them in
2362          forward order at the end.  Each struct-declaration may
2363          declare multiple components (comma-separated), so we must use
2364          chainon to join them, although when parsing each
2365          struct-declaration we can use TREE_CHAIN directly.
2366
2367          The theory behind all this is that there will be more
2368          semicolon separated fields than comma separated fields, and
2369          so we'll be minimizing the number of node traversals required
2370          by chainon.  */
2371       tree contents = NULL_TREE;
2372       c_parser_consume_token (parser);
2373       /* Handle the Objective-C @defs construct,
2374          e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2375       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2376         {
2377           tree name;
2378           gcc_assert (c_dialect_objc ());
2379           c_parser_consume_token (parser);
2380           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2381             goto end_at_defs;
2382           if (c_parser_next_token_is (parser, CPP_NAME)
2383               && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2384             {
2385               name = c_parser_peek_token (parser)->value;
2386               c_parser_consume_token (parser);
2387             }
2388           else
2389             {
2390               c_parser_error (parser, "expected class name");
2391               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2392               goto end_at_defs;
2393             }
2394           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2395                                      "expected %<)%>");
2396           contents = nreverse (objc_get_class_ivars (name));
2397         }
2398     end_at_defs:
2399       /* Parse the struct-declarations and semicolons.  Problems with
2400          semicolons are diagnosed here; empty structures are diagnosed
2401          elsewhere.  */
2402       while (true)
2403         {
2404           tree decls;
2405           /* Parse any stray semicolon.  */
2406           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2407             {
2408               pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2409                        "extra semicolon in struct or union specified");
2410               c_parser_consume_token (parser);
2411               continue;
2412             }
2413           /* Stop if at the end of the struct or union contents.  */
2414           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2415             {
2416               c_parser_consume_token (parser);
2417               break;
2418             }
2419           /* Accept #pragmas at struct scope.  */
2420           if (c_parser_next_token_is (parser, CPP_PRAGMA))
2421             {
2422               c_parser_pragma (parser, pragma_external);
2423               continue;
2424             }
2425           /* Parse some comma-separated declarations, but not the
2426              trailing semicolon if any.  */
2427           decls = c_parser_struct_declaration (parser);
2428           contents = chainon (decls, contents);
2429           /* If no semicolon follows, either we have a parse error or
2430              are at the end of the struct or union and should
2431              pedwarn.  */
2432           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2433             c_parser_consume_token (parser);
2434           else
2435             {
2436               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2437                 pedwarn (c_parser_peek_token (parser)->location, 0,
2438                          "no semicolon at end of struct or union");
2439               else if (parser->error
2440                        || !c_parser_next_token_starts_declspecs (parser))
2441                 {
2442                   c_parser_error (parser, "expected %<;%>");
2443                   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2444                   break;
2445                 }
2446
2447               /* If we come here, we have already emitted an error
2448                  for an expected `;', identifier or `(', and we also
2449                  recovered already.  Go on with the next field. */
2450             }
2451         }
2452       postfix_attrs = c_parser_attributes (parser);
2453       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2454                                 chainon (attrs, postfix_attrs), struct_info);
2455       ret.kind = ctsk_tagdef;
2456       ret.expr = NULL_TREE;
2457       ret.expr_const_operands = true;
2458       return ret;
2459     }
2460   else if (!ident)
2461     {
2462       c_parser_error (parser, "expected %<{%>");
2463       ret.spec = error_mark_node;
2464       ret.kind = ctsk_tagref;
2465       ret.expr = NULL_TREE;
2466       ret.expr_const_operands = true;
2467       return ret;
2468     }
2469   ret = parser_xref_tag (ident_loc, code, ident);
2470   return ret;
2471 }
2472
2473 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2474    the trailing semicolon.
2475
2476    struct-declaration:
2477      specifier-qualifier-list struct-declarator-list
2478      static_assert-declaration-no-semi
2479
2480    specifier-qualifier-list:
2481      type-specifier specifier-qualifier-list[opt]
2482      type-qualifier specifier-qualifier-list[opt]
2483      attributes specifier-qualifier-list[opt]
2484
2485    struct-declarator-list:
2486      struct-declarator
2487      struct-declarator-list , attributes[opt] struct-declarator
2488
2489    struct-declarator:
2490      declarator attributes[opt]
2491      declarator[opt] : constant-expression attributes[opt]
2492
2493    GNU extensions:
2494
2495    struct-declaration:
2496      __extension__ struct-declaration
2497      specifier-qualifier-list
2498
2499    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
2500    of attributes where shown is a GNU extension.  In GNU C, we accept
2501    any expression without commas in the syntax (assignment
2502    expressions, not just conditional expressions); assignment
2503    expressions will be diagnosed as non-constant.  */
2504
2505 static tree
2506 c_parser_struct_declaration (c_parser *parser)
2507 {
2508   struct c_declspecs *specs;
2509   tree prefix_attrs;
2510   tree all_prefix_attrs;
2511   tree decls;
2512   location_t decl_loc;
2513   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2514     {
2515       int ext;
2516       tree decl;
2517       ext = disable_extension_diagnostics ();
2518       c_parser_consume_token (parser);
2519       decl = c_parser_struct_declaration (parser);
2520       restore_extension_diagnostics (ext);
2521       return decl;
2522     }
2523   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2524     {
2525       c_parser_static_assert_declaration_no_semi (parser);
2526       return NULL_TREE;
2527     }
2528   specs = build_null_declspecs ();
2529   decl_loc = c_parser_peek_token (parser)->location;
2530   c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2531   if (parser->error)
2532     return NULL_TREE;
2533   if (!specs->declspecs_seen_p)
2534     {
2535       c_parser_error (parser, "expected specifier-qualifier-list");
2536       return NULL_TREE;
2537     }
2538   finish_declspecs (specs);
2539   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2540       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2541     {
2542       tree ret;
2543       if (specs->typespec_kind == ctsk_none)
2544         {
2545           pedwarn (decl_loc, OPT_pedantic,
2546                    "ISO C forbids member declarations with no members");
2547           shadow_tag_warned (specs, pedantic);
2548           ret = NULL_TREE;
2549         }
2550       else
2551         {
2552           /* Support for unnamed structs or unions as members of
2553              structs or unions (which is [a] useful and [b] supports
2554              MS P-SDK).  */
2555           tree attrs = NULL;
2556
2557           ret = grokfield (c_parser_peek_token (parser)->location,
2558                            build_id_declarator (NULL_TREE), specs,
2559                            NULL_TREE, &attrs);
2560           if (ret)
2561             decl_attributes (&ret, attrs, 0);
2562         }
2563       return ret;
2564     }
2565
2566   /* Provide better error recovery.  Note that a type name here is valid,
2567      and will be treated as a field name.  */
2568   if (specs->typespec_kind == ctsk_tagdef
2569       && TREE_CODE (specs->type) != ENUMERAL_TYPE
2570       && c_parser_next_token_starts_declspecs (parser)
2571       && !c_parser_next_token_is (parser, CPP_NAME))
2572     {
2573       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2574       parser->error = false;
2575       return NULL_TREE;
2576     }
2577
2578   pending_xref_error ();
2579   prefix_attrs = specs->attrs;
2580   all_prefix_attrs = prefix_attrs;
2581   specs->attrs = NULL_TREE;
2582   decls = NULL_TREE;
2583   while (true)
2584     {
2585       /* Declaring one or more declarators or un-named bit-fields.  */
2586       struct c_declarator *declarator;
2587       bool dummy = false;
2588       if (c_parser_next_token_is (parser, CPP_COLON))
2589         declarator = build_id_declarator (NULL_TREE);
2590       else
2591         declarator = c_parser_declarator (parser,
2592                                           specs->typespec_kind != ctsk_none,
2593                                           C_DTR_NORMAL, &dummy);
2594       if (declarator == NULL)
2595         {
2596           c_parser_skip_to_end_of_block_or_statement (parser);
2597           break;
2598         }
2599       if (c_parser_next_token_is (parser, CPP_COLON)
2600           || c_parser_next_token_is (parser, CPP_COMMA)
2601           || c_parser_next_token_is (parser, CPP_SEMICOLON)
2602           || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2603           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2604         {
2605           tree postfix_attrs = NULL_TREE;
2606           tree width = NULL_TREE;
2607           tree d;
2608           if (c_parser_next_token_is (parser, CPP_COLON))
2609             {
2610               c_parser_consume_token (parser);
2611               width = c_parser_expr_no_commas (parser, NULL).value;
2612             }
2613           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2614             postfix_attrs = c_parser_attributes (parser);
2615           d = grokfield (c_parser_peek_token (parser)->location,
2616                          declarator, specs, width, &all_prefix_attrs);
2617           decl_attributes (&d, chainon (postfix_attrs,
2618                                         all_prefix_attrs), 0);
2619           DECL_CHAIN (d) = decls;
2620           decls = d;
2621           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2622             all_prefix_attrs = chainon (c_parser_attributes (parser),
2623                                         prefix_attrs);
2624           else
2625             all_prefix_attrs = prefix_attrs;
2626           if (c_parser_next_token_is (parser, CPP_COMMA))
2627             c_parser_consume_token (parser);
2628           else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2629                    || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2630             {
2631               /* Semicolon consumed in caller.  */
2632               break;
2633             }
2634           else
2635             {
2636               c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2637               break;
2638             }
2639         }
2640       else
2641         {
2642           c_parser_error (parser,
2643                           "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2644                           "%<__attribute__%>");
2645           break;
2646         }
2647     }
2648   return decls;
2649 }
2650
2651 /* Parse a typeof specifier (a GNU extension).
2652
2653    typeof-specifier:
2654      typeof ( expression )
2655      typeof ( type-name )
2656 */
2657
2658 static struct c_typespec
2659 c_parser_typeof_specifier (c_parser *parser)
2660 {
2661   struct c_typespec ret;
2662   ret.kind = ctsk_typeof;
2663   ret.spec = error_mark_node;
2664   ret.expr = NULL_TREE;
2665   ret.expr_const_operands = true;
2666   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2667   c_parser_consume_token (parser);
2668   c_inhibit_evaluation_warnings++;
2669   in_typeof++;
2670   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2671     {
2672       c_inhibit_evaluation_warnings--;
2673       in_typeof--;
2674       return ret;
2675     }
2676   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2677     {
2678       struct c_type_name *type = c_parser_type_name (parser);
2679       c_inhibit_evaluation_warnings--;
2680       in_typeof--;
2681       if (type != NULL)
2682         {
2683           ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2684           pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2685         }
2686     }
2687   else
2688     {
2689       bool was_vm;
2690       location_t here = c_parser_peek_token (parser)->location;
2691       struct c_expr expr = c_parser_expression (parser);
2692       c_inhibit_evaluation_warnings--;
2693       in_typeof--;
2694       if (TREE_CODE (expr.value) == COMPONENT_REF
2695           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2696         error_at (here, "%<typeof%> applied to a bit-field");
2697       mark_exp_read (expr.value);
2698       ret.spec = TREE_TYPE (expr.value);
2699       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2700       /* This is returned with the type so that when the type is
2701          evaluated, this can be evaluated.  */
2702       if (was_vm)
2703         ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2704       pop_maybe_used (was_vm);
2705     }
2706   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2707   return ret;
2708 }
2709
2710 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2711    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
2712    be redeclared; otherwise it may not.  KIND indicates which kind of
2713    declarator is wanted.  Returns a valid declarator except in the
2714    case of a syntax error in which case NULL is returned.  *SEEN_ID is
2715    set to true if an identifier being declared is seen; this is used
2716    to diagnose bad forms of abstract array declarators and to
2717    determine whether an identifier list is syntactically permitted.
2718
2719    declarator:
2720      pointer[opt] direct-declarator
2721
2722    direct-declarator:
2723      identifier
2724      ( attributes[opt] declarator )
2725      direct-declarator array-declarator
2726      direct-declarator ( parameter-type-list )
2727      direct-declarator ( identifier-list[opt] )
2728
2729    pointer:
2730      * type-qualifier-list[opt]
2731      * type-qualifier-list[opt] pointer
2732
2733    type-qualifier-list:
2734      type-qualifier
2735      attributes
2736      type-qualifier-list type-qualifier
2737      type-qualifier-list attributes
2738
2739    parameter-type-list:
2740      parameter-list
2741      parameter-list , ...
2742
2743    parameter-list:
2744      parameter-declaration
2745      parameter-list , parameter-declaration
2746
2747    parameter-declaration:
2748      declaration-specifiers declarator attributes[opt]
2749      declaration-specifiers abstract-declarator[opt] attributes[opt]
2750
2751    identifier-list:
2752      identifier
2753      identifier-list , identifier
2754
2755    abstract-declarator:
2756      pointer
2757      pointer[opt] direct-abstract-declarator
2758
2759    direct-abstract-declarator:
2760      ( attributes[opt] abstract-declarator )
2761      direct-abstract-declarator[opt] array-declarator
2762      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2763
2764    GNU extensions:
2765
2766    direct-declarator:
2767      direct-declarator ( parameter-forward-declarations
2768                          parameter-type-list[opt] )
2769
2770    direct-abstract-declarator:
2771      direct-abstract-declarator[opt] ( parameter-forward-declarations
2772                                        parameter-type-list[opt] )
2773
2774    parameter-forward-declarations:
2775      parameter-list ;
2776      parameter-forward-declarations parameter-list ;
2777
2778    The uses of attributes shown above are GNU extensions.
2779
2780    Some forms of array declarator are not included in C99 in the
2781    syntax for abstract declarators; these are disallowed elsewhere.
2782    This may be a defect (DR#289).
2783
2784    This function also accepts an omitted abstract declarator as being
2785    an abstract declarator, although not part of the formal syntax.  */
2786
2787 static struct c_declarator *
2788 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2789                      bool *seen_id)
2790 {
2791   /* Parse any initial pointer part.  */
2792   if (c_parser_next_token_is (parser, CPP_MULT))
2793     {
2794       struct c_declspecs *quals_attrs = build_null_declspecs ();
2795       struct c_declarator *inner;
2796       c_parser_consume_token (parser);
2797       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2798       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2799       if (inner == NULL)
2800         return NULL;
2801       else
2802         return make_pointer_declarator (quals_attrs, inner);
2803     }
2804   /* Now we have a direct declarator, direct abstract declarator or
2805      nothing (which counts as a direct abstract declarator here).  */
2806   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2807 }
2808
2809 /* Parse a direct declarator or direct abstract declarator; arguments
2810    as c_parser_declarator.  */
2811
2812 static struct c_declarator *
2813 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2814                             bool *seen_id)
2815 {
2816   /* The direct declarator must start with an identifier (possibly
2817      omitted) or a parenthesized declarator (possibly abstract).  In
2818      an ordinary declarator, initial parentheses must start a
2819      parenthesized declarator.  In an abstract declarator or parameter
2820      declarator, they could start a parenthesized declarator or a
2821      parameter list.  To tell which, the open parenthesis and any
2822      following attributes must be read.  If a declaration specifier
2823      follows, then it is a parameter list; if the specifier is a
2824      typedef name, there might be an ambiguity about redeclaring it,
2825      which is resolved in the direction of treating it as a typedef
2826      name.  If a close parenthesis follows, it is also an empty
2827      parameter list, as the syntax does not permit empty abstract
2828      declarators.  Otherwise, it is a parenthesized declarator (in
2829      which case the analysis may be repeated inside it, recursively).
2830
2831      ??? There is an ambiguity in a parameter declaration "int
2832      (__attribute__((foo)) x)", where x is not a typedef name: it
2833      could be an abstract declarator for a function, or declare x with
2834      parentheses.  The proper resolution of this ambiguity needs
2835      documenting.  At present we follow an accident of the old
2836      parser's implementation, whereby the first parameter must have
2837      some declaration specifiers other than just attributes.  Thus as
2838      a parameter declaration it is treated as a parenthesized
2839      parameter named x, and as an abstract declarator it is
2840      rejected.
2841
2842      ??? Also following the old parser, attributes inside an empty
2843      parameter list are ignored, making it a list not yielding a
2844      prototype, rather than giving an error or making it have one
2845      parameter with implicit type int.
2846
2847      ??? Also following the old parser, typedef names may be
2848      redeclared in declarators, but not Objective-C class names.  */
2849
2850   if (kind != C_DTR_ABSTRACT
2851       && c_parser_next_token_is (parser, CPP_NAME)
2852       && ((type_seen_p
2853            && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2854                || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2855           || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2856     {
2857       struct c_declarator *inner
2858         = build_id_declarator (c_parser_peek_token (parser)->value);
2859       *seen_id = true;
2860       inner->id_loc = c_parser_peek_token (parser)->location;
2861       c_parser_consume_token (parser);
2862       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2863     }
2864
2865   if (kind != C_DTR_NORMAL
2866       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2867     {
2868       struct c_declarator *inner = build_id_declarator (NULL_TREE);
2869       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2870     }
2871
2872   /* Either we are at the end of an abstract declarator, or we have
2873      parentheses.  */
2874
2875   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2876     {
2877       tree attrs;
2878       struct c_declarator *inner;
2879       c_parser_consume_token (parser);
2880       attrs = c_parser_attributes (parser);
2881       if (kind != C_DTR_NORMAL
2882           && (c_parser_next_token_starts_declspecs (parser)
2883               || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2884         {
2885           struct c_arg_info *args
2886             = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2887                                          attrs);
2888           if (args == NULL)
2889             return NULL;
2890           else
2891             {
2892               inner
2893                 = build_function_declarator (args,
2894                                              build_id_declarator (NULL_TREE));
2895               return c_parser_direct_declarator_inner (parser, *seen_id,
2896                                                        inner);
2897             }
2898         }
2899       /* A parenthesized declarator.  */
2900       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2901       if (inner != NULL && attrs != NULL)
2902         inner = build_attrs_declarator (attrs, inner);
2903       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2904         {
2905           c_parser_consume_token (parser);
2906           if (inner == NULL)
2907             return NULL;
2908           else
2909             return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2910         }
2911       else
2912         {
2913           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2914                                      "expected %<)%>");
2915           return NULL;
2916         }
2917     }
2918   else
2919     {
2920       if (kind == C_DTR_NORMAL)
2921         {
2922           c_parser_error (parser, "expected identifier or %<(%>");
2923           return NULL;
2924         }
2925       else
2926         return build_id_declarator (NULL_TREE);
2927     }
2928 }
2929
2930 /* Parse part of a direct declarator or direct abstract declarator,
2931    given that some (in INNER) has already been parsed; ID_PRESENT is
2932    true if an identifier is present, false for an abstract
2933    declarator.  */
2934
2935 static struct c_declarator *
2936 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2937                                   struct c_declarator *inner)
2938 {
2939   /* Parse a sequence of array declarators and parameter lists.  */
2940   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2941     {
2942       location_t brace_loc = c_parser_peek_token (parser)->location;
2943       struct c_declarator *declarator;
2944       struct c_declspecs *quals_attrs = build_null_declspecs ();
2945       bool static_seen;
2946       bool star_seen;
2947       tree dimen;
2948       c_parser_consume_token (parser);
2949       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2950       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2951       if (static_seen)
2952         c_parser_consume_token (parser);
2953       if (static_seen && !quals_attrs->declspecs_seen_p)
2954         c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2955       if (!quals_attrs->declspecs_seen_p)
2956         quals_attrs = NULL;
2957       /* If "static" is present, there must be an array dimension.
2958          Otherwise, there may be a dimension, "*", or no
2959          dimension.  */
2960       if (static_seen)
2961         {
2962           star_seen = false;
2963           dimen = c_parser_expr_no_commas (parser, NULL).value;
2964         }
2965       else
2966         {
2967           if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2968             {
2969               dimen = NULL_TREE;
2970               star_seen = false;
2971             }
2972           else if (c_parser_next_token_is (parser, CPP_MULT))
2973             {
2974               if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2975                 {
2976                   dimen = NULL_TREE;
2977                   star_seen = true;
2978                   c_parser_consume_token (parser);
2979                 }
2980               else
2981                 {
2982                   star_seen = false;
2983                   dimen = c_parser_expr_no_commas (parser, NULL).value;
2984                 }
2985             }
2986           else
2987             {
2988               star_seen = false;
2989               dimen = c_parser_expr_no_commas (parser, NULL).value;
2990             }
2991         }
2992       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2993         c_parser_consume_token (parser);
2994       else
2995         {
2996           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2997                                      "expected %<]%>");
2998           return NULL;
2999         }
3000       if (dimen)
3001         mark_exp_read (dimen);
3002       declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3003                                            static_seen, star_seen);
3004       if (declarator == NULL)
3005         return NULL;
3006       inner = set_array_declarator_inner (declarator, inner);
3007       return c_parser_direct_declarator_inner (parser, id_present, inner);
3008     }
3009   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3010     {
3011       tree attrs;
3012       struct c_arg_info *args;
3013       c_parser_consume_token (parser);
3014       attrs = c_parser_attributes (parser);
3015       args = c_parser_parms_declarator (parser, id_present, attrs);
3016       if (args == NULL)
3017         return NULL;
3018       else
3019         {
3020           inner = build_function_declarator (args, inner);
3021           return c_parser_direct_declarator_inner (parser, id_present, inner);
3022         }
3023     }
3024   return inner;
3025 }
3026
3027 /* Parse a parameter list or identifier list, including the closing
3028    parenthesis but not the opening one.  ATTRS are the attributes at
3029    the start of the list.  ID_LIST_OK is true if an identifier list is
3030    acceptable; such a list must not have attributes at the start.  */
3031
3032 static struct c_arg_info *
3033 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3034 {
3035   push_scope ();
3036   declare_parm_level ();
3037   /* If the list starts with an identifier, it is an identifier list.
3038      Otherwise, it is either a prototype list or an empty list.  */
3039   if (id_list_ok
3040       && !attrs
3041       && c_parser_next_token_is (parser, CPP_NAME)
3042       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3043       
3044       /* Look ahead to detect typos in type names.  */
3045       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3046       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3047       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3048       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3049     {
3050       tree list = NULL_TREE, *nextp = &list;
3051       while (c_parser_next_token_is (parser, CPP_NAME)
3052              && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3053         {
3054           *nextp = build_tree_list (NULL_TREE,
3055                                     c_parser_peek_token (parser)->value);
3056           nextp = & TREE_CHAIN (*nextp);
3057           c_parser_consume_token (parser);
3058           if (c_parser_next_token_is_not (parser, CPP_COMMA))
3059             break;
3060           c_parser_consume_token (parser);
3061           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3062             {
3063               c_parser_error (parser, "expected identifier");
3064               break;
3065             }
3066         }
3067       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3068         {
3069           struct c_arg_info *ret = build_arg_info ();
3070           ret->types = list;
3071           c_parser_consume_token (parser);
3072           pop_scope ();
3073           return ret;
3074         }
3075       else
3076         {
3077           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3078                                      "expected %<)%>");
3079           pop_scope ();
3080           return NULL;
3081         }
3082     }
3083   else
3084     {
3085       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
3086       pop_scope ();
3087       return ret;
3088     }
3089 }
3090
3091 /* Parse a parameter list (possibly empty), including the closing
3092    parenthesis but not the opening one.  ATTRS are the attributes at
3093    the start of the list.  */
3094
3095 static struct c_arg_info *
3096 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
3097 {
3098   bool bad_parm = false;
3099   /* ??? Following the old parser, forward parameter declarations may
3100      use abstract declarators, and if no real parameter declarations
3101      follow the forward declarations then this is not diagnosed.  Also
3102      note as above that attributes are ignored as the only contents of
3103      the parentheses, or as the only contents after forward
3104      declarations.  */
3105   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3106     {
3107       struct c_arg_info *ret = build_arg_info ();
3108       c_parser_consume_token (parser);
3109       return ret;
3110     }
3111   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3112     {
3113       struct c_arg_info *ret = build_arg_info ();
3114       /* Suppress -Wold-style-definition for this case.  */
3115       ret->types = error_mark_node;
3116       error_at (c_parser_peek_token (parser)->location,
3117                 "ISO C requires a named argument before %<...%>");
3118       c_parser_consume_token (parser);
3119       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3120         {
3121           c_parser_consume_token (parser);
3122           return ret;
3123         }
3124       else
3125         {
3126           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3127                                      "expected %<)%>");
3128           return NULL;
3129         }
3130     }
3131   /* Nonempty list of parameters, either terminated with semicolon
3132      (forward declarations; recurse) or with close parenthesis (normal
3133      function) or with ", ... )" (variadic function).  */
3134   while (true)
3135     {
3136       /* Parse a parameter.  */
3137       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3138       attrs = NULL_TREE;
3139       if (parm == NULL)
3140         bad_parm = true;
3141       else
3142         push_parm_decl (parm);
3143       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3144         {
3145           tree new_attrs;
3146           c_parser_consume_token (parser);
3147           mark_forward_parm_decls ();
3148           new_attrs = c_parser_attributes (parser);
3149           return c_parser_parms_list_declarator (parser, new_attrs);
3150         }
3151       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3152         {
3153           c_parser_consume_token (parser);
3154           if (bad_parm)
3155             {
3156               get_pending_sizes ();
3157               return NULL;
3158             }
3159           else
3160             return get_parm_info (false);
3161         }
3162       if (!c_parser_require (parser, CPP_COMMA,
3163                              "expected %<;%>, %<,%> or %<)%>"))
3164         {
3165           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3166           get_pending_sizes ();
3167           return NULL;
3168         }
3169       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3170         {
3171           c_parser_consume_token (parser);
3172           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3173             {
3174               c_parser_consume_token (parser);
3175               if (bad_parm)
3176                 {
3177                   get_pending_sizes ();
3178                   return NULL;
3179                 }
3180               else
3181                 return get_parm_info (true);
3182             }
3183           else
3184             {
3185               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3186                                          "expected %<)%>");
3187               get_pending_sizes ();
3188               return NULL;
3189             }
3190         }
3191     }
3192 }
3193
3194 /* Parse a parameter declaration.  ATTRS are the attributes at the
3195    start of the declaration if it is the first parameter.  */
3196
3197 static struct c_parm *
3198 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3199 {
3200   struct c_declspecs *specs;
3201   struct c_declarator *declarator;
3202   tree prefix_attrs;
3203   tree postfix_attrs = NULL_TREE;
3204   bool dummy = false;
3205   if (!c_parser_next_token_starts_declspecs (parser))
3206     {
3207       c_token *token = c_parser_peek_token (parser);
3208       if (parser->error)
3209         return NULL;
3210       c_parser_set_source_position_from_token (token);
3211       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3212         {
3213           error ("unknown type name %qE", token->value);
3214           parser->error = true;
3215         }
3216       /* ??? In some Objective-C cases '...' isn't applicable so there
3217          should be a different message.  */
3218       else
3219         c_parser_error (parser,
3220                         "expected declaration specifiers or %<...%>");
3221       c_parser_skip_to_end_of_parameter (parser);
3222       return NULL;
3223     }
3224   specs = build_null_declspecs ();
3225   if (attrs)
3226     {
3227       declspecs_add_attrs (specs, attrs);
3228       attrs = NULL_TREE;
3229     }
3230   c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3231   finish_declspecs (specs);
3232   pending_xref_error ();
3233   prefix_attrs = specs->attrs;
3234   specs->attrs = NULL_TREE;
3235   declarator = c_parser_declarator (parser,
3236                                     specs->typespec_kind != ctsk_none,
3237                                     C_DTR_PARM, &dummy);
3238   if (declarator == NULL)
3239     {
3240       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3241       return NULL;
3242     }
3243   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3244     postfix_attrs = c_parser_attributes (parser);
3245   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3246                        declarator);
3247 }
3248
3249 /* Parse a string literal in an asm expression.  It should not be
3250    translated, and wide string literals are an error although
3251    permitted by the syntax.  This is a GNU extension.
3252
3253    asm-string-literal:
3254      string-literal
3255
3256    ??? At present, following the old parser, the caller needs to have
3257    set lex_untranslated_string to 1.  It would be better to follow the
3258    C++ parser rather than using this kludge.  */
3259
3260 static tree
3261 c_parser_asm_string_literal (c_parser *parser)
3262 {
3263   tree str;
3264   if (c_parser_next_token_is (parser, CPP_STRING))
3265     {
3266       str = c_parser_peek_token (parser)->value;
3267       c_parser_consume_token (parser);
3268     }
3269   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3270     {
3271       error_at (c_parser_peek_token (parser)->location,
3272                 "wide string literal in %<asm%>");
3273       str = build_string (1, "");
3274       c_parser_consume_token (parser);
3275     }
3276   else
3277     {
3278       c_parser_error (parser, "expected string literal");
3279       str = NULL_TREE;
3280     }
3281   return str;
3282 }
3283
3284 /* Parse a simple asm expression.  This is used in restricted
3285    contexts, where a full expression with inputs and outputs does not
3286    make sense.  This is a GNU extension.
3287
3288    simple-asm-expr:
3289      asm ( asm-string-literal )
3290 */
3291
3292 static tree
3293 c_parser_simple_asm_expr (c_parser *parser)
3294 {
3295   tree str;
3296   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3297   /* ??? Follow the C++ parser rather than using the
3298      lex_untranslated_string kludge.  */
3299   parser->lex_untranslated_string = true;
3300   c_parser_consume_token (parser);
3301   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3302     {
3303       parser->lex_untranslated_string = false;
3304       return NULL_TREE;
3305     }
3306   str = c_parser_asm_string_literal (parser);
3307   parser->lex_untranslated_string = false;
3308   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3309     {
3310       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3311       return NULL_TREE;
3312     }
3313   return str;
3314 }
3315
3316 /* Parse (possibly empty) attributes.  This is a GNU extension.
3317
3318    attributes:
3319      empty
3320      attributes attribute
3321
3322    attribute:
3323      __attribute__ ( ( attribute-list ) )
3324
3325    attribute-list:
3326      attrib
3327      attribute_list , attrib
3328
3329    attrib:
3330      empty
3331      any-word
3332      any-word ( identifier )
3333      any-word ( identifier , nonempty-expr-list )
3334      any-word ( expr-list )
3335
3336    where the "identifier" must not be declared as a type, and
3337    "any-word" may be any identifier (including one declared as a
3338    type), a reserved word storage class specifier, type specifier or
3339    type qualifier.  ??? This still leaves out most reserved keywords
3340    (following the old parser), shouldn't we include them, and why not
3341    allow identifiers declared as types to start the arguments?  */
3342
3343 static tree
3344 c_parser_attributes (c_parser *parser)
3345 {
3346   tree attrs = NULL_TREE;
3347   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3348     {
3349       /* ??? Follow the C++ parser rather than using the
3350          lex_untranslated_string kludge.  */
3351       parser->lex_untranslated_string = true;
3352       c_parser_consume_token (parser);
3353       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3354         {
3355           parser->lex_untranslated_string = false;
3356           return attrs;
3357         }
3358       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3359         {
3360           parser->lex_untranslated_string = false;
3361           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3362           return attrs;
3363         }
3364       /* Parse the attribute list.  */
3365       while (c_parser_next_token_is (parser, CPP_COMMA)
3366              || c_parser_next_token_is (parser, CPP_NAME)
3367              || c_parser_next_token_is (parser, CPP_KEYWORD))
3368         {
3369           tree attr, attr_name, attr_args;
3370           VEC(tree,gc) *expr_list;
3371           if (c_parser_next_token_is (parser, CPP_COMMA))
3372             {
3373               c_parser_consume_token (parser);
3374               continue;
3375             }
3376           if (c_parser_next_token_is (parser, CPP_KEYWORD))
3377             {
3378               /* ??? See comment above about what keywords are
3379                  accepted here.  */
3380               bool ok;
3381               switch (c_parser_peek_token (parser)->keyword)
3382                 {
3383                 case RID_STATIC:
3384                 case RID_UNSIGNED:
3385                 case RID_LONG:
3386                 case RID_INT128:
3387                 case RID_CONST:
3388                 case RID_EXTERN:
3389                 case RID_REGISTER:
3390                 case RID_TYPEDEF:
3391                 case RID_SHORT:
3392                 case RID_INLINE:
3393                 case RID_VOLATILE:
3394                 case RID_SIGNED:
3395                 case RID_AUTO:
3396                 case RID_RESTRICT:
3397                 case RID_COMPLEX:
3398                 case RID_THREAD:
3399                 case RID_INT:
3400                 case RID_CHAR:
3401                 case RID_FLOAT:
3402                 case RID_DOUBLE:
3403                 case RID_VOID:
3404                 case RID_DFLOAT32:
3405                 case RID_DFLOAT64:
3406                 case RID_DFLOAT128:
3407                 case RID_BOOL:
3408                 case RID_FRACT:
3409                 case RID_ACCUM:
3410                 case RID_SAT:
3411                   ok = true;
3412                   break;
3413                 default:
3414                   ok = false;
3415                   break;
3416                 }
3417               if (!ok)
3418                 break;
3419               /* Accept __attribute__((__const)) as __attribute__((const))
3420                  etc.  */
3421               attr_name
3422                 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3423             }
3424           else
3425             attr_name = c_parser_peek_token (parser)->value;
3426           c_parser_consume_token (parser);
3427           if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3428             {
3429               attr = build_tree_list (attr_name, NULL_TREE);
3430               attrs = chainon (attrs, attr);
3431               continue;
3432             }
3433           c_parser_consume_token (parser);
3434           /* Parse the attribute contents.  If they start with an
3435              identifier which is followed by a comma or close
3436              parenthesis, then the arguments start with that
3437              identifier; otherwise they are an expression list.  
3438              In objective-c the identifier may be a classname.  */
3439           if (c_parser_next_token_is (parser, CPP_NAME)
3440               && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3441                   || (c_dialect_objc () 
3442                       && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3443               && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3444                   || (c_parser_peek_2nd_token (parser)->type
3445                       == CPP_CLOSE_PAREN)))
3446             {
3447               tree arg1 = c_parser_peek_token (parser)->value;
3448               c_parser_consume_token (parser);
3449               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3450                 attr_args = build_tree_list (NULL_TREE, arg1);
3451               else
3452                 {
3453                   tree tree_list;
3454                   c_parser_consume_token (parser);
3455                   expr_list = c_parser_expr_list (parser, false, true, NULL);
3456                   tree_list = build_tree_list_vec (expr_list);
3457                   attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3458                   release_tree_vector (expr_list);
3459                 }
3460             }
3461           else
3462             {
3463               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3464                 attr_args = NULL_TREE;
3465               else
3466                 {
3467                   expr_list = c_parser_expr_list (parser, false, true, NULL);
3468                   attr_args = build_tree_list_vec (expr_list);
3469                   release_tree_vector (expr_list);
3470                 }
3471             }
3472           attr = build_tree_list (attr_name, attr_args);
3473           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3474             c_parser_consume_token (parser);
3475           else
3476             {
3477               parser->lex_untranslated_string = false;
3478               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3479                                          "expected %<)%>");
3480               return attrs;
3481             }
3482           attrs = chainon (attrs, attr);
3483         }
3484       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3485         c_parser_consume_token (parser);
3486       else
3487         {
3488           parser->lex_untranslated_string = false;
3489           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3490                                      "expected %<)%>");
3491           return attrs;
3492         }
3493       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3494         c_parser_consume_token (parser);
3495       else
3496         {
3497           parser->lex_untranslated_string = false;
3498           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3499                                      "expected %<)%>");
3500           return attrs;
3501         }
3502       parser->lex_untranslated_string = false;
3503     }
3504   return attrs;
3505 }
3506
3507 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3508
3509    type-name:
3510      specifier-qualifier-list abstract-declarator[opt]
3511 */
3512
3513 static struct c_type_name *
3514 c_parser_type_name (c_parser *parser)
3515 {
3516   struct c_declspecs *specs = build_null_declspecs ();
3517   struct c_declarator *declarator;
3518   struct c_type_name *ret;
3519   bool dummy = false;
3520   c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3521   if (!specs->declspecs_seen_p)
3522     {
3523       c_parser_error (parser, "expected specifier-qualifier-list");
3524       return NULL;
3525     }
3526   if (specs->type != error_mark_node)
3527     {
3528       pending_xref_error ();
3529       finish_declspecs (specs);
3530     }
3531   declarator = c_parser_declarator (parser,
3532                                     specs->typespec_kind != ctsk_none,
3533                                     C_DTR_ABSTRACT, &dummy);
3534   if (declarator == NULL)
3535     return NULL;
3536   ret = XOBNEW (&parser_obstack, struct c_type_name);
3537   ret->specs = specs;
3538   ret->declarator = declarator;
3539   return ret;
3540 }
3541
3542 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3543
3544    initializer:
3545      assignment-expression
3546      { initializer-list }
3547      { initializer-list , }
3548
3549    initializer-list:
3550      designation[opt] initializer
3551      initializer-list , designation[opt] initializer
3552
3553    designation:
3554      designator-list =
3555
3556    designator-list:
3557      designator
3558      designator-list designator
3559
3560    designator:
3561      array-designator
3562      . identifier
3563
3564    array-designator:
3565      [ constant-expression ]
3566
3567    GNU extensions:
3568
3569    initializer:
3570      { }
3571
3572    designation:
3573      array-designator
3574      identifier :
3575
3576    array-designator:
3577      [ constant-expression ... constant-expression ]
3578
3579    Any expression without commas is accepted in the syntax for the
3580    constant-expressions, with non-constant expressions rejected later.
3581
3582    This function is only used for top-level initializers; for nested
3583    ones, see c_parser_initval.  */
3584
3585 static struct c_expr
3586 c_parser_initializer (c_parser *parser)
3587 {
3588   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3589     return c_parser_braced_init (parser, NULL_TREE, false);
3590   else
3591     {
3592       struct c_expr ret;
3593       location_t loc = c_parser_peek_token (parser)->location;
3594       ret = c_parser_expr_no_commas (parser, NULL);
3595       if (TREE_CODE (ret.value) != STRING_CST
3596           && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3597         ret = default_function_array_read_conversion (loc, ret);
3598       return ret;
3599     }
3600 }
3601
3602 /* Parse a braced initializer list.  TYPE is the type specified for a
3603    compound literal, and NULL_TREE for other initializers and for
3604    nested braced lists.  NESTED_P is true for nested braced lists,
3605    false for the list of a compound literal or the list that is the
3606    top-level initializer in a declaration.  */
3607
3608 static struct c_expr
3609 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3610 {
3611   struct c_expr ret;
3612   struct obstack braced_init_obstack;
3613   location_t brace_loc = c_parser_peek_token (parser)->location;
3614   gcc_obstack_init (&braced_init_obstack);
3615   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3616   c_parser_consume_token (parser);
3617   if (nested_p)
3618     push_init_level (0, &braced_init_obstack);
3619   else
3620     really_start_incremental_init (type);
3621   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3622     {
3623       pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3624     }
3625   else
3626     {
3627       /* Parse a non-empty initializer list, possibly with a trailing
3628          comma.  */
3629       while (true)
3630         {
3631           c_parser_initelt (parser, &braced_init_obstack);
3632           if (parser->error)
3633             break;
3634           if (c_parser_next_token_is (parser, CPP_COMMA))
3635             c_parser_consume_token (parser);
3636           else
3637             break;
3638           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3639             break;
3640         }
3641     }
3642   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3643     {
3644       ret.value = error_mark_node;
3645       ret.original_code = ERROR_MARK;
3646       ret.original_type = NULL;
3647       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3648       pop_init_level (0, &braced_init_obstack);
3649       obstack_free (&braced_init_obstack, NULL);
3650       return ret;
3651     }
3652   c_parser_consume_token (parser);
3653   ret = pop_init_level (0, &braced_init_obstack);
3654   obstack_free (&braced_init_obstack, NULL);
3655   return ret;
3656 }
3657
3658 /* Parse a nested initializer, including designators.  */
3659
3660 static void
3661 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3662 {
3663   /* Parse any designator or designator list.  A single array
3664      designator may have the subsequent "=" omitted in GNU C, but a
3665      longer list or a structure member designator may not.  */
3666   if (c_parser_next_token_is (parser, CPP_NAME)
3667       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3668     {
3669       /* Old-style structure member designator.  */
3670       set_init_label (c_parser_peek_token (parser)->value,
3671                       braced_init_obstack);
3672       /* Use the colon as the error location.  */
3673       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3674                "obsolete use of designated initializer with %<:%>");
3675       c_parser_consume_token (parser);
3676       c_parser_consume_token (parser);
3677     }
3678   else
3679     {
3680       /* des_seen is 0 if there have been no designators, 1 if there
3681          has been a single array designator and 2 otherwise.  */
3682       int des_seen = 0;
3683       /* Location of a designator.  */
3684       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3685       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3686              || c_parser_next_token_is (parser, CPP_DOT))
3687         {
3688           int des_prev = des_seen;
3689           if (!des_seen)
3690             des_loc = c_parser_peek_token (parser)->location;
3691           if (des_seen < 2)
3692             des_seen++;
3693           if (c_parser_next_token_is (parser, CPP_DOT))
3694             {
3695               des_seen = 2;
3696               c_parser_consume_token (parser);
3697               if (c_parser_next_token_is (parser, CPP_NAME))
3698                 {
3699                   set_init_label (c_parser_peek_token (parser)->value,
3700                                   braced_init_obstack);
3701                   c_parser_consume_token (parser);
3702                 }
3703               else
3704                 {
3705                   struct c_expr init;
3706                   init.value = error_mark_node;
3707                   init.original_code = ERROR_MARK;
3708                   init.original_type = NULL;
3709                   c_parser_error (parser, "expected identifier");
3710                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3711                   process_init_element (init, false, braced_init_obstack);
3712                   return;
3713                 }
3714             }
3715           else
3716             {
3717               tree first, second;
3718               location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3719               /* ??? Following the old parser, [ objc-receiver
3720                  objc-message-args ] is accepted as an initializer,
3721                  being distinguished from a designator by what follows
3722                  the first assignment expression inside the square
3723                  brackets, but after a first array designator a
3724                  subsequent square bracket is for Objective-C taken to
3725                  start an expression, using the obsolete form of
3726                  designated initializer without '=', rather than
3727                  possibly being a second level of designation: in LALR
3728                  terms, the '[' is shifted rather than reducing
3729                  designator to designator-list.  */
3730               if (des_prev == 1 && c_dialect_objc ())
3731                 {
3732                   des_seen = des_prev;
3733                   break;
3734                 }
3735               if (des_prev == 0 && c_dialect_objc ())
3736                 {
3737                   /* This might be an array designator or an
3738                      Objective-C message expression.  If the former,
3739                      continue parsing here; if the latter, parse the
3740                      remainder of the initializer given the starting
3741                      primary-expression.  ??? It might make sense to
3742                      distinguish when des_prev == 1 as well; see
3743                      previous comment.  */
3744                   tree rec, args;
3745                   struct c_expr mexpr;
3746                   c_parser_consume_token (parser);
3747                   if (c_parser_peek_token (parser)->type == CPP_NAME
3748                       && ((c_parser_peek_token (parser)->id_kind
3749                            == C_ID_TYPENAME)
3750                           || (c_parser_peek_token (parser)->id_kind
3751                               == C_ID_CLASSNAME)))
3752                     {
3753                       /* Type name receiver.  */
3754                       tree id = c_parser_peek_token (parser)->value;
3755                       c_parser_consume_token (parser);
3756                       rec = objc_get_class_reference (id);
3757                       goto parse_message_args;
3758                     }
3759                   first = c_parser_expr_no_commas (parser, NULL).value;
3760                   mark_exp_read (first);
3761                   if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3762                       || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3763                     goto array_desig_after_first;
3764                   /* Expression receiver.  So far only one part
3765                      without commas has been parsed; there might be
3766                      more of the expression.  */
3767                   rec = first;
3768                   while (c_parser_next_token_is (parser, CPP_COMMA))
3769                     {
3770                       struct c_expr next;
3771                       location_t comma_loc, exp_loc;
3772                       comma_loc = c_parser_peek_token (parser)->location;
3773                       c_parser_consume_token (parser);
3774                       exp_loc = c_parser_peek_token (parser)->location;
3775                       next = c_parser_expr_no_commas (parser, NULL);
3776                       next = default_function_array_read_conversion (exp_loc,
3777                                                                      next);
3778                       rec = build_compound_expr (comma_loc, rec, next.value);
3779                     }
3780                 parse_message_args:
3781                   /* Now parse the objc-message-args.  */
3782                   args = c_parser_objc_message_args (parser);
3783                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3784                                              "expected %<]%>");
3785                   mexpr.value
3786                     = objc_build_message_expr (build_tree_list (rec, args));
3787                   mexpr.original_code = ERROR_MARK;
3788                   mexpr.original_type = NULL;
3789                   /* Now parse and process the remainder of the
3790                      initializer, starting with this message
3791                      expression as a primary-expression.  */
3792                   c_parser_initval (parser, &mexpr, braced_init_obstack);
3793                   return;
3794                 }
3795               c_parser_consume_token (parser);
3796               first = c_parser_expr_no_commas (parser, NULL).value;
3797               mark_exp_read (first);
3798             array_desig_after_first:
3799               if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3800                 {
3801                   ellipsis_loc = c_parser_peek_token (parser)->location;
3802                   c_parser_consume_token (parser);
3803                   second = c_parser_expr_no_commas (parser, NULL).value;
3804                   mark_exp_read (second);
3805                 }
3806               else
3807                 second = NULL_TREE;
3808               if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3809                 {
3810                   c_parser_consume_token (parser);
3811                   set_init_index (first, second, braced_init_obstack);
3812                   if (second)
3813                     pedwarn (ellipsis_loc, OPT_pedantic,
3814                              "ISO C forbids specifying range of elements to initialize");
3815                 }
3816               else
3817                 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3818                                            "expected %<]%>");
3819             }
3820         }
3821       if (des_seen >= 1)
3822         {
3823           if (c_parser_next_token_is (parser, CPP_EQ))
3824             {
3825               if (!flag_isoc99)
3826                 pedwarn (des_loc, OPT_pedantic,
3827                          "ISO C90 forbids specifying subobject to initialize");
3828               c_parser_consume_token (parser);
3829             }
3830           else
3831             {
3832               if (des_seen == 1)
3833                 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3834                          "obsolete use of designated initializer without %<=%>");
3835               else
3836                 {
3837                   struct c_expr init;
3838                   init.value = error_mark_node;
3839                   init.original_code = ERROR_MARK;
3840                   init.original_type = NULL;
3841                   c_parser_error (parser, "expected %<=%>");
3842                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3843                   process_init_element (init, false, braced_init_obstack);
3844                   return;
3845                 }
3846             }
3847         }
3848     }
3849   c_parser_initval (parser, NULL, braced_init_obstack);
3850 }
3851
3852 /* Parse a nested initializer; as c_parser_initializer but parses
3853    initializers within braced lists, after any designators have been
3854    applied.  If AFTER is not NULL then it is an Objective-C message
3855    expression which is the primary-expression starting the
3856    initializer.  */
3857
3858 static void
3859 c_parser_initval (c_parser *parser, struct c_expr *after,
3860                   struct obstack * braced_init_obstack)
3861 {
3862   struct c_expr init;
3863   gcc_assert (!after || c_dialect_objc ());
3864   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3865     init = c_parser_braced_init (parser, NULL_TREE, true);
3866   else
3867     {
3868       location_t loc = c_parser_peek_token (parser)->location;
3869       init = c_parser_expr_no_commas (parser, after);
3870       if (init.value != NULL_TREE
3871           && TREE_CODE (init.value) != STRING_CST
3872           && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3873         init = default_function_array_read_conversion (loc, init);
3874     }
3875   process_init_element (init, false, braced_init_obstack);
3876 }
3877
3878 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3879    C99 6.8.2).
3880
3881    compound-statement:
3882      { block-item-list[opt] }
3883      { label-declarations block-item-list }
3884
3885    block-item-list:
3886      block-item
3887      block-item-list block-item
3888
3889    block-item:
3890      nested-declaration
3891      statement
3892
3893    nested-declaration:
3894      declaration
3895
3896    GNU extensions:
3897
3898    compound-statement:
3899      { label-declarations block-item-list }
3900
3901    nested-declaration:
3902      __extension__ nested-declaration
3903      nested-function-definition
3904
3905    label-declarations:
3906      label-declaration
3907      label-declarations label-declaration
3908
3909    label-declaration:
3910      __label__ identifier-list ;
3911
3912    Allowing the mixing of declarations and code is new in C99.  The
3913    GNU syntax also permits (not shown above) labels at the end of
3914    compound statements, which yield an error.  We don't allow labels
3915    on declarations; this might seem like a natural extension, but
3916    there would be a conflict between attributes on the label and
3917    prefix attributes on the declaration.  ??? The syntax follows the
3918    old parser in requiring something after label declarations.
3919    Although they are erroneous if the labels declared aren't defined,
3920    is it useful for the syntax to be this way?
3921
3922    OpenMP:
3923
3924    block-item:
3925      openmp-directive
3926
3927    openmp-directive:
3928      barrier-directive
3929      flush-directive  */
3930
3931 static tree
3932 c_parser_compound_statement (c_parser *parser)
3933 {
3934   tree stmt;
3935   location_t brace_loc;
3936   brace_loc = c_parser_peek_token (parser)->location;
3937   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3938     {
3939       /* Ensure a scope is entered and left anyway to avoid confusion
3940          if we have just prepared to enter a function body.  */
3941       stmt = c_begin_compound_stmt (true);
3942       c_end_compound_stmt (brace_loc, stmt, true);
3943       return error_mark_node;
3944     }
3945   stmt = c_begin_compound_stmt (true);
3946   c_parser_compound_statement_nostart (parser);
3947   return c_end_compound_stmt (brace_loc, stmt, true);
3948 }
3949
3950 /* Parse a compound statement except for the opening brace.  This is
3951    used for parsing both compound statements and statement expressions
3952    (which follow different paths to handling the opening).  */
3953
3954 static void
3955 c_parser_compound_statement_nostart (c_parser *parser)
3956 {
3957   bool last_stmt = false;
3958   bool last_label = false;
3959   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3960   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3961   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3962     {
3963       c_parser_consume_token (parser);
3964       return;
3965     }
3966   mark_valid_location_for_stdc_pragma (true);
3967   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3968     {
3969       /* Read zero or more forward-declarations for labels that nested
3970          functions can jump to.  */
3971       mark_valid_location_for_stdc_pragma (false);
3972       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3973         {
3974           label_loc = c_parser_peek_token (parser)->location;
3975           c_parser_consume_token (parser);
3976           /* Any identifiers, including those declared as type names,
3977              are OK here.  */
3978           while (true)
3979             {
3980               tree label;
3981               if (c_parser_next_token_is_not (parser, CPP_NAME))
3982                 {
3983                   c_parser_error (parser, "expected identifier");
3984                   break;
3985                 }
3986               label
3987                 = declare_label (c_parser_peek_token (parser)->value);
3988               C_DECLARED_LABEL_FLAG (label) = 1;
3989               add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3990               c_parser_consume_token (parser);
3991               if (c_parser_next_token_is (parser, CPP_COMMA))
3992                 c_parser_consume_token (parser);
3993               else
3994                 break;
3995             }
3996           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3997         }
3998       pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3999     }
4000   /* We must now have at least one statement, label or declaration.  */
4001   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4002     {
4003       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4004       c_parser_error (parser, "expected declaration or statement");
4005       c_parser_consume_token (parser);
4006       return;
4007     }
4008   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4009     {
4010       location_t loc = c_parser_peek_token (parser)->location;
4011       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4012           || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4013           || (c_parser_next_token_is (parser, CPP_NAME)
4014               && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4015         {
4016           if (c_parser_next_token_is_keyword (parser, RID_CASE))
4017             label_loc = c_parser_peek_2nd_token (parser)->location;
4018           else
4019             label_loc = c_parser_peek_token (parser)->location;
4020           last_label = true;
4021           last_stmt = false;
4022           mark_valid_location_for_stdc_pragma (false);
4023           c_parser_label (parser);
4024         }
4025       else if (!last_label
4026                && c_parser_next_tokens_start_declaration (parser))
4027         {
4028           last_label = false;
4029           mark_valid_location_for_stdc_pragma (false);
4030           c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4031           if (last_stmt)
4032             pedwarn_c90 (loc,
4033                          (pedantic && !flag_isoc99)
4034                          ? OPT_pedantic
4035                          : OPT_Wdeclaration_after_statement,
4036                          "ISO C90 forbids mixed declarations and code");
4037           last_stmt = false;
4038         }
4039       else if (!last_label
4040                && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4041         {
4042           /* __extension__ can start a declaration, but is also an
4043              unary operator that can start an expression.  Consume all
4044              but the last of a possible series of __extension__ to
4045              determine which.  */
4046           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4047                  && (c_parser_peek_2nd_token (parser)->keyword
4048                      == RID_EXTENSION))
4049             c_parser_consume_token (parser);
4050           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4051             {
4052               int ext;
4053               ext = disable_extension_diagnostics ();
4054               c_parser_consume_token (parser);
4055               last_label = false;
4056               mark_valid_location_for_stdc_pragma (false);
4057               c_parser_declaration_or_fndef (parser, true, true, true, true,
4058                                              true, NULL);
4059               /* Following the old parser, __extension__ does not
4060                  disable this diagnostic.  */
4061               restore_extension_diagnostics (ext);
4062               if (last_stmt)
4063                 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4064                              ? OPT_pedantic
4065                              : OPT_Wdeclaration_after_statement,
4066                              "ISO C90 forbids mixed declarations and code");
4067               last_stmt = false;
4068             }
4069           else
4070             goto statement;
4071         }
4072       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4073         {
4074           /* External pragmas, and some omp pragmas, are not associated
4075              with regular c code, and so are not to be considered statements
4076              syntactically.  This ensures that the user doesn't put them
4077              places that would turn into syntax errors if the directive
4078              were ignored.  */
4079           if (c_parser_pragma (parser, pragma_compound))
4080             last_label = false, last_stmt = true;
4081         }
4082       else if (c_parser_next_token_is (parser, CPP_EOF))
4083         {
4084           mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4085           c_parser_error (parser, "expected declaration or statement");
4086           return;
4087         }
4088       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4089         {
4090           if (parser->in_if_block)
4091             {
4092               mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4093               error_at (loc, """expected %<}%> before %<else%>");
4094               return;
4095             }
4096           else
4097             {
4098               error_at (loc, "%<else%> without a previous %<if%>");
4099               c_parser_consume_token (parser);
4100               continue;
4101             }
4102         }
4103       else
4104         {
4105         statement:
4106           last_label = false;
4107           last_stmt = true;
4108           mark_valid_location_for_stdc_pragma (false);
4109           c_parser_statement_after_labels (parser);
4110         }
4111
4112       parser->error = false;
4113     }
4114   if (last_label)
4115     error_at (label_loc, "label at end of compound statement");
4116   c_parser_consume_token (parser);
4117   /* Restore the value we started with.  */
4118   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4119 }
4120
4121 /* Parse a label (C90 6.6.1, C99 6.8.1).
4122
4123    label:
4124      identifier : attributes[opt]
4125      case constant-expression :
4126      default :
4127
4128    GNU extensions:
4129
4130    label:
4131      case constant-expression ... constant-expression :
4132
4133    The use of attributes on labels is a GNU extension.  The syntax in
4134    GNU C accepts any expressions without commas, non-constant
4135    expressions being rejected later.  */
4136
4137 static void
4138 c_parser_label (c_parser *parser)
4139 {
4140   location_t loc1 = c_parser_peek_token (parser)->location;
4141   tree label = NULL_TREE;
4142   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4143     {
4144       tree exp1, exp2;
4145       c_parser_consume_token (parser);
4146       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4147       if (c_parser_next_token_is (parser, CPP_COLON))
4148         {
4149           c_parser_consume_token (parser);
4150           label = do_case (loc1, exp1, NULL_TREE);
4151         }
4152       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4153         {
4154           c_parser_consume_token (parser);
4155           exp2 = c_parser_expr_no_commas (parser, NULL).value;
4156           if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4157             label = do_case (loc1, exp1, exp2);
4158         }
4159       else
4160         c_parser_error (parser, "expected %<:%> or %<...%>");
4161     }
4162   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4163     {
4164       c_parser_consume_token (parser);
4165       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4166         label = do_case (loc1, NULL_TREE, NULL_TREE);
4167     }
4168   else
4169     {
4170       tree name = c_parser_peek_token (parser)->value;
4171       tree tlab;
4172       tree attrs;
4173       location_t loc2 = c_parser_peek_token (parser)->location;
4174       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4175       c_parser_consume_token (parser);
4176       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4177       c_parser_consume_token (parser);
4178       attrs = c_parser_attributes (parser);
4179       tlab = define_label (loc2, name);
4180       if (tlab)
4181         {
4182           decl_attributes (&tlab, attrs, 0);
4183           label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4184         }
4185     }
4186   if (label)
4187     {
4188       if (c_parser_next_tokens_start_declaration (parser))
4189         {
4190           error_at (c_parser_peek_token (parser)->location,
4191                     "a label can only be part of a statement and "
4192                     "a declaration is not a statement");
4193           c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4194                                          /*static_assert_ok*/ true,
4195                                          /*nested*/ true, /*empty_ok*/ false,
4196                                          /*start_attr_ok*/ true, NULL);
4197         }
4198     }
4199 }
4200
4201 /* Parse a statement (C90 6.6, C99 6.8).
4202
4203    statement:
4204      labeled-statement
4205      compound-statement
4206      expression-statement
4207      selection-statement
4208      iteration-statement
4209      jump-statement
4210
4211    labeled-statement:
4212      label statement
4213
4214    expression-statement:
4215      expression[opt] ;
4216
4217    selection-statement:
4218      if-statement
4219      switch-statement
4220
4221    iteration-statement:
4222      while-statement
4223      do-statement
4224      for-statement
4225
4226    jump-statement:
4227      goto identifier ;
4228      continue ;
4229      break ;
4230      return expression[opt] ;
4231
4232    GNU extensions:
4233
4234    statement:
4235      asm-statement
4236
4237    jump-statement:
4238      goto * expression ;
4239
4240    Objective-C:
4241
4242    statement:
4243      objc-throw-statement
4244      objc-try-catch-statement
4245      objc-synchronized-statement
4246
4247    objc-throw-statement:
4248      @throw expression ;
4249      @throw ;
4250
4251    OpenMP:
4252
4253    statement:
4254      openmp-construct
4255
4256    openmp-construct:
4257      parallel-construct
4258      for-construct
4259      sections-construct
4260      single-construct
4261      parallel-for-construct
4262      parallel-sections-construct
4263      master-construct
4264      critical-construct
4265      atomic-construct
4266      ordered-construct
4267
4268    parallel-construct:
4269      parallel-directive structured-block
4270
4271    for-construct:
4272      for-directive iteration-statement
4273
4274    sections-construct:
4275      sections-directive section-scope
4276
4277    single-construct:
4278      single-directive structured-block
4279
4280    parallel-for-construct:
4281      parallel-for-directive iteration-statement
4282
4283    parallel-sections-construct:
4284      parallel-sections-directive section-scope
4285
4286    master-construct:
4287      master-directive structured-block
4288
4289    critical-construct:
4290      critical-directive structured-block
4291
4292    atomic-construct:
4293      atomic-directive expression-statement
4294
4295    ordered-construct:
4296      ordered-directive structured-block  */
4297
4298 static void
4299 c_parser_statement (c_parser *parser)
4300 {
4301   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4302          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4303          || (c_parser_next_token_is (parser, CPP_NAME)
4304              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4305     c_parser_label (parser);
4306   c_parser_statement_after_labels (parser);
4307 }
4308
4309 /* Parse a statement, other than a labeled statement.  */
4310
4311 static void
4312 c_parser_statement_after_labels (c_parser *parser)
4313 {
4314   location_t loc = c_parser_peek_token (parser)->location;
4315   tree stmt = NULL_TREE;
4316   bool in_if_block = parser->in_if_block;
4317   parser->in_if_block = false;
4318   switch (c_parser_peek_token (parser)->type)
4319     {
4320     case CPP_OPEN_BRACE:
4321       add_stmt (c_parser_compound_statement (parser));
4322       break;
4323     case CPP_KEYWORD:
4324       switch (c_parser_peek_token (parser)->keyword)
4325         {
4326         case RID_IF:
4327           c_parser_if_statement (parser);
4328           break;
4329         case RID_SWITCH:
4330           c_parser_switch_statement (parser);
4331           break;
4332         case RID_WHILE:
4333           c_parser_while_statement (parser);
4334           break;
4335         case RID_DO:
4336           c_parser_do_statement (parser);
4337           break;
4338         case RID_FOR:
4339           c_parser_for_statement (parser);
4340           break;
4341         case RID_GOTO:
4342           c_parser_consume_token (parser);
4343           if (c_parser_next_token_is (parser, CPP_NAME))
4344             {
4345               stmt = c_finish_goto_label (loc,
4346                                           c_parser_peek_token (parser)->value);
4347               c_parser_consume_token (parser);
4348             }
4349           else if (c_parser_next_token_is (parser, CPP_MULT))
4350             {
4351               tree val;
4352
4353               c_parser_consume_token (parser);
4354               val = c_parser_expression (parser).value;
4355               mark_exp_read (val);
4356               stmt = c_finish_goto_ptr (loc, val);
4357             }
4358           else
4359             c_parser_error (parser, "expected identifier or %<*%>");
4360           goto expect_semicolon;
4361         case RID_CONTINUE:
4362           c_parser_consume_token (parser);
4363           stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4364           goto expect_semicolon;
4365         case RID_BREAK:
4366           c_parser_consume_token (parser);
4367           stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4368           goto expect_semicolon;
4369         case RID_RETURN:
4370           c_parser_consume_token (parser);
4371           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4372             {
4373               stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4374               c_parser_consume_token (parser);
4375             }
4376           else
4377             {
4378               struct c_expr expr = c_parser_expression_conv (parser);
4379               mark_exp_read (expr.value);
4380               stmt = c_finish_return (loc, expr.value, expr.original_type);
4381               goto expect_semicolon;
4382             }
4383           break;
4384         case RID_ASM:
4385           stmt = c_parser_asm_statement (parser);
4386           break;
4387         case RID_AT_THROW:
4388           gcc_assert (c_dialect_objc ());
4389           c_parser_consume_token (parser);
4390           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4391             {
4392               stmt = objc_build_throw_stmt (loc, NULL_TREE);
4393               c_parser_consume_token (parser);
4394             }
4395           else
4396             {
4397               tree expr = c_parser_expression (parser).value;
4398               expr = c_fully_fold (expr, false, NULL);
4399               stmt = objc_build_throw_stmt (loc, expr);
4400               goto expect_semicolon;
4401             }
4402           break;
4403         case RID_AT_TRY:
4404           gcc_assert (c_dialect_objc ());
4405           c_parser_objc_try_catch_finally_statement (parser);
4406           break;
4407         case RID_AT_SYNCHRONIZED:
4408           gcc_assert (c_dialect_objc ());
4409           c_parser_objc_synchronized_statement (parser);
4410           break;
4411         default:
4412           goto expr_stmt;
4413         }
4414       break;
4415     case CPP_SEMICOLON:
4416       c_parser_consume_token (parser);
4417       break;
4418     case CPP_CLOSE_PAREN:
4419     case CPP_CLOSE_SQUARE:
4420       /* Avoid infinite loop in error recovery:
4421          c_parser_skip_until_found stops at a closing nesting
4422          delimiter without consuming it, but here we need to consume
4423          it to proceed further.  */
4424       c_parser_error (parser, "expected statement");
4425       c_parser_consume_token (parser);
4426       break;
4427     case CPP_PRAGMA:
4428       c_parser_pragma (parser, pragma_stmt);
4429       break;
4430     default:
4431     expr_stmt:
4432       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4433     expect_semicolon:
4434       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4435       break;
4436     }
4437   /* Two cases cannot and do not have line numbers associated: If stmt
4438      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4439      cannot hold line numbers.  But that's OK because the statement
4440      will either be changed to a MODIFY_EXPR during gimplification of
4441      the statement expr, or discarded.  If stmt was compound, but
4442      without new variables, we will have skipped the creation of a
4443      BIND and will have a bare STATEMENT_LIST.  But that's OK because
4444      (recursively) all of the component statements should already have
4445      line numbers assigned.  ??? Can we discard no-op statements
4446      earlier?  */
4447   if (CAN_HAVE_LOCATION_P (stmt)
4448       && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4449     SET_EXPR_LOCATION (stmt, loc);
4450
4451   parser->in_if_block = in_if_block;
4452 }
4453
4454 /* Parse the condition from an if, do, while or for statements.  */
4455
4456 static tree
4457 c_parser_condition (c_parser *parser)
4458 {
4459   location_t loc = c_parser_peek_token (parser)->location;
4460   tree cond;
4461   cond = c_parser_expression_conv (parser).value;
4462   cond = c_objc_common_truthvalue_conversion (loc, cond);
4463   cond = c_fully_fold (cond, false, NULL);
4464   if (warn_sequence_point)
4465     verify_sequence_points (cond);
4466   return cond;
4467 }
4468
4469 /* Parse a parenthesized condition from an if, do or while statement.
4470
4471    condition:
4472      ( expression )
4473 */
4474 static tree
4475 c_parser_paren_condition (c_parser *parser)
4476 {
4477   tree cond;
4478   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4479     return error_mark_node;
4480   cond = c_parser_condition (parser);
4481   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4482   return cond;
4483 }
4484
4485 /* Parse a statement which is a block in C99.  */
4486
4487 static tree
4488 c_parser_c99_block_statement (c_parser *parser)
4489 {
4490   tree block = c_begin_compound_stmt (flag_isoc99);
4491   location_t loc = c_parser_peek_token (parser)->location;
4492   c_parser_statement (parser);
4493   return c_end_compound_stmt (loc, block, flag_isoc99);
4494 }
4495
4496 /* Parse the body of an if statement.  This is just parsing a
4497    statement but (a) it is a block in C99, (b) we track whether the
4498    body is an if statement for the sake of -Wparentheses warnings, (c)
4499    we handle an empty body specially for the sake of -Wempty-body
4500    warnings, and (d) we call parser_compound_statement directly
4501    because c_parser_statement_after_labels resets
4502    parser->in_if_block.  */
4503
4504 static tree
4505 c_parser_if_body (c_parser *parser, bool *if_p)
4506 {
4507   tree block = c_begin_compound_stmt (flag_isoc99);
4508   location_t body_loc = c_parser_peek_token (parser)->location;
4509   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4510          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4511          || (c_parser_next_token_is (parser, CPP_NAME)
4512              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4513     c_parser_label (parser);
4514   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4515   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4516     {
4517       location_t loc = c_parser_peek_token (parser)->location;
4518       add_stmt (build_empty_stmt (loc));
4519       c_parser_consume_token (parser);
4520       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4521         warning_at (loc, OPT_Wempty_body,
4522                     "suggest braces around empty body in an %<if%> statement");
4523     }
4524   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4525     add_stmt (c_parser_compound_statement (parser));
4526   else
4527     c_parser_statement_after_labels (parser);
4528   return c_end_compound_stmt (body_loc, block, flag_isoc99);
4529 }
4530
4531 /* Parse the else body of an if statement.  This is just parsing a
4532    statement but (a) it is a block in C99, (b) we handle an empty body
4533    specially for the sake of -Wempty-body warnings.  */
4534
4535 static tree
4536 c_parser_else_body (c_parser *parser)
4537 {
4538   location_t else_loc = c_parser_peek_token (parser)->location;
4539   tree block = c_begin_compound_stmt (flag_isoc99);
4540   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4541          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4542          || (c_parser_next_token_is (parser, CPP_NAME)
4543              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4544     c_parser_label (parser);
4545   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4546     {
4547       location_t loc = c_parser_peek_token (parser)->location;
4548       warning_at (loc,
4549                   OPT_Wempty_body,
4550                  "suggest braces around empty body in an %<else%> statement");
4551       add_stmt (build_empty_stmt (loc));
4552       c_parser_consume_token (parser);
4553     }
4554   else
4555     c_parser_statement_after_labels (parser);
4556   return c_end_compound_stmt (else_loc, block, flag_isoc99);
4557 }
4558
4559 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4560
4561    if-statement:
4562      if ( expression ) statement
4563      if ( expression ) statement else statement
4564 */
4565
4566 static void
4567 c_parser_if_statement (c_parser *parser)
4568 {
4569   tree block;
4570   location_t loc;
4571   tree cond;
4572   bool first_if = false;
4573   tree first_body, second_body;
4574   bool in_if_block;
4575
4576   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4577   c_parser_consume_token (parser);
4578   block = c_begin_compound_stmt (flag_isoc99);
4579   loc = c_parser_peek_token (parser)->location;
4580   cond = c_parser_paren_condition (parser);
4581   in_if_block = parser->in_if_block;
4582   parser->in_if_block = true;
4583   first_body = c_parser_if_body (parser, &first_if);
4584   parser->in_if_block = in_if_block;
4585   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4586     {
4587       c_parser_consume_token (parser);
4588       second_body = c_parser_else_body (parser);
4589     }
4590   else
4591     second_body = NULL_TREE;
4592   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4593   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4594 }
4595
4596 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4597
4598    switch-statement:
4599      switch (expression) statement
4600 */
4601
4602 static void
4603 c_parser_switch_statement (c_parser *parser)
4604 {
4605   tree block, expr, body, save_break;
4606   location_t switch_loc = c_parser_peek_token (parser)->location;
4607   location_t switch_cond_loc;
4608   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4609   c_parser_consume_token (parser);
4610   block = c_begin_compound_stmt (flag_isoc99);
4611   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4612     {
4613       switch_cond_loc = c_parser_peek_token (parser)->location;
4614       expr = c_parser_expression (parser).value;
4615       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4616     }
4617   else
4618     {
4619       switch_cond_loc = UNKNOWN_LOCATION;
4620       expr = error_mark_node;
4621     }
4622   c_start_case (switch_loc, switch_cond_loc, expr);
4623   save_break = c_break_label;
4624   c_break_label = NULL_TREE;
4625   body = c_parser_c99_block_statement (parser);
4626   c_finish_case (body);
4627   if (c_break_label)
4628     {
4629       location_t here = c_parser_peek_token (parser)->location;
4630       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4631       SET_EXPR_LOCATION (t, here);
4632       add_stmt (t);
4633     }
4634   c_break_label = save_break;
4635   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4636 }
4637
4638 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4639
4640    while-statement:
4641       while (expression) statement
4642 */
4643
4644 static void
4645 c_parser_while_statement (c_parser *parser)
4646 {
4647   tree block, cond, body, save_break, save_cont;
4648   location_t loc;
4649   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4650   c_parser_consume_token (parser);
4651   block = c_begin_compound_stmt (flag_isoc99);
4652   loc = c_parser_peek_token (parser)->location;
4653   cond = c_parser_paren_condition (parser);
4654   save_break = c_break_label;
4655   c_break_label = NULL_TREE;
4656   save_cont = c_cont_label;
4657   c_cont_label = NULL_TREE;
4658   body = c_parser_c99_block_statement (parser);
4659   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4660   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4661   c_break_label = save_break;
4662   c_cont_label = save_cont;
4663 }
4664
4665 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4666
4667    do-statement:
4668      do statement while ( expression ) ;
4669 */
4670
4671 static void
4672 c_parser_do_statement (c_parser *parser)
4673 {
4674   tree block, cond, body, save_break, save_cont, new_break, new_cont;
4675   location_t loc;
4676   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4677   c_parser_consume_token (parser);
4678   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4679     warning_at (c_parser_peek_token (parser)->location,
4680                 OPT_Wempty_body,
4681                 "suggest braces around empty body in %<do%> statement");
4682   block = c_begin_compound_stmt (flag_isoc99);
4683   loc = c_parser_peek_token (parser)->location;
4684   save_break = c_break_label;
4685   c_break_label = NULL_TREE;
4686   save_cont = c_cont_label;
4687   c_cont_label = NULL_TREE;
4688   body = c_parser_c99_block_statement (parser);
4689   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4690   new_break = c_break_label;
4691   c_break_label = save_break;
4692   new_cont = c_cont_label;
4693   c_cont_label = save_cont;
4694   cond = c_parser_paren_condition (parser);
4695   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4696     c_parser_skip_to_end_of_block_or_statement (parser);
4697   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4698   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4699 }
4700
4701 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4702
4703    for-statement:
4704      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4705      for ( nested-declaration expression[opt] ; expression[opt] ) statement
4706
4707    The form with a declaration is new in C99.
4708
4709    ??? In accordance with the old parser, the declaration may be a
4710    nested function, which is then rejected in check_for_loop_decls,
4711    but does it make any sense for this to be included in the grammar?
4712    Note in particular that the nested function does not include a
4713    trailing ';', whereas the "declaration" production includes one.
4714    Also, can we reject bad declarations earlier and cheaper than
4715    check_for_loop_decls?
4716
4717    In Objective-C, there are two additional variants:
4718
4719    foreach-statement:
4720      for ( expression in expresssion ) statement
4721      for ( declaration in expression ) statement
4722
4723    This is inconsistent with C, because the second variant is allowed
4724    even if c99 is not enabled.
4725
4726    The rest of the comment documents these Objective-C foreach-statement.
4727
4728    Here is the canonical example of the first variant:
4729     for (object in array)    { do something with object }
4730    we call the first expression ("object") the "object_expression" and 
4731    the second expression ("array") the "collection_expression".
4732    object_expression must be an lvalue of type "id" (a generic Objective-C
4733    object) because the loop works by assigning to object_expression the
4734    various objects from the collection_expression.  collection_expression
4735    must evaluate to something of type "id" which responds to the method
4736    countByEnumeratingWithState:objects:count:.
4737
4738    The canonical example of the second variant is:
4739     for (id object in array)    { do something with object }
4740    which is completely equivalent to
4741     {
4742       id object;
4743       for (object in array) { do something with object }
4744     }
4745    Note that initizializing 'object' in some way (eg, "for ((object =
4746    xxx) in array) { do something with object }") is possibly
4747    technically valid, but completely pointless as 'object' will be
4748    assigned to something else as soon as the loop starts.  We should
4749    most likely reject it (TODO).
4750
4751    The beginning of the Objective-C foreach-statement looks exactly
4752    like the beginning of the for-statement, and we can tell it is a
4753    foreach-statement only because the initial declaration or
4754    expression is terminated by 'in' instead of ';'.
4755 */
4756
4757 static void
4758 c_parser_for_statement (c_parser *parser)
4759 {
4760   tree block, cond, incr, save_break, save_cont, body;
4761   /* The following are only used when parsing an ObjC foreach statement.  */
4762   tree object_expression, collection_expression;
4763   location_t loc = c_parser_peek_token (parser)->location;
4764   location_t for_loc = c_parser_peek_token (parser)->location;
4765   bool is_foreach_statement = false;
4766   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4767   c_parser_consume_token (parser);
4768   /* Open a compound statement in Objective-C as well, just in case this is
4769      as foreach expression.  */
4770   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4771   cond = error_mark_node;
4772   incr = error_mark_node;
4773   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4774     {
4775       /* Parse the initialization declaration or expression.  */
4776       object_expression = error_mark_node;
4777       parser->objc_could_be_foreach_context = c_dialect_objc ();
4778       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4779         {
4780           parser->objc_could_be_foreach_context = false;
4781           c_parser_consume_token (parser);
4782           c_finish_expr_stmt (loc, NULL_TREE);
4783         }
4784       else if (c_parser_next_tokens_start_declaration (parser))
4785         {
4786           c_parser_declaration_or_fndef (parser, true, true, true, true, true, 
4787                                          &object_expression);
4788           parser->objc_could_be_foreach_context = false;
4789           
4790           if (c_parser_next_token_is_keyword (parser, RID_IN))
4791             {
4792               c_parser_consume_token (parser);
4793               is_foreach_statement = true;
4794               if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4795                 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4796             }
4797           else
4798             check_for_loop_decls (for_loc, flag_isoc99);
4799         }
4800       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4801         {
4802           /* __extension__ can start a declaration, but is also an
4803              unary operator that can start an expression.  Consume all
4804              but the last of a possible series of __extension__ to
4805              determine which.  */
4806           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4807                  && (c_parser_peek_2nd_token (parser)->keyword
4808                      == RID_EXTENSION))
4809             c_parser_consume_token (parser);
4810           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4811             {
4812               int ext;
4813               ext = disable_extension_diagnostics ();
4814               c_parser_consume_token (parser);
4815               c_parser_declaration_or_fndef (parser, true, true, true, true,
4816                                              true, &object_expression);
4817               parser->objc_could_be_foreach_context = false;
4818               
4819               restore_extension_diagnostics (ext);
4820               if (c_parser_next_token_is_keyword (parser, RID_IN))
4821                 {
4822                   c_parser_consume_token (parser);
4823                   is_foreach_statement = true;
4824                   if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4825                     c_parser_error (parser, "multiple iterating variables in fast enumeration");
4826                 }
4827               else
4828                 check_for_loop_decls (for_loc, flag_isoc99);
4829             }
4830           else
4831             goto init_expr;
4832         }
4833       else
4834         {
4835         init_expr:
4836           {
4837             tree init_expression;
4838             init_expression = c_parser_expression (parser).value;
4839             parser->objc_could_be_foreach_context = false;
4840             if (c_parser_next_token_is_keyword (parser, RID_IN))
4841               {
4842                 c_parser_consume_token (parser);
4843                 is_foreach_statement = true;
4844                 if (! lvalue_p (init_expression))
4845                   c_parser_error (parser, "invalid iterating variable in fast enumeration");
4846                 object_expression = c_fully_fold (init_expression, false, NULL);
4847               }
4848             else
4849               {
4850                 c_finish_expr_stmt (loc, init_expression);
4851                 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4852               }
4853           }
4854         }
4855       /* Parse the loop condition.  In the case of a foreach
4856          statement, there is no loop condition.  */
4857       gcc_assert (!parser->objc_could_be_foreach_context);
4858       if (!is_foreach_statement)
4859         {
4860           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4861             {
4862               c_parser_consume_token (parser);
4863               cond = NULL_TREE;
4864             }
4865           else
4866             {
4867               cond = c_parser_condition (parser);
4868               c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4869             }
4870         }
4871       /* Parse the increment expression (the third expression in a
4872          for-statement).  In the case of a foreach-statement, this is
4873          the expression that follows the 'in'.  */
4874       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4875         {
4876           if (is_foreach_statement)
4877             {
4878               c_parser_error (parser, "missing collection in fast enumeration");
4879               collection_expression = error_mark_node;
4880             }
4881           else
4882             incr = c_process_expr_stmt (loc, NULL_TREE);
4883         }
4884       else
4885         {
4886           if (is_foreach_statement)
4887             collection_expression = c_fully_fold (c_parser_expression (parser).value,
4888                                                   false, NULL);
4889           else
4890             incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4891         }
4892       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4893     }
4894   save_break = c_break_label;
4895   c_break_label = NULL_TREE;
4896   save_cont = c_cont_label;
4897   c_cont_label = NULL_TREE;
4898   body = c_parser_c99_block_statement (parser);
4899   if (is_foreach_statement)
4900     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4901   else
4902     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4903   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4904   c_break_label = save_break;
4905   c_cont_label = save_cont;
4906 }
4907
4908 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
4909    statement with inputs, outputs, clobbers, and volatile tag
4910    allowed.
4911
4912    asm-statement:
4913      asm type-qualifier[opt] ( asm-argument ) ;
4914      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4915
4916    asm-argument:
4917      asm-string-literal
4918      asm-string-literal : asm-operands[opt]
4919      asm-string-literal : asm-operands[opt] : asm-operands[opt]
4920      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4921
4922    asm-goto-argument:
4923      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4924        : asm-goto-operands
4925
4926    Qualifiers other than volatile are accepted in the syntax but
4927    warned for.  */
4928
4929 static tree
4930 c_parser_asm_statement (c_parser *parser)
4931 {
4932   tree quals, str, outputs, inputs, clobbers, labels, ret;
4933   bool simple, is_goto;
4934   location_t asm_loc = c_parser_peek_token (parser)->location;
4935   int section, nsections;
4936
4937   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4938   c_parser_consume_token (parser);
4939   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4940     {
4941       quals = c_parser_peek_token (parser)->value;
4942       c_parser_consume_token (parser);
4943     }
4944   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4945            || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4946     {
4947       warning_at (c_parser_peek_token (parser)->location,
4948                   0,
4949                   "%E qualifier ignored on asm",
4950                   c_parser_peek_token (parser)->value);
4951       quals = NULL_TREE;
4952       c_parser_consume_token (parser);
4953     }
4954   else
4955     quals = NULL_TREE;
4956
4957   is_goto = false;
4958   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4959     {
4960       c_parser_consume_token (parser);
4961       is_goto = true;
4962     }
4963
4964   /* ??? Follow the C++ parser rather than using the
4965      lex_untranslated_string kludge.  */
4966   parser->lex_untranslated_string = true;
4967   ret = NULL;
4968
4969   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4970     goto error;
4971
4972   str = c_parser_asm_string_literal (parser);
4973   if (str == NULL_TREE)
4974     goto error_close_paren;
4975
4976   simple = true;
4977   outputs = NULL_TREE;
4978   inputs = NULL_TREE;
4979   clobbers = NULL_TREE;
4980   labels = NULL_TREE;
4981
4982   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4983     goto done_asm;
4984
4985   /* Parse each colon-delimited section of operands.  */
4986   nsections = 3 + is_goto;
4987   for (section = 0; section < nsections; ++section)
4988     {
4989       if (!c_parser_require (parser, CPP_COLON,
4990                              is_goto
4991                              ? "expected %<:%>"
4992                              : "expected %<:%> or %<)%>"))
4993         goto error_close_paren;
4994
4995       /* Once past any colon, we're no longer a simple asm.  */
4996       simple = false;
4997
4998       if ((!c_parser_next_token_is (parser, CPP_COLON)
4999            && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5000           || section == 3)
5001         switch (section)
5002           {
5003           case 0:
5004             /* For asm goto, we don't allow output operands, but reserve
5005                the slot for a future extension that does allow them.  */
5006             if (!is_goto)
5007               outputs = c_parser_asm_operands (parser, false);
5008             break;
5009           case 1:
5010             inputs = c_parser_asm_operands (parser, true);
5011             break;
5012           case 2:
5013             clobbers = c_parser_asm_clobbers (parser);
5014             break;
5015           case 3:
5016             labels = c_parser_asm_goto_operands (parser);
5017             break;
5018           default:
5019             gcc_unreachable ();
5020           }
5021
5022       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5023         goto done_asm;
5024     }
5025
5026  done_asm:
5027   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5028     {
5029       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5030       goto error;
5031     }
5032
5033   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5034     c_parser_skip_to_end_of_block_or_statement (parser);
5035
5036   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5037                                                clobbers, labels, simple));
5038
5039  error:
5040   parser->lex_untranslated_string = false;
5041   return ret;
5042
5043  error_close_paren:
5044   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5045   goto error;
5046 }
5047
5048 /* Parse asm operands, a GNU extension.  If CONVERT_P (for inputs but
5049    not outputs), apply the default conversion of functions and arrays
5050    to pointers.
5051
5052    asm-operands:
5053      asm-operand
5054      asm-operands , asm-operand
5055
5056    asm-operand:
5057      asm-string-literal ( expression )
5058      [ identifier ] asm-string-literal ( expression )
5059 */
5060
5061 static tree
5062 c_parser_asm_operands (c_parser *parser, bool convert_p)
5063 {
5064   tree list = NULL_TREE;
5065   location_t loc;
5066   while (true)
5067     {
5068       tree name, str;
5069       struct c_expr expr;
5070       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5071         {
5072           c_parser_consume_token (parser);
5073           if (c_parser_next_token_is (parser, CPP_NAME))
5074             {
5075               tree id = c_parser_peek_token (parser)->value;
5076               c_parser_consume_token (parser);
5077               name = build_string (IDENTIFIER_LENGTH (id),
5078                                    IDENTIFIER_POINTER (id));
5079             }
5080           else
5081             {
5082               c_parser_error (parser, "expected identifier");
5083               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5084               return NULL_TREE;
5085             }
5086           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5087                                      "expected %<]%>");
5088         }
5089       else
5090         name = NULL_TREE;
5091       str = c_parser_asm_string_literal (parser);
5092       if (str == NULL_TREE)
5093         return NULL_TREE;
5094       parser->lex_untranslated_string = false;
5095       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5096         {
5097           parser->lex_untranslated_string = true;
5098           return NULL_TREE;
5099         }
5100       loc = c_parser_peek_token (parser)->location;
5101       expr = c_parser_expression (parser);
5102       mark_exp_read (expr.value);
5103       if (convert_p)
5104         expr = default_function_array_conversion (loc, expr);
5105       expr.value = c_fully_fold (expr.value, false, NULL);
5106       parser->lex_untranslated_string = true;
5107       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5108         {
5109           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5110           return NULL_TREE;
5111         }
5112       list = chainon (list, build_tree_list (build_tree_list (name, str),
5113                                              expr.value));
5114       if (c_parser_next_token_is (parser, CPP_COMMA))
5115         c_parser_consume_token (parser);
5116       else
5117         break;
5118     }
5119   return list;
5120 }
5121
5122 /* Parse asm clobbers, a GNU extension.
5123
5124    asm-clobbers:
5125      asm-string-literal
5126      asm-clobbers , asm-string-literal
5127 */
5128
5129 static tree
5130 c_parser_asm_clobbers (c_parser *parser)
5131 {
5132   tree list = NULL_TREE;
5133   while (true)
5134     {
5135       tree str = c_parser_asm_string_literal (parser);
5136       if (str)
5137         list = tree_cons (NULL_TREE, str, list);
5138       else
5139         return NULL_TREE;
5140       if (c_parser_next_token_is (parser, CPP_COMMA))
5141         c_parser_consume_token (parser);
5142       else
5143         break;
5144     }
5145   return list;
5146 }
5147
5148 /* Parse asm goto labels, a GNU extension.
5149
5150    asm-goto-operands:
5151      identifier
5152      asm-goto-operands , identifier
5153 */
5154
5155 static tree
5156 c_parser_asm_goto_operands (c_parser *parser)
5157 {
5158   tree list = NULL_TREE;
5159   while (true)
5160     {
5161       tree name, label;
5162
5163       if (c_parser_next_token_is (parser, CPP_NAME))
5164         {
5165           c_token *tok = c_parser_peek_token (parser);
5166           name = tok->value;
5167           label = lookup_label_for_goto (tok->location, name);
5168           c_parser_consume_token (parser);
5169           TREE_USED (label) = 1;
5170         }
5171       else
5172         {
5173           c_parser_error (parser, "expected identifier");
5174           return NULL_TREE;
5175         }
5176
5177       name = build_string (IDENTIFIER_LENGTH (name),
5178                            IDENTIFIER_POINTER (name));
5179       list = tree_cons (name, label, list);
5180       if (c_parser_next_token_is (parser, CPP_COMMA))
5181         c_parser_consume_token (parser);
5182       else
5183         return nreverse (list);
5184     }
5185 }
5186
5187 /* Parse an expression other than a compound expression; that is, an
5188    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
5189    NULL then it is an Objective-C message expression which is the
5190    primary-expression starting the expression as an initializer.
5191
5192    assignment-expression:
5193      conditional-expression
5194      unary-expression assignment-operator assignment-expression
5195
5196    assignment-operator: one of
5197      = *= /= %= += -= <<= >>= &= ^= |=
5198
5199    In GNU C we accept any conditional expression on the LHS and
5200    diagnose the invalid lvalue rather than producing a syntax
5201    error.  */
5202
5203 static struct c_expr
5204 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5205 {
5206   struct c_expr lhs, rhs, ret;
5207   enum tree_code code;
5208   location_t op_location, exp_location;
5209   gcc_assert (!after || c_dialect_objc ());
5210   lhs = c_parser_conditional_expression (parser, after);
5211   op_location = c_parser_peek_token (parser)->location;
5212   switch (c_parser_peek_token (parser)->type)
5213     {
5214     case CPP_EQ:
5215       code = NOP_EXPR;
5216       break;
5217     case CPP_MULT_EQ:
5218       code = MULT_EXPR;
5219       break;
5220     case CPP_DIV_EQ:
5221       code = TRUNC_DIV_EXPR;
5222       break;
5223     case CPP_MOD_EQ:
5224       code = TRUNC_MOD_EXPR;
5225       break;
5226     case CPP_PLUS_EQ:
5227       code = PLUS_EXPR;
5228       break;
5229     case CPP_MINUS_EQ:
5230       code = MINUS_EXPR;
5231       break;
5232     case CPP_LSHIFT_EQ:
5233       code = LSHIFT_EXPR;
5234       break;
5235     case CPP_RSHIFT_EQ:
5236       code = RSHIFT_EXPR;
5237       break;
5238     case CPP_AND_EQ:
5239       code = BIT_AND_EXPR;
5240       break;
5241     case CPP_XOR_EQ:
5242       code = BIT_XOR_EXPR;
5243       break;
5244     case CPP_OR_EQ:
5245       code = BIT_IOR_EXPR;
5246       break;
5247     default:
5248       return lhs;
5249     }
5250   c_parser_consume_token (parser);
5251   exp_location = c_parser_peek_token (parser)->location;
5252   rhs = c_parser_expr_no_commas (parser, NULL);
5253   rhs = default_function_array_read_conversion (exp_location, rhs);
5254   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5255                                  code, exp_location, rhs.value,
5256                                  rhs.original_type);
5257   if (code == NOP_EXPR)
5258     ret.original_code = MODIFY_EXPR;
5259   else
5260     {
5261       TREE_NO_WARNING (ret.value) = 1;
5262       ret.original_code = ERROR_MARK;
5263     }
5264   ret.original_type = NULL;
5265   return ret;
5266 }
5267
5268 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
5269    is not NULL then it is an Objective-C message expression which is
5270    the primary-expression starting the expression as an initializer.
5271
5272    conditional-expression:
5273      logical-OR-expression
5274      logical-OR-expression ? expression : conditional-expression
5275
5276    GNU extensions:
5277
5278    conditional-expression:
5279      logical-OR-expression ? : conditional-expression
5280 */
5281
5282 static struct c_expr
5283 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5284 {
5285   struct c_expr cond, exp1, exp2, ret;
5286   location_t cond_loc, colon_loc, middle_loc;
5287
5288   gcc_assert (!after || c_dialect_objc ());
5289
5290   cond = c_parser_binary_expression (parser, after);
5291
5292   if (c_parser_next_token_is_not (parser, CPP_QUERY))
5293     return cond;
5294   cond_loc = c_parser_peek_token (parser)->location;
5295   cond = default_function_array_read_conversion (cond_loc, cond);
5296   c_parser_consume_token (parser);
5297   if (c_parser_next_token_is (parser, CPP_COLON))
5298     {
5299       tree eptype = NULL_TREE;
5300
5301       middle_loc = c_parser_peek_token (parser)->location;
5302       pedwarn (middle_loc, OPT_pedantic, 
5303                "ISO C forbids omitting the middle term of a ?: expression");
5304       warn_for_omitted_condop (middle_loc, cond.value);
5305       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5306         {
5307           eptype = TREE_TYPE (cond.value);
5308           cond.value = TREE_OPERAND (cond.value, 0);
5309         }
5310       /* Make sure first operand is calculated only once.  */
5311       exp1.value = c_save_expr (default_conversion (cond.value));
5312       if (eptype)
5313         exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5314       exp1.original_type = NULL;
5315       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5316       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5317     }
5318   else
5319     {
5320       cond.value
5321         = c_objc_common_truthvalue_conversion
5322         (cond_loc, default_conversion (cond.value));
5323       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5324       exp1 = c_parser_expression_conv (parser);
5325       mark_exp_read (exp1.value);
5326       c_inhibit_evaluation_warnings +=
5327         ((cond.value == truthvalue_true_node)
5328          - (cond.value == truthvalue_false_node));
5329     }
5330
5331   colon_loc = c_parser_peek_token (parser)->location;
5332   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5333     {
5334       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5335       ret.value = error_mark_node;
5336       ret.original_code = ERROR_MARK;
5337       ret.original_type = NULL;
5338       return ret;
5339     }
5340   {
5341     location_t exp2_loc = c_parser_peek_token (parser)->location;
5342     exp2 = c_parser_conditional_expression (parser, NULL);
5343     exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5344   }
5345   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5346   ret.value = build_conditional_expr (colon_loc, cond.value,
5347                                       cond.original_code == C_MAYBE_CONST_EXPR,
5348                                       exp1.value, exp1.original_type,
5349                                       exp2.value, exp2.original_type);
5350   ret.original_code = ERROR_MARK;
5351   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5352     ret.original_type = NULL;
5353   else
5354     {
5355       tree t1, t2;
5356
5357       /* If both sides are enum type, the default conversion will have
5358          made the type of the result be an integer type.  We want to
5359          remember the enum types we started with.  */
5360       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5361       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5362       ret.original_type = ((t1 != error_mark_node
5363                             && t2 != error_mark_node
5364                             && (TYPE_MAIN_VARIANT (t1)
5365                                 == TYPE_MAIN_VARIANT (t2)))
5366                            ? t1
5367                            : NULL);
5368     }
5369   return ret;
5370 }
5371
5372 /* Parse a binary expression; that is, a logical-OR-expression (C90
5373    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
5374    an Objective-C message expression which is the primary-expression
5375    starting the expression as an initializer.
5376
5377    multiplicative-expression:
5378      cast-expression
5379      multiplicative-expression * cast-expression
5380      multiplicative-expression / cast-expression
5381      multiplicative-expression % cast-expression
5382
5383    additive-expression:
5384      multiplicative-expression
5385      additive-expression + multiplicative-expression
5386      additive-expression - multiplicative-expression
5387
5388    shift-expression:
5389      additive-expression
5390      shift-expression << additive-expression
5391      shift-expression >> additive-expression
5392
5393    relational-expression:
5394      shift-expression
5395      relational-expression < shift-expression
5396      relational-expression > shift-expression
5397      relational-expression <= shift-expression
5398      relational-expression >= shift-expression
5399
5400    equality-expression:
5401      relational-expression
5402      equality-expression == relational-expression
5403      equality-expression != relational-expression
5404
5405    AND-expression:
5406      equality-expression
5407      AND-expression & equality-expression
5408
5409    exclusive-OR-expression:
5410      AND-expression
5411      exclusive-OR-expression ^ AND-expression
5412
5413    inclusive-OR-expression:
5414      exclusive-OR-expression
5415      inclusive-OR-expression | exclusive-OR-expression
5416
5417    logical-AND-expression:
5418      inclusive-OR-expression
5419      logical-AND-expression && inclusive-OR-expression
5420
5421    logical-OR-expression:
5422      logical-AND-expression
5423      logical-OR-expression || logical-AND-expression
5424 */
5425
5426 static struct c_expr
5427 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5428 {
5429   /* A binary expression is parsed using operator-precedence parsing,
5430      with the operands being cast expressions.  All the binary
5431      operators are left-associative.  Thus a binary expression is of
5432      form:
5433
5434      E0 op1 E1 op2 E2 ...
5435
5436      which we represent on a stack.  On the stack, the precedence
5437      levels are strictly increasing.  When a new operator is
5438      encountered of higher precedence than that at the top of the
5439      stack, it is pushed; its LHS is the top expression, and its RHS
5440      is everything parsed until it is popped.  When a new operator is
5441      encountered with precedence less than or equal to that at the top
5442      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5443      by the result of the operation until the operator at the top of
5444      the stack has lower precedence than the new operator or there is
5445      only one element on the stack; then the top expression is the LHS
5446      of the new operator.  In the case of logical AND and OR
5447      expressions, we also need to adjust c_inhibit_evaluation_warnings
5448      as appropriate when the operators are pushed and popped.  */
5449
5450   /* The precedence levels, where 0 is a dummy lowest level used for
5451      the bottom of the stack.  */
5452   enum prec {
5453     PREC_NONE,
5454     PREC_LOGOR,
5455     PREC_LOGAND,
5456     PREC_BITOR,
5457     PREC_BITXOR,
5458     PREC_BITAND,
5459     PREC_EQ,
5460     PREC_REL,
5461     PREC_SHIFT,
5462     PREC_ADD,
5463     PREC_MULT,
5464     NUM_PRECS
5465   };
5466   struct {
5467     /* The expression at this stack level.  */
5468     struct c_expr expr;
5469     /* The precedence of the operator on its left, PREC_NONE at the
5470        bottom of the stack.  */
5471     enum prec prec;
5472     /* The operation on its left.  */
5473     enum tree_code op;
5474     /* The source location of this operation.  */
5475     location_t loc;
5476   } stack[NUM_PRECS];
5477   int sp;
5478   /* Location of the binary operator.  */
5479   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
5480 #define POP                                                                   \
5481   do {                                                                        \
5482     switch (stack[sp].op)                                                     \
5483       {                                                                       \
5484       case TRUTH_ANDIF_EXPR:                                                  \
5485         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
5486                                           == truthvalue_false_node);          \
5487         break;                                                                \
5488       case TRUTH_ORIF_EXPR:                                                   \
5489         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
5490                                           == truthvalue_true_node);           \
5491         break;                                                                \
5492       default:                                                                \
5493         break;                                                                \
5494       }                                                                       \
5495     stack[sp - 1].expr                                                        \
5496       = default_function_array_read_conversion (stack[sp - 1].loc,            \
5497                                                 stack[sp - 1].expr);          \
5498     stack[sp].expr                                                            \
5499       = default_function_array_read_conversion (stack[sp].loc,                \
5500                                                 stack[sp].expr);              \
5501     stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,               \
5502                                                  stack[sp].op,                \
5503                                                  stack[sp - 1].expr,          \
5504                                                  stack[sp].expr);             \
5505     sp--;                                                                     \
5506   } while (0)
5507   gcc_assert (!after || c_dialect_objc ());
5508   stack[0].loc = c_parser_peek_token (parser)->location;
5509   stack[0].expr = c_parser_cast_expression (parser, after);
5510   stack[0].prec = PREC_NONE;
5511   sp = 0;
5512   while (true)
5513     {
5514       enum prec oprec;
5515       enum tree_code ocode;
5516       if (parser->error)
5517         goto out;
5518       switch (c_parser_peek_token (parser)->type)
5519         {
5520         case CPP_MULT:
5521           oprec = PREC_MULT;
5522           ocode = MULT_EXPR;
5523           break;
5524         case CPP_DIV:
5525           oprec = PREC_MULT;
5526           ocode = TRUNC_DIV_EXPR;
5527           break;
5528         case CPP_MOD:
5529           oprec = PREC_MULT;
5530           ocode = TRUNC_MOD_EXPR;
5531           break;
5532         case CPP_PLUS:
5533           oprec = PREC_ADD;
5534           ocode = PLUS_EXPR;
5535           break;
5536         case CPP_MINUS:
5537           oprec = PREC_ADD;
5538           ocode = MINUS_EXPR;
5539           break;
5540         case CPP_LSHIFT:
5541           oprec = PREC_SHIFT;
5542           ocode = LSHIFT_EXPR;
5543           break;
5544         case CPP_RSHIFT:
5545           oprec = PREC_SHIFT;
5546           ocode = RSHIFT_EXPR;
5547           break;
5548         case CPP_LESS:
5549           oprec = PREC_REL;
5550           ocode = LT_EXPR;
5551           break;
5552         case CPP_GREATER:
5553           oprec = PREC_REL;
5554           ocode = GT_EXPR;
5555           break;
5556         case CPP_LESS_EQ:
5557           oprec = PREC_REL;
5558           ocode = LE_EXPR;
5559           break;
5560         case CPP_GREATER_EQ:
5561           oprec = PREC_REL;
5562           ocode = GE_EXPR;
5563           break;
5564         case CPP_EQ_EQ:
5565           oprec = PREC_EQ;
5566           ocode = EQ_EXPR;
5567           break;
5568         case CPP_NOT_EQ:
5569           oprec = PREC_EQ;
5570           ocode = NE_EXPR;
5571           break;
5572         case CPP_AND:
5573           oprec = PREC_BITAND;
5574           ocode = BIT_AND_EXPR;
5575           break;
5576         case CPP_XOR:
5577           oprec = PREC_BITXOR;
5578           ocode = BIT_XOR_EXPR;
5579           break;
5580         case CPP_OR:
5581           oprec = PREC_BITOR;
5582           ocode = BIT_IOR_EXPR;
5583           break;
5584         case CPP_AND_AND:
5585           oprec = PREC_LOGAND;
5586           ocode = TRUTH_ANDIF_EXPR;
5587           break;
5588         case CPP_OR_OR:
5589           oprec = PREC_LOGOR;
5590           ocode = TRUTH_ORIF_EXPR;
5591           break;
5592         default:
5593           /* Not a binary operator, so end of the binary
5594              expression.  */
5595           goto out;
5596         }
5597       binary_loc = c_parser_peek_token (parser)->location;
5598       c_parser_consume_token (parser);
5599       while (oprec <= stack[sp].prec)
5600         POP;
5601       switch (ocode)
5602         {
5603         case TRUTH_ANDIF_EXPR:
5604           stack[sp].expr
5605             = default_function_array_read_conversion (stack[sp].loc,
5606                                                       stack[sp].expr);
5607           stack[sp].expr.value = c_objc_common_truthvalue_conversion
5608             (stack[sp].loc, default_conversion (stack[sp].expr.value));
5609           c_inhibit_evaluation_warnings += (stack[sp].expr.value
5610                                             == truthvalue_false_node);
5611           break;
5612         case TRUTH_ORIF_EXPR:
5613           stack[sp].expr
5614             = default_function_array_read_conversion (stack[sp].loc,
5615                                                       stack[sp].expr);
5616           stack[sp].expr.value = c_objc_common_truthvalue_conversion
5617             (stack[sp].loc, default_conversion (stack[sp].expr.value));
5618           c_inhibit_evaluation_warnings += (stack[sp].expr.value
5619                                             == truthvalue_true_node);
5620           break;
5621         default:
5622           break;
5623         }
5624       sp++;
5625       stack[sp].loc = binary_loc;
5626       stack[sp].expr = c_parser_cast_expression (parser, NULL);
5627       stack[sp].prec = oprec;
5628       stack[sp].op = ocode;
5629       stack[sp].loc = binary_loc;
5630     }
5631  out:
5632   while (sp > 0)
5633     POP;
5634   return stack[0].expr;
5635 #undef POP
5636 }
5637
5638 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
5639    NULL then it is an Objective-C message expression which is the
5640    primary-expression starting the expression as an initializer.
5641
5642    cast-expression:
5643      unary-expression
5644      ( type-name ) unary-expression
5645 */
5646
5647 static struct c_expr
5648 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5649 {
5650   location_t cast_loc = c_parser_peek_token (parser)->location;
5651   gcc_assert (!after || c_dialect_objc ());
5652   if (after)
5653     return c_parser_postfix_expression_after_primary (parser,
5654                                                       cast_loc, *after);
5655   /* If the expression begins with a parenthesized type name, it may
5656      be either a cast or a compound literal; we need to see whether
5657      the next character is '{' to tell the difference.  If not, it is
5658      an unary expression.  Full detection of unknown typenames here
5659      would require a 3-token lookahead.  */
5660   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5661       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5662     {
5663       struct c_type_name *type_name;
5664       struct c_expr ret;
5665       struct c_expr expr;
5666       c_parser_consume_token (parser);
5667       type_name = c_parser_type_name (parser);
5668       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5669       if (type_name == NULL)
5670         {
5671           ret.value = error_mark_node;
5672           ret.original_code = ERROR_MARK;
5673           ret.original_type = NULL;
5674           return ret;
5675         }
5676
5677       /* Save casted types in the function's used types hash table.  */
5678       used_types_insert (type_name->specs->type);
5679
5680       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5681         return c_parser_postfix_expression_after_paren_type (parser, type_name,
5682                                                              cast_loc);
5683       {
5684         location_t expr_loc = c_parser_peek_token (parser)->location;
5685         expr = c_parser_cast_expression (parser, NULL);
5686         expr = default_function_array_read_conversion (expr_loc, expr);
5687       }
5688       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5689       ret.original_code = ERROR_MARK;
5690       ret.original_type = NULL;
5691       return ret;
5692     }
5693   else
5694     return c_parser_unary_expression (parser);
5695 }
5696
5697 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5698
5699    unary-expression:
5700      postfix-expression
5701      ++ unary-expression
5702      -- unary-expression
5703      unary-operator cast-expression
5704      sizeof unary-expression
5705      sizeof ( type-name )
5706
5707    unary-operator: one of
5708      & * + - ~ !
5709
5710    GNU extensions:
5711
5712    unary-expression:
5713      __alignof__ unary-expression
5714      __alignof__ ( type-name )
5715      && identifier
5716
5717    unary-operator: one of
5718      __extension__ __real__ __imag__
5719
5720    In addition, the GNU syntax treats ++ and -- as unary operators, so
5721    they may be applied to cast expressions with errors for non-lvalues
5722    given later.  */
5723
5724 static struct c_expr
5725 c_parser_unary_expression (c_parser *parser)
5726 {
5727   int ext;
5728   struct c_expr ret, op;
5729   location_t op_loc = c_parser_peek_token (parser)->location;
5730   location_t exp_loc;
5731   ret.original_code = ERROR_MARK;
5732   ret.original_type = NULL;
5733   switch (c_parser_peek_token (parser)->type)
5734     {
5735     case CPP_PLUS_PLUS:
5736       c_parser_consume_token (parser);
5737       exp_loc = c_parser_peek_token (parser)->location;
5738       op = c_parser_cast_expression (parser, NULL);
5739       op = default_function_array_read_conversion (exp_loc, op);
5740       return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5741     case CPP_MINUS_MINUS:
5742       c_parser_consume_token (parser);
5743       exp_loc = c_parser_peek_token (parser)->location;
5744       op = c_parser_cast_expression (parser, NULL);
5745       op = default_function_array_read_conversion (exp_loc, op);
5746       return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5747     case CPP_AND:
5748       c_parser_consume_token (parser);
5749       op = c_parser_cast_expression (parser, NULL);
5750       mark_exp_read (op.value);
5751       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5752     case CPP_MULT:
5753       c_parser_consume_token (parser);
5754       exp_loc = c_parser_peek_token (parser)->location;
5755       op = c_parser_cast_expression (parser, NULL);
5756       op = default_function_array_read_conversion (exp_loc, op);
5757       ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5758       return ret;
5759     case CPP_PLUS:
5760       if (!c_dialect_objc () && !in_system_header)
5761         warning_at (op_loc,
5762                     OPT_Wtraditional,
5763                     "traditional C rejects the unary plus operator");
5764       c_parser_consume_token (parser);
5765       exp_loc = c_parser_peek_token (parser)->location;
5766       op = c_parser_cast_expression (parser, NULL);
5767       op = default_function_array_read_conversion (exp_loc, op);
5768       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5769     case CPP_MINUS:
5770       c_parser_consume_token (parser);
5771       exp_loc = c_parser_peek_token (parser)->location;
5772       op = c_parser_cast_expression (parser, NULL);
5773       op = default_function_array_read_conversion (exp_loc, op);
5774       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5775     case CPP_COMPL:
5776       c_parser_consume_token (parser);
5777       exp_loc = c_parser_peek_token (parser)->location;
5778       op = c_parser_cast_expression (parser, NULL);
5779       op = default_function_array_read_conversion (exp_loc, op);
5780       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5781     case CPP_NOT:
5782       c_parser_consume_token (parser);
5783       exp_loc = c_parser_peek_token (parser)->location;
5784       op = c_parser_cast_expression (parser, NULL);
5785       op = default_function_array_read_conversion (exp_loc, op);
5786       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5787     case CPP_AND_AND:
5788       /* Refer to the address of a label as a pointer.  */
5789       c_parser_consume_token (parser);
5790       if (c_parser_next_token_is (parser, CPP_NAME))
5791         {
5792           ret.value = finish_label_address_expr
5793             (c_parser_peek_token (parser)->value, op_loc);
5794           c_parser_consume_token (parser);
5795         }
5796       else
5797         {
5798           c_parser_error (parser, "expected identifier");
5799           ret.value = error_mark_node;
5800         }
5801         return ret;
5802     case CPP_KEYWORD:
5803       switch (c_parser_peek_token (parser)->keyword)
5804         {
5805         case RID_SIZEOF:
5806           return c_parser_sizeof_expression (parser);
5807         case RID_ALIGNOF:
5808           return c_parser_alignof_expression (parser);
5809         case RID_EXTENSION:
5810           c_parser_consume_token (parser);
5811           ext = disable_extension_diagnostics ();
5812           ret = c_parser_cast_expression (parser, NULL);
5813           restore_extension_diagnostics (ext);
5814           return ret;
5815         case RID_REALPART:
5816           c_parser_consume_token (parser);
5817           exp_loc = c_parser_peek_token (parser)->location;
5818           op = c_parser_cast_expression (parser, NULL);
5819           op = default_function_array_conversion (exp_loc, op);
5820           return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5821         case RID_IMAGPART:
5822           c_parser_consume_token (parser);
5823           exp_loc = c_parser_peek_token (parser)->location;
5824           op = c_parser_cast_expression (parser, NULL);
5825           op = default_function_array_conversion (exp_loc, op);
5826           return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5827         default:
5828           return c_parser_postfix_expression (parser);
5829         }
5830     default:
5831       return c_parser_postfix_expression (parser);
5832     }
5833 }
5834
5835 /* Parse a sizeof expression.  */
5836
5837 static struct c_expr
5838 c_parser_sizeof_expression (c_parser *parser)
5839 {
5840   struct c_expr expr;
5841   location_t expr_loc;
5842   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5843   c_parser_consume_token (parser);
5844   c_inhibit_evaluation_warnings++;
5845   in_sizeof++;
5846   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5847       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5848     {
5849       /* Either sizeof ( type-name ) or sizeof unary-expression
5850          starting with a compound literal.  */
5851       struct c_type_name *type_name;
5852       c_parser_consume_token (parser);
5853       expr_loc = c_parser_peek_token (parser)->location;
5854       type_name = c_parser_type_name (parser);
5855       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5856       if (type_name == NULL)
5857         {
5858           struct c_expr ret;
5859           c_inhibit_evaluation_warnings--;
5860           in_sizeof--;
5861           ret.value = error_mark_node;
5862           ret.original_code = ERROR_MARK;
5863           ret.original_type = NULL;
5864           return ret;
5865         }
5866       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5867         {
5868           expr = c_parser_postfix_expression_after_paren_type (parser,
5869                                                                type_name,
5870                                                                expr_loc);
5871           goto sizeof_expr;
5872         }
5873       /* sizeof ( type-name ).  */
5874       c_inhibit_evaluation_warnings--;
5875       in_sizeof--;
5876       return c_expr_sizeof_type (expr_loc, type_name);
5877     }
5878   else
5879     {
5880       expr_loc = c_parser_peek_token (parser)->location;
5881       expr = c_parser_unary_expression (parser);
5882     sizeof_expr:
5883       c_inhibit_evaluation_warnings--;
5884       in_sizeof--;
5885       mark_exp_read (expr.value);
5886       if (TREE_CODE (expr.value) == COMPONENT_REF
5887           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5888         error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5889       return c_expr_sizeof_expr (expr_loc, expr);
5890     }
5891 }
5892
5893 /* Parse an alignof expression.  */
5894
5895 static struct c_expr
5896 c_parser_alignof_expression (c_parser *parser)
5897 {
5898   struct c_expr expr;
5899   location_t loc = c_parser_peek_token (parser)->location;
5900   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5901   c_parser_consume_token (parser);
5902   c_inhibit_evaluation_warnings++;
5903   in_alignof++;
5904   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5905       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5906     {
5907       /* Either __alignof__ ( type-name ) or __alignof__
5908          unary-expression starting with a compound literal.  */
5909       location_t loc;
5910       struct c_type_name *type_name;
5911       struct c_expr ret;
5912       c_parser_consume_token (parser);
5913       loc = c_parser_peek_token (parser)->location;
5914       type_name = c_parser_type_name (parser);
5915       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5916       if (type_name == NULL)
5917         {
5918           struct c_expr ret;
5919           c_inhibit_evaluation_warnings--;
5920           in_alignof--;
5921           ret.value = error_mark_node;
5922           ret.original_code = ERROR_MARK;
5923           ret.original_type = NULL;
5924           return ret;
5925         }
5926       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5927         {
5928           expr = c_parser_postfix_expression_after_paren_type (parser,
5929                                                                type_name,
5930                                                                loc);
5931           goto alignof_expr;
5932         }
5933       /* alignof ( type-name ).  */
5934       c_inhibit_evaluation_warnings--;
5935       in_alignof--;
5936       ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5937       ret.original_code = ERROR_MARK;
5938       ret.original_type = NULL;
5939       return ret;
5940     }
5941   else
5942     {
5943       struct c_expr ret;
5944       expr = c_parser_unary_expression (parser);
5945     alignof_expr:
5946       mark_exp_read (expr.value);
5947       c_inhibit_evaluation_warnings--;
5948       in_alignof--;
5949       ret.value = c_alignof_expr (loc, expr.value);
5950       ret.original_code = ERROR_MARK;
5951       ret.original_type = NULL;
5952       return ret;
5953     }
5954 }
5955
5956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5957
5958    postfix-expression:
5959      primary-expression
5960      postfix-expression [ expression ]
5961      postfix-expression ( argument-expression-list[opt] )
5962      postfix-expression . identifier
5963      postfix-expression -> identifier
5964      postfix-expression ++
5965      postfix-expression --
5966      ( type-name ) { initializer-list }
5967      ( type-name ) { initializer-list , }
5968
5969    argument-expression-list:
5970      argument-expression
5971      argument-expression-list , argument-expression
5972
5973    primary-expression:
5974      identifier
5975      constant
5976      string-literal
5977      ( expression )
5978
5979    GNU extensions:
5980
5981    primary-expression:
5982      __func__
5983        (treated as a keyword in GNU C)
5984      __FUNCTION__
5985      __PRETTY_FUNCTION__
5986      ( compound-statement )
5987      __builtin_va_arg ( assignment-expression , type-name )
5988      __builtin_offsetof ( type-name , offsetof-member-designator )
5989      __builtin_choose_expr ( assignment-expression ,
5990                              assignment-expression ,
5991                              assignment-expression )
5992      __builtin_types_compatible_p ( type-name , type-name )
5993
5994    offsetof-member-designator:
5995      identifier
5996      offsetof-member-designator . identifier
5997      offsetof-member-designator [ expression ]
5998
5999    Objective-C:
6000
6001    primary-expression:
6002      [ objc-receiver objc-message-args ]
6003      @selector ( objc-selector-arg )
6004      @protocol ( identifier )
6005      @encode ( type-name )
6006      objc-string-literal
6007      Classname . identifier
6008 */
6009
6010 static struct c_expr
6011 c_parser_postfix_expression (c_parser *parser)
6012 {
6013   struct c_expr expr, e1, e2, e3;
6014   struct c_type_name *t1, *t2;
6015   location_t loc = c_parser_peek_token (parser)->location;;
6016   expr.original_code = ERROR_MARK;
6017   expr.original_type = NULL;
6018   switch (c_parser_peek_token (parser)->type)
6019     {
6020     case CPP_NUMBER:
6021       expr.value = c_parser_peek_token (parser)->value;
6022       loc = c_parser_peek_token (parser)->location;
6023       c_parser_consume_token (parser);
6024       if (TREE_CODE (expr.value) == FIXED_CST
6025           && !targetm.fixed_point_supported_p ())
6026         {
6027           error_at (loc, "fixed-point types not supported for this target");
6028           expr.value = error_mark_node;
6029         }
6030       break;
6031     case CPP_CHAR:
6032     case CPP_CHAR16:
6033     case CPP_CHAR32:
6034     case CPP_WCHAR:
6035       expr.value = c_parser_peek_token (parser)->value;
6036       c_parser_consume_token (parser);
6037       break;
6038     case CPP_STRING:
6039     case CPP_STRING16:
6040     case CPP_STRING32:
6041     case CPP_WSTRING:
6042     case CPP_UTF8STRING:
6043       expr.value = c_parser_peek_token (parser)->value;
6044       expr.original_code = STRING_CST;
6045       c_parser_consume_token (parser);
6046       break;
6047     case CPP_OBJC_STRING:
6048       gcc_assert (c_dialect_objc ());
6049       expr.value
6050         = objc_build_string_object (c_parser_peek_token (parser)->value);
6051       c_parser_consume_token (parser);
6052       break;
6053     case CPP_NAME:
6054       switch (c_parser_peek_token (parser)->id_kind)
6055         {
6056         case C_ID_ID:
6057           {
6058             tree id = c_parser_peek_token (parser)->value;
6059             c_parser_consume_token (parser);
6060             expr.value = build_external_ref (loc, id,
6061                                              (c_parser_peek_token (parser)->type
6062                                               == CPP_OPEN_PAREN),
6063                                              &expr.original_type);
6064             break;
6065           }
6066         case C_ID_CLASSNAME:
6067           {
6068             /* Here we parse the Objective-C 2.0 Class.name dot
6069                syntax.  */
6070             tree class_name = c_parser_peek_token (parser)->value;
6071             tree component;
6072             c_parser_consume_token (parser);
6073             gcc_assert (c_dialect_objc ());
6074             if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6075               {
6076                 expr.value = error_mark_node;
6077                 break;
6078               }
6079             if (c_parser_next_token_is_not (parser, CPP_NAME))
6080               {
6081                 c_parser_error (parser, "expected identifier");
6082                 expr.value = error_mark_node;
6083                 break;
6084               }
6085             component = c_parser_peek_token (parser)->value;
6086             c_parser_consume_token (parser);
6087             expr.value = objc_build_class_component_ref (class_name, 
6088                                                          component);
6089             break;
6090           }
6091         default:
6092           c_parser_error (parser, "expected expression");
6093           expr.value = error_mark_node;
6094           break;
6095         }
6096       break;
6097     case CPP_OPEN_PAREN:
6098       /* A parenthesized expression, statement expression or compound
6099          literal.  */
6100       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6101         {
6102           /* A statement expression.  */
6103           tree stmt;
6104           location_t brace_loc;
6105           c_parser_consume_token (parser);
6106           brace_loc = c_parser_peek_token (parser)->location;
6107           c_parser_consume_token (parser);
6108           if (cur_stmt_list == NULL)
6109             {
6110               error_at (loc, "braced-group within expression allowed "
6111                         "only inside a function");
6112               parser->error = true;
6113               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6114               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6115               expr.value = error_mark_node;
6116               break;
6117             }
6118           stmt = c_begin_stmt_expr ();
6119           c_parser_compound_statement_nostart (parser);
6120           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6121                                      "expected %<)%>");
6122           pedwarn (loc, OPT_pedantic,
6123                    "ISO C forbids braced-groups within expressions");
6124           expr.value = c_finish_stmt_expr (brace_loc, stmt);
6125           mark_exp_read (expr.value);
6126         }
6127       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6128         {
6129           /* A compound literal.  ??? Can we actually get here rather
6130              than going directly to
6131              c_parser_postfix_expression_after_paren_type from
6132              elsewhere?  */
6133           location_t loc;
6134           struct c_type_name *type_name;
6135           c_parser_consume_token (parser);
6136           loc = c_parser_peek_token (parser)->location;
6137           type_name = c_parser_type_name (parser);
6138           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6139                                      "expected %<)%>");
6140           if (type_name == NULL)
6141             {
6142               expr.value = error_mark_node;
6143             }
6144           else
6145             expr = c_parser_postfix_expression_after_paren_type (parser,
6146                                                                  type_name,
6147                                                                  loc);
6148         }
6149       else
6150         {
6151           /* A parenthesized expression.  */
6152           c_parser_consume_token (parser);
6153           expr = c_parser_expression (parser);
6154           if (TREE_CODE (expr.value) == MODIFY_EXPR)
6155             TREE_NO_WARNING (expr.value) = 1;
6156           if (expr.original_code != C_MAYBE_CONST_EXPR)
6157             expr.original_code = ERROR_MARK;
6158           /* Don't change EXPR.ORIGINAL_TYPE.  */
6159           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6160                                      "expected %<)%>");
6161         }
6162       break;
6163     case CPP_KEYWORD:
6164       switch (c_parser_peek_token (parser)->keyword)
6165         {
6166         case RID_FUNCTION_NAME:
6167         case RID_PRETTY_FUNCTION_NAME:
6168         case RID_C99_FUNCTION_NAME:
6169           expr.value = fname_decl (loc,
6170                                    c_parser_peek_token (parser)->keyword,
6171                                    c_parser_peek_token (parser)->value);
6172           c_parser_consume_token (parser);
6173           break;
6174         case RID_VA_ARG:
6175           c_parser_consume_token (parser);
6176           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6177             {
6178               expr.value = error_mark_node;
6179               break;
6180             }
6181           e1 = c_parser_expr_no_commas (parser, NULL);
6182           mark_exp_read (e1.value);
6183           e1.value = c_fully_fold (e1.value, false, NULL);
6184           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6185             {
6186               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6187               expr.value = error_mark_node;
6188               break;
6189             }
6190           loc = c_parser_peek_token (parser)->location;
6191           t1 = c_parser_type_name (parser);
6192           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6193                                      "expected %<)%>");
6194           if (t1 == NULL)
6195             {
6196               expr.value = error_mark_node;
6197             }
6198           else
6199             {
6200               tree type_expr = NULL_TREE;
6201               expr.value = c_build_va_arg (loc, e1.value,
6202                                            groktypename (t1, &type_expr, NULL));
6203               if (type_expr)
6204                 {
6205                   expr.value = build2 (C_MAYBE_CONST_EXPR,
6206                                        TREE_TYPE (expr.value), type_expr,
6207                                        expr.value);
6208                   C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6209                 }
6210             }
6211           break;
6212         case RID_OFFSETOF:
6213           c_parser_consume_token (parser);
6214           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6215             {
6216               expr.value = error_mark_node;
6217               break;
6218             }
6219           t1 = c_parser_type_name (parser);
6220           if (t1 == NULL)
6221             parser->error = true;
6222           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6223             gcc_assert (parser->error);
6224           if (parser->error)
6225             {
6226               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6227               expr.value = error_mark_node;
6228               break;
6229             }
6230
6231           {
6232             tree type = groktypename (t1, NULL, NULL);
6233             tree offsetof_ref;
6234             if (type == error_mark_node)
6235               offsetof_ref = error_mark_node;
6236             else
6237               {
6238                 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6239                 SET_EXPR_LOCATION (offsetof_ref, loc);
6240               }
6241             /* Parse the second argument to __builtin_offsetof.  We
6242                must have one identifier, and beyond that we want to
6243                accept sub structure and sub array references.  */
6244             if (c_parser_next_token_is (parser, CPP_NAME))
6245               {
6246                 offsetof_ref = build_component_ref
6247                   (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6248                 c_parser_consume_token (parser);
6249                 while (c_parser_next_token_is (parser, CPP_DOT)
6250                        || c_parser_next_token_is (parser,
6251                                                   CPP_OPEN_SQUARE)
6252                        || c_parser_next_token_is (parser,
6253                                                   CPP_DEREF))
6254                   {
6255                     if (c_parser_next_token_is (parser, CPP_DEREF))
6256                       {
6257                         loc = c_parser_peek_token (parser)->location;
6258                         offsetof_ref = build_array_ref (loc,
6259                                                         offsetof_ref,
6260                                                         integer_zero_node);
6261                         goto do_dot;
6262                       }
6263                     else if (c_parser_next_token_is (parser, CPP_DOT))
6264                       {
6265                       do_dot:
6266                         c_parser_consume_token (parser);
6267                         if (c_parser_next_token_is_not (parser,
6268                                                         CPP_NAME))
6269                           {
6270                             c_parser_error (parser, "expected identifier");
6271                             break;
6272                           }
6273                         offsetof_ref = build_component_ref
6274                           (loc, offsetof_ref,
6275                            c_parser_peek_token (parser)->value);
6276                         c_parser_consume_token (parser);
6277                       }
6278                     else
6279                       {
6280                         tree idx;
6281                         loc = c_parser_peek_token (parser)->location;
6282                         c_parser_consume_token (parser);
6283                         idx = c_parser_expression (parser).value;
6284                         idx = c_fully_fold (idx, false, NULL);
6285                         c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6286                                                    "expected %<]%>");
6287                         offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6288                       }
6289                   }
6290               }
6291             else
6292               c_parser_error (parser, "expected identifier");
6293             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6294                                        "expected %<)%>");
6295             expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6296           }
6297           break;
6298         case RID_CHOOSE_EXPR:
6299           c_parser_consume_token (parser);
6300           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6301             {
6302               expr.value = error_mark_node;
6303               break;
6304             }
6305           loc = c_parser_peek_token (parser)->location;
6306           e1 = c_parser_expr_no_commas (parser, NULL);
6307           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6308             {
6309               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6310               expr.value = error_mark_node;
6311               break;
6312             }
6313           e2 = c_parser_expr_no_commas (parser, NULL);
6314           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6315             {
6316               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6317               expr.value = error_mark_node;
6318               break;
6319             }
6320           e3 = c_parser_expr_no_commas (parser, NULL);
6321           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6322                                      "expected %<)%>");
6323           {
6324             tree c;
6325
6326             c = e1.value;
6327             mark_exp_read (e2.value);
6328             mark_exp_read (e3.value);
6329             if (TREE_CODE (c) != INTEGER_CST
6330                 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6331               error_at (loc,
6332                         "first argument to %<__builtin_choose_expr%> not"
6333                         " a constant");
6334             constant_expression_warning (c);
6335             expr = integer_zerop (c) ? e3 : e2;
6336           }
6337           break;
6338         case RID_TYPES_COMPATIBLE_P:
6339           c_parser_consume_token (parser);
6340           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6341             {
6342               expr.value = error_mark_node;
6343               break;
6344             }
6345           t1 = c_parser_type_name (parser);
6346           if (t1 == NULL)
6347             {
6348               expr.value = error_mark_node;
6349               break;
6350             }
6351           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6352             {
6353               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6354               expr.value = error_mark_node;
6355               break;
6356             }
6357           t2 = c_parser_type_name (parser);
6358           if (t2 == NULL)
6359             {
6360               expr.value = error_mark_node;
6361               break;
6362             }
6363           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6364                                      "expected %<)%>");
6365           {
6366             tree e1, e2;
6367
6368             e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6369             e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6370
6371             expr.value
6372               = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6373           }
6374           break;
6375         case RID_AT_SELECTOR:
6376           gcc_assert (c_dialect_objc ());
6377           c_parser_consume_token (parser);
6378           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6379             {
6380               expr.value = error_mark_node;
6381               break;
6382             }
6383           {
6384             tree sel = c_parser_objc_selector_arg (parser);
6385             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6386                                        "expected %<)%>");
6387             expr.value = objc_build_selector_expr (loc, sel);
6388           }
6389           break;
6390         case RID_AT_PROTOCOL:
6391           gcc_assert (c_dialect_objc ());
6392           c_parser_consume_token (parser);
6393           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6394             {
6395               expr.value = error_mark_node;
6396               break;
6397             }
6398           if (c_parser_next_token_is_not (parser, CPP_NAME))
6399             {
6400               c_parser_error (parser, "expected identifier");
6401               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6402               expr.value = error_mark_node;
6403               break;
6404             }
6405           {
6406             tree id = c_parser_peek_token (parser)->value;
6407             c_parser_consume_token (parser);
6408             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6409                                        "expected %<)%>");
6410             expr.value = objc_build_protocol_expr (id);
6411           }
6412           break;
6413         case RID_AT_ENCODE:
6414           /* Extension to support C-structures in the archiver.  */
6415           gcc_assert (c_dialect_objc ());
6416           c_parser_consume_token (parser);
6417           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6418             {
6419               expr.value = error_mark_node;
6420               break;
6421             }
6422           t1 = c_parser_type_name (parser);
6423           if (t1 == NULL)
6424             {
6425               expr.value = error_mark_node;
6426               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6427               break;
6428             }
6429           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6430                                      "expected %<)%>");
6431           {
6432             tree type = groktypename (t1, NULL, NULL);
6433             expr.value = objc_build_encode_expr (type);
6434           }
6435           break;
6436         default:
6437           c_parser_error (parser, "expected expression");
6438           expr.value = error_mark_node;
6439           break;
6440         }
6441       break;
6442     case CPP_OPEN_SQUARE:
6443       if (c_dialect_objc ())
6444         {
6445           tree receiver, args;
6446           c_parser_consume_token (parser);
6447           receiver = c_parser_objc_receiver (parser);
6448           args = c_parser_objc_message_args (parser);
6449           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6450                                      "expected %<]%>");
6451           expr.value = objc_build_message_expr (build_tree_list (receiver,
6452                                                                  args));
6453           break;
6454         }
6455       /* Else fall through to report error.  */
6456     default:
6457       c_parser_error (parser, "expected expression");
6458       expr.value = error_mark_node;
6459       break;
6460     }
6461   return c_parser_postfix_expression_after_primary (parser, loc, expr);
6462 }
6463
6464 /* Parse a postfix expression after a parenthesized type name: the
6465    brace-enclosed initializer of a compound literal, possibly followed
6466    by some postfix operators.  This is separate because it is not
6467    possible to tell until after the type name whether a cast
6468    expression has a cast or a compound literal, or whether the operand
6469    of sizeof is a parenthesized type name or starts with a compound
6470    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
6471    location of the first token after the parentheses around the type
6472    name.  */
6473
6474 static struct c_expr
6475 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6476                                               struct c_type_name *type_name,
6477                                               location_t type_loc)
6478 {
6479   tree type;
6480   struct c_expr init;
6481   bool non_const;
6482   struct c_expr expr;
6483   location_t start_loc;
6484   tree type_expr = NULL_TREE;
6485   bool type_expr_const = true;
6486   check_compound_literal_type (type_loc, type_name);
6487   start_init (NULL_TREE, NULL, 0);
6488   type = groktypename (type_name, &type_expr, &type_expr_const);
6489   start_loc = c_parser_peek_token (parser)->location;
6490   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6491     {
6492       error_at (type_loc, "compound literal has variable size");
6493       type = error_mark_node;
6494     }
6495   init = c_parser_braced_init (parser, type, false);
6496   finish_init ();
6497   maybe_warn_string_init (type, init);
6498
6499   if (type != error_mark_node
6500       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6501       && current_function_decl)
6502     {
6503       error ("compound literal qualified by address-space qualifier");
6504       type = error_mark_node;
6505     }
6506
6507   if (!flag_isoc99)
6508     pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6509   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6510                ? CONSTRUCTOR_NON_CONST (init.value)
6511                : init.original_code == C_MAYBE_CONST_EXPR);
6512   non_const |= !type_expr_const;
6513   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6514   expr.original_code = ERROR_MARK;
6515   expr.original_type = NULL;
6516   if (type_expr)
6517     {
6518       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6519         {
6520           gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6521           C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6522         }
6523       else
6524         {
6525           gcc_assert (!non_const);
6526           expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6527                                type_expr, expr.value);
6528         }
6529     }
6530   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6531 }
6532
6533 /* Parse a postfix expression after the initial primary or compound
6534    literal; that is, parse a series of postfix operators.
6535
6536    EXPR_LOC is the location of the primary expression.  */
6537
6538 static struct c_expr
6539 c_parser_postfix_expression_after_primary (c_parser *parser,
6540                                            location_t expr_loc,
6541                                            struct c_expr expr)
6542 {
6543   struct c_expr orig_expr;
6544   tree ident, idx;
6545   VEC(tree,gc) *exprlist;
6546   VEC(tree,gc) *origtypes;
6547   while (true)
6548     {
6549       location_t op_loc = c_parser_peek_token (parser)->location;
6550       switch (c_parser_peek_token (parser)->type)
6551         {
6552         case CPP_OPEN_SQUARE:
6553           /* Array reference.  */
6554           c_parser_consume_token (parser);
6555           idx = c_parser_expression (parser).value;
6556           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6557                                      "expected %<]%>");
6558           expr.value = build_array_ref (op_loc, expr.value, idx);
6559           expr.original_code = ERROR_MARK;
6560           expr.original_type = NULL;
6561           break;
6562         case CPP_OPEN_PAREN:
6563           /* Function call.  */
6564           c_parser_consume_token (parser);
6565           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6566             exprlist = NULL;
6567           else
6568             exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6569           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6570                                      "expected %<)%>");
6571           orig_expr = expr;
6572           mark_exp_read (expr.value);
6573           /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6574              "(" after the FUNCNAME, which is what we have now.    */
6575           expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6576                                                 origtypes);
6577           expr.original_code = ERROR_MARK;
6578           if (TREE_CODE (expr.value) == INTEGER_CST
6579               && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6580               && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6581               && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6582             expr.original_code = C_MAYBE_CONST_EXPR;
6583           expr.original_type = NULL;
6584           if (exprlist != NULL)
6585             {
6586               release_tree_vector (exprlist);
6587               release_tree_vector (origtypes);
6588             }
6589           break;
6590         case CPP_DOT:
6591           /* Structure element reference.  */
6592           c_parser_consume_token (parser);
6593           expr = default_function_array_conversion (expr_loc, expr);
6594           if (c_parser_next_token_is (parser, CPP_NAME))
6595             ident = c_parser_peek_token (parser)->value;
6596           else
6597             {
6598               c_parser_error (parser, "expected identifier");
6599               expr.value = error_mark_node;
6600               expr.original_code = ERROR_MARK;
6601               expr.original_type = NULL;
6602               return expr;
6603             }
6604           c_parser_consume_token (parser);
6605           expr.value = build_component_ref (op_loc, expr.value, ident);
6606           expr.original_code = ERROR_MARK;
6607           if (TREE_CODE (expr.value) != COMPONENT_REF)
6608             expr.original_type = NULL;
6609           else
6610             {
6611               /* Remember the original type of a bitfield.  */
6612               tree field = TREE_OPERAND (expr.value, 1);
6613               if (TREE_CODE (field) != FIELD_DECL)
6614                 expr.original_type = NULL;
6615               else
6616                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6617             }
6618           break;
6619         case CPP_DEREF:
6620           /* Structure element reference.  */
6621           c_parser_consume_token (parser);
6622           expr = default_function_array_conversion (expr_loc, expr);
6623           if (c_parser_next_token_is (parser, CPP_NAME))
6624             ident = c_parser_peek_token (parser)->value;
6625           else
6626             {
6627               c_parser_error (parser, "expected identifier");
6628               expr.value = error_mark_node;
6629               expr.original_code = ERROR_MARK;
6630               expr.original_type = NULL;
6631               return expr;
6632             }
6633           c_parser_consume_token (parser);
6634           expr.value = build_component_ref (op_loc,
6635                                             build_indirect_ref (op_loc,
6636                                                                 expr.value,
6637                                                                 RO_ARROW),
6638                                             ident);
6639           expr.original_code = ERROR_MARK;
6640           if (TREE_CODE (expr.value) != COMPONENT_REF)
6641             expr.original_type = NULL;
6642           else
6643             {
6644               /* Remember the original type of a bitfield.  */
6645               tree field = TREE_OPERAND (expr.value, 1);
6646               if (TREE_CODE (field) != FIELD_DECL)
6647                 expr.original_type = NULL;
6648               else
6649                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6650             }
6651           break;
6652         case CPP_PLUS_PLUS:
6653           /* Postincrement.  */
6654           c_parser_consume_token (parser);
6655           expr = default_function_array_read_conversion (expr_loc, expr);
6656           expr.value = build_unary_op (op_loc,
6657                                        POSTINCREMENT_EXPR, expr.value, 0);
6658           expr.original_code = ERROR_MARK;
6659           expr.original_type = NULL;
6660           break;
6661         case CPP_MINUS_MINUS:
6662           /* Postdecrement.  */
6663           c_parser_consume_token (parser);
6664           expr = default_function_array_read_conversion (expr_loc, expr);
6665           expr.value = build_unary_op (op_loc,
6666                                        POSTDECREMENT_EXPR, expr.value, 0);
6667           expr.original_code = ERROR_MARK;
6668           expr.original_type = NULL;
6669           break;
6670         default:
6671           return expr;
6672         }
6673     }
6674 }
6675
6676 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6677
6678    expression:
6679      assignment-expression
6680      expression , assignment-expression
6681 */
6682
6683 static struct c_expr
6684 c_parser_expression (c_parser *parser)
6685 {
6686   struct c_expr expr;
6687   expr = c_parser_expr_no_commas (parser, NULL);
6688   while (c_parser_next_token_is (parser, CPP_COMMA))
6689     {
6690       struct c_expr next;
6691       tree lhsval;
6692       location_t loc = c_parser_peek_token (parser)->location;
6693       location_t expr_loc;
6694       c_parser_consume_token (parser);
6695       expr_loc = c_parser_peek_token (parser)->location;
6696       lhsval = expr.value;
6697       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6698         lhsval = TREE_OPERAND (lhsval, 1);
6699       if (DECL_P (lhsval) || handled_component_p (lhsval))
6700         mark_exp_read (lhsval);
6701       next = c_parser_expr_no_commas (parser, NULL);
6702       next = default_function_array_conversion (expr_loc, next);
6703       expr.value = build_compound_expr (loc, expr.value, next.value);
6704       expr.original_code = COMPOUND_EXPR;
6705       expr.original_type = next.original_type;
6706     }
6707   return expr;
6708 }
6709
6710 /* Parse an expression and convert functions or arrays to
6711    pointers.  */
6712
6713 static struct c_expr
6714 c_parser_expression_conv (c_parser *parser)
6715 {
6716   struct c_expr expr;
6717   location_t loc = c_parser_peek_token (parser)->location;
6718   expr = c_parser_expression (parser);
6719   expr = default_function_array_conversion (loc, expr);
6720   return expr;
6721 }
6722
6723 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
6724    functions and arrays to pointers.  If FOLD_P, fold the expressions.
6725
6726    nonempty-expr-list:
6727      assignment-expression
6728      nonempty-expr-list , assignment-expression
6729 */
6730
6731 static VEC(tree,gc) *
6732 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6733                     VEC(tree,gc) **p_orig_types)
6734 {
6735   VEC(tree,gc) *ret;
6736   VEC(tree,gc) *orig_types;
6737   struct c_expr expr;
6738   location_t loc = c_parser_peek_token (parser)->location;
6739
6740   ret = make_tree_vector ();
6741   if (p_orig_types == NULL)
6742     orig_types = NULL;
6743   else
6744     orig_types = make_tree_vector ();
6745
6746   expr = c_parser_expr_no_commas (parser, NULL);
6747   if (convert_p)
6748     expr = default_function_array_read_conversion (loc, expr);
6749   if (fold_p)
6750     expr.value = c_fully_fold (expr.value, false, NULL);
6751   VEC_quick_push (tree, ret, expr.value);
6752   if (orig_types != NULL)
6753     VEC_quick_push (tree, orig_types, expr.original_type);
6754   while (c_parser_next_token_is (parser, CPP_COMMA))
6755     {
6756       c_parser_consume_token (parser);
6757       loc = c_parser_peek_token (parser)->location;
6758       expr = c_parser_expr_no_commas (parser, NULL);
6759       if (convert_p)
6760         expr = default_function_array_read_conversion (loc, expr);
6761       if (fold_p)
6762         expr.value = c_fully_fold (expr.value, false, NULL);
6763       VEC_safe_push (tree, gc, ret, expr.value);
6764       if (orig_types != NULL)
6765         VEC_safe_push (tree, gc, orig_types, expr.original_type);
6766     }
6767   if (orig_types != NULL)
6768     *p_orig_types = orig_types;
6769   return ret;
6770 }
6771 \f
6772 /* Parse Objective-C-specific constructs.  */
6773
6774 /* Parse an objc-class-definition.
6775
6776    objc-class-definition:
6777      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6778        objc-class-instance-variables[opt] objc-methodprotolist @end
6779      @implementation identifier objc-superclass[opt]
6780        objc-class-instance-variables[opt]
6781      @interface identifier ( identifier ) objc-protocol-refs[opt]
6782        objc-methodprotolist @end
6783      @interface identifier ( ) objc-protocol-refs[opt]
6784        objc-methodprotolist @end
6785      @implementation identifier ( identifier )
6786
6787    objc-superclass:
6788      : identifier
6789
6790    "@interface identifier (" must start "@interface identifier (
6791    identifier ) ...": objc-methodprotolist in the first production may
6792    not start with a parenthesized identifier as a declarator of a data
6793    definition with no declaration specifiers if the objc-superclass,
6794    objc-protocol-refs and objc-class-instance-variables are omitted.  */
6795
6796 static void
6797 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6798 {
6799   bool iface_p;
6800   tree id1;
6801   tree superclass;
6802   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6803     iface_p = true;
6804   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6805     iface_p = false;
6806   else
6807     gcc_unreachable ();
6808
6809   c_parser_consume_token (parser);
6810   if (c_parser_next_token_is_not (parser, CPP_NAME))
6811     {
6812       c_parser_error (parser, "expected identifier");
6813       return;
6814     }
6815   id1 = c_parser_peek_token (parser)->value;
6816   c_parser_consume_token (parser);
6817   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6818     {
6819       /* We have a category or class extension.  */
6820       tree id2;
6821       tree proto = NULL_TREE;
6822       c_parser_consume_token (parser);
6823       if (c_parser_next_token_is_not (parser, CPP_NAME))
6824         {
6825           if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6826             {
6827               /* We have a class extension.  */
6828               id2 = NULL_TREE;
6829             }
6830           else
6831             {
6832               c_parser_error (parser, "expected identifier or %<)%>");
6833               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6834               return;
6835             }
6836         }
6837       else
6838         {
6839           id2 = c_parser_peek_token (parser)->value;
6840           c_parser_consume_token (parser);
6841         }
6842       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6843       if (!iface_p)
6844         {
6845           objc_start_category_implementation (id1, id2);
6846           return;
6847         }
6848       if (c_parser_next_token_is (parser, CPP_LESS))
6849         proto = c_parser_objc_protocol_refs (parser);
6850       objc_start_category_interface (id1, id2, proto, attributes);
6851       c_parser_objc_methodprotolist (parser);
6852       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6853       objc_finish_interface ();
6854       return;
6855     }
6856   if (c_parser_next_token_is (parser, CPP_COLON))
6857     {
6858       c_parser_consume_token (parser);
6859       if (c_parser_next_token_is_not (parser, CPP_NAME))
6860         {
6861           c_parser_error (parser, "expected identifier");
6862           return;
6863         }
6864       superclass = c_parser_peek_token (parser)->value;
6865       c_parser_consume_token (parser);
6866     }
6867   else
6868     superclass = NULL_TREE;
6869   if (iface_p)
6870     {
6871       tree proto = NULL_TREE;
6872       if (c_parser_next_token_is (parser, CPP_LESS))
6873         proto = c_parser_objc_protocol_refs (parser);
6874       objc_start_class_interface (id1, superclass, proto, attributes);
6875     }
6876   else
6877     objc_start_class_implementation (id1, superclass);
6878   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6879     c_parser_objc_class_instance_variables (parser);
6880   if (iface_p)
6881     {
6882       objc_continue_interface ();
6883       c_parser_objc_methodprotolist (parser);
6884       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6885       objc_finish_interface ();
6886     }
6887   else
6888     {
6889       objc_continue_implementation ();
6890       return;
6891     }
6892 }
6893
6894 /* Parse objc-class-instance-variables.
6895
6896    objc-class-instance-variables:
6897      { objc-instance-variable-decl-list[opt] }
6898
6899    objc-instance-variable-decl-list:
6900      objc-visibility-spec
6901      objc-instance-variable-decl ;
6902      ;
6903      objc-instance-variable-decl-list objc-visibility-spec
6904      objc-instance-variable-decl-list objc-instance-variable-decl ;
6905      objc-instance-variable-decl-list ;
6906
6907    objc-visibility-spec:
6908      @private
6909      @protected
6910      @public
6911
6912    objc-instance-variable-decl:
6913      struct-declaration
6914 */
6915
6916 static void
6917 c_parser_objc_class_instance_variables (c_parser *parser)
6918 {
6919   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6920   c_parser_consume_token (parser);
6921   while (c_parser_next_token_is_not (parser, CPP_EOF))
6922     {
6923       tree decls;
6924       /* Parse any stray semicolon.  */
6925       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6926         {
6927           pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6928                    "extra semicolon in struct or union specified");
6929           c_parser_consume_token (parser);
6930           continue;
6931         }
6932       /* Stop if at the end of the instance variables.  */
6933       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6934         {
6935           c_parser_consume_token (parser);
6936           break;
6937         }
6938       /* Parse any objc-visibility-spec.  */
6939       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6940         {
6941           c_parser_consume_token (parser);
6942           objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6943           continue;
6944         }
6945       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6946         {
6947           c_parser_consume_token (parser);
6948           objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6949           continue;
6950         }
6951       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6952         {
6953           c_parser_consume_token (parser);
6954           objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6955           continue;
6956         }
6957       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6958         {
6959           c_parser_consume_token (parser);
6960           objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6961           continue;
6962         }
6963       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6964         {
6965           c_parser_pragma (parser, pragma_external);
6966           continue;
6967         }
6968
6969       /* Parse some comma-separated declarations.  */
6970       decls = c_parser_struct_declaration (parser);
6971       {
6972         /* Comma-separated instance variables are chained together in
6973            reverse order; add them one by one.  */
6974         tree ivar = nreverse (decls);
6975         for (; ivar; ivar = DECL_CHAIN (ivar))
6976           objc_add_instance_variable (copy_node (ivar));
6977       }
6978       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6979     }
6980 }
6981
6982 /* Parse an objc-class-declaration.
6983
6984    objc-class-declaration:
6985      @class identifier-list ;
6986 */
6987
6988 static void
6989 c_parser_objc_class_declaration (c_parser *parser)
6990 {
6991   tree list = NULL_TREE;
6992   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6993   c_parser_consume_token (parser);
6994   /* Any identifiers, including those declared as type names, are OK
6995      here.  */
6996   while (true)
6997     {
6998       tree id;
6999       if (c_parser_next_token_is_not (parser, CPP_NAME))
7000         {
7001           c_parser_error (parser, "expected identifier");
7002           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7003           parser->error = false;
7004           return;
7005         }
7006       id = c_parser_peek_token (parser)->value;
7007       list = chainon (list, build_tree_list (NULL_TREE, id));
7008       c_parser_consume_token (parser);
7009       if (c_parser_next_token_is (parser, CPP_COMMA))
7010         c_parser_consume_token (parser);
7011       else
7012         break;
7013     }
7014   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7015   objc_declare_class (list);
7016 }
7017
7018 /* Parse an objc-alias-declaration.
7019
7020    objc-alias-declaration:
7021      @compatibility_alias identifier identifier ;
7022 */
7023
7024 static void
7025 c_parser_objc_alias_declaration (c_parser *parser)
7026 {
7027   tree id1, id2;
7028   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7029   c_parser_consume_token (parser);
7030   if (c_parser_next_token_is_not (parser, CPP_NAME))
7031     {
7032       c_parser_error (parser, "expected identifier");
7033       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7034       return;
7035     }
7036   id1 = c_parser_peek_token (parser)->value;
7037   c_parser_consume_token (parser);
7038   if (c_parser_next_token_is_not (parser, CPP_NAME))
7039     {
7040       c_parser_error (parser, "expected identifier");
7041       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7042       return;
7043     }
7044   id2 = c_parser_peek_token (parser)->value;
7045   c_parser_consume_token (parser);
7046   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7047   objc_declare_alias (id1, id2);
7048 }
7049
7050 /* Parse an objc-protocol-definition.
7051
7052    objc-protocol-definition:
7053      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7054      @protocol identifier-list ;
7055
7056    "@protocol identifier ;" should be resolved as "@protocol
7057    identifier-list ;": objc-methodprotolist may not start with a
7058    semicolon in the first alternative if objc-protocol-refs are
7059    omitted.  */
7060
7061 static void
7062 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7063 {
7064   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7065
7066   c_parser_consume_token (parser);
7067   if (c_parser_next_token_is_not (parser, CPP_NAME))
7068     {
7069       c_parser_error (parser, "expected identifier");
7070       return;
7071     }
7072   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7073       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7074     {
7075       tree list = NULL_TREE;
7076       /* Any identifiers, including those declared as type names, are
7077          OK here.  */
7078       while (true)
7079         {
7080           tree id;
7081           if (c_parser_next_token_is_not (parser, CPP_NAME))
7082             {
7083               c_parser_error (parser, "expected identifier");
7084               break;
7085             }
7086           id = c_parser_peek_token (parser)->value;
7087           list = chainon (list, build_tree_list (NULL_TREE, id));
7088           c_parser_consume_token (parser);
7089           if (c_parser_next_token_is (parser, CPP_COMMA))
7090             c_parser_consume_token (parser);
7091           else
7092             break;
7093         }
7094       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7095       objc_declare_protocols (list, attributes);
7096     }
7097   else
7098     {
7099       tree id = c_parser_peek_token (parser)->value;
7100       tree proto = NULL_TREE;
7101       c_parser_consume_token (parser);
7102       if (c_parser_next_token_is (parser, CPP_LESS))
7103         proto = c_parser_objc_protocol_refs (parser);
7104       parser->objc_pq_context = true;
7105       objc_start_protocol (id, proto, attributes);
7106       c_parser_objc_methodprotolist (parser);
7107       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7108       parser->objc_pq_context = false;
7109       objc_finish_interface ();
7110     }
7111 }
7112
7113 /* Parse an objc-method-type.
7114
7115    objc-method-type:
7116      +
7117      -
7118
7119    Return true if it is a class method (+) and false if it is
7120    an instance method (-).
7121 */
7122 static inline bool
7123 c_parser_objc_method_type (c_parser *parser)
7124 {
7125   switch (c_parser_peek_token (parser)->type)
7126     {
7127     case CPP_PLUS:
7128       c_parser_consume_token (parser);
7129       return true;
7130     case CPP_MINUS:
7131       c_parser_consume_token (parser);
7132       return false;
7133     default:
7134       gcc_unreachable ();
7135     }
7136 }
7137
7138 /* Parse an objc-method-definition.
7139
7140    objc-method-definition:
7141      objc-method-type objc-method-decl ;[opt] compound-statement
7142 */
7143
7144 static void
7145 c_parser_objc_method_definition (c_parser *parser)
7146 {
7147   bool is_class_method = c_parser_objc_method_type (parser);
7148   tree decl, attributes = NULL_TREE;
7149   parser->objc_pq_context = true;
7150   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7151   if (decl == error_mark_node)
7152     return;  /* Bail here. */
7153
7154   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7155     {
7156       c_parser_consume_token (parser);
7157       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7158                "extra semicolon in method definition specified");
7159     }
7160
7161   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7162     {
7163       c_parser_error (parser, "expected %<{%>");
7164       return;
7165     }
7166
7167   parser->objc_pq_context = false;
7168   if (objc_start_method_definition (is_class_method, decl, attributes))
7169     {
7170       add_stmt (c_parser_compound_statement (parser));
7171       objc_finish_method_definition (current_function_decl);
7172     }
7173   else
7174     {
7175       /* This code is executed when we find a method definition
7176          outside of an @implementation context (or invalid for other
7177          reasons).  Parse the method (to keep going) but do not emit
7178          any code.
7179       */
7180       c_parser_compound_statement (parser);
7181     }
7182 }
7183
7184 /* Parse an objc-methodprotolist.
7185
7186    objc-methodprotolist:
7187      empty
7188      objc-methodprotolist objc-methodproto
7189      objc-methodprotolist declaration
7190      objc-methodprotolist ;
7191      @optional
7192      @required
7193
7194    The declaration is a data definition, which may be missing
7195    declaration specifiers under the same rules and diagnostics as
7196    other data definitions outside functions, and the stray semicolon
7197    is diagnosed the same way as a stray semicolon outside a
7198    function.  */
7199
7200 static void
7201 c_parser_objc_methodprotolist (c_parser *parser)
7202 {
7203   while (true)
7204     {
7205       /* The list is terminated by @end.  */
7206       switch (c_parser_peek_token (parser)->type)
7207         {
7208         case CPP_SEMICOLON:
7209           pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7210                    "ISO C does not allow extra %<;%> outside of a function");
7211           c_parser_consume_token (parser);
7212           break;
7213         case CPP_PLUS:
7214         case CPP_MINUS:
7215           c_parser_objc_methodproto (parser);
7216           break;
7217         case CPP_PRAGMA:
7218           c_parser_pragma (parser, pragma_external);
7219           break;
7220         case CPP_EOF:
7221           return;
7222         default:
7223           if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7224             return;
7225           else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7226             c_parser_objc_at_property_declaration (parser);
7227           else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7228             {
7229               objc_set_method_opt (true);
7230               c_parser_consume_token (parser);
7231             }
7232           else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7233             {
7234               objc_set_method_opt (false);
7235               c_parser_consume_token (parser);
7236             }
7237           else
7238             c_parser_declaration_or_fndef (parser, false, false, true,
7239                                            false, true, NULL);
7240           break;
7241         }
7242     }
7243 }
7244
7245 /* Parse an objc-methodproto.
7246
7247    objc-methodproto:
7248      objc-method-type objc-method-decl ;
7249 */
7250
7251 static void
7252 c_parser_objc_methodproto (c_parser *parser)
7253 {
7254   bool is_class_method = c_parser_objc_method_type (parser);
7255   tree decl, attributes = NULL_TREE;
7256
7257   /* Remember protocol qualifiers in prototypes.  */
7258   parser->objc_pq_context = true;
7259   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7260   /* Forget protocol qualifiers now.  */
7261   parser->objc_pq_context = false;
7262
7263   /* Do not allow the presence of attributes to hide an erroneous 
7264      method implementation in the interface section.  */
7265   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7266     {
7267       c_parser_error (parser, "expected %<;%>");
7268       return;
7269     }
7270   
7271   if (decl != error_mark_node)
7272     objc_add_method_declaration (is_class_method, decl, attributes);
7273
7274   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7275 }
7276
7277 /* If we are at a position that method attributes may be present, check that 
7278    there are not any parsed already (a syntax error) and then collect any 
7279    specified at the current location.  Finally, if new attributes were present,
7280    check that the next token is legal ( ';' for decls and '{' for defs).  */
7281    
7282 static bool 
7283 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7284 {
7285   bool bad = false;
7286   if (*attributes)
7287     {
7288       c_parser_error (parser, 
7289                     "method attributes must be specified at the end only");
7290       *attributes = NULL_TREE;
7291       bad = true;
7292     }
7293
7294   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7295     *attributes = c_parser_attributes (parser);
7296
7297   /* If there were no attributes here, just report any earlier error.  */
7298   if (*attributes == NULL_TREE || bad)
7299     return bad;
7300
7301   /* If the attributes are followed by a ; or {, then just report any earlier
7302      error.  */
7303   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7304       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7305     return bad;
7306
7307   /* We've got attributes, but not at the end.  */
7308   c_parser_error (parser, 
7309                   "expected %<;%> or %<{%> after method attribute definition");
7310   return true;
7311 }
7312
7313 /* Parse an objc-method-decl.
7314
7315    objc-method-decl:
7316      ( objc-type-name ) objc-selector
7317      objc-selector
7318      ( objc-type-name ) objc-keyword-selector objc-optparmlist
7319      objc-keyword-selector objc-optparmlist
7320      attributes
7321
7322    objc-keyword-selector:
7323      objc-keyword-decl
7324      objc-keyword-selector objc-keyword-decl
7325
7326    objc-keyword-decl:
7327      objc-selector : ( objc-type-name ) identifier
7328      objc-selector : identifier
7329      : ( objc-type-name ) identifier
7330      : identifier
7331
7332    objc-optparmlist:
7333      objc-optparms objc-optellipsis
7334
7335    objc-optparms:
7336      empty
7337      objc-opt-parms , parameter-declaration
7338
7339    objc-optellipsis:
7340      empty
7341      , ...
7342 */
7343
7344 static tree
7345 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7346 {
7347   tree type = NULL_TREE;
7348   tree sel;
7349   tree parms = NULL_TREE;
7350   bool ellipsis = false;
7351   bool attr_err = false;
7352
7353   *attributes = NULL_TREE;
7354   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7355     {
7356       c_parser_consume_token (parser);
7357       type = c_parser_objc_type_name (parser);
7358       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7359     }
7360   sel = c_parser_objc_selector (parser);
7361   /* If there is no selector, or a colon follows, we have an
7362      objc-keyword-selector.  If there is a selector, and a colon does
7363      not follow, that selector ends the objc-method-decl.  */
7364   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7365     {
7366       tree tsel = sel;
7367       tree list = NULL_TREE;
7368       while (true)
7369         {
7370           tree atype = NULL_TREE, id, keyworddecl;
7371           tree param_attr = NULL_TREE;
7372           if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7373             break;
7374           if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7375             {
7376               c_parser_consume_token (parser);
7377               atype = c_parser_objc_type_name (parser);
7378               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7379                                          "expected %<)%>");
7380             }
7381           /* New ObjC allows attributes on method parameters.  */
7382           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7383             param_attr = c_parser_attributes (parser);
7384           if (c_parser_next_token_is_not (parser, CPP_NAME))
7385             {
7386               c_parser_error (parser, "expected identifier");
7387               return error_mark_node;
7388             }
7389           id = c_parser_peek_token (parser)->value;
7390           c_parser_consume_token (parser);
7391           keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7392           list = chainon (list, keyworddecl);
7393           tsel = c_parser_objc_selector (parser);
7394           if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7395             break;
7396         }
7397
7398       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7399
7400       /* Parse the optional parameter list.  Optional Objective-C
7401          method parameters follow the C syntax, and may include '...'
7402          to denote a variable number of arguments.  */
7403       parms = make_node (TREE_LIST);
7404       while (c_parser_next_token_is (parser, CPP_COMMA))
7405         {
7406           struct c_parm *parm;
7407           c_parser_consume_token (parser);
7408           if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7409             {
7410               ellipsis = true;
7411               c_parser_consume_token (parser);
7412               attr_err |= c_parser_objc_maybe_method_attributes 
7413                                                 (parser, attributes) ;
7414               break;
7415             }
7416           parm = c_parser_parameter_declaration (parser, NULL_TREE);
7417           if (parm == NULL)
7418             break;
7419           parms = chainon (parms,
7420                            build_tree_list (NULL_TREE, grokparm (parm)));
7421         }
7422       sel = list;
7423     }
7424   else
7425     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7426
7427   if (sel == NULL)
7428     {
7429       c_parser_error (parser, "objective-c method declaration is expected");
7430       return error_mark_node;
7431     }
7432
7433   if (attr_err)
7434     return error_mark_node;
7435
7436   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7437 }
7438
7439 /* Parse an objc-type-name.
7440
7441    objc-type-name:
7442      objc-type-qualifiers[opt] type-name
7443      objc-type-qualifiers[opt]
7444
7445    objc-type-qualifiers:
7446      objc-type-qualifier
7447      objc-type-qualifiers objc-type-qualifier
7448
7449    objc-type-qualifier: one of
7450      in out inout bycopy byref oneway
7451 */
7452
7453 static tree
7454 c_parser_objc_type_name (c_parser *parser)
7455 {
7456   tree quals = NULL_TREE;
7457   struct c_type_name *type_name = NULL;
7458   tree type = NULL_TREE;
7459   while (true)
7460     {
7461       c_token *token = c_parser_peek_token (parser);
7462       if (token->type == CPP_KEYWORD
7463           && (token->keyword == RID_IN
7464               || token->keyword == RID_OUT
7465               || token->keyword == RID_INOUT
7466               || token->keyword == RID_BYCOPY
7467               || token->keyword == RID_BYREF
7468               || token->keyword == RID_ONEWAY))
7469         {
7470           quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7471           c_parser_consume_token (parser);
7472         }
7473       else
7474         break;
7475     }
7476   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7477     type_name = c_parser_type_name (parser);
7478   if (type_name)
7479     type = groktypename (type_name, NULL, NULL);
7480
7481   /* If the type is unknown, and error has already been produced and
7482      we need to recover from the error.  In that case, use NULL_TREE
7483      for the type, as if no type had been specified; this will use the
7484      default type ('id') which is good for error recovery.  */
7485   if (type == error_mark_node)
7486     type = NULL_TREE;
7487
7488   return build_tree_list (quals, type);
7489 }
7490
7491 /* Parse objc-protocol-refs.
7492
7493    objc-protocol-refs:
7494      < identifier-list >
7495 */
7496
7497 static tree
7498 c_parser_objc_protocol_refs (c_parser *parser)
7499 {
7500   tree list = NULL_TREE;
7501   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7502   c_parser_consume_token (parser);
7503   /* Any identifiers, including those declared as type names, are OK
7504      here.  */
7505   while (true)
7506     {
7507       tree id;
7508       if (c_parser_next_token_is_not (parser, CPP_NAME))
7509         {
7510           c_parser_error (parser, "expected identifier");
7511           break;
7512         }
7513       id = c_parser_peek_token (parser)->value;
7514       list = chainon (list, build_tree_list (NULL_TREE, id));
7515       c_parser_consume_token (parser);
7516       if (c_parser_next_token_is (parser, CPP_COMMA))
7517         c_parser_consume_token (parser);
7518       else
7519         break;
7520     }
7521   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7522   return list;
7523 }
7524
7525 /* Parse an objc-try-catch-finally-statement.
7526
7527    objc-try-catch-finally-statement:
7528      @try compound-statement objc-catch-list[opt]
7529      @try compound-statement objc-catch-list[opt] @finally compound-statement
7530
7531    objc-catch-list:
7532      @catch ( objc-catch-parameter-declaration ) compound-statement
7533      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7534
7535    objc-catch-parameter-declaration:
7536      parameter-declaration
7537      '...'
7538
7539    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7540
7541    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7542    for C++.  Keep them in sync.  */   
7543
7544 static void
7545 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7546 {
7547   location_t location;
7548   tree stmt;
7549
7550   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7551   c_parser_consume_token (parser);
7552   location = c_parser_peek_token (parser)->location;
7553   objc_maybe_warn_exceptions (location);
7554   stmt = c_parser_compound_statement (parser);
7555   objc_begin_try_stmt (location, stmt);
7556
7557   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7558     {
7559       struct c_parm *parm;
7560       tree parameter_declaration = error_mark_node;
7561       bool seen_open_paren = false;
7562
7563       c_parser_consume_token (parser);
7564       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7565         seen_open_paren = true;
7566       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7567         {
7568           /* We have "@catch (...)" (where the '...' are literally
7569              what is in the code).  Skip the '...'.
7570              parameter_declaration is set to NULL_TREE, and
7571              objc_being_catch_clauses() knows that that means
7572              '...'.  */
7573           c_parser_consume_token (parser);
7574           parameter_declaration = NULL_TREE;
7575         }
7576       else
7577         {
7578           /* We have "@catch (NSException *exception)" or something
7579              like that.  Parse the parameter declaration.  */
7580           parm = c_parser_parameter_declaration (parser, NULL_TREE);
7581           if (parm == NULL)
7582             parameter_declaration = error_mark_node;
7583           else
7584             parameter_declaration = grokparm (parm);
7585         }
7586       if (seen_open_paren)
7587         c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7588       else
7589         {
7590           /* If there was no open parenthesis, we are recovering from
7591              an error, and we are trying to figure out what mistake
7592              the user has made.  */
7593
7594           /* If there is an immediate closing parenthesis, the user
7595              probably forgot the opening one (ie, they typed "@catch
7596              NSException *e)".  Parse the closing parenthesis and keep
7597              going.  */
7598           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7599             c_parser_consume_token (parser);
7600           
7601           /* If these is no immediate closing parenthesis, the user
7602              probably doesn't know that parenthesis are required at
7603              all (ie, they typed "@catch NSException *e").  So, just
7604              forget about the closing parenthesis and keep going.  */
7605         }
7606       objc_begin_catch_clause (parameter_declaration);
7607       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7608         c_parser_compound_statement_nostart (parser);
7609       objc_finish_catch_clause ();
7610     }
7611   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7612     {
7613       c_parser_consume_token (parser);
7614       location = c_parser_peek_token (parser)->location;
7615       stmt = c_parser_compound_statement (parser);
7616       objc_build_finally_clause (location, stmt);
7617     }
7618   objc_finish_try_stmt ();
7619 }
7620
7621 /* Parse an objc-synchronized-statement.
7622
7623    objc-synchronized-statement:
7624      @synchronized ( expression ) compound-statement
7625 */
7626
7627 static void
7628 c_parser_objc_synchronized_statement (c_parser *parser)
7629 {
7630   location_t loc;
7631   tree expr, stmt;
7632   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7633   c_parser_consume_token (parser);
7634   loc = c_parser_peek_token (parser)->location;
7635   objc_maybe_warn_exceptions (loc);
7636   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7637     {
7638       expr = c_parser_expression (parser).value;
7639       expr = c_fully_fold (expr, false, NULL);
7640       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7641     }
7642   else
7643     expr = error_mark_node;
7644   stmt = c_parser_compound_statement (parser);
7645   objc_build_synchronized (loc, expr, stmt);
7646 }
7647
7648 /* Parse an objc-selector; return NULL_TREE without an error if the
7649    next token is not an objc-selector.
7650
7651    objc-selector:
7652      identifier
7653      one of
7654        enum struct union if else while do for switch case default
7655        break continue return goto asm sizeof typeof __alignof
7656        unsigned long const short volatile signed restrict _Complex
7657        in out inout bycopy byref oneway int char float double void _Bool
7658
7659    ??? Why this selection of keywords but not, for example, storage
7660    class specifiers?  */
7661
7662 static tree
7663 c_parser_objc_selector (c_parser *parser)
7664 {
7665   c_token *token = c_parser_peek_token (parser);
7666   tree value = token->value;
7667   if (token->type == CPP_NAME)
7668     {
7669       c_parser_consume_token (parser);
7670       return value;
7671     }
7672   if (token->type != CPP_KEYWORD)
7673     return NULL_TREE;
7674   switch (token->keyword)
7675     {
7676     case RID_ENUM:
7677     case RID_STRUCT:
7678     case RID_UNION:
7679     case RID_IF:
7680     case RID_ELSE:
7681     case RID_WHILE:
7682     case RID_DO:
7683     case RID_FOR:
7684     case RID_SWITCH:
7685     case RID_CASE:
7686     case RID_DEFAULT:
7687     case RID_BREAK:
7688     case RID_CONTINUE:
7689     case RID_RETURN:
7690     case RID_GOTO:
7691     case RID_ASM:
7692     case RID_SIZEOF:
7693     case RID_TYPEOF:
7694     case RID_ALIGNOF:
7695     case RID_UNSIGNED:
7696     case RID_LONG:
7697     case RID_INT128:
7698     case RID_CONST:
7699     case RID_SHORT:
7700     case RID_VOLATILE:
7701     case RID_SIGNED:
7702     case RID_RESTRICT:
7703     case RID_COMPLEX:
7704     case RID_IN:
7705     case RID_OUT:
7706     case RID_INOUT:
7707     case RID_BYCOPY:
7708     case RID_BYREF:
7709     case RID_ONEWAY:
7710     case RID_INT:
7711     case RID_CHAR:
7712     case RID_FLOAT:
7713     case RID_DOUBLE:
7714     case RID_VOID:
7715     case RID_BOOL:
7716       c_parser_consume_token (parser);
7717       return value;
7718     default:
7719       return NULL_TREE;
7720     }
7721 }
7722
7723 /* Parse an objc-selector-arg.
7724
7725    objc-selector-arg:
7726      objc-selector
7727      objc-keywordname-list
7728
7729    objc-keywordname-list:
7730      objc-keywordname
7731      objc-keywordname-list objc-keywordname
7732
7733    objc-keywordname:
7734      objc-selector :
7735      :
7736 */
7737
7738 static tree
7739 c_parser_objc_selector_arg (c_parser *parser)
7740 {
7741   tree sel = c_parser_objc_selector (parser);
7742   tree list = NULL_TREE;
7743   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7744     return sel;
7745   while (true)
7746     {
7747       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7748         return list;
7749       list = chainon (list, build_tree_list (sel, NULL_TREE));
7750       sel = c_parser_objc_selector (parser);
7751       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7752         break;
7753     }
7754   return list;
7755 }
7756
7757 /* Parse an objc-receiver.
7758
7759    objc-receiver:
7760      expression
7761      class-name
7762      type-name
7763 */
7764
7765 static tree
7766 c_parser_objc_receiver (c_parser *parser)
7767 {
7768   if (c_parser_peek_token (parser)->type == CPP_NAME
7769       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7770           || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7771     {
7772       tree id = c_parser_peek_token (parser)->value;
7773       c_parser_consume_token (parser);
7774       return objc_get_class_reference (id);
7775     }
7776   return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7777 }
7778
7779 /* Parse objc-message-args.
7780
7781    objc-message-args:
7782      objc-selector
7783      objc-keywordarg-list
7784
7785    objc-keywordarg-list:
7786      objc-keywordarg
7787      objc-keywordarg-list objc-keywordarg
7788
7789    objc-keywordarg:
7790      objc-selector : objc-keywordexpr
7791      : objc-keywordexpr
7792 */
7793
7794 static tree
7795 c_parser_objc_message_args (c_parser *parser)
7796 {
7797   tree sel = c_parser_objc_selector (parser);
7798   tree list = NULL_TREE;
7799   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7800     return sel;
7801   while (true)
7802     {
7803       tree keywordexpr;
7804       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7805         return error_mark_node;
7806       keywordexpr = c_parser_objc_keywordexpr (parser);
7807       list = chainon (list, build_tree_list (sel, keywordexpr));
7808       sel = c_parser_objc_selector (parser);
7809       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7810         break;
7811     }
7812   return list;
7813 }
7814
7815 /* Parse an objc-keywordexpr.
7816
7817    objc-keywordexpr:
7818      nonempty-expr-list
7819 */
7820
7821 static tree
7822 c_parser_objc_keywordexpr (c_parser *parser)
7823 {
7824   tree ret;
7825   VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7826   if (VEC_length (tree, expr_list) == 1)
7827     {
7828       /* Just return the expression, remove a level of
7829          indirection.  */
7830       ret = VEC_index (tree, expr_list, 0);
7831     }
7832   else
7833     {
7834       /* We have a comma expression, we will collapse later.  */
7835       ret = build_tree_list_vec (expr_list);
7836     }
7837   release_tree_vector (expr_list);
7838   return ret;
7839 }
7840
7841 /* A check, needed in several places, that ObjC interface, implementation or
7842    method definitions are not prefixed by incorrect items.  */
7843 static bool
7844 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, 
7845                                            struct c_declspecs *specs)
7846 {
7847   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7848       || specs->typespec_kind != ctsk_none)
7849     {
7850       c_parser_error (parser, 
7851                       "no type or storage class may be specified here,");
7852       c_parser_skip_to_end_of_block_or_statement (parser);
7853       return true;
7854     }
7855   return false;
7856 }
7857
7858 /* Parse an Objective-C @property declaration.  The syntax is:
7859
7860    objc-property-declaration:
7861      '@property' objc-property-attributes[opt] struct-declaration ;
7862
7863    objc-property-attributes:
7864     '(' objc-property-attribute-list ')'
7865
7866    objc-property-attribute-list:
7867      objc-property-attribute
7868      objc-property-attribute-list, objc-property-attribute
7869
7870    objc-property-attribute
7871      'getter' = identifier
7872      'setter' = identifier
7873      'readonly'
7874      'readwrite'
7875      'assign'
7876      'retain'
7877      'copy'
7878      'nonatomic'
7879
7880   For example:
7881     @property NSString *name;
7882     @property (readonly) id object;
7883     @property (retain, nonatomic, getter=getTheName) id name;
7884     @property int a, b, c;
7885
7886   PS: This function is identical to cp_parser_objc_at_propery_declaration
7887   for C++.  Keep them in sync.  */
7888 static void
7889 c_parser_objc_at_property_declaration (c_parser *parser)
7890 {
7891   /* The following variables hold the attributes of the properties as
7892      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
7893      seen.  When we see an attribute, we set them to 'true' (if they
7894      are boolean properties) or to the identifier (if they have an
7895      argument, ie, for getter and setter).  Note that here we only
7896      parse the list of attributes, check the syntax and accumulate the
7897      attributes that we find.  objc_add_property_declaration() will
7898      then process the information.  */
7899   bool property_assign = false;
7900   bool property_copy = false;
7901   tree property_getter_ident = NULL_TREE;
7902   bool property_nonatomic = false;
7903   bool property_readonly = false;
7904   bool property_readwrite = false;
7905   bool property_retain = false;
7906   tree property_setter_ident = NULL_TREE;
7907
7908   /* 'properties' is the list of properties that we read.  Usually a
7909      single one, but maybe more (eg, in "@property int a, b, c;" there
7910      are three).  */
7911   tree properties;
7912   location_t loc;
7913
7914   loc = c_parser_peek_token (parser)->location;
7915   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7916
7917   c_parser_consume_token (parser);  /* Eat '@property'.  */
7918
7919   /* Parse the optional attribute list...  */
7920   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7921     {
7922       /* Eat the '(' */
7923       c_parser_consume_token (parser);
7924       
7925       /* Property attribute keywords are valid now.  */
7926       parser->objc_property_attr_context = true;
7927
7928       while (true)
7929         {
7930           bool syntax_error = false;
7931           c_token *token = c_parser_peek_token (parser);
7932           enum rid keyword;
7933
7934           if (token->type != CPP_KEYWORD)
7935             {
7936               if (token->type == CPP_CLOSE_PAREN)
7937                 c_parser_error (parser, "expected identifier");
7938               else
7939                 {
7940                   c_parser_consume_token (parser);
7941                   c_parser_error (parser, "unknown property attribute");
7942                 }
7943               break;
7944             }
7945           keyword = token->keyword;
7946           c_parser_consume_token (parser);
7947           switch (keyword)
7948             {
7949             case RID_ASSIGN:    property_assign = true;    break;
7950             case RID_COPY:      property_copy = true;      break;
7951             case RID_NONATOMIC: property_nonatomic = true; break;
7952             case RID_READONLY:  property_readonly = true;  break;
7953             case RID_READWRITE: property_readwrite = true; break;
7954             case RID_RETAIN:    property_retain = true;    break;
7955
7956             case RID_GETTER:
7957             case RID_SETTER:
7958               if (c_parser_next_token_is_not (parser, CPP_EQ))
7959                 {
7960                   if (keyword == RID_GETTER)
7961                     c_parser_error (parser,
7962                                     "missing %<=%> (after %<getter%> attribute)");
7963                   else
7964                     c_parser_error (parser,
7965                                     "missing %<=%> (after %<setter%> attribute)");
7966                   syntax_error = true;
7967                   break;
7968                 }
7969               c_parser_consume_token (parser); /* eat the = */
7970               if (c_parser_next_token_is_not (parser, CPP_NAME))
7971                 {
7972                   c_parser_error (parser, "expected identifier");
7973                   syntax_error = true;
7974                   break;
7975                 }
7976               if (keyword == RID_SETTER)
7977                 {
7978                   if (property_setter_ident != NULL_TREE)
7979                     c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7980                   else
7981                     property_setter_ident = c_parser_peek_token (parser)->value;
7982                   c_parser_consume_token (parser);
7983                   if (c_parser_next_token_is_not (parser, CPP_COLON))
7984                     c_parser_error (parser, "setter name must terminate with %<:%>");
7985                   else
7986                     c_parser_consume_token (parser);
7987                 }
7988               else
7989                 {
7990                   if (property_getter_ident != NULL_TREE)
7991                     c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7992                   else
7993                     property_getter_ident = c_parser_peek_token (parser)->value;
7994                   c_parser_consume_token (parser);
7995                 }
7996               break;
7997             default:
7998               c_parser_error (parser, "unknown property attribute");
7999               syntax_error = true;
8000               break;
8001             }
8002
8003           if (syntax_error)
8004             break;
8005           
8006           if (c_parser_next_token_is (parser, CPP_COMMA))
8007             c_parser_consume_token (parser);
8008           else
8009             break;
8010         }
8011       parser->objc_property_attr_context = false;
8012       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8013     }
8014   /* ... and the property declaration(s).  */
8015   properties = c_parser_struct_declaration (parser);
8016
8017   if (properties == error_mark_node)
8018     {
8019       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8020       parser->error = false;
8021       return;
8022     }
8023
8024   if (properties == NULL_TREE)
8025     c_parser_error (parser, "expected identifier");
8026   else
8027     {
8028       /* Comma-separated properties are chained together in
8029          reverse order; add them one by one.  */
8030       properties = nreverse (properties);
8031       
8032       for (; properties; properties = TREE_CHAIN (properties))
8033         objc_add_property_declaration (loc, copy_node (properties),
8034                                        property_readonly, property_readwrite,
8035                                        property_assign, property_retain,
8036                                        property_copy, property_nonatomic,
8037                                        property_getter_ident, property_setter_ident);
8038     }
8039
8040   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8041   parser->error = false;
8042 }
8043
8044 /* Parse an Objective-C @synthesize declaration.  The syntax is:
8045
8046    objc-synthesize-declaration:
8047      @synthesize objc-synthesize-identifier-list ;
8048
8049    objc-synthesize-identifier-list:
8050      objc-synthesize-identifier
8051      objc-synthesize-identifier-list, objc-synthesize-identifier
8052
8053    objc-synthesize-identifier
8054      identifier
8055      identifier = identifier
8056
8057   For example:
8058     @synthesize MyProperty;
8059     @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8060
8061   PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8062   for C++.  Keep them in sync.
8063 */
8064 static void
8065 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8066 {
8067   tree list = NULL_TREE;
8068   location_t loc;
8069   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8070   loc = c_parser_peek_token (parser)->location;
8071
8072   c_parser_consume_token (parser);
8073   while (true)
8074     {
8075       tree property, ivar;
8076       if (c_parser_next_token_is_not (parser, CPP_NAME))
8077         {
8078           c_parser_error (parser, "expected identifier");
8079           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8080           /* Once we find the semicolon, we can resume normal parsing.
8081              We have to reset parser->error manually because
8082              c_parser_skip_until_found() won't reset it for us if the
8083              next token is precisely a semicolon.  */
8084           parser->error = false;
8085           return;
8086         }
8087       property = c_parser_peek_token (parser)->value;
8088       c_parser_consume_token (parser);
8089       if (c_parser_next_token_is (parser, CPP_EQ))
8090         {
8091           c_parser_consume_token (parser);
8092           if (c_parser_next_token_is_not (parser, CPP_NAME))
8093             {
8094               c_parser_error (parser, "expected identifier");
8095               c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8096               parser->error = false;
8097               return;
8098             }
8099           ivar = c_parser_peek_token (parser)->value;
8100           c_parser_consume_token (parser);
8101         }
8102       else
8103         ivar = NULL_TREE;
8104       list = chainon (list, build_tree_list (ivar, property));
8105       if (c_parser_next_token_is (parser, CPP_COMMA))
8106         c_parser_consume_token (parser);
8107       else
8108         break;
8109     }
8110   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8111   objc_add_synthesize_declaration (loc, list);
8112 }
8113
8114 /* Parse an Objective-C @dynamic declaration.  The syntax is:
8115
8116    objc-dynamic-declaration:
8117      @dynamic identifier-list ;
8118
8119    For example:
8120      @dynamic MyProperty;
8121      @dynamic MyProperty, AnotherProperty;
8122
8123   PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8124   for C++.  Keep them in sync.
8125 */
8126 static void
8127 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8128 {
8129   tree list = NULL_TREE;
8130   location_t loc;
8131   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8132   loc = c_parser_peek_token (parser)->location;
8133
8134   c_parser_consume_token (parser);
8135   while (true)
8136     {
8137       tree property;
8138       if (c_parser_next_token_is_not (parser, CPP_NAME))
8139         {
8140           c_parser_error (parser, "expected identifier");
8141           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8142           parser->error = false;
8143           return;
8144         }
8145       property = c_parser_peek_token (parser)->value;
8146       list = chainon (list, build_tree_list (NULL_TREE, property));
8147       c_parser_consume_token (parser);
8148       if (c_parser_next_token_is (parser, CPP_COMMA))
8149         c_parser_consume_token (parser);
8150       else
8151         break;
8152     }
8153   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8154   objc_add_dynamic_declaration (loc, list);
8155 }
8156
8157 \f
8158 /* Handle pragmas.  Some OpenMP pragmas are associated with, and therefore
8159    should be considered, statements.  ALLOW_STMT is true if we're within
8160    the context of a function and such pragmas are to be allowed.  Returns
8161    true if we actually parsed such a pragma.  */
8162
8163 static bool
8164 c_parser_pragma (c_parser *parser, enum pragma_context context)
8165 {
8166   unsigned int id;
8167
8168   id = c_parser_peek_token (parser)->pragma_kind;
8169   gcc_assert (id != PRAGMA_NONE);
8170
8171   switch (id)
8172     {
8173     case PRAGMA_OMP_BARRIER:
8174       if (context != pragma_compound)
8175         {
8176           if (context == pragma_stmt)
8177             c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8178                             "used in compound statements");
8179           goto bad_stmt;
8180         }
8181       c_parser_omp_barrier (parser);
8182       return false;
8183
8184     case PRAGMA_OMP_FLUSH:
8185       if (context != pragma_compound)
8186         {
8187           if (context == pragma_stmt)
8188             c_parser_error (parser, "%<#pragma omp flush%> may only be "
8189                             "used in compound statements");
8190           goto bad_stmt;
8191         }
8192       c_parser_omp_flush (parser);
8193       return false;
8194
8195     case PRAGMA_OMP_TASKWAIT:
8196       if (context != pragma_compound)
8197         {
8198           if (context == pragma_stmt)
8199             c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8200                             "used in compound statements");
8201           goto bad_stmt;
8202         }
8203       c_parser_omp_taskwait (parser);
8204       return false;
8205
8206     case PRAGMA_OMP_THREADPRIVATE:
8207       c_parser_omp_threadprivate (parser);
8208       return false;
8209
8210     case PRAGMA_OMP_SECTION:
8211       error_at (c_parser_peek_token (parser)->location,
8212                 "%<#pragma omp section%> may only be used in "
8213                 "%<#pragma omp sections%> construct");
8214       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8215       return false;
8216
8217     case PRAGMA_GCC_PCH_PREPROCESS:
8218       c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8219       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8220       return false;
8221
8222     default:
8223       if (id < PRAGMA_FIRST_EXTERNAL)
8224         {
8225           if (context == pragma_external)
8226             {
8227             bad_stmt:
8228               c_parser_error (parser, "expected declaration specifiers");
8229               c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8230               return false;
8231             }
8232           c_parser_omp_construct (parser);
8233           return true;
8234         }
8235       break;
8236     }
8237
8238   c_parser_consume_pragma (parser);
8239   c_invoke_pragma_handler (id);
8240
8241   /* Skip to EOL, but suppress any error message.  Those will have been
8242      generated by the handler routine through calling error, as opposed
8243      to calling c_parser_error.  */
8244   parser->error = true;
8245   c_parser_skip_to_pragma_eol (parser);
8246
8247   return false;
8248 }
8249
8250 /* The interface the pragma parsers have to the lexer.  */
8251
8252 enum cpp_ttype
8253 pragma_lex (tree *value)
8254 {
8255   c_token *tok = c_parser_peek_token (the_parser);
8256   enum cpp_ttype ret = tok->type;
8257
8258   *value = tok->value;
8259   if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8260     ret = CPP_EOF;
8261   else
8262     {
8263       if (ret == CPP_KEYWORD)
8264         ret = CPP_NAME;
8265       c_parser_consume_token (the_parser);
8266     }
8267
8268   return ret;
8269 }
8270
8271 static void
8272 c_parser_pragma_pch_preprocess (c_parser *parser)
8273 {
8274   tree name = NULL;
8275
8276   c_parser_consume_pragma (parser);
8277   if (c_parser_next_token_is (parser, CPP_STRING))
8278     {
8279       name = c_parser_peek_token (parser)->value;
8280       c_parser_consume_token (parser);
8281     }
8282   else
8283     c_parser_error (parser, "expected string literal");
8284   c_parser_skip_to_pragma_eol (parser);
8285
8286   if (name)
8287     c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8288 }
8289 \f
8290 /* OpenMP 2.5 parsing routines.  */
8291
8292 /* Returns name of the next clause.
8293    If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8294    the token is not consumed.  Otherwise appropriate pragma_omp_clause is
8295    returned and the token is consumed.  */
8296
8297 static pragma_omp_clause
8298 c_parser_omp_clause_name (c_parser *parser)
8299 {
8300   pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8301
8302   if (c_parser_next_token_is_keyword (parser, RID_IF))
8303     result = PRAGMA_OMP_CLAUSE_IF;
8304   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8305     result = PRAGMA_OMP_CLAUSE_DEFAULT;
8306   else if (c_parser_next_token_is (parser, CPP_NAME))
8307     {
8308       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8309
8310       switch (p[0])
8311         {
8312         case 'c':
8313           if (!strcmp ("collapse", p))
8314             result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8315           else if (!strcmp ("copyin", p))
8316             result = PRAGMA_OMP_CLAUSE_COPYIN;
8317           else if (!strcmp ("copyprivate", p))
8318             result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8319           break;
8320         case 'f':
8321           if (!strcmp ("firstprivate", p))
8322             result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8323           break;
8324         case 'l':
8325           if (!strcmp ("lastprivate", p))
8326             result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8327           break;
8328         case 'n':
8329           if (!strcmp ("nowait", p))
8330             result = PRAGMA_OMP_CLAUSE_NOWAIT;
8331           else if (!strcmp ("num_threads", p))
8332             result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8333           break;
8334         case 'o':
8335           if (!strcmp ("ordered", p))
8336             result = PRAGMA_OMP_CLAUSE_ORDERED;
8337           break;
8338         case 'p':
8339           if (!strcmp ("private", p))
8340             result = PRAGMA_OMP_CLAUSE_PRIVATE;
8341           break;
8342         case 'r':
8343           if (!strcmp ("reduction", p))
8344             result = PRAGMA_OMP_CLAUSE_REDUCTION;
8345           break;
8346         case 's':
8347           if (!strcmp ("schedule", p))
8348             result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8349           else if (!strcmp ("shared", p))
8350             result = PRAGMA_OMP_CLAUSE_SHARED;
8351           break;
8352         case 'u':
8353           if (!strcmp ("untied", p))
8354             result = PRAGMA_OMP_CLAUSE_UNTIED;
8355           break;
8356         }
8357     }
8358
8359   if (result != PRAGMA_OMP_CLAUSE_NONE)
8360     c_parser_consume_token (parser);
8361
8362   return result;
8363 }
8364
8365 /* Validate that a clause of the given type does not already exist.  */
8366
8367 static void
8368 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8369                            const char *name)
8370 {
8371   tree c;
8372
8373   for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8374     if (OMP_CLAUSE_CODE (c) == code)
8375       {
8376         location_t loc = OMP_CLAUSE_LOCATION (c);
8377         error_at (loc, "too many %qs clauses", name);
8378         break;
8379       }
8380 }
8381
8382 /* OpenMP 2.5:
8383    variable-list:
8384      identifier
8385      variable-list , identifier
8386
8387    If KIND is nonzero, create the appropriate node and install the
8388    decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8389    If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8390
8391    If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8392    return the list created.  */
8393
8394 static tree
8395 c_parser_omp_variable_list (c_parser *parser,
8396                             location_t clause_loc,
8397                             enum omp_clause_code kind,
8398                             tree list)
8399 {
8400   if (c_parser_next_token_is_not (parser, CPP_NAME)
8401       || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8402     c_parser_error (parser, "expected identifier");
8403
8404   while (c_parser_next_token_is (parser, CPP_NAME)
8405          && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8406     {
8407       tree t = lookup_name (c_parser_peek_token (parser)->value);
8408
8409       if (t == NULL_TREE)
8410         undeclared_variable (c_parser_peek_token (parser)->location,
8411                              c_parser_peek_token (parser)->value);
8412       else if (t == error_mark_node)
8413         ;
8414       else if (kind != 0)
8415         {
8416           tree u = build_omp_clause (clause_loc, kind);
8417           OMP_CLAUSE_DECL (u) = t;
8418           OMP_CLAUSE_CHAIN (u) = list;
8419           list = u;
8420         }
8421       else
8422         list = tree_cons (t, NULL_TREE, list);
8423
8424       c_parser_consume_token (parser);
8425
8426       if (c_parser_next_token_is_not (parser, CPP_COMMA))
8427         break;
8428
8429       c_parser_consume_token (parser);
8430     }
8431
8432   return list;
8433 }
8434
8435 /* Similarly, but expect leading and trailing parenthesis.  This is a very
8436    common case for omp clauses.  */
8437
8438 static tree
8439 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8440                               tree list)
8441 {
8442   /* The clauses location.  */
8443   location_t loc = c_parser_peek_token (parser)->location;
8444
8445   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8446     {
8447       list = c_parser_omp_variable_list (parser, loc, kind, list);
8448       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8449     }
8450   return list;
8451 }
8452
8453 /* OpenMP 3.0:
8454    collapse ( constant-expression ) */
8455
8456 static tree
8457 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8458 {
8459   tree c, num = error_mark_node;
8460   HOST_WIDE_INT n;
8461   location_t loc;
8462
8463   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8464
8465   loc = c_parser_peek_token (parser)->location;
8466   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8467     {
8468       num = c_parser_expr_no_commas (parser, NULL).value;
8469       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8470     }
8471   if (num == error_mark_node)
8472     return list;
8473   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8474       || !host_integerp (num, 0)
8475       || (n = tree_low_cst (num, 0)) <= 0
8476       || (int) n != n)
8477     {
8478       error_at (loc,
8479                 "collapse argument needs positive constant integer expression");
8480       return list;
8481     }
8482   c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8483   OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8484   OMP_CLAUSE_CHAIN (c) = list;
8485   return c;
8486 }
8487
8488 /* OpenMP 2.5:
8489    copyin ( variable-list ) */
8490
8491 static tree
8492 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8493 {
8494   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8495 }
8496
8497 /* OpenMP 2.5:
8498    copyprivate ( variable-list ) */
8499
8500 static tree
8501 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8502 {
8503   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8504 }
8505
8506 /* OpenMP 2.5:
8507    default ( shared | none ) */
8508
8509 static tree
8510 c_parser_omp_clause_default (c_parser *parser, tree list)
8511 {
8512   enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8513   location_t loc = c_parser_peek_token (parser)->location;
8514   tree c;
8515
8516   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8517     return list;
8518   if (c_parser_next_token_is (parser, CPP_NAME))
8519     {
8520       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8521
8522       switch (p[0])
8523         {
8524         case 'n':
8525           if (strcmp ("none", p) != 0)
8526             goto invalid_kind;
8527           kind = OMP_CLAUSE_DEFAULT_NONE;
8528           break;
8529
8530         case 's':
8531           if (strcmp ("shared", p) != 0)
8532             goto invalid_kind;
8533           kind = OMP_CLAUSE_DEFAULT_SHARED;
8534           break;
8535
8536         default:
8537           goto invalid_kind;
8538         }
8539
8540       c_parser_consume_token (parser);
8541     }
8542   else
8543     {
8544     invalid_kind:
8545       c_parser_error (parser, "expected %<none%> or %<shared%>");
8546     }
8547   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8548
8549   if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8550     return list;
8551
8552   check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8553   c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8554   OMP_CLAUSE_CHAIN (c) = list;
8555   OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8556
8557   return c;
8558 }
8559
8560 /* OpenMP 2.5:
8561    firstprivate ( variable-list ) */
8562
8563 static tree
8564 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8565 {
8566   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8567 }
8568
8569 /* OpenMP 2.5:
8570    if ( expression ) */
8571
8572 static tree
8573 c_parser_omp_clause_if (c_parser *parser, tree list)
8574 {
8575   location_t loc = c_parser_peek_token (parser)->location;
8576   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8577     {
8578       tree t = c_parser_paren_condition (parser);
8579       tree c;
8580
8581       check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8582
8583       c = build_omp_clause (loc, OMP_CLAUSE_IF);
8584       OMP_CLAUSE_IF_EXPR (c) = t;
8585       OMP_CLAUSE_CHAIN (c) = list;
8586       list = c;
8587     }
8588   else
8589     c_parser_error (parser, "expected %<(%>");
8590
8591   return list;
8592 }
8593
8594 /* OpenMP 2.5:
8595    lastprivate ( variable-list ) */
8596
8597 static tree
8598 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8599 {
8600   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8601 }
8602
8603 /* OpenMP 2.5:
8604    nowait */
8605
8606 static tree
8607 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8608 {
8609   tree c;
8610   location_t loc = c_parser_peek_token (parser)->location;
8611
8612   check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8613
8614   c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8615   OMP_CLAUSE_CHAIN (c) = list;
8616   return c;
8617 }
8618
8619 /* OpenMP 2.5:
8620    num_threads ( expression ) */
8621
8622 static tree
8623 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8624 {
8625   location_t num_threads_loc = c_parser_peek_token (parser)->location;
8626   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8627     {
8628       location_t expr_loc = c_parser_peek_token (parser)->location;
8629       tree c, t = c_parser_expression (parser).value;
8630       t = c_fully_fold (t, false, NULL);
8631
8632       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8633
8634       if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8635         {
8636           c_parser_error (parser, "expected integer expression");
8637           return list;
8638         }
8639
8640       /* Attempt to statically determine when the number isn't positive.  */
8641       c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8642                        build_int_cst (TREE_TYPE (t), 0));
8643       if (CAN_HAVE_LOCATION_P (c))
8644         SET_EXPR_LOCATION (c, expr_loc);
8645       if (c == boolean_true_node)
8646         {
8647           warning_at (expr_loc, 0,
8648                       "%<num_threads%> value must be positive");
8649           t = integer_one_node;
8650         }
8651
8652       check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8653
8654       c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8655       OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8656       OMP_CLAUSE_CHAIN (c) = list;
8657       list = c;
8658     }
8659
8660   return list;
8661 }
8662
8663 /* OpenMP 2.5:
8664    ordered */
8665
8666 static tree
8667 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8668 {
8669   tree c;
8670
8671   check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8672
8673   c = build_omp_clause (c_parser_peek_token (parser)->location,
8674                         OMP_CLAUSE_ORDERED);
8675   OMP_CLAUSE_CHAIN (c) = list;
8676
8677   return c;
8678 }
8679
8680 /* OpenMP 2.5:
8681    private ( variable-list ) */
8682
8683 static tree
8684 c_parser_omp_clause_private (c_parser *parser, tree list)
8685 {
8686   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8687 }
8688
8689 /* OpenMP 2.5:
8690    reduction ( reduction-operator : variable-list )
8691
8692    reduction-operator:
8693      One of: + * - & ^ | && || */
8694
8695 static tree
8696 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8697 {
8698   location_t clause_loc = c_parser_peek_token (parser)->location;
8699   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8700     {
8701       enum tree_code code;
8702
8703       switch (c_parser_peek_token (parser)->type)
8704         {
8705         case CPP_PLUS:
8706           code = PLUS_EXPR;
8707           break;
8708         case CPP_MULT:
8709           code = MULT_EXPR;
8710           break;
8711         case CPP_MINUS:
8712           code = MINUS_EXPR;
8713           break;
8714         case CPP_AND:
8715           code = BIT_AND_EXPR;
8716           break;
8717         case CPP_XOR:
8718           code = BIT_XOR_EXPR;
8719           break;
8720         case CPP_OR:
8721           code = BIT_IOR_EXPR;
8722           break;
8723         case CPP_AND_AND:
8724           code = TRUTH_ANDIF_EXPR;
8725           break;
8726         case CPP_OR_OR:
8727           code = TRUTH_ORIF_EXPR;
8728           break;
8729         default:
8730           c_parser_error (parser,
8731                           "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8732                           "%<^%>, %<|%>, %<&&%>, or %<||%>");
8733           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8734           return list;
8735         }
8736       c_parser_consume_token (parser);
8737       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8738         {
8739           tree nl, c;
8740
8741           nl = c_parser_omp_variable_list (parser, clause_loc,
8742                                            OMP_CLAUSE_REDUCTION, list);
8743           for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8744             OMP_CLAUSE_REDUCTION_CODE (c) = code;
8745
8746           list = nl;
8747         }
8748       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8749     }
8750   return list;
8751 }
8752
8753 /* OpenMP 2.5:
8754    schedule ( schedule-kind )
8755    schedule ( schedule-kind , expression )
8756
8757    schedule-kind:
8758      static | dynamic | guided | runtime | auto
8759 */
8760
8761 static tree
8762 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8763 {
8764   tree c, t;
8765   location_t loc = c_parser_peek_token (parser)->location;
8766
8767   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8768     return list;
8769
8770   c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8771
8772   if (c_parser_next_token_is (parser, CPP_NAME))
8773     {
8774       tree kind = c_parser_peek_token (parser)->value;
8775       const char *p = IDENTIFIER_POINTER (kind);
8776
8777       switch (p[0])
8778         {
8779         case 'd':
8780           if (strcmp ("dynamic", p) != 0)
8781             goto invalid_kind;
8782           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8783           break;
8784
8785         case 'g':
8786           if (strcmp ("guided", p) != 0)
8787             goto invalid_kind;
8788           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8789           break;
8790
8791         case 'r':
8792           if (strcmp ("runtime", p) != 0)
8793             goto invalid_kind;
8794           OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8795           break;
8796
8797         default:
8798           goto invalid_kind;
8799         }
8800     }
8801   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8802     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8803   else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8804     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8805   else
8806     goto invalid_kind;
8807
8808   c_parser_consume_token (parser);
8809   if (c_parser_next_token_is (parser, CPP_COMMA))
8810     {
8811       location_t here;
8812       c_parser_consume_token (parser);
8813
8814       here = c_parser_peek_token (parser)->location;
8815       t = c_parser_expr_no_commas (parser, NULL).value;
8816       t = c_fully_fold (t, false, NULL);
8817
8818       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8819         error_at (here, "schedule %<runtime%> does not take "
8820                   "a %<chunk_size%> parameter");
8821       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8822         error_at (here,
8823                   "schedule %<auto%> does not take "
8824                   "a %<chunk_size%> parameter");
8825       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8826         OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8827       else
8828         c_parser_error (parser, "expected integer expression");
8829
8830       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8831     }
8832   else
8833     c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8834                                "expected %<,%> or %<)%>");
8835
8836   check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8837   OMP_CLAUSE_CHAIN (c) = list;
8838   return c;
8839
8840  invalid_kind:
8841   c_parser_error (parser, "invalid schedule kind");
8842   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8843   return list;
8844 }
8845
8846 /* OpenMP 2.5:
8847    shared ( variable-list ) */
8848
8849 static tree
8850 c_parser_omp_clause_shared (c_parser *parser, tree list)
8851 {
8852   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8853 }
8854
8855 /* OpenMP 3.0:
8856    untied */
8857
8858 static tree
8859 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8860 {
8861   tree c;
8862
8863   /* FIXME: Should we allow duplicates?  */
8864   check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8865
8866   c = build_omp_clause (c_parser_peek_token (parser)->location,
8867                         OMP_CLAUSE_UNTIED);
8868   OMP_CLAUSE_CHAIN (c) = list;
8869
8870   return c;
8871 }
8872
8873 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
8874    is a bitmask in MASK.  Return the list of clauses found; the result
8875    of clause default goes in *pdefault.  */
8876
8877 static tree
8878 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8879                           const char *where)
8880 {
8881   tree clauses = NULL;
8882   bool first = true;
8883
8884   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8885     {
8886       location_t here;
8887       pragma_omp_clause c_kind;
8888       const char *c_name;
8889       tree prev = clauses;
8890
8891       if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8892         c_parser_consume_token (parser);
8893
8894       first = false;
8895       here = c_parser_peek_token (parser)->location;
8896       c_kind = c_parser_omp_clause_name (parser);
8897
8898       switch (c_kind)
8899         {
8900         case PRAGMA_OMP_CLAUSE_COLLAPSE:
8901           clauses = c_parser_omp_clause_collapse (parser, clauses);
8902           c_name = "collapse";
8903           break;
8904         case PRAGMA_OMP_CLAUSE_COPYIN:
8905           clauses = c_parser_omp_clause_copyin (parser, clauses);
8906           c_name = "copyin";
8907           break;
8908         case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8909           clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8910           c_name = "copyprivate";
8911           break;
8912         case PRAGMA_OMP_CLAUSE_DEFAULT:
8913           clauses = c_parser_omp_clause_default (parser, clauses);
8914           c_name = "default";
8915           break;
8916         case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8917           clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8918           c_name = "firstprivate";
8919           break;
8920         case PRAGMA_OMP_CLAUSE_IF:
8921           clauses = c_parser_omp_clause_if (parser, clauses);
8922           c_name = "if";
8923           break;
8924         case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8925           clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8926           c_name = "lastprivate";
8927           break;
8928         case PRAGMA_OMP_CLAUSE_NOWAIT:
8929           clauses = c_parser_omp_clause_nowait (parser, clauses);
8930           c_name = "nowait";
8931           break;
8932         case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8933           clauses = c_parser_omp_clause_num_threads (parser, clauses);
8934           c_name = "num_threads";
8935           break;
8936         case PRAGMA_OMP_CLAUSE_ORDERED:
8937           clauses = c_parser_omp_clause_ordered (parser, clauses);
8938           c_name = "ordered";
8939           break;
8940         case PRAGMA_OMP_CLAUSE_PRIVATE:
8941           clauses = c_parser_omp_clause_private (parser, clauses);
8942           c_name = "private";
8943           break;
8944         case PRAGMA_OMP_CLAUSE_REDUCTION:
8945           clauses = c_parser_omp_clause_reduction (parser, clauses);
8946           c_name = "reduction";
8947           break;
8948         case PRAGMA_OMP_CLAUSE_SCHEDULE:
8949           clauses = c_parser_omp_clause_schedule (parser, clauses);
8950           c_name = "schedule";
8951           break;
8952         case PRAGMA_OMP_CLAUSE_SHARED:
8953           clauses = c_parser_omp_clause_shared (parser, clauses);
8954           c_name = "shared";
8955           break;
8956         case PRAGMA_OMP_CLAUSE_UNTIED:
8957           clauses = c_parser_omp_clause_untied (parser, clauses);
8958           c_name = "untied";
8959           break;
8960         default:
8961           c_parser_error (parser, "expected %<#pragma omp%> clause");
8962           goto saw_error;
8963         }
8964
8965       if (((mask >> c_kind) & 1) == 0 && !parser->error)
8966         {
8967           /* Remove the invalid clause(s) from the list to avoid
8968              confusing the rest of the compiler.  */
8969           clauses = prev;
8970           error_at (here, "%qs is not valid for %qs", c_name, where);
8971         }
8972     }
8973
8974  saw_error:
8975   c_parser_skip_to_pragma_eol (parser);
8976
8977   return c_finish_omp_clauses (clauses);
8978 }
8979
8980 /* OpenMP 2.5:
8981    structured-block:
8982      statement
8983
8984    In practice, we're also interested in adding the statement to an
8985    outer node.  So it is convenient if we work around the fact that
8986    c_parser_statement calls add_stmt.  */
8987
8988 static tree
8989 c_parser_omp_structured_block (c_parser *parser)
8990 {
8991   tree stmt = push_stmt_list ();
8992   c_parser_statement (parser);
8993   return pop_stmt_list (stmt);
8994 }
8995
8996 /* OpenMP 2.5:
8997    # pragma omp atomic new-line
8998      expression-stmt
8999
9000    expression-stmt:
9001      x binop= expr | x++ | ++x | x-- | --x
9002    binop:
9003      +, *, -, /, &, ^, |, <<, >>
9004
9005   where x is an lvalue expression with scalar type.
9006
9007   LOC is the location of the #pragma token.  */
9008
9009 static void
9010 c_parser_omp_atomic (location_t loc, c_parser *parser)
9011 {
9012   tree lhs, rhs;
9013   tree stmt;
9014   enum tree_code code;
9015   struct c_expr rhs_expr;
9016
9017   c_parser_skip_to_pragma_eol (parser);
9018
9019   lhs = c_parser_unary_expression (parser).value;
9020   lhs = c_fully_fold (lhs, false, NULL);
9021   switch (TREE_CODE (lhs))
9022     {
9023     case ERROR_MARK:
9024     saw_error:
9025       c_parser_skip_to_end_of_block_or_statement (parser);
9026       return;
9027
9028     case PREINCREMENT_EXPR:
9029     case POSTINCREMENT_EXPR:
9030       lhs = TREE_OPERAND (lhs, 0);
9031       code = PLUS_EXPR;
9032       rhs = integer_one_node;
9033       break;
9034
9035     case PREDECREMENT_EXPR:
9036     case POSTDECREMENT_EXPR:
9037       lhs = TREE_OPERAND (lhs, 0);
9038       code = MINUS_EXPR;
9039       rhs = integer_one_node;
9040       break;
9041
9042     case COMPOUND_EXPR:
9043       if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9044           && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9045           && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9046           && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9047           && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9048                                               (TREE_OPERAND (lhs, 1), 0), 0)))
9049              == BOOLEAN_TYPE)
9050         /* Undo effects of boolean_increment for post {in,de}crement.  */
9051         lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9052       /* FALLTHRU */
9053     case MODIFY_EXPR:
9054       if (TREE_CODE (lhs) == MODIFY_EXPR
9055           && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9056         {
9057           /* Undo effects of boolean_increment.  */
9058           if (integer_onep (TREE_OPERAND (lhs, 1)))
9059             {
9060               /* This is pre or post increment.  */
9061               rhs = TREE_OPERAND (lhs, 1);
9062               lhs = TREE_OPERAND (lhs, 0);
9063               code = NOP_EXPR;
9064               break;
9065             }
9066           if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9067               && TREE_OPERAND (lhs, 0)
9068                  == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9069             {
9070               /* This is pre or post decrement.  */
9071               rhs = TREE_OPERAND (lhs, 1);
9072               lhs = TREE_OPERAND (lhs, 0);
9073               code = NOP_EXPR;
9074               break;
9075             }
9076         }
9077       /* FALLTHRU */
9078     default:
9079       switch (c_parser_peek_token (parser)->type)
9080         {
9081         case CPP_MULT_EQ:
9082           code = MULT_EXPR;
9083           break;
9084         case CPP_DIV_EQ:
9085           code = TRUNC_DIV_EXPR;
9086           break;
9087         case CPP_PLUS_EQ:
9088           code = PLUS_EXPR;
9089           break;
9090         case CPP_MINUS_EQ:
9091           code = MINUS_EXPR;
9092           break;
9093         case CPP_LSHIFT_EQ:
9094           code = LSHIFT_EXPR;
9095           break;
9096         case CPP_RSHIFT_EQ:
9097           code = RSHIFT_EXPR;
9098           break;
9099         case CPP_AND_EQ:
9100           code = BIT_AND_EXPR;
9101           break;
9102         case CPP_OR_EQ:
9103           code = BIT_IOR_EXPR;
9104           break;
9105         case CPP_XOR_EQ:
9106           code = BIT_XOR_EXPR;
9107           break;
9108         default:
9109           c_parser_error (parser,
9110                           "invalid operator for %<#pragma omp atomic%>");
9111           goto saw_error;
9112         }
9113
9114       /* Arrange to pass the location of the assignment operator to
9115          c_finish_omp_atomic.  */
9116       loc = c_parser_peek_token (parser)->location;
9117       c_parser_consume_token (parser);
9118       {
9119         location_t rhs_loc = c_parser_peek_token (parser)->location;
9120         rhs_expr = c_parser_expression (parser);
9121         rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9122       }
9123       rhs = rhs_expr.value;
9124       rhs = c_fully_fold (rhs, false, NULL);
9125       break;
9126     }
9127   stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
9128   if (stmt != error_mark_node)
9129     add_stmt (stmt);
9130   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9131 }
9132
9133
9134 /* OpenMP 2.5:
9135    # pragma omp barrier new-line
9136 */
9137
9138 static void
9139 c_parser_omp_barrier (c_parser *parser)
9140 {
9141   location_t loc = c_parser_peek_token (parser)->location;
9142   c_parser_consume_pragma (parser);
9143   c_parser_skip_to_pragma_eol (parser);
9144
9145   c_finish_omp_barrier (loc);
9146 }
9147
9148 /* OpenMP 2.5:
9149    # pragma omp critical [(name)] new-line
9150      structured-block
9151
9152   LOC is the location of the #pragma itself.  */
9153
9154 static tree
9155 c_parser_omp_critical (location_t loc, c_parser *parser)
9156 {
9157   tree stmt, name = NULL;
9158
9159   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9160     {
9161       c_parser_consume_token (parser);
9162       if (c_parser_next_token_is (parser, CPP_NAME))
9163         {
9164           name = c_parser_peek_token (parser)->value;
9165           c_parser_consume_token (parser);
9166           c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9167         }
9168       else
9169         c_parser_error (parser, "expected identifier");
9170     }
9171   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9172     c_parser_error (parser, "expected %<(%> or end of line");
9173   c_parser_skip_to_pragma_eol (parser);
9174
9175   stmt = c_parser_omp_structured_block (parser);
9176   return c_finish_omp_critical (loc, stmt, name);
9177 }
9178
9179 /* OpenMP 2.5:
9180    # pragma omp flush flush-vars[opt] new-line
9181
9182    flush-vars:
9183      ( variable-list ) */
9184
9185 static void
9186 c_parser_omp_flush (c_parser *parser)
9187 {
9188   location_t loc = c_parser_peek_token (parser)->location;
9189   c_parser_consume_pragma (parser);
9190   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9191     c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9192   else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9193     c_parser_error (parser, "expected %<(%> or end of line");
9194   c_parser_skip_to_pragma_eol (parser);
9195
9196   c_finish_omp_flush (loc);
9197 }
9198
9199 /* Parse the restricted form of the for statement allowed by OpenMP.
9200    The real trick here is to determine the loop control variable early
9201    so that we can push a new decl if necessary to make it private.
9202    LOC is the location of the OMP in "#pragma omp".  */
9203
9204 static tree
9205 c_parser_omp_for_loop (location_t loc,
9206                        c_parser *parser, tree clauses, tree *par_clauses)
9207 {
9208   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9209   tree declv, condv, incrv, initv, ret = NULL;
9210   bool fail = false, open_brace_parsed = false;
9211   int i, collapse = 1, nbraces = 0;
9212   location_t for_loc;
9213   VEC(tree,gc) *for_block = make_tree_vector ();
9214
9215   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9216     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9217       collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9218
9219   gcc_assert (collapse >= 1);
9220
9221   declv = make_tree_vec (collapse);
9222   initv = make_tree_vec (collapse);
9223   condv = make_tree_vec (collapse);
9224   incrv = make_tree_vec (collapse);
9225
9226   if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9227     {
9228       c_parser_error (parser, "for statement expected");
9229       return NULL;
9230     }
9231   for_loc = c_parser_peek_token (parser)->location;
9232   c_parser_consume_token (parser);
9233
9234   for (i = 0; i < collapse; i++)
9235     {
9236       int bracecount = 0;
9237
9238       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9239         goto pop_scopes;
9240
9241       /* Parse the initialization declaration or expression.  */
9242       if (c_parser_next_tokens_start_declaration (parser))
9243         {
9244           if (i > 0)
9245             VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9246           c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9247           decl = check_for_loop_decls (for_loc, flag_isoc99);
9248           if (decl == NULL)
9249             goto error_init;
9250           if (DECL_INITIAL (decl) == error_mark_node)
9251             decl = error_mark_node;
9252           init = decl;
9253         }
9254       else if (c_parser_next_token_is (parser, CPP_NAME)
9255                && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9256         {
9257           struct c_expr decl_exp;
9258           struct c_expr init_exp;
9259           location_t init_loc;
9260
9261           decl_exp = c_parser_postfix_expression (parser);
9262           decl = decl_exp.value;
9263
9264           c_parser_require (parser, CPP_EQ, "expected %<=%>");
9265
9266           init_loc = c_parser_peek_token (parser)->location;
9267           init_exp = c_parser_expr_no_commas (parser, NULL);
9268           init_exp = default_function_array_read_conversion (init_loc,
9269                                                              init_exp);
9270           init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9271                                     NOP_EXPR, init_loc, init_exp.value,
9272                                     init_exp.original_type);
9273           init = c_process_expr_stmt (init_loc, init);
9274
9275           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9276         }
9277       else
9278         {
9279         error_init:
9280           c_parser_error (parser,
9281                           "expected iteration declaration or initialization");
9282           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9283                                      "expected %<)%>");
9284           fail = true;
9285           goto parse_next;
9286         }
9287
9288       /* Parse the loop condition.  */
9289       cond = NULL_TREE;
9290       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9291         {
9292           location_t cond_loc = c_parser_peek_token (parser)->location;
9293           struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
9294
9295           cond = cond_expr.value;
9296           cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9297           cond = c_fully_fold (cond, false, NULL);
9298           switch (cond_expr.original_code)
9299             {
9300             case GT_EXPR:
9301             case GE_EXPR:
9302             case LT_EXPR:
9303             case LE_EXPR:
9304               break;
9305             default:
9306               /* Can't be cond = error_mark_node, because we want to preserve
9307                  the location until c_finish_omp_for.  */
9308               cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9309               break;
9310             }
9311           protected_set_expr_location (cond, cond_loc);
9312         }
9313       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9314
9315       /* Parse the increment expression.  */
9316       incr = NULL_TREE;
9317       if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9318         {
9319           location_t incr_loc = c_parser_peek_token (parser)->location;
9320
9321           incr = c_process_expr_stmt (incr_loc,
9322                                       c_parser_expression (parser).value);
9323         }
9324       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9325
9326       if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9327         fail = true;
9328       else
9329         {
9330           TREE_VEC_ELT (declv, i) = decl;
9331           TREE_VEC_ELT (initv, i) = init;
9332           TREE_VEC_ELT (condv, i) = cond;
9333           TREE_VEC_ELT (incrv, i) = incr;
9334         }
9335
9336     parse_next:
9337       if (i == collapse - 1)
9338         break;
9339
9340       /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9341          in between the collapsed for loops to be still considered perfectly
9342          nested.  Hopefully the final version clarifies this.
9343          For now handle (multiple) {'s and empty statements.  */
9344       do
9345         {
9346           if (c_parser_next_token_is_keyword (parser, RID_FOR))
9347             {
9348               c_parser_consume_token (parser);
9349               break;
9350             }
9351           else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9352             {
9353               c_parser_consume_token (parser);
9354               bracecount++;
9355             }
9356           else if (bracecount
9357                    && c_parser_next_token_is (parser, CPP_SEMICOLON))
9358             c_parser_consume_token (parser);
9359           else
9360             {
9361               c_parser_error (parser, "not enough perfectly nested loops");
9362               if (bracecount)
9363                 {
9364                   open_brace_parsed = true;
9365                   bracecount--;
9366                 }
9367               fail = true;
9368               collapse = 0;
9369               break;
9370             }
9371         }
9372       while (1);
9373
9374       nbraces += bracecount;
9375     }
9376
9377   save_break = c_break_label;
9378   c_break_label = size_one_node;
9379   save_cont = c_cont_label;
9380   c_cont_label = NULL_TREE;
9381   body = push_stmt_list ();
9382
9383   if (open_brace_parsed)
9384     {
9385       location_t here = c_parser_peek_token (parser)->location;
9386       stmt = c_begin_compound_stmt (true);
9387       c_parser_compound_statement_nostart (parser);
9388       add_stmt (c_end_compound_stmt (here, stmt, true));
9389     }
9390   else
9391     add_stmt (c_parser_c99_block_statement (parser));
9392   if (c_cont_label)
9393     {
9394       tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9395       SET_EXPR_LOCATION (t, loc);
9396       add_stmt (t);
9397     }
9398
9399   body = pop_stmt_list (body);
9400   c_break_label = save_break;
9401   c_cont_label = save_cont;
9402
9403   while (nbraces)
9404     {
9405       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9406         {
9407           c_parser_consume_token (parser);
9408           nbraces--;
9409         }
9410       else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9411         c_parser_consume_token (parser);
9412       else
9413         {
9414           c_parser_error (parser, "collapsed loops not perfectly nested");
9415           while (nbraces)
9416             {
9417               location_t here = c_parser_peek_token (parser)->location;
9418               stmt = c_begin_compound_stmt (true);
9419               add_stmt (body);
9420               c_parser_compound_statement_nostart (parser);
9421               body = c_end_compound_stmt (here, stmt, true);
9422               nbraces--;
9423             }
9424           goto pop_scopes;
9425         }
9426     }
9427
9428   /* Only bother calling c_finish_omp_for if we haven't already generated
9429      an error from the initialization parsing.  */
9430   if (!fail)
9431     {
9432       stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9433       if (stmt)
9434         {
9435           if (par_clauses != NULL)
9436             {
9437               tree *c;
9438               for (c = par_clauses; *c ; )
9439                 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9440                     && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9441                   c = &OMP_CLAUSE_CHAIN (*c);
9442                 else
9443                   {
9444                     for (i = 0; i < collapse; i++)
9445                       if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9446                         break;
9447                     if (i == collapse)
9448                       c = &OMP_CLAUSE_CHAIN (*c);
9449                     else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9450                       {
9451                         error_at (loc,
9452                                   "iteration variable %qD should not be firstprivate",
9453                                   OMP_CLAUSE_DECL (*c));
9454                         *c = OMP_CLAUSE_CHAIN (*c);
9455                       }
9456                     else
9457                       {
9458                         /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9459                            change it to shared (decl) in
9460                            OMP_PARALLEL_CLAUSES.  */
9461                         tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9462                                                    OMP_CLAUSE_LASTPRIVATE);
9463                         OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9464                         OMP_CLAUSE_CHAIN (l) = clauses;
9465                         clauses = l;
9466                         OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9467                       }
9468                   }
9469             }
9470           OMP_FOR_CLAUSES (stmt) = clauses;
9471         }
9472       ret = stmt;
9473     }
9474 pop_scopes:
9475   while (!VEC_empty (tree, for_block))
9476     {
9477       /* FIXME diagnostics: LOC below should be the actual location of
9478          this particular for block.  We need to build a list of
9479          locations to go along with FOR_BLOCK.  */
9480       stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9481       add_stmt (stmt);
9482     }
9483   release_tree_vector (for_block);
9484   return ret;
9485 }
9486
9487 /* OpenMP 2.5:
9488    #pragma omp for for-clause[optseq] new-line
9489      for-loop
9490
9491    LOC is the location of the #pragma token.
9492 */
9493
9494 #define OMP_FOR_CLAUSE_MASK                             \
9495         ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)             \
9496         | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)        \
9497         | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)         \
9498         | (1u << PRAGMA_OMP_CLAUSE_REDUCTION)           \
9499         | (1u << PRAGMA_OMP_CLAUSE_ORDERED)             \
9500         | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE)            \
9501         | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE)            \
9502         | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9503
9504 static tree
9505 c_parser_omp_for (location_t loc, c_parser *parser)
9506 {
9507   tree block, clauses, ret;
9508
9509   clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9510                                       "#pragma omp for");
9511
9512   block = c_begin_compound_stmt (true);
9513   ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9514   block = c_end_compound_stmt (loc, block, true);
9515   add_stmt (block);
9516
9517   return ret;
9518 }
9519
9520 /* OpenMP 2.5:
9521    # pragma omp master new-line
9522      structured-block
9523
9524    LOC is the location of the #pragma token.
9525 */
9526
9527 static tree
9528 c_parser_omp_master (location_t loc, c_parser *parser)
9529 {
9530   c_parser_skip_to_pragma_eol (parser);
9531   return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9532 }
9533
9534 /* OpenMP 2.5:
9535    # pragma omp ordered new-line
9536      structured-block
9537
9538    LOC is the location of the #pragma itself.
9539 */
9540
9541 static tree
9542 c_parser_omp_ordered (location_t loc, c_parser *parser)
9543 {
9544   c_parser_skip_to_pragma_eol (parser);
9545   return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9546 }
9547
9548 /* OpenMP 2.5:
9549
9550    section-scope:
9551      { section-sequence }
9552
9553    section-sequence:
9554      section-directive[opt] structured-block
9555      section-sequence section-directive structured-block
9556
9557     SECTIONS_LOC is the location of the #pragma omp sections.  */
9558
9559 static tree
9560 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9561 {
9562   tree stmt, substmt;
9563   bool error_suppress = false;
9564   location_t loc;
9565
9566   loc = c_parser_peek_token (parser)->location;
9567   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9568     {
9569       /* Avoid skipping until the end of the block.  */
9570       parser->error = false;
9571       return NULL_TREE;
9572     }
9573
9574   stmt = push_stmt_list ();
9575
9576   if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9577     {
9578       substmt = push_stmt_list ();
9579
9580       while (1)
9581         {
9582           c_parser_statement (parser);
9583
9584           if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9585             break;
9586           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9587             break;
9588           if (c_parser_next_token_is (parser, CPP_EOF))
9589             break;
9590         }
9591
9592       substmt = pop_stmt_list (substmt);
9593       substmt = build1 (OMP_SECTION, void_type_node, substmt);
9594       SET_EXPR_LOCATION (substmt, loc);
9595       add_stmt (substmt);
9596     }
9597
9598   while (1)
9599     {
9600       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9601         break;
9602       if (c_parser_next_token_is (parser, CPP_EOF))
9603         break;
9604
9605       loc = c_parser_peek_token (parser)->location;
9606       if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9607         {
9608           c_parser_consume_pragma (parser);
9609           c_parser_skip_to_pragma_eol (parser);
9610           error_suppress = false;
9611         }
9612       else if (!error_suppress)
9613         {
9614           error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9615           error_suppress = true;
9616         }
9617
9618       substmt = c_parser_omp_structured_block (parser);
9619       substmt = build1 (OMP_SECTION, void_type_node, substmt);
9620       SET_EXPR_LOCATION (substmt, loc);
9621       add_stmt (substmt);
9622     }
9623   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9624                              "expected %<#pragma omp section%> or %<}%>");
9625
9626   substmt = pop_stmt_list (stmt);
9627
9628   stmt = make_node (OMP_SECTIONS);
9629   SET_EXPR_LOCATION (stmt, sections_loc);
9630   TREE_TYPE (stmt) = void_type_node;
9631   OMP_SECTIONS_BODY (stmt) = substmt;
9632
9633   return add_stmt (stmt);
9634 }
9635
9636 /* OpenMP 2.5:
9637    # pragma omp sections sections-clause[optseq] newline
9638      sections-scope
9639
9640    LOC is the location of the #pragma token.
9641 */
9642
9643 #define OMP_SECTIONS_CLAUSE_MASK                        \
9644         ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)             \
9645         | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)        \
9646         | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE)         \
9647         | (1u << PRAGMA_OMP_CLAUSE_REDUCTION)           \
9648         | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9649
9650 static tree
9651 c_parser_omp_sections (location_t loc, c_parser *parser)
9652 {
9653   tree block, clauses, ret;
9654
9655   clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9656                                       "#pragma omp sections");
9657
9658   block = c_begin_compound_stmt (true);
9659   ret = c_parser_omp_sections_scope (loc, parser);
9660   if (ret)
9661     OMP_SECTIONS_CLAUSES (ret) = clauses;
9662   block = c_end_compound_stmt (loc, block, true);
9663   add_stmt (block);
9664
9665   return ret;
9666 }
9667
9668 /* OpenMP 2.5:
9669    # pragma parallel parallel-clause new-line
9670    # pragma parallel for parallel-for-clause new-line
9671    # pragma parallel sections parallel-sections-clause new-line
9672
9673    LOC is the location of the #pragma token.
9674 */
9675
9676 #define OMP_PARALLEL_CLAUSE_MASK                        \
9677         ( (1u << PRAGMA_OMP_CLAUSE_IF)                  \
9678         | (1u << PRAGMA_OMP_CLAUSE_PRIVATE)             \
9679         | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)        \
9680         | (1u << PRAGMA_OMP_CLAUSE_DEFAULT)             \
9681         | (1u << PRAGMA_OMP_CLAUSE_SHARED)              \
9682         | (1u << PRAGMA_OMP_CLAUSE_COPYIN)              \
9683         | (1u << PRAGMA_OMP_CLAUSE_REDUCTION)           \
9684         | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9685
9686 static tree
9687 c_parser_omp_parallel (location_t loc, c_parser *parser)
9688 {
9689   enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9690   const char *p_name = "#pragma omp parallel";
9691   tree stmt, clauses, par_clause, ws_clause, block;
9692   unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9693
9694   if (c_parser_next_token_is_keyword (parser, RID_FOR))
9695     {
9696       c_parser_consume_token (parser);
9697       p_kind = PRAGMA_OMP_PARALLEL_FOR;
9698       p_name = "#pragma omp parallel for";
9699       mask |= OMP_FOR_CLAUSE_MASK;
9700       mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9701     }
9702   else if (c_parser_next_token_is (parser, CPP_NAME))
9703     {
9704       const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9705       if (strcmp (p, "sections") == 0)
9706         {
9707           c_parser_consume_token (parser);
9708           p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9709           p_name = "#pragma omp parallel sections";
9710           mask |= OMP_SECTIONS_CLAUSE_MASK;
9711           mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9712         }
9713     }
9714
9715   clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9716
9717   switch (p_kind)
9718     {
9719     case PRAGMA_OMP_PARALLEL:
9720       block = c_begin_omp_parallel ();
9721       c_parser_statement (parser);
9722       stmt = c_finish_omp_parallel (loc, clauses, block);
9723       break;
9724
9725     case PRAGMA_OMP_PARALLEL_FOR:
9726       block = c_begin_omp_parallel ();
9727       c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9728       c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9729       stmt = c_finish_omp_parallel (loc, par_clause, block);
9730       OMP_PARALLEL_COMBINED (stmt) = 1;
9731       break;
9732
9733     case PRAGMA_OMP_PARALLEL_SECTIONS:
9734       block = c_begin_omp_parallel ();
9735       c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9736       stmt = c_parser_omp_sections_scope (loc, parser);
9737       if (stmt)
9738         OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9739       stmt = c_finish_omp_parallel (loc, par_clause, block);
9740       OMP_PARALLEL_COMBINED (stmt) = 1;
9741       break;
9742
9743     default:
9744       gcc_unreachable ();
9745     }
9746
9747   return stmt;
9748 }
9749
9750 /* OpenMP 2.5:
9751    # pragma omp single single-clause[optseq] new-line
9752      structured-block
9753
9754    LOC is the location of the #pragma.
9755 */
9756
9757 #define OMP_SINGLE_CLAUSE_MASK                          \
9758         ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE)             \
9759         | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)        \
9760         | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE)         \
9761         | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9762
9763 static tree
9764 c_parser_omp_single (location_t loc, c_parser *parser)
9765 {
9766   tree stmt = make_node (OMP_SINGLE);
9767   SET_EXPR_LOCATION (stmt, loc);
9768   TREE_TYPE (stmt) = void_type_node;
9769
9770   OMP_SINGLE_CLAUSES (stmt)
9771     = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9772                                 "#pragma omp single");
9773   OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9774
9775   return add_stmt (stmt);
9776 }
9777
9778 /* OpenMP 3.0:
9779    # pragma omp task task-clause[optseq] new-line
9780
9781    LOC is the location of the #pragma.
9782 */
9783
9784 #define OMP_TASK_CLAUSE_MASK                            \
9785         ( (1u << PRAGMA_OMP_CLAUSE_IF)                  \
9786         | (1u << PRAGMA_OMP_CLAUSE_UNTIED)              \
9787         | (1u << PRAGMA_OMP_CLAUSE_DEFAULT)             \
9788         | (1u << PRAGMA_OMP_CLAUSE_PRIVATE)             \
9789         | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)        \
9790         | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9791
9792 static tree
9793 c_parser_omp_task (location_t loc, c_parser *parser)
9794 {
9795   tree clauses, block;
9796
9797   clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9798                                       "#pragma omp task");
9799
9800   block = c_begin_omp_task ();
9801   c_parser_statement (parser);
9802   return c_finish_omp_task (loc, clauses, block);
9803 }
9804
9805 /* OpenMP 3.0:
9806    # pragma omp taskwait new-line
9807 */
9808
9809 static void
9810 c_parser_omp_taskwait (c_parser *parser)
9811 {
9812   location_t loc = c_parser_peek_token (parser)->location;
9813   c_parser_consume_pragma (parser);
9814   c_parser_skip_to_pragma_eol (parser);
9815
9816   c_finish_omp_taskwait (loc);
9817 }
9818
9819 /* Main entry point to parsing most OpenMP pragmas.  */
9820
9821 static void
9822 c_parser_omp_construct (c_parser *parser)
9823 {
9824   enum pragma_kind p_kind;
9825   location_t loc;
9826   tree stmt;
9827
9828   loc = c_parser_peek_token (parser)->location;
9829   p_kind = c_parser_peek_token (parser)->pragma_kind;
9830   c_parser_consume_pragma (parser);
9831
9832   switch (p_kind)
9833     {
9834     case PRAGMA_OMP_ATOMIC:
9835       c_parser_omp_atomic (loc, parser);
9836       return;
9837     case PRAGMA_OMP_CRITICAL:
9838       stmt = c_parser_omp_critical (loc, parser);
9839       break;
9840     case PRAGMA_OMP_FOR:
9841       stmt = c_parser_omp_for (loc, parser);
9842       break;
9843     case PRAGMA_OMP_MASTER:
9844       stmt = c_parser_omp_master (loc, parser);
9845       break;
9846     case PRAGMA_OMP_ORDERED:
9847       stmt = c_parser_omp_ordered (loc, parser);
9848       break;
9849     case PRAGMA_OMP_PARALLEL:
9850       stmt = c_parser_omp_parallel (loc, parser);
9851       break;
9852     case PRAGMA_OMP_SECTIONS:
9853       stmt = c_parser_omp_sections (loc, parser);
9854       break;
9855     case PRAGMA_OMP_SINGLE:
9856       stmt = c_parser_omp_single (loc, parser);
9857       break;
9858     case PRAGMA_OMP_TASK:
9859       stmt = c_parser_omp_task (loc, parser);
9860       break;
9861     default:
9862       gcc_unreachable ();
9863     }
9864
9865   if (stmt)
9866     gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9867 }
9868
9869
9870 /* OpenMP 2.5:
9871    # pragma omp threadprivate (variable-list) */
9872
9873 static void
9874 c_parser_omp_threadprivate (c_parser *parser)
9875 {
9876   tree vars, t;
9877   location_t loc;
9878
9879   c_parser_consume_pragma (parser);
9880   loc = c_parser_peek_token (parser)->location;
9881   vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9882
9883   /* Mark every variable in VARS to be assigned thread local storage.  */
9884   for (t = vars; t; t = TREE_CHAIN (t))
9885     {
9886       tree v = TREE_PURPOSE (t);
9887
9888       /* FIXME diagnostics: Ideally we should keep individual
9889          locations for all the variables in the var list to make the
9890          following errors more precise.  Perhaps
9891          c_parser_omp_var_list_parens() should construct a list of
9892          locations to go along with the var list.  */
9893
9894       /* If V had already been marked threadprivate, it doesn't matter
9895          whether it had been used prior to this point.  */
9896       if (TREE_CODE (v) != VAR_DECL)
9897         error_at (loc, "%qD is not a variable", v);
9898       else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9899         error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9900       else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9901         error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9902       else if (TREE_TYPE (v) == error_mark_node)
9903         ;
9904       else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9905         error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9906       else
9907         {
9908           if (! DECL_THREAD_LOCAL_P (v))
9909             {
9910               DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9911               /* If rtl has been already set for this var, call
9912                  make_decl_rtl once again, so that encode_section_info
9913                  has a chance to look at the new decl flags.  */
9914               if (DECL_RTL_SET_P (v))
9915                 make_decl_rtl (v);
9916             }
9917           C_DECL_THREADPRIVATE_P (v) = 1;
9918         }
9919     }
9920
9921   c_parser_skip_to_pragma_eol (parser);
9922 }
9923
9924 \f
9925 /* Parse a single source file.  */
9926
9927 void
9928 c_parse_file (void)
9929 {
9930   /* Use local storage to begin.  If the first token is a pragma, parse it.
9931      If it is #pragma GCC pch_preprocess, then this will load a PCH file
9932      which will cause garbage collection.  */
9933   c_parser tparser;
9934
9935   memset (&tparser, 0, sizeof tparser);
9936   the_parser = &tparser;
9937
9938   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9939     c_parser_pragma_pch_preprocess (&tparser);
9940
9941   the_parser = ggc_alloc_c_parser ();
9942   *the_parser = tparser;
9943
9944   /* Initialize EH, if we've been told to do so.  */
9945   if (flag_exceptions)
9946     using_eh_for_cleanups ();
9947
9948   c_parser_translation_unit (the_parser);
9949   the_parser = NULL;
9950 }
9951
9952 #include "gt-c-parser.h"