OSDN Git Service

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