OSDN Git Service

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