OSDN Git Service

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