OSDN Git Service

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