OSDN Git Service

PR c++/44062
[pf3gnuchains/gcc-fork.git] / gcc / c-parser.c
1 /* Parser for C and Objective-C.
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4    Free Software Foundation, Inc.
5
6    Parser actions based on the old Bison parser; structure somewhat
7    influenced by and fragments based on the C++ parser.
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3.  If not see
23 <http://www.gnu.org/licenses/>.  */
24
25 /* TODO:
26
27    Make sure all relevant comments, and all relevant code from all
28    actions, brought over from old parser.  Verify exact correspondence
29    of syntax accepted.
30
31    Add testcases covering every input symbol in every state in old and
32    new parsers.
33
34    Include full syntax for GNU C, including erroneous cases accepted
35    with error messages, in syntax productions in comments.
36
37    Make more diagnostics in the front end generally take an explicit
38    location rather than implicitly using input_location.  */
39
40 #include "config.h"
41 #include "system.h"
42 #include "coretypes.h"
43 #include "tm.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "langhooks.h"
47 #include "input.h"
48 #include "cpplib.h"
49 #include "timevar.h"
50 #include "c-pragma.h"
51 #include "c-tree.h"
52 #include "flags.h"
53 #include "output.h"
54 #include "toplev.h"
55 #include "ggc.h"
56 #include "c-common.h"
57 #include "vec.h"
58 #include "target.h"
59 #include "cgraph.h"
60 #include "plugin.h"
61 #include "except.h"
62
63 \f
64 /* Initialization routine for this file.  */
65
66 void
67 c_parse_init (void)
68 {
69   /* The only initialization required is of the reserved word
70      identifiers.  */
71   unsigned int i;
72   tree id;
73   int mask = 0;
74
75   /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
76      the c_token structure.  */
77   gcc_assert (RID_MAX <= 255);
78
79   mask |= D_CXXONLY;
80   if (!flag_isoc99)
81     mask |= D_C99;
82   if (flag_no_asm)
83     {
84       mask |= D_ASM | D_EXT;
85       if (!flag_isoc99)
86         mask |= D_EXT89;
87     }
88   if (!c_dialect_objc ())
89     mask |= D_OBJC | D_CXX_OBJC;
90
91   ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
92   for (i = 0; i < num_c_common_reswords; i++)
93     {
94       /* If a keyword is disabled, do not enter it into the table
95          and so create a canonical spelling that isn't a keyword.  */
96       if (c_common_reswords[i].disable & mask)
97         {
98           if (warn_cxx_compat
99               && (c_common_reswords[i].disable & D_CXXWARN))
100             {
101               id = get_identifier (c_common_reswords[i].word);
102               C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
103               C_IS_RESERVED_WORD (id) = 1;
104             }
105           continue;
106         }
107
108       id = get_identifier (c_common_reswords[i].word);
109       C_SET_RID_CODE (id, c_common_reswords[i].rid);
110       C_IS_RESERVED_WORD (id) = 1;
111       ridpointers [(int) c_common_reswords[i].rid] = id;
112     }
113 }
114 \f
115 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
116    and the C parser.  Unlike the C++ lexer, the parser structure
117    stores the lexer information instead of using a separate structure.
118    Identifiers are separated into ordinary identifiers, type names,
119    keywords and some other Objective-C types of identifiers, and some
120    look-ahead is maintained.
121
122    ??? It might be a good idea to lex the whole file up front (as for
123    C++).  It would then be possible to share more of the C and C++
124    lexer code, if desired.  */
125
126 /* The following local token type is used.  */
127
128 /* A keyword.  */
129 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
130
131 /* More information about the type of a CPP_NAME token.  */
132 typedef enum c_id_kind {
133   /* An ordinary identifier.  */
134   C_ID_ID,
135   /* An identifier declared as a typedef name.  */
136   C_ID_TYPENAME,
137   /* An identifier declared as an Objective-C class name.  */
138   C_ID_CLASSNAME,
139   /* An address space identifier.  */
140   C_ID_ADDRSPACE,
141   /* Not an identifier.  */
142   C_ID_NONE
143 } c_id_kind;
144
145 /* A single C token after string literal concatenation and conversion
146    of preprocessing tokens to tokens.  */
147 typedef struct GTY (()) c_token {
148   /* The kind of token.  */
149   ENUM_BITFIELD (cpp_ttype) type : 8;
150   /* If this token is a CPP_NAME, this value indicates whether also
151      declared as some kind of type.  Otherwise, it is C_ID_NONE.  */
152   ENUM_BITFIELD (c_id_kind) id_kind : 8;
153   /* If this token is a keyword, this value indicates which keyword.
154      Otherwise, this value is RID_MAX.  */
155   ENUM_BITFIELD (rid) keyword : 8;
156   /* If this token is a CPP_PRAGMA, this indicates the pragma that
157      was seen.  Otherwise it is PRAGMA_NONE.  */
158   ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
159   /* The location at which this token was found.  */
160   location_t location;
161   /* The value associated with this token, if any.  */
162   tree value;
163 } c_token;
164
165 /* A parser structure recording information about the state and
166    context of parsing.  Includes lexer information with up to two
167    tokens of look-ahead; more are not needed for C.  */
168 typedef struct GTY(()) c_parser {
169   /* The look-ahead tokens.  */
170   c_token tokens[2];
171   /* How many look-ahead tokens are available (0, 1 or 2).  */
172   short tokens_avail;
173   /* True if a syntax error is being recovered from; false otherwise.
174      c_parser_error sets this flag.  It should clear this flag when
175      enough tokens have been consumed to recover from the error.  */
176   BOOL_BITFIELD error : 1;
177   /* True if we're processing a pragma, and shouldn't automatically
178      consume CPP_PRAGMA_EOL.  */
179   BOOL_BITFIELD in_pragma : 1;
180   /* True if we're parsing the outermost block of an if statement.  */
181   BOOL_BITFIELD in_if_block : 1;
182   /* True if we want to lex an untranslated string.  */
183   BOOL_BITFIELD lex_untranslated_string : 1;
184   /* Objective-C specific parser/lexer information.  */
185   BOOL_BITFIELD objc_pq_context : 1;
186   /* The following flag is needed to contextualize Objective-C lexical
187      analysis.  In some cases (e.g., 'int NSObject;'), it is
188      undesirable to bind an identifier to an Objective-C class, even
189      if a class with that name exists.  */
190   BOOL_BITFIELD objc_need_raw_identifier : 1;
191 } c_parser;
192
193
194 /* The actual parser and external interface.  ??? Does this need to be
195    garbage-collected?  */
196
197 static GTY (()) c_parser *the_parser;
198
199
200 /* Read in and lex a single token, storing it in *TOKEN.  */
201
202 static void
203 c_lex_one_token (c_parser *parser, c_token *token)
204 {
205   timevar_push (TV_LEX);
206
207   token->type = c_lex_with_flags (&token->value, &token->location, NULL,
208                                   (parser->lex_untranslated_string
209                                    ? C_LEX_STRING_NO_TRANSLATE : 0));
210   token->id_kind = C_ID_NONE;
211   token->keyword = RID_MAX;
212   token->pragma_kind = PRAGMA_NONE;
213
214   switch (token->type)
215     {
216     case CPP_NAME:
217       {
218         tree decl;
219
220         bool objc_force_identifier = parser->objc_need_raw_identifier;
221         if (c_dialect_objc ())
222           parser->objc_need_raw_identifier = false;
223
224         if (C_IS_RESERVED_WORD (token->value))
225           {
226             enum rid rid_code = C_RID_CODE (token->value);
227
228             if (rid_code == RID_CXX_COMPAT_WARN)
229               {
230                 warning_at (token->location,
231                             OPT_Wc___compat,
232                             "identifier %qE conflicts with C++ keyword",
233                             token->value);
234               }
235             else if (rid_code >= RID_FIRST_ADDR_SPACE
236                      && rid_code <= RID_LAST_ADDR_SPACE)
237               {
238                 token->id_kind = C_ID_ADDRSPACE;
239                 token->keyword = rid_code;
240                 break;
241               }
242             else if (c_dialect_objc ())
243               {
244                 if (!objc_is_reserved_word (token->value)
245                     && (!OBJC_IS_PQ_KEYWORD (rid_code)
246                         || parser->objc_pq_context))
247                   {
248                     /* Return the canonical spelling for this keyword.  */
249                     token->value = ridpointers[(int) rid_code];
250                     token->type = CPP_KEYWORD;
251                     token->keyword = rid_code;
252                     break;
253                   }
254               }
255             else
256               {
257                 token->type = CPP_KEYWORD;
258                 token->keyword = rid_code;
259                 break;
260               }
261           }
262
263         decl = lookup_name (token->value);
264         if (decl)
265           {
266             if (TREE_CODE (decl) == TYPE_DECL)
267               {
268                 token->id_kind = C_ID_TYPENAME;
269                 break;
270               }
271           }
272         else if (c_dialect_objc ())
273           {
274             tree objc_interface_decl = objc_is_class_name (token->value);
275             /* Objective-C class names are in the same namespace as
276                variables and typedefs, and hence are shadowed by local
277                declarations.  */
278             if (objc_interface_decl
279                 && (global_bindings_p ()
280                     || (!objc_force_identifier && !decl)))
281               {
282                 token->value = objc_interface_decl;
283                 token->id_kind = C_ID_CLASSNAME;
284                 break;
285               }
286           }
287         token->id_kind = C_ID_ID;
288       }
289       break;
290     case CPP_AT_NAME:
291       /* This only happens in Objective-C; it must be a keyword.  */
292       token->type = CPP_KEYWORD;
293       token->keyword = C_RID_CODE (token->value);
294       break;
295     case CPP_COLON:
296     case CPP_COMMA:
297     case CPP_CLOSE_PAREN:
298     case CPP_SEMICOLON:
299       /* These tokens may affect the interpretation of any identifiers
300          following, if doing Objective-C.  */
301       if (c_dialect_objc ())
302         parser->objc_need_raw_identifier = false;
303       break;
304     case CPP_PRAGMA:
305       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
306       token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
307       token->value = NULL;
308       break;
309     default:
310       break;
311     }
312   timevar_pop (TV_LEX);
313 }
314
315 /* Return a pointer to the next token from PARSER, reading it in if
316    necessary.  */
317
318 static inline c_token *
319 c_parser_peek_token (c_parser *parser)
320 {
321   if (parser->tokens_avail == 0)
322     {
323       c_lex_one_token (parser, &parser->tokens[0]);
324       parser->tokens_avail = 1;
325     }
326   return &parser->tokens[0];
327 }
328
329 /* Return true if the next token from PARSER has the indicated
330    TYPE.  */
331
332 static inline bool
333 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
334 {
335   return c_parser_peek_token (parser)->type == type;
336 }
337
338 /* Return true if the next token from PARSER does not have the
339    indicated TYPE.  */
340
341 static inline bool
342 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
343 {
344   return !c_parser_next_token_is (parser, type);
345 }
346
347 /* Return true if the next token from PARSER is the indicated
348    KEYWORD.  */
349
350 static inline bool
351 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
352 {
353   return c_parser_peek_token (parser)->keyword == keyword;
354 }
355
356 /* Return true if TOKEN can start a type name,
357    false otherwise.  */
358 static bool
359 c_token_starts_typename (c_token *token)
360 {
361   switch (token->type)
362     {
363     case CPP_NAME:
364       switch (token->id_kind)
365         {
366         case C_ID_ID:
367           return false;
368         case C_ID_ADDRSPACE:
369           return true;
370         case C_ID_TYPENAME:
371           return true;
372         case C_ID_CLASSNAME:
373           gcc_assert (c_dialect_objc ());
374           return true;
375         default:
376           gcc_unreachable ();
377         }
378     case CPP_KEYWORD:
379       switch (token->keyword)
380         {
381         case RID_UNSIGNED:
382         case RID_LONG:
383         case RID_SHORT:
384         case RID_SIGNED:
385         case RID_COMPLEX:
386         case RID_INT:
387         case RID_CHAR:
388         case RID_FLOAT:
389         case RID_DOUBLE:
390         case RID_VOID:
391         case RID_DFLOAT32:
392         case RID_DFLOAT64:
393         case RID_DFLOAT128:
394         case RID_BOOL:
395         case RID_ENUM:
396         case RID_STRUCT:
397         case RID_UNION:
398         case RID_TYPEOF:
399         case RID_CONST:
400         case RID_VOLATILE:
401         case RID_RESTRICT:
402         case RID_ATTRIBUTE:
403         case RID_FRACT:
404         case RID_ACCUM:
405         case RID_SAT:
406           return true;
407         default:
408           return false;
409         }
410     case CPP_LESS:
411       if (c_dialect_objc ())
412         return true;
413       return false;
414     default:
415       return false;
416     }
417 }
418
419 /* Return true if the next token from PARSER can start a type name,
420    false otherwise.  */
421 static inline bool
422 c_parser_next_token_starts_typename (c_parser *parser)
423 {
424   c_token *token = c_parser_peek_token (parser);
425   return c_token_starts_typename (token);
426 }
427
428 /* Return true if TOKEN can start declaration specifiers, false
429    otherwise.  */
430 static bool
431 c_token_starts_declspecs (c_token *token)
432 {
433   switch (token->type)
434     {
435     case CPP_NAME:
436       switch (token->id_kind)
437         {
438         case C_ID_ID:
439           return false;
440         case C_ID_ADDRSPACE:
441           return true;
442         case C_ID_TYPENAME:
443           return true;
444         case C_ID_CLASSNAME:
445           gcc_assert (c_dialect_objc ());
446           return true;
447         default:
448           gcc_unreachable ();
449         }
450     case CPP_KEYWORD:
451       switch (token->keyword)
452         {
453         case RID_STATIC:
454         case RID_EXTERN:
455         case RID_REGISTER:
456         case RID_TYPEDEF:
457         case RID_INLINE:
458         case RID_AUTO:
459         case RID_THREAD:
460         case RID_UNSIGNED:
461         case RID_LONG:
462         case RID_SHORT:
463         case RID_SIGNED:
464         case RID_COMPLEX:
465         case RID_INT:
466         case RID_CHAR:
467         case RID_FLOAT:
468         case RID_DOUBLE:
469         case RID_VOID:
470         case RID_DFLOAT32:
471         case RID_DFLOAT64:
472         case RID_DFLOAT128:
473         case RID_BOOL:
474         case RID_ENUM:
475         case RID_STRUCT:
476         case RID_UNION:
477         case RID_TYPEOF:
478         case RID_CONST:
479         case RID_VOLATILE:
480         case RID_RESTRICT:
481         case RID_ATTRIBUTE:
482         case RID_FRACT:
483         case RID_ACCUM:
484         case RID_SAT:
485           return true;
486         default:
487           return false;
488         }
489     case CPP_LESS:
490       if (c_dialect_objc ())
491         return true;
492       return false;
493     default:
494       return false;
495     }
496 }
497
498 /* Return true if the next token from PARSER can start declaration
499    specifiers, false otherwise.  */
500 static inline bool
501 c_parser_next_token_starts_declspecs (c_parser *parser)
502 {
503   c_token *token = c_parser_peek_token (parser);
504   return c_token_starts_declspecs (token);
505 }
506
507 /* Return a pointer to the next-but-one token from PARSER, reading it
508    in if necessary.  The next token is already read in.  */
509
510 static c_token *
511 c_parser_peek_2nd_token (c_parser *parser)
512 {
513   if (parser->tokens_avail >= 2)
514     return &parser->tokens[1];
515   gcc_assert (parser->tokens_avail == 1);
516   gcc_assert (parser->tokens[0].type != CPP_EOF);
517   gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
518   c_lex_one_token (parser, &parser->tokens[1]);
519   parser->tokens_avail = 2;
520   return &parser->tokens[1];
521 }
522
523 /* Consume the next token from PARSER.  */
524
525 static void
526 c_parser_consume_token (c_parser *parser)
527 {
528   gcc_assert (parser->tokens_avail >= 1);
529   gcc_assert (parser->tokens[0].type != CPP_EOF);
530   gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
531   gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
532   if (parser->tokens_avail == 2)
533     parser->tokens[0] = parser->tokens[1];
534   parser->tokens_avail--;
535 }
536
537 /* Expect the current token to be a #pragma.  Consume it and remember
538    that we've begun parsing a pragma.  */
539
540 static void
541 c_parser_consume_pragma (c_parser *parser)
542 {
543   gcc_assert (!parser->in_pragma);
544   gcc_assert (parser->tokens_avail >= 1);
545   gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
546   if (parser->tokens_avail == 2)
547     parser->tokens[0] = parser->tokens[1];
548   parser->tokens_avail--;
549   parser->in_pragma = true;
550 }
551
552 /* Update the globals input_location and in_system_header from
553    TOKEN.  */
554 static inline void
555 c_parser_set_source_position_from_token (c_token *token)
556 {
557   if (token->type != CPP_EOF)
558     {
559       input_location = token->location;
560     }
561 }
562
563 /* Issue a diagnostic of the form
564       FILE:LINE: MESSAGE before TOKEN
565    where TOKEN is the next token in the input stream of PARSER.
566    MESSAGE (specified by the caller) is usually of the form "expected
567    OTHER-TOKEN".
568
569    Do not issue a diagnostic if still recovering from an error.
570
571    ??? This is taken from the C++ parser, but building up messages in
572    this way is not i18n-friendly and some other approach should be
573    used.  */
574
575 static void
576 c_parser_error (c_parser *parser, const char *gmsgid)
577 {
578   c_token *token = c_parser_peek_token (parser);
579   if (parser->error)
580     return;
581   parser->error = true;
582   if (!gmsgid)
583     return;
584   /* This diagnostic makes more sense if it is tagged to the line of
585      the token we just peeked at.  */
586   c_parser_set_source_position_from_token (token);
587   c_parse_error (gmsgid,
588                  /* Because c_parse_error does not understand
589                     CPP_KEYWORD, keywords are treated like
590                     identifiers.  */
591                  (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
592                  /* ??? The C parser does not save the cpp flags of a
593                     token, we need to pass 0 here and we will not get
594                     the source spelling of some tokens but rather the
595                     canonical spelling.  */
596                  token->value, /*flags=*/0);
597 }
598
599 /* If the next token is of the indicated TYPE, consume it.  Otherwise,
600    issue the error MSGID.  If MSGID is NULL then a message has already
601    been produced and no message will be produced this time.  Returns
602    true if found, false otherwise.  */
603
604 static bool
605 c_parser_require (c_parser *parser,
606                   enum cpp_ttype type,
607                   const char *msgid)
608 {
609   if (c_parser_next_token_is (parser, type))
610     {
611       c_parser_consume_token (parser);
612       return true;
613     }
614   else
615     {
616       c_parser_error (parser, msgid);
617       return false;
618     }
619 }
620
621 /* If the next token is the indicated keyword, consume it.  Otherwise,
622    issue the error MSGID.  Returns true if found, false otherwise.  */
623
624 static bool
625 c_parser_require_keyword (c_parser *parser,
626                           enum rid keyword,
627                           const char *msgid)
628 {
629   if (c_parser_next_token_is_keyword (parser, keyword))
630     {
631       c_parser_consume_token (parser);
632       return true;
633     }
634   else
635     {
636       c_parser_error (parser, msgid);
637       return false;
638     }
639 }
640
641 /* Like c_parser_require, except that tokens will be skipped until the
642    desired token is found.  An error message is still produced if the
643    next token is not as expected.  If MSGID is NULL then a message has
644    already been produced and no message will be produced this
645    time.  */
646
647 static void
648 c_parser_skip_until_found (c_parser *parser,
649                            enum cpp_ttype type,
650                            const char *msgid)
651 {
652   unsigned nesting_depth = 0;
653
654   if (c_parser_require (parser, type, msgid))
655     return;
656
657   /* Skip tokens until the desired token is found.  */
658   while (true)
659     {
660       /* Peek at the next token.  */
661       c_token *token = c_parser_peek_token (parser);
662       /* If we've reached the token we want, consume it and stop.  */
663       if (token->type == type && !nesting_depth)
664         {
665           c_parser_consume_token (parser);
666           break;
667         }
668
669       /* If we've run out of tokens, stop.  */
670       if (token->type == CPP_EOF)
671         return;
672       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
673         return;
674       if (token->type == CPP_OPEN_BRACE
675           || token->type == CPP_OPEN_PAREN
676           || token->type == CPP_OPEN_SQUARE)
677         ++nesting_depth;
678       else if (token->type == CPP_CLOSE_BRACE
679                || token->type == CPP_CLOSE_PAREN
680                || token->type == CPP_CLOSE_SQUARE)
681         {
682           if (nesting_depth-- == 0)
683             break;
684         }
685       /* Consume this token.  */
686       c_parser_consume_token (parser);
687     }
688   parser->error = false;
689 }
690
691 /* Skip tokens until the end of a parameter is found, but do not
692    consume the comma, semicolon or closing delimiter.  */
693
694 static void
695 c_parser_skip_to_end_of_parameter (c_parser *parser)
696 {
697   unsigned nesting_depth = 0;
698
699   while (true)
700     {
701       c_token *token = c_parser_peek_token (parser);
702       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
703           && !nesting_depth)
704         break;
705       /* If we've run out of tokens, stop.  */
706       if (token->type == CPP_EOF)
707         return;
708       if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
709         return;
710       if (token->type == CPP_OPEN_BRACE
711           || token->type == CPP_OPEN_PAREN
712           || token->type == CPP_OPEN_SQUARE)
713         ++nesting_depth;
714       else if (token->type == CPP_CLOSE_BRACE
715                || token->type == CPP_CLOSE_PAREN
716                || token->type == CPP_CLOSE_SQUARE)
717         {
718           if (nesting_depth-- == 0)
719             break;
720         }
721       /* Consume this token.  */
722       c_parser_consume_token (parser);
723     }
724   parser->error = false;
725 }
726
727 /* Expect to be at the end of the pragma directive and consume an
728    end of line marker.  */
729
730 static void
731 c_parser_skip_to_pragma_eol (c_parser *parser)
732 {
733   gcc_assert (parser->in_pragma);
734   parser->in_pragma = false;
735
736   if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
737     while (true)
738       {
739         c_token *token = c_parser_peek_token (parser);
740         if (token->type == CPP_EOF)
741           break;
742         if (token->type == CPP_PRAGMA_EOL)
743           {
744             c_parser_consume_token (parser);
745             break;
746           }
747         c_parser_consume_token (parser);
748       }
749
750   parser->error = false;
751 }
752
753 /* Skip tokens until we have consumed an entire block, or until we
754    have consumed a non-nested ';'.  */
755
756 static void
757 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
758 {
759   unsigned nesting_depth = 0;
760   bool save_error = parser->error;
761
762   while (true)
763     {
764       c_token *token;
765
766       /* Peek at the next token.  */
767       token = c_parser_peek_token (parser);
768
769       switch (token->type)
770         {
771         case CPP_EOF:
772           return;
773
774         case CPP_PRAGMA_EOL:
775           if (parser->in_pragma)
776             return;
777           break;
778
779         case CPP_SEMICOLON:
780           /* If the next token is a ';', we have reached the
781              end of the statement.  */
782           if (!nesting_depth)
783             {
784               /* Consume the ';'.  */
785               c_parser_consume_token (parser);
786               goto finished;
787             }
788           break;
789
790         case CPP_CLOSE_BRACE:
791           /* If the next token is a non-nested '}', then we have
792              reached the end of the current block.  */
793           if (nesting_depth == 0 || --nesting_depth == 0)
794             {
795               c_parser_consume_token (parser);
796               goto finished;
797             }
798           break;
799
800         case CPP_OPEN_BRACE:
801           /* If it the next token is a '{', then we are entering a new
802              block.  Consume the entire block.  */
803           ++nesting_depth;
804           break;
805
806         case CPP_PRAGMA:
807           /* If we see a pragma, consume the whole thing at once.  We
808              have some safeguards against consuming pragmas willy-nilly.
809              Normally, we'd expect to be here with parser->error set,
810              which disables these safeguards.  But it's possible to get
811              here for secondary error recovery, after parser->error has
812              been cleared.  */
813           c_parser_consume_pragma (parser);
814           c_parser_skip_to_pragma_eol (parser);
815           parser->error = save_error;
816           continue;
817
818         default:
819           break;
820         }
821
822       c_parser_consume_token (parser);
823     }
824
825  finished:
826   parser->error = false;
827 }
828
829 /* CPP's options (initialized by c-opts.c).  */
830 extern cpp_options *cpp_opts;
831
832 /* Save the warning flags which are controlled by __extension__.  */
833
834 static inline int
835 disable_extension_diagnostics (void)
836 {
837   int ret = (pedantic
838              | (warn_pointer_arith << 1)
839              | (warn_traditional << 2)
840              | (flag_iso << 3)
841              | (warn_long_long << 4)
842              | (warn_cxx_compat << 5));
843   cpp_opts->pedantic = pedantic = 0;
844   warn_pointer_arith = 0;
845   cpp_opts->warn_traditional = warn_traditional = 0;
846   flag_iso = 0;
847   cpp_opts->warn_long_long = warn_long_long = 0;
848   warn_cxx_compat = 0;
849   return ret;
850 }
851
852 /* Restore the warning flags which are controlled by __extension__.
853    FLAGS is the return value from disable_extension_diagnostics.  */
854
855 static inline void
856 restore_extension_diagnostics (int flags)
857 {
858   cpp_opts->pedantic = pedantic = flags & 1;
859   warn_pointer_arith = (flags >> 1) & 1;
860   cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
861   flag_iso = (flags >> 3) & 1;
862   cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
863   warn_cxx_compat = (flags >> 5) & 1;
864 }
865
866 /* Possibly kinds of declarator to parse.  */
867 typedef enum c_dtr_syn {
868   /* A normal declarator with an identifier.  */
869   C_DTR_NORMAL,
870   /* An abstract declarator (maybe empty).  */
871   C_DTR_ABSTRACT,
872   /* A parameter declarator: may be either, but after a type name does
873      not redeclare a typedef name as an identifier if it can
874      alternatively be interpreted as a typedef name; see DR#009,
875      applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
876      following DR#249.  For example, given a typedef T, "int T" and
877      "int *T" are valid parameter declarations redeclaring T, while
878      "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
879      abstract declarators rather than involving redundant parentheses;
880      the same applies with attributes inside the parentheses before
881      "T".  */
882   C_DTR_PARM
883 } c_dtr_syn;
884
885 static void c_parser_external_declaration (c_parser *);
886 static void c_parser_asm_definition (c_parser *);
887 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
888 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
889                                 bool);
890 static struct c_typespec c_parser_enum_specifier (c_parser *);
891 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
892 static tree c_parser_struct_declaration (c_parser *);
893 static struct c_typespec c_parser_typeof_specifier (c_parser *);
894 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
895                                                  bool *);
896 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
897                                                         c_dtr_syn, bool *);
898 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
899                                                               bool,
900                                                               struct c_declarator *);
901 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
902 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
903 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
904 static tree c_parser_simple_asm_expr (c_parser *);
905 static tree c_parser_attributes (c_parser *);
906 static struct c_type_name *c_parser_type_name (c_parser *);
907 static struct c_expr c_parser_initializer (c_parser *);
908 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
909 static void c_parser_initelt (c_parser *, struct obstack *);
910 static void c_parser_initval (c_parser *, struct c_expr *,
911                               struct obstack *);
912 static tree c_parser_compound_statement (c_parser *);
913 static void c_parser_compound_statement_nostart (c_parser *);
914 static void c_parser_label (c_parser *);
915 static void c_parser_statement (c_parser *);
916 static void c_parser_statement_after_labels (c_parser *);
917 static void c_parser_if_statement (c_parser *);
918 static void c_parser_switch_statement (c_parser *);
919 static void c_parser_while_statement (c_parser *);
920 static void c_parser_do_statement (c_parser *);
921 static void c_parser_for_statement (c_parser *);
922 static tree c_parser_asm_statement (c_parser *);
923 static tree c_parser_asm_operands (c_parser *, bool);
924 static tree c_parser_asm_goto_operands (c_parser *);
925 static tree c_parser_asm_clobbers (c_parser *);
926 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
927 static struct c_expr c_parser_conditional_expression (c_parser *,
928                                                       struct c_expr *);
929 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
930 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
931 static struct c_expr c_parser_unary_expression (c_parser *);
932 static struct c_expr c_parser_sizeof_expression (c_parser *);
933 static struct c_expr c_parser_alignof_expression (c_parser *);
934 static struct c_expr c_parser_postfix_expression (c_parser *);
935 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
936                                                                    struct c_type_name *,
937                                                                    location_t);
938 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
939                                                                 location_t loc,
940                                                                 struct c_expr);
941 static struct c_expr c_parser_expression (c_parser *);
942 static struct c_expr c_parser_expression_conv (c_parser *);
943 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
944                                          VEC(tree,gc) **);
945 static void c_parser_omp_construct (c_parser *);
946 static void c_parser_omp_threadprivate (c_parser *);
947 static void c_parser_omp_barrier (c_parser *);
948 static void c_parser_omp_flush (c_parser *);
949 static void c_parser_omp_taskwait (c_parser *);
950
951 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
952 static bool c_parser_pragma (c_parser *, enum pragma_context);
953
954 /* These Objective-C parser functions are only ever called when
955    compiling Objective-C.  */
956 static void c_parser_objc_class_definition (c_parser *);
957 static void c_parser_objc_class_instance_variables (c_parser *);
958 static void c_parser_objc_class_declaration (c_parser *);
959 static void c_parser_objc_alias_declaration (c_parser *);
960 static void c_parser_objc_protocol_definition (c_parser *);
961 static enum tree_code c_parser_objc_method_type (c_parser *);
962 static void c_parser_objc_method_definition (c_parser *);
963 static void c_parser_objc_methodprotolist (c_parser *);
964 static void c_parser_objc_methodproto (c_parser *);
965 static tree c_parser_objc_method_decl (c_parser *);
966 static tree c_parser_objc_type_name (c_parser *);
967 static tree c_parser_objc_protocol_refs (c_parser *);
968 static void c_parser_objc_try_catch_statement (c_parser *);
969 static void c_parser_objc_synchronized_statement (c_parser *);
970 static tree c_parser_objc_selector (c_parser *);
971 static tree c_parser_objc_selector_arg (c_parser *);
972 static tree c_parser_objc_receiver (c_parser *);
973 static tree c_parser_objc_message_args (c_parser *);
974 static tree c_parser_objc_keywordexpr (c_parser *);
975
976 /* Parse a translation unit (C90 6.7, C99 6.9).
977
978    translation-unit:
979      external-declarations
980
981    external-declarations:
982      external-declaration
983      external-declarations external-declaration
984
985    GNU extensions:
986
987    translation-unit:
988      empty
989 */
990
991 static void
992 c_parser_translation_unit (c_parser *parser)
993 {
994   if (c_parser_next_token_is (parser, CPP_EOF))
995     {
996       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
997                "ISO C forbids an empty translation unit");
998     }
999   else
1000     {
1001       void *obstack_position = obstack_alloc (&parser_obstack, 0);
1002       mark_valid_location_for_stdc_pragma (false);
1003       do
1004         {
1005           ggc_collect ();
1006           c_parser_external_declaration (parser);
1007           obstack_free (&parser_obstack, obstack_position);
1008         }
1009       while (c_parser_next_token_is_not (parser, CPP_EOF));
1010     }
1011 }
1012
1013 /* Parse an external declaration (C90 6.7, C99 6.9).
1014
1015    external-declaration:
1016      function-definition
1017      declaration
1018
1019    GNU extensions:
1020
1021    external-declaration:
1022      asm-definition
1023      ;
1024      __extension__ external-declaration
1025
1026    Objective-C:
1027
1028    external-declaration:
1029      objc-class-definition
1030      objc-class-declaration
1031      objc-alias-declaration
1032      objc-protocol-definition
1033      objc-method-definition
1034      @end
1035 */
1036
1037 static void
1038 c_parser_external_declaration (c_parser *parser)
1039 {
1040   int ext;
1041   switch (c_parser_peek_token (parser)->type)
1042     {
1043     case CPP_KEYWORD:
1044       switch (c_parser_peek_token (parser)->keyword)
1045         {
1046         case RID_EXTENSION:
1047           ext = disable_extension_diagnostics ();
1048           c_parser_consume_token (parser);
1049           c_parser_external_declaration (parser);
1050           restore_extension_diagnostics (ext);
1051           break;
1052         case RID_ASM:
1053           c_parser_asm_definition (parser);
1054           break;
1055         case RID_AT_INTERFACE:
1056         case RID_AT_IMPLEMENTATION:
1057           gcc_assert (c_dialect_objc ());
1058           c_parser_objc_class_definition (parser);
1059           break;
1060         case RID_CLASS:
1061           gcc_assert (c_dialect_objc ());
1062           c_parser_objc_class_declaration (parser);
1063           break;
1064         case RID_AT_ALIAS:
1065           gcc_assert (c_dialect_objc ());
1066           c_parser_objc_alias_declaration (parser);
1067           break;
1068         case RID_AT_PROTOCOL:
1069           gcc_assert (c_dialect_objc ());
1070           c_parser_objc_protocol_definition (parser);
1071           break;
1072         case RID_AT_END:
1073           gcc_assert (c_dialect_objc ());
1074           c_parser_consume_token (parser);
1075           objc_finish_implementation ();
1076           break;
1077         default:
1078           goto decl_or_fndef;
1079         }
1080       break;
1081     case CPP_SEMICOLON:
1082       pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1083                "ISO C does not allow extra %<;%> outside of a function");
1084       c_parser_consume_token (parser);
1085       break;
1086     case CPP_PRAGMA:
1087       mark_valid_location_for_stdc_pragma (true);
1088       c_parser_pragma (parser, pragma_external);
1089       mark_valid_location_for_stdc_pragma (false);
1090       break;
1091     case CPP_PLUS:
1092     case CPP_MINUS:
1093       if (c_dialect_objc ())
1094         {
1095           c_parser_objc_method_definition (parser);
1096           break;
1097         }
1098       /* Else fall through, and yield a syntax error trying to parse
1099          as a declaration or function definition.  */
1100     default:
1101     decl_or_fndef:
1102       /* A declaration or a function definition.  We can only tell
1103          which after parsing the declaration specifiers, if any, and
1104          the first declarator.  */
1105       c_parser_declaration_or_fndef (parser, true, true, false, true);
1106       break;
1107     }
1108 }
1109
1110
1111 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1112    6.7, 6.9.1).  If FNDEF_OK is true, a function definition is
1113    accepted; otherwise (old-style parameter declarations) only other
1114    declarations are accepted.  If NESTED is true, we are inside a
1115    function or parsing old-style parameter declarations; any functions
1116    encountered are nested functions and declaration specifiers are
1117    required; otherwise we are at top level and functions are normal
1118    functions and declaration specifiers may be optional.  If EMPTY_OK
1119    is true, empty declarations are OK (subject to all other
1120    constraints); otherwise (old-style parameter declarations) they are
1121    diagnosed.  If START_ATTR_OK is true, the declaration specifiers
1122    may start with attributes; otherwise they may not.
1123
1124    declaration:
1125      declaration-specifiers init-declarator-list[opt] ;
1126
1127    function-definition:
1128      declaration-specifiers[opt] declarator declaration-list[opt]
1129        compound-statement
1130
1131    declaration-list:
1132      declaration
1133      declaration-list declaration
1134
1135    init-declarator-list:
1136      init-declarator
1137      init-declarator-list , init-declarator
1138
1139    init-declarator:
1140      declarator simple-asm-expr[opt] attributes[opt]
1141      declarator simple-asm-expr[opt] attributes[opt] = initializer
1142
1143    GNU extensions:
1144
1145    nested-function-definition:
1146      declaration-specifiers declarator declaration-list[opt]
1147        compound-statement
1148
1149    The simple-asm-expr and attributes are GNU extensions.
1150
1151    This function does not handle __extension__; that is handled in its
1152    callers.  ??? Following the old parser, __extension__ may start
1153    external declarations, declarations in functions and declarations
1154    at the start of "for" loops, but not old-style parameter
1155    declarations.
1156
1157    C99 requires declaration specifiers in a function definition; the
1158    absence is diagnosed through the diagnosis of implicit int.  In GNU
1159    C we also allow but diagnose declarations without declaration
1160    specifiers, but only at top level (elsewhere they conflict with
1161    other syntax).
1162
1163    OpenMP:
1164
1165    declaration:
1166      threadprivate-directive  */
1167
1168 static void
1169 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1170                                bool nested, bool start_attr_ok)
1171 {
1172   struct c_declspecs *specs;
1173   tree prefix_attrs;
1174   tree all_prefix_attrs;
1175   bool diagnosed_no_specs = false;
1176   location_t here = c_parser_peek_token (parser)->location;
1177
1178   specs = build_null_declspecs ();
1179   c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1180   if (parser->error)
1181     {
1182       c_parser_skip_to_end_of_block_or_statement (parser);
1183       return;
1184     }
1185   if (nested && !specs->declspecs_seen_p)
1186     {
1187       c_parser_error (parser, "expected declaration specifiers");
1188       c_parser_skip_to_end_of_block_or_statement (parser);
1189       return;
1190     }
1191   finish_declspecs (specs);
1192   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1193     {
1194       if (empty_ok)
1195         shadow_tag (specs);
1196       else
1197         {
1198           shadow_tag_warned (specs, 1);
1199           pedwarn (here, 0, "empty declaration");
1200         }
1201       c_parser_consume_token (parser);
1202       return;
1203     }
1204   pending_xref_error ();
1205   prefix_attrs = specs->attrs;
1206   all_prefix_attrs = prefix_attrs;
1207   specs->attrs = NULL_TREE;
1208   while (true)
1209     {
1210       struct c_declarator *declarator;
1211       bool dummy = false;
1212       tree fnbody;
1213       /* Declaring either one or more declarators (in which case we
1214          should diagnose if there were no declaration specifiers) or a
1215          function definition (in which case the diagnostic for
1216          implicit int suffices).  */
1217       declarator = c_parser_declarator (parser, specs->type_seen_p,
1218                                         C_DTR_NORMAL, &dummy);
1219       if (declarator == NULL)
1220         {
1221           c_parser_skip_to_end_of_block_or_statement (parser);
1222           return;
1223         }
1224       if (c_parser_next_token_is (parser, CPP_EQ)
1225           || c_parser_next_token_is (parser, CPP_COMMA)
1226           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1227           || c_parser_next_token_is_keyword (parser, RID_ASM)
1228           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1229         {
1230           tree asm_name = NULL_TREE;
1231           tree postfix_attrs = NULL_TREE;
1232           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1233             {
1234               diagnosed_no_specs = true;
1235               pedwarn (here, 0, "data definition has no type or storage class");
1236             }
1237           /* Having seen a data definition, there cannot now be a
1238              function definition.  */
1239           fndef_ok = false;
1240           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1241             asm_name = c_parser_simple_asm_expr (parser);
1242           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1243             postfix_attrs = c_parser_attributes (parser);
1244           if (c_parser_next_token_is (parser, CPP_EQ))
1245             {
1246               tree d;
1247               struct c_expr init;
1248               location_t init_loc;
1249               c_parser_consume_token (parser);
1250               /* The declaration of the variable is in effect while
1251                  its initializer is parsed.  */
1252               d = start_decl (declarator, specs, true,
1253                               chainon (postfix_attrs, all_prefix_attrs));
1254               if (!d)
1255                 d = error_mark_node;
1256               start_init (d, asm_name, global_bindings_p ());
1257               init_loc = c_parser_peek_token (parser)->location;
1258               init = c_parser_initializer (parser);
1259               finish_init ();
1260               if (d != error_mark_node)
1261                 {
1262                   maybe_warn_string_init (TREE_TYPE (d), init);
1263                   finish_decl (d, init_loc, init.value,
1264                                init.original_type, asm_name);
1265                 }
1266             }
1267           else
1268             {
1269               tree d = start_decl (declarator, specs, false,
1270                                    chainon (postfix_attrs,
1271                                             all_prefix_attrs));
1272               if (d)
1273                 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1274                              NULL_TREE, asm_name);
1275             }
1276           if (c_parser_next_token_is (parser, CPP_COMMA))
1277             {
1278               c_parser_consume_token (parser);
1279               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1280                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1281                                             prefix_attrs);
1282               else
1283                 all_prefix_attrs = prefix_attrs;
1284               continue;
1285             }
1286           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1287             {
1288               c_parser_consume_token (parser);
1289               return;
1290             }
1291           else
1292             {
1293               c_parser_error (parser, "expected %<,%> or %<;%>");
1294               c_parser_skip_to_end_of_block_or_statement (parser);
1295               return;
1296             }
1297         }
1298       else if (!fndef_ok)
1299         {
1300           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1301                           "%<asm%> or %<__attribute__%>");
1302           c_parser_skip_to_end_of_block_or_statement (parser);
1303           return;
1304         }
1305       /* Function definition (nested or otherwise).  */
1306       if (nested)
1307         {
1308           pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1309           c_push_function_context ();
1310         }
1311       if (!start_function (specs, declarator, all_prefix_attrs))
1312         {
1313           /* This can appear in many cases looking nothing like a
1314              function definition, so we don't give a more specific
1315              error suggesting there was one.  */
1316           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1317                           "or %<__attribute__%>");
1318           if (nested)
1319             c_pop_function_context ();
1320           break;
1321         }
1322       /* Parse old-style parameter declarations.  ??? Attributes are
1323          not allowed to start declaration specifiers here because of a
1324          syntax conflict between a function declaration with attribute
1325          suffix and a function definition with an attribute prefix on
1326          first old-style parameter declaration.  Following the old
1327          parser, they are not accepted on subsequent old-style
1328          parameter declarations either.  However, there is no
1329          ambiguity after the first declaration, nor indeed on the
1330          first as long as we don't allow postfix attributes after a
1331          declarator with a nonempty identifier list in a definition;
1332          and postfix attributes have never been accepted here in
1333          function definitions either.  */
1334       while (c_parser_next_token_is_not (parser, CPP_EOF)
1335              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1336         c_parser_declaration_or_fndef (parser, false, false, true, false);
1337       store_parm_decls ();
1338       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1339         = c_parser_peek_token (parser)->location;
1340       fnbody = c_parser_compound_statement (parser);
1341       if (nested)
1342         {
1343           tree decl = current_function_decl;
1344           /* Mark nested functions as needing static-chain initially.
1345              lower_nested_functions will recompute it but the
1346              DECL_STATIC_CHAIN flag is also used before that happens,
1347              by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
1348           DECL_STATIC_CHAIN (decl) = 1;
1349           add_stmt (fnbody);
1350           finish_function ();
1351           c_pop_function_context ();
1352           add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1353         }
1354       else
1355         {
1356           add_stmt (fnbody);
1357           finish_function ();
1358         }
1359       break;
1360     }
1361 }
1362
1363 /* Parse an asm-definition (asm() outside a function body).  This is a
1364    GNU extension.
1365
1366    asm-definition:
1367      simple-asm-expr ;
1368 */
1369
1370 static void
1371 c_parser_asm_definition (c_parser *parser)
1372 {
1373   tree asm_str = c_parser_simple_asm_expr (parser);
1374   if (asm_str)
1375     cgraph_add_asm_node (asm_str);
1376   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1377 }
1378
1379 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1380    6.7), adding them to SPECS (which may already include some).
1381    Storage class specifiers are accepted iff SCSPEC_OK; type
1382    specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1383    the start iff START_ATTR_OK.
1384
1385    declaration-specifiers:
1386      storage-class-specifier declaration-specifiers[opt]
1387      type-specifier declaration-specifiers[opt]
1388      type-qualifier declaration-specifiers[opt]
1389      function-specifier declaration-specifiers[opt]
1390
1391    Function specifiers (inline) are from C99, and are currently
1392    handled as storage class specifiers, as is __thread.
1393
1394    C90 6.5.1, C99 6.7.1:
1395    storage-class-specifier:
1396      typedef
1397      extern
1398      static
1399      auto
1400      register
1401
1402    C99 6.7.4:
1403    function-specifier:
1404      inline
1405
1406    C90 6.5.2, C99 6.7.2:
1407    type-specifier:
1408      void
1409      char
1410      short
1411      int
1412      long
1413      float
1414      double
1415      signed
1416      unsigned
1417      _Bool
1418      _Complex
1419      [_Imaginary removed in C99 TC2]
1420      struct-or-union-specifier
1421      enum-specifier
1422      typedef-name
1423
1424    (_Bool and _Complex are new in C99.)
1425
1426    C90 6.5.3, C99 6.7.3:
1427
1428    type-qualifier:
1429      const
1430      restrict
1431      volatile
1432      address-space-qualifier
1433
1434    (restrict is new in C99.)
1435
1436    GNU extensions:
1437
1438    declaration-specifiers:
1439      attributes declaration-specifiers[opt]
1440
1441    type-qualifier:
1442      address-space
1443
1444    address-space:
1445      identifier recognized by the target
1446
1447    storage-class-specifier:
1448      __thread
1449
1450    type-specifier:
1451      typeof-specifier
1452      _Decimal32
1453      _Decimal64
1454      _Decimal128
1455      _Fract
1456      _Accum
1457      _Sat
1458
1459   (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1460    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1461
1462    Objective-C:
1463
1464    type-specifier:
1465      class-name objc-protocol-refs[opt]
1466      typedef-name objc-protocol-refs
1467      objc-protocol-refs
1468 */
1469
1470 static void
1471 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1472                     bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1473 {
1474   bool attrs_ok = start_attr_ok;
1475   bool seen_type = specs->type_seen_p;
1476   while (c_parser_next_token_is (parser, CPP_NAME)
1477          || c_parser_next_token_is (parser, CPP_KEYWORD)
1478          || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1479     {
1480       struct c_typespec t;
1481       tree attrs;
1482       location_t loc = c_parser_peek_token (parser)->location;
1483       if (c_parser_next_token_is (parser, CPP_NAME))
1484         {
1485           tree value = c_parser_peek_token (parser)->value;
1486           c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1487
1488           if (kind == C_ID_ADDRSPACE)
1489             {
1490               addr_space_t as
1491                 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1492               declspecs_add_addrspace (specs, as);
1493               c_parser_consume_token (parser);
1494               attrs_ok = true;
1495               continue;
1496             }
1497
1498           /* This finishes the specifiers unless a type name is OK, it
1499              is declared as a type name and a type name hasn't yet
1500              been seen.  */
1501           if (!typespec_ok || seen_type
1502               || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1503             break;
1504           c_parser_consume_token (parser);
1505           seen_type = true;
1506           attrs_ok = true;
1507           if (kind == C_ID_TYPENAME
1508               && (!c_dialect_objc ()
1509                   || c_parser_next_token_is_not (parser, CPP_LESS)))
1510             {
1511               t.kind = ctsk_typedef;
1512               /* For a typedef name, record the meaning, not the name.
1513                  In case of 'foo foo, bar;'.  */
1514               t.spec = lookup_name (value);
1515               t.expr = NULL_TREE;
1516               t.expr_const_operands = true;
1517             }
1518           else
1519             {
1520               tree proto = NULL_TREE;
1521               gcc_assert (c_dialect_objc ());
1522               t.kind = ctsk_objc;
1523               if (c_parser_next_token_is (parser, CPP_LESS))
1524                 proto = c_parser_objc_protocol_refs (parser);
1525               t.spec = objc_get_protocol_qualified_type (value, proto);
1526               t.expr = NULL_TREE;
1527               t.expr_const_operands = true;
1528             }
1529           declspecs_add_type (loc, specs, t);
1530           continue;
1531         }
1532       if (c_parser_next_token_is (parser, CPP_LESS))
1533         {
1534           /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1535              nisse@lysator.liu.se.  */
1536           tree proto;
1537           gcc_assert (c_dialect_objc ());
1538           if (!typespec_ok || seen_type)
1539             break;
1540           proto = c_parser_objc_protocol_refs (parser);
1541           t.kind = ctsk_objc;
1542           t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1543           t.expr = NULL_TREE;
1544           t.expr_const_operands = true;
1545           declspecs_add_type (loc, specs, t);
1546           continue;
1547         }
1548       gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1549       switch (c_parser_peek_token (parser)->keyword)
1550         {
1551         case RID_STATIC:
1552         case RID_EXTERN:
1553         case RID_REGISTER:
1554         case RID_TYPEDEF:
1555         case RID_INLINE:
1556         case RID_AUTO:
1557         case RID_THREAD:
1558           if (!scspec_ok)
1559             goto out;
1560           attrs_ok = true;
1561           /* TODO: Distinguish between function specifiers (inline)
1562              and storage class specifiers, either here or in
1563              declspecs_add_scspec.  */
1564           declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1565           c_parser_consume_token (parser);
1566           break;
1567         case RID_UNSIGNED:
1568         case RID_LONG:
1569         case RID_SHORT:
1570         case RID_SIGNED:
1571         case RID_COMPLEX:
1572         case RID_INT:
1573         case RID_CHAR:
1574         case RID_FLOAT:
1575         case RID_DOUBLE:
1576         case RID_VOID:
1577         case RID_DFLOAT32:
1578         case RID_DFLOAT64:
1579         case RID_DFLOAT128:
1580         case RID_BOOL:
1581         case RID_FRACT:
1582         case RID_ACCUM:
1583         case RID_SAT:
1584           if (!typespec_ok)
1585             goto out;
1586           attrs_ok = true;
1587           seen_type = true;
1588           if (c_dialect_objc ())
1589             parser->objc_need_raw_identifier = true;
1590           t.kind = ctsk_resword;
1591           t.spec = c_parser_peek_token (parser)->value;
1592           t.expr = NULL_TREE;
1593           t.expr_const_operands = true;
1594           declspecs_add_type (loc, specs, t);
1595           c_parser_consume_token (parser);
1596           break;
1597         case RID_ENUM:
1598           if (!typespec_ok)
1599             goto out;
1600           attrs_ok = true;
1601           seen_type = true;
1602           t = c_parser_enum_specifier (parser);
1603           declspecs_add_type (loc, specs, t);
1604           break;
1605         case RID_STRUCT:
1606         case RID_UNION:
1607           if (!typespec_ok)
1608             goto out;
1609           attrs_ok = true;
1610           seen_type = true;
1611           t = c_parser_struct_or_union_specifier (parser);
1612           invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1613           declspecs_add_type (loc, specs, t);
1614           break;
1615         case RID_TYPEOF:
1616           /* ??? The old parser rejected typeof after other type
1617              specifiers, but is a syntax error the best way of
1618              handling this?  */
1619           if (!typespec_ok || seen_type)
1620             goto out;
1621           attrs_ok = true;
1622           seen_type = true;
1623           t = c_parser_typeof_specifier (parser);
1624           declspecs_add_type (loc, specs, t);
1625           break;
1626         case RID_CONST:
1627         case RID_VOLATILE:
1628         case RID_RESTRICT:
1629           attrs_ok = true;
1630           declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1631           c_parser_consume_token (parser);
1632           break;
1633         case RID_ATTRIBUTE:
1634           if (!attrs_ok)
1635             goto out;
1636           attrs = c_parser_attributes (parser);
1637           declspecs_add_attrs (specs, attrs);
1638           break;
1639         default:
1640           goto out;
1641         }
1642     }
1643  out: ;
1644 }
1645
1646 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1647
1648    enum-specifier:
1649      enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1650      enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1651      enum attributes[opt] identifier
1652
1653    The form with trailing comma is new in C99.  The forms with
1654    attributes are GNU extensions.  In GNU C, we accept any expression
1655    without commas in the syntax (assignment expressions, not just
1656    conditional expressions); assignment expressions will be diagnosed
1657    as non-constant.
1658
1659    enumerator-list:
1660      enumerator
1661      enumerator-list , enumerator
1662
1663    enumerator:
1664      enumeration-constant
1665      enumeration-constant = constant-expression
1666 */
1667
1668 static struct c_typespec
1669 c_parser_enum_specifier (c_parser *parser)
1670 {
1671   struct c_typespec ret;
1672   tree attrs;
1673   tree ident = NULL_TREE;
1674   location_t enum_loc;
1675   location_t ident_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
1676   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1677   enum_loc = c_parser_peek_token (parser)->location;
1678   c_parser_consume_token (parser);
1679   attrs = c_parser_attributes (parser);
1680   enum_loc = c_parser_peek_token (parser)->location;
1681   /* Set the location in case we create a decl now.  */
1682   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1683   if (c_parser_next_token_is (parser, CPP_NAME))
1684     {
1685       ident = c_parser_peek_token (parser)->value;
1686       ident_loc = c_parser_peek_token (parser)->location;
1687       enum_loc = ident_loc;
1688       c_parser_consume_token (parser);
1689     }
1690   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1691     {
1692       /* Parse an enum definition.  */
1693       struct c_enum_contents the_enum;
1694       tree type = start_enum (enum_loc, &the_enum, ident);
1695       tree postfix_attrs;
1696       /* We chain the enumerators in reverse order, then put them in
1697          forward order at the end.  */
1698       tree values = NULL_TREE;
1699       c_parser_consume_token (parser);
1700       while (true)
1701         {
1702           tree enum_id;
1703           tree enum_value;
1704           tree enum_decl;
1705           bool seen_comma;
1706           c_token *token;
1707           location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
1708           location_t value_loc;
1709           if (c_parser_next_token_is_not (parser, CPP_NAME))
1710             {
1711               c_parser_error (parser, "expected identifier");
1712               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1713               values = error_mark_node;
1714               break;
1715             }
1716           token = c_parser_peek_token (parser);
1717           enum_id = token->value;
1718           /* Set the location in case we create a decl now.  */
1719           c_parser_set_source_position_from_token (token);
1720           value_loc = token->location;
1721           c_parser_consume_token (parser);
1722           if (c_parser_next_token_is (parser, CPP_EQ))
1723             {
1724               c_parser_consume_token (parser);
1725               value_loc = c_parser_peek_token (parser)->location;
1726               enum_value = c_parser_expr_no_commas (parser, NULL).value;
1727             }
1728           else
1729             enum_value = NULL_TREE;
1730           enum_decl = build_enumerator (value_loc,
1731                                         &the_enum, enum_id, enum_value);
1732           TREE_CHAIN (enum_decl) = values;
1733           values = enum_decl;
1734           seen_comma = false;
1735           if (c_parser_next_token_is (parser, CPP_COMMA))
1736             {
1737               comma_loc = c_parser_peek_token (parser)->location;
1738               seen_comma = true;
1739               c_parser_consume_token (parser);
1740             }
1741           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1742             {
1743               if (seen_comma && !flag_isoc99)
1744                 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1745               c_parser_consume_token (parser);
1746               break;
1747             }
1748           if (!seen_comma)
1749             {
1750               c_parser_error (parser, "expected %<,%> or %<}%>");
1751               c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1752               values = error_mark_node;
1753               break;
1754             }
1755         }
1756       postfix_attrs = c_parser_attributes (parser);
1757       ret.spec = finish_enum (type, nreverse (values),
1758                               chainon (attrs, postfix_attrs));
1759       ret.kind = ctsk_tagdef;
1760       ret.expr = NULL_TREE;
1761       ret.expr_const_operands = true;
1762       return ret;
1763     }
1764   else if (!ident)
1765     {
1766       c_parser_error (parser, "expected %<{%>");
1767       ret.spec = error_mark_node;
1768       ret.kind = ctsk_tagref;
1769       ret.expr = NULL_TREE;
1770       ret.expr_const_operands = true;
1771       return ret;
1772     }
1773   ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1774   /* In ISO C, enumerated types can be referred to only if already
1775      defined.  */
1776   if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1777     {
1778       gcc_assert (ident);
1779       pedwarn (enum_loc, OPT_pedantic,
1780                "ISO C forbids forward references to %<enum%> types");
1781     }
1782   return ret;
1783 }
1784
1785 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1786
1787    struct-or-union-specifier:
1788      struct-or-union attributes[opt] identifier[opt]
1789        { struct-contents } attributes[opt]
1790      struct-or-union attributes[opt] identifier
1791
1792    struct-contents:
1793      struct-declaration-list
1794
1795    struct-declaration-list:
1796      struct-declaration ;
1797      struct-declaration-list struct-declaration ;
1798
1799    GNU extensions:
1800
1801    struct-contents:
1802      empty
1803      struct-declaration
1804      struct-declaration-list struct-declaration
1805
1806    struct-declaration-list:
1807      struct-declaration-list ;
1808      ;
1809
1810    (Note that in the syntax here, unlike that in ISO C, the semicolons
1811    are included here rather than in struct-declaration, in order to
1812    describe the syntax with extra semicolons and missing semicolon at
1813    end.)
1814
1815    Objective-C:
1816
1817    struct-declaration-list:
1818      @defs ( class-name )
1819
1820    (Note this does not include a trailing semicolon, but can be
1821    followed by further declarations, and gets a pedwarn-if-pedantic
1822    when followed by a semicolon.)  */
1823
1824 static struct c_typespec
1825 c_parser_struct_or_union_specifier (c_parser *parser)
1826 {
1827   struct c_typespec ret;
1828   tree attrs;
1829   tree ident = NULL_TREE;
1830   location_t struct_loc;
1831   location_t ident_loc = UNKNOWN_LOCATION;
1832   enum tree_code code;
1833   switch (c_parser_peek_token (parser)->keyword)
1834     {
1835     case RID_STRUCT:
1836       code = RECORD_TYPE;
1837       break;
1838     case RID_UNION:
1839       code = UNION_TYPE;
1840       break;
1841     default:
1842       gcc_unreachable ();
1843     }
1844   struct_loc = c_parser_peek_token (parser)->location;
1845   c_parser_consume_token (parser);
1846   attrs = c_parser_attributes (parser);
1847
1848   /* Set the location in case we create a decl now.  */
1849   c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1850
1851   if (c_parser_next_token_is (parser, CPP_NAME))
1852     {
1853       ident = c_parser_peek_token (parser)->value;
1854       ident_loc = c_parser_peek_token (parser)->location;
1855       struct_loc = ident_loc;
1856       c_parser_consume_token (parser);
1857     }
1858   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1859     {
1860       /* Parse a struct or union definition.  Start the scope of the
1861          tag before parsing components.  */
1862       struct c_struct_parse_info *struct_info;
1863       tree type = start_struct (struct_loc, code, ident, &struct_info);
1864       tree postfix_attrs;
1865       /* We chain the components in reverse order, then put them in
1866          forward order at the end.  Each struct-declaration may
1867          declare multiple components (comma-separated), so we must use
1868          chainon to join them, although when parsing each
1869          struct-declaration we can use TREE_CHAIN directly.
1870
1871          The theory behind all this is that there will be more
1872          semicolon separated fields than comma separated fields, and
1873          so we'll be minimizing the number of node traversals required
1874          by chainon.  */
1875       tree contents = NULL_TREE;
1876       c_parser_consume_token (parser);
1877       /* Handle the Objective-C @defs construct,
1878          e.g. foo(sizeof(struct{ @defs(ClassName) }));.  */
1879       if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1880         {
1881           tree name;
1882           gcc_assert (c_dialect_objc ());
1883           c_parser_consume_token (parser);
1884           if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1885             goto end_at_defs;
1886           if (c_parser_next_token_is (parser, CPP_NAME)
1887               && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1888             {
1889               name = c_parser_peek_token (parser)->value;
1890               c_parser_consume_token (parser);
1891             }
1892           else
1893             {
1894               c_parser_error (parser, "expected class name");
1895               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1896               goto end_at_defs;
1897             }
1898           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1899                                      "expected %<)%>");
1900           contents = nreverse (objc_get_class_ivars (name));
1901         }
1902     end_at_defs:
1903       /* Parse the struct-declarations and semicolons.  Problems with
1904          semicolons are diagnosed here; empty structures are diagnosed
1905          elsewhere.  */
1906       while (true)
1907         {
1908           tree decls;
1909           /* Parse any stray semicolon.  */
1910           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1911             {
1912               pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1913                        "extra semicolon in struct or union specified");
1914               c_parser_consume_token (parser);
1915               continue;
1916             }
1917           /* Stop if at the end of the struct or union contents.  */
1918           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1919             {
1920               c_parser_consume_token (parser);
1921               break;
1922             }
1923           /* Accept #pragmas at struct scope.  */
1924           if (c_parser_next_token_is (parser, CPP_PRAGMA))
1925             {
1926               c_parser_pragma (parser, pragma_external);
1927               continue;
1928             }
1929           /* Parse some comma-separated declarations, but not the
1930              trailing semicolon if any.  */
1931           decls = c_parser_struct_declaration (parser);
1932           contents = chainon (decls, contents);
1933           /* If no semicolon follows, either we have a parse error or
1934              are at the end of the struct or union and should
1935              pedwarn.  */
1936           if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1937             c_parser_consume_token (parser);
1938           else
1939             {
1940               if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1941                 pedwarn (c_parser_peek_token (parser)->location, 0,
1942                          "no semicolon at end of struct or union");
1943               else
1944                 {
1945                   c_parser_error (parser, "expected %<;%>");
1946                   c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1947                   break;
1948                 }
1949             }
1950         }
1951       postfix_attrs = c_parser_attributes (parser);
1952       ret.spec = finish_struct (struct_loc, type, nreverse (contents),
1953                                 chainon (attrs, postfix_attrs), struct_info);
1954       ret.kind = ctsk_tagdef;
1955       ret.expr = NULL_TREE;
1956       ret.expr_const_operands = true;
1957       return ret;
1958     }
1959   else if (!ident)
1960     {
1961       c_parser_error (parser, "expected %<{%>");
1962       ret.spec = error_mark_node;
1963       ret.kind = ctsk_tagref;
1964       ret.expr = NULL_TREE;
1965       ret.expr_const_operands = true;
1966       return ret;
1967     }
1968   ret = parser_xref_tag (ident_loc, code, ident);
1969   return ret;
1970 }
1971
1972 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1973    the trailing semicolon.
1974
1975    struct-declaration:
1976      specifier-qualifier-list struct-declarator-list
1977
1978    specifier-qualifier-list:
1979      type-specifier specifier-qualifier-list[opt]
1980      type-qualifier specifier-qualifier-list[opt]
1981      attributes specifier-qualifier-list[opt]
1982
1983    struct-declarator-list:
1984      struct-declarator
1985      struct-declarator-list , attributes[opt] struct-declarator
1986
1987    struct-declarator:
1988      declarator attributes[opt]
1989      declarator[opt] : constant-expression attributes[opt]
1990
1991    GNU extensions:
1992
1993    struct-declaration:
1994      __extension__ struct-declaration
1995      specifier-qualifier-list
1996
1997    Unlike the ISO C syntax, semicolons are handled elsewhere.  The use
1998    of attributes where shown is a GNU extension.  In GNU C, we accept
1999    any expression without commas in the syntax (assignment
2000    expressions, not just conditional expressions); assignment
2001    expressions will be diagnosed as non-constant.  */
2002
2003 static tree
2004 c_parser_struct_declaration (c_parser *parser)
2005 {
2006   struct c_declspecs *specs;
2007   tree prefix_attrs;
2008   tree all_prefix_attrs;
2009   tree decls;
2010   location_t decl_loc;
2011   if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2012     {
2013       int ext;
2014       tree decl;
2015       ext = disable_extension_diagnostics ();
2016       c_parser_consume_token (parser);
2017       decl = c_parser_struct_declaration (parser);
2018       restore_extension_diagnostics (ext);
2019       return decl;
2020     }
2021   specs = build_null_declspecs ();
2022   decl_loc = c_parser_peek_token (parser)->location;
2023   c_parser_declspecs (parser, specs, false, true, true);
2024   if (parser->error)
2025     return NULL_TREE;
2026   if (!specs->declspecs_seen_p)
2027     {
2028       c_parser_error (parser, "expected specifier-qualifier-list");
2029       return NULL_TREE;
2030     }
2031   finish_declspecs (specs);
2032   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2033     {
2034       tree ret;
2035       if (!specs->type_seen_p)
2036         {
2037           pedwarn (decl_loc, OPT_pedantic,
2038                    "ISO C forbids member declarations with no members");
2039           shadow_tag_warned (specs, pedantic);
2040           ret = NULL_TREE;
2041         }
2042       else
2043         {
2044           /* Support for unnamed structs or unions as members of
2045              structs or unions (which is [a] useful and [b] supports
2046              MS P-SDK).  */
2047           tree attrs = NULL;
2048
2049           ret = grokfield (c_parser_peek_token (parser)->location,
2050                            build_id_declarator (NULL_TREE), specs,
2051                            NULL_TREE, &attrs);
2052           if (ret)
2053             decl_attributes (&ret, attrs, 0);
2054         }
2055       return ret;
2056     }
2057   pending_xref_error ();
2058   prefix_attrs = specs->attrs;
2059   all_prefix_attrs = prefix_attrs;
2060   specs->attrs = NULL_TREE;
2061   decls = NULL_TREE;
2062   while (true)
2063     {
2064       /* Declaring one or more declarators or un-named bit-fields.  */
2065       struct c_declarator *declarator;
2066       bool dummy = false;
2067       if (c_parser_next_token_is (parser, CPP_COLON))
2068         declarator = build_id_declarator (NULL_TREE);
2069       else
2070         declarator = c_parser_declarator (parser, specs->type_seen_p,
2071                                           C_DTR_NORMAL, &dummy);
2072       if (declarator == NULL)
2073         {
2074           c_parser_skip_to_end_of_block_or_statement (parser);
2075           break;
2076         }
2077       if (c_parser_next_token_is (parser, CPP_COLON)
2078           || c_parser_next_token_is (parser, CPP_COMMA)
2079           || c_parser_next_token_is (parser, CPP_SEMICOLON)
2080           || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2081           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2082         {
2083           tree postfix_attrs = NULL_TREE;
2084           tree width = NULL_TREE;
2085           tree d;
2086           if (c_parser_next_token_is (parser, CPP_COLON))
2087             {
2088               c_parser_consume_token (parser);
2089               width = c_parser_expr_no_commas (parser, NULL).value;
2090             }
2091           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2092             postfix_attrs = c_parser_attributes (parser);
2093           d = grokfield (c_parser_peek_token (parser)->location,
2094                          declarator, specs, width, &all_prefix_attrs);
2095           decl_attributes (&d, chainon (postfix_attrs,
2096                                         all_prefix_attrs), 0);
2097           TREE_CHAIN (d) = decls;
2098           decls = d;
2099           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2100             all_prefix_attrs = chainon (c_parser_attributes (parser),
2101                                         prefix_attrs);
2102           else
2103             all_prefix_attrs = prefix_attrs;
2104           if (c_parser_next_token_is (parser, CPP_COMMA))
2105             c_parser_consume_token (parser);
2106           else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2107                    || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2108             {
2109               /* Semicolon consumed in caller.  */
2110               break;
2111             }
2112           else
2113             {
2114               c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2115               break;
2116             }
2117         }
2118       else
2119         {
2120           c_parser_error (parser,
2121                           "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2122                           "%<__attribute__%>");
2123           break;
2124         }
2125     }
2126   return decls;
2127 }
2128
2129 /* Parse a typeof specifier (a GNU extension).
2130
2131    typeof-specifier:
2132      typeof ( expression )
2133      typeof ( type-name )
2134 */
2135
2136 static struct c_typespec
2137 c_parser_typeof_specifier (c_parser *parser)
2138 {
2139   struct c_typespec ret;
2140   ret.kind = ctsk_typeof;
2141   ret.spec = error_mark_node;
2142   ret.expr = NULL_TREE;
2143   ret.expr_const_operands = true;
2144   gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2145   c_parser_consume_token (parser);
2146   c_inhibit_evaluation_warnings++;
2147   in_typeof++;
2148   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2149     {
2150       c_inhibit_evaluation_warnings--;
2151       in_typeof--;
2152       return ret;
2153     }
2154   if (c_parser_next_token_starts_typename (parser))
2155     {
2156       struct c_type_name *type = c_parser_type_name (parser);
2157       c_inhibit_evaluation_warnings--;
2158       in_typeof--;
2159       if (type != NULL)
2160         {
2161           ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2162           pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2163         }
2164     }
2165   else
2166     {
2167       bool was_vm;
2168       location_t here = c_parser_peek_token (parser)->location;
2169       struct c_expr expr = c_parser_expression (parser);
2170       c_inhibit_evaluation_warnings--;
2171       in_typeof--;
2172       if (TREE_CODE (expr.value) == COMPONENT_REF
2173           && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2174         error_at (here, "%<typeof%> applied to a bit-field");
2175       mark_exp_read (expr.value);
2176       ret.spec = TREE_TYPE (expr.value);
2177       was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2178       /* This is returned with the type so that when the type is
2179          evaluated, this can be evaluated.  */
2180       if (was_vm)
2181         ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2182       pop_maybe_used (was_vm);
2183     }
2184   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2185   return ret;
2186 }
2187
2188 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2189    6.5.5, C99 6.7.5, 6.7.6).  If TYPE_SEEN_P then a typedef name may
2190    be redeclared; otherwise it may not.  KIND indicates which kind of
2191    declarator is wanted.  Returns a valid declarator except in the
2192    case of a syntax error in which case NULL is returned.  *SEEN_ID is
2193    set to true if an identifier being declared is seen; this is used
2194    to diagnose bad forms of abstract array declarators and to
2195    determine whether an identifier list is syntactically permitted.
2196
2197    declarator:
2198      pointer[opt] direct-declarator
2199
2200    direct-declarator:
2201      identifier
2202      ( attributes[opt] declarator )
2203      direct-declarator array-declarator
2204      direct-declarator ( parameter-type-list )
2205      direct-declarator ( identifier-list[opt] )
2206
2207    pointer:
2208      * type-qualifier-list[opt]
2209      * type-qualifier-list[opt] pointer
2210
2211    type-qualifier-list:
2212      type-qualifier
2213      attributes
2214      type-qualifier-list type-qualifier
2215      type-qualifier-list attributes
2216
2217    parameter-type-list:
2218      parameter-list
2219      parameter-list , ...
2220
2221    parameter-list:
2222      parameter-declaration
2223      parameter-list , parameter-declaration
2224
2225    parameter-declaration:
2226      declaration-specifiers declarator attributes[opt]
2227      declaration-specifiers abstract-declarator[opt] attributes[opt]
2228
2229    identifier-list:
2230      identifier
2231      identifier-list , identifier
2232
2233    abstract-declarator:
2234      pointer
2235      pointer[opt] direct-abstract-declarator
2236
2237    direct-abstract-declarator:
2238      ( attributes[opt] abstract-declarator )
2239      direct-abstract-declarator[opt] array-declarator
2240      direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2241
2242    GNU extensions:
2243
2244    direct-declarator:
2245      direct-declarator ( parameter-forward-declarations
2246                          parameter-type-list[opt] )
2247
2248    direct-abstract-declarator:
2249      direct-abstract-declarator[opt] ( parameter-forward-declarations
2250                                        parameter-type-list[opt] )
2251
2252    parameter-forward-declarations:
2253      parameter-list ;
2254      parameter-forward-declarations parameter-list ;
2255
2256    The uses of attributes shown above are GNU extensions.
2257
2258    Some forms of array declarator are not included in C99 in the
2259    syntax for abstract declarators; these are disallowed elsewhere.
2260    This may be a defect (DR#289).
2261
2262    This function also accepts an omitted abstract declarator as being
2263    an abstract declarator, although not part of the formal syntax.  */
2264
2265 static struct c_declarator *
2266 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2267                      bool *seen_id)
2268 {
2269   /* Parse any initial pointer part.  */
2270   if (c_parser_next_token_is (parser, CPP_MULT))
2271     {
2272       struct c_declspecs *quals_attrs = build_null_declspecs ();
2273       struct c_declarator *inner;
2274       c_parser_consume_token (parser);
2275       c_parser_declspecs (parser, quals_attrs, false, false, true);
2276       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2277       if (inner == NULL)
2278         return NULL;
2279       else
2280         return make_pointer_declarator (quals_attrs, inner);
2281     }
2282   /* Now we have a direct declarator, direct abstract declarator or
2283      nothing (which counts as a direct abstract declarator here).  */
2284   return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2285 }
2286
2287 /* Parse a direct declarator or direct abstract declarator; arguments
2288    as c_parser_declarator.  */
2289
2290 static struct c_declarator *
2291 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2292                             bool *seen_id)
2293 {
2294   /* The direct declarator must start with an identifier (possibly
2295      omitted) or a parenthesized declarator (possibly abstract).  In
2296      an ordinary declarator, initial parentheses must start a
2297      parenthesized declarator.  In an abstract declarator or parameter
2298      declarator, they could start a parenthesized declarator or a
2299      parameter list.  To tell which, the open parenthesis and any
2300      following attributes must be read.  If a declaration specifier
2301      follows, then it is a parameter list; if the specifier is a
2302      typedef name, there might be an ambiguity about redeclaring it,
2303      which is resolved in the direction of treating it as a typedef
2304      name.  If a close parenthesis follows, it is also an empty
2305      parameter list, as the syntax does not permit empty abstract
2306      declarators.  Otherwise, it is a parenthesized declarator (in
2307      which case the analysis may be repeated inside it, recursively).
2308
2309      ??? There is an ambiguity in a parameter declaration "int
2310      (__attribute__((foo)) x)", where x is not a typedef name: it
2311      could be an abstract declarator for a function, or declare x with
2312      parentheses.  The proper resolution of this ambiguity needs
2313      documenting.  At present we follow an accident of the old
2314      parser's implementation, whereby the first parameter must have
2315      some declaration specifiers other than just attributes.  Thus as
2316      a parameter declaration it is treated as a parenthesized
2317      parameter named x, and as an abstract declarator it is
2318      rejected.
2319
2320      ??? Also following the old parser, attributes inside an empty
2321      parameter list are ignored, making it a list not yielding a
2322      prototype, rather than giving an error or making it have one
2323      parameter with implicit type int.
2324
2325      ??? Also following the old parser, typedef names may be
2326      redeclared in declarators, but not Objective-C class names.  */
2327
2328   if (kind != C_DTR_ABSTRACT
2329       && c_parser_next_token_is (parser, CPP_NAME)
2330       && ((type_seen_p
2331            && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2332           || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2333     {
2334       struct c_declarator *inner
2335         = build_id_declarator (c_parser_peek_token (parser)->value);
2336       *seen_id = true;
2337       inner->id_loc = c_parser_peek_token (parser)->location;
2338       c_parser_consume_token (parser);
2339       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2340     }
2341
2342   if (kind != C_DTR_NORMAL
2343       && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2344     {
2345       struct c_declarator *inner = build_id_declarator (NULL_TREE);
2346       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2347     }
2348
2349   /* Either we are at the end of an abstract declarator, or we have
2350      parentheses.  */
2351
2352   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2353     {
2354       tree attrs;
2355       struct c_declarator *inner;
2356       c_parser_consume_token (parser);
2357       attrs = c_parser_attributes (parser);
2358       if (kind != C_DTR_NORMAL
2359           && (c_parser_next_token_starts_declspecs (parser)
2360               || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2361         {
2362           struct c_arg_info *args
2363             = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2364                                          attrs);
2365           if (args == NULL)
2366             return NULL;
2367           else
2368             {
2369               inner
2370                 = build_function_declarator (args,
2371                                              build_id_declarator (NULL_TREE));
2372               return c_parser_direct_declarator_inner (parser, *seen_id,
2373                                                        inner);
2374             }
2375         }
2376       /* A parenthesized declarator.  */
2377       inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2378       if (inner != NULL && attrs != NULL)
2379         inner = build_attrs_declarator (attrs, inner);
2380       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2381         {
2382           c_parser_consume_token (parser);
2383           if (inner == NULL)
2384             return NULL;
2385           else
2386             return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2387         }
2388       else
2389         {
2390           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2391                                      "expected %<)%>");
2392           return NULL;
2393         }
2394     }
2395   else
2396     {
2397       if (kind == C_DTR_NORMAL)
2398         {
2399           c_parser_error (parser, "expected identifier or %<(%>");
2400           return NULL;
2401         }
2402       else
2403         return build_id_declarator (NULL_TREE);
2404     }
2405 }
2406
2407 /* Parse part of a direct declarator or direct abstract declarator,
2408    given that some (in INNER) has already been parsed; ID_PRESENT is
2409    true if an identifier is present, false for an abstract
2410    declarator.  */
2411
2412 static struct c_declarator *
2413 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2414                                   struct c_declarator *inner)
2415 {
2416   /* Parse a sequence of array declarators and parameter lists.  */
2417   if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2418     {
2419       location_t brace_loc = c_parser_peek_token (parser)->location;
2420       struct c_declarator *declarator;
2421       struct c_declspecs *quals_attrs = build_null_declspecs ();
2422       bool static_seen;
2423       bool star_seen;
2424       tree dimen;
2425       c_parser_consume_token (parser);
2426       c_parser_declspecs (parser, quals_attrs, false, false, true);
2427       static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2428       if (static_seen)
2429         c_parser_consume_token (parser);
2430       if (static_seen && !quals_attrs->declspecs_seen_p)
2431         c_parser_declspecs (parser, quals_attrs, false, false, true);
2432       if (!quals_attrs->declspecs_seen_p)
2433         quals_attrs = NULL;
2434       /* If "static" is present, there must be an array dimension.
2435          Otherwise, there may be a dimension, "*", or no
2436          dimension.  */
2437       if (static_seen)
2438         {
2439           star_seen = false;
2440           dimen = c_parser_expr_no_commas (parser, NULL).value;
2441         }
2442       else
2443         {
2444           if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2445             {
2446               dimen = NULL_TREE;
2447               star_seen = false;
2448             }
2449           else if (c_parser_next_token_is (parser, CPP_MULT))
2450             {
2451               if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2452                 {
2453                   dimen = NULL_TREE;
2454                   star_seen = true;
2455                   c_parser_consume_token (parser);
2456                 }
2457               else
2458                 {
2459                   star_seen = false;
2460                   dimen = c_parser_expr_no_commas (parser, NULL).value;
2461                 }
2462             }
2463           else
2464             {
2465               star_seen = false;
2466               dimen = c_parser_expr_no_commas (parser, NULL).value;
2467             }
2468         }
2469       if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2470         c_parser_consume_token (parser);
2471       else
2472         {
2473           c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2474                                      "expected %<]%>");
2475           return NULL;
2476         }
2477       if (dimen)
2478         mark_exp_read (dimen);
2479       declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2480                                            static_seen, star_seen);
2481       if (declarator == NULL)
2482         return NULL;
2483       inner = set_array_declarator_inner (declarator, inner);
2484       return c_parser_direct_declarator_inner (parser, id_present, inner);
2485     }
2486   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2487     {
2488       tree attrs;
2489       struct c_arg_info *args;
2490       c_parser_consume_token (parser);
2491       attrs = c_parser_attributes (parser);
2492       args = c_parser_parms_declarator (parser, id_present, attrs);
2493       if (args == NULL)
2494         return NULL;
2495       else
2496         {
2497           inner = build_function_declarator (args, inner);
2498           return c_parser_direct_declarator_inner (parser, id_present, inner);
2499         }
2500     }
2501   return inner;
2502 }
2503
2504 /* Parse a parameter list or identifier list, including the closing
2505    parenthesis but not the opening one.  ATTRS are the attributes at
2506    the start of the list.  ID_LIST_OK is true if an identifier list is
2507    acceptable; such a list must not have attributes at the start.  */
2508
2509 static struct c_arg_info *
2510 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2511 {
2512   push_scope ();
2513   declare_parm_level ();
2514   /* If the list starts with an identifier, it is an identifier list.
2515      Otherwise, it is either a prototype list or an empty list.  */
2516   if (id_list_ok
2517       && !attrs
2518       && c_parser_next_token_is (parser, CPP_NAME)
2519       && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2520     {
2521       tree list = NULL_TREE, *nextp = &list;
2522       while (c_parser_next_token_is (parser, CPP_NAME)
2523              && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2524         {
2525           *nextp = build_tree_list (NULL_TREE,
2526                                     c_parser_peek_token (parser)->value);
2527           nextp = & TREE_CHAIN (*nextp);
2528           c_parser_consume_token (parser);
2529           if (c_parser_next_token_is_not (parser, CPP_COMMA))
2530             break;
2531           c_parser_consume_token (parser);
2532           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2533             {
2534               c_parser_error (parser, "expected identifier");
2535               break;
2536             }
2537         }
2538       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2539         {
2540           struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2541           ret->parms = 0;
2542           ret->tags = 0;
2543           ret->types = list;
2544           ret->others = 0;
2545           ret->pending_sizes = 0;
2546           ret->had_vla_unspec = 0;
2547           c_parser_consume_token (parser);
2548           pop_scope ();
2549           return ret;
2550         }
2551       else
2552         {
2553           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2554                                      "expected %<)%>");
2555           pop_scope ();
2556           return NULL;
2557         }
2558     }
2559   else
2560     {
2561       struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2562       pop_scope ();
2563       return ret;
2564     }
2565 }
2566
2567 /* Parse a parameter list (possibly empty), including the closing
2568    parenthesis but not the opening one.  ATTRS are the attributes at
2569    the start of the list.  */
2570
2571 static struct c_arg_info *
2572 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2573 {
2574   bool good_parm = false;
2575   /* ??? Following the old parser, forward parameter declarations may
2576      use abstract declarators, and if no real parameter declarations
2577      follow the forward declarations then this is not diagnosed.  Also
2578      note as above that attributes are ignored as the only contents of
2579      the parentheses, or as the only contents after forward
2580      declarations.  */
2581   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2582     {
2583       struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2584       ret->parms = 0;
2585       ret->tags = 0;
2586       ret->types = 0;
2587       ret->others = 0;
2588       ret->pending_sizes = 0;
2589       ret->had_vla_unspec = 0;
2590       c_parser_consume_token (parser);
2591       return ret;
2592     }
2593   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2594     {
2595       struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2596       ret->parms = 0;
2597       ret->tags = 0;
2598       ret->others = 0;
2599       ret->pending_sizes = 0;
2600       ret->had_vla_unspec = 0;
2601       /* Suppress -Wold-style-definition for this case.  */
2602       ret->types = error_mark_node;
2603       error_at (c_parser_peek_token (parser)->location,
2604                 "ISO C requires a named argument before %<...%>");
2605       c_parser_consume_token (parser);
2606       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2607         {
2608           c_parser_consume_token (parser);
2609           return ret;
2610         }
2611       else
2612         {
2613           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2614                                      "expected %<)%>");
2615           return NULL;
2616         }
2617     }
2618   /* Nonempty list of parameters, either terminated with semicolon
2619      (forward declarations; recurse) or with close parenthesis (normal
2620      function) or with ", ... )" (variadic function).  */
2621   while (true)
2622     {
2623       /* Parse a parameter.  */
2624       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2625       attrs = NULL_TREE;
2626       if (parm != NULL)
2627         {
2628           good_parm = true;
2629           push_parm_decl (parm);
2630         }
2631       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2632         {
2633           tree new_attrs;
2634           c_parser_consume_token (parser);
2635           mark_forward_parm_decls ();
2636           new_attrs = c_parser_attributes (parser);
2637           return c_parser_parms_list_declarator (parser, new_attrs);
2638         }
2639       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2640         {
2641           c_parser_consume_token (parser);
2642           if (good_parm)
2643             return get_parm_info (false);
2644           else
2645             {
2646               struct c_arg_info *ret
2647                 = XOBNEW (&parser_obstack, struct c_arg_info);
2648               ret->parms = 0;
2649               ret->tags = 0;
2650               ret->types = 0;
2651               ret->others = 0;
2652               ret->pending_sizes = 0;
2653               ret->had_vla_unspec = 0;
2654               return ret;
2655             }
2656         }
2657       if (!c_parser_require (parser, CPP_COMMA,
2658                              "expected %<;%>, %<,%> or %<)%>"))
2659         {
2660           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2661           get_pending_sizes ();
2662           return NULL;
2663         }
2664       if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2665         {
2666           c_parser_consume_token (parser);
2667           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2668             {
2669               c_parser_consume_token (parser);
2670               if (good_parm)
2671                 return get_parm_info (true);
2672               else
2673                 {
2674                   struct c_arg_info *ret
2675                     = XOBNEW (&parser_obstack, struct c_arg_info);
2676                   ret->parms = 0;
2677                   ret->tags = 0;
2678                   ret->types = 0;
2679                   ret->others = 0;
2680                   ret->pending_sizes = 0;
2681                   ret->had_vla_unspec = 0;
2682                   return ret;
2683                 }
2684             }
2685           else
2686             {
2687               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2688                                          "expected %<)%>");
2689               get_pending_sizes ();
2690               return NULL;
2691             }
2692         }
2693     }
2694 }
2695
2696 /* Parse a parameter declaration.  ATTRS are the attributes at the
2697    start of the declaration if it is the first parameter.  */
2698
2699 static struct c_parm *
2700 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2701 {
2702   struct c_declspecs *specs;
2703   struct c_declarator *declarator;
2704   tree prefix_attrs;
2705   tree postfix_attrs = NULL_TREE;
2706   bool dummy = false;
2707   if (!c_parser_next_token_starts_declspecs (parser))
2708     {
2709       /* ??? In some Objective-C cases '...' isn't applicable so there
2710          should be a different message.  */
2711       c_parser_error (parser,
2712                       "expected declaration specifiers or %<...%>");
2713       c_parser_skip_to_end_of_parameter (parser);
2714       return NULL;
2715     }
2716   specs = build_null_declspecs ();
2717   if (attrs)
2718     {
2719       declspecs_add_attrs (specs, attrs);
2720       attrs = NULL_TREE;
2721     }
2722   c_parser_declspecs (parser, specs, true, true, true);
2723   finish_declspecs (specs);
2724   pending_xref_error ();
2725   prefix_attrs = specs->attrs;
2726   specs->attrs = NULL_TREE;
2727   declarator = c_parser_declarator (parser, specs->type_seen_p,
2728                                     C_DTR_PARM, &dummy);
2729   if (declarator == NULL)
2730     {
2731       c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2732       return NULL;
2733     }
2734   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2735     postfix_attrs = c_parser_attributes (parser);
2736   return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2737                        declarator);
2738 }
2739
2740 /* Parse a string literal in an asm expression.  It should not be
2741    translated, and wide string literals are an error although
2742    permitted by the syntax.  This is a GNU extension.
2743
2744    asm-string-literal:
2745      string-literal
2746
2747    ??? At present, following the old parser, the caller needs to have
2748    set lex_untranslated_string to 1.  It would be better to follow the
2749    C++ parser rather than using this kludge.  */
2750
2751 static tree
2752 c_parser_asm_string_literal (c_parser *parser)
2753 {
2754   tree str;
2755   if (c_parser_next_token_is (parser, CPP_STRING))
2756     {
2757       str = c_parser_peek_token (parser)->value;
2758       c_parser_consume_token (parser);
2759     }
2760   else if (c_parser_next_token_is (parser, CPP_WSTRING))
2761     {
2762       error_at (c_parser_peek_token (parser)->location,
2763                 "wide string literal in %<asm%>");
2764       str = build_string (1, "");
2765       c_parser_consume_token (parser);
2766     }
2767   else
2768     {
2769       c_parser_error (parser, "expected string literal");
2770       str = NULL_TREE;
2771     }
2772   return str;
2773 }
2774
2775 /* Parse a simple asm expression.  This is used in restricted
2776    contexts, where a full expression with inputs and outputs does not
2777    make sense.  This is a GNU extension.
2778
2779    simple-asm-expr:
2780      asm ( asm-string-literal )
2781 */
2782
2783 static tree
2784 c_parser_simple_asm_expr (c_parser *parser)
2785 {
2786   tree str;
2787   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2788   /* ??? Follow the C++ parser rather than using the
2789      lex_untranslated_string kludge.  */
2790   parser->lex_untranslated_string = true;
2791   c_parser_consume_token (parser);
2792   if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2793     {
2794       parser->lex_untranslated_string = false;
2795       return NULL_TREE;
2796     }
2797   str = c_parser_asm_string_literal (parser);
2798   parser->lex_untranslated_string = false;
2799   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2800     {
2801       c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2802       return NULL_TREE;
2803     }
2804   return str;
2805 }
2806
2807 /* Parse (possibly empty) attributes.  This is a GNU extension.
2808
2809    attributes:
2810      empty
2811      attributes attribute
2812
2813    attribute:
2814      __attribute__ ( ( attribute-list ) )
2815
2816    attribute-list:
2817      attrib
2818      attribute_list , attrib
2819
2820    attrib:
2821      empty
2822      any-word
2823      any-word ( identifier )
2824      any-word ( identifier , nonempty-expr-list )
2825      any-word ( expr-list )
2826
2827    where the "identifier" must not be declared as a type, and
2828    "any-word" may be any identifier (including one declared as a
2829    type), a reserved word storage class specifier, type specifier or
2830    type qualifier.  ??? This still leaves out most reserved keywords
2831    (following the old parser), shouldn't we include them, and why not
2832    allow identifiers declared as types to start the arguments?  */
2833
2834 static tree
2835 c_parser_attributes (c_parser *parser)
2836 {
2837   tree attrs = NULL_TREE;
2838   while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2839     {
2840       /* ??? Follow the C++ parser rather than using the
2841          lex_untranslated_string kludge.  */
2842       parser->lex_untranslated_string = true;
2843       c_parser_consume_token (parser);
2844       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2845         {
2846           parser->lex_untranslated_string = false;
2847           return attrs;
2848         }
2849       if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2850         {
2851           parser->lex_untranslated_string = false;
2852           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2853           return attrs;
2854         }
2855       /* Parse the attribute list.  */
2856       while (c_parser_next_token_is (parser, CPP_COMMA)
2857              || c_parser_next_token_is (parser, CPP_NAME)
2858              || c_parser_next_token_is (parser, CPP_KEYWORD))
2859         {
2860           tree attr, attr_name, attr_args;
2861           VEC(tree,gc) *expr_list;
2862           if (c_parser_next_token_is (parser, CPP_COMMA))
2863             {
2864               c_parser_consume_token (parser);
2865               continue;
2866             }
2867           if (c_parser_next_token_is (parser, CPP_KEYWORD))
2868             {
2869               /* ??? See comment above about what keywords are
2870                  accepted here.  */
2871               bool ok;
2872               switch (c_parser_peek_token (parser)->keyword)
2873                 {
2874                 case RID_STATIC:
2875                 case RID_UNSIGNED:
2876                 case RID_LONG:
2877                 case RID_CONST:
2878                 case RID_EXTERN:
2879                 case RID_REGISTER:
2880                 case RID_TYPEDEF:
2881                 case RID_SHORT:
2882                 case RID_INLINE:
2883                 case RID_VOLATILE:
2884                 case RID_SIGNED:
2885                 case RID_AUTO:
2886                 case RID_RESTRICT:
2887                 case RID_COMPLEX:
2888                 case RID_THREAD:
2889                 case RID_INT:
2890                 case RID_CHAR:
2891                 case RID_FLOAT:
2892                 case RID_DOUBLE:
2893                 case RID_VOID:
2894                 case RID_DFLOAT32:
2895                 case RID_DFLOAT64:
2896                 case RID_DFLOAT128:
2897                 case RID_BOOL:
2898                 case RID_FRACT:
2899                 case RID_ACCUM:
2900                 case RID_SAT:
2901                   ok = true;
2902                   break;
2903                 default:
2904                   ok = false;
2905                   break;
2906                 }
2907               if (!ok)
2908                 break;
2909               /* Accept __attribute__((__const)) as __attribute__((const))
2910                  etc.  */
2911               attr_name
2912                 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2913             }
2914           else
2915             attr_name = c_parser_peek_token (parser)->value;
2916           c_parser_consume_token (parser);
2917           if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2918             {
2919               attr = build_tree_list (attr_name, NULL_TREE);
2920               attrs = chainon (attrs, attr);
2921               continue;
2922             }
2923           c_parser_consume_token (parser);
2924           /* Parse the attribute contents.  If they start with an
2925              identifier which is followed by a comma or close
2926              parenthesis, then the arguments start with that
2927              identifier; otherwise they are an expression list.  */
2928           if (c_parser_next_token_is (parser, CPP_NAME)
2929               && c_parser_peek_token (parser)->id_kind == C_ID_ID
2930               && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2931                   || (c_parser_peek_2nd_token (parser)->type
2932                       == CPP_CLOSE_PAREN)))
2933             {
2934               tree arg1 = c_parser_peek_token (parser)->value;
2935               c_parser_consume_token (parser);
2936               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2937                 attr_args = build_tree_list (NULL_TREE, arg1);
2938               else
2939                 {
2940                   tree tree_list;
2941                   c_parser_consume_token (parser);
2942                   expr_list = c_parser_expr_list (parser, false, true, NULL);
2943                   tree_list = build_tree_list_vec (expr_list);
2944                   attr_args = tree_cons (NULL_TREE, arg1, tree_list);
2945                   release_tree_vector (expr_list);
2946                 }
2947             }
2948           else
2949             {
2950               if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2951                 attr_args = NULL_TREE;
2952               else
2953                 {
2954                   expr_list = c_parser_expr_list (parser, false, true, NULL);
2955                   attr_args = build_tree_list_vec (expr_list);
2956                   release_tree_vector (expr_list);
2957                 }
2958             }
2959           attr = build_tree_list (attr_name, attr_args);
2960           if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2961             c_parser_consume_token (parser);
2962           else
2963             {
2964               parser->lex_untranslated_string = false;
2965               c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2966                                          "expected %<)%>");
2967               return attrs;
2968             }
2969           attrs = chainon (attrs, attr);
2970         }
2971       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2972         c_parser_consume_token (parser);
2973       else
2974         {
2975           parser->lex_untranslated_string = false;
2976           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2977                                      "expected %<)%>");
2978           return attrs;
2979         }
2980       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2981         c_parser_consume_token (parser);
2982       else
2983         {
2984           parser->lex_untranslated_string = false;
2985           c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2986                                      "expected %<)%>");
2987           return attrs;
2988         }
2989       parser->lex_untranslated_string = false;
2990     }
2991   return attrs;
2992 }
2993
2994 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2995
2996    type-name:
2997      specifier-qualifier-list abstract-declarator[opt]
2998 */
2999
3000 static struct c_type_name *
3001 c_parser_type_name (c_parser *parser)
3002 {
3003   struct c_declspecs *specs = build_null_declspecs ();
3004   struct c_declarator *declarator;
3005   struct c_type_name *ret;
3006   bool dummy = false;
3007   c_parser_declspecs (parser, specs, false, true, true);
3008   if (!specs->declspecs_seen_p)
3009     {
3010       c_parser_error (parser, "expected specifier-qualifier-list");
3011       return NULL;
3012     }
3013   pending_xref_error ();
3014   finish_declspecs (specs);
3015   declarator = c_parser_declarator (parser, specs->type_seen_p,
3016                                     C_DTR_ABSTRACT, &dummy);
3017   if (declarator == NULL)
3018     return NULL;
3019   ret = XOBNEW (&parser_obstack, struct c_type_name);
3020   ret->specs = specs;
3021   ret->declarator = declarator;
3022   return ret;
3023 }
3024
3025 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3026
3027    initializer:
3028      assignment-expression
3029      { initializer-list }
3030      { initializer-list , }
3031
3032    initializer-list:
3033      designation[opt] initializer
3034      initializer-list , designation[opt] initializer
3035
3036    designation:
3037      designator-list =
3038
3039    designator-list:
3040      designator
3041      designator-list designator
3042
3043    designator:
3044      array-designator
3045      . identifier
3046
3047    array-designator:
3048      [ constant-expression ]
3049
3050    GNU extensions:
3051
3052    initializer:
3053      { }
3054
3055    designation:
3056      array-designator
3057      identifier :
3058
3059    array-designator:
3060      [ constant-expression ... constant-expression ]
3061
3062    Any expression without commas is accepted in the syntax for the
3063    constant-expressions, with non-constant expressions rejected later.
3064
3065    This function is only used for top-level initializers; for nested
3066    ones, see c_parser_initval.  */
3067
3068 static struct c_expr
3069 c_parser_initializer (c_parser *parser)
3070 {
3071   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3072     return c_parser_braced_init (parser, NULL_TREE, false);
3073   else
3074     {
3075       struct c_expr ret;
3076       location_t loc = c_parser_peek_token (parser)->location;
3077       ret = c_parser_expr_no_commas (parser, NULL);
3078       if (TREE_CODE (ret.value) != STRING_CST
3079           && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3080         ret = default_function_array_read_conversion (loc, ret);
3081       return ret;
3082     }
3083 }
3084
3085 /* Parse a braced initializer list.  TYPE is the type specified for a
3086    compound literal, and NULL_TREE for other initializers and for
3087    nested braced lists.  NESTED_P is true for nested braced lists,
3088    false for the list of a compound literal or the list that is the
3089    top-level initializer in a declaration.  */
3090
3091 static struct c_expr
3092 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3093 {
3094   struct c_expr ret;
3095   struct obstack braced_init_obstack;
3096   location_t brace_loc = c_parser_peek_token (parser)->location;
3097   gcc_obstack_init (&braced_init_obstack);
3098   gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3099   c_parser_consume_token (parser);
3100   if (nested_p)
3101     push_init_level (0, &braced_init_obstack);
3102   else
3103     really_start_incremental_init (type);
3104   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3105     {
3106       pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3107     }
3108   else
3109     {
3110       /* Parse a non-empty initializer list, possibly with a trailing
3111          comma.  */
3112       while (true)
3113         {
3114           c_parser_initelt (parser, &braced_init_obstack);
3115           if (parser->error)
3116             break;
3117           if (c_parser_next_token_is (parser, CPP_COMMA))
3118             c_parser_consume_token (parser);
3119           else
3120             break;
3121           if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3122             break;
3123         }
3124     }
3125   if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3126     {
3127       ret.value = error_mark_node;
3128       ret.original_code = ERROR_MARK;
3129       ret.original_type = NULL;
3130       c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3131       pop_init_level (0, &braced_init_obstack);
3132       obstack_free (&braced_init_obstack, NULL);
3133       return ret;
3134     }
3135   c_parser_consume_token (parser);
3136   ret = pop_init_level (0, &braced_init_obstack);
3137   obstack_free (&braced_init_obstack, NULL);
3138   return ret;
3139 }
3140
3141 /* Parse a nested initializer, including designators.  */
3142
3143 static void
3144 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3145 {
3146   /* Parse any designator or designator list.  A single array
3147      designator may have the subsequent "=" omitted in GNU C, but a
3148      longer list or a structure member designator may not.  */
3149   if (c_parser_next_token_is (parser, CPP_NAME)
3150       && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3151     {
3152       /* Old-style structure member designator.  */
3153       set_init_label (c_parser_peek_token (parser)->value,
3154                       braced_init_obstack);
3155       /* Use the colon as the error location.  */
3156       pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3157                "obsolete use of designated initializer with %<:%>");
3158       c_parser_consume_token (parser);
3159       c_parser_consume_token (parser);
3160     }
3161   else
3162     {
3163       /* des_seen is 0 if there have been no designators, 1 if there
3164          has been a single array designator and 2 otherwise.  */
3165       int des_seen = 0;
3166       /* Location of a designator.  */
3167       location_t des_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3168       while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3169              || c_parser_next_token_is (parser, CPP_DOT))
3170         {
3171           int des_prev = des_seen;
3172           if (!des_seen)
3173             des_loc = c_parser_peek_token (parser)->location;
3174           if (des_seen < 2)
3175             des_seen++;
3176           if (c_parser_next_token_is (parser, CPP_DOT))
3177             {
3178               des_seen = 2;
3179               c_parser_consume_token (parser);
3180               if (c_parser_next_token_is (parser, CPP_NAME))
3181                 {
3182                   set_init_label (c_parser_peek_token (parser)->value,
3183                                   braced_init_obstack);
3184                   c_parser_consume_token (parser);
3185                 }
3186               else
3187                 {
3188                   struct c_expr init;
3189                   init.value = error_mark_node;
3190                   init.original_code = ERROR_MARK;
3191                   init.original_type = NULL;
3192                   c_parser_error (parser, "expected identifier");
3193                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3194                   process_init_element (init, false, braced_init_obstack);
3195                   return;
3196                 }
3197             }
3198           else
3199             {
3200               tree first, second;
3201               location_t ellipsis_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3202               /* ??? Following the old parser, [ objc-receiver
3203                  objc-message-args ] is accepted as an initializer,
3204                  being distinguished from a designator by what follows
3205                  the first assignment expression inside the square
3206                  brackets, but after a first array designator a
3207                  subsequent square bracket is for Objective-C taken to
3208                  start an expression, using the obsolete form of
3209                  designated initializer without '=', rather than
3210                  possibly being a second level of designation: in LALR
3211                  terms, the '[' is shifted rather than reducing
3212                  designator to designator-list.  */
3213               if (des_prev == 1 && c_dialect_objc ())
3214                 {
3215                   des_seen = des_prev;
3216                   break;
3217                 }
3218               if (des_prev == 0 && c_dialect_objc ())
3219                 {
3220                   /* This might be an array designator or an
3221                      Objective-C message expression.  If the former,
3222                      continue parsing here; if the latter, parse the
3223                      remainder of the initializer given the starting
3224                      primary-expression.  ??? It might make sense to
3225                      distinguish when des_prev == 1 as well; see
3226                      previous comment.  */
3227                   tree rec, args;
3228                   struct c_expr mexpr;
3229                   c_parser_consume_token (parser);
3230                   if (c_parser_peek_token (parser)->type == CPP_NAME
3231                       && ((c_parser_peek_token (parser)->id_kind
3232                            == C_ID_TYPENAME)
3233                           || (c_parser_peek_token (parser)->id_kind
3234                               == C_ID_CLASSNAME)))
3235                     {
3236                       /* Type name receiver.  */
3237                       tree id = c_parser_peek_token (parser)->value;
3238                       c_parser_consume_token (parser);
3239                       rec = objc_get_class_reference (id);
3240                       goto parse_message_args;
3241                     }
3242                   first = c_parser_expr_no_commas (parser, NULL).value;
3243                   mark_exp_read (first);
3244                   if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3245                       || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3246                     goto array_desig_after_first;
3247                   /* Expression receiver.  So far only one part
3248                      without commas has been parsed; there might be
3249                      more of the expression.  */
3250                   rec = first;
3251                   while (c_parser_next_token_is (parser, CPP_COMMA))
3252                     {
3253                       struct c_expr next;
3254                       location_t comma_loc, exp_loc;
3255                       comma_loc = c_parser_peek_token (parser)->location;
3256                       c_parser_consume_token (parser);
3257                       exp_loc = c_parser_peek_token (parser)->location;
3258                       next = c_parser_expr_no_commas (parser, NULL);
3259                       next = default_function_array_read_conversion (exp_loc,
3260                                                                      next);
3261                       rec = build_compound_expr (comma_loc, rec, next.value);
3262                     }
3263                 parse_message_args:
3264                   /* Now parse the objc-message-args.  */
3265                   args = c_parser_objc_message_args (parser);
3266                   c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3267                                              "expected %<]%>");
3268                   mexpr.value
3269                     = objc_build_message_expr (build_tree_list (rec, args));
3270                   mexpr.original_code = ERROR_MARK;
3271                   mexpr.original_type = NULL;
3272                   /* Now parse and process the remainder of the
3273                      initializer, starting with this message
3274                      expression as a primary-expression.  */
3275                   c_parser_initval (parser, &mexpr, braced_init_obstack);
3276                   return;
3277                 }
3278               c_parser_consume_token (parser);
3279               first = c_parser_expr_no_commas (parser, NULL).value;
3280               mark_exp_read (first);
3281             array_desig_after_first:
3282               if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3283                 {
3284                   ellipsis_loc = c_parser_peek_token (parser)->location;
3285                   c_parser_consume_token (parser);
3286                   second = c_parser_expr_no_commas (parser, NULL).value;
3287                   mark_exp_read (second);
3288                 }
3289               else
3290                 second = NULL_TREE;
3291               if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3292                 {
3293                   c_parser_consume_token (parser);
3294                   set_init_index (first, second, braced_init_obstack);
3295                   if (second)
3296                     pedwarn (ellipsis_loc, OPT_pedantic,
3297                              "ISO C forbids specifying range of elements to initialize");
3298                 }
3299               else
3300                 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3301                                            "expected %<]%>");
3302             }
3303         }
3304       if (des_seen >= 1)
3305         {
3306           if (c_parser_next_token_is (parser, CPP_EQ))
3307             {
3308               if (!flag_isoc99)
3309                 pedwarn (des_loc, OPT_pedantic,
3310                          "ISO C90 forbids specifying subobject to initialize");
3311               c_parser_consume_token (parser);
3312             }
3313           else
3314             {
3315               if (des_seen == 1)
3316                 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3317                          "obsolete use of designated initializer without %<=%>");
3318               else
3319                 {
3320                   struct c_expr init;
3321                   init.value = error_mark_node;
3322                   init.original_code = ERROR_MARK;
3323                   init.original_type = NULL;
3324                   c_parser_error (parser, "expected %<=%>");
3325                   c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3326                   process_init_element (init, false, braced_init_obstack);
3327                   return;
3328                 }
3329             }
3330         }
3331     }
3332   c_parser_initval (parser, NULL, braced_init_obstack);
3333 }
3334
3335 /* Parse a nested initializer; as c_parser_initializer but parses
3336    initializers within braced lists, after any designators have been
3337    applied.  If AFTER is not NULL then it is an Objective-C message
3338    expression which is the primary-expression starting the
3339    initializer.  */
3340
3341 static void
3342 c_parser_initval (c_parser *parser, struct c_expr *after,
3343                   struct obstack * braced_init_obstack)
3344 {
3345   struct c_expr init;
3346   gcc_assert (!after || c_dialect_objc ());
3347   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3348     init = c_parser_braced_init (parser, NULL_TREE, true);
3349   else
3350     {
3351       location_t loc = c_parser_peek_token (parser)->location;
3352       init = c_parser_expr_no_commas (parser, after);
3353       if (init.value != NULL_TREE
3354           && TREE_CODE (init.value) != STRING_CST
3355           && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3356         init = default_function_array_read_conversion (loc, init);
3357     }
3358   process_init_element (init, false, braced_init_obstack);
3359 }
3360
3361 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3362    C99 6.8.2).
3363
3364    compound-statement:
3365      { block-item-list[opt] }
3366      { label-declarations block-item-list }
3367
3368    block-item-list:
3369      block-item
3370      block-item-list block-item
3371
3372    block-item:
3373      nested-declaration
3374      statement
3375
3376    nested-declaration:
3377      declaration
3378
3379    GNU extensions:
3380
3381    compound-statement:
3382      { label-declarations block-item-list }
3383
3384    nested-declaration:
3385      __extension__ nested-declaration
3386      nested-function-definition
3387
3388    label-declarations:
3389      label-declaration
3390      label-declarations label-declaration
3391
3392    label-declaration:
3393      __label__ identifier-list ;
3394
3395    Allowing the mixing of declarations and code is new in C99.  The
3396    GNU syntax also permits (not shown above) labels at the end of
3397    compound statements, which yield an error.  We don't allow labels
3398    on declarations; this might seem like a natural extension, but
3399    there would be a conflict between attributes on the label and
3400    prefix attributes on the declaration.  ??? The syntax follows the
3401    old parser in requiring something after label declarations.
3402    Although they are erroneous if the labels declared aren't defined,
3403    is it useful for the syntax to be this way?
3404
3405    OpenMP:
3406
3407    block-item:
3408      openmp-directive
3409
3410    openmp-directive:
3411      barrier-directive
3412      flush-directive  */
3413
3414 static tree
3415 c_parser_compound_statement (c_parser *parser)
3416 {
3417   tree stmt;
3418   location_t brace_loc;
3419   brace_loc = c_parser_peek_token (parser)->location;
3420   if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3421     {
3422       /* Ensure a scope is entered and left anyway to avoid confusion
3423          if we have just prepared to enter a function body.  */
3424       stmt = c_begin_compound_stmt (true);
3425       c_end_compound_stmt (brace_loc, stmt, true);
3426       return error_mark_node;
3427     }
3428   stmt = c_begin_compound_stmt (true);
3429   c_parser_compound_statement_nostart (parser);
3430   return c_end_compound_stmt (brace_loc, stmt, true);
3431 }
3432
3433 /* Parse a compound statement except for the opening brace.  This is
3434    used for parsing both compound statements and statement expressions
3435    (which follow different paths to handling the opening).  */
3436
3437 static void
3438 c_parser_compound_statement_nostart (c_parser *parser)
3439 {
3440   bool last_stmt = false;
3441   bool last_label = false;
3442   bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3443   location_t label_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
3444   if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3445     {
3446       c_parser_consume_token (parser);
3447       return;
3448     }
3449   mark_valid_location_for_stdc_pragma (true);
3450   if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3451     {
3452       /* Read zero or more forward-declarations for labels that nested
3453          functions can jump to.  */
3454       mark_valid_location_for_stdc_pragma (false);
3455       while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3456         {
3457           label_loc = c_parser_peek_token (parser)->location;
3458           c_parser_consume_token (parser);
3459           /* Any identifiers, including those declared as type names,
3460              are OK here.  */
3461           while (true)
3462             {
3463               tree label;
3464               if (c_parser_next_token_is_not (parser, CPP_NAME))
3465                 {
3466                   c_parser_error (parser, "expected identifier");
3467                   break;
3468                 }
3469               label
3470                 = declare_label (c_parser_peek_token (parser)->value);
3471               C_DECLARED_LABEL_FLAG (label) = 1;
3472               add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3473               c_parser_consume_token (parser);
3474