OSDN Git Service

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