note PR 28834
[official-gcc.git] / gcc / c-parser.c
blob32776dddab4f5c11a4b551ad52df1c2d6b0fb91f
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 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO:
26 Make sure all relevant comments, and all relevant code from all
27 actions, brought over from old parser. Verify exact correspondence
28 of syntax accepted.
30 Add testcases covering every input symbol in every state in old and
31 new parsers.
33 Include full syntax for GNU C, including erroneous cases accepted
34 with error messages, in syntax productions in comments.
36 Make more diagnostics in the front end generally take an explicit
37 location rather than implicitly using input_location. */
39 #include "config.h"
40 #include "system.h"
41 #include "coretypes.h"
42 #include "tm.h"
43 #include "tree.h"
44 #include "rtl.h"
45 #include "langhooks.h"
46 #include "input.h"
47 #include "cpplib.h"
48 #include "timevar.h"
49 #include "c-pragma.h"
50 #include "c-tree.h"
51 #include "flags.h"
52 #include "output.h"
53 #include "toplev.h"
54 #include "ggc.h"
55 #include "c-common.h"
56 #include "vec.h"
57 #include "target.h"
58 #include "cgraph.h"
61 /* The reserved keyword table. */
62 struct resword
64 const char *word;
65 ENUM_BITFIELD(rid) rid : 16;
66 unsigned int disable : 16;
69 /* Disable mask. Keywords are disabled if (reswords[i].disable &
70 mask) is _true_. */
71 #define D_C89 0x01 /* not in C89 */
72 #define D_EXT 0x02 /* GCC extension */
73 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
74 #define D_OBJC 0x08 /* Objective C only */
76 static const struct resword reswords[] =
78 { "_Bool", RID_BOOL, 0 },
79 { "_Complex", RID_COMPLEX, 0 },
80 { "_Decimal32", RID_DFLOAT32, D_EXT },
81 { "_Decimal64", RID_DFLOAT64, D_EXT },
82 { "_Decimal128", RID_DFLOAT128, D_EXT },
83 { "_Fract", RID_FRACT, D_EXT },
84 { "_Accum", RID_ACCUM, D_EXT },
85 { "_Sat", RID_SAT, D_EXT },
86 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
87 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
88 { "__alignof", RID_ALIGNOF, 0 },
89 { "__alignof__", RID_ALIGNOF, 0 },
90 { "__asm", RID_ASM, 0 },
91 { "__asm__", RID_ASM, 0 },
92 { "__attribute", RID_ATTRIBUTE, 0 },
93 { "__attribute__", RID_ATTRIBUTE, 0 },
94 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
95 { "__builtin_offsetof", RID_OFFSETOF, 0 },
96 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
97 { "__builtin_va_arg", RID_VA_ARG, 0 },
98 { "__complex", RID_COMPLEX, 0 },
99 { "__complex__", RID_COMPLEX, 0 },
100 { "__const", RID_CONST, 0 },
101 { "__const__", RID_CONST, 0 },
102 { "__extension__", RID_EXTENSION, 0 },
103 { "__func__", RID_C99_FUNCTION_NAME, 0 },
104 { "__imag", RID_IMAGPART, 0 },
105 { "__imag__", RID_IMAGPART, 0 },
106 { "__inline", RID_INLINE, 0 },
107 { "__inline__", RID_INLINE, 0 },
108 { "__label__", RID_LABEL, 0 },
109 { "__real", RID_REALPART, 0 },
110 { "__real__", RID_REALPART, 0 },
111 { "__restrict", RID_RESTRICT, 0 },
112 { "__restrict__", RID_RESTRICT, 0 },
113 { "__signed", RID_SIGNED, 0 },
114 { "__signed__", RID_SIGNED, 0 },
115 { "__thread", RID_THREAD, 0 },
116 { "__typeof", RID_TYPEOF, 0 },
117 { "__typeof__", RID_TYPEOF, 0 },
118 { "__volatile", RID_VOLATILE, 0 },
119 { "__volatile__", RID_VOLATILE, 0 },
120 { "asm", RID_ASM, D_EXT },
121 { "auto", RID_AUTO, 0 },
122 { "break", RID_BREAK, 0 },
123 { "case", RID_CASE, 0 },
124 { "char", RID_CHAR, 0 },
125 { "const", RID_CONST, 0 },
126 { "continue", RID_CONTINUE, 0 },
127 { "default", RID_DEFAULT, 0 },
128 { "do", RID_DO, 0 },
129 { "double", RID_DOUBLE, 0 },
130 { "else", RID_ELSE, 0 },
131 { "enum", RID_ENUM, 0 },
132 { "extern", RID_EXTERN, 0 },
133 { "float", RID_FLOAT, 0 },
134 { "for", RID_FOR, 0 },
135 { "goto", RID_GOTO, 0 },
136 { "if", RID_IF, 0 },
137 { "inline", RID_INLINE, D_EXT89 },
138 { "int", RID_INT, 0 },
139 { "long", RID_LONG, 0 },
140 { "register", RID_REGISTER, 0 },
141 { "restrict", RID_RESTRICT, D_C89 },
142 { "return", RID_RETURN, 0 },
143 { "short", RID_SHORT, 0 },
144 { "signed", RID_SIGNED, 0 },
145 { "sizeof", RID_SIZEOF, 0 },
146 { "static", RID_STATIC, 0 },
147 { "struct", RID_STRUCT, 0 },
148 { "switch", RID_SWITCH, 0 },
149 { "typedef", RID_TYPEDEF, 0 },
150 { "typeof", RID_TYPEOF, D_EXT },
151 { "union", RID_UNION, 0 },
152 { "unsigned", RID_UNSIGNED, 0 },
153 { "void", RID_VOID, 0 },
154 { "volatile", RID_VOLATILE, 0 },
155 { "while", RID_WHILE, 0 },
156 /* These Objective-C keywords are recognized only immediately after
157 an '@'. */
158 { "class", RID_AT_CLASS, D_OBJC },
159 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
160 { "defs", RID_AT_DEFS, D_OBJC },
161 { "encode", RID_AT_ENCODE, D_OBJC },
162 { "end", RID_AT_END, D_OBJC },
163 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
164 { "interface", RID_AT_INTERFACE, D_OBJC },
165 { "private", RID_AT_PRIVATE, D_OBJC },
166 { "protected", RID_AT_PROTECTED, D_OBJC },
167 { "protocol", RID_AT_PROTOCOL, D_OBJC },
168 { "public", RID_AT_PUBLIC, D_OBJC },
169 { "selector", RID_AT_SELECTOR, D_OBJC },
170 { "throw", RID_AT_THROW, D_OBJC },
171 { "try", RID_AT_TRY, D_OBJC },
172 { "catch", RID_AT_CATCH, D_OBJC },
173 { "finally", RID_AT_FINALLY, D_OBJC },
174 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
175 /* These are recognized only in protocol-qualifier context
176 (see above) */
177 { "bycopy", RID_BYCOPY, D_OBJC },
178 { "byref", RID_BYREF, D_OBJC },
179 { "in", RID_IN, D_OBJC },
180 { "inout", RID_INOUT, D_OBJC },
181 { "oneway", RID_ONEWAY, D_OBJC },
182 { "out", RID_OUT, D_OBJC },
184 #define N_reswords (sizeof reswords / sizeof (struct resword))
186 /* Initialization routine for this file. */
188 void
189 c_parse_init (void)
191 /* The only initialization required is of the reserved word
192 identifiers. */
193 unsigned int i;
194 tree id;
195 int mask = (flag_isoc99 ? 0 : D_C89)
196 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
198 if (!c_dialect_objc ())
199 mask |= D_OBJC;
201 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
202 for (i = 0; i < N_reswords; i++)
204 /* If a keyword is disabled, do not enter it into the table
205 and so create a canonical spelling that isn't a keyword. */
206 if (reswords[i].disable & mask)
207 continue;
209 id = get_identifier (reswords[i].word);
210 C_RID_CODE (id) = reswords[i].rid;
211 C_IS_RESERVED_WORD (id) = 1;
212 ridpointers [(int) reswords[i].rid] = id;
216 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
217 and the C parser. Unlike the C++ lexer, the parser structure
218 stores the lexer information instead of using a separate structure.
219 Identifiers are separated into ordinary identifiers, type names,
220 keywords and some other Objective-C types of identifiers, and some
221 look-ahead is maintained.
223 ??? It might be a good idea to lex the whole file up front (as for
224 C++). It would then be possible to share more of the C and C++
225 lexer code, if desired. */
227 /* The following local token type is used. */
229 /* A keyword. */
230 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
232 /* More information about the type of a CPP_NAME token. */
233 typedef enum c_id_kind {
234 /* An ordinary identifier. */
235 C_ID_ID,
236 /* An identifier declared as a typedef name. */
237 C_ID_TYPENAME,
238 /* An identifier declared as an Objective-C class name. */
239 C_ID_CLASSNAME,
240 /* Not an identifier. */
241 C_ID_NONE
242 } c_id_kind;
244 /* A single C token after string literal concatenation and conversion
245 of preprocessing tokens to tokens. */
246 typedef struct c_token GTY (())
248 /* The kind of token. */
249 ENUM_BITFIELD (cpp_ttype) type : 8;
250 /* If this token is a CPP_NAME, this value indicates whether also
251 declared as some kind of type. Otherwise, it is C_ID_NONE. */
252 ENUM_BITFIELD (c_id_kind) id_kind : 8;
253 /* If this token is a keyword, this value indicates which keyword.
254 Otherwise, this value is RID_MAX. */
255 ENUM_BITFIELD (rid) keyword : 8;
256 /* If this token is a CPP_PRAGMA, this indicates the pragma that
257 was seen. Otherwise it is PRAGMA_NONE. */
258 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
259 /* True if this token is from a system header. */
260 BOOL_BITFIELD in_system_header : 1;
261 /* The value associated with this token, if any. */
262 tree value;
263 /* The location at which this token was found. */
264 location_t location;
265 } c_token;
267 /* A parser structure recording information about the state and
268 context of parsing. Includes lexer information with up to two
269 tokens of look-ahead; more are not needed for C. */
270 typedef struct c_parser GTY(())
272 /* The look-ahead tokens. */
273 c_token tokens[2];
274 /* How many look-ahead tokens are available (0, 1 or 2). */
275 short tokens_avail;
276 /* True if a syntax error is being recovered from; false otherwise.
277 c_parser_error sets this flag. It should clear this flag when
278 enough tokens have been consumed to recover from the error. */
279 BOOL_BITFIELD error : 1;
280 /* True if we're processing a pragma, and shouldn't automatically
281 consume CPP_PRAGMA_EOL. */
282 BOOL_BITFIELD in_pragma : 1;
283 /* True if we want to lex an untranslated string. */
284 BOOL_BITFIELD lex_untranslated_string : 1;
285 /* Objective-C specific parser/lexer information. */
286 BOOL_BITFIELD objc_pq_context : 1;
287 /* The following flag is needed to contextualize Objective-C lexical
288 analysis. In some cases (e.g., 'int NSObject;'), it is
289 undesirable to bind an identifier to an Objective-C class, even
290 if a class with that name exists. */
291 BOOL_BITFIELD objc_need_raw_identifier : 1;
292 } c_parser;
295 /* The actual parser and external interface. ??? Does this need to be
296 garbage-collected? */
298 static GTY (()) c_parser *the_parser;
301 /* Read in and lex a single token, storing it in *TOKEN. */
303 static void
304 c_lex_one_token (c_parser *parser, c_token *token)
306 timevar_push (TV_LEX);
308 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
309 (parser->lex_untranslated_string
310 ? C_LEX_STRING_NO_TRANSLATE : 0));
311 token->id_kind = C_ID_NONE;
312 token->keyword = RID_MAX;
313 token->pragma_kind = PRAGMA_NONE;
314 token->in_system_header = in_system_header;
316 switch (token->type)
318 case CPP_NAME:
320 tree decl;
322 bool objc_force_identifier = parser->objc_need_raw_identifier;
323 if (c_dialect_objc ())
324 parser->objc_need_raw_identifier = false;
326 if (C_IS_RESERVED_WORD (token->value))
328 enum rid rid_code = C_RID_CODE (token->value);
330 if (c_dialect_objc ())
332 if (!OBJC_IS_AT_KEYWORD (rid_code)
333 && (!OBJC_IS_PQ_KEYWORD (rid_code)
334 || parser->objc_pq_context))
336 /* Return the canonical spelling for this keyword. */
337 token->value = ridpointers[(int) rid_code];
338 token->type = CPP_KEYWORD;
339 token->keyword = rid_code;
340 break;
343 else
345 /* Return the canonical spelling for this keyword. */
346 token->value = ridpointers[(int) rid_code];
347 token->type = CPP_KEYWORD;
348 token->keyword = rid_code;
349 break;
353 decl = lookup_name (token->value);
354 if (decl)
356 if (TREE_CODE (decl) == TYPE_DECL)
358 token->id_kind = C_ID_TYPENAME;
359 break;
362 else if (c_dialect_objc ())
364 tree objc_interface_decl = objc_is_class_name (token->value);
365 /* Objective-C class names are in the same namespace as
366 variables and typedefs, and hence are shadowed by local
367 declarations. */
368 if (objc_interface_decl
369 && (global_bindings_p ()
370 || (!objc_force_identifier && !decl)))
372 token->value = objc_interface_decl;
373 token->id_kind = C_ID_CLASSNAME;
374 break;
377 token->id_kind = C_ID_ID;
379 break;
380 case CPP_AT_NAME:
381 /* This only happens in Objective-C; it must be a keyword. */
382 token->type = CPP_KEYWORD;
383 token->keyword = C_RID_CODE (token->value);
384 break;
385 case CPP_COLON:
386 case CPP_COMMA:
387 case CPP_CLOSE_PAREN:
388 case CPP_SEMICOLON:
389 /* These tokens may affect the interpretation of any identifiers
390 following, if doing Objective-C. */
391 if (c_dialect_objc ())
392 parser->objc_need_raw_identifier = false;
393 break;
394 case CPP_PRAGMA:
395 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
396 token->pragma_kind = TREE_INT_CST_LOW (token->value);
397 token->value = NULL;
398 break;
399 default:
400 break;
402 timevar_pop (TV_LEX);
405 /* Return a pointer to the next token from PARSER, reading it in if
406 necessary. */
408 static inline c_token *
409 c_parser_peek_token (c_parser *parser)
411 if (parser->tokens_avail == 0)
413 c_lex_one_token (parser, &parser->tokens[0]);
414 parser->tokens_avail = 1;
416 return &parser->tokens[0];
419 /* Return true if the next token from PARSER has the indicated
420 TYPE. */
422 static inline bool
423 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
425 return c_parser_peek_token (parser)->type == type;
428 /* Return true if the next token from PARSER does not have the
429 indicated TYPE. */
431 static inline bool
432 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
434 return !c_parser_next_token_is (parser, type);
437 /* Return true if the next token from PARSER is the indicated
438 KEYWORD. */
440 static inline bool
441 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
443 c_token *token;
445 /* Peek at the next token. */
446 token = c_parser_peek_token (parser);
447 /* Check to see if it is the indicated keyword. */
448 return token->keyword == keyword;
451 /* Return true if TOKEN can start a type name,
452 false otherwise. */
453 static bool
454 c_token_starts_typename (c_token *token)
456 switch (token->type)
458 case CPP_NAME:
459 switch (token->id_kind)
461 case C_ID_ID:
462 return false;
463 case C_ID_TYPENAME:
464 return true;
465 case C_ID_CLASSNAME:
466 gcc_assert (c_dialect_objc ());
467 return true;
468 default:
469 gcc_unreachable ();
471 case CPP_KEYWORD:
472 switch (token->keyword)
474 case RID_UNSIGNED:
475 case RID_LONG:
476 case RID_SHORT:
477 case RID_SIGNED:
478 case RID_COMPLEX:
479 case RID_INT:
480 case RID_CHAR:
481 case RID_FLOAT:
482 case RID_DOUBLE:
483 case RID_VOID:
484 case RID_DFLOAT32:
485 case RID_DFLOAT64:
486 case RID_DFLOAT128:
487 case RID_BOOL:
488 case RID_ENUM:
489 case RID_STRUCT:
490 case RID_UNION:
491 case RID_TYPEOF:
492 case RID_CONST:
493 case RID_VOLATILE:
494 case RID_RESTRICT:
495 case RID_ATTRIBUTE:
496 case RID_FRACT:
497 case RID_ACCUM:
498 case RID_SAT:
499 return true;
500 default:
501 return false;
503 case CPP_LESS:
504 if (c_dialect_objc ())
505 return true;
506 return false;
507 default:
508 return false;
512 /* Return true if the next token from PARSER can start a type name,
513 false otherwise. */
514 static inline bool
515 c_parser_next_token_starts_typename (c_parser *parser)
517 c_token *token = c_parser_peek_token (parser);
518 return c_token_starts_typename (token);
521 /* Return true if TOKEN can start declaration specifiers, false
522 otherwise. */
523 static bool
524 c_token_starts_declspecs (c_token *token)
526 switch (token->type)
528 case CPP_NAME:
529 switch (token->id_kind)
531 case C_ID_ID:
532 return false;
533 case C_ID_TYPENAME:
534 return true;
535 case C_ID_CLASSNAME:
536 gcc_assert (c_dialect_objc ());
537 return true;
538 default:
539 gcc_unreachable ();
541 case CPP_KEYWORD:
542 switch (token->keyword)
544 case RID_STATIC:
545 case RID_EXTERN:
546 case RID_REGISTER:
547 case RID_TYPEDEF:
548 case RID_INLINE:
549 case RID_AUTO:
550 case RID_THREAD:
551 case RID_UNSIGNED:
552 case RID_LONG:
553 case RID_SHORT:
554 case RID_SIGNED:
555 case RID_COMPLEX:
556 case RID_INT:
557 case RID_CHAR:
558 case RID_FLOAT:
559 case RID_DOUBLE:
560 case RID_VOID:
561 case RID_DFLOAT32:
562 case RID_DFLOAT64:
563 case RID_DFLOAT128:
564 case RID_BOOL:
565 case RID_ENUM:
566 case RID_STRUCT:
567 case RID_UNION:
568 case RID_TYPEOF:
569 case RID_CONST:
570 case RID_VOLATILE:
571 case RID_RESTRICT:
572 case RID_ATTRIBUTE:
573 case RID_FRACT:
574 case RID_ACCUM:
575 case RID_SAT:
576 return true;
577 default:
578 return false;
580 case CPP_LESS:
581 if (c_dialect_objc ())
582 return true;
583 return false;
584 default:
585 return false;
589 /* Return true if the next token from PARSER can start declaration
590 specifiers, false otherwise. */
591 static inline bool
592 c_parser_next_token_starts_declspecs (c_parser *parser)
594 c_token *token = c_parser_peek_token (parser);
595 return c_token_starts_declspecs (token);
598 /* Return a pointer to the next-but-one token from PARSER, reading it
599 in if necessary. The next token is already read in. */
601 static c_token *
602 c_parser_peek_2nd_token (c_parser *parser)
604 if (parser->tokens_avail >= 2)
605 return &parser->tokens[1];
606 gcc_assert (parser->tokens_avail == 1);
607 gcc_assert (parser->tokens[0].type != CPP_EOF);
608 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
609 c_lex_one_token (parser, &parser->tokens[1]);
610 parser->tokens_avail = 2;
611 return &parser->tokens[1];
614 /* Consume the next token from PARSER. */
616 static void
617 c_parser_consume_token (c_parser *parser)
619 gcc_assert (parser->tokens_avail >= 1);
620 gcc_assert (parser->tokens[0].type != CPP_EOF);
621 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
622 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
623 if (parser->tokens_avail == 2)
624 parser->tokens[0] = parser->tokens[1];
625 parser->tokens_avail--;
628 /* Expect the current token to be a #pragma. Consume it and remember
629 that we've begun parsing a pragma. */
631 static void
632 c_parser_consume_pragma (c_parser *parser)
634 gcc_assert (!parser->in_pragma);
635 gcc_assert (parser->tokens_avail >= 1);
636 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
637 if (parser->tokens_avail == 2)
638 parser->tokens[0] = parser->tokens[1];
639 parser->tokens_avail--;
640 parser->in_pragma = true;
643 /* Update the globals input_location and in_system_header from
644 TOKEN. */
645 static inline void
646 c_parser_set_source_position_from_token (c_token *token)
648 if (token->type != CPP_EOF)
650 input_location = token->location;
651 in_system_header = token->in_system_header;
655 /* Issue a diagnostic of the form
656 FILE:LINE: MESSAGE before TOKEN
657 where TOKEN is the next token in the input stream of PARSER.
658 MESSAGE (specified by the caller) is usually of the form "expected
659 OTHER-TOKEN".
661 Do not issue a diagnostic if still recovering from an error.
663 ??? This is taken from the C++ parser, but building up messages in
664 this way is not i18n-friendly and some other approach should be
665 used. */
667 static void
668 c_parser_error (c_parser *parser, const char *gmsgid)
670 c_token *token = c_parser_peek_token (parser);
671 if (parser->error)
672 return;
673 parser->error = true;
674 if (!gmsgid)
675 return;
676 /* This diagnostic makes more sense if it is tagged to the line of
677 the token we just peeked at. */
678 c_parser_set_source_position_from_token (token);
679 c_parse_error (gmsgid,
680 /* Because c_parse_error does not understand
681 CPP_KEYWORD, keywords are treated like
682 identifiers. */
683 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
684 token->value);
687 /* If the next token is of the indicated TYPE, consume it. Otherwise,
688 issue the error MSGID. If MSGID is NULL then a message has already
689 been produced and no message will be produced this time. Returns
690 true if found, false otherwise. */
692 static bool
693 c_parser_require (c_parser *parser,
694 enum cpp_ttype type,
695 const char *msgid)
697 if (c_parser_next_token_is (parser, type))
699 c_parser_consume_token (parser);
700 return true;
702 else
704 c_parser_error (parser, msgid);
705 return false;
709 /* If the next token is the indicated keyword, consume it. Otherwise,
710 issue the error MSGID. Returns true if found, false otherwise. */
712 static bool
713 c_parser_require_keyword (c_parser *parser,
714 enum rid keyword,
715 const char *msgid)
717 if (c_parser_next_token_is_keyword (parser, keyword))
719 c_parser_consume_token (parser);
720 return true;
722 else
724 c_parser_error (parser, msgid);
725 return false;
729 /* Like c_parser_require, except that tokens will be skipped until the
730 desired token is found. An error message is still produced if the
731 next token is not as expected. If MSGID is NULL then a message has
732 already been produced and no message will be produced this
733 time. */
735 static void
736 c_parser_skip_until_found (c_parser *parser,
737 enum cpp_ttype type,
738 const char *msgid)
740 unsigned nesting_depth = 0;
742 if (c_parser_require (parser, type, msgid))
743 return;
745 /* Skip tokens until the desired token is found. */
746 while (true)
748 /* Peek at the next token. */
749 c_token *token = c_parser_peek_token (parser);
750 /* If we've reached the token we want, consume it and stop. */
751 if (token->type == type && !nesting_depth)
753 c_parser_consume_token (parser);
754 break;
757 /* If we've run out of tokens, stop. */
758 if (token->type == CPP_EOF)
759 return;
760 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
761 return;
762 if (token->type == CPP_OPEN_BRACE
763 || token->type == CPP_OPEN_PAREN
764 || token->type == CPP_OPEN_SQUARE)
765 ++nesting_depth;
766 else if (token->type == CPP_CLOSE_BRACE
767 || token->type == CPP_CLOSE_PAREN
768 || token->type == CPP_CLOSE_SQUARE)
770 if (nesting_depth-- == 0)
771 break;
773 /* Consume this token. */
774 c_parser_consume_token (parser);
776 parser->error = false;
779 /* Skip tokens until the end of a parameter is found, but do not
780 consume the comma, semicolon or closing delimiter. */
782 static void
783 c_parser_skip_to_end_of_parameter (c_parser *parser)
785 unsigned nesting_depth = 0;
787 while (true)
789 c_token *token = c_parser_peek_token (parser);
790 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
791 && !nesting_depth)
792 break;
793 /* If we've run out of tokens, stop. */
794 if (token->type == CPP_EOF)
795 return;
796 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
797 return;
798 if (token->type == CPP_OPEN_BRACE
799 || token->type == CPP_OPEN_PAREN
800 || token->type == CPP_OPEN_SQUARE)
801 ++nesting_depth;
802 else if (token->type == CPP_CLOSE_BRACE
803 || token->type == CPP_CLOSE_PAREN
804 || token->type == CPP_CLOSE_SQUARE)
806 if (nesting_depth-- == 0)
807 break;
809 /* Consume this token. */
810 c_parser_consume_token (parser);
812 parser->error = false;
815 /* Expect to be at the end of the pragma directive and consume an
816 end of line marker. */
818 static void
819 c_parser_skip_to_pragma_eol (c_parser *parser)
821 gcc_assert (parser->in_pragma);
822 parser->in_pragma = false;
824 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
825 while (true)
827 c_token *token = c_parser_peek_token (parser);
828 if (token->type == CPP_EOF)
829 break;
830 if (token->type == CPP_PRAGMA_EOL)
832 c_parser_consume_token (parser);
833 break;
835 c_parser_consume_token (parser);
838 parser->error = false;
841 /* Skip tokens until we have consumed an entire block, or until we
842 have consumed a non-nested ';'. */
844 static void
845 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
847 unsigned nesting_depth = 0;
848 bool save_error = parser->error;
850 while (true)
852 c_token *token;
854 /* Peek at the next token. */
855 token = c_parser_peek_token (parser);
857 switch (token->type)
859 case CPP_EOF:
860 return;
862 case CPP_PRAGMA_EOL:
863 if (parser->in_pragma)
864 return;
865 break;
867 case CPP_SEMICOLON:
868 /* If the next token is a ';', we have reached the
869 end of the statement. */
870 if (!nesting_depth)
872 /* Consume the ';'. */
873 c_parser_consume_token (parser);
874 goto finished;
876 break;
878 case CPP_CLOSE_BRACE:
879 /* If the next token is a non-nested '}', then we have
880 reached the end of the current block. */
881 if (nesting_depth == 0 || --nesting_depth == 0)
883 c_parser_consume_token (parser);
884 goto finished;
886 break;
888 case CPP_OPEN_BRACE:
889 /* If it the next token is a '{', then we are entering a new
890 block. Consume the entire block. */
891 ++nesting_depth;
892 break;
894 case CPP_PRAGMA:
895 /* If we see a pragma, consume the whole thing at once. We
896 have some safeguards against consuming pragmas willy-nilly.
897 Normally, we'd expect to be here with parser->error set,
898 which disables these safeguards. But it's possible to get
899 here for secondary error recovery, after parser->error has
900 been cleared. */
901 c_parser_consume_pragma (parser);
902 c_parser_skip_to_pragma_eol (parser);
903 parser->error = save_error;
904 continue;
906 default:
907 break;
910 c_parser_consume_token (parser);
913 finished:
914 parser->error = false;
917 /* Save the warning flags which are controlled by __extension__. */
919 static inline int
920 disable_extension_diagnostics (void)
922 int ret = (pedantic
923 | (warn_pointer_arith << 1)
924 | (warn_traditional << 2)
925 | (flag_iso << 3));
926 pedantic = 0;
927 warn_pointer_arith = 0;
928 warn_traditional = 0;
929 flag_iso = 0;
930 return ret;
933 /* Restore the warning flags which are controlled by __extension__.
934 FLAGS is the return value from disable_extension_diagnostics. */
936 static inline void
937 restore_extension_diagnostics (int flags)
939 pedantic = flags & 1;
940 warn_pointer_arith = (flags >> 1) & 1;
941 warn_traditional = (flags >> 2) & 1;
942 flag_iso = (flags >> 3) & 1;
945 /* Possibly kinds of declarator to parse. */
946 typedef enum c_dtr_syn {
947 /* A normal declarator with an identifier. */
948 C_DTR_NORMAL,
949 /* An abstract declarator (maybe empty). */
950 C_DTR_ABSTRACT,
951 /* A parameter declarator: may be either, but after a type name does
952 not redeclare a typedef name as an identifier if it can
953 alternatively be interpreted as a typedef name; see DR#009,
954 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
955 following DR#249. For example, given a typedef T, "int T" and
956 "int *T" are valid parameter declarations redeclaring T, while
957 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
958 abstract declarators rather than involving redundant parentheses;
959 the same applies with attributes inside the parentheses before
960 "T". */
961 C_DTR_PARM
962 } c_dtr_syn;
964 static void c_parser_external_declaration (c_parser *);
965 static void c_parser_asm_definition (c_parser *);
966 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
967 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
968 bool);
969 static struct c_typespec c_parser_enum_specifier (c_parser *);
970 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
971 static tree c_parser_struct_declaration (c_parser *);
972 static struct c_typespec c_parser_typeof_specifier (c_parser *);
973 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
974 bool *);
975 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
976 c_dtr_syn, bool *);
977 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
978 bool,
979 struct c_declarator *);
980 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
981 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
982 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
983 static tree c_parser_simple_asm_expr (c_parser *);
984 static tree c_parser_attributes (c_parser *);
985 static struct c_type_name *c_parser_type_name (c_parser *);
986 static struct c_expr c_parser_initializer (c_parser *);
987 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
988 static void c_parser_initelt (c_parser *);
989 static void c_parser_initval (c_parser *, struct c_expr *);
990 static tree c_parser_compound_statement (c_parser *);
991 static void c_parser_compound_statement_nostart (c_parser *);
992 static void c_parser_label (c_parser *);
993 static void c_parser_statement (c_parser *);
994 static void c_parser_statement_after_labels (c_parser *);
995 static void c_parser_if_statement (c_parser *);
996 static void c_parser_switch_statement (c_parser *);
997 static void c_parser_while_statement (c_parser *);
998 static void c_parser_do_statement (c_parser *);
999 static void c_parser_for_statement (c_parser *);
1000 static tree c_parser_asm_statement (c_parser *);
1001 static tree c_parser_asm_operands (c_parser *, bool);
1002 static tree c_parser_asm_clobbers (c_parser *);
1003 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1004 static struct c_expr c_parser_conditional_expression (c_parser *,
1005 struct c_expr *);
1006 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1007 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1008 static struct c_expr c_parser_unary_expression (c_parser *);
1009 static struct c_expr c_parser_sizeof_expression (c_parser *);
1010 static struct c_expr c_parser_alignof_expression (c_parser *);
1011 static struct c_expr c_parser_postfix_expression (c_parser *);
1012 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1013 struct c_type_name *);
1014 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1015 struct c_expr);
1016 static struct c_expr c_parser_expression (c_parser *);
1017 static struct c_expr c_parser_expression_conv (c_parser *);
1018 static tree c_parser_expr_list (c_parser *, bool);
1019 static void c_parser_omp_construct (c_parser *);
1020 static void c_parser_omp_threadprivate (c_parser *);
1021 static void c_parser_omp_barrier (c_parser *);
1022 static void c_parser_omp_flush (c_parser *);
1024 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1025 static bool c_parser_pragma (c_parser *, enum pragma_context);
1027 /* These Objective-C parser functions are only ever called when
1028 compiling Objective-C. */
1029 static void c_parser_objc_class_definition (c_parser *);
1030 static void c_parser_objc_class_instance_variables (c_parser *);
1031 static void c_parser_objc_class_declaration (c_parser *);
1032 static void c_parser_objc_alias_declaration (c_parser *);
1033 static void c_parser_objc_protocol_definition (c_parser *);
1034 static enum tree_code c_parser_objc_method_type (c_parser *);
1035 static void c_parser_objc_method_definition (c_parser *);
1036 static void c_parser_objc_methodprotolist (c_parser *);
1037 static void c_parser_objc_methodproto (c_parser *);
1038 static tree c_parser_objc_method_decl (c_parser *);
1039 static tree c_parser_objc_type_name (c_parser *);
1040 static tree c_parser_objc_protocol_refs (c_parser *);
1041 static void c_parser_objc_try_catch_statement (c_parser *);
1042 static void c_parser_objc_synchronized_statement (c_parser *);
1043 static tree c_parser_objc_selector (c_parser *);
1044 static tree c_parser_objc_selector_arg (c_parser *);
1045 static tree c_parser_objc_receiver (c_parser *);
1046 static tree c_parser_objc_message_args (c_parser *);
1047 static tree c_parser_objc_keywordexpr (c_parser *);
1049 /* Parse a translation unit (C90 6.7, C99 6.9).
1051 translation-unit:
1052 external-declarations
1054 external-declarations:
1055 external-declaration
1056 external-declarations external-declaration
1058 GNU extensions:
1060 translation-unit:
1061 empty
1064 static void
1065 c_parser_translation_unit (c_parser *parser)
1067 if (c_parser_next_token_is (parser, CPP_EOF))
1069 if (pedantic)
1070 pedwarn ("%HISO C forbids an empty source file",
1071 &c_parser_peek_token (parser)->location);
1073 else
1075 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1078 ggc_collect ();
1079 c_parser_external_declaration (parser);
1080 obstack_free (&parser_obstack, obstack_position);
1082 while (c_parser_next_token_is_not (parser, CPP_EOF));
1086 /* Parse an external declaration (C90 6.7, C99 6.9).
1088 external-declaration:
1089 function-definition
1090 declaration
1092 GNU extensions:
1094 external-declaration:
1095 asm-definition
1097 __extension__ external-declaration
1099 Objective-C:
1101 external-declaration:
1102 objc-class-definition
1103 objc-class-declaration
1104 objc-alias-declaration
1105 objc-protocol-definition
1106 objc-method-definition
1107 @end
1110 static void
1111 c_parser_external_declaration (c_parser *parser)
1113 int ext;
1114 switch (c_parser_peek_token (parser)->type)
1116 case CPP_KEYWORD:
1117 switch (c_parser_peek_token (parser)->keyword)
1119 case RID_EXTENSION:
1120 ext = disable_extension_diagnostics ();
1121 c_parser_consume_token (parser);
1122 c_parser_external_declaration (parser);
1123 restore_extension_diagnostics (ext);
1124 break;
1125 case RID_ASM:
1126 c_parser_asm_definition (parser);
1127 break;
1128 case RID_AT_INTERFACE:
1129 case RID_AT_IMPLEMENTATION:
1130 gcc_assert (c_dialect_objc ());
1131 c_parser_objc_class_definition (parser);
1132 break;
1133 case RID_AT_CLASS:
1134 gcc_assert (c_dialect_objc ());
1135 c_parser_objc_class_declaration (parser);
1136 break;
1137 case RID_AT_ALIAS:
1138 gcc_assert (c_dialect_objc ());
1139 c_parser_objc_alias_declaration (parser);
1140 break;
1141 case RID_AT_PROTOCOL:
1142 gcc_assert (c_dialect_objc ());
1143 c_parser_objc_protocol_definition (parser);
1144 break;
1145 case RID_AT_END:
1146 gcc_assert (c_dialect_objc ());
1147 c_parser_consume_token (parser);
1148 objc_finish_implementation ();
1149 break;
1150 default:
1151 goto decl_or_fndef;
1153 break;
1154 case CPP_SEMICOLON:
1155 if (pedantic)
1156 pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
1157 &c_parser_peek_token (parser)->location);
1158 c_parser_consume_token (parser);
1159 break;
1160 case CPP_PRAGMA:
1161 c_parser_pragma (parser, pragma_external);
1162 break;
1163 case CPP_PLUS:
1164 case CPP_MINUS:
1165 if (c_dialect_objc ())
1167 c_parser_objc_method_definition (parser);
1168 break;
1170 /* Else fall through, and yield a syntax error trying to parse
1171 as a declaration or function definition. */
1172 default:
1173 decl_or_fndef:
1174 /* A declaration or a function definition. We can only tell
1175 which after parsing the declaration specifiers, if any, and
1176 the first declarator. */
1177 c_parser_declaration_or_fndef (parser, true, true, false, true);
1178 break;
1183 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1184 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1185 accepted; otherwise (old-style parameter declarations) only other
1186 declarations are accepted. If NESTED is true, we are inside a
1187 function or parsing old-style parameter declarations; any functions
1188 encountered are nested functions and declaration specifiers are
1189 required; otherwise we are at top level and functions are normal
1190 functions and declaration specifiers may be optional. If EMPTY_OK
1191 is true, empty declarations are OK (subject to all other
1192 constraints); otherwise (old-style parameter declarations) they are
1193 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1194 may start with attributes; otherwise they may not.
1196 declaration:
1197 declaration-specifiers init-declarator-list[opt] ;
1199 function-definition:
1200 declaration-specifiers[opt] declarator declaration-list[opt]
1201 compound-statement
1203 declaration-list:
1204 declaration
1205 declaration-list declaration
1207 init-declarator-list:
1208 init-declarator
1209 init-declarator-list , init-declarator
1211 init-declarator:
1212 declarator simple-asm-expr[opt] attributes[opt]
1213 declarator simple-asm-expr[opt] attributes[opt] = initializer
1215 GNU extensions:
1217 nested-function-definition:
1218 declaration-specifiers declarator declaration-list[opt]
1219 compound-statement
1221 The simple-asm-expr and attributes are GNU extensions.
1223 This function does not handle __extension__; that is handled in its
1224 callers. ??? Following the old parser, __extension__ may start
1225 external declarations, declarations in functions and declarations
1226 at the start of "for" loops, but not old-style parameter
1227 declarations.
1229 C99 requires declaration specifiers in a function definition; the
1230 absence is diagnosed through the diagnosis of implicit int. In GNU
1231 C we also allow but diagnose declarations without declaration
1232 specifiers, but only at top level (elsewhere they conflict with
1233 other syntax).
1235 OpenMP:
1237 declaration:
1238 threadprivate-directive */
1240 static void
1241 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1242 bool nested, bool start_attr_ok)
1244 struct c_declspecs *specs;
1245 tree prefix_attrs;
1246 tree all_prefix_attrs;
1247 bool diagnosed_no_specs = false;
1248 location_t here = c_parser_peek_token (parser)->location;
1250 specs = build_null_declspecs ();
1251 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1252 if (parser->error)
1254 c_parser_skip_to_end_of_block_or_statement (parser);
1255 return;
1257 if (nested && !specs->declspecs_seen_p)
1259 c_parser_error (parser, "expected declaration specifiers");
1260 c_parser_skip_to_end_of_block_or_statement (parser);
1261 return;
1263 finish_declspecs (specs);
1264 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1266 if (empty_ok)
1267 shadow_tag (specs);
1268 else
1270 shadow_tag_warned (specs, 1);
1271 pedwarn ("%Hempty declaration", &here);
1273 c_parser_consume_token (parser);
1274 return;
1276 pending_xref_error ();
1277 prefix_attrs = specs->attrs;
1278 all_prefix_attrs = prefix_attrs;
1279 specs->attrs = NULL_TREE;
1280 while (true)
1282 struct c_declarator *declarator;
1283 bool dummy = false;
1284 tree fnbody;
1285 /* Declaring either one or more declarators (in which case we
1286 should diagnose if there were no declaration specifiers) or a
1287 function definition (in which case the diagnostic for
1288 implicit int suffices). */
1289 declarator = c_parser_declarator (parser, specs->type_seen_p,
1290 C_DTR_NORMAL, &dummy);
1291 if (declarator == NULL)
1293 c_parser_skip_to_end_of_block_or_statement (parser);
1294 return;
1296 if (c_parser_next_token_is (parser, CPP_EQ)
1297 || c_parser_next_token_is (parser, CPP_COMMA)
1298 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1299 || c_parser_next_token_is_keyword (parser, RID_ASM)
1300 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1302 tree asm_name = NULL_TREE;
1303 tree postfix_attrs = NULL_TREE;
1304 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1306 diagnosed_no_specs = true;
1307 pedwarn ("%Hdata definition has no type or storage class",
1308 &here);
1310 /* Having seen a data definition, there cannot now be a
1311 function definition. */
1312 fndef_ok = false;
1313 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1314 asm_name = c_parser_simple_asm_expr (parser);
1315 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1316 postfix_attrs = c_parser_attributes (parser);
1317 if (c_parser_next_token_is (parser, CPP_EQ))
1319 tree d;
1320 struct c_expr init;
1321 c_parser_consume_token (parser);
1322 /* The declaration of the variable is in effect while
1323 its initializer is parsed. */
1324 d = start_decl (declarator, specs, true,
1325 chainon (postfix_attrs, all_prefix_attrs));
1326 if (!d)
1327 d = error_mark_node;
1328 start_init (d, asm_name, global_bindings_p ());
1329 init = c_parser_initializer (parser);
1330 finish_init ();
1331 if (d != error_mark_node)
1333 maybe_warn_string_init (TREE_TYPE (d), init);
1334 finish_decl (d, init.value, asm_name);
1337 else
1339 tree d = start_decl (declarator, specs, false,
1340 chainon (postfix_attrs,
1341 all_prefix_attrs));
1342 if (d)
1343 finish_decl (d, NULL_TREE, asm_name);
1345 if (c_parser_next_token_is (parser, CPP_COMMA))
1347 c_parser_consume_token (parser);
1348 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1349 all_prefix_attrs = chainon (c_parser_attributes (parser),
1350 prefix_attrs);
1351 else
1352 all_prefix_attrs = prefix_attrs;
1353 continue;
1355 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1357 c_parser_consume_token (parser);
1358 return;
1360 else
1362 c_parser_error (parser, "expected %<,%> or %<;%>");
1363 c_parser_skip_to_end_of_block_or_statement (parser);
1364 return;
1367 else if (!fndef_ok)
1369 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1370 "%<asm%> or %<__attribute__%>");
1371 c_parser_skip_to_end_of_block_or_statement (parser);
1372 return;
1374 /* Function definition (nested or otherwise). */
1375 if (nested)
1377 if (pedantic)
1378 pedwarn ("%HISO C forbids nested functions", &here);
1379 push_function_context ();
1381 if (!start_function (specs, declarator, all_prefix_attrs))
1383 /* This can appear in many cases looking nothing like a
1384 function definition, so we don't give a more specific
1385 error suggesting there was one. */
1386 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1387 "or %<__attribute__%>");
1388 if (nested)
1389 pop_function_context ();
1390 break;
1392 /* Parse old-style parameter declarations. ??? Attributes are
1393 not allowed to start declaration specifiers here because of a
1394 syntax conflict between a function declaration with attribute
1395 suffix and a function definition with an attribute prefix on
1396 first old-style parameter declaration. Following the old
1397 parser, they are not accepted on subsequent old-style
1398 parameter declarations either. However, there is no
1399 ambiguity after the first declaration, nor indeed on the
1400 first as long as we don't allow postfix attributes after a
1401 declarator with a nonempty identifier list in a definition;
1402 and postfix attributes have never been accepted here in
1403 function definitions either. */
1404 while (c_parser_next_token_is_not (parser, CPP_EOF)
1405 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1406 c_parser_declaration_or_fndef (parser, false, false, true, false);
1407 DECL_SOURCE_LOCATION (current_function_decl)
1408 = c_parser_peek_token (parser)->location;
1409 store_parm_decls ();
1410 fnbody = c_parser_compound_statement (parser);
1411 if (nested)
1413 tree decl = current_function_decl;
1414 add_stmt (fnbody);
1415 finish_function ();
1416 pop_function_context ();
1417 add_stmt (build_stmt (DECL_EXPR, decl));
1419 else
1421 add_stmt (fnbody);
1422 finish_function ();
1424 break;
1428 /* Parse an asm-definition (asm() outside a function body). This is a
1429 GNU extension.
1431 asm-definition:
1432 simple-asm-expr ;
1435 static void
1436 c_parser_asm_definition (c_parser *parser)
1438 tree asm_str = c_parser_simple_asm_expr (parser);
1439 if (asm_str)
1440 cgraph_add_asm_node (asm_str);
1441 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1444 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1445 6.7), adding them to SPECS (which may already include some).
1446 Storage class specifiers are accepted iff SCSPEC_OK; type
1447 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1448 the start iff START_ATTR_OK.
1450 declaration-specifiers:
1451 storage-class-specifier declaration-specifiers[opt]
1452 type-specifier declaration-specifiers[opt]
1453 type-qualifier declaration-specifiers[opt]
1454 function-specifier declaration-specifiers[opt]
1456 Function specifiers (inline) are from C99, and are currently
1457 handled as storage class specifiers, as is __thread.
1459 C90 6.5.1, C99 6.7.1:
1460 storage-class-specifier:
1461 typedef
1462 extern
1463 static
1464 auto
1465 register
1467 C99 6.7.4:
1468 function-specifier:
1469 inline
1471 C90 6.5.2, C99 6.7.2:
1472 type-specifier:
1473 void
1474 char
1475 short
1477 long
1478 float
1479 double
1480 signed
1481 unsigned
1482 _Bool
1483 _Complex
1484 [_Imaginary removed in C99 TC2]
1485 struct-or-union-specifier
1486 enum-specifier
1487 typedef-name
1489 (_Bool and _Complex are new in C99.)
1491 C90 6.5.3, C99 6.7.3:
1493 type-qualifier:
1494 const
1495 restrict
1496 volatile
1498 (restrict is new in C99.)
1500 GNU extensions:
1502 declaration-specifiers:
1503 attributes declaration-specifiers[opt]
1505 storage-class-specifier:
1506 __thread
1508 type-specifier:
1509 typeof-specifier
1510 _Decimal32
1511 _Decimal64
1512 _Decimal128
1513 _Fract
1514 _Accum
1515 _Sat
1517 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1518 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1520 Objective-C:
1522 type-specifier:
1523 class-name objc-protocol-refs[opt]
1524 typedef-name objc-protocol-refs
1525 objc-protocol-refs
1528 static void
1529 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1530 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1532 bool attrs_ok = start_attr_ok;
1533 bool seen_type = specs->type_seen_p;
1534 while (c_parser_next_token_is (parser, CPP_NAME)
1535 || c_parser_next_token_is (parser, CPP_KEYWORD)
1536 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1538 struct c_typespec t;
1539 tree attrs;
1540 if (c_parser_next_token_is (parser, CPP_NAME))
1542 tree value = c_parser_peek_token (parser)->value;
1543 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1544 /* This finishes the specifiers unless a type name is OK, it
1545 is declared as a type name and a type name hasn't yet
1546 been seen. */
1547 if (!typespec_ok || seen_type
1548 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1549 break;
1550 c_parser_consume_token (parser);
1551 seen_type = true;
1552 attrs_ok = true;
1553 if (kind == C_ID_TYPENAME
1554 && (!c_dialect_objc ()
1555 || c_parser_next_token_is_not (parser, CPP_LESS)))
1557 t.kind = ctsk_typedef;
1558 /* For a typedef name, record the meaning, not the name.
1559 In case of 'foo foo, bar;'. */
1560 t.spec = lookup_name (value);
1562 else
1564 tree proto = NULL_TREE;
1565 gcc_assert (c_dialect_objc ());
1566 t.kind = ctsk_objc;
1567 if (c_parser_next_token_is (parser, CPP_LESS))
1568 proto = c_parser_objc_protocol_refs (parser);
1569 t.spec = objc_get_protocol_qualified_type (value, proto);
1571 declspecs_add_type (specs, t);
1572 continue;
1574 if (c_parser_next_token_is (parser, CPP_LESS))
1576 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1577 nisse@lysator.liu.se. */
1578 tree proto;
1579 gcc_assert (c_dialect_objc ());
1580 if (!typespec_ok || seen_type)
1581 break;
1582 proto = c_parser_objc_protocol_refs (parser);
1583 t.kind = ctsk_objc;
1584 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1585 declspecs_add_type (specs, t);
1586 continue;
1588 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1589 switch (c_parser_peek_token (parser)->keyword)
1591 case RID_STATIC:
1592 case RID_EXTERN:
1593 case RID_REGISTER:
1594 case RID_TYPEDEF:
1595 case RID_INLINE:
1596 case RID_AUTO:
1597 case RID_THREAD:
1598 if (!scspec_ok)
1599 goto out;
1600 attrs_ok = true;
1601 /* TODO: Distinguish between function specifiers (inline)
1602 and storage class specifiers, either here or in
1603 declspecs_add_scspec. */
1604 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1605 c_parser_consume_token (parser);
1606 break;
1607 case RID_UNSIGNED:
1608 case RID_LONG:
1609 case RID_SHORT:
1610 case RID_SIGNED:
1611 case RID_COMPLEX:
1612 case RID_INT:
1613 case RID_CHAR:
1614 case RID_FLOAT:
1615 case RID_DOUBLE:
1616 case RID_VOID:
1617 case RID_DFLOAT32:
1618 case RID_DFLOAT64:
1619 case RID_DFLOAT128:
1620 case RID_BOOL:
1621 case RID_FRACT:
1622 case RID_ACCUM:
1623 case RID_SAT:
1624 if (!typespec_ok)
1625 goto out;
1626 attrs_ok = true;
1627 seen_type = true;
1628 if (c_dialect_objc ())
1629 parser->objc_need_raw_identifier = true;
1630 t.kind = ctsk_resword;
1631 t.spec = c_parser_peek_token (parser)->value;
1632 declspecs_add_type (specs, t);
1633 c_parser_consume_token (parser);
1634 break;
1635 case RID_ENUM:
1636 if (!typespec_ok)
1637 goto out;
1638 attrs_ok = true;
1639 seen_type = true;
1640 t = c_parser_enum_specifier (parser);
1641 declspecs_add_type (specs, t);
1642 break;
1643 case RID_STRUCT:
1644 case RID_UNION:
1645 if (!typespec_ok)
1646 goto out;
1647 attrs_ok = true;
1648 seen_type = true;
1649 t = c_parser_struct_or_union_specifier (parser);
1650 declspecs_add_type (specs, t);
1651 break;
1652 case RID_TYPEOF:
1653 /* ??? The old parser rejected typeof after other type
1654 specifiers, but is a syntax error the best way of
1655 handling this? */
1656 if (!typespec_ok || seen_type)
1657 goto out;
1658 attrs_ok = true;
1659 seen_type = true;
1660 t = c_parser_typeof_specifier (parser);
1661 declspecs_add_type (specs, t);
1662 break;
1663 case RID_CONST:
1664 case RID_VOLATILE:
1665 case RID_RESTRICT:
1666 attrs_ok = true;
1667 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1668 c_parser_consume_token (parser);
1669 break;
1670 case RID_ATTRIBUTE:
1671 if (!attrs_ok)
1672 goto out;
1673 attrs = c_parser_attributes (parser);
1674 declspecs_add_attrs (specs, attrs);
1675 break;
1676 default:
1677 goto out;
1680 out: ;
1683 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1685 enum-specifier:
1686 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1687 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1688 enum attributes[opt] identifier
1690 The form with trailing comma is new in C99. The forms with
1691 attributes are GNU extensions. In GNU C, we accept any expression
1692 without commas in the syntax (assignment expressions, not just
1693 conditional expressions); assignment expressions will be diagnosed
1694 as non-constant.
1696 enumerator-list:
1697 enumerator
1698 enumerator-list , enumerator
1700 enumerator:
1701 enumeration-constant
1702 enumeration-constant = constant-expression
1705 static struct c_typespec
1706 c_parser_enum_specifier (c_parser *parser)
1708 struct c_typespec ret;
1709 tree attrs;
1710 tree ident = NULL_TREE;
1711 location_t ident_loc;
1712 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1713 c_parser_consume_token (parser);
1714 attrs = c_parser_attributes (parser);
1715 /* Set the location in case we create a decl now. */
1716 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1717 if (c_parser_next_token_is (parser, CPP_NAME))
1719 ident = c_parser_peek_token (parser)->value;
1720 ident_loc = c_parser_peek_token (parser)->location;
1721 c_parser_consume_token (parser);
1723 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1725 /* Parse an enum definition. */
1726 struct c_enum_contents the_enum;
1727 tree type = start_enum (&the_enum, ident);
1728 tree postfix_attrs;
1729 /* We chain the enumerators in reverse order, then put them in
1730 forward order at the end. */
1731 tree values = NULL_TREE;
1732 c_parser_consume_token (parser);
1733 while (true)
1735 tree enum_id;
1736 tree enum_value;
1737 tree enum_decl;
1738 bool seen_comma;
1739 c_token *token;
1740 location_t comma_loc;
1741 if (c_parser_next_token_is_not (parser, CPP_NAME))
1743 c_parser_error (parser, "expected identifier");
1744 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1745 values = error_mark_node;
1746 break;
1748 token = c_parser_peek_token (parser);
1749 enum_id = token->value;
1750 /* Set the location in case we create a decl now. */
1751 c_parser_set_source_position_from_token (token);
1752 c_parser_consume_token (parser);
1753 if (c_parser_next_token_is (parser, CPP_EQ))
1755 c_parser_consume_token (parser);
1756 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1758 else
1759 enum_value = NULL_TREE;
1760 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1761 TREE_CHAIN (enum_decl) = values;
1762 values = enum_decl;
1763 seen_comma = false;
1764 if (c_parser_next_token_is (parser, CPP_COMMA))
1766 comma_loc = c_parser_peek_token (parser)->location;
1767 seen_comma = true;
1768 c_parser_consume_token (parser);
1770 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1772 if (seen_comma && pedantic && !flag_isoc99)
1773 pedwarn ("%Hcomma at end of enumerator list", &comma_loc);
1774 c_parser_consume_token (parser);
1775 break;
1777 if (!seen_comma)
1779 c_parser_error (parser, "expected %<,%> or %<}%>");
1780 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1781 values = error_mark_node;
1782 break;
1785 postfix_attrs = c_parser_attributes (parser);
1786 ret.spec = finish_enum (type, nreverse (values),
1787 chainon (attrs, postfix_attrs));
1788 ret.kind = ctsk_tagdef;
1789 return ret;
1791 else if (!ident)
1793 c_parser_error (parser, "expected %<{%>");
1794 ret.spec = error_mark_node;
1795 ret.kind = ctsk_tagref;
1796 return ret;
1798 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1799 /* In ISO C, enumerated types can be referred to only if already
1800 defined. */
1801 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1803 gcc_assert (ident);
1804 pedwarn ("%HISO C forbids forward references to %<enum%> types",
1805 &ident_loc);
1807 return ret;
1810 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1812 struct-or-union-specifier:
1813 struct-or-union attributes[opt] identifier[opt]
1814 { struct-contents } attributes[opt]
1815 struct-or-union attributes[opt] identifier
1817 struct-contents:
1818 struct-declaration-list
1820 struct-declaration-list:
1821 struct-declaration ;
1822 struct-declaration-list struct-declaration ;
1824 GNU extensions:
1826 struct-contents:
1827 empty
1828 struct-declaration
1829 struct-declaration-list struct-declaration
1831 struct-declaration-list:
1832 struct-declaration-list ;
1835 (Note that in the syntax here, unlike that in ISO C, the semicolons
1836 are included here rather than in struct-declaration, in order to
1837 describe the syntax with extra semicolons and missing semicolon at
1838 end.)
1840 Objective-C:
1842 struct-declaration-list:
1843 @defs ( class-name )
1845 (Note this does not include a trailing semicolon, but can be
1846 followed by further declarations, and gets a pedwarn-if-pedantic
1847 when followed by a semicolon.) */
1849 static struct c_typespec
1850 c_parser_struct_or_union_specifier (c_parser *parser)
1852 struct c_typespec ret;
1853 tree attrs;
1854 tree ident = NULL_TREE;
1855 enum tree_code code;
1856 switch (c_parser_peek_token (parser)->keyword)
1858 case RID_STRUCT:
1859 code = RECORD_TYPE;
1860 break;
1861 case RID_UNION:
1862 code = UNION_TYPE;
1863 break;
1864 default:
1865 gcc_unreachable ();
1867 c_parser_consume_token (parser);
1868 attrs = c_parser_attributes (parser);
1869 /* Set the location in case we create a decl now. */
1870 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1871 if (c_parser_next_token_is (parser, CPP_NAME))
1873 ident = c_parser_peek_token (parser)->value;
1874 c_parser_consume_token (parser);
1876 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1878 /* Parse a struct or union definition. Start the scope of the
1879 tag before parsing components. */
1880 tree type = start_struct (code, ident);
1881 tree postfix_attrs;
1882 /* We chain the components in reverse order, then put them in
1883 forward order at the end. Each struct-declaration may
1884 declare multiple components (comma-separated), so we must use
1885 chainon to join them, although when parsing each
1886 struct-declaration we can use TREE_CHAIN directly.
1888 The theory behind all this is that there will be more
1889 semicolon separated fields than comma separated fields, and
1890 so we'll be minimizing the number of node traversals required
1891 by chainon. */
1892 tree contents = NULL_TREE;
1893 c_parser_consume_token (parser);
1894 /* Handle the Objective-C @defs construct,
1895 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1896 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1898 tree name;
1899 gcc_assert (c_dialect_objc ());
1900 c_parser_consume_token (parser);
1901 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1902 goto end_at_defs;
1903 if (c_parser_next_token_is (parser, CPP_NAME)
1904 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1906 name = c_parser_peek_token (parser)->value;
1907 c_parser_consume_token (parser);
1909 else
1911 c_parser_error (parser, "expected class name");
1912 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1913 goto end_at_defs;
1915 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1916 "expected %<)%>");
1917 contents = nreverse (objc_get_class_ivars (name));
1919 end_at_defs:
1920 /* Parse the struct-declarations and semicolons. Problems with
1921 semicolons are diagnosed here; empty structures are diagnosed
1922 elsewhere. */
1923 while (true)
1925 tree decls;
1926 /* Parse any stray semicolon. */
1927 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1929 if (pedantic)
1930 pedwarn ("%Hextra semicolon in struct or union specified",
1931 &c_parser_peek_token (parser)->location);
1932 c_parser_consume_token (parser);
1933 continue;
1935 /* Stop if at the end of the struct or union contents. */
1936 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1938 c_parser_consume_token (parser);
1939 break;
1941 /* Accept #pragmas at struct scope. */
1942 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1944 c_parser_pragma (parser, pragma_external);
1945 continue;
1947 /* Parse some comma-separated declarations, but not the
1948 trailing semicolon if any. */
1949 decls = c_parser_struct_declaration (parser);
1950 contents = chainon (decls, contents);
1951 /* If no semicolon follows, either we have a parse error or
1952 are at the end of the struct or union and should
1953 pedwarn. */
1954 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1955 c_parser_consume_token (parser);
1956 else
1958 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1959 pedwarn ("%Hno semicolon at end of struct or union",
1960 &c_parser_peek_token (parser)->location);
1961 else
1963 c_parser_error (parser, "expected %<;%>");
1964 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1965 break;
1969 postfix_attrs = c_parser_attributes (parser);
1970 ret.spec = finish_struct (type, nreverse (contents),
1971 chainon (attrs, postfix_attrs));
1972 ret.kind = ctsk_tagdef;
1973 return ret;
1975 else if (!ident)
1977 c_parser_error (parser, "expected %<{%>");
1978 ret.spec = error_mark_node;
1979 ret.kind = ctsk_tagref;
1980 return ret;
1982 ret = parser_xref_tag (code, ident);
1983 return ret;
1986 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1987 the trailing semicolon.
1989 struct-declaration:
1990 specifier-qualifier-list struct-declarator-list
1992 specifier-qualifier-list:
1993 type-specifier specifier-qualifier-list[opt]
1994 type-qualifier specifier-qualifier-list[opt]
1995 attributes specifier-qualifier-list[opt]
1997 struct-declarator-list:
1998 struct-declarator
1999 struct-declarator-list , attributes[opt] struct-declarator
2001 struct-declarator:
2002 declarator attributes[opt]
2003 declarator[opt] : constant-expression attributes[opt]
2005 GNU extensions:
2007 struct-declaration:
2008 __extension__ struct-declaration
2009 specifier-qualifier-list
2011 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2012 of attributes where shown is a GNU extension. In GNU C, we accept
2013 any expression without commas in the syntax (assignment
2014 expressions, not just conditional expressions); assignment
2015 expressions will be diagnosed as non-constant. */
2017 static tree
2018 c_parser_struct_declaration (c_parser *parser)
2020 struct c_declspecs *specs;
2021 tree prefix_attrs;
2022 tree all_prefix_attrs;
2023 tree decls;
2024 location_t decl_loc;
2025 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2027 int ext;
2028 tree decl;
2029 ext = disable_extension_diagnostics ();
2030 c_parser_consume_token (parser);
2031 decl = c_parser_struct_declaration (parser);
2032 restore_extension_diagnostics (ext);
2033 return decl;
2035 specs = build_null_declspecs ();
2036 decl_loc = c_parser_peek_token (parser)->location;
2037 c_parser_declspecs (parser, specs, false, true, true);
2038 if (parser->error)
2039 return NULL_TREE;
2040 if (!specs->declspecs_seen_p)
2042 c_parser_error (parser, "expected specifier-qualifier-list");
2043 return NULL_TREE;
2045 finish_declspecs (specs);
2046 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2048 tree ret;
2049 if (!specs->type_seen_p)
2051 if (pedantic)
2052 pedwarn ("%HISO C forbids member declarations with no members",
2053 &decl_loc);
2054 shadow_tag_warned (specs, pedantic);
2055 ret = NULL_TREE;
2057 else
2059 /* Support for unnamed structs or unions as members of
2060 structs or unions (which is [a] useful and [b] supports
2061 MS P-SDK). */
2062 tree attrs = NULL;
2063 ret = grokfield (build_id_declarator (NULL_TREE), specs,
2064 NULL_TREE, &attrs);
2065 if (ret)
2066 decl_attributes (&ret, attrs, 0);
2068 return ret;
2070 pending_xref_error ();
2071 prefix_attrs = specs->attrs;
2072 all_prefix_attrs = prefix_attrs;
2073 specs->attrs = NULL_TREE;
2074 decls = NULL_TREE;
2075 while (true)
2077 /* Declaring one or more declarators or un-named bit-fields. */
2078 struct c_declarator *declarator;
2079 bool dummy = false;
2080 if (c_parser_next_token_is (parser, CPP_COLON))
2081 declarator = build_id_declarator (NULL_TREE);
2082 else
2083 declarator = c_parser_declarator (parser, specs->type_seen_p,
2084 C_DTR_NORMAL, &dummy);
2085 if (declarator == NULL)
2087 c_parser_skip_to_end_of_block_or_statement (parser);
2088 break;
2090 if (c_parser_next_token_is (parser, CPP_COLON)
2091 || c_parser_next_token_is (parser, CPP_COMMA)
2092 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2093 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2094 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2096 tree postfix_attrs = NULL_TREE;
2097 tree width = NULL_TREE;
2098 tree d;
2099 if (c_parser_next_token_is (parser, CPP_COLON))
2101 c_parser_consume_token (parser);
2102 width = c_parser_expr_no_commas (parser, NULL).value;
2104 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2105 postfix_attrs = c_parser_attributes (parser);
2106 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2107 decl_attributes (&d, chainon (postfix_attrs,
2108 all_prefix_attrs), 0);
2109 TREE_CHAIN (d) = decls;
2110 decls = d;
2111 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2112 all_prefix_attrs = chainon (c_parser_attributes (parser),
2113 prefix_attrs);
2114 else
2115 all_prefix_attrs = prefix_attrs;
2116 if (c_parser_next_token_is (parser, CPP_COMMA))
2117 c_parser_consume_token (parser);
2118 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2119 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2121 /* Semicolon consumed in caller. */
2122 break;
2124 else
2126 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2127 break;
2130 else
2132 c_parser_error (parser,
2133 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2134 "%<__attribute__%>");
2135 break;
2138 return decls;
2141 /* Parse a typeof specifier (a GNU extension).
2143 typeof-specifier:
2144 typeof ( expression )
2145 typeof ( type-name )
2148 static struct c_typespec
2149 c_parser_typeof_specifier (c_parser *parser)
2151 struct c_typespec ret;
2152 ret.kind = ctsk_typeof;
2153 ret.spec = error_mark_node;
2154 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2155 c_parser_consume_token (parser);
2156 skip_evaluation++;
2157 in_typeof++;
2158 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2160 skip_evaluation--;
2161 in_typeof--;
2162 return ret;
2164 if (c_parser_next_token_starts_typename (parser))
2166 struct c_type_name *type = c_parser_type_name (parser);
2167 skip_evaluation--;
2168 in_typeof--;
2169 if (type != NULL)
2171 ret.spec = groktypename (type);
2172 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2175 else
2177 bool was_vm;
2178 location_t here = c_parser_peek_token (parser)->location;
2179 struct c_expr expr = c_parser_expression (parser);
2180 skip_evaluation--;
2181 in_typeof--;
2182 if (TREE_CODE (expr.value) == COMPONENT_REF
2183 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2184 error ("%H%<typeof%> applied to a bit-field", &here);
2185 ret.spec = TREE_TYPE (expr.value);
2186 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2187 /* This should be returned with the type so that when the type
2188 is evaluated, this can be evaluated. For now, we avoid
2189 evaluation when the context might. */
2190 if (!skip_evaluation && was_vm)
2192 tree e = expr.value;
2194 /* If the expression is not of a type to which we cannot assign a line
2195 number, wrap the thing in a no-op NOP_EXPR. */
2196 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2197 e = build1 (NOP_EXPR, void_type_node, e);
2199 if (CAN_HAVE_LOCATION_P (e))
2200 SET_EXPR_LOCATION (e, input_location);
2202 add_stmt (e);
2204 pop_maybe_used (was_vm);
2206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2207 return ret;
2210 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2211 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2212 be redeclared; otherwise it may not. KIND indicates which kind of
2213 declarator is wanted. Returns a valid declarator except in the
2214 case of a syntax error in which case NULL is returned. *SEEN_ID is
2215 set to true if an identifier being declared is seen; this is used
2216 to diagnose bad forms of abstract array declarators and to
2217 determine whether an identifier list is syntactically permitted.
2219 declarator:
2220 pointer[opt] direct-declarator
2222 direct-declarator:
2223 identifier
2224 ( attributes[opt] declarator )
2225 direct-declarator array-declarator
2226 direct-declarator ( parameter-type-list )
2227 direct-declarator ( identifier-list[opt] )
2229 pointer:
2230 * type-qualifier-list[opt]
2231 * type-qualifier-list[opt] pointer
2233 type-qualifier-list:
2234 type-qualifier
2235 attributes
2236 type-qualifier-list type-qualifier
2237 type-qualifier-list attributes
2239 parameter-type-list:
2240 parameter-list
2241 parameter-list , ...
2243 parameter-list:
2244 parameter-declaration
2245 parameter-list , parameter-declaration
2247 parameter-declaration:
2248 declaration-specifiers declarator attributes[opt]
2249 declaration-specifiers abstract-declarator[opt] attributes[opt]
2251 identifier-list:
2252 identifier
2253 identifier-list , identifier
2255 abstract-declarator:
2256 pointer
2257 pointer[opt] direct-abstract-declarator
2259 direct-abstract-declarator:
2260 ( attributes[opt] abstract-declarator )
2261 direct-abstract-declarator[opt] array-declarator
2262 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2264 GNU extensions:
2266 direct-declarator:
2267 direct-declarator ( parameter-forward-declarations
2268 parameter-type-list[opt] )
2270 direct-abstract-declarator:
2271 direct-abstract-declarator[opt] ( parameter-forward-declarations
2272 parameter-type-list[opt] )
2274 parameter-forward-declarations:
2275 parameter-list ;
2276 parameter-forward-declarations parameter-list ;
2278 The uses of attributes shown above are GNU extensions.
2280 Some forms of array declarator are not included in C99 in the
2281 syntax for abstract declarators; these are disallowed elsewhere.
2282 This may be a defect (DR#289).
2284 This function also accepts an omitted abstract declarator as being
2285 an abstract declarator, although not part of the formal syntax. */
2287 static struct c_declarator *
2288 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2289 bool *seen_id)
2291 /* Parse any initial pointer part. */
2292 if (c_parser_next_token_is (parser, CPP_MULT))
2294 struct c_declspecs *quals_attrs = build_null_declspecs ();
2295 struct c_declarator *inner;
2296 c_parser_consume_token (parser);
2297 c_parser_declspecs (parser, quals_attrs, false, false, true);
2298 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2299 if (inner == NULL)
2300 return NULL;
2301 else
2302 return make_pointer_declarator (quals_attrs, inner);
2304 /* Now we have a direct declarator, direct abstract declarator or
2305 nothing (which counts as a direct abstract declarator here). */
2306 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2309 /* Parse a direct declarator or direct abstract declarator; arguments
2310 as c_parser_declarator. */
2312 static struct c_declarator *
2313 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2314 bool *seen_id)
2316 /* The direct declarator must start with an identifier (possibly
2317 omitted) or a parenthesized declarator (possibly abstract). In
2318 an ordinary declarator, initial parentheses must start a
2319 parenthesized declarator. In an abstract declarator or parameter
2320 declarator, they could start a parenthesized declarator or a
2321 parameter list. To tell which, the open parenthesis and any
2322 following attributes must be read. If a declaration specifier
2323 follows, then it is a parameter list; if the specifier is a
2324 typedef name, there might be an ambiguity about redeclaring it,
2325 which is resolved in the direction of treating it as a typedef
2326 name. If a close parenthesis follows, it is also an empty
2327 parameter list, as the syntax does not permit empty abstract
2328 declarators. Otherwise, it is a parenthesized declarator (in
2329 which case the analysis may be repeated inside it, recursively).
2331 ??? There is an ambiguity in a parameter declaration "int
2332 (__attribute__((foo)) x)", where x is not a typedef name: it
2333 could be an abstract declarator for a function, or declare x with
2334 parentheses. The proper resolution of this ambiguity needs
2335 documenting. At present we follow an accident of the old
2336 parser's implementation, whereby the first parameter must have
2337 some declaration specifiers other than just attributes. Thus as
2338 a parameter declaration it is treated as a parenthesized
2339 parameter named x, and as an abstract declarator it is
2340 rejected.
2342 ??? Also following the old parser, attributes inside an empty
2343 parameter list are ignored, making it a list not yielding a
2344 prototype, rather than giving an error or making it have one
2345 parameter with implicit type int.
2347 ??? Also following the old parser, typedef names may be
2348 redeclared in declarators, but not Objective-C class names. */
2350 if (kind != C_DTR_ABSTRACT
2351 && c_parser_next_token_is (parser, CPP_NAME)
2352 && ((type_seen_p
2353 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2354 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2356 struct c_declarator *inner
2357 = build_id_declarator (c_parser_peek_token (parser)->value);
2358 *seen_id = true;
2359 inner->id_loc = c_parser_peek_token (parser)->location;
2360 c_parser_consume_token (parser);
2361 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2364 if (kind != C_DTR_NORMAL
2365 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2367 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2368 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2371 /* Either we are at the end of an abstract declarator, or we have
2372 parentheses. */
2374 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2376 tree attrs;
2377 struct c_declarator *inner;
2378 c_parser_consume_token (parser);
2379 attrs = c_parser_attributes (parser);
2380 if (kind != C_DTR_NORMAL
2381 && (c_parser_next_token_starts_declspecs (parser)
2382 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2384 struct c_arg_info *args
2385 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2386 attrs);
2387 if (args == NULL)
2388 return NULL;
2389 else
2391 inner
2392 = build_function_declarator (args,
2393 build_id_declarator (NULL_TREE));
2394 return c_parser_direct_declarator_inner (parser, *seen_id,
2395 inner);
2398 /* A parenthesized declarator. */
2399 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2400 if (inner != NULL && attrs != NULL)
2401 inner = build_attrs_declarator (attrs, inner);
2402 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2404 c_parser_consume_token (parser);
2405 if (inner == NULL)
2406 return NULL;
2407 else
2408 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2410 else
2412 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2413 "expected %<)%>");
2414 return NULL;
2417 else
2419 if (kind == C_DTR_NORMAL)
2421 c_parser_error (parser, "expected identifier or %<(%>");
2422 return NULL;
2424 else
2425 return build_id_declarator (NULL_TREE);
2429 /* Parse part of a direct declarator or direct abstract declarator,
2430 given that some (in INNER) has already been parsed; ID_PRESENT is
2431 true if an identifier is present, false for an abstract
2432 declarator. */
2434 static struct c_declarator *
2435 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2436 struct c_declarator *inner)
2438 /* Parse a sequence of array declarators and parameter lists. */
2439 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2441 struct c_declarator *declarator;
2442 struct c_declspecs *quals_attrs = build_null_declspecs ();
2443 bool static_seen;
2444 bool star_seen;
2445 tree dimen;
2446 c_parser_consume_token (parser);
2447 c_parser_declspecs (parser, quals_attrs, false, false, true);
2448 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2449 if (static_seen)
2450 c_parser_consume_token (parser);
2451 if (static_seen && !quals_attrs->declspecs_seen_p)
2452 c_parser_declspecs (parser, quals_attrs, false, false, true);
2453 if (!quals_attrs->declspecs_seen_p)
2454 quals_attrs = NULL;
2455 /* If "static" is present, there must be an array dimension.
2456 Otherwise, there may be a dimension, "*", or no
2457 dimension. */
2458 if (static_seen)
2460 star_seen = false;
2461 dimen = c_parser_expr_no_commas (parser, NULL).value;
2463 else
2465 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2467 dimen = NULL_TREE;
2468 star_seen = false;
2470 else if (c_parser_next_token_is (parser, CPP_MULT))
2472 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2474 dimen = NULL_TREE;
2475 star_seen = true;
2476 c_parser_consume_token (parser);
2478 else
2480 star_seen = false;
2481 dimen = c_parser_expr_no_commas (parser, NULL).value;
2484 else
2486 star_seen = false;
2487 dimen = c_parser_expr_no_commas (parser, NULL).value;
2490 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2491 c_parser_consume_token (parser);
2492 else
2494 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2495 "expected %<]%>");
2496 return NULL;
2498 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2499 star_seen);
2500 if (declarator == NULL)
2501 return NULL;
2502 inner = set_array_declarator_inner (declarator, inner, !id_present);
2503 return c_parser_direct_declarator_inner (parser, id_present, inner);
2505 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2507 tree attrs;
2508 struct c_arg_info *args;
2509 c_parser_consume_token (parser);
2510 attrs = c_parser_attributes (parser);
2511 args = c_parser_parms_declarator (parser, id_present, attrs);
2512 if (args == NULL)
2513 return NULL;
2514 else
2516 inner = build_function_declarator (args, inner);
2517 return c_parser_direct_declarator_inner (parser, id_present, inner);
2520 return inner;
2523 /* Parse a parameter list or identifier list, including the closing
2524 parenthesis but not the opening one. ATTRS are the attributes at
2525 the start of the list. ID_LIST_OK is true if an identifier list is
2526 acceptable; such a list must not have attributes at the start. */
2528 static struct c_arg_info *
2529 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2531 push_scope ();
2532 declare_parm_level ();
2533 /* If the list starts with an identifier, it is an identifier list.
2534 Otherwise, it is either a prototype list or an empty list. */
2535 if (id_list_ok
2536 && !attrs
2537 && c_parser_next_token_is (parser, CPP_NAME)
2538 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2540 tree list = NULL_TREE, *nextp = &list;
2541 while (c_parser_next_token_is (parser, CPP_NAME)
2542 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2544 *nextp = build_tree_list (NULL_TREE,
2545 c_parser_peek_token (parser)->value);
2546 nextp = & TREE_CHAIN (*nextp);
2547 c_parser_consume_token (parser);
2548 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2549 break;
2550 c_parser_consume_token (parser);
2551 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2553 c_parser_error (parser, "expected identifier");
2554 break;
2557 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2559 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2560 ret->parms = 0;
2561 ret->tags = 0;
2562 ret->types = list;
2563 ret->others = 0;
2564 ret->pending_sizes = 0;
2565 ret->had_vla_unspec = 0;
2566 c_parser_consume_token (parser);
2567 pop_scope ();
2568 return ret;
2570 else
2572 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2573 "expected %<)%>");
2574 pop_scope ();
2575 return NULL;
2578 else
2580 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2581 pop_scope ();
2582 return ret;
2586 /* Parse a parameter list (possibly empty), including the closing
2587 parenthesis but not the opening one. ATTRS are the attributes at
2588 the start of the list. */
2590 static struct c_arg_info *
2591 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2593 bool good_parm = false;
2594 /* ??? Following the old parser, forward parameter declarations may
2595 use abstract declarators, and if no real parameter declarations
2596 follow the forward declarations then this is not diagnosed. Also
2597 note as above that attributes are ignored as the only contents of
2598 the parentheses, or as the only contents after forward
2599 declarations. */
2600 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2602 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2603 ret->parms = 0;
2604 ret->tags = 0;
2605 ret->types = 0;
2606 ret->others = 0;
2607 ret->pending_sizes = 0;
2608 ret->had_vla_unspec = 0;
2609 c_parser_consume_token (parser);
2610 return ret;
2612 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2614 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2615 ret->parms = 0;
2616 ret->tags = 0;
2617 ret->others = 0;
2618 ret->pending_sizes = 0;
2619 ret->had_vla_unspec = 0;
2620 /* Suppress -Wold-style-definition for this case. */
2621 ret->types = error_mark_node;
2622 error ("%HISO C requires a named argument before %<...%>",
2623 &c_parser_peek_token (parser)->location);
2624 c_parser_consume_token (parser);
2625 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2627 c_parser_consume_token (parser);
2628 return ret;
2630 else
2632 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2633 "expected %<)%>");
2634 return NULL;
2637 /* Nonempty list of parameters, either terminated with semicolon
2638 (forward declarations; recurse) or with close parenthesis (normal
2639 function) or with ", ... )" (variadic function). */
2640 while (true)
2642 /* Parse a parameter. */
2643 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2644 attrs = NULL_TREE;
2645 if (parm != NULL)
2647 good_parm = true;
2648 push_parm_decl (parm);
2650 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2652 tree new_attrs;
2653 c_parser_consume_token (parser);
2654 mark_forward_parm_decls ();
2655 new_attrs = c_parser_attributes (parser);
2656 return c_parser_parms_list_declarator (parser, new_attrs);
2658 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2660 c_parser_consume_token (parser);
2661 if (good_parm)
2662 return get_parm_info (false);
2663 else
2665 struct c_arg_info *ret
2666 = XOBNEW (&parser_obstack, struct c_arg_info);
2667 ret->parms = 0;
2668 ret->tags = 0;
2669 ret->types = 0;
2670 ret->others = 0;
2671 ret->pending_sizes = 0;
2672 ret->had_vla_unspec = 0;
2673 return ret;
2676 if (!c_parser_require (parser, CPP_COMMA,
2677 "expected %<;%>, %<,%> or %<)%>"))
2679 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2680 return NULL;
2682 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2684 c_parser_consume_token (parser);
2685 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2687 c_parser_consume_token (parser);
2688 if (good_parm)
2689 return get_parm_info (true);
2690 else
2692 struct c_arg_info *ret
2693 = XOBNEW (&parser_obstack, struct c_arg_info);
2694 ret->parms = 0;
2695 ret->tags = 0;
2696 ret->types = 0;
2697 ret->others = 0;
2698 ret->pending_sizes = 0;
2699 ret->had_vla_unspec = 0;
2700 return ret;
2703 else
2705 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2706 "expected %<)%>");
2707 return NULL;
2713 /* Parse a parameter declaration. ATTRS are the attributes at the
2714 start of the declaration if it is the first parameter. */
2716 static struct c_parm *
2717 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2719 struct c_declspecs *specs;
2720 struct c_declarator *declarator;
2721 tree prefix_attrs;
2722 tree postfix_attrs = NULL_TREE;
2723 bool dummy = false;
2724 if (!c_parser_next_token_starts_declspecs (parser))
2726 /* ??? In some Objective-C cases '...' isn't applicable so there
2727 should be a different message. */
2728 c_parser_error (parser,
2729 "expected declaration specifiers or %<...%>");
2730 c_parser_skip_to_end_of_parameter (parser);
2731 return NULL;
2733 specs = build_null_declspecs ();
2734 if (attrs)
2736 declspecs_add_attrs (specs, attrs);
2737 attrs = NULL_TREE;
2739 c_parser_declspecs (parser, specs, true, true, true);
2740 finish_declspecs (specs);
2741 pending_xref_error ();
2742 prefix_attrs = specs->attrs;
2743 specs->attrs = NULL_TREE;
2744 declarator = c_parser_declarator (parser, specs->type_seen_p,
2745 C_DTR_PARM, &dummy);
2746 if (declarator == NULL)
2748 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2749 return NULL;
2751 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2752 postfix_attrs = c_parser_attributes (parser);
2753 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2754 declarator);
2757 /* Parse a string literal in an asm expression. It should not be
2758 translated, and wide string literals are an error although
2759 permitted by the syntax. This is a GNU extension.
2761 asm-string-literal:
2762 string-literal
2764 ??? At present, following the old parser, the caller needs to have
2765 set lex_untranslated_string to 1. It would be better to follow the
2766 C++ parser rather than using this kludge. */
2768 static tree
2769 c_parser_asm_string_literal (c_parser *parser)
2771 tree str;
2772 if (c_parser_next_token_is (parser, CPP_STRING))
2774 str = c_parser_peek_token (parser)->value;
2775 c_parser_consume_token (parser);
2777 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2779 error ("%Hwide string literal in %<asm%>",
2780 &c_parser_peek_token (parser)->location);
2781 str = build_string (1, "");
2782 c_parser_consume_token (parser);
2784 else
2786 c_parser_error (parser, "expected string literal");
2787 str = NULL_TREE;
2789 return str;
2792 /* Parse a simple asm expression. This is used in restricted
2793 contexts, where a full expression with inputs and outputs does not
2794 make sense. This is a GNU extension.
2796 simple-asm-expr:
2797 asm ( asm-string-literal )
2800 static tree
2801 c_parser_simple_asm_expr (c_parser *parser)
2803 tree str;
2804 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2805 /* ??? Follow the C++ parser rather than using the
2806 lex_untranslated_string kludge. */
2807 parser->lex_untranslated_string = true;
2808 c_parser_consume_token (parser);
2809 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2811 parser->lex_untranslated_string = false;
2812 return NULL_TREE;
2814 str = c_parser_asm_string_literal (parser);
2815 parser->lex_untranslated_string = false;
2816 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2818 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2819 return NULL_TREE;
2821 return str;
2824 /* Parse (possibly empty) attributes. This is a GNU extension.
2826 attributes:
2827 empty
2828 attributes attribute
2830 attribute:
2831 __attribute__ ( ( attribute-list ) )
2833 attribute-list:
2834 attrib
2835 attribute_list , attrib
2837 attrib:
2838 empty
2839 any-word
2840 any-word ( identifier )
2841 any-word ( identifier , nonempty-expr-list )
2842 any-word ( expr-list )
2844 where the "identifier" must not be declared as a type, and
2845 "any-word" may be any identifier (including one declared as a
2846 type), a reserved word storage class specifier, type specifier or
2847 type qualifier. ??? This still leaves out most reserved keywords
2848 (following the old parser), shouldn't we include them, and why not
2849 allow identifiers declared as types to start the arguments? */
2851 static tree
2852 c_parser_attributes (c_parser *parser)
2854 tree attrs = NULL_TREE;
2855 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2857 /* ??? Follow the C++ parser rather than using the
2858 lex_untranslated_string kludge. */
2859 parser->lex_untranslated_string = true;
2860 c_parser_consume_token (parser);
2861 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2863 parser->lex_untranslated_string = false;
2864 return attrs;
2866 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2868 parser->lex_untranslated_string = false;
2869 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2870 return attrs;
2872 /* Parse the attribute list. */
2873 while (c_parser_next_token_is (parser, CPP_COMMA)
2874 || c_parser_next_token_is (parser, CPP_NAME)
2875 || c_parser_next_token_is (parser, CPP_KEYWORD))
2877 tree attr, attr_name, attr_args;
2878 if (c_parser_next_token_is (parser, CPP_COMMA))
2880 c_parser_consume_token (parser);
2881 continue;
2883 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2885 /* ??? See comment above about what keywords are
2886 accepted here. */
2887 bool ok;
2888 switch (c_parser_peek_token (parser)->keyword)
2890 case RID_STATIC:
2891 case RID_UNSIGNED:
2892 case RID_LONG:
2893 case RID_CONST:
2894 case RID_EXTERN:
2895 case RID_REGISTER:
2896 case RID_TYPEDEF:
2897 case RID_SHORT:
2898 case RID_INLINE:
2899 case RID_VOLATILE:
2900 case RID_SIGNED:
2901 case RID_AUTO:
2902 case RID_RESTRICT:
2903 case RID_COMPLEX:
2904 case RID_THREAD:
2905 case RID_INT:
2906 case RID_CHAR:
2907 case RID_FLOAT:
2908 case RID_DOUBLE:
2909 case RID_VOID:
2910 case RID_DFLOAT32:
2911 case RID_DFLOAT64:
2912 case RID_DFLOAT128:
2913 case RID_BOOL:
2914 case RID_FRACT:
2915 case RID_ACCUM:
2916 case RID_SAT:
2917 ok = true;
2918 break;
2919 default:
2920 ok = false;
2921 break;
2923 if (!ok)
2924 break;
2926 attr_name = c_parser_peek_token (parser)->value;
2927 c_parser_consume_token (parser);
2928 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2930 attr = build_tree_list (attr_name, NULL_TREE);
2931 attrs = chainon (attrs, attr);
2932 continue;
2934 c_parser_consume_token (parser);
2935 /* Parse the attribute contents. If they start with an
2936 identifier which is followed by a comma or close
2937 parenthesis, then the arguments start with that
2938 identifier; otherwise they are an expression list. */
2939 if (c_parser_next_token_is (parser, CPP_NAME)
2940 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2941 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2942 || (c_parser_peek_2nd_token (parser)->type
2943 == CPP_CLOSE_PAREN)))
2945 tree arg1 = c_parser_peek_token (parser)->value;
2946 c_parser_consume_token (parser);
2947 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2948 attr_args = build_tree_list (NULL_TREE, arg1);
2949 else
2951 c_parser_consume_token (parser);
2952 attr_args = tree_cons (NULL_TREE, arg1,
2953 c_parser_expr_list (parser, false));
2956 else
2958 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2959 attr_args = NULL_TREE;
2960 else
2961 attr_args = c_parser_expr_list (parser, false);
2963 attr = build_tree_list (attr_name, attr_args);
2964 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2965 c_parser_consume_token (parser);
2966 else
2968 parser->lex_untranslated_string = false;
2969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2970 "expected %<)%>");
2971 return attrs;
2973 attrs = chainon (attrs, attr);
2975 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2976 c_parser_consume_token (parser);
2977 else
2979 parser->lex_untranslated_string = false;
2980 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2981 "expected %<)%>");
2982 return attrs;
2984 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2985 c_parser_consume_token (parser);
2986 else
2988 parser->lex_untranslated_string = false;
2989 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2990 "expected %<)%>");
2991 return attrs;
2993 parser->lex_untranslated_string = false;
2995 return attrs;
2998 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3000 type-name:
3001 specifier-qualifier-list abstract-declarator[opt]
3004 static struct c_type_name *
3005 c_parser_type_name (c_parser *parser)
3007 struct c_declspecs *specs = build_null_declspecs ();
3008 struct c_declarator *declarator;
3009 struct c_type_name *ret;
3010 bool dummy = false;
3011 c_parser_declspecs (parser, specs, false, true, true);
3012 if (!specs->declspecs_seen_p)
3014 c_parser_error (parser, "expected specifier-qualifier-list");
3015 return NULL;
3017 pending_xref_error ();
3018 finish_declspecs (specs);
3019 declarator = c_parser_declarator (parser, specs->type_seen_p,
3020 C_DTR_ABSTRACT, &dummy);
3021 if (declarator == NULL)
3022 return NULL;
3023 ret = XOBNEW (&parser_obstack, struct c_type_name);
3024 ret->specs = specs;
3025 ret->declarator = declarator;
3026 return ret;
3029 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3031 initializer:
3032 assignment-expression
3033 { initializer-list }
3034 { initializer-list , }
3036 initializer-list:
3037 designation[opt] initializer
3038 initializer-list , designation[opt] initializer
3040 designation:
3041 designator-list =
3043 designator-list:
3044 designator
3045 designator-list designator
3047 designator:
3048 array-designator
3049 . identifier
3051 array-designator:
3052 [ constant-expression ]
3054 GNU extensions:
3056 initializer:
3059 designation:
3060 array-designator
3061 identifier :
3063 array-designator:
3064 [ constant-expression ... constant-expression ]
3066 Any expression without commas is accepted in the syntax for the
3067 constant-expressions, with non-constant expressions rejected later.
3069 This function is only used for top-level initializers; for nested
3070 ones, see c_parser_initval. */
3072 static struct c_expr
3073 c_parser_initializer (c_parser *parser)
3075 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3076 return c_parser_braced_init (parser, NULL_TREE, false);
3077 else
3079 struct c_expr ret;
3080 ret = c_parser_expr_no_commas (parser, NULL);
3081 if (TREE_CODE (ret.value) != STRING_CST
3082 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3083 ret = default_function_array_conversion (ret);
3084 return ret;
3088 /* Parse a braced initializer list. TYPE is the type specified for a
3089 compound literal, and NULL_TREE for other initializers and for
3090 nested braced lists. NESTED_P is true for nested braced lists,
3091 false for the list of a compound literal or the list that is the
3092 top-level initializer in a declaration. */
3094 static struct c_expr
3095 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3097 location_t brace_loc = c_parser_peek_token (parser)->location;
3098 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3099 c_parser_consume_token (parser);
3100 if (nested_p)
3101 push_init_level (0);
3102 else
3103 really_start_incremental_init (type);
3104 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3106 if (pedantic)
3107 pedwarn ("%HISO C forbids empty initializer braces", &brace_loc);
3109 else
3111 /* Parse a non-empty initializer list, possibly with a trailing
3112 comma. */
3113 while (true)
3115 c_parser_initelt (parser);
3116 if (parser->error)
3117 break;
3118 if (c_parser_next_token_is (parser, CPP_COMMA))
3119 c_parser_consume_token (parser);
3120 else
3121 break;
3122 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3123 break;
3126 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3128 struct c_expr ret;
3129 ret.value = error_mark_node;
3130 ret.original_code = ERROR_MARK;
3131 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3132 return ret;
3134 c_parser_consume_token (parser);
3135 return pop_init_level (0);
3138 /* Parse a nested initializer, including designators. */
3140 static void
3141 c_parser_initelt (c_parser *parser)
3143 /* Parse any designator or designator list. A single array
3144 designator may have the subsequent "=" omitted in GNU C, but a
3145 longer list or a structure member designator may not. */
3146 if (c_parser_next_token_is (parser, CPP_NAME)
3147 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3149 /* Old-style structure member designator. */
3150 set_init_label (c_parser_peek_token (parser)->value);
3151 if (pedantic)
3153 /* Use the colon as the error location. */
3154 pedwarn ("%Hobsolete use of designated initializer with %<:%>",
3155 &c_parser_peek_2nd_token (parser)->location);
3157 c_parser_consume_token (parser);
3158 c_parser_consume_token (parser);
3160 else
3162 /* des_seen is 0 if there have been no designators, 1 if there
3163 has been a single array designator and 2 otherwise. */
3164 int des_seen = 0;
3165 /* Location of a designator. */
3166 location_t des_loc;
3167 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3168 || c_parser_next_token_is (parser, CPP_DOT))
3170 int des_prev = des_seen;
3171 if (!des_seen)
3172 des_loc = c_parser_peek_token (parser)->location;
3173 if (des_seen < 2)
3174 des_seen++;
3175 if (c_parser_next_token_is (parser, CPP_DOT))
3177 des_seen = 2;
3178 c_parser_consume_token (parser);
3179 if (c_parser_next_token_is (parser, CPP_NAME))
3181 set_init_label (c_parser_peek_token (parser)->value);
3182 c_parser_consume_token (parser);
3184 else
3186 struct c_expr init;
3187 init.value = error_mark_node;
3188 init.original_code = ERROR_MARK;
3189 c_parser_error (parser, "expected identifier");
3190 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3191 process_init_element (init);
3192 return;
3195 else
3197 tree first, second;
3198 location_t ellipsis_loc;
3199 /* ??? Following the old parser, [ objc-receiver
3200 objc-message-args ] is accepted as an initializer,
3201 being distinguished from a designator by what follows
3202 the first assignment expression inside the square
3203 brackets, but after a first array designator a
3204 subsequent square bracket is for Objective-C taken to
3205 start an expression, using the obsolete form of
3206 designated initializer without '=', rather than
3207 possibly being a second level of designation: in LALR
3208 terms, the '[' is shifted rather than reducing
3209 designator to designator-list. */
3210 if (des_prev == 1 && c_dialect_objc ())
3212 des_seen = des_prev;
3213 break;
3215 if (des_prev == 0 && c_dialect_objc ())
3217 /* This might be an array designator or an
3218 Objective-C message expression. If the former,
3219 continue parsing here; if the latter, parse the
3220 remainder of the initializer given the starting
3221 primary-expression. ??? It might make sense to
3222 distinguish when des_prev == 1 as well; see
3223 previous comment. */
3224 tree rec, args;
3225 struct c_expr mexpr;
3226 c_parser_consume_token (parser);
3227 if (c_parser_peek_token (parser)->type == CPP_NAME
3228 && ((c_parser_peek_token (parser)->id_kind
3229 == C_ID_TYPENAME)
3230 || (c_parser_peek_token (parser)->id_kind
3231 == C_ID_CLASSNAME)))
3233 /* Type name receiver. */
3234 tree id = c_parser_peek_token (parser)->value;
3235 c_parser_consume_token (parser);
3236 rec = objc_get_class_reference (id);
3237 goto parse_message_args;
3239 first = c_parser_expr_no_commas (parser, NULL).value;
3240 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3241 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3242 goto array_desig_after_first;
3243 /* Expression receiver. So far only one part
3244 without commas has been parsed; there might be
3245 more of the expression. */
3246 rec = first;
3247 while (c_parser_next_token_is (parser, CPP_COMMA))
3249 struct c_expr next;
3250 c_parser_consume_token (parser);
3251 next = c_parser_expr_no_commas (parser, NULL);
3252 next = default_function_array_conversion (next);
3253 rec = build_compound_expr (rec, next.value);
3255 parse_message_args:
3256 /* Now parse the objc-message-args. */
3257 args = c_parser_objc_message_args (parser);
3258 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3259 "expected %<]%>");
3260 mexpr.value
3261 = objc_build_message_expr (build_tree_list (rec, args));
3262 mexpr.original_code = ERROR_MARK;
3263 /* Now parse and process the remainder of the
3264 initializer, starting with this message
3265 expression as a primary-expression. */
3266 c_parser_initval (parser, &mexpr);
3267 return;
3269 c_parser_consume_token (parser);
3270 first = c_parser_expr_no_commas (parser, NULL).value;
3271 array_desig_after_first:
3272 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3274 ellipsis_loc = c_parser_peek_token (parser)->location;
3275 c_parser_consume_token (parser);
3276 second = c_parser_expr_no_commas (parser, NULL).value;
3278 else
3279 second = NULL_TREE;
3280 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3282 c_parser_consume_token (parser);
3283 set_init_index (first, second);
3284 if (pedantic && second)
3285 pedwarn ("%HISO C forbids specifying range of "
3286 "elements to initialize", &ellipsis_loc);
3288 else
3289 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3290 "expected %<]%>");
3293 if (des_seen >= 1)
3295 if (c_parser_next_token_is (parser, CPP_EQ))
3297 if (pedantic && !flag_isoc99)
3298 pedwarn ("%HISO C90 forbids specifying subobject "
3299 "to initialize", &des_loc);
3300 c_parser_consume_token (parser);
3302 else
3304 if (des_seen == 1)
3306 if (pedantic)
3307 pedwarn ("%Hobsolete use of designated initializer "
3308 "without %<=%>",
3309 &c_parser_peek_token (parser)->location);
3311 else
3313 struct c_expr init;
3314 init.value = error_mark_node;
3315 init.original_code = ERROR_MARK;
3316 c_parser_error (parser, "expected %<=%>");
3317 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3318 process_init_element (init);
3319 return;
3324 c_parser_initval (parser, NULL);
3327 /* Parse a nested initializer; as c_parser_initializer but parses
3328 initializers within braced lists, after any designators have been
3329 applied. If AFTER is not NULL then it is an Objective-C message
3330 expression which is the primary-expression starting the
3331 initializer. */
3333 static void
3334 c_parser_initval (c_parser *parser, struct c_expr *after)
3336 struct c_expr init;
3337 gcc_assert (!after || c_dialect_objc ());
3338 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3339 init = c_parser_braced_init (parser, NULL_TREE, true);
3340 else
3342 init = c_parser_expr_no_commas (parser, after);
3343 if (init.value != NULL_TREE
3344 && TREE_CODE (init.value) != STRING_CST
3345 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3346 init = default_function_array_conversion (init);
3348 process_init_element (init);
3351 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3352 C99 6.8.2).
3354 compound-statement:
3355 { block-item-list[opt] }
3356 { label-declarations block-item-list }
3358 block-item-list:
3359 block-item
3360 block-item-list block-item
3362 block-item:
3363 nested-declaration
3364 statement
3366 nested-declaration:
3367 declaration
3369 GNU extensions:
3371 compound-statement:
3372 { label-declarations block-item-list }
3374 nested-declaration:
3375 __extension__ nested-declaration
3376 nested-function-definition
3378 label-declarations:
3379 label-declaration
3380 label-declarations label-declaration
3382 label-declaration:
3383 __label__ identifier-list ;
3385 Allowing the mixing of declarations and code is new in C99. The
3386 GNU syntax also permits (not shown above) labels at the end of
3387 compound statements, which yield an error. We don't allow labels
3388 on declarations; this might seem like a natural extension, but
3389 there would be a conflict between attributes on the label and
3390 prefix attributes on the declaration. ??? The syntax follows the
3391 old parser in requiring something after label declarations.
3392 Although they are erroneous if the labels declared aren't defined,
3393 is it useful for the syntax to be this way?
3395 OpenMP:
3397 block-item:
3398 openmp-directive
3400 openmp-directive:
3401 barrier-directive
3402 flush-directive */
3404 static tree
3405 c_parser_compound_statement (c_parser *parser)
3407 tree stmt;
3408 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3409 return error_mark_node;
3410 stmt = c_begin_compound_stmt (true);
3411 c_parser_compound_statement_nostart (parser);
3412 return c_end_compound_stmt (stmt, true);
3415 /* Parse a compound statement except for the opening brace. This is
3416 used for parsing both compound statements and statement expressions
3417 (which follow different paths to handling the opening). */
3419 static void
3420 c_parser_compound_statement_nostart (c_parser *parser)
3422 bool last_stmt = false;
3423 bool last_label = false;
3424 location_t label_loc;
3425 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3427 c_parser_consume_token (parser);
3428 return;
3430 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3432 location_t err_loc = c_parser_peek_token (parser)->location;
3433 /* Read zero or more forward-declarations for labels that nested
3434 functions can jump to. */
3435 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3437 c_parser_consume_token (parser);
3438 /* Any identifiers, including those declared as type names,
3439 are OK here. */
3440 while (true)
3442 tree label;
3443 if (c_parser_next_token_is_not (parser, CPP_NAME))
3445 c_parser_error (parser, "expected identifier");
3446 break;
3448 label
3449 = declare_label (c_parser_peek_token (parser)->value);
3450 C_DECLARED_LABEL_FLAG (label) = 1;
3451 add_stmt (build_stmt (DECL_EXPR, label));
3452 c_parser_consume_token (parser);
3453 if (c_parser_next_token_is (parser, CPP_COMMA))
3454 c_parser_consume_token (parser);
3455 else
3456 break;
3458 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3460 if (pedantic)
3461 pedwarn ("%HISO C forbids label declarations", &err_loc);
3463 /* We must now have at least one statement, label or declaration. */
3464 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3466 c_parser_error (parser, "expected declaration or statement");
3467 c_parser_consume_token (parser);
3468 return;
3470 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3472 location_t loc = c_parser_peek_token (parser)->location;
3473 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3474 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3475 || (c_parser_next_token_is (parser, CPP_NAME)
3476 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3478 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3479 label_loc = c_parser_peek_2nd_token (parser)->location;
3480 else
3481 label_loc = c_parser_peek_token (parser)->location;
3482 last_label = true;
3483 last_stmt = false;
3484 c_parser_label (parser);
3486 else if (!last_label
3487 && c_parser_next_token_starts_declspecs (parser))
3489 last_label = false;
3490 c_parser_declaration_or_fndef (parser, true, true, true, true);
3491 if (last_stmt
3492 && ((pedantic && !flag_isoc99)
3493 || warn_declaration_after_statement))
3494 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3495 &loc);
3496 last_stmt = false;
3498 else if (!last_label
3499 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3501 /* __extension__ can start a declaration, but is also an
3502 unary operator that can start an expression. Consume all
3503 but the last of a possible series of __extension__ to
3504 determine which. */
3505 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3506 && (c_parser_peek_2nd_token (parser)->keyword
3507 == RID_EXTENSION))
3508 c_parser_consume_token (parser);
3509 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3511 int ext;
3512 ext = disable_extension_diagnostics ();
3513 c_parser_consume_token (parser);
3514 last_label = false;
3515 c_parser_declaration_or_fndef (parser, true, true, true, true);
3516 /* Following the old parser, __extension__ does not
3517 disable this diagnostic. */
3518 restore_extension_diagnostics (ext);
3519 if (last_stmt
3520 && ((pedantic && !flag_isoc99)
3521 || warn_declaration_after_statement))
3522 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3523 &loc);
3524 last_stmt = false;
3526 else
3527 goto statement;
3529 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3531 /* External pragmas, and some omp pragmas, are not associated
3532 with regular c code, and so are not to be considered statements
3533 syntactically. This ensures that the user doesn't put them
3534 places that would turn into syntax errors if the directive
3535 were ignored. */
3536 if (c_parser_pragma (parser, pragma_compound))
3537 last_label = false, last_stmt = true;
3539 else if (c_parser_next_token_is (parser, CPP_EOF))
3541 c_parser_error (parser, "expected declaration or statement");
3542 return;
3544 else
3546 statement:
3547 last_label = false;
3548 last_stmt = true;
3549 c_parser_statement_after_labels (parser);
3552 parser->error = false;
3554 if (last_label)
3555 error ("%Hlabel at end of compound statement", &label_loc);
3556 c_parser_consume_token (parser);
3559 /* Parse a label (C90 6.6.1, C99 6.8.1).
3561 label:
3562 identifier : attributes[opt]
3563 case constant-expression :
3564 default :
3566 GNU extensions:
3568 label:
3569 case constant-expression ... constant-expression :
3571 The use of attributes on labels is a GNU extension. The syntax in
3572 GNU C accepts any expressions without commas, non-constant
3573 expressions being rejected later. */
3575 static void
3576 c_parser_label (c_parser *parser)
3578 location_t loc1 = c_parser_peek_token (parser)->location;
3579 tree label = NULL_TREE;
3580 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3582 tree exp1, exp2;
3583 c_parser_consume_token (parser);
3584 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3585 if (c_parser_next_token_is (parser, CPP_COLON))
3587 c_parser_consume_token (parser);
3588 label = do_case (exp1, NULL_TREE);
3590 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3592 c_parser_consume_token (parser);
3593 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3594 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3595 label = do_case (exp1, exp2);
3597 else
3598 c_parser_error (parser, "expected %<:%> or %<...%>");
3600 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3602 c_parser_consume_token (parser);
3603 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3604 label = do_case (NULL_TREE, NULL_TREE);
3606 else
3608 tree name = c_parser_peek_token (parser)->value;
3609 tree tlab;
3610 tree attrs;
3611 location_t loc2 = c_parser_peek_token (parser)->location;
3612 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3613 c_parser_consume_token (parser);
3614 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3615 c_parser_consume_token (parser);
3616 attrs = c_parser_attributes (parser);
3617 tlab = define_label (loc2, name);
3618 if (tlab)
3620 decl_attributes (&tlab, attrs, 0);
3621 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3624 if (label)
3625 SET_EXPR_LOCATION (label, loc1);
3628 /* Parse a statement (C90 6.6, C99 6.8).
3630 statement:
3631 labeled-statement
3632 compound-statement
3633 expression-statement
3634 selection-statement
3635 iteration-statement
3636 jump-statement
3638 labeled-statement:
3639 label statement
3641 expression-statement:
3642 expression[opt] ;
3644 selection-statement:
3645 if-statement
3646 switch-statement
3648 iteration-statement:
3649 while-statement
3650 do-statement
3651 for-statement
3653 jump-statement:
3654 goto identifier ;
3655 continue ;
3656 break ;
3657 return expression[opt] ;
3659 GNU extensions:
3661 statement:
3662 asm-statement
3664 jump-statement:
3665 goto * expression ;
3667 Objective-C:
3669 statement:
3670 objc-throw-statement
3671 objc-try-catch-statement
3672 objc-synchronized-statement
3674 objc-throw-statement:
3675 @throw expression ;
3676 @throw ;
3678 OpenMP:
3680 statement:
3681 openmp-construct
3683 openmp-construct:
3684 parallel-construct
3685 for-construct
3686 sections-construct
3687 single-construct
3688 parallel-for-construct
3689 parallel-sections-construct
3690 master-construct
3691 critical-construct
3692 atomic-construct
3693 ordered-construct
3695 parallel-construct:
3696 parallel-directive structured-block
3698 for-construct:
3699 for-directive iteration-statement
3701 sections-construct:
3702 sections-directive section-scope
3704 single-construct:
3705 single-directive structured-block
3707 parallel-for-construct:
3708 parallel-for-directive iteration-statement
3710 parallel-sections-construct:
3711 parallel-sections-directive section-scope
3713 master-construct:
3714 master-directive structured-block
3716 critical-construct:
3717 critical-directive structured-block
3719 atomic-construct:
3720 atomic-directive expression-statement
3722 ordered-construct:
3723 ordered-directive structured-block */
3725 static void
3726 c_parser_statement (c_parser *parser)
3728 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3729 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3730 || (c_parser_next_token_is (parser, CPP_NAME)
3731 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3732 c_parser_label (parser);
3733 c_parser_statement_after_labels (parser);
3736 /* Parse a statement, other than a labeled statement. */
3738 static void
3739 c_parser_statement_after_labels (c_parser *parser)
3741 location_t loc = c_parser_peek_token (parser)->location;
3742 tree stmt = NULL_TREE;
3743 switch (c_parser_peek_token (parser)->type)
3745 case CPP_OPEN_BRACE:
3746 add_stmt (c_parser_compound_statement (parser));
3747 break;
3748 case CPP_KEYWORD:
3749 switch (c_parser_peek_token (parser)->keyword)
3751 case RID_IF:
3752 c_parser_if_statement (parser);
3753 break;
3754 case RID_SWITCH:
3755 c_parser_switch_statement (parser);
3756 break;
3757 case RID_WHILE:
3758 c_parser_while_statement (parser);
3759 break;
3760 case RID_DO:
3761 c_parser_do_statement (parser);
3762 break;
3763 case RID_FOR:
3764 c_parser_for_statement (parser);
3765 break;
3766 case RID_GOTO:
3767 c_parser_consume_token (parser);
3768 if (c_parser_next_token_is (parser, CPP_NAME))
3770 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3771 c_parser_consume_token (parser);
3773 else if (c_parser_next_token_is (parser, CPP_MULT))
3775 c_parser_consume_token (parser);
3776 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3778 else
3779 c_parser_error (parser, "expected identifier or %<*%>");
3780 goto expect_semicolon;
3781 case RID_CONTINUE:
3782 c_parser_consume_token (parser);
3783 stmt = c_finish_bc_stmt (&c_cont_label, false);
3784 goto expect_semicolon;
3785 case RID_BREAK:
3786 c_parser_consume_token (parser);
3787 stmt = c_finish_bc_stmt (&c_break_label, true);
3788 goto expect_semicolon;
3789 case RID_RETURN:
3790 c_parser_consume_token (parser);
3791 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3793 stmt = c_finish_return (NULL_TREE);
3794 c_parser_consume_token (parser);
3796 else
3798 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3799 goto expect_semicolon;
3801 break;
3802 case RID_ASM:
3803 stmt = c_parser_asm_statement (parser);
3804 break;
3805 case RID_AT_THROW:
3806 gcc_assert (c_dialect_objc ());
3807 c_parser_consume_token (parser);
3808 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3810 stmt = objc_build_throw_stmt (NULL_TREE);
3811 c_parser_consume_token (parser);
3813 else
3815 stmt
3816 = objc_build_throw_stmt (c_parser_expression (parser).value);
3817 goto expect_semicolon;
3819 break;
3820 case RID_AT_TRY:
3821 gcc_assert (c_dialect_objc ());
3822 c_parser_objc_try_catch_statement (parser);
3823 break;
3824 case RID_AT_SYNCHRONIZED:
3825 gcc_assert (c_dialect_objc ());
3826 c_parser_objc_synchronized_statement (parser);
3827 break;
3828 default:
3829 goto expr_stmt;
3831 break;
3832 case CPP_SEMICOLON:
3833 c_parser_consume_token (parser);
3834 break;
3835 case CPP_CLOSE_PAREN:
3836 case CPP_CLOSE_SQUARE:
3837 /* Avoid infinite loop in error recovery:
3838 c_parser_skip_until_found stops at a closing nesting
3839 delimiter without consuming it, but here we need to consume
3840 it to proceed further. */
3841 c_parser_error (parser, "expected statement");
3842 c_parser_consume_token (parser);
3843 break;
3844 case CPP_PRAGMA:
3845 c_parser_pragma (parser, pragma_stmt);
3846 break;
3847 default:
3848 expr_stmt:
3849 if (c_parser_next_token_starts_declspecs (parser))
3851 error ("%Ha label can only be part of a statement and "
3852 "a declaration is not a statement",
3853 &c_parser_peek_token (parser)->location);
3854 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3855 /*nested*/ true, /*empty_ok*/ false,
3856 /*start_attr_ok*/ true);
3857 return;
3859 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3860 expect_semicolon:
3861 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3862 break;
3864 /* Two cases cannot and do not have line numbers associated: If stmt
3865 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3866 cannot hold line numbers. But that's OK because the statement
3867 will either be changed to a MODIFY_EXPR during gimplification of
3868 the statement expr, or discarded. If stmt was compound, but
3869 without new variables, we will have skipped the creation of a
3870 BIND and will have a bare STATEMENT_LIST. But that's OK because
3871 (recursively) all of the component statements should already have
3872 line numbers assigned. ??? Can we discard no-op statements
3873 earlier? */
3874 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3875 SET_EXPR_LOCATION (stmt, loc);
3878 /* Parse a parenthesized condition from an if, do or while statement.
3880 condition:
3881 ( expression )
3883 static tree
3884 c_parser_paren_condition (c_parser *parser)
3886 location_t loc;
3887 tree cond;
3888 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3889 return error_mark_node;
3890 loc = c_parser_peek_token (parser)->location;
3891 cond = c_objc_common_truthvalue_conversion
3892 (c_parser_expression_conv (parser).value);
3893 if (CAN_HAVE_LOCATION_P (cond))
3894 SET_EXPR_LOCATION (cond, loc);
3895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3896 return cond;
3899 /* Parse a statement which is a block in C99. */
3901 static tree
3902 c_parser_c99_block_statement (c_parser *parser)
3904 tree block = c_begin_compound_stmt (flag_isoc99);
3905 c_parser_statement (parser);
3906 return c_end_compound_stmt (block, flag_isoc99);
3909 /* Parse the body of an if statement or the else half thereof. This
3910 is just parsing a statement but (a) it is a block in C99, (b) we
3911 track whether the body is an if statement for the sake of
3912 -Wparentheses warnings, (c) we handle an empty body specially for
3913 the sake of -Wempty-body warnings. */
3915 static tree
3916 c_parser_if_body (c_parser *parser, bool *if_p)
3918 tree block = c_begin_compound_stmt (flag_isoc99);
3919 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3920 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3921 || (c_parser_next_token_is (parser, CPP_NAME)
3922 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3923 c_parser_label (parser);
3924 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3925 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3926 add_stmt (build_empty_stmt ());
3927 c_parser_statement_after_labels (parser);
3928 return c_end_compound_stmt (block, flag_isoc99);
3931 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3933 if-statement:
3934 if ( expression ) statement
3935 if ( expression ) statement else statement
3938 static void
3939 c_parser_if_statement (c_parser *parser)
3941 tree block;
3942 location_t loc;
3943 tree cond;
3944 bool first_if = false, second_if = false;
3945 tree first_body, second_body;
3946 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3947 c_parser_consume_token (parser);
3948 block = c_begin_compound_stmt (flag_isoc99);
3949 loc = c_parser_peek_token (parser)->location;
3950 cond = c_parser_paren_condition (parser);
3951 first_body = c_parser_if_body (parser, &first_if);
3952 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3954 c_parser_consume_token (parser);
3955 second_body = c_parser_if_body (parser, &second_if);
3957 else
3958 second_body = NULL_TREE;
3959 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3960 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3963 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3965 switch-statement:
3966 switch (expression) statement
3969 static void
3970 c_parser_switch_statement (c_parser *parser)
3972 tree block, expr, body, save_break;
3973 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3974 c_parser_consume_token (parser);
3975 block = c_begin_compound_stmt (flag_isoc99);
3976 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3978 expr = c_parser_expression (parser).value;
3979 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3981 else
3982 expr = error_mark_node;
3983 c_start_case (expr);
3984 save_break = c_break_label;
3985 c_break_label = NULL_TREE;
3986 body = c_parser_c99_block_statement (parser);
3987 c_finish_case (body);
3988 if (c_break_label)
3989 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3990 c_break_label = save_break;
3991 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3994 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3996 while-statement:
3997 while (expression) statement
4000 static void
4001 c_parser_while_statement (c_parser *parser)
4003 tree block, cond, body, save_break, save_cont;
4004 location_t loc;
4005 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4006 c_parser_consume_token (parser);
4007 block = c_begin_compound_stmt (flag_isoc99);
4008 loc = c_parser_peek_token (parser)->location;
4009 cond = c_parser_paren_condition (parser);
4010 save_break = c_break_label;
4011 c_break_label = NULL_TREE;
4012 save_cont = c_cont_label;
4013 c_cont_label = NULL_TREE;
4014 body = c_parser_c99_block_statement (parser);
4015 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4016 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4017 c_break_label = save_break;
4018 c_cont_label = save_cont;
4021 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4023 do-statement:
4024 do statement while ( expression ) ;
4027 static void
4028 c_parser_do_statement (c_parser *parser)
4030 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4031 location_t loc;
4032 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4033 c_parser_consume_token (parser);
4034 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4035 warning (OPT_Wempty_body,
4036 "%Hsuggest braces around empty body in %<do%> statement",
4037 &c_parser_peek_token (parser)->location);
4038 block = c_begin_compound_stmt (flag_isoc99);
4039 loc = c_parser_peek_token (parser)->location;
4040 save_break = c_break_label;
4041 c_break_label = NULL_TREE;
4042 save_cont = c_cont_label;
4043 c_cont_label = NULL_TREE;
4044 body = c_parser_c99_block_statement (parser);
4045 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4046 new_break = c_break_label;
4047 c_break_label = save_break;
4048 new_cont = c_cont_label;
4049 c_cont_label = save_cont;
4050 cond = c_parser_paren_condition (parser);
4051 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4052 c_parser_skip_to_end_of_block_or_statement (parser);
4053 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4054 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4057 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4059 for-statement:
4060 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4061 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4063 The form with a declaration is new in C99.
4065 ??? In accordance with the old parser, the declaration may be a
4066 nested function, which is then rejected in check_for_loop_decls,
4067 but does it make any sense for this to be included in the grammar?
4068 Note in particular that the nested function does not include a
4069 trailing ';', whereas the "declaration" production includes one.
4070 Also, can we reject bad declarations earlier and cheaper than
4071 check_for_loop_decls? */
4073 static void
4074 c_parser_for_statement (c_parser *parser)
4076 tree block, cond, incr, save_break, save_cont, body;
4077 location_t loc;
4078 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4079 loc = c_parser_peek_token (parser)->location;
4080 c_parser_consume_token (parser);
4081 block = c_begin_compound_stmt (flag_isoc99);
4082 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4084 /* Parse the initialization declaration or expression. */
4085 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4087 c_parser_consume_token (parser);
4088 c_finish_expr_stmt (NULL_TREE);
4090 else if (c_parser_next_token_starts_declspecs (parser))
4092 c_parser_declaration_or_fndef (parser, true, true, true, true);
4093 check_for_loop_decls ();
4095 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4097 /* __extension__ can start a declaration, but is also an
4098 unary operator that can start an expression. Consume all
4099 but the last of a possible series of __extension__ to
4100 determine which. */
4101 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4102 && (c_parser_peek_2nd_token (parser)->keyword
4103 == RID_EXTENSION))
4104 c_parser_consume_token (parser);
4105 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4107 int ext;
4108 ext = disable_extension_diagnostics ();
4109 c_parser_consume_token (parser);
4110 c_parser_declaration_or_fndef (parser, true, true, true, true);
4111 restore_extension_diagnostics (ext);
4112 check_for_loop_decls ();
4114 else
4115 goto init_expr;
4117 else
4119 init_expr:
4120 c_finish_expr_stmt (c_parser_expression (parser).value);
4121 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4123 /* Parse the loop condition. */
4124 loc = c_parser_peek_token (parser)->location;
4125 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4127 c_parser_consume_token (parser);
4128 cond = NULL_TREE;
4130 else
4132 tree ocond = c_parser_expression_conv (parser).value;
4133 cond = c_objc_common_truthvalue_conversion (ocond);
4134 if (CAN_HAVE_LOCATION_P (cond))
4135 SET_EXPR_LOCATION (cond, loc);
4136 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4138 /* Parse the increment expression. */
4139 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4140 incr = c_process_expr_stmt (NULL_TREE);
4141 else
4142 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4143 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4145 else
4147 cond = error_mark_node;
4148 incr = error_mark_node;
4150 save_break = c_break_label;
4151 c_break_label = NULL_TREE;
4152 save_cont = c_cont_label;
4153 c_cont_label = NULL_TREE;
4154 body = c_parser_c99_block_statement (parser);
4155 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4156 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4157 c_break_label = save_break;
4158 c_cont_label = save_cont;
4161 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4162 statement with inputs, outputs, clobbers, and volatile tag
4163 allowed.
4165 asm-statement:
4166 asm type-qualifier[opt] ( asm-argument ) ;
4168 asm-argument:
4169 asm-string-literal
4170 asm-string-literal : asm-operands[opt]
4171 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4172 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4174 Qualifiers other than volatile are accepted in the syntax but
4175 warned for. */
4177 static tree
4178 c_parser_asm_statement (c_parser *parser)
4180 tree quals, str, outputs, inputs, clobbers, ret;
4181 bool simple;
4182 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4183 c_parser_consume_token (parser);
4184 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4186 quals = c_parser_peek_token (parser)->value;
4187 c_parser_consume_token (parser);
4189 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4190 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4192 warning (0, "%H%E qualifier ignored on asm",
4193 &c_parser_peek_token (parser)->location,
4194 c_parser_peek_token (parser)->value);
4195 quals = NULL_TREE;
4196 c_parser_consume_token (parser);
4198 else
4199 quals = NULL_TREE;
4200 /* ??? Follow the C++ parser rather than using the
4201 lex_untranslated_string kludge. */
4202 parser->lex_untranslated_string = true;
4203 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4205 parser->lex_untranslated_string = false;
4206 return NULL_TREE;
4208 str = c_parser_asm_string_literal (parser);
4209 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4211 simple = true;
4212 outputs = NULL_TREE;
4213 inputs = NULL_TREE;
4214 clobbers = NULL_TREE;
4215 goto done_asm;
4217 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4219 parser->lex_untranslated_string = false;
4220 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4221 return NULL_TREE;
4223 simple = false;
4224 /* Parse outputs. */
4225 if (c_parser_next_token_is (parser, CPP_COLON)
4226 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4227 outputs = NULL_TREE;
4228 else
4229 outputs = c_parser_asm_operands (parser, false);
4230 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4232 inputs = NULL_TREE;
4233 clobbers = NULL_TREE;
4234 goto done_asm;
4236 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4238 parser->lex_untranslated_string = false;
4239 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4240 return NULL_TREE;
4242 /* Parse inputs. */
4243 if (c_parser_next_token_is (parser, CPP_COLON)
4244 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4245 inputs = NULL_TREE;
4246 else
4247 inputs = c_parser_asm_operands (parser, true);
4248 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4250 clobbers = NULL_TREE;
4251 goto done_asm;
4253 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4255 parser->lex_untranslated_string = false;
4256 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4257 return NULL_TREE;
4259 /* Parse clobbers. */
4260 clobbers = c_parser_asm_clobbers (parser);
4261 done_asm:
4262 parser->lex_untranslated_string = false;
4263 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4266 return NULL_TREE;
4268 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4269 c_parser_skip_to_end_of_block_or_statement (parser);
4270 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4271 clobbers, simple));
4272 return ret;
4275 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4276 not outputs), apply the default conversion of functions and arrays
4277 to pointers.
4279 asm-operands:
4280 asm-operand
4281 asm-operands , asm-operand
4283 asm-operand:
4284 asm-string-literal ( expression )
4285 [ identifier ] asm-string-literal ( expression )
4288 static tree
4289 c_parser_asm_operands (c_parser *parser, bool convert_p)
4291 tree list = NULL_TREE;
4292 while (true)
4294 tree name, str;
4295 struct c_expr expr;
4296 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4298 c_parser_consume_token (parser);
4299 if (c_parser_next_token_is (parser, CPP_NAME))
4301 tree id = c_parser_peek_token (parser)->value;
4302 c_parser_consume_token (parser);
4303 name = build_string (IDENTIFIER_LENGTH (id),
4304 IDENTIFIER_POINTER (id));
4306 else
4308 c_parser_error (parser, "expected identifier");
4309 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4310 return NULL_TREE;
4312 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4313 "expected %<]%>");
4315 else
4316 name = NULL_TREE;
4317 str = c_parser_asm_string_literal (parser);
4318 if (str == NULL_TREE)
4319 return NULL_TREE;
4320 parser->lex_untranslated_string = false;
4321 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4323 parser->lex_untranslated_string = true;
4324 return NULL_TREE;
4326 expr = c_parser_expression (parser);
4327 if (convert_p)
4328 expr = default_function_array_conversion (expr);
4329 parser->lex_untranslated_string = true;
4330 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4332 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4333 return NULL_TREE;
4335 list = chainon (list, build_tree_list (build_tree_list (name, str),
4336 expr.value));
4337 if (c_parser_next_token_is (parser, CPP_COMMA))
4338 c_parser_consume_token (parser);
4339 else
4340 break;
4342 return list;
4345 /* Parse asm clobbers, a GNU extension.
4347 asm-clobbers:
4348 asm-string-literal
4349 asm-clobbers , asm-string-literal
4352 static tree
4353 c_parser_asm_clobbers (c_parser *parser)
4355 tree list = NULL_TREE;
4356 while (true)
4358 tree str = c_parser_asm_string_literal (parser);
4359 if (str)
4360 list = tree_cons (NULL_TREE, str, list);
4361 else
4362 return NULL_TREE;
4363 if (c_parser_next_token_is (parser, CPP_COMMA))
4364 c_parser_consume_token (parser);
4365 else
4366 break;
4368 return list;
4371 /* Parse an expression other than a compound expression; that is, an
4372 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4373 NULL then it is an Objective-C message expression which is the
4374 primary-expression starting the expression as an initializer.
4376 assignment-expression:
4377 conditional-expression
4378 unary-expression assignment-operator assignment-expression
4380 assignment-operator: one of
4381 = *= /= %= += -= <<= >>= &= ^= |=
4383 In GNU C we accept any conditional expression on the LHS and
4384 diagnose the invalid lvalue rather than producing a syntax
4385 error. */
4387 static struct c_expr
4388 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4390 struct c_expr lhs, rhs, ret;
4391 enum tree_code code;
4392 gcc_assert (!after || c_dialect_objc ());
4393 lhs = c_parser_conditional_expression (parser, after);
4394 switch (c_parser_peek_token (parser)->type)
4396 case CPP_EQ:
4397 code = NOP_EXPR;
4398 break;
4399 case CPP_MULT_EQ:
4400 code = MULT_EXPR;
4401 break;
4402 case CPP_DIV_EQ:
4403 code = TRUNC_DIV_EXPR;
4404 break;
4405 case CPP_MOD_EQ:
4406 code = TRUNC_MOD_EXPR;
4407 break;
4408 case CPP_PLUS_EQ:
4409 code = PLUS_EXPR;
4410 break;
4411 case CPP_MINUS_EQ:
4412 code = MINUS_EXPR;
4413 break;
4414 case CPP_LSHIFT_EQ:
4415 code = LSHIFT_EXPR;
4416 break;
4417 case CPP_RSHIFT_EQ:
4418 code = RSHIFT_EXPR;
4419 break;
4420 case CPP_AND_EQ:
4421 code = BIT_AND_EXPR;
4422 break;
4423 case CPP_XOR_EQ:
4424 code = BIT_XOR_EXPR;
4425 break;
4426 case CPP_OR_EQ:
4427 code = BIT_IOR_EXPR;
4428 break;
4429 default:
4430 return lhs;
4432 c_parser_consume_token (parser);
4433 rhs = c_parser_expr_no_commas (parser, NULL);
4434 rhs = default_function_array_conversion (rhs);
4435 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4436 if (code == NOP_EXPR)
4437 ret.original_code = MODIFY_EXPR;
4438 else
4440 TREE_NO_WARNING (ret.value) = 1;
4441 ret.original_code = ERROR_MARK;
4443 return ret;
4446 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4447 is not NULL then it is an Objective-C message expression which is
4448 the primary-expression starting the expression as an initializer.
4450 conditional-expression:
4451 logical-OR-expression
4452 logical-OR-expression ? expression : conditional-expression
4454 GNU extensions:
4456 conditional-expression:
4457 logical-OR-expression ? : conditional-expression
4460 static struct c_expr
4461 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4463 struct c_expr cond, exp1, exp2, ret;
4464 gcc_assert (!after || c_dialect_objc ());
4465 cond = c_parser_binary_expression (parser, after);
4466 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4467 return cond;
4468 cond = default_function_array_conversion (cond);
4469 c_parser_consume_token (parser);
4470 if (c_parser_next_token_is (parser, CPP_COLON))
4472 if (pedantic)
4473 pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
4474 &c_parser_peek_token (parser)->location);
4475 /* Make sure first operand is calculated only once. */
4476 exp1.value = save_expr (default_conversion (cond.value));
4477 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4478 skip_evaluation += cond.value == truthvalue_true_node;
4480 else
4482 cond.value
4483 = c_objc_common_truthvalue_conversion
4484 (default_conversion (cond.value));
4485 skip_evaluation += cond.value == truthvalue_false_node;
4486 exp1 = c_parser_expression_conv (parser);
4487 skip_evaluation += ((cond.value == truthvalue_true_node)
4488 - (cond.value == truthvalue_false_node));
4490 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4492 skip_evaluation -= cond.value == truthvalue_true_node;
4493 ret.value = error_mark_node;
4494 ret.original_code = ERROR_MARK;
4495 return ret;
4497 exp2 = c_parser_conditional_expression (parser, NULL);
4498 exp2 = default_function_array_conversion (exp2);
4499 skip_evaluation -= cond.value == truthvalue_true_node;
4500 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4501 ret.original_code = ERROR_MARK;
4502 return ret;
4505 /* Parse a binary expression; that is, a logical-OR-expression (C90
4506 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4507 an Objective-C message expression which is the primary-expression
4508 starting the expression as an initializer.
4510 multiplicative-expression:
4511 cast-expression
4512 multiplicative-expression * cast-expression
4513 multiplicative-expression / cast-expression
4514 multiplicative-expression % cast-expression
4516 additive-expression:
4517 multiplicative-expression
4518 additive-expression + multiplicative-expression
4519 additive-expression - multiplicative-expression
4521 shift-expression:
4522 additive-expression
4523 shift-expression << additive-expression
4524 shift-expression >> additive-expression
4526 relational-expression:
4527 shift-expression
4528 relational-expression < shift-expression
4529 relational-expression > shift-expression
4530 relational-expression <= shift-expression
4531 relational-expression >= shift-expression
4533 equality-expression:
4534 relational-expression
4535 equality-expression == relational-expression
4536 equality-expression != relational-expression
4538 AND-expression:
4539 equality-expression
4540 AND-expression & equality-expression
4542 exclusive-OR-expression:
4543 AND-expression
4544 exclusive-OR-expression ^ AND-expression
4546 inclusive-OR-expression:
4547 exclusive-OR-expression
4548 inclusive-OR-expression | exclusive-OR-expression
4550 logical-AND-expression:
4551 inclusive-OR-expression
4552 logical-AND-expression && inclusive-OR-expression
4554 logical-OR-expression:
4555 logical-AND-expression
4556 logical-OR-expression || logical-AND-expression
4559 static struct c_expr
4560 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4562 /* A binary expression is parsed using operator-precedence parsing,
4563 with the operands being cast expressions. All the binary
4564 operators are left-associative. Thus a binary expression is of
4565 form:
4567 E0 op1 E1 op2 E2 ...
4569 which we represent on a stack. On the stack, the precedence
4570 levels are strictly increasing. When a new operator is
4571 encountered of higher precedence than that at the top of the
4572 stack, it is pushed; its LHS is the top expression, and its RHS
4573 is everything parsed until it is popped. When a new operator is
4574 encountered with precedence less than or equal to that at the top
4575 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4576 by the result of the operation until the operator at the top of
4577 the stack has lower precedence than the new operator or there is
4578 only one element on the stack; then the top expression is the LHS
4579 of the new operator. In the case of logical AND and OR
4580 expressions, we also need to adjust skip_evaluation as
4581 appropriate when the operators are pushed and popped. */
4583 /* The precedence levels, where 0 is a dummy lowest level used for
4584 the bottom of the stack. */
4585 enum prec {
4586 PREC_NONE,
4587 PREC_LOGOR,
4588 PREC_LOGAND,
4589 PREC_BITOR,
4590 PREC_BITXOR,
4591 PREC_BITAND,
4592 PREC_EQ,
4593 PREC_REL,
4594 PREC_SHIFT,
4595 PREC_ADD,
4596 PREC_MULT,
4597 NUM_PRECS
4599 struct {
4600 /* The expression at this stack level. */
4601 struct c_expr expr;
4602 /* The precedence of the operator on its left, PREC_NONE at the
4603 bottom of the stack. */
4604 enum prec prec;
4605 /* The operation on its left. */
4606 enum tree_code op;
4607 } stack[NUM_PRECS];
4608 int sp;
4609 #define POP \
4610 do { \
4611 switch (stack[sp].op) \
4613 case TRUTH_ANDIF_EXPR: \
4614 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4615 break; \
4616 case TRUTH_ORIF_EXPR: \
4617 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4618 break; \
4619 default: \
4620 break; \
4622 stack[sp - 1].expr \
4623 = default_function_array_conversion (stack[sp - 1].expr); \
4624 stack[sp].expr \
4625 = default_function_array_conversion (stack[sp].expr); \
4626 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4627 stack[sp - 1].expr, \
4628 stack[sp].expr); \
4629 sp--; \
4630 } while (0)
4631 gcc_assert (!after || c_dialect_objc ());
4632 stack[0].expr = c_parser_cast_expression (parser, after);
4633 stack[0].prec = PREC_NONE;
4634 sp = 0;
4635 while (true)
4637 enum prec oprec;
4638 enum tree_code ocode;
4639 if (parser->error)
4640 goto out;
4641 switch (c_parser_peek_token (parser)->type)
4643 case CPP_MULT:
4644 oprec = PREC_MULT;
4645 ocode = MULT_EXPR;
4646 break;
4647 case CPP_DIV:
4648 oprec = PREC_MULT;
4649 ocode = TRUNC_DIV_EXPR;
4650 break;
4651 case CPP_MOD:
4652 oprec = PREC_MULT;
4653 ocode = TRUNC_MOD_EXPR;
4654 break;
4655 case CPP_PLUS:
4656 oprec = PREC_ADD;
4657 ocode = PLUS_EXPR;
4658 break;
4659 case CPP_MINUS:
4660 oprec = PREC_ADD;
4661 ocode = MINUS_EXPR;
4662 break;
4663 case CPP_LSHIFT:
4664 oprec = PREC_SHIFT;
4665 ocode = LSHIFT_EXPR;
4666 break;
4667 case CPP_RSHIFT:
4668 oprec = PREC_SHIFT;
4669 ocode = RSHIFT_EXPR;
4670 break;
4671 case CPP_LESS:
4672 oprec = PREC_REL;
4673 ocode = LT_EXPR;
4674 break;
4675 case CPP_GREATER:
4676 oprec = PREC_REL;
4677 ocode = GT_EXPR;
4678 break;
4679 case CPP_LESS_EQ:
4680 oprec = PREC_REL;
4681 ocode = LE_EXPR;
4682 break;
4683 case CPP_GREATER_EQ:
4684 oprec = PREC_REL;
4685 ocode = GE_EXPR;
4686 break;
4687 case CPP_EQ_EQ:
4688 oprec = PREC_EQ;
4689 ocode = EQ_EXPR;
4690 break;
4691 case CPP_NOT_EQ:
4692 oprec = PREC_EQ;
4693 ocode = NE_EXPR;
4694 break;
4695 case CPP_AND:
4696 oprec = PREC_BITAND;
4697 ocode = BIT_AND_EXPR;
4698 break;
4699 case CPP_XOR:
4700 oprec = PREC_BITXOR;
4701 ocode = BIT_XOR_EXPR;
4702 break;
4703 case CPP_OR:
4704 oprec = PREC_BITOR;
4705 ocode = BIT_IOR_EXPR;
4706 break;
4707 case CPP_AND_AND:
4708 oprec = PREC_LOGAND;
4709 ocode = TRUTH_ANDIF_EXPR;
4710 break;
4711 case CPP_OR_OR:
4712 oprec = PREC_LOGOR;
4713 ocode = TRUTH_ORIF_EXPR;
4714 break;
4715 default:
4716 /* Not a binary operator, so end of the binary
4717 expression. */
4718 goto out;
4720 c_parser_consume_token (parser);
4721 while (oprec <= stack[sp].prec)
4722 POP;
4723 switch (ocode)
4725 case TRUTH_ANDIF_EXPR:
4726 stack[sp].expr
4727 = default_function_array_conversion (stack[sp].expr);
4728 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4729 (default_conversion (stack[sp].expr.value));
4730 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4731 break;
4732 case TRUTH_ORIF_EXPR:
4733 stack[sp].expr
4734 = default_function_array_conversion (stack[sp].expr);
4735 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4736 (default_conversion (stack[sp].expr.value));
4737 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4738 break;
4739 default:
4740 break;
4742 sp++;
4743 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4744 stack[sp].prec = oprec;
4745 stack[sp].op = ocode;
4747 out:
4748 while (sp > 0)
4749 POP;
4750 return stack[0].expr;
4751 #undef POP
4754 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4755 NULL then it is an Objective-C message expression which is the
4756 primary-expression starting the expression as an initializer.
4758 cast-expression:
4759 unary-expression
4760 ( type-name ) unary-expression
4763 static struct c_expr
4764 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4766 gcc_assert (!after || c_dialect_objc ());
4767 if (after)
4768 return c_parser_postfix_expression_after_primary (parser, *after);
4769 /* If the expression begins with a parenthesized type name, it may
4770 be either a cast or a compound literal; we need to see whether
4771 the next character is '{' to tell the difference. If not, it is
4772 an unary expression. */
4773 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4774 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4776 struct c_type_name *type_name;
4777 struct c_expr ret;
4778 struct c_expr expr;
4779 c_parser_consume_token (parser);
4780 type_name = c_parser_type_name (parser);
4781 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4782 if (type_name == NULL)
4784 ret.value = error_mark_node;
4785 ret.original_code = ERROR_MARK;
4786 return ret;
4789 /* Save casted types in the function's used types hash table. */
4790 used_types_insert (type_name->specs->type);
4792 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4793 return c_parser_postfix_expression_after_paren_type (parser,
4794 type_name);
4795 expr = c_parser_cast_expression (parser, NULL);
4796 expr = default_function_array_conversion (expr);
4797 ret.value = c_cast_expr (type_name, expr.value);
4798 ret.original_code = ERROR_MARK;
4799 return ret;
4801 else
4802 return c_parser_unary_expression (parser);
4805 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4807 unary-expression:
4808 postfix-expression
4809 ++ unary-expression
4810 -- unary-expression
4811 unary-operator cast-expression
4812 sizeof unary-expression
4813 sizeof ( type-name )
4815 unary-operator: one of
4816 & * + - ~ !
4818 GNU extensions:
4820 unary-expression:
4821 __alignof__ unary-expression
4822 __alignof__ ( type-name )
4823 && identifier
4825 unary-operator: one of
4826 __extension__ __real__ __imag__
4828 In addition, the GNU syntax treats ++ and -- as unary operators, so
4829 they may be applied to cast expressions with errors for non-lvalues
4830 given later. */
4832 static struct c_expr
4833 c_parser_unary_expression (c_parser *parser)
4835 int ext;
4836 struct c_expr ret, op;
4837 switch (c_parser_peek_token (parser)->type)
4839 case CPP_PLUS_PLUS:
4840 c_parser_consume_token (parser);
4841 op = c_parser_cast_expression (parser, NULL);
4842 op = default_function_array_conversion (op);
4843 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4844 case CPP_MINUS_MINUS:
4845 c_parser_consume_token (parser);
4846 op = c_parser_cast_expression (parser, NULL);
4847 op = default_function_array_conversion (op);
4848 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4849 case CPP_AND:
4850 c_parser_consume_token (parser);
4851 return parser_build_unary_op (ADDR_EXPR,
4852 c_parser_cast_expression (parser, NULL));
4853 case CPP_MULT:
4854 c_parser_consume_token (parser);
4855 op = c_parser_cast_expression (parser, NULL);
4856 op = default_function_array_conversion (op);
4857 ret.value = build_indirect_ref (op.value, "unary *");
4858 ret.original_code = ERROR_MARK;
4859 return ret;
4860 case CPP_PLUS:
4861 if (!c_dialect_objc () && !in_system_header)
4862 warning (OPT_Wtraditional,
4863 "%Htraditional C rejects the unary plus operator",
4864 &c_parser_peek_token (parser)->location);
4865 c_parser_consume_token (parser);
4866 op = c_parser_cast_expression (parser, NULL);
4867 op = default_function_array_conversion (op);
4868 return parser_build_unary_op (CONVERT_EXPR, op);
4869 case CPP_MINUS:
4870 c_parser_consume_token (parser);
4871 op = c_parser_cast_expression (parser, NULL);
4872 op = default_function_array_conversion (op);
4873 return parser_build_unary_op (NEGATE_EXPR, op);
4874 case CPP_COMPL:
4875 c_parser_consume_token (parser);
4876 op = c_parser_cast_expression (parser, NULL);
4877 op = default_function_array_conversion (op);
4878 return parser_build_unary_op (BIT_NOT_EXPR, op);
4879 case CPP_NOT:
4880 c_parser_consume_token (parser);
4881 op = c_parser_cast_expression (parser, NULL);
4882 op = default_function_array_conversion (op);
4883 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4884 case CPP_AND_AND:
4885 /* Refer to the address of a label as a pointer. */
4886 c_parser_consume_token (parser);
4887 if (c_parser_next_token_is (parser, CPP_NAME))
4889 ret.value = finish_label_address_expr
4890 (c_parser_peek_token (parser)->value);
4891 c_parser_consume_token (parser);
4893 else
4895 c_parser_error (parser, "expected identifier");
4896 ret.value = error_mark_node;
4898 ret.original_code = ERROR_MARK;
4899 return ret;
4900 case CPP_KEYWORD:
4901 switch (c_parser_peek_token (parser)->keyword)
4903 case RID_SIZEOF:
4904 return c_parser_sizeof_expression (parser);
4905 case RID_ALIGNOF:
4906 return c_parser_alignof_expression (parser);
4907 case RID_EXTENSION:
4908 c_parser_consume_token (parser);
4909 ext = disable_extension_diagnostics ();
4910 ret = c_parser_cast_expression (parser, NULL);
4911 restore_extension_diagnostics (ext);
4912 return ret;
4913 case RID_REALPART:
4914 c_parser_consume_token (parser);
4915 op = c_parser_cast_expression (parser, NULL);
4916 op = default_function_array_conversion (op);
4917 return parser_build_unary_op (REALPART_EXPR, op);
4918 case RID_IMAGPART:
4919 c_parser_consume_token (parser);
4920 op = c_parser_cast_expression (parser, NULL);
4921 op = default_function_array_conversion (op);
4922 return parser_build_unary_op (IMAGPART_EXPR, op);
4923 default:
4924 return c_parser_postfix_expression (parser);
4926 default:
4927 return c_parser_postfix_expression (parser);
4931 /* Parse a sizeof expression. */
4933 static struct c_expr
4934 c_parser_sizeof_expression (c_parser *parser)
4936 struct c_expr expr;
4937 location_t expr_loc;
4938 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4939 c_parser_consume_token (parser);
4940 skip_evaluation++;
4941 in_sizeof++;
4942 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4943 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4945 /* Either sizeof ( type-name ) or sizeof unary-expression
4946 starting with a compound literal. */
4947 struct c_type_name *type_name;
4948 c_parser_consume_token (parser);
4949 expr_loc = c_parser_peek_token (parser)->location;
4950 type_name = c_parser_type_name (parser);
4951 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4952 if (type_name == NULL)
4954 struct c_expr ret;
4955 skip_evaluation--;
4956 in_sizeof--;
4957 ret.value = error_mark_node;
4958 ret.original_code = ERROR_MARK;
4959 return ret;
4961 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4963 expr = c_parser_postfix_expression_after_paren_type (parser,
4964 type_name);
4965 goto sizeof_expr;
4967 /* sizeof ( type-name ). */
4968 skip_evaluation--;
4969 in_sizeof--;
4970 if (type_name->declarator->kind == cdk_array
4971 && type_name->declarator->u.array.vla_unspec_p)
4973 /* C99 6.7.5.2p4 */
4974 error ("%H%<[*]%> not allowed in other than a declaration",
4975 &expr_loc);
4977 return c_expr_sizeof_type (type_name);
4979 else
4981 expr_loc = c_parser_peek_token (parser)->location;
4982 expr = c_parser_unary_expression (parser);
4983 sizeof_expr:
4984 skip_evaluation--;
4985 in_sizeof--;
4986 if (TREE_CODE (expr.value) == COMPONENT_REF
4987 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4988 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
4989 return c_expr_sizeof_expr (expr);
4993 /* Parse an alignof expression. */
4995 static struct c_expr
4996 c_parser_alignof_expression (c_parser *parser)
4998 struct c_expr expr;
4999 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5000 c_parser_consume_token (parser);
5001 skip_evaluation++;
5002 in_alignof++;
5003 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5004 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5006 /* Either __alignof__ ( type-name ) or __alignof__
5007 unary-expression starting with a compound literal. */
5008 struct c_type_name *type_name;
5009 struct c_expr ret;
5010 c_parser_consume_token (parser);
5011 type_name = c_parser_type_name (parser);
5012 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5013 if (type_name == NULL)
5015 struct c_expr ret;
5016 skip_evaluation--;
5017 in_alignof--;
5018 ret.value = error_mark_node;
5019 ret.original_code = ERROR_MARK;
5020 return ret;
5022 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5024 expr = c_parser_postfix_expression_after_paren_type (parser,
5025 type_name);
5026 goto alignof_expr;
5028 /* alignof ( type-name ). */
5029 skip_evaluation--;
5030 in_alignof--;
5031 ret.value = c_alignof (groktypename (type_name));
5032 ret.original_code = ERROR_MARK;
5033 return ret;
5035 else
5037 struct c_expr ret;
5038 expr = c_parser_unary_expression (parser);
5039 alignof_expr:
5040 skip_evaluation--;
5041 in_alignof--;
5042 ret.value = c_alignof_expr (expr.value);
5043 ret.original_code = ERROR_MARK;
5044 return ret;
5048 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5050 postfix-expression:
5051 primary-expression
5052 postfix-expression [ expression ]
5053 postfix-expression ( argument-expression-list[opt] )
5054 postfix-expression . identifier
5055 postfix-expression -> identifier
5056 postfix-expression ++
5057 postfix-expression --
5058 ( type-name ) { initializer-list }
5059 ( type-name ) { initializer-list , }
5061 argument-expression-list:
5062 argument-expression
5063 argument-expression-list , argument-expression
5065 primary-expression:
5066 identifier
5067 constant
5068 string-literal
5069 ( expression )
5071 GNU extensions:
5073 primary-expression:
5074 __func__
5075 (treated as a keyword in GNU C)
5076 __FUNCTION__
5077 __PRETTY_FUNCTION__
5078 ( compound-statement )
5079 __builtin_va_arg ( assignment-expression , type-name )
5080 __builtin_offsetof ( type-name , offsetof-member-designator )
5081 __builtin_choose_expr ( assignment-expression ,
5082 assignment-expression ,
5083 assignment-expression )
5084 __builtin_types_compatible_p ( type-name , type-name )
5086 offsetof-member-designator:
5087 identifier
5088 offsetof-member-designator . identifier
5089 offsetof-member-designator [ expression ]
5091 Objective-C:
5093 primary-expression:
5094 [ objc-receiver objc-message-args ]
5095 @selector ( objc-selector-arg )
5096 @protocol ( identifier )
5097 @encode ( type-name )
5098 objc-string-literal
5101 static struct c_expr
5102 c_parser_postfix_expression (c_parser *parser)
5104 struct c_expr expr, e1, e2, e3;
5105 struct c_type_name *t1, *t2;
5106 location_t loc;
5107 switch (c_parser_peek_token (parser)->type)
5109 case CPP_NUMBER:
5110 case CPP_CHAR:
5111 case CPP_WCHAR:
5112 expr.value = c_parser_peek_token (parser)->value;
5113 expr.original_code = ERROR_MARK;
5114 c_parser_consume_token (parser);
5115 break;
5116 case CPP_STRING:
5117 case CPP_WSTRING:
5118 expr.value = c_parser_peek_token (parser)->value;
5119 expr.original_code = STRING_CST;
5120 c_parser_consume_token (parser);
5121 break;
5122 case CPP_OBJC_STRING:
5123 gcc_assert (c_dialect_objc ());
5124 expr.value
5125 = objc_build_string_object (c_parser_peek_token (parser)->value);
5126 expr.original_code = ERROR_MARK;
5127 c_parser_consume_token (parser);
5128 break;
5129 case CPP_NAME:
5130 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5132 c_parser_error (parser, "expected expression");
5133 expr.value = error_mark_node;
5134 expr.original_code = ERROR_MARK;
5135 break;
5138 tree id = c_parser_peek_token (parser)->value;
5139 location_t loc = c_parser_peek_token (parser)->location;
5140 c_parser_consume_token (parser);
5141 expr.value = build_external_ref (id,
5142 (c_parser_peek_token (parser)->type
5143 == CPP_OPEN_PAREN), loc);
5144 expr.original_code = ERROR_MARK;
5146 break;
5147 case CPP_OPEN_PAREN:
5148 /* A parenthesized expression, statement expression or compound
5149 literal. */
5150 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5152 /* A statement expression. */
5153 tree stmt;
5154 location_t here = c_parser_peek_token (parser)->location;
5155 c_parser_consume_token (parser);
5156 c_parser_consume_token (parser);
5157 if (cur_stmt_list == NULL)
5159 error ("%Hbraced-group within expression allowed "
5160 "only inside a function", &here);
5161 parser->error = true;
5162 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5163 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5164 expr.value = error_mark_node;
5165 expr.original_code = ERROR_MARK;
5166 break;
5168 stmt = c_begin_stmt_expr ();
5169 c_parser_compound_statement_nostart (parser);
5170 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5171 "expected %<)%>");
5172 if (pedantic)
5173 pedwarn ("%HISO C forbids braced-groups within expressions",
5174 &here);
5175 expr.value = c_finish_stmt_expr (stmt);
5176 expr.original_code = ERROR_MARK;
5178 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5180 /* A compound literal. ??? Can we actually get here rather
5181 than going directly to
5182 c_parser_postfix_expression_after_paren_type from
5183 elsewhere? */
5184 struct c_type_name *type_name;
5185 c_parser_consume_token (parser);
5186 type_name = c_parser_type_name (parser);
5187 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5188 "expected %<)%>");
5189 if (type_name == NULL)
5191 expr.value = error_mark_node;
5192 expr.original_code = ERROR_MARK;
5194 else
5195 expr = c_parser_postfix_expression_after_paren_type (parser,
5196 type_name);
5198 else
5200 /* A parenthesized expression. */
5201 c_parser_consume_token (parser);
5202 expr = c_parser_expression (parser);
5203 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5204 TREE_NO_WARNING (expr.value) = 1;
5205 expr.original_code = ERROR_MARK;
5206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5207 "expected %<)%>");
5209 break;
5210 case CPP_KEYWORD:
5211 switch (c_parser_peek_token (parser)->keyword)
5213 case RID_FUNCTION_NAME:
5214 case RID_PRETTY_FUNCTION_NAME:
5215 case RID_C99_FUNCTION_NAME:
5216 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5217 c_parser_peek_token (parser)->value);
5218 expr.original_code = ERROR_MARK;
5219 c_parser_consume_token (parser);
5220 break;
5221 case RID_VA_ARG:
5222 c_parser_consume_token (parser);
5223 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5225 expr.value = error_mark_node;
5226 expr.original_code = ERROR_MARK;
5227 break;
5229 e1 = c_parser_expr_no_commas (parser, NULL);
5230 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5232 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5233 expr.value = error_mark_node;
5234 expr.original_code = ERROR_MARK;
5235 break;
5237 t1 = c_parser_type_name (parser);
5238 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5239 "expected %<)%>");
5240 if (t1 == NULL)
5242 expr.value = error_mark_node;
5243 expr.original_code = ERROR_MARK;
5245 else
5247 expr.value = build_va_arg (e1.value, groktypename (t1));
5248 expr.original_code = ERROR_MARK;
5250 break;
5251 case RID_OFFSETOF:
5252 c_parser_consume_token (parser);
5253 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5255 expr.value = error_mark_node;
5256 expr.original_code = ERROR_MARK;
5257 break;
5259 t1 = c_parser_type_name (parser);
5260 if (t1 == NULL)
5262 expr.value = error_mark_node;
5263 expr.original_code = ERROR_MARK;
5264 break;
5266 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5268 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5269 expr.value = error_mark_node;
5270 expr.original_code = ERROR_MARK;
5271 break;
5274 tree type = groktypename (t1);
5275 tree offsetof_ref;
5276 if (type == error_mark_node)
5277 offsetof_ref = error_mark_node;
5278 else
5279 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5280 /* Parse the second argument to __builtin_offsetof. We
5281 must have one identifier, and beyond that we want to
5282 accept sub structure and sub array references. */
5283 if (c_parser_next_token_is (parser, CPP_NAME))
5285 offsetof_ref = build_component_ref
5286 (offsetof_ref, c_parser_peek_token (parser)->value);
5287 c_parser_consume_token (parser);
5288 while (c_parser_next_token_is (parser, CPP_DOT)
5289 || c_parser_next_token_is (parser,
5290 CPP_OPEN_SQUARE))
5292 if (c_parser_next_token_is (parser, CPP_DOT))
5294 c_parser_consume_token (parser);
5295 if (c_parser_next_token_is_not (parser,
5296 CPP_NAME))
5298 c_parser_error (parser, "expected identifier");
5299 break;
5301 offsetof_ref = build_component_ref
5302 (offsetof_ref,
5303 c_parser_peek_token (parser)->value);
5304 c_parser_consume_token (parser);
5306 else
5308 tree idx;
5309 c_parser_consume_token (parser);
5310 idx = c_parser_expression (parser).value;
5311 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5312 "expected %<]%>");
5313 offsetof_ref = build_array_ref (offsetof_ref, idx);
5317 else
5318 c_parser_error (parser, "expected identifier");
5319 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5320 "expected %<)%>");
5321 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5322 expr.original_code = ERROR_MARK;
5324 break;
5325 case RID_CHOOSE_EXPR:
5326 c_parser_consume_token (parser);
5327 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5329 expr.value = error_mark_node;
5330 expr.original_code = ERROR_MARK;
5331 break;
5333 loc = c_parser_peek_token (parser)->location;
5334 e1 = c_parser_expr_no_commas (parser, NULL);
5335 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5337 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5338 expr.value = error_mark_node;
5339 expr.original_code = ERROR_MARK;
5340 break;
5342 e2 = c_parser_expr_no_commas (parser, NULL);
5343 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5345 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5346 expr.value = error_mark_node;
5347 expr.original_code = ERROR_MARK;
5348 break;
5350 e3 = c_parser_expr_no_commas (parser, NULL);
5351 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5352 "expected %<)%>");
5354 tree c;
5356 c = fold (e1.value);
5357 if (TREE_CODE (c) != INTEGER_CST)
5358 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5359 " a constant", &loc);
5360 expr = integer_zerop (c) ? e3 : e2;
5362 break;
5363 case RID_TYPES_COMPATIBLE_P:
5364 c_parser_consume_token (parser);
5365 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5367 expr.value = error_mark_node;
5368 expr.original_code = ERROR_MARK;
5369 break;
5371 t1 = c_parser_type_name (parser);
5372 if (t1 == NULL)
5374 expr.value = error_mark_node;
5375 expr.original_code = ERROR_MARK;
5376 break;
5378 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5380 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5381 expr.value = error_mark_node;
5382 expr.original_code = ERROR_MARK;
5383 break;
5385 t2 = c_parser_type_name (parser);
5386 if (t2 == NULL)
5388 expr.value = error_mark_node;
5389 expr.original_code = ERROR_MARK;
5390 break;
5392 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5393 "expected %<)%>");
5395 tree e1, e2;
5397 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5398 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5400 expr.value = comptypes (e1, e2)
5401 ? build_int_cst (NULL_TREE, 1)
5402 : build_int_cst (NULL_TREE, 0);
5403 expr.original_code = ERROR_MARK;
5405 break;
5406 case RID_AT_SELECTOR:
5407 gcc_assert (c_dialect_objc ());
5408 c_parser_consume_token (parser);
5409 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5411 expr.value = error_mark_node;
5412 expr.original_code = ERROR_MARK;
5413 break;
5416 tree sel = c_parser_objc_selector_arg (parser);
5417 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5418 "expected %<)%>");
5419 expr.value = objc_build_selector_expr (sel);
5420 expr.original_code = ERROR_MARK;
5422 break;
5423 case RID_AT_PROTOCOL:
5424 gcc_assert (c_dialect_objc ());
5425 c_parser_consume_token (parser);
5426 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5428 expr.value = error_mark_node;
5429 expr.original_code = ERROR_MARK;
5430 break;
5432 if (c_parser_next_token_is_not (parser, CPP_NAME))
5434 c_parser_error (parser, "expected identifier");
5435 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5436 expr.value = error_mark_node;
5437 expr.original_code = ERROR_MARK;
5438 break;
5441 tree id = c_parser_peek_token (parser)->value;
5442 c_parser_consume_token (parser);
5443 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5444 "expected %<)%>");
5445 expr.value = objc_build_protocol_expr (id);
5446 expr.original_code = ERROR_MARK;
5448 break;
5449 case RID_AT_ENCODE:
5450 /* Extension to support C-structures in the archiver. */
5451 gcc_assert (c_dialect_objc ());
5452 c_parser_consume_token (parser);
5453 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5455 expr.value = error_mark_node;
5456 expr.original_code = ERROR_MARK;
5457 break;
5459 t1 = c_parser_type_name (parser);
5460 if (t1 == NULL)
5462 expr.value = error_mark_node;
5463 expr.original_code = ERROR_MARK;
5464 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5465 break;
5467 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5468 "expected %<)%>");
5470 tree type = groktypename (t1);
5471 expr.value = objc_build_encode_expr (type);
5472 expr.original_code = ERROR_MARK;
5474 break;
5475 default:
5476 c_parser_error (parser, "expected expression");
5477 expr.value = error_mark_node;
5478 expr.original_code = ERROR_MARK;
5479 break;
5481 break;
5482 case CPP_OPEN_SQUARE:
5483 if (c_dialect_objc ())
5485 tree receiver, args;
5486 c_parser_consume_token (parser);
5487 receiver = c_parser_objc_receiver (parser);
5488 args = c_parser_objc_message_args (parser);
5489 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5490 "expected %<]%>");
5491 expr.value = objc_build_message_expr (build_tree_list (receiver,
5492 args));
5493 expr.original_code = ERROR_MARK;
5494 break;
5496 /* Else fall through to report error. */
5497 default:
5498 c_parser_error (parser, "expected expression");
5499 expr.value = error_mark_node;
5500 expr.original_code = ERROR_MARK;
5501 break;
5503 return c_parser_postfix_expression_after_primary (parser, expr);
5506 /* Parse a postfix expression after a parenthesized type name: the
5507 brace-enclosed initializer of a compound literal, possibly followed
5508 by some postfix operators. This is separate because it is not
5509 possible to tell until after the type name whether a cast
5510 expression has a cast or a compound literal, or whether the operand
5511 of sizeof is a parenthesized type name or starts with a compound
5512 literal. */
5514 static struct c_expr
5515 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5516 struct c_type_name *type_name)
5518 tree type;
5519 struct c_expr init;
5520 struct c_expr expr;
5521 location_t start_loc;
5522 start_init (NULL_TREE, NULL, 0);
5523 type = groktypename (type_name);
5524 start_loc = c_parser_peek_token (parser)->location;
5525 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5527 error ("%Hcompound literal has variable size", &start_loc);
5528 type = error_mark_node;
5530 init = c_parser_braced_init (parser, type, false);
5531 finish_init ();
5532 maybe_warn_string_init (type, init);
5534 if (pedantic && !flag_isoc99)
5535 pedwarn ("%HISO C90 forbids compound literals", &start_loc);
5536 expr.value = build_compound_literal (type, init.value);
5537 expr.original_code = ERROR_MARK;
5538 return c_parser_postfix_expression_after_primary (parser, expr);
5541 /* Parse a postfix expression after the initial primary or compound
5542 literal; that is, parse a series of postfix operators. */
5544 static struct c_expr
5545 c_parser_postfix_expression_after_primary (c_parser *parser,
5546 struct c_expr expr)
5548 tree ident, idx, exprlist;
5549 while (true)
5551 switch (c_parser_peek_token (parser)->type)
5553 case CPP_OPEN_SQUARE:
5554 /* Array reference. */
5555 c_parser_consume_token (parser);
5556 idx = c_parser_expression (parser).value;
5557 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5558 "expected %<]%>");
5559 expr.value = build_array_ref (expr.value, idx);
5560 expr.original_code = ERROR_MARK;
5561 break;
5562 case CPP_OPEN_PAREN:
5563 /* Function call. */
5564 c_parser_consume_token (parser);
5565 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5566 exprlist = NULL_TREE;
5567 else
5568 exprlist = c_parser_expr_list (parser, true);
5569 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5570 "expected %<)%>");
5571 expr.value = build_function_call (expr.value, exprlist);
5572 expr.original_code = ERROR_MARK;
5573 break;
5574 case CPP_DOT:
5575 /* Structure element reference. */
5576 c_parser_consume_token (parser);
5577 expr = default_function_array_conversion (expr);
5578 if (c_parser_next_token_is (parser, CPP_NAME))
5579 ident = c_parser_peek_token (parser)->value;
5580 else
5582 c_parser_error (parser, "expected identifier");
5583 expr.value = error_mark_node;
5584 expr.original_code = ERROR_MARK;
5585 return expr;
5587 c_parser_consume_token (parser);
5588 expr.value = build_component_ref (expr.value, ident);
5589 expr.original_code = ERROR_MARK;
5590 break;
5591 case CPP_DEREF:
5592 /* Structure element reference. */
5593 c_parser_consume_token (parser);
5594 expr = default_function_array_conversion (expr);
5595 if (c_parser_next_token_is (parser, CPP_NAME))
5596 ident = c_parser_peek_token (parser)->value;
5597 else
5599 c_parser_error (parser, "expected identifier");
5600 expr.value = error_mark_node;
5601 expr.original_code = ERROR_MARK;
5602 return expr;
5604 c_parser_consume_token (parser);
5605 expr.value = build_component_ref (build_indirect_ref (expr.value,
5606 "->"), ident);
5607 expr.original_code = ERROR_MARK;
5608 break;
5609 case CPP_PLUS_PLUS:
5610 /* Postincrement. */
5611 c_parser_consume_token (parser);
5612 expr = default_function_array_conversion (expr);
5613 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5614 expr.original_code = ERROR_MARK;
5615 break;
5616 case CPP_MINUS_MINUS:
5617 /* Postdecrement. */
5618 c_parser_consume_token (parser);
5619 expr = default_function_array_conversion (expr);
5620 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5621 expr.original_code = ERROR_MARK;
5622 break;
5623 default:
5624 return expr;
5629 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5631 expression:
5632 assignment-expression
5633 expression , assignment-expression
5636 static struct c_expr
5637 c_parser_expression (c_parser *parser)
5639 struct c_expr expr;
5640 expr = c_parser_expr_no_commas (parser, NULL);
5641 while (c_parser_next_token_is (parser, CPP_COMMA))
5643 struct c_expr next;
5644 c_parser_consume_token (parser);
5645 next = c_parser_expr_no_commas (parser, NULL);
5646 next = default_function_array_conversion (next);
5647 expr.value = build_compound_expr (expr.value, next.value);
5648 expr.original_code = COMPOUND_EXPR;
5650 return expr;
5653 /* Parse an expression and convert functions or arrays to
5654 pointers. */
5656 static struct c_expr
5657 c_parser_expression_conv (c_parser *parser)
5659 struct c_expr expr;
5660 expr = c_parser_expression (parser);
5661 expr = default_function_array_conversion (expr);
5662 return expr;
5665 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5666 functions and arrays to pointers.
5668 nonempty-expr-list:
5669 assignment-expression
5670 nonempty-expr-list , assignment-expression
5673 static tree
5674 c_parser_expr_list (c_parser *parser, bool convert_p)
5676 struct c_expr expr;
5677 tree ret, cur;
5678 expr = c_parser_expr_no_commas (parser, NULL);
5679 if (convert_p)
5680 expr = default_function_array_conversion (expr);
5681 ret = cur = build_tree_list (NULL_TREE, expr.value);
5682 while (c_parser_next_token_is (parser, CPP_COMMA))
5684 c_parser_consume_token (parser);
5685 expr = c_parser_expr_no_commas (parser, NULL);
5686 if (convert_p)
5687 expr = default_function_array_conversion (expr);
5688 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5690 return ret;
5694 /* Parse Objective-C-specific constructs. */
5696 /* Parse an objc-class-definition.
5698 objc-class-definition:
5699 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5700 objc-class-instance-variables[opt] objc-methodprotolist @end
5701 @implementation identifier objc-superclass[opt]
5702 objc-class-instance-variables[opt]
5703 @interface identifier ( identifier ) objc-protocol-refs[opt]
5704 objc-methodprotolist @end
5705 @implementation identifier ( identifier )
5707 objc-superclass:
5708 : identifier
5710 "@interface identifier (" must start "@interface identifier (
5711 identifier ) ...": objc-methodprotolist in the first production may
5712 not start with a parenthesized identifier as a declarator of a data
5713 definition with no declaration specifiers if the objc-superclass,
5714 objc-protocol-refs and objc-class-instance-variables are omitted. */
5716 static void
5717 c_parser_objc_class_definition (c_parser *parser)
5719 bool iface_p;
5720 tree id1;
5721 tree superclass;
5722 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5723 iface_p = true;
5724 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5725 iface_p = false;
5726 else
5727 gcc_unreachable ();
5728 c_parser_consume_token (parser);
5729 if (c_parser_next_token_is_not (parser, CPP_NAME))
5731 c_parser_error (parser, "expected identifier");
5732 return;
5734 id1 = c_parser_peek_token (parser)->value;
5735 c_parser_consume_token (parser);
5736 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5738 tree id2;
5739 tree proto = NULL_TREE;
5740 c_parser_consume_token (parser);
5741 if (c_parser_next_token_is_not (parser, CPP_NAME))
5743 c_parser_error (parser, "expected identifier");
5744 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5745 return;
5747 id2 = c_parser_peek_token (parser)->value;
5748 c_parser_consume_token (parser);
5749 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5750 if (!iface_p)
5752 objc_start_category_implementation (id1, id2);
5753 return;
5755 if (c_parser_next_token_is (parser, CPP_LESS))
5756 proto = c_parser_objc_protocol_refs (parser);
5757 objc_start_category_interface (id1, id2, proto);
5758 c_parser_objc_methodprotolist (parser);
5759 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5760 objc_finish_interface ();
5761 return;
5763 if (c_parser_next_token_is (parser, CPP_COLON))
5765 c_parser_consume_token (parser);
5766 if (c_parser_next_token_is_not (parser, CPP_NAME))
5768 c_parser_error (parser, "expected identifier");
5769 return;
5771 superclass = c_parser_peek_token (parser)->value;
5772 c_parser_consume_token (parser);
5774 else
5775 superclass = NULL_TREE;
5776 if (iface_p)
5778 tree proto = NULL_TREE;
5779 if (c_parser_next_token_is (parser, CPP_LESS))
5780 proto = c_parser_objc_protocol_refs (parser);
5781 objc_start_class_interface (id1, superclass, proto);
5783 else
5784 objc_start_class_implementation (id1, superclass);
5785 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5786 c_parser_objc_class_instance_variables (parser);
5787 if (iface_p)
5789 objc_continue_interface ();
5790 c_parser_objc_methodprotolist (parser);
5791 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5792 objc_finish_interface ();
5794 else
5796 objc_continue_implementation ();
5797 return;
5801 /* Parse objc-class-instance-variables.
5803 objc-class-instance-variables:
5804 { objc-instance-variable-decl-list[opt] }
5806 objc-instance-variable-decl-list:
5807 objc-visibility-spec
5808 objc-instance-variable-decl ;
5810 objc-instance-variable-decl-list objc-visibility-spec
5811 objc-instance-variable-decl-list objc-instance-variable-decl ;
5812 objc-instance-variable-decl-list ;
5814 objc-visibility-spec:
5815 @private
5816 @protected
5817 @public
5819 objc-instance-variable-decl:
5820 struct-declaration
5823 static void
5824 c_parser_objc_class_instance_variables (c_parser *parser)
5826 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5827 c_parser_consume_token (parser);
5828 while (c_parser_next_token_is_not (parser, CPP_EOF))
5830 tree decls;
5831 /* Parse any stray semicolon. */
5832 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5834 if (pedantic)
5835 pedwarn ("%Hextra semicolon in struct or union specified",
5836 &c_parser_peek_token (parser)->location);
5837 c_parser_consume_token (parser);
5838 continue;
5840 /* Stop if at the end of the instance variables. */
5841 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5843 c_parser_consume_token (parser);
5844 break;
5846 /* Parse any objc-visibility-spec. */
5847 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5849 c_parser_consume_token (parser);
5850 objc_set_visibility (2);
5851 continue;
5853 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5855 c_parser_consume_token (parser);
5856 objc_set_visibility (0);
5857 continue;
5859 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5861 c_parser_consume_token (parser);
5862 objc_set_visibility (1);
5863 continue;
5865 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5867 c_parser_pragma (parser, pragma_external);
5868 continue;
5871 /* Parse some comma-separated declarations. */
5872 decls = c_parser_struct_declaration (parser);
5874 /* Comma-separated instance variables are chained together in
5875 reverse order; add them one by one. */
5876 tree ivar = nreverse (decls);
5877 for (; ivar; ivar = TREE_CHAIN (ivar))
5878 objc_add_instance_variable (copy_node (ivar));
5880 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5884 /* Parse an objc-class-declaration.
5886 objc-class-declaration:
5887 @class identifier-list ;
5890 static void
5891 c_parser_objc_class_declaration (c_parser *parser)
5893 tree list = NULL_TREE;
5894 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5895 c_parser_consume_token (parser);
5896 /* Any identifiers, including those declared as type names, are OK
5897 here. */
5898 while (true)
5900 tree id;
5901 if (c_parser_next_token_is_not (parser, CPP_NAME))
5903 c_parser_error (parser, "expected identifier");
5904 break;
5906 id = c_parser_peek_token (parser)->value;
5907 list = chainon (list, build_tree_list (NULL_TREE, id));
5908 c_parser_consume_token (parser);
5909 if (c_parser_next_token_is (parser, CPP_COMMA))
5910 c_parser_consume_token (parser);
5911 else
5912 break;
5914 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5915 objc_declare_class (list);
5918 /* Parse an objc-alias-declaration.
5920 objc-alias-declaration:
5921 @compatibility_alias identifier identifier ;
5924 static void
5925 c_parser_objc_alias_declaration (c_parser *parser)
5927 tree id1, id2;
5928 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5929 c_parser_consume_token (parser);
5930 if (c_parser_next_token_is_not (parser, CPP_NAME))
5932 c_parser_error (parser, "expected identifier");
5933 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5934 return;
5936 id1 = c_parser_peek_token (parser)->value;
5937 c_parser_consume_token (parser);
5938 if (c_parser_next_token_is_not (parser, CPP_NAME))
5940 c_parser_error (parser, "expected identifier");
5941 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5942 return;
5944 id2 = c_parser_peek_token (parser)->value;
5945 c_parser_consume_token (parser);
5946 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5947 objc_declare_alias (id1, id2);
5950 /* Parse an objc-protocol-definition.
5952 objc-protocol-definition:
5953 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5954 @protocol identifier-list ;
5956 "@protocol identifier ;" should be resolved as "@protocol
5957 identifier-list ;": objc-methodprotolist may not start with a
5958 semicolon in the first alternative if objc-protocol-refs are
5959 omitted. */
5961 static void
5962 c_parser_objc_protocol_definition (c_parser *parser)
5964 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5965 c_parser_consume_token (parser);
5966 if (c_parser_next_token_is_not (parser, CPP_NAME))
5968 c_parser_error (parser, "expected identifier");
5969 return;
5971 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5972 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5974 tree list = NULL_TREE;
5975 /* Any identifiers, including those declared as type names, are
5976 OK here. */
5977 while (true)
5979 tree id;
5980 if (c_parser_next_token_is_not (parser, CPP_NAME))
5982 c_parser_error (parser, "expected identifier");
5983 break;
5985 id = c_parser_peek_token (parser)->value;
5986 list = chainon (list, build_tree_list (NULL_TREE, id));
5987 c_parser_consume_token (parser);
5988 if (c_parser_next_token_is (parser, CPP_COMMA))
5989 c_parser_consume_token (parser);
5990 else
5991 break;
5993 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5994 objc_declare_protocols (list);
5996 else
5998 tree id = c_parser_peek_token (parser)->value;
5999 tree proto = NULL_TREE;
6000 c_parser_consume_token (parser);
6001 if (c_parser_next_token_is (parser, CPP_LESS))
6002 proto = c_parser_objc_protocol_refs (parser);
6003 parser->objc_pq_context = true;
6004 objc_start_protocol (id, proto);
6005 c_parser_objc_methodprotolist (parser);
6006 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6007 parser->objc_pq_context = false;
6008 objc_finish_interface ();
6012 /* Parse an objc-method-type.
6014 objc-method-type:
6019 static enum tree_code
6020 c_parser_objc_method_type (c_parser *parser)
6022 switch (c_parser_peek_token (parser)->type)
6024 case CPP_PLUS:
6025 c_parser_consume_token (parser);
6026 return PLUS_EXPR;
6027 case CPP_MINUS:
6028 c_parser_consume_token (parser);
6029 return MINUS_EXPR;
6030 default:
6031 gcc_unreachable ();
6035 /* Parse an objc-method-definition.
6037 objc-method-definition:
6038 objc-method-type objc-method-decl ;[opt] compound-statement
6041 static void
6042 c_parser_objc_method_definition (c_parser *parser)
6044 enum tree_code type = c_parser_objc_method_type (parser);
6045 tree decl;
6046 objc_set_method_type (type);
6047 parser->objc_pq_context = true;
6048 decl = c_parser_objc_method_decl (parser);
6049 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6051 c_parser_consume_token (parser);
6052 if (pedantic)
6053 pedwarn ("%Hextra semicolon in method definition specified",
6054 &c_parser_peek_token (parser)->location);
6056 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6058 c_parser_error (parser, "expected %<{%>");
6059 return;
6061 parser->objc_pq_context = false;
6062 objc_start_method_definition (decl);
6063 add_stmt (c_parser_compound_statement (parser));
6064 objc_finish_method_definition (current_function_decl);
6067 /* Parse an objc-methodprotolist.
6069 objc-methodprotolist:
6070 empty
6071 objc-methodprotolist objc-methodproto
6072 objc-methodprotolist declaration
6073 objc-methodprotolist ;
6075 The declaration is a data definition, which may be missing
6076 declaration specifiers under the same rules and diagnostics as
6077 other data definitions outside functions, and the stray semicolon
6078 is diagnosed the same way as a stray semicolon outside a
6079 function. */
6081 static void
6082 c_parser_objc_methodprotolist (c_parser *parser)
6084 while (true)
6086 /* The list is terminated by @end. */
6087 switch (c_parser_peek_token (parser)->type)
6089 case CPP_SEMICOLON:
6090 if (pedantic)
6091 pedwarn ("%HISO C does not allow extra %<;%> "
6092 "outside of a function",
6093 &c_parser_peek_token (parser)->location);
6094 c_parser_consume_token (parser);
6095 break;
6096 case CPP_PLUS:
6097 case CPP_MINUS:
6098 c_parser_objc_methodproto (parser);
6099 break;
6100 case CPP_PRAGMA:
6101 c_parser_pragma (parser, pragma_external);
6102 break;
6103 case CPP_EOF:
6104 return;
6105 default:
6106 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6107 return;
6108 c_parser_declaration_or_fndef (parser, false, true, false, true);
6109 break;
6114 /* Parse an objc-methodproto.
6116 objc-methodproto:
6117 objc-method-type objc-method-decl ;
6120 static void
6121 c_parser_objc_methodproto (c_parser *parser)
6123 enum tree_code type = c_parser_objc_method_type (parser);
6124 tree decl;
6125 objc_set_method_type (type);
6126 /* Remember protocol qualifiers in prototypes. */
6127 parser->objc_pq_context = true;
6128 decl = c_parser_objc_method_decl (parser);
6129 /* Forget protocol qualifiers here. */
6130 parser->objc_pq_context = false;
6131 objc_add_method_declaration (decl);
6132 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6135 /* Parse an objc-method-decl.
6137 objc-method-decl:
6138 ( objc-type-name ) objc-selector
6139 objc-selector
6140 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6141 objc-keyword-selector objc-optparmlist
6143 objc-keyword-selector:
6144 objc-keyword-decl
6145 objc-keyword-selector objc-keyword-decl
6147 objc-keyword-decl:
6148 objc-selector : ( objc-type-name ) identifier
6149 objc-selector : identifier
6150 : ( objc-type-name ) identifier
6151 : identifier
6153 objc-optparmlist:
6154 objc-optparms objc-optellipsis
6156 objc-optparms:
6157 empty
6158 objc-opt-parms , parameter-declaration
6160 objc-optellipsis:
6161 empty
6162 , ...
6165 static tree
6166 c_parser_objc_method_decl (c_parser *parser)
6168 tree type = NULL_TREE;
6169 tree sel;
6170 tree parms = NULL_TREE;
6171 bool ellipsis = false;
6173 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6175 c_parser_consume_token (parser);
6176 type = c_parser_objc_type_name (parser);
6177 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6179 sel = c_parser_objc_selector (parser);
6180 /* If there is no selector, or a colon follows, we have an
6181 objc-keyword-selector. If there is a selector, and a colon does
6182 not follow, that selector ends the objc-method-decl. */
6183 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6185 tree tsel = sel;
6186 tree list = NULL_TREE;
6187 while (true)
6189 tree atype = NULL_TREE, id, keyworddecl;
6190 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6191 break;
6192 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6194 c_parser_consume_token (parser);
6195 atype = c_parser_objc_type_name (parser);
6196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6197 "expected %<)%>");
6199 if (c_parser_next_token_is_not (parser, CPP_NAME))
6201 c_parser_error (parser, "expected identifier");
6202 return error_mark_node;
6204 id = c_parser_peek_token (parser)->value;
6205 c_parser_consume_token (parser);
6206 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6207 list = chainon (list, keyworddecl);
6208 tsel = c_parser_objc_selector (parser);
6209 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6210 break;
6212 /* Parse the optional parameter list. Optional Objective-C
6213 method parameters follow the C syntax, and may include '...'
6214 to denote a variable number of arguments. */
6215 parms = make_node (TREE_LIST);
6216 while (c_parser_next_token_is (parser, CPP_COMMA))
6218 struct c_parm *parm;
6219 c_parser_consume_token (parser);
6220 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6222 ellipsis = true;
6223 c_parser_consume_token (parser);
6224 break;
6226 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6227 if (parm == NULL)
6228 break;
6229 parms = chainon (parms,
6230 build_tree_list (NULL_TREE, grokparm (parm)));
6232 sel = list;
6234 return objc_build_method_signature (type, sel, parms, ellipsis);
6237 /* Parse an objc-type-name.
6239 objc-type-name:
6240 objc-type-qualifiers[opt] type-name
6241 objc-type-qualifiers[opt]
6243 objc-type-qualifiers:
6244 objc-type-qualifier
6245 objc-type-qualifiers objc-type-qualifier
6247 objc-type-qualifier: one of
6248 in out inout bycopy byref oneway
6251 static tree
6252 c_parser_objc_type_name (c_parser *parser)
6254 tree quals = NULL_TREE;
6255 struct c_type_name *typename = NULL;
6256 tree type = NULL_TREE;
6257 while (true)
6259 c_token *token = c_parser_peek_token (parser);
6260 if (token->type == CPP_KEYWORD
6261 && (token->keyword == RID_IN
6262 || token->keyword == RID_OUT
6263 || token->keyword == RID_INOUT
6264 || token->keyword == RID_BYCOPY
6265 || token->keyword == RID_BYREF
6266 || token->keyword == RID_ONEWAY))
6268 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6269 c_parser_consume_token (parser);
6271 else
6272 break;
6274 if (c_parser_next_token_starts_typename (parser))
6275 typename = c_parser_type_name (parser);
6276 if (typename)
6277 type = groktypename (typename);
6278 return build_tree_list (quals, type);
6281 /* Parse objc-protocol-refs.
6283 objc-protocol-refs:
6284 < identifier-list >
6287 static tree
6288 c_parser_objc_protocol_refs (c_parser *parser)
6290 tree list = NULL_TREE;
6291 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6292 c_parser_consume_token (parser);
6293 /* Any identifiers, including those declared as type names, are OK
6294 here. */
6295 while (true)
6297 tree id;
6298 if (c_parser_next_token_is_not (parser, CPP_NAME))
6300 c_parser_error (parser, "expected identifier");
6301 break;
6303 id = c_parser_peek_token (parser)->value;
6304 list = chainon (list, build_tree_list (NULL_TREE, id));
6305 c_parser_consume_token (parser);
6306 if (c_parser_next_token_is (parser, CPP_COMMA))
6307 c_parser_consume_token (parser);
6308 else
6309 break;
6311 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6312 return list;
6315 /* Parse an objc-try-catch-statement.
6317 objc-try-catch-statement:
6318 @try compound-statement objc-catch-list[opt]
6319 @try compound-statement objc-catch-list[opt] @finally compound-statement
6321 objc-catch-list:
6322 @catch ( parameter-declaration ) compound-statement
6323 objc-catch-list @catch ( parameter-declaration ) compound-statement
6326 static void
6327 c_parser_objc_try_catch_statement (c_parser *parser)
6329 location_t loc;
6330 tree stmt;
6331 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6332 c_parser_consume_token (parser);
6333 loc = c_parser_peek_token (parser)->location;
6334 stmt = c_parser_compound_statement (parser);
6335 objc_begin_try_stmt (loc, stmt);
6336 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6338 struct c_parm *parm;
6339 c_parser_consume_token (parser);
6340 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6341 break;
6342 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6343 if (parm == NULL)
6345 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6346 break;
6348 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6349 objc_begin_catch_clause (grokparm (parm));
6350 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6351 c_parser_compound_statement_nostart (parser);
6352 objc_finish_catch_clause ();
6354 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6356 location_t finloc;
6357 tree finstmt;
6358 c_parser_consume_token (parser);
6359 finloc = c_parser_peek_token (parser)->location;
6360 finstmt = c_parser_compound_statement (parser);
6361 objc_build_finally_clause (finloc, finstmt);
6363 objc_finish_try_stmt ();
6366 /* Parse an objc-synchronized-statement.
6368 objc-synchronized-statement:
6369 @synchronized ( expression ) compound-statement
6372 static void
6373 c_parser_objc_synchronized_statement (c_parser *parser)
6375 location_t loc;
6376 tree expr, stmt;
6377 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6378 c_parser_consume_token (parser);
6379 loc = c_parser_peek_token (parser)->location;
6380 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6382 expr = c_parser_expression (parser).value;
6383 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6385 else
6386 expr = error_mark_node;
6387 stmt = c_parser_compound_statement (parser);
6388 objc_build_synchronized (loc, expr, stmt);
6391 /* Parse an objc-selector; return NULL_TREE without an error if the
6392 next token is not an objc-selector.
6394 objc-selector:
6395 identifier
6396 one of
6397 enum struct union if else while do for switch case default
6398 break continue return goto asm sizeof typeof __alignof
6399 unsigned long const short volatile signed restrict _Complex
6400 in out inout bycopy byref oneway int char float double void _Bool
6402 ??? Why this selection of keywords but not, for example, storage
6403 class specifiers? */
6405 static tree
6406 c_parser_objc_selector (c_parser *parser)
6408 c_token *token = c_parser_peek_token (parser);
6409 tree value = token->value;
6410 if (token->type == CPP_NAME)
6412 c_parser_consume_token (parser);
6413 return value;
6415 if (token->type != CPP_KEYWORD)
6416 return NULL_TREE;
6417 switch (token->keyword)
6419 case RID_ENUM:
6420 case RID_STRUCT:
6421 case RID_UNION:
6422 case RID_IF:
6423 case RID_ELSE:
6424 case RID_WHILE:
6425 case RID_DO:
6426 case RID_FOR:
6427 case RID_SWITCH:
6428 case RID_CASE:
6429 case RID_DEFAULT:
6430 case RID_BREAK:
6431 case RID_CONTINUE:
6432 case RID_RETURN:
6433 case RID_GOTO:
6434 case RID_ASM:
6435 case RID_SIZEOF:
6436 case RID_TYPEOF:
6437 case RID_ALIGNOF:
6438 case RID_UNSIGNED:
6439 case RID_LONG:
6440 case RID_CONST:
6441 case RID_SHORT:
6442 case RID_VOLATILE:
6443 case RID_SIGNED:
6444 case RID_RESTRICT:
6445 case RID_COMPLEX:
6446 case RID_IN:
6447 case RID_OUT:
6448 case RID_INOUT:
6449 case RID_BYCOPY:
6450 case RID_BYREF:
6451 case RID_ONEWAY:
6452 case RID_INT:
6453 case RID_CHAR:
6454 case RID_FLOAT:
6455 case RID_DOUBLE:
6456 case RID_VOID:
6457 case RID_BOOL:
6458 c_parser_consume_token (parser);
6459 return value;
6460 default:
6461 return NULL_TREE;
6465 /* Parse an objc-selector-arg.
6467 objc-selector-arg:
6468 objc-selector
6469 objc-keywordname-list
6471 objc-keywordname-list:
6472 objc-keywordname
6473 objc-keywordname-list objc-keywordname
6475 objc-keywordname:
6476 objc-selector :
6480 static tree
6481 c_parser_objc_selector_arg (c_parser *parser)
6483 tree sel = c_parser_objc_selector (parser);
6484 tree list = NULL_TREE;
6485 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6486 return sel;
6487 while (true)
6489 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6490 return list;
6491 list = chainon (list, build_tree_list (sel, NULL_TREE));
6492 sel = c_parser_objc_selector (parser);
6493 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6494 break;
6496 return list;
6499 /* Parse an objc-receiver.
6501 objc-receiver:
6502 expression
6503 class-name
6504 type-name
6507 static tree
6508 c_parser_objc_receiver (c_parser *parser)
6510 if (c_parser_peek_token (parser)->type == CPP_NAME
6511 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6512 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6514 tree id = c_parser_peek_token (parser)->value;
6515 c_parser_consume_token (parser);
6516 return objc_get_class_reference (id);
6518 return c_parser_expression (parser).value;
6521 /* Parse objc-message-args.
6523 objc-message-args:
6524 objc-selector
6525 objc-keywordarg-list
6527 objc-keywordarg-list:
6528 objc-keywordarg
6529 objc-keywordarg-list objc-keywordarg
6531 objc-keywordarg:
6532 objc-selector : objc-keywordexpr
6533 : objc-keywordexpr
6536 static tree
6537 c_parser_objc_message_args (c_parser *parser)
6539 tree sel = c_parser_objc_selector (parser);
6540 tree list = NULL_TREE;
6541 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6542 return sel;
6543 while (true)
6545 tree keywordexpr;
6546 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6547 return list;
6548 keywordexpr = c_parser_objc_keywordexpr (parser);
6549 list = chainon (list, build_tree_list (sel, keywordexpr));
6550 sel = c_parser_objc_selector (parser);
6551 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6552 break;
6554 return list;
6557 /* Parse an objc-keywordexpr.
6559 objc-keywordexpr:
6560 nonempty-expr-list
6563 static tree
6564 c_parser_objc_keywordexpr (c_parser *parser)
6566 tree list = c_parser_expr_list (parser, true);
6567 if (TREE_CHAIN (list) == NULL_TREE)
6569 /* Just return the expression, remove a level of
6570 indirection. */
6571 return TREE_VALUE (list);
6573 else
6575 /* We have a comma expression, we will collapse later. */
6576 return list;
6581 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6582 should be considered, statements. ALLOW_STMT is true if we're within
6583 the context of a function and such pragmas are to be allowed. Returns
6584 true if we actually parsed such a pragma. */
6586 static bool
6587 c_parser_pragma (c_parser *parser, enum pragma_context context)
6589 unsigned int id;
6591 id = c_parser_peek_token (parser)->pragma_kind;
6592 gcc_assert (id != PRAGMA_NONE);
6594 switch (id)
6596 case PRAGMA_OMP_BARRIER:
6597 if (context != pragma_compound)
6599 if (context == pragma_stmt)
6600 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6601 "used in compound statements");
6602 goto bad_stmt;
6604 c_parser_omp_barrier (parser);
6605 return false;
6607 case PRAGMA_OMP_FLUSH:
6608 if (context != pragma_compound)
6610 if (context == pragma_stmt)
6611 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6612 "used in compound statements");
6613 goto bad_stmt;
6615 c_parser_omp_flush (parser);
6616 return false;
6618 case PRAGMA_OMP_THREADPRIVATE:
6619 c_parser_omp_threadprivate (parser);
6620 return false;
6622 case PRAGMA_OMP_SECTION:
6623 error ("%H%<#pragma omp section%> may only be used in "
6624 "%<#pragma omp sections%> construct",
6625 &c_parser_peek_token (parser)->location);
6626 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6627 return false;
6629 case PRAGMA_GCC_PCH_PREPROCESS:
6630 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6631 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6632 return false;
6634 default:
6635 if (id < PRAGMA_FIRST_EXTERNAL)
6637 if (context == pragma_external)
6639 bad_stmt:
6640 c_parser_error (parser, "expected declaration specifiers");
6641 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6642 return false;
6644 c_parser_omp_construct (parser);
6645 return true;
6647 break;
6650 c_parser_consume_pragma (parser);
6651 c_invoke_pragma_handler (id);
6653 /* Skip to EOL, but suppress any error message. Those will have been
6654 generated by the handler routine through calling error, as opposed
6655 to calling c_parser_error. */
6656 parser->error = true;
6657 c_parser_skip_to_pragma_eol (parser);
6659 return false;
6662 /* The interface the pragma parsers have to the lexer. */
6664 enum cpp_ttype
6665 pragma_lex (tree *value)
6667 c_token *tok = c_parser_peek_token (the_parser);
6668 enum cpp_ttype ret = tok->type;
6670 *value = tok->value;
6671 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6672 ret = CPP_EOF;
6673 else
6675 if (ret == CPP_KEYWORD)
6676 ret = CPP_NAME;
6677 c_parser_consume_token (the_parser);
6680 return ret;
6683 static void
6684 c_parser_pragma_pch_preprocess (c_parser *parser)
6686 tree name = NULL;
6688 c_parser_consume_pragma (parser);
6689 if (c_parser_next_token_is (parser, CPP_STRING))
6691 name = c_parser_peek_token (parser)->value;
6692 c_parser_consume_token (parser);
6694 else
6695 c_parser_error (parser, "expected string literal");
6696 c_parser_skip_to_pragma_eol (parser);
6698 if (name)
6699 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6702 /* OpenMP 2.5 parsing routines. */
6704 /* Returns name of the next clause.
6705 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6706 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6707 returned and the token is consumed. */
6709 static pragma_omp_clause
6710 c_parser_omp_clause_name (c_parser *parser)
6712 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6714 if (c_parser_next_token_is_keyword (parser, RID_IF))
6715 result = PRAGMA_OMP_CLAUSE_IF;
6716 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6717 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6718 else if (c_parser_next_token_is (parser, CPP_NAME))
6720 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6722 switch (p[0])
6724 case 'c':
6725 if (!strcmp ("copyin", p))
6726 result = PRAGMA_OMP_CLAUSE_COPYIN;
6727 else if (!strcmp ("copyprivate", p))
6728 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6729 break;
6730 case 'f':
6731 if (!strcmp ("firstprivate", p))
6732 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6733 break;
6734 case 'l':
6735 if (!strcmp ("lastprivate", p))
6736 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6737 break;
6738 case 'n':
6739 if (!strcmp ("nowait", p))
6740 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6741 else if (!strcmp ("num_threads", p))
6742 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6743 break;
6744 case 'o':
6745 if (!strcmp ("ordered", p))
6746 result = PRAGMA_OMP_CLAUSE_ORDERED;
6747 break;
6748 case 'p':
6749 if (!strcmp ("private", p))
6750 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6751 break;
6752 case 'r':
6753 if (!strcmp ("reduction", p))
6754 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6755 break;
6756 case 's':
6757 if (!strcmp ("schedule", p))
6758 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6759 else if (!strcmp ("shared", p))
6760 result = PRAGMA_OMP_CLAUSE_SHARED;
6761 break;
6765 if (result != PRAGMA_OMP_CLAUSE_NONE)
6766 c_parser_consume_token (parser);
6768 return result;
6771 /* Validate that a clause of the given type does not already exist. */
6773 static void
6774 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6776 tree c;
6778 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6779 if (OMP_CLAUSE_CODE (c) == code)
6781 error ("too many %qs clauses", name);
6782 break;
6786 /* OpenMP 2.5:
6787 variable-list:
6788 identifier
6789 variable-list , identifier
6791 If KIND is nonzero, create the appropriate node and install the decl
6792 in OMP_CLAUSE_DECL and add the node to the head of the list.
6794 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6795 return the list created. */
6797 static tree
6798 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6799 tree list)
6801 if (c_parser_next_token_is_not (parser, CPP_NAME)
6802 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6803 c_parser_error (parser, "expected identifier");
6805 while (c_parser_next_token_is (parser, CPP_NAME)
6806 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6808 tree t = lookup_name (c_parser_peek_token (parser)->value);
6810 if (t == NULL_TREE)
6811 undeclared_variable (c_parser_peek_token (parser)->value,
6812 c_parser_peek_token (parser)->location);
6813 else if (t == error_mark_node)
6815 else if (kind != 0)
6817 tree u = build_omp_clause (kind);
6818 OMP_CLAUSE_DECL (u) = t;
6819 OMP_CLAUSE_CHAIN (u) = list;
6820 list = u;
6822 else
6823 list = tree_cons (t, NULL_TREE, list);
6825 c_parser_consume_token (parser);
6827 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6828 break;
6830 c_parser_consume_token (parser);
6833 return list;
6836 /* Similarly, but expect leading and trailing parenthesis. This is a very
6837 common case for omp clauses. */
6839 static tree
6840 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6842 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6844 list = c_parser_omp_variable_list (parser, kind, list);
6845 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6847 return list;
6850 /* OpenMP 2.5:
6851 copyin ( variable-list ) */
6853 static tree
6854 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6856 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6859 /* OpenMP 2.5:
6860 copyprivate ( variable-list ) */
6862 static tree
6863 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6865 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6868 /* OpenMP 2.5:
6869 default ( shared | none ) */
6871 static tree
6872 c_parser_omp_clause_default (c_parser *parser, tree list)
6874 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6875 tree c;
6877 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6878 return list;
6879 if (c_parser_next_token_is (parser, CPP_NAME))
6881 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6883 switch (p[0])
6885 case 'n':
6886 if (strcmp ("none", p) != 0)
6887 goto invalid_kind;
6888 kind = OMP_CLAUSE_DEFAULT_NONE;
6889 break;
6891 case 's':
6892 if (strcmp ("shared", p) != 0)
6893 goto invalid_kind;
6894 kind = OMP_CLAUSE_DEFAULT_SHARED;
6895 break;
6897 default:
6898 goto invalid_kind;
6901 c_parser_consume_token (parser);
6903 else
6905 invalid_kind:
6906 c_parser_error (parser, "expected %<none%> or %<shared%>");
6908 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6910 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6911 return list;
6913 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6914 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6915 OMP_CLAUSE_CHAIN (c) = list;
6916 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6918 return c;
6921 /* OpenMP 2.5:
6922 firstprivate ( variable-list ) */
6924 static tree
6925 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6927 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6930 /* OpenMP 2.5:
6931 if ( expression ) */
6933 static tree
6934 c_parser_omp_clause_if (c_parser *parser, tree list)
6936 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6938 tree t = c_parser_paren_condition (parser);
6939 tree c;
6941 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6943 c = build_omp_clause (OMP_CLAUSE_IF);
6944 OMP_CLAUSE_IF_EXPR (c) = t;
6945 OMP_CLAUSE_CHAIN (c) = list;
6946 list = c;
6948 else
6949 c_parser_error (parser, "expected %<(%>");
6951 return list;
6954 /* OpenMP 2.5:
6955 lastprivate ( variable-list ) */
6957 static tree
6958 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6960 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6963 /* OpenMP 2.5:
6964 nowait */
6966 static tree
6967 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6969 tree c;
6971 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6973 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6974 OMP_CLAUSE_CHAIN (c) = list;
6975 return c;
6978 /* OpenMP 2.5:
6979 num_threads ( expression ) */
6981 static tree
6982 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6984 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6986 location_t expr_loc = c_parser_peek_token (parser)->location;
6987 tree c, t = c_parser_expression (parser).value;
6989 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6991 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6993 c_parser_error (parser, "expected integer expression");
6994 return list;
6997 /* Attempt to statically determine when the number isn't positive. */
6998 c = fold_build2 (LE_EXPR, boolean_type_node, t,
6999 build_int_cst (TREE_TYPE (t), 0));
7000 if (c == boolean_true_node)
7002 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7003 t = integer_one_node;
7006 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7008 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7009 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7010 OMP_CLAUSE_CHAIN (c) = list;
7011 list = c;
7014 return list;
7017 /* OpenMP 2.5:
7018 ordered */
7020 static tree
7021 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7023 tree c;
7025 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7027 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7028 OMP_CLAUSE_CHAIN (c) = list;
7029 return c;
7032 /* OpenMP 2.5:
7033 private ( variable-list ) */
7035 static tree
7036 c_parser_omp_clause_private (c_parser *parser, tree list)
7038 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7041 /* OpenMP 2.5:
7042 reduction ( reduction-operator : variable-list )
7044 reduction-operator:
7045 One of: + * - & ^ | && || */
7047 static tree
7048 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7050 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7052 enum tree_code code;
7054 switch (c_parser_peek_token (parser)->type)
7056 case CPP_PLUS:
7057 code = PLUS_EXPR;
7058 break;
7059 case CPP_MULT:
7060 code = MULT_EXPR;
7061 break;
7062 case CPP_MINUS:
7063 code = MINUS_EXPR;
7064 break;
7065 case CPP_AND:
7066 code = BIT_AND_EXPR;
7067 break;
7068 case CPP_XOR:
7069 code = BIT_XOR_EXPR;
7070 break;
7071 case CPP_OR:
7072 code = BIT_IOR_EXPR;
7073 break;
7074 case CPP_AND_AND:
7075 code = TRUTH_ANDIF_EXPR;
7076 break;
7077 case CPP_OR_OR:
7078 code = TRUTH_ORIF_EXPR;
7079 break;
7080 default:
7081 c_parser_error (parser,
7082 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7083 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7084 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7085 return list;
7087 c_parser_consume_token (parser);
7088 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7090 tree nl, c;
7092 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7093 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7094 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7096 list = nl;
7098 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7100 return list;
7103 /* OpenMP 2.5:
7104 schedule ( schedule-kind )
7105 schedule ( schedule-kind , expression )
7107 schedule-kind:
7108 static | dynamic | guided | runtime
7111 static tree
7112 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7114 tree c, t;
7116 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7117 return list;
7119 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7121 if (c_parser_next_token_is (parser, CPP_NAME))
7123 tree kind = c_parser_peek_token (parser)->value;
7124 const char *p = IDENTIFIER_POINTER (kind);
7126 switch (p[0])
7128 case 'd':
7129 if (strcmp ("dynamic", p) != 0)
7130 goto invalid_kind;
7131 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7132 break;
7134 case 'g':
7135 if (strcmp ("guided", p) != 0)
7136 goto invalid_kind;
7137 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7138 break;
7140 case 'r':
7141 if (strcmp ("runtime", p) != 0)
7142 goto invalid_kind;
7143 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7144 break;
7146 default:
7147 goto invalid_kind;
7150 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7151 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7152 else
7153 goto invalid_kind;
7155 c_parser_consume_token (parser);
7156 if (c_parser_next_token_is (parser, CPP_COMMA))
7158 location_t here;
7159 c_parser_consume_token (parser);
7161 here = c_parser_peek_token (parser)->location;
7162 t = c_parser_expr_no_commas (parser, NULL).value;
7164 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7165 error ("%Hschedule %<runtime%> does not take "
7166 "a %<chunk_size%> parameter", &here);
7167 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7168 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7169 else
7170 c_parser_error (parser, "expected integer expression");
7172 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7174 else
7175 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7176 "expected %<,%> or %<)%>");
7178 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7179 OMP_CLAUSE_CHAIN (c) = list;
7180 return c;
7182 invalid_kind:
7183 c_parser_error (parser, "invalid schedule kind");
7184 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7185 return list;
7188 /* OpenMP 2.5:
7189 shared ( variable-list ) */
7191 static tree
7192 c_parser_omp_clause_shared (c_parser *parser, tree list)
7194 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7197 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7198 is a bitmask in MASK. Return the list of clauses found; the result
7199 of clause default goes in *pdefault. */
7201 static tree
7202 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7203 const char *where)
7205 tree clauses = NULL;
7207 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7209 location_t here = c_parser_peek_token (parser)->location;
7210 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7211 const char *c_name;
7212 tree prev = clauses;
7214 switch (c_kind)
7216 case PRAGMA_OMP_CLAUSE_COPYIN:
7217 clauses = c_parser_omp_clause_copyin (parser, clauses);
7218 c_name = "copyin";
7219 break;
7220 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7221 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7222 c_name = "copyprivate";
7223 break;
7224 case PRAGMA_OMP_CLAUSE_DEFAULT:
7225 clauses = c_parser_omp_clause_default (parser, clauses);
7226 c_name = "default";
7227 break;
7228 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7229 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7230 c_name = "firstprivate";
7231 break;
7232 case PRAGMA_OMP_CLAUSE_IF:
7233 clauses = c_parser_omp_clause_if (parser, clauses);
7234 c_name = "if";
7235 break;
7236 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7237 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7238 c_name = "lastprivate";
7239 break;
7240 case PRAGMA_OMP_CLAUSE_NOWAIT:
7241 clauses = c_parser_omp_clause_nowait (parser, clauses);
7242 c_name = "nowait";
7243 break;
7244 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7245 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7246 c_name = "num_threads";
7247 break;
7248 case PRAGMA_OMP_CLAUSE_ORDERED:
7249 clauses = c_parser_omp_clause_ordered (parser, clauses);
7250 c_name = "ordered";
7251 break;
7252 case PRAGMA_OMP_CLAUSE_PRIVATE:
7253 clauses = c_parser_omp_clause_private (parser, clauses);
7254 c_name = "private";
7255 break;
7256 case PRAGMA_OMP_CLAUSE_REDUCTION:
7257 clauses = c_parser_omp_clause_reduction (parser, clauses);
7258 c_name = "reduction";
7259 break;
7260 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7261 clauses = c_parser_omp_clause_schedule (parser, clauses);
7262 c_name = "schedule";
7263 break;
7264 case PRAGMA_OMP_CLAUSE_SHARED:
7265 clauses = c_parser_omp_clause_shared (parser, clauses);
7266 c_name = "shared";
7267 break;
7268 default:
7269 c_parser_error (parser, "expected %<#pragma omp%> clause");
7270 goto saw_error;
7273 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7275 /* Remove the invalid clause(s) from the list to avoid
7276 confusing the rest of the compiler. */
7277 clauses = prev;
7278 error ("%H%qs is not valid for %qs", &here, c_name, where);
7282 saw_error:
7283 c_parser_skip_to_pragma_eol (parser);
7285 return c_finish_omp_clauses (clauses);
7288 /* OpenMP 2.5:
7289 structured-block:
7290 statement
7292 In practice, we're also interested in adding the statement to an
7293 outer node. So it is convenient if we work around the fact that
7294 c_parser_statement calls add_stmt. */
7296 static tree
7297 c_parser_omp_structured_block (c_parser *parser)
7299 tree stmt = push_stmt_list ();
7300 c_parser_statement (parser);
7301 return pop_stmt_list (stmt);
7304 /* OpenMP 2.5:
7305 # pragma omp atomic new-line
7306 expression-stmt
7308 expression-stmt:
7309 x binop= expr | x++ | ++x | x-- | --x
7310 binop:
7311 +, *, -, /, &, ^, |, <<, >>
7313 where x is an lvalue expression with scalar type. */
7315 static void
7316 c_parser_omp_atomic (c_parser *parser)
7318 tree lhs, rhs;
7319 tree stmt;
7320 enum tree_code code;
7322 c_parser_skip_to_pragma_eol (parser);
7324 lhs = c_parser_unary_expression (parser).value;
7325 switch (TREE_CODE (lhs))
7327 case ERROR_MARK:
7328 saw_error:
7329 c_parser_skip_to_end_of_block_or_statement (parser);
7330 return;
7332 case PREINCREMENT_EXPR:
7333 case POSTINCREMENT_EXPR:
7334 lhs = TREE_OPERAND (lhs, 0);
7335 code = PLUS_EXPR;
7336 rhs = integer_one_node;
7337 break;
7339 case PREDECREMENT_EXPR:
7340 case POSTDECREMENT_EXPR:
7341 lhs = TREE_OPERAND (lhs, 0);
7342 code = MINUS_EXPR;
7343 rhs = integer_one_node;
7344 break;
7346 default:
7347 switch (c_parser_peek_token (parser)->type)
7349 case CPP_MULT_EQ:
7350 code = MULT_EXPR;
7351 break;
7352 case CPP_DIV_EQ:
7353 code = TRUNC_DIV_EXPR;
7354 break;
7355 case CPP_PLUS_EQ:
7356 code = PLUS_EXPR;
7357 break;
7358 case CPP_MINUS_EQ:
7359 code = MINUS_EXPR;
7360 break;
7361 case CPP_LSHIFT_EQ:
7362 code = LSHIFT_EXPR;
7363 break;
7364 case CPP_RSHIFT_EQ:
7365 code = RSHIFT_EXPR;
7366 break;
7367 case CPP_AND_EQ:
7368 code = BIT_AND_EXPR;
7369 break;
7370 case CPP_OR_EQ:
7371 code = BIT_IOR_EXPR;
7372 break;
7373 case CPP_XOR_EQ:
7374 code = BIT_XOR_EXPR;
7375 break;
7376 default:
7377 c_parser_error (parser,
7378 "invalid operator for %<#pragma omp atomic%>");
7379 goto saw_error;
7382 c_parser_consume_token (parser);
7383 rhs = c_parser_expression (parser).value;
7384 break;
7386 stmt = c_finish_omp_atomic (code, lhs, rhs);
7387 if (stmt != error_mark_node)
7388 add_stmt (stmt);
7389 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7393 /* OpenMP 2.5:
7394 # pragma omp barrier new-line
7397 static void
7398 c_parser_omp_barrier (c_parser *parser)
7400 c_parser_consume_pragma (parser);
7401 c_parser_skip_to_pragma_eol (parser);
7403 c_finish_omp_barrier ();
7406 /* OpenMP 2.5:
7407 # pragma omp critical [(name)] new-line
7408 structured-block
7411 static tree
7412 c_parser_omp_critical (c_parser *parser)
7414 tree stmt, name = NULL;
7416 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7418 c_parser_consume_token (parser);
7419 if (c_parser_next_token_is (parser, CPP_NAME))
7421 name = c_parser_peek_token (parser)->value;
7422 c_parser_consume_token (parser);
7423 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7425 else
7426 c_parser_error (parser, "expected identifier");
7428 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7429 c_parser_error (parser, "expected %<(%> or end of line");
7430 c_parser_skip_to_pragma_eol (parser);
7432 stmt = c_parser_omp_structured_block (parser);
7433 return c_finish_omp_critical (stmt, name);
7436 /* OpenMP 2.5:
7437 # pragma omp flush flush-vars[opt] new-line
7439 flush-vars:
7440 ( variable-list ) */
7442 static void
7443 c_parser_omp_flush (c_parser *parser)
7445 c_parser_consume_pragma (parser);
7446 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7447 c_parser_omp_var_list_parens (parser, 0, NULL);
7448 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7449 c_parser_error (parser, "expected %<(%> or end of line");
7450 c_parser_skip_to_pragma_eol (parser);
7452 c_finish_omp_flush ();
7455 /* Parse the restricted form of the for statment allowed by OpenMP.
7456 The real trick here is to determine the loop control variable early
7457 so that we can push a new decl if necessary to make it private. */
7459 static tree
7460 c_parser_omp_for_loop (c_parser *parser)
7462 tree decl, cond, incr, save_break, save_cont, body, init;
7463 location_t loc;
7465 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7467 c_parser_error (parser, "for statement expected");
7468 return NULL;
7470 loc = c_parser_peek_token (parser)->location;
7471 c_parser_consume_token (parser);
7473 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7474 return NULL;
7476 /* Parse the initialization declaration or expression. */
7477 if (c_parser_next_token_starts_declspecs (parser))
7479 c_parser_declaration_or_fndef (parser, true, true, true, true);
7480 decl = check_for_loop_decls ();
7481 if (decl == NULL)
7482 goto error_init;
7483 init = decl;
7485 else if (c_parser_next_token_is (parser, CPP_NAME)
7486 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7488 decl = c_parser_postfix_expression (parser).value;
7490 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7492 init = c_parser_expr_no_commas (parser, NULL).value;
7493 init = build_modify_expr (decl, NOP_EXPR, init);
7494 init = c_process_expr_stmt (init);
7496 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7498 else
7499 goto error_init;
7501 /* Parse the loop condition. */
7502 cond = NULL_TREE;
7503 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7505 cond = c_parser_expression_conv (parser).value;
7506 cond = c_objc_common_truthvalue_conversion (cond);
7507 if (CAN_HAVE_LOCATION_P (cond))
7508 SET_EXPR_LOCATION (cond, input_location);
7510 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7512 /* Parse the increment expression. */
7513 incr = NULL_TREE;
7514 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7515 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7516 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7518 parse_body:
7519 save_break = c_break_label;
7520 c_break_label = size_one_node;
7521 save_cont = c_cont_label;
7522 c_cont_label = NULL_TREE;
7523 body = push_stmt_list ();
7525 add_stmt (c_parser_c99_block_statement (parser));
7526 if (c_cont_label)
7527 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7529 body = pop_stmt_list (body);
7530 c_break_label = save_break;
7531 c_cont_label = save_cont;
7533 /* Only bother calling c_finish_omp_for if we havn't already generated
7534 an error from the initialization parsing. */
7535 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7536 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7537 return NULL;
7539 error_init:
7540 c_parser_error (parser, "expected iteration declaration or initialization");
7541 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7542 decl = init = cond = incr = NULL_TREE;
7543 goto parse_body;
7546 /* OpenMP 2.5:
7547 #pragma omp for for-clause[optseq] new-line
7548 for-loop
7551 #define OMP_FOR_CLAUSE_MASK \
7552 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7553 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7554 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7555 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7556 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7557 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7558 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7560 static tree
7561 c_parser_omp_for (c_parser *parser)
7563 tree block, clauses, ret;
7565 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7566 "#pragma omp for");
7568 block = c_begin_compound_stmt (true);
7569 ret = c_parser_omp_for_loop (parser);
7570 if (ret)
7571 OMP_FOR_CLAUSES (ret) = clauses;
7572 block = c_end_compound_stmt (block, true);
7573 add_stmt (block);
7575 return ret;
7578 /* OpenMP 2.5:
7579 # pragma omp master new-line
7580 structured-block
7583 static tree
7584 c_parser_omp_master (c_parser *parser)
7586 c_parser_skip_to_pragma_eol (parser);
7587 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7590 /* OpenMP 2.5:
7591 # pragma omp ordered new-line
7592 structured-block
7595 static tree
7596 c_parser_omp_ordered (c_parser *parser)
7598 c_parser_skip_to_pragma_eol (parser);
7599 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7602 /* OpenMP 2.5:
7604 section-scope:
7605 { section-sequence }
7607 section-sequence:
7608 section-directive[opt] structured-block
7609 section-sequence section-directive structured-block */
7611 static tree
7612 c_parser_omp_sections_scope (c_parser *parser)
7614 tree stmt, substmt;
7615 bool error_suppress = false;
7616 location_t loc;
7618 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7620 /* Avoid skipping until the end of the block. */
7621 parser->error = false;
7622 return NULL_TREE;
7625 stmt = push_stmt_list ();
7627 loc = c_parser_peek_token (parser)->location;
7628 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7630 substmt = push_stmt_list ();
7632 while (1)
7634 c_parser_statement (parser);
7636 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7637 break;
7638 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7639 break;
7640 if (c_parser_next_token_is (parser, CPP_EOF))
7641 break;
7644 substmt = pop_stmt_list (substmt);
7645 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7646 SET_EXPR_LOCATION (substmt, loc);
7647 add_stmt (substmt);
7650 while (1)
7652 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7653 break;
7654 if (c_parser_next_token_is (parser, CPP_EOF))
7655 break;
7657 loc = c_parser_peek_token (parser)->location;
7658 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7660 c_parser_consume_pragma (parser);
7661 c_parser_skip_to_pragma_eol (parser);
7662 error_suppress = false;
7664 else if (!error_suppress)
7666 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7667 &loc);
7668 error_suppress = true;
7671 substmt = c_parser_omp_structured_block (parser);
7672 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7673 SET_EXPR_LOCATION (substmt, loc);
7674 add_stmt (substmt);
7676 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7677 "expected %<#pragma omp section%> or %<}%>");
7679 substmt = pop_stmt_list (stmt);
7681 stmt = make_node (OMP_SECTIONS);
7682 TREE_TYPE (stmt) = void_type_node;
7683 OMP_SECTIONS_BODY (stmt) = substmt;
7685 return add_stmt (stmt);
7688 /* OpenMP 2.5:
7689 # pragma omp sections sections-clause[optseq] newline
7690 sections-scope
7693 #define OMP_SECTIONS_CLAUSE_MASK \
7694 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7695 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7696 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7697 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7698 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7700 static tree
7701 c_parser_omp_sections (c_parser *parser)
7703 tree block, clauses, ret;
7705 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7706 "#pragma omp sections");
7708 block = c_begin_compound_stmt (true);
7709 ret = c_parser_omp_sections_scope (parser);
7710 if (ret)
7711 OMP_SECTIONS_CLAUSES (ret) = clauses;
7712 block = c_end_compound_stmt (block, true);
7713 add_stmt (block);
7715 return ret;
7718 /* OpenMP 2.5:
7719 # pragma parallel parallel-clause new-line
7720 # pragma parallel for parallel-for-clause new-line
7721 # pragma parallel sections parallel-sections-clause new-line
7724 #define OMP_PARALLEL_CLAUSE_MASK \
7725 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7726 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7727 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7728 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7729 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7730 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7731 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7732 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7734 static tree
7735 c_parser_omp_parallel (c_parser *parser)
7737 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7738 const char *p_name = "#pragma omp parallel";
7739 tree stmt, clauses, par_clause, ws_clause, block;
7740 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7742 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7744 c_parser_consume_token (parser);
7745 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7746 p_name = "#pragma omp parallel for";
7747 mask |= OMP_FOR_CLAUSE_MASK;
7748 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7750 else if (c_parser_next_token_is (parser, CPP_NAME))
7752 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7753 if (strcmp (p, "sections") == 0)
7755 c_parser_consume_token (parser);
7756 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7757 p_name = "#pragma omp parallel sections";
7758 mask |= OMP_SECTIONS_CLAUSE_MASK;
7759 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7763 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7765 switch (p_kind)
7767 case PRAGMA_OMP_PARALLEL:
7768 block = c_begin_omp_parallel ();
7769 c_parser_statement (parser);
7770 stmt = c_finish_omp_parallel (clauses, block);
7771 break;
7773 case PRAGMA_OMP_PARALLEL_FOR:
7774 block = c_begin_omp_parallel ();
7775 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7776 stmt = c_parser_omp_for_loop (parser);
7777 if (stmt)
7778 OMP_FOR_CLAUSES (stmt) = ws_clause;
7779 stmt = c_finish_omp_parallel (par_clause, block);
7780 OMP_PARALLEL_COMBINED (stmt) = 1;
7781 break;
7783 case PRAGMA_OMP_PARALLEL_SECTIONS:
7784 block = c_begin_omp_parallel ();
7785 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7786 stmt = c_parser_omp_sections_scope (parser);
7787 if (stmt)
7788 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7789 stmt = c_finish_omp_parallel (par_clause, block);
7790 OMP_PARALLEL_COMBINED (stmt) = 1;
7791 break;
7793 default:
7794 gcc_unreachable ();
7797 return stmt;
7800 /* OpenMP 2.5:
7801 # pragma omp single single-clause[optseq] new-line
7802 structured-block
7805 #define OMP_SINGLE_CLAUSE_MASK \
7806 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7807 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7808 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7809 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7811 static tree
7812 c_parser_omp_single (c_parser *parser)
7814 tree stmt = make_node (OMP_SINGLE);
7815 TREE_TYPE (stmt) = void_type_node;
7817 OMP_SINGLE_CLAUSES (stmt)
7818 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7819 "#pragma omp single");
7820 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7822 return add_stmt (stmt);
7826 /* Main entry point to parsing most OpenMP pragmas. */
7828 static void
7829 c_parser_omp_construct (c_parser *parser)
7831 enum pragma_kind p_kind;
7832 location_t loc;
7833 tree stmt;
7835 loc = c_parser_peek_token (parser)->location;
7836 p_kind = c_parser_peek_token (parser)->pragma_kind;
7837 c_parser_consume_pragma (parser);
7839 /* For all constructs below except #pragma omp atomic
7840 MUST_NOT_THROW catch handlers are needed when exceptions
7841 are enabled. */
7842 if (p_kind != PRAGMA_OMP_ATOMIC)
7843 c_maybe_initialize_eh ();
7845 switch (p_kind)
7847 case PRAGMA_OMP_ATOMIC:
7848 c_parser_omp_atomic (parser);
7849 return;
7850 case PRAGMA_OMP_CRITICAL:
7851 stmt = c_parser_omp_critical (parser);
7852 break;
7853 case PRAGMA_OMP_FOR:
7854 stmt = c_parser_omp_for (parser);
7855 break;
7856 case PRAGMA_OMP_MASTER:
7857 stmt = c_parser_omp_master (parser);
7858 break;
7859 case PRAGMA_OMP_ORDERED:
7860 stmt = c_parser_omp_ordered (parser);
7861 break;
7862 case PRAGMA_OMP_PARALLEL:
7863 stmt = c_parser_omp_parallel (parser);
7864 break;
7865 case PRAGMA_OMP_SECTIONS:
7866 stmt = c_parser_omp_sections (parser);
7867 break;
7868 case PRAGMA_OMP_SINGLE:
7869 stmt = c_parser_omp_single (parser);
7870 break;
7871 default:
7872 gcc_unreachable ();
7875 if (stmt)
7876 SET_EXPR_LOCATION (stmt, loc);
7880 /* OpenMP 2.5:
7881 # pragma omp threadprivate (variable-list) */
7883 static void
7884 c_parser_omp_threadprivate (c_parser *parser)
7886 tree vars, t;
7888 c_parser_consume_pragma (parser);
7889 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7891 /* Mark every variable in VARS to be assigned thread local storage. */
7892 for (t = vars; t; t = TREE_CHAIN (t))
7894 tree v = TREE_PURPOSE (t);
7896 /* If V had already been marked threadprivate, it doesn't matter
7897 whether it had been used prior to this point. */
7898 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7899 error ("%qE declared %<threadprivate%> after first use", v);
7900 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7901 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7902 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7903 error ("%<threadprivate%> %qE has incomplete type", v);
7904 else
7906 if (! DECL_THREAD_LOCAL_P (v))
7908 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7909 /* If rtl has been already set for this var, call
7910 make_decl_rtl once again, so that encode_section_info
7911 has a chance to look at the new decl flags. */
7912 if (DECL_RTL_SET_P (v))
7913 make_decl_rtl (v);
7915 C_DECL_THREADPRIVATE_P (v) = 1;
7919 c_parser_skip_to_pragma_eol (parser);
7923 /* Parse a single source file. */
7925 void
7926 c_parse_file (void)
7928 /* Use local storage to begin. If the first token is a pragma, parse it.
7929 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7930 which will cause garbage collection. */
7931 c_parser tparser;
7933 memset (&tparser, 0, sizeof tparser);
7934 the_parser = &tparser;
7936 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7937 c_parser_pragma_pch_preprocess (&tparser);
7939 the_parser = GGC_NEW (c_parser);
7940 *the_parser = tparser;
7942 c_parser_translation_unit (the_parser);
7943 the_parser = NULL;
7946 #include "gt-c-parser.h"