OSDN Git Service

2005-12-16 Paolo Bonzini <bonzini@gnu.org>
[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 Free Software Foundation, Inc.
4
5    Parser actions based on the old Bison parser; structure somewhat
6    influenced by and fragments based on the C++ parser.
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
14
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18 for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING.  If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301, USA.  */
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 "langhooks.h"
46 #include "input.h"
47 #include "cpplib.h"
48 #include "timevar.h"
49 #include "c-pragma.h"
50 #include "c-tree.h"
51 #include "flags.h"
52 #include "output.h"
53 #include "toplev.h"
54 #include "ggc.h"
55 #include "c-common.h"
56
57 \f
58 /* Miscellaneous data and functions needed for the parser.  */
59
60 int yydebug;
61
62 /* Objective-C specific parser/lexer information.  */
63
64 static int objc_pq_context = 0;
65
66 /* The following flag is needed to contextualize Objective-C lexical
67    analysis.  In some cases (e.g., 'int NSObject;'), it is undesirable
68    to bind an identifier to an Objective-C class, even if a class with
69    that name exists.  */
70 static int objc_need_raw_identifier = 0;
71 #define OBJC_NEED_RAW_IDENTIFIER(VAL)           \
72   do {                                          \
73     if (c_dialect_objc ())                      \
74       objc_need_raw_identifier = VAL;           \
75   } while (0)
76
77 /* The reserved keyword table.  */
78 struct resword
79 {
80   const char *word;
81   ENUM_BITFIELD(rid) rid : 16;
82   unsigned int disable   : 16;
83 };
84
85 /* Disable mask.  Keywords are disabled if (reswords[i].disable &
86    mask) is _true_.  */
87 #define D_C89   0x01    /* not in C89 */
88 #define D_EXT   0x02    /* GCC extension */
89 #define D_EXT89 0x04    /* GCC extension incorporated in C99 */
90 #define D_OBJC  0x08    /* Objective C only */
91
92 static const struct resword reswords[] =
93 {
94   { "_Bool",            RID_BOOL,       0 },
95   { "_Complex",         RID_COMPLEX,    0 },
96   { "_Decimal32",       RID_DFLOAT32,  D_EXT },
97   { "_Decimal64",       RID_DFLOAT64,  D_EXT },
98   { "_Decimal128",      RID_DFLOAT128, D_EXT },
99   { "__FUNCTION__",     RID_FUNCTION_NAME, 0 },
100   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
101   { "__alignof",        RID_ALIGNOF,    0 },
102   { "__alignof__",      RID_ALIGNOF,    0 },
103   { "__asm",            RID_ASM,        0 },
104   { "__asm__",          RID_ASM,        0 },
105   { "__attribute",      RID_ATTRIBUTE,  0 },
106   { "__attribute__",    RID_ATTRIBUTE,  0 },
107   { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
108   { "__builtin_offsetof", RID_OFFSETOF, 0 },
109   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
110   { "__builtin_va_arg", RID_VA_ARG,     0 },
111   { "__complex",        RID_COMPLEX,    0 },
112   { "__complex__",      RID_COMPLEX,    0 },
113   { "__const",          RID_CONST,      0 },
114   { "__const__",        RID_CONST,      0 },
115   { "__extension__",    RID_EXTENSION,  0 },
116   { "__func__",         RID_C99_FUNCTION_NAME, 0 },
117   { "__imag",           RID_IMAGPART,   0 },
118   { "__imag__",         RID_IMAGPART,   0 },
119   { "__inline",         RID_INLINE,     0 },
120   { "__inline__",       RID_INLINE,     0 },
121   { "__label__",        RID_LABEL,      0 },
122   { "__real",           RID_REALPART,   0 },
123   { "__real__",         RID_REALPART,   0 },
124   { "__restrict",       RID_RESTRICT,   0 },
125   { "__restrict__",     RID_RESTRICT,   0 },
126   { "__signed",         RID_SIGNED,     0 },
127   { "__signed__",       RID_SIGNED,     0 },
128   { "__thread",         RID_THREAD,     0 },
129   { "__typeof",         RID_TYPEOF,     0 },
130   { "__typeof__",       RID_TYPEOF,     0 },
131   { "__volatile",       RID_VOLATILE,   0 },
132   { "__volatile__",     RID_VOLATILE,   0 },
133   { "asm",              RID_ASM,        D_EXT },
134   { "auto",             RID_AUTO,       0 },
135   { "break",            RID_BREAK,      0 },
136   { "case",             RID_CASE,       0 },
137   { "char",             RID_CHAR,       0 },
138   { "const",            RID_CONST,      0 },
139   { "continue",         RID_CONTINUE,   0 },
140   { "default",          RID_DEFAULT,    0 },
141   { "do",               RID_DO,         0 },
142   { "double",           RID_DOUBLE,     0 },
143   { "else",             RID_ELSE,       0 },
144   { "enum",             RID_ENUM,       0 },
145   { "extern",           RID_EXTERN,     0 },
146   { "float",            RID_FLOAT,      0 },
147   { "for",              RID_FOR,        0 },
148   { "goto",             RID_GOTO,       0 },
149   { "if",               RID_IF,         0 },
150   { "inline",           RID_INLINE,     D_EXT89 },
151   { "int",              RID_INT,        0 },
152   { "long",             RID_LONG,       0 },
153   { "register",         RID_REGISTER,   0 },
154   { "restrict",         RID_RESTRICT,   D_C89 },
155   { "return",           RID_RETURN,     0 },
156   { "short",            RID_SHORT,      0 },
157   { "signed",           RID_SIGNED,     0 },
158   { "sizeof",           RID_SIZEOF,     0 },
159   { "static",           RID_STATIC,     0 },
160   { "struct",           RID_STRUCT,     0 },
161   { "switch",           RID_SWITCH,     0 },
162   { "typedef",          RID_TYPEDEF,    0 },
163   { "typeof",           RID_TYPEOF,     D_EXT },
164   { "union",            RID_UNION,      0 },
165   { "unsigned",         RID_UNSIGNED,   0 },
166   { "void",             RID_VOID,       0 },
167   { "volatile",         RID_VOLATILE,   0 },
168   { "while",            RID_WHILE,      0 },
169   /* These Objective-C keywords are recognized only immediately after
170      an '@'.  */
171   { "class",            RID_AT_CLASS,           D_OBJC },
172   { "compatibility_alias", RID_AT_ALIAS,        D_OBJC },
173   { "defs",             RID_AT_DEFS,            D_OBJC },
174   { "encode",           RID_AT_ENCODE,          D_OBJC },
175   { "end",              RID_AT_END,             D_OBJC },
176   { "implementation",   RID_AT_IMPLEMENTATION,  D_OBJC },
177   { "interface",        RID_AT_INTERFACE,       D_OBJC },
178   { "private",          RID_AT_PRIVATE,         D_OBJC },
179   { "protected",        RID_AT_PROTECTED,       D_OBJC },
180   { "protocol",         RID_AT_PROTOCOL,        D_OBJC },
181   { "public",           RID_AT_PUBLIC,          D_OBJC },
182   { "selector",         RID_AT_SELECTOR,        D_OBJC },
183   { "throw",            RID_AT_THROW,           D_OBJC },
184   { "try",              RID_AT_TRY,             D_OBJC },
185   { "catch",            RID_AT_CATCH,           D_OBJC },
186   { "finally",          RID_AT_FINALLY,         D_OBJC },
187   { "synchronized",     RID_AT_SYNCHRONIZED,    D_OBJC },
188   /* These are recognized only in protocol-qualifier context
189      (see above) */
190   { "bycopy",           RID_BYCOPY,             D_OBJC },
191   { "byref",            RID_BYREF,              D_OBJC },
192   { "in",               RID_IN,                 D_OBJC },
193   { "inout",            RID_INOUT,              D_OBJC },
194   { "oneway",           RID_ONEWAY,             D_OBJC },
195   { "out",              RID_OUT,                D_OBJC },
196 };
197 #define N_reswords (sizeof reswords / sizeof (struct resword))
198
199 /* Initialization routine for this file.  */
200
201 void
202 c_parse_init (void)
203 {
204   /* The only initialization required is of the reserved word
205      identifiers.  */
206   unsigned int i;
207   tree id;
208   int mask = (flag_isoc99 ? 0 : D_C89)
209               | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
210
211   if (!c_dialect_objc ())
212      mask |= D_OBJC;
213
214   ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
215   for (i = 0; i < N_reswords; i++)
216     {
217       /* If a keyword is disabled, do not enter it into the table
218          and so create a canonical spelling that isn't a keyword.  */
219       if (reswords[i].disable & mask)
220         continue;
221
222       id = get_identifier (reswords[i].word);
223       C_RID_CODE (id) = reswords[i].rid;
224       C_IS_RESERVED_WORD (id) = 1;
225       ridpointers [(int) reswords[i].rid] = id;
226     }
227 }
228 \f
229 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
230    and the C parser.  Unlike the C++ lexer, the parser structure
231    stores the lexer information instead of using a separate structure.
232    Identifiers are separated into ordinary identifiers, type names,
233    keywords and some other Objective-C types of identifiers, and some
234    look-ahead is maintained.
235
236    ??? It might be a good idea to lex the whole file up front (as for
237    C++).  It would then be possible to share more of the C and C++
238    lexer code, if desired.  */
239
240 /* The following local token type is used.  */
241
242 /* A keyword.  */
243 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
244
245 /* More information about the type of a CPP_NAME token.  */
246 typedef enum c_id_kind {
247   /* An ordinary identifier.  */
248   C_ID_ID,
249   /* An identifier declared as a typedef name.  */
250   C_ID_TYPENAME,
251   /* An identifier declared as an Objective-C class name.  */
252   C_ID_CLASSNAME,
253   /* Not an identifier.  */
254   C_ID_NONE
255 } c_id_kind;
256
257 /* A single C token after string literal concatenation and conversion
258    of preprocessing tokens to tokens.  */
259 typedef struct c_token GTY (())
260 {
261   /* The kind of token.  */
262   ENUM_BITFIELD (cpp_ttype) type : 8;
263   /* If this token is a CPP_NAME, this value indicates whether also
264      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
265   ENUM_BITFIELD (c_id_kind) id_kind : 8;
266   /* If this token is a keyword, this value indicates which keyword.
267      Otherwise, this value is RID_MAX.  */
268   ENUM_BITFIELD (rid) keyword : 8;
269   /* True if this token is from a system header.  */
270   BOOL_BITFIELD in_system_header : 1;
271   /* The value associated with this token, if any.  */
272   tree value;
273   /* The location at which this token was found.  */
274   location_t location;
275 } c_token;
276
277 /* A parser structure recording information about the state and
278    context of parsing.  Includes lexer information with up to two
279    tokens of look-ahead; more are not needed for C.  */
280 typedef struct c_parser GTY(())
281 {
282   /* The look-ahead tokens.  */
283   c_token tokens[2];
284   /* How many look-ahead tokens are available (0, 1 or 2).  */
285   short tokens_avail;
286   /* True if a syntax error is being recovered from; false otherwise.
287      c_parser_error sets this flag.  It should clear this flag when
288      enough tokens have been consumed to recover from the error.  */
289   BOOL_BITFIELD error : 1;
290 } c_parser;
291
292 /* Read in and lex a single token, storing it in *TOKEN.  */
293
294 static void
295 c_lex_one_token (c_token *token)
296 {
297   timevar_push (TV_LEX);
298   token->type = c_lex_with_flags (&token->value, &token->location, NULL);
299   token->in_system_header = in_system_header;
300   switch (token->type)
301     {
302     case CPP_NAME:
303       token->id_kind = C_ID_NONE;
304       token->keyword = RID_MAX;
305       {
306         tree decl;
307
308         int objc_force_identifier = objc_need_raw_identifier;
309         OBJC_NEED_RAW_IDENTIFIER (0);
310
311         if (C_IS_RESERVED_WORD (token->value))
312           {
313             enum rid rid_code = C_RID_CODE (token->value);
314
315             if (c_dialect_objc ())
316               {
317                 if (!OBJC_IS_AT_KEYWORD (rid_code)
318                     && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
319                   {
320                     /* Return the canonical spelling for this keyword.  */
321                     token->value = ridpointers[(int) rid_code];
322                     token->type = CPP_KEYWORD;
323                     token->keyword = rid_code;
324                     break;
325                   }
326               }
327             else
328               {
329                 /* Return the canonical spelling for this keyword.  */
330                 token->value = ridpointers[(int) rid_code];
331                 token->type = CPP_KEYWORD;
332                 token->keyword = rid_code;
333                 break;
334               }
335           }
336
337         decl = lookup_name (token->value);
338         if (decl)
339           {
340             if (TREE_CODE (decl) == TYPE_DECL)
341               {
342                 token->id_kind = C_ID_TYPENAME;
343                 break;
344               }
345           }
346         else if (c_dialect_objc ())
347           {
348             tree objc_interface_decl = objc_is_class_name (token->value);
349             /* Objective-C class names are in the same namespace as
350                variables and typedefs, and hence are shadowed by local
351                declarations.  */
352             if (objc_interface_decl
353                 && (global_bindings_p ()
354                     || (!objc_force_identifier && !decl)))
355               {
356                 token->value = objc_interface_decl;
357                 token->id_kind = C_ID_CLASSNAME;
358                 break;
359               }
360           }
361       }
362       token->id_kind = C_ID_ID;
363       break;
364     case CPP_AT_NAME:
365       /* This only happens in Objective-C; it must be a keyword.  */
366       token->type = CPP_KEYWORD;
367       token->id_kind = C_ID_NONE;
368       token->keyword = C_RID_CODE (token->value);
369       break;
370     case CPP_COLON:
371     case CPP_COMMA:
372     case CPP_CLOSE_PAREN:
373     case CPP_SEMICOLON:
374       /* These tokens may affect the interpretation of any identifiers
375          following, if doing Objective-C.  */
376       OBJC_NEED_RAW_IDENTIFIER (0);
377       token->id_kind = C_ID_NONE;
378       token->keyword = RID_MAX;
379       break;
380     default:
381       token->id_kind = C_ID_NONE;
382       token->keyword = RID_MAX;
383       break;
384     }
385   timevar_pop (TV_LEX);
386 }
387
388 /* Return a pointer to the next token from PARSER, reading it in if
389    necessary.  */
390
391 static inline c_token *
392 c_parser_peek_token (c_parser *parser)
393 {
394   if (parser->tokens_avail == 0)
395     {
396       c_lex_one_token (&parser->tokens[0]);
397       parser->tokens_avail = 1;
398     }
399   return &parser->tokens[0];
400 }
401
402 /* Return true if the next token from PARSER has the indicated
403    TYPE.  */
404
405 static inline bool
406 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
407 {
408   return c_parser_peek_token (parser)->type == type;
409 }
410
411 /* Return true if the next token from PARSER does not have the
412    indicated TYPE.  */
413
414 static inline bool
415 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
416 {
417   return !c_parser_next_token_is (parser, type);
418 }
419
420 /* Return true if the next token from PARSER is the indicated
421    KEYWORD.  */
422
423 static inline bool
424 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
425 {
426   c_token *token;
427
428   /* Peek at the next token.  */
429   token = c_parser_peek_token (parser);
430   /* Check to see if it is the indicated keyword.  */
431   return token->keyword == keyword;
432 }
433
434 /* Return true if TOKEN can start a type name,
435    false otherwise.  */
436 static bool
437 c_token_starts_typename (c_token *token)
438 {
439   switch (token->type)
440     {
441     case CPP_NAME:
442       switch (token->id_kind)
443         {
444         case C_ID_ID:
445           return false;
446         case C_ID_TYPENAME:
447           return true;
448         case C_ID_CLASSNAME:
449           gcc_assert (c_dialect_objc ());
450           return true;
451         default:
452           gcc_unreachable ();
453         }
454     case CPP_KEYWORD:
455       switch (token->keyword)
456         {
457         case RID_UNSIGNED:
458         case RID_LONG:
459         case RID_SHORT:
460         case RID_SIGNED:
461         case RID_COMPLEX:
462         case RID_INT:
463         case RID_CHAR:
464         case RID_FLOAT:
465         case RID_DOUBLE:
466         case RID_VOID:
467         case RID_DFLOAT32:
468         case RID_DFLOAT64:
469         case RID_DFLOAT128:
470         case RID_BOOL:
471         case RID_ENUM:
472         case RID_STRUCT:
473         case RID_UNION:
474         case RID_TYPEOF:
475         case RID_CONST:
476         case RID_VOLATILE:
477         case RID_RESTRICT:
478         case RID_ATTRIBUTE:
479           return true;
480         default:
481           return false;
482         }
483     case CPP_LESS:
484       if (c_dialect_objc ())
485         return true;
486       return false;
487     default:
488       return false;
489     }
490 }
491
492 /* Return true if the next token from PARSER can start a type name,
493    false otherwise.  */
494 static inline bool
495 c_parser_next_token_starts_typename (c_parser *parser)
496 {
497   c_token *token = c_parser_peek_token (parser);
498   return c_token_starts_typename (token);
499 }
500
501 /* Return true if TOKEN can start declaration specifiers, false
502    otherwise.  */
503 static bool
504 c_token_starts_declspecs (c_token *token)
505 {
506   switch (token->type)
507     {
508     case CPP_NAME:
509       switch (token->id_kind)
510         {
511         case C_ID_ID:
512           return false;
513         case C_ID_TYPENAME:
514           return true;
515         case C_ID_CLASSNAME:
516           gcc_assert (c_dialect_objc ());
517           return true;
518         default:
519           gcc_unreachable ();
520         }
521     case CPP_KEYWORD:
522       switch (token->keyword)
523         {
524         case RID_STATIC:
525         case RID_EXTERN:
526         case RID_REGISTER:
527         case RID_TYPEDEF:
528         case RID_INLINE:
529         case RID_AUTO:
530         case RID_THREAD:
531         case RID_UNSIGNED:
532         case RID_LONG:
533         case RID_SHORT:
534         case RID_SIGNED:
535         case RID_COMPLEX:
536         case RID_INT:
537         case RID_CHAR:
538         case RID_FLOAT:
539         case RID_DOUBLE:
540         case RID_VOID:
541         case RID_DFLOAT32:
542         case RID_DFLOAT64:
543         case RID_DFLOAT128:
544         case RID_BOOL:
545         case RID_ENUM:
546         case RID_STRUCT:
547         case RID_UNION:
548         case RID_TYPEOF:
549         case RID_CONST:
550         case RID_VOLATILE:
551         case RID_RESTRICT:
552         case RID_ATTRIBUTE:
553           return true;
554         default:
555           return false;
556         }
557     case CPP_LESS:
558       if (c_dialect_objc ())
559         return true;
560       return false;
561     default:
562       return false;
563     }
564 }
565
566 /* Return true if the next token from PARSER can start declaration
567    specifiers, false otherwise.  */
568 static inline bool
569 c_parser_next_token_starts_declspecs (c_parser *parser)
570 {
571   c_token *token = c_parser_peek_token (parser);
572   return c_token_starts_declspecs (token);
573 }
574
575 /* Return a pointer to the next-but-one token from PARSER, reading it
576    in if necessary.  The next token is already read in.  */
577
578 static c_token *
579 c_parser_peek_2nd_token (c_parser *parser)
580 {
581   if (parser->tokens_avail >= 2)
582     return &parser->tokens[1];
583   gcc_assert (parser->tokens_avail == 1);
584   gcc_assert (parser->tokens[0].type != CPP_EOF);
585   c_lex_one_token (&parser->tokens[1]);
586   parser->tokens_avail = 2;
587   return &parser->tokens[1];
588 }
589
590 /* Consume the next token from PARSER.  */
591
592 static void
593 c_parser_consume_token (c_parser *parser)
594 {
595   if (parser->tokens_avail == 2)
596     parser->tokens[0] = parser->tokens[1];
597   else
598     {
599       gcc_assert (parser->tokens_avail == 1);
600       gcc_assert (parser->tokens[0].type != CPP_EOF);
601     }
602   parser->tokens_avail--;
603 }
604
605 /* Update the globals input_location and in_system_header from
606    TOKEN.  */
607 static inline void
608 c_parser_set_source_position_from_token (c_token *token)
609 {
610   if (token->type != CPP_EOF)
611     {
612       input_location = token->location;
613       in_system_header = token->in_system_header;
614     }
615 }
616
617 /* Allocate a new parser.  */
618
619 static c_parser *
620 c_parser_new (void)
621 {
622   /* Use local storage to lex the first token because loading a PCH
623      file may cause garbage collection.  */
624   c_parser tparser;
625   c_parser *ret;
626   memset (&tparser, 0, sizeof tparser);
627   c_lex_one_token (&tparser.tokens[0]);
628   tparser.tokens_avail = 1;
629   ret = GGC_NEW (c_parser);
630   memcpy (ret, &tparser, sizeof tparser);
631   return ret;
632 }
633
634 /* Issue a diagnostic of the form
635       FILE:LINE: MESSAGE before TOKEN
636    where TOKEN is the next token in the input stream of PARSER.
637    MESSAGE (specified by the caller) is usually of the form "expected
638    OTHER-TOKEN".
639
640    Do not issue a diagnostic if still recovering from an error.
641
642    ??? This is taken from the C++ parser, but building up messages in
643    this way is not i18n-friendly and some other approach should be
644    used.  */
645
646 static void
647 c_parser_error (c_parser *parser, const char *gmsgid)
648 {
649   c_token *token = c_parser_peek_token (parser);
650   if (parser->error)
651     return;
652   parser->error = true;
653   if (!gmsgid)
654     return;
655   /* This diagnostic makes more sense if it is tagged to the line of
656      the token we just peeked at.  */
657   c_parser_set_source_position_from_token (token);
658   c_parse_error (gmsgid,
659                  /* Because c_parse_error does not understand
660                     CPP_KEYWORD, keywords are treated like
661                     identifiers.  */
662                  (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
663                  token->value);
664 }
665
666 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
667    issue the error MSGID.  If MSGID is NULL then a message has already
668    been produced and no message will be produced this time.  Returns
669    true if found, false otherwise.  */
670
671 static bool
672 c_parser_require (c_parser *parser,
673                   enum cpp_ttype type,
674                   const char *msgid)
675 {
676   if (c_parser_next_token_is (parser, type))
677     {
678       c_parser_consume_token (parser);
679       return true;
680     }
681   else
682     {
683       c_parser_error (parser, msgid);
684       return false;
685     }
686 }
687
688 /* If the next token is the indicated keyword, consume it.  Otherwise,
689    issue the error MSGID.  Returns true if found, false otherwise.  */
690
691 static bool
692 c_parser_require_keyword (c_parser *parser,
693                           enum rid keyword,
694                           const char *msgid)
695 {
696   if (c_parser_next_token_is_keyword (parser, keyword))
697     {
698       c_parser_consume_token (parser);
699       return true;
700     }
701   else
702     {
703       c_parser_error (parser, msgid);
704       return false;
705     }
706 }
707
708 /* Like c_parser_require, except that tokens will be skipped until the
709    desired token is found.  An error message is still produced if the
710    next token is not as expected.  If MSGID is NULL then a message has
711    already been produced and no message will be produced this
712    time.  */
713
714 static void
715 c_parser_skip_until_found (c_parser *parser,
716                            enum cpp_ttype type,
717                            const char *msgid)
718 {
719   unsigned nesting_depth = 0;
720
721   if (c_parser_require (parser, type, msgid))
722     return;
723
724   /* Skip tokens until the desired token is found.  */
725   while (true)
726     {
727       /* Peek at the next token.  */
728       c_token *token = c_parser_peek_token (parser);
729       /* If we've reached the token we want, consume it and stop.  */
730       if (token->type == type && !nesting_depth)
731         {
732           c_parser_consume_token (parser);
733           break;
734         }
735       /* If we've run out of tokens, stop.  */
736       if (token->type == CPP_EOF)
737         return;
738       if (token->type == CPP_OPEN_BRACE
739           || token->type == CPP_OPEN_PAREN
740           || token->type == CPP_OPEN_SQUARE)
741         ++nesting_depth;
742       else if (token->type == CPP_CLOSE_BRACE
743                || token->type == CPP_CLOSE_PAREN
744                || token->type == CPP_CLOSE_SQUARE)
745         {
746           if (nesting_depth-- == 0)
747             break;
748         }
749       /* Consume this token.  */
750       c_parser_consume_token (parser);
751     }
752   parser->error = false;
753 }
754
755 /* Skip tokens until the end of a parameter is found, but do not
756    consume the comma, semicolon or closing delimiter.  */
757
758 static void
759 c_parser_skip_to_end_of_parameter (c_parser *parser)
760 {
761   unsigned nesting_depth = 0;
762
763   while (true)
764     {
765       c_token *token = c_parser_peek_token (parser);
766       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
767           && !nesting_depth)
768         break;
769       /* If we've run out of tokens, stop.  */
770       if (token->type == CPP_EOF)
771         return;
772       if (token->type == CPP_OPEN_BRACE
773           || token->type == CPP_OPEN_PAREN
774           || token->type == CPP_OPEN_SQUARE)
775         ++nesting_depth;
776       else if (token->type == CPP_CLOSE_BRACE
777                || token->type == CPP_CLOSE_PAREN
778                || token->type == CPP_CLOSE_SQUARE)
779         {
780           if (nesting_depth-- == 0)
781             break;
782         }
783       /* Consume this token.  */
784       c_parser_consume_token (parser);
785     }
786   parser->error = false;
787 }
788
789 /* Skip tokens until we have consumed an entire block, or until we
790    have consumed a non-nested ';'.  */
791
792 static void
793 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
794 {
795   unsigned nesting_depth = 0;
796
797   while (true)
798     {
799       c_token *token;
800
801       /* Peek at the next token.  */
802       token = c_parser_peek_token (parser);
803       /* If we've run out of tokens, stop.  */
804       if (token->type == CPP_EOF)
805         return;
806       /* If the next token is a ';', we have reached the end of the
807          statement.  */
808       if (token->type == CPP_SEMICOLON && !nesting_depth)
809         {
810           /* Consume the ';'.  */
811           c_parser_consume_token (parser);
812           break;
813         }
814       /* If the next token is a non-nested '}', then we have reached
815          the end of the current block.  */
816       if (token->type == CPP_CLOSE_BRACE
817           && (nesting_depth == 0 || --nesting_depth == 0))
818         {
819           c_parser_consume_token (parser);
820           break;
821         }
822       /* If it the next token is a '{', then we are entering a new
823          block.  Consume the entire block.  */
824       if (token->type == CPP_OPEN_BRACE)
825         ++nesting_depth;
826       c_parser_consume_token (parser);
827     }
828   parser->error = false;
829 }
830
831
832 /* Save the warning flags which are controlled by __extension__.  */
833
834 static inline int
835 disable_extension_diagnostics (void)
836 {
837   int ret = (pedantic
838              | (warn_pointer_arith << 1)
839              | (warn_traditional << 2)
840              | (flag_iso << 3));
841   pedantic = 0;
842   warn_pointer_arith = 0;
843   warn_traditional = 0;
844   flag_iso = 0;
845   return ret;
846 }
847
848 /* Restore the warning flags which are controlled by __extension__.
849    FLAGS is the return value from disable_extension_diagnostics.  */
850
851 static inline void
852 restore_extension_diagnostics (int flags)
853 {
854   pedantic = flags & 1;
855   warn_pointer_arith = (flags >> 1) & 1;
856   warn_traditional = (flags >> 2) & 1;
857   flag_iso = (flags >> 3) & 1;
858 }
859
860 /* Possibly kinds of declarator to parse.  */
861 typedef enum c_dtr_syn {
862   /* A normal declarator with an identifier.  */
863   C_DTR_NORMAL,
864   /* An abstract declarator (maybe empty).  */
865   C_DTR_ABSTRACT,
866   /* A parameter declarator: may be either, but after a type name does
867      not redeclare a typedef name as an identifier if it can
868      alternatively be interpreted as a typedef name; see DR#009,
869      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
870      following DR#249.  For example, given a typedef T, "int T" and
871      "int *T" are valid parameter declarations redeclaring T, while
872      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
873      abstract declarators rather than involving redundant parentheses;
874      the same applies with attributes inside the parentheses before
875      "T".  */
876   C_DTR_PARM
877 } c_dtr_syn;
878
879 static void c_parser_external_declaration (c_parser *);
880 static void c_parser_asm_definition (c_parser *);
881 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
882 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
883                                 bool);
884 static struct c_typespec c_parser_enum_specifier (c_parser *);
885 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
886 static tree c_parser_struct_declaration (c_parser *);
887 static struct c_typespec c_parser_typeof_specifier (c_parser *);
888 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
889                                                  bool *);
890 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
891                                                         c_dtr_syn, bool *);
892 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
893                                                               bool,
894                                                               struct c_declarator *);
895 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
896 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
897 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
898 static tree c_parser_simple_asm_expr (c_parser *);
899 static tree c_parser_attributes (c_parser *);
900 static struct c_type_name *c_parser_type_name (c_parser *);
901 static struct c_expr c_parser_initializer (c_parser *);
902 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
903 static void c_parser_initelt (c_parser *);
904 static void c_parser_initval (c_parser *, struct c_expr *);
905 static tree c_parser_compound_statement (c_parser *);
906 static void c_parser_compound_statement_nostart (c_parser *);
907 static void c_parser_label (c_parser *);
908 static void c_parser_statement (c_parser *);
909 static void c_parser_statement_after_labels (c_parser *);
910 static void c_parser_if_statement (c_parser *);
911 static void c_parser_switch_statement (c_parser *);
912 static void c_parser_while_statement (c_parser *);
913 static void c_parser_do_statement (c_parser *);
914 static void c_parser_for_statement (c_parser *);
915 static tree c_parser_asm_statement (c_parser *);
916 static tree c_parser_asm_operands (c_parser *, bool);
917 static tree c_parser_asm_clobbers (c_parser *);
918 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
919 static struct c_expr c_parser_conditional_expression (c_parser *,
920                                                       struct c_expr *);
921 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
922 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
923 static struct c_expr c_parser_unary_expression (c_parser *);
924 static struct c_expr c_parser_sizeof_expression (c_parser *);
925 static struct c_expr c_parser_alignof_expression (c_parser *);
926 static struct c_expr c_parser_postfix_expression (c_parser *);
927 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
928                                                                    struct c_type_name *);
929 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
930                                                                 struct c_expr);
931 static struct c_expr c_parser_expression (c_parser *);
932 static struct c_expr c_parser_expression_conv (c_parser *);
933 static tree c_parser_expr_list (c_parser *, bool);
934
935 /* These Objective-C parser functions are only ever called when
936    compiling Objective-C.  */
937 static void c_parser_objc_class_definition (c_parser *);
938 static void c_parser_objc_class_instance_variables (c_parser *);
939 static void c_parser_objc_class_declaration (c_parser *);
940 static void c_parser_objc_alias_declaration (c_parser *);
941 static void c_parser_objc_protocol_definition (c_parser *);
942 static enum tree_code c_parser_objc_method_type (c_parser *);
943 static void c_parser_objc_method_definition (c_parser *);
944 static void c_parser_objc_methodprotolist (c_parser *);
945 static void c_parser_objc_methodproto (c_parser *);
946 static tree c_parser_objc_method_decl (c_parser *);
947 static tree c_parser_objc_type_name (c_parser *);
948 static tree c_parser_objc_protocol_refs (c_parser *);
949 static void c_parser_objc_try_catch_statement (c_parser *);
950 static void c_parser_objc_synchronized_statement (c_parser *);
951 static tree c_parser_objc_selector (c_parser *);
952 static tree c_parser_objc_selector_arg (c_parser *);
953 static tree c_parser_objc_receiver (c_parser *);
954 static tree c_parser_objc_message_args (c_parser *);
955 static tree c_parser_objc_keywordexpr (c_parser *);
956
957 /* Parse a translation unit (C90 6.7, C99 6.9).
958
959    translation-unit:
960      external-declarations
961
962    external-declarations:
963      external-declaration
964      external-declarations external-declaration
965
966    GNU extensions:
967
968    translation-unit:
969      empty
970 */
971
972 static void
973 c_parser_translation_unit (c_parser *parser)
974 {
975   if (c_parser_next_token_is (parser, CPP_EOF))
976     {
977       if (pedantic)
978         pedwarn ("ISO C forbids an empty source file");
979     }
980   else
981     {
982       void *obstack_position = obstack_alloc (&parser_obstack, 0);
983       do
984         {
985           ggc_collect ();
986           c_parser_external_declaration (parser);
987           obstack_free (&parser_obstack, obstack_position);
988         }
989       while (c_parser_next_token_is_not (parser, CPP_EOF));
990     }
991 }
992
993 /* Parse an external declaration (C90 6.7, C99 6.9).
994
995    external-declaration:
996      function-definition
997      declaration
998
999    GNU extensions:
1000
1001    external-declaration:
1002      asm-definition
1003      ;
1004      __extension__ external-declaration
1005
1006    Objective-C:
1007
1008    external-declaration:
1009      objc-class-definition
1010      objc-class-declaration
1011      objc-alias-declaration
1012      objc-protocol-definition
1013      objc-method-definition
1014      @end
1015 */
1016
1017 static void
1018 c_parser_external_declaration (c_parser *parser)
1019 {
1020   int ext;
1021   switch (c_parser_peek_token (parser)->type)
1022     {
1023     case CPP_KEYWORD:
1024       switch (c_parser_peek_token (parser)->keyword)
1025         {
1026         case RID_EXTENSION:
1027           ext = disable_extension_diagnostics ();
1028           c_parser_consume_token (parser);
1029           c_parser_external_declaration (parser);
1030           restore_extension_diagnostics (ext);
1031           break;
1032         case RID_ASM:
1033           c_parser_asm_definition (parser);
1034           break;
1035         case RID_AT_INTERFACE:
1036         case RID_AT_IMPLEMENTATION:
1037           gcc_assert (c_dialect_objc ());
1038           c_parser_objc_class_definition (parser);
1039           break;
1040         case RID_AT_CLASS:
1041           gcc_assert (c_dialect_objc ());
1042           c_parser_objc_class_declaration (parser);
1043           break;
1044         case RID_AT_ALIAS:
1045           gcc_assert (c_dialect_objc ());
1046           c_parser_objc_alias_declaration (parser);
1047           break;
1048         case RID_AT_PROTOCOL:
1049           gcc_assert (c_dialect_objc ());
1050           c_parser_objc_protocol_definition (parser);
1051           break;
1052         case RID_AT_END:
1053           gcc_assert (c_dialect_objc ());
1054           c_parser_consume_token (parser);
1055           objc_finish_implementation ();
1056           break;
1057         default:
1058           goto decl_or_fndef;
1059         }
1060       break;
1061     case CPP_SEMICOLON:
1062       if (pedantic)
1063         pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1064       c_parser_consume_token (parser);
1065       break;
1066     case CPP_PLUS:
1067     case CPP_MINUS:
1068       if (c_dialect_objc ())
1069         {
1070           c_parser_objc_method_definition (parser);
1071           break;
1072         }
1073       /* Else fall through, and yield a syntax error trying to parse
1074          as a declaration or function definition.  */
1075     default:
1076     decl_or_fndef:
1077       /* A declaration or a function definition.  We can only tell
1078          which after parsing the declaration specifiers, if any, and
1079          the first declarator.  */
1080       c_parser_declaration_or_fndef (parser, true, true, false, true);
1081       break;
1082     }
1083 }
1084
1085 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1086    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1087    accepted; otherwise (old-style parameter declarations) only other
1088    declarations are accepted.  If NESTED is true, we are inside a
1089    function or parsing old-style parameter declarations; any functions
1090    encountered are nested functions and declaration specifiers are
1091    required; otherwise we are at top level and functions are normal
1092    functions and declaration specifiers may be optional.  If EMPTY_OK
1093    is true, empty declarations are OK (subject to all other
1094    constraints); otherwise (old-style parameter declarations) they are
1095    diagnosed.  If START_ATTR_OK is true, the declaration specifiers
1096    may start with attributes; otherwise they may not.
1097
1098    declaration:
1099      declaration-specifiers init-declarator-list[opt] ;
1100
1101    function-definition:
1102      declaration-specifiers[opt] declarator declaration-list[opt]
1103        compound-statement
1104
1105    declaration-list:
1106      declaration
1107      declaration-list declaration
1108
1109    init-declarator-list:
1110      init-declarator
1111      init-declarator-list , init-declarator
1112
1113    init-declarator:
1114      declarator simple-asm-expr[opt] attributes[opt]
1115      declarator simple-asm-expr[opt] attributes[opt] = initializer
1116
1117    GNU extensions:
1118
1119    nested-function-definition:
1120      declaration-specifiers declarator declaration-list[opt]
1121        compound-statement
1122
1123    The simple-asm-expr and attributes are GNU extensions.
1124
1125    This function does not handle __extension__; that is handled in its
1126    callers.  ??? Following the old parser, __extension__ may start
1127    external declarations, declarations in functions and declarations
1128    at the start of "for" loops, but not old-style parameter
1129    declarations.
1130
1131    C99 requires declaration specifiers in a function definition; the
1132    absence is diagnosed through the diagnosis of implicit int.  In GNU
1133    C we also allow but diagnose declarations without declaration
1134    specifiers, but only at top level (elsewhere they conflict with
1135    other syntax).  */
1136
1137 static void
1138 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1139                                bool nested, bool start_attr_ok)
1140 {
1141   struct c_declspecs *specs;
1142   tree prefix_attrs;
1143   tree all_prefix_attrs;
1144   bool diagnosed_no_specs = false;
1145   specs = build_null_declspecs ();
1146   c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1147   if (parser->error)
1148     {
1149       c_parser_skip_to_end_of_block_or_statement (parser);
1150       return;
1151     }
1152   if (nested && !specs->declspecs_seen_p)
1153     {
1154       c_parser_error (parser, "expected declaration specifiers");
1155       c_parser_skip_to_end_of_block_or_statement (parser);
1156       return;
1157     }
1158   finish_declspecs (specs);
1159   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1160     {
1161       if (empty_ok)
1162         shadow_tag (specs);
1163       else
1164         {
1165           shadow_tag_warned (specs, 1);
1166           pedwarn ("empty declaration");
1167         }
1168       c_parser_consume_token (parser);
1169       return;
1170     }
1171   pending_xref_error ();
1172   prefix_attrs = specs->attrs;
1173   all_prefix_attrs = prefix_attrs;
1174   specs->attrs = NULL_TREE;
1175   while (true)
1176     {
1177       struct c_declarator *declarator;
1178       bool dummy = false;
1179       tree fnbody;
1180       /* Declaring either one or more declarators (in which case we
1181          should diagnose if there were no declaration specifiers) or a
1182          function definition (in which case the diagnostic for
1183          implicit int suffices).  */
1184       declarator = c_parser_declarator (parser, specs->type_seen_p,
1185                                         C_DTR_NORMAL, &dummy);
1186       if (declarator == NULL)
1187         {
1188           c_parser_skip_to_end_of_block_or_statement (parser);
1189           return;
1190         }
1191       if (c_parser_next_token_is (parser, CPP_EQ)
1192           || c_parser_next_token_is (parser, CPP_COMMA)
1193           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1194           || c_parser_next_token_is_keyword (parser, RID_ASM)
1195           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1196         {
1197           tree asm_name = NULL_TREE;
1198           tree postfix_attrs = NULL_TREE;
1199           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1200             {
1201               diagnosed_no_specs = true;
1202               pedwarn ("data definition has no type or storage class");
1203             }
1204           /* Having seen a data definition, there cannot now be a
1205              function definition.  */
1206           fndef_ok = false;
1207           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1208             asm_name = c_parser_simple_asm_expr (parser);
1209           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1210             postfix_attrs = c_parser_attributes (parser);
1211           if (c_parser_next_token_is (parser, CPP_EQ))
1212             {
1213               tree d;
1214               struct c_expr init;
1215               c_parser_consume_token (parser);
1216               /* The declaration of the variable is in effect while
1217                  its initializer is parsed.  */
1218               d = start_decl (declarator, specs, true,
1219                               chainon (postfix_attrs, all_prefix_attrs));
1220               if (!d)
1221                 d = error_mark_node;
1222               start_init (d, asm_name, global_bindings_p ());
1223               init = c_parser_initializer (parser);
1224               finish_init ();
1225               if (d != error_mark_node)
1226                 {
1227                   maybe_warn_string_init (TREE_TYPE (d), init);
1228                   finish_decl (d, init.value, asm_name);
1229                 }
1230             }
1231           else
1232             {
1233               tree d = start_decl (declarator, specs, false,
1234                                    chainon (postfix_attrs,
1235                                             all_prefix_attrs));
1236               if (d)
1237                 finish_decl (d, NULL_TREE, asm_name);
1238             }
1239           if (c_parser_next_token_is (parser, CPP_COMMA))
1240             {
1241               c_parser_consume_token (parser);
1242               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1243                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1244                                             prefix_attrs);
1245               else
1246                 all_prefix_attrs = prefix_attrs;
1247               continue;
1248             }
1249           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1250             {
1251               c_parser_consume_token (parser);
1252               return;
1253             }
1254           else
1255             {
1256               c_parser_error (parser, "expected %<,%> or %<;%>");
1257               c_parser_skip_to_end_of_block_or_statement (parser);
1258               return;
1259             }
1260         }
1261       else if (!fndef_ok)
1262         {
1263           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1264                           "%<asm%> or %<__attribute__%>");
1265           c_parser_skip_to_end_of_block_or_statement (parser);
1266           return;
1267         }
1268       /* Function definition (nested or otherwise).  */
1269       if (nested)
1270         {
1271           if (pedantic)
1272             pedwarn ("ISO C forbids nested functions");
1273           push_function_context ();
1274         }
1275       if (!start_function (specs, declarator, all_prefix_attrs))
1276         {
1277           /* This can appear in many cases looking nothing like a
1278              function definition, so we don't give a more specific
1279              error suggesting there was one.  */
1280           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1281                           "or %<__attribute__%>");
1282           if (nested)
1283             pop_function_context ();
1284           break;
1285         }
1286       /* Parse old-style parameter declarations.  ??? Attributes are
1287          not allowed to start declaration specifiers here because of a
1288          syntax conflict between a function declaration with attribute
1289          suffix and a function definition with an attribute prefix on
1290          first old-style parameter declaration.  Following the old
1291          parser, they are not accepted on subsequent old-style
1292          parameter declarations either.  However, there is no
1293          ambiguity after the first declaration, nor indeed on the
1294          first as long as we don't allow postfix attributes after a
1295          declarator with a nonempty identifier list in a definition;
1296          and postfix attributes have never been accepted here in
1297          function definitions either.  */
1298       while (c_parser_next_token_is_not (parser, CPP_EOF)
1299              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1300         c_parser_declaration_or_fndef (parser, false, false, true, false);
1301       DECL_SOURCE_LOCATION (current_function_decl)
1302         = c_parser_peek_token (parser)->location;
1303       store_parm_decls ();
1304       fnbody = c_parser_compound_statement (parser);
1305       if (nested)
1306         {
1307           tree decl = current_function_decl;
1308           add_stmt (fnbody);
1309           finish_function ();
1310           pop_function_context ();
1311           add_stmt (build_stmt (DECL_EXPR, decl));
1312         }
1313       else
1314         {
1315           add_stmt (fnbody);
1316           finish_function ();
1317         }
1318       break;
1319     }
1320 }
1321
1322 /* Parse an asm-definition (asm() outside a function body).  This is a
1323    GNU extension.
1324
1325    asm-definition:
1326      simple-asm-expr ;
1327 */
1328
1329 static void
1330 c_parser_asm_definition (c_parser *parser)
1331 {
1332   tree asm_str = c_parser_simple_asm_expr (parser);
1333   /* ??? This only works sensibly in the presence of
1334      -fno-unit-at-a-time; file-scope asms really need to be passed to
1335      cgraph which needs to preserve the order of functions and
1336      file-scope asms.  */
1337   if (asm_str)
1338     assemble_asm (asm_str);
1339   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1340 }
1341
1342 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1343    6.7), adding them to SPECS (which may already include some).
1344    Storage class specifiers are accepted iff SCSPEC_OK; type
1345    specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1346    the start iff START_ATTR_OK.
1347
1348    declaration-specifiers:
1349      storage-class-specifier declaration-specifiers[opt]
1350      type-specifier declaration-specifiers[opt]
1351      type-qualifier declaration-specifiers[opt]
1352      function-specifier declaration-specifiers[opt]
1353
1354    Function specifiers (inline) are from C99, and are currently
1355    handled as storage class specifiers, as is __thread.
1356
1357    C90 6.5.1, C99 6.7.1:
1358    storage-class-specifier:
1359      typedef
1360      extern
1361      static
1362      auto
1363      register
1364
1365    C99 6.7.4:
1366    function-specifier:
1367      inline
1368
1369    C90 6.5.2, C99 6.7.2:
1370    type-specifier:
1371      void
1372      char
1373      short
1374      int
1375      long
1376      float
1377      double
1378      signed
1379      unsigned
1380      _Bool
1381      _Complex
1382      [_Imaginary removed in C99 TC2]
1383      struct-or-union-specifier
1384      enum-specifier
1385      typedef-name
1386
1387    (_Bool and _Complex are new in C99.)
1388
1389    C90 6.5.3, C99 6.7.3:
1390
1391    type-qualifier:
1392      const
1393      restrict
1394      volatile
1395
1396    (restrict is new in C99.)
1397
1398    GNU extensions:
1399
1400    declaration-specifiers:
1401      attributes declaration-specifiers[opt]
1402
1403    storage-class-specifier:
1404      __thread
1405
1406    type-specifier:
1407      typeof-specifier
1408      _Decimal32
1409      _Decimal64
1410      _Decimal128
1411
1412    Objective-C:
1413
1414    type-specifier:
1415      class-name objc-protocol-refs[opt]
1416      typedef-name objc-protocol-refs
1417      objc-protocol-refs
1418 */
1419
1420 static void
1421 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1422                     bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1423 {
1424   bool attrs_ok = start_attr_ok;
1425   bool seen_type = specs->type_seen_p;
1426   while (c_parser_next_token_is (parser, CPP_NAME)
1427          || c_parser_next_token_is (parser, CPP_KEYWORD)
1428          || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1429     {
1430       struct c_typespec t;
1431       tree attrs;
1432       if (c_parser_next_token_is (parser, CPP_NAME))
1433         {
1434           tree value = c_parser_peek_token (parser)->value;
1435           c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1436           /* This finishes the specifiers unless a type name is OK, it
1437              is declared as a type name and a type name hasn't yet
1438              been seen.  */
1439           if (!typespec_ok || seen_type
1440               || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1441             break;
1442           c_parser_consume_token (parser);
1443           seen_type = true;
1444           attrs_ok = true;
1445           if (kind == C_ID_TYPENAME
1446               && (!c_dialect_objc ()
1447                   || c_parser_next_token_is_not (parser, CPP_LESS)))
1448             {
1449               t.kind = ctsk_typedef;
1450               /* For a typedef name, record the meaning, not the name.
1451                  In case of 'foo foo, bar;'.  */
1452               t.spec = lookup_name (value);
1453             }
1454           else
1455             {
1456               tree proto = NULL_TREE;
1457               gcc_assert (c_dialect_objc ());
1458               t.kind = ctsk_objc;
1459               if (c_parser_next_token_is (parser, CPP_LESS))
1460                 proto = c_parser_objc_protocol_refs (parser);
1461               t.spec = objc_get_protocol_qualified_type (value, proto);
1462             }
1463           declspecs_add_type (specs, t);
1464           continue;
1465         }
1466       if (c_parser_next_token_is (parser, CPP_LESS))
1467         {
1468           /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1469              nisse@lysator.liu.se.  */
1470           tree proto;
1471           gcc_assert (c_dialect_objc ());
1472           if (!typespec_ok || seen_type)
1473             break;
1474           proto = c_parser_objc_protocol_refs (parser);
1475           t.kind = ctsk_objc;
1476           t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1477           declspecs_add_type (specs, t);
1478           continue;
1479         }
1480       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1481       switch (c_parser_peek_token (parser)->keyword)
1482         {
1483         case RID_STATIC:
1484         case RID_EXTERN:
1485         case RID_REGISTER:
1486         case RID_TYPEDEF:
1487         case RID_INLINE:
1488         case RID_AUTO:
1489         case RID_THREAD:
1490           if (!scspec_ok)
1491             goto out;
1492           attrs_ok = true;
1493           /* TODO: Distinguish between function specifiers (inline)
1494              and storage class specifiers, either here or in
1495              declspecs_add_scspec.  */
1496           declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1497           c_parser_consume_token (parser);
1498           break;
1499         case RID_UNSIGNED:
1500         case RID_LONG:
1501         case RID_SHORT:
1502         case RID_SIGNED:
1503         case RID_COMPLEX:
1504         case RID_INT:
1505         case RID_CHAR:
1506         case RID_FLOAT:
1507         case RID_DOUBLE:
1508         case RID_VOID:
1509         case RID_DFLOAT32:
1510         case RID_DFLOAT64:
1511         case RID_DFLOAT128:
1512         case RID_BOOL:
1513           if (!typespec_ok)
1514             goto out;
1515           attrs_ok = true;
1516           seen_type = true;
1517           OBJC_NEED_RAW_IDENTIFIER (1);
1518           t.kind = ctsk_resword;
1519           t.spec = c_parser_peek_token (parser)->value;
1520           declspecs_add_type (specs, t);
1521           c_parser_consume_token (parser);
1522           break;
1523         case RID_ENUM:
1524           if (!typespec_ok)
1525             goto out;
1526           attrs_ok = true;
1527           seen_type = true;
1528           t = c_parser_enum_specifier (parser);
1529           declspecs_add_type (specs, t);
1530           break;
1531         case RID_STRUCT:
1532         case RID_UNION:
1533           if (!typespec_ok)
1534             goto out;
1535           attrs_ok = true;
1536           seen_type = true;
1537           t = c_parser_struct_or_union_specifier (parser);
1538           declspecs_add_type (specs, t);
1539           break;
1540         case RID_TYPEOF:
1541           /* ??? The old parser rejected typeof after other type
1542              specifiers, but is a syntax error the best way of
1543              handling this?  */
1544           if (!typespec_ok || seen_type)
1545             goto out;
1546           attrs_ok = true;
1547           seen_type = true;
1548           t = c_parser_typeof_specifier (parser);
1549           declspecs_add_type (specs, t);
1550           break;
1551         case RID_CONST:
1552         case RID_VOLATILE:
1553         case RID_RESTRICT:
1554           attrs_ok = true;
1555           declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1556           c_parser_consume_token (parser);
1557           break;
1558         case RID_ATTRIBUTE:
1559           if (!attrs_ok)
1560             goto out;
1561           attrs = c_parser_attributes (parser);
1562           declspecs_add_attrs (specs, attrs);
1563           break;
1564         default:
1565           goto out;
1566         }
1567     }
1568  out: ;
1569 }
1570
1571 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1572
1573    enum-specifier:
1574      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1575      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1576      enum attributes[opt] identifier
1577
1578    The form with trailing comma is new in C99.  The forms with
1579    attributes are GNU extensions.  In GNU C, we accept any expression
1580    without commas in the syntax (assignment expressions, not just
1581    conditional expressions); assignment expressions will be diagnosed
1582    as non-constant.
1583
1584    enumerator-list:
1585      enumerator
1586      enumerator-list , enumerator
1587
1588    enumerator:
1589      enumeration-constant
1590      enumeration-constant = constant-expression
1591 */
1592
1593 static struct c_typespec
1594 c_parser_enum_specifier (c_parser *parser)
1595 {
1596   struct c_typespec ret;
1597   tree attrs;
1598   tree ident = NULL_TREE;
1599   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1600   c_parser_consume_token (parser);
1601   attrs = c_parser_attributes (parser);
1602   if (c_parser_next_token_is (parser, CPP_NAME))
1603     {
1604       ident = c_parser_peek_token (parser)->value;
1605       c_parser_consume_token (parser);
1606     }
1607   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1608     {
1609       /* Parse an enum definition.  */
1610       tree type = start_enum (ident);
1611       tree postfix_attrs;
1612       /* We chain the enumerators in reverse order, then put them in
1613          forward order at the end.  */
1614       tree values = NULL_TREE;
1615       c_parser_consume_token (parser);
1616       while (true)
1617         {
1618           tree enum_id;
1619           tree enum_value;
1620           tree enum_decl;
1621           bool seen_comma;
1622           if (c_parser_next_token_is_not (parser, CPP_NAME))
1623             {
1624               c_parser_error (parser, "expected identifier");
1625               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1626               values = error_mark_node;
1627               break;
1628             }
1629           enum_id = c_parser_peek_token (parser)->value;
1630           c_parser_consume_token (parser);
1631           if (c_parser_next_token_is (parser, CPP_EQ))
1632             {
1633               c_parser_consume_token (parser);
1634               enum_value = c_parser_expr_no_commas (parser, NULL).value;
1635             }
1636           else
1637             enum_value = NULL_TREE;
1638           enum_decl = build_enumerator (enum_id, enum_value);
1639           TREE_CHAIN (enum_decl) = values;
1640           values = enum_decl;
1641           seen_comma = false;
1642           if (c_parser_next_token_is (parser, CPP_COMMA))
1643             {
1644               seen_comma = true;
1645               c_parser_consume_token (parser);
1646             }
1647           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1648             {
1649               if (seen_comma && pedantic && !flag_isoc99)
1650                 pedwarn ("comma at end of enumerator list");
1651               c_parser_consume_token (parser);
1652               break;
1653             }
1654           if (!seen_comma)
1655             {
1656               c_parser_error (parser, "expected %<,%> or %<}%>");
1657               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1658               values = error_mark_node;
1659               break;
1660             }
1661         }
1662       postfix_attrs = c_parser_attributes (parser);
1663       ret.spec = finish_enum (type, nreverse (values),
1664                               chainon (attrs, postfix_attrs));
1665       ret.kind = ctsk_tagdef;
1666       return ret;
1667     }
1668   else if (!ident)
1669     {
1670       c_parser_error (parser, "expected %<{%>");
1671       ret.spec = error_mark_node;
1672       ret.kind = ctsk_tagref;
1673       return ret;
1674     }
1675   ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1676   /* In ISO C, enumerated types can be referred to only if already
1677      defined.  */
1678   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1679     pedwarn ("ISO C forbids forward references to %<enum%> types");
1680   return ret;
1681 }
1682
1683 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1684
1685    struct-or-union-specifier:
1686      struct-or-union attributes[opt] identifier[opt]
1687        { struct-contents } attributes[opt]
1688      struct-or-union attributes[opt] identifier
1689
1690    struct-contents:
1691      struct-declaration-list
1692
1693    struct-declaration-list:
1694      struct-declaration ;
1695      struct-declaration-list struct-declaration ;
1696
1697    GNU extensions:
1698
1699    struct-contents:
1700      empty
1701      struct-declaration
1702      struct-declaration-list struct-declaration
1703
1704    struct-declaration-list:
1705      struct-declaration-list ;
1706      ;
1707
1708    (Note that in the syntax here, unlike that in ISO C, the semicolons
1709    are included here rather than in struct-declaration, in order to
1710    describe the syntax with extra semicolons and missing semicolon at
1711    end.)
1712
1713    Objective-C:
1714
1715    struct-declaration-list:
1716      @defs ( class-name )
1717
1718    (Note this does not include a trailing semicolon, but can be
1719    followed by further declarations, and gets a pedwarn-if-pedantic
1720    when followed by a semicolon.)  */
1721
1722 static struct c_typespec
1723 c_parser_struct_or_union_specifier (c_parser *parser)
1724 {
1725   struct c_typespec ret;
1726   tree attrs;
1727   tree ident = NULL_TREE;
1728   enum tree_code code;
1729   switch (c_parser_peek_token (parser)->keyword)
1730     {
1731     case RID_STRUCT:
1732       code = RECORD_TYPE;
1733       break;
1734     case RID_UNION:
1735       code = UNION_TYPE;
1736       break;
1737     default:
1738       gcc_unreachable ();
1739     }
1740   c_parser_consume_token (parser);
1741   attrs = c_parser_attributes (parser);
1742   if (c_parser_next_token_is (parser, CPP_NAME))
1743     {
1744       ident = c_parser_peek_token (parser)->value;
1745       c_parser_consume_token (parser);
1746     }
1747   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1748     {
1749       /* Parse a struct or union definition.  Start the scope of the
1750          tag before parsing components.  */
1751       tree type = start_struct (code, ident);
1752       tree postfix_attrs;
1753       /* We chain the components in reverse order, then put them in
1754          forward order at the end.  Each struct-declaration may
1755          declare multiple components (comma-separated), so we must use
1756          chainon to join them, although when parsing each
1757          struct-declaration we can use TREE_CHAIN directly.
1758
1759          The theory behind all this is that there will be more
1760          semicolon separated fields than comma separated fields, and
1761          so we'll be minimizing the number of node traversals required
1762          by chainon.  */
1763       tree contents = NULL_TREE;
1764       c_parser_consume_token (parser);
1765       /* Handle the Objective-C @defs construct,
1766          e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
1767       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1768         {
1769           tree name;
1770           gcc_assert (c_dialect_objc ());
1771           c_parser_consume_token (parser);
1772           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1773             goto end_at_defs;
1774           if (c_parser_next_token_is (parser, CPP_NAME)
1775               && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1776             {
1777               name = c_parser_peek_token (parser)->value;
1778               c_parser_consume_token (parser);
1779             }
1780           else
1781             {
1782               c_parser_error (parser, "expected class name");
1783               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1784               goto end_at_defs;
1785             }
1786           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1787                                      "expected %<)%>");
1788           contents = nreverse (objc_get_class_ivars (name));
1789         }
1790     end_at_defs:
1791       /* Parse the struct-declarations and semicolons.  Problems with
1792          semicolons are diagnosed here; empty structures are diagnosed
1793          elsewhere.  */
1794       while (true)
1795         {
1796           tree decls;
1797           /* Parse any stray semicolon.  */
1798           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1799             {
1800               if (pedantic)
1801                 pedwarn ("extra semicolon in struct or union specified");
1802               c_parser_consume_token (parser);
1803               continue;
1804             }
1805           /* Stop if at the end of the struct or union contents.  */
1806           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1807             {
1808               c_parser_consume_token (parser);
1809               break;
1810             }
1811           /* Parse some comma-separated declarations, but not the
1812              trailing semicolon if any.  */
1813           decls = c_parser_struct_declaration (parser);
1814           contents = chainon (decls, contents);
1815           /* If no semicolon follows, either we have a parse error or
1816              are at the end of the struct or union and should
1817              pedwarn.  */
1818           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1819             c_parser_consume_token (parser);
1820           else
1821             {
1822               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1823                 pedwarn ("no semicolon at end of struct or union");
1824               else
1825                 {
1826                   c_parser_error (parser, "expected %<;%>");
1827                   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1828                   break;
1829                 }
1830             }
1831         }
1832       postfix_attrs = c_parser_attributes (parser);
1833       ret.spec = finish_struct (type, nreverse (contents),
1834                                 chainon (attrs, postfix_attrs));
1835       ret.kind = ctsk_tagdef;
1836       return ret;
1837     }
1838   else if (!ident)
1839     {
1840       c_parser_error (parser, "expected %<{%>");
1841       ret.spec = error_mark_node;
1842       ret.kind = ctsk_tagref;
1843       return ret;
1844     }
1845   ret = parser_xref_tag (code, ident);
1846   return ret;
1847 }
1848
1849 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1850    the trailing semicolon.
1851
1852    struct-declaration:
1853      specifier-qualifier-list struct-declarator-list
1854
1855    specifier-qualifier-list:
1856      type-specifier specifier-qualifier-list[opt]
1857      type-qualifier specifier-qualifier-list[opt]
1858      attributes specifier-qualifier-list[opt]
1859
1860    struct-declarator-list:
1861      struct-declarator
1862      struct-declarator-list , attributes[opt] struct-declarator
1863
1864    struct-declarator:
1865      declarator attributes[opt]
1866      declarator[opt] : constant-expression attributes[opt]
1867
1868    GNU extensions:
1869
1870    struct-declaration:
1871      __extension__ struct-declaration
1872      specifier-qualifier-list
1873
1874    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
1875    of attributes where shown is a GNU extension.  In GNU C, we accept
1876    any expression without commas in the syntax (assignment
1877    expressions, not just conditional expressions); assignment
1878    expressions will be diagnosed as non-constant.  */
1879
1880 static tree
1881 c_parser_struct_declaration (c_parser *parser)
1882 {
1883   struct c_declspecs *specs;
1884   tree prefix_attrs;
1885   tree all_prefix_attrs;
1886   tree decls;
1887   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1888     {
1889       int ext;
1890       tree decl;
1891       ext = disable_extension_diagnostics ();
1892       c_parser_consume_token (parser);
1893       decl = c_parser_struct_declaration (parser);
1894       restore_extension_diagnostics (ext);
1895       return decl;
1896     }
1897   specs = build_null_declspecs ();
1898   c_parser_declspecs (parser, specs, false, true, true);
1899   if (parser->error)
1900     return NULL_TREE;
1901   if (!specs->declspecs_seen_p)
1902     {
1903       c_parser_error (parser, "expected specifier-qualifier-list");
1904       return NULL_TREE;
1905     }
1906   finish_declspecs (specs);
1907   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1908     {
1909       tree ret;
1910       if (!specs->type_seen_p)
1911         {
1912           if (pedantic)
1913             pedwarn ("ISO C forbids member declarations with no members");
1914           shadow_tag_warned (specs, pedantic);
1915           ret = NULL_TREE;
1916         }
1917       else
1918         {
1919           /* Support for unnamed structs or unions as members of
1920              structs or unions (which is [a] useful and [b] supports
1921              MS P-SDK).  */
1922           ret = grokfield (build_id_declarator (NULL_TREE), specs, NULL_TREE);
1923         }
1924       return ret;
1925     }
1926   pending_xref_error ();
1927   prefix_attrs = specs->attrs;
1928   all_prefix_attrs = prefix_attrs;
1929   specs->attrs = NULL_TREE;
1930   decls = NULL_TREE;
1931   while (true)
1932     {
1933       /* Declaring one or more declarators or un-named bit-fields.  */
1934       struct c_declarator *declarator;
1935       bool dummy = false;
1936       if (c_parser_next_token_is (parser, CPP_COLON))
1937         declarator = build_id_declarator (NULL_TREE);
1938       else
1939         declarator = c_parser_declarator (parser, specs->type_seen_p,
1940                                           C_DTR_NORMAL, &dummy);
1941       if (declarator == NULL)
1942         {
1943           c_parser_skip_to_end_of_block_or_statement (parser);
1944           break;
1945         }
1946       if (c_parser_next_token_is (parser, CPP_COLON)
1947           || c_parser_next_token_is (parser, CPP_COMMA)
1948           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1949           || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
1950           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1951         {
1952           tree postfix_attrs = NULL_TREE;
1953           tree width = NULL_TREE;
1954           tree d;
1955           if (c_parser_next_token_is (parser, CPP_COLON))
1956             {
1957               c_parser_consume_token (parser);
1958               width = c_parser_expr_no_commas (parser, NULL).value;
1959             }
1960           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1961             postfix_attrs = c_parser_attributes (parser);
1962           d = grokfield (declarator, specs, width);
1963           decl_attributes (&d, chainon (postfix_attrs,
1964                                         all_prefix_attrs), 0);
1965           TREE_CHAIN (d) = decls;
1966           decls = d;
1967           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1968             all_prefix_attrs = chainon (c_parser_attributes (parser),
1969                                         prefix_attrs);
1970           else
1971             all_prefix_attrs = prefix_attrs;
1972           if (c_parser_next_token_is (parser, CPP_COMMA))
1973             c_parser_consume_token (parser);
1974           else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
1975                    || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1976             {
1977               /* Semicolon consumed in caller.  */
1978               break;
1979             }
1980           else
1981             {
1982               c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
1983               break;
1984             }
1985         }
1986       else
1987         {
1988           c_parser_error (parser,
1989                           "expected %<:%>, %<,%>, %<;%>, %<}%> or "
1990                           "%<__attribute__%>");
1991           break;
1992         }
1993     }
1994   return decls;
1995 }
1996
1997 /* Parse a typeof specifier (a GNU extension).
1998
1999    typeof-specifier:
2000      typeof ( expression )
2001      typeof ( type-name )
2002 */
2003
2004 static struct c_typespec
2005 c_parser_typeof_specifier (c_parser *parser)
2006 {
2007   struct c_typespec ret;
2008   ret.kind = ctsk_typeof;
2009   ret.spec = error_mark_node;
2010   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2011   c_parser_consume_token (parser);
2012   skip_evaluation++;
2013   in_typeof++;
2014   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2015     {
2016       skip_evaluation--;
2017       in_typeof--;
2018       return ret;
2019     }
2020   if (c_parser_next_token_starts_typename (parser))
2021     {
2022       struct c_type_name *type = c_parser_type_name (parser);
2023       skip_evaluation--;
2024       in_typeof--;
2025       if (type != NULL)
2026         {
2027           ret.spec = groktypename (type);
2028           pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2029         }
2030     }
2031   else
2032     {
2033       struct c_expr expr = c_parser_expression (parser);
2034       skip_evaluation--;
2035       in_typeof--;
2036       if (TREE_CODE (expr.value) == COMPONENT_REF
2037           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2038         error ("%<typeof%> applied to a bit-field");
2039       ret.spec = TREE_TYPE (expr.value);
2040       pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2041     }
2042   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2043   return ret;
2044 }
2045
2046 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2047    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
2048    be redeclared; otherwise it may not.  KIND indicates which kind of
2049    declarator is wanted.  Returns a valid declarator except in the
2050    case of a syntax error in which case NULL is returned.  *SEEN_ID is
2051    set to true if an identifier being declared is seen; this is used
2052    to diagnose bad forms of abstract array declarators and to
2053    determine whether an identifier list is syntactically permitted.
2054
2055    declarator:
2056      pointer[opt] direct-declarator
2057
2058    direct-declarator:
2059      identifier
2060      ( attributes[opt] declarator )
2061      direct-declarator array-declarator
2062      direct-declarator ( parameter-type-list )
2063      direct-declarator ( identifier-list[opt] )
2064
2065    pointer:
2066      * type-qualifier-list[opt]
2067      * type-qualifier-list[opt] pointer
2068
2069    type-qualifier-list:
2070      type-qualifier
2071      attributes
2072      type-qualifier-list type-qualifier
2073      type-qualifier-list attributes
2074
2075    parameter-type-list:
2076      parameter-list
2077      parameter-list , ...
2078
2079    parameter-list:
2080      parameter-declaration
2081      parameter-list , parameter-declaration
2082
2083    parameter-declaration:
2084      declaration-specifiers declarator attributes[opt]
2085      declaration-specifiers abstract-declarator[opt] attributes[opt]
2086
2087    identifier-list:
2088      identifier
2089      identifier-list , identifier
2090
2091    abstract-declarator:
2092      pointer
2093      pointer[opt] direct-abstract-declarator
2094
2095    direct-abstract-declarator:
2096      ( attributes[opt] abstract-declarator )
2097      direct-abstract-declarator[opt] array-declarator
2098      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2099
2100    GNU extensions:
2101
2102    direct-declarator:
2103      direct-declarator ( parameter-forward-declarations
2104                          parameter-type-list[opt] )
2105
2106    direct-abstract-declarator:
2107      direct-abstract-declarator[opt] ( parameter-forward-declarations 
2108                                        parameter-type-list[opt] )
2109
2110    parameter-forward-declarations:
2111      parameter-list ;
2112      parameter-forward-declarations parameter-list ;
2113
2114    The uses of attributes shown above are GNU extensions.
2115
2116    Some forms of array declarator are not included in C99 in the
2117    syntax for abstract declarators; these are disallowed elsewhere.
2118    This may be a defect (DR#289).
2119
2120    This function also accepts an omitted abstract declarator as being
2121    an abstract declarator, although not part of the formal syntax.  */
2122
2123 static struct c_declarator *
2124 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2125                      bool *seen_id)
2126 {
2127   /* Parse any initial pointer part.  */
2128   if (c_parser_next_token_is (parser, CPP_MULT))
2129     {
2130       struct c_declspecs *quals_attrs = build_null_declspecs ();
2131       struct c_declarator *inner;
2132       c_parser_consume_token (parser);
2133       c_parser_declspecs (parser, quals_attrs, false, false, true);
2134       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2135       if (inner == NULL)
2136         return NULL;
2137       else
2138         return make_pointer_declarator (quals_attrs, inner);
2139     }
2140   /* Now we have a direct declarator, direct abstract declarator or
2141      nothing (which counts as a direct abstract declarator here).  */
2142   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2143 }
2144
2145 /* Parse a direct declarator or direct abstract declarator; arguments
2146    as c_parser_declarator.  */
2147
2148 static struct c_declarator *
2149 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2150                             bool *seen_id)
2151 {
2152   /* The direct declarator must start with an identifier (possibly
2153      omitted) or a parenthesized declarator (possibly abstract).  In
2154      an ordinary declarator, initial parentheses must start a
2155      parenthesized declarator.  In an abstract declarator or parameter
2156      declarator, they could start a parenthesized declarator or a
2157      parameter list.  To tell which, the open parenthesis and any
2158      following attributes must be read.  If a declaration specifier
2159      follows, then it is a parameter list; if the specifier is a
2160      typedef name, there might be an ambiguity about redeclaring it,
2161      which is resolved in the direction of treating it as a typedef
2162      name.  If a close parenthesis follows, it is also an empty
2163      parameter list, as the syntax does not permit empty abstract
2164      declarators.  Otherwise, it is a parenthesized declarator (in
2165      which case the analysis may be repeated inside it, recursively).
2166
2167      ??? There is an ambiguity in a parameter declaration "int
2168      (__attribute__((foo)) x)", where x is not a typedef name: it
2169      could be an abstract declarator for a function, or declare x with
2170      parentheses.  The proper resolution of this ambiguity needs
2171      documenting.  At present we follow an accident of the old
2172      parser's implementation, whereby the first parameter must have
2173      some declaration specifiers other than just attributes.  Thus as
2174      a parameter declaration it is treated as a parenthesized
2175      parameter named x, and as an abstract declarator it is
2176      rejected.
2177
2178      ??? Also following the old parser, attributes inside an empty
2179      parameter list are ignored, making it a list not yielding a
2180      prototype, rather than giving an error or making it have one
2181      parameter with implicit type int.
2182
2183      ??? Also following the old parser, typedef names may be
2184      redeclared in declarators, but not Objective-C class names.  */
2185
2186   if (kind != C_DTR_ABSTRACT
2187       && c_parser_next_token_is (parser, CPP_NAME)
2188       && ((type_seen_p
2189            && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2190           || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2191     {
2192       struct c_declarator *inner
2193         = build_id_declarator (c_parser_peek_token (parser)->value);
2194       *seen_id = true;
2195       inner->id_loc = c_parser_peek_token (parser)->location;
2196       c_parser_consume_token (parser);
2197       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2198     }
2199
2200   if (kind != C_DTR_NORMAL
2201       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2202     {
2203       struct c_declarator *inner = build_id_declarator (NULL_TREE);
2204       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2205     }
2206
2207   /* Either we are at the end of an abstract declarator, or we have
2208      parentheses.  */
2209
2210   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2211     {
2212       tree attrs;
2213       struct c_declarator *inner;
2214       c_parser_consume_token (parser);
2215       attrs = c_parser_attributes (parser);
2216       if (kind != C_DTR_NORMAL
2217           && (c_parser_next_token_starts_declspecs (parser)
2218               || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2219         {
2220           struct c_arg_info *args
2221             = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2222                                          attrs);
2223           if (args == NULL)
2224             return NULL;
2225           else
2226             {
2227               inner
2228                 = build_function_declarator (args,
2229                                              build_id_declarator (NULL_TREE));
2230               return c_parser_direct_declarator_inner (parser, *seen_id,
2231                                                        inner);
2232             }
2233         }
2234       /* A parenthesized declarator.  */
2235       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2236       if (inner != NULL && attrs != NULL)
2237         inner = build_attrs_declarator (attrs, inner);
2238       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2239         {
2240           c_parser_consume_token (parser);
2241           if (inner == NULL)
2242             return NULL;
2243           else
2244             return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2245         }
2246       else
2247         {
2248           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2249                                      "expected %<)%>");
2250           return NULL;
2251         }
2252     }
2253   else
2254     {
2255       if (kind == C_DTR_NORMAL)
2256         {
2257           c_parser_error (parser, "expected identifier or %<(%>");
2258           return NULL;
2259         }
2260       else
2261         return build_id_declarator (NULL_TREE);
2262     }
2263 }
2264
2265 /* Parse part of a direct declarator or direct abstract declarator,
2266    given that some (in INNER) has already been parsed; ID_PRESENT is
2267    true if an identifier is present, false for an abstract
2268    declarator.  */
2269
2270 static struct c_declarator *
2271 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2272                                   struct c_declarator *inner)
2273 {
2274   /* Parse a sequence of array declarators and parameter lists.  */
2275   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2276     {
2277       struct c_declarator *declarator;
2278       struct c_declspecs *quals_attrs = build_null_declspecs ();
2279       bool static_seen;
2280       bool star_seen;
2281       tree dimen;
2282       c_parser_consume_token (parser);
2283       c_parser_declspecs (parser, quals_attrs, false, false, true);
2284       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2285       if (static_seen)
2286         c_parser_consume_token (parser);
2287       if (static_seen && !quals_attrs->declspecs_seen_p)
2288         c_parser_declspecs (parser, quals_attrs, false, false, true);
2289       if (!quals_attrs->declspecs_seen_p)
2290         quals_attrs = NULL;
2291       /* If "static" is present, there must be an array dimension.
2292          Otherwise, there may be a dimension, "*", or no
2293          dimension.  */
2294       if (static_seen)
2295         {
2296           star_seen = false;
2297           dimen = c_parser_expr_no_commas (parser, NULL).value;
2298         }
2299       else
2300         {
2301           if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2302             {
2303               dimen = NULL_TREE;
2304               star_seen = false;
2305             }
2306           else if (c_parser_next_token_is (parser, CPP_MULT))
2307             {
2308               if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2309                 {
2310                   dimen = NULL_TREE;
2311                   star_seen = true;
2312                   c_parser_consume_token (parser);
2313                 }
2314               else
2315                 {
2316                   star_seen = false;
2317                   dimen = c_parser_expr_no_commas (parser, NULL).value;
2318                 }
2319             }
2320           else
2321             {
2322               star_seen = false;
2323               dimen = c_parser_expr_no_commas (parser, NULL).value;
2324             }
2325         }
2326       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2327         c_parser_consume_token (parser);
2328       else
2329         {
2330           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2331                                      "expected %<]%>");
2332           return NULL;
2333         }
2334       declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2335                                            star_seen);
2336       inner = set_array_declarator_inner (declarator, inner, !id_present);
2337       return c_parser_direct_declarator_inner (parser, id_present, inner);
2338     }
2339   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2340     {
2341       tree attrs;
2342       struct c_arg_info *args;
2343       c_parser_consume_token (parser);
2344       attrs = c_parser_attributes (parser);
2345       args = c_parser_parms_declarator (parser, id_present, attrs);
2346       if (args == NULL)
2347         return NULL;
2348       else
2349         {
2350           inner = build_function_declarator (args, inner);
2351           return c_parser_direct_declarator_inner (parser, id_present, inner);
2352         }
2353     }
2354   return inner;
2355 }
2356
2357 /* Parse a parameter list or identifier list, including the closing
2358    parenthesis but not the opening one.  ATTRS are the attributes at
2359    the start of the list.  ID_LIST_OK is true if an identifier list is
2360    acceptable; such a list must not have attributes at the start.  */
2361
2362 static struct c_arg_info *
2363 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2364 {
2365   push_scope ();
2366   declare_parm_level ();
2367   /* If the list starts with an identifier, it is an identifier list.
2368      Otherwise, it is either a prototype list or an empty list.  */
2369   if (id_list_ok
2370       && !attrs
2371       && c_parser_next_token_is (parser, CPP_NAME)
2372       && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2373     {
2374       tree list = NULL_TREE, *nextp = &list;
2375       while (c_parser_next_token_is (parser, CPP_NAME)
2376              && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2377         {
2378           *nextp = build_tree_list (NULL_TREE,
2379                                     c_parser_peek_token (parser)->value);
2380           nextp = & TREE_CHAIN (*nextp);
2381           c_parser_consume_token (parser);
2382           if (c_parser_next_token_is_not (parser, CPP_COMMA))
2383             break;
2384           c_parser_consume_token (parser);
2385           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2386             {
2387               c_parser_error (parser, "expected identifier");
2388               break;
2389             }
2390         }
2391       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2392         {
2393           struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2394           ret->parms = 0;
2395           ret->tags = 0;
2396           ret->types = list;
2397           ret->others = 0;
2398           c_parser_consume_token (parser);
2399           pop_scope ();
2400           return ret;
2401         }
2402       else
2403         {
2404           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2405                                      "expected %<)%>");
2406           pop_scope ();
2407           return NULL;
2408         }
2409     }
2410   else
2411     {
2412       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2413       pop_scope ();
2414       return ret;
2415     }
2416 }
2417
2418 /* Parse a parameter list (possibly empty), including the closing
2419    parenthesis but not the opening one.  ATTRS are the attributes at
2420    the start of the list.  */
2421
2422 static struct c_arg_info *
2423 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2424 {
2425   bool good_parm = false;
2426   /* ??? Following the old parser, forward parameter declarations may
2427      use abstract declarators, and if no real parameter declarations
2428      follow the forward declarations then this is not diagnosed.  Also
2429      note as above that attributes are ignored as the only contents of
2430      the parentheses, or as the only contents after forward
2431      declarations.  */
2432   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2433     {
2434       struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2435       ret->parms = 0;
2436       ret->tags = 0;
2437       ret->types = 0;
2438       ret->others = 0;
2439       c_parser_consume_token (parser);
2440       return ret;
2441     }
2442   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2443     {
2444       struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2445       ret->parms = 0;
2446       ret->tags = 0;
2447       ret->others = 0;
2448       /* Suppress -Wold-style-definition for this case.  */
2449       ret->types = error_mark_node;
2450       error ("ISO C requires a named argument before %<...%>");
2451       c_parser_consume_token (parser);
2452       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2453         {
2454           c_parser_consume_token (parser);
2455           return ret;
2456         }
2457       else
2458         {
2459           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2460                                      "expected %<)%>");
2461           return NULL;
2462         }
2463     }
2464   /* Nonempty list of parameters, either terminated with semicolon
2465      (forward declarations; recurse) or with close parenthesis (normal
2466      function) or with ", ... )" (variadic function).  */
2467   while (true)
2468     {
2469       /* Parse a parameter.  */
2470       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2471       attrs = NULL_TREE;
2472       if (parm != NULL)
2473         {
2474           good_parm = true;
2475           push_parm_decl (parm);
2476         }
2477       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2478         {
2479           tree new_attrs;
2480           c_parser_consume_token (parser);
2481           mark_forward_parm_decls ();
2482           new_attrs = c_parser_attributes (parser);
2483           return c_parser_parms_list_declarator (parser, new_attrs);
2484         }
2485       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2486         {
2487           c_parser_consume_token (parser);
2488           if (good_parm)
2489             return get_parm_info (false);
2490           else
2491             {
2492               struct c_arg_info *ret
2493                 = XOBNEW (&parser_obstack, struct c_arg_info);
2494               ret->parms = 0;
2495               ret->tags = 0;
2496               ret->types = 0;
2497               ret->others = 0;
2498               return ret;
2499             }
2500         }
2501       if (!c_parser_require (parser, CPP_COMMA,
2502                              "expected %<;%>, %<,%> or %<)%>"))
2503         {
2504           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2505           return NULL;
2506         }
2507       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2508         {
2509           c_parser_consume_token (parser);
2510           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2511             {
2512               c_parser_consume_token (parser);
2513               if (good_parm)
2514                 return get_parm_info (true);
2515               else
2516                 {
2517                   struct c_arg_info *ret
2518                     = XOBNEW (&parser_obstack, struct c_arg_info);
2519                   ret->parms = 0;
2520                   ret->tags = 0;
2521                   ret->types = 0;
2522                   ret->others = 0;
2523                   return ret;
2524                 }
2525             }
2526           else
2527             {
2528               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2529                                          "expected %<)%>");
2530               return NULL;
2531             }
2532         }
2533     }
2534 }
2535
2536 /* Parse a parameter declaration.  ATTRS are the attributes at the
2537    start of the declaration if it is the first parameter.  */
2538
2539 static struct c_parm *
2540 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2541 {
2542   struct c_declspecs *specs;
2543   struct c_declarator *declarator;
2544   tree prefix_attrs;
2545   tree postfix_attrs = NULL_TREE;
2546   bool dummy = false;
2547   if (!c_parser_next_token_starts_declspecs (parser))
2548     {
2549       /* ??? In some Objective-C cases '...' isn't applicable so there
2550          should be a different message.  */
2551       c_parser_error (parser,
2552                       "expected declaration specifiers or %<...%>");
2553       c_parser_skip_to_end_of_parameter (parser);
2554       return NULL;
2555     }
2556   specs = build_null_declspecs ();
2557   if (attrs)
2558     {
2559       declspecs_add_attrs (specs, attrs);
2560       attrs = NULL_TREE;
2561     }
2562   c_parser_declspecs (parser, specs, true, true, true);
2563   finish_declspecs (specs);
2564   pending_xref_error ();
2565   prefix_attrs = specs->attrs;
2566   specs->attrs = NULL_TREE;
2567   declarator = c_parser_declarator (parser, specs->type_seen_p,
2568                                     C_DTR_PARM, &dummy);
2569   if (declarator == NULL)
2570     {
2571       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2572       return NULL;
2573     }
2574   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2575     postfix_attrs = c_parser_attributes (parser);
2576   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2577                        declarator);
2578 }
2579
2580 /* Parse a string literal in an asm expression.  It should not be
2581    translated, and wide string literals are an error although
2582    permitted by the syntax.  This is a GNU extension.
2583
2584    asm-string-literal:
2585      string-literal
2586
2587    ??? At present, following the old parser, the caller needs to have
2588    set c_lex_string_translate to 0.  It would be better to follow the
2589    C++ parser rather than using the c_lex_string_translate kludge.  */
2590
2591 static tree
2592 c_parser_asm_string_literal (c_parser *parser)
2593 {
2594   tree str;
2595   if (c_parser_next_token_is (parser, CPP_STRING))
2596     {
2597       str = c_parser_peek_token (parser)->value;
2598       c_parser_consume_token (parser);
2599     }
2600   else if (c_parser_next_token_is (parser, CPP_WSTRING))
2601     {
2602       error ("wide string literal in %<asm%>");
2603       str = build_string (1, "");
2604       c_parser_consume_token (parser);
2605     }
2606   else
2607     {
2608       c_parser_error (parser, "expected string literal");
2609       str = NULL_TREE;
2610     }
2611   return str;
2612 }
2613
2614 /* Parse a simple asm expression.  This is used in restricted
2615    contexts, where a full expression with inputs and outputs does not
2616    make sense.  This is a GNU extension.
2617
2618    simple-asm-expr:
2619      asm ( asm-string-literal )
2620 */
2621
2622 static tree
2623 c_parser_simple_asm_expr (c_parser *parser)
2624 {
2625   tree str;
2626   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2627   /* ??? Follow the C++ parser rather than using the
2628      c_lex_string_translate kludge.  */
2629   c_lex_string_translate = 0;
2630   c_parser_consume_token (parser);
2631   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2632     {
2633       c_lex_string_translate = 1;
2634       return NULL_TREE;
2635     }
2636   str = c_parser_asm_string_literal (parser);
2637   c_lex_string_translate = 1;
2638   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2639     {
2640       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2641       return NULL_TREE;
2642     }
2643   return str;
2644 }
2645
2646 /* Parse (possibly empty) attributes.  This is a GNU extension.
2647
2648    attributes:
2649      empty
2650      attributes attribute
2651
2652    attribute:
2653      __attribute__ ( ( attribute-list ) )
2654
2655    attribute-list:
2656      attrib
2657      attribute_list , attrib
2658
2659    attrib:
2660      empty
2661      any-word
2662      any-word ( identifier )
2663      any-word ( identifier , nonempty-expr-list )
2664      any-word ( expr-list )
2665
2666    where the "identifier" must not be declared as a type, and
2667    "any-word" may be any identifier (including one declared as a
2668    type), a reserved word storage class specifier, type specifier or
2669    type qualifier.  ??? This still leaves out most reserved keywords
2670    (following the old parser), shouldn't we include them, and why not
2671    allow identifiers declared as types to start the arguments?  */
2672
2673 static tree
2674 c_parser_attributes (c_parser *parser)
2675 {
2676   tree attrs = NULL_TREE;
2677   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2678     {
2679       /* ??? Follow the C++ parser rather than using the
2680          c_lex_string_translate kludge.  */
2681       c_lex_string_translate = 0;
2682       c_parser_consume_token (parser);
2683       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2684         {
2685           c_lex_string_translate = 1;
2686           return attrs;
2687         }
2688       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2689         {
2690           c_lex_string_translate = 1;
2691           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2692           return attrs;
2693         }
2694       /* Parse the attribute list.  */
2695       while (c_parser_next_token_is (parser, CPP_COMMA)
2696              || c_parser_next_token_is (parser, CPP_NAME)
2697              || c_parser_next_token_is (parser, CPP_KEYWORD))
2698         {
2699           tree attr, attr_name, attr_args;
2700           if (c_parser_next_token_is (parser, CPP_COMMA))
2701             {
2702               c_parser_consume_token (parser);
2703               continue;
2704             }
2705           if (c_parser_next_token_is (parser, CPP_KEYWORD))
2706             {
2707               /* ??? See comment above about what keywords are
2708                  accepted here.  */
2709               bool ok;
2710               switch (c_parser_peek_token (parser)->keyword)
2711                 {
2712                 case RID_STATIC:
2713                 case RID_UNSIGNED:
2714                 case RID_LONG:
2715                 case RID_CONST:
2716                 case RID_EXTERN:
2717                 case RID_REGISTER:
2718                 case RID_TYPEDEF:
2719                 case RID_SHORT:
2720                 case RID_INLINE:
2721                 case RID_VOLATILE:
2722                 case RID_SIGNED:
2723                 case RID_AUTO:
2724                 case RID_RESTRICT:
2725                 case RID_COMPLEX:
2726                 case RID_THREAD:
2727                 case RID_INT:
2728                 case RID_CHAR:
2729                 case RID_FLOAT:
2730                 case RID_DOUBLE:
2731                 case RID_VOID:
2732                 case RID_DFLOAT32:
2733                 case RID_DFLOAT64:
2734                 case RID_DFLOAT128:
2735                 case RID_BOOL:
2736                   ok = true;
2737                   break;
2738                 default:
2739                   ok = false;
2740                   break;
2741                 }
2742               if (!ok)
2743                 break;
2744             }
2745           attr_name = c_parser_peek_token (parser)->value;
2746           c_parser_consume_token (parser);
2747           if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2748             {
2749               attr = build_tree_list (attr_name, NULL_TREE);
2750               attrs = chainon (attrs, attr);
2751               continue;
2752             }
2753           c_parser_consume_token (parser);
2754           /* Parse the attribute contents.  If they start with an
2755              identifier which is followed by a comma or close
2756              parenthesis, then the arguments start with that
2757              identifier; otherwise they are an expression list.  */
2758           if (c_parser_next_token_is (parser, CPP_NAME)
2759               && c_parser_peek_token (parser)->id_kind == C_ID_ID
2760               && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2761                   || (c_parser_peek_2nd_token (parser)->type
2762                       == CPP_CLOSE_PAREN)))
2763             {
2764               tree arg1 = c_parser_peek_token (parser)->value;
2765               c_parser_consume_token (parser);
2766               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2767                 attr_args = build_tree_list (NULL_TREE, arg1);
2768               else
2769                 {
2770                   c_parser_consume_token (parser);
2771                   attr_args = tree_cons (NULL_TREE, arg1,
2772                                          c_parser_expr_list (parser, false));
2773                 }
2774             }
2775           else
2776             {
2777               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2778                 attr_args = NULL_TREE;
2779               else
2780                 attr_args = c_parser_expr_list (parser, false);
2781             }
2782           attr = build_tree_list (attr_name, attr_args);
2783           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2784             c_parser_consume_token (parser);
2785           else
2786             {
2787               c_lex_string_translate = 1;
2788               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2789                                          "expected %<)%>");
2790               return attrs;
2791             }
2792           attrs = chainon (attrs, attr);
2793         }
2794       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2795         c_parser_consume_token (parser);
2796       else
2797         {
2798           c_lex_string_translate = 1;
2799           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2800                                      "expected %<)%>");
2801           return attrs;
2802         }
2803       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2804         c_parser_consume_token (parser);
2805       else
2806         {
2807           c_lex_string_translate = 1;
2808           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2809                                      "expected %<)%>");
2810           return attrs;
2811         }
2812       c_lex_string_translate = 1;
2813     }
2814   return attrs;
2815 }
2816
2817 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2818
2819    type-name:
2820      specifier-qualifier-list abstract-declarator[opt]
2821 */
2822
2823 static struct c_type_name *
2824 c_parser_type_name (c_parser *parser)
2825 {
2826   struct c_declspecs *specs = build_null_declspecs ();
2827   struct c_declarator *declarator;
2828   struct c_type_name *ret;
2829   bool dummy = false;
2830   c_parser_declspecs (parser, specs, false, true, true);
2831   if (!specs->declspecs_seen_p)
2832     {
2833       c_parser_error (parser, "expected specifier-qualifier-list");
2834       return NULL;
2835     }
2836   pending_xref_error ();
2837   finish_declspecs (specs);
2838   declarator = c_parser_declarator (parser, specs->type_seen_p,
2839                                     C_DTR_ABSTRACT, &dummy);
2840   if (declarator == NULL)
2841     return NULL;
2842   ret = XOBNEW (&parser_obstack, struct c_type_name);
2843   ret->specs = specs;
2844   ret->declarator = declarator;
2845   return ret;
2846 }
2847
2848 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2849
2850    initializer:
2851      assignment-expression
2852      { initializer-list }
2853      { initializer-list , }
2854
2855    initializer-list:
2856      designation[opt] initializer
2857      initializer-list , designation[opt] initializer
2858
2859    designation:
2860      designator-list =
2861
2862    designator-list:
2863      designator
2864      designator-list designator
2865
2866    designator:
2867      array-designator
2868      . identifier
2869
2870    array-designator:
2871      [ constant-expression ]
2872
2873    GNU extensions:
2874
2875    initializer:
2876      { }
2877
2878    designation:
2879      array-designator
2880      identifier :
2881
2882    array-designator:
2883      [ constant-expression ... constant-expression ]
2884
2885    Any expression without commas is accepted in the syntax for the
2886    constant-expressions, with non-constant expressions rejected later.
2887
2888    This function is only used for top-level initializers; for nested
2889    ones, see c_parser_initval.  */
2890
2891 static struct c_expr
2892 c_parser_initializer (c_parser *parser)
2893 {
2894   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2895     return c_parser_braced_init (parser, NULL_TREE, false);
2896   else
2897     {
2898       struct c_expr ret;
2899       ret = c_parser_expr_no_commas (parser, NULL);
2900       if (TREE_CODE (ret.value) != STRING_CST
2901           && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
2902         ret = default_function_array_conversion (ret);
2903       return ret;
2904     }
2905 }
2906
2907 /* Parse a braced initializer list.  TYPE is the type specified for a
2908    compound literal, and NULL_TREE for other initializers and for
2909    nested braced lists.  NESTED_P is true for nested braced lists,
2910    false for the list of a compound literal or the list that is the
2911    top-level initializer in a declaration.  */
2912
2913 static struct c_expr
2914 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
2915 {
2916   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
2917   c_parser_consume_token (parser);
2918   if (nested_p)
2919     push_init_level (0);
2920   else
2921     really_start_incremental_init (type);
2922   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2923     {
2924       if (pedantic)
2925         pedwarn ("ISO C forbids empty initializer braces");
2926     }
2927   else
2928     {
2929       /* Parse a non-empty initializer list, possibly with a trailing
2930          comma.  */
2931       while (true)
2932         {
2933           c_parser_initelt (parser);
2934           if (parser->error)
2935             break;
2936           if (c_parser_next_token_is (parser, CPP_COMMA))
2937             c_parser_consume_token (parser);
2938           else
2939             break;
2940           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2941             break;
2942         }
2943     }
2944   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
2945     {
2946       struct c_expr ret;
2947       ret.value = error_mark_node;
2948       ret.original_code = ERROR_MARK;
2949       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
2950       return ret;
2951     }
2952   c_parser_consume_token (parser);
2953   return pop_init_level (0);
2954 }
2955
2956 /* Parse a nested initializer, including designators.  */
2957
2958 static void
2959 c_parser_initelt (c_parser *parser)
2960 {
2961   /* Parse any designator or designator list.  A single array
2962      designator may have the subsequent "=" omitted in GNU C, but a
2963      longer list or a structure member designator may not.  */
2964   if (c_parser_next_token_is (parser, CPP_NAME)
2965       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
2966     {
2967       /* Old-style structure member designator.  */
2968       set_init_label (c_parser_peek_token (parser)->value);
2969       if (pedantic)
2970         pedwarn ("obsolete use of designated initializer with %<:%>");
2971       c_parser_consume_token (parser);
2972       c_parser_consume_token (parser);
2973     }
2974   else
2975     {
2976       /* des_seen is 0 if there have been no designators, 1 if there
2977          has been a single array designator and 2 otherwise.  */
2978       int des_seen = 0;
2979       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
2980              || c_parser_next_token_is (parser, CPP_DOT))
2981         {
2982           int des_prev = des_seen;
2983           if (des_seen < 2)
2984             des_seen++;
2985           if (c_parser_next_token_is (parser, CPP_DOT))
2986             {
2987               des_seen = 2;
2988               c_parser_consume_token (parser);
2989               if (c_parser_next_token_is (parser, CPP_NAME))
2990                 {
2991                   set_init_label (c_parser_peek_token (parser)->value);
2992                   c_parser_consume_token (parser);
2993                 }
2994               else
2995                 {
2996                   struct c_expr init;
2997                   init.value = error_mark_node;
2998                   init.original_code = ERROR_MARK;
2999                   c_parser_error (parser, "expected identifier");
3000                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3001                   process_init_element (init);
3002                   return;
3003                 }
3004             }
3005           else
3006             {
3007               tree first, second;
3008               /* ??? Following the old parser, [ objc-receiver
3009                  objc-message-args ] is accepted as an initializer,
3010                  being distinguished from a designator by what follows
3011                  the first assignment expression inside the square
3012                  brackets, but after a first array designator a
3013                  subsequent square bracket is for Objective-C taken to
3014                  start an expression, using the obsolete form of
3015                  designated initializer without '=', rather than
3016                  possibly being a second level of designation: in LALR
3017                  terms, the '[' is shifted rather than reducing
3018                  designator to designator-list.  */
3019               if (des_prev == 1 && c_dialect_objc ())
3020                 {
3021                   des_seen = des_prev;
3022                   break;
3023                 }
3024               if (des_prev == 0 && c_dialect_objc ())
3025                 {
3026                   /* This might be an array designator or an
3027                      Objective-C message expression.  If the former,
3028                      continue parsing here; if the latter, parse the
3029                      remainder of the initializer given the starting
3030                      primary-expression.  ??? It might make sense to
3031                      distinguish when des_prev == 1 as well; see
3032                      previous comment.  */
3033                   tree rec, args;
3034                   struct c_expr mexpr;
3035                   c_parser_consume_token (parser);
3036                   if (c_parser_peek_token (parser)->type == CPP_NAME
3037                       && ((c_parser_peek_token (parser)->id_kind
3038                            == C_ID_TYPENAME)
3039                           || (c_parser_peek_token (parser)->id_kind
3040                               == C_ID_CLASSNAME)))
3041                     {
3042                       /* Type name receiver.  */
3043                       tree id = c_parser_peek_token (parser)->value;
3044                       c_parser_consume_token (parser);
3045                       rec = objc_get_class_reference (id);
3046                       goto parse_message_args;
3047                     }
3048                   first = c_parser_expr_no_commas (parser, NULL).value;
3049                   if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3050                       || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3051                     goto array_desig_after_first;
3052                   /* Expression receiver.  So far only one part
3053                      without commas has been parsed; there might be
3054                      more of the expression.  */
3055                   rec = first;
3056                   while (c_parser_next_token_is (parser, CPP_COMMA))
3057                     {
3058                       struct c_expr next;
3059                       c_parser_consume_token (parser);
3060                       next = c_parser_expr_no_commas (parser, NULL);
3061                       next = default_function_array_conversion (next);
3062                       rec = build_compound_expr (rec, next.value);
3063                     }
3064                 parse_message_args:
3065                   /* Now parse the objc-message-args.  */
3066                   args = c_parser_objc_message_args (parser);
3067                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3068                                              "expected %<]%>");
3069                   mexpr.value
3070                     = objc_build_message_expr (build_tree_list (rec, args));
3071                   mexpr.original_code = ERROR_MARK;
3072                   /* Now parse and process the remainder of the
3073                      initializer, starting with this message
3074                      expression as a primary-expression.  */
3075                   c_parser_initval (parser, &mexpr);
3076                   return;
3077                 }
3078               c_parser_consume_token (parser);
3079               first = c_parser_expr_no_commas (parser, NULL).value;
3080             array_desig_after_first:
3081               if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3082                 {
3083                   c_parser_consume_token (parser);
3084                   second = c_parser_expr_no_commas (parser, NULL).value;
3085                 }
3086               else
3087                 second = NULL_TREE;
3088               if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3089                 {
3090                   c_parser_consume_token (parser);
3091                   set_init_index (first, second);
3092                   if (pedantic && second)
3093                     pedwarn ("ISO C forbids specifying range of "
3094                              "elements to initialize");
3095                 }
3096               else
3097                 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3098                                            "expected %<]%>");
3099             }
3100         }
3101       if (des_seen >= 1)
3102         {
3103           if (c_parser_next_token_is (parser, CPP_EQ))
3104             {
3105               if (pedantic && !flag_isoc99)
3106                 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3107               c_parser_consume_token (parser);
3108             }
3109           else
3110             {
3111               if (des_seen == 1)
3112                 {
3113                   if (pedantic)
3114                     pedwarn ("obsolete use of designated initializer "
3115                              "without %<=%>");
3116                 }
3117               else
3118                 {
3119                   struct c_expr init;
3120                   init.value = error_mark_node;
3121                   init.original_code = ERROR_MARK;
3122                   c_parser_error (parser, "expected %<=%>");
3123                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3124                   process_init_element (init);
3125                   return;
3126                 }
3127             }
3128         }
3129     }
3130   c_parser_initval (parser, NULL);
3131 }
3132
3133 /* Parse a nested initializer; as c_parser_initializer but parses
3134    initializers within braced lists, after any designators have been
3135    applied.  If AFTER is not NULL then it is an Objective-C message
3136    expression which is the primary-expression starting the
3137    initializer.  */
3138
3139 static void
3140 c_parser_initval (c_parser *parser, struct c_expr *after)
3141 {
3142   struct c_expr init;
3143   gcc_assert (!after || c_dialect_objc ());
3144   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3145     init = c_parser_braced_init (parser, NULL_TREE, true);
3146   else
3147     {
3148       init = c_parser_expr_no_commas (parser, after);
3149       if (init.value != NULL_TREE
3150           && TREE_CODE (init.value) != STRING_CST
3151           && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3152         init = default_function_array_conversion (init);
3153     }
3154   process_init_element (init);
3155 }
3156
3157 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3158    C99 6.8.2).
3159
3160    compound-statement:
3161      { block-item-list[opt] }
3162      { label-declarations block-item-list }
3163
3164    block-item-list:
3165      block-item
3166      block-item-list block-item
3167
3168    block-item:
3169      nested-declaration
3170      statement
3171
3172    nested-declaration:
3173      declaration
3174
3175    GNU extensions:
3176
3177    compound-statement:
3178      { label-declarations block-item-list }
3179
3180    nested-declaration:
3181      __extension__ nested-declaration
3182      nested-function-definition
3183
3184    label-declarations:
3185      label-declaration
3186      label-declarations label-declaration
3187
3188    label-declaration:
3189      __label__ identifier-list ;
3190
3191    Allowing the mixing of declarations and code is new in C99.  The
3192    GNU syntax also permits (not shown above) labels at the end of
3193    compound statements, which yield an error.  We don't allow labels
3194    on declarations; this might seem like a natural extension, but
3195    there would be a conflict between attributes on the label and
3196    prefix attributes on the declaration.  ??? The syntax follows the
3197    old parser in requiring something after label declarations.
3198    Although they are erroneous if the labels declared aren't defined,
3199    is it useful for the syntax to be this way?  */
3200
3201 static tree
3202 c_parser_compound_statement (c_parser *parser)
3203 {
3204   tree stmt;
3205   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3206     return error_mark_node;
3207   stmt = c_begin_compound_stmt (true);
3208   c_parser_compound_statement_nostart (parser);
3209   return c_end_compound_stmt (stmt, true);
3210 }
3211
3212 /* Parse a compound statement except for the opening brace.  This is
3213    used for parsing both compound statements and statement expressions
3214    (which follow different paths to handling the opening).  */
3215
3216 static void
3217 c_parser_compound_statement_nostart (c_parser *parser)
3218 {
3219   bool last_stmt = false;
3220   bool last_label = false;
3221   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3222     {
3223       c_parser_consume_token (parser);
3224       return;
3225     }
3226   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3227     {
3228       /* Read zero or more forward-declarations for labels that nested
3229          functions can jump to.  */
3230       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3231         {
3232           c_parser_consume_token (parser);
3233           /* Any identifiers, including those declared as type names,
3234              are OK here.  */
3235           while (true)
3236             {
3237               tree label;
3238               if (c_parser_next_token_is_not (parser, CPP_NAME))
3239                 {
3240                   c_parser_error (parser, "expected identifier");
3241                   break;
3242                 }
3243               label
3244                 = declare_label (c_parser_peek_token (parser)->value);
3245               C_DECLARED_LABEL_FLAG (label) = 1;
3246               add_stmt (build_stmt (DECL_EXPR, label));
3247               c_parser_consume_token (parser);
3248               if (c_parser_next_token_is (parser, CPP_COMMA))
3249                 c_parser_consume_token (parser);
3250               else
3251                 break;
3252             }
3253           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3254         }
3255       /* ??? Locating this diagnostic on the token after the
3256          declarations end follows the old parser, but it might be
3257          better to locate it where the declarations start instead.  */
3258       if (pedantic)
3259         pedwarn ("ISO C forbids label declarations");
3260     }
3261   /* We must now have at least one statement, label or declaration.  */
3262   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3263     {
3264       c_parser_error (parser, "expected declaration or statement");
3265       c_parser_consume_token (parser);
3266       return;
3267     }
3268   while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3269     {
3270       location_t loc = c_parser_peek_token (parser)->location;
3271       if (c_parser_next_token_is (parser, CPP_EOF))
3272         {
3273           c_parser_error (parser, "expected declaration or statement");
3274           return;
3275         }
3276       if (c_parser_next_token_is_keyword (parser, RID_CASE)
3277           || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3278           || (c_parser_next_token_is (parser, CPP_NAME)
3279               && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3280         {
3281           last_label = true;
3282           last_stmt = false;
3283           c_parser_label (parser);
3284         }
3285       else if (!last_label
3286                && c_parser_next_token_starts_declspecs (parser))
3287         {
3288           last_label = false;
3289           c_parser_declaration_or_fndef (parser, true, true, true, true);
3290           if (last_stmt
3291               && ((pedantic && !flag_isoc99)
3292                   || warn_declaration_after_statement))
3293             pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3294                          &loc);
3295           last_stmt = false;
3296         }
3297       else if (!last_label
3298                && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3299         {
3300           /* __extension__ can start a declaration, but is also an
3301              unary operator that can start an expression.  Consume all
3302              but the last of a possible series of __extension__ to
3303              determine which.  */
3304           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3305                  && (c_parser_peek_2nd_token (parser)->keyword
3306                      == RID_EXTENSION))
3307             c_parser_consume_token (parser);
3308           if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3309             {
3310               int ext;
3311               ext = disable_extension_diagnostics ();
3312               c_parser_consume_token (parser);
3313               last_label = false;
3314               c_parser_declaration_or_fndef (parser, true, true, true, true);
3315               /* Following the old parser, __extension__ does not
3316                  disable this diagnostic.  */
3317               restore_extension_diagnostics (ext);
3318               if (last_stmt
3319                   && ((pedantic && !flag_isoc99)
3320                       || warn_declaration_after_statement))
3321                 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3322                              &loc);
3323               last_stmt = false;
3324             }
3325           else
3326             goto statement;
3327         }
3328       else
3329         {
3330         statement:
3331           last_label = false;
3332           last_stmt = true;
3333           c_parser_statement_after_labels (parser);
3334         }
3335     }
3336   if (last_label)
3337     error ("label at end of compound statement");
3338   c_parser_consume_token (parser);
3339 }
3340
3341 /* Parse a label (C90 6.6.1, C99 6.8.1).
3342
3343    label:
3344      identifier : attributes[opt]
3345      case constant-expression :
3346      default :
3347
3348    GNU extensions:
3349
3350    label:
3351      case constant-expression ... constant-expression :
3352
3353    The use of attributes on labels is a GNU extension.  The syntax in
3354    GNU C accepts any expressions without commas, non-constant
3355    expressions being rejected later.  */
3356
3357 static void
3358 c_parser_label (c_parser *parser)
3359 {
3360   location_t loc1 = c_parser_peek_token (parser)->location;
3361   tree label = NULL_TREE;
3362   if (c_parser_next_token_is_keyword (parser, RID_CASE))
3363     {
3364       tree exp1, exp2;
3365       c_parser_consume_token (parser);
3366       exp1 = c_parser_expr_no_commas (parser, NULL).value;
3367       if (c_parser_next_token_is (parser, CPP_COLON))
3368         {
3369           c_parser_consume_token (parser);
3370           label = do_case (exp1, NULL_TREE);
3371         }
3372       else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3373         {
3374           c_parser_consume_token (parser);
3375           exp2 = c_parser_expr_no_commas (parser, NULL).value;
3376           if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3377             label = do_case (exp1, exp2);
3378         }
3379       else
3380         c_parser_error (parser, "expected %<:%> or %<...%>");
3381     }
3382   else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3383     {
3384       c_parser_consume_token (parser);
3385       if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3386         label = do_case (NULL_TREE, NULL_TREE);
3387     }
3388   else
3389     {
3390       tree name = c_parser_peek_token (parser)->value;
3391       tree tlab;
3392       location_t loc2;
3393       tree attrs;
3394       gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3395       c_parser_consume_token (parser);
3396       gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3397       loc2 = c_parser_peek_token (parser)->location;
3398       c_parser_consume_token (parser);
3399       attrs = c_parser_attributes (parser);
3400       tlab = define_label (loc2, name);
3401       if (tlab)
3402         {
3403           decl_attributes (&tlab, attrs, 0);
3404           label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3405         }
3406     }
3407   if (label)
3408     SET_EXPR_LOCATION (label, loc1);
3409 }
3410
3411 /* Parse a statement (C90 6.6, C99 6.8).
3412
3413    statement:
3414      labeled-statement
3415      compound-statement
3416      expression-statement
3417      selection-statement
3418      iteration-statement
3419      jump-statement
3420
3421    labeled-statement:
3422      label statement
3423
3424    expression-statement:
3425      expression[opt] ;
3426
3427    selection-statement:
3428      if-statement
3429      switch-statement
3430
3431    iteration-statement:
3432      while-statement
3433      do-statement
3434      for-statement
3435
3436    jump-statement:
3437      goto identifier ;
3438      continue ;
3439      break ;
3440      return expression[opt] ;
3441
3442    GNU extensions:
3443
3444    statement:
3445      asm-statement
3446
3447    jump-statement:
3448      goto * expression ;
3449
3450    Objective-C:
3451
3452    statement:
3453      objc-throw-statement
3454      objc-try-catch-statement
3455      objc-synchronized-statement
3456
3457    objc-throw-statement:
3458      @throw expression ;
3459      @throw ;
3460 */
3461
3462 static void
3463 c_parser_statement (c_parser *parser)
3464 {
3465   while (c_parser_next_token_is_keyword (parser, RID_CASE)
3466          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3467          || (c_parser_next_token_is (parser, CPP_NAME)
3468              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3469     c_parser_label (parser);
3470   c_parser_statement_after_labels (parser);
3471 }
3472
3473 /* Parse a statement, other than a labeled statement.  */
3474
3475 static void
3476 c_parser_statement_after_labels (c_parser *parser)
3477 {
3478   location_t loc = c_parser_peek_token (parser)->location;
3479   tree stmt = NULL_TREE;
3480   switch (c_parser_peek_token (parser)->type)
3481     {
3482     case CPP_OPEN_BRACE:
3483       add_stmt (c_parser_compound_statement (parser));
3484       break;
3485     case CPP_KEYWORD:
3486       switch (c_parser_peek_token (parser)->keyword)
3487         {
3488         case RID_IF:
3489           c_parser_if_statement (parser);
3490           break;
3491         case RID_SWITCH:
3492           c_parser_switch_statement (parser);
3493           break;
3494         case RID_WHILE:
3495           c_parser_while_statement (parser);
3496           break;
3497         case RID_DO:
3498           c_parser_do_statement (parser);
3499           break;
3500         case RID_FOR:
3501           c_parser_for_statement (parser);
3502           break;
3503         case RID_GOTO:
3504           c_parser_consume_token (parser);
3505           if (c_parser_next_token_is (parser, CPP_NAME))
3506             {
3507               stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3508               c_parser_consume_token (parser);
3509             }
3510           else if (c_parser_next_token_is (parser, CPP_MULT))
3511             {
3512               c_parser_consume_token (parser);
3513               stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3514             }
3515           else
3516             c_parser_error (parser, "expected identifier or %<*%>");
3517           goto expect_semicolon;
3518         case RID_CONTINUE:
3519           c_parser_consume_token (parser);
3520           stmt = c_finish_bc_stmt (&c_cont_label, false);
3521           goto expect_semicolon;
3522         case RID_BREAK:
3523           c_parser_consume_token (parser);
3524           stmt = c_finish_bc_stmt (&c_break_label, true);
3525           goto expect_semicolon;
3526         case RID_RETURN:
3527           c_parser_consume_token (parser);
3528           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3529             {
3530               stmt = c_finish_return (NULL_TREE);
3531               c_parser_consume_token (parser);
3532             }
3533           else
3534             {
3535               stmt = c_finish_return (c_parser_expression_conv (parser).value);
3536               goto expect_semicolon;
3537             }
3538           break;
3539         case RID_ASM:
3540           stmt = c_parser_asm_statement (parser);
3541           break;
3542         case RID_AT_THROW:
3543           gcc_assert (c_dialect_objc ());
3544           c_parser_consume_token (parser);
3545           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3546             {
3547               stmt = objc_build_throw_stmt (NULL_TREE);
3548               c_parser_consume_token (parser);
3549             }
3550           else
3551             {
3552               stmt
3553                 = objc_build_throw_stmt (c_parser_expression (parser).value);
3554               goto expect_semicolon;
3555             }
3556           break;
3557         case RID_AT_TRY:
3558           gcc_assert (c_dialect_objc ());
3559           c_parser_objc_try_catch_statement (parser);
3560           break;
3561         case RID_AT_SYNCHRONIZED:
3562           gcc_assert (c_dialect_objc ());
3563           c_parser_objc_synchronized_statement (parser);
3564           break;
3565         default:
3566           goto expr_stmt;
3567         }
3568       break;
3569     case CPP_SEMICOLON:
3570       c_parser_consume_token (parser);
3571       break;
3572     case CPP_CLOSE_PAREN:
3573     case CPP_CLOSE_SQUARE:
3574       /* Avoid infinite loop in error recovery:
3575          c_parser_skip_until_found stops at a closing nesting
3576          delimiter without consuming it, but here we need to consume
3577          it to proceed further.  */
3578       c_parser_error (parser, "expected statement");
3579       c_parser_consume_token (parser);
3580       break;
3581     default:
3582     expr_stmt:
3583       stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3584     expect_semicolon:
3585       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3586       break;
3587     }
3588   /* Two cases cannot and do not have line numbers associated: If stmt
3589      is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3590      cannot hold line numbers.  But that's OK because the statement
3591      will either be changed to a MODIFY_EXPR during gimplification of
3592      the statement expr, or discarded.  If stmt was compound, but
3593      without new variables, we will have skipped the creation of a
3594      BIND and will have a bare STATEMENT_LIST.  But that's OK because
3595      (recursively) all of the component statements should already have
3596      line numbers assigned.  ??? Can we discard no-op statements
3597      earlier?  */
3598   if (stmt && EXPR_P (stmt))
3599     SET_EXPR_LOCATION (stmt, loc);
3600 }
3601
3602 /* Parse a parenthesized condition from an if, do or while statement.
3603
3604    condition:
3605      ( expression )
3606 */
3607 static tree
3608 c_parser_paren_condition (c_parser *parser)
3609 {
3610   location_t loc;
3611   tree cond;
3612   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3613     return error_mark_node;
3614   loc = c_parser_peek_token (parser)->location;
3615   cond = c_objc_common_truthvalue_conversion
3616     (c_parser_expression_conv (parser).value);
3617   if (EXPR_P (cond))
3618     SET_EXPR_LOCATION (cond, loc);
3619   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3620   return cond;
3621 }
3622
3623 /* Parse a statement which is a block in C99.  */
3624
3625 static tree
3626 c_parser_c99_block_statement (c_parser *parser)
3627 {
3628   tree block = c_begin_compound_stmt (flag_isoc99);
3629   c_parser_statement (parser);
3630   return c_end_compound_stmt (block, flag_isoc99);
3631 }
3632
3633 /* Parse the body of an if statement or the else half thereof.  This
3634    is just parsing a statement but (a) it is a block in C99, (b) we
3635    track whether the body is an if statement for the sake of
3636    -Wparentheses warnings, (c) we handle an empty body specially for
3637    the sake of -Wextra warnings.  */
3638
3639 static tree
3640 c_parser_if_body (c_parser *parser, bool *if_p)
3641 {
3642   tree block = c_begin_compound_stmt (flag_isoc99);
3643   while (c_parser_next_token_is_keyword (parser, RID_CASE)
3644          || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3645          || (c_parser_next_token_is (parser, CPP_NAME)
3646              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3647     c_parser_label (parser);
3648   *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3649   if (extra_warnings && c_parser_next_token_is (parser, CPP_SEMICOLON))
3650     add_stmt (build1 (NOP_EXPR, NULL_TREE, NULL_TREE));
3651   c_parser_statement_after_labels (parser);
3652   return c_end_compound_stmt (block, flag_isoc99);
3653 }
3654
3655 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3656
3657    if-statement:
3658      if ( expression ) statement
3659      if ( expression ) statement else statement
3660 */
3661
3662 static void
3663 c_parser_if_statement (c_parser *parser)
3664 {
3665   tree block;
3666   location_t loc;
3667   tree cond;
3668   bool first_if = false, second_if = false;
3669   tree first_body, second_body;
3670   gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3671   c_parser_consume_token (parser);
3672   block = c_begin_compound_stmt (flag_isoc99);
3673   loc = c_parser_peek_token (parser)->location;
3674   cond = c_parser_paren_condition (parser);
3675   first_body = c_parser_if_body (parser, &first_if);
3676   if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3677     {
3678       c_parser_consume_token (parser);
3679       second_body = c_parser_if_body (parser, &second_if);
3680     }
3681   else
3682     second_body = NULL_TREE;
3683   c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3684   add_stmt (c_end_compound_stmt (block, flag_isoc99));
3685 }
3686
3687 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3688
3689    switch-statement:
3690      switch (expression) statement
3691 */
3692
3693 static void
3694 c_parser_switch_statement (c_parser *parser)
3695 {
3696   tree block, expr, body, save_break;
3697   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3698   c_parser_consume_token (parser);
3699   block = c_begin_compound_stmt (flag_isoc99);
3700   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3701     {
3702       expr = c_parser_expression (parser).value;
3703       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3704     }
3705   else
3706     expr = error_mark_node;
3707   c_start_case (expr);
3708   save_break = c_break_label;
3709   c_break_label = NULL_TREE;
3710   body = c_parser_c99_block_statement (parser);
3711   c_finish_case (body);
3712   if (c_break_label)
3713     add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3714   c_break_label = save_break;
3715   add_stmt (c_end_compound_stmt (block, flag_isoc99));
3716 }
3717
3718 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3719
3720    while-statement:
3721       while (expression) statement
3722 */
3723
3724 static void
3725 c_parser_while_statement (c_parser *parser)
3726 {
3727   tree block, cond, body, save_break, save_cont;
3728   location_t loc;
3729   gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3730   c_parser_consume_token (parser);
3731   block = c_begin_compound_stmt (flag_isoc99);
3732   loc = c_parser_peek_token (parser)->location;
3733   cond = c_parser_paren_condition (parser);
3734   save_break = c_break_label;
3735   c_break_label = NULL_TREE;
3736   save_cont = c_cont_label;
3737   c_cont_label = NULL_TREE;
3738   body = c_parser_c99_block_statement (parser);
3739   c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3740   add_stmt (c_end_compound_stmt (block, flag_isoc99));
3741   c_break_label = save_break;
3742   c_cont_label = save_cont;
3743 }
3744
3745 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3746
3747    do-statement:
3748      do statement while ( expression ) ;
3749 */
3750
3751 static void
3752 c_parser_do_statement (c_parser *parser)
3753 {
3754   tree block, cond, body, save_break, save_cont, new_break, new_cont;
3755   location_t loc;
3756   gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3757   c_parser_consume_token (parser);
3758   block = c_begin_compound_stmt (flag_isoc99);
3759   loc = c_parser_peek_token (parser)->location;
3760   save_break = c_break_label;
3761   c_break_label = NULL_TREE;
3762   save_cont = c_cont_label;
3763   c_cont_label = NULL_TREE;
3764   body = c_parser_c99_block_statement (parser);
3765   c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
3766   new_break = c_break_label;
3767   c_break_label = save_break;
3768   new_cont = c_cont_label;
3769   c_cont_label = save_cont;
3770   cond = c_parser_paren_condition (parser);
3771   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3772     c_parser_skip_to_end_of_block_or_statement (parser);
3773   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
3774   add_stmt (c_end_compound_stmt (block, flag_isoc99));
3775 }
3776
3777 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3778
3779    for-statement:
3780      for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3781      for ( nested-declaration expression[opt] ; expression[opt] ) statement
3782
3783    The form with a declaration is new in C99.
3784
3785    ??? In accordance with the old parser, the declaration may be a
3786    nested function, which is then rejected in check_for_loop_decls,
3787    but does it make any sense for this to be included in the grammar?
3788    Note in particular that the nested function does not include a
3789    trailing ';', whereas the "declaration" production includes one.
3790    Also, can we reject bad declarations earlier and cheaper than
3791    check_for_loop_decls?  */
3792
3793 static void
3794 c_parser_for_statement (c_parser *parser)
3795 {
3796   tree block, cond, incr, save_break, save_cont, body;
3797   location_t loc;
3798   gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
3799   loc = c_parser_peek_token (parser)->location;
3800   c_parser_consume_token (parser);
3801   block = c_begin_compound_stmt (flag_isoc99);
3802   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3803     {
3804       /* Parse the initialization declaration or expression.  */
3805       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3806         {
3807           c_parser_consume_token (parser);
3808           c_finish_expr_stmt (NULL_TREE);
3809         }
3810       else if (c_parser_next_token_starts_declspecs (parser))
3811         {
3812           c_parser_declaration_or_fndef (parser, true, true, true, true);
3813           check_for_loop_decls ();
3814         }
3815       else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3816         {
3817           /* __extension__ can start a declaration, but is also an
3818              unary operator that can start an expression.  Consume all
3819              but the last of a possible series of __extension__ to
3820              determine which.  */
3821           while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3822                  && (c_parser_peek_2nd_token (parser)->keyword
3823                      == RID_EXTENSION))
3824             c_parser_consume_token (parser);
3825           if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3826             {
3827               int ext;
3828               ext = disable_extension_diagnostics ();
3829               c_parser_consume_token (parser);
3830               c_parser_declaration_or_fndef (parser, true, true, true, true);
3831               restore_extension_diagnostics (ext);
3832               check_for_loop_decls ();
3833             }
3834           else
3835             goto init_expr;
3836         }
3837       else
3838         {
3839         init_expr:
3840           c_finish_expr_stmt (c_parser_expression (parser).value);
3841           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3842         }
3843       /* Parse the loop condition.  */
3844       loc = c_parser_peek_token (parser)->location;
3845       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3846         {
3847           c_parser_consume_token (parser);
3848           cond = NULL_TREE;
3849         }
3850       else
3851         {
3852           tree ocond = c_parser_expression_conv (parser).value;
3853           cond = c_objc_common_truthvalue_conversion (ocond);
3854           if (EXPR_P (cond))
3855             SET_EXPR_LOCATION (cond, loc);
3856           c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3857         }
3858       /* Parse the increment expression.  */
3859       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3860         incr = c_process_expr_stmt (NULL_TREE);
3861       else
3862         incr = c_process_expr_stmt (c_parser_expression (parser).value);
3863       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3864     }
3865   else
3866     {
3867       cond = error_mark_node;
3868       incr = error_mark_node;
3869     }
3870   save_break = c_break_label;
3871   c_break_label = NULL_TREE;
3872   save_cont = c_cont_label;
3873   c_cont_label = NULL_TREE;
3874   body = c_parser_c99_block_statement (parser);
3875   c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
3876   add_stmt (c_end_compound_stmt (block, flag_isoc99));
3877   c_break_label = save_break;
3878   c_cont_label = save_cont;
3879 }
3880
3881 /* Parse an asm statement, a GNU extension.  This is a full-blown asm
3882    statement with inputs, outputs, clobbers, and volatile tag
3883    allowed.
3884
3885    asm-statement:
3886      asm type-qualifier[opt] ( asm-argument ) ;
3887
3888    asm-argument:
3889      asm-string-literal
3890      asm-string-literal : asm-operands[opt]
3891      asm-string-literal : asm-operands[opt] : asm-operands[opt]
3892      asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
3893
3894    Qualifiers other than volatile are accepted in the syntax but
3895    warned for.  */
3896
3897 static tree
3898 c_parser_asm_statement (c_parser *parser)
3899 {
3900   tree quals, str, outputs, inputs, clobbers, ret;
3901   bool simple;
3902   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3903   c_parser_consume_token (parser);
3904   if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
3905     {
3906       quals = c_parser_peek_token (parser)->value;
3907       c_parser_consume_token (parser);
3908     }
3909   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
3910            || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
3911     {
3912       warning (0, "%E qualifier ignored on asm",
3913                c_parser_peek_token (parser)->value);
3914       quals = NULL_TREE;
3915       c_parser_consume_token (parser);
3916     }
3917   else
3918     quals = NULL_TREE;
3919   /* ??? Follow the C++ parser rather than using the
3920      c_lex_string_translate kludge.  */
3921   c_lex_string_translate = 0;
3922   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3923     {
3924       c_lex_string_translate = 1;
3925       return NULL_TREE;
3926     }
3927   str = c_parser_asm_string_literal (parser);
3928   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3929     {
3930       simple = true;
3931       outputs = NULL_TREE;
3932       inputs = NULL_TREE;
3933       clobbers = NULL_TREE;
3934       goto done_asm;
3935     }
3936   if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
3937     {
3938       c_lex_string_translate = 1;
3939       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3940       return NULL_TREE;
3941     }
3942   simple = false;
3943   /* Parse outputs.  */
3944   if (c_parser_next_token_is (parser, CPP_COLON)
3945       || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3946     outputs = NULL_TREE;
3947   else
3948     outputs = c_parser_asm_operands (parser, false);
3949   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3950     {
3951       inputs = NULL_TREE;
3952       clobbers = NULL_TREE;
3953       goto done_asm;
3954     }
3955   if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
3956     {
3957       c_lex_string_translate = 1;
3958       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3959       return NULL_TREE;
3960     }
3961   /* Parse inputs.  */
3962   if (c_parser_next_token_is (parser, CPP_COLON)
3963       || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3964     inputs = NULL_TREE;
3965   else
3966     inputs = c_parser_asm_operands (parser, true);
3967   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3968     {
3969       clobbers = NULL_TREE;
3970       goto done_asm;
3971     }
3972   if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
3973     {
3974       c_lex_string_translate = 1;
3975       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3976       return NULL_TREE;
3977     }
3978   /* Parse clobbers.  */
3979   clobbers = c_parser_asm_clobbers (parser);
3980  done_asm:
3981   c_lex_string_translate = 1;
3982   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3983     {
3984       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3985       return NULL_TREE;
3986     }
3987   if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3988     c_parser_skip_to_end_of_block_or_statement (parser);
3989   ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
3990                                                clobbers, simple));
3991   return ret;
3992 }
3993
3994 /* Parse asm operands, a GNU extension.  If CONVERT_P (for inputs but
3995    not outputs), apply the default conversion of functions and arrays
3996    to pointers.
3997
3998    asm-operands:
3999      asm-operand
4000      asm-operands , asm-operand
4001
4002    asm-operand:
4003      asm-string-literal ( expression )
4004      [ identifier ] asm-string-literal ( expression )
4005 */
4006
4007 static tree
4008 c_parser_asm_operands (c_parser *parser, bool convert_p)
4009 {
4010   tree list = NULL_TREE;
4011   while (true)
4012     {
4013       tree name, str;
4014       struct c_expr expr;
4015       if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4016         {
4017           c_parser_consume_token (parser);
4018           if (c_parser_next_token_is (parser, CPP_NAME))
4019             {
4020               tree id = c_parser_peek_token (parser)->value;
4021               c_parser_consume_token (parser);
4022               name = build_string (IDENTIFIER_LENGTH (id),
4023                                    IDENTIFIER_POINTER (id));
4024             }
4025           else
4026             {
4027               c_parser_error (parser, "expected identifier");
4028               c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4029               return NULL_TREE;
4030             }
4031           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4032                                      "expected %<]%>");
4033         }
4034       else
4035         name = NULL_TREE;
4036       str = c_parser_asm_string_literal (parser);
4037       if (str == NULL_TREE)
4038         return NULL_TREE;
4039       c_lex_string_translate = 1;
4040       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4041         {
4042           c_lex_string_translate = 0;
4043           return NULL_TREE;
4044         }
4045       expr = c_parser_expression (parser);
4046       if (convert_p)
4047         expr = default_function_array_conversion (expr);
4048       c_lex_string_translate = 0;
4049       if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4050         {
4051           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4052           return NULL_TREE;
4053         }
4054       list = chainon (list, build_tree_list (build_tree_list (name, str),
4055                                              expr.value));
4056       if (c_parser_next_token_is (parser, CPP_COMMA))
4057         c_parser_consume_token (parser);
4058       else
4059         break;
4060     }
4061   return list;
4062 }
4063
4064 /* Parse asm clobbers, a GNU extension.
4065
4066    asm-clobbers:
4067      asm-string-literal
4068      asm-clobbers , asm-string-literal
4069 */
4070
4071 static tree
4072 c_parser_asm_clobbers (c_parser *parser)
4073 {
4074   tree list = NULL_TREE;
4075   while (true)
4076     {
4077       tree str = c_parser_asm_string_literal (parser);
4078       if (str)
4079         list = tree_cons (NULL_TREE, str, list);
4080       else
4081         return NULL_TREE;
4082       if (c_parser_next_token_is (parser, CPP_COMMA))
4083         c_parser_consume_token (parser);
4084       else
4085         break;
4086     }
4087   return list;
4088 }
4089
4090 /* Parse an expression other than a compound expression; that is, an
4091    assignment expression (C90 6.3.16, C99 6.5.16).  If AFTER is not
4092    NULL then it is an Objective-C message expression which is the
4093    primary-expression starting the expression as an initializer.
4094
4095    assignment-expression:
4096      conditional-expression
4097      unary-expression assignment-operator assignment-expression
4098
4099    assignment-operator: one of
4100      = *= /= %= += -= <<= >>= &= ^= |=
4101
4102    In GNU C we accept any conditional expression on the LHS and
4103    diagnose the invalid lvalue rather than producing a syntax
4104    error.  */
4105
4106 static struct c_expr
4107 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4108 {
4109   struct c_expr lhs, rhs, ret;
4110   enum tree_code code;
4111   gcc_assert (!after || c_dialect_objc ());
4112   lhs = c_parser_conditional_expression (parser, after);
4113   switch (c_parser_peek_token (parser)->type)
4114     {
4115     case CPP_EQ:
4116       code = NOP_EXPR;
4117       break;
4118     case CPP_MULT_EQ:
4119       code = MULT_EXPR;
4120       break;
4121     case CPP_DIV_EQ:
4122       code = TRUNC_DIV_EXPR;
4123       break;
4124     case CPP_MOD_EQ:
4125       code = TRUNC_MOD_EXPR;
4126       break;
4127     case CPP_PLUS_EQ:
4128       code = PLUS_EXPR;
4129       break;
4130     case CPP_MINUS_EQ:
4131       code = MINUS_EXPR;
4132       break;
4133     case CPP_LSHIFT_EQ:
4134       code = LSHIFT_EXPR;
4135       break;
4136     case CPP_RSHIFT_EQ:
4137       code = RSHIFT_EXPR;
4138       break;
4139     case CPP_AND_EQ:
4140       code = BIT_AND_EXPR;
4141       break;
4142     case CPP_XOR_EQ:
4143       code = BIT_XOR_EXPR;
4144       break;
4145     case CPP_OR_EQ:
4146       code = BIT_IOR_EXPR;
4147       break;
4148     default:
4149       return lhs;
4150     }
4151   c_parser_consume_token (parser);
4152   rhs = c_parser_expr_no_commas (parser, NULL);
4153   rhs = default_function_array_conversion (rhs);
4154   ret.value = build_modify_expr (lhs.value, code, rhs.value);
4155   if (code == NOP_EXPR)
4156     ret.original_code = MODIFY_EXPR;
4157   else
4158     {
4159       TREE_NO_WARNING (ret.value) = 1;
4160       ret.original_code = ERROR_MARK;
4161     }
4162   return ret;
4163 }
4164
4165 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15).  If AFTER
4166    is not NULL then it is an Objective-C message expression which is
4167    the primary-expression starting the expression as an initializer.
4168
4169    conditional-expression:
4170      logical-OR-expression
4171      logical-OR-expression ? expression : conditional-expression
4172
4173    GNU extensions:
4174
4175    conditional-expression:
4176      logical-OR-expression ? : conditional-expression
4177 */
4178
4179 static struct c_expr
4180 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4181 {
4182   struct c_expr cond, exp1, exp2, ret;
4183   gcc_assert (!after || c_dialect_objc ());
4184   cond = c_parser_binary_expression (parser, after);
4185   if (c_parser_next_token_is_not (parser, CPP_QUERY))
4186     return cond;
4187   cond = default_function_array_conversion (cond);
4188   c_parser_consume_token (parser);
4189   if (c_parser_next_token_is (parser, CPP_COLON))
4190     {
4191       if (pedantic)
4192         pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4193       /* Make sure first operand is calculated only once.  */
4194       exp1.value = save_expr (default_conversion (cond.value));
4195       cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4196       skip_evaluation += cond.value == truthvalue_true_node;
4197     }
4198   else
4199     {
4200       cond.value
4201         = c_objc_common_truthvalue_conversion
4202         (default_conversion (cond.value));
4203       skip_evaluation += cond.value == truthvalue_false_node;
4204       exp1 = c_parser_expression_conv (parser);
4205       skip_evaluation += ((cond.value == truthvalue_true_node)
4206                           - (cond.value == truthvalue_false_node));
4207     }
4208   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4209     {
4210       skip_evaluation -= cond.value == truthvalue_true_node;
4211       ret.value = error_mark_node;
4212       ret.original_code = ERROR_MARK;
4213       return ret;
4214     }
4215   exp2 = c_parser_conditional_expression (parser, NULL);
4216   exp2 = default_function_array_conversion (exp2);
4217   skip_evaluation -= cond.value == truthvalue_true_node;
4218   ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4219   ret.original_code = ERROR_MARK;
4220   return ret;
4221 }
4222
4223 /* Parse a binary expression; that is, a logical-OR-expression (C90
4224    6.3.5-6.3.14, C99 6.5.5-6.5.14).  If AFTER is not NULL then it is
4225    an Objective-C message expression which is the primary-expression
4226    starting the expression as an initializer.
4227
4228    multiplicative-expression:
4229      cast-expression
4230      multiplicative-expression * cast-expression
4231      multiplicative-expression / cast-expression
4232      multiplicative-expression % cast-expression
4233
4234    additive-expression:
4235      multiplicative-expression
4236      additive-expression + multiplicative-expression
4237      additive-expression - multiplicative-expression
4238
4239    shift-expression:
4240      additive-expression
4241      shift-expression << additive-expression
4242      shift-expression >> additive-expression
4243
4244    relational-expression:
4245      shift-expression
4246      relational-expression < shift-expression
4247      relational-expression > shift-expression
4248      relational-expression <= shift-expression
4249      relational-expression >= shift-expression
4250
4251    equality-expression:
4252      relational-expression
4253      equality-expression == relational-expression
4254      equality-expression != relational-expression
4255
4256    AND-expression:
4257      equality-expression
4258      AND-expression & equality-expression
4259
4260    exclusive-OR-expression:
4261      AND-expression
4262      exclusive-OR-expression ^ AND-expression
4263
4264    inclusive-OR-expression:
4265      exclusive-OR-expression
4266      inclusive-OR-expression | exclusive-OR-expression
4267
4268    logical-AND-expression:
4269      inclusive-OR-expression
4270      logical-AND-expression && inclusive-OR-expression
4271
4272    logical-OR-expression:
4273      logical-AND-expression
4274      logical-OR-expression || logical-AND-expression
4275 */
4276
4277 static struct c_expr
4278 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4279 {
4280   /* A binary expression is parsed using operator-precedence parsing,
4281      with the operands being cast expressions.  All the binary
4282      operators are left-associative.  Thus a binary expression is of
4283      form:
4284
4285      E0 op1 E1 op2 E2 ...
4286
4287      which we represent on a stack.  On the stack, the precedence
4288      levels are strictly increasing.  When a new operator is
4289      encountered of higher precedence than that at the top of the
4290      stack, it is pushed; its LHS is the top expression, and its RHS
4291      is everything parsed until it is popped.  When a new operator is
4292      encountered with precedence less than or equal to that at the top
4293      of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4294      by the result of the operation until the operator at the top of
4295      the stack has lower precedence than the new operator or there is
4296      only one element on the stack; then the top expression is the LHS
4297      of the new operator.  In the case of logical AND and OR
4298      expressions, we also need to adjust skip_evaluation as
4299      appropriate when the operators are pushed and popped.  */
4300
4301   /* The precedence levels, where 0 is a dummy lowest level used for
4302      the bottom of the stack.  */
4303   enum prec {
4304     PREC_NONE,
4305     PREC_LOGOR,
4306     PREC_LOGAND,
4307     PREC_BITOR,
4308     PREC_BITXOR,
4309     PREC_BITAND,
4310     PREC_EQ,
4311     PREC_REL,
4312     PREC_SHIFT,
4313     PREC_ADD,
4314     PREC_MULT,
4315     NUM_PRECS
4316   };
4317   struct {
4318     /* The expression at this stack level.  */
4319     struct c_expr expr;
4320     /* The precedence of the operator on its left, PREC_NONE at the
4321        bottom of the stack.  */
4322     enum prec prec;
4323     /* The operation on its left.  */
4324     enum tree_code op;
4325   } stack[NUM_PRECS];
4326   int sp;
4327 #define POP                                                                   \
4328   do {                                                                        \
4329     switch (stack[sp].op)                                                     \
4330       {                                                                       \
4331       case TRUTH_ANDIF_EXPR:                                                  \
4332         skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4333         break;                                                                \
4334       case TRUTH_ORIF_EXPR:                                                   \
4335         skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node;  \
4336         break;                                                                \
4337       default:                                                                \
4338         break;                                                                \
4339       }                                                                       \
4340     stack[sp - 1].expr                                                        \
4341       = default_function_array_conversion (stack[sp - 1].expr);               \
4342     stack[sp].expr                                                            \
4343       = default_function_array_conversion (stack[sp].expr);                   \
4344     stack[sp - 1].expr = parser_build_binary_op (stack[sp].op,                \
4345                                                  stack[sp - 1].expr,          \
4346                                                  stack[sp].expr);             \
4347     sp--;                                                                     \
4348   } while (0)
4349   gcc_assert (!after || c_dialect_objc ());
4350   stack[0].expr = c_parser_cast_expression (parser, after);
4351   stack[0].prec = PREC_NONE;
4352   sp = 0;
4353   while (true)
4354     {
4355       enum prec oprec;
4356       enum tree_code ocode;
4357       if (parser->error)
4358         goto out;
4359       switch (c_parser_peek_token (parser)->type)
4360         {
4361         case CPP_MULT:
4362           oprec = PREC_MULT;
4363           ocode = MULT_EXPR;
4364           break;
4365         case CPP_DIV:
4366           oprec = PREC_MULT;
4367           ocode = TRUNC_DIV_EXPR;
4368           break;
4369         case CPP_MOD:
4370           oprec = PREC_MULT;
4371           ocode = TRUNC_MOD_EXPR;
4372           break;
4373         case CPP_PLUS:
4374           oprec = PREC_ADD;
4375           ocode = PLUS_EXPR;
4376           break;
4377         case CPP_MINUS:
4378           oprec = PREC_ADD;
4379           ocode = MINUS_EXPR;
4380           break;
4381         case CPP_LSHIFT:
4382           oprec = PREC_SHIFT;
4383           ocode = LSHIFT_EXPR;
4384           break;
4385         case CPP_RSHIFT:
4386           oprec = PREC_SHIFT;
4387           ocode = RSHIFT_EXPR;
4388           break;
4389         case CPP_LESS:
4390           oprec = PREC_REL;
4391           ocode = LT_EXPR;
4392           break;
4393         case CPP_GREATER:
4394           oprec = PREC_REL;
4395           ocode = GT_EXPR;
4396           break;
4397         case CPP_LESS_EQ:
4398           oprec = PREC_REL;
4399           ocode = LE_EXPR;
4400           break;
4401         case CPP_GREATER_EQ:
4402           oprec = PREC_REL;
4403           ocode = GE_EXPR;
4404           break;
4405         case CPP_EQ_EQ:
4406           oprec = PREC_EQ;
4407           ocode = EQ_EXPR;
4408           break;
4409         case CPP_NOT_EQ:
4410           oprec = PREC_EQ;
4411           ocode = NE_EXPR;
4412           break;
4413         case CPP_AND:
4414           oprec = PREC_BITAND;
4415           ocode = BIT_AND_EXPR;
4416           break;
4417         case CPP_XOR:
4418           oprec = PREC_BITXOR;
4419           ocode = BIT_XOR_EXPR;
4420           break;
4421         case CPP_OR:
4422           oprec = PREC_BITOR;
4423           ocode = BIT_IOR_EXPR;
4424           break;
4425         case CPP_AND_AND:
4426           oprec = PREC_LOGAND;
4427           ocode = TRUTH_ANDIF_EXPR;
4428           break;
4429         case CPP_OR_OR:
4430           oprec = PREC_LOGOR;
4431           ocode = TRUTH_ORIF_EXPR;
4432           break;
4433         default:
4434           /* Not a binary operator, so end of the binary
4435              expression.  */
4436           goto out;
4437         }
4438       c_parser_consume_token (parser);
4439       while (oprec <= stack[sp].prec)
4440         POP;
4441       switch (ocode)
4442         {
4443         case TRUTH_ANDIF_EXPR:
4444           stack[sp].expr
4445             = default_function_array_conversion (stack[sp].expr);
4446           stack[sp].expr.value = c_objc_common_truthvalue_conversion
4447             (default_conversion (stack[sp].expr.value));
4448           skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4449           break;
4450         case TRUTH_ORIF_EXPR:
4451           stack[sp].expr
4452             = default_function_array_conversion (stack[sp].expr);
4453           stack[sp].expr.value = c_objc_common_truthvalue_conversion
4454             (default_conversion (stack[sp].expr.value));
4455           skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4456           break;
4457         default:
4458           break;
4459         }
4460       sp++;
4461       stack[sp].expr = c_parser_cast_expression (parser, NULL);
4462       stack[sp].prec = oprec;
4463       stack[sp].op = ocode;
4464     }
4465  out:
4466   while (sp > 0)
4467     POP;
4468   return stack[0].expr;
4469 #undef POP
4470 }
4471
4472 /* Parse a cast expression (C90 6.3.4, C99 6.5.4).  If AFTER is not
4473    NULL then it is an Objective-C message expression which is the
4474    primary-expression starting the expression as an initializer.
4475
4476    cast-expression:
4477      unary-expression
4478      ( type-name ) unary-expression
4479 */
4480
4481 static struct c_expr
4482 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4483 {
4484   gcc_assert (!after || c_dialect_objc ());
4485   if (after)
4486     return c_parser_postfix_expression_after_primary (parser, *after);
4487   /* If the expression begins with a parenthesized type name, it may
4488      be either a cast or a compound literal; we need to see whether
4489      the next character is '{' to tell the difference.  If not, it is
4490      an unary expression.  */
4491   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4492       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4493     {
4494       struct c_type_name *type_name;
4495       struct c_expr ret;
4496       struct c_expr expr;
4497       c_parser_consume_token (parser);
4498       type_name = c_parser_type_name (parser);
4499       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4500       if (type_name == NULL)
4501         {
4502           ret.value = error_mark_node;
4503           ret.original_code = ERROR_MARK;
4504           return ret;
4505         }
4506       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4507         return c_parser_postfix_expression_after_paren_type (parser,
4508                                                              type_name);
4509       expr = c_parser_cast_expression (parser, NULL);
4510       expr = default_function_array_conversion (expr);
4511       ret.value = c_cast_expr (type_name, expr.value);
4512       ret.original_code = ERROR_MARK;
4513       return ret;
4514     }
4515   else
4516     return c_parser_unary_expression (parser);
4517 }
4518
4519 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4520
4521    unary-expression:
4522      postfix-expression
4523      ++ unary-expression
4524      -- unary-expression
4525      unary-operator cast-expression
4526      sizeof unary-expression
4527      sizeof ( type-name )
4528
4529    unary-operator: one of
4530      & * + - ~ !
4531
4532    GNU extensions:
4533
4534    unary-expression:
4535      __alignof__ unary-expression
4536      __alignof__ ( type-name )
4537      && identifier
4538
4539    unary-operator: one of
4540      __extension__ __real__ __imag__
4541
4542    In addition, the GNU syntax treats ++ and -- as unary operators, so
4543    they may be applied to cast expressions with errors for non-lvalues
4544    given later.  */
4545
4546 static struct c_expr
4547 c_parser_unary_expression (c_parser *parser)
4548 {
4549   int ext;
4550   struct c_expr ret, op;
4551   switch (c_parser_peek_token (parser)->type)
4552     {
4553     case CPP_PLUS_PLUS:
4554       c_parser_consume_token (parser);
4555       op = c_parser_cast_expression (parser, NULL);
4556       op = default_function_array_conversion (op);
4557       return parser_build_unary_op (PREINCREMENT_EXPR, op);
4558     case CPP_MINUS_MINUS:
4559       c_parser_consume_token (parser);
4560       op = c_parser_cast_expression (parser, NULL);
4561       op = default_function_array_conversion (op);
4562       return parser_build_unary_op (PREDECREMENT_EXPR, op);
4563     case CPP_AND:
4564       c_parser_consume_token (parser);
4565       return parser_build_unary_op (ADDR_EXPR,
4566                                     c_parser_cast_expression (parser, NULL));
4567     case CPP_MULT:
4568       c_parser_consume_token (parser);
4569       op = c_parser_cast_expression (parser, NULL);
4570       op = default_function_array_conversion (op);
4571       ret.value = build_indirect_ref (op.value, "unary *");
4572       ret.original_code = ERROR_MARK;
4573       return ret;
4574     case CPP_PLUS:
4575       c_parser_consume_token (parser);
4576       if (!c_dialect_objc () && !in_system_header)
4577         warning (OPT_Wtraditional,
4578                  "traditional C rejects the unary plus operator");
4579       op = c_parser_cast_expression (parser, NULL);
4580       op = default_function_array_conversion (op);
4581       return parser_build_unary_op (CONVERT_EXPR, op);
4582     case CPP_MINUS:
4583       c_parser_consume_token (parser);
4584       op = c_parser_cast_expression (parser, NULL);
4585       op = default_function_array_conversion (op);
4586       return parser_build_unary_op (NEGATE_EXPR, op);
4587     case CPP_COMPL:
4588       c_parser_consume_token (parser);
4589       op = c_parser_cast_expression (parser, NULL);
4590       op = default_function_array_conversion (op);
4591       return parser_build_unary_op (BIT_NOT_EXPR, op);
4592     case CPP_NOT:
4593       c_parser_consume_token (parser);
4594       op = c_parser_cast_expression (parser, NULL);
4595       op = default_function_array_conversion (op);
4596       return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4597     case CPP_AND_AND:
4598       /* Refer to the address of a label as a pointer.  */
4599       c_parser_consume_token (parser);
4600       if (c_parser_next_token_is (parser, CPP_NAME))
4601         {
4602           ret.value = finish_label_address_expr
4603             (c_parser_peek_token (parser)->value);
4604           c_parser_consume_token (parser);
4605         }
4606       else
4607         {
4608           c_parser_error (parser, "expected identifier");
4609           ret.value = error_mark_node;
4610         }
4611         ret.original_code = ERROR_MARK;
4612         return ret;
4613     case CPP_KEYWORD:
4614       switch (c_parser_peek_token (parser)->keyword)
4615         {
4616         case RID_SIZEOF:
4617           return c_parser_sizeof_expression (parser);
4618         case RID_ALIGNOF:
4619           return c_parser_alignof_expression (parser);
4620         case RID_EXTENSION:
4621           c_parser_consume_token (parser);
4622           ext = disable_extension_diagnostics ();
4623           ret = c_parser_cast_expression (parser, NULL);
4624           restore_extension_diagnostics (ext);
4625           return ret;
4626         case RID_REALPART:
4627           c_parser_consume_token (parser);
4628           op = c_parser_cast_expression (parser, NULL);
4629           op = default_function_array_conversion (op);
4630           return parser_build_unary_op (REALPART_EXPR, op);
4631         case RID_IMAGPART:
4632           c_parser_consume_token (parser);
4633           op = c_parser_cast_expression (parser, NULL);
4634           op = default_function_array_conversion (op);
4635           return parser_build_unary_op (IMAGPART_EXPR, op);
4636         default:
4637           return c_parser_postfix_expression (parser);
4638         }
4639     default:
4640       return c_parser_postfix_expression (parser);
4641     }
4642 }
4643
4644 /* Parse a sizeof expression.  */
4645
4646 static struct c_expr
4647 c_parser_sizeof_expression (c_parser *parser)
4648 {
4649   struct c_expr expr;
4650   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4651   c_parser_consume_token (parser);
4652   skip_evaluation++;
4653   in_sizeof++;
4654   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4655       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4656     {
4657       /* Either sizeof ( type-name ) or sizeof unary-expression
4658          starting with a compound literal.  */
4659       struct c_type_name *type_name;
4660       c_parser_consume_token (parser);
4661       type_name = c_parser_type_name (parser);
4662       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4663       if (type_name == NULL)
4664         {
4665           struct c_expr ret;
4666           skip_evaluation--;
4667           in_sizeof--;
4668           ret.value = error_mark_node;
4669           ret.original_code = ERROR_MARK;
4670           return ret;
4671         }
4672       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4673         {
4674           expr = c_parser_postfix_expression_after_paren_type (parser,
4675                                                                type_name);
4676           goto sizeof_expr;
4677         }
4678       /* sizeof ( type-name ).  */
4679       skip_evaluation--;
4680       in_sizeof--;
4681       return c_expr_sizeof_type (type_name);
4682     }
4683   else
4684     {
4685       expr = c_parser_unary_expression (parser);
4686     sizeof_expr:
4687       skip_evaluation--;
4688       in_sizeof--;
4689       if (TREE_CODE (expr.value) == COMPONENT_REF
4690           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4691         error ("%<sizeof%> applied to a bit-field");
4692       return c_expr_sizeof_expr (expr);
4693     }
4694 }
4695
4696 /* Parse an alignof expression.  */
4697
4698 static struct c_expr
4699 c_parser_alignof_expression (c_parser *parser)
4700 {
4701   struct c_expr expr;
4702   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4703   c_parser_consume_token (parser);
4704   skip_evaluation++;
4705   in_alignof++;
4706   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4707       && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4708     {
4709       /* Either __alignof__ ( type-name ) or __alignof__
4710          unary-expression starting with a compound literal.  */
4711       struct c_type_name *type_name;
4712       struct c_expr ret;
4713       c_parser_consume_token (parser);
4714       type_name = c_parser_type_name (parser);
4715       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4716       if (type_name == NULL)
4717         {
4718           struct c_expr ret;
4719           skip_evaluation--;
4720           in_alignof--;
4721           ret.value = error_mark_node;
4722           ret.original_code = ERROR_MARK;
4723           return ret;
4724         }
4725       if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4726         {
4727           expr = c_parser_postfix_expression_after_paren_type (parser,
4728                                                                type_name);
4729           goto alignof_expr;
4730         }
4731       /* alignof ( type-name ).  */
4732       skip_evaluation--;
4733       in_alignof--;
4734       ret.value = c_alignof (groktypename (type_name));
4735       ret.original_code = ERROR_MARK;
4736       return ret;
4737     }
4738   else
4739     {
4740       struct c_expr ret;
4741       expr = c_parser_unary_expression (parser);
4742     alignof_expr:
4743       skip_evaluation--;
4744       in_alignof--;
4745       ret.value = c_alignof_expr (expr.value);
4746       ret.original_code = ERROR_MARK;
4747       return ret;
4748     }
4749 }
4750
4751 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4752
4753    postfix-expression:
4754      primary-expression
4755      postfix-expression [ expression ]
4756      postfix-expression ( argument-expression-list[opt] )
4757      postfix-expression . identifier
4758      postfix-expression -> identifier
4759      postfix-expression ++
4760      postfix-expression --
4761      ( type-name ) { initializer-list }
4762      ( type-name ) { initializer-list , }
4763
4764    argument-expression-list:
4765      argument-expression
4766      argument-expression-list , argument-expression
4767
4768    primary-expression:
4769      identifier
4770      constant
4771      string-literal
4772      ( expression )
4773
4774    GNU extensions:
4775
4776    primary-expression:
4777      __func__
4778        (treated as a keyword in GNU C)
4779      __FUNCTION__
4780      __PRETTY_FUNCTION__
4781      ( compound-statement )
4782      __builtin_va_arg ( assignment-expression , type-name )
4783      __builtin_offsetof ( type-name , offsetof-member-designator )
4784      __builtin_choose_expr ( assignment-expression ,
4785                              assignment-expression ,
4786                              assignment-expression )
4787      __builtin_types_compatible_p ( type-name , type-name )
4788
4789    offsetof-member-designator:
4790      identifier
4791      offsetof-member-designator . identifier
4792      offsetof-member-designator [ expression ]
4793
4794    Objective-C:
4795
4796    primary-expression:
4797      [ objc-receiver objc-message-args ]
4798      @selector ( objc-selector-arg )
4799      @protocol ( identifier )
4800      @encode ( type-name )
4801      objc-string-literal
4802 */
4803
4804 static struct c_expr
4805 c_parser_postfix_expression (c_parser *parser)
4806 {
4807   struct c_expr expr, e1, e2, e3;
4808   struct c_type_name *t1, *t2;
4809   switch (c_parser_peek_token (parser)->type)
4810     {
4811     case CPP_NUMBER:
4812     case CPP_CHAR:
4813     case CPP_WCHAR:
4814       expr.value = c_parser_peek_token (parser)->value;
4815       expr.original_code = ERROR_MARK;
4816       c_parser_consume_token (parser);
4817       break;
4818     case CPP_STRING:
4819     case CPP_WSTRING:
4820       expr.value = c_parser_peek_token (parser)->value;
4821       expr.original_code = STRING_CST;
4822       c_parser_consume_token (parser);
4823       break;
4824     case CPP_OBJC_STRING:
4825       gcc_assert (c_dialect_objc ());
4826       expr.value
4827         = objc_build_string_object (c_parser_peek_token (parser)->value);
4828       expr.original_code = ERROR_MARK;
4829       c_parser_consume_token (parser);
4830       break;
4831     case CPP_NAME:
4832       if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
4833         {
4834           c_parser_error (parser, "expected expression");
4835           expr.value = error_mark_node;
4836           expr.original_code = ERROR_MARK;
4837           break;
4838         }
4839       {
4840         tree id = c_parser_peek_token (parser)->value;
4841         location_t loc = c_parser_peek_token (parser)->location;
4842         c_parser_consume_token (parser);
4843         expr.value = build_external_ref (id,
4844                                          (c_parser_peek_token (parser)->type
4845                                           == CPP_OPEN_PAREN), loc);
4846         expr.original_code = ERROR_MARK;
4847       }
4848       break;
4849     case CPP_OPEN_PAREN:
4850       /* A parenthesized expression, statement expression or compound
4851          literal.  */
4852       if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
4853         {
4854           /* A statement expression.  */
4855           tree stmt;
4856           c_parser_consume_token (parser);
4857           c_parser_consume_token (parser);
4858           if (cur_stmt_list == NULL)
4859             {
4860               error ("braced-group within expression allowed "
4861                      "only inside a function");
4862               parser->error = true;
4863               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
4864               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4865               expr.value = error_mark_node;
4866               expr.original_code = ERROR_MARK;
4867               break;
4868             }
4869           stmt = c_begin_stmt_expr ();
4870           c_parser_compound_statement_nostart (parser);
4871           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4872                                      "expected %<)%>");
4873           if (pedantic)
4874             pedwarn ("ISO C forbids braced-groups within expressions");
4875           expr.value = c_finish_stmt_expr (stmt);
4876           expr.original_code = ERROR_MARK;
4877         }
4878       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4879         {
4880           /* A compound literal.  ??? Can we actually get here rather
4881              than going directly to
4882              c_parser_postfix_expression_after_paren_type from
4883              elsewhere?  */
4884           struct c_type_name *type_name;
4885           c_parser_consume_token (parser);
4886           type_name = c_parser_type_name (parser);
4887           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4888                                      "expected %<)%>");
4889           if (type_name == NULL)
4890             {
4891               expr.value = error_mark_node;
4892               expr.original_code = ERROR_MARK;
4893             }
4894           else
4895             expr = c_parser_postfix_expression_after_paren_type (parser,
4896                                                                  type_name);
4897         }
4898       else
4899         {
4900           /* A parenthesized expression.  */
4901           c_parser_consume_token (parser);
4902           expr = c_parser_expression (parser);
4903           if (TREE_CODE (expr.value) == MODIFY_EXPR)
4904             TREE_NO_WARNING (expr.value) = 1;
4905           expr.original_code = ERROR_MARK;
4906           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4907                                      "expected %<)%>");
4908         }
4909       break;
4910     case CPP_KEYWORD:
4911       switch (c_parser_peek_token (parser)->keyword)
4912         {
4913         case RID_FUNCTION_NAME:
4914         case RID_PRETTY_FUNCTION_NAME:
4915         case RID_C99_FUNCTION_NAME:
4916           expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
4917                                    c_parser_peek_token (parser)->value);
4918           expr.original_code = ERROR_MARK;
4919           c_parser_consume_token (parser);
4920           break;
4921         case RID_VA_ARG:
4922           c_parser_consume_token (parser);
4923           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4924             {
4925               expr.value = error_mark_node;
4926               expr.original_code = ERROR_MARK;
4927               break;
4928             }
4929           e1 = c_parser_expr_no_commas (parser, NULL);
4930           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
4931             {
4932               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4933               expr.value = error_mark_node;
4934               expr.original_code = ERROR_MARK;
4935               break;
4936             }
4937           t1 = c_parser_type_name (parser);
4938           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
4939                                      "expected %<)%>");
4940           if (t1 == NULL)
4941             {
4942               expr.value = error_mark_node;
4943               expr.original_code = ERROR_MARK;
4944             }
4945           else
4946             {
4947               expr.value = build_va_arg (e1.value, groktypename (t1));
4948               expr.original_code = ERROR_MARK;
4949             }
4950           break;
4951         case RID_OFFSETOF:
4952           c_parser_consume_token (parser);
4953           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4954             {
4955               expr.value = error_mark_node;
4956               expr.original_code = ERROR_MARK;
4957               break;
4958             }
4959           t1 = c_parser_type_name (parser);
4960           if (t1 == NULL)
4961             {
4962               expr.value = error_mark_node;
4963               expr.original_code = ERROR_MARK;
4964               break;
4965             }
4966           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
4967             {
4968               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4969               expr.value = error_mark_node;
4970               expr.original_code = ERROR_MARK;
4971               break;
4972             }
4973           {
4974             tree type = groktypename (t1);
4975             tree offsetof_ref;
4976             if (type == error_mark_node)
4977               offsetof_ref = error_mark_node;
4978             else
4979               offsetof_ref = build1 (INDIRECT_REF, type, NULL);
4980             /* Parse the second argument to __builtin_offsetof.  We
4981                must have one identifier, and beyond that we want to
4982                accept sub structure and sub array references.  */
4983             if (c_parser_next_token_is (parser, CPP_NAME))
4984               {
4985                 offsetof_ref = build_component_ref
4986                   (offsetof_ref, c_parser_peek_token (parser)->value);
4987                 c_parser_consume_token (parser);
4988                 while (c_parser_next_token_is (parser, CPP_DOT)
4989                        || c_parser_next_token_is (parser,
4990                                                   CPP_OPEN_SQUARE))
4991                   {
4992                     if (c_parser_next_token_is (parser, CPP_DOT))
4993                       {
4994                         c_parser_consume_token (parser);
4995                         if (c_parser_next_token_is_not (parser,
4996                                                         CPP_NAME))
4997                           {
4998                             c_parser_error (parser, "expected identifier");
4999                             break;
5000                           }
5001                         offsetof_ref = build_component_ref
5002                           (offsetof_ref,
5003                            c_parser_peek_token (parser)->value);
5004                         c_parser_consume_token (parser);
5005                       }
5006                     else
5007                       {
5008                         tree idx;
5009                         c_parser_consume_token (parser);
5010                         idx = c_parser_expression (parser).value;
5011                         c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5012                                                    "expected %<]%>");
5013                         offsetof_ref = build_array_ref (offsetof_ref, idx);
5014                       }
5015                   }
5016               }
5017             else
5018               c_parser_error (parser, "expected identifier");
5019             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5020                                        "expected %<)%>");
5021             expr.value = fold_offsetof (offsetof_ref);
5022             expr.original_code = ERROR_MARK;
5023           }
5024           break;
5025         case RID_CHOOSE_EXPR:
5026           c_parser_consume_token (parser);
5027           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5028             {
5029               expr.value = error_mark_node;
5030               expr.original_code = ERROR_MARK;
5031               break;
5032             }
5033           e1 = c_parser_expr_no_commas (parser, NULL);
5034           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5035             {
5036               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5037               expr.value = error_mark_node;
5038               expr.original_code = ERROR_MARK;
5039               break;
5040             }
5041           e2 = c_parser_expr_no_commas (parser, NULL);
5042           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5043             {
5044               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5045               expr.value = error_mark_node;
5046               expr.original_code = ERROR_MARK;
5047               break;
5048             }
5049           e3 = c_parser_expr_no_commas (parser, NULL);
5050           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5051                                      "expected %<)%>");
5052           {
5053             tree c;
5054
5055             c = fold (e1.value);
5056             if (TREE_CODE (c) != INTEGER_CST)
5057               error ("first argument to %<__builtin_choose_expr%> not"
5058                      " a constant");
5059             expr = integer_zerop (c) ? e3 : e2;
5060           }
5061           break;
5062         case RID_TYPES_COMPATIBLE_P:
5063           c_parser_consume_token (parser);
5064           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5065             {
5066               expr.value = error_mark_node;
5067               expr.original_code = ERROR_MARK;
5068               break;
5069             }
5070           t1 = c_parser_type_name (parser);
5071           if (t1 == NULL)
5072             {
5073               expr.value = error_mark_node;
5074               expr.original_code = ERROR_MARK;
5075               break;
5076             }
5077           if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5078             {
5079               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5080               expr.value = error_mark_node;
5081               expr.original_code = ERROR_MARK;
5082               break;
5083             }
5084           t2 = c_parser_type_name (parser);
5085           if (t2 == NULL)
5086             {
5087               expr.value = error_mark_node;
5088               expr.original_code = ERROR_MARK;
5089               break;
5090             }
5091           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5092                                      "expected %<)%>");
5093           {
5094             tree e1, e2;
5095
5096             e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5097             e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5098
5099             expr.value = comptypes (e1, e2)
5100               ? build_int_cst (NULL_TREE, 1)
5101               : build_int_cst (NULL_TREE, 0);
5102             expr.original_code = ERROR_MARK;
5103           }
5104           break;
5105         case RID_AT_SELECTOR:
5106           gcc_assert (c_dialect_objc ());
5107           c_parser_consume_token (parser);
5108           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5109             {
5110               expr.value = error_mark_node;
5111               expr.original_code = ERROR_MARK;
5112               break;
5113             }
5114           {
5115             tree sel = c_parser_objc_selector_arg (parser);
5116             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5117                                        "expected %<)%>");
5118             expr.value = objc_build_selector_expr (sel);
5119             expr.original_code = ERROR_MARK;
5120           }
5121           break;
5122         case RID_AT_PROTOCOL:
5123           gcc_assert (c_dialect_objc ());
5124           c_parser_consume_token (parser);
5125           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5126             {
5127               expr.value = error_mark_node;
5128               expr.original_code = ERROR_MARK;
5129               break;
5130             }
5131           if (c_parser_next_token_is_not (parser, CPP_NAME))
5132             {
5133               c_parser_error (parser, "expected identifier");
5134               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5135               expr.value = error_mark_node;
5136               expr.original_code = ERROR_MARK;
5137               break;
5138             }
5139           {
5140             tree id = c_parser_peek_token (parser)->value;
5141             c_parser_consume_token (parser);
5142             c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5143                                        "expected %<)%>");
5144             expr.value = objc_build_protocol_expr (id);
5145             expr.original_code = ERROR_MARK;
5146           }
5147           break;
5148         case RID_AT_ENCODE:
5149           /* Extension to support C-structures in the archiver.  */
5150           gcc_assert (c_dialect_objc ());
5151           c_parser_consume_token (parser);
5152           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5153             {
5154               expr.value = error_mark_node;
5155               expr.original_code = ERROR_MARK;
5156               break;
5157             }
5158           t1 = c_parser_type_name (parser);
5159           if (t1 == NULL)
5160             {
5161               expr.value = error_mark_node;
5162               expr.original_code = ERROR_MARK;
5163               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5164               break;
5165             }
5166           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5167                                      "expected %<)%>");
5168           {
5169             tree type = groktypename (t1);
5170             expr.value = objc_build_encode_expr (type);
5171             expr.original_code = ERROR_MARK;
5172           }
5173           break;
5174         default:
5175           c_parser_error (parser, "expected expression");
5176           expr.value = error_mark_node;
5177           expr.original_code = ERROR_MARK;
5178           break;
5179         }
5180       break;
5181     case CPP_OPEN_SQUARE:
5182       if (c_dialect_objc ())
5183         {
5184           tree receiver, args;
5185           c_parser_consume_token (parser);
5186           receiver = c_parser_objc_receiver (parser);
5187           args = c_parser_objc_message_args (parser);
5188           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5189                                      "expected %<]%>");
5190           expr.value = objc_build_message_expr (build_tree_list (receiver,
5191                                                                  args));
5192           expr.original_code = ERROR_MARK;
5193           break;
5194         }
5195       /* Else fall through to report error.  */
5196     default:
5197       c_parser_error (parser, "expected expression");
5198       expr.value = error_mark_node;
5199       expr.original_code = ERROR_MARK;
5200       break;
5201     }
5202   return c_parser_postfix_expression_after_primary (parser, expr);
5203 }
5204
5205 /* Parse a postfix expression after a parenthesized type name: the
5206    brace-enclosed initializer of a compound literal, possibly followed
5207    by some postfix operators.  This is separate because it is not
5208    possible to tell until after the type name whether a cast
5209    expression has a cast or a compound literal, or whether the operand
5210    of sizeof is a parenthesized type name or starts with a compound
5211    literal.  */
5212
5213 static struct c_expr
5214 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5215                                               struct c_type_name *type_name)
5216 {
5217   tree type;
5218   struct c_expr init;
5219   struct c_expr expr;
5220   start_init (NULL_TREE, NULL, 0);
5221   type = groktypename (type_name);
5222   if (C_TYPE_VARIABLE_SIZE (type))
5223     {
5224       error ("compound literal has variable size");
5225       type = error_mark_node;
5226     }
5227   init = c_parser_braced_init (parser, type, false);
5228   finish_init ();
5229   maybe_warn_string_init (type, init);
5230
5231   if (pedantic && !flag_isoc99)
5232     pedwarn ("ISO C90 forbids compound literals");
5233   expr.value = build_compound_literal (type, init.value);
5234   expr.original_code = ERROR_MARK;
5235   return c_parser_postfix_expression_after_primary (parser, expr);
5236 }
5237
5238 /* Parse a postfix expression after the initial primary or compound
5239    literal; that is, parse a series of postfix operators.  */
5240
5241 static struct c_expr
5242 c_parser_postfix_expression_after_primary (c_parser *parser,
5243                                            struct c_expr expr)
5244 {
5245   tree ident, idx, exprlist;
5246   while (true)
5247     {
5248       switch (c_parser_peek_token (parser)->type)
5249         {
5250         case CPP_OPEN_SQUARE:
5251           /* Array reference.  */
5252           c_parser_consume_token (parser);
5253           idx = c_parser_expression (parser).value;
5254           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5255                                      "expected %<]%>");
5256           expr.value = build_array_ref (expr.value, idx);
5257           expr.original_code = ERROR_MARK;
5258           break;
5259         case CPP_OPEN_PAREN:
5260           /* Function call.  */
5261           c_parser_consume_token (parser);
5262           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5263             exprlist = NULL_TREE;
5264           else
5265             exprlist = c_parser_expr_list (parser, true);
5266           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5267                                      "expected %<)%>");
5268           expr.value = build_function_call (expr.value, exprlist);
5269           expr.original_code = ERROR_MARK;
5270           break;
5271         case CPP_DOT:
5272           /* Structure element reference.  */
5273           c_parser_consume_token (parser);
5274           expr = default_function_array_conversion (expr);
5275           if (c_parser_next_token_is (parser, CPP_NAME))
5276             ident = c_parser_peek_token (parser)->value;
5277           else
5278             {
5279               c_parser_error (parser, "expected identifier");
5280               expr.value = error_mark_node;
5281               expr.original_code = ERROR_MARK;
5282               return expr;
5283             }
5284           c_parser_consume_token (parser);
5285           expr.value = build_component_ref (expr.value, ident);
5286           expr.original_code = ERROR_MARK;
5287           break;
5288         case CPP_DEREF:
5289           /* Structure element reference.  */
5290           c_parser_consume_token (parser);
5291           expr = default_function_array_conversion (expr);
5292           if (c_parser_next_token_is (parser, CPP_NAME))
5293             ident = c_parser_peek_token (parser)->value;
5294           else
5295             {
5296               c_parser_error (parser, "expected identifier");
5297               expr.value = error_mark_node;
5298               expr.original_code = ERROR_MARK;
5299               return expr;
5300             }
5301           c_parser_consume_token (parser);
5302           expr.value = build_component_ref (build_indirect_ref (expr.value,
5303                                                                 "->"), ident);
5304           expr.original_code = ERROR_MARK;
5305           break;
5306         case CPP_PLUS_PLUS:
5307           /* Postincrement.  */
5308           c_parser_consume_token (parser);
5309           expr = default_function_array_conversion (expr);
5310           expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5311           expr.original_code = ERROR_MARK;
5312           break;
5313         case CPP_MINUS_MINUS:
5314           /* Postdecrement.  */
5315           c_parser_consume_token (parser);
5316           expr = default_function_array_conversion (expr);
5317           expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5318           expr.original_code = ERROR_MARK;
5319           break;
5320         default:
5321           return expr;
5322         }
5323     }
5324 }
5325
5326 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5327
5328    expression:
5329      assignment-expression
5330      expression , assignment-expression
5331 */
5332
5333 static struct c_expr
5334 c_parser_expression (c_parser *parser)
5335 {
5336   struct c_expr expr;
5337   expr = c_parser_expr_no_commas (parser, NULL);
5338   while (c_parser_next_token_is (parser, CPP_COMMA))
5339     {
5340       struct c_expr next;
5341       c_parser_consume_token (parser);
5342       next = c_parser_expr_no_commas (parser, NULL);
5343       next = default_function_array_conversion (next);
5344       expr.value = build_compound_expr (expr.value, next.value);
5345       expr.original_code = COMPOUND_EXPR;
5346     }
5347   return expr;
5348 }
5349
5350 /* Parse an expression and convert functions or arrays to
5351    pointers.  */
5352
5353 static struct c_expr
5354 c_parser_expression_conv (c_parser *parser)
5355 {
5356   struct c_expr expr;
5357   expr = c_parser_expression (parser);
5358   expr = default_function_array_conversion (expr);
5359   return expr;
5360 }
5361
5362 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
5363    functions and arrays to pointers.
5364
5365    nonempty-expr-list:
5366      assignment-expression
5367      nonempty-expr-list , assignment-expression
5368 */
5369
5370 static tree
5371 c_parser_expr_list (c_parser *parser, bool convert_p)
5372 {
5373   struct c_expr expr;
5374   tree ret, cur;
5375   expr = c_parser_expr_no_commas (parser, NULL);
5376   if (convert_p)
5377     expr = default_function_array_conversion (expr);
5378   ret = cur = build_tree_list (NULL_TREE, expr.value);
5379   while (c_parser_next_token_is (parser, CPP_COMMA))
5380     {
5381       c_parser_consume_token (parser);
5382       expr = c_parser_expr_no_commas (parser, NULL);
5383       if (convert_p)
5384         expr = default_function_array_conversion (expr);
5385       cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5386     }
5387   return ret;
5388 }
5389
5390 \f
5391 /* Parse Objective-C-specific constructs.  */
5392
5393 /* Parse an objc-class-definition.
5394
5395    objc-class-definition:
5396      @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5397        objc-class-instance-variables[opt] objc-methodprotolist @end
5398      @implementation identifier objc-superclass[opt]
5399        objc-class-instance-variables[opt]
5400      @interface identifier ( identifier ) objc-protocol-refs[opt]
5401        objc-methodprotolist @end
5402      @implementation identifier ( identifier )
5403
5404    objc-superclass:
5405      : identifier
5406
5407    "@interface identifier (" must start "@interface identifier (
5408    identifier ) ...": objc-methodprotolist in the first production may
5409    not start with a parenthesized identifier as a declarator of a data
5410    definition with no declaration specifiers if the objc-superclass,
5411    objc-protocol-refs and objc-class-instance-variables are omitted.  */
5412
5413 static void
5414 c_parser_objc_class_definition (c_parser *parser)
5415 {
5416   bool iface_p;
5417   tree id1;
5418   tree superclass;
5419   if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5420     iface_p = true;
5421   else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5422     iface_p = false;
5423   else
5424     gcc_unreachable ();
5425   c_parser_consume_token (parser);
5426   if (c_parser_next_token_is_not (parser, CPP_NAME))
5427     {
5428       c_parser_error (parser, "expected identifier");
5429       return;
5430     }
5431   id1 = c_parser_peek_token (parser)->value;
5432   c_parser_consume_token (parser);
5433   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5434     {
5435       tree id2;
5436       tree proto = NULL_TREE;
5437       c_parser_consume_token (parser);
5438       if (c_parser_next_token_is_not (parser, CPP_NAME))
5439         {
5440           c_parser_error (parser, "expected identifier");
5441           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5442           return;
5443         }
5444       id2 = c_parser_peek_token (parser)->value;
5445       c_parser_consume_token (parser);
5446       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5447       if (!iface_p)
5448         {
5449           objc_start_category_implementation (id1, id2);
5450           return;
5451         }
5452       if (c_parser_next_token_is (parser, CPP_LESS))
5453         proto = c_parser_objc_protocol_refs (parser);
5454       objc_start_category_interface (id1, id2, proto);
5455       c_parser_objc_methodprotolist (parser);
5456       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5457       objc_finish_interface ();
5458       return;
5459     }
5460   if (c_parser_next_token_is (parser, CPP_COLON))
5461     {
5462       c_parser_consume_token (parser);
5463       if (c_parser_next_token_is_not (parser, CPP_NAME))
5464         {
5465           c_parser_error (parser, "expected identifier");
5466           return;
5467         }
5468       superclass = c_parser_peek_token (parser)->value;
5469       c_parser_consume_token (parser);
5470     }
5471   else
5472     superclass = NULL_TREE;
5473   if (iface_p)
5474     {
5475       tree proto = NULL_TREE;
5476       if (c_parser_next_token_is (parser, CPP_LESS))
5477         proto = c_parser_objc_protocol_refs (parser);
5478       objc_start_class_interface (id1, superclass, proto);
5479     }
5480   else
5481     objc_start_class_implementation (id1, superclass);
5482   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5483     c_parser_objc_class_instance_variables (parser);
5484   if (iface_p)
5485     {
5486       objc_continue_interface ();
5487       c_parser_objc_methodprotolist (parser);
5488       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5489       objc_finish_interface ();
5490     }
5491   else
5492     {
5493       objc_continue_implementation ();
5494       return;
5495     }
5496 }
5497
5498 /* Parse objc-class-instance-variables.
5499
5500    objc-class-instance-variables:
5501      { objc-instance-variable-decl-list[opt] }
5502
5503    objc-instance-variable-decl-list:
5504      objc-visibility-spec
5505      objc-instance-variable-decl ;
5506      ;
5507      objc-instance-variable-decl-list objc-visibility-spec
5508      objc-instance-variable-decl-list objc-instance-variable-decl ;
5509      objc-instance-variable-decl-list ;
5510
5511    objc-visibility-spec:
5512      @private
5513      @protected
5514      @public
5515
5516    objc-instance-variable-decl:
5517      struct-declaration
5518 */
5519
5520 static void
5521 c_parser_objc_class_instance_variables (c_parser *parser)
5522 {
5523   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5524   c_parser_consume_token (parser);
5525   while (c_parser_next_token_is_not (parser, CPP_EOF))
5526     {
5527       tree decls;
5528       /* Parse any stray semicolon.  */
5529       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5530         {
5531           if (pedantic)
5532             pedwarn ("extra semicolon in struct or union specified");
5533           c_parser_consume_token (parser);
5534           continue;
5535         }
5536       /* Stop if at the end of the instance variables.  */
5537       if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5538         {
5539           c_parser_consume_token (parser);
5540           break;
5541         }
5542       /* Parse any objc-visibility-spec.  */
5543       if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5544         {
5545           c_parser_consume_token (parser);
5546           objc_set_visibility (2);
5547           continue;
5548         }
5549       else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5550         {
5551           c_parser_consume_token (parser);
5552           objc_set_visibility (0);
5553           continue;
5554         }
5555       else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5556         {
5557           c_parser_consume_token (parser);
5558           objc_set_visibility (1);
5559           continue;
5560         }
5561       /* Parse some comma-separated declarations.  */
5562       decls = c_parser_struct_declaration (parser);
5563       {
5564         /* Comma-separated instance variables are chained together in
5565            reverse order; add them one by one.  */
5566         tree ivar = nreverse (decls);
5567         for (; ivar; ivar = TREE_CHAIN (ivar))
5568           objc_add_instance_variable (copy_node (ivar));
5569       }
5570       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5571     }
5572 }
5573
5574 /* Parse an objc-class-declaration.
5575
5576    objc-class-declaration:
5577      @class identifier-list ;
5578 */
5579
5580 static void
5581 c_parser_objc_class_declaration (c_parser *parser)
5582 {
5583   tree list = NULL_TREE;
5584   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5585   c_parser_consume_token (parser);
5586   /* Any identifiers, including those declared as type names, are OK
5587      here.  */
5588   while (true)
5589     {
5590       tree id;
5591       if (c_parser_next_token_is_not (parser, CPP_NAME))
5592         {
5593           c_parser_error (parser, "expected identifier");
5594           break;
5595         }
5596       id = c_parser_peek_token (parser)->value;
5597       list = chainon (list, build_tree_list (NULL_TREE, id));
5598       c_parser_consume_token (parser);
5599       if (c_parser_next_token_is (parser, CPP_COMMA))
5600         c_parser_consume_token (parser);
5601       else
5602         break;
5603     }
5604   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5605   objc_declare_class (list);
5606 }
5607
5608 /* Parse an objc-alias-declaration.
5609
5610    objc-alias-declaration:
5611      @compatibility_alias identifier identifier ;
5612 */
5613
5614 static void
5615 c_parser_objc_alias_declaration (c_parser *parser)
5616 {
5617   tree id1, id2;
5618   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5619   c_parser_consume_token (parser);
5620   if (c_parser_next_token_is_not (parser, CPP_NAME))
5621     {
5622       c_parser_error (parser, "expected identifier");
5623       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5624       return;
5625     }
5626   id1 = c_parser_peek_token (parser)->value;
5627   c_parser_consume_token (parser);
5628   if (c_parser_next_token_is_not (parser, CPP_NAME))
5629     {
5630       c_parser_error (parser, "expected identifier");
5631       c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5632       return;
5633     }
5634   id2 = c_parser_peek_token (parser)->value;
5635   c_parser_consume_token (parser);
5636   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5637   objc_declare_alias (id1, id2);
5638 }
5639
5640 /* Parse an objc-protocol-definition.
5641
5642    objc-protocol-definition:
5643      @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5644      @protocol identifier-list ;
5645
5646    "@protocol identifier ;" should be resolved as "@protocol
5647    identifier-list ;": objc-methodprotolist may not start with a
5648    semicolon in the first alternative if objc-protocol-refs are
5649    omitted.  */
5650
5651 static void
5652 c_parser_objc_protocol_definition (c_parser *parser)
5653 {
5654   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5655   c_parser_consume_token (parser);
5656   if (c_parser_next_token_is_not (parser, CPP_NAME))
5657     {
5658       c_parser_error (parser, "expected identifier");
5659       return;
5660     }
5661   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5662       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5663     {
5664       tree list = NULL_TREE;
5665       /* Any identifiers, including those declared as type names, are
5666          OK here.  */
5667       while (true)
5668         {
5669           tree id;
5670           if (c_parser_next_token_is_not (parser, CPP_NAME))
5671             {
5672               c_parser_error (parser, "expected identifier");
5673               break;
5674             }
5675           id = c_parser_peek_token (parser)->value;
5676           list = chainon (list, build_tree_list (NULL_TREE, id));
5677           c_parser_consume_token (parser);
5678           if (c_parser_next_token_is (parser, CPP_COMMA))
5679             c_parser_consume_token (parser);
5680           else
5681             break;
5682         }
5683       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5684       objc_declare_protocols (list);
5685     }
5686   else
5687     {
5688       tree id = c_parser_peek_token (parser)->value;
5689       tree proto = NULL_TREE;
5690       c_parser_consume_token (parser);
5691       if (c_parser_next_token_is (parser, CPP_LESS))
5692         proto = c_parser_objc_protocol_refs (parser);
5693       objc_pq_context = 1;
5694       objc_start_protocol (id, proto);
5695       c_parser_objc_methodprotolist (parser);
5696       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5697       objc_pq_context = 0;
5698       objc_finish_interface ();
5699     }
5700 }
5701
5702 /* Parse an objc-method-type.
5703
5704    objc-method-type:
5705      +
5706      -
5707 */
5708
5709 static enum tree_code
5710 c_parser_objc_method_type (c_parser *parser)
5711 {
5712   switch (c_parser_peek_token (parser)->type)
5713     {
5714     case CPP_PLUS:
5715       c_parser_consume_token (parser);
5716       return PLUS_EXPR;
5717     case CPP_MINUS:
5718       c_parser_consume_token (parser);
5719       return MINUS_EXPR;
5720     default:
5721       gcc_unreachable ();
5722     }
5723 }
5724
5725 /* Parse an objc-method-definition.
5726
5727    objc-method-definition:
5728      objc-method-type objc-method-decl ;[opt] compound-statement
5729 */
5730
5731 static void
5732 c_parser_objc_method_definition (c_parser *parser)
5733 {
5734   enum tree_code type = c_parser_objc_method_type (parser);
5735   tree decl;
5736   objc_set_method_type (type);
5737   objc_pq_context = 1;
5738   decl = c_parser_objc_method_decl (parser);
5739   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5740     {
5741       c_parser_consume_token (parser);
5742       if (pedantic)
5743         pedwarn ("extra semicolon in method definition specified");
5744     }
5745   if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5746     {
5747       c_parser_error (parser, "expected %<{%>");
5748       return;
5749     }
5750   objc_pq_context = 0;
5751   objc_start_method_definition (decl);
5752   add_stmt (c_parser_compound_statement (parser));
5753   objc_finish_method_definition (current_function_decl);
5754 }
5755
5756 /* Parse an objc-methodprotolist.
5757
5758    objc-methodprotolist:
5759      empty
5760      objc-methodprotolist objc-methodproto
5761      objc-methodprotolist declaration
5762      objc-methodprotolist ;
5763
5764    The declaration is a data definition, which may be missing
5765    declaration specifiers under the same rules and diagnostics as
5766    other data definitions outside functions, and the stray semicolon
5767    is diagnosed the same way as a stray semicolon outside a
5768    function.  */
5769
5770 static void
5771 c_parser_objc_methodprotolist (c_parser *parser)
5772 {
5773   while (true)
5774     {
5775       /* The list is terminated by @end.  */
5776       switch (c_parser_peek_token (parser)->type)
5777         {
5778         case CPP_SEMICOLON:
5779           if (pedantic)
5780             pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5781           c_parser_consume_token (parser);
5782           break;
5783         case CPP_PLUS:
5784         case CPP_MINUS:
5785           c_parser_objc_methodproto (parser);
5786           break;
5787         case CPP_EOF:
5788           return;
5789         default:
5790           if (c_parser_next_token_is_keyword (parser, RID_AT_END))
5791             return;
5792           c_parser_declaration_or_fndef (parser, false, true, false, true);
5793           break;
5794         }
5795     }
5796 }
5797
5798 /* Parse an objc-methodproto.
5799
5800    objc-methodproto:
5801      objc-method-type objc-method-decl ;
5802 */
5803
5804 static void
5805 c_parser_objc_methodproto (c_parser *parser)
5806 {
5807   enum tree_code type = c_parser_objc_method_type (parser);
5808   tree decl;
5809   objc_set_method_type (type);
5810   /* Remember protocol qualifiers in prototypes.  */
5811   objc_pq_context = 1;
5812   decl = c_parser_objc_method_decl (parser);
5813   /* Forget protocol qualifiers here.  */
5814   objc_pq_context = 0;
5815   objc_add_method_declaration (decl);
5816   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5817 }
5818
5819 /* Parse an objc-method-decl.
5820
5821    objc-method-decl:
5822      ( objc-type-name ) objc-selector
5823      objc-selector
5824      ( objc-type-name ) objc-keyword-selector objc-optparmlist
5825      objc-keyword-selector objc-optparmlist
5826
5827    objc-keyword-selector:
5828      objc-keyword-decl
5829      objc-keyword-selector objc-keyword-decl
5830
5831    objc-keyword-decl:
5832      objc-selector : ( objc-type-name ) identifier
5833      objc-selector : identifier
5834      : ( objc-type-name ) identifier
5835      : identifier
5836
5837    objc-optparmlist:
5838      objc-optparms objc-optellipsis
5839
5840    objc-optparms:
5841      empty
5842      objc-opt-parms , parameter-declaration
5843
5844    objc-optellipsis:
5845      empty
5846      , ...
5847 */
5848
5849 static tree
5850 c_parser_objc_method_decl (c_parser *parser)
5851 {
5852   tree type = NULL_TREE;
5853   tree sel;
5854   tree parms = NULL_TREE;
5855   bool ellipsis = false;
5856
5857   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5858     {
5859       c_parser_consume_token (parser);
5860       type = c_parser_objc_type_name (parser);
5861       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5862     }
5863   sel = c_parser_objc_selector (parser);
5864   /* If there is no selector, or a colon follows, we have an
5865      objc-keyword-selector.  If there is a selector, and a colon does
5866      not follow, that selector ends the objc-method-decl.  */
5867   if (!sel || c_parser_next_token_is (parser, CPP_COLON))
5868     {
5869       tree tsel = sel;
5870       tree list = NULL_TREE;
5871       while (true)
5872         {
5873           tree atype = NULL_TREE, id, keyworddecl;
5874           if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5875             break;
5876           if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5877             {
5878               c_parser_consume_token (parser);
5879               atype = c_parser_objc_type_name (parser);
5880               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5881                                          "expected %<)%>");
5882             }
5883           if (c_parser_next_token_is_not (parser, CPP_NAME))
5884             {
5885               c_parser_error (parser, "expected identifier");
5886               return error_mark_node;
5887             }
5888           id = c_parser_peek_token (parser)->value;
5889           c_parser_consume_token (parser);
5890           keyworddecl = objc_build_keyword_decl (tsel, atype, id);
5891           list = chainon (list, keyworddecl);
5892           tsel = c_parser_objc_selector (parser);
5893           if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
5894             break;
5895         }
5896       /* Parse the optional parameter list.  Optional Objective-C
5897          method parameters follow the C syntax, and may include '...'
5898          to denote a variable number of arguments.  */
5899       parms = make_node (TREE_LIST);
5900       while (c_parser_next_token_is (parser, CPP_COMMA))
5901         {
5902           struct c_parm *parm;
5903           c_parser_consume_token (parser);
5904           if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
5905             {
5906               ellipsis = true;
5907               c_parser_consume_token (parser);
5908               break;
5909             }
5910           parm = c_parser_parameter_declaration (parser, NULL_TREE);
5911           if (parm == NULL)
5912             break;
5913           parms = chainon (parms,
5914                            build_tree_list (NULL_TREE, grokparm (parm)));
5915         }
5916       sel = list;
5917     }
5918   return objc_build_method_signature (type, sel, parms, ellipsis);
5919 }
5920
5921 /* Parse an objc-type-name.
5922
5923    objc-type-name:
5924      objc-type-qualifiers[opt] type-name
5925      objc-type-qualifiers[opt]
5926
5927    objc-type-qualifiers:
5928      objc-type-qualifier
5929      objc-type-qualifiers objc-type-qualifier
5930
5931    objc-type-qualifier: one of
5932      in out inout bycopy byref oneway
5933 */
5934
5935 static tree
5936 c_parser_objc_type_name (c_parser *parser)
5937 {
5938   tree quals = NULL_TREE;
5939   struct c_type_name *typename = NULL;
5940   tree type = NULL_TREE;
5941   while (true)
5942     {
5943       c_token *token = c_parser_peek_token (parser);
5944       if (token->type == CPP_KEYWORD
5945           && (token->keyword == RID_IN
5946               || token->keyword == RID_OUT
5947               || token->keyword == RID_INOUT
5948               || token->keyword == RID_BYCOPY
5949               || token->keyword == RID_BYREF
5950               || token->keyword == RID_ONEWAY))
5951         {
5952           quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
5953           c_parser_consume_token (parser);
5954         }
5955       else
5956         break;
5957     }
5958   if (c_parser_next_token_starts_typename (parser))
5959     typename = c_parser_type_name (parser);
5960   if (typename)
5961     type = groktypename (typename);
5962   return build_tree_list (quals, type);
5963 }
5964
5965 /* Parse objc-protocol-refs.
5966
5967    objc-protocol-refs:
5968      < identifier-list >
5969 */
5970
5971 static tree
5972 c_parser_objc_protocol_refs (c_parser *parser)
5973 {
5974   tree list = NULL_TREE;
5975   gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
5976   c_parser_consume_token (parser);
5977   /* Any identifiers, including those declared as type names, are OK
5978      here.  */
5979   while (true)
5980     {
5981       tree id;
5982       if (c_parser_next_token_is_not (parser, CPP_NAME))
5983         {
5984           c_parser_error (parser, "expected identifier");
5985           break;
5986         }
5987       id = c_parser_peek_token (parser)->value;
5988       list = chainon (list, build_tree_list (NULL_TREE, id));
5989       c_parser_consume_token (parser);
5990       if (c_parser_next_token_is (parser, CPP_COMMA))
5991         c_parser_consume_token (parser);
5992       else
5993         break;
5994     }
5995   c_parser_require (parser, CPP_GREATER, "expected %<>%>");
5996   return list;
5997 }
5998
5999 /* Parse an objc-try-catch-statement.
6000
6001    objc-try-catch-statement:
6002      @try compound-statement objc-catch-list[opt]
6003      @try compound-statement objc-catch-list[opt] @finally compound-statement
6004
6005    objc-catch-list:
6006      @catch ( parameter-declaration ) compound-statement
6007      objc-catch-list @catch ( parameter-declaration ) compound-statement
6008 */
6009
6010 static void
6011 c_parser_objc_try_catch_statement (c_parser *parser)
6012 {
6013   location_t loc;
6014   tree stmt;
6015   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6016   c_parser_consume_token (parser);
6017   loc = c_parser_peek_token (parser)->location;
6018   stmt = c_parser_compound_statement (parser);
6019   objc_begin_try_stmt (loc, stmt);
6020   while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6021     {
6022       struct c_parm *parm;
6023       c_parser_consume_token (parser);
6024       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6025         break;
6026       parm = c_parser_parameter_declaration (parser, NULL_TREE);
6027       if (parm == NULL)
6028         {
6029           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6030           break;
6031         }
6032       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6033       objc_begin_catch_clause (grokparm (parm));
6034       if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6035         c_parser_compound_statement_nostart (parser);
6036       objc_finish_catch_clause ();
6037     }
6038   if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6039     {
6040       location_t finloc;
6041       tree finstmt;
6042       c_parser_consume_token (parser);
6043       finloc = c_parser_peek_token (parser)->location;
6044       finstmt = c_parser_compound_statement (parser);
6045       objc_build_finally_clause (finloc, finstmt);
6046     }
6047   objc_finish_try_stmt ();
6048 }
6049
6050 /* Parse an objc-synchronized-statement.
6051
6052    objc-synchronized-statement:
6053      @synchronized ( expression ) compound-statement
6054 */
6055
6056 static void
6057 c_parser_objc_synchronized_statement (c_parser *parser)
6058 {
6059   location_t loc;
6060   tree expr, stmt;
6061   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6062   c_parser_consume_token (parser);
6063   loc = c_parser_peek_token (parser)->location;
6064   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6065     {
6066       expr = c_parser_expression (parser).value;
6067       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6068     }
6069   else
6070     expr = error_mark_node;
6071   stmt = c_parser_compound_statement (parser);
6072   objc_build_synchronized (loc, expr, stmt);
6073 }
6074
6075 /* Parse an objc-selector; return NULL_TREE without an error if the
6076    next token is not an objc-selector.
6077
6078    objc-selector:
6079      identifier
6080      one of
6081        enum struct union if else while do for switch case default
6082        break continue return goto asm sizeof typeof __alignof
6083        unsigned long const short volatile signed restrict _Complex
6084        in out inout bycopy byref oneway int char float double void _Bool
6085
6086    ??? Why this selection of keywords but not, for example, storage
6087    class specifiers?  */
6088
6089 static tree
6090 c_parser_objc_selector (c_parser *parser)
6091 {
6092   c_token *token = c_parser_peek_token (parser);
6093   tree value = token->value;
6094   if (token->type == CPP_NAME)
6095     {
6096       c_parser_consume_token (parser);
6097       return value;
6098     }
6099   if (token->type != CPP_KEYWORD)
6100     return NULL_TREE;
6101   switch (token->keyword)
6102     {
6103     case RID_ENUM:
6104     case RID_STRUCT:
6105     case RID_UNION:
6106     case RID_IF:
6107     case RID_ELSE:
6108     case RID_WHILE:
6109     case RID_DO:
6110     case RID_FOR:
6111     case RID_SWITCH:
6112     case RID_CASE:
6113     case RID_DEFAULT:
6114     case RID_BREAK:
6115     case RID_CONTINUE:
6116     case RID_RETURN:
6117     case RID_GOTO:
6118     case RID_ASM:
6119     case RID_SIZEOF:
6120     case RID_TYPEOF:
6121     case RID_ALIGNOF:
6122     case RID_UNSIGNED:
6123     case RID_LONG:
6124     case RID_CONST:
6125     case RID_SHORT:
6126     case RID_VOLATILE:
6127     case RID_SIGNED:
6128     case RID_RESTRICT:
6129     case RID_COMPLEX:
6130     case RID_IN:
6131     case RID_OUT:
6132     case RID_INOUT:
6133     case RID_BYCOPY:
6134     case RID_BYREF:
6135     case RID_ONEWAY:
6136     case RID_INT:
6137     case RID_CHAR:
6138     case RID_FLOAT:
6139     case RID_DOUBLE:
6140     case RID_VOID:
6141     case RID_BOOL:
6142       c_parser_consume_token (parser);
6143       return value;
6144     default:
6145       return NULL_TREE;
6146     }
6147 }
6148
6149 /* Parse an objc-selector-arg.
6150
6151    objc-selector-arg:
6152      objc-selector
6153      objc-keywordname-list
6154
6155    objc-keywordname-list:
6156      objc-keywordname
6157      objc-keywordname-list objc-keywordname
6158
6159    objc-keywordname:
6160      objc-selector :
6161      :
6162 */
6163
6164 static tree
6165 c_parser_objc_selector_arg (c_parser *parser)
6166 {
6167   tree sel = c_parser_objc_selector (parser);
6168   tree list = NULL_TREE;
6169   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6170     return sel;
6171   while (true)
6172     {
6173       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6174         return list;
6175       list = chainon (list, build_tree_list (sel, NULL_TREE));
6176       sel = c_parser_objc_selector (parser);
6177       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6178         break;
6179     }
6180   return list;
6181 }
6182
6183 /* Parse an objc-receiver.
6184
6185    objc-receiver:
6186      expression
6187      class-name
6188      type-name
6189 */
6190
6191 static tree
6192 c_parser_objc_receiver (c_parser *parser)
6193 {
6194   if (c_parser_peek_token (parser)->type == CPP_NAME
6195       && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6196           || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6197     {
6198       tree id = c_parser_peek_token (parser)->value;
6199       c_parser_consume_token (parser);
6200       return objc_get_class_reference (id);
6201     }
6202   return c_parser_expression (parser).value;
6203 }
6204
6205 /* Parse objc-message-args.
6206
6207    objc-message-args:
6208      objc-selector
6209      objc-keywordarg-list
6210
6211    objc-keywordarg-list:
6212      objc-keywordarg
6213      objc-keywordarg-list objc-keywordarg
6214
6215    objc-keywordarg:
6216      objc-selector : objc-keywordexpr
6217      : objc-keywordexpr
6218 */
6219
6220 static tree
6221 c_parser_objc_message_args (c_parser *parser)
6222 {
6223   tree sel = c_parser_objc_selector (parser);
6224   tree list = NULL_TREE;
6225   if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6226     return sel;
6227   while (true)
6228     {
6229       tree keywordexpr;
6230       if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6231         return list;
6232       keywordexpr = c_parser_objc_keywordexpr (parser);
6233       list = chainon (list, build_tree_list (sel, keywordexpr));
6234       sel = c_parser_objc_selector (parser);
6235       if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6236         break;
6237     }
6238   return list;
6239 }
6240
6241 /* Parse an objc-keywordexpr.
6242
6243    objc-keywordexpr:
6244      nonempty-expr-list
6245 */
6246
6247 static tree
6248 c_parser_objc_keywordexpr (c_parser *parser)
6249 {
6250   tree list = c_parser_expr_list (parser, true);
6251   if (TREE_CHAIN (list) == NULL_TREE)
6252     {
6253       /* Just return the expression, remove a level of
6254          indirection.  */
6255       return TREE_VALUE (list);
6256     }
6257   else
6258     {
6259       /* We have a comma expression, we will collapse later.  */
6260       return list;
6261     }
6262 }
6263
6264 \f
6265 /* The actual parser and external interface.  ??? Does this need to be
6266    garbage-collected?  */
6267
6268 static GTY (()) c_parser *the_parser;
6269
6270 /* Parse a single source file.  */
6271
6272 void
6273 c_parse_file (void)
6274 {
6275   the_parser = c_parser_new ();
6276   c_parser_translation_unit (the_parser);
6277   the_parser = NULL;
6278 }
6279
6280 #include "gt-c-parser.h"