OSDN Git Service

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