OSDN Git Service

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