OSDN Git Service

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