OSDN Git Service

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