OSDN Git Service

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