OSDN Git Service

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