OSDN Git Service

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