OSDN Git Service

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