1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* The reserved keyword table. */
66 ENUM_BITFIELD(rid) rid : 16;
67 unsigned int disable : 16;
70 /* Disable mask. Keywords are disabled if (reswords[i].disable &
72 #define D_C89 0x01 /* not in C89 */
73 #define D_EXT 0x02 /* GCC extension */
74 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
75 #define D_OBJC 0x08 /* Objective C only */
77 static const struct resword reswords[] =
79 { "_Bool", RID_BOOL, 0 },
80 { "_Complex", RID_COMPLEX, 0 },
81 { "_Decimal32", RID_DFLOAT32, D_EXT },
82 { "_Decimal64", RID_DFLOAT64, D_EXT },
83 { "_Decimal128", RID_DFLOAT128, D_EXT },
84 { "_Fract", RID_FRACT, D_EXT },
85 { "_Accum", RID_ACCUM, D_EXT },
86 { "_Sat", RID_SAT, D_EXT },
87 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
88 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
89 { "__alignof", RID_ALIGNOF, 0 },
90 { "__alignof__", RID_ALIGNOF, 0 },
91 { "__asm", RID_ASM, 0 },
92 { "__asm__", RID_ASM, 0 },
93 { "__attribute", RID_ATTRIBUTE, 0 },
94 { "__attribute__", RID_ATTRIBUTE, 0 },
95 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
96 { "__builtin_offsetof", RID_OFFSETOF, 0 },
97 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
98 { "__builtin_va_arg", RID_VA_ARG, 0 },
99 { "__complex", RID_COMPLEX, 0 },
100 { "__complex__", RID_COMPLEX, 0 },
101 { "__const", RID_CONST, 0 },
102 { "__const__", RID_CONST, 0 },
103 { "__extension__", RID_EXTENSION, 0 },
104 { "__func__", RID_C99_FUNCTION_NAME, 0 },
105 { "__imag", RID_IMAGPART, 0 },
106 { "__imag__", RID_IMAGPART, 0 },
107 { "__inline", RID_INLINE, 0 },
108 { "__inline__", RID_INLINE, 0 },
109 { "__label__", RID_LABEL, 0 },
110 { "__real", RID_REALPART, 0 },
111 { "__real__", RID_REALPART, 0 },
112 { "__restrict", RID_RESTRICT, 0 },
113 { "__restrict__", RID_RESTRICT, 0 },
114 { "__signed", RID_SIGNED, 0 },
115 { "__signed__", RID_SIGNED, 0 },
116 { "__thread", RID_THREAD, 0 },
117 { "__typeof", RID_TYPEOF, 0 },
118 { "__typeof__", RID_TYPEOF, 0 },
119 { "__volatile", RID_VOLATILE, 0 },
120 { "__volatile__", RID_VOLATILE, 0 },
121 { "asm", RID_ASM, D_EXT },
122 { "auto", RID_AUTO, 0 },
123 { "break", RID_BREAK, 0 },
124 { "case", RID_CASE, 0 },
125 { "char", RID_CHAR, 0 },
126 { "const", RID_CONST, 0 },
127 { "continue", RID_CONTINUE, 0 },
128 { "default", RID_DEFAULT, 0 },
130 { "double", RID_DOUBLE, 0 },
131 { "else", RID_ELSE, 0 },
132 { "enum", RID_ENUM, 0 },
133 { "extern", RID_EXTERN, 0 },
134 { "float", RID_FLOAT, 0 },
135 { "for", RID_FOR, 0 },
136 { "goto", RID_GOTO, 0 },
138 { "inline", RID_INLINE, D_EXT89 },
139 { "int", RID_INT, 0 },
140 { "long", RID_LONG, 0 },
141 { "register", RID_REGISTER, 0 },
142 { "restrict", RID_RESTRICT, D_C89 },
143 { "return", RID_RETURN, 0 },
144 { "short", RID_SHORT, 0 },
145 { "signed", RID_SIGNED, 0 },
146 { "sizeof", RID_SIZEOF, 0 },
147 { "static", RID_STATIC, 0 },
148 { "struct", RID_STRUCT, 0 },
149 { "switch", RID_SWITCH, 0 },
150 { "typedef", RID_TYPEDEF, 0 },
151 { "typeof", RID_TYPEOF, D_EXT },
152 { "union", RID_UNION, 0 },
153 { "unsigned", RID_UNSIGNED, 0 },
154 { "void", RID_VOID, 0 },
155 { "volatile", RID_VOLATILE, 0 },
156 { "while", RID_WHILE, 0 },
157 /* These Objective-C keywords are recognized only immediately after
159 { "class", RID_AT_CLASS, D_OBJC },
160 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
161 { "defs", RID_AT_DEFS, D_OBJC },
162 { "encode", RID_AT_ENCODE, D_OBJC },
163 { "end", RID_AT_END, D_OBJC },
164 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
165 { "interface", RID_AT_INTERFACE, D_OBJC },
166 { "private", RID_AT_PRIVATE, D_OBJC },
167 { "protected", RID_AT_PROTECTED, D_OBJC },
168 { "protocol", RID_AT_PROTOCOL, D_OBJC },
169 { "public", RID_AT_PUBLIC, D_OBJC },
170 { "selector", RID_AT_SELECTOR, D_OBJC },
171 { "throw", RID_AT_THROW, D_OBJC },
172 { "try", RID_AT_TRY, D_OBJC },
173 { "catch", RID_AT_CATCH, D_OBJC },
174 { "finally", RID_AT_FINALLY, D_OBJC },
175 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
176 /* These are recognized only in protocol-qualifier context
178 { "bycopy", RID_BYCOPY, D_OBJC },
179 { "byref", RID_BYREF, D_OBJC },
180 { "in", RID_IN, D_OBJC },
181 { "inout", RID_INOUT, D_OBJC },
182 { "oneway", RID_ONEWAY, D_OBJC },
183 { "out", RID_OUT, D_OBJC },
185 #define N_reswords (sizeof reswords / sizeof (struct resword))
187 /* Initialization routine for this file. */
192 /* The only initialization required is of the reserved word
196 int mask = (flag_isoc99 ? 0 : D_C89)
197 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
199 if (!c_dialect_objc ())
202 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
203 for (i = 0; i < N_reswords; i++)
205 /* If a keyword is disabled, do not enter it into the table
206 and so create a canonical spelling that isn't a keyword. */
207 if (reswords[i].disable & mask)
210 id = get_identifier (reswords[i].word);
211 C_RID_CODE (id) = reswords[i].rid;
212 C_IS_RESERVED_WORD (id) = 1;
213 ridpointers [(int) reswords[i].rid] = id;
217 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
218 and the C parser. Unlike the C++ lexer, the parser structure
219 stores the lexer information instead of using a separate structure.
220 Identifiers are separated into ordinary identifiers, type names,
221 keywords and some other Objective-C types of identifiers, and some
222 look-ahead is maintained.
224 ??? It might be a good idea to lex the whole file up front (as for
225 C++). It would then be possible to share more of the C and C++
226 lexer code, if desired. */
228 /* The following local token type is used. */
231 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
233 /* More information about the type of a CPP_NAME token. */
234 typedef enum c_id_kind {
235 /* An ordinary identifier. */
237 /* An identifier declared as a typedef name. */
239 /* An identifier declared as an Objective-C class name. */
241 /* Not an identifier. */
245 /* A single C token after string literal concatenation and conversion
246 of preprocessing tokens to tokens. */
247 typedef struct c_token GTY (())
249 /* The kind of token. */
250 ENUM_BITFIELD (cpp_ttype) type : 8;
251 /* If this token is a CPP_NAME, this value indicates whether also
252 declared as some kind of type. Otherwise, it is C_ID_NONE. */
253 ENUM_BITFIELD (c_id_kind) id_kind : 8;
254 /* If this token is a keyword, this value indicates which keyword.
255 Otherwise, this value is RID_MAX. */
256 ENUM_BITFIELD (rid) keyword : 8;
257 /* If this token is a CPP_PRAGMA, this indicates the pragma that
258 was seen. Otherwise it is PRAGMA_NONE. */
259 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
260 /* True if this token is from a system header. */
261 BOOL_BITFIELD in_system_header : 1;
262 /* The value associated with this token, if any. */
264 /* The location at which this token was found. */
268 /* A parser structure recording information about the state and
269 context of parsing. Includes lexer information with up to two
270 tokens of look-ahead; more are not needed for C. */
271 typedef struct c_parser GTY(())
273 /* The look-ahead tokens. */
275 /* How many look-ahead tokens are available (0, 1 or 2). */
277 /* True if a syntax error is being recovered from; false otherwise.
278 c_parser_error sets this flag. It should clear this flag when
279 enough tokens have been consumed to recover from the error. */
280 BOOL_BITFIELD error : 1;
281 /* True if we're processing a pragma, and shouldn't automatically
282 consume CPP_PRAGMA_EOL. */
283 BOOL_BITFIELD in_pragma : 1;
284 /* True if we're parsing the outermost block of an if statement. */
285 BOOL_BITFIELD in_if_block : 1;
286 /* True if we want to lex an untranslated string. */
287 BOOL_BITFIELD lex_untranslated_string : 1;
288 /* Objective-C specific parser/lexer information. */
289 BOOL_BITFIELD objc_pq_context : 1;
290 /* The following flag is needed to contextualize Objective-C lexical
291 analysis. In some cases (e.g., 'int NSObject;'), it is
292 undesirable to bind an identifier to an Objective-C class, even
293 if a class with that name exists. */
294 BOOL_BITFIELD objc_need_raw_identifier : 1;
298 /* The actual parser and external interface. ??? Does this need to be
299 garbage-collected? */
301 static GTY (()) c_parser *the_parser;
304 /* Read in and lex a single token, storing it in *TOKEN. */
307 c_lex_one_token (c_parser *parser, c_token *token)
309 timevar_push (TV_LEX);
311 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
312 (parser->lex_untranslated_string
313 ? C_LEX_STRING_NO_TRANSLATE : 0));
314 token->id_kind = C_ID_NONE;
315 token->keyword = RID_MAX;
316 token->pragma_kind = PRAGMA_NONE;
317 token->in_system_header = in_system_header;
325 bool objc_force_identifier = parser->objc_need_raw_identifier;
326 if (c_dialect_objc ())
327 parser->objc_need_raw_identifier = false;
329 if (C_IS_RESERVED_WORD (token->value))
331 enum rid rid_code = C_RID_CODE (token->value);
333 if (c_dialect_objc ())
335 if (!OBJC_IS_AT_KEYWORD (rid_code)
336 && (!OBJC_IS_PQ_KEYWORD (rid_code)
337 || parser->objc_pq_context))
339 /* Return the canonical spelling for this keyword. */
340 token->value = ridpointers[(int) rid_code];
341 token->type = CPP_KEYWORD;
342 token->keyword = rid_code;
348 /* Return the canonical spelling for this keyword. */
349 token->value = ridpointers[(int) rid_code];
350 token->type = CPP_KEYWORD;
351 token->keyword = rid_code;
356 decl = lookup_name (token->value);
359 if (TREE_CODE (decl) == TYPE_DECL)
361 token->id_kind = C_ID_TYPENAME;
365 else if (c_dialect_objc ())
367 tree objc_interface_decl = objc_is_class_name (token->value);
368 /* Objective-C class names are in the same namespace as
369 variables and typedefs, and hence are shadowed by local
371 if (objc_interface_decl
372 && (global_bindings_p ()
373 || (!objc_force_identifier && !decl)))
375 token->value = objc_interface_decl;
376 token->id_kind = C_ID_CLASSNAME;
380 token->id_kind = C_ID_ID;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token->type = CPP_KEYWORD;
386 token->keyword = C_RID_CODE (token->value);
390 case CPP_CLOSE_PAREN:
392 /* These tokens may affect the interpretation of any identifiers
393 following, if doing Objective-C. */
394 if (c_dialect_objc ())
395 parser->objc_need_raw_identifier = false;
398 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
399 token->pragma_kind = TREE_INT_CST_LOW (token->value);
405 timevar_pop (TV_LEX);
408 /* Return a pointer to the next token from PARSER, reading it in if
411 static inline c_token *
412 c_parser_peek_token (c_parser *parser)
414 if (parser->tokens_avail == 0)
416 c_lex_one_token (parser, &parser->tokens[0]);
417 parser->tokens_avail = 1;
419 return &parser->tokens[0];
422 /* Return true if the next token from PARSER has the indicated
426 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
428 return c_parser_peek_token (parser)->type == type;
431 /* Return true if the next token from PARSER does not have the
435 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
437 return !c_parser_next_token_is (parser, type);
440 /* Return true if the next token from PARSER is the indicated
444 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
446 return c_parser_peek_token (parser)->keyword == keyword;
449 /* Return true if TOKEN can start a type name,
452 c_token_starts_typename (c_token *token)
457 switch (token->id_kind)
464 gcc_assert (c_dialect_objc ());
470 switch (token->keyword)
502 if (c_dialect_objc ())
510 /* Return true if the next token from PARSER can start a type name,
513 c_parser_next_token_starts_typename (c_parser *parser)
515 c_token *token = c_parser_peek_token (parser);
516 return c_token_starts_typename (token);
519 /* Return true if TOKEN can start declaration specifiers, false
522 c_token_starts_declspecs (c_token *token)
527 switch (token->id_kind)
534 gcc_assert (c_dialect_objc ());
540 switch (token->keyword)
579 if (c_dialect_objc ())
587 /* Return true if the next token from PARSER can start declaration
588 specifiers, false otherwise. */
590 c_parser_next_token_starts_declspecs (c_parser *parser)
592 c_token *token = c_parser_peek_token (parser);
593 return c_token_starts_declspecs (token);
596 /* Return a pointer to the next-but-one token from PARSER, reading it
597 in if necessary. The next token is already read in. */
600 c_parser_peek_2nd_token (c_parser *parser)
602 if (parser->tokens_avail >= 2)
603 return &parser->tokens[1];
604 gcc_assert (parser->tokens_avail == 1);
605 gcc_assert (parser->tokens[0].type != CPP_EOF);
606 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
607 c_lex_one_token (parser, &parser->tokens[1]);
608 parser->tokens_avail = 2;
609 return &parser->tokens[1];
612 /* Consume the next token from PARSER. */
615 c_parser_consume_token (c_parser *parser)
617 gcc_assert (parser->tokens_avail >= 1);
618 gcc_assert (parser->tokens[0].type != CPP_EOF);
619 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
620 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
621 if (parser->tokens_avail == 2)
622 parser->tokens[0] = parser->tokens[1];
623 parser->tokens_avail--;
626 /* Expect the current token to be a #pragma. Consume it and remember
627 that we've begun parsing a pragma. */
630 c_parser_consume_pragma (c_parser *parser)
632 gcc_assert (!parser->in_pragma);
633 gcc_assert (parser->tokens_avail >= 1);
634 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
635 if (parser->tokens_avail == 2)
636 parser->tokens[0] = parser->tokens[1];
637 parser->tokens_avail--;
638 parser->in_pragma = true;
641 /* Update the globals input_location and in_system_header from
644 c_parser_set_source_position_from_token (c_token *token)
646 if (token->type != CPP_EOF)
648 input_location = token->location;
649 in_system_header = token->in_system_header;
653 /* Issue a diagnostic of the form
654 FILE:LINE: MESSAGE before TOKEN
655 where TOKEN is the next token in the input stream of PARSER.
656 MESSAGE (specified by the caller) is usually of the form "expected
659 Do not issue a diagnostic if still recovering from an error.
661 ??? This is taken from the C++ parser, but building up messages in
662 this way is not i18n-friendly and some other approach should be
666 c_parser_error (c_parser *parser, const char *gmsgid)
668 c_token *token = c_parser_peek_token (parser);
671 parser->error = true;
674 /* This diagnostic makes more sense if it is tagged to the line of
675 the token we just peeked at. */
676 c_parser_set_source_position_from_token (token);
677 c_parse_error (gmsgid,
678 /* Because c_parse_error does not understand
679 CPP_KEYWORD, keywords are treated like
681 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
685 /* If the next token is of the indicated TYPE, consume it. Otherwise,
686 issue the error MSGID. If MSGID is NULL then a message has already
687 been produced and no message will be produced this time. Returns
688 true if found, false otherwise. */
691 c_parser_require (c_parser *parser,
695 if (c_parser_next_token_is (parser, type))
697 c_parser_consume_token (parser);
702 c_parser_error (parser, msgid);
707 /* If the next token is the indicated keyword, consume it. Otherwise,
708 issue the error MSGID. Returns true if found, false otherwise. */
711 c_parser_require_keyword (c_parser *parser,
715 if (c_parser_next_token_is_keyword (parser, keyword))
717 c_parser_consume_token (parser);
722 c_parser_error (parser, msgid);
727 /* Like c_parser_require, except that tokens will be skipped until the
728 desired token is found. An error message is still produced if the
729 next token is not as expected. If MSGID is NULL then a message has
730 already been produced and no message will be produced this
734 c_parser_skip_until_found (c_parser *parser,
738 unsigned nesting_depth = 0;
740 if (c_parser_require (parser, type, msgid))
743 /* Skip tokens until the desired token is found. */
746 /* Peek at the next token. */
747 c_token *token = c_parser_peek_token (parser);
748 /* If we've reached the token we want, consume it and stop. */
749 if (token->type == type && !nesting_depth)
751 c_parser_consume_token (parser);
755 /* If we've run out of tokens, stop. */
756 if (token->type == CPP_EOF)
758 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
760 if (token->type == CPP_OPEN_BRACE
761 || token->type == CPP_OPEN_PAREN
762 || token->type == CPP_OPEN_SQUARE)
764 else if (token->type == CPP_CLOSE_BRACE
765 || token->type == CPP_CLOSE_PAREN
766 || token->type == CPP_CLOSE_SQUARE)
768 if (nesting_depth-- == 0)
771 /* Consume this token. */
772 c_parser_consume_token (parser);
774 parser->error = false;
777 /* Skip tokens until the end of a parameter is found, but do not
778 consume the comma, semicolon or closing delimiter. */
781 c_parser_skip_to_end_of_parameter (c_parser *parser)
783 unsigned nesting_depth = 0;
787 c_token *token = c_parser_peek_token (parser);
788 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
791 /* If we've run out of tokens, stop. */
792 if (token->type == CPP_EOF)
794 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
796 if (token->type == CPP_OPEN_BRACE
797 || token->type == CPP_OPEN_PAREN
798 || token->type == CPP_OPEN_SQUARE)
800 else if (token->type == CPP_CLOSE_BRACE
801 || token->type == CPP_CLOSE_PAREN
802 || token->type == CPP_CLOSE_SQUARE)
804 if (nesting_depth-- == 0)
807 /* Consume this token. */
808 c_parser_consume_token (parser);
810 parser->error = false;
813 /* Expect to be at the end of the pragma directive and consume an
814 end of line marker. */
817 c_parser_skip_to_pragma_eol (c_parser *parser)
819 gcc_assert (parser->in_pragma);
820 parser->in_pragma = false;
822 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
825 c_token *token = c_parser_peek_token (parser);
826 if (token->type == CPP_EOF)
828 if (token->type == CPP_PRAGMA_EOL)
830 c_parser_consume_token (parser);
833 c_parser_consume_token (parser);
836 parser->error = false;
839 /* Skip tokens until we have consumed an entire block, or until we
840 have consumed a non-nested ';'. */
843 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
845 unsigned nesting_depth = 0;
846 bool save_error = parser->error;
852 /* Peek at the next token. */
853 token = c_parser_peek_token (parser);
861 if (parser->in_pragma)
866 /* If the next token is a ';', we have reached the
867 end of the statement. */
870 /* Consume the ';'. */
871 c_parser_consume_token (parser);
876 case CPP_CLOSE_BRACE:
877 /* If the next token is a non-nested '}', then we have
878 reached the end of the current block. */
879 if (nesting_depth == 0 || --nesting_depth == 0)
881 c_parser_consume_token (parser);
887 /* If it the next token is a '{', then we are entering a new
888 block. Consume the entire block. */
893 /* If we see a pragma, consume the whole thing at once. We
894 have some safeguards against consuming pragmas willy-nilly.
895 Normally, we'd expect to be here with parser->error set,
896 which disables these safeguards. But it's possible to get
897 here for secondary error recovery, after parser->error has
899 c_parser_consume_pragma (parser);
900 c_parser_skip_to_pragma_eol (parser);
901 parser->error = save_error;
908 c_parser_consume_token (parser);
912 parser->error = false;
915 /* Save the warning flags which are controlled by __extension__. */
918 disable_extension_diagnostics (void)
921 | (warn_pointer_arith << 1)
922 | (warn_traditional << 2)
925 warn_pointer_arith = 0;
926 warn_traditional = 0;
931 /* Restore the warning flags which are controlled by __extension__.
932 FLAGS is the return value from disable_extension_diagnostics. */
935 restore_extension_diagnostics (int flags)
937 pedantic = flags & 1;
938 warn_pointer_arith = (flags >> 1) & 1;
939 warn_traditional = (flags >> 2) & 1;
940 flag_iso = (flags >> 3) & 1;
943 /* Possibly kinds of declarator to parse. */
944 typedef enum c_dtr_syn {
945 /* A normal declarator with an identifier. */
947 /* An abstract declarator (maybe empty). */
949 /* A parameter declarator: may be either, but after a type name does
950 not redeclare a typedef name as an identifier if it can
951 alternatively be interpreted as a typedef name; see DR#009,
952 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
953 following DR#249. For example, given a typedef T, "int T" and
954 "int *T" are valid parameter declarations redeclaring T, while
955 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
956 abstract declarators rather than involving redundant parentheses;
957 the same applies with attributes inside the parentheses before
962 static void c_parser_external_declaration (c_parser *);
963 static void c_parser_asm_definition (c_parser *);
964 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
965 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
967 static struct c_typespec c_parser_enum_specifier (c_parser *);
968 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
969 static tree c_parser_struct_declaration (c_parser *);
970 static struct c_typespec c_parser_typeof_specifier (c_parser *);
971 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
973 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
975 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
977 struct c_declarator *);
978 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
979 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
980 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
981 static tree c_parser_simple_asm_expr (c_parser *);
982 static tree c_parser_attributes (c_parser *);
983 static struct c_type_name *c_parser_type_name (c_parser *);
984 static struct c_expr c_parser_initializer (c_parser *);
985 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
986 static void c_parser_initelt (c_parser *);
987 static void c_parser_initval (c_parser *, struct c_expr *);
988 static tree c_parser_compound_statement (c_parser *);
989 static void c_parser_compound_statement_nostart (c_parser *);
990 static void c_parser_label (c_parser *);
991 static void c_parser_statement (c_parser *);
992 static void c_parser_statement_after_labels (c_parser *);
993 static void c_parser_if_statement (c_parser *);
994 static void c_parser_switch_statement (c_parser *);
995 static void c_parser_while_statement (c_parser *);
996 static void c_parser_do_statement (c_parser *);
997 static void c_parser_for_statement (c_parser *);
998 static tree c_parser_asm_statement (c_parser *);
999 static tree c_parser_asm_operands (c_parser *, bool);
1000 static tree c_parser_asm_clobbers (c_parser *);
1001 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1002 static struct c_expr c_parser_conditional_expression (c_parser *,
1004 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1005 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1006 static struct c_expr c_parser_unary_expression (c_parser *);
1007 static struct c_expr c_parser_sizeof_expression (c_parser *);
1008 static struct c_expr c_parser_alignof_expression (c_parser *);
1009 static struct c_expr c_parser_postfix_expression (c_parser *);
1010 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1011 struct c_type_name *);
1012 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1014 static struct c_expr c_parser_expression (c_parser *);
1015 static struct c_expr c_parser_expression_conv (c_parser *);
1016 static tree c_parser_expr_list (c_parser *, bool);
1017 static void c_parser_omp_construct (c_parser *);
1018 static void c_parser_omp_threadprivate (c_parser *);
1019 static void c_parser_omp_barrier (c_parser *);
1020 static void c_parser_omp_flush (c_parser *);
1022 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1023 static bool c_parser_pragma (c_parser *, enum pragma_context);
1025 /* These Objective-C parser functions are only ever called when
1026 compiling Objective-C. */
1027 static void c_parser_objc_class_definition (c_parser *);
1028 static void c_parser_objc_class_instance_variables (c_parser *);
1029 static void c_parser_objc_class_declaration (c_parser *);
1030 static void c_parser_objc_alias_declaration (c_parser *);
1031 static void c_parser_objc_protocol_definition (c_parser *);
1032 static enum tree_code c_parser_objc_method_type (c_parser *);
1033 static void c_parser_objc_method_definition (c_parser *);
1034 static void c_parser_objc_methodprotolist (c_parser *);
1035 static void c_parser_objc_methodproto (c_parser *);
1036 static tree c_parser_objc_method_decl (c_parser *);
1037 static tree c_parser_objc_type_name (c_parser *);
1038 static tree c_parser_objc_protocol_refs (c_parser *);
1039 static void c_parser_objc_try_catch_statement (c_parser *);
1040 static void c_parser_objc_synchronized_statement (c_parser *);
1041 static tree c_parser_objc_selector (c_parser *);
1042 static tree c_parser_objc_selector_arg (c_parser *);
1043 static tree c_parser_objc_receiver (c_parser *);
1044 static tree c_parser_objc_message_args (c_parser *);
1045 static tree c_parser_objc_keywordexpr (c_parser *);
1047 /* Parse a translation unit (C90 6.7, C99 6.9).
1050 external-declarations
1052 external-declarations:
1053 external-declaration
1054 external-declarations external-declaration
1063 c_parser_translation_unit (c_parser *parser)
1065 if (c_parser_next_token_is (parser, CPP_EOF))
1068 pedwarn ("%HISO C forbids an empty translation unit",
1069 &c_parser_peek_token (parser)->location);
1073 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1077 c_parser_external_declaration (parser);
1078 obstack_free (&parser_obstack, obstack_position);
1080 while (c_parser_next_token_is_not (parser, CPP_EOF));
1084 /* Parse an external declaration (C90 6.7, C99 6.9).
1086 external-declaration:
1092 external-declaration:
1095 __extension__ external-declaration
1099 external-declaration:
1100 objc-class-definition
1101 objc-class-declaration
1102 objc-alias-declaration
1103 objc-protocol-definition
1104 objc-method-definition
1109 c_parser_external_declaration (c_parser *parser)
1112 switch (c_parser_peek_token (parser)->type)
1115 switch (c_parser_peek_token (parser)->keyword)
1118 ext = disable_extension_diagnostics ();
1119 c_parser_consume_token (parser);
1120 c_parser_external_declaration (parser);
1121 restore_extension_diagnostics (ext);
1124 c_parser_asm_definition (parser);
1126 case RID_AT_INTERFACE:
1127 case RID_AT_IMPLEMENTATION:
1128 gcc_assert (c_dialect_objc ());
1129 c_parser_objc_class_definition (parser);
1132 gcc_assert (c_dialect_objc ());
1133 c_parser_objc_class_declaration (parser);
1136 gcc_assert (c_dialect_objc ());
1137 c_parser_objc_alias_declaration (parser);
1139 case RID_AT_PROTOCOL:
1140 gcc_assert (c_dialect_objc ());
1141 c_parser_objc_protocol_definition (parser);
1144 gcc_assert (c_dialect_objc ());
1145 c_parser_consume_token (parser);
1146 objc_finish_implementation ();
1154 pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
1155 &c_parser_peek_token (parser)->location);
1156 c_parser_consume_token (parser);
1159 c_parser_pragma (parser, pragma_external);
1163 if (c_dialect_objc ())
1165 c_parser_objc_method_definition (parser);
1168 /* Else fall through, and yield a syntax error trying to parse
1169 as a declaration or function definition. */
1172 /* A declaration or a function definition. We can only tell
1173 which after parsing the declaration specifiers, if any, and
1174 the first declarator. */
1175 c_parser_declaration_or_fndef (parser, true, true, false, true);
1181 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1182 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1183 accepted; otherwise (old-style parameter declarations) only other
1184 declarations are accepted. If NESTED is true, we are inside a
1185 function or parsing old-style parameter declarations; any functions
1186 encountered are nested functions and declaration specifiers are
1187 required; otherwise we are at top level and functions are normal
1188 functions and declaration specifiers may be optional. If EMPTY_OK
1189 is true, empty declarations are OK (subject to all other
1190 constraints); otherwise (old-style parameter declarations) they are
1191 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1192 may start with attributes; otherwise they may not.
1195 declaration-specifiers init-declarator-list[opt] ;
1197 function-definition:
1198 declaration-specifiers[opt] declarator declaration-list[opt]
1203 declaration-list declaration
1205 init-declarator-list:
1207 init-declarator-list , init-declarator
1210 declarator simple-asm-expr[opt] attributes[opt]
1211 declarator simple-asm-expr[opt] attributes[opt] = initializer
1215 nested-function-definition:
1216 declaration-specifiers declarator declaration-list[opt]
1219 The simple-asm-expr and attributes are GNU extensions.
1221 This function does not handle __extension__; that is handled in its
1222 callers. ??? Following the old parser, __extension__ may start
1223 external declarations, declarations in functions and declarations
1224 at the start of "for" loops, but not old-style parameter
1227 C99 requires declaration specifiers in a function definition; the
1228 absence is diagnosed through the diagnosis of implicit int. In GNU
1229 C we also allow but diagnose declarations without declaration
1230 specifiers, but only at top level (elsewhere they conflict with
1236 threadprivate-directive */
1239 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1240 bool nested, bool start_attr_ok)
1242 struct c_declspecs *specs;
1244 tree all_prefix_attrs;
1245 bool diagnosed_no_specs = false;
1246 location_t here = c_parser_peek_token (parser)->location;
1248 specs = build_null_declspecs ();
1249 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1252 c_parser_skip_to_end_of_block_or_statement (parser);
1255 if (nested && !specs->declspecs_seen_p)
1257 c_parser_error (parser, "expected declaration specifiers");
1258 c_parser_skip_to_end_of_block_or_statement (parser);
1261 finish_declspecs (specs);
1262 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1268 shadow_tag_warned (specs, 1);
1269 pedwarn ("%Hempty declaration", &here);
1271 c_parser_consume_token (parser);
1274 pending_xref_error ();
1275 prefix_attrs = specs->attrs;
1276 all_prefix_attrs = prefix_attrs;
1277 specs->attrs = NULL_TREE;
1280 struct c_declarator *declarator;
1283 /* Declaring either one or more declarators (in which case we
1284 should diagnose if there were no declaration specifiers) or a
1285 function definition (in which case the diagnostic for
1286 implicit int suffices). */
1287 declarator = c_parser_declarator (parser, specs->type_seen_p,
1288 C_DTR_NORMAL, &dummy);
1289 if (declarator == NULL)
1291 c_parser_skip_to_end_of_block_or_statement (parser);
1294 if (c_parser_next_token_is (parser, CPP_EQ)
1295 || c_parser_next_token_is (parser, CPP_COMMA)
1296 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1297 || c_parser_next_token_is_keyword (parser, RID_ASM)
1298 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1300 tree asm_name = NULL_TREE;
1301 tree postfix_attrs = NULL_TREE;
1302 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1304 diagnosed_no_specs = true;
1305 pedwarn ("%Hdata definition has no type or storage class",
1308 /* Having seen a data definition, there cannot now be a
1309 function definition. */
1311 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1312 asm_name = c_parser_simple_asm_expr (parser);
1313 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1314 postfix_attrs = c_parser_attributes (parser);
1315 if (c_parser_next_token_is (parser, CPP_EQ))
1319 c_parser_consume_token (parser);
1320 /* The declaration of the variable is in effect while
1321 its initializer is parsed. */
1322 d = start_decl (declarator, specs, true,
1323 chainon (postfix_attrs, all_prefix_attrs));
1325 d = error_mark_node;
1326 start_init (d, asm_name, global_bindings_p ());
1327 init = c_parser_initializer (parser);
1329 if (d != error_mark_node)
1331 maybe_warn_string_init (TREE_TYPE (d), init);
1332 finish_decl (d, init.value, asm_name);
1337 tree d = start_decl (declarator, specs, false,
1338 chainon (postfix_attrs,
1341 finish_decl (d, NULL_TREE, asm_name);
1343 if (c_parser_next_token_is (parser, CPP_COMMA))
1345 c_parser_consume_token (parser);
1346 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1347 all_prefix_attrs = chainon (c_parser_attributes (parser),
1350 all_prefix_attrs = prefix_attrs;
1353 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1355 c_parser_consume_token (parser);
1360 c_parser_error (parser, "expected %<,%> or %<;%>");
1361 c_parser_skip_to_end_of_block_or_statement (parser);
1367 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1368 "%<asm%> or %<__attribute__%>");
1369 c_parser_skip_to_end_of_block_or_statement (parser);
1372 /* Function definition (nested or otherwise). */
1376 pedwarn ("%HISO C forbids nested functions", &here);
1377 c_push_function_context ();
1379 if (!start_function (specs, declarator, all_prefix_attrs))
1381 /* This can appear in many cases looking nothing like a
1382 function definition, so we don't give a more specific
1383 error suggesting there was one. */
1384 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1385 "or %<__attribute__%>");
1387 c_pop_function_context ();
1390 /* Parse old-style parameter declarations. ??? Attributes are
1391 not allowed to start declaration specifiers here because of a
1392 syntax conflict between a function declaration with attribute
1393 suffix and a function definition with an attribute prefix on
1394 first old-style parameter declaration. Following the old
1395 parser, they are not accepted on subsequent old-style
1396 parameter declarations either. However, there is no
1397 ambiguity after the first declaration, nor indeed on the
1398 first as long as we don't allow postfix attributes after a
1399 declarator with a nonempty identifier list in a definition;
1400 and postfix attributes have never been accepted here in
1401 function definitions either. */
1402 while (c_parser_next_token_is_not (parser, CPP_EOF)
1403 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1404 c_parser_declaration_or_fndef (parser, false, false, true, false);
1405 DECL_SOURCE_LOCATION (current_function_decl)
1406 = c_parser_peek_token (parser)->location;
1407 store_parm_decls ();
1408 fnbody = c_parser_compound_statement (parser);
1411 tree decl = current_function_decl;
1414 c_pop_function_context ();
1415 add_stmt (build_stmt (DECL_EXPR, decl));
1426 /* Parse an asm-definition (asm() outside a function body). This is a
1434 c_parser_asm_definition (c_parser *parser)
1436 tree asm_str = c_parser_simple_asm_expr (parser);
1438 cgraph_add_asm_node (asm_str);
1439 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1442 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1443 6.7), adding them to SPECS (which may already include some).
1444 Storage class specifiers are accepted iff SCSPEC_OK; type
1445 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1446 the start iff START_ATTR_OK.
1448 declaration-specifiers:
1449 storage-class-specifier declaration-specifiers[opt]
1450 type-specifier declaration-specifiers[opt]
1451 type-qualifier declaration-specifiers[opt]
1452 function-specifier declaration-specifiers[opt]
1454 Function specifiers (inline) are from C99, and are currently
1455 handled as storage class specifiers, as is __thread.
1457 C90 6.5.1, C99 6.7.1:
1458 storage-class-specifier:
1469 C90 6.5.2, C99 6.7.2:
1482 [_Imaginary removed in C99 TC2]
1483 struct-or-union-specifier
1487 (_Bool and _Complex are new in C99.)
1489 C90 6.5.3, C99 6.7.3:
1496 (restrict is new in C99.)
1500 declaration-specifiers:
1501 attributes declaration-specifiers[opt]
1503 storage-class-specifier:
1515 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1516 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1521 class-name objc-protocol-refs[opt]
1522 typedef-name objc-protocol-refs
1527 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1528 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1530 bool attrs_ok = start_attr_ok;
1531 bool seen_type = specs->type_seen_p;
1532 while (c_parser_next_token_is (parser, CPP_NAME)
1533 || c_parser_next_token_is (parser, CPP_KEYWORD)
1534 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1536 struct c_typespec t;
1538 if (c_parser_next_token_is (parser, CPP_NAME))
1540 tree value = c_parser_peek_token (parser)->value;
1541 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1542 /* This finishes the specifiers unless a type name is OK, it
1543 is declared as a type name and a type name hasn't yet
1545 if (!typespec_ok || seen_type
1546 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1548 c_parser_consume_token (parser);
1551 if (kind == C_ID_TYPENAME
1552 && (!c_dialect_objc ()
1553 || c_parser_next_token_is_not (parser, CPP_LESS)))
1555 t.kind = ctsk_typedef;
1556 /* For a typedef name, record the meaning, not the name.
1557 In case of 'foo foo, bar;'. */
1558 t.spec = lookup_name (value);
1562 tree proto = NULL_TREE;
1563 gcc_assert (c_dialect_objc ());
1565 if (c_parser_next_token_is (parser, CPP_LESS))
1566 proto = c_parser_objc_protocol_refs (parser);
1567 t.spec = objc_get_protocol_qualified_type (value, proto);
1569 declspecs_add_type (specs, t);
1572 if (c_parser_next_token_is (parser, CPP_LESS))
1574 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1575 nisse@lysator.liu.se. */
1577 gcc_assert (c_dialect_objc ());
1578 if (!typespec_ok || seen_type)
1580 proto = c_parser_objc_protocol_refs (parser);
1582 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1583 declspecs_add_type (specs, t);
1586 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1587 switch (c_parser_peek_token (parser)->keyword)
1599 /* TODO: Distinguish between function specifiers (inline)
1600 and storage class specifiers, either here or in
1601 declspecs_add_scspec. */
1602 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1603 c_parser_consume_token (parser);
1626 if (c_dialect_objc ())
1627 parser->objc_need_raw_identifier = true;
1628 t.kind = ctsk_resword;
1629 t.spec = c_parser_peek_token (parser)->value;
1630 declspecs_add_type (specs, t);
1631 c_parser_consume_token (parser);
1638 t = c_parser_enum_specifier (parser);
1639 declspecs_add_type (specs, t);
1647 t = c_parser_struct_or_union_specifier (parser);
1648 declspecs_add_type (specs, t);
1651 /* ??? The old parser rejected typeof after other type
1652 specifiers, but is a syntax error the best way of
1654 if (!typespec_ok || seen_type)
1658 t = c_parser_typeof_specifier (parser);
1659 declspecs_add_type (specs, t);
1665 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1666 c_parser_consume_token (parser);
1671 attrs = c_parser_attributes (parser);
1672 declspecs_add_attrs (specs, attrs);
1681 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1684 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1685 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1686 enum attributes[opt] identifier
1688 The form with trailing comma is new in C99. The forms with
1689 attributes are GNU extensions. In GNU C, we accept any expression
1690 without commas in the syntax (assignment expressions, not just
1691 conditional expressions); assignment expressions will be diagnosed
1696 enumerator-list , enumerator
1699 enumeration-constant
1700 enumeration-constant = constant-expression
1703 static struct c_typespec
1704 c_parser_enum_specifier (c_parser *parser)
1706 struct c_typespec ret;
1708 tree ident = NULL_TREE;
1709 location_t ident_loc;
1710 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1711 c_parser_consume_token (parser);
1712 attrs = c_parser_attributes (parser);
1713 /* Set the location in case we create a decl now. */
1714 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1715 if (c_parser_next_token_is (parser, CPP_NAME))
1717 ident = c_parser_peek_token (parser)->value;
1718 ident_loc = c_parser_peek_token (parser)->location;
1719 c_parser_consume_token (parser);
1721 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1723 /* Parse an enum definition. */
1724 struct c_enum_contents the_enum;
1725 tree type = start_enum (&the_enum, ident);
1727 /* We chain the enumerators in reverse order, then put them in
1728 forward order at the end. */
1729 tree values = NULL_TREE;
1730 c_parser_consume_token (parser);
1738 location_t comma_loc;
1739 if (c_parser_next_token_is_not (parser, CPP_NAME))
1741 c_parser_error (parser, "expected identifier");
1742 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1743 values = error_mark_node;
1746 token = c_parser_peek_token (parser);
1747 enum_id = token->value;
1748 /* Set the location in case we create a decl now. */
1749 c_parser_set_source_position_from_token (token);
1750 c_parser_consume_token (parser);
1751 if (c_parser_next_token_is (parser, CPP_EQ))
1753 c_parser_consume_token (parser);
1754 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1757 enum_value = NULL_TREE;
1758 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1759 TREE_CHAIN (enum_decl) = values;
1762 if (c_parser_next_token_is (parser, CPP_COMMA))
1764 comma_loc = c_parser_peek_token (parser)->location;
1766 c_parser_consume_token (parser);
1768 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1770 if (seen_comma && pedantic && !flag_isoc99)
1771 pedwarn ("%Hcomma at end of enumerator list", &comma_loc);
1772 c_parser_consume_token (parser);
1777 c_parser_error (parser, "expected %<,%> or %<}%>");
1778 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1779 values = error_mark_node;
1783 postfix_attrs = c_parser_attributes (parser);
1784 ret.spec = finish_enum (type, nreverse (values),
1785 chainon (attrs, postfix_attrs));
1786 ret.kind = ctsk_tagdef;
1791 c_parser_error (parser, "expected %<{%>");
1792 ret.spec = error_mark_node;
1793 ret.kind = ctsk_tagref;
1796 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1797 /* In ISO C, enumerated types can be referred to only if already
1799 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1802 pedwarn ("%HISO C forbids forward references to %<enum%> types",
1808 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1810 struct-or-union-specifier:
1811 struct-or-union attributes[opt] identifier[opt]
1812 { struct-contents } attributes[opt]
1813 struct-or-union attributes[opt] identifier
1816 struct-declaration-list
1818 struct-declaration-list:
1819 struct-declaration ;
1820 struct-declaration-list struct-declaration ;
1827 struct-declaration-list struct-declaration
1829 struct-declaration-list:
1830 struct-declaration-list ;
1833 (Note that in the syntax here, unlike that in ISO C, the semicolons
1834 are included here rather than in struct-declaration, in order to
1835 describe the syntax with extra semicolons and missing semicolon at
1840 struct-declaration-list:
1841 @defs ( class-name )
1843 (Note this does not include a trailing semicolon, but can be
1844 followed by further declarations, and gets a pedwarn-if-pedantic
1845 when followed by a semicolon.) */
1847 static struct c_typespec
1848 c_parser_struct_or_union_specifier (c_parser *parser)
1850 struct c_typespec ret;
1852 tree ident = NULL_TREE;
1853 enum tree_code code;
1854 switch (c_parser_peek_token (parser)->keyword)
1865 c_parser_consume_token (parser);
1866 attrs = c_parser_attributes (parser);
1867 /* Set the location in case we create a decl now. */
1868 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1869 if (c_parser_next_token_is (parser, CPP_NAME))
1871 ident = c_parser_peek_token (parser)->value;
1872 c_parser_consume_token (parser);
1874 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1876 /* Parse a struct or union definition. Start the scope of the
1877 tag before parsing components. */
1878 tree type = start_struct (code, ident);
1880 /* We chain the components in reverse order, then put them in
1881 forward order at the end. Each struct-declaration may
1882 declare multiple components (comma-separated), so we must use
1883 chainon to join them, although when parsing each
1884 struct-declaration we can use TREE_CHAIN directly.
1886 The theory behind all this is that there will be more
1887 semicolon separated fields than comma separated fields, and
1888 so we'll be minimizing the number of node traversals required
1890 tree contents = NULL_TREE;
1891 c_parser_consume_token (parser);
1892 /* Handle the Objective-C @defs construct,
1893 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1894 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1897 gcc_assert (c_dialect_objc ());
1898 c_parser_consume_token (parser);
1899 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1901 if (c_parser_next_token_is (parser, CPP_NAME)
1902 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1904 name = c_parser_peek_token (parser)->value;
1905 c_parser_consume_token (parser);
1909 c_parser_error (parser, "expected class name");
1910 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1913 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1915 contents = nreverse (objc_get_class_ivars (name));
1918 /* Parse the struct-declarations and semicolons. Problems with
1919 semicolons are diagnosed here; empty structures are diagnosed
1924 /* Parse any stray semicolon. */
1925 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1928 pedwarn ("%Hextra semicolon in struct or union specified",
1929 &c_parser_peek_token (parser)->location);
1930 c_parser_consume_token (parser);
1933 /* Stop if at the end of the struct or union contents. */
1934 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1936 c_parser_consume_token (parser);
1939 /* Accept #pragmas at struct scope. */
1940 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1942 c_parser_pragma (parser, pragma_external);
1945 /* Parse some comma-separated declarations, but not the
1946 trailing semicolon if any. */
1947 decls = c_parser_struct_declaration (parser);
1948 contents = chainon (decls, contents);
1949 /* If no semicolon follows, either we have a parse error or
1950 are at the end of the struct or union and should
1952 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1953 c_parser_consume_token (parser);
1956 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1957 pedwarn ("%Hno semicolon at end of struct or union",
1958 &c_parser_peek_token (parser)->location);
1961 c_parser_error (parser, "expected %<;%>");
1962 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1967 postfix_attrs = c_parser_attributes (parser);
1968 ret.spec = finish_struct (type, nreverse (contents),
1969 chainon (attrs, postfix_attrs));
1970 ret.kind = ctsk_tagdef;
1975 c_parser_error (parser, "expected %<{%>");
1976 ret.spec = error_mark_node;
1977 ret.kind = ctsk_tagref;
1980 ret = parser_xref_tag (code, ident);
1984 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1985 the trailing semicolon.
1988 specifier-qualifier-list struct-declarator-list
1990 specifier-qualifier-list:
1991 type-specifier specifier-qualifier-list[opt]
1992 type-qualifier specifier-qualifier-list[opt]
1993 attributes specifier-qualifier-list[opt]
1995 struct-declarator-list:
1997 struct-declarator-list , attributes[opt] struct-declarator
2000 declarator attributes[opt]
2001 declarator[opt] : constant-expression attributes[opt]
2006 __extension__ struct-declaration
2007 specifier-qualifier-list
2009 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2010 of attributes where shown is a GNU extension. In GNU C, we accept
2011 any expression without commas in the syntax (assignment
2012 expressions, not just conditional expressions); assignment
2013 expressions will be diagnosed as non-constant. */
2016 c_parser_struct_declaration (c_parser *parser)
2018 struct c_declspecs *specs;
2020 tree all_prefix_attrs;
2022 location_t decl_loc;
2023 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2027 ext = disable_extension_diagnostics ();
2028 c_parser_consume_token (parser);
2029 decl = c_parser_struct_declaration (parser);
2030 restore_extension_diagnostics (ext);
2033 specs = build_null_declspecs ();
2034 decl_loc = c_parser_peek_token (parser)->location;
2035 c_parser_declspecs (parser, specs, false, true, true);
2038 if (!specs->declspecs_seen_p)
2040 c_parser_error (parser, "expected specifier-qualifier-list");
2043 finish_declspecs (specs);
2044 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2047 if (!specs->type_seen_p)
2050 pedwarn ("%HISO C forbids member declarations with no members",
2052 shadow_tag_warned (specs, pedantic);
2057 /* Support for unnamed structs or unions as members of
2058 structs or unions (which is [a] useful and [b] supports
2061 ret = grokfield (build_id_declarator (NULL_TREE), specs,
2064 decl_attributes (&ret, attrs, 0);
2068 pending_xref_error ();
2069 prefix_attrs = specs->attrs;
2070 all_prefix_attrs = prefix_attrs;
2071 specs->attrs = NULL_TREE;
2075 /* Declaring one or more declarators or un-named bit-fields. */
2076 struct c_declarator *declarator;
2078 if (c_parser_next_token_is (parser, CPP_COLON))
2079 declarator = build_id_declarator (NULL_TREE);
2081 declarator = c_parser_declarator (parser, specs->type_seen_p,
2082 C_DTR_NORMAL, &dummy);
2083 if (declarator == NULL)
2085 c_parser_skip_to_end_of_block_or_statement (parser);
2088 if (c_parser_next_token_is (parser, CPP_COLON)
2089 || c_parser_next_token_is (parser, CPP_COMMA)
2090 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2091 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2092 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2094 tree postfix_attrs = NULL_TREE;
2095 tree width = NULL_TREE;
2097 if (c_parser_next_token_is (parser, CPP_COLON))
2099 c_parser_consume_token (parser);
2100 width = c_parser_expr_no_commas (parser, NULL).value;
2102 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2103 postfix_attrs = c_parser_attributes (parser);
2104 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2105 decl_attributes (&d, chainon (postfix_attrs,
2106 all_prefix_attrs), 0);
2107 TREE_CHAIN (d) = decls;
2109 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2110 all_prefix_attrs = chainon (c_parser_attributes (parser),
2113 all_prefix_attrs = prefix_attrs;
2114 if (c_parser_next_token_is (parser, CPP_COMMA))
2115 c_parser_consume_token (parser);
2116 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2117 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2119 /* Semicolon consumed in caller. */
2124 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2130 c_parser_error (parser,
2131 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2132 "%<__attribute__%>");
2139 /* Parse a typeof specifier (a GNU extension).
2142 typeof ( expression )
2143 typeof ( type-name )
2146 static struct c_typespec
2147 c_parser_typeof_specifier (c_parser *parser)
2149 struct c_typespec ret;
2150 ret.kind = ctsk_typeof;
2151 ret.spec = error_mark_node;
2152 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2153 c_parser_consume_token (parser);
2156 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2162 if (c_parser_next_token_starts_typename (parser))
2164 struct c_type_name *type = c_parser_type_name (parser);
2169 ret.spec = groktypename (type);
2170 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2176 location_t here = c_parser_peek_token (parser)->location;
2177 struct c_expr expr = c_parser_expression (parser);
2180 if (TREE_CODE (expr.value) == COMPONENT_REF
2181 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2182 error ("%H%<typeof%> applied to a bit-field", &here);
2183 ret.spec = TREE_TYPE (expr.value);
2184 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2185 /* This should be returned with the type so that when the type
2186 is evaluated, this can be evaluated. For now, we avoid
2187 evaluation when the context might. */
2188 if (!skip_evaluation && was_vm)
2190 tree e = expr.value;
2192 /* If the expression is not of a type to which we cannot assign a line
2193 number, wrap the thing in a no-op NOP_EXPR. */
2194 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2195 e = build1 (NOP_EXPR, void_type_node, e);
2197 if (CAN_HAVE_LOCATION_P (e))
2198 SET_EXPR_LOCATION (e, input_location);
2202 pop_maybe_used (was_vm);
2204 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2208 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2209 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2210 be redeclared; otherwise it may not. KIND indicates which kind of
2211 declarator is wanted. Returns a valid declarator except in the
2212 case of a syntax error in which case NULL is returned. *SEEN_ID is
2213 set to true if an identifier being declared is seen; this is used
2214 to diagnose bad forms of abstract array declarators and to
2215 determine whether an identifier list is syntactically permitted.
2218 pointer[opt] direct-declarator
2222 ( attributes[opt] declarator )
2223 direct-declarator array-declarator
2224 direct-declarator ( parameter-type-list )
2225 direct-declarator ( identifier-list[opt] )
2228 * type-qualifier-list[opt]
2229 * type-qualifier-list[opt] pointer
2231 type-qualifier-list:
2234 type-qualifier-list type-qualifier
2235 type-qualifier-list attributes
2237 parameter-type-list:
2239 parameter-list , ...
2242 parameter-declaration
2243 parameter-list , parameter-declaration
2245 parameter-declaration:
2246 declaration-specifiers declarator attributes[opt]
2247 declaration-specifiers abstract-declarator[opt] attributes[opt]
2251 identifier-list , identifier
2253 abstract-declarator:
2255 pointer[opt] direct-abstract-declarator
2257 direct-abstract-declarator:
2258 ( attributes[opt] abstract-declarator )
2259 direct-abstract-declarator[opt] array-declarator
2260 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2265 direct-declarator ( parameter-forward-declarations
2266 parameter-type-list[opt] )
2268 direct-abstract-declarator:
2269 direct-abstract-declarator[opt] ( parameter-forward-declarations
2270 parameter-type-list[opt] )
2272 parameter-forward-declarations:
2274 parameter-forward-declarations parameter-list ;
2276 The uses of attributes shown above are GNU extensions.
2278 Some forms of array declarator are not included in C99 in the
2279 syntax for abstract declarators; these are disallowed elsewhere.
2280 This may be a defect (DR#289).
2282 This function also accepts an omitted abstract declarator as being
2283 an abstract declarator, although not part of the formal syntax. */
2285 static struct c_declarator *
2286 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2289 /* Parse any initial pointer part. */
2290 if (c_parser_next_token_is (parser, CPP_MULT))
2292 struct c_declspecs *quals_attrs = build_null_declspecs ();
2293 struct c_declarator *inner;
2294 c_parser_consume_token (parser);
2295 c_parser_declspecs (parser, quals_attrs, false, false, true);
2296 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2300 return make_pointer_declarator (quals_attrs, inner);
2302 /* Now we have a direct declarator, direct abstract declarator or
2303 nothing (which counts as a direct abstract declarator here). */
2304 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2307 /* Parse a direct declarator or direct abstract declarator; arguments
2308 as c_parser_declarator. */
2310 static struct c_declarator *
2311 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2314 /* The direct declarator must start with an identifier (possibly
2315 omitted) or a parenthesized declarator (possibly abstract). In
2316 an ordinary declarator, initial parentheses must start a
2317 parenthesized declarator. In an abstract declarator or parameter
2318 declarator, they could start a parenthesized declarator or a
2319 parameter list. To tell which, the open parenthesis and any
2320 following attributes must be read. If a declaration specifier
2321 follows, then it is a parameter list; if the specifier is a
2322 typedef name, there might be an ambiguity about redeclaring it,
2323 which is resolved in the direction of treating it as a typedef
2324 name. If a close parenthesis follows, it is also an empty
2325 parameter list, as the syntax does not permit empty abstract
2326 declarators. Otherwise, it is a parenthesized declarator (in
2327 which case the analysis may be repeated inside it, recursively).
2329 ??? There is an ambiguity in a parameter declaration "int
2330 (__attribute__((foo)) x)", where x is not a typedef name: it
2331 could be an abstract declarator for a function, or declare x with
2332 parentheses. The proper resolution of this ambiguity needs
2333 documenting. At present we follow an accident of the old
2334 parser's implementation, whereby the first parameter must have
2335 some declaration specifiers other than just attributes. Thus as
2336 a parameter declaration it is treated as a parenthesized
2337 parameter named x, and as an abstract declarator it is
2340 ??? Also following the old parser, attributes inside an empty
2341 parameter list are ignored, making it a list not yielding a
2342 prototype, rather than giving an error or making it have one
2343 parameter with implicit type int.
2345 ??? Also following the old parser, typedef names may be
2346 redeclared in declarators, but not Objective-C class names. */
2348 if (kind != C_DTR_ABSTRACT
2349 && c_parser_next_token_is (parser, CPP_NAME)
2351 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2352 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2354 struct c_declarator *inner
2355 = build_id_declarator (c_parser_peek_token (parser)->value);
2357 inner->id_loc = c_parser_peek_token (parser)->location;
2358 c_parser_consume_token (parser);
2359 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2362 if (kind != C_DTR_NORMAL
2363 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2365 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2366 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2369 /* Either we are at the end of an abstract declarator, or we have
2372 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2375 struct c_declarator *inner;
2376 c_parser_consume_token (parser);
2377 attrs = c_parser_attributes (parser);
2378 if (kind != C_DTR_NORMAL
2379 && (c_parser_next_token_starts_declspecs (parser)
2380 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2382 struct c_arg_info *args
2383 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2390 = build_function_declarator (args,
2391 build_id_declarator (NULL_TREE));
2392 return c_parser_direct_declarator_inner (parser, *seen_id,
2396 /* A parenthesized declarator. */
2397 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2398 if (inner != NULL && attrs != NULL)
2399 inner = build_attrs_declarator (attrs, inner);
2400 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2402 c_parser_consume_token (parser);
2406 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2417 if (kind == C_DTR_NORMAL)
2419 c_parser_error (parser, "expected identifier or %<(%>");
2423 return build_id_declarator (NULL_TREE);
2427 /* Parse part of a direct declarator or direct abstract declarator,
2428 given that some (in INNER) has already been parsed; ID_PRESENT is
2429 true if an identifier is present, false for an abstract
2432 static struct c_declarator *
2433 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2434 struct c_declarator *inner)
2436 /* Parse a sequence of array declarators and parameter lists. */
2437 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2439 struct c_declarator *declarator;
2440 struct c_declspecs *quals_attrs = build_null_declspecs ();
2444 c_parser_consume_token (parser);
2445 c_parser_declspecs (parser, quals_attrs, false, false, true);
2446 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2448 c_parser_consume_token (parser);
2449 if (static_seen && !quals_attrs->declspecs_seen_p)
2450 c_parser_declspecs (parser, quals_attrs, false, false, true);
2451 if (!quals_attrs->declspecs_seen_p)
2453 /* If "static" is present, there must be an array dimension.
2454 Otherwise, there may be a dimension, "*", or no
2459 dimen = c_parser_expr_no_commas (parser, NULL).value;
2463 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2468 else if (c_parser_next_token_is (parser, CPP_MULT))
2470 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2474 c_parser_consume_token (parser);
2479 dimen = c_parser_expr_no_commas (parser, NULL).value;
2485 dimen = c_parser_expr_no_commas (parser, NULL).value;
2488 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2489 c_parser_consume_token (parser);
2492 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2496 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2498 if (declarator == NULL)
2500 inner = set_array_declarator_inner (declarator, inner);
2501 return c_parser_direct_declarator_inner (parser, id_present, inner);
2503 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2506 struct c_arg_info *args;
2507 c_parser_consume_token (parser);
2508 attrs = c_parser_attributes (parser);
2509 args = c_parser_parms_declarator (parser, id_present, attrs);
2514 inner = build_function_declarator (args, inner);
2515 return c_parser_direct_declarator_inner (parser, id_present, inner);
2521 /* Parse a parameter list or identifier list, including the closing
2522 parenthesis but not the opening one. ATTRS are the attributes at
2523 the start of the list. ID_LIST_OK is true if an identifier list is
2524 acceptable; such a list must not have attributes at the start. */
2526 static struct c_arg_info *
2527 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2530 declare_parm_level ();
2531 /* If the list starts with an identifier, it is an identifier list.
2532 Otherwise, it is either a prototype list or an empty list. */
2535 && c_parser_next_token_is (parser, CPP_NAME)
2536 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2538 tree list = NULL_TREE, *nextp = &list;
2539 while (c_parser_next_token_is (parser, CPP_NAME)
2540 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2542 *nextp = build_tree_list (NULL_TREE,
2543 c_parser_peek_token (parser)->value);
2544 nextp = & TREE_CHAIN (*nextp);
2545 c_parser_consume_token (parser);
2546 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2548 c_parser_consume_token (parser);
2549 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2551 c_parser_error (parser, "expected identifier");
2555 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2557 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2562 ret->pending_sizes = 0;
2563 ret->had_vla_unspec = 0;
2564 c_parser_consume_token (parser);
2570 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2578 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2584 /* Parse a parameter list (possibly empty), including the closing
2585 parenthesis but not the opening one. ATTRS are the attributes at
2586 the start of the list. */
2588 static struct c_arg_info *
2589 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2591 bool good_parm = false;
2592 /* ??? Following the old parser, forward parameter declarations may
2593 use abstract declarators, and if no real parameter declarations
2594 follow the forward declarations then this is not diagnosed. Also
2595 note as above that attributes are ignored as the only contents of
2596 the parentheses, or as the only contents after forward
2598 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2600 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2605 ret->pending_sizes = 0;
2606 ret->had_vla_unspec = 0;
2607 c_parser_consume_token (parser);
2610 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2612 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2616 ret->pending_sizes = 0;
2617 ret->had_vla_unspec = 0;
2618 /* Suppress -Wold-style-definition for this case. */
2619 ret->types = error_mark_node;
2620 error ("%HISO C requires a named argument before %<...%>",
2621 &c_parser_peek_token (parser)->location);
2622 c_parser_consume_token (parser);
2623 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2625 c_parser_consume_token (parser);
2630 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2635 /* Nonempty list of parameters, either terminated with semicolon
2636 (forward declarations; recurse) or with close parenthesis (normal
2637 function) or with ", ... )" (variadic function). */
2640 /* Parse a parameter. */
2641 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2646 push_parm_decl (parm);
2648 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2651 c_parser_consume_token (parser);
2652 mark_forward_parm_decls ();
2653 new_attrs = c_parser_attributes (parser);
2654 return c_parser_parms_list_declarator (parser, new_attrs);
2656 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2658 c_parser_consume_token (parser);
2660 return get_parm_info (false);
2663 struct c_arg_info *ret
2664 = XOBNEW (&parser_obstack, struct c_arg_info);
2669 ret->pending_sizes = 0;
2670 ret->had_vla_unspec = 0;
2674 if (!c_parser_require (parser, CPP_COMMA,
2675 "expected %<;%>, %<,%> or %<)%>"))
2677 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2680 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2682 c_parser_consume_token (parser);
2683 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2685 c_parser_consume_token (parser);
2687 return get_parm_info (true);
2690 struct c_arg_info *ret
2691 = XOBNEW (&parser_obstack, struct c_arg_info);
2696 ret->pending_sizes = 0;
2697 ret->had_vla_unspec = 0;
2703 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2711 /* Parse a parameter declaration. ATTRS are the attributes at the
2712 start of the declaration if it is the first parameter. */
2714 static struct c_parm *
2715 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2717 struct c_declspecs *specs;
2718 struct c_declarator *declarator;
2720 tree postfix_attrs = NULL_TREE;
2722 if (!c_parser_next_token_starts_declspecs (parser))
2724 /* ??? In some Objective-C cases '...' isn't applicable so there
2725 should be a different message. */
2726 c_parser_error (parser,
2727 "expected declaration specifiers or %<...%>");
2728 c_parser_skip_to_end_of_parameter (parser);
2731 specs = build_null_declspecs ();
2734 declspecs_add_attrs (specs, attrs);
2737 c_parser_declspecs (parser, specs, true, true, true);
2738 finish_declspecs (specs);
2739 pending_xref_error ();
2740 prefix_attrs = specs->attrs;
2741 specs->attrs = NULL_TREE;
2742 declarator = c_parser_declarator (parser, specs->type_seen_p,
2743 C_DTR_PARM, &dummy);
2744 if (declarator == NULL)
2746 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2749 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2750 postfix_attrs = c_parser_attributes (parser);
2751 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2755 /* Parse a string literal in an asm expression. It should not be
2756 translated, and wide string literals are an error although
2757 permitted by the syntax. This is a GNU extension.
2762 ??? At present, following the old parser, the caller needs to have
2763 set lex_untranslated_string to 1. It would be better to follow the
2764 C++ parser rather than using this kludge. */
2767 c_parser_asm_string_literal (c_parser *parser)
2770 if (c_parser_next_token_is (parser, CPP_STRING))
2772 str = c_parser_peek_token (parser)->value;
2773 c_parser_consume_token (parser);
2775 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2777 error ("%Hwide string literal in %<asm%>",
2778 &c_parser_peek_token (parser)->location);
2779 str = build_string (1, "");
2780 c_parser_consume_token (parser);
2784 c_parser_error (parser, "expected string literal");
2790 /* Parse a simple asm expression. This is used in restricted
2791 contexts, where a full expression with inputs and outputs does not
2792 make sense. This is a GNU extension.
2795 asm ( asm-string-literal )
2799 c_parser_simple_asm_expr (c_parser *parser)
2802 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2803 /* ??? Follow the C++ parser rather than using the
2804 lex_untranslated_string kludge. */
2805 parser->lex_untranslated_string = true;
2806 c_parser_consume_token (parser);
2807 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2809 parser->lex_untranslated_string = false;
2812 str = c_parser_asm_string_literal (parser);
2813 parser->lex_untranslated_string = false;
2814 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2816 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2822 /* Parse (possibly empty) attributes. This is a GNU extension.
2826 attributes attribute
2829 __attribute__ ( ( attribute-list ) )
2833 attribute_list , attrib
2838 any-word ( identifier )
2839 any-word ( identifier , nonempty-expr-list )
2840 any-word ( expr-list )
2842 where the "identifier" must not be declared as a type, and
2843 "any-word" may be any identifier (including one declared as a
2844 type), a reserved word storage class specifier, type specifier or
2845 type qualifier. ??? This still leaves out most reserved keywords
2846 (following the old parser), shouldn't we include them, and why not
2847 allow identifiers declared as types to start the arguments? */
2850 c_parser_attributes (c_parser *parser)
2852 tree attrs = NULL_TREE;
2853 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2855 /* ??? Follow the C++ parser rather than using the
2856 lex_untranslated_string kludge. */
2857 parser->lex_untranslated_string = true;
2858 c_parser_consume_token (parser);
2859 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2861 parser->lex_untranslated_string = false;
2864 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2866 parser->lex_untranslated_string = false;
2867 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2870 /* Parse the attribute list. */
2871 while (c_parser_next_token_is (parser, CPP_COMMA)
2872 || c_parser_next_token_is (parser, CPP_NAME)
2873 || c_parser_next_token_is (parser, CPP_KEYWORD))
2875 tree attr, attr_name, attr_args;
2876 if (c_parser_next_token_is (parser, CPP_COMMA))
2878 c_parser_consume_token (parser);
2881 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2883 /* ??? See comment above about what keywords are
2886 switch (c_parser_peek_token (parser)->keyword)
2924 attr_name = c_parser_peek_token (parser)->value;
2925 c_parser_consume_token (parser);
2926 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2928 attr = build_tree_list (attr_name, NULL_TREE);
2929 attrs = chainon (attrs, attr);
2932 c_parser_consume_token (parser);
2933 /* Parse the attribute contents. If they start with an
2934 identifier which is followed by a comma or close
2935 parenthesis, then the arguments start with that
2936 identifier; otherwise they are an expression list. */
2937 if (c_parser_next_token_is (parser, CPP_NAME)
2938 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2939 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2940 || (c_parser_peek_2nd_token (parser)->type
2941 == CPP_CLOSE_PAREN)))
2943 tree arg1 = c_parser_peek_token (parser)->value;
2944 c_parser_consume_token (parser);
2945 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2946 attr_args = build_tree_list (NULL_TREE, arg1);
2949 c_parser_consume_token (parser);
2950 attr_args = tree_cons (NULL_TREE, arg1,
2951 c_parser_expr_list (parser, false));
2956 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2957 attr_args = NULL_TREE;
2959 attr_args = c_parser_expr_list (parser, false);
2961 attr = build_tree_list (attr_name, attr_args);
2962 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2963 c_parser_consume_token (parser);
2966 parser->lex_untranslated_string = false;
2967 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2971 attrs = chainon (attrs, attr);
2973 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2974 c_parser_consume_token (parser);
2977 parser->lex_untranslated_string = false;
2978 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2982 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2983 c_parser_consume_token (parser);
2986 parser->lex_untranslated_string = false;
2987 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2991 parser->lex_untranslated_string = false;
2996 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2999 specifier-qualifier-list abstract-declarator[opt]
3002 static struct c_type_name *
3003 c_parser_type_name (c_parser *parser)
3005 struct c_declspecs *specs = build_null_declspecs ();
3006 struct c_declarator *declarator;
3007 struct c_type_name *ret;
3009 c_parser_declspecs (parser, specs, false, true, true);
3010 if (!specs->declspecs_seen_p)
3012 c_parser_error (parser, "expected specifier-qualifier-list");
3015 pending_xref_error ();
3016 finish_declspecs (specs);
3017 declarator = c_parser_declarator (parser, specs->type_seen_p,
3018 C_DTR_ABSTRACT, &dummy);
3019 if (declarator == NULL)
3021 ret = XOBNEW (&parser_obstack, struct c_type_name);
3023 ret->declarator = declarator;
3027 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3030 assignment-expression
3031 { initializer-list }
3032 { initializer-list , }
3035 designation[opt] initializer
3036 initializer-list , designation[opt] initializer
3043 designator-list designator
3050 [ constant-expression ]
3062 [ constant-expression ... constant-expression ]
3064 Any expression without commas is accepted in the syntax for the
3065 constant-expressions, with non-constant expressions rejected later.
3067 This function is only used for top-level initializers; for nested
3068 ones, see c_parser_initval. */
3070 static struct c_expr
3071 c_parser_initializer (c_parser *parser)
3073 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3074 return c_parser_braced_init (parser, NULL_TREE, false);
3078 ret = c_parser_expr_no_commas (parser, NULL);
3079 if (TREE_CODE (ret.value) != STRING_CST
3080 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3081 ret = default_function_array_conversion (ret);
3086 /* Parse a braced initializer list. TYPE is the type specified for a
3087 compound literal, and NULL_TREE for other initializers and for
3088 nested braced lists. NESTED_P is true for nested braced lists,
3089 false for the list of a compound literal or the list that is the
3090 top-level initializer in a declaration. */
3092 static struct c_expr
3093 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3095 location_t brace_loc = c_parser_peek_token (parser)->location;
3096 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3097 c_parser_consume_token (parser);
3099 push_init_level (0);
3101 really_start_incremental_init (type);
3102 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3105 pedwarn ("%HISO C forbids empty initializer braces", &brace_loc);
3109 /* Parse a non-empty initializer list, possibly with a trailing
3113 c_parser_initelt (parser);
3116 if (c_parser_next_token_is (parser, CPP_COMMA))
3117 c_parser_consume_token (parser);
3120 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3124 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3127 ret.value = error_mark_node;
3128 ret.original_code = ERROR_MARK;
3129 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3132 c_parser_consume_token (parser);
3133 return pop_init_level (0);
3136 /* Parse a nested initializer, including designators. */
3139 c_parser_initelt (c_parser *parser)
3141 /* Parse any designator or designator list. A single array
3142 designator may have the subsequent "=" omitted in GNU C, but a
3143 longer list or a structure member designator may not. */
3144 if (c_parser_next_token_is (parser, CPP_NAME)
3145 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3147 /* Old-style structure member designator. */
3148 set_init_label (c_parser_peek_token (parser)->value);
3151 /* Use the colon as the error location. */
3152 pedwarn ("%Hobsolete use of designated initializer with %<:%>",
3153 &c_parser_peek_2nd_token (parser)->location);
3155 c_parser_consume_token (parser);
3156 c_parser_consume_token (parser);
3160 /* des_seen is 0 if there have been no designators, 1 if there
3161 has been a single array designator and 2 otherwise. */
3163 /* Location of a designator. */
3165 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3166 || c_parser_next_token_is (parser, CPP_DOT))
3168 int des_prev = des_seen;
3170 des_loc = c_parser_peek_token (parser)->location;
3173 if (c_parser_next_token_is (parser, CPP_DOT))
3176 c_parser_consume_token (parser);
3177 if (c_parser_next_token_is (parser, CPP_NAME))
3179 set_init_label (c_parser_peek_token (parser)->value);
3180 c_parser_consume_token (parser);
3185 init.value = error_mark_node;
3186 init.original_code = ERROR_MARK;
3187 c_parser_error (parser, "expected identifier");
3188 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3189 process_init_element (init);
3196 location_t ellipsis_loc;
3197 /* ??? Following the old parser, [ objc-receiver
3198 objc-message-args ] is accepted as an initializer,
3199 being distinguished from a designator by what follows
3200 the first assignment expression inside the square
3201 brackets, but after a first array designator a
3202 subsequent square bracket is for Objective-C taken to
3203 start an expression, using the obsolete form of
3204 designated initializer without '=', rather than
3205 possibly being a second level of designation: in LALR
3206 terms, the '[' is shifted rather than reducing
3207 designator to designator-list. */
3208 if (des_prev == 1 && c_dialect_objc ())
3210 des_seen = des_prev;
3213 if (des_prev == 0 && c_dialect_objc ())
3215 /* This might be an array designator or an
3216 Objective-C message expression. If the former,
3217 continue parsing here; if the latter, parse the
3218 remainder of the initializer given the starting
3219 primary-expression. ??? It might make sense to
3220 distinguish when des_prev == 1 as well; see
3221 previous comment. */
3223 struct c_expr mexpr;
3224 c_parser_consume_token (parser);
3225 if (c_parser_peek_token (parser)->type == CPP_NAME
3226 && ((c_parser_peek_token (parser)->id_kind
3228 || (c_parser_peek_token (parser)->id_kind
3229 == C_ID_CLASSNAME)))
3231 /* Type name receiver. */
3232 tree id = c_parser_peek_token (parser)->value;
3233 c_parser_consume_token (parser);
3234 rec = objc_get_class_reference (id);
3235 goto parse_message_args;
3237 first = c_parser_expr_no_commas (parser, NULL).value;
3238 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3239 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3240 goto array_desig_after_first;
3241 /* Expression receiver. So far only one part
3242 without commas has been parsed; there might be
3243 more of the expression. */
3245 while (c_parser_next_token_is (parser, CPP_COMMA))
3248 c_parser_consume_token (parser);
3249 next = c_parser_expr_no_commas (parser, NULL);
3250 next = default_function_array_conversion (next);
3251 rec = build_compound_expr (rec, next.value);
3254 /* Now parse the objc-message-args. */
3255 args = c_parser_objc_message_args (parser);
3256 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3259 = objc_build_message_expr (build_tree_list (rec, args));
3260 mexpr.original_code = ERROR_MARK;
3261 /* Now parse and process the remainder of the
3262 initializer, starting with this message
3263 expression as a primary-expression. */
3264 c_parser_initval (parser, &mexpr);
3267 c_parser_consume_token (parser);
3268 first = c_parser_expr_no_commas (parser, NULL).value;
3269 array_desig_after_first:
3270 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3272 ellipsis_loc = c_parser_peek_token (parser)->location;
3273 c_parser_consume_token (parser);
3274 second = c_parser_expr_no_commas (parser, NULL).value;
3278 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3280 c_parser_consume_token (parser);
3281 set_init_index (first, second);
3282 if (pedantic && second)
3283 pedwarn ("%HISO C forbids specifying range of "
3284 "elements to initialize", &ellipsis_loc);
3287 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3293 if (c_parser_next_token_is (parser, CPP_EQ))
3295 if (pedantic && !flag_isoc99)
3296 pedwarn ("%HISO C90 forbids specifying subobject "
3297 "to initialize", &des_loc);
3298 c_parser_consume_token (parser);
3305 pedwarn ("%Hobsolete use of designated initializer "
3307 &c_parser_peek_token (parser)->location);
3312 init.value = error_mark_node;
3313 init.original_code = ERROR_MARK;
3314 c_parser_error (parser, "expected %<=%>");
3315 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3316 process_init_element (init);
3322 c_parser_initval (parser, NULL);
3325 /* Parse a nested initializer; as c_parser_initializer but parses
3326 initializers within braced lists, after any designators have been
3327 applied. If AFTER is not NULL then it is an Objective-C message
3328 expression which is the primary-expression starting the
3332 c_parser_initval (c_parser *parser, struct c_expr *after)
3335 gcc_assert (!after || c_dialect_objc ());
3336 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3337 init = c_parser_braced_init (parser, NULL_TREE, true);
3340 init = c_parser_expr_no_commas (parser, after);
3341 if (init.value != NULL_TREE
3342 && TREE_CODE (init.value) != STRING_CST
3343 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3344 init = default_function_array_conversion (init);
3346 process_init_element (init);
3349 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3353 { block-item-list[opt] }
3354 { label-declarations block-item-list }
3358 block-item-list block-item
3370 { label-declarations block-item-list }
3373 __extension__ nested-declaration
3374 nested-function-definition
3378 label-declarations label-declaration
3381 __label__ identifier-list ;
3383 Allowing the mixing of declarations and code is new in C99. The
3384 GNU syntax also permits (not shown above) labels at the end of
3385 compound statements, which yield an error. We don't allow labels
3386 on declarations; this might seem like a natural extension, but
3387 there would be a conflict between attributes on the label and
3388 prefix attributes on the declaration. ??? The syntax follows the
3389 old parser in requiring something after label declarations.
3390 Although they are erroneous if the labels declared aren't defined,
3391 is it useful for the syntax to be this way?
3403 c_parser_compound_statement (c_parser *parser)
3406 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3407 return error_mark_node;
3408 stmt = c_begin_compound_stmt (true);
3409 c_parser_compound_statement_nostart (parser);
3410 return c_end_compound_stmt (stmt, true);
3413 /* Parse a compound statement except for the opening brace. This is
3414 used for parsing both compound statements and statement expressions
3415 (which follow different paths to handling the opening). */
3418 c_parser_compound_statement_nostart (c_parser *parser)
3420 bool last_stmt = false;
3421 bool last_label = false;
3422 location_t label_loc;
3423 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3425 c_parser_consume_token (parser);
3428 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3430 location_t err_loc = c_parser_peek_token (parser)->location;
3431 /* Read zero or more forward-declarations for labels that nested
3432 functions can jump to. */
3433 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3435 c_parser_consume_token (parser);
3436 /* Any identifiers, including those declared as type names,
3441 if (c_parser_next_token_is_not (parser, CPP_NAME))
3443 c_parser_error (parser, "expected identifier");
3447 = declare_label (c_parser_peek_token (parser)->value);
3448 C_DECLARED_LABEL_FLAG (label) = 1;
3449 add_stmt (build_stmt (DECL_EXPR, label));
3450 c_parser_consume_token (parser);
3451 if (c_parser_next_token_is (parser, CPP_COMMA))
3452 c_parser_consume_token (parser);
3456 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3459 pedwarn ("%HISO C forbids label declarations", &err_loc);
3461 /* We must now have at least one statement, label or declaration. */
3462 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3464 c_parser_error (parser, "expected declaration or statement");
3465 c_parser_consume_token (parser);
3468 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3470 location_t loc = c_parser_peek_token (parser)->location;
3471 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3472 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3473 || (c_parser_next_token_is (parser, CPP_NAME)
3474 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3476 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3477 label_loc = c_parser_peek_2nd_token (parser)->location;
3479 label_loc = c_parser_peek_token (parser)->location;
3482 c_parser_label (parser);
3484 else if (!last_label
3485 && c_parser_next_token_starts_declspecs (parser))
3488 c_parser_declaration_or_fndef (parser, true, true, true, true);
3490 && ((pedantic && !flag_isoc99)
3491 || warn_declaration_after_statement))
3492 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3496 else if (!last_label
3497 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3499 /* __extension__ can start a declaration, but is also an
3500 unary operator that can start an expression. Consume all
3501 but the last of a possible series of __extension__ to
3503 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3504 && (c_parser_peek_2nd_token (parser)->keyword
3506 c_parser_consume_token (parser);
3507 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3510 ext = disable_extension_diagnostics ();
3511 c_parser_consume_token (parser);
3513 c_parser_declaration_or_fndef (parser, true, true, true, true);
3514 /* Following the old parser, __extension__ does not
3515 disable this diagnostic. */
3516 restore_extension_diagnostics (ext);
3518 && ((pedantic && !flag_isoc99)
3519 || warn_declaration_after_statement))
3520 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3527 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3529 /* External pragmas, and some omp pragmas, are not associated
3530 with regular c code, and so are not to be considered statements
3531 syntactically. This ensures that the user doesn't put them
3532 places that would turn into syntax errors if the directive
3534 if (c_parser_pragma (parser, pragma_compound))
3535 last_label = false, last_stmt = true;
3537 else if (c_parser_next_token_is (parser, CPP_EOF))
3539 c_parser_error (parser, "expected declaration or statement");
3542 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3544 if (parser->in_if_block)
3546 error ("%H""expected %<}%> before %<else%>", &loc);
3551 error ("%H%<else%> without a previous %<if%>", &loc);
3552 c_parser_consume_token (parser);
3561 c_parser_statement_after_labels (parser);
3564 parser->error = false;
3567 error ("%Hlabel at end of compound statement", &label_loc);
3568 c_parser_consume_token (parser);
3571 /* Parse a label (C90 6.6.1, C99 6.8.1).
3574 identifier : attributes[opt]
3575 case constant-expression :
3581 case constant-expression ... constant-expression :
3583 The use of attributes on labels is a GNU extension. The syntax in
3584 GNU C accepts any expressions without commas, non-constant
3585 expressions being rejected later. */
3588 c_parser_label (c_parser *parser)
3590 location_t loc1 = c_parser_peek_token (parser)->location;
3591 tree label = NULL_TREE;
3592 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3595 c_parser_consume_token (parser);
3596 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3597 if (c_parser_next_token_is (parser, CPP_COLON))
3599 c_parser_consume_token (parser);
3600 label = do_case (exp1, NULL_TREE);
3602 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3604 c_parser_consume_token (parser);
3605 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3606 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3607 label = do_case (exp1, exp2);
3610 c_parser_error (parser, "expected %<:%> or %<...%>");
3612 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3614 c_parser_consume_token (parser);
3615 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3616 label = do_case (NULL_TREE, NULL_TREE);
3620 tree name = c_parser_peek_token (parser)->value;
3623 location_t loc2 = c_parser_peek_token (parser)->location;
3624 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3625 c_parser_consume_token (parser);
3626 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3627 c_parser_consume_token (parser);
3628 attrs = c_parser_attributes (parser);
3629 tlab = define_label (loc2, name);
3632 decl_attributes (&tlab, attrs, 0);
3633 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3638 SET_EXPR_LOCATION (label, loc1);
3639 if (c_parser_next_token_starts_declspecs (parser)
3640 && !(c_parser_next_token_is (parser, CPP_NAME)
3641 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3643 error ("%Ha label can only be part of a statement and "
3644 "a declaration is not a statement",
3645 &c_parser_peek_token (parser)->location);
3646 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3647 /*nested*/ true, /*empty_ok*/ false,
3648 /*start_attr_ok*/ true);
3653 /* Parse a statement (C90 6.6, C99 6.8).
3658 expression-statement
3666 expression-statement:
3669 selection-statement:
3673 iteration-statement:
3682 return expression[opt] ;
3695 objc-throw-statement
3696 objc-try-catch-statement
3697 objc-synchronized-statement
3699 objc-throw-statement:
3713 parallel-for-construct
3714 parallel-sections-construct
3721 parallel-directive structured-block
3724 for-directive iteration-statement
3727 sections-directive section-scope
3730 single-directive structured-block
3732 parallel-for-construct:
3733 parallel-for-directive iteration-statement
3735 parallel-sections-construct:
3736 parallel-sections-directive section-scope
3739 master-directive structured-block
3742 critical-directive structured-block
3745 atomic-directive expression-statement
3748 ordered-directive structured-block */
3751 c_parser_statement (c_parser *parser)
3753 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3754 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3755 || (c_parser_next_token_is (parser, CPP_NAME)
3756 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3757 c_parser_label (parser);
3758 c_parser_statement_after_labels (parser);
3761 /* Parse a statement, other than a labeled statement. */
3764 c_parser_statement_after_labels (c_parser *parser)
3766 location_t loc = c_parser_peek_token (parser)->location;
3767 tree stmt = NULL_TREE;
3768 bool in_if_block = parser->in_if_block;
3769 parser->in_if_block = false;
3770 switch (c_parser_peek_token (parser)->type)
3772 case CPP_OPEN_BRACE:
3773 add_stmt (c_parser_compound_statement (parser));
3776 switch (c_parser_peek_token (parser)->keyword)
3779 c_parser_if_statement (parser);
3782 c_parser_switch_statement (parser);
3785 c_parser_while_statement (parser);
3788 c_parser_do_statement (parser);
3791 c_parser_for_statement (parser);
3794 c_parser_consume_token (parser);
3795 if (c_parser_next_token_is (parser, CPP_NAME))
3797 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3798 c_parser_consume_token (parser);
3800 else if (c_parser_next_token_is (parser, CPP_MULT))
3802 c_parser_consume_token (parser);
3803 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3806 c_parser_error (parser, "expected identifier or %<*%>");
3807 goto expect_semicolon;
3809 c_parser_consume_token (parser);
3810 stmt = c_finish_bc_stmt (&c_cont_label, false);
3811 goto expect_semicolon;
3813 c_parser_consume_token (parser);
3814 stmt = c_finish_bc_stmt (&c_break_label, true);
3815 goto expect_semicolon;
3817 c_parser_consume_token (parser);
3818 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3820 stmt = c_finish_return (NULL_TREE);
3821 c_parser_consume_token (parser);
3825 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3826 goto expect_semicolon;
3830 stmt = c_parser_asm_statement (parser);
3833 gcc_assert (c_dialect_objc ());
3834 c_parser_consume_token (parser);
3835 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3837 stmt = objc_build_throw_stmt (NULL_TREE);
3838 c_parser_consume_token (parser);
3843 = objc_build_throw_stmt (c_parser_expression (parser).value);
3844 goto expect_semicolon;
3848 gcc_assert (c_dialect_objc ());
3849 c_parser_objc_try_catch_statement (parser);
3851 case RID_AT_SYNCHRONIZED:
3852 gcc_assert (c_dialect_objc ());
3853 c_parser_objc_synchronized_statement (parser);
3860 c_parser_consume_token (parser);
3862 case CPP_CLOSE_PAREN:
3863 case CPP_CLOSE_SQUARE:
3864 /* Avoid infinite loop in error recovery:
3865 c_parser_skip_until_found stops at a closing nesting
3866 delimiter without consuming it, but here we need to consume
3867 it to proceed further. */
3868 c_parser_error (parser, "expected statement");
3869 c_parser_consume_token (parser);
3872 c_parser_pragma (parser, pragma_stmt);
3876 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3878 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3881 /* Two cases cannot and do not have line numbers associated: If stmt
3882 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3883 cannot hold line numbers. But that's OK because the statement
3884 will either be changed to a MODIFY_EXPR during gimplification of
3885 the statement expr, or discarded. If stmt was compound, but
3886 without new variables, we will have skipped the creation of a
3887 BIND and will have a bare STATEMENT_LIST. But that's OK because
3888 (recursively) all of the component statements should already have
3889 line numbers assigned. ??? Can we discard no-op statements
3891 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3892 SET_EXPR_LOCATION (stmt, loc);
3894 parser->in_if_block = in_if_block;
3897 /* Parse a parenthesized condition from an if, do or while statement.
3903 c_parser_paren_condition (c_parser *parser)
3907 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3908 return error_mark_node;
3909 loc = c_parser_peek_token (parser)->location;
3910 cond = c_objc_common_truthvalue_conversion
3911 (c_parser_expression_conv (parser).value);
3912 if (CAN_HAVE_LOCATION_P (cond))
3913 SET_EXPR_LOCATION (cond, loc);
3914 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3918 /* Parse a statement which is a block in C99. */
3921 c_parser_c99_block_statement (c_parser *parser)
3923 tree block = c_begin_compound_stmt (flag_isoc99);
3924 c_parser_statement (parser);
3925 return c_end_compound_stmt (block, flag_isoc99);
3928 /* Parse the body of an if statement. This is just parsing a
3929 statement but (a) it is a block in C99, (b) we track whether the
3930 body is an if statement for the sake of -Wparentheses warnings, (c)
3931 we handle an empty body specially for the sake of -Wempty-body
3932 warnings, and (d) we call parser_compound_statement directly
3933 because c_parser_statement_after_labels resets
3934 parser->in_if_block. */
3937 c_parser_if_body (c_parser *parser, bool *if_p)
3939 tree block = c_begin_compound_stmt (flag_isoc99);
3940 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3941 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3942 || (c_parser_next_token_is (parser, CPP_NAME)
3943 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3944 c_parser_label (parser);
3945 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3946 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3948 add_stmt (build_empty_stmt ());
3949 c_parser_consume_token (parser);
3951 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3952 add_stmt (c_parser_compound_statement (parser));
3954 c_parser_statement_after_labels (parser);
3955 return c_end_compound_stmt (block, flag_isoc99);
3958 /* Parse the else body of an if statement. This is just parsing a
3959 statement but (a) it is a block in C99, (b) we handle an empty body
3960 specially for the sake of -Wempty-body warnings. */
3963 c_parser_else_body (c_parser *parser)
3965 tree block = c_begin_compound_stmt (flag_isoc99);
3966 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3967 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3968 || (c_parser_next_token_is (parser, CPP_NAME)
3969 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3970 c_parser_label (parser);
3971 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3973 add_stmt (build_empty_stmt ());
3974 c_parser_consume_token (parser);
3977 c_parser_statement_after_labels (parser);
3978 return c_end_compound_stmt (block, flag_isoc99);
3981 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3984 if ( expression ) statement
3985 if ( expression ) statement else statement
3989 c_parser_if_statement (c_parser *parser)
3994 bool first_if = false;
3995 tree first_body, second_body;
3998 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3999 c_parser_consume_token (parser);
4000 block = c_begin_compound_stmt (flag_isoc99);
4001 loc = c_parser_peek_token (parser)->location;
4002 cond = c_parser_paren_condition (parser);
4003 in_if_block = parser->in_if_block;
4004 parser->in_if_block = true;
4005 first_body = c_parser_if_body (parser, &first_if);
4006 parser->in_if_block = in_if_block;
4007 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4009 c_parser_consume_token (parser);
4010 second_body = c_parser_else_body (parser);
4013 second_body = NULL_TREE;
4014 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4015 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4018 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4021 switch (expression) statement
4025 c_parser_switch_statement (c_parser *parser)
4027 tree block, expr, body, save_break;
4028 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4029 c_parser_consume_token (parser);
4030 block = c_begin_compound_stmt (flag_isoc99);
4031 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4033 expr = c_parser_expression (parser).value;
4034 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4037 expr = error_mark_node;
4038 c_start_case (expr);
4039 save_break = c_break_label;
4040 c_break_label = NULL_TREE;
4041 body = c_parser_c99_block_statement (parser);
4042 c_finish_case (body);
4044 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
4045 c_break_label = save_break;
4046 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4049 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4052 while (expression) statement
4056 c_parser_while_statement (c_parser *parser)
4058 tree block, cond, body, save_break, save_cont;
4060 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4061 c_parser_consume_token (parser);
4062 block = c_begin_compound_stmt (flag_isoc99);
4063 loc = c_parser_peek_token (parser)->location;
4064 cond = c_parser_paren_condition (parser);
4065 save_break = c_break_label;
4066 c_break_label = NULL_TREE;
4067 save_cont = c_cont_label;
4068 c_cont_label = NULL_TREE;
4069 body = c_parser_c99_block_statement (parser);
4070 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4071 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4072 c_break_label = save_break;
4073 c_cont_label = save_cont;
4076 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4079 do statement while ( expression ) ;
4083 c_parser_do_statement (c_parser *parser)
4085 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4087 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4088 c_parser_consume_token (parser);
4089 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4090 warning (OPT_Wempty_body,
4091 "%Hsuggest braces around empty body in %<do%> statement",
4092 &c_parser_peek_token (parser)->location);
4093 block = c_begin_compound_stmt (flag_isoc99);
4094 loc = c_parser_peek_token (parser)->location;
4095 save_break = c_break_label;
4096 c_break_label = NULL_TREE;
4097 save_cont = c_cont_label;
4098 c_cont_label = NULL_TREE;
4099 body = c_parser_c99_block_statement (parser);
4100 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4101 new_break = c_break_label;
4102 c_break_label = save_break;
4103 new_cont = c_cont_label;
4104 c_cont_label = save_cont;
4105 cond = c_parser_paren_condition (parser);
4106 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4107 c_parser_skip_to_end_of_block_or_statement (parser);
4108 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4109 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4112 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4115 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4116 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4118 The form with a declaration is new in C99.
4120 ??? In accordance with the old parser, the declaration may be a
4121 nested function, which is then rejected in check_for_loop_decls,
4122 but does it make any sense for this to be included in the grammar?
4123 Note in particular that the nested function does not include a
4124 trailing ';', whereas the "declaration" production includes one.
4125 Also, can we reject bad declarations earlier and cheaper than
4126 check_for_loop_decls? */
4129 c_parser_for_statement (c_parser *parser)
4131 tree block, cond, incr, save_break, save_cont, body;
4133 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4134 loc = c_parser_peek_token (parser)->location;
4135 c_parser_consume_token (parser);
4136 block = c_begin_compound_stmt (flag_isoc99);
4137 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4139 /* Parse the initialization declaration or expression. */
4140 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4142 c_parser_consume_token (parser);
4143 c_finish_expr_stmt (NULL_TREE);
4145 else if (c_parser_next_token_starts_declspecs (parser))
4147 c_parser_declaration_or_fndef (parser, true, true, true, true);
4148 check_for_loop_decls ();
4150 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4152 /* __extension__ can start a declaration, but is also an
4153 unary operator that can start an expression. Consume all
4154 but the last of a possible series of __extension__ to
4156 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4157 && (c_parser_peek_2nd_token (parser)->keyword
4159 c_parser_consume_token (parser);
4160 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4163 ext = disable_extension_diagnostics ();
4164 c_parser_consume_token (parser);
4165 c_parser_declaration_or_fndef (parser, true, true, true, true);
4166 restore_extension_diagnostics (ext);
4167 check_for_loop_decls ();
4175 c_finish_expr_stmt (c_parser_expression (parser).value);
4176 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4178 /* Parse the loop condition. */
4179 loc = c_parser_peek_token (parser)->location;
4180 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4182 c_parser_consume_token (parser);
4187 tree ocond = c_parser_expression_conv (parser).value;
4188 cond = c_objc_common_truthvalue_conversion (ocond);
4189 if (CAN_HAVE_LOCATION_P (cond))
4190 SET_EXPR_LOCATION (cond, loc);
4191 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4193 /* Parse the increment expression. */
4194 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4195 incr = c_process_expr_stmt (NULL_TREE);
4197 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4198 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4202 cond = error_mark_node;
4203 incr = error_mark_node;
4205 save_break = c_break_label;
4206 c_break_label = NULL_TREE;
4207 save_cont = c_cont_label;
4208 c_cont_label = NULL_TREE;
4209 body = c_parser_c99_block_statement (parser);
4210 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4211 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4212 c_break_label = save_break;
4213 c_cont_label = save_cont;
4216 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4217 statement with inputs, outputs, clobbers, and volatile tag
4221 asm type-qualifier[opt] ( asm-argument ) ;
4225 asm-string-literal : asm-operands[opt]
4226 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4227 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4229 Qualifiers other than volatile are accepted in the syntax but
4233 c_parser_asm_statement (c_parser *parser)
4235 tree quals, str, outputs, inputs, clobbers, ret;
4237 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4238 c_parser_consume_token (parser);
4239 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4241 quals = c_parser_peek_token (parser)->value;
4242 c_parser_consume_token (parser);
4244 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4245 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4247 warning (0, "%H%E qualifier ignored on asm",
4248 &c_parser_peek_token (parser)->location,
4249 c_parser_peek_token (parser)->value);
4251 c_parser_consume_token (parser);
4255 /* ??? Follow the C++ parser rather than using the
4256 lex_untranslated_string kludge. */
4257 parser->lex_untranslated_string = true;
4258 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4260 parser->lex_untranslated_string = false;
4263 str = c_parser_asm_string_literal (parser);
4264 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4267 outputs = NULL_TREE;
4269 clobbers = NULL_TREE;
4272 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4274 parser->lex_untranslated_string = false;
4275 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4279 /* Parse outputs. */
4280 if (c_parser_next_token_is (parser, CPP_COLON)
4281 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4282 outputs = NULL_TREE;
4284 outputs = c_parser_asm_operands (parser, false);
4285 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4288 clobbers = NULL_TREE;
4291 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4293 parser->lex_untranslated_string = false;
4294 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4298 if (c_parser_next_token_is (parser, CPP_COLON)
4299 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4302 inputs = c_parser_asm_operands (parser, true);
4303 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4305 clobbers = NULL_TREE;
4308 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4310 parser->lex_untranslated_string = false;
4311 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4314 /* Parse clobbers. */
4315 clobbers = c_parser_asm_clobbers (parser);
4317 parser->lex_untranslated_string = false;
4318 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4323 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4324 c_parser_skip_to_end_of_block_or_statement (parser);
4325 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4330 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4331 not outputs), apply the default conversion of functions and arrays
4336 asm-operands , asm-operand
4339 asm-string-literal ( expression )
4340 [ identifier ] asm-string-literal ( expression )
4344 c_parser_asm_operands (c_parser *parser, bool convert_p)
4346 tree list = NULL_TREE;
4351 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4353 c_parser_consume_token (parser);
4354 if (c_parser_next_token_is (parser, CPP_NAME))
4356 tree id = c_parser_peek_token (parser)->value;
4357 c_parser_consume_token (parser);
4358 name = build_string (IDENTIFIER_LENGTH (id),
4359 IDENTIFIER_POINTER (id));
4363 c_parser_error (parser, "expected identifier");
4364 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4367 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4372 str = c_parser_asm_string_literal (parser);
4373 if (str == NULL_TREE)
4375 parser->lex_untranslated_string = false;
4376 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4378 parser->lex_untranslated_string = true;
4381 expr = c_parser_expression (parser);
4383 expr = default_function_array_conversion (expr);
4384 parser->lex_untranslated_string = true;
4385 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4387 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4390 list = chainon (list, build_tree_list (build_tree_list (name, str),
4392 if (c_parser_next_token_is (parser, CPP_COMMA))
4393 c_parser_consume_token (parser);
4400 /* Parse asm clobbers, a GNU extension.
4404 asm-clobbers , asm-string-literal
4408 c_parser_asm_clobbers (c_parser *parser)
4410 tree list = NULL_TREE;
4413 tree str = c_parser_asm_string_literal (parser);
4415 list = tree_cons (NULL_TREE, str, list);
4418 if (c_parser_next_token_is (parser, CPP_COMMA))
4419 c_parser_consume_token (parser);
4426 /* Parse an expression other than a compound expression; that is, an
4427 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4428 NULL then it is an Objective-C message expression which is the
4429 primary-expression starting the expression as an initializer.
4431 assignment-expression:
4432 conditional-expression
4433 unary-expression assignment-operator assignment-expression
4435 assignment-operator: one of
4436 = *= /= %= += -= <<= >>= &= ^= |=
4438 In GNU C we accept any conditional expression on the LHS and
4439 diagnose the invalid lvalue rather than producing a syntax
4442 static struct c_expr
4443 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4445 struct c_expr lhs, rhs, ret;
4446 enum tree_code code;
4447 gcc_assert (!after || c_dialect_objc ());
4448 lhs = c_parser_conditional_expression (parser, after);
4449 switch (c_parser_peek_token (parser)->type)
4458 code = TRUNC_DIV_EXPR;
4461 code = TRUNC_MOD_EXPR;
4476 code = BIT_AND_EXPR;
4479 code = BIT_XOR_EXPR;
4482 code = BIT_IOR_EXPR;
4487 c_parser_consume_token (parser);
4488 rhs = c_parser_expr_no_commas (parser, NULL);
4489 rhs = default_function_array_conversion (rhs);
4490 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4491 if (code == NOP_EXPR)
4492 ret.original_code = MODIFY_EXPR;
4495 TREE_NO_WARNING (ret.value) = 1;
4496 ret.original_code = ERROR_MARK;
4501 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4502 is not NULL then it is an Objective-C message expression which is
4503 the primary-expression starting the expression as an initializer.
4505 conditional-expression:
4506 logical-OR-expression
4507 logical-OR-expression ? expression : conditional-expression
4511 conditional-expression:
4512 logical-OR-expression ? : conditional-expression
4515 static struct c_expr
4516 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4518 struct c_expr cond, exp1, exp2, ret;
4519 gcc_assert (!after || c_dialect_objc ());
4520 cond = c_parser_binary_expression (parser, after);
4521 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4523 cond = default_function_array_conversion (cond);
4524 c_parser_consume_token (parser);
4525 if (c_parser_next_token_is (parser, CPP_COLON))
4528 pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
4529 &c_parser_peek_token (parser)->location);
4530 /* Make sure first operand is calculated only once. */
4531 exp1.value = save_expr (default_conversion (cond.value));
4532 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4533 skip_evaluation += cond.value == truthvalue_true_node;
4538 = c_objc_common_truthvalue_conversion
4539 (default_conversion (cond.value));
4540 skip_evaluation += cond.value == truthvalue_false_node;
4541 exp1 = c_parser_expression_conv (parser);
4542 skip_evaluation += ((cond.value == truthvalue_true_node)
4543 - (cond.value == truthvalue_false_node));
4545 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4547 skip_evaluation -= cond.value == truthvalue_true_node;
4548 ret.value = error_mark_node;
4549 ret.original_code = ERROR_MARK;
4552 exp2 = c_parser_conditional_expression (parser, NULL);
4553 exp2 = default_function_array_conversion (exp2);
4554 skip_evaluation -= cond.value == truthvalue_true_node;
4555 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4556 ret.original_code = ERROR_MARK;
4560 /* Parse a binary expression; that is, a logical-OR-expression (C90
4561 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4562 an Objective-C message expression which is the primary-expression
4563 starting the expression as an initializer.
4565 multiplicative-expression:
4567 multiplicative-expression * cast-expression
4568 multiplicative-expression / cast-expression
4569 multiplicative-expression % cast-expression
4571 additive-expression:
4572 multiplicative-expression
4573 additive-expression + multiplicative-expression
4574 additive-expression - multiplicative-expression
4578 shift-expression << additive-expression
4579 shift-expression >> additive-expression
4581 relational-expression:
4583 relational-expression < shift-expression
4584 relational-expression > shift-expression
4585 relational-expression <= shift-expression
4586 relational-expression >= shift-expression
4588 equality-expression:
4589 relational-expression
4590 equality-expression == relational-expression
4591 equality-expression != relational-expression
4595 AND-expression & equality-expression
4597 exclusive-OR-expression:
4599 exclusive-OR-expression ^ AND-expression
4601 inclusive-OR-expression:
4602 exclusive-OR-expression
4603 inclusive-OR-expression | exclusive-OR-expression
4605 logical-AND-expression:
4606 inclusive-OR-expression
4607 logical-AND-expression && inclusive-OR-expression
4609 logical-OR-expression:
4610 logical-AND-expression
4611 logical-OR-expression || logical-AND-expression
4614 static struct c_expr
4615 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4617 /* A binary expression is parsed using operator-precedence parsing,
4618 with the operands being cast expressions. All the binary
4619 operators are left-associative. Thus a binary expression is of
4622 E0 op1 E1 op2 E2 ...
4624 which we represent on a stack. On the stack, the precedence
4625 levels are strictly increasing. When a new operator is
4626 encountered of higher precedence than that at the top of the
4627 stack, it is pushed; its LHS is the top expression, and its RHS
4628 is everything parsed until it is popped. When a new operator is
4629 encountered with precedence less than or equal to that at the top
4630 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4631 by the result of the operation until the operator at the top of
4632 the stack has lower precedence than the new operator or there is
4633 only one element on the stack; then the top expression is the LHS
4634 of the new operator. In the case of logical AND and OR
4635 expressions, we also need to adjust skip_evaluation as
4636 appropriate when the operators are pushed and popped. */
4638 /* The precedence levels, where 0 is a dummy lowest level used for
4639 the bottom of the stack. */
4655 /* The expression at this stack level. */
4657 /* The precedence of the operator on its left, PREC_NONE at the
4658 bottom of the stack. */
4660 /* The operation on its left. */
4666 switch (stack[sp].op) \
4668 case TRUTH_ANDIF_EXPR: \
4669 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4671 case TRUTH_ORIF_EXPR: \
4672 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4677 stack[sp - 1].expr \
4678 = default_function_array_conversion (stack[sp - 1].expr); \
4680 = default_function_array_conversion (stack[sp].expr); \
4681 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4682 stack[sp - 1].expr, \
4686 gcc_assert (!after || c_dialect_objc ());
4687 stack[0].expr = c_parser_cast_expression (parser, after);
4688 stack[0].prec = PREC_NONE;
4693 enum tree_code ocode;
4696 switch (c_parser_peek_token (parser)->type)
4704 ocode = TRUNC_DIV_EXPR;
4708 ocode = TRUNC_MOD_EXPR;
4720 ocode = LSHIFT_EXPR;
4724 ocode = RSHIFT_EXPR;
4738 case CPP_GREATER_EQ:
4751 oprec = PREC_BITAND;
4752 ocode = BIT_AND_EXPR;
4755 oprec = PREC_BITXOR;
4756 ocode = BIT_XOR_EXPR;
4760 ocode = BIT_IOR_EXPR;
4763 oprec = PREC_LOGAND;
4764 ocode = TRUTH_ANDIF_EXPR;
4768 ocode = TRUTH_ORIF_EXPR;
4771 /* Not a binary operator, so end of the binary
4775 c_parser_consume_token (parser);
4776 while (oprec <= stack[sp].prec)
4780 case TRUTH_ANDIF_EXPR:
4782 = default_function_array_conversion (stack[sp].expr);
4783 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4784 (default_conversion (stack[sp].expr.value));
4785 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4787 case TRUTH_ORIF_EXPR:
4789 = default_function_array_conversion (stack[sp].expr);
4790 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4791 (default_conversion (stack[sp].expr.value));
4792 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4798 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4799 stack[sp].prec = oprec;
4800 stack[sp].op = ocode;
4805 return stack[0].expr;
4809 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4810 NULL then it is an Objective-C message expression which is the
4811 primary-expression starting the expression as an initializer.
4815 ( type-name ) unary-expression
4818 static struct c_expr
4819 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4821 gcc_assert (!after || c_dialect_objc ());
4823 return c_parser_postfix_expression_after_primary (parser, *after);
4824 /* If the expression begins with a parenthesized type name, it may
4825 be either a cast or a compound literal; we need to see whether
4826 the next character is '{' to tell the difference. If not, it is
4827 an unary expression. */
4828 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4829 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4831 struct c_type_name *type_name;
4834 c_parser_consume_token (parser);
4835 type_name = c_parser_type_name (parser);
4836 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4837 if (type_name == NULL)
4839 ret.value = error_mark_node;
4840 ret.original_code = ERROR_MARK;
4844 /* Save casted types in the function's used types hash table. */
4845 used_types_insert (type_name->specs->type);
4847 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4848 return c_parser_postfix_expression_after_paren_type (parser,
4850 expr = c_parser_cast_expression (parser, NULL);
4851 expr = default_function_array_conversion (expr);
4852 ret.value = c_cast_expr (type_name, expr.value);
4853 ret.original_code = ERROR_MARK;
4857 return c_parser_unary_expression (parser);
4860 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4866 unary-operator cast-expression
4867 sizeof unary-expression
4868 sizeof ( type-name )
4870 unary-operator: one of
4876 __alignof__ unary-expression
4877 __alignof__ ( type-name )
4880 unary-operator: one of
4881 __extension__ __real__ __imag__
4883 In addition, the GNU syntax treats ++ and -- as unary operators, so
4884 they may be applied to cast expressions with errors for non-lvalues
4887 static struct c_expr
4888 c_parser_unary_expression (c_parser *parser)
4891 struct c_expr ret, op;
4892 switch (c_parser_peek_token (parser)->type)
4895 c_parser_consume_token (parser);
4896 op = c_parser_cast_expression (parser, NULL);
4897 op = default_function_array_conversion (op);
4898 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4899 case CPP_MINUS_MINUS:
4900 c_parser_consume_token (parser);
4901 op = c_parser_cast_expression (parser, NULL);
4902 op = default_function_array_conversion (op);
4903 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4905 c_parser_consume_token (parser);
4906 return parser_build_unary_op (ADDR_EXPR,
4907 c_parser_cast_expression (parser, NULL));
4909 c_parser_consume_token (parser);
4910 op = c_parser_cast_expression (parser, NULL);
4911 op = default_function_array_conversion (op);
4912 ret.value = build_indirect_ref (op.value, "unary *");
4913 ret.original_code = ERROR_MARK;
4916 if (!c_dialect_objc () && !in_system_header)
4917 warning (OPT_Wtraditional,
4918 "%Htraditional C rejects the unary plus operator",
4919 &c_parser_peek_token (parser)->location);
4920 c_parser_consume_token (parser);
4921 op = c_parser_cast_expression (parser, NULL);
4922 op = default_function_array_conversion (op);
4923 return parser_build_unary_op (CONVERT_EXPR, op);
4925 c_parser_consume_token (parser);
4926 op = c_parser_cast_expression (parser, NULL);
4927 op = default_function_array_conversion (op);
4928 return parser_build_unary_op (NEGATE_EXPR, op);
4930 c_parser_consume_token (parser);
4931 op = c_parser_cast_expression (parser, NULL);
4932 op = default_function_array_conversion (op);
4933 return parser_build_unary_op (BIT_NOT_EXPR, op);
4935 c_parser_consume_token (parser);
4936 op = c_parser_cast_expression (parser, NULL);
4937 op = default_function_array_conversion (op);
4938 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4940 /* Refer to the address of a label as a pointer. */
4941 c_parser_consume_token (parser);
4942 if (c_parser_next_token_is (parser, CPP_NAME))
4944 ret.value = finish_label_address_expr
4945 (c_parser_peek_token (parser)->value);
4946 c_parser_consume_token (parser);
4950 c_parser_error (parser, "expected identifier");
4951 ret.value = error_mark_node;
4953 ret.original_code = ERROR_MARK;
4956 switch (c_parser_peek_token (parser)->keyword)
4959 return c_parser_sizeof_expression (parser);
4961 return c_parser_alignof_expression (parser);
4963 c_parser_consume_token (parser);
4964 ext = disable_extension_diagnostics ();
4965 ret = c_parser_cast_expression (parser, NULL);
4966 restore_extension_diagnostics (ext);
4969 c_parser_consume_token (parser);
4970 op = c_parser_cast_expression (parser, NULL);
4971 op = default_function_array_conversion (op);
4972 return parser_build_unary_op (REALPART_EXPR, op);
4974 c_parser_consume_token (parser);
4975 op = c_parser_cast_expression (parser, NULL);
4976 op = default_function_array_conversion (op);
4977 return parser_build_unary_op (IMAGPART_EXPR, op);
4979 return c_parser_postfix_expression (parser);
4982 return c_parser_postfix_expression (parser);
4986 /* Parse a sizeof expression. */
4988 static struct c_expr
4989 c_parser_sizeof_expression (c_parser *parser)
4992 location_t expr_loc;
4993 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4994 c_parser_consume_token (parser);
4997 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4998 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5000 /* Either sizeof ( type-name ) or sizeof unary-expression
5001 starting with a compound literal. */
5002 struct c_type_name *type_name;
5003 c_parser_consume_token (parser);
5004 expr_loc = c_parser_peek_token (parser)->location;
5005 type_name = c_parser_type_name (parser);
5006 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5007 if (type_name == NULL)
5012 ret.value = error_mark_node;
5013 ret.original_code = ERROR_MARK;
5016 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5018 expr = c_parser_postfix_expression_after_paren_type (parser,
5022 /* sizeof ( type-name ). */
5025 if (type_name->declarator->kind == cdk_array
5026 && type_name->declarator->u.array.vla_unspec_p)
5029 error ("%H%<[*]%> not allowed in other than a declaration",
5032 return c_expr_sizeof_type (type_name);
5036 expr_loc = c_parser_peek_token (parser)->location;
5037 expr = c_parser_unary_expression (parser);
5041 if (TREE_CODE (expr.value) == COMPONENT_REF
5042 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5043 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
5044 return c_expr_sizeof_expr (expr);
5048 /* Parse an alignof expression. */
5050 static struct c_expr
5051 c_parser_alignof_expression (c_parser *parser)
5054 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5055 c_parser_consume_token (parser);
5058 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5059 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5061 /* Either __alignof__ ( type-name ) or __alignof__
5062 unary-expression starting with a compound literal. */
5063 struct c_type_name *type_name;
5065 c_parser_consume_token (parser);
5066 type_name = c_parser_type_name (parser);
5067 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5068 if (type_name == NULL)
5073 ret.value = error_mark_node;
5074 ret.original_code = ERROR_MARK;
5077 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5079 expr = c_parser_postfix_expression_after_paren_type (parser,
5083 /* alignof ( type-name ). */
5086 ret.value = c_alignof (groktypename (type_name));
5087 ret.original_code = ERROR_MARK;
5093 expr = c_parser_unary_expression (parser);
5097 ret.value = c_alignof_expr (expr.value);
5098 ret.original_code = ERROR_MARK;
5103 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5107 postfix-expression [ expression ]
5108 postfix-expression ( argument-expression-list[opt] )
5109 postfix-expression . identifier
5110 postfix-expression -> identifier
5111 postfix-expression ++
5112 postfix-expression --
5113 ( type-name ) { initializer-list }
5114 ( type-name ) { initializer-list , }
5116 argument-expression-list:
5118 argument-expression-list , argument-expression
5130 (treated as a keyword in GNU C)
5133 ( compound-statement )
5134 __builtin_va_arg ( assignment-expression , type-name )
5135 __builtin_offsetof ( type-name , offsetof-member-designator )
5136 __builtin_choose_expr ( assignment-expression ,
5137 assignment-expression ,
5138 assignment-expression )
5139 __builtin_types_compatible_p ( type-name , type-name )
5141 offsetof-member-designator:
5143 offsetof-member-designator . identifier
5144 offsetof-member-designator [ expression ]
5149 [ objc-receiver objc-message-args ]
5150 @selector ( objc-selector-arg )
5151 @protocol ( identifier )
5152 @encode ( type-name )
5156 static struct c_expr
5157 c_parser_postfix_expression (c_parser *parser)
5159 struct c_expr expr, e1, e2, e3;
5160 struct c_type_name *t1, *t2;
5162 switch (c_parser_peek_token (parser)->type)
5169 expr.value = c_parser_peek_token (parser)->value;
5170 expr.original_code = ERROR_MARK;
5171 c_parser_consume_token (parser);
5177 expr.value = c_parser_peek_token (parser)->value;
5178 expr.original_code = STRING_CST;
5179 c_parser_consume_token (parser);
5181 case CPP_OBJC_STRING:
5182 gcc_assert (c_dialect_objc ());
5184 = objc_build_string_object (c_parser_peek_token (parser)->value);
5185 expr.original_code = ERROR_MARK;
5186 c_parser_consume_token (parser);
5189 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5191 c_parser_error (parser, "expected expression");
5192 expr.value = error_mark_node;
5193 expr.original_code = ERROR_MARK;
5197 tree id = c_parser_peek_token (parser)->value;
5198 location_t loc = c_parser_peek_token (parser)->location;
5199 c_parser_consume_token (parser);
5200 expr.value = build_external_ref (id,
5201 (c_parser_peek_token (parser)->type
5202 == CPP_OPEN_PAREN), loc);
5203 expr.original_code = ERROR_MARK;
5206 case CPP_OPEN_PAREN:
5207 /* A parenthesized expression, statement expression or compound
5209 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5211 /* A statement expression. */
5213 location_t here = c_parser_peek_token (parser)->location;
5214 c_parser_consume_token (parser);
5215 c_parser_consume_token (parser);
5216 if (cur_stmt_list == NULL)
5218 error ("%Hbraced-group within expression allowed "
5219 "only inside a function", &here);
5220 parser->error = true;
5221 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5222 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5223 expr.value = error_mark_node;
5224 expr.original_code = ERROR_MARK;
5227 stmt = c_begin_stmt_expr ();
5228 c_parser_compound_statement_nostart (parser);
5229 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5232 pedwarn ("%HISO C forbids braced-groups within expressions",
5234 expr.value = c_finish_stmt_expr (stmt);
5235 expr.original_code = ERROR_MARK;
5237 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5239 /* A compound literal. ??? Can we actually get here rather
5240 than going directly to
5241 c_parser_postfix_expression_after_paren_type from
5243 struct c_type_name *type_name;
5244 c_parser_consume_token (parser);
5245 type_name = c_parser_type_name (parser);
5246 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5248 if (type_name == NULL)
5250 expr.value = error_mark_node;
5251 expr.original_code = ERROR_MARK;
5254 expr = c_parser_postfix_expression_after_paren_type (parser,
5259 /* A parenthesized expression. */
5260 c_parser_consume_token (parser);
5261 expr = c_parser_expression (parser);
5262 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5263 TREE_NO_WARNING (expr.value) = 1;
5264 expr.original_code = ERROR_MARK;
5265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5270 switch (c_parser_peek_token (parser)->keyword)
5272 case RID_FUNCTION_NAME:
5273 case RID_PRETTY_FUNCTION_NAME:
5274 case RID_C99_FUNCTION_NAME:
5275 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5276 c_parser_peek_token (parser)->value);
5277 expr.original_code = ERROR_MARK;
5278 c_parser_consume_token (parser);
5281 c_parser_consume_token (parser);
5282 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5284 expr.value = error_mark_node;
5285 expr.original_code = ERROR_MARK;
5288 e1 = c_parser_expr_no_commas (parser, NULL);
5289 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5291 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5292 expr.value = error_mark_node;
5293 expr.original_code = ERROR_MARK;
5296 t1 = c_parser_type_name (parser);
5297 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5301 expr.value = error_mark_node;
5302 expr.original_code = ERROR_MARK;
5306 expr.value = build_va_arg (e1.value, groktypename (t1));
5307 expr.original_code = ERROR_MARK;
5311 c_parser_consume_token (parser);
5312 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5314 expr.value = error_mark_node;
5315 expr.original_code = ERROR_MARK;
5318 t1 = c_parser_type_name (parser);
5321 expr.value = error_mark_node;
5322 expr.original_code = ERROR_MARK;
5325 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5327 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5328 expr.value = error_mark_node;
5329 expr.original_code = ERROR_MARK;
5333 tree type = groktypename (t1);
5335 if (type == error_mark_node)
5336 offsetof_ref = error_mark_node;
5338 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5339 /* Parse the second argument to __builtin_offsetof. We
5340 must have one identifier, and beyond that we want to
5341 accept sub structure and sub array references. */
5342 if (c_parser_next_token_is (parser, CPP_NAME))
5344 offsetof_ref = build_component_ref
5345 (offsetof_ref, c_parser_peek_token (parser)->value);
5346 c_parser_consume_token (parser);
5347 while (c_parser_next_token_is (parser, CPP_DOT)
5348 || c_parser_next_token_is (parser,
5351 if (c_parser_next_token_is (parser, CPP_DOT))
5353 c_parser_consume_token (parser);
5354 if (c_parser_next_token_is_not (parser,
5357 c_parser_error (parser, "expected identifier");
5360 offsetof_ref = build_component_ref
5362 c_parser_peek_token (parser)->value);
5363 c_parser_consume_token (parser);
5368 c_parser_consume_token (parser);
5369 idx = c_parser_expression (parser).value;
5370 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5372 offsetof_ref = build_array_ref (offsetof_ref, idx);
5377 c_parser_error (parser, "expected identifier");
5378 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5380 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5381 expr.original_code = ERROR_MARK;
5384 case RID_CHOOSE_EXPR:
5385 c_parser_consume_token (parser);
5386 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5388 expr.value = error_mark_node;
5389 expr.original_code = ERROR_MARK;
5392 loc = c_parser_peek_token (parser)->location;
5393 e1 = c_parser_expr_no_commas (parser, NULL);
5394 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5397 expr.value = error_mark_node;
5398 expr.original_code = ERROR_MARK;
5401 e2 = c_parser_expr_no_commas (parser, NULL);
5402 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5404 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5405 expr.value = error_mark_node;
5406 expr.original_code = ERROR_MARK;
5409 e3 = c_parser_expr_no_commas (parser, NULL);
5410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5415 c = fold (e1.value);
5416 if (TREE_CODE (c) != INTEGER_CST)
5417 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5418 " a constant", &loc);
5419 expr = integer_zerop (c) ? e3 : e2;
5422 case RID_TYPES_COMPATIBLE_P:
5423 c_parser_consume_token (parser);
5424 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5426 expr.value = error_mark_node;
5427 expr.original_code = ERROR_MARK;
5430 t1 = c_parser_type_name (parser);
5433 expr.value = error_mark_node;
5434 expr.original_code = ERROR_MARK;
5437 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5439 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5440 expr.value = error_mark_node;
5441 expr.original_code = ERROR_MARK;
5444 t2 = c_parser_type_name (parser);
5447 expr.value = error_mark_node;
5448 expr.original_code = ERROR_MARK;
5451 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5456 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5457 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5459 expr.value = comptypes (e1, e2)
5460 ? build_int_cst (NULL_TREE, 1)
5461 : build_int_cst (NULL_TREE, 0);
5462 expr.original_code = ERROR_MARK;
5465 case RID_AT_SELECTOR:
5466 gcc_assert (c_dialect_objc ());
5467 c_parser_consume_token (parser);
5468 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5470 expr.value = error_mark_node;
5471 expr.original_code = ERROR_MARK;
5475 tree sel = c_parser_objc_selector_arg (parser);
5476 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5478 expr.value = objc_build_selector_expr (sel);
5479 expr.original_code = ERROR_MARK;
5482 case RID_AT_PROTOCOL:
5483 gcc_assert (c_dialect_objc ());
5484 c_parser_consume_token (parser);
5485 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5487 expr.value = error_mark_node;
5488 expr.original_code = ERROR_MARK;
5491 if (c_parser_next_token_is_not (parser, CPP_NAME))
5493 c_parser_error (parser, "expected identifier");
5494 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5495 expr.value = error_mark_node;
5496 expr.original_code = ERROR_MARK;
5500 tree id = c_parser_peek_token (parser)->value;
5501 c_parser_consume_token (parser);
5502 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5504 expr.value = objc_build_protocol_expr (id);
5505 expr.original_code = ERROR_MARK;
5509 /* Extension to support C-structures in the archiver. */
5510 gcc_assert (c_dialect_objc ());
5511 c_parser_consume_token (parser);
5512 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5514 expr.value = error_mark_node;
5515 expr.original_code = ERROR_MARK;
5518 t1 = c_parser_type_name (parser);
5521 expr.value = error_mark_node;
5522 expr.original_code = ERROR_MARK;
5523 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5526 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5529 tree type = groktypename (t1);
5530 expr.value = objc_build_encode_expr (type);
5531 expr.original_code = ERROR_MARK;
5535 c_parser_error (parser, "expected expression");
5536 expr.value = error_mark_node;
5537 expr.original_code = ERROR_MARK;
5541 case CPP_OPEN_SQUARE:
5542 if (c_dialect_objc ())
5544 tree receiver, args;
5545 c_parser_consume_token (parser);
5546 receiver = c_parser_objc_receiver (parser);
5547 args = c_parser_objc_message_args (parser);
5548 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5550 expr.value = objc_build_message_expr (build_tree_list (receiver,
5552 expr.original_code = ERROR_MARK;
5555 /* Else fall through to report error. */
5557 c_parser_error (parser, "expected expression");
5558 expr.value = error_mark_node;
5559 expr.original_code = ERROR_MARK;
5562 return c_parser_postfix_expression_after_primary (parser, expr);
5565 /* Parse a postfix expression after a parenthesized type name: the
5566 brace-enclosed initializer of a compound literal, possibly followed
5567 by some postfix operators. This is separate because it is not
5568 possible to tell until after the type name whether a cast
5569 expression has a cast or a compound literal, or whether the operand
5570 of sizeof is a parenthesized type name or starts with a compound
5573 static struct c_expr
5574 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5575 struct c_type_name *type_name)
5580 location_t start_loc;
5581 start_init (NULL_TREE, NULL, 0);
5582 type = groktypename (type_name);
5583 start_loc = c_parser_peek_token (parser)->location;
5584 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5586 error ("%Hcompound literal has variable size", &start_loc);
5587 type = error_mark_node;
5589 init = c_parser_braced_init (parser, type, false);
5591 maybe_warn_string_init (type, init);
5593 if (pedantic && !flag_isoc99)
5594 pedwarn ("%HISO C90 forbids compound literals", &start_loc);
5595 expr.value = build_compound_literal (type, init.value);
5596 expr.original_code = ERROR_MARK;
5597 return c_parser_postfix_expression_after_primary (parser, expr);
5600 /* Parse a postfix expression after the initial primary or compound
5601 literal; that is, parse a series of postfix operators. */
5603 static struct c_expr
5604 c_parser_postfix_expression_after_primary (c_parser *parser,
5607 tree ident, idx, exprlist;
5610 switch (c_parser_peek_token (parser)->type)
5612 case CPP_OPEN_SQUARE:
5613 /* Array reference. */
5614 c_parser_consume_token (parser);
5615 idx = c_parser_expression (parser).value;
5616 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5618 expr.value = build_array_ref (expr.value, idx);
5619 expr.original_code = ERROR_MARK;
5621 case CPP_OPEN_PAREN:
5622 /* Function call. */
5623 c_parser_consume_token (parser);
5624 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5625 exprlist = NULL_TREE;
5627 exprlist = c_parser_expr_list (parser, true);
5628 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5630 expr.value = build_function_call (expr.value, exprlist);
5631 expr.original_code = ERROR_MARK;
5634 /* Structure element reference. */
5635 c_parser_consume_token (parser);
5636 expr = default_function_array_conversion (expr);
5637 if (c_parser_next_token_is (parser, CPP_NAME))
5638 ident = c_parser_peek_token (parser)->value;
5641 c_parser_error (parser, "expected identifier");
5642 expr.value = error_mark_node;
5643 expr.original_code = ERROR_MARK;
5646 c_parser_consume_token (parser);
5647 expr.value = build_component_ref (expr.value, ident);
5648 expr.original_code = ERROR_MARK;
5651 /* Structure element reference. */
5652 c_parser_consume_token (parser);
5653 expr = default_function_array_conversion (expr);
5654 if (c_parser_next_token_is (parser, CPP_NAME))
5655 ident = c_parser_peek_token (parser)->value;
5658 c_parser_error (parser, "expected identifier");
5659 expr.value = error_mark_node;
5660 expr.original_code = ERROR_MARK;
5663 c_parser_consume_token (parser);
5664 expr.value = build_component_ref (build_indirect_ref (expr.value,
5666 expr.original_code = ERROR_MARK;
5669 /* Postincrement. */
5670 c_parser_consume_token (parser);
5671 expr = default_function_array_conversion (expr);
5672 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5673 expr.original_code = ERROR_MARK;
5675 case CPP_MINUS_MINUS:
5676 /* Postdecrement. */
5677 c_parser_consume_token (parser);
5678 expr = default_function_array_conversion (expr);
5679 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5680 expr.original_code = ERROR_MARK;
5688 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5691 assignment-expression
5692 expression , assignment-expression
5695 static struct c_expr
5696 c_parser_expression (c_parser *parser)
5699 expr = c_parser_expr_no_commas (parser, NULL);
5700 while (c_parser_next_token_is (parser, CPP_COMMA))
5703 c_parser_consume_token (parser);
5704 next = c_parser_expr_no_commas (parser, NULL);
5705 next = default_function_array_conversion (next);
5706 expr.value = build_compound_expr (expr.value, next.value);
5707 expr.original_code = COMPOUND_EXPR;
5712 /* Parse an expression and convert functions or arrays to
5715 static struct c_expr
5716 c_parser_expression_conv (c_parser *parser)
5719 expr = c_parser_expression (parser);
5720 expr = default_function_array_conversion (expr);
5724 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5725 functions and arrays to pointers.
5728 assignment-expression
5729 nonempty-expr-list , assignment-expression
5733 c_parser_expr_list (c_parser *parser, bool convert_p)
5737 expr = c_parser_expr_no_commas (parser, NULL);
5739 expr = default_function_array_conversion (expr);
5740 ret = cur = build_tree_list (NULL_TREE, expr.value);
5741 while (c_parser_next_token_is (parser, CPP_COMMA))
5743 c_parser_consume_token (parser);
5744 expr = c_parser_expr_no_commas (parser, NULL);
5746 expr = default_function_array_conversion (expr);
5747 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5753 /* Parse Objective-C-specific constructs. */
5755 /* Parse an objc-class-definition.
5757 objc-class-definition:
5758 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5759 objc-class-instance-variables[opt] objc-methodprotolist @end
5760 @implementation identifier objc-superclass[opt]
5761 objc-class-instance-variables[opt]
5762 @interface identifier ( identifier ) objc-protocol-refs[opt]
5763 objc-methodprotolist @end
5764 @implementation identifier ( identifier )
5769 "@interface identifier (" must start "@interface identifier (
5770 identifier ) ...": objc-methodprotolist in the first production may
5771 not start with a parenthesized identifier as a declarator of a data
5772 definition with no declaration specifiers if the objc-superclass,
5773 objc-protocol-refs and objc-class-instance-variables are omitted. */
5776 c_parser_objc_class_definition (c_parser *parser)
5781 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5783 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5787 c_parser_consume_token (parser);
5788 if (c_parser_next_token_is_not (parser, CPP_NAME))
5790 c_parser_error (parser, "expected identifier");
5793 id1 = c_parser_peek_token (parser)->value;
5794 c_parser_consume_token (parser);
5795 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5798 tree proto = NULL_TREE;
5799 c_parser_consume_token (parser);
5800 if (c_parser_next_token_is_not (parser, CPP_NAME))
5802 c_parser_error (parser, "expected identifier");
5803 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5806 id2 = c_parser_peek_token (parser)->value;
5807 c_parser_consume_token (parser);
5808 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5811 objc_start_category_implementation (id1, id2);
5814 if (c_parser_next_token_is (parser, CPP_LESS))
5815 proto = c_parser_objc_protocol_refs (parser);
5816 objc_start_category_interface (id1, id2, proto);
5817 c_parser_objc_methodprotolist (parser);
5818 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5819 objc_finish_interface ();
5822 if (c_parser_next_token_is (parser, CPP_COLON))
5824 c_parser_consume_token (parser);
5825 if (c_parser_next_token_is_not (parser, CPP_NAME))
5827 c_parser_error (parser, "expected identifier");
5830 superclass = c_parser_peek_token (parser)->value;
5831 c_parser_consume_token (parser);
5834 superclass = NULL_TREE;
5837 tree proto = NULL_TREE;
5838 if (c_parser_next_token_is (parser, CPP_LESS))
5839 proto = c_parser_objc_protocol_refs (parser);
5840 objc_start_class_interface (id1, superclass, proto);
5843 objc_start_class_implementation (id1, superclass);
5844 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5845 c_parser_objc_class_instance_variables (parser);
5848 objc_continue_interface ();
5849 c_parser_objc_methodprotolist (parser);
5850 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5851 objc_finish_interface ();
5855 objc_continue_implementation ();
5860 /* Parse objc-class-instance-variables.
5862 objc-class-instance-variables:
5863 { objc-instance-variable-decl-list[opt] }
5865 objc-instance-variable-decl-list:
5866 objc-visibility-spec
5867 objc-instance-variable-decl ;
5869 objc-instance-variable-decl-list objc-visibility-spec
5870 objc-instance-variable-decl-list objc-instance-variable-decl ;
5871 objc-instance-variable-decl-list ;
5873 objc-visibility-spec:
5878 objc-instance-variable-decl:
5883 c_parser_objc_class_instance_variables (c_parser *parser)
5885 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5886 c_parser_consume_token (parser);
5887 while (c_parser_next_token_is_not (parser, CPP_EOF))
5890 /* Parse any stray semicolon. */
5891 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5894 pedwarn ("%Hextra semicolon in struct or union specified",
5895 &c_parser_peek_token (parser)->location);
5896 c_parser_consume_token (parser);
5899 /* Stop if at the end of the instance variables. */
5900 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5902 c_parser_consume_token (parser);
5905 /* Parse any objc-visibility-spec. */
5906 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5908 c_parser_consume_token (parser);
5909 objc_set_visibility (2);
5912 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5914 c_parser_consume_token (parser);
5915 objc_set_visibility (0);
5918 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5920 c_parser_consume_token (parser);
5921 objc_set_visibility (1);
5924 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5926 c_parser_pragma (parser, pragma_external);
5930 /* Parse some comma-separated declarations. */
5931 decls = c_parser_struct_declaration (parser);
5933 /* Comma-separated instance variables are chained together in
5934 reverse order; add them one by one. */
5935 tree ivar = nreverse (decls);
5936 for (; ivar; ivar = TREE_CHAIN (ivar))
5937 objc_add_instance_variable (copy_node (ivar));
5939 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5943 /* Parse an objc-class-declaration.
5945 objc-class-declaration:
5946 @class identifier-list ;
5950 c_parser_objc_class_declaration (c_parser *parser)
5952 tree list = NULL_TREE;
5953 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5954 c_parser_consume_token (parser);
5955 /* Any identifiers, including those declared as type names, are OK
5960 if (c_parser_next_token_is_not (parser, CPP_NAME))
5962 c_parser_error (parser, "expected identifier");
5965 id = c_parser_peek_token (parser)->value;
5966 list = chainon (list, build_tree_list (NULL_TREE, id));
5967 c_parser_consume_token (parser);
5968 if (c_parser_next_token_is (parser, CPP_COMMA))
5969 c_parser_consume_token (parser);
5973 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5974 objc_declare_class (list);
5977 /* Parse an objc-alias-declaration.
5979 objc-alias-declaration:
5980 @compatibility_alias identifier identifier ;
5984 c_parser_objc_alias_declaration (c_parser *parser)
5987 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5988 c_parser_consume_token (parser);
5989 if (c_parser_next_token_is_not (parser, CPP_NAME))
5991 c_parser_error (parser, "expected identifier");
5992 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5995 id1 = c_parser_peek_token (parser)->value;
5996 c_parser_consume_token (parser);
5997 if (c_parser_next_token_is_not (parser, CPP_NAME))
5999 c_parser_error (parser, "expected identifier");
6000 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6003 id2 = c_parser_peek_token (parser)->value;
6004 c_parser_consume_token (parser);
6005 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6006 objc_declare_alias (id1, id2);
6009 /* Parse an objc-protocol-definition.
6011 objc-protocol-definition:
6012 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6013 @protocol identifier-list ;
6015 "@protocol identifier ;" should be resolved as "@protocol
6016 identifier-list ;": objc-methodprotolist may not start with a
6017 semicolon in the first alternative if objc-protocol-refs are
6021 c_parser_objc_protocol_definition (c_parser *parser)
6023 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6024 c_parser_consume_token (parser);
6025 if (c_parser_next_token_is_not (parser, CPP_NAME))
6027 c_parser_error (parser, "expected identifier");
6030 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6031 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6033 tree list = NULL_TREE;
6034 /* Any identifiers, including those declared as type names, are
6039 if (c_parser_next_token_is_not (parser, CPP_NAME))
6041 c_parser_error (parser, "expected identifier");
6044 id = c_parser_peek_token (parser)->value;
6045 list = chainon (list, build_tree_list (NULL_TREE, id));
6046 c_parser_consume_token (parser);
6047 if (c_parser_next_token_is (parser, CPP_COMMA))
6048 c_parser_consume_token (parser);
6052 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6053 objc_declare_protocols (list);
6057 tree id = c_parser_peek_token (parser)->value;
6058 tree proto = NULL_TREE;
6059 c_parser_consume_token (parser);
6060 if (c_parser_next_token_is (parser, CPP_LESS))
6061 proto = c_parser_objc_protocol_refs (parser);
6062 parser->objc_pq_context = true;
6063 objc_start_protocol (id, proto);
6064 c_parser_objc_methodprotolist (parser);
6065 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6066 parser->objc_pq_context = false;
6067 objc_finish_interface ();
6071 /* Parse an objc-method-type.
6078 static enum tree_code
6079 c_parser_objc_method_type (c_parser *parser)
6081 switch (c_parser_peek_token (parser)->type)
6084 c_parser_consume_token (parser);
6087 c_parser_consume_token (parser);
6094 /* Parse an objc-method-definition.
6096 objc-method-definition:
6097 objc-method-type objc-method-decl ;[opt] compound-statement
6101 c_parser_objc_method_definition (c_parser *parser)
6103 enum tree_code type = c_parser_objc_method_type (parser);
6105 objc_set_method_type (type);
6106 parser->objc_pq_context = true;
6107 decl = c_parser_objc_method_decl (parser);
6108 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6110 c_parser_consume_token (parser);
6112 pedwarn ("%Hextra semicolon in method definition specified",
6113 &c_parser_peek_token (parser)->location);
6115 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6117 c_parser_error (parser, "expected %<{%>");
6120 parser->objc_pq_context = false;
6121 objc_start_method_definition (decl);
6122 add_stmt (c_parser_compound_statement (parser));
6123 objc_finish_method_definition (current_function_decl);
6126 /* Parse an objc-methodprotolist.
6128 objc-methodprotolist:
6130 objc-methodprotolist objc-methodproto
6131 objc-methodprotolist declaration
6132 objc-methodprotolist ;
6134 The declaration is a data definition, which may be missing
6135 declaration specifiers under the same rules and diagnostics as
6136 other data definitions outside functions, and the stray semicolon
6137 is diagnosed the same way as a stray semicolon outside a
6141 c_parser_objc_methodprotolist (c_parser *parser)
6145 /* The list is terminated by @end. */
6146 switch (c_parser_peek_token (parser)->type)
6150 pedwarn ("%HISO C does not allow extra %<;%> "
6151 "outside of a function",
6152 &c_parser_peek_token (parser)->location);
6153 c_parser_consume_token (parser);
6157 c_parser_objc_methodproto (parser);
6160 c_parser_pragma (parser, pragma_external);
6165 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6167 c_parser_declaration_or_fndef (parser, false, true, false, true);
6173 /* Parse an objc-methodproto.
6176 objc-method-type objc-method-decl ;
6180 c_parser_objc_methodproto (c_parser *parser)
6182 enum tree_code type = c_parser_objc_method_type (parser);
6184 objc_set_method_type (type);
6185 /* Remember protocol qualifiers in prototypes. */
6186 parser->objc_pq_context = true;
6187 decl = c_parser_objc_method_decl (parser);
6188 /* Forget protocol qualifiers here. */
6189 parser->objc_pq_context = false;
6190 objc_add_method_declaration (decl);
6191 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6194 /* Parse an objc-method-decl.
6197 ( objc-type-name ) objc-selector
6199 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6200 objc-keyword-selector objc-optparmlist
6202 objc-keyword-selector:
6204 objc-keyword-selector objc-keyword-decl
6207 objc-selector : ( objc-type-name ) identifier
6208 objc-selector : identifier
6209 : ( objc-type-name ) identifier
6213 objc-optparms objc-optellipsis
6217 objc-opt-parms , parameter-declaration
6225 c_parser_objc_method_decl (c_parser *parser)
6227 tree type = NULL_TREE;
6229 tree parms = NULL_TREE;
6230 bool ellipsis = false;
6232 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6234 c_parser_consume_token (parser);
6235 type = c_parser_objc_type_name (parser);
6236 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6238 sel = c_parser_objc_selector (parser);
6239 /* If there is no selector, or a colon follows, we have an
6240 objc-keyword-selector. If there is a selector, and a colon does
6241 not follow, that selector ends the objc-method-decl. */
6242 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6245 tree list = NULL_TREE;
6248 tree atype = NULL_TREE, id, keyworddecl;
6249 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6251 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6253 c_parser_consume_token (parser);
6254 atype = c_parser_objc_type_name (parser);
6255 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6258 if (c_parser_next_token_is_not (parser, CPP_NAME))
6260 c_parser_error (parser, "expected identifier");
6261 return error_mark_node;
6263 id = c_parser_peek_token (parser)->value;
6264 c_parser_consume_token (parser);
6265 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6266 list = chainon (list, keyworddecl);
6267 tsel = c_parser_objc_selector (parser);
6268 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6271 /* Parse the optional parameter list. Optional Objective-C
6272 method parameters follow the C syntax, and may include '...'
6273 to denote a variable number of arguments. */
6274 parms = make_node (TREE_LIST);
6275 while (c_parser_next_token_is (parser, CPP_COMMA))
6277 struct c_parm *parm;
6278 c_parser_consume_token (parser);
6279 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6282 c_parser_consume_token (parser);
6285 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6288 parms = chainon (parms,
6289 build_tree_list (NULL_TREE, grokparm (parm)));
6293 return objc_build_method_signature (type, sel, parms, ellipsis);
6296 /* Parse an objc-type-name.
6299 objc-type-qualifiers[opt] type-name
6300 objc-type-qualifiers[opt]
6302 objc-type-qualifiers:
6304 objc-type-qualifiers objc-type-qualifier
6306 objc-type-qualifier: one of
6307 in out inout bycopy byref oneway
6311 c_parser_objc_type_name (c_parser *parser)
6313 tree quals = NULL_TREE;
6314 struct c_type_name *typename = NULL;
6315 tree type = NULL_TREE;
6318 c_token *token = c_parser_peek_token (parser);
6319 if (token->type == CPP_KEYWORD
6320 && (token->keyword == RID_IN
6321 || token->keyword == RID_OUT
6322 || token->keyword == RID_INOUT
6323 || token->keyword == RID_BYCOPY
6324 || token->keyword == RID_BYREF
6325 || token->keyword == RID_ONEWAY))
6327 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6328 c_parser_consume_token (parser);
6333 if (c_parser_next_token_starts_typename (parser))
6334 typename = c_parser_type_name (parser);
6336 type = groktypename (typename);
6337 return build_tree_list (quals, type);
6340 /* Parse objc-protocol-refs.
6347 c_parser_objc_protocol_refs (c_parser *parser)
6349 tree list = NULL_TREE;
6350 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6351 c_parser_consume_token (parser);
6352 /* Any identifiers, including those declared as type names, are OK
6357 if (c_parser_next_token_is_not (parser, CPP_NAME))
6359 c_parser_error (parser, "expected identifier");
6362 id = c_parser_peek_token (parser)->value;
6363 list = chainon (list, build_tree_list (NULL_TREE, id));
6364 c_parser_consume_token (parser);
6365 if (c_parser_next_token_is (parser, CPP_COMMA))
6366 c_parser_consume_token (parser);
6370 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6374 /* Parse an objc-try-catch-statement.
6376 objc-try-catch-statement:
6377 @try compound-statement objc-catch-list[opt]
6378 @try compound-statement objc-catch-list[opt] @finally compound-statement
6381 @catch ( parameter-declaration ) compound-statement
6382 objc-catch-list @catch ( parameter-declaration ) compound-statement
6386 c_parser_objc_try_catch_statement (c_parser *parser)
6390 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6391 c_parser_consume_token (parser);
6392 loc = c_parser_peek_token (parser)->location;
6393 stmt = c_parser_compound_statement (parser);
6394 objc_begin_try_stmt (loc, stmt);
6395 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6397 struct c_parm *parm;
6398 c_parser_consume_token (parser);
6399 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6401 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6404 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6407 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6408 objc_begin_catch_clause (grokparm (parm));
6409 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6410 c_parser_compound_statement_nostart (parser);
6411 objc_finish_catch_clause ();
6413 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6417 c_parser_consume_token (parser);
6418 finloc = c_parser_peek_token (parser)->location;
6419 finstmt = c_parser_compound_statement (parser);
6420 objc_build_finally_clause (finloc, finstmt);
6422 objc_finish_try_stmt ();
6425 /* Parse an objc-synchronized-statement.
6427 objc-synchronized-statement:
6428 @synchronized ( expression ) compound-statement
6432 c_parser_objc_synchronized_statement (c_parser *parser)
6436 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6437 c_parser_consume_token (parser);
6438 loc = c_parser_peek_token (parser)->location;
6439 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6441 expr = c_parser_expression (parser).value;
6442 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6445 expr = error_mark_node;
6446 stmt = c_parser_compound_statement (parser);
6447 objc_build_synchronized (loc, expr, stmt);
6450 /* Parse an objc-selector; return NULL_TREE without an error if the
6451 next token is not an objc-selector.
6456 enum struct union if else while do for switch case default
6457 break continue return goto asm sizeof typeof __alignof
6458 unsigned long const short volatile signed restrict _Complex
6459 in out inout bycopy byref oneway int char float double void _Bool
6461 ??? Why this selection of keywords but not, for example, storage
6462 class specifiers? */
6465 c_parser_objc_selector (c_parser *parser)
6467 c_token *token = c_parser_peek_token (parser);
6468 tree value = token->value;
6469 if (token->type == CPP_NAME)
6471 c_parser_consume_token (parser);
6474 if (token->type != CPP_KEYWORD)
6476 switch (token->keyword)
6517 c_parser_consume_token (parser);
6524 /* Parse an objc-selector-arg.
6528 objc-keywordname-list
6530 objc-keywordname-list:
6532 objc-keywordname-list objc-keywordname
6540 c_parser_objc_selector_arg (c_parser *parser)
6542 tree sel = c_parser_objc_selector (parser);
6543 tree list = NULL_TREE;
6544 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6548 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6550 list = chainon (list, build_tree_list (sel, NULL_TREE));
6551 sel = c_parser_objc_selector (parser);
6552 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6558 /* Parse an objc-receiver.
6567 c_parser_objc_receiver (c_parser *parser)
6569 if (c_parser_peek_token (parser)->type == CPP_NAME
6570 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6571 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6573 tree id = c_parser_peek_token (parser)->value;
6574 c_parser_consume_token (parser);
6575 return objc_get_class_reference (id);
6577 return c_parser_expression (parser).value;
6580 /* Parse objc-message-args.
6584 objc-keywordarg-list
6586 objc-keywordarg-list:
6588 objc-keywordarg-list objc-keywordarg
6591 objc-selector : objc-keywordexpr
6596 c_parser_objc_message_args (c_parser *parser)
6598 tree sel = c_parser_objc_selector (parser);
6599 tree list = NULL_TREE;
6600 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6605 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6607 keywordexpr = c_parser_objc_keywordexpr (parser);
6608 list = chainon (list, build_tree_list (sel, keywordexpr));
6609 sel = c_parser_objc_selector (parser);
6610 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6616 /* Parse an objc-keywordexpr.
6623 c_parser_objc_keywordexpr (c_parser *parser)
6625 tree list = c_parser_expr_list (parser, true);
6626 if (TREE_CHAIN (list) == NULL_TREE)
6628 /* Just return the expression, remove a level of
6630 return TREE_VALUE (list);
6634 /* We have a comma expression, we will collapse later. */
6640 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6641 should be considered, statements. ALLOW_STMT is true if we're within
6642 the context of a function and such pragmas are to be allowed. Returns
6643 true if we actually parsed such a pragma. */
6646 c_parser_pragma (c_parser *parser, enum pragma_context context)
6650 id = c_parser_peek_token (parser)->pragma_kind;
6651 gcc_assert (id != PRAGMA_NONE);
6655 case PRAGMA_OMP_BARRIER:
6656 if (context != pragma_compound)
6658 if (context == pragma_stmt)
6659 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6660 "used in compound statements");
6663 c_parser_omp_barrier (parser);
6666 case PRAGMA_OMP_FLUSH:
6667 if (context != pragma_compound)
6669 if (context == pragma_stmt)
6670 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6671 "used in compound statements");
6674 c_parser_omp_flush (parser);
6677 case PRAGMA_OMP_THREADPRIVATE:
6678 c_parser_omp_threadprivate (parser);
6681 case PRAGMA_OMP_SECTION:
6682 error ("%H%<#pragma omp section%> may only be used in "
6683 "%<#pragma omp sections%> construct",
6684 &c_parser_peek_token (parser)->location);
6685 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6688 case PRAGMA_GCC_PCH_PREPROCESS:
6689 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6690 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6694 if (id < PRAGMA_FIRST_EXTERNAL)
6696 if (context == pragma_external)
6699 c_parser_error (parser, "expected declaration specifiers");
6700 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6703 c_parser_omp_construct (parser);
6709 c_parser_consume_pragma (parser);
6710 c_invoke_pragma_handler (id);
6712 /* Skip to EOL, but suppress any error message. Those will have been
6713 generated by the handler routine through calling error, as opposed
6714 to calling c_parser_error. */
6715 parser->error = true;
6716 c_parser_skip_to_pragma_eol (parser);
6721 /* The interface the pragma parsers have to the lexer. */
6724 pragma_lex (tree *value)
6726 c_token *tok = c_parser_peek_token (the_parser);
6727 enum cpp_ttype ret = tok->type;
6729 *value = tok->value;
6730 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6734 if (ret == CPP_KEYWORD)
6736 c_parser_consume_token (the_parser);
6743 c_parser_pragma_pch_preprocess (c_parser *parser)
6747 c_parser_consume_pragma (parser);
6748 if (c_parser_next_token_is (parser, CPP_STRING))
6750 name = c_parser_peek_token (parser)->value;
6751 c_parser_consume_token (parser);
6754 c_parser_error (parser, "expected string literal");
6755 c_parser_skip_to_pragma_eol (parser);
6758 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6761 /* OpenMP 2.5 parsing routines. */
6763 /* Returns name of the next clause.
6764 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6765 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6766 returned and the token is consumed. */
6768 static pragma_omp_clause
6769 c_parser_omp_clause_name (c_parser *parser)
6771 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6773 if (c_parser_next_token_is_keyword (parser, RID_IF))
6774 result = PRAGMA_OMP_CLAUSE_IF;
6775 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6776 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6777 else if (c_parser_next_token_is (parser, CPP_NAME))
6779 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6784 if (!strcmp ("copyin", p))
6785 result = PRAGMA_OMP_CLAUSE_COPYIN;
6786 else if (!strcmp ("copyprivate", p))
6787 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6790 if (!strcmp ("firstprivate", p))
6791 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6794 if (!strcmp ("lastprivate", p))
6795 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6798 if (!strcmp ("nowait", p))
6799 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6800 else if (!strcmp ("num_threads", p))
6801 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6804 if (!strcmp ("ordered", p))
6805 result = PRAGMA_OMP_CLAUSE_ORDERED;
6808 if (!strcmp ("private", p))
6809 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6812 if (!strcmp ("reduction", p))
6813 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6816 if (!strcmp ("schedule", p))
6817 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6818 else if (!strcmp ("shared", p))
6819 result = PRAGMA_OMP_CLAUSE_SHARED;
6824 if (result != PRAGMA_OMP_CLAUSE_NONE)
6825 c_parser_consume_token (parser);
6830 /* Validate that a clause of the given type does not already exist. */
6833 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6837 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6838 if (OMP_CLAUSE_CODE (c) == code)
6840 error ("too many %qs clauses", name);
6848 variable-list , identifier
6850 If KIND is nonzero, create the appropriate node and install the decl
6851 in OMP_CLAUSE_DECL and add the node to the head of the list.
6853 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6854 return the list created. */
6857 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6860 if (c_parser_next_token_is_not (parser, CPP_NAME)
6861 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6862 c_parser_error (parser, "expected identifier");
6864 while (c_parser_next_token_is (parser, CPP_NAME)
6865 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6867 tree t = lookup_name (c_parser_peek_token (parser)->value);
6870 undeclared_variable (c_parser_peek_token (parser)->value,
6871 c_parser_peek_token (parser)->location);
6872 else if (t == error_mark_node)
6876 tree u = build_omp_clause (kind);
6877 OMP_CLAUSE_DECL (u) = t;
6878 OMP_CLAUSE_CHAIN (u) = list;
6882 list = tree_cons (t, NULL_TREE, list);
6884 c_parser_consume_token (parser);
6886 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6889 c_parser_consume_token (parser);
6895 /* Similarly, but expect leading and trailing parenthesis. This is a very
6896 common case for omp clauses. */
6899 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6901 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6903 list = c_parser_omp_variable_list (parser, kind, list);
6904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6910 copyin ( variable-list ) */
6913 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6915 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6919 copyprivate ( variable-list ) */
6922 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6924 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6928 default ( shared | none ) */
6931 c_parser_omp_clause_default (c_parser *parser, tree list)
6933 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6936 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6938 if (c_parser_next_token_is (parser, CPP_NAME))
6940 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6945 if (strcmp ("none", p) != 0)
6947 kind = OMP_CLAUSE_DEFAULT_NONE;
6951 if (strcmp ("shared", p) != 0)
6953 kind = OMP_CLAUSE_DEFAULT_SHARED;
6960 c_parser_consume_token (parser);
6965 c_parser_error (parser, "expected %<none%> or %<shared%>");
6967 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6969 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6972 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6973 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6974 OMP_CLAUSE_CHAIN (c) = list;
6975 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6981 firstprivate ( variable-list ) */
6984 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6986 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6990 if ( expression ) */
6993 c_parser_omp_clause_if (c_parser *parser, tree list)
6995 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6997 tree t = c_parser_paren_condition (parser);
7000 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7002 c = build_omp_clause (OMP_CLAUSE_IF);
7003 OMP_CLAUSE_IF_EXPR (c) = t;
7004 OMP_CLAUSE_CHAIN (c) = list;
7008 c_parser_error (parser, "expected %<(%>");
7014 lastprivate ( variable-list ) */
7017 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7019 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7026 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7030 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7032 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7033 OMP_CLAUSE_CHAIN (c) = list;
7038 num_threads ( expression ) */
7041 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7043 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7045 location_t expr_loc = c_parser_peek_token (parser)->location;
7046 tree c, t = c_parser_expression (parser).value;
7048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7050 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7052 c_parser_error (parser, "expected integer expression");
7056 /* Attempt to statically determine when the number isn't positive. */
7057 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7058 build_int_cst (TREE_TYPE (t), 0));
7059 if (c == boolean_true_node)
7061 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7062 t = integer_one_node;
7065 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7067 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7068 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7069 OMP_CLAUSE_CHAIN (c) = list;
7080 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7084 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7086 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7087 OMP_CLAUSE_CHAIN (c) = list;
7092 private ( variable-list ) */
7095 c_parser_omp_clause_private (c_parser *parser, tree list)
7097 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7101 reduction ( reduction-operator : variable-list )
7104 One of: + * - & ^ | && || */
7107 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7109 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7111 enum tree_code code;
7113 switch (c_parser_peek_token (parser)->type)
7125 code = BIT_AND_EXPR;
7128 code = BIT_XOR_EXPR;
7131 code = BIT_IOR_EXPR;
7134 code = TRUTH_ANDIF_EXPR;
7137 code = TRUTH_ORIF_EXPR;
7140 c_parser_error (parser,
7141 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7142 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7143 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7146 c_parser_consume_token (parser);
7147 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7151 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7152 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7153 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7157 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7163 schedule ( schedule-kind )
7164 schedule ( schedule-kind , expression )
7167 static | dynamic | guided | runtime
7171 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7175 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7178 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7180 if (c_parser_next_token_is (parser, CPP_NAME))
7182 tree kind = c_parser_peek_token (parser)->value;
7183 const char *p = IDENTIFIER_POINTER (kind);
7188 if (strcmp ("dynamic", p) != 0)
7190 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7194 if (strcmp ("guided", p) != 0)
7196 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7200 if (strcmp ("runtime", p) != 0)
7202 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7209 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7210 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7214 c_parser_consume_token (parser);
7215 if (c_parser_next_token_is (parser, CPP_COMMA))
7218 c_parser_consume_token (parser);
7220 here = c_parser_peek_token (parser)->location;
7221 t = c_parser_expr_no_commas (parser, NULL).value;
7223 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7224 error ("%Hschedule %<runtime%> does not take "
7225 "a %<chunk_size%> parameter", &here);
7226 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7227 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7229 c_parser_error (parser, "expected integer expression");
7231 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7234 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7235 "expected %<,%> or %<)%>");
7237 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7238 OMP_CLAUSE_CHAIN (c) = list;
7242 c_parser_error (parser, "invalid schedule kind");
7243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7248 shared ( variable-list ) */
7251 c_parser_omp_clause_shared (c_parser *parser, tree list)
7253 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7256 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7257 is a bitmask in MASK. Return the list of clauses found; the result
7258 of clause default goes in *pdefault. */
7261 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7264 tree clauses = NULL;
7267 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7270 pragma_omp_clause c_kind;
7272 tree prev = clauses;
7274 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7275 c_parser_consume_token (parser);
7278 here = c_parser_peek_token (parser)->location;
7279 c_kind = c_parser_omp_clause_name (parser);
7283 case PRAGMA_OMP_CLAUSE_COPYIN:
7284 clauses = c_parser_omp_clause_copyin (parser, clauses);
7287 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7288 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7289 c_name = "copyprivate";
7291 case PRAGMA_OMP_CLAUSE_DEFAULT:
7292 clauses = c_parser_omp_clause_default (parser, clauses);
7295 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7296 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7297 c_name = "firstprivate";
7299 case PRAGMA_OMP_CLAUSE_IF:
7300 clauses = c_parser_omp_clause_if (parser, clauses);
7303 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7304 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7305 c_name = "lastprivate";
7307 case PRAGMA_OMP_CLAUSE_NOWAIT:
7308 clauses = c_parser_omp_clause_nowait (parser, clauses);
7311 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7312 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7313 c_name = "num_threads";
7315 case PRAGMA_OMP_CLAUSE_ORDERED:
7316 clauses = c_parser_omp_clause_ordered (parser, clauses);
7319 case PRAGMA_OMP_CLAUSE_PRIVATE:
7320 clauses = c_parser_omp_clause_private (parser, clauses);
7323 case PRAGMA_OMP_CLAUSE_REDUCTION:
7324 clauses = c_parser_omp_clause_reduction (parser, clauses);
7325 c_name = "reduction";
7327 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7328 clauses = c_parser_omp_clause_schedule (parser, clauses);
7329 c_name = "schedule";
7331 case PRAGMA_OMP_CLAUSE_SHARED:
7332 clauses = c_parser_omp_clause_shared (parser, clauses);
7336 c_parser_error (parser, "expected %<#pragma omp%> clause");
7340 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7342 /* Remove the invalid clause(s) from the list to avoid
7343 confusing the rest of the compiler. */
7345 error ("%H%qs is not valid for %qs", &here, c_name, where);
7350 c_parser_skip_to_pragma_eol (parser);
7352 return c_finish_omp_clauses (clauses);
7359 In practice, we're also interested in adding the statement to an
7360 outer node. So it is convenient if we work around the fact that
7361 c_parser_statement calls add_stmt. */
7364 c_parser_omp_structured_block (c_parser *parser)
7366 tree stmt = push_stmt_list ();
7367 c_parser_statement (parser);
7368 return pop_stmt_list (stmt);
7372 # pragma omp atomic new-line
7376 x binop= expr | x++ | ++x | x-- | --x
7378 +, *, -, /, &, ^, |, <<, >>
7380 where x is an lvalue expression with scalar type. */
7383 c_parser_omp_atomic (c_parser *parser)
7387 enum tree_code code;
7388 struct c_expr rhs_expr;
7390 c_parser_skip_to_pragma_eol (parser);
7392 lhs = c_parser_unary_expression (parser).value;
7393 switch (TREE_CODE (lhs))
7397 c_parser_skip_to_end_of_block_or_statement (parser);
7400 case PREINCREMENT_EXPR:
7401 case POSTINCREMENT_EXPR:
7402 lhs = TREE_OPERAND (lhs, 0);
7404 rhs = integer_one_node;
7407 case PREDECREMENT_EXPR:
7408 case POSTDECREMENT_EXPR:
7409 lhs = TREE_OPERAND (lhs, 0);
7411 rhs = integer_one_node;
7415 switch (c_parser_peek_token (parser)->type)
7421 code = TRUNC_DIV_EXPR;
7436 code = BIT_AND_EXPR;
7439 code = BIT_IOR_EXPR;
7442 code = BIT_XOR_EXPR;
7445 c_parser_error (parser,
7446 "invalid operator for %<#pragma omp atomic%>");
7450 c_parser_consume_token (parser);
7451 rhs_expr = c_parser_expression (parser);
7452 rhs_expr = default_function_array_conversion (rhs_expr);
7453 rhs = rhs_expr.value;
7456 stmt = c_finish_omp_atomic (code, lhs, rhs);
7457 if (stmt != error_mark_node)
7459 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7464 # pragma omp barrier new-line
7468 c_parser_omp_barrier (c_parser *parser)
7470 c_parser_consume_pragma (parser);
7471 c_parser_skip_to_pragma_eol (parser);
7473 c_finish_omp_barrier ();
7477 # pragma omp critical [(name)] new-line
7482 c_parser_omp_critical (c_parser *parser)
7484 tree stmt, name = NULL;
7486 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7488 c_parser_consume_token (parser);
7489 if (c_parser_next_token_is (parser, CPP_NAME))
7491 name = c_parser_peek_token (parser)->value;
7492 c_parser_consume_token (parser);
7493 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7496 c_parser_error (parser, "expected identifier");
7498 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7499 c_parser_error (parser, "expected %<(%> or end of line");
7500 c_parser_skip_to_pragma_eol (parser);
7502 stmt = c_parser_omp_structured_block (parser);
7503 return c_finish_omp_critical (stmt, name);
7507 # pragma omp flush flush-vars[opt] new-line
7510 ( variable-list ) */
7513 c_parser_omp_flush (c_parser *parser)
7515 c_parser_consume_pragma (parser);
7516 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7517 c_parser_omp_var_list_parens (parser, 0, NULL);
7518 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7519 c_parser_error (parser, "expected %<(%> or end of line");
7520 c_parser_skip_to_pragma_eol (parser);
7522 c_finish_omp_flush ();
7525 /* Parse the restricted form of the for statment allowed by OpenMP.
7526 The real trick here is to determine the loop control variable early
7527 so that we can push a new decl if necessary to make it private. */
7530 c_parser_omp_for_loop (c_parser *parser)
7532 tree decl, cond, incr, save_break, save_cont, body, init;
7535 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7537 c_parser_error (parser, "for statement expected");
7540 loc = c_parser_peek_token (parser)->location;
7541 c_parser_consume_token (parser);
7543 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7546 /* Parse the initialization declaration or expression. */
7547 if (c_parser_next_token_starts_declspecs (parser))
7549 c_parser_declaration_or_fndef (parser, true, true, true, true);
7550 decl = check_for_loop_decls ();
7553 if (DECL_INITIAL (decl) == error_mark_node)
7554 decl = error_mark_node;
7557 else if (c_parser_next_token_is (parser, CPP_NAME)
7558 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7560 decl = c_parser_postfix_expression (parser).value;
7562 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7564 init = c_parser_expr_no_commas (parser, NULL).value;
7565 init = build_modify_expr (decl, NOP_EXPR, init);
7566 init = c_process_expr_stmt (init);
7568 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7573 /* Parse the loop condition. */
7575 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7577 cond = c_parser_expression_conv (parser).value;
7578 cond = c_objc_common_truthvalue_conversion (cond);
7579 if (CAN_HAVE_LOCATION_P (cond))
7580 SET_EXPR_LOCATION (cond, input_location);
7582 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7584 /* Parse the increment expression. */
7586 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7587 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7588 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7591 save_break = c_break_label;
7592 c_break_label = size_one_node;
7593 save_cont = c_cont_label;
7594 c_cont_label = NULL_TREE;
7595 body = push_stmt_list ();
7597 add_stmt (c_parser_c99_block_statement (parser));
7599 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7601 body = pop_stmt_list (body);
7602 c_break_label = save_break;
7603 c_cont_label = save_cont;
7605 /* Only bother calling c_finish_omp_for if we haven't already generated
7606 an error from the initialization parsing. */
7607 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7608 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7612 c_parser_error (parser, "expected iteration declaration or initialization");
7613 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7614 decl = init = cond = incr = NULL_TREE;
7619 #pragma omp for for-clause[optseq] new-line
7623 #define OMP_FOR_CLAUSE_MASK \
7624 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7625 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7626 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7627 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7628 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7629 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7630 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7633 c_parser_omp_for (c_parser *parser)
7635 tree block, clauses, ret;
7637 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7640 block = c_begin_compound_stmt (true);
7641 ret = c_parser_omp_for_loop (parser);
7643 OMP_FOR_CLAUSES (ret) = clauses;
7644 block = c_end_compound_stmt (block, true);
7651 # pragma omp master new-line
7656 c_parser_omp_master (c_parser *parser)
7658 c_parser_skip_to_pragma_eol (parser);
7659 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7663 # pragma omp ordered new-line
7668 c_parser_omp_ordered (c_parser *parser)
7670 c_parser_skip_to_pragma_eol (parser);
7671 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7677 { section-sequence }
7680 section-directive[opt] structured-block
7681 section-sequence section-directive structured-block */
7684 c_parser_omp_sections_scope (c_parser *parser)
7687 bool error_suppress = false;
7690 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7692 /* Avoid skipping until the end of the block. */
7693 parser->error = false;
7697 stmt = push_stmt_list ();
7699 loc = c_parser_peek_token (parser)->location;
7700 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7702 substmt = push_stmt_list ();
7706 c_parser_statement (parser);
7708 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7710 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7712 if (c_parser_next_token_is (parser, CPP_EOF))
7716 substmt = pop_stmt_list (substmt);
7717 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7718 SET_EXPR_LOCATION (substmt, loc);
7724 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7726 if (c_parser_next_token_is (parser, CPP_EOF))
7729 loc = c_parser_peek_token (parser)->location;
7730 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7732 c_parser_consume_pragma (parser);
7733 c_parser_skip_to_pragma_eol (parser);
7734 error_suppress = false;
7736 else if (!error_suppress)
7738 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7740 error_suppress = true;
7743 substmt = c_parser_omp_structured_block (parser);
7744 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7745 SET_EXPR_LOCATION (substmt, loc);
7748 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7749 "expected %<#pragma omp section%> or %<}%>");
7751 substmt = pop_stmt_list (stmt);
7753 stmt = make_node (OMP_SECTIONS);
7754 TREE_TYPE (stmt) = void_type_node;
7755 OMP_SECTIONS_BODY (stmt) = substmt;
7757 return add_stmt (stmt);
7761 # pragma omp sections sections-clause[optseq] newline
7765 #define OMP_SECTIONS_CLAUSE_MASK \
7766 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7767 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7768 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7769 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7770 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7773 c_parser_omp_sections (c_parser *parser)
7775 tree block, clauses, ret;
7777 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7778 "#pragma omp sections");
7780 block = c_begin_compound_stmt (true);
7781 ret = c_parser_omp_sections_scope (parser);
7783 OMP_SECTIONS_CLAUSES (ret) = clauses;
7784 block = c_end_compound_stmt (block, true);
7791 # pragma parallel parallel-clause new-line
7792 # pragma parallel for parallel-for-clause new-line
7793 # pragma parallel sections parallel-sections-clause new-line
7796 #define OMP_PARALLEL_CLAUSE_MASK \
7797 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7798 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7799 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7800 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7801 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7802 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7803 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7804 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7807 c_parser_omp_parallel (c_parser *parser)
7809 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7810 const char *p_name = "#pragma omp parallel";
7811 tree stmt, clauses, par_clause, ws_clause, block;
7812 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7814 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7816 c_parser_consume_token (parser);
7817 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7818 p_name = "#pragma omp parallel for";
7819 mask |= OMP_FOR_CLAUSE_MASK;
7820 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7822 else if (c_parser_next_token_is (parser, CPP_NAME))
7824 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7825 if (strcmp (p, "sections") == 0)
7827 c_parser_consume_token (parser);
7828 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7829 p_name = "#pragma omp parallel sections";
7830 mask |= OMP_SECTIONS_CLAUSE_MASK;
7831 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7835 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7839 case PRAGMA_OMP_PARALLEL:
7840 block = c_begin_omp_parallel ();
7841 c_parser_statement (parser);
7842 stmt = c_finish_omp_parallel (clauses, block);
7845 case PRAGMA_OMP_PARALLEL_FOR:
7846 block = c_begin_omp_parallel ();
7847 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7848 stmt = c_parser_omp_for_loop (parser);
7850 OMP_FOR_CLAUSES (stmt) = ws_clause;
7851 stmt = c_finish_omp_parallel (par_clause, block);
7852 OMP_PARALLEL_COMBINED (stmt) = 1;
7855 case PRAGMA_OMP_PARALLEL_SECTIONS:
7856 block = c_begin_omp_parallel ();
7857 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7858 stmt = c_parser_omp_sections_scope (parser);
7860 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7861 stmt = c_finish_omp_parallel (par_clause, block);
7862 OMP_PARALLEL_COMBINED (stmt) = 1;
7873 # pragma omp single single-clause[optseq] new-line
7877 #define OMP_SINGLE_CLAUSE_MASK \
7878 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7879 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7880 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7881 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7884 c_parser_omp_single (c_parser *parser)
7886 tree stmt = make_node (OMP_SINGLE);
7887 TREE_TYPE (stmt) = void_type_node;
7889 OMP_SINGLE_CLAUSES (stmt)
7890 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7891 "#pragma omp single");
7892 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7894 return add_stmt (stmt);
7898 /* Main entry point to parsing most OpenMP pragmas. */
7901 c_parser_omp_construct (c_parser *parser)
7903 enum pragma_kind p_kind;
7907 loc = c_parser_peek_token (parser)->location;
7908 p_kind = c_parser_peek_token (parser)->pragma_kind;
7909 c_parser_consume_pragma (parser);
7911 /* For all constructs below except #pragma omp atomic
7912 MUST_NOT_THROW catch handlers are needed when exceptions
7914 if (p_kind != PRAGMA_OMP_ATOMIC)
7915 c_maybe_initialize_eh ();
7919 case PRAGMA_OMP_ATOMIC:
7920 c_parser_omp_atomic (parser);
7922 case PRAGMA_OMP_CRITICAL:
7923 stmt = c_parser_omp_critical (parser);
7925 case PRAGMA_OMP_FOR:
7926 stmt = c_parser_omp_for (parser);
7928 case PRAGMA_OMP_MASTER:
7929 stmt = c_parser_omp_master (parser);
7931 case PRAGMA_OMP_ORDERED:
7932 stmt = c_parser_omp_ordered (parser);
7934 case PRAGMA_OMP_PARALLEL:
7935 stmt = c_parser_omp_parallel (parser);
7937 case PRAGMA_OMP_SECTIONS:
7938 stmt = c_parser_omp_sections (parser);
7940 case PRAGMA_OMP_SINGLE:
7941 stmt = c_parser_omp_single (parser);
7948 SET_EXPR_LOCATION (stmt, loc);
7953 # pragma omp threadprivate (variable-list) */
7956 c_parser_omp_threadprivate (c_parser *parser)
7960 c_parser_consume_pragma (parser);
7961 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7963 /* Mark every variable in VARS to be assigned thread local storage. */
7964 for (t = vars; t; t = TREE_CHAIN (t))
7966 tree v = TREE_PURPOSE (t);
7968 /* If V had already been marked threadprivate, it doesn't matter
7969 whether it had been used prior to this point. */
7970 if (TREE_CODE (v) != VAR_DECL)
7971 error ("%qD is not a variable", v);
7972 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7973 error ("%qE declared %<threadprivate%> after first use", v);
7974 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7975 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7976 else if (TREE_TYPE (v) == error_mark_node)
7978 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7979 error ("%<threadprivate%> %qE has incomplete type", v);
7982 if (! DECL_THREAD_LOCAL_P (v))
7984 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7985 /* If rtl has been already set for this var, call
7986 make_decl_rtl once again, so that encode_section_info
7987 has a chance to look at the new decl flags. */
7988 if (DECL_RTL_SET_P (v))
7991 C_DECL_THREADPRIVATE_P (v) = 1;
7995 c_parser_skip_to_pragma_eol (parser);
7999 /* Parse a single source file. */
8004 /* Use local storage to begin. If the first token is a pragma, parse it.
8005 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8006 which will cause garbage collection. */
8009 memset (&tparser, 0, sizeof tparser);
8010 the_parser = &tparser;
8012 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8013 c_parser_pragma_pch_preprocess (&tparser);
8015 the_parser = GGC_NEW (c_parser);
8016 *the_parser = tparser;
8018 c_parser_translation_unit (the_parser);
8022 #include "gt-c-parser.h"