OSDN Git Service

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