OSDN Git Service

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