OSDN Git Service

In gcc/:
[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                  */
258                 if (parser->objc_pq_context)
259                   {
260                     token->type = CPP_KEYWORD;
261                     token->keyword = rid_code;
262                     break;
263                   }
264                 else if (parser->objc_could_be_foreach_context
265                          && rid_code == RID_IN)
266                   {
267                     /* We are in Objective-C, inside a (potential)
268                        foreach context (which means after having
269                        parsed 'for (', but before having parsed ';'),
270                        and we found 'in'.  We consider it the keyword
271                        which terminates the declaration at the
272                        beginning of a foreach-statement.  Note that
273                        this means you can't use 'in' for anything else
274                        in that context; in particular, in Objective-C
275                        you can't use 'in' as the name of the running
276                        variable in a C for loop.  We could potentially
277                        try to add code here to disambiguate, but it
278                        seems a reasonable limitation.
279                     */
280                     token->type = CPP_KEYWORD;
281                     token->keyword = rid_code;
282                     break;
283                   }
284                 /* Else, "pq" keywords outside of the "pq" context are
285                    not keywords, and we fall through to the code for
286                    normal tokens.
287                 */
288               }
289             else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
290               {
291                 /* We found an Objective-C "property attribute" keyword 
292                    (readonly, copies, getter, setter, ivar). These are 
293                    only valid in the property context.  */
294                 if (parser->objc_property_attr_context)
295                   {
296                     token->type = CPP_KEYWORD;
297                     token->keyword = rid_code;
298                     break;
299                   }
300                 /* Else they are not special keywords.
301                 */
302               }
303             else if (c_dialect_objc () 
304                      && (OBJC_IS_AT_KEYWORD (rid_code)
305                          || OBJC_IS_CXX_KEYWORD (rid_code)))
306               {
307                 /* We found one of the Objective-C "@" keywords (defs,
308                    selector, synchronized, etc) or one of the
309                    Objective-C "cxx" keywords (class, private,
310                    protected, public, try, catch, throw) without a
311                    preceding '@' sign.  Do nothing and fall through to
312                    the code for normal tokens (in C++ we would still
313                    consider the CXX ones keywords, but not in C).
314                 */
315                 ;
316               }
317             else
318               {
319                 token->type = CPP_KEYWORD;
320                 token->keyword = rid_code;
321                 break;
322               }
323           }
324
325         decl = lookup_name (token->value);
326         if (decl)
327           {
328             if (TREE_CODE (decl) == TYPE_DECL)
329               {
330                 token->id_kind = C_ID_TYPENAME;
331                 break;
332               }
333           }
334         else if (c_dialect_objc ())
335           {
336             tree objc_interface_decl = objc_is_class_name (token->value);
337             /* Objective-C class names are in the same namespace as
338                variables and typedefs, and hence are shadowed by local
339                declarations.  */
340             if (objc_interface_decl
341                 && (global_bindings_p ()
342                     || (!objc_force_identifier && !decl)))
343               {
344                 token->value = objc_interface_decl;
345                 token->id_kind = C_ID_CLASSNAME;
346                 break;
347               }
348           }
349         token->id_kind = C_ID_ID;
350       }
351       break;
352     case CPP_AT_NAME:
353       /* This only happens in Objective-C; it must be a keyword.  */
354       token->type = CPP_KEYWORD;
355       switch (C_RID_CODE (token->value))
356         {
357           /* Replace 'class' with '@class', 'private' with '@private',
358              etc.  This prevents confusion with the C++ keyword
359              'class', and makes the tokens consistent with other
360              Objective-C 'AT' keywords.  For example '@class' is
361              reported as RID_AT_CLASS which is consistent with
362              '@synchronized', which is reported as
363              RID_AT_SYNCHRONIZED.
364           */
365         case RID_CLASS:     token->keyword = RID_AT_CLASS; break;
366         case RID_PRIVATE:   token->keyword = RID_AT_PRIVATE; break;
367         case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
368         case RID_PUBLIC:    token->keyword = RID_AT_PUBLIC; break;
369         case RID_THROW:     token->keyword = RID_AT_THROW; break;
370         case RID_TRY:       token->keyword = RID_AT_TRY; break;
371         case RID_CATCH:     token->keyword = RID_AT_CATCH; break;
372         default:            token->keyword = C_RID_CODE (token->value);
373         }
374       break;
375     case CPP_COLON:
376     case CPP_COMMA:
377     case CPP_CLOSE_PAREN:
378     case CPP_SEMICOLON:
379       /* These tokens may affect the interpretation of any identifiers
380          following, if doing Objective-C.  */
381       if (c_dialect_objc ())
382         parser->objc_need_raw_identifier = false;
383       break;
384     case CPP_PRAGMA:
385       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
386       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
387       token->value = NULL;
388       break;
389     default:
390       break;
391     }
392   timevar_pop (TV_LEX);
393 }
394
395 /* Return a pointer to the next token from PARSER, reading it in if
396    necessary.  */
397
398 static inline c_token *
399 c_parser_peek_token (c_parser *parser)
400 {
401   if (parser->tokens_avail == 0)
402     {
403       c_lex_one_token (parser, &parser->tokens[0]);
404       parser->tokens_avail = 1;
405     }
406   return &parser->tokens[0];
407 }
408
409 /* Return true if the next token from PARSER has the indicated
410    TYPE.  */
411
412 static inline bool
413 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
414 {
415   return c_parser_peek_token (parser)->type == type;
416 }
417
418 /* Return true if the next token from PARSER does not have the
419    indicated TYPE.  */
420
421 static inline bool
422 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
423 {
424   return !c_parser_next_token_is (parser, type);
425 }
426
427 /* Return true if the next token from PARSER is the indicated
428    KEYWORD.  */
429
430 static inline bool
431 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
432 {
433   return c_parser_peek_token (parser)->keyword == keyword;
434 }
435
436 /* Return a pointer to the next-but-one token from PARSER, reading it
437    in if necessary.  The next token is already read in.  */
438
439 static c_token *
440 c_parser_peek_2nd_token (c_parser *parser)
441 {
442   if (parser->tokens_avail >= 2)
443     return &parser->tokens[1];
444   gcc_assert (parser->tokens_avail == 1);
445   gcc_assert (parser->tokens[0].type != CPP_EOF);
446   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
447   c_lex_one_token (parser, &parser->tokens[1]);
448   parser->tokens_avail = 2;
449   return &parser->tokens[1];
450 }
451
452 /* Return true if TOKEN can start a type name,
453    false otherwise.  */
454 static bool
455 c_token_starts_typename (c_token *token)
456 {
457   switch (token->type)
458     {
459     case CPP_NAME:
460       switch (token->id_kind)
461         {
462         case C_ID_ID:
463           return false;
464         case C_ID_ADDRSPACE:
465           return true;
466         case C_ID_TYPENAME:
467           return true;
468         case C_ID_CLASSNAME:
469           gcc_assert (c_dialect_objc ());
470           return true;
471         default:
472           gcc_unreachable ();
473         }
474     case CPP_KEYWORD:
475       switch (token->keyword)
476         {
477         case RID_UNSIGNED:
478         case RID_LONG:
479         case RID_INT128:
480         case RID_SHORT:
481         case RID_SIGNED:
482         case RID_COMPLEX:
483         case RID_INT:
484         case RID_CHAR:
485         case RID_FLOAT:
486         case RID_DOUBLE:
487         case RID_VOID:
488         case RID_DFLOAT32:
489         case RID_DFLOAT64:
490         case RID_DFLOAT128:
491         case RID_BOOL:
492         case RID_ENUM:
493         case RID_STRUCT:
494         case RID_UNION:
495         case RID_TYPEOF:
496         case RID_CONST:
497         case RID_VOLATILE:
498         case RID_RESTRICT:
499         case RID_ATTRIBUTE:
500         case RID_FRACT:
501         case RID_ACCUM:
502         case RID_SAT:
503           return true;
504         default:
505           return false;
506         }
507     case CPP_LESS:
508       if (c_dialect_objc ())
509         return true;
510       return false;
511     default:
512       return false;
513     }
514 }
515
516 enum c_lookahead_kind {
517   /* Always treat unknown identifiers as typenames.  */
518   cla_prefer_type,
519
520   /* Could be parsing a nonabstract declarator.  Only treat an identifier
521      as a typename if followed by another identifier or a star.  */
522   cla_nonabstract_decl,
523
524   /* Never treat identifiers as typenames.  */
525   cla_prefer_id
526 };
527
528 /* Return true if the next token from PARSER can start a type name,
529    false otherwise.  LA specifies how to do lookahead in order to
530    detect unknown type names.  If unsure, pick CLA_PREFER_ID.  */
531
532 static inline bool
533 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
534 {
535   c_token *token = c_parser_peek_token (parser);
536   if (c_token_starts_typename (token))
537     return true;
538
539   /* Try a bit harder to detect an unknown typename.  */
540   if (la != cla_prefer_id
541       && token->type == CPP_NAME
542       && token->id_kind == C_ID_ID
543
544       /* Do not try too hard when we could have "object in array".  */
545       && !parser->objc_could_be_foreach_context
546
547       && (la == cla_prefer_type
548           || c_parser_peek_2nd_token (parser)->type == CPP_NAME
549           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
550
551       /* Only unknown identifiers.  */
552       && !lookup_name (token->value))
553     return true;
554
555   return false;
556 }
557
558 /* Return true if TOKEN is a type qualifier, false otherwise.  */
559 static bool
560 c_token_is_qualifier (c_token *token)
561 {
562   switch (token->type)
563     {
564     case CPP_NAME:
565       switch (token->id_kind)
566         {
567         case C_ID_ADDRSPACE:
568           return true;
569         default:
570           return false;
571         }
572     case CPP_KEYWORD:
573       switch (token->keyword)
574         {
575         case RID_CONST:
576         case RID_VOLATILE:
577         case RID_RESTRICT:
578         case RID_ATTRIBUTE:
579           return true;
580         default:
581           return false;
582         }
583     case CPP_LESS:
584       return false;
585     default:
586       gcc_unreachable ();
587     }
588 }
589
590 /* Return true if the next token from PARSER is a type qualifier,
591    false otherwise.  */
592 static inline bool
593 c_parser_next_token_is_qualifier (c_parser *parser)
594 {
595   c_token *token = c_parser_peek_token (parser);
596   return c_token_is_qualifier (token);
597 }
598
599 /* Return true if TOKEN can start declaration specifiers, false
600    otherwise.  */
601 static bool
602 c_token_starts_declspecs (c_token *token)
603 {
604   switch (token->type)
605     {
606     case CPP_NAME:
607       switch (token->id_kind)
608         {
609         case C_ID_ID:
610           return false;
611         case C_ID_ADDRSPACE:
612           return true;
613         case C_ID_TYPENAME:
614           return true;
615         case C_ID_CLASSNAME:
616           gcc_assert (c_dialect_objc ());
617           return true;
618         default:
619           gcc_unreachable ();
620         }
621     case CPP_KEYWORD:
622       switch (token->keyword)
623         {
624         case RID_STATIC:
625         case RID_EXTERN:
626         case RID_REGISTER:
627         case RID_TYPEDEF:
628         case RID_INLINE:
629         case RID_AUTO:
630         case RID_THREAD:
631         case RID_UNSIGNED:
632         case RID_LONG:
633         case RID_INT128:
634         case RID_SHORT:
635         case RID_SIGNED:
636         case RID_COMPLEX:
637         case RID_INT:
638         case RID_CHAR:
639         case RID_FLOAT:
640         case RID_DOUBLE:
641         case RID_VOID:
642         case RID_DFLOAT32:
643         case RID_DFLOAT64:
644         case RID_DFLOAT128:
645         case RID_BOOL:
646         case RID_ENUM:
647         case RID_STRUCT:
648         case RID_UNION:
649         case RID_TYPEOF:
650         case RID_CONST:
651         case RID_VOLATILE:
652         case RID_RESTRICT:
653         case RID_ATTRIBUTE:
654         case RID_FRACT:
655         case RID_ACCUM:
656         case RID_SAT:
657           return true;
658         default:
659           return false;
660         }
661     case CPP_LESS:
662       if (c_dialect_objc ())
663         return true;
664       return false;
665     default:
666       return false;
667     }
668 }
669
670
671 /* Return true if TOKEN can start declaration specifiers or a static
672    assertion, false otherwise.  */
673 static bool
674 c_token_starts_declaration (c_token *token)
675 {
676   if (c_token_starts_declspecs (token)
677       || token->keyword == RID_STATIC_ASSERT)
678     return true;
679   else
680     return false;
681 }
682
683 /* Return true if the next token from PARSER can start declaration
684    specifiers, false otherwise.  */
685 static inline bool
686 c_parser_next_token_starts_declspecs (c_parser *parser)
687 {
688   c_token *token = c_parser_peek_token (parser);
689
690   /* In Objective-C, a classname normally starts a declspecs unless it
691      is immediately followed by a dot.  In that case, it is the
692      Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
693      setter/getter on the class.  c_token_starts_declspecs() can't
694      differentiate between the two cases because it only checks the
695      current token, so we have a special check here.  */
696   if (c_dialect_objc () 
697       && token->type == CPP_NAME
698       && token->id_kind == C_ID_CLASSNAME 
699       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
700     return false;
701
702   return c_token_starts_declspecs (token);
703 }
704
705 /* Return true if the next tokens from PARSER can start declaration
706    specifiers or a static assertion, false otherwise.  */
707 static inline bool
708 c_parser_next_tokens_start_declaration (c_parser *parser)
709 {
710   c_token *token = c_parser_peek_token (parser);
711
712   /* Same as above.  */
713   if (c_dialect_objc () 
714       && token->type == CPP_NAME
715       && token->id_kind == C_ID_CLASSNAME 
716       && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
717     return false;
718
719   /* Labels do not start declarations.  */
720   if (token->type == CPP_NAME
721       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
722     return false;
723
724   if (c_token_starts_declaration (token))
725     return true;
726
727   if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
728     return true;
729
730   return false;
731 }
732
733 /* Consume the next token from PARSER.  */
734
735 static void
736 c_parser_consume_token (c_parser *parser)
737 {
738   gcc_assert (parser->tokens_avail >= 1);
739   gcc_assert (parser->tokens[0].type != CPP_EOF);
740   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
741   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
742   if (parser->tokens_avail == 2)
743     parser->tokens[0] = parser->tokens[1];
744   parser->tokens_avail--;
745 }
746
747 /* Expect the current token to be a #pragma.  Consume it and remember
748    that we've begun parsing a pragma.  */
749
750 static void
751 c_parser_consume_pragma (c_parser *parser)
752 {
753   gcc_assert (!parser->in_pragma);
754   gcc_assert (parser->tokens_avail >= 1);
755   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
756   if (parser->tokens_avail == 2)
757     parser->tokens[0] = parser->tokens[1];
758   parser->tokens_avail--;
759   parser->in_pragma = true;
760 }
761
762 /* Update the globals input_location and in_system_header from
763    TOKEN.  */
764 static inline void
765 c_parser_set_source_position_from_token (c_token *token)
766 {
767   if (token->type != CPP_EOF)
768     {
769       input_location = token->location;
770     }
771 }
772
773 /* Issue a diagnostic of the form
774       FILE:LINE: MESSAGE before TOKEN
775    where TOKEN is the next token in the input stream of PARSER.
776    MESSAGE (specified by the caller) is usually of the form "expected
777    OTHER-TOKEN".
778
779    Do not issue a diagnostic if still recovering from an error.
780
781    ??? This is taken from the C++ parser, but building up messages in
782    this way is not i18n-friendly and some other approach should be
783    used.  */
784
785 static void
786 c_parser_error (c_parser *parser, const char *gmsgid)
787 {
788   c_token *token = c_parser_peek_token (parser);
789   if (parser->error)
790     return;
791   parser->error = true;
792   if (!gmsgid)
793     return;
794   /* This diagnostic makes more sense if it is tagged to the line of
795      the token we just peeked at.  */
796   c_parser_set_source_position_from_token (token);
797   c_parse_error (gmsgid,
798                  /* Because c_parse_error does not understand
799                     CPP_KEYWORD, keywords are treated like
800                     identifiers.  */
801                  (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
802                  /* ??? The C parser does not save the cpp flags of a
803                     token, we need to pass 0 here and we will not get
804                     the source spelling of some tokens but rather the
805                     canonical spelling.  */
806                  token->value, /*flags=*/0);
807 }
808
809 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
810    issue the error MSGID.  If MSGID is NULL then a message has already
811    been produced and no message will be produced this time.  Returns
812    true if found, false otherwise.  */
813
814 static bool
815 c_parser_require (c_parser *parser,
816                   enum cpp_ttype type,
817                   const char *msgid)
818 {
819   if (c_parser_next_token_is (parser, type))
820     {
821       c_parser_consume_token (parser);
822       return true;
823     }
824   else
825     {
826       c_parser_error (parser, msgid);
827       return false;
828     }
829 }
830
831 /* If the next token is the indicated keyword, consume it.  Otherwise,
832    issue the error MSGID.  Returns true if found, false otherwise.  */
833
834 static bool
835 c_parser_require_keyword (c_parser *parser,
836                           enum rid keyword,
837                           const char *msgid)
838 {
839   if (c_parser_next_token_is_keyword (parser, keyword))
840     {
841       c_parser_consume_token (parser);
842       return true;
843     }
844   else
845     {
846       c_parser_error (parser, msgid);
847       return false;
848     }
849 }
850
851 /* Like c_parser_require, except that tokens will be skipped until the
852    desired token is found.  An error message is still produced if the
853    next token is not as expected.  If MSGID is NULL then a message has
854    already been produced and no message will be produced this
855    time.  */
856
857 static void
858 c_parser_skip_until_found (c_parser *parser,
859                            enum cpp_ttype type,
860                            const char *msgid)
861 {
862   unsigned nesting_depth = 0;
863
864   if (c_parser_require (parser, type, msgid))
865     return;
866
867   /* Skip tokens until the desired token is found.  */
868   while (true)
869     {
870       /* Peek at the next token.  */
871       c_token *token = c_parser_peek_token (parser);
872       /* If we've reached the token we want, consume it and stop.  */
873       if (token->type == type && !nesting_depth)
874         {
875           c_parser_consume_token (parser);
876           break;
877         }
878
879       /* If we've run out of tokens, stop.  */
880       if (token->type == CPP_EOF)
881         return;
882       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
883         return;
884       if (token->type == CPP_OPEN_BRACE
885           || token->type == CPP_OPEN_PAREN
886           || token->type == CPP_OPEN_SQUARE)
887         ++nesting_depth;
888       else if (token->type == CPP_CLOSE_BRACE
889                || token->type == CPP_CLOSE_PAREN
890                || token->type == CPP_CLOSE_SQUARE)
891         {
892           if (nesting_depth-- == 0)
893             break;
894         }
895       /* Consume this token.  */
896       c_parser_consume_token (parser);
897     }
898   parser->error = false;
899 }
900
901 /* Skip tokens until the end of a parameter is found, but do not
902    consume the comma, semicolon or closing delimiter.  */
903
904 static void
905 c_parser_skip_to_end_of_parameter (c_parser *parser)
906 {
907   unsigned nesting_depth = 0;
908
909   while (true)
910     {
911       c_token *token = c_parser_peek_token (parser);
912       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
913           && !nesting_depth)
914         break;
915       /* If we've run out of tokens, stop.  */
916       if (token->type == CPP_EOF)
917         return;
918       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
919         return;
920       if (token->type == CPP_OPEN_BRACE
921           || token->type == CPP_OPEN_PAREN
922           || token->type == CPP_OPEN_SQUARE)
923         ++nesting_depth;
924       else if (token->type == CPP_CLOSE_BRACE
925                || token->type == CPP_CLOSE_PAREN
926                || token->type == CPP_CLOSE_SQUARE)
927         {
928           if (nesting_depth-- == 0)
929             break;
930         }
931       /* Consume this token.  */
932       c_parser_consume_token (parser);
933     }
934   parser->error = false;
935 }
936
937 /* Expect to be at the end of the pragma directive and consume an
938    end of line marker.  */
939
940 static void
941 c_parser_skip_to_pragma_eol (c_parser *parser)
942 {
943   gcc_assert (parser->in_pragma);
944   parser->in_pragma = false;
945
946   if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
947     while (true)
948       {
949         c_token *token = c_parser_peek_token (parser);
950         if (token->type == CPP_EOF)
951           break;
952         if (token->type == CPP_PRAGMA_EOL)
953           {
954             c_parser_consume_token (parser);
955             break;
956           }
957         c_parser_consume_token (parser);
958       }
959
960   parser->error = false;
961 }
962
963 /* Skip tokens until we have consumed an entire block, or until we
964    have consumed a non-nested ';'.  */
965
966 static void
967 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
968 {
969   unsigned nesting_depth = 0;
970   bool save_error = parser->error;
971
972   while (true)
973     {
974       c_token *token;
975
976       /* Peek at the next token.  */
977       token = c_parser_peek_token (parser);
978
979       switch (token->type)
980         {
981         case CPP_EOF:
982           return;
983
984         case CPP_PRAGMA_EOL:
985           if (parser->in_pragma)
986             return;
987           break;
988
989         case CPP_SEMICOLON:
990           /* If the next token is a ';', we have reached the
991              end of the statement.  */
992           if (!nesting_depth)
993             {
994               /* Consume the ';'.  */
995               c_parser_consume_token (parser);
996               goto finished;
997             }
998           break;
999
1000         case CPP_CLOSE_BRACE:
1001           /* If the next token is a non-nested '}', then we have
1002              reached the end of the current block.  */
1003           if (nesting_depth == 0 || --nesting_depth == 0)
1004             {
1005               c_parser_consume_token (parser);
1006               goto finished;
1007             }
1008           break;
1009
1010         case CPP_OPEN_BRACE:
1011           /* If it the next token is a '{', then we are entering a new
1012              block.  Consume the entire block.  */
1013           ++nesting_depth;
1014           break;
1015
1016         case CPP_PRAGMA:
1017           /* If we see a pragma, consume the whole thing at once.  We
1018              have some safeguards against consuming pragmas willy-nilly.
1019              Normally, we'd expect to be here with parser->error set,
1020              which disables these safeguards.  But it's possible to get
1021              here for secondary error recovery, after parser->error has
1022              been cleared.  */
1023           c_parser_consume_pragma (parser);
1024           c_parser_skip_to_pragma_eol (parser);
1025           parser->error = save_error;
1026           continue;
1027
1028         default:
1029           break;
1030         }
1031
1032       c_parser_consume_token (parser);
1033     }
1034
1035  finished:
1036   parser->error = false;
1037 }
1038
1039 /* CPP's options (initialized by c-opts.c).  */
1040 extern cpp_options *cpp_opts;
1041
1042 /* Save the warning flags which are controlled by __extension__.  */
1043
1044 static inline int
1045 disable_extension_diagnostics (void)
1046 {
1047   int ret = (pedantic
1048              | (warn_pointer_arith << 1)
1049              | (warn_traditional << 2)
1050              | (flag_iso << 3)
1051              | (warn_long_long << 4)
1052              | (warn_cxx_compat << 5));
1053   cpp_opts->cpp_pedantic = pedantic = 0;
1054   warn_pointer_arith = 0;
1055   cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1056   flag_iso = 0;
1057   cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1058   warn_cxx_compat = 0;
1059   return ret;
1060 }
1061
1062 /* Restore the warning flags which are controlled by __extension__.
1063    FLAGS is the return value from disable_extension_diagnostics.  */
1064
1065 static inline void
1066 restore_extension_diagnostics (int flags)
1067 {
1068   cpp_opts->cpp_pedantic = pedantic = flags & 1;
1069   warn_pointer_arith = (flags >> 1) & 1;
1070   cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1071   flag_iso = (flags >> 3) & 1;
1072   cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1073   warn_cxx_compat = (flags >> 5) & 1;
1074 }
1075
1076 /* Possibly kinds of declarator to parse.  */
1077 typedef enum c_dtr_syn {
1078   /* A normal declarator with an identifier.  */
1079   C_DTR_NORMAL,
1080   /* An abstract declarator (maybe empty).  */
1081   C_DTR_ABSTRACT,
1082   /* A parameter declarator: may be either, but after a type name does
1083      not redeclare a typedef name as an identifier if it can
1084      alternatively be interpreted as a typedef name; see DR#009,
1085      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086      following DR#249.  For example, given a typedef T, "int T" and
1087      "int *T" are valid parameter declarations redeclaring T, while
1088      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089      abstract declarators rather than involving redundant parentheses;
1090      the same applies with attributes inside the parentheses before
1091      "T".  */
1092   C_DTR_PARM
1093 } c_dtr_syn;
1094
1095 static void c_parser_external_declaration (c_parser *);
1096 static void c_parser_asm_definition (c_parser *);
1097 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1098                                            bool, bool, tree *);
1099 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1100 static void c_parser_static_assert_declaration (c_parser *);
1101 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1102                                 bool, enum c_lookahead_kind);
1103 static struct c_typespec c_parser_enum_specifier (c_parser *);
1104 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1105 static tree c_parser_struct_declaration (c_parser *);
1106 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1107 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1108                                                  bool *);
1109 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1110                                                         c_dtr_syn, bool *);
1111 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1112                                                               bool,
1113                                                               struct c_declarator *);
1114 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1115 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1116 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1117 static tree c_parser_simple_asm_expr (c_parser *);
1118 static tree c_parser_attributes (c_parser *);
1119 static struct c_type_name *c_parser_type_name (c_parser *);
1120 static struct c_expr c_parser_initializer (c_parser *);
1121 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1122 static void c_parser_initelt (c_parser *, struct obstack *);
1123 static void c_parser_initval (c_parser *, struct c_expr *,
1124                               struct obstack *);
1125 static tree c_parser_compound_statement (c_parser *);
1126 static void c_parser_compound_statement_nostart (c_parser *);
1127 static void c_parser_label (c_parser *);
1128 static void c_parser_statement (c_parser *);
1129 static void c_parser_statement_after_labels (c_parser *);
1130 static void c_parser_if_statement (c_parser *);
1131 static void c_parser_switch_statement (c_parser *);
1132 static void c_parser_while_statement (c_parser *);
1133 static void c_parser_do_statement (c_parser *);
1134 static void c_parser_for_statement (c_parser *);
1135 static tree c_parser_asm_statement (c_parser *);
1136 static tree c_parser_asm_operands (c_parser *, bool);
1137 static tree c_parser_asm_goto_operands (c_parser *);
1138 static tree c_parser_asm_clobbers (c_parser *);
1139 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1140 static struct c_expr c_parser_conditional_expression (c_parser *,
1141                                                       struct c_expr *);
1142 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1143 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1144 static struct c_expr c_parser_unary_expression (c_parser *);
1145 static struct c_expr c_parser_sizeof_expression (c_parser *);
1146 static struct c_expr c_parser_alignof_expression (c_parser *);
1147 static struct c_expr c_parser_postfix_expression (c_parser *);
1148 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1149                                                                    struct c_type_name *,
1150                                                                    location_t);
1151 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1152                                                                 location_t loc,
1153                                                                 struct c_expr);
1154 static struct c_expr c_parser_expression (c_parser *);
1155 static struct c_expr c_parser_expression_conv (c_parser *);
1156 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1157                                          VEC(tree,gc) **);
1158 static void c_parser_omp_construct (c_parser *);
1159 static void c_parser_omp_threadprivate (c_parser *);
1160 static void c_parser_omp_barrier (c_parser *);
1161 static void c_parser_omp_flush (c_parser *);
1162 static void c_parser_omp_taskwait (c_parser *);
1163
1164 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1165 static bool c_parser_pragma (c_parser *, enum pragma_context);
1166
1167 /* These Objective-C parser functions are only ever called when
1168    compiling Objective-C.  */
1169 static void c_parser_objc_class_definition (c_parser *, tree);
1170 static void c_parser_objc_class_instance_variables (c_parser *);
1171 static void c_parser_objc_class_declaration (c_parser *);
1172 static void c_parser_objc_alias_declaration (c_parser *);
1173 static void c_parser_objc_protocol_definition (c_parser *, tree);
1174 static bool c_parser_objc_method_type (c_parser *);
1175 static void c_parser_objc_method_definition (c_parser *);
1176 static void c_parser_objc_methodprotolist (c_parser *);
1177 static void c_parser_objc_methodproto (c_parser *);
1178 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
1179 static tree c_parser_objc_type_name (c_parser *);
1180 static tree c_parser_objc_protocol_refs (c_parser *);
1181 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1182 static void c_parser_objc_synchronized_statement (c_parser *);
1183 static tree c_parser_objc_selector (c_parser *);
1184 static tree c_parser_objc_selector_arg (c_parser *);
1185 static tree c_parser_objc_receiver (c_parser *);
1186 static tree c_parser_objc_message_args (c_parser *);
1187 static tree c_parser_objc_keywordexpr (c_parser *);
1188 static void c_parser_objc_at_property_declaration (c_parser *);
1189 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1190 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1191 static bool c_parser_objc_diagnose_bad_element_prefix
1192   (c_parser *, struct c_declspecs *);
1193
1194 /* Parse a translation unit (C90 6.7, C99 6.9).
1195
1196    translation-unit:
1197      external-declarations
1198
1199    external-declarations:
1200      external-declaration
1201      external-declarations external-declaration
1202
1203    GNU extensions:
1204
1205    translation-unit:
1206      empty
1207 */
1208
1209 static void
1210 c_parser_translation_unit (c_parser *parser)
1211 {
1212   if (c_parser_next_token_is (parser, CPP_EOF))
1213     {
1214       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1215                "ISO C forbids an empty translation unit");
1216     }
1217   else
1218     {
1219       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1220       mark_valid_location_for_stdc_pragma (false);
1221       do
1222         {
1223           ggc_collect ();
1224           c_parser_external_declaration (parser);
1225           obstack_free (&parser_obstack, obstack_position);
1226         }
1227       while (c_parser_next_token_is_not (parser, CPP_EOF));
1228     }
1229 }
1230
1231 /* Parse an external declaration (C90 6.7, C99 6.9).
1232
1233    external-declaration:
1234      function-definition
1235      declaration
1236
1237    GNU extensions:
1238
1239    external-declaration:
1240      asm-definition
1241      ;
1242      __extension__ external-declaration
1243
1244    Objective-C:
1245
1246    external-declaration:
1247      objc-class-definition
1248      objc-class-declaration
1249      objc-alias-declaration
1250      objc-protocol-definition
1251      objc-method-definition
1252      @end
1253 */
1254
1255 static void
1256 c_parser_external_declaration (c_parser *parser)
1257 {
1258   int ext;
1259   switch (c_parser_peek_token (parser)->type)
1260     {
1261     case CPP_KEYWORD:
1262       switch (c_parser_peek_token (parser)->keyword)
1263         {
1264         case RID_EXTENSION:
1265           ext = disable_extension_diagnostics ();
1266           c_parser_consume_token (parser);
1267           c_parser_external_declaration (parser);
1268           restore_extension_diagnostics (ext);
1269           break;
1270         case RID_ASM:
1271           c_parser_asm_definition (parser);
1272           break;
1273         case RID_AT_INTERFACE:
1274         case RID_AT_IMPLEMENTATION:
1275           gcc_assert (c_dialect_objc ());
1276           c_parser_objc_class_definition (parser, NULL_TREE);
1277           break;
1278         case RID_AT_CLASS:
1279           gcc_assert (c_dialect_objc ());
1280           c_parser_objc_class_declaration (parser);
1281           break;
1282         case RID_AT_ALIAS:
1283           gcc_assert (c_dialect_objc ());
1284           c_parser_objc_alias_declaration (parser);
1285           break;
1286         case RID_AT_PROTOCOL:
1287           gcc_assert (c_dialect_objc ());
1288           c_parser_objc_protocol_definition (parser, NULL_TREE);
1289           break;
1290         case RID_AT_PROPERTY:
1291           gcc_assert (c_dialect_objc ());
1292           c_parser_objc_at_property_declaration (parser);
1293           break;
1294         case RID_AT_SYNTHESIZE:
1295           gcc_assert (c_dialect_objc ());
1296           c_parser_objc_at_synthesize_declaration (parser);
1297           break;
1298         case RID_AT_DYNAMIC:
1299           gcc_assert (c_dialect_objc ());
1300           c_parser_objc_at_dynamic_declaration (parser);
1301           break;
1302         case RID_AT_END:
1303           gcc_assert (c_dialect_objc ());
1304           c_parser_consume_token (parser);
1305           objc_finish_implementation ();
1306           break;
1307         default:
1308           goto decl_or_fndef;
1309         }
1310       break;
1311     case CPP_SEMICOLON:
1312       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1313                "ISO C does not allow extra %<;%> outside of a function");
1314       c_parser_consume_token (parser);
1315       break;
1316     case CPP_PRAGMA:
1317       mark_valid_location_for_stdc_pragma (true);
1318       c_parser_pragma (parser, pragma_external);
1319       mark_valid_location_for_stdc_pragma (false);
1320       break;
1321     case CPP_PLUS:
1322     case CPP_MINUS:
1323       if (c_dialect_objc ())
1324         {
1325           c_parser_objc_method_definition (parser);
1326           break;
1327         }
1328       /* Else fall through, and yield a syntax error trying to parse
1329          as a declaration or function definition.  */
1330     default:
1331     decl_or_fndef:
1332       /* A declaration or a function definition (or, in Objective-C,
1333          an @interface or @protocol with prefix attributes).  We can
1334          only tell which after parsing the declaration specifiers, if
1335          any, and the first declarator.  */
1336       c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1337       break;
1338     }
1339 }
1340
1341 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1342    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1343    accepted; otherwise (old-style parameter declarations) only other
1344    declarations are accepted.  If STATIC_ASSERT_OK is true, a static
1345    assertion is accepted; otherwise (old-style parameter declarations)
1346    it is not.  If NESTED is true, we are inside a function or parsing
1347    old-style parameter declarations; any functions encountered are
1348    nested functions and declaration specifiers are required; otherwise
1349    we are at top level and functions are normal functions and
1350    declaration specifiers may be optional.  If EMPTY_OK is true, empty
1351    declarations are OK (subject to all other constraints); otherwise
1352    (old-style parameter declarations) they are diagnosed.  If
1353    START_ATTR_OK is true, the declaration specifiers may start with
1354    attributes; otherwise they may not.
1355    OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1356    declaration when parsing an Objective-C foreach statement.
1357
1358    declaration:
1359      declaration-specifiers init-declarator-list[opt] ;
1360      static_assert-declaration
1361
1362    function-definition:
1363      declaration-specifiers[opt] declarator declaration-list[opt]
1364        compound-statement
1365
1366    declaration-list:
1367      declaration
1368      declaration-list declaration
1369
1370    init-declarator-list:
1371      init-declarator
1372      init-declarator-list , init-declarator
1373
1374    init-declarator:
1375      declarator simple-asm-expr[opt] attributes[opt]
1376      declarator simple-asm-expr[opt] attributes[opt] = initializer
1377
1378    GNU extensions:
1379
1380    nested-function-definition:
1381      declaration-specifiers declarator declaration-list[opt]
1382        compound-statement
1383
1384    Objective-C:
1385      attributes objc-class-definition
1386      attributes objc-category-definition
1387      attributes objc-protocol-definition
1388
1389    The simple-asm-expr and attributes are GNU extensions.
1390
1391    This function does not handle __extension__; that is handled in its
1392    callers.  ??? Following the old parser, __extension__ may start
1393    external declarations, declarations in functions and declarations
1394    at the start of "for" loops, but not old-style parameter
1395    declarations.
1396
1397    C99 requires declaration specifiers in a function definition; the
1398    absence is diagnosed through the diagnosis of implicit int.  In GNU
1399    C we also allow but diagnose declarations without declaration
1400    specifiers, but only at top level (elsewhere they conflict with
1401    other syntax).
1402
1403    In Objective-C, declarations of the looping variable in a foreach
1404    statement are exceptionally terminated by 'in' (for example, 'for
1405    (NSObject *object in array) { ... }').
1406
1407    OpenMP:
1408
1409    declaration:
1410      threadprivate-directive  */
1411
1412 static void
1413 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1414                                bool static_assert_ok, bool empty_ok,
1415                                bool nested, bool start_attr_ok,
1416                                tree *objc_foreach_object_declaration)
1417 {
1418   struct c_declspecs *specs;
1419   tree prefix_attrs;
1420   tree all_prefix_attrs;
1421   bool diagnosed_no_specs = false;
1422   location_t here = c_parser_peek_token (parser)->location;
1423
1424   if (static_assert_ok
1425       && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1426     {
1427       c_parser_static_assert_declaration (parser);
1428       return;
1429     }
1430   specs = build_null_declspecs ();
1431
1432   /* Try to detect an unknown type name when we have "A B" or "A *B".  */
1433   if (c_parser_peek_token (parser)->type == CPP_NAME
1434       && c_parser_peek_token (parser)->id_kind == C_ID_ID
1435       && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1436           || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1437       && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1438     {
1439       error_at (here, "unknown type name %qE",
1440                 c_parser_peek_token (parser)->value);
1441
1442       /* Parse declspecs normally to get a correct pointer type, but avoid
1443          a further "fails to be a type name" error.  Refuse nested functions
1444          since it is not how the user likely wants us to recover.  */
1445       c_parser_peek_token (parser)->type = CPP_KEYWORD;
1446       c_parser_peek_token (parser)->keyword = RID_VOID;
1447       c_parser_peek_token (parser)->value = error_mark_node;
1448       fndef_ok = !nested;
1449     }
1450
1451   c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1452   if (parser->error)
1453     {
1454       c_parser_skip_to_end_of_block_or_statement (parser);
1455       return;
1456     }
1457   if (nested && !specs->declspecs_seen_p)
1458     {
1459       c_parser_error (parser, "expected declaration specifiers");
1460       c_parser_skip_to_end_of_block_or_statement (parser);
1461       return;
1462     }
1463   finish_declspecs (specs);
1464   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1465     {
1466       if (empty_ok)
1467         shadow_tag (specs);
1468       else
1469         {
1470           shadow_tag_warned (specs, 1);
1471           pedwarn (here, 0, "empty declaration");
1472         }
1473       c_parser_consume_token (parser);
1474       return;
1475     }
1476
1477   /* Provide better error recovery.  Note that a type name here is usually
1478      better diagnosed as a redeclaration.  */
1479   if (empty_ok
1480       && specs->typespec_kind == ctsk_tagdef
1481       && c_parser_next_token_starts_declspecs (parser)
1482       && !c_parser_next_token_is (parser, CPP_NAME))
1483     {
1484       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1485       parser->error = false;
1486       shadow_tag_warned (specs, 1);
1487       return;
1488     }
1489   else if (c_dialect_objc ())
1490     {
1491       /* Prefix attributes are an error on method decls.  */
1492       switch (c_parser_peek_token (parser)->type)
1493         {
1494           case CPP_PLUS:
1495           case CPP_MINUS:
1496             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1497               return;
1498             if (specs->attrs)
1499               {
1500                 warning_at (c_parser_peek_token (parser)->location, 
1501                             OPT_Wattributes,
1502                             "prefix attributes are ignored for methods");
1503                 specs->attrs = NULL_TREE;
1504               }
1505             if (fndef_ok)
1506               c_parser_objc_method_definition (parser);
1507             else
1508               c_parser_objc_methodproto (parser);
1509             return;
1510             break;
1511           default:
1512             break;
1513         }
1514       /* This is where we parse 'attributes @interface ...',
1515          'attributes @implementation ...', 'attributes @protocol ...'
1516          (where attributes could be, for example, __attribute__
1517          ((deprecated)).
1518       */
1519       switch (c_parser_peek_token (parser)->keyword)
1520         {
1521         case RID_AT_INTERFACE:
1522           {
1523             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1524               return;
1525             c_parser_objc_class_definition (parser, specs->attrs);
1526             return;
1527           }
1528           break;
1529         case RID_AT_IMPLEMENTATION:
1530           {
1531             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1532               return;
1533             if (specs->attrs)
1534               {
1535                 warning_at (c_parser_peek_token (parser)->location, 
1536                         OPT_Wattributes,
1537                         "prefix attributes are ignored for implementations");
1538                 specs->attrs = NULL_TREE;
1539               }
1540             c_parser_objc_class_definition (parser, NULL_TREE);     
1541             return;
1542           }
1543           break;
1544         case RID_AT_PROTOCOL:
1545           {
1546             if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1547               return;
1548             c_parser_objc_protocol_definition (parser, specs->attrs);
1549             return;
1550           }
1551           break;
1552         case RID_AT_ALIAS:
1553         case RID_AT_CLASS:
1554         case RID_AT_END:
1555         case RID_AT_PROPERTY:
1556           if (specs->attrs)
1557             {
1558               c_parser_error (parser, "unexpected attribute");
1559               specs->attrs = NULL;
1560             }
1561           break;
1562         default:
1563           break;
1564         }
1565     }
1566   
1567   pending_xref_error ();
1568   prefix_attrs = specs->attrs;
1569   all_prefix_attrs = prefix_attrs;
1570   specs->attrs = NULL_TREE;
1571   while (true)
1572     {
1573       struct c_declarator *declarator;
1574       bool dummy = false;
1575       tree fnbody;
1576       /* Declaring either one or more declarators (in which case we
1577          should diagnose if there were no declaration specifiers) or a
1578          function definition (in which case the diagnostic for
1579          implicit int suffices).  */
1580       declarator = c_parser_declarator (parser, 
1581                                         specs->typespec_kind != ctsk_none,
1582                                         C_DTR_NORMAL, &dummy);
1583       if (declarator == NULL)
1584         {
1585           c_parser_skip_to_end_of_block_or_statement (parser);
1586           return;
1587         }
1588       if (c_parser_next_token_is (parser, CPP_EQ)
1589           || c_parser_next_token_is (parser, CPP_COMMA)
1590           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1591           || c_parser_next_token_is_keyword (parser, RID_ASM)
1592           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1593           || c_parser_next_token_is_keyword (parser, RID_IN))
1594         {
1595           tree asm_name = NULL_TREE;
1596           tree postfix_attrs = NULL_TREE;
1597           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1598             {
1599               diagnosed_no_specs = true;
1600               pedwarn (here, 0, "data definition has no type or storage class");
1601             }
1602           /* Having seen a data definition, there cannot now be a
1603              function definition.  */
1604           fndef_ok = false;
1605           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1606             asm_name = c_parser_simple_asm_expr (parser);
1607           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1608             postfix_attrs = c_parser_attributes (parser);
1609           if (c_parser_next_token_is (parser, CPP_EQ))
1610             {
1611               tree d;
1612               struct c_expr init;
1613               location_t init_loc;
1614               c_parser_consume_token (parser);
1615               /* The declaration of the variable is in effect while
1616                  its initializer is parsed.  */
1617               d = start_decl (declarator, specs, true,
1618                               chainon (postfix_attrs, all_prefix_attrs));
1619               if (!d)
1620                 d = error_mark_node;
1621               start_init (d, asm_name, global_bindings_p ());
1622               init_loc = c_parser_peek_token (parser)->location;
1623               init = c_parser_initializer (parser);
1624               finish_init ();
1625               if (d != error_mark_node)
1626                 {
1627                   maybe_warn_string_init (TREE_TYPE (d), init);
1628                   finish_decl (d, init_loc, init.value,
1629                                init.original_type, asm_name);
1630                 }
1631             }
1632           else
1633             {
1634               tree d = start_decl (declarator, specs, false,
1635                                    chainon (postfix_attrs,
1636                                             all_prefix_attrs));
1637               if (d)
1638                 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1639                              NULL_TREE, asm_name);
1640               
1641               if (c_parser_next_token_is_keyword (parser, RID_IN))
1642                 {
1643                   if (d)
1644                     *objc_foreach_object_declaration = d;
1645                   else
1646                     *objc_foreach_object_declaration = error_mark_node;             
1647                 }
1648             }
1649           if (c_parser_next_token_is (parser, CPP_COMMA))
1650             {
1651               c_parser_consume_token (parser);
1652               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1653                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1654                                             prefix_attrs);
1655               else
1656                 all_prefix_attrs = prefix_attrs;
1657               continue;
1658             }
1659           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1660             {
1661               c_parser_consume_token (parser);
1662               return;
1663             }
1664           else if (c_parser_next_token_is_keyword (parser, RID_IN))
1665             {
1666               /* This can only happen in Objective-C: we found the
1667                  'in' that terminates the declaration inside an
1668                  Objective-C foreach statement.  Do not consume the
1669                  token, so that the caller can use it to determine
1670                  that this indeed is a foreach context.  */
1671               return;
1672             }
1673           else
1674             {
1675               c_parser_error (parser, "expected %<,%> or %<;%>");
1676               c_parser_skip_to_end_of_block_or_statement (parser);
1677               return;
1678             }
1679         }
1680       else if (!fndef_ok)
1681         {
1682           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1683                           "%<asm%> or %<__attribute__%>");
1684           c_parser_skip_to_end_of_block_or_statement (parser);
1685           return;
1686         }
1687       /* Function definition (nested or otherwise).  */
1688       if (nested)
1689         {
1690           pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1691           c_push_function_context ();
1692         }
1693       if (!start_function (specs, declarator, all_prefix_attrs))
1694         {
1695           /* This can appear in many cases looking nothing like a
1696              function definition, so we don't give a more specific
1697              error suggesting there was one.  */
1698           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1699                           "or %<__attribute__%>");
1700           if (nested)
1701             c_pop_function_context ();
1702           break;
1703         }
1704       /* Parse old-style parameter declarations.  ??? Attributes are
1705          not allowed to start declaration specifiers here because of a
1706          syntax conflict between a function declaration with attribute
1707          suffix and a function definition with an attribute prefix on
1708          first old-style parameter declaration.  Following the old
1709          parser, they are not accepted on subsequent old-style
1710          parameter declarations either.  However, there is no
1711          ambiguity after the first declaration, nor indeed on the
1712          first as long as we don't allow postfix attributes after a
1713          declarator with a nonempty identifier list in a definition;
1714          and postfix attributes have never been accepted here in
1715          function definitions either.  */
1716       while (c_parser_next_token_is_not (parser, CPP_EOF)
1717              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1718         c_parser_declaration_or_fndef (parser, false, false, false,
1719                                        true, false, NULL);
1720       store_parm_decls ();
1721       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1722         = c_parser_peek_token (parser)->location;
1723       fnbody = c_parser_compound_statement (parser);
1724       if (nested)
1725         {
1726           tree decl = current_function_decl;
1727           /* Mark nested functions as needing static-chain initially.
1728              lower_nested_functions will recompute it but the
1729              DECL_STATIC_CHAIN flag is also used before that happens,
1730              by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1731           DECL_STATIC_CHAIN (decl) = 1;
1732           add_stmt (fnbody);
1733           finish_function ();
1734           c_pop_function_context ();
1735           add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1736         }
1737       else
1738         {
1739           add_stmt (fnbody);
1740           finish_function ();
1741         }
1742       break;
1743     }
1744 }
1745
1746 /* Parse an asm-definition (asm() outside a function body).  This is a
1747    GNU extension.
1748
1749    asm-definition:
1750      simple-asm-expr ;
1751 */
1752
1753 static void
1754 c_parser_asm_definition (c_parser *parser)
1755 {
1756   tree asm_str = c_parser_simple_asm_expr (parser);
1757   if (asm_str)
1758     cgraph_add_asm_node (asm_str);
1759   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1760 }
1761
1762 /* Parse a static assertion (C1X N1425 6.7.10).
1763
1764    static_assert-declaration:
1765      static_assert-declaration-no-semi ;
1766 */
1767
1768 static void
1769 c_parser_static_assert_declaration (c_parser *parser)
1770 {
1771   c_parser_static_assert_declaration_no_semi (parser);
1772   if (parser->error
1773       || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1774     c_parser_skip_to_end_of_block_or_statement (parser);
1775 }
1776
1777 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1778    semicolon.
1779
1780    static_assert-declaration-no-semi:
1781      _Static_assert ( constant-expression , string-literal )
1782 */
1783
1784 static void
1785 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1786 {
1787   location_t assert_loc, value_loc;
1788   tree value;
1789   tree string;
1790
1791   gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1792   assert_loc = c_parser_peek_token (parser)->location;
1793   if (!flag_isoc1x)
1794     {
1795       if (flag_isoc99)
1796         pedwarn (assert_loc, OPT_pedantic,
1797                  "ISO C99 does not support %<_Static_assert%>");
1798       else
1799         pedwarn (assert_loc, OPT_pedantic,
1800                  "ISO C90 does not support %<_Static_assert%>");
1801     }
1802   c_parser_consume_token (parser);
1803   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1804     return;
1805   value_loc = c_parser_peek_token (parser)->location;
1806   value = c_parser_expr_no_commas (parser, NULL).value;
1807   parser->lex_untranslated_string = true;
1808   if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1809     {
1810       parser->lex_untranslated_string = false;
1811       return;
1812     }
1813   switch (c_parser_peek_token (parser)->type)
1814     {
1815     case CPP_STRING:
1816     case CPP_STRING16:
1817     case CPP_STRING32:
1818     case CPP_WSTRING:
1819     case CPP_UTF8STRING:
1820       string = c_parser_peek_token (parser)->value;
1821       c_parser_consume_token (parser);
1822       parser->lex_untranslated_string = false;
1823       break;
1824     default:
1825       c_parser_error (parser, "expected string literal");
1826       parser->lex_untranslated_string = false;
1827       return;
1828     }
1829   c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1830
1831   if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1832     {
1833       error_at (value_loc, "expression in static assertion is not an integer");
1834       return;
1835     }
1836   if (TREE_CODE (value) != INTEGER_CST)
1837     {
1838       value = c_fully_fold (value, false, NULL);
1839       if (TREE_CODE (value) == INTEGER_CST)
1840         pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1841                  "is not an integer constant expression");
1842     }
1843   if (TREE_CODE (value) != INTEGER_CST)
1844     {
1845       error_at (value_loc, "expression in static assertion is not constant");
1846       return;
1847     }
1848   constant_expression_warning (value);
1849   if (integer_zerop (value))
1850     error_at (assert_loc, "static assertion failed: %E", string);
1851 }
1852
1853 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1854    6.7), adding them to SPECS (which may already include some).
1855    Storage class specifiers are accepted iff SCSPEC_OK; type
1856    specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1857    the start iff START_ATTR_OK.
1858
1859    declaration-specifiers:
1860      storage-class-specifier declaration-specifiers[opt]
1861      type-specifier declaration-specifiers[opt]
1862      type-qualifier declaration-specifiers[opt]
1863      function-specifier declaration-specifiers[opt]
1864
1865    Function specifiers (inline) are from C99, and are currently
1866    handled as storage class specifiers, as is __thread.
1867
1868    C90 6.5.1, C99 6.7.1:
1869    storage-class-specifier:
1870      typedef
1871      extern
1872      static
1873      auto
1874      register
1875
1876    C99 6.7.4:
1877    function-specifier:
1878      inline
1879
1880    C90 6.5.2, C99 6.7.2:
1881    type-specifier:
1882      void
1883      char
1884      short
1885      int
1886      long
1887      float
1888      double
1889      signed
1890      unsigned
1891      _Bool
1892      _Complex
1893      [_Imaginary removed in C99 TC2]
1894      struct-or-union-specifier
1895      enum-specifier
1896      typedef-name
1897
1898    (_Bool and _Complex are new in C99.)
1899
1900    C90 6.5.3, C99 6.7.3:
1901
1902    type-qualifier:
1903      const
1904      restrict
1905      volatile
1906      address-space-qualifier
1907
1908    (restrict is new in C99.)
1909
1910    GNU extensions:
1911
1912    declaration-specifiers:
1913      attributes declaration-specifiers[opt]
1914
1915    type-qualifier:
1916      address-space
1917
1918    address-space:
1919      identifier recognized by the target
1920
1921    storage-class-specifier:
1922      __thread
1923
1924    type-specifier:
1925      typeof-specifier
1926      __int128
1927      _Decimal32
1928      _Decimal64
1929      _Decimal128
1930      _Fract
1931      _Accum
1932      _Sat
1933
1934   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1935    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1936
1937    Objective-C:
1938
1939    type-specifier:
1940      class-name objc-protocol-refs[opt]
1941      typedef-name objc-protocol-refs
1942      objc-protocol-refs
1943 */
1944
1945 static void
1946 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1947                     bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1948                     enum c_lookahead_kind la)
1949 {
1950   bool attrs_ok = start_attr_ok;
1951   bool seen_type = specs->typespec_kind != ctsk_none;
1952
1953   if (!typespec_ok)
1954     gcc_assert (la == cla_prefer_id);
1955
1956   while (c_parser_next_token_is (parser, CPP_NAME)
1957          || c_parser_next_token_is (parser, CPP_KEYWORD)
1958          || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1959     {
1960       struct c_typespec t;
1961       tree attrs;
1962       location_t loc = c_parser_peek_token (parser)->location;
1963
1964       /* If we cannot accept a type, exit if the next token must start
1965          one.  Also, if we already have seen a tagged definition,
1966          a typename would be an error anyway and likely the user
1967          has simply forgotten a semicolon, so we exit.  */
1968       if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1969           && c_parser_next_tokens_start_typename (parser, la)
1970           && !c_parser_next_token_is_qualifier (parser))
1971         break;
1972
1973       if (c_parser_next_token_is (parser, CPP_NAME))
1974         {
1975           tree value = c_parser_peek_token (parser)->value;
1976           c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1977
1978           if (kind == C_ID_ADDRSPACE)
1979             {
1980               addr_space_t as
1981                 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1982               declspecs_add_addrspace (specs, as);
1983               c_parser_consume_token (parser);
1984               attrs_ok = true;
1985               continue;
1986             }
1987
1988           gcc_assert (!c_parser_next_token_is_qualifier (parser));
1989
1990           /* If we cannot accept a type, and the next token must start one,
1991              exit.  Do the same if we already have seen a tagged definition,
1992              since it would be an error anyway and likely the user has simply
1993              forgotten a semicolon.  */
1994           if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
1995             break;
1996
1997           /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
1998              a C_ID_CLASSNAME.  */
1999           c_parser_consume_token (parser);
2000           seen_type = true;
2001           attrs_ok = true;
2002           if (kind == C_ID_ID)
2003             {
2004               error ("unknown type name %qE", value);
2005               t.kind = ctsk_typedef;
2006               t.spec = error_mark_node;
2007             }
2008           else if (kind == C_ID_TYPENAME
2009                    && (!c_dialect_objc ()
2010                        || c_parser_next_token_is_not (parser, CPP_LESS)))
2011             {
2012               t.kind = ctsk_typedef;
2013               /* For a typedef name, record the meaning, not the name.
2014                  In case of 'foo foo, bar;'.  */
2015               t.spec = lookup_name (value);
2016             }
2017           else
2018             {
2019               tree proto = NULL_TREE;
2020               gcc_assert (c_dialect_objc ());
2021               t.kind = ctsk_objc;
2022               if (c_parser_next_token_is (parser, CPP_LESS))
2023                 proto = c_parser_objc_protocol_refs (parser);
2024               t.spec = objc_get_protocol_qualified_type (value, proto);
2025             }
2026           t.expr = NULL_TREE;
2027           t.expr_const_operands = true;
2028           declspecs_add_type (loc, specs, t);
2029           continue;
2030         }
2031       if (c_parser_next_token_is (parser, CPP_LESS))
2032         {
2033           /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2034              nisse@lysator.liu.se.  */
2035           tree proto;
2036           gcc_assert (c_dialect_objc ());
2037           if (!typespec_ok || seen_type)
2038             break;
2039           proto = c_parser_objc_protocol_refs (parser);
2040           t.kind = ctsk_objc;
2041           t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2042           t.expr = NULL_TREE;
2043           t.expr_const_operands = true;
2044           declspecs_add_type (loc, specs, t);
2045           continue;
2046         }
2047       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2048       switch (c_parser_peek_token (parser)->keyword)
2049         {
2050         case RID_STATIC:
2051         case RID_EXTERN:
2052         case RID_REGISTER:
2053         case RID_TYPEDEF:
2054         case RID_INLINE:
2055         case RID_AUTO:
2056         case RID_THREAD:
2057           if (!scspec_ok)
2058             goto out;
2059           attrs_ok = true;
2060           /* TODO: Distinguish between function specifiers (inline)
2061              and storage class specifiers, either here or in
2062              declspecs_add_scspec.  */
2063           declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2064           c_parser_consume_token (parser);
2065           break;
2066         case RID_UNSIGNED:
2067         case RID_LONG:
2068         case RID_INT128:
2069         case RID_SHORT:
2070         case RID_SIGNED:
2071         case RID_COMPLEX:
2072         case RID_INT:
2073         case RID_CHAR:
2074         case RID_FLOAT:
2075         case RID_DOUBLE:
2076         case RID_VOID:
2077         case RID_DFLOAT32:
2078         case RID_DFLOAT64:
2079         case RID_DFLOAT128:
2080         case RID_BOOL:
2081         case RID_FRACT:
2082         case RID_ACCUM:
2083         case RID_SAT:
2084           if (!typespec_ok)
2085             goto out;
2086           attrs_ok = true;
2087           seen_type = true;
2088           if (c_dialect_objc ())
2089             parser->objc_need_raw_identifier = true;
2090           t.kind = ctsk_resword;
2091           t.spec = c_parser_peek_token (parser)->value;
2092           t.expr = NULL_TREE;
2093           t.expr_const_operands = true;
2094           declspecs_add_type (loc, specs, t);
2095           c_parser_consume_token (parser);
2096           break;
2097         case RID_ENUM:
2098           if (!typespec_ok)
2099             goto out;
2100           attrs_ok = true;
2101           seen_type = true;
2102           t = c_parser_enum_specifier (parser);
2103           declspecs_add_type (loc, specs, t);
2104           break;
2105         case RID_STRUCT:
2106         case RID_UNION:
2107           if (!typespec_ok)
2108             goto out;
2109           attrs_ok = true;
2110           seen_type = true;
2111           t = c_parser_struct_or_union_specifier (parser);
2112           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2113           declspecs_add_type (loc, specs, t);
2114           break;
2115         case RID_TYPEOF:
2116           /* ??? The old parser rejected typeof after other type
2117              specifiers, but is a syntax error the best way of
2118              handling this?  */
2119           if (!typespec_ok || seen_type)
2120             goto out;
2121           attrs_ok = true;
2122           seen_type = true;
2123           t = c_parser_typeof_specifier (parser);
2124           declspecs_add_type (loc, specs, t);
2125           break;
2126         case RID_CONST:
2127         case RID_VOLATILE:
2128         case RID_RESTRICT:
2129           attrs_ok = true;
2130           declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2131           c_parser_consume_token (parser);
2132           break;
2133         case RID_ATTRIBUTE:
2134           if (!attrs_ok)
2135             goto out;
2136           attrs = c_parser_attributes (parser);
2137           declspecs_add_attrs (specs, attrs);
2138           break;
2139         default:
2140           goto out;
2141         }
2142     }
2143  out: ;
2144 }
2145
2146 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2147
2148    enum-specifier:
2149      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2150      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2151      enum attributes[opt] identifier
2152
2153    The form with trailing comma is new in C99.  The forms with
2154    attributes are GNU extensions.  In GNU C, we accept any expression
2155    without commas in the syntax (assignment expressions, not just
2156    conditional expressions); assignment expressions will be diagnosed
2157    as non-constant.
2158
2159    enumerator-list:
2160      enumerator
2161      enumerator-list , enumerator
2162
2163    enumerator:
2164      enumeration-constant
2165      enumeration-constant = constant-expression
2166 */
2167
2168 static struct c_typespec
2169 c_parser_enum_specifier (c_parser *parser)
2170 {
2171   struct c_typespec ret;
2172   tree attrs;
2173   tree ident = NULL_TREE;
2174   location_t enum_loc;
2175   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2176   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2177   enum_loc = c_parser_peek_token (parser)->location;
2178   c_parser_consume_token (parser);
2179   attrs = c_parser_attributes (parser);
2180   enum_loc = c_parser_peek_token (parser)->location;
2181   /* Set the location in case we create a decl now.  */
2182   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2183   if (c_parser_next_token_is (parser, CPP_NAME))
2184     {
2185       ident = c_parser_peek_token (parser)->value;
2186       ident_loc = c_parser_peek_token (parser)->location;
2187       enum_loc = ident_loc;
2188       c_parser_consume_token (parser);
2189     }
2190   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2191     {
2192       /* Parse an enum definition.  */
2193       struct c_enum_contents the_enum;
2194       tree type = start_enum (enum_loc, &the_enum, ident);
2195       tree postfix_attrs;
2196       /* We chain the enumerators in reverse order, then put them in
2197          forward order at the end.  */
2198       tree values = NULL_TREE;
2199       c_parser_consume_token (parser);
2200       while (true)
2201         {
2202           tree enum_id;
2203           tree enum_value;
2204           tree enum_decl;
2205           bool seen_comma;
2206           c_token *token;
2207           location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
2208           location_t decl_loc, value_loc;
2209           if (c_parser_next_token_is_not (parser, CPP_NAME))
2210             {
2211               c_parser_error (parser, "expected identifier");
2212               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2213               values = error_mark_node;
2214               break;
2215             }
2216           token = c_parser_peek_token (parser);
2217           enum_id = token->value;
2218           /* Set the location in case we create a decl now.  */
2219           c_parser_set_source_position_from_token (token);
2220           decl_loc = value_loc = token->location;
2221           c_parser_consume_token (parser);
2222           if (c_parser_next_token_is (parser, CPP_EQ))
2223             {
2224               c_parser_consume_token (parser);
2225               value_loc = c_parser_peek_token (parser)->location;
2226               enum_value = c_parser_expr_no_commas (parser, NULL).value;
2227             }
2228           else
2229             enum_value = NULL_TREE;
2230           enum_decl = build_enumerator (decl_loc, value_loc,
2231                                         &the_enum, enum_id, enum_value);
2232           TREE_CHAIN (enum_decl) = values;
2233           values = enum_decl;
2234           seen_comma = false;
2235           if (c_parser_next_token_is (parser, CPP_COMMA))
2236             {
2237               comma_loc = c_parser_peek_token (parser)->location;
2238               seen_comma = true;
2239               c_parser_consume_token (parser);
2240             }
2241           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2242             {
2243               if (seen_comma && !flag_isoc99)
2244                 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2245               c_parser_consume_token (parser);
2246               break;
2247             }
2248           if (!seen_comma)
2249             {
2250               c_parser_error (parser, "expected %<,%> or %<}%>");
2251               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2252               values = error_mark_node;
2253               break;
2254             }
2255         }
2256       postfix_attrs = c_parser_attributes (parser);
2257       ret.spec = finish_enum (type, nreverse (values),
2258                               chainon (attrs, postfix_attrs));
2259       ret.kind = ctsk_tagdef;
2260       ret.expr = NULL_TREE;
2261       ret.expr_const_operands = true;
2262       return ret;
2263     }
2264   else if (!ident)
2265     {
2266       c_parser_error (parser, "expected %<{%>");
2267       ret.spec = error_mark_node;
2268       ret.kind = ctsk_tagref;
2269       ret.expr = NULL_TREE;
2270       ret.expr_const_operands = true;
2271       return ret;
2272     }
2273   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2274   /* In ISO C, enumerated types can be referred to only if already
2275      defined.  */
2276   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2277     {
2278       gcc_assert (ident);
2279       pedwarn (enum_loc, OPT_pedantic,
2280                "ISO C forbids forward references to %<enum%> types");
2281     }
2282   return ret;
2283 }
2284
2285 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2286
2287    struct-or-union-specifier:
2288      struct-or-union attributes[opt] identifier[opt]
2289        { struct-contents } attributes[opt]
2290      struct-or-union attributes[opt] identifier
2291
2292    struct-contents:
2293      struct-declaration-list
2294
2295    struct-declaration-list:
2296      struct-declaration ;
2297      struct-declaration-list struct-declaration ;
2298
2299    GNU extensions:
2300
2301    struct-contents:
2302      empty
2303      struct-declaration
2304      struct-declaration-list struct-declaration
2305
2306    struct-declaration-list:
2307      struct-declaration-list ;
2308      ;
2309
2310    (Note that in the syntax here, unlike that in ISO C, the semicolons
2311    are included here rather than in struct-declaration, in order to
2312    describe the syntax with extra semicolons and missing semicolon at
2313    end.)
2314
2315    Objective-C:
2316
2317    struct-declaration-list:
2318      @defs ( class-name )
2319
2320    (Note this does not include a trailing semicolon, but can be
2321    followed by further declarations, and gets a pedwarn-if-pedantic
2322    when followed by a semicolon.)  */
2323
2324 static struct c_typespec
2325 c_parser_struct_or_union_specifier (c_parser *parser)
2326 {
2327   struct c_typespec ret;
2328   tree attrs;
2329   tree ident = NULL_TREE;
2330   location_t struct_loc;
2331   location_t ident_loc = UNKNOWN_LOCATION;
2332   enum tree_code code;
2333   switch (c_parser_peek_token (parser)->keyword)
2334     {
2335     case RID_STRUCT:
2336       code = RECORD_TYPE;
2337       break;
2338     case RID_UNION:
2339       code = UNION_TYPE;
2340       break;
2341     default:
2342       gcc_unreachable ();
2343     }
2344   struct_loc = c_parser_peek_token (parser)->location;
2345   c_parser_consume_token (parser);
2346   attrs = c_parser_attributes (parser);
2347
2348   /* Set the location in case we create a decl now.  */
2349   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2350
2351   if (c_parser_next_token_is (parser, CPP_NAME))
2352     {
2353       ident = c_parser_peek_token (parser)->value;
2354       ident_loc = c_parser_peek_token (parser)->location;
2355       struct_loc = ident_loc;
2356       c_parser_consume_token (parser);
2357     }
2358   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2359     {
2360       /* Parse a struct or union definition.  Start the scope of the
2361          tag before parsing components.  */
2362       struct c_struct_parse_info *struct_info;
2363       tree type = start_struct (struct_loc, code, ident, &struct_info);
2364       tree postfix_attrs;
2365       /* We chain the components in reverse order, then put them in
2366          forward order at the end.  Each struct-declaration may
2367          declare multiple components (comma-separated), so we must use
2368          chainon to join them, although when parsing each
2369          struct-declaration we can use TREE_CHAIN directly.
2370
2371          The theory behind all this is that there will be more
2372          semicolon separated fields than comma separated fields, and
2373          so we'll be minimizing the number of node traversals required
2374          by chainon.  */
2375       tree contents = NULL_TREE;
2376       c_parser_consume_token (parser);
2377       /* Handle the Objective-C @defs construct,
2378          e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
2379       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2380         {
2381           tree name;
2382           gcc_assert (c_dialect_objc ());
2383           c_parser_consume_token (parser);
2384           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2385             goto end_at_defs;
2386           if (c_parser_next_token_is (parser, CPP_NAME)
2387               && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2388             {
2389               name = c_parser_peek_token (parser)->value;
2390               c_parser_consume_token (parser);
2391             }
2392           else
2393             {
2394               c_parser_error (parser, "expected class name");
2395               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2396               goto end_at_defs;
2397             }
2398           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2399                                      "expected %<)%>");
2400           contents = nreverse (objc_get_class_ivars (name));
2401         }
2402     end_at_defs:
2403       /* Parse the struct-declarations and semicolons.  Problems with
2404          semicolons are diagnosed here; empty structures are diagnosed
2405          elsewhere.  */
2406       while (true)
2407         {
2408           tree decls;
2409           /* Parse any stray semicolon.  */
2410           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2411             {
2412               pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2413                        "extra semicolon in struct or union specified");
2414               c_parser_consume_token (parser);
2415               continue;
2416             }
2417           /* Stop if at the end of the struct or union contents.  */
2418           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2419             {
2420               c_parser_consume_token (parser);
2421               break;
2422             }
2423           /* Accept #pragmas at struct scope.  */
2424           if (c_parser_next_token_is (parser, CPP_PRAGMA))
2425             {
2426               c_parser_pragma (parser, pragma_external);
2427               continue;
2428             }
2429           /* Parse some comma-separated declarations, but not the
2430              trailing semicolon if any.  */
2431           decls = c_parser_struct_declaration (parser);
2432           contents = chainon (decls, contents);
2433           /* If no semicolon follows, either we have a parse error or
2434              are at the end of the struct or union and should
2435              pedwarn.  */
2436           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2437             c_parser_consume_token (parser);
2438           else
2439             {
2440               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2441                 pedwarn (c_parser_peek_token (parser)->location, 0,
2442                          "no semicolon at end of struct or union");
2443               else if (parser->error
2444                        || !c_parser_next_token_starts_declspecs (parser))
2445                 {
2446                   c_parser_error (parser, "expected %<;%>");
2447                   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2448                   break;
2449                 }
2450
2451               /* If we come here, we have already emitted an error
2452                  for an expected `;', identifier or `(', and we also
2453                  recovered already.  Go on with the next field. */
2454             }
2455         }
2456       postfix_attrs = c_parser_attributes (parser);
2457       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2458                                 chainon (attrs, postfix_attrs), struct_info);
2459       ret.kind = ctsk_tagdef;
2460       ret.expr = NULL_TREE;
2461       ret.expr_const_operands = true;
2462       return ret;
2463     }
2464   else if (!ident)
2465     {
2466       c_parser_error (parser, "expected %<{%>");
2467       ret.spec = error_mark_node;
2468       ret.kind = ctsk_tagref;
2469       ret.expr = NULL_TREE;
2470       ret.expr_const_operands = true;
2471       return ret;
2472     }
2473   ret = parser_xref_tag (ident_loc, code, ident);
2474   return ret;
2475 }
2476
2477 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2478    the trailing semicolon.
2479
2480    struct-declaration:
2481      specifier-qualifier-list struct-declarator-list
2482      static_assert-declaration-no-semi
2483
2484    specifier-qualifier-list:
2485      type-specifier specifier-qualifier-list[opt]
2486      type-qualifier specifier-qualifier-list[opt]
2487      attributes specifier-qualifier-list[opt]
2488
2489    struct-declarator-list:
2490      struct-declarator
2491      struct-declarator-list , attributes[opt] struct-declarator
2492
2493    struct-declarator:
2494      declarator attributes[opt]
2495      declarator[opt] : constant-expression attributes[opt]
2496
2497    GNU extensions:
2498
2499    struct-declaration:
2500      __extension__ struct-declaration
2501      specifier-qualifier-list
2502
2503    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
2504    of attributes where shown is a GNU extension.  In GNU C, we accept
2505    any expression without commas in the syntax (assignment
2506    expressions, not just conditional expressions); assignment
2507    expressions will be diagnosed as non-constant.  */
2508
2509 static tree
2510 c_parser_struct_declaration (c_parser *parser)
2511 {
2512   struct c_declspecs *specs;
2513   tree prefix_attrs;
2514   tree all_prefix_attrs;
2515   tree decls;
2516   location_t decl_loc;
2517   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2518     {
2519       int ext;
2520       tree decl;
2521       ext = disable_extension_diagnostics ();
2522       c_parser_consume_token (parser);
2523       decl = c_parser_struct_declaration (parser);
2524       restore_extension_diagnostics (ext);
2525       return decl;
2526     }
2527   if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2528     {
2529       c_parser_static_assert_declaration_no_semi (parser);
2530       return NULL_TREE;
2531     }
2532   specs = build_null_declspecs ();
2533   decl_loc = c_parser_peek_token (parser)->location;
2534   c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2535   if (parser->error)
2536     return NULL_TREE;
2537   if (!specs->declspecs_seen_p)
2538     {
2539       c_parser_error (parser, "expected specifier-qualifier-list");
2540       return NULL_TREE;
2541     }
2542   finish_declspecs (specs);
2543   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2544       || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2545     {
2546       tree ret;
2547       if (specs->typespec_kind == ctsk_none)
2548         {
2549           pedwarn (decl_loc, OPT_pedantic,
2550                    "ISO C forbids member declarations with no members");
2551           shadow_tag_warned (specs, pedantic);
2552           ret = NULL_TREE;
2553         }
2554       else
2555         {
2556           /* Support for unnamed structs or unions as members of
2557              structs or unions (which is [a] useful and [b] supports
2558              MS P-SDK).  */
2559           tree attrs = NULL;
2560
2561           ret = grokfield (c_parser_peek_token (parser)->location,
2562                            build_id_declarator (NULL_TREE), specs,
2563                            NULL_TREE, &attrs);
2564           if (ret)
2565             decl_attributes (&ret, attrs, 0);
2566         }
2567       return ret;
2568     }
2569
2570   /* Provide better error recovery.  Note that a type name here is valid,
2571      and will be treated as a field name.  */
2572   if (specs->typespec_kind == ctsk_tagdef
2573       && TREE_CODE (specs->type) != ENUMERAL_TYPE
2574       && c_parser_next_token_starts_declspecs (parser)
2575       && !c_parser_next_token_is (parser, CPP_NAME))
2576     {
2577       c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2578       parser->error = false;
2579       return NULL_TREE;
2580     }
2581
2582   pending_xref_error ();
2583   prefix_attrs = specs->attrs;
2584   all_prefix_attrs = prefix_attrs;
2585   specs->attrs = NULL_TREE;
2586   decls = NULL_TREE;
2587   while (true)
2588     {
2589       /* Declaring one or more declarators or un-named bit-fields.  */
2590       struct c_declarator *declarator;
2591       bool dummy = false;
2592       if (c_parser_next_token_is (parser, CPP_COLON))
2593         declarator = build_id_declarator (NULL_TREE);
2594       else
2595         declarator = c_parser_declarator (parser,
2596                                           specs->typespec_kind != ctsk_none,
2597                                           C_DTR_NORMAL, &dummy);
2598       if (declarator == NULL)
2599         {
2600           c_parser_skip_to_end_of_block_or_statement (parser);
2601           break;
2602         }
2603       if (c_parser_next_token_is (parser, CPP_COLON)
2604           || c_parser_next_token_is (parser, CPP_COMMA)
2605           || c_parser_next_token_is (parser, CPP_SEMICOLON)
2606           || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2607           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2608         {
2609           tree postfix_attrs = NULL_TREE;
2610           tree width = NULL_TREE;
2611           tree d;
2612           if (c_parser_next_token_is (parser, CPP_COLON))
2613             {
2614               c_parser_consume_token (parser);
2615               width = c_parser_expr_no_commas (parser, NULL).value;
2616             }
2617           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2618             postfix_attrs = c_parser_attributes (parser);
2619           d = grokfield (c_parser_peek_token (parser)->location,
2620                          declarator, specs, width, &all_prefix_attrs);
2621           decl_attributes (&d, chainon (postfix_attrs,
2622                                         all_prefix_attrs), 0);
2623           DECL_CHAIN (d) = decls;
2624           decls = d;
2625           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2626             all_prefix_attrs = chainon (c_parser_attributes (parser),
2627                                         prefix_attrs);
2628           else
2629             all_prefix_attrs = prefix_attrs;
2630           if (c_parser_next_token_is (parser, CPP_COMMA))
2631             c_parser_consume_token (parser);
2632           else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2633                    || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2634             {
2635               /* Semicolon consumed in caller.  */
2636               break;
2637             }
2638           else
2639             {
2640               c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2641               break;
2642             }
2643         }
2644       else
2645         {
2646           c_parser_error (parser,
2647                           "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2648                           "%<__attribute__%>");
2649           break;
2650         }
2651     }
2652   return decls;
2653 }
2654
2655 /* Parse a typeof specifier (a GNU extension).
2656
2657    typeof-specifier:
2658      typeof ( expression )
2659      typeof ( type-name )
2660 */
2661
2662 static struct c_typespec
2663 c_parser_typeof_specifier (c_parser *parser)
2664 {
2665   struct c_typespec ret;
2666   ret.kind = ctsk_typeof;
2667   ret.spec = error_mark_node;
2668   ret.expr = NULL_TREE;
2669   ret.expr_const_operands = true;
2670   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2671   c_parser_consume_token (parser);
2672   c_inhibit_evaluation_warnings++;
2673   in_typeof++;
2674   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2675     {
2676       c_inhibit_evaluation_warnings--;
2677       in_typeof--;
2678       return ret;
2679     }
2680   if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2681     {
2682       struct c_type_name *type = c_parser_type_name (parser);
2683       c_inhibit_evaluation_warnings--;
2684       in_typeof--;
2685       if (type != NULL)
2686         {
2687           ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2688           pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2689         }
2690     }
2691   else
2692     {
2693       bool was_vm;
2694       location_t here = c_parser_peek_token (parser)->location;
2695       struct c_expr expr = c_parser_expression (parser);
2696       c_inhibit_evaluation_warnings--;
2697       in_typeof--;
2698       if (TREE_CODE (expr.value) == COMPONENT_REF
2699           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2700         error_at (here, "%<typeof%> applied to a bit-field");
2701       mark_exp_read (expr.value);
2702       ret.spec = TREE_TYPE (expr.value);
2703       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2704       /* This is returned with the type so that when the type is
2705          evaluated, this can be evaluated.  */
2706       if (was_vm)
2707         ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2708       pop_maybe_used (was_vm);
2709     }
2710   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2711   return ret;
2712 }
2713
2714 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2715    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
2716    be redeclared; otherwise it may not.  KIND indicates which kind of
2717    declarator is wanted.  Returns a valid declarator except in the
2718    case of a syntax error in which case NULL is returned.  *SEEN_ID is
2719    set to true if an identifier being declared is seen; this is used
2720    to diagnose bad forms of abstract array declarators and to
2721    determine whether an identifier list is syntactically permitted.
2722
2723    declarator:
2724      pointer[opt] direct-declarator
2725
2726    direct-declarator:
2727      identifier
2728      ( attributes[opt] declarator )
2729      direct-declarator array-declarator
2730      direct-declarator ( parameter-type-list )
2731      direct-declarator ( identifier-list[opt] )
2732
2733    pointer:
2734      * type-qualifier-list[opt]
2735      * type-qualifier-list[opt] pointer
2736
2737    type-qualifier-list:
2738      type-qualifier
2739      attributes
2740      type-qualifier-list type-qualifier
2741      type-qualifier-list attributes
2742
2743    parameter-type-list:
2744      parameter-list
2745      parameter-list , ...
2746
2747    parameter-list:
2748      parameter-declaration
2749      parameter-list , parameter-declaration
2750
2751    parameter-declaration:
2752      declaration-specifiers declarator attributes[opt]
2753      declaration-specifiers abstract-declarator[opt] attributes[opt]
2754
2755    identifier-list:
2756      identifier
2757      identifier-list , identifier
2758
2759    abstract-declarator:
2760      pointer
2761      pointer[opt] direct-abstract-declarator
2762
2763    direct-abstract-declarator:
2764      ( attributes[opt] abstract-declarator )
2765      direct-abstract-declarator[opt] array-declarator
2766      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2767
2768    GNU extensions:
2769
2770    direct-declarator:
2771      direct-declarator ( parameter-forward-declarations
2772                          parameter-type-list[opt] )
2773
2774    direct-abstract-declarator:
2775      direct-abstract-declarator[opt] ( parameter-forward-declarations
2776                                        parameter-type-list[opt] )
2777
2778    parameter-forward-declarations:
2779      parameter-list ;
2780      parameter-forward-declarations parameter-list ;
2781
2782    The uses of attributes shown above are GNU extensions.
2783
2784    Some forms of array declarator are not included in C99 in the
2785    syntax for abstract declarators; these are disallowed elsewhere.
2786    This may be a defect (DR#289).
2787
2788    This function also accepts an omitted abstract declarator as being
2789    an abstract declarator, although not part of the formal syntax.  */
2790
2791 static struct c_declarator *
2792 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2793                      bool *seen_id)
2794 {
2795   /* Parse any initial pointer part.  */
2796   if (c_parser_next_token_is (parser, CPP_MULT))
2797     {
2798       struct c_declspecs *quals_attrs = build_null_declspecs ();
2799       struct c_declarator *inner;
2800       c_parser_consume_token (parser);
2801       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2802       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2803       if (inner == NULL)
2804         return NULL;
2805       else
2806         return make_pointer_declarator (quals_attrs, inner);
2807     }
2808   /* Now we have a direct declarator, direct abstract declarator or
2809      nothing (which counts as a direct abstract declarator here).  */
2810   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2811 }
2812
2813 /* Parse a direct declarator or direct abstract declarator; arguments
2814    as c_parser_declarator.  */
2815
2816 static struct c_declarator *
2817 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2818                             bool *seen_id)
2819 {
2820   /* The direct declarator must start with an identifier (possibly
2821      omitted) or a parenthesized declarator (possibly abstract).  In
2822      an ordinary declarator, initial parentheses must start a
2823      parenthesized declarator.  In an abstract declarator or parameter
2824      declarator, they could start a parenthesized declarator or a
2825      parameter list.  To tell which, the open parenthesis and any
2826      following attributes must be read.  If a declaration specifier
2827      follows, then it is a parameter list; if the specifier is a
2828      typedef name, there might be an ambiguity about redeclaring it,
2829      which is resolved in the direction of treating it as a typedef
2830      name.  If a close parenthesis follows, it is also an empty
2831      parameter list, as the syntax does not permit empty abstract
2832      declarators.  Otherwise, it is a parenthesized declarator (in
2833      which case the analysis may be repeated inside it, recursively).
2834
2835      ??? There is an ambiguity in a parameter declaration "int
2836      (__attribute__((foo)) x)", where x is not a typedef name: it
2837      could be an abstract declarator for a function, or declare x with
2838      parentheses.  The proper resolution of this ambiguity needs
2839      documenting.  At present we follow an accident of the old
2840      parser's implementation, whereby the first parameter must have
2841      some declaration specifiers other than just attributes.  Thus as
2842      a parameter declaration it is treated as a parenthesized
2843      parameter named x, and as an abstract declarator it is
2844      rejected.
2845
2846      ??? Also following the old parser, attributes inside an empty
2847      parameter list are ignored, making it a list not yielding a
2848      prototype, rather than giving an error or making it have one
2849      parameter with implicit type int.
2850
2851      ??? Also following the old parser, typedef names may be
2852      redeclared in declarators, but not Objective-C class names.  */
2853
2854   if (kind != C_DTR_ABSTRACT
2855       && c_parser_next_token_is (parser, CPP_NAME)
2856       && ((type_seen_p
2857            && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2858                || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2859           || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2860     {
2861       struct c_declarator *inner
2862         = build_id_declarator (c_parser_peek_token (parser)->value);
2863       *seen_id = true;
2864       inner->id_loc = c_parser_peek_token (parser)->location;
2865       c_parser_consume_token (parser);
2866       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2867     }
2868
2869   if (kind != C_DTR_NORMAL
2870       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2871     {
2872       struct c_declarator *inner = build_id_declarator (NULL_TREE);
2873       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2874     }
2875
2876   /* Either we are at the end of an abstract declarator, or we have
2877      parentheses.  */
2878
2879   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2880     {
2881       tree attrs;
2882       struct c_declarator *inner;
2883       c_parser_consume_token (parser);
2884       attrs = c_parser_attributes (parser);
2885       if (kind != C_DTR_NORMAL
2886           && (c_parser_next_token_starts_declspecs (parser)
2887               || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2888         {
2889           struct c_arg_info *args
2890             = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2891                                          attrs);
2892           if (args == NULL)
2893             return NULL;
2894           else
2895             {
2896               inner
2897                 = build_function_declarator (args,
2898                                              build_id_declarator (NULL_TREE));
2899               return c_parser_direct_declarator_inner (parser, *seen_id,
2900                                                        inner);
2901             }
2902         }
2903       /* A parenthesized declarator.  */
2904       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2905       if (inner != NULL && attrs != NULL)
2906         inner = build_attrs_declarator (attrs, inner);
2907       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2908         {
2909           c_parser_consume_token (parser);
2910           if (inner == NULL)
2911             return NULL;
2912           else
2913             return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2914         }
2915       else
2916         {
2917           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2918                                      "expected %<)%>");
2919           return NULL;
2920         }
2921     }
2922   else
2923     {
2924       if (kind == C_DTR_NORMAL)
2925         {
2926           c_parser_error (parser, "expected identifier or %<(%>");
2927           return NULL;
2928         }
2929       else
2930         return build_id_declarator (NULL_TREE);
2931     }
2932 }
2933
2934 /* Parse part of a direct declarator or direct abstract declarator,
2935    given that some (in INNER) has already been parsed; ID_PRESENT is
2936    true if an identifier is present, false for an abstract
2937    declarator.  */
2938
2939 static struct c_declarator *
2940 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2941                                   struct c_declarator *inner)
2942 {
2943   /* Parse a sequence of array declarators and parameter lists.  */
2944   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2945     {
2946       location_t brace_loc = c_parser_peek_token (parser)->location;
2947       struct c_declarator *declarator;
2948       struct c_declspecs *quals_attrs = build_null_declspecs ();
2949       bool static_seen;
2950       bool star_seen;
2951       tree dimen;
2952       c_parser_consume_token (parser);
2953       c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2954       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2955       if (static_seen)
2956         c_parser_consume_token (parser);
2957       if (static_seen && !quals_attrs->declspecs_seen_p)
2958         c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2959       if (!quals_attrs->declspecs_seen_p)
2960         quals_attrs = NULL;
2961       /* If "static" is present, there must be an array dimension.
2962          Otherwise, there may be a dimension, "*", or no
2963          dimension.  */
2964       if (static_seen)
2965         {
2966           star_seen = false;
2967           dimen = c_parser_expr_no_commas (parser, NULL).value;
2968         }
2969       else
2970         {
2971           if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2972             {
2973               dimen = NULL_TREE;
2974               star_seen = false;
2975             }
2976           else if (c_parser_next_token_is (parser, CPP_MULT))
2977             {
2978               if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2979                 {
2980                   dimen = NULL_TREE;
2981                   star_seen = true;
2982                   c_parser_consume_token (parser);
2983                 }
2984               else
2985                 {
2986                   star_seen = false;
2987                   dimen = c_parser_expr_no_commas (parser, NULL).value;
2988                 }
2989             }
2990           else
2991             {
2992               star_seen = false;
2993               dimen = c_parser_expr_no_commas (parser, NULL).value;
2994             }
2995         }
2996       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2997         c_parser_consume_token (parser);
2998       else
2999         {
3000           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3001                                      "expected %<]%>");
3002           return NULL;
3003         }
3004       if (dimen)
3005         mark_exp_read (dimen);
3006       declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3007                                            static_seen, star_seen);
3008       if (declarator == NULL)
3009         return NULL;
3010       inner = set_array_declarator_inner (declarator, inner);
3011       return c_parser_direct_declarator_inner (parser, id_present, inner);
3012     }
3013   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3014     {
3015       tree attrs;
3016       struct c_arg_info *args;
3017       c_parser_consume_token (parser);
3018       attrs = c_parser_attributes (parser);
3019       args = c_parser_parms_declarator (parser, id_present, attrs);
3020       if (args == NULL)
3021         return NULL;
3022       else
3023         {
3024           inner = build_function_declarator (args, inner);
3025           return c_parser_direct_declarator_inner (parser, id_present, inner);
3026         }
3027     }
3028   return inner;
3029 }
3030
3031 /* Parse a parameter list or identifier list, including the closing
3032    parenthesis but not the opening one.  ATTRS are the attributes at
3033    the start of the list.  ID_LIST_OK is true if an identifier list is
3034    acceptable; such a list must not have attributes at the start.  */
3035
3036 static struct c_arg_info *
3037 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3038 {
3039   push_scope ();
3040   declare_parm_level ();
3041   /* If the list starts with an identifier, it is an identifier list.
3042      Otherwise, it is either a prototype list or an empty list.  */
3043   if (id_list_ok
3044       && !attrs
3045       && c_parser_next_token_is (parser, CPP_NAME)
3046       && c_parser_peek_token (parser)->id_kind == C_ID_ID
3047       
3048       /* Look ahead to detect typos in type names.  */
3049       && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3050       && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3051       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3052       && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3053     {
3054       tree list = NULL_TREE, *nextp = &list;
3055       while (c_parser_next_token_is (parser, CPP_NAME)
3056              && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3057         {
3058           *nextp = build_tree_list (NULL_TREE,
3059                                     c_parser_peek_token (parser)->value);
3060           nextp = & TREE_CHAIN (*nextp);
3061           c_parser_consume_token (parser);
3062           if (c_parser_next_token_is_not (parser, CPP_COMMA))
3063             break;
3064           c_parser_consume_token (parser);
3065           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3066             {
3067               c_parser_error (parser, "expected identifier");
3068               break;
3069             }
3070         }
3071       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3072         {
3073           struct c_arg_info *ret = build_arg_info ();
3074           ret->types = list;
3075           c_parser_consume_token (parser);
3076           pop_scope ();
3077           return ret;
3078         }
3079       else
3080         {
3081           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3082                                      "expected %<)%>");
3083           pop_scope ();
3084           return NULL;
3085         }
3086     }
3087   else
3088     {
3089       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
3090       pop_scope ();
3091       return ret;
3092     }
3093 }
3094
3095 /* Parse a parameter list (possibly empty), including the closing
3096    parenthesis but not the opening one.  ATTRS are the attributes at
3097    the start of the list.  */
3098
3099 static struct c_arg_info *
3100 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
3101 {
3102   bool bad_parm = false;
3103   /* ??? Following the old parser, forward parameter declarations may
3104      use abstract declarators, and if no real parameter declarations
3105      follow the forward declarations then this is not diagnosed.  Also
3106      note as above that attributes are ignored as the only contents of
3107      the parentheses, or as the only contents after forward
3108      declarations.  */
3109   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3110     {
3111       struct c_arg_info *ret = build_arg_info ();
3112       c_parser_consume_token (parser);
3113       return ret;
3114     }
3115   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3116     {
3117       struct c_arg_info *ret = build_arg_info ();
3118       /* Suppress -Wold-style-definition for this case.  */
3119       ret->types = error_mark_node;
3120       error_at (c_parser_peek_token (parser)->location,
3121                 "ISO C requires a named argument before %<...%>");
3122       c_parser_consume_token (parser);
3123       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3124         {
3125           c_parser_consume_token (parser);
3126           return ret;
3127         }
3128       else
3129         {
3130           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3131                                      "expected %<)%>");
3132           return NULL;
3133         }
3134     }
3135   /* Nonempty list of parameters, either terminated with semicolon
3136      (forward declarations; recurse) or with close parenthesis (normal
3137      function) or with ", ... )" (variadic function).  */
3138   while (true)
3139     {
3140       /* Parse a parameter.  */
3141       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3142       attrs = NULL_TREE;
3143       if (parm == NULL)
3144         bad_parm = true;
3145       else
3146         push_parm_decl (parm);
3147       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3148         {
3149           tree new_attrs;
3150           c_parser_consume_token (parser);
3151           mark_forward_parm_decls ();
3152           new_attrs = c_parser_attributes (parser);
3153           return c_parser_parms_list_declarator (parser, new_attrs);
3154         }
3155       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3156         {
3157           c_parser_consume_token (parser);
3158           if (bad_parm)
3159             {
3160               get_pending_sizes ();
3161               return NULL;
3162             }
3163           else
3164             return get_parm_info (false);
3165         }
3166       if (!c_parser_require (parser, CPP_COMMA,
3167                              "expected %<;%>, %<,%> or %<)%>"))
3168         {
3169           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3170           get_pending_sizes ();
3171           return NULL;
3172         }
3173       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3174         {
3175           c_parser_consume_token (parser);
3176           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3177             {
3178               c_parser_consume_token (parser);
3179               if (bad_parm)
3180                 {
3181                   get_pending_sizes ();
3182                   return NULL;
3183                 }
3184               else
3185                 return get_parm_info (true);
3186             }
3187           else
3188             {
3189               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3190                                          "expected %<)%>");
3191               get_pending_sizes ();
3192               return NULL;
3193             }
3194         }
3195     }
3196 }
3197
3198 /* Parse a parameter declaration.  ATTRS are the attributes at the
3199    start of the declaration if it is the first parameter.  */
3200
3201 static struct c_parm *
3202 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3203 {
3204   struct c_declspecs *specs;
3205   struct c_declarator *declarator;
3206   tree prefix_attrs;
3207   tree postfix_attrs = NULL_TREE;
3208   bool dummy = false;
3209   if (!c_parser_next_token_starts_declspecs (parser))
3210     {
3211       c_token *token = c_parser_peek_token (parser);
3212       if (parser->error)
3213         return NULL;
3214       c_parser_set_source_position_from_token (token);
3215       if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3216         {
3217           error ("unknown type name %qE", token->value);
3218           parser->error = true;
3219         }
3220       /* ??? In some Objective-C cases '...' isn't applicable so there
3221          should be a different message.  */
3222       else
3223         c_parser_error (parser,
3224                         "expected declaration specifiers or %<...%>");
3225       c_parser_skip_to_end_of_parameter (parser);
3226       return NULL;
3227     }
3228   specs = build_null_declspecs ();
3229   if (attrs)
3230     {
3231       declspecs_add_attrs (specs, attrs);
3232       attrs = NULL_TREE;
3233     }
3234   c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3235   finish_declspecs (specs);
3236   pending_xref_error ();
3237   prefix_attrs = specs->attrs;
3238   specs->attrs = NULL_TREE;
3239   declarator = c_parser_declarator (parser,
3240                                     specs->typespec_kind != ctsk_none,
3241                                     C_DTR_PARM, &dummy);
3242   if (declarator == NULL)
3243     {
3244       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3245       return NULL;
3246     }
3247   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3248     postfix_attrs = c_parser_attributes (parser);
3249   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3250                        declarator);
3251 }
3252
3253 /* Parse a string literal in an asm expression.  It should not be
3254    translated, and wide string literals are an error although
3255    permitted by the syntax.  This is a GNU extension.
3256
3257    asm-string-literal:
3258      string-literal
3259
3260    ??? At present, following the old parser, the caller needs to have
3261    set lex_untranslated_string to 1.  It would be better to follow the
3262    C++ parser rather than using this kludge.  */
3263
3264 static tree
3265 c_parser_asm_string_literal (c_parser *parser)
3266 {
3267   tree str;
3268   if (c_parser_next_token_is (parser, CPP_STRING))
3269     {
3270       str = c_parser_peek_token (parser)->value;
3271       c_parser_consume_token (parser);
3272     }
3273   else if (c_parser_next_token_is (parser, CPP_WSTRING))
3274     {
3275       error_at (c_parser_peek_token (parser)->location,
3276                 "wide string literal in %<asm%>");
3277       str = build_string (1, "");
3278       c_parser_consume_token (parser);
3279     }
3280   else
3281     {
3282       c_parser_error (parser, "expected string literal");
3283       str = NULL_TREE;
3284     }
3285   return str;
3286 }
3287
3288 /* Parse a simple asm expression.  This is used in restricted
3289    contexts, where a full expression with inputs and outputs does not
3290    make sense.  This is a GNU extension.
3291
3292    simple-asm-expr:
3293      asm ( asm-string-literal )
3294 */
3295
3296 static tree
3297 c_parser_simple_asm_expr (c_parser *parser)
3298 {
3299   tree str;
3300   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3301   /* ??? Follow the C++ parser rather than using the
3302      lex_untranslated_string kludge.  */
3303   parser->lex_untranslated_string = true;
3304   c_parser_consume_token (parser);
3305   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3306     {
3307       parser->lex_untranslated_string = false;
3308       return NULL_TREE;
3309     }
3310   str = c_parser_asm_string_literal (parser);
3311   parser->lex_untranslated_string = false;
3312   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3313     {
3314       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3315       return NULL_TREE;
3316     }
3317   return str;
3318 }
3319
3320 /* Parse (possibly empty) attributes.  This is a GNU extension.
3321
3322    attributes:
3323      empty
3324      attributes attribute
3325
3326    attribute:
3327      __attribute__ ( ( attribute-list ) )
3328
3329    attribute-list:
3330      attrib
3331      attribute_list , attrib
3332
3333    attrib:
3334      empty
3335      any-word
3336      any-word ( identifier )
3337      any-word ( identifier , nonempty-expr-list )
3338      any-word ( expr-list )
3339
3340    where the "identifier" must not be declared as a type, and
3341    "any-word" may be any identifier (including one declared as a
3342    type), a reserved word storage class specifier, type specifier or
3343    type qualifier.  ??? This still leaves out most reserved keywords
3344    (following the old parser), shouldn't we include them, and why not
3345    allow identifiers declared as types to start the arguments?  */
3346
3347 static tree
3348 c_parser_attributes (c_parser *parser)
3349 {
3350   tree attrs = NULL_TREE;
3351   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3352     {
3353       /* ??? Follow the C++ parser rather than using the
3354          lex_untranslated_string kludge.  */
3355       parser->lex_untranslated_string = true;
3356       c_parser_consume_token (parser);
3357       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3358         {
3359           parser->lex_untranslated_string = false;
3360           return attrs;
3361         }
3362       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3363         {
3364           parser->lex_untranslated_string = false;
3365           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3366           return attrs;
3367         }
3368       /* Parse the attribute list.  */
3369       while (c_parser_next_token_is (parser, CPP_COMMA)
3370              || c_parser_next_token_is (parser, CPP_NAME)
3371              || c_parser_next_token_is (parser, CPP_KEYWORD))
3372         {
3373           tree attr, attr_name, attr_args;
3374           VEC(tree,gc) *expr_list;
3375           if (c_parser_next_token_is (parser, CPP_COMMA))
3376             {
3377               c_parser_consume_token (parser);
3378               continue;
3379             }
3380           if (c_parser_next_token_is (parser, CPP_KEYWORD))
3381             {
3382               /* ??? See comment above about what keywords are
3383                  accepted here.  */
3384               bool ok;
3385               switch (c_parser_peek_token (parser)->keyword)
3386                 {
3387                 case RID_STATIC:
3388                 case RID_UNSIGNED:
3389                 case RID_LONG:
3390                 case RID_INT128:
3391                 case RID_CONST:
3392                 case RID_EXTERN:
3393                 case RID_REGISTER:
3394                 case RID_TYPEDEF:
3395                 case RID_SHORT:
3396                 case RID_INLINE:
3397                 case RID_VOLATILE:
3398                 case RID_SIGNED:
3399                 case RID_AUTO:
3400                 case RID_RESTRICT:
3401                 case RID_COMPLEX:
3402                 case RID_THREAD:
3403                 case RID_INT:
3404                 case RID_CHAR:
3405                 case RID_FLOAT:
3406                 case RID_DOUBLE:
3407                 case RID_VOID:
3408                 case RID_DFLOAT32:
3409                 case RID_DFLOAT64:
3410                 case RID_DFLOAT128:
3411                 case RID_BOOL:
3412                 case RID_FRACT:
3413                 case RID_ACCUM:
3414                 case RID_SAT:
3415                   ok = true;
3416                   break;
3417                 default:
3418                   ok = false;
3419                   break;
3420                 }
3421               if (!ok)
3422                 break;
3423               /* Accept __attribute__((__const)) as __attribute__((const))
3424                  etc.  */
3425               attr_name
3426                 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3427             }
3428           else
3429             attr_name = c_parser_peek_token (parser)->value;
3430           c_parser_consume_token (parser);
3431           if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3432             {
3433               attr = build_tree_list (attr_name, NULL_TREE);
3434               attrs = chainon (attrs, attr);
3435               continue;
3436             }
3437           c_parser_consume_token (parser);
3438           /* Parse the attribute contents.  If they start with an
3439              identifier which is followed by a comma or close
3440              parenthesis, then the arguments start with that
3441              identifier; otherwise they are an expression list.  
3442              In objective-c the identifier may be a classname.  */
3443           if (c_parser_next_token_is (parser, CPP_NAME)
3444               && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3445                   || (c_dialect_objc () 
3446                       && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3447               && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3448                   || (c_parser_peek_2nd_token (parser)->type
3449                       == CPP_CLOSE_PAREN)))
3450             {
3451               tree arg1 = c_parser_peek_token (parser)->value;
3452               c_parser_consume_token (parser);
3453               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3454                 attr_args = build_tree_list (NULL_TREE, arg1);
3455               else
3456                 {
3457                   tree tree_list;
3458                   c_parser_consume_token (parser);
3459                   expr_list = c_parser_expr_list (parser, false, true, NULL);
3460                   tree_list = build_tree_list_vec (expr_list);
3461                   attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3462                   release_tree_vector (expr_list);
3463                 }
3464             }
3465           else
3466             {
3467               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3468                 attr_args = NULL_TREE;
3469               else
3470                 {
3471                   expr_list = c_parser_expr_list (parser, false, true, NULL);
3472                   attr_args = build_tree_list_vec (expr_list);
3473                   release_tree_vector (expr_list);
3474                 }
3475             }
3476           attr = build_tree_list (attr_name, attr_args);
3477           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3478             c_parser_consume_token (parser);
3479           else
3480             {
3481               parser->lex_untranslated_string = false;
3482               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3483                                          "expected %<)%>");
3484               return attrs;
3485             }
3486           attrs = chainon (attrs, attr);
3487         }
3488       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3489         c_parser_consume_token (parser);
3490       else
3491         {
3492           parser->lex_untranslated_string = false;
3493           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3494                                      "expected %<)%>");
3495           return attrs;
3496         }
3497       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3498         c_parser_consume_token (parser);
3499       else
3500         {
3501           parser->lex_untranslated_string = false;
3502           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3503                                      "expected %<)%>");
3504           return attrs;
3505         }
3506       parser->lex_untranslated_string = false;
3507     }
3508   return attrs;
3509 }
3510
3511 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3512
3513    type-name:
3514      specifier-qualifier-list abstract-declarator[opt]
3515 */
3516
3517 static struct c_type_name *
3518 c_parser_type_name (c_parser *parser)
3519 {
3520   struct c_declspecs *specs = build_null_declspecs ();
3521   struct c_declarator *declarator;
3522   struct c_type_name *ret;
3523   bool dummy = false;
3524   c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3525   if (!specs->declspecs_seen_p)
3526     {
3527       c_parser_error (parser, "expected specifier-qualifier-list");
3528       return NULL;
3529     }
3530   if (specs->type != error_mark_node)
3531     {
3532       pending_xref_error ();
3533       finish_declspecs (specs);
3534     }
3535   declarator = c_parser_declarator (parser,
3536                                     specs->typespec_kind != ctsk_none,
3537                                     C_DTR_ABSTRACT, &dummy);
3538   if (declarator == NULL)
3539     return NULL;
3540   ret = XOBNEW (&parser_obstack, struct c_type_name);
3541   ret->specs = specs;
3542   ret->declarator = declarator;
3543   return ret;
3544 }
3545
3546 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3547
3548    initializer:
3549      assignment-expression
3550      { initializer-list }
3551      { initializer-list , }
3552
3553    initializer-list:
3554      designation[opt] initializer
3555      initializer-list , designation[opt] initializer
3556
3557    designation:
3558      designator-list =
3559
3560    designator-list:
3561      designator
3562      designator-list designator
3563
3564    designator:
3565      array-designator
3566      . identifier
3567
3568    array-designator:
3569      [ constant-expression ]
3570
3571    GNU extensions:
3572
3573    initializer:
3574      { }
3575
3576    designation:
3577      array-designator
3578      identifier :
3579
3580    array-designator:
3581      [ constant-expression ... constant-expression ]
3582
3583    Any expression without commas is accepted in the syntax for the
3584    constant-expressions, with non-constant expressions rejected later.
3585
3586    This function is only used for top-level initializers; for nested
3587    ones, see c_parser_initval.  */
3588
3589 static struct c_expr
3590 c_parser_initializer (c_parser *parser)
3591 {
3592   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3593     return c_parser_braced_init (parser, NULL_TREE, false);
3594   else
3595     {
3596       struct c_expr ret;
3597       location_t loc = c_parser_peek_token (parser)->location;
3598       ret = c_parser_expr_no_commas (parser, NULL);
3599       if (TREE_CODE (ret.value) != STRING_CST
3600           && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3601         ret = default_function_array_read_conversion (loc, ret);
3602       return ret;
3603     }
3604 }
3605
3606 /* Parse a braced initializer list.  TYPE is the type specified for a
3607    compound literal, and NULL_TREE for other initializers and for
3608    nested braced lists.  NESTED_P is true for nested braced lists,
3609    false for the list of a compound literal or the list that is the
3610    top-level initializer in a declaration.  */
3611
3612 static struct c_expr
3613 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3614 {
3615   struct c_expr ret;
3616   struct obstack braced_init_obstack;
3617   location_t brace_loc = c_parser_peek_token (parser)->location;
3618   gcc_obstack_init (&braced_init_obstack);
3619   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3620   c_parser_consume_token (parser);
3621   if (nested_p)
3622     push_init_level (0, &braced_init_obstack);
3623   else
3624     really_start_incremental_init (type);
3625   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3626     {
3627       pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3628     }
3629   else
3630     {
3631       /* Parse a non-empty initializer list, possibly with a trailing
3632          comma.  */
3633       while (true)
3634         {
3635           c_parser_initelt (parser, &braced_init_obstack);
3636           if (parser->error)
3637             break;
3638           if (c_parser_next_token_is (parser, CPP_COMMA))
3639             c_parser_consume_token (parser);
3640           else
3641             break;
3642           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3643             break;
3644         }
3645     }
3646   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3647     {
3648       ret.value = error_mark_node;
3649       ret.original_code = ERROR_MARK;
3650       ret.original_type = NULL;
3651       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3652       pop_init_level (0, &braced_init_obstack);
3653       obstack_free (&braced_init_obstack, NULL);
3654       return ret;
3655     }
3656   c_parser_consume_token (parser);
3657   ret = pop_init_level (0, &braced_init_obstack);
3658   obstack_free (&braced_init_obstack, NULL);
3659   return ret;
3660 }
3661
3662 /* Parse a nested initializer, including designators.  */
3663
3664 static void
3665 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3666 {
3667   /* Parse any designator or designator list.  A single array
3668      designator may have the subsequent "=" omitted in GNU C, but a
3669      longer list or a structure member designator may not.  */
3670   if (c_parser_next_token_is (parser, CPP_NAME)
3671       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3672     {
3673       /* Old-style structure member designator.  */
3674       set_init_label (c_parser_peek_token (parser)->value,
3675                       braced_init_obstack);
3676       /* Use the colon as the error location.  */
3677       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3678                "obsolete use of designated initializer with %<:%>");
3679       c_parser_consume_token (parser);
3680       c_parser_consume_token (parser);
3681     }
3682   else
3683     {
3684       /* des_seen is 0 if there have been no designators, 1 if there
3685          has been a single array designator and 2 otherwise.  */
3686       int des_seen = 0;
3687       /* Location of a designator.  */
3688       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3689       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3690              || c_parser_next_token_is (parser, CPP_DOT))
3691         {
3692           int des_prev = des_seen;
3693           if (!des_seen)
3694             des_loc = c_parser_peek_token (parser)->location;
3695           if (des_seen < 2)
3696             des_seen++;
3697           if (c_parser_next_token_is (parser, CPP_DOT))
3698             {
3699               des_seen = 2;
3700               c_parser_consume_token (parser);
3701               if (c_parser_next_token_is (parser, CPP_NAME))
3702                 {
3703                   set_init_label (c_parser_peek_token (parser)->value,
3704                                   braced_init_obstack);
3705                   c_parser_consume_token (parser);
3706                 }
3707               else
3708                 {
3709                   struct c_expr init;
3710                   init.value = error_mark_node;
3711                   init.original_code = ERROR_MARK;
3712                   init.original_type = NULL;
3713                   c_parser_error (parser, "expected identifier");
3714                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3715                   process_init_element (init, false, braced_init_obstack);
3716                   return;
3717                 }
3718             }
3719           else
3720             {
3721               tree first, second;
3722               location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3723               /* ??? Following the old parser, [ objc-receiver
3724                  objc-message-args ] is accepted as an initializer,
3725                  being distinguished from a designator by what follows
3726                  the first assignment expression inside the square
3727                  brackets, but after a first array designator a
3728                  subsequent square bracket is for Objective-C taken to
3729                  start an expression, using the obsolete form of
3730                  designated initializer without '=', rather than
3731                  possibly being a second level of designation: in LALR
3732                  terms, the '[' is shifted rather than reducing
3733                  designator to designator-list.  */
3734               if (des_prev == 1 && c_dialect_objc ())
3735                 {
3736                   des_seen = des_prev;
3737                   break;
3738                 }
3739               if (des_prev == 0 && c_dialect_objc ())
3740                 {
3741                   /* This might be an array designator or an
3742                      Objective-C message expression.  If the former,
3743                      continue parsing here; if the latter, parse the
3744                      remainder of the initializer given the starting
3745                      primary-expression.  ??? It might make sense to
3746                      distinguish when des_prev == 1 as well; see
3747                      previous comment.  */
3748                   tree rec, args;
3749                   struct c_expr mexpr;
3750                   c_parser_consume_token (parser);
3751                   if (c_parser_peek_token (parser)->type == CPP_NAME
3752                       && ((c_parser_peek_token (parser)->id_kind
3753                            == C_ID_TYPENAME)
3754                           || (c_parser_peek_token (parser)->id_kind
3755                               == C_ID_CLASSNAME)))
3756                     {
3757                       /* Type name receiver.  */
3758                       tree id = c_parser_peek_token (parser)->value;
3759                       c_parser_consume_token (parser);
3760                       rec = objc_get_class_reference (id);
3761                       goto parse_message_args;
3762                     }
3763                   first = c_parser_expr_no_commas (parser, NULL).value;
3764                   mark_exp_read (first);
3765                   if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3766                       || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3767                     goto array_desig_after_first;
3768                   /* Expression receiver.  So far only one part
3769                      without commas has been parsed; there might be
3770                      more of the expression.  */
3771                   rec = first;
3772                   while (c_parser_next_token_is (parser, CPP_COMMA))
3773                     {
3774                       struct c_expr next;
3775                       location_t comma_loc, exp_loc;
3776                       comma_loc = c_parser_peek_token (parser)->location;
3777                       c_parser_consume_token (parser);
3778                       exp_loc = c_parser_peek_token (parser)->location;
3779                       next = c_parser_expr_no_commas (parser, NULL);
3780                       next = default_function_array_read_conversion (exp_loc,
3781                                                                      next);
3782                       rec = build_compound_expr (comma_loc, rec, next.value);
3783                     }
3784                 parse_message_args:
3785                   /* Now parse the objc-message-args.  */
3786                   args = c_parser_objc_message_args (parser);
3787                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3788                                              "expected %<]%>");
3789                   mexpr.value
3790                     = objc_build_message_expr (build_tree_list (rec, args));
3791                   mexpr.original_code = ERROR_MARK;
3792                   mexpr.original_type = NULL;
3793                   /* Now parse and process the remainder of the
3794                      initializer, starting with this message
3795                      expression as a primary-expression.  */
3796                   c_parser_initval (parser, &mexpr, braced_init_obstack);
3797                   return;
3798                 }
3799               c_parser_consume_token (parser);
3800               first = c_parser_expr_no_commas (parser, NULL).value;
3801               mark_exp_read (first);
3802             array_desig_after_first:
3803               if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3804                 {
3805                   ellipsis_loc = c_parser_peek_token (parser)->location;
3806                   c_parser_consume_token (parser);
3807                   second = c_parser_expr_no_commas (parser, NULL).value;
3808                   mark_exp_read (second);
3809                 }
3810               else
3811                 second = NULL_TREE;
3812               if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3813                 {
3814                   c_parser_consume_token (parser);
3815                   set_init_index (first, second, braced_init_obstack);
3816                   if (second)
3817                     pedwarn (ellipsis_loc, OPT_pedantic,
3818                              "ISO C forbids specifying range of elements to initialize");
3819                 }
3820               else
3821                 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3822                                            "expected %<]%>");
3823             }
3824         }
3825       if (des_seen >= 1)
3826         {
3827           if (c_parser_next_token_is (parser, CPP_EQ))
3828             {
3829               if (!flag_isoc99)
3830                 pedwarn (des_loc, OPT_pedantic,
3831                          "ISO C90 forbids specifying subobject to initialize");
3832               c_parser_consume_token (parser);
3833             }
3834           else
3835             {
3836               if (des_seen == 1)
3837                 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3838                          "obsolete use of designated initializer without %<=%>");
3839               else
3840                 {
3841                   struct c_expr init;
3842                   init.value = error_mark_node;
3843                   init.original_code = ERROR_MARK;
3844                   init.original_type = NULL;
3845                   c_parser_error (parser, "expected %<=%>");
3846                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3847                   process_init_element (init, false, braced_init_obstack);
3848                   return;
3849                 }
3850             }
3851         }
3852     }
3853   c_parser_initval (parser, NULL, braced_init_obstack);
3854 }
3855
3856 /* Parse a nested initializer; as c_parser_initializer but parses
3857    initializers within braced lists, after any designators have been
3858    applied.  If AFTER is not NULL then it is an Objective-C message
3859    expression which is the primary-expression starting the
3860    initializer.  */
3861
3862 static void
3863 c_parser_initval (c_parser *parser, struct c_expr *after,
3864                   struct obstack * braced_init_obstack)
3865 {
3866   struct c_expr init;
3867   gcc_assert (!after || c_dialect_objc ());
3868   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3869     init = c_parser_braced_init (parser, NULL_TREE, true);
3870   else
3871     {
3872       location_t loc = c_parser_peek_token (parser)->location;
3873       init = c_parser_expr_no_commas (parser, after);
3874       if (init.value != NULL_TREE
3875           && TREE_CODE (init.value) != STRING_CST
3876           && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3877         init = default_function_array_read_conversion (loc, init);
3878     }
3879   process_init_element (init, false, braced_init_obstack);
3880 }
3881
3882 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3883    C99 6.8.2).
3884
3885    compound-statement:
3886      { block-item-list[opt] }
3887      { label-declarations block-item-list }
3888
3889    block-item-list:
3890      block-item
3891      block-item-list block-item
3892
3893    block-item:
3894      nested-declaration
3895      statement
3896
3897    nested-declaration:
3898      declaration
3899
3900    GNU extensions:
3901
3902    compound-statement:
3903      { label-declarations block-item-list }
3904
3905    nested-declaration:
3906      __extension__ nested-declaration
3907      nested-function-definition
3908
3909    label-declarations:
3910      label-declaration
3911      label-declarations label-declaration
3912
3913    label-declaration:
3914      __label__ identifier-list ;
3915
3916    Allowing the mixing of declarations and code is new in C99.  The
3917    GNU syntax also permits (not shown above) labels at the end of
3918    compound statements, which yield an error.  We don't allow labels
3919    on declarations; this might seem like a natural extension, but
3920    there would be a conflict between attributes on the label and
3921    prefix attributes on the declaration.  ??? The syntax follows the
3922    old parser in requiring something after label declarations.
3923    Although they are erroneous if the labels declared aren't defined,
3924    is it useful for the syntax to be this way?
3925
3926    OpenMP:
3927
3928    block-item:
3929      openmp-directive
3930
3931    openmp-directive:
3932      barrier-directive
3933      flush-directive  */
3934
3935 static tree
3936 c_parser_compound_statement (c_parser *parser)
3937 {
3938   tree stmt;
3939   location_t brace_loc;
3940   brace_loc = c_parser_peek_token (parser)->location;
3941   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3942     {
3943       /* Ensure a scope is entered and left anyway to avoid confusion
3944          if we have just prepared to enter a function body.  */
3945       stmt = c_begin_compound_stmt (true);
3946       c_end_compound_stmt (brace_loc, stmt, true);
3947       return error_mark_node;
3948     }
3949   stmt = c_begin_compound_stmt (true);
3950   c_parser_compound_statement_nostart (parser);
3951   return c_end_compound_stmt (brace_loc, stmt, true);
3952 }
3953
3954 /* Parse a compound statement except for the opening brace.  This is
3955    used for parsing both compound statements and statement expressions
3956    (which follow different paths to handling the opening).  */
3957
3958 static void
3959 c_parser_compound_statement_nostart (c_parser *parser)
3960 {
3961   bool last_stmt = false;
3962   bool last_label = false;
3963   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3964   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3965   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3966     {
3967       c_parser_consume_token (parser);
3968       return;
3969     }
3970   mark_valid_location_for_stdc_pragma (true);
3971   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3972     {
3973       /* Read zero or more forward-declarations for labels that nested
3974          functions can jump to.  */
3975       mark_valid_location_for_stdc_pragma (false);
3976       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3977         {
3978           label_loc = c_parser_peek_token (parser)->location;
3979           c_parser_consume_token (parser);
3980           /* Any identifiers, including those declared as type names,
3981              are OK here.  */
3982           while (true)
3983             {
3984               tree label;
3985               if (c_parser_next_token_is_not (parser, CPP_NAME))
3986                 {
3987                   c_parser_error (parser, "expected identifier");
3988                   break;
3989                 }
3990               label
3991                 = declare_label (c_parser_peek_token (parser)->value);
3992               C_DECLARED_LABEL_FLAG (label) = 1;
3993               add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3994               c_parser_consume_token (parser);
3995               if (c_parser_next_token_is (parser, CPP_COMMA))
3996                 c_parser_consume_token (parser);
3997               else
3998                 break;
3999             }
4000           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4001         }
4002       pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
4003     }
4004   /* We must now have at least one statement, label or declaration.  */
4005   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4006     {
4007       mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4008       c_parser_error (parser, "expected declaration or statement");
4009       c_parser_consume_token (parser);
4010       return;
4011     }
4012   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4013     {
4014       location_t loc = c_parser_peek_token (parser)->location;
4015       if (c_parser_next_token_is_keyword (parser, RID_CASE)
4016           || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4017           || (c_parser_next_token_is (parser, CPP_NAME)
4018               && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4019         {
4020           if (c_parser_next_token_is_keyword (parser, RID_CASE))
4021             label_loc = c_parser_peek_2nd_token (parser)->location;
4022           else
4023             label_loc = c_parser_peek_token (parser)->location;
4024           last_label = true;
4025           last_stmt = false;
4026           mark_valid_location_for_stdc_pragma (false);
4027           c_parser_label (parser);
4028         }
4029       else if (!last_label
4030                && c_parser_next_tokens_start_declaration (parser))
4031         {
4032           last_label = false;
4033           mark_valid_location_for_stdc_pragma (false);
4034           c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4035           if (last_stmt)
4036             pedwarn_c90 (loc,
4037                          (pedantic && !flag_isoc99)
4038                          ? OPT_pedantic
4039                          : OPT_Wdeclaration_after_statement,
4040                          "ISO C90 forbids mixed declarations and code");
4041           last_stmt = false;
4042         }
4043       else if (!last_label
4044                && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4045         {
4046           /* __extension__ can start a declaration, but is also an
4047              unary operator that can start an expression.  Consume all
4048              but the last of a possible series of __extension__ to
4049              determine which.  */
4050           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4051                  && (c_parser_peek_2nd_token (parser)->keyword
4052                      == RID_EXTENSION))
4053             c_parser_consume_token (parser);
4054           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4055             {
4056               int ext;
4057               ext = disable_extension_diagnostics ();
4058               c_parser_consume_token (parser);
4059               last_label = false;
4060               mark_valid_location_for_stdc_pragma (false);
4061               c_parser_declaration_or_fndef (parser, true, true, true, true,
4062                                              true, NULL);
4063               /* Following the old parser, __extension__ does not
4064                  disable this diagnostic.  */
4065               restore_extension_diagnostics (ext);
4066               if (last_stmt)
4067                 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4068                              ? OPT_pedantic
4069                              : OPT_Wdeclaration_after_statement,
4070                              "ISO C90 forbids mixed declarations and code");
4071               last_stmt = false;
4072             }
4073           else
4074             goto statement;
4075         }
4076       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4077         {
4078           /* External pragmas, and some omp pragmas, are not associated
4079              with regular c code, and so are not to be considered statements
4080              syntactically.  This ensures that the user doesn't put them
4081              places that would turn into syntax errors if the directive
4082              were ignored.  */
4083           if (c_parser_pragma (parser, pragma_compound))
4084             last_label = false, last_stmt = true;
4085         }
4086       else if (c_parser_next_token_is (parser, CPP_EOF))
4087         {
4088           mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4089           c_parser_error (parser, "expected declaration or statement");
4090           return;
4091         }
4092       else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4093         {
4094           if (parser->in_if_block)
4095             {
4096               mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4097               error_at (loc, """expected %<}%> before %<else%>");
4098               return;
4099             }
4100           else
4101             {
4102               error_at (loc, "%<else%> without a previous %<if%>");
4103               c_parser_consume_token (parser);
4104               continue;
4105             }
4106         }
4107       else
4108         {
4109         statement:
4110           last_label = false;
4111           last_stmt = true;
4112           mark_valid_location_for_stdc_pragma (false);
4113           c_parser_statement_after_labels (parser);
4114         }
4115
4116       parser->error = false;
4117     }
4118   if (last_label)
4119     error_at (label_loc, "label at end of compound statement");
4120   c_parser_consume_token (parser);
4121   /* Restore the value we started with.  */
4122   mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4123 }
4124
4125 /* Parse a label (C90 6.6.1, C99 6.8.1).
4126
4127    label:
4128      identifier : attributes[opt]
4129      case constant-expression :
4130      default :
4131
4132    GNU extensions:
4133
4134    label:
4135      case constant-expression ... constant-expression :
4136
4137    The use of attributes on labels is a GNU extension.  The syntax in
4138    GNU C accepts any expressions without commas, non-constant
4139    expressions being rejected later.  */
4140
4141 static void
4142 c_parser_label (c_parser *parser)
4143 {
4144   location_t loc1 = c_parser_peek_token (parser)->location;
4145   tree label = NULL_TREE;
4146   if (c_parser_next_token_is_keyword (parser, RID_CASE))
4147     {
4148       tree exp1, exp2;
4149       c_parser_consume_token (parser);
4150       exp1 = c_parser_expr_no_commas (parser, NULL).value;
4151       if (c_parser_next_token_is (parser, CPP_COLON))
4152         {
4153           c_parser_consume_token (parser);
4154           label = do_case (loc1, exp1, NULL_TREE);
4155         }
4156       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4157         {
4158           c_parser_consume_token (parser);
4159           exp2 = c_parser_expr_no_commas (parser, NULL).value;
4160           if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4161             label = do_case (loc1, exp1, exp2);
4162         }
4163       else
4164         c_parser_error (parser, "expected %<:%> or %<...%>");
4165     }
4166   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4167     {
4168       c_parser_consume_token (parser);
4169       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4170         label = do_case (loc1, NULL_TREE, NULL_TREE);
4171     }
4172   else
4173     {
4174       tree name = c_parser_peek_token (parser)->value;
4175       tree tlab;
4176       tree attrs;
4177       location_t loc2 = c_parser_peek_token (parser)->location;
4178       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4179       c_parser_consume_token (parser);
4180       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4181       c_parser_consume_token (parser);
4182       attrs = c_parser_attributes (parser);
4183       tlab = define_label (loc2, name);
4184       if (tlab)
4185         {
4186           decl_attributes (&tlab, attrs, 0);
4187           label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4188         }
4189     }
4190   if (label)
4191     {
4192       if (c_parser_next_tokens_start_declaration (parser))
4193         {
4194           error_at (c_parser_peek_token (parser)->location,
4195                     "a label can only be part of a statement and "
4196                     "a declaration is not a statement");
4197           c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4198                                          /*static_assert_ok*/ true,
4199                                          /*nested*/ true, /*empty_ok*/ false,
4200                                          /*start_attr_ok*/ true, NULL);
4201         }
4202     }
4203 }
4204
4205 /* Parse a statement (C90 6.6, C99 6.8).
4206
4207    statement:
4208      labeled-statement
4209      compound-statement
4210      expression-statement
4211      selection-statement
4212      iteration-statement
4213      jump-statement
4214
4215    labeled-statement:
4216      label statement
4217
4218    expression-statement:
4219      expression[opt] ;
4220
4221    selection-statement:
4222      if-statement
4223      switch-statement
4224
4225    iteration-statement:
4226      while-statement
4227      do-statement
4228      for-statement
4229
4230    jump-statement:
4231      goto identifier ;
4232      continue ;
4233      break ;
4234      return expression[opt] ;
4235
4236    GNU extensions:
4237
4238    statement:
4239      asm-statement
4240
4241    jump-statement:
4242      goto * expression ;
4243
4244    Objective-C:
4245
4246    statement:
4247      objc-throw-statement
4248      objc-try-catch-statement
4249      objc-synchronized-statement
4250
4251    objc-throw-statement:
4252      @throw expression ;
4253      @throw ;
4254
4255    OpenMP:
4256
4257    statement:
4258      openmp-construct
4259
4260    openmp-construct:
4261      parallel-construct
4262      for-construct
4263      sections-construct
4264      single-construct
4265      parallel-for-construct
4266      parallel-sections-construct
4267      master-construct
4268      critical-construct
4269      atomic-construct
4270      ordered-construct
4271
4272    parallel-construct:
4273      parallel-directive structured-block
4274
4275    for-construct:
4276      for-directive iteration-statement
4277
4278    sections-construct:
4279      sections-directive section-scope
4280
4281    single-construct:
4282      single-directive structured-block
4283
4284    parallel-for-construct:
4285      parallel-for-directive iteration-statement
4286
4287    parallel-sections-construct:
4288      parallel-sections-directive section-scope
4289
4290    master-construct:
4291      master-directive structured-block
4292
4293    critical-construct:
4294      critical-directive structured-block
4295
4296    atomic-construct:
4297      atomic-directive expression-statement
4298
4299    ordered-construct:
4300      ordered-directive structured-block  */
4301
4302 static void
4303 c_parser_statement (c_parser *parser)
4304 {
4305   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4306          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4307          || (c_parser_next_token_is (parser, CPP_NAME)
4308              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4309     c_parser_label (parser);
4310   c_parser_statement_after_labels (parser);
4311 }
4312
4313 /* Parse a statement, other than a labeled statement.  */
4314
4315 static void
4316 c_parser_statement_after_labels (c_parser *parser)
4317 {
4318   location_t loc = c_parser_peek_token (parser)->location;
4319   tree stmt = NULL_TREE;
4320   bool in_if_block = parser->in_if_block;
4321   parser->in_if_block = false;
4322   switch (c_parser_peek_token (parser)->type)
4323     {
4324     case CPP_OPEN_BRACE:
4325       add_stmt (c_parser_compound_statement (parser));
4326       break;
4327     case CPP_KEYWORD:
4328       switch (c_parser_peek_token (parser)->keyword)
4329         {
4330         case RID_IF:
4331           c_parser_if_statement (parser);
4332           break;
4333         case RID_SWITCH:
4334           c_parser_switch_statement (parser);
4335           break;
4336         case RID_WHILE:
4337           c_parser_while_statement (parser);
4338           break;
4339         case RID_DO:
4340           c_parser_do_statement (parser);
4341           break;
4342         case RID_FOR:
4343           c_parser_for_statement (parser);
4344           break;
4345         case RID_GOTO:
4346           c_parser_consume_token (parser);
4347           if (c_parser_next_token_is (parser, CPP_NAME))
4348             {
4349               stmt = c_finish_goto_label (loc,
4350                                           c_parser_peek_token (parser)->value);
4351               c_parser_consume_token (parser);
4352             }
4353           else if (c_parser_next_token_is (parser, CPP_MULT))
4354             {
4355               tree val;
4356
4357               c_parser_consume_token (parser);
4358               val = c_parser_expression (parser).value;
4359               mark_exp_read (val);
4360               stmt = c_finish_goto_ptr (loc, val);
4361             }
4362           else
4363             c_parser_error (parser, "expected identifier or %<*%>");
4364           goto expect_semicolon;
4365         case RID_CONTINUE:
4366           c_parser_consume_token (parser);
4367           stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4368           goto expect_semicolon;
4369         case RID_BREAK:
4370           c_parser_consume_token (parser);
4371           stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4372           goto expect_semicolon;
4373         case RID_RETURN:
4374           c_parser_consume_token (parser);
4375           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4376             {
4377               stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4378               c_parser_consume_token (parser);
4379             }
4380           else
4381             {
4382               struct c_expr expr = c_parser_expression_conv (parser);
4383               mark_exp_read (expr.value);
4384               stmt = c_finish_return (loc, expr.value, expr.original_type);
4385               goto expect_semicolon;
4386             }
4387           break;
4388         case RID_ASM:
4389           stmt = c_parser_asm_statement (parser);
4390           break;
4391         case RID_AT_THROW:
4392           gcc_assert (c_dialect_objc ());
4393           c_parser_consume_token (parser);
4394           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4395             {
4396               stmt = objc_build_throw_stmt (loc, NULL_TREE);
4397               c_parser_consume_token (parser);
4398             }
4399           else
4400             {
4401               tree expr = c_parser_expression (parser).value;
4402               expr = c_fully_fold (expr, false, NULL);
4403               stmt = objc_build_throw_stmt (loc, expr);
4404               goto expect_semicolon;
4405             }
4406           break;
4407         case RID_AT_TRY:
4408           gcc_assert (c_dialect_objc ());
4409           c_parser_objc_try_catch_finally_statement (parser);
4410           break;
4411         case RID_AT_SYNCHRONIZED:
4412           gcc_assert (c_dialect_objc ());
4413           c_parser_objc_synchronized_statement (parser);
4414           break;
4415         default:
4416           goto expr_stmt;
4417         }
4418       break;
4419     case CPP_SEMICOLON:
4420       c_parser_consume_token (parser);
4421       break;
4422     case CPP_CLOSE_PAREN:
4423     case CPP_CLOSE_SQUARE:
4424       /* Avoid infinite loop in error recovery:
4425          c_parser_skip_until_found stops at a closing nesting
4426          delimiter without consuming it, but here we need to consume
4427          it to proceed further.  */
4428       c_parser_error (parser, "expected statement");
4429       c_parser_consume_token (parser);
4430       break;
4431     case CPP_PRAGMA:
4432       c_parser_pragma (parser, pragma_stmt);
4433       break;
4434     default:
4435     expr_stmt:
4436       stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4437     expect_semicolon:
4438       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4439       break;
4440     }
4441   /* Two cases cannot and do not have line numbers associated: If stmt
4442      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4443      cannot hold line numbers.  But that's OK because the statement
4444      will either be changed to a MODIFY_EXPR during gimplification of
4445      the statement expr, or discarded.  If stmt was compound, but
4446      without new variables, we will have skipped the creation of a
4447      BIND and will have a bare STATEMENT_LIST.  But that's OK because
4448      (recursively) all of the component statements should already have
4449      line numbers assigned.  ??? Can we discard no-op statements
4450      earlier?  */
4451   if (CAN_HAVE_LOCATION_P (stmt)
4452       && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4453     SET_EXPR_LOCATION (stmt, loc);
4454
4455   parser->in_if_block = in_if_block;
4456 }
4457
4458 /* Parse the condition from an if, do, while or for statements.  */
4459
4460 static tree
4461 c_parser_condition (c_parser *parser)
4462 {
4463   location_t loc = c_parser_peek_token (parser)->location;
4464   tree cond;
4465   cond = c_parser_expression_conv (parser).value;
4466   cond = c_objc_common_truthvalue_conversion (loc, cond);
4467   cond = c_fully_fold (cond, false, NULL);
4468   if (warn_sequence_point)
4469     verify_sequence_points (cond);
4470   return cond;
4471 }
4472
4473 /* Parse a parenthesized condition from an if, do or while statement.
4474
4475    condition:
4476      ( expression )
4477 */
4478 static tree
4479 c_parser_paren_condition (c_parser *parser)
4480 {
4481   tree cond;
4482   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4483     return error_mark_node;
4484   cond = c_parser_condition (parser);
4485   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4486   return cond;
4487 }
4488
4489 /* Parse a statement which is a block in C99.  */
4490
4491 static tree
4492 c_parser_c99_block_statement (c_parser *parser)
4493 {
4494   tree block = c_begin_compound_stmt (flag_isoc99);
4495   location_t loc = c_parser_peek_token (parser)->location;
4496   c_parser_statement (parser);
4497   return c_end_compound_stmt (loc, block, flag_isoc99);
4498 }
4499
4500 /* Parse the body of an if statement.  This is just parsing a
4501    statement but (a) it is a block in C99, (b) we track whether the
4502    body is an if statement for the sake of -Wparentheses warnings, (c)
4503    we handle an empty body specially for the sake of -Wempty-body
4504    warnings, and (d) we call parser_compound_statement directly
4505    because c_parser_statement_after_labels resets
4506    parser->in_if_block.  */
4507
4508 static tree
4509 c_parser_if_body (c_parser *parser, bool *if_p)
4510 {
4511   tree block = c_begin_compound_stmt (flag_isoc99);
4512   location_t body_loc = c_parser_peek_token (parser)->location;
4513   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4514          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4515          || (c_parser_next_token_is (parser, CPP_NAME)
4516              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4517     c_parser_label (parser);
4518   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4519   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4520     {
4521       location_t loc = c_parser_peek_token (parser)->location;
4522       add_stmt (build_empty_stmt (loc));
4523       c_parser_consume_token (parser);
4524       if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4525         warning_at (loc, OPT_Wempty_body,
4526                     "suggest braces around empty body in an %<if%> statement");
4527     }
4528   else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4529     add_stmt (c_parser_compound_statement (parser));
4530   else
4531     c_parser_statement_after_labels (parser);
4532   return c_end_compound_stmt (body_loc, block, flag_isoc99);
4533 }
4534
4535 /* Parse the else body of an if statement.  This is just parsing a
4536    statement but (a) it is a block in C99, (b) we handle an empty body
4537    specially for the sake of -Wempty-body warnings.  */
4538
4539 static tree
4540 c_parser_else_body (c_parser *parser)
4541 {
4542   location_t else_loc = c_parser_peek_token (parser)->location;
4543   tree block = c_begin_compound_stmt (flag_isoc99);
4544   while (c_parser_next_token_is_keyword (parser, RID_CASE)
4545          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4546          || (c_parser_next_token_is (parser, CPP_NAME)
4547              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4548     c_parser_label (parser);
4549   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4550     {
4551       location_t loc = c_parser_peek_token (parser)->location;
4552       warning_at (loc,
4553                   OPT_Wempty_body,
4554                  "suggest braces around empty body in an %<else%> statement");
4555       add_stmt (build_empty_stmt (loc));
4556       c_parser_consume_token (parser);
4557     }
4558   else
4559     c_parser_statement_after_labels (parser);
4560   return c_end_compound_stmt (else_loc, block, flag_isoc99);
4561 }
4562
4563 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4564
4565    if-statement:
4566      if ( expression ) statement
4567      if ( expression ) statement else statement
4568 */
4569
4570 static void
4571 c_parser_if_statement (c_parser *parser)
4572 {
4573   tree block;
4574   location_t loc;
4575   tree cond;
4576   bool first_if = false;
4577   tree first_body, second_body;
4578   bool in_if_block;
4579
4580   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4581   c_parser_consume_token (parser);
4582   block = c_begin_compound_stmt (flag_isoc99);
4583   loc = c_parser_peek_token (parser)->location;
4584   cond = c_parser_paren_condition (parser);
4585   in_if_block = parser->in_if_block;
4586   parser->in_if_block = true;
4587   first_body = c_parser_if_body (parser, &first_if);
4588   parser->in_if_block = in_if_block;
4589   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4590     {
4591       c_parser_consume_token (parser);
4592       second_body = c_parser_else_body (parser);
4593     }
4594   else
4595     second_body = NULL_TREE;
4596   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4597   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4598 }
4599
4600 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4601
4602    switch-statement:
4603      switch (expression) statement
4604 */
4605
4606 static void
4607 c_parser_switch_statement (c_parser *parser)
4608 {
4609   tree block, expr, body, save_break;
4610   location_t switch_loc = c_parser_peek_token (parser)->location;
4611   location_t switch_cond_loc;
4612   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4613   c_parser_consume_token (parser);
4614   block = c_begin_compound_stmt (flag_isoc99);
4615   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4616     {
4617       switch_cond_loc = c_parser_peek_token (parser)->location;
4618       expr = c_parser_expression (parser).value;
4619       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4620     }
4621   else
4622     {
4623       switch_cond_loc = UNKNOWN_LOCATION;
4624       expr = error_mark_node;
4625     }
4626   c_start_case (switch_loc, switch_cond_loc, expr);
4627   save_break = c_break_label;
4628   c_break_label = NULL_TREE;
4629   body = c_parser_c99_block_statement (parser);
4630   c_finish_case (body);
4631   if (c_break_label)
4632     {
4633       location_t here = c_parser_peek_token (parser)->location;
4634       tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4635       SET_EXPR_LOCATION (t, here);
4636       add_stmt (t);
4637     }
4638   c_break_label = save_break;
4639   add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4640 }
4641
4642 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4643
4644    while-statement:
4645       while (expression) statement
4646 */
4647
4648 static void
4649 c_parser_while_statement (c_parser *parser)
4650 {
4651   tree block, cond, body, save_break, save_cont;
4652   location_t loc;
4653   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4654   c_parser_consume_token (parser);
4655   block = c_begin_compound_stmt (flag_isoc99);
4656   loc = c_parser_peek_token (parser)->location;
4657   cond = c_parser_paren_condition (parser);
4658   save_break = c_break_label;
4659   c_break_label = NULL_TREE;
4660   save_cont = c_cont_label;
4661   c_cont_label = NULL_TREE;
4662   body = c_parser_c99_block_statement (parser);
4663   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4664   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4665   c_break_label = save_break;
4666   c_cont_label = save_cont;
4667 }
4668
4669 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4670
4671    do-statement:
4672      do statement while ( expression ) ;
4673 */
4674
4675 static void
4676 c_parser_do_statement (c_parser *parser)
4677 {
4678   tree block, cond, body, save_break, save_cont, new_break, new_cont;
4679   location_t loc;
4680   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4681   c_parser_consume_token (parser);
4682   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4683     warning_at (c_parser_peek_token (parser)->location,
4684                 OPT_Wempty_body,
4685                 "suggest braces around empty body in %<do%> statement");
4686   block = c_begin_compound_stmt (flag_isoc99);
4687   loc = c_parser_peek_token (parser)->location;
4688   save_break = c_break_label;
4689   c_break_label = NULL_TREE;
4690   save_cont = c_cont_label;
4691   c_cont_label = NULL_TREE;
4692   body = c_parser_c99_block_statement (parser);
4693   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4694   new_break = c_break_label;
4695   c_break_label = save_break;
4696   new_cont = c_cont_label;
4697   c_cont_label = save_cont;
4698   cond = c_parser_paren_condition (parser);
4699   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4700     c_parser_skip_to_end_of_block_or_statement (parser);
4701   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4702   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4703 }
4704
4705 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4706
4707    for-statement:
4708      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4709      for ( nested-declaration expression[opt] ; expression[opt] ) statement
4710
4711    The form with a declaration is new in C99.
4712
4713    ??? In accordance with the old parser, the declaration may be a
4714    nested function, which is then rejected in check_for_loop_decls,
4715    but does it make any sense for this to be included in the grammar?
4716    Note in particular that the nested function does not include a
4717    trailing ';', whereas the "declaration" production includes one.
4718    Also, can we reject bad declarations earlier and cheaper than
4719    check_for_loop_decls?
4720
4721    In Objective-C, there are two additional variants:
4722
4723    foreach-statement:
4724      for ( expression in expresssion ) statement
4725      for ( declaration in expression ) statement
4726
4727    This is inconsistent with C, because the second variant is allowed
4728    even if c99 is not enabled.
4729
4730    The rest of the comment documents these Objective-C foreach-statement.
4731
4732    Here is the canonical example of the first variant:
4733     for (object in array)    { do something with object }
4734    we call the first expression ("object") the "object_expression" and 
4735    the second expression ("array") the "collection_expression".
4736    object_expression must be an lvalue of type "id" (a generic Objective-C
4737    object) because the loop works by assigning to object_expression the
4738    various objects from the collection_expression.  collection_expression
4739    must evaluate to something of type "id" which responds to the method
4740    countByEnumeratingWithState:objects:count:.
4741
4742    The canonical example of the second variant is:
4743     for (id object in array)    { do something with object }
4744    which is completely equivalent to
4745     {
4746       id object;
4747       for (object in array) { do something with object }
4748     }
4749    Note that initizializing 'object' in some way (eg, "for ((object =
4750    xxx) in array) { do something with object }") is possibly
4751    technically valid, but completely pointless as 'object' will be
4752    assigned to something else as soon as the loop starts.  We should
4753    most likely reject it (TODO).
4754
4755    The beginning of the Objective-C foreach-statement looks exactly
4756    like the beginning of the for-statement, and we can tell it is a
4757    foreach-statement only because the initial declaration or
4758    expression is terminated by 'in' instead of ';'.
4759 */
4760
4761 static void
4762 c_parser_for_statement (c_parser *parser)
4763 {
4764   tree block, cond, incr, save_break, save_cont, body;
4765   /* The following are only used when parsing an ObjC foreach statement.  */
4766   tree object_expression, collection_expression;
4767   location_t loc = c_parser_peek_token (parser)->location;
4768   location_t for_loc = c_parser_peek_token (parser)->location;
4769   bool is_foreach_statement = false;
4770   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4771   c_parser_consume_token (parser);
4772   /* Open a compound statement in Objective-C as well, just in case this is
4773      as foreach expression.  */
4774   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4775   cond = error_mark_node;
4776   incr = error_mark_node;
4777   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4778     {
4779       /* Parse the initialization declaration or expression.  */
4780       object_expression = error_mark_node;
4781       parser->objc_could_be_foreach_context = c_dialect_objc ();
4782       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4783         {
4784           parser->objc_could_be_foreach_context = false;
4785           c_parser_consume_token (parser);
4786           c_finish_expr_stmt (loc, NULL_TREE);
4787         }
4788       else if (c_parser_next_tokens_start_declaration (parser))
4789         {
4790           c_parser_declaration_or_fndef (parser, true, true, true, true, true, 
4791                                          &object_expression);
4792           parser->objc_could_be_foreach_context = false;
4793           
4794           if (c_parser_next_token_is_keyword (parser, RID_IN))
4795             {
4796               c_parser_consume_token (parser);
4797               is_foreach_statement = true;
4798               if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4799                 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4800             }
4801           else
4802             check_for_loop_decls (for_loc, flag_isoc99);
4803         }
4804       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4805         {
4806           /* __extension__ can start a declaration, but is also an
4807              unary operator that can start an expression.  Consume all
4808              but the last of a possible series of __extension__ to
4809              determine which.  */
4810           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4811                  && (c_parser_peek_2nd_token (parser)->keyword
4812                      == RID_EXTENSION))
4813             c_parser_consume_token (parser);
4814           if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4815             {
4816               int ext;
4817               ext = disable_extension_diagnostics ();
4818               c_parser_consume_token (parser);
4819               c_parser_declaration_or_fndef (parser, true, true, true, true,
4820                                              true, &object_expression);
4821               parser->objc_could_be_foreach_context = false;
4822               
4823               restore_extension_diagnostics (ext);
4824               if (c_parser_next_token_is_keyword (parser, RID_IN))
4825                 {
4826                   c_parser_consume_token (parser);
4827                   is_foreach_statement = true;
4828                   if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4829                     c_parser_error (parser, "multiple iterating variables in fast enumeration");
4830                 }
4831               else
4832                 check_for_loop_decls (for_loc, flag_isoc99);
4833             }
4834           else
4835             goto init_expr;
4836         }
4837       else
4838         {
4839         init_expr:
4840           {
4841             tree init_expression;
4842             init_expression = c_parser_expression (parser).value;
4843             parser->objc_could_be_foreach_context = false;
4844             if (c_parser_next_token_is_keyword (parser, RID_IN))
4845               {
4846                 c_parser_consume_token (parser);
4847                 is_foreach_statement = true;
4848                 if (! lvalue_p (init_expression))
4849                   c_parser_error (parser, "invalid iterating variable in fast enumeration");
4850                 object_expression = c_fully_fold (init_expression, false, NULL);
4851               }
4852             else
4853               {
4854                 c_finish_expr_stmt (loc, init_expression);
4855                 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4856               }
4857           }
4858         }
4859       /* Parse the loop condition.  In the case of a foreach
4860          statement, there is no loop condition.  */
4861       gcc_assert (!parser->objc_could_be_foreach_context);
4862       if (!is_foreach_statement)
4863         {
4864           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4865             {
4866               c_parser_consume_token (parser);
4867               cond = NULL_TREE;
4868             }
4869           else
4870             {
4871               cond = c_parser_condition (parser);
4872               c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4873             }
4874         }
4875       /* Parse the increment expression (the third expression in a
4876          for-statement).  In the case of a foreach-statement, this is
4877          the expression that follows the 'in'.  */
4878       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4879         {
4880           if (is_foreach_statement)
4881             {
4882               c_parser_error (parser, "missing collection in fast enumeration");
4883               collection_expression = error_mark_node;
4884             }
4885           else
4886             incr = c_process_expr_stmt (loc, NULL_TREE);
4887         }
4888       else
4889         {
4890           if (is_foreach_statement)
4891             collection_expression = c_fully_fold (c_parser_expression (parser).value,
4892                                                   false, NULL);
4893           else
4894             incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4895         }
4896       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4897     }
4898   save_break = c_break_label;
4899   c_break_label = NULL_TREE;
4900   save_cont = c_cont_label;
4901   c_cont_label = NULL_TREE;
4902   body = c_parser_c99_block_statement (parser);
4903   if (is_foreach_statement)
4904     objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4905   else
4906     c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4907   add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4908   c_break_label = save_break;
4909   c_cont_label = save_cont;
4910 }
4911
4912 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
4913    statement with inputs, outputs, clobbers, and volatile tag
4914    allowed.
4915
4916    asm-statement:
4917      asm type-qualifier[opt] ( asm-argument ) ;
4918      asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4919
4920    asm-argument:
4921      asm-string-literal
4922      asm-string-literal : asm-operands[opt]
4923      asm-string-literal : asm-operands[opt] : asm-operands[opt]
4924      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4925
4926    asm-goto-argument:
4927      asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4928        : asm-goto-operands
4929
4930    Qualifiers other than volatile are accepted in the syntax but
4931    warned for.  */
4932
4933 static tree
4934 c_parser_asm_statement (c_parser *parser)
4935 {
4936   tree quals, str, outputs, inputs, clobbers, labels, ret;
4937   bool simple, is_goto;
4938   location_t asm_loc = c_parser_peek_token (parser)->location;
4939   int section, nsections;
4940
4941   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4942   c_parser_consume_token (parser);
4943   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4944     {
4945       quals = c_parser_peek_token (parser)->value;
4946       c_parser_consume_token (parser);
4947     }
4948   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4949            || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4950     {
4951       warning_at (c_parser_peek_token (parser)->location,
4952                   0,
4953                   "%E qualifier ignored on asm",
4954                   c_parser_peek_token (parser)->value);
4955       quals = NULL_TREE;
4956       c_parser_consume_token (parser);
4957     }
4958   else
4959     quals = NULL_TREE;
4960
4961   is_goto = false;
4962   if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4963     {
4964       c_parser_consume_token (parser);
4965       is_goto = true;
4966     }
4967
4968   /* ??? Follow the C++ parser rather than using the
4969      lex_untranslated_string kludge.  */
4970   parser->lex_untranslated_string = true;
4971   ret = NULL;
4972
4973   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4974     goto error;
4975
4976   str = c_parser_asm_string_literal (parser);
4977   if (str == NULL_TREE)
4978     goto error_close_paren;
4979
4980   simple = true;
4981   outputs = NULL_TREE;
4982   inputs = NULL_TREE;
4983   clobbers = NULL_TREE;
4984   labels = NULL_TREE;
4985
4986   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4987     goto done_asm;
4988
4989   /* Parse each colon-delimited section of operands.  */
4990   nsections = 3 + is_goto;
4991   for (section = 0; section < nsections; ++section)
4992     {
4993       if (!c_parser_require (parser, CPP_COLON,
4994                              is_goto
4995                              ? "expected %<:%>"
4996                              : "expected %<:%> or %<)%>"))
4997         goto error_close_paren;
4998
4999       /* Once past any colon, we're no longer a simple asm.  */
5000       simple = false;
5001
5002       if ((!c_parser_next_token_is (parser, CPP_COLON)
5003            && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5004           || section == 3)
5005         switch (section)
5006           {
5007           case 0:
5008             /* For asm goto, we don't allow output operands, but reserve
5009                the slot for a future extension that does allow them.  */
5010             if (!is_goto)
5011               outputs = c_parser_asm_operands (parser, false);
5012             break;
5013           case 1:
5014             inputs = c_parser_asm_operands (parser, true);
5015             break;
5016           case 2:
5017             clobbers = c_parser_asm_clobbers (parser);
5018             break;
5019           case 3:
5020             labels = c_parser_asm_goto_operands (parser);
5021             break;
5022           default:
5023             gcc_unreachable ();
5024           }
5025
5026       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5027         goto done_asm;
5028     }
5029
5030  done_asm:
5031   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5032     {
5033       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5034       goto error;
5035     }
5036
5037   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5038     c_parser_skip_to_end_of_block_or_statement (parser);
5039
5040   ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5041                                                clobbers, labels, simple));
5042
5043  error:
5044   parser->lex_untranslated_string = false;
5045   return ret;
5046
5047  error_close_paren:
5048   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5049   goto error;
5050 }
5051
5052 /* Parse asm operands, a GNU extension.  If CONVERT_P (for inputs but
5053    not outputs), apply the default conversion of functions and arrays
5054    to pointers.
5055
5056    asm-operands:
5057      asm-operand
5058      asm-operands , asm-operand
5059
5060    asm-operand:
5061      asm-string-literal ( expression )
5062      [ identifier ] asm-string-literal ( expression )
5063 */
5064
5065 static tree
5066 c_parser_asm_operands (c_parser *parser, bool convert_p)
5067 {
5068   tree list = NULL_TREE;
5069   location_t loc;
5070   while (true)
5071     {
5072       tree name, str;
5073       struct c_expr expr;
5074       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5075         {
5076           c_parser_consume_token (parser);
5077           if (c_parser_next_token_is (parser, CPP_NAME))
5078             {
5079               tree id = c_parser_peek_token (parser)->value;
5080               c_parser_consume_token (parser);
5081               name = build_string (IDENTIFIER_LENGTH (id),
5082                                    IDENTIFIER_POINTER (id));
5083             }
5084           else
5085             {
5086               c_parser_error (parser, "expected identifier");
5087               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5088               return NULL_TREE;
5089             }
5090           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5091                                      "expected %<]%>");
5092         }
5093       else
5094         name = NULL_TREE;
5095       str = c_parser_asm_string_literal (parser);
5096       if (str == NULL_TREE)
5097         return NULL_TREE;
5098       parser->lex_untranslated_string = false;
5099       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5100         {
5101           parser->lex_untranslated_string = true;
5102           return NULL_TREE;
5103         }
5104       loc = c_parser_peek_token (parser)->location;
5105       expr = c_parser_expression (parser);
5106       mark_exp_read (expr.value);
5107       if (convert_p)
5108         expr = default_function_array_conversion (loc, expr);
5109       expr.value = c_fully_fold (expr.value, false, NULL);
5110       parser->lex_untranslated_string = true;
5111       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5112         {
5113           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5114           return NULL_TREE;
5115         }
5116       list = chainon (list, build_tree_list (build_tree_list (name, str),
5117                                              expr.value));
5118       if (c_parser_next_token_is (parser, CPP_COMMA))
5119         c_parser_consume_token (parser);
5120       else
5121         break;
5122     }
5123   return list;
5124 }
5125
5126 /* Parse asm clobbers, a GNU extension.
5127
5128    asm-clobbers:
5129      asm-string-literal
5130      asm-clobbers , asm-string-literal
5131 */
5132
5133 static tree
5134 c_parser_asm_clobbers (c_parser *parser)
5135 {
5136   tree list = NULL_TREE;
5137   while (true)
5138     {
5139       tree str = c_parser_asm_string_literal (parser);
5140       if (str)
5141         list = tree_cons (NULL_TREE, str, list);
5142       else
5143         return NULL_TREE;
5144       if (c_parser_next_token_is (parser, CPP_COMMA))
5145         c_parser_consume_token (parser);
5146       else
5147         break;
5148     }
5149   return list;
5150 }
5151
5152 /* Parse asm goto labels, a GNU extension.
5153
5154    asm-goto-operands:
5155      identifier
5156      asm-goto-operands , identifier
5157 */
5158
5159 static tree
5160 c_parser_asm_goto_operands (c_parser *parser)
5161 {
5162   tree list = NULL_TREE;
5163   while (true)
5164     {
5165       tree name, label;
5166
5167       if (c_parser_next_token_is (parser, CPP_NAME))
5168         {
5169           c_token *tok = c_parser_peek_token (parser);
5170           name = tok->value;
5171           label = lookup_label_for_goto (tok->location, name);
5172           c_parser_consume_token (parser);
5173           TREE_USED (label) = 1;
5174         }
5175       else
5176         {
5177           c_parser_error (parser, "expected identifier");
5178           return NULL_TREE;
5179         }
5180
5181       name = build_string (IDENTIFIER_LENGTH (name),
5182                            IDENTIFIER_POINTER (name));
5183       list = tree_cons (name, label, list);
5184       if (c_parser_next_token_is (parser, CPP_COMMA))
5185         c_parser_consume_token (parser);
5186       else
5187         return nreverse (list);
5188     }
5189 }
5190
5191 /* Parse an expression other than a compound expression; that is, an
5192    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
5193    NULL then it is an Objective-C message expression which is the
5194    primary-expression starting the expression as an initializer.
5195
5196    assignment-expression:
5197      conditional-expression
5198      unary-expression assignment-operator assignment-expression
5199
5200    assignment-operator: one of
5201      = *= /= %= += -= <<= >>= &= ^= |=
5202
5203    In GNU C we accept any conditional expression on the LHS and
5204    diagnose the invalid lvalue rather than producing a syntax
5205    error.  */
5206
5207 static struct c_expr
5208 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5209 {
5210   struct c_expr lhs, rhs, ret;
5211   enum tree_code code;
5212   location_t op_location, exp_location;
5213   gcc_assert (!after || c_dialect_objc ());
5214   lhs = c_parser_conditional_expression (parser, after);
5215   op_location = c_parser_peek_token (parser)->location;
5216   switch (c_parser_peek_token (parser)->type)
5217     {
5218     case CPP_EQ:
5219       code = NOP_EXPR;
5220       break;
5221     case CPP_MULT_EQ:
5222       code = MULT_EXPR;
5223       break;
5224     case CPP_DIV_EQ:
5225       code = TRUNC_DIV_EXPR;
5226       break;
5227     case CPP_MOD_EQ:
5228       code = TRUNC_MOD_EXPR;
5229       break;
5230     case CPP_PLUS_EQ:
5231       code = PLUS_EXPR;
5232       break;
5233     case CPP_MINUS_EQ:
5234       code = MINUS_EXPR;
5235       break;
5236     case CPP_LSHIFT_EQ:
5237       code = LSHIFT_EXPR;
5238       break;
5239     case CPP_RSHIFT_EQ:
5240       code = RSHIFT_EXPR;
5241       break;
5242     case CPP_AND_EQ:
5243       code = BIT_AND_EXPR;
5244       break;
5245     case CPP_XOR_EQ:
5246       code = BIT_XOR_EXPR;
5247       break;
5248     case CPP_OR_EQ:
5249       code = BIT_IOR_EXPR;
5250       break;
5251     default:
5252       return lhs;
5253     }
5254   c_parser_consume_token (parser);
5255   exp_location = c_parser_peek_token (parser)->location;
5256   rhs = c_parser_expr_no_commas (parser, NULL);
5257   rhs = default_function_array_read_conversion (exp_location, rhs);
5258   ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5259                                  code, exp_location, rhs.value,
5260                                  rhs.original_type);
5261   if (code == NOP_EXPR)
5262     ret.original_code = MODIFY_EXPR;
5263   else
5264     {
5265       TREE_NO_WARNING (ret.value) = 1;
5266       ret.original_code = ERROR_MARK;
5267     }
5268   ret.original_type = NULL;
5269   return ret;
5270 }
5271
5272 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
5273    is not NULL then it is an Objective-C message expression which is
5274    the primary-expression starting the expression as an initializer.
5275
5276    conditional-expression:
5277      logical-OR-expression
5278      logical-OR-expression ? expression : conditional-expression
5279
5280    GNU extensions:
5281
5282    conditional-expression:
5283      logical-OR-expression ? : conditional-expression
5284 */
5285
5286 static struct c_expr
5287 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5288 {
5289   struct c_expr cond, exp1, exp2, ret;
5290   location_t cond_loc, colon_loc, middle_loc;
5291
5292   gcc_assert (!after || c_dialect_objc ());
5293
5294   cond = c_parser_binary_expression (parser, after);
5295
5296   if (c_parser_next_token_is_not (parser, CPP_QUERY))
5297     return cond;
5298   cond_loc = c_parser_peek_token (parser)->location;
5299   cond = default_function_array_read_conversion (cond_loc, cond);
5300   c_parser_consume_token (parser);
5301   if (c_parser_next_token_is (parser, CPP_COLON))
5302     {
5303       tree eptype = NULL_TREE;
5304
5305       middle_loc = c_parser_peek_token (parser)->location;
5306       pedwarn (middle_loc, OPT_pedantic, 
5307                "ISO C forbids omitting the middle term of a ?: expression");
5308       warn_for_omitted_condop (middle_loc, cond.value);
5309       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5310         {
5311           eptype = TREE_TYPE (cond.value);
5312           cond.value = TREE_OPERAND (cond.value, 0);
5313         }
5314       /* Make sure first operand is calculated only once.  */
5315       exp1.value = c_save_expr (default_conversion (cond.value));
5316       if (eptype)
5317         exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5318       exp1.original_type = NULL;
5319       cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5320       c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5321     }
5322   else
5323     {
5324       cond.value
5325         = c_objc_common_truthvalue_conversion
5326         (cond_loc, default_conversion (cond.value));
5327       c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5328       exp1 = c_parser_expression_conv (parser);
5329       mark_exp_read (exp1.value);
5330       c_inhibit_evaluation_warnings +=
5331         ((cond.value == truthvalue_true_node)
5332          - (cond.value == truthvalue_false_node));
5333     }
5334
5335   colon_loc = c_parser_peek_token (parser)->location;
5336   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5337     {
5338       c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5339       ret.value = error_mark_node;
5340       ret.original_code = ERROR_MARK;
5341       ret.original_type = NULL;
5342       return ret;
5343     }
5344   {
5345     location_t exp2_loc = c_parser_peek_token (parser)->location;
5346     exp2 = c_parser_conditional_expression (parser, NULL);
5347     exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5348   }
5349   c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5350   ret.value = build_conditional_expr (colon_loc, cond.value,
5351                                       cond.original_code == C_MAYBE_CONST_EXPR,
5352                                       exp1.value, exp1.original_type,
5353                                       exp2.value, exp2.original_type);
5354   ret.original_code = ERROR_MARK;
5355   if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5356     ret.original_type = NULL;
5357   else
5358     {
5359       tree t1, t2;
5360
5361       /* If both sides are enum type, the default conversion will have
5362          made the type of the result be an integer type.  We want to
5363          remember the enum types we started with.  */
5364       t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5365       t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5366       ret.original_type = ((t1 != error_mark_node
5367                             && t2 != error_mark_node
5368                             && (TYPE_MAIN_VARIANT (t1)
5369                                 == TYPE_MAIN_VARIANT (t2)))
5370                            ? t1
5371                            : NULL);
5372     }
5373   return ret;
5374 }
5375
5376 /* Parse a binary expression; that is, a logical-OR-expression (C90
5377    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
5378    an Objective-C message expression which is the primary-expression
5379    starting the expression as an initializer.
5380
5381    multiplicative-expression:
5382      cast-expression
5383      multiplicative-expression * cast-expression
5384      multiplicative-expression / cast-expression
5385      multiplicative-expression % cast-expression
5386
5387    additive-expression:
5388      multiplicative-expression
5389      additive-expression + multiplicative-expression
5390      additive-expression - multiplicative-expression
5391
5392    shift-expression:
5393      additive-expression
5394      shift-expression << additive-expression
5395      shift-expression >> additive-expression
5396
5397    relational-expression:
5398      shift-expression
5399      relational-expression < shift-expression
5400      relational-expression > shift-expression
5401      relational-expression <= shift-expression
5402      relational-expression >= shift-expression
5403
5404    equality-expression:
5405      relational-expression
5406      equality-expression == relational-expression
5407      equality-expression != relational-expression
5408
5409    AND-expression:
5410      equality-expression
5411      AND-expression & equality-expression
5412
5413    exclusive-OR-expression:
5414      AND-expression
5415      exclusive-OR-expression ^ AND-expression
5416
5417    inclusive-OR-expression:
5418      exclusive-OR-expression
5419      inclusive-OR-expression | exclusive-OR-expression
5420
5421    logical-AND-expression:
5422      inclusive-OR-expression
5423      logical-AND-expression && inclusive-OR-expression
5424
5425    logical-OR-expression:
5426      logical-AND-expression
5427      logical-OR-expression || logical-AND-expression
5428 */
5429
5430 static struct c_expr
5431 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5432 {
5433   /* A binary expression is parsed using operator-precedence parsing,
5434      with the operands being cast expressions.  All the binary
5435      operators are left-associative.  Thus a binary expression is of
5436      form:
5437
5438      E0 op1 E1 op2 E2 ...
5439
5440      which we represent on a stack.  On the stack, the precedence
5441      levels are strictly increasing.  When a new operator is
5442      encountered of higher precedence than that at the top of the
5443      stack, it is pushed; its LHS is the top expression, and its RHS
5444      is everything parsed until it is popped.  When a new operator is
5445      encountered with precedence less than or equal to that at the top
5446      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5447      by the result of the operation until the operator at the top of
5448      the stack has lower precedence than the new operator or there is
5449      only one element on the stack; then the top expression is the LHS
5450      of the new operator.  In the case of logical AND and OR
5451      expressions, we also need to adjust c_inhibit_evaluation_warnings
5452      as appropriate when the operators are pushed and popped.  */
5453
5454   /* The precedence levels, where 0 is a dummy lowest level used for
5455      the bottom of the stack.  */
5456   enum prec {
5457     PREC_NONE,
5458     PREC_LOGOR,
5459     PREC_LOGAND,
5460     PREC_BITOR,
5461     PREC_BITXOR,
5462     PREC_BITAND,
5463     PREC_EQ,
5464     PREC_REL,
5465     PREC_SHIFT,
5466     PREC_ADD,
5467     PREC_MULT,
5468     NUM_PRECS
5469   };
5470   struct {
5471     /* The expression at this stack level.  */
5472     struct c_expr expr;
5473     /* The precedence of the operator on its left, PREC_NONE at the
5474        bottom of the stack.  */
5475     enum prec prec;
5476     /* The operation on its left.  */
5477     enum tree_code op;
5478     /* The source location of this operation.  */
5479     location_t loc;
5480   } stack[NUM_PRECS];
5481   int sp;
5482   /* Location of the binary operator.  */
5483   location_t binary_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
5484 #define POP                                                                   \
5485   do {                                                                        \
5486     switch (stack[sp].op)                                                     \
5487       {                                                                       \
5488       case TRUTH_ANDIF_EXPR:                                                  \
5489         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
5490                                           == truthvalue_false_node);          \
5491         break;                                                                \
5492       case TRUTH_ORIF_EXPR:                                                   \
5493         c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value            \
5494                                           == truthvalue_true_node);           \
5495         break;                                                                \
5496       default:                                                                \
5497         break;                                                                \
5498       }                                                                       \
5499     stack[sp - 1].expr                                                        \
5500       = default_function_array_read_conversion (stack[sp - 1].loc,            \
5501                                                 stack[sp - 1].expr);          \
5502     stack[sp].expr                                                            \
5503       = default_function_array_read_conversion (stack[sp].loc,                \
5504                                                 stack[sp].expr);              \
5505     stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc,               \
5506                                                  stack[sp].op,                \
5507                                                  stack[sp - 1].expr,          \
5508                                                  stack[sp].expr);             \
5509     sp--;                                                                     \
5510   } while (0)
5511   gcc_assert (!after || c_dialect_objc ());
5512   stack[0].loc = c_parser_peek_token (parser)->location;
5513   stack[0].expr = c_parser_cast_expression (parser, after);
5514   stack[0].prec = PREC_NONE;
5515   sp = 0;
5516   while (true)
5517     {
5518       enum prec oprec;
5519       enum tree_code ocode;
5520       if (parser->error)
5521         goto out;
5522       switch (c_parser_peek_token (parser)->type)
5523         {
5524         case CPP_MULT:
5525           oprec = PREC_MULT;
5526           ocode = MULT_EXPR;
5527           break;
5528         case CPP_DIV:
5529           oprec = PREC_MULT;
5530           ocode = TRUNC_DIV_EXPR;
5531           break;
5532         case CPP_MOD:
5533           oprec = PREC_MULT;
5534           ocode = TRUNC_MOD_EXPR;
5535           break;
5536         case CPP_PLUS:
5537           oprec = PREC_ADD;
5538           ocode = PLUS_EXPR;
5539           break;
5540         case CPP_MINUS:
5541           oprec = PREC_ADD;
5542           ocode = MINUS_EXPR;
5543           break;
5544         case CPP_LSHIFT:
5545           oprec = PREC_SHIFT;
5546           ocode = LSHIFT_EXPR;
5547           break;
5548         case CPP_RSHIFT:
5549           oprec = PREC_SHIFT;
5550           ocode = RSHIFT_EXPR;
5551           break;
5552         case CPP_LESS:
5553           oprec = PREC_REL;
5554           ocode = LT_EXPR;
5555           break;
5556         case CPP_GREATER:
5557           oprec = PREC_REL;
5558           ocode = GT_EXPR;
5559           break;
5560         case CPP_LESS_EQ:
5561           oprec = PREC_REL;
5562           ocode = LE_EXPR;
5563           break;
5564         case CPP_GREATER_EQ:
5565           oprec = PREC_REL;
5566           ocode = GE_EXPR;
5567           break;
5568         case CPP_EQ_EQ:
5569           oprec = PREC_EQ;
5570           ocode = EQ_EXPR;
5571           break;
5572         case CPP_NOT_EQ:
5573           oprec = PREC_EQ;
5574           ocode = NE_EXPR;
5575           break;
5576         case CPP_AND:
5577           oprec = PREC_BITAND;
5578           ocode = BIT_AND_EXPR;
5579           break;
5580         case CPP_XOR:
5581           oprec = PREC_BITXOR;
5582           ocode = BIT_XOR_EXPR;
5583           break;
5584         case CPP_OR:
5585           oprec = PREC_BITOR;
5586           ocode = BIT_IOR_EXPR;
5587           break;
5588         case CPP_AND_AND:
5589           oprec = PREC_LOGAND;
5590           ocode = TRUTH_ANDIF_EXPR;
5591           break;
5592         case CPP_OR_OR:
5593           oprec = PREC_LOGOR;
5594           ocode = TRUTH_ORIF_EXPR;
5595           break;
5596         default:
5597           /* Not a binary operator, so end of the binary
5598              expression.  */
5599           goto out;
5600         }
5601       binary_loc = c_parser_peek_token (parser)->location;
5602       c_parser_consume_token (parser);
5603       while (oprec <= stack[sp].prec)
5604         POP;
5605       switch (ocode)
5606         {
5607         case TRUTH_ANDIF_EXPR:
5608           stack[sp].expr
5609             = default_function_array_read_conversion (stack[sp].loc,
5610                                                       stack[sp].expr);
5611           stack[sp].expr.value = c_objc_common_truthvalue_conversion
5612             (stack[sp].loc, default_conversion (stack[sp].expr.value));
5613           c_inhibit_evaluation_warnings += (stack[sp].expr.value
5614                                             == truthvalue_false_node);
5615           break;
5616         case TRUTH_ORIF_EXPR:
5617           stack[sp].expr
5618             = default_function_array_read_conversion (stack[sp].loc,
5619                                                       stack[sp].expr);
5620           stack[sp].expr.value = c_objc_common_truthvalue_conversion
5621             (stack[sp].loc, default_conversion (stack[sp].expr.value));
5622           c_inhibit_evaluation_warnings += (stack[sp].expr.value
5623                                             == truthvalue_true_node);
5624           break;
5625         default:
5626           break;
5627         }
5628       sp++;
5629       stack[sp].loc = binary_loc;
5630       stack[sp].expr = c_parser_cast_expression (parser, NULL);
5631       stack[sp].prec = oprec;
5632       stack[sp].op = ocode;
5633       stack[sp].loc = binary_loc;
5634     }
5635  out:
5636   while (sp > 0)
5637     POP;
5638   return stack[0].expr;
5639 #undef POP
5640 }
5641
5642 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
5643    NULL then it is an Objective-C message expression which is the
5644    primary-expression starting the expression as an initializer.
5645
5646    cast-expression:
5647      unary-expression
5648      ( type-name ) unary-expression
5649 */
5650
5651 static struct c_expr
5652 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5653 {
5654   location_t cast_loc = c_parser_peek_token (parser)->location;
5655   gcc_assert (!after || c_dialect_objc ());
5656   if (after)
5657     return c_parser_postfix_expression_after_primary (parser,
5658                                                       cast_loc, *after);
5659   /* If the expression begins with a parenthesized type name, it may
5660      be either a cast or a compound literal; we need to see whether
5661      the next character is '{' to tell the difference.  If not, it is
5662      an unary expression.  Full detection of unknown typenames here
5663      would require a 3-token lookahead.  */
5664   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5665       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5666     {
5667       struct c_type_name *type_name;
5668       struct c_expr ret;
5669       struct c_expr expr;
5670       c_parser_consume_token (parser);
5671       type_name = c_parser_type_name (parser);
5672       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5673       if (type_name == NULL)
5674         {
5675           ret.value = error_mark_node;
5676           ret.original_code = ERROR_MARK;
5677           ret.original_type = NULL;
5678           return ret;
5679         }
5680
5681       /* Save casted types in the function's used types hash table.  */
5682       used_types_insert (type_name->specs->type);
5683
5684       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5685         return c_parser_postfix_expression_after_paren_type (parser, type_name,
5686                                                              cast_loc);
5687       {
5688         location_t expr_loc = c_parser_peek_token (parser)->location;
5689         expr = c_parser_cast_expression (parser, NULL);
5690         expr = default_function_array_read_conversion (expr_loc, expr);
5691       }
5692       ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5693       ret.original_code = ERROR_MARK;
5694       ret.original_type = NULL;
5695       return ret;
5696     }
5697   else
5698     return c_parser_unary_expression (parser);
5699 }
5700
5701 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5702
5703    unary-expression:
5704      postfix-expression
5705      ++ unary-expression
5706      -- unary-expression
5707      unary-operator cast-expression
5708      sizeof unary-expression
5709      sizeof ( type-name )
5710
5711    unary-operator: one of
5712      & * + - ~ !
5713
5714    GNU extensions:
5715
5716    unary-expression:
5717      __alignof__ unary-expression
5718      __alignof__ ( type-name )
5719      && identifier
5720
5721    unary-operator: one of
5722      __extension__ __real__ __imag__
5723
5724    In addition, the GNU syntax treats ++ and -- as unary operators, so
5725    they may be applied to cast expressions with errors for non-lvalues
5726    given later.  */
5727
5728 static struct c_expr
5729 c_parser_unary_expression (c_parser *parser)
5730 {
5731   int ext;
5732   struct c_expr ret, op;
5733   location_t op_loc = c_parser_peek_token (parser)->location;
5734   location_t exp_loc;
5735   ret.original_code = ERROR_MARK;
5736   ret.original_type = NULL;
5737   switch (c_parser_peek_token (parser)->type)
5738     {
5739     case CPP_PLUS_PLUS:
5740       c_parser_consume_token (parser);
5741       exp_loc = c_parser_peek_token (parser)->location;
5742       op = c_parser_cast_expression (parser, NULL);
5743       op = default_function_array_read_conversion (exp_loc, op);
5744       return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5745     case CPP_MINUS_MINUS:
5746       c_parser_consume_token (parser);
5747       exp_loc = c_parser_peek_token (parser)->location;
5748       op = c_parser_cast_expression (parser, NULL);
5749       op = default_function_array_read_conversion (exp_loc, op);
5750       return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5751     case CPP_AND:
5752       c_parser_consume_token (parser);
5753       op = c_parser_cast_expression (parser, NULL);
5754       mark_exp_read (op.value);
5755       return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5756     case CPP_MULT:
5757       c_parser_consume_token (parser);
5758       exp_loc = c_parser_peek_token (parser)->location;
5759       op = c_parser_cast_expression (parser, NULL);
5760       op = default_function_array_read_conversion (exp_loc, op);
5761       ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5762       return ret;
5763     case CPP_PLUS:
5764       if (!c_dialect_objc () && !in_system_header)
5765         warning_at (op_loc,
5766                     OPT_Wtraditional,
5767                     "traditional C rejects the unary plus operator");
5768       c_parser_consume_token (parser);
5769       exp_loc = c_parser_peek_token (parser)->location;
5770       op = c_parser_cast_expression (parser, NULL);
5771       op = default_function_array_read_conversion (exp_loc, op);
5772       return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5773     case CPP_MINUS:
5774       c_parser_consume_token (parser);
5775       exp_loc = c_parser_peek_token (parser)->location;
5776       op = c_parser_cast_expression (parser, NULL);
5777       op = default_function_array_read_conversion (exp_loc, op);
5778       return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5779     case CPP_COMPL:
5780       c_parser_consume_token (parser);
5781       exp_loc = c_parser_peek_token (parser)->location;
5782       op = c_parser_cast_expression (parser, NULL);
5783       op = default_function_array_read_conversion (exp_loc, op);
5784       return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5785     case CPP_NOT:
5786       c_parser_consume_token (parser);
5787       exp_loc = c_parser_peek_token (parser)->location;
5788       op = c_parser_cast_expression (parser, NULL);
5789       op = default_function_array_read_conversion (exp_loc, op);
5790       return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5791     case CPP_AND_AND:
5792       /* Refer to the address of a label as a pointer.  */
5793       c_parser_consume_token (parser);
5794       if (c_parser_next_token_is (parser, CPP_NAME))
5795         {
5796           ret.value = finish_label_address_expr
5797             (c_parser_peek_token (parser)->value, op_loc);
5798           c_parser_consume_token (parser);
5799         }
5800       else
5801         {
5802           c_parser_error (parser, "expected identifier");
5803           ret.value = error_mark_node;
5804         }
5805         return ret;
5806     case CPP_KEYWORD:
5807       switch (c_parser_peek_token (parser)->keyword)
5808         {
5809         case RID_SIZEOF:
5810           return c_parser_sizeof_expression (parser);
5811         case RID_ALIGNOF:
5812           return c_parser_alignof_expression (parser);
5813         case RID_EXTENSION:
5814           c_parser_consume_token (parser);
5815           ext = disable_extension_diagnostics ();
5816           ret = c_parser_cast_expression (parser, NULL);
5817           restore_extension_diagnostics (ext);
5818           return ret;
5819         case RID_REALPART:
5820           c_parser_consume_token (parser);
5821           exp_loc = c_parser_peek_token (parser)->location;
5822           op = c_parser_cast_expression (parser, NULL);
5823           op = default_function_array_conversion (exp_loc, op);
5824           return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5825         case RID_IMAGPART:
5826           c_parser_consume_token (parser);
5827           exp_loc = c_parser_peek_token (parser)->location;
5828           op = c_parser_cast_expression (parser, NULL);
5829           op = default_function_array_conversion (exp_loc, op);
5830           return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5831         default:
5832           return c_parser_postfix_expression (parser);
5833         }
5834     default:
5835       return c_parser_postfix_expression (parser);
5836     }
5837 }
5838
5839 /* Parse a sizeof expression.  */
5840
5841 static struct c_expr
5842 c_parser_sizeof_expression (c_parser *parser)
5843 {
5844   struct c_expr expr;
5845   location_t expr_loc;
5846   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5847   c_parser_consume_token (parser);
5848   c_inhibit_evaluation_warnings++;
5849   in_sizeof++;
5850   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5851       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5852     {
5853       /* Either sizeof ( type-name ) or sizeof unary-expression
5854          starting with a compound literal.  */
5855       struct c_type_name *type_name;
5856       c_parser_consume_token (parser);
5857       expr_loc = c_parser_peek_token (parser)->location;
5858       type_name = c_parser_type_name (parser);
5859       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5860       if (type_name == NULL)
5861         {
5862           struct c_expr ret;
5863           c_inhibit_evaluation_warnings--;
5864           in_sizeof--;
5865           ret.value = error_mark_node;
5866           ret.original_code = ERROR_MARK;
5867           ret.original_type = NULL;
5868           return ret;
5869         }
5870       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5871         {
5872           expr = c_parser_postfix_expression_after_paren_type (parser,
5873                                                                type_name,
5874                                                                expr_loc);
5875           goto sizeof_expr;
5876         }
5877       /* sizeof ( type-name ).  */
5878       c_inhibit_evaluation_warnings--;
5879       in_sizeof--;
5880       return c_expr_sizeof_type (expr_loc, type_name);
5881     }
5882   else
5883     {
5884       expr_loc = c_parser_peek_token (parser)->location;
5885       expr = c_parser_unary_expression (parser);
5886     sizeof_expr:
5887       c_inhibit_evaluation_warnings--;
5888       in_sizeof--;
5889       mark_exp_read (expr.value);
5890       if (TREE_CODE (expr.value) == COMPONENT_REF
5891           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5892         error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5893       return c_expr_sizeof_expr (expr_loc, expr);
5894     }
5895 }
5896
5897 /* Parse an alignof expression.  */
5898
5899 static struct c_expr
5900 c_parser_alignof_expression (c_parser *parser)
5901 {
5902   struct c_expr expr;
5903   location_t loc = c_parser_peek_token (parser)->location;
5904   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5905   c_parser_consume_token (parser);
5906   c_inhibit_evaluation_warnings++;
5907   in_alignof++;
5908   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5909       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5910     {
5911       /* Either __alignof__ ( type-name ) or __alignof__
5912          unary-expression starting with a compound literal.  */
5913       location_t loc;
5914       struct c_type_name *type_name;
5915       struct c_expr ret;
5916       c_parser_consume_token (parser);
5917       loc = c_parser_peek_token (parser)->location;
5918       type_name = c_parser_type_name (parser);
5919       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5920       if (type_name == NULL)
5921         {
5922           struct c_expr ret;
5923           c_inhibit_evaluation_warnings--;
5924           in_alignof--;
5925           ret.value = error_mark_node;
5926           ret.original_code = ERROR_MARK;
5927           ret.original_type = NULL;
5928           return ret;
5929         }
5930       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5931         {
5932           expr = c_parser_postfix_expression_after_paren_type (parser,
5933                                                                type_name,
5934                                                                loc);
5935           goto alignof_expr;
5936         }
5937       /* alignof ( type-name ).  */
5938       c_inhibit_evaluation_warnings--;
5939       in_alignof--;
5940       ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5941       ret.original_code = ERROR_MARK;
5942       ret.original_type = NULL;
5943       return ret;
5944     }
5945   else
5946     {
5947       struct c_expr ret;
5948       expr = c_parser_unary_expression (parser);
5949     alignof_expr:
5950       mark_exp_read (expr.value);
5951       c_inhibit_evaluation_warnings--;
5952       in_alignof--;
5953       ret.value = c_alignof_expr (loc, expr.value);
5954       ret.original_code = ERROR_MARK;
5955       ret.original_type = NULL;
5956       return ret;
5957     }
5958 }
5959
5960 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5961
5962    postfix-expression:
5963      primary-expression
5964      postfix-expression [ expression ]
5965      postfix-expression ( argument-expression-list[opt] )
5966      postfix-expression . identifier
5967      postfix-expression -> identifier
5968      postfix-expression ++
5969      postfix-expression --
5970      ( type-name ) { initializer-list }
5971      ( type-name ) { initializer-list , }
5972
5973    argument-expression-list:
5974      argument-expression
5975      argument-expression-list , argument-expression
5976
5977    primary-expression:
5978      identifier
5979      constant
5980      string-literal
5981      ( expression )
5982
5983    GNU extensions:
5984
5985    primary-expression:
5986      __func__
5987        (treated as a keyword in GNU C)
5988      __FUNCTION__
5989      __PRETTY_FUNCTION__
5990      ( compound-statement )
5991      __builtin_va_arg ( assignment-expression , type-name )
5992      __builtin_offsetof ( type-name , offsetof-member-designator )
5993      __builtin_choose_expr ( assignment-expression ,
5994                              assignment-expression ,
5995                              assignment-expression )
5996      __builtin_types_compatible_p ( type-name , type-name )
5997
5998    offsetof-member-designator:
5999      identifier
6000      offsetof-member-designator . identifier
6001      offsetof-member-designator [ expression ]
6002
6003    Objective-C:
6004
6005    primary-expression:
6006      [ objc-receiver objc-message-args ]
6007      @selector ( objc-selector-arg )
6008      @protocol ( identifier )
6009      @encode ( type-name )
6010      objc-string-literal
6011      Classname . identifier
6012 */
6013
6014 static struct c_expr
6015 c_parser_postfix_expression (c_parser *parser)
6016 {
6017   struct c_expr expr, e1, e2, e3;
6018   struct c_type_name *t1, *t2;
6019   location_t loc = c_parser_peek_token (parser)->location;;
6020   expr.original_code = ERROR_MARK;
6021   expr.original_type = NULL;
6022   switch (c_parser_peek_token (parser)->type)
6023     {
6024     case CPP_NUMBER:
6025       expr.value = c_parser_peek_token (parser)->value;
6026       loc = c_parser_peek_token (parser)->location;
6027       c_parser_consume_token (parser);
6028       if (TREE_CODE (expr.value) == FIXED_CST
6029           && !targetm.fixed_point_supported_p ())
6030         {
6031           error_at (loc, "fixed-point types not supported for this target");
6032           expr.value = error_mark_node;
6033         }
6034       break;
6035     case CPP_CHAR:
6036     case CPP_CHAR16:
6037     case CPP_CHAR32:
6038     case CPP_WCHAR:
6039       expr.value = c_parser_peek_token (parser)->value;
6040       c_parser_consume_token (parser);
6041       break;
6042     case CPP_STRING:
6043     case CPP_STRING16:
6044     case CPP_STRING32:
6045     case CPP_WSTRING:
6046     case CPP_UTF8STRING:
6047       expr.value = c_parser_peek_token (parser)->value;
6048       expr.original_code = STRING_CST;
6049       c_parser_consume_token (parser);
6050       break;
6051     case CPP_OBJC_STRING:
6052       gcc_assert (c_dialect_objc ());
6053       expr.value
6054         = objc_build_string_object (c_parser_peek_token (parser)->value);
6055       c_parser_consume_token (parser);
6056       break;
6057     case CPP_NAME:
6058       switch (c_parser_peek_token (parser)->id_kind)
6059         {
6060         case C_ID_ID:
6061           {
6062             tree id = c_parser_peek_token (parser)->value;
6063             c_parser_consume_token (parser);
6064             expr.value = build_external_ref (loc, id,
6065                                              (c_parser_peek_token (parser)->type
6066                                               == CPP_OPEN_PAREN),
6067                                              &expr.original_type);
6068             break;
6069           }
6070         case C_ID_CLASSNAME:
6071           {
6072             /* Here we parse the Objective-C 2.0 Class.name dot
6073                syntax.  */
6074             tree class_name = c_parser_peek_token (parser)->value;
6075             tree component;
6076             c_parser_consume_token (parser);
6077             gcc_assert (c_dialect_objc ());
6078             if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6079               {
6080                 expr.value = error_mark_node;
6081                 break;
6082               }
6083             if (c_parser_next_token_is_not (parser, CPP_NAME))
6084               {
6085                 c_parser_error (parser, "expected identifier");
6086                 expr.value = error_mark_node;
6087                 break;
6088               }
6089             component = c_parser_peek_token (parser)->value;
6090             c_parser_consume_token (parser);
6091             expr.value = objc_build_class_component_ref (class_name, 
6092                                                          component);
6093             break;
6094           }
6095         default:
6096           c_parser_error (parser, "expected expression");
6097           expr.value = error_mark_node;
6098           break;
6099         }
6100       break;
6101     case CPP_OPEN_PAREN:
6102       /* A parenthesized expression, statement expression or compound
6103          literal.  */
6104       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6105         {
6106           /* A statement expression.  */
6107           tree stmt;
6108           location_t brace_loc;
6109           c_parser_consume_token (parser);
6110           brace_loc = c_parser_peek_token (parser)->location;
6111           c_parser_consume_token (parser);
6112           if (cur_stmt_list == NULL)
6113             {
6114               error_at (loc, "braced-group within expression allowed "
6115                         "only inside a function");
6116               parser->error = true;
6117               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6118               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6119               expr.value = error_mark_node;
6120               break;
6121             }
6122           stmt = c_begin_stmt_expr ();
6123           c_parser_compound_statement_nostart (parser);
6124           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6125                                      "expected %<)%>");
6126           pedwarn (loc, OPT_pedantic,
6127                    "ISO C forbids braced-groups within expressions");
6128           expr.value = c_finish_stmt_expr (brace_loc, stmt);
6129           mark_exp_read (expr.value);
6130         }
6131       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6132         {
6133           /* A compound literal.  ??? Can we actually get here rather
6134              than going directly to
6135              c_parser_postfix_expression_after_paren_type from
6136              elsewhere?  */
6137           location_t loc;
6138           struct c_type_name *type_name;
6139           c_parser_consume_token (parser);
6140           loc = c_parser_peek_token (parser)->location;
6141           type_name = c_parser_type_name (parser);
6142           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6143                                      "expected %<)%>");
6144           if (type_name == NULL)
6145             {
6146               expr.value = error_mark_node;
6147             }
6148           else
6149             expr = c_parser_postfix_expression_after_paren_type (parser,
6150                                                                  type_name,
6151                                                                  loc);
6152         }
6153       else
6154         {
6155           /* A parenthesized expression.  */
6156           c_parser_consume_token (parser);
6157           expr = c_parser_expression (parser);
6158           if (TREE_CODE (expr.value) == MODIFY_EXPR)
6159             TREE_NO_WARNING (expr.value) = 1;
6160           if (expr.original_code != C_MAYBE_CONST_EXPR)
6161             expr.original_code = ERROR_MARK;
6162           /* Don't change EXPR.ORIGINAL_TYPE.  */
6163           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6164                                      "expected %<)%>");
6165         }
6166       break;
6167     case CPP_KEYWORD:
6168       switch (c_parser_peek_token (parser)->keyword)
6169         {
6170         case RID_FUNCTION_NAME:
6171         case RID_PRETTY_FUNCTION_NAME:
6172         case RID_C99_FUNCTION_NAME:
6173           expr.value = fname_decl (loc,
6174                                    c_parser_peek_token (parser)->keyword,
6175                                    c_parser_peek_token (parser)->value);
6176           c_parser_consume_token (parser);
6177           break;
6178         case RID_VA_ARG:
6179           c_parser_consume_token (parser);
6180           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6181             {
6182               expr.value = error_mark_node;
6183               break;
6184             }
6185           e1 = c_parser_expr_no_commas (parser, NULL);
6186           mark_exp_read (e1.value);
6187           e1.value = c_fully_fold (e1.value, false, NULL);
6188           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6189             {
6190               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6191               expr.value = error_mark_node;
6192               break;
6193             }
6194           loc = c_parser_peek_token (parser)->location;
6195           t1 = c_parser_type_name (parser);
6196           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6197                                      "expected %<)%>");
6198           if (t1 == NULL)
6199             {
6200               expr.value = error_mark_node;
6201             }
6202           else
6203             {
6204               tree type_expr = NULL_TREE;
6205               expr.value = c_build_va_arg (loc, e1.value,
6206                                            groktypename (t1, &type_expr, NULL));
6207               if (type_expr)
6208                 {
6209                   expr.value = build2 (C_MAYBE_CONST_EXPR,
6210                                        TREE_TYPE (expr.value), type_expr,
6211                                        expr.value);
6212                   C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6213                 }
6214             }
6215           break;
6216         case RID_OFFSETOF:
6217           c_parser_consume_token (parser);
6218           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6219             {
6220               expr.value = error_mark_node;
6221               break;
6222             }
6223           t1 = c_parser_type_name (parser);
6224           if (t1 == NULL)
6225             parser->error = true;
6226           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6227             gcc_assert (parser->error);
6228           if (parser->error)
6229             {
6230               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6231               expr.value = error_mark_node;
6232               break;
6233             }
6234
6235           {
6236             tree type = groktypename (t1, NULL, NULL);
6237             tree offsetof_ref;
6238             if (type == error_mark_node)
6239               offsetof_ref = error_mark_node;
6240             else
6241               {
6242                 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6243                 SET_EXPR_LOCATION (offsetof_ref, loc);
6244               }
6245             /* Parse the second argument to __builtin_offsetof.  We
6246                must have one identifier, and beyond that we want to
6247                accept sub structure and sub array references.  */
6248             if (c_parser_next_token_is (parser, CPP_NAME))
6249               {
6250                 offsetof_ref = build_component_ref
6251                   (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6252                 c_parser_consume_token (parser);
6253                 while (c_parser_next_token_is (parser, CPP_DOT)
6254                        || c_parser_next_token_is (parser,
6255                                                   CPP_OPEN_SQUARE)
6256                        || c_parser_next_token_is (parser,
6257                                                   CPP_DEREF))
6258                   {
6259                     if (c_parser_next_token_is (parser, CPP_DEREF))
6260                       {
6261                         loc = c_parser_peek_token (parser)->location;
6262                         offsetof_ref = build_array_ref (loc,
6263                                                         offsetof_ref,
6264                                                         integer_zero_node);
6265                         goto do_dot;
6266                       }
6267                     else if (c_parser_next_token_is (parser, CPP_DOT))
6268                       {
6269                       do_dot:
6270                         c_parser_consume_token (parser);
6271                         if (c_parser_next_token_is_not (parser,
6272                                                         CPP_NAME))
6273                           {
6274                             c_parser_error (parser, "expected identifier");
6275                             break;
6276                           }
6277                         offsetof_ref = build_component_ref
6278                           (loc, offsetof_ref,
6279                            c_parser_peek_token (parser)->value);
6280                         c_parser_consume_token (parser);
6281                       }
6282                     else
6283                       {
6284                         tree idx;
6285                         loc = c_parser_peek_token (parser)->location;
6286                         c_parser_consume_token (parser);
6287                         idx = c_parser_expression (parser).value;
6288                         idx = c_fully_fold (idx, false, NULL);
6289                         c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6290                                                    "expected %<]%>");
6291                         offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6292                       }
6293                   }
6294               }
6295             else
6296               c_parser_error (parser, "expected identifier");
6297             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6298                                        "expected %<)%>");
6299             expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6300           }
6301           break;
6302         case RID_CHOOSE_EXPR:
6303           c_parser_consume_token (parser);
6304           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6305             {
6306               expr.value = error_mark_node;
6307               break;
6308             }
6309           loc = c_parser_peek_token (parser)->location;
6310           e1 = c_parser_expr_no_commas (parser, NULL);
6311           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6312             {
6313               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6314               expr.value = error_mark_node;
6315               break;
6316             }
6317           e2 = c_parser_expr_no_commas (parser, NULL);
6318           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6319             {
6320               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6321               expr.value = error_mark_node;
6322               break;
6323             }
6324           e3 = c_parser_expr_no_commas (parser, NULL);
6325           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6326                                      "expected %<)%>");
6327           {
6328             tree c;
6329
6330             c = e1.value;
6331             mark_exp_read (e2.value);
6332             mark_exp_read (e3.value);
6333             if (TREE_CODE (c) != INTEGER_CST
6334                 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6335               error_at (loc,
6336                         "first argument to %<__builtin_choose_expr%> not"
6337                         " a constant");
6338             constant_expression_warning (c);
6339             expr = integer_zerop (c) ? e3 : e2;
6340           }
6341           break;
6342         case RID_TYPES_COMPATIBLE_P:
6343           c_parser_consume_token (parser);
6344           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6345             {
6346               expr.value = error_mark_node;
6347               break;
6348             }
6349           t1 = c_parser_type_name (parser);
6350           if (t1 == NULL)
6351             {
6352               expr.value = error_mark_node;
6353               break;
6354             }
6355           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6356             {
6357               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6358               expr.value = error_mark_node;
6359               break;
6360             }
6361           t2 = c_parser_type_name (parser);
6362           if (t2 == NULL)
6363             {
6364               expr.value = error_mark_node;
6365               break;
6366             }
6367           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6368                                      "expected %<)%>");
6369           {
6370             tree e1, e2;
6371
6372             e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6373             e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6374
6375             expr.value
6376               = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6377           }
6378           break;
6379         case RID_AT_SELECTOR:
6380           gcc_assert (c_dialect_objc ());
6381           c_parser_consume_token (parser);
6382           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6383             {
6384               expr.value = error_mark_node;
6385               break;
6386             }
6387           {
6388             tree sel = c_parser_objc_selector_arg (parser);
6389             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6390                                        "expected %<)%>");
6391             expr.value = objc_build_selector_expr (loc, sel);
6392           }
6393           break;
6394         case RID_AT_PROTOCOL:
6395           gcc_assert (c_dialect_objc ());
6396           c_parser_consume_token (parser);
6397           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6398             {
6399               expr.value = error_mark_node;
6400               break;
6401             }
6402           if (c_parser_next_token_is_not (parser, CPP_NAME))
6403             {
6404               c_parser_error (parser, "expected identifier");
6405               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6406               expr.value = error_mark_node;
6407               break;
6408             }
6409           {
6410             tree id = c_parser_peek_token (parser)->value;
6411             c_parser_consume_token (parser);
6412             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6413                                        "expected %<)%>");
6414             expr.value = objc_build_protocol_expr (id);
6415           }
6416           break;
6417         case RID_AT_ENCODE:
6418           /* Extension to support C-structures in the archiver.  */
6419           gcc_assert (c_dialect_objc ());
6420           c_parser_consume_token (parser);
6421           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6422             {
6423               expr.value = error_mark_node;
6424               break;
6425             }
6426           t1 = c_parser_type_name (parser);
6427           if (t1 == NULL)
6428             {
6429               expr.value = error_mark_node;
6430               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6431               break;
6432             }
6433           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6434                                      "expected %<)%>");
6435           {
6436             tree type = groktypename (t1, NULL, NULL);
6437             expr.value = objc_build_encode_expr (type);
6438           }
6439           break;
6440         default:
6441           c_parser_error (parser, "expected expression");
6442           expr.value = error_mark_node;
6443           break;
6444         }
6445       break;
6446     case CPP_OPEN_SQUARE:
6447       if (c_dialect_objc ())
6448         {
6449           tree receiver, args;
6450           c_parser_consume_token (parser);
6451           receiver = c_parser_objc_receiver (parser);
6452           args = c_parser_objc_message_args (parser);
6453           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6454                                      "expected %<]%>");
6455           expr.value = objc_build_message_expr (build_tree_list (receiver,
6456                                                                  args));
6457           break;
6458         }
6459       /* Else fall through to report error.  */
6460     default:
6461       c_parser_error (parser, "expected expression");
6462       expr.value = error_mark_node;
6463       break;
6464     }
6465   return c_parser_postfix_expression_after_primary (parser, loc, expr);
6466 }
6467
6468 /* Parse a postfix expression after a parenthesized type name: the
6469    brace-enclosed initializer of a compound literal, possibly followed
6470    by some postfix operators.  This is separate because it is not
6471    possible to tell until after the type name whether a cast
6472    expression has a cast or a compound literal, or whether the operand
6473    of sizeof is a parenthesized type name or starts with a compound
6474    literal.  TYPE_LOC is the location where TYPE_NAME starts--the
6475    location of the first token after the parentheses around the type
6476    name.  */
6477
6478 static struct c_expr
6479 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6480                                               struct c_type_name *type_name,
6481                                               location_t type_loc)
6482 {
6483   tree type;
6484   struct c_expr init;
6485   bool non_const;
6486   struct c_expr expr;
6487   location_t start_loc;
6488   tree type_expr = NULL_TREE;
6489   bool type_expr_const = true;
6490   check_compound_literal_type (type_loc, type_name);
6491   start_init (NULL_TREE, NULL, 0);
6492   type = groktypename (type_name, &type_expr, &type_expr_const);
6493   start_loc = c_parser_peek_token (parser)->location;
6494   if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6495     {
6496       error_at (type_loc, "compound literal has variable size");
6497       type = error_mark_node;
6498     }
6499   init = c_parser_braced_init (parser, type, false);
6500   finish_init ();
6501   maybe_warn_string_init (type, init);
6502
6503   if (type != error_mark_node
6504       && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6505       && current_function_decl)
6506     {
6507       error ("compound literal qualified by address-space qualifier");
6508       type = error_mark_node;
6509     }
6510
6511   if (!flag_isoc99)
6512     pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6513   non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6514                ? CONSTRUCTOR_NON_CONST (init.value)
6515                : init.original_code == C_MAYBE_CONST_EXPR);
6516   non_const |= !type_expr_const;
6517   expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6518   expr.original_code = ERROR_MARK;
6519   expr.original_type = NULL;
6520   if (type_expr)
6521     {
6522       if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6523         {
6524           gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6525           C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6526         }
6527       else
6528         {
6529           gcc_assert (!non_const);
6530           expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6531                                type_expr, expr.value);
6532         }
6533     }
6534   return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6535 }
6536
6537 /* Parse a postfix expression after the initial primary or compound
6538    literal; that is, parse a series of postfix operators.
6539
6540    EXPR_LOC is the location of the primary expression.  */
6541
6542 static struct c_expr
6543 c_parser_postfix_expression_after_primary (c_parser *parser,
6544                                            location_t expr_loc,
6545                                            struct c_expr expr)
6546 {
6547   struct c_expr orig_expr;
6548   tree ident, idx;
6549   VEC(tree,gc) *exprlist;
6550   VEC(tree,gc) *origtypes;
6551   while (true)
6552     {
6553       location_t op_loc = c_parser_peek_token (parser)->location;
6554       switch (c_parser_peek_token (parser)->type)
6555         {
6556         case CPP_OPEN_SQUARE:
6557           /* Array reference.  */
6558           c_parser_consume_token (parser);
6559           idx = c_parser_expression (parser).value;
6560           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6561                                      "expected %<]%>");
6562           expr.value = build_array_ref (op_loc, expr.value, idx);
6563           expr.original_code = ERROR_MARK;
6564           expr.original_type = NULL;
6565           break;
6566         case CPP_OPEN_PAREN:
6567           /* Function call.  */
6568           c_parser_consume_token (parser);
6569           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6570             exprlist = NULL;
6571           else
6572             exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6573           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6574                                      "expected %<)%>");
6575           orig_expr = expr;
6576           mark_exp_read (expr.value);
6577           /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6578              "(" after the FUNCNAME, which is what we have now.    */
6579           expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6580                                                 origtypes);
6581           expr.original_code = ERROR_MARK;
6582           if (TREE_CODE (expr.value) == INTEGER_CST
6583               && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6584               && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6585               && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6586             expr.original_code = C_MAYBE_CONST_EXPR;
6587           expr.original_type = NULL;
6588           if (exprlist != NULL)
6589             {
6590               release_tree_vector (exprlist);
6591               release_tree_vector (origtypes);
6592             }
6593           break;
6594         case CPP_DOT:
6595           /* Structure element reference.  */
6596           c_parser_consume_token (parser);
6597           expr = default_function_array_conversion (expr_loc, expr);
6598           if (c_parser_next_token_is (parser, CPP_NAME))
6599             ident = c_parser_peek_token (parser)->value;
6600           else
6601             {
6602               c_parser_error (parser, "expected identifier");
6603               expr.value = error_mark_node;
6604               expr.original_code = ERROR_MARK;
6605               expr.original_type = NULL;
6606               return expr;
6607             }
6608           c_parser_consume_token (parser);
6609           expr.value = build_component_ref (op_loc, expr.value, ident);
6610           expr.original_code = ERROR_MARK;
6611           if (TREE_CODE (expr.value) != COMPONENT_REF)
6612             expr.original_type = NULL;
6613           else
6614             {
6615               /* Remember the original type of a bitfield.  */
6616               tree field = TREE_OPERAND (expr.value, 1);
6617               if (TREE_CODE (field) != FIELD_DECL)
6618                 expr.original_type = NULL;
6619               else
6620                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6621             }
6622           break;
6623         case CPP_DEREF:
6624           /* Structure element reference.  */
6625           c_parser_consume_token (parser);
6626           expr = default_function_array_conversion (expr_loc, expr);
6627           if (c_parser_next_token_is (parser, CPP_NAME))
6628             ident = c_parser_peek_token (parser)->value;
6629           else
6630             {
6631               c_parser_error (parser, "expected identifier");
6632               expr.value = error_mark_node;
6633               expr.original_code = ERROR_MARK;
6634               expr.original_type = NULL;
6635               return expr;
6636             }
6637           c_parser_consume_token (parser);
6638           expr.value = build_component_ref (op_loc,
6639                                             build_indirect_ref (op_loc,
6640                                                                 expr.value,
6641                                                                 RO_ARROW),
6642                                             ident);
6643           expr.original_code = ERROR_MARK;
6644           if (TREE_CODE (expr.value) != COMPONENT_REF)
6645             expr.original_type = NULL;
6646           else
6647             {
6648               /* Remember the original type of a bitfield.  */
6649               tree field = TREE_OPERAND (expr.value, 1);
6650               if (TREE_CODE (field) != FIELD_DECL)
6651                 expr.original_type = NULL;
6652               else
6653                 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6654             }
6655           break;
6656         case CPP_PLUS_PLUS:
6657           /* Postincrement.  */
6658           c_parser_consume_token (parser);
6659           expr = default_function_array_read_conversion (expr_loc, expr);
6660           expr.value = build_unary_op (op_loc,
6661                                        POSTINCREMENT_EXPR, expr.value, 0);
6662           expr.original_code = ERROR_MARK;
6663           expr.original_type = NULL;
6664           break;
6665         case CPP_MINUS_MINUS:
6666           /* Postdecrement.  */
6667           c_parser_consume_token (parser);
6668           expr = default_function_array_read_conversion (expr_loc, expr);
6669           expr.value = build_unary_op (op_loc,
6670                                        POSTDECREMENT_EXPR, expr.value, 0);
6671           expr.original_code = ERROR_MARK;
6672           expr.original_type = NULL;
6673           break;
6674         default:
6675           return expr;
6676         }
6677     }
6678 }
6679
6680 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6681
6682    expression:
6683      assignment-expression
6684      expression , assignment-expression
6685 */
6686
6687 static struct c_expr
6688 c_parser_expression (c_parser *parser)
6689 {
6690   struct c_expr expr;
6691   expr = c_parser_expr_no_commas (parser, NULL);
6692   while (c_parser_next_token_is (parser, CPP_COMMA))
6693     {
6694       struct c_expr next;
6695       tree lhsval;
6696       location_t loc = c_parser_peek_token (parser)->location;
6697       location_t expr_loc;
6698       c_parser_consume_token (parser);
6699       expr_loc = c_parser_peek_token (parser)->location;
6700       lhsval = expr.value;
6701       while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6702         lhsval = TREE_OPERAND (lhsval, 1);
6703       if (DECL_P (lhsval) || handled_component_p (lhsval))
6704         mark_exp_read (lhsval);
6705       next = c_parser_expr_no_commas (parser, NULL);
6706       next = default_function_array_conversion (expr_loc, next);
6707       expr.value = build_compound_expr (loc, expr.value, next.value);
6708       expr.original_code = COMPOUND_EXPR;
6709       expr.original_type = next.original_type;
6710     }
6711   return expr;
6712 }
6713
6714 /* Parse an expression and convert functions or arrays to
6715    pointers.  */
6716
6717 static struct c_expr
6718 c_parser_expression_conv (c_parser *parser)
6719 {
6720   struct c_expr expr;
6721   location_t loc = c_parser_peek_token (parser)->location;
6722   expr = c_parser_expression (parser);
6723   expr = default_function_array_conversion (loc, expr);
6724   return expr;
6725 }
6726
6727 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
6728    functions and arrays to pointers.  If FOLD_P, fold the expressions.
6729
6730    nonempty-expr-list:
6731      assignment-expression
6732      nonempty-expr-list , assignment-expression
6733 */
6734
6735 static VEC(tree,gc) *
6736 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6737                     VEC(tree,gc) **p_orig_types)
6738 {
6739   VEC(tree,gc) *ret;
6740   VEC(tree,gc) *orig_types;
6741   struct c_expr expr;
6742   location_t loc = c_parser_peek_token (parser)->location;
6743
6744   ret = make_tree_vector ();
6745   if (p_orig_types == NULL)
6746     orig_types = NULL;
6747   else
6748     orig_types = make_tree_vector ();
6749
6750   expr = c_parser_expr_no_commas (parser, NULL);
6751   if (convert_p)
6752     expr = default_function_array_read_conversion (loc, expr);
6753   if (fold_p)
6754     expr.value = c_fully_fold (expr.value, false, NULL);
6755   VEC_quick_push (tree, ret, expr.value);
6756   if (orig_types != NULL)
6757     VEC_quick_push (tree, orig_types, expr.original_type);
6758   while (c_parser_next_token_is (parser, CPP_COMMA))
6759     {
6760       c_parser_consume_token (parser);
6761       loc = c_parser_peek_token (parser)->location;
6762       expr = c_parser_expr_no_commas (parser, NULL);
6763       if (convert_p)
6764         expr = default_function_array_read_conversion (loc, expr);
6765       if (fold_p)
6766         expr.value = c_fully_fold (expr.value, false, NULL);
6767       VEC_safe_push (tree, gc, ret, expr.value);
6768       if (orig_types != NULL)
6769         VEC_safe_push (tree, gc, orig_types, expr.original_type);
6770     }
6771   if (orig_types != NULL)
6772     *p_orig_types = orig_types;
6773   return ret;
6774 }
6775 \f
6776 /* Parse Objective-C-specific constructs.  */
6777
6778 /* Parse an objc-class-definition.
6779
6780    objc-class-definition:
6781      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6782        objc-class-instance-variables[opt] objc-methodprotolist @end
6783      @implementation identifier objc-superclass[opt]
6784        objc-class-instance-variables[opt]
6785      @interface identifier ( identifier ) objc-protocol-refs[opt]
6786        objc-methodprotolist @end
6787      @interface identifier ( ) objc-protocol-refs[opt]
6788        objc-methodprotolist @end
6789      @implementation identifier ( identifier )
6790
6791    objc-superclass:
6792      : identifier
6793
6794    "@interface identifier (" must start "@interface identifier (
6795    identifier ) ...": objc-methodprotolist in the first production may
6796    not start with a parenthesized identifier as a declarator of a data
6797    definition with no declaration specifiers if the objc-superclass,
6798    objc-protocol-refs and objc-class-instance-variables are omitted.  */
6799
6800 static void
6801 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6802 {
6803   bool iface_p;
6804   tree id1;
6805   tree superclass;
6806   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6807     iface_p = true;
6808   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6809     iface_p = false;
6810   else
6811     gcc_unreachable ();
6812
6813   c_parser_consume_token (parser);
6814   if (c_parser_next_token_is_not (parser, CPP_NAME))
6815     {
6816       c_parser_error (parser, "expected identifier");
6817       return;
6818     }
6819   id1 = c_parser_peek_token (parser)->value;
6820   c_parser_consume_token (parser);
6821   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6822     {
6823       /* We have a category or class extension.  */
6824       tree id2;
6825       tree proto = NULL_TREE;
6826       c_parser_consume_token (parser);
6827       if (c_parser_next_token_is_not (parser, CPP_NAME))
6828         {
6829           if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6830             {
6831               /* We have a class extension.  */
6832               id2 = NULL_TREE;
6833             }
6834           else
6835             {
6836               c_parser_error (parser, "expected identifier or %<)%>");
6837               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6838               return;
6839             }
6840         }
6841       else
6842         {
6843           id2 = c_parser_peek_token (parser)->value;
6844           c_parser_consume_token (parser);
6845         }
6846       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6847       if (!iface_p)
6848         {
6849           objc_start_category_implementation (id1, id2);
6850           return;
6851         }
6852       if (c_parser_next_token_is (parser, CPP_LESS))
6853         proto = c_parser_objc_protocol_refs (parser);
6854       objc_start_category_interface (id1, id2, proto, attributes);
6855       c_parser_objc_methodprotolist (parser);
6856       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6857       objc_finish_interface ();
6858       return;
6859     }
6860   if (c_parser_next_token_is (parser, CPP_COLON))
6861     {
6862       c_parser_consume_token (parser);
6863       if (c_parser_next_token_is_not (parser, CPP_NAME))
6864         {
6865           c_parser_error (parser, "expected identifier");
6866           return;
6867         }
6868       superclass = c_parser_peek_token (parser)->value;
6869       c_parser_consume_token (parser);
6870     }
6871   else
6872     superclass = NULL_TREE;
6873   if (iface_p)
6874     {
6875       tree proto = NULL_TREE;
6876       if (c_parser_next_token_is (parser, CPP_LESS))
6877         proto = c_parser_objc_protocol_refs (parser);
6878       objc_start_class_interface (id1, superclass, proto, attributes);
6879     }
6880   else
6881     objc_start_class_implementation (id1, superclass);
6882   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6883     c_parser_objc_class_instance_variables (parser);
6884   if (iface_p)
6885     {
6886       objc_continue_interface ();
6887       c_parser_objc_methodprotolist (parser);
6888       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6889       objc_finish_interface ();
6890     }
6891   else
6892     {
6893       objc_continue_implementation ();
6894       return;
6895     }
6896 }
6897
6898 /* Parse objc-class-instance-variables.
6899
6900    objc-class-instance-variables:
6901      { objc-instance-variable-decl-list[opt] }
6902
6903    objc-instance-variable-decl-list:
6904      objc-visibility-spec
6905      objc-instance-variable-decl ;
6906      ;
6907      objc-instance-variable-decl-list objc-visibility-spec
6908      objc-instance-variable-decl-list objc-instance-variable-decl ;
6909      objc-instance-variable-decl-list ;
6910
6911    objc-visibility-spec:
6912      @private
6913      @protected
6914      @public
6915
6916    objc-instance-variable-decl:
6917      struct-declaration
6918 */
6919
6920 static void
6921 c_parser_objc_class_instance_variables (c_parser *parser)
6922 {
6923   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6924   c_parser_consume_token (parser);
6925   while (c_parser_next_token_is_not (parser, CPP_EOF))
6926     {
6927       tree decls;
6928       /* Parse any stray semicolon.  */
6929       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6930         {
6931           pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6932                    "extra semicolon in struct or union specified");
6933           c_parser_consume_token (parser);
6934           continue;
6935         }
6936       /* Stop if at the end of the instance variables.  */
6937       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6938         {
6939           c_parser_consume_token (parser);
6940           break;
6941         }
6942       /* Parse any objc-visibility-spec.  */
6943       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6944         {
6945           c_parser_consume_token (parser);
6946           objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6947           continue;
6948         }
6949       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6950         {
6951           c_parser_consume_token (parser);
6952           objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6953           continue;
6954         }
6955       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6956         {
6957           c_parser_consume_token (parser);
6958           objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6959           continue;
6960         }
6961       else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6962         {
6963           c_parser_consume_token (parser);
6964           objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6965           continue;
6966         }
6967       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6968         {
6969           c_parser_pragma (parser, pragma_external);
6970           continue;
6971         }
6972
6973       /* Parse some comma-separated declarations.  */
6974       decls = c_parser_struct_declaration (parser);
6975       {
6976         /* Comma-separated instance variables are chained together in
6977            reverse order; add them one by one.  */
6978         tree ivar = nreverse (decls);
6979         for (; ivar; ivar = DECL_CHAIN (ivar))
6980           objc_add_instance_variable (copy_node (ivar));
6981       }
6982       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6983     }
6984 }
6985
6986 /* Parse an objc-class-declaration.
6987
6988    objc-class-declaration:
6989      @class identifier-list ;
6990 */
6991
6992 static void
6993 c_parser_objc_class_declaration (c_parser *parser)
6994 {
6995   tree list = NULL_TREE;
6996   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6997   c_parser_consume_token (parser);
6998   /* Any identifiers, including those declared as type names, are OK
6999      here.  */
7000   while (true)
7001     {
7002       tree id;
7003       if (c_parser_next_token_is_not (parser, CPP_NAME))
7004         {
7005           c_parser_error (parser, "expected identifier");
7006           c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7007           parser->error = false;
7008           return;
7009         }
7010       id = c_parser_peek_token (parser)->value;
7011       list = chainon (list, build_tree_list (NULL_TREE, id));
7012       c_parser_consume_token (parser);
7013       if (c_parser_next_token_is (parser, CPP_COMMA))
7014         c_parser_consume_token (parser);
7015       else
7016         break;
7017     }
7018   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7019   objc_declare_class (list);
7020 }
7021
7022 /* Parse an objc-alias-declaration.
7023
7024    objc-alias-declaration:
7025      @compatibility_alias identifier identifier ;
7026 */
7027
7028 static void
7029 c_parser_objc_alias_declaration (c_parser *parser)
7030 {
7031   tree id1, id2;
7032   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7033   c_parser_consume_token (parser);
7034   if (c_parser_next_token_is_not (parser, CPP_NAME))
7035     {
7036       c_parser_error (parser, "expected identifier");
7037       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7038       return;
7039     }
7040   id1 = c_parser_peek_token (parser)->value;
7041   c_parser_consume_token (parser);
7042   if (c_parser_next_token_is_not (parser, CPP_NAME))
7043     {
7044       c_parser_error (parser, "expected identifier");
7045       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7046       return;
7047     }
7048   id2 = c_parser_peek_token (parser)->value;
7049   c_parser_consume_token (parser);
7050   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7051   objc_declare_alias (id1, id2);
7052 }
7053
7054 /* Parse an objc-protocol-definition.
7055
7056    objc-protocol-definition:
7057      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7058      @protocol identifier-list ;
7059
7060    "@protocol identifier ;" should be resolved as "@protocol
7061    identifier-list ;": objc-methodprotolist may not start with a
7062    semicolon in the first alternative if objc-protocol-refs are
7063    omitted.  */
7064
7065 static void
7066 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7067 {
7068   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7069
7070   c_parser_consume_token (parser);
7071   if (c_parser_next_token_is_not (parser, CPP_NAME))
7072     {
7073       c_parser_error (parser, "expected identifier");
7074       return;
7075     }
7076   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7077       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7078     {
7079       tree list = NULL_TREE;
7080       /* Any identifiers, including those declared as type names, are
7081          OK here.  */
7082       while (true)
7083         {
7084           tree id;
7085           if (c_parser_next_token_is_not (parser, CPP_NAME))
7086             {
7087               c_parser_error (parser, "expected identifier");
7088               break;
7089             }
7090           id = c_parser_peek_token (parser)->value;
7091           list = chainon (list, build_tree_list (NULL_TREE, id));
7092           c_parser_consume_token (parser);
7093           if (c_parser_next_token_is (parser, CPP_COMMA))
7094             c_parser_consume_token (parser);
7095           else
7096             break;
7097         }
7098       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7099       objc_declare_protocols (list, attributes);
7100     }
7101   else
7102     {
7103       tree id = c_parser_peek_token (parser)->value;
7104       tree proto = NULL_TREE;
7105       c_parser_consume_token (parser);
7106       if (c_parser_next_token_is (parser, CPP_LESS))
7107         proto = c_parser_objc_protocol_refs (parser);
7108       parser->objc_pq_context = true;
7109       objc_start_protocol (id, proto, attributes);
7110       c_parser_objc_methodprotolist (parser);
7111       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7112       parser->objc_pq_context = false;
7113       objc_finish_interface ();
7114     }
7115 }
7116
7117 /* Parse an objc-method-type.
7118
7119    objc-method-type:
7120      +
7121      -
7122
7123    Return true if it is a class method (+) and false if it is
7124    an instance method (-).
7125 */
7126 static inline bool
7127 c_parser_objc_method_type (c_parser *parser)
7128 {
7129   switch (c_parser_peek_token (parser)->type)
7130     {
7131     case CPP_PLUS:
7132       c_parser_consume_token (parser);
7133       return true;
7134     case CPP_MINUS:
7135       c_parser_consume_token (parser);
7136       return false;
7137     default:
7138       gcc_unreachable ();
7139     }
7140 }
7141
7142 /* Parse an objc-method-definition.
7143
7144    objc-method-definition:
7145      objc-method-type objc-method-decl ;[opt] compound-statement
7146 */
7147
7148 static void
7149 c_parser_objc_method_definition (c_parser *parser)
7150 {
7151   bool is_class_method = c_parser_objc_method_type (parser);
7152   tree decl, attributes = NULL_TREE;
7153   parser->objc_pq_context = true;
7154   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7155   if (decl == error_mark_node)
7156     return;  /* Bail here. */
7157
7158   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7159     {
7160       c_parser_consume_token (parser);
7161       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7162                "extra semicolon in method definition specified");
7163     }
7164
7165   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7166     {
7167       c_parser_error (parser, "expected %<{%>");
7168       return;
7169     }
7170
7171   parser->objc_pq_context = false;
7172   if (objc_start_method_definition (is_class_method, decl, attributes))
7173     {
7174       add_stmt (c_parser_compound_statement (parser));
7175       objc_finish_method_definition (current_function_decl);
7176     }
7177   else
7178     {
7179       /* This code is executed when we find a method definition
7180          outside of an @implementation context (or invalid for other
7181          reasons).  Parse the method (to keep going) but do not emit
7182          any code.
7183       */
7184       c_parser_compound_statement (parser);
7185     }
7186 }
7187
7188 /* Parse an objc-methodprotolist.
7189
7190    objc-methodprotolist:
7191      empty
7192      objc-methodprotolist objc-methodproto
7193      objc-methodprotolist declaration
7194      objc-methodprotolist ;
7195      @optional
7196      @required
7197
7198    The declaration is a data definition, which may be missing
7199    declaration specifiers under the same rules and diagnostics as
7200    other data definitions outside functions, and the stray semicolon
7201    is diagnosed the same way as a stray semicolon outside a
7202    function.  */
7203
7204 static void
7205 c_parser_objc_methodprotolist (c_parser *parser)
7206 {
7207   while (true)
7208     {
7209       /* The list is terminated by @end.  */
7210       switch (c_parser_peek_token (parser)->type)
7211         {
7212         case CPP_SEMICOLON:
7213           pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7214                    "ISO C does not allow extra %<;%> outside of a function");
7215           c_parser_consume_token (parser);
7216           break;
7217         case CPP_PLUS:
7218         case CPP_MINUS:
7219           c_parser_objc_methodproto (parser);
7220           break;
7221         case CPP_PRAGMA:
7222           c_parser_pragma (parser, pragma_external);
7223           break;
7224         case CPP_EOF:
7225           return;
7226         default:
7227           if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7228             return;
7229           else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7230             c_parser_objc_at_property_declaration (parser);
7231           else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7232             {
7233               objc_set_method_opt (true);
7234               c_parser_consume_token (parser);
7235             }
7236           else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7237             {
7238               objc_set_method_opt (false);
7239               c_parser_consume_token (parser);
7240             }
7241           else
7242             c_parser_declaration_or_fndef (parser, false, false, true,
7243                                            false, true, NULL);
7244           break;
7245         }
7246     }
7247 }
7248
7249 /* Parse an objc-methodproto.
7250
7251    objc-methodproto:
7252      objc-method-type objc-method-decl ;
7253 */
7254
7255 static void
7256 c_parser_objc_methodproto (c_parser *parser)
7257 {
7258   bool is_class_method = c_parser_objc_method_type (parser);
7259   tree decl, attributes = NULL_TREE;
7260
7261   /* Remember protocol qualifiers in prototypes.  */
7262   parser->objc_pq_context = true;
7263   decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7264   /* Forget protocol qualifiers now.  */
7265   parser->objc_pq_context = false;
7266
7267   /* Do not allow the presence of attributes to hide an erroneous 
7268      method implementation in the interface section.  */
7269   if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7270     {
7271       c_parser_error (parser, "expected %<;%>");
7272       return;
7273     }
7274   
7275   if (decl != error_mark_node)
7276     objc_add_method_declaration (is_class_method, decl, attributes);
7277
7278   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7279 }
7280
7281 /* If we are at a position that method attributes may be present, check that 
7282    there are not any parsed already (a syntax error) and then collect any 
7283    specified at the current location.  Finally, if new attributes were present,
7284    check that the next token is legal ( ';' for decls and '{' for defs).  */
7285    
7286 static bool 
7287 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7288 {
7289   bool bad = false;
7290   if (*attributes)
7291     {
7292       c_parser_error (parser, 
7293                     "method attributes must be specified at the end only");
7294       *attributes = NULL_TREE;
7295       bad = true;
7296     }
7297
7298   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7299     *attributes = c_parser_attributes (parser);
7300
7301   /* If there were no attributes here, just report any earlier error.  */
7302   if (*attributes == NULL_TREE || bad)
7303     return bad;
7304
7305   /* If the attributes are followed by a ; or {, then just report any earlier
7306      error.  */
7307   if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7308       || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7309     return bad;
7310
7311   /* We've got attributes, but not at the end.  */
7312   c_parser_error (parser, 
7313                   "expected %<;%> or %<{%> after method attribute definition");
7314   return true;
7315 }
7316
7317 /* Parse an objc-method-decl.
7318
7319    objc-method-decl:
7320      ( objc-type-name ) objc-selector
7321      objc-selector
7322      ( objc-type-name ) objc-keyword-selector objc-optparmlist
7323      objc-keyword-selector objc-optparmlist
7324      attributes
7325
7326    objc-keyword-selector:
7327      objc-keyword-decl
7328      objc-keyword-selector objc-keyword-decl
7329
7330    objc-keyword-decl:
7331      objc-selector : ( objc-type-name ) identifier
7332      objc-selector : identifier
7333      : ( objc-type-name ) identifier
7334      : identifier
7335
7336    objc-optparmlist:
7337      objc-optparms objc-optellipsis
7338
7339    objc-optparms:
7340      empty
7341      objc-opt-parms , parameter-declaration
7342
7343    objc-optellipsis:
7344      empty
7345      , ...
7346 */
7347
7348 static tree
7349 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7350 {
7351   tree type = NULL_TREE;
7352   tree sel;
7353   tree parms = NULL_TREE;
7354   bool ellipsis = false;
7355   bool attr_err = false;
7356
7357   *attributes = NULL_TREE;
7358   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7359     {
7360       c_parser_consume_token (parser);
7361       type = c_parser_objc_type_name (parser);
7362       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7363     }
7364   sel = c_parser_objc_selector (parser);
7365   /* If there is no selector, or a colon follows, we have an
7366      objc-keyword-selector.  If there is a selector, and a colon does
7367      not follow, that selector ends the objc-method-decl.  */
7368   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7369     {
7370       tree tsel = sel;
7371       tree list = NULL_TREE;
7372       while (true)
7373         {
7374           tree atype = NULL_TREE, id, keyworddecl;
7375           tree param_attr = NULL_TREE;
7376           if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7377             break;
7378           if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7379             {
7380               c_parser_consume_token (parser);
7381               atype = c_parser_objc_type_name (parser);
7382               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7383                                          "expected %<)%>");
7384             }
7385           /* New ObjC allows attributes on method parameters.  */
7386           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7387             param_attr = c_parser_attributes (parser);
7388           if (c_parser_next_token_is_not (parser, CPP_NAME))
7389             {
7390               c_parser_error (parser, "expected identifier");
7391               return error_mark_node;
7392             }
7393           id = c_parser_peek_token (parser)->value;
7394           c_parser_consume_token (parser);
7395           keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7396           list = chainon (list, keyworddecl);
7397           tsel = c_parser_objc_selector (parser);
7398           if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7399             break;
7400         }
7401
7402       attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7403
7404       /* Parse the optional parameter list.  Optional Objective-C
7405          method parameters follow the C syntax, and may include '...'
7406          to denote a variable number of arguments.  */
7407       parms = make_node (TREE_LIST);
7408       while (c_parser_next_token_is (parser, CPP_COMMA))
7409         {
7410           struct c_parm *parm;
7411           c_parser_consume_token (parser);
7412           if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7413             {
7414               ellipsis = true;
7415               c_parser_consume_token (parser);
7416               attr_err |= c_parser_objc_maybe_method_attributes 
7417                                                 (parser, attributes) ;
7418               break;
7419             }
7420           parm = c_parser_parameter_declaration (parser, NULL_TREE);
7421           if (parm == NULL)
7422             break;
7423           parms = chainon (parms,
7424                            build_tree_list (NULL_TREE, grokparm (parm)));
7425         }
7426       sel = list;
7427     }
7428   else
7429     attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7430
7431   if (sel == NULL)
7432     {
7433       c_parser_error (parser, "objective-c method declaration is expected");
7434       return error_mark_node;
7435     }
7436
7437   if (attr_err)
7438     return error_mark_node;
7439
7440   return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7441 }
7442
7443 /* Parse an objc-type-name.
7444
7445    objc-type-name:
7446      objc-type-qualifiers[opt] type-name
7447      objc-type-qualifiers[opt]
7448
7449    objc-type-qualifiers:
7450      objc-type-qualifier
7451      objc-type-qualifiers objc-type-qualifier
7452
7453    objc-type-qualifier: one of
7454      in out inout bycopy byref oneway
7455 */
7456
7457 static tree
7458 c_parser_objc_type_name (c_parser *parser)
7459 {
7460   tree quals = NULL_TREE;
7461   struct c_type_name *type_name = NULL;
7462   tree type = NULL_TREE;
7463   while (true)
7464     {
7465       c_token *token = c_parser_peek_token (parser);
7466       if (token->type == CPP_KEYWORD
7467           && (token->keyword == RID_IN
7468               || token->keyword == RID_OUT
7469               || token->keyword == RID_INOUT
7470               || token->keyword == RID_BYCOPY
7471               || token->keyword == RID_BYREF
7472               || token->keyword == RID_ONEWAY))
7473         {
7474           quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7475           c_parser_consume_token (parser);
7476         }
7477       else
7478         break;
7479     }
7480   if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7481     type_name = c_parser_type_name (parser);
7482   if (type_name)
7483     type = groktypename (type_name, NULL, NULL);
7484
7485   /* If the type is unknown, and error has already been produced and
7486      we need to recover from the error.  In that case, use NULL_TREE
7487      for the type, as if no type had been specified; this will use the
7488      default type ('id') which is good for error recovery.  */
7489   if (type == error_mark_node)
7490     type = NULL_TREE;
7491
7492   return build_tree_list (quals, type);
7493 }
7494
7495 /* Parse objc-protocol-refs.
7496
7497    objc-protocol-refs:
7498      < identifier-list >
7499 */
7500
7501 static tree
7502 c_parser_objc_protocol_refs (c_parser *parser)
7503 {
7504   tree list = NULL_TREE;
7505   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7506   c_parser_consume_token (parser);
7507   /* Any identifiers, including those declared as type names, are OK
7508      here.  */
7509   while (true)
7510     {
7511       tree id;
7512       if (c_parser_next_token_is_not (parser, CPP_NAME))
7513         {
7514           c_parser_error (parser, "expected identifier");
7515           break;
7516         }
7517       id = c_parser_peek_token (parser)->value;
7518       list = chainon (list, build_tree_list (NULL_TREE, id));
7519       c_parser_consume_token (parser);
7520       if (c_parser_next_token_is (parser, CPP_COMMA))
7521         c_parser_consume_token (parser);
7522       else
7523         break;
7524     }
7525   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7526   return list;
7527 }
7528
7529 /* Parse an objc-try-catch-finally-statement.
7530
7531    objc-try-catch-finally-statement:
7532      @try compound-statement objc-catch-list[opt]
7533      @try compound-statement objc-catch-list[opt] @finally compound-statement
7534
7535    objc-catch-list:
7536      @catch ( objc-catch-parameter-declaration ) compound-statement
7537      objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7538
7539    objc-catch-parameter-declaration:
7540      parameter-declaration
7541      '...'
7542
7543    where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7544
7545    PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7546    for C++.  Keep them in sync.  */   
7547
7548 static void
7549 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7550 {
7551   location_t location;
7552   tree stmt;
7553
7554   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7555   c_parser_consume_token (parser);
7556   location = c_parser_peek_token (parser)->location;
7557   objc_maybe_warn_exceptions (location);
7558   stmt = c_parser_compound_statement (parser);
7559   objc_begin_try_stmt (location, stmt);
7560
7561   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7562     {
7563       struct c_parm *parm;
7564       tree parameter_declaration = error_mark_node;
7565       bool seen_open_paren = false;
7566
7567       c_parser_consume_token (parser);
7568       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7569         seen_open_paren = true;
7570       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7571         {
7572           /* We have "@catch (...)" (where the '...' are literally
7573              what is in the code).  Skip the '...'.
7574              parameter_declaration is set to NULL_TREE, and
7575              objc_being_catch_clauses() knows that that means
7576              '...'.  */
7577           c_parser_consume_token (parser);
7578           parameter_declaration = NULL_TREE;
7579         }
7580       else
7581         {
7582           /* We have "@catch (NSException *exception)" or something
7583              like that.  Parse the parameter declaration.  */
7584           parm = c_parser_parameter_declaration (parser, NULL_TREE);
7585           if (parm == NULL)
7586             parameter_declaration = error_mark_node;
7587           else
7588             parameter_declaration = grokparm (parm);
7589         }
7590       if (seen_open_paren)
7591         c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7592       else
7593         {
7594           /* If there was no open parenthesis, we are recovering from
7595              an error, and we are trying to figure out what mistake
7596              the user has made.  */
7597
7598           /* If there is an immediate closing parenthesis, the user
7599              probably forgot the opening one (ie, they typed "@catch
7600              NSException *e)".  Parse the closing parenthesis and keep
7601              going.  */
7602           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7603             c_parser_consume_token (parser);
7604           
7605           /* If these is no immediate closing parenthesis, the user
7606              probably doesn't know that parenthesis are required at
7607              all (ie, they typed "@catch NSException *e").  So, just
7608              forget about the closing parenthesis and keep going.  */
7609         }
7610       objc_begin_catch_clause (parameter_declaration);
7611       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7612         c_parser_compound_statement_nostart (parser);
7613       objc_finish_catch_clause ();
7614     }
7615   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7616     {
7617       c_parser_consume_token (parser);
7618       location = c_parser_peek_token (parser)->location;
7619       stmt = c_parser_compound_statement (parser);
7620       objc_build_finally_clause (location, stmt);
7621     }
7622   objc_finish_try_stmt ();
7623 }
7624
7625 /* Parse an objc-synchronized-statement.
7626
7627    objc-synchronized-statement:
7628      @synchronized ( expression ) compound-statement
7629 */
7630
7631 static void
7632 c_parser_objc_synchronized_statement (c_parser *parser)
7633 {
7634   location_t loc;
7635   tree expr, stmt;
7636   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7637   c_parser_consume_token (parser);
7638   loc = c_parser_peek_token (parser)->location;
7639   objc_maybe_warn_exceptions (loc);
7640   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7641     {
7642       expr = c_parser_expression (parser).value;
7643       expr = c_fully_fold (expr, false, NULL);
7644       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7645     }
7646   else
7647     expr = error_mark_node;
7648   stmt = c_parser_compound_statement (parser);
7649   objc_build_synchronized (loc, expr, stmt);
7650 }
7651
7652 /* Parse an objc-selector; return NULL_TREE without an error if the
7653    next token is not an objc-selector.
7654
7655    objc-selector:
7656      identifier
7657      one of
7658        enum struct union if else while do for switch case default
7659        break continue return goto asm sizeof typeof __alignof
7660        unsigned long const short volatile signed restrict _Complex
7661        in out inout bycopy byref oneway int char float double void _Bool
7662
7663    ??? Why this selection of keywords but not, for example, storage
7664    class specifiers?  */
7665
7666 static tree
7667 c_parser_objc_selector (c_parser *parser)
7668 {
7669   c_token *token = c_parser_peek_token (parser);
7670   tree value = token->value;
7671   if (token->type == CPP_NAME)
7672     {
7673       c_parser_consume_token (parser);
7674       return value;
7675     }
7676   if (token->type != CPP_KEYWORD)
7677     return NULL_TREE;
7678   switch (token->keyword)
7679     {
7680     case RID_ENUM:
7681     case RID_STRUCT:
7682     case RID_UNION:
7683     case RID_IF:
7684     case RID_ELSE:
7685     case RID_WHILE:
7686     case RID_DO:
7687     case RID_FOR:
7688     case RID_SWITCH:
7689     case RID_CASE:
7690     case RID_DEFAULT:
7691     case RID_BREAK:
7692     case RID_CONTINUE:
7693     case RID_RETURN:
7694     case RID_GOTO:
7695     case RID_ASM:
7696     case RID_SIZEOF:
7697     case RID_TYPEOF:
7698     case RID_ALIGNOF:
7699     case RID_UNSIGNED:
7700     case RID_LONG:
7701     case RID_INT128:
7702     case RID_CONST:
7703     case RID_SHORT:
7704     case RID_VOLATILE:
7705     case RID_SIGNED:
7706     case RID_RESTRICT:
7707     case RID_COMPLEX:
7708     case RID_IN:
7709     case RID_OUT:
7710     case RID_INOUT:
7711     case RID_BYCOPY:
7712     case RID_BYREF:
7713     case RID_ONEWAY:
7714     case RID_INT:
7715     case RID_CHAR:
7716     case RID_FLOAT:
7717     case RID_DOUBLE:
7718     case RID_VOID:
7719     case RID_BOOL:
7720       c_parser_consume_token (parser);
7721       return value;
7722     default:
7723       return NULL_TREE;
7724     }
7725 }
7726
7727 /* Parse an objc-selector-arg.
7728
7729    objc-selector-arg:
7730      objc-selector
7731      objc-keywordname-list
7732
7733    objc-keywordname-list:
7734      objc-keywordname
7735      objc-keywordname-list objc-keywordname
7736
7737    objc-keywordname:
7738      objc-selector :
7739      :
7740 */
7741
7742 static tree
7743 c_parser_objc_selector_arg (c_parser *parser)
7744 {
7745   tree sel = c_parser_objc_selector (parser);
7746   tree list = NULL_TREE;
7747   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7748     return sel;
7749   while (true)
7750     {
7751       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7752         return list;
7753       list = chainon (list, build_tree_list (sel, NULL_TREE));
7754       sel = c_parser_objc_selector (parser);
7755       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7756         break;
7757     }
7758   return list;
7759 }
7760
7761 /* Parse an objc-receiver.
7762
7763    objc-receiver:
7764      expression
7765      class-name
7766      type-name
7767 */
7768
7769 static tree
7770 c_parser_objc_receiver (c_parser *parser)
7771 {
7772   if (c_parser_peek_token (parser)->type == CPP_NAME
7773       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7774           || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7775     {
7776       tree id = c_parser_peek_token (parser)->value;
7777       c_parser_consume_token (parser);
7778       return objc_get_class_reference (id);
7779     }
7780   return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7781 }
7782
7783 /* Parse objc-message-args.
7784
7785    objc-message-args:
7786      objc-selector
7787      objc-keywordarg-list
7788
7789    objc-keywordarg-list:
7790      objc-keywordarg
7791      objc-keywordarg-list objc-keywordarg
7792
7793    objc-keywordarg:
7794      objc-selector : objc-keywordexpr
7795      : objc-keywordexpr
7796 */
7797
7798 static tree
7799 c_parser_objc_message_args (c_parser *parser)
7800 {
7801   tree sel = c_parser_objc_selector (parser);
7802   tree list = NULL_TREE;
7803   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7804     return sel;
7805   while (true)
7806     {
7807       tree keywordexpr;
7808       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7809         return error_mark_node;
7810       keywordexpr = c_parser_objc_keywordexpr (parser);
7811       list = chainon (list, build_tree_list (sel, keywordexpr));
7812       sel = c_parser_objc_selector (parser);
7813       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7814         break;
7815     }
7816   return list;
7817 }
7818
7819 /* Parse an objc-keywordexpr.
7820
7821    objc-keywordexpr:
7822      nonempty-expr-list
7823 */
7824
7825 static tree
7826 c_parser_objc_keywordexpr (c_parser *parser)
7827 {
7828   tree ret;
7829   VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7830   if (VEC_length (tree, expr_list) == 1)
7831     {
7832       /* Just return the expression, remove a level of
7833          indirection.  */
7834       ret = VEC_index (tree, expr_list, 0);
7835     }
7836   else
7837     {
7838       /* We have a comma expression, we will collapse later.  */
7839       ret = build_tree_list_vec (expr_list);
7840     }
7841   release_tree_vector (expr_list);
7842   return ret;
7843 }
7844
7845 /* A check, needed in several places, that ObjC interface, implementation or
7846    method definitions are not prefixed by incorrect items.  */
7847 static bool
7848 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, 
7849                                            struct c_declspecs *specs)
7850 {
7851   if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7852       || specs->typespec_kind != ctsk_none)
7853     {
7854       c_parser_error (parser, 
7855                       "no type or storage class may be specified here,");
7856       c_parser_skip_to_end_of_block_or_statement (parser);
7857       return true;
7858     }
7859   return false;
7860 }
7861
7862 /* Parse an Objective-C @property declaration.  The syntax is:
7863
7864    objc-property-declaration:
7865      '@property' objc-property-attributes[opt] struct-declaration ;
7866
7867    objc-property-attributes:
7868     '(' objc-property-attribute-list ')'
7869
7870    objc-property-attribute-list:
7871      objc-property-attribute
7872      objc-property-attribute-list, objc-property-attribute
7873
7874    objc-property-attribute
7875      'getter' = identifier
7876      'setter' = identifier
7877      'readonly'
7878      'readwrite'
7879      'assign'
7880      'retain'
7881      'copy'
7882      'nonatomic'
7883
7884   For example:
7885     @property NSString *name;
7886     @property (readonly) id object;
7887     @property (retain, nonatomic, getter=getTheName) id name;
7888     @property int a, b, c;
7889
7890   PS: This function is identical to cp_parser_objc_at_propery_declaration
7891   for C++.  Keep them in sync.  */
7892 static void
7893 c_parser_objc_at_property_declaration (c_parser *parser)
7894 {
7895   /* The following variables hold the attributes of the properties as
7896      parsed.  They are 'false' or 'NULL_TREE' if the attribute was not
7897      seen.  When we see an attribute, we set them to 'true' (if they
7898      are boolean properties) or to the identifier (if they have an
7899      argument, ie, for getter and setter).  Note that here we only
7900      parse the list of attributes, check the syntax and accumulate the
7901      attributes that we find.  objc_add_property_declaration() will
7902      then process the information.  */
7903   bool property_assign = false;
7904   bool property_copy = false;
7905   tree property_getter_ident = NULL_TREE;
7906   bool property_nonatomic = false;
7907   bool property_readonly = false;
7908   bool property_readwrite = false;
7909   bool property_retain = false;
7910   tree property_setter_ident = NULL_TREE;
7911
7912   /* 'properties' is the list of properties that we read.  Usually a
7913      single one, but maybe more (eg, in "@property int a, b, c;" there
7914      are three).  */
7915   tree properties;
7916   location_t loc;
7917
7918   loc = c_parser_peek_token (parser)->location;
7919   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7920
7921   c_parser_consume_token (parser);  /* Eat '@property'.  */
7922
7923   /* Parse the optional attribute list...  */
7924   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7925     {
7926       /* Eat the '(' */
7927       c_parser_consume_token (parser);
7928       
7929       /* Property attribute keywords are valid now.  */
7930       parser->objc_property_attr_context = true;
7931
7932       while (true)
7933         {
7934           bool syntax_error = false;
7935           c_token *token = c_parser_peek_token (parser);
7936           enum rid keyword;
7937
7938           if (token->type != CPP_KEYWORD)
7939             {
7940               if (token->type == CPP_CLOSE_PAREN)
7941                 c_parser_error (parser, "expected identifier");
7942               else
7943                 {
7944                   c_parser_consume_token (parser);
7945                   c_parser_error (parser, "unknown property attribute");
7946                 }
7947               break;
7948             }
7949           keyword = token->keyword;
7950           c_parser_consume_token (parser);
7951           switch (keyword)
7952             {
7953             case RID_ASSIGN:    property_assign = true;    break;
7954             case RID_COPY:      property_copy = true;      break;
7955             case RID_NONATOMIC: property_nonatomic = true; break;
7956             case RID_READONLY:  property_readonly = true;  break;
7957             case RID_READWRITE: property_readwrite = true; break;
7958             case RID_RETAIN:    property_retain = true;    break;
7959
7960             case RID_GETTER:
7961             case RID_SETTER:
7962               if (c_parser_next_token_is_not (parser, CPP_EQ))
7963                 {
7964                   c_parser_error (parser,
7965                                   "getter/setter attribute must be followed by %<=%>");
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"