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 *);
1021 static void c_parser_omp_taskwait (c_parser *);
1023 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1024 static bool c_parser_pragma (c_parser *, enum pragma_context);
1026 /* These Objective-C parser functions are only ever called when
1027 compiling Objective-C. */
1028 static void c_parser_objc_class_definition (c_parser *);
1029 static void c_parser_objc_class_instance_variables (c_parser *);
1030 static void c_parser_objc_class_declaration (c_parser *);
1031 static void c_parser_objc_alias_declaration (c_parser *);
1032 static void c_parser_objc_protocol_definition (c_parser *);
1033 static enum tree_code c_parser_objc_method_type (c_parser *);
1034 static void c_parser_objc_method_definition (c_parser *);
1035 static void c_parser_objc_methodprotolist (c_parser *);
1036 static void c_parser_objc_methodproto (c_parser *);
1037 static tree c_parser_objc_method_decl (c_parser *);
1038 static tree c_parser_objc_type_name (c_parser *);
1039 static tree c_parser_objc_protocol_refs (c_parser *);
1040 static void c_parser_objc_try_catch_statement (c_parser *);
1041 static void c_parser_objc_synchronized_statement (c_parser *);
1042 static tree c_parser_objc_selector (c_parser *);
1043 static tree c_parser_objc_selector_arg (c_parser *);
1044 static tree c_parser_objc_receiver (c_parser *);
1045 static tree c_parser_objc_message_args (c_parser *);
1046 static tree c_parser_objc_keywordexpr (c_parser *);
1048 /* Parse a translation unit (C90 6.7, C99 6.9).
1051 external-declarations
1053 external-declarations:
1054 external-declaration
1055 external-declarations external-declaration
1064 c_parser_translation_unit (c_parser *parser)
1066 if (c_parser_next_token_is (parser, CPP_EOF))
1069 pedwarn ("%HISO C forbids an empty translation unit",
1070 &c_parser_peek_token (parser)->location);
1074 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1078 c_parser_external_declaration (parser);
1079 obstack_free (&parser_obstack, obstack_position);
1081 while (c_parser_next_token_is_not (parser, CPP_EOF));
1085 /* Parse an external declaration (C90 6.7, C99 6.9).
1087 external-declaration:
1093 external-declaration:
1096 __extension__ external-declaration
1100 external-declaration:
1101 objc-class-definition
1102 objc-class-declaration
1103 objc-alias-declaration
1104 objc-protocol-definition
1105 objc-method-definition
1110 c_parser_external_declaration (c_parser *parser)
1113 switch (c_parser_peek_token (parser)->type)
1116 switch (c_parser_peek_token (parser)->keyword)
1119 ext = disable_extension_diagnostics ();
1120 c_parser_consume_token (parser);
1121 c_parser_external_declaration (parser);
1122 restore_extension_diagnostics (ext);
1125 c_parser_asm_definition (parser);
1127 case RID_AT_INTERFACE:
1128 case RID_AT_IMPLEMENTATION:
1129 gcc_assert (c_dialect_objc ());
1130 c_parser_objc_class_definition (parser);
1133 gcc_assert (c_dialect_objc ());
1134 c_parser_objc_class_declaration (parser);
1137 gcc_assert (c_dialect_objc ());
1138 c_parser_objc_alias_declaration (parser);
1140 case RID_AT_PROTOCOL:
1141 gcc_assert (c_dialect_objc ());
1142 c_parser_objc_protocol_definition (parser);
1145 gcc_assert (c_dialect_objc ());
1146 c_parser_consume_token (parser);
1147 objc_finish_implementation ();
1155 pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
1156 &c_parser_peek_token (parser)->location);
1157 c_parser_consume_token (parser);
1160 c_parser_pragma (parser, pragma_external);
1164 if (c_dialect_objc ())
1166 c_parser_objc_method_definition (parser);
1169 /* Else fall through, and yield a syntax error trying to parse
1170 as a declaration or function definition. */
1173 /* A declaration or a function definition. We can only tell
1174 which after parsing the declaration specifiers, if any, and
1175 the first declarator. */
1176 c_parser_declaration_or_fndef (parser, true, true, false, true);
1182 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1183 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1184 accepted; otherwise (old-style parameter declarations) only other
1185 declarations are accepted. If NESTED is true, we are inside a
1186 function or parsing old-style parameter declarations; any functions
1187 encountered are nested functions and declaration specifiers are
1188 required; otherwise we are at top level and functions are normal
1189 functions and declaration specifiers may be optional. If EMPTY_OK
1190 is true, empty declarations are OK (subject to all other
1191 constraints); otherwise (old-style parameter declarations) they are
1192 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1193 may start with attributes; otherwise they may not.
1196 declaration-specifiers init-declarator-list[opt] ;
1198 function-definition:
1199 declaration-specifiers[opt] declarator declaration-list[opt]
1204 declaration-list declaration
1206 init-declarator-list:
1208 init-declarator-list , init-declarator
1211 declarator simple-asm-expr[opt] attributes[opt]
1212 declarator simple-asm-expr[opt] attributes[opt] = initializer
1216 nested-function-definition:
1217 declaration-specifiers declarator declaration-list[opt]
1220 The simple-asm-expr and attributes are GNU extensions.
1222 This function does not handle __extension__; that is handled in its
1223 callers. ??? Following the old parser, __extension__ may start
1224 external declarations, declarations in functions and declarations
1225 at the start of "for" loops, but not old-style parameter
1228 C99 requires declaration specifiers in a function definition; the
1229 absence is diagnosed through the diagnosis of implicit int. In GNU
1230 C we also allow but diagnose declarations without declaration
1231 specifiers, but only at top level (elsewhere they conflict with
1237 threadprivate-directive */
1240 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1241 bool nested, bool start_attr_ok)
1243 struct c_declspecs *specs;
1245 tree all_prefix_attrs;
1246 bool diagnosed_no_specs = false;
1247 location_t here = c_parser_peek_token (parser)->location;
1249 specs = build_null_declspecs ();
1250 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1253 c_parser_skip_to_end_of_block_or_statement (parser);
1256 if (nested && !specs->declspecs_seen_p)
1258 c_parser_error (parser, "expected declaration specifiers");
1259 c_parser_skip_to_end_of_block_or_statement (parser);
1262 finish_declspecs (specs);
1263 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1269 shadow_tag_warned (specs, 1);
1270 pedwarn ("%Hempty declaration", &here);
1272 c_parser_consume_token (parser);
1275 pending_xref_error ();
1276 prefix_attrs = specs->attrs;
1277 all_prefix_attrs = prefix_attrs;
1278 specs->attrs = NULL_TREE;
1281 struct c_declarator *declarator;
1284 /* Declaring either one or more declarators (in which case we
1285 should diagnose if there were no declaration specifiers) or a
1286 function definition (in which case the diagnostic for
1287 implicit int suffices). */
1288 declarator = c_parser_declarator (parser, specs->type_seen_p,
1289 C_DTR_NORMAL, &dummy);
1290 if (declarator == NULL)
1292 c_parser_skip_to_end_of_block_or_statement (parser);
1295 if (c_parser_next_token_is (parser, CPP_EQ)
1296 || c_parser_next_token_is (parser, CPP_COMMA)
1297 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1298 || c_parser_next_token_is_keyword (parser, RID_ASM)
1299 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1301 tree asm_name = NULL_TREE;
1302 tree postfix_attrs = NULL_TREE;
1303 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1305 diagnosed_no_specs = true;
1306 pedwarn ("%Hdata definition has no type or storage class",
1309 /* Having seen a data definition, there cannot now be a
1310 function definition. */
1312 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1313 asm_name = c_parser_simple_asm_expr (parser);
1314 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1315 postfix_attrs = c_parser_attributes (parser);
1316 if (c_parser_next_token_is (parser, CPP_EQ))
1320 c_parser_consume_token (parser);
1321 /* The declaration of the variable is in effect while
1322 its initializer is parsed. */
1323 d = start_decl (declarator, specs, true,
1324 chainon (postfix_attrs, all_prefix_attrs));
1326 d = error_mark_node;
1327 start_init (d, asm_name, global_bindings_p ());
1328 init = c_parser_initializer (parser);
1330 if (d != error_mark_node)
1332 maybe_warn_string_init (TREE_TYPE (d), init);
1333 finish_decl (d, init.value, asm_name);
1338 tree d = start_decl (declarator, specs, false,
1339 chainon (postfix_attrs,
1342 finish_decl (d, NULL_TREE, asm_name);
1344 if (c_parser_next_token_is (parser, CPP_COMMA))
1346 c_parser_consume_token (parser);
1347 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1348 all_prefix_attrs = chainon (c_parser_attributes (parser),
1351 all_prefix_attrs = prefix_attrs;
1354 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1356 c_parser_consume_token (parser);
1361 c_parser_error (parser, "expected %<,%> or %<;%>");
1362 c_parser_skip_to_end_of_block_or_statement (parser);
1368 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1369 "%<asm%> or %<__attribute__%>");
1370 c_parser_skip_to_end_of_block_or_statement (parser);
1373 /* Function definition (nested or otherwise). */
1377 pedwarn ("%HISO C forbids nested functions", &here);
1378 c_push_function_context ();
1380 if (!start_function (specs, declarator, all_prefix_attrs))
1382 /* This can appear in many cases looking nothing like a
1383 function definition, so we don't give a more specific
1384 error suggesting there was one. */
1385 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1386 "or %<__attribute__%>");
1388 c_pop_function_context ();
1391 /* Parse old-style parameter declarations. ??? Attributes are
1392 not allowed to start declaration specifiers here because of a
1393 syntax conflict between a function declaration with attribute
1394 suffix and a function definition with an attribute prefix on
1395 first old-style parameter declaration. Following the old
1396 parser, they are not accepted on subsequent old-style
1397 parameter declarations either. However, there is no
1398 ambiguity after the first declaration, nor indeed on the
1399 first as long as we don't allow postfix attributes after a
1400 declarator with a nonempty identifier list in a definition;
1401 and postfix attributes have never been accepted here in
1402 function definitions either. */
1403 while (c_parser_next_token_is_not (parser, CPP_EOF)
1404 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1405 c_parser_declaration_or_fndef (parser, false, false, true, false);
1406 DECL_SOURCE_LOCATION (current_function_decl)
1407 = c_parser_peek_token (parser)->location;
1408 store_parm_decls ();
1409 fnbody = c_parser_compound_statement (parser);
1412 tree decl = current_function_decl;
1415 c_pop_function_context ();
1416 add_stmt (build_stmt (DECL_EXPR, decl));
1427 /* Parse an asm-definition (asm() outside a function body). This is a
1435 c_parser_asm_definition (c_parser *parser)
1437 tree asm_str = c_parser_simple_asm_expr (parser);
1439 cgraph_add_asm_node (asm_str);
1440 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1443 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1444 6.7), adding them to SPECS (which may already include some).
1445 Storage class specifiers are accepted iff SCSPEC_OK; type
1446 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1447 the start iff START_ATTR_OK.
1449 declaration-specifiers:
1450 storage-class-specifier declaration-specifiers[opt]
1451 type-specifier declaration-specifiers[opt]
1452 type-qualifier declaration-specifiers[opt]
1453 function-specifier declaration-specifiers[opt]
1455 Function specifiers (inline) are from C99, and are currently
1456 handled as storage class specifiers, as is __thread.
1458 C90 6.5.1, C99 6.7.1:
1459 storage-class-specifier:
1470 C90 6.5.2, C99 6.7.2:
1483 [_Imaginary removed in C99 TC2]
1484 struct-or-union-specifier
1488 (_Bool and _Complex are new in C99.)
1490 C90 6.5.3, C99 6.7.3:
1497 (restrict is new in C99.)
1501 declaration-specifiers:
1502 attributes declaration-specifiers[opt]
1504 storage-class-specifier:
1516 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1517 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1522 class-name objc-protocol-refs[opt]
1523 typedef-name objc-protocol-refs
1528 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1529 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1531 bool attrs_ok = start_attr_ok;
1532 bool seen_type = specs->type_seen_p;
1533 while (c_parser_next_token_is (parser, CPP_NAME)
1534 || c_parser_next_token_is (parser, CPP_KEYWORD)
1535 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1537 struct c_typespec t;
1539 if (c_parser_next_token_is (parser, CPP_NAME))
1541 tree value = c_parser_peek_token (parser)->value;
1542 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1543 /* This finishes the specifiers unless a type name is OK, it
1544 is declared as a type name and a type name hasn't yet
1546 if (!typespec_ok || seen_type
1547 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1549 c_parser_consume_token (parser);
1552 if (kind == C_ID_TYPENAME
1553 && (!c_dialect_objc ()
1554 || c_parser_next_token_is_not (parser, CPP_LESS)))
1556 t.kind = ctsk_typedef;
1557 /* For a typedef name, record the meaning, not the name.
1558 In case of 'foo foo, bar;'. */
1559 t.spec = lookup_name (value);
1563 tree proto = NULL_TREE;
1564 gcc_assert (c_dialect_objc ());
1566 if (c_parser_next_token_is (parser, CPP_LESS))
1567 proto = c_parser_objc_protocol_refs (parser);
1568 t.spec = objc_get_protocol_qualified_type (value, proto);
1570 declspecs_add_type (specs, t);
1573 if (c_parser_next_token_is (parser, CPP_LESS))
1575 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1576 nisse@lysator.liu.se. */
1578 gcc_assert (c_dialect_objc ());
1579 if (!typespec_ok || seen_type)
1581 proto = c_parser_objc_protocol_refs (parser);
1583 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1584 declspecs_add_type (specs, t);
1587 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1588 switch (c_parser_peek_token (parser)->keyword)
1600 /* TODO: Distinguish between function specifiers (inline)
1601 and storage class specifiers, either here or in
1602 declspecs_add_scspec. */
1603 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1604 c_parser_consume_token (parser);
1627 if (c_dialect_objc ())
1628 parser->objc_need_raw_identifier = true;
1629 t.kind = ctsk_resword;
1630 t.spec = c_parser_peek_token (parser)->value;
1631 declspecs_add_type (specs, t);
1632 c_parser_consume_token (parser);
1639 t = c_parser_enum_specifier (parser);
1640 declspecs_add_type (specs, t);
1648 t = c_parser_struct_or_union_specifier (parser);
1649 declspecs_add_type (specs, t);
1652 /* ??? The old parser rejected typeof after other type
1653 specifiers, but is a syntax error the best way of
1655 if (!typespec_ok || seen_type)
1659 t = c_parser_typeof_specifier (parser);
1660 declspecs_add_type (specs, t);
1666 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1667 c_parser_consume_token (parser);
1672 attrs = c_parser_attributes (parser);
1673 declspecs_add_attrs (specs, attrs);
1682 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1685 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1686 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1687 enum attributes[opt] identifier
1689 The form with trailing comma is new in C99. The forms with
1690 attributes are GNU extensions. In GNU C, we accept any expression
1691 without commas in the syntax (assignment expressions, not just
1692 conditional expressions); assignment expressions will be diagnosed
1697 enumerator-list , enumerator
1700 enumeration-constant
1701 enumeration-constant = constant-expression
1704 static struct c_typespec
1705 c_parser_enum_specifier (c_parser *parser)
1707 struct c_typespec ret;
1709 tree ident = NULL_TREE;
1710 location_t ident_loc;
1711 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1712 c_parser_consume_token (parser);
1713 attrs = c_parser_attributes (parser);
1714 /* Set the location in case we create a decl now. */
1715 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1716 if (c_parser_next_token_is (parser, CPP_NAME))
1718 ident = c_parser_peek_token (parser)->value;
1719 ident_loc = c_parser_peek_token (parser)->location;
1720 c_parser_consume_token (parser);
1722 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1724 /* Parse an enum definition. */
1725 struct c_enum_contents the_enum;
1726 tree type = start_enum (&the_enum, ident);
1728 /* We chain the enumerators in reverse order, then put them in
1729 forward order at the end. */
1730 tree values = NULL_TREE;
1731 c_parser_consume_token (parser);
1739 location_t comma_loc;
1740 if (c_parser_next_token_is_not (parser, CPP_NAME))
1742 c_parser_error (parser, "expected identifier");
1743 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1744 values = error_mark_node;
1747 token = c_parser_peek_token (parser);
1748 enum_id = token->value;
1749 /* Set the location in case we create a decl now. */
1750 c_parser_set_source_position_from_token (token);
1751 c_parser_consume_token (parser);
1752 if (c_parser_next_token_is (parser, CPP_EQ))
1754 c_parser_consume_token (parser);
1755 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1758 enum_value = NULL_TREE;
1759 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1760 TREE_CHAIN (enum_decl) = values;
1763 if (c_parser_next_token_is (parser, CPP_COMMA))
1765 comma_loc = c_parser_peek_token (parser)->location;
1767 c_parser_consume_token (parser);
1769 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1771 if (seen_comma && pedantic && !flag_isoc99)
1772 pedwarn ("%Hcomma at end of enumerator list", &comma_loc);
1773 c_parser_consume_token (parser);
1778 c_parser_error (parser, "expected %<,%> or %<}%>");
1779 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1780 values = error_mark_node;
1784 postfix_attrs = c_parser_attributes (parser);
1785 ret.spec = finish_enum (type, nreverse (values),
1786 chainon (attrs, postfix_attrs));
1787 ret.kind = ctsk_tagdef;
1792 c_parser_error (parser, "expected %<{%>");
1793 ret.spec = error_mark_node;
1794 ret.kind = ctsk_tagref;
1797 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1798 /* In ISO C, enumerated types can be referred to only if already
1800 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1803 pedwarn ("%HISO C forbids forward references to %<enum%> types",
1809 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1811 struct-or-union-specifier:
1812 struct-or-union attributes[opt] identifier[opt]
1813 { struct-contents } attributes[opt]
1814 struct-or-union attributes[opt] identifier
1817 struct-declaration-list
1819 struct-declaration-list:
1820 struct-declaration ;
1821 struct-declaration-list struct-declaration ;
1828 struct-declaration-list struct-declaration
1830 struct-declaration-list:
1831 struct-declaration-list ;
1834 (Note that in the syntax here, unlike that in ISO C, the semicolons
1835 are included here rather than in struct-declaration, in order to
1836 describe the syntax with extra semicolons and missing semicolon at
1841 struct-declaration-list:
1842 @defs ( class-name )
1844 (Note this does not include a trailing semicolon, but can be
1845 followed by further declarations, and gets a pedwarn-if-pedantic
1846 when followed by a semicolon.) */
1848 static struct c_typespec
1849 c_parser_struct_or_union_specifier (c_parser *parser)
1851 struct c_typespec ret;
1853 tree ident = NULL_TREE;
1854 enum tree_code code;
1855 switch (c_parser_peek_token (parser)->keyword)
1866 c_parser_consume_token (parser);
1867 attrs = c_parser_attributes (parser);
1868 /* Set the location in case we create a decl now. */
1869 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1870 if (c_parser_next_token_is (parser, CPP_NAME))
1872 ident = c_parser_peek_token (parser)->value;
1873 c_parser_consume_token (parser);
1875 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1877 /* Parse a struct or union definition. Start the scope of the
1878 tag before parsing components. */
1879 tree type = start_struct (code, ident);
1881 /* We chain the components in reverse order, then put them in
1882 forward order at the end. Each struct-declaration may
1883 declare multiple components (comma-separated), so we must use
1884 chainon to join them, although when parsing each
1885 struct-declaration we can use TREE_CHAIN directly.
1887 The theory behind all this is that there will be more
1888 semicolon separated fields than comma separated fields, and
1889 so we'll be minimizing the number of node traversals required
1891 tree contents = NULL_TREE;
1892 c_parser_consume_token (parser);
1893 /* Handle the Objective-C @defs construct,
1894 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1895 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1898 gcc_assert (c_dialect_objc ());
1899 c_parser_consume_token (parser);
1900 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1902 if (c_parser_next_token_is (parser, CPP_NAME)
1903 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1905 name = c_parser_peek_token (parser)->value;
1906 c_parser_consume_token (parser);
1910 c_parser_error (parser, "expected class name");
1911 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1914 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1916 contents = nreverse (objc_get_class_ivars (name));
1919 /* Parse the struct-declarations and semicolons. Problems with
1920 semicolons are diagnosed here; empty structures are diagnosed
1925 /* Parse any stray semicolon. */
1926 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1929 pedwarn ("%Hextra semicolon in struct or union specified",
1930 &c_parser_peek_token (parser)->location);
1931 c_parser_consume_token (parser);
1934 /* Stop if at the end of the struct or union contents. */
1935 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1937 c_parser_consume_token (parser);
1940 /* Accept #pragmas at struct scope. */
1941 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1943 c_parser_pragma (parser, pragma_external);
1946 /* Parse some comma-separated declarations, but not the
1947 trailing semicolon if any. */
1948 decls = c_parser_struct_declaration (parser);
1949 contents = chainon (decls, contents);
1950 /* If no semicolon follows, either we have a parse error or
1951 are at the end of the struct or union and should
1953 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1954 c_parser_consume_token (parser);
1957 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1958 pedwarn ("%Hno semicolon at end of struct or union",
1959 &c_parser_peek_token (parser)->location);
1962 c_parser_error (parser, "expected %<;%>");
1963 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1968 postfix_attrs = c_parser_attributes (parser);
1969 ret.spec = finish_struct (type, nreverse (contents),
1970 chainon (attrs, postfix_attrs));
1971 ret.kind = ctsk_tagdef;
1976 c_parser_error (parser, "expected %<{%>");
1977 ret.spec = error_mark_node;
1978 ret.kind = ctsk_tagref;
1981 ret = parser_xref_tag (code, ident);
1985 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1986 the trailing semicolon.
1989 specifier-qualifier-list struct-declarator-list
1991 specifier-qualifier-list:
1992 type-specifier specifier-qualifier-list[opt]
1993 type-qualifier specifier-qualifier-list[opt]
1994 attributes specifier-qualifier-list[opt]
1996 struct-declarator-list:
1998 struct-declarator-list , attributes[opt] struct-declarator
2001 declarator attributes[opt]
2002 declarator[opt] : constant-expression attributes[opt]
2007 __extension__ struct-declaration
2008 specifier-qualifier-list
2010 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2011 of attributes where shown is a GNU extension. In GNU C, we accept
2012 any expression without commas in the syntax (assignment
2013 expressions, not just conditional expressions); assignment
2014 expressions will be diagnosed as non-constant. */
2017 c_parser_struct_declaration (c_parser *parser)
2019 struct c_declspecs *specs;
2021 tree all_prefix_attrs;
2023 location_t decl_loc;
2024 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2028 ext = disable_extension_diagnostics ();
2029 c_parser_consume_token (parser);
2030 decl = c_parser_struct_declaration (parser);
2031 restore_extension_diagnostics (ext);
2034 specs = build_null_declspecs ();
2035 decl_loc = c_parser_peek_token (parser)->location;
2036 c_parser_declspecs (parser, specs, false, true, true);
2039 if (!specs->declspecs_seen_p)
2041 c_parser_error (parser, "expected specifier-qualifier-list");
2044 finish_declspecs (specs);
2045 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2048 if (!specs->type_seen_p)
2051 pedwarn ("%HISO C forbids member declarations with no members",
2053 shadow_tag_warned (specs, pedantic);
2058 /* Support for unnamed structs or unions as members of
2059 structs or unions (which is [a] useful and [b] supports
2062 ret = grokfield (build_id_declarator (NULL_TREE), specs,
2065 decl_attributes (&ret, attrs, 0);
2069 pending_xref_error ();
2070 prefix_attrs = specs->attrs;
2071 all_prefix_attrs = prefix_attrs;
2072 specs->attrs = NULL_TREE;
2076 /* Declaring one or more declarators or un-named bit-fields. */
2077 struct c_declarator *declarator;
2079 if (c_parser_next_token_is (parser, CPP_COLON))
2080 declarator = build_id_declarator (NULL_TREE);
2082 declarator = c_parser_declarator (parser, specs->type_seen_p,
2083 C_DTR_NORMAL, &dummy);
2084 if (declarator == NULL)
2086 c_parser_skip_to_end_of_block_or_statement (parser);
2089 if (c_parser_next_token_is (parser, CPP_COLON)
2090 || c_parser_next_token_is (parser, CPP_COMMA)
2091 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2092 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2093 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2095 tree postfix_attrs = NULL_TREE;
2096 tree width = NULL_TREE;
2098 if (c_parser_next_token_is (parser, CPP_COLON))
2100 c_parser_consume_token (parser);
2101 width = c_parser_expr_no_commas (parser, NULL).value;
2103 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2104 postfix_attrs = c_parser_attributes (parser);
2105 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2106 decl_attributes (&d, chainon (postfix_attrs,
2107 all_prefix_attrs), 0);
2108 TREE_CHAIN (d) = decls;
2110 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2111 all_prefix_attrs = chainon (c_parser_attributes (parser),
2114 all_prefix_attrs = prefix_attrs;
2115 if (c_parser_next_token_is (parser, CPP_COMMA))
2116 c_parser_consume_token (parser);
2117 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2118 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2120 /* Semicolon consumed in caller. */
2125 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2131 c_parser_error (parser,
2132 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2133 "%<__attribute__%>");
2140 /* Parse a typeof specifier (a GNU extension).
2143 typeof ( expression )
2144 typeof ( type-name )
2147 static struct c_typespec
2148 c_parser_typeof_specifier (c_parser *parser)
2150 struct c_typespec ret;
2151 ret.kind = ctsk_typeof;
2152 ret.spec = error_mark_node;
2153 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2154 c_parser_consume_token (parser);
2157 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2163 if (c_parser_next_token_starts_typename (parser))
2165 struct c_type_name *type = c_parser_type_name (parser);
2170 ret.spec = groktypename (type);
2171 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2177 location_t here = c_parser_peek_token (parser)->location;
2178 struct c_expr expr = c_parser_expression (parser);
2181 if (TREE_CODE (expr.value) == COMPONENT_REF
2182 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2183 error ("%H%<typeof%> applied to a bit-field", &here);
2184 ret.spec = TREE_TYPE (expr.value);
2185 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2186 /* This should be returned with the type so that when the type
2187 is evaluated, this can be evaluated. For now, we avoid
2188 evaluation when the context might. */
2189 if (!skip_evaluation && was_vm)
2191 tree e = expr.value;
2193 /* If the expression is not of a type to which we cannot assign a line
2194 number, wrap the thing in a no-op NOP_EXPR. */
2195 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2196 e = build1 (NOP_EXPR, void_type_node, e);
2198 if (CAN_HAVE_LOCATION_P (e))
2199 SET_EXPR_LOCATION (e, input_location);
2203 pop_maybe_used (was_vm);
2205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2209 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2210 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2211 be redeclared; otherwise it may not. KIND indicates which kind of
2212 declarator is wanted. Returns a valid declarator except in the
2213 case of a syntax error in which case NULL is returned. *SEEN_ID is
2214 set to true if an identifier being declared is seen; this is used
2215 to diagnose bad forms of abstract array declarators and to
2216 determine whether an identifier list is syntactically permitted.
2219 pointer[opt] direct-declarator
2223 ( attributes[opt] declarator )
2224 direct-declarator array-declarator
2225 direct-declarator ( parameter-type-list )
2226 direct-declarator ( identifier-list[opt] )
2229 * type-qualifier-list[opt]
2230 * type-qualifier-list[opt] pointer
2232 type-qualifier-list:
2235 type-qualifier-list type-qualifier
2236 type-qualifier-list attributes
2238 parameter-type-list:
2240 parameter-list , ...
2243 parameter-declaration
2244 parameter-list , parameter-declaration
2246 parameter-declaration:
2247 declaration-specifiers declarator attributes[opt]
2248 declaration-specifiers abstract-declarator[opt] attributes[opt]
2252 identifier-list , identifier
2254 abstract-declarator:
2256 pointer[opt] direct-abstract-declarator
2258 direct-abstract-declarator:
2259 ( attributes[opt] abstract-declarator )
2260 direct-abstract-declarator[opt] array-declarator
2261 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2266 direct-declarator ( parameter-forward-declarations
2267 parameter-type-list[opt] )
2269 direct-abstract-declarator:
2270 direct-abstract-declarator[opt] ( parameter-forward-declarations
2271 parameter-type-list[opt] )
2273 parameter-forward-declarations:
2275 parameter-forward-declarations parameter-list ;
2277 The uses of attributes shown above are GNU extensions.
2279 Some forms of array declarator are not included in C99 in the
2280 syntax for abstract declarators; these are disallowed elsewhere.
2281 This may be a defect (DR#289).
2283 This function also accepts an omitted abstract declarator as being
2284 an abstract declarator, although not part of the formal syntax. */
2286 static struct c_declarator *
2287 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2290 /* Parse any initial pointer part. */
2291 if (c_parser_next_token_is (parser, CPP_MULT))
2293 struct c_declspecs *quals_attrs = build_null_declspecs ();
2294 struct c_declarator *inner;
2295 c_parser_consume_token (parser);
2296 c_parser_declspecs (parser, quals_attrs, false, false, true);
2297 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2301 return make_pointer_declarator (quals_attrs, inner);
2303 /* Now we have a direct declarator, direct abstract declarator or
2304 nothing (which counts as a direct abstract declarator here). */
2305 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2308 /* Parse a direct declarator or direct abstract declarator; arguments
2309 as c_parser_declarator. */
2311 static struct c_declarator *
2312 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2315 /* The direct declarator must start with an identifier (possibly
2316 omitted) or a parenthesized declarator (possibly abstract). In
2317 an ordinary declarator, initial parentheses must start a
2318 parenthesized declarator. In an abstract declarator or parameter
2319 declarator, they could start a parenthesized declarator or a
2320 parameter list. To tell which, the open parenthesis and any
2321 following attributes must be read. If a declaration specifier
2322 follows, then it is a parameter list; if the specifier is a
2323 typedef name, there might be an ambiguity about redeclaring it,
2324 which is resolved in the direction of treating it as a typedef
2325 name. If a close parenthesis follows, it is also an empty
2326 parameter list, as the syntax does not permit empty abstract
2327 declarators. Otherwise, it is a parenthesized declarator (in
2328 which case the analysis may be repeated inside it, recursively).
2330 ??? There is an ambiguity in a parameter declaration "int
2331 (__attribute__((foo)) x)", where x is not a typedef name: it
2332 could be an abstract declarator for a function, or declare x with
2333 parentheses. The proper resolution of this ambiguity needs
2334 documenting. At present we follow an accident of the old
2335 parser's implementation, whereby the first parameter must have
2336 some declaration specifiers other than just attributes. Thus as
2337 a parameter declaration it is treated as a parenthesized
2338 parameter named x, and as an abstract declarator it is
2341 ??? Also following the old parser, attributes inside an empty
2342 parameter list are ignored, making it a list not yielding a
2343 prototype, rather than giving an error or making it have one
2344 parameter with implicit type int.
2346 ??? Also following the old parser, typedef names may be
2347 redeclared in declarators, but not Objective-C class names. */
2349 if (kind != C_DTR_ABSTRACT
2350 && c_parser_next_token_is (parser, CPP_NAME)
2352 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2353 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2355 struct c_declarator *inner
2356 = build_id_declarator (c_parser_peek_token (parser)->value);
2358 inner->id_loc = c_parser_peek_token (parser)->location;
2359 c_parser_consume_token (parser);
2360 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2363 if (kind != C_DTR_NORMAL
2364 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2366 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2367 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2370 /* Either we are at the end of an abstract declarator, or we have
2373 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2376 struct c_declarator *inner;
2377 c_parser_consume_token (parser);
2378 attrs = c_parser_attributes (parser);
2379 if (kind != C_DTR_NORMAL
2380 && (c_parser_next_token_starts_declspecs (parser)
2381 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2383 struct c_arg_info *args
2384 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2391 = build_function_declarator (args,
2392 build_id_declarator (NULL_TREE));
2393 return c_parser_direct_declarator_inner (parser, *seen_id,
2397 /* A parenthesized declarator. */
2398 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2399 if (inner != NULL && attrs != NULL)
2400 inner = build_attrs_declarator (attrs, inner);
2401 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2403 c_parser_consume_token (parser);
2407 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2411 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2418 if (kind == C_DTR_NORMAL)
2420 c_parser_error (parser, "expected identifier or %<(%>");
2424 return build_id_declarator (NULL_TREE);
2428 /* Parse part of a direct declarator or direct abstract declarator,
2429 given that some (in INNER) has already been parsed; ID_PRESENT is
2430 true if an identifier is present, false for an abstract
2433 static struct c_declarator *
2434 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2435 struct c_declarator *inner)
2437 /* Parse a sequence of array declarators and parameter lists. */
2438 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2440 struct c_declarator *declarator;
2441 struct c_declspecs *quals_attrs = build_null_declspecs ();
2445 c_parser_consume_token (parser);
2446 c_parser_declspecs (parser, quals_attrs, false, false, true);
2447 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2449 c_parser_consume_token (parser);
2450 if (static_seen && !quals_attrs->declspecs_seen_p)
2451 c_parser_declspecs (parser, quals_attrs, false, false, true);
2452 if (!quals_attrs->declspecs_seen_p)
2454 /* If "static" is present, there must be an array dimension.
2455 Otherwise, there may be a dimension, "*", or no
2460 dimen = c_parser_expr_no_commas (parser, NULL).value;
2464 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2469 else if (c_parser_next_token_is (parser, CPP_MULT))
2471 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2475 c_parser_consume_token (parser);
2480 dimen = c_parser_expr_no_commas (parser, NULL).value;
2486 dimen = c_parser_expr_no_commas (parser, NULL).value;
2489 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2490 c_parser_consume_token (parser);
2493 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2497 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2499 if (declarator == NULL)
2501 inner = set_array_declarator_inner (declarator, inner);
2502 return c_parser_direct_declarator_inner (parser, id_present, inner);
2504 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2507 struct c_arg_info *args;
2508 c_parser_consume_token (parser);
2509 attrs = c_parser_attributes (parser);
2510 args = c_parser_parms_declarator (parser, id_present, attrs);
2515 inner = build_function_declarator (args, inner);
2516 return c_parser_direct_declarator_inner (parser, id_present, inner);
2522 /* Parse a parameter list or identifier list, including the closing
2523 parenthesis but not the opening one. ATTRS are the attributes at
2524 the start of the list. ID_LIST_OK is true if an identifier list is
2525 acceptable; such a list must not have attributes at the start. */
2527 static struct c_arg_info *
2528 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2531 declare_parm_level ();
2532 /* If the list starts with an identifier, it is an identifier list.
2533 Otherwise, it is either a prototype list or an empty list. */
2536 && c_parser_next_token_is (parser, CPP_NAME)
2537 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2539 tree list = NULL_TREE, *nextp = &list;
2540 while (c_parser_next_token_is (parser, CPP_NAME)
2541 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2543 *nextp = build_tree_list (NULL_TREE,
2544 c_parser_peek_token (parser)->value);
2545 nextp = & TREE_CHAIN (*nextp);
2546 c_parser_consume_token (parser);
2547 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2549 c_parser_consume_token (parser);
2550 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2552 c_parser_error (parser, "expected identifier");
2556 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2558 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2563 ret->pending_sizes = 0;
2564 ret->had_vla_unspec = 0;
2565 c_parser_consume_token (parser);
2571 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2579 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2585 /* Parse a parameter list (possibly empty), including the closing
2586 parenthesis but not the opening one. ATTRS are the attributes at
2587 the start of the list. */
2589 static struct c_arg_info *
2590 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2592 bool good_parm = false;
2593 /* ??? Following the old parser, forward parameter declarations may
2594 use abstract declarators, and if no real parameter declarations
2595 follow the forward declarations then this is not diagnosed. Also
2596 note as above that attributes are ignored as the only contents of
2597 the parentheses, or as the only contents after forward
2599 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2601 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2606 ret->pending_sizes = 0;
2607 ret->had_vla_unspec = 0;
2608 c_parser_consume_token (parser);
2611 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2613 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2617 ret->pending_sizes = 0;
2618 ret->had_vla_unspec = 0;
2619 /* Suppress -Wold-style-definition for this case. */
2620 ret->types = error_mark_node;
2621 error ("%HISO C requires a named argument before %<...%>",
2622 &c_parser_peek_token (parser)->location);
2623 c_parser_consume_token (parser);
2624 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2626 c_parser_consume_token (parser);
2631 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2636 /* Nonempty list of parameters, either terminated with semicolon
2637 (forward declarations; recurse) or with close parenthesis (normal
2638 function) or with ", ... )" (variadic function). */
2641 /* Parse a parameter. */
2642 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2647 push_parm_decl (parm);
2649 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2652 c_parser_consume_token (parser);
2653 mark_forward_parm_decls ();
2654 new_attrs = c_parser_attributes (parser);
2655 return c_parser_parms_list_declarator (parser, new_attrs);
2657 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2659 c_parser_consume_token (parser);
2661 return get_parm_info (false);
2664 struct c_arg_info *ret
2665 = XOBNEW (&parser_obstack, struct c_arg_info);
2670 ret->pending_sizes = 0;
2671 ret->had_vla_unspec = 0;
2675 if (!c_parser_require (parser, CPP_COMMA,
2676 "expected %<;%>, %<,%> or %<)%>"))
2678 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2681 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2683 c_parser_consume_token (parser);
2684 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2686 c_parser_consume_token (parser);
2688 return get_parm_info (true);
2691 struct c_arg_info *ret
2692 = XOBNEW (&parser_obstack, struct c_arg_info);
2697 ret->pending_sizes = 0;
2698 ret->had_vla_unspec = 0;
2704 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2712 /* Parse a parameter declaration. ATTRS are the attributes at the
2713 start of the declaration if it is the first parameter. */
2715 static struct c_parm *
2716 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2718 struct c_declspecs *specs;
2719 struct c_declarator *declarator;
2721 tree postfix_attrs = NULL_TREE;
2723 if (!c_parser_next_token_starts_declspecs (parser))
2725 /* ??? In some Objective-C cases '...' isn't applicable so there
2726 should be a different message. */
2727 c_parser_error (parser,
2728 "expected declaration specifiers or %<...%>");
2729 c_parser_skip_to_end_of_parameter (parser);
2732 specs = build_null_declspecs ();
2735 declspecs_add_attrs (specs, attrs);
2738 c_parser_declspecs (parser, specs, true, true, true);
2739 finish_declspecs (specs);
2740 pending_xref_error ();
2741 prefix_attrs = specs->attrs;
2742 specs->attrs = NULL_TREE;
2743 declarator = c_parser_declarator (parser, specs->type_seen_p,
2744 C_DTR_PARM, &dummy);
2745 if (declarator == NULL)
2747 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2750 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2751 postfix_attrs = c_parser_attributes (parser);
2752 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2756 /* Parse a string literal in an asm expression. It should not be
2757 translated, and wide string literals are an error although
2758 permitted by the syntax. This is a GNU extension.
2763 ??? At present, following the old parser, the caller needs to have
2764 set lex_untranslated_string to 1. It would be better to follow the
2765 C++ parser rather than using this kludge. */
2768 c_parser_asm_string_literal (c_parser *parser)
2771 if (c_parser_next_token_is (parser, CPP_STRING))
2773 str = c_parser_peek_token (parser)->value;
2774 c_parser_consume_token (parser);
2776 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2778 error ("%Hwide string literal in %<asm%>",
2779 &c_parser_peek_token (parser)->location);
2780 str = build_string (1, "");
2781 c_parser_consume_token (parser);
2785 c_parser_error (parser, "expected string literal");
2791 /* Parse a simple asm expression. This is used in restricted
2792 contexts, where a full expression with inputs and outputs does not
2793 make sense. This is a GNU extension.
2796 asm ( asm-string-literal )
2800 c_parser_simple_asm_expr (c_parser *parser)
2803 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2804 /* ??? Follow the C++ parser rather than using the
2805 lex_untranslated_string kludge. */
2806 parser->lex_untranslated_string = true;
2807 c_parser_consume_token (parser);
2808 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2810 parser->lex_untranslated_string = false;
2813 str = c_parser_asm_string_literal (parser);
2814 parser->lex_untranslated_string = false;
2815 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2817 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2823 /* Parse (possibly empty) attributes. This is a GNU extension.
2827 attributes attribute
2830 __attribute__ ( ( attribute-list ) )
2834 attribute_list , attrib
2839 any-word ( identifier )
2840 any-word ( identifier , nonempty-expr-list )
2841 any-word ( expr-list )
2843 where the "identifier" must not be declared as a type, and
2844 "any-word" may be any identifier (including one declared as a
2845 type), a reserved word storage class specifier, type specifier or
2846 type qualifier. ??? This still leaves out most reserved keywords
2847 (following the old parser), shouldn't we include them, and why not
2848 allow identifiers declared as types to start the arguments? */
2851 c_parser_attributes (c_parser *parser)
2853 tree attrs = NULL_TREE;
2854 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2856 /* ??? Follow the C++ parser rather than using the
2857 lex_untranslated_string kludge. */
2858 parser->lex_untranslated_string = true;
2859 c_parser_consume_token (parser);
2860 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2862 parser->lex_untranslated_string = false;
2865 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2867 parser->lex_untranslated_string = false;
2868 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2871 /* Parse the attribute list. */
2872 while (c_parser_next_token_is (parser, CPP_COMMA)
2873 || c_parser_next_token_is (parser, CPP_NAME)
2874 || c_parser_next_token_is (parser, CPP_KEYWORD))
2876 tree attr, attr_name, attr_args;
2877 if (c_parser_next_token_is (parser, CPP_COMMA))
2879 c_parser_consume_token (parser);
2882 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2884 /* ??? See comment above about what keywords are
2887 switch (c_parser_peek_token (parser)->keyword)
2925 attr_name = c_parser_peek_token (parser)->value;
2926 c_parser_consume_token (parser);
2927 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2929 attr = build_tree_list (attr_name, NULL_TREE);
2930 attrs = chainon (attrs, attr);
2933 c_parser_consume_token (parser);
2934 /* Parse the attribute contents. If they start with an
2935 identifier which is followed by a comma or close
2936 parenthesis, then the arguments start with that
2937 identifier; otherwise they are an expression list. */
2938 if (c_parser_next_token_is (parser, CPP_NAME)
2939 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2940 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2941 || (c_parser_peek_2nd_token (parser)->type
2942 == CPP_CLOSE_PAREN)))
2944 tree arg1 = c_parser_peek_token (parser)->value;
2945 c_parser_consume_token (parser);
2946 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2947 attr_args = build_tree_list (NULL_TREE, arg1);
2950 c_parser_consume_token (parser);
2951 attr_args = tree_cons (NULL_TREE, arg1,
2952 c_parser_expr_list (parser, false));
2957 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2958 attr_args = NULL_TREE;
2960 attr_args = c_parser_expr_list (parser, false);
2962 attr = build_tree_list (attr_name, attr_args);
2963 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2964 c_parser_consume_token (parser);
2967 parser->lex_untranslated_string = false;
2968 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2972 attrs = chainon (attrs, attr);
2974 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2975 c_parser_consume_token (parser);
2978 parser->lex_untranslated_string = false;
2979 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2983 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2984 c_parser_consume_token (parser);
2987 parser->lex_untranslated_string = false;
2988 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2992 parser->lex_untranslated_string = false;
2997 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3000 specifier-qualifier-list abstract-declarator[opt]
3003 static struct c_type_name *
3004 c_parser_type_name (c_parser *parser)
3006 struct c_declspecs *specs = build_null_declspecs ();
3007 struct c_declarator *declarator;
3008 struct c_type_name *ret;
3010 c_parser_declspecs (parser, specs, false, true, true);
3011 if (!specs->declspecs_seen_p)
3013 c_parser_error (parser, "expected specifier-qualifier-list");
3016 pending_xref_error ();
3017 finish_declspecs (specs);
3018 declarator = c_parser_declarator (parser, specs->type_seen_p,
3019 C_DTR_ABSTRACT, &dummy);
3020 if (declarator == NULL)
3022 ret = XOBNEW (&parser_obstack, struct c_type_name);
3024 ret->declarator = declarator;
3028 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3031 assignment-expression
3032 { initializer-list }
3033 { initializer-list , }
3036 designation[opt] initializer
3037 initializer-list , designation[opt] initializer
3044 designator-list designator
3051 [ constant-expression ]
3063 [ constant-expression ... constant-expression ]
3065 Any expression without commas is accepted in the syntax for the
3066 constant-expressions, with non-constant expressions rejected later.
3068 This function is only used for top-level initializers; for nested
3069 ones, see c_parser_initval. */
3071 static struct c_expr
3072 c_parser_initializer (c_parser *parser)
3074 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3075 return c_parser_braced_init (parser, NULL_TREE, false);
3079 ret = c_parser_expr_no_commas (parser, NULL);
3080 if (TREE_CODE (ret.value) != STRING_CST
3081 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3082 ret = default_function_array_conversion (ret);
3087 /* Parse a braced initializer list. TYPE is the type specified for a
3088 compound literal, and NULL_TREE for other initializers and for
3089 nested braced lists. NESTED_P is true for nested braced lists,
3090 false for the list of a compound literal or the list that is the
3091 top-level initializer in a declaration. */
3093 static struct c_expr
3094 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3096 location_t brace_loc = c_parser_peek_token (parser)->location;
3097 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3098 c_parser_consume_token (parser);
3100 push_init_level (0);
3102 really_start_incremental_init (type);
3103 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3106 pedwarn ("%HISO C forbids empty initializer braces", &brace_loc);
3110 /* Parse a non-empty initializer list, possibly with a trailing
3114 c_parser_initelt (parser);
3117 if (c_parser_next_token_is (parser, CPP_COMMA))
3118 c_parser_consume_token (parser);
3121 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3125 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3128 ret.value = error_mark_node;
3129 ret.original_code = ERROR_MARK;
3130 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3133 c_parser_consume_token (parser);
3134 return pop_init_level (0);
3137 /* Parse a nested initializer, including designators. */
3140 c_parser_initelt (c_parser *parser)
3142 /* Parse any designator or designator list. A single array
3143 designator may have the subsequent "=" omitted in GNU C, but a
3144 longer list or a structure member designator may not. */
3145 if (c_parser_next_token_is (parser, CPP_NAME)
3146 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3148 /* Old-style structure member designator. */
3149 set_init_label (c_parser_peek_token (parser)->value);
3152 /* Use the colon as the error location. */
3153 pedwarn ("%Hobsolete use of designated initializer with %<:%>",
3154 &c_parser_peek_2nd_token (parser)->location);
3156 c_parser_consume_token (parser);
3157 c_parser_consume_token (parser);
3161 /* des_seen is 0 if there have been no designators, 1 if there
3162 has been a single array designator and 2 otherwise. */
3164 /* Location of a designator. */
3166 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3167 || c_parser_next_token_is (parser, CPP_DOT))
3169 int des_prev = des_seen;
3171 des_loc = c_parser_peek_token (parser)->location;
3174 if (c_parser_next_token_is (parser, CPP_DOT))
3177 c_parser_consume_token (parser);
3178 if (c_parser_next_token_is (parser, CPP_NAME))
3180 set_init_label (c_parser_peek_token (parser)->value);
3181 c_parser_consume_token (parser);
3186 init.value = error_mark_node;
3187 init.original_code = ERROR_MARK;
3188 c_parser_error (parser, "expected identifier");
3189 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3190 process_init_element (init);
3197 location_t ellipsis_loc;
3198 /* ??? Following the old parser, [ objc-receiver
3199 objc-message-args ] is accepted as an initializer,
3200 being distinguished from a designator by what follows
3201 the first assignment expression inside the square
3202 brackets, but after a first array designator a
3203 subsequent square bracket is for Objective-C taken to
3204 start an expression, using the obsolete form of
3205 designated initializer without '=', rather than
3206 possibly being a second level of designation: in LALR
3207 terms, the '[' is shifted rather than reducing
3208 designator to designator-list. */
3209 if (des_prev == 1 && c_dialect_objc ())
3211 des_seen = des_prev;
3214 if (des_prev == 0 && c_dialect_objc ())
3216 /* This might be an array designator or an
3217 Objective-C message expression. If the former,
3218 continue parsing here; if the latter, parse the
3219 remainder of the initializer given the starting
3220 primary-expression. ??? It might make sense to
3221 distinguish when des_prev == 1 as well; see
3222 previous comment. */
3224 struct c_expr mexpr;
3225 c_parser_consume_token (parser);
3226 if (c_parser_peek_token (parser)->type == CPP_NAME
3227 && ((c_parser_peek_token (parser)->id_kind
3229 || (c_parser_peek_token (parser)->id_kind
3230 == C_ID_CLASSNAME)))
3232 /* Type name receiver. */
3233 tree id = c_parser_peek_token (parser)->value;
3234 c_parser_consume_token (parser);
3235 rec = objc_get_class_reference (id);
3236 goto parse_message_args;
3238 first = c_parser_expr_no_commas (parser, NULL).value;
3239 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3240 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3241 goto array_desig_after_first;
3242 /* Expression receiver. So far only one part
3243 without commas has been parsed; there might be
3244 more of the expression. */
3246 while (c_parser_next_token_is (parser, CPP_COMMA))
3249 c_parser_consume_token (parser);
3250 next = c_parser_expr_no_commas (parser, NULL);
3251 next = default_function_array_conversion (next);
3252 rec = build_compound_expr (rec, next.value);
3255 /* Now parse the objc-message-args. */
3256 args = c_parser_objc_message_args (parser);
3257 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3260 = objc_build_message_expr (build_tree_list (rec, args));
3261 mexpr.original_code = ERROR_MARK;
3262 /* Now parse and process the remainder of the
3263 initializer, starting with this message
3264 expression as a primary-expression. */
3265 c_parser_initval (parser, &mexpr);
3268 c_parser_consume_token (parser);
3269 first = c_parser_expr_no_commas (parser, NULL).value;
3270 array_desig_after_first:
3271 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3273 ellipsis_loc = c_parser_peek_token (parser)->location;
3274 c_parser_consume_token (parser);
3275 second = c_parser_expr_no_commas (parser, NULL).value;
3279 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3281 c_parser_consume_token (parser);
3282 set_init_index (first, second);
3283 if (pedantic && second)
3284 pedwarn ("%HISO C forbids specifying range of "
3285 "elements to initialize", &ellipsis_loc);
3288 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3294 if (c_parser_next_token_is (parser, CPP_EQ))
3296 if (pedantic && !flag_isoc99)
3297 pedwarn ("%HISO C90 forbids specifying subobject "
3298 "to initialize", &des_loc);
3299 c_parser_consume_token (parser);
3306 pedwarn ("%Hobsolete use of designated initializer "
3308 &c_parser_peek_token (parser)->location);
3313 init.value = error_mark_node;
3314 init.original_code = ERROR_MARK;
3315 c_parser_error (parser, "expected %<=%>");
3316 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3317 process_init_element (init);
3323 c_parser_initval (parser, NULL);
3326 /* Parse a nested initializer; as c_parser_initializer but parses
3327 initializers within braced lists, after any designators have been
3328 applied. If AFTER is not NULL then it is an Objective-C message
3329 expression which is the primary-expression starting the
3333 c_parser_initval (c_parser *parser, struct c_expr *after)
3336 gcc_assert (!after || c_dialect_objc ());
3337 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3338 init = c_parser_braced_init (parser, NULL_TREE, true);
3341 init = c_parser_expr_no_commas (parser, after);
3342 if (init.value != NULL_TREE
3343 && TREE_CODE (init.value) != STRING_CST
3344 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3345 init = default_function_array_conversion (init);
3347 process_init_element (init);
3350 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3354 { block-item-list[opt] }
3355 { label-declarations block-item-list }
3359 block-item-list block-item
3371 { label-declarations block-item-list }
3374 __extension__ nested-declaration
3375 nested-function-definition
3379 label-declarations label-declaration
3382 __label__ identifier-list ;
3384 Allowing the mixing of declarations and code is new in C99. The
3385 GNU syntax also permits (not shown above) labels at the end of
3386 compound statements, which yield an error. We don't allow labels
3387 on declarations; this might seem like a natural extension, but
3388 there would be a conflict between attributes on the label and
3389 prefix attributes on the declaration. ??? The syntax follows the
3390 old parser in requiring something after label declarations.
3391 Although they are erroneous if the labels declared aren't defined,
3392 is it useful for the syntax to be this way?
3404 c_parser_compound_statement (c_parser *parser)
3407 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3408 return error_mark_node;
3409 stmt = c_begin_compound_stmt (true);
3410 c_parser_compound_statement_nostart (parser);
3411 return c_end_compound_stmt (stmt, true);
3414 /* Parse a compound statement except for the opening brace. This is
3415 used for parsing both compound statements and statement expressions
3416 (which follow different paths to handling the opening). */
3419 c_parser_compound_statement_nostart (c_parser *parser)
3421 bool last_stmt = false;
3422 bool last_label = false;
3423 location_t label_loc;
3424 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3426 c_parser_consume_token (parser);
3429 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3431 location_t err_loc = c_parser_peek_token (parser)->location;
3432 /* Read zero or more forward-declarations for labels that nested
3433 functions can jump to. */
3434 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3436 c_parser_consume_token (parser);
3437 /* Any identifiers, including those declared as type names,
3442 if (c_parser_next_token_is_not (parser, CPP_NAME))
3444 c_parser_error (parser, "expected identifier");
3448 = declare_label (c_parser_peek_token (parser)->value);
3449 C_DECLARED_LABEL_FLAG (label) = 1;
3450 add_stmt (build_stmt (DECL_EXPR, label));
3451 c_parser_consume_token (parser);
3452 if (c_parser_next_token_is (parser, CPP_COMMA))
3453 c_parser_consume_token (parser);
3457 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3460 pedwarn ("%HISO C forbids label declarations", &err_loc);
3462 /* We must now have at least one statement, label or declaration. */
3463 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3465 c_parser_error (parser, "expected declaration or statement");
3466 c_parser_consume_token (parser);
3469 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3471 location_t loc = c_parser_peek_token (parser)->location;
3472 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3473 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3474 || (c_parser_next_token_is (parser, CPP_NAME)
3475 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3477 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3478 label_loc = c_parser_peek_2nd_token (parser)->location;
3480 label_loc = c_parser_peek_token (parser)->location;
3483 c_parser_label (parser);
3485 else if (!last_label
3486 && c_parser_next_token_starts_declspecs (parser))
3489 c_parser_declaration_or_fndef (parser, true, true, true, true);
3491 && ((pedantic && !flag_isoc99)
3492 || warn_declaration_after_statement))
3493 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3497 else if (!last_label
3498 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3500 /* __extension__ can start a declaration, but is also an
3501 unary operator that can start an expression. Consume all
3502 but the last of a possible series of __extension__ to
3504 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3505 && (c_parser_peek_2nd_token (parser)->keyword
3507 c_parser_consume_token (parser);
3508 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3511 ext = disable_extension_diagnostics ();
3512 c_parser_consume_token (parser);
3514 c_parser_declaration_or_fndef (parser, true, true, true, true);
3515 /* Following the old parser, __extension__ does not
3516 disable this diagnostic. */
3517 restore_extension_diagnostics (ext);
3519 && ((pedantic && !flag_isoc99)
3520 || warn_declaration_after_statement))
3521 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3528 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3530 /* External pragmas, and some omp pragmas, are not associated
3531 with regular c code, and so are not to be considered statements
3532 syntactically. This ensures that the user doesn't put them
3533 places that would turn into syntax errors if the directive
3535 if (c_parser_pragma (parser, pragma_compound))
3536 last_label = false, last_stmt = true;
3538 else if (c_parser_next_token_is (parser, CPP_EOF))
3540 c_parser_error (parser, "expected declaration or statement");
3543 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3545 if (parser->in_if_block)
3547 error ("%H""expected %<}%> before %<else%>", &loc);
3552 error ("%H%<else%> without a previous %<if%>", &loc);
3553 c_parser_consume_token (parser);
3562 c_parser_statement_after_labels (parser);
3565 parser->error = false;
3568 error ("%Hlabel at end of compound statement", &label_loc);
3569 c_parser_consume_token (parser);
3572 /* Parse a label (C90 6.6.1, C99 6.8.1).
3575 identifier : attributes[opt]
3576 case constant-expression :
3582 case constant-expression ... constant-expression :
3584 The use of attributes on labels is a GNU extension. The syntax in
3585 GNU C accepts any expressions without commas, non-constant
3586 expressions being rejected later. */
3589 c_parser_label (c_parser *parser)
3591 location_t loc1 = c_parser_peek_token (parser)->location;
3592 tree label = NULL_TREE;
3593 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3596 c_parser_consume_token (parser);
3597 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3598 if (c_parser_next_token_is (parser, CPP_COLON))
3600 c_parser_consume_token (parser);
3601 label = do_case (exp1, NULL_TREE);
3603 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3605 c_parser_consume_token (parser);
3606 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3607 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3608 label = do_case (exp1, exp2);
3611 c_parser_error (parser, "expected %<:%> or %<...%>");
3613 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3615 c_parser_consume_token (parser);
3616 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3617 label = do_case (NULL_TREE, NULL_TREE);
3621 tree name = c_parser_peek_token (parser)->value;
3624 location_t loc2 = c_parser_peek_token (parser)->location;
3625 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3626 c_parser_consume_token (parser);
3627 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3628 c_parser_consume_token (parser);
3629 attrs = c_parser_attributes (parser);
3630 tlab = define_label (loc2, name);
3633 decl_attributes (&tlab, attrs, 0);
3634 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3639 SET_EXPR_LOCATION (label, loc1);
3640 if (c_parser_next_token_starts_declspecs (parser)
3641 && !(c_parser_next_token_is (parser, CPP_NAME)
3642 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3644 error ("%Ha label can only be part of a statement and "
3645 "a declaration is not a statement",
3646 &c_parser_peek_token (parser)->location);
3647 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3648 /*nested*/ true, /*empty_ok*/ false,
3649 /*start_attr_ok*/ true);
3654 /* Parse a statement (C90 6.6, C99 6.8).
3659 expression-statement
3667 expression-statement:
3670 selection-statement:
3674 iteration-statement:
3683 return expression[opt] ;
3696 objc-throw-statement
3697 objc-try-catch-statement
3698 objc-synchronized-statement
3700 objc-throw-statement:
3714 parallel-for-construct
3715 parallel-sections-construct
3722 parallel-directive structured-block
3725 for-directive iteration-statement
3728 sections-directive section-scope
3731 single-directive structured-block
3733 parallel-for-construct:
3734 parallel-for-directive iteration-statement
3736 parallel-sections-construct:
3737 parallel-sections-directive section-scope
3740 master-directive structured-block
3743 critical-directive structured-block
3746 atomic-directive expression-statement
3749 ordered-directive structured-block */
3752 c_parser_statement (c_parser *parser)
3754 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3755 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3756 || (c_parser_next_token_is (parser, CPP_NAME)
3757 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3758 c_parser_label (parser);
3759 c_parser_statement_after_labels (parser);
3762 /* Parse a statement, other than a labeled statement. */
3765 c_parser_statement_after_labels (c_parser *parser)
3767 location_t loc = c_parser_peek_token (parser)->location;
3768 tree stmt = NULL_TREE;
3769 bool in_if_block = parser->in_if_block;
3770 parser->in_if_block = false;
3771 switch (c_parser_peek_token (parser)->type)
3773 case CPP_OPEN_BRACE:
3774 add_stmt (c_parser_compound_statement (parser));
3777 switch (c_parser_peek_token (parser)->keyword)
3780 c_parser_if_statement (parser);
3783 c_parser_switch_statement (parser);
3786 c_parser_while_statement (parser);
3789 c_parser_do_statement (parser);
3792 c_parser_for_statement (parser);
3795 c_parser_consume_token (parser);
3796 if (c_parser_next_token_is (parser, CPP_NAME))
3798 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3799 c_parser_consume_token (parser);
3801 else if (c_parser_next_token_is (parser, CPP_MULT))
3803 c_parser_consume_token (parser);
3804 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3807 c_parser_error (parser, "expected identifier or %<*%>");
3808 goto expect_semicolon;
3810 c_parser_consume_token (parser);
3811 stmt = c_finish_bc_stmt (&c_cont_label, false);
3812 goto expect_semicolon;
3814 c_parser_consume_token (parser);
3815 stmt = c_finish_bc_stmt (&c_break_label, true);
3816 goto expect_semicolon;
3818 c_parser_consume_token (parser);
3819 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3821 stmt = c_finish_return (NULL_TREE);
3822 c_parser_consume_token (parser);
3826 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3827 goto expect_semicolon;
3831 stmt = c_parser_asm_statement (parser);
3834 gcc_assert (c_dialect_objc ());
3835 c_parser_consume_token (parser);
3836 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3838 stmt = objc_build_throw_stmt (NULL_TREE);
3839 c_parser_consume_token (parser);
3844 = objc_build_throw_stmt (c_parser_expression (parser).value);
3845 goto expect_semicolon;
3849 gcc_assert (c_dialect_objc ());
3850 c_parser_objc_try_catch_statement (parser);
3852 case RID_AT_SYNCHRONIZED:
3853 gcc_assert (c_dialect_objc ());
3854 c_parser_objc_synchronized_statement (parser);
3861 c_parser_consume_token (parser);
3863 case CPP_CLOSE_PAREN:
3864 case CPP_CLOSE_SQUARE:
3865 /* Avoid infinite loop in error recovery:
3866 c_parser_skip_until_found stops at a closing nesting
3867 delimiter without consuming it, but here we need to consume
3868 it to proceed further. */
3869 c_parser_error (parser, "expected statement");
3870 c_parser_consume_token (parser);
3873 c_parser_pragma (parser, pragma_stmt);
3877 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3879 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3882 /* Two cases cannot and do not have line numbers associated: If stmt
3883 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3884 cannot hold line numbers. But that's OK because the statement
3885 will either be changed to a MODIFY_EXPR during gimplification of
3886 the statement expr, or discarded. If stmt was compound, but
3887 without new variables, we will have skipped the creation of a
3888 BIND and will have a bare STATEMENT_LIST. But that's OK because
3889 (recursively) all of the component statements should already have
3890 line numbers assigned. ??? Can we discard no-op statements
3892 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3893 SET_EXPR_LOCATION (stmt, loc);
3895 parser->in_if_block = in_if_block;
3898 /* Parse a parenthesized condition from an if, do or while statement.
3904 c_parser_paren_condition (c_parser *parser)
3908 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3909 return error_mark_node;
3910 loc = c_parser_peek_token (parser)->location;
3911 cond = c_objc_common_truthvalue_conversion
3912 (c_parser_expression_conv (parser).value);
3913 if (CAN_HAVE_LOCATION_P (cond))
3914 SET_EXPR_LOCATION (cond, loc);
3915 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3919 /* Parse a statement which is a block in C99. */
3922 c_parser_c99_block_statement (c_parser *parser)
3924 tree block = c_begin_compound_stmt (flag_isoc99);
3925 c_parser_statement (parser);
3926 return c_end_compound_stmt (block, flag_isoc99);
3929 /* Parse the body of an if statement. This is just parsing a
3930 statement but (a) it is a block in C99, (b) we track whether the
3931 body is an if statement for the sake of -Wparentheses warnings, (c)
3932 we handle an empty body specially for the sake of -Wempty-body
3933 warnings, and (d) we call parser_compound_statement directly
3934 because c_parser_statement_after_labels resets
3935 parser->in_if_block. */
3938 c_parser_if_body (c_parser *parser, bool *if_p)
3940 tree block = c_begin_compound_stmt (flag_isoc99);
3941 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3942 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3943 || (c_parser_next_token_is (parser, CPP_NAME)
3944 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3945 c_parser_label (parser);
3946 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3947 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3949 add_stmt (build_empty_stmt ());
3950 c_parser_consume_token (parser);
3952 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3953 add_stmt (c_parser_compound_statement (parser));
3955 c_parser_statement_after_labels (parser);
3956 return c_end_compound_stmt (block, flag_isoc99);
3959 /* Parse the else body of an if statement. This is just parsing a
3960 statement but (a) it is a block in C99, (b) we handle an empty body
3961 specially for the sake of -Wempty-body warnings. */
3964 c_parser_else_body (c_parser *parser)
3966 tree block = c_begin_compound_stmt (flag_isoc99);
3967 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3968 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3969 || (c_parser_next_token_is (parser, CPP_NAME)
3970 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3971 c_parser_label (parser);
3972 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3974 add_stmt (build_empty_stmt ());
3975 c_parser_consume_token (parser);
3978 c_parser_statement_after_labels (parser);
3979 return c_end_compound_stmt (block, flag_isoc99);
3982 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3985 if ( expression ) statement
3986 if ( expression ) statement else statement
3990 c_parser_if_statement (c_parser *parser)
3995 bool first_if = false;
3996 tree first_body, second_body;
3999 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4000 c_parser_consume_token (parser);
4001 block = c_begin_compound_stmt (flag_isoc99);
4002 loc = c_parser_peek_token (parser)->location;
4003 cond = c_parser_paren_condition (parser);
4004 in_if_block = parser->in_if_block;
4005 parser->in_if_block = true;
4006 first_body = c_parser_if_body (parser, &first_if);
4007 parser->in_if_block = in_if_block;
4008 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4010 c_parser_consume_token (parser);
4011 second_body = c_parser_else_body (parser);
4014 second_body = NULL_TREE;
4015 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4016 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4019 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4022 switch (expression) statement
4026 c_parser_switch_statement (c_parser *parser)
4028 tree block, expr, body, save_break;
4029 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4030 c_parser_consume_token (parser);
4031 block = c_begin_compound_stmt (flag_isoc99);
4032 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4034 expr = c_parser_expression (parser).value;
4035 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4038 expr = error_mark_node;
4039 c_start_case (expr);
4040 save_break = c_break_label;
4041 c_break_label = NULL_TREE;
4042 body = c_parser_c99_block_statement (parser);
4043 c_finish_case (body);
4045 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
4046 c_break_label = save_break;
4047 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4050 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4053 while (expression) statement
4057 c_parser_while_statement (c_parser *parser)
4059 tree block, cond, body, save_break, save_cont;
4061 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4062 c_parser_consume_token (parser);
4063 block = c_begin_compound_stmt (flag_isoc99);
4064 loc = c_parser_peek_token (parser)->location;
4065 cond = c_parser_paren_condition (parser);
4066 save_break = c_break_label;
4067 c_break_label = NULL_TREE;
4068 save_cont = c_cont_label;
4069 c_cont_label = NULL_TREE;
4070 body = c_parser_c99_block_statement (parser);
4071 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4072 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4073 c_break_label = save_break;
4074 c_cont_label = save_cont;
4077 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4080 do statement while ( expression ) ;
4084 c_parser_do_statement (c_parser *parser)
4086 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4088 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4089 c_parser_consume_token (parser);
4090 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4091 warning (OPT_Wempty_body,
4092 "%Hsuggest braces around empty body in %<do%> statement",
4093 &c_parser_peek_token (parser)->location);
4094 block = c_begin_compound_stmt (flag_isoc99);
4095 loc = c_parser_peek_token (parser)->location;
4096 save_break = c_break_label;
4097 c_break_label = NULL_TREE;
4098 save_cont = c_cont_label;
4099 c_cont_label = NULL_TREE;
4100 body = c_parser_c99_block_statement (parser);
4101 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4102 new_break = c_break_label;
4103 c_break_label = save_break;
4104 new_cont = c_cont_label;
4105 c_cont_label = save_cont;
4106 cond = c_parser_paren_condition (parser);
4107 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4108 c_parser_skip_to_end_of_block_or_statement (parser);
4109 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4110 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4113 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4116 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4117 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4119 The form with a declaration is new in C99.
4121 ??? In accordance with the old parser, the declaration may be a
4122 nested function, which is then rejected in check_for_loop_decls,
4123 but does it make any sense for this to be included in the grammar?
4124 Note in particular that the nested function does not include a
4125 trailing ';', whereas the "declaration" production includes one.
4126 Also, can we reject bad declarations earlier and cheaper than
4127 check_for_loop_decls? */
4130 c_parser_for_statement (c_parser *parser)
4132 tree block, cond, incr, save_break, save_cont, body;
4134 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4135 loc = c_parser_peek_token (parser)->location;
4136 c_parser_consume_token (parser);
4137 block = c_begin_compound_stmt (flag_isoc99);
4138 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4140 /* Parse the initialization declaration or expression. */
4141 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4143 c_parser_consume_token (parser);
4144 c_finish_expr_stmt (NULL_TREE);
4146 else if (c_parser_next_token_starts_declspecs (parser))
4148 c_parser_declaration_or_fndef (parser, true, true, true, true);
4149 check_for_loop_decls ();
4151 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4153 /* __extension__ can start a declaration, but is also an
4154 unary operator that can start an expression. Consume all
4155 but the last of a possible series of __extension__ to
4157 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4158 && (c_parser_peek_2nd_token (parser)->keyword
4160 c_parser_consume_token (parser);
4161 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4164 ext = disable_extension_diagnostics ();
4165 c_parser_consume_token (parser);
4166 c_parser_declaration_or_fndef (parser, true, true, true, true);
4167 restore_extension_diagnostics (ext);
4168 check_for_loop_decls ();
4176 c_finish_expr_stmt (c_parser_expression (parser).value);
4177 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4179 /* Parse the loop condition. */
4180 loc = c_parser_peek_token (parser)->location;
4181 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4183 c_parser_consume_token (parser);
4188 tree ocond = c_parser_expression_conv (parser).value;
4189 cond = c_objc_common_truthvalue_conversion (ocond);
4190 if (CAN_HAVE_LOCATION_P (cond))
4191 SET_EXPR_LOCATION (cond, loc);
4192 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4194 /* Parse the increment expression. */
4195 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4196 incr = c_process_expr_stmt (NULL_TREE);
4198 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4199 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4203 cond = error_mark_node;
4204 incr = error_mark_node;
4206 save_break = c_break_label;
4207 c_break_label = NULL_TREE;
4208 save_cont = c_cont_label;
4209 c_cont_label = NULL_TREE;
4210 body = c_parser_c99_block_statement (parser);
4211 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4212 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4213 c_break_label = save_break;
4214 c_cont_label = save_cont;
4217 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4218 statement with inputs, outputs, clobbers, and volatile tag
4222 asm type-qualifier[opt] ( asm-argument ) ;
4226 asm-string-literal : asm-operands[opt]
4227 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4228 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4230 Qualifiers other than volatile are accepted in the syntax but
4234 c_parser_asm_statement (c_parser *parser)
4236 tree quals, str, outputs, inputs, clobbers, ret;
4238 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4239 c_parser_consume_token (parser);
4240 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4242 quals = c_parser_peek_token (parser)->value;
4243 c_parser_consume_token (parser);
4245 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4246 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4248 warning (0, "%H%E qualifier ignored on asm",
4249 &c_parser_peek_token (parser)->location,
4250 c_parser_peek_token (parser)->value);
4252 c_parser_consume_token (parser);
4256 /* ??? Follow the C++ parser rather than using the
4257 lex_untranslated_string kludge. */
4258 parser->lex_untranslated_string = true;
4259 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4261 parser->lex_untranslated_string = false;
4264 str = c_parser_asm_string_literal (parser);
4265 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4268 outputs = NULL_TREE;
4270 clobbers = NULL_TREE;
4273 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4275 parser->lex_untranslated_string = false;
4276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4280 /* Parse outputs. */
4281 if (c_parser_next_token_is (parser, CPP_COLON)
4282 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4283 outputs = NULL_TREE;
4285 outputs = c_parser_asm_operands (parser, false);
4286 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4289 clobbers = NULL_TREE;
4292 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4294 parser->lex_untranslated_string = false;
4295 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4299 if (c_parser_next_token_is (parser, CPP_COLON)
4300 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4303 inputs = c_parser_asm_operands (parser, true);
4304 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4306 clobbers = NULL_TREE;
4309 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4311 parser->lex_untranslated_string = false;
4312 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4315 /* Parse clobbers. */
4316 clobbers = c_parser_asm_clobbers (parser);
4318 parser->lex_untranslated_string = false;
4319 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4321 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4324 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4325 c_parser_skip_to_end_of_block_or_statement (parser);
4326 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4331 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4332 not outputs), apply the default conversion of functions and arrays
4337 asm-operands , asm-operand
4340 asm-string-literal ( expression )
4341 [ identifier ] asm-string-literal ( expression )
4345 c_parser_asm_operands (c_parser *parser, bool convert_p)
4347 tree list = NULL_TREE;
4352 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4354 c_parser_consume_token (parser);
4355 if (c_parser_next_token_is (parser, CPP_NAME))
4357 tree id = c_parser_peek_token (parser)->value;
4358 c_parser_consume_token (parser);
4359 name = build_string (IDENTIFIER_LENGTH (id),
4360 IDENTIFIER_POINTER (id));
4364 c_parser_error (parser, "expected identifier");
4365 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4368 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4373 str = c_parser_asm_string_literal (parser);
4374 if (str == NULL_TREE)
4376 parser->lex_untranslated_string = false;
4377 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4379 parser->lex_untranslated_string = true;
4382 expr = c_parser_expression (parser);
4384 expr = default_function_array_conversion (expr);
4385 parser->lex_untranslated_string = true;
4386 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4388 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4391 list = chainon (list, build_tree_list (build_tree_list (name, str),
4393 if (c_parser_next_token_is (parser, CPP_COMMA))
4394 c_parser_consume_token (parser);
4401 /* Parse asm clobbers, a GNU extension.
4405 asm-clobbers , asm-string-literal
4409 c_parser_asm_clobbers (c_parser *parser)
4411 tree list = NULL_TREE;
4414 tree str = c_parser_asm_string_literal (parser);
4416 list = tree_cons (NULL_TREE, str, list);
4419 if (c_parser_next_token_is (parser, CPP_COMMA))
4420 c_parser_consume_token (parser);
4427 /* Parse an expression other than a compound expression; that is, an
4428 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4429 NULL then it is an Objective-C message expression which is the
4430 primary-expression starting the expression as an initializer.
4432 assignment-expression:
4433 conditional-expression
4434 unary-expression assignment-operator assignment-expression
4436 assignment-operator: one of
4437 = *= /= %= += -= <<= >>= &= ^= |=
4439 In GNU C we accept any conditional expression on the LHS and
4440 diagnose the invalid lvalue rather than producing a syntax
4443 static struct c_expr
4444 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4446 struct c_expr lhs, rhs, ret;
4447 enum tree_code code;
4448 gcc_assert (!after || c_dialect_objc ());
4449 lhs = c_parser_conditional_expression (parser, after);
4450 switch (c_parser_peek_token (parser)->type)
4459 code = TRUNC_DIV_EXPR;
4462 code = TRUNC_MOD_EXPR;
4477 code = BIT_AND_EXPR;
4480 code = BIT_XOR_EXPR;
4483 code = BIT_IOR_EXPR;
4488 c_parser_consume_token (parser);
4489 rhs = c_parser_expr_no_commas (parser, NULL);
4490 rhs = default_function_array_conversion (rhs);
4491 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4492 if (code == NOP_EXPR)
4493 ret.original_code = MODIFY_EXPR;
4496 TREE_NO_WARNING (ret.value) = 1;
4497 ret.original_code = ERROR_MARK;
4502 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4503 is not NULL then it is an Objective-C message expression which is
4504 the primary-expression starting the expression as an initializer.
4506 conditional-expression:
4507 logical-OR-expression
4508 logical-OR-expression ? expression : conditional-expression
4512 conditional-expression:
4513 logical-OR-expression ? : conditional-expression
4516 static struct c_expr
4517 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4519 struct c_expr cond, exp1, exp2, ret;
4520 gcc_assert (!after || c_dialect_objc ());
4521 cond = c_parser_binary_expression (parser, after);
4522 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4524 cond = default_function_array_conversion (cond);
4525 c_parser_consume_token (parser);
4526 if (c_parser_next_token_is (parser, CPP_COLON))
4529 pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
4530 &c_parser_peek_token (parser)->location);
4531 /* Make sure first operand is calculated only once. */
4532 exp1.value = save_expr (default_conversion (cond.value));
4533 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4534 skip_evaluation += cond.value == truthvalue_true_node;
4539 = c_objc_common_truthvalue_conversion
4540 (default_conversion (cond.value));
4541 skip_evaluation += cond.value == truthvalue_false_node;
4542 exp1 = c_parser_expression_conv (parser);
4543 skip_evaluation += ((cond.value == truthvalue_true_node)
4544 - (cond.value == truthvalue_false_node));
4546 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4548 skip_evaluation -= cond.value == truthvalue_true_node;
4549 ret.value = error_mark_node;
4550 ret.original_code = ERROR_MARK;
4553 exp2 = c_parser_conditional_expression (parser, NULL);
4554 exp2 = default_function_array_conversion (exp2);
4555 skip_evaluation -= cond.value == truthvalue_true_node;
4556 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4557 ret.original_code = ERROR_MARK;
4561 /* Parse a binary expression; that is, a logical-OR-expression (C90
4562 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4563 an Objective-C message expression which is the primary-expression
4564 starting the expression as an initializer.
4566 multiplicative-expression:
4568 multiplicative-expression * cast-expression
4569 multiplicative-expression / cast-expression
4570 multiplicative-expression % cast-expression
4572 additive-expression:
4573 multiplicative-expression
4574 additive-expression + multiplicative-expression
4575 additive-expression - multiplicative-expression
4579 shift-expression << additive-expression
4580 shift-expression >> additive-expression
4582 relational-expression:
4584 relational-expression < shift-expression
4585 relational-expression > shift-expression
4586 relational-expression <= shift-expression
4587 relational-expression >= shift-expression
4589 equality-expression:
4590 relational-expression
4591 equality-expression == relational-expression
4592 equality-expression != relational-expression
4596 AND-expression & equality-expression
4598 exclusive-OR-expression:
4600 exclusive-OR-expression ^ AND-expression
4602 inclusive-OR-expression:
4603 exclusive-OR-expression
4604 inclusive-OR-expression | exclusive-OR-expression
4606 logical-AND-expression:
4607 inclusive-OR-expression
4608 logical-AND-expression && inclusive-OR-expression
4610 logical-OR-expression:
4611 logical-AND-expression
4612 logical-OR-expression || logical-AND-expression
4615 static struct c_expr
4616 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4618 /* A binary expression is parsed using operator-precedence parsing,
4619 with the operands being cast expressions. All the binary
4620 operators are left-associative. Thus a binary expression is of
4623 E0 op1 E1 op2 E2 ...
4625 which we represent on a stack. On the stack, the precedence
4626 levels are strictly increasing. When a new operator is
4627 encountered of higher precedence than that at the top of the
4628 stack, it is pushed; its LHS is the top expression, and its RHS
4629 is everything parsed until it is popped. When a new operator is
4630 encountered with precedence less than or equal to that at the top
4631 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4632 by the result of the operation until the operator at the top of
4633 the stack has lower precedence than the new operator or there is
4634 only one element on the stack; then the top expression is the LHS
4635 of the new operator. In the case of logical AND and OR
4636 expressions, we also need to adjust skip_evaluation as
4637 appropriate when the operators are pushed and popped. */
4639 /* The precedence levels, where 0 is a dummy lowest level used for
4640 the bottom of the stack. */
4656 /* The expression at this stack level. */
4658 /* The precedence of the operator on its left, PREC_NONE at the
4659 bottom of the stack. */
4661 /* The operation on its left. */
4667 switch (stack[sp].op) \
4669 case TRUTH_ANDIF_EXPR: \
4670 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4672 case TRUTH_ORIF_EXPR: \
4673 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4678 stack[sp - 1].expr \
4679 = default_function_array_conversion (stack[sp - 1].expr); \
4681 = default_function_array_conversion (stack[sp].expr); \
4682 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4683 stack[sp - 1].expr, \
4687 gcc_assert (!after || c_dialect_objc ());
4688 stack[0].expr = c_parser_cast_expression (parser, after);
4689 stack[0].prec = PREC_NONE;
4694 enum tree_code ocode;
4697 switch (c_parser_peek_token (parser)->type)
4705 ocode = TRUNC_DIV_EXPR;
4709 ocode = TRUNC_MOD_EXPR;
4721 ocode = LSHIFT_EXPR;
4725 ocode = RSHIFT_EXPR;
4739 case CPP_GREATER_EQ:
4752 oprec = PREC_BITAND;
4753 ocode = BIT_AND_EXPR;
4756 oprec = PREC_BITXOR;
4757 ocode = BIT_XOR_EXPR;
4761 ocode = BIT_IOR_EXPR;
4764 oprec = PREC_LOGAND;
4765 ocode = TRUTH_ANDIF_EXPR;
4769 ocode = TRUTH_ORIF_EXPR;
4772 /* Not a binary operator, so end of the binary
4776 c_parser_consume_token (parser);
4777 while (oprec <= stack[sp].prec)
4781 case TRUTH_ANDIF_EXPR:
4783 = default_function_array_conversion (stack[sp].expr);
4784 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4785 (default_conversion (stack[sp].expr.value));
4786 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4788 case TRUTH_ORIF_EXPR:
4790 = default_function_array_conversion (stack[sp].expr);
4791 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4792 (default_conversion (stack[sp].expr.value));
4793 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4799 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4800 stack[sp].prec = oprec;
4801 stack[sp].op = ocode;
4806 return stack[0].expr;
4810 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4811 NULL then it is an Objective-C message expression which is the
4812 primary-expression starting the expression as an initializer.
4816 ( type-name ) unary-expression
4819 static struct c_expr
4820 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4822 gcc_assert (!after || c_dialect_objc ());
4824 return c_parser_postfix_expression_after_primary (parser, *after);
4825 /* If the expression begins with a parenthesized type name, it may
4826 be either a cast or a compound literal; we need to see whether
4827 the next character is '{' to tell the difference. If not, it is
4828 an unary expression. */
4829 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4830 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4832 struct c_type_name *type_name;
4835 c_parser_consume_token (parser);
4836 type_name = c_parser_type_name (parser);
4837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4838 if (type_name == NULL)
4840 ret.value = error_mark_node;
4841 ret.original_code = ERROR_MARK;
4845 /* Save casted types in the function's used types hash table. */
4846 used_types_insert (type_name->specs->type);
4848 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4849 return c_parser_postfix_expression_after_paren_type (parser,
4851 expr = c_parser_cast_expression (parser, NULL);
4852 expr = default_function_array_conversion (expr);
4853 ret.value = c_cast_expr (type_name, expr.value);
4854 ret.original_code = ERROR_MARK;
4858 return c_parser_unary_expression (parser);
4861 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4867 unary-operator cast-expression
4868 sizeof unary-expression
4869 sizeof ( type-name )
4871 unary-operator: one of
4877 __alignof__ unary-expression
4878 __alignof__ ( type-name )
4881 unary-operator: one of
4882 __extension__ __real__ __imag__
4884 In addition, the GNU syntax treats ++ and -- as unary operators, so
4885 they may be applied to cast expressions with errors for non-lvalues
4888 static struct c_expr
4889 c_parser_unary_expression (c_parser *parser)
4892 struct c_expr ret, op;
4893 switch (c_parser_peek_token (parser)->type)
4896 c_parser_consume_token (parser);
4897 op = c_parser_cast_expression (parser, NULL);
4898 op = default_function_array_conversion (op);
4899 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4900 case CPP_MINUS_MINUS:
4901 c_parser_consume_token (parser);
4902 op = c_parser_cast_expression (parser, NULL);
4903 op = default_function_array_conversion (op);
4904 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4906 c_parser_consume_token (parser);
4907 return parser_build_unary_op (ADDR_EXPR,
4908 c_parser_cast_expression (parser, NULL));
4910 c_parser_consume_token (parser);
4911 op = c_parser_cast_expression (parser, NULL);
4912 op = default_function_array_conversion (op);
4913 ret.value = build_indirect_ref (op.value, "unary *");
4914 ret.original_code = ERROR_MARK;
4917 if (!c_dialect_objc () && !in_system_header)
4918 warning (OPT_Wtraditional,
4919 "%Htraditional C rejects the unary plus operator",
4920 &c_parser_peek_token (parser)->location);
4921 c_parser_consume_token (parser);
4922 op = c_parser_cast_expression (parser, NULL);
4923 op = default_function_array_conversion (op);
4924 return parser_build_unary_op (CONVERT_EXPR, op);
4926 c_parser_consume_token (parser);
4927 op = c_parser_cast_expression (parser, NULL);
4928 op = default_function_array_conversion (op);
4929 return parser_build_unary_op (NEGATE_EXPR, op);
4931 c_parser_consume_token (parser);
4932 op = c_parser_cast_expression (parser, NULL);
4933 op = default_function_array_conversion (op);
4934 return parser_build_unary_op (BIT_NOT_EXPR, op);
4936 c_parser_consume_token (parser);
4937 op = c_parser_cast_expression (parser, NULL);
4938 op = default_function_array_conversion (op);
4939 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4941 /* Refer to the address of a label as a pointer. */
4942 c_parser_consume_token (parser);
4943 if (c_parser_next_token_is (parser, CPP_NAME))
4945 ret.value = finish_label_address_expr
4946 (c_parser_peek_token (parser)->value);
4947 c_parser_consume_token (parser);
4951 c_parser_error (parser, "expected identifier");
4952 ret.value = error_mark_node;
4954 ret.original_code = ERROR_MARK;
4957 switch (c_parser_peek_token (parser)->keyword)
4960 return c_parser_sizeof_expression (parser);
4962 return c_parser_alignof_expression (parser);
4964 c_parser_consume_token (parser);
4965 ext = disable_extension_diagnostics ();
4966 ret = c_parser_cast_expression (parser, NULL);
4967 restore_extension_diagnostics (ext);
4970 c_parser_consume_token (parser);
4971 op = c_parser_cast_expression (parser, NULL);
4972 op = default_function_array_conversion (op);
4973 return parser_build_unary_op (REALPART_EXPR, op);
4975 c_parser_consume_token (parser);
4976 op = c_parser_cast_expression (parser, NULL);
4977 op = default_function_array_conversion (op);
4978 return parser_build_unary_op (IMAGPART_EXPR, op);
4980 return c_parser_postfix_expression (parser);
4983 return c_parser_postfix_expression (parser);
4987 /* Parse a sizeof expression. */
4989 static struct c_expr
4990 c_parser_sizeof_expression (c_parser *parser)
4993 location_t expr_loc;
4994 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4995 c_parser_consume_token (parser);
4998 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4999 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5001 /* Either sizeof ( type-name ) or sizeof unary-expression
5002 starting with a compound literal. */
5003 struct c_type_name *type_name;
5004 c_parser_consume_token (parser);
5005 expr_loc = c_parser_peek_token (parser)->location;
5006 type_name = c_parser_type_name (parser);
5007 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5008 if (type_name == NULL)
5013 ret.value = error_mark_node;
5014 ret.original_code = ERROR_MARK;
5017 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5019 expr = c_parser_postfix_expression_after_paren_type (parser,
5023 /* sizeof ( type-name ). */
5026 if (type_name->declarator->kind == cdk_array
5027 && type_name->declarator->u.array.vla_unspec_p)
5030 error ("%H%<[*]%> not allowed in other than a declaration",
5033 return c_expr_sizeof_type (type_name);
5037 expr_loc = c_parser_peek_token (parser)->location;
5038 expr = c_parser_unary_expression (parser);
5042 if (TREE_CODE (expr.value) == COMPONENT_REF
5043 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5044 error ("%H%<sizeof%> applied to a bit-field", &expr_loc);
5045 return c_expr_sizeof_expr (expr);
5049 /* Parse an alignof expression. */
5051 static struct c_expr
5052 c_parser_alignof_expression (c_parser *parser)
5055 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5056 c_parser_consume_token (parser);
5059 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5060 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5062 /* Either __alignof__ ( type-name ) or __alignof__
5063 unary-expression starting with a compound literal. */
5064 struct c_type_name *type_name;
5066 c_parser_consume_token (parser);
5067 type_name = c_parser_type_name (parser);
5068 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5069 if (type_name == NULL)
5074 ret.value = error_mark_node;
5075 ret.original_code = ERROR_MARK;
5078 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5080 expr = c_parser_postfix_expression_after_paren_type (parser,
5084 /* alignof ( type-name ). */
5087 ret.value = c_alignof (groktypename (type_name));
5088 ret.original_code = ERROR_MARK;
5094 expr = c_parser_unary_expression (parser);
5098 ret.value = c_alignof_expr (expr.value);
5099 ret.original_code = ERROR_MARK;
5104 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5108 postfix-expression [ expression ]
5109 postfix-expression ( argument-expression-list[opt] )
5110 postfix-expression . identifier
5111 postfix-expression -> identifier
5112 postfix-expression ++
5113 postfix-expression --
5114 ( type-name ) { initializer-list }
5115 ( type-name ) { initializer-list , }
5117 argument-expression-list:
5119 argument-expression-list , argument-expression
5131 (treated as a keyword in GNU C)
5134 ( compound-statement )
5135 __builtin_va_arg ( assignment-expression , type-name )
5136 __builtin_offsetof ( type-name , offsetof-member-designator )
5137 __builtin_choose_expr ( assignment-expression ,
5138 assignment-expression ,
5139 assignment-expression )
5140 __builtin_types_compatible_p ( type-name , type-name )
5142 offsetof-member-designator:
5144 offsetof-member-designator . identifier
5145 offsetof-member-designator [ expression ]
5150 [ objc-receiver objc-message-args ]
5151 @selector ( objc-selector-arg )
5152 @protocol ( identifier )
5153 @encode ( type-name )
5157 static struct c_expr
5158 c_parser_postfix_expression (c_parser *parser)
5160 struct c_expr expr, e1, e2, e3;
5161 struct c_type_name *t1, *t2;
5163 switch (c_parser_peek_token (parser)->type)
5170 expr.value = c_parser_peek_token (parser)->value;
5171 expr.original_code = ERROR_MARK;
5172 c_parser_consume_token (parser);
5178 expr.value = c_parser_peek_token (parser)->value;
5179 expr.original_code = STRING_CST;
5180 c_parser_consume_token (parser);
5182 case CPP_OBJC_STRING:
5183 gcc_assert (c_dialect_objc ());
5185 = objc_build_string_object (c_parser_peek_token (parser)->value);
5186 expr.original_code = ERROR_MARK;
5187 c_parser_consume_token (parser);
5190 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5192 c_parser_error (parser, "expected expression");
5193 expr.value = error_mark_node;
5194 expr.original_code = ERROR_MARK;
5198 tree id = c_parser_peek_token (parser)->value;
5199 location_t loc = c_parser_peek_token (parser)->location;
5200 c_parser_consume_token (parser);
5201 expr.value = build_external_ref (id,
5202 (c_parser_peek_token (parser)->type
5203 == CPP_OPEN_PAREN), loc);
5204 expr.original_code = ERROR_MARK;
5207 case CPP_OPEN_PAREN:
5208 /* A parenthesized expression, statement expression or compound
5210 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5212 /* A statement expression. */
5214 location_t here = c_parser_peek_token (parser)->location;
5215 c_parser_consume_token (parser);
5216 c_parser_consume_token (parser);
5217 if (cur_stmt_list == NULL)
5219 error ("%Hbraced-group within expression allowed "
5220 "only inside a function", &here);
5221 parser->error = true;
5222 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5223 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5224 expr.value = error_mark_node;
5225 expr.original_code = ERROR_MARK;
5228 stmt = c_begin_stmt_expr ();
5229 c_parser_compound_statement_nostart (parser);
5230 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5233 pedwarn ("%HISO C forbids braced-groups within expressions",
5235 expr.value = c_finish_stmt_expr (stmt);
5236 expr.original_code = ERROR_MARK;
5238 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5240 /* A compound literal. ??? Can we actually get here rather
5241 than going directly to
5242 c_parser_postfix_expression_after_paren_type from
5244 struct c_type_name *type_name;
5245 c_parser_consume_token (parser);
5246 type_name = c_parser_type_name (parser);
5247 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5249 if (type_name == NULL)
5251 expr.value = error_mark_node;
5252 expr.original_code = ERROR_MARK;
5255 expr = c_parser_postfix_expression_after_paren_type (parser,
5260 /* A parenthesized expression. */
5261 c_parser_consume_token (parser);
5262 expr = c_parser_expression (parser);
5263 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5264 TREE_NO_WARNING (expr.value) = 1;
5265 expr.original_code = ERROR_MARK;
5266 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5271 switch (c_parser_peek_token (parser)->keyword)
5273 case RID_FUNCTION_NAME:
5274 case RID_PRETTY_FUNCTION_NAME:
5275 case RID_C99_FUNCTION_NAME:
5276 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5277 c_parser_peek_token (parser)->value);
5278 expr.original_code = ERROR_MARK;
5279 c_parser_consume_token (parser);
5282 c_parser_consume_token (parser);
5283 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5285 expr.value = error_mark_node;
5286 expr.original_code = ERROR_MARK;
5289 e1 = c_parser_expr_no_commas (parser, NULL);
5290 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5292 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5293 expr.value = error_mark_node;
5294 expr.original_code = ERROR_MARK;
5297 t1 = c_parser_type_name (parser);
5298 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5302 expr.value = error_mark_node;
5303 expr.original_code = ERROR_MARK;
5307 expr.value = build_va_arg (e1.value, groktypename (t1));
5308 expr.original_code = ERROR_MARK;
5312 c_parser_consume_token (parser);
5313 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5315 expr.value = error_mark_node;
5316 expr.original_code = ERROR_MARK;
5319 t1 = c_parser_type_name (parser);
5322 expr.value = error_mark_node;
5323 expr.original_code = ERROR_MARK;
5326 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5328 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5329 expr.value = error_mark_node;
5330 expr.original_code = ERROR_MARK;
5334 tree type = groktypename (t1);
5336 if (type == error_mark_node)
5337 offsetof_ref = error_mark_node;
5339 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5340 /* Parse the second argument to __builtin_offsetof. We
5341 must have one identifier, and beyond that we want to
5342 accept sub structure and sub array references. */
5343 if (c_parser_next_token_is (parser, CPP_NAME))
5345 offsetof_ref = build_component_ref
5346 (offsetof_ref, c_parser_peek_token (parser)->value);
5347 c_parser_consume_token (parser);
5348 while (c_parser_next_token_is (parser, CPP_DOT)
5349 || c_parser_next_token_is (parser,
5352 if (c_parser_next_token_is (parser, CPP_DOT))
5354 c_parser_consume_token (parser);
5355 if (c_parser_next_token_is_not (parser,
5358 c_parser_error (parser, "expected identifier");
5361 offsetof_ref = build_component_ref
5363 c_parser_peek_token (parser)->value);
5364 c_parser_consume_token (parser);
5369 c_parser_consume_token (parser);
5370 idx = c_parser_expression (parser).value;
5371 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5373 offsetof_ref = build_array_ref (offsetof_ref, idx);
5378 c_parser_error (parser, "expected identifier");
5379 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5381 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5382 expr.original_code = ERROR_MARK;
5385 case RID_CHOOSE_EXPR:
5386 c_parser_consume_token (parser);
5387 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5389 expr.value = error_mark_node;
5390 expr.original_code = ERROR_MARK;
5393 loc = c_parser_peek_token (parser)->location;
5394 e1 = c_parser_expr_no_commas (parser, NULL);
5395 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5398 expr.value = error_mark_node;
5399 expr.original_code = ERROR_MARK;
5402 e2 = c_parser_expr_no_commas (parser, NULL);
5403 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5405 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5406 expr.value = error_mark_node;
5407 expr.original_code = ERROR_MARK;
5410 e3 = c_parser_expr_no_commas (parser, NULL);
5411 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5416 c = fold (e1.value);
5417 if (TREE_CODE (c) != INTEGER_CST)
5418 error ("%Hfirst argument to %<__builtin_choose_expr%> not"
5419 " a constant", &loc);
5420 expr = integer_zerop (c) ? e3 : e2;
5423 case RID_TYPES_COMPATIBLE_P:
5424 c_parser_consume_token (parser);
5425 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5427 expr.value = error_mark_node;
5428 expr.original_code = ERROR_MARK;
5431 t1 = c_parser_type_name (parser);
5434 expr.value = error_mark_node;
5435 expr.original_code = ERROR_MARK;
5438 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5440 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5441 expr.value = error_mark_node;
5442 expr.original_code = ERROR_MARK;
5445 t2 = c_parser_type_name (parser);
5448 expr.value = error_mark_node;
5449 expr.original_code = ERROR_MARK;
5452 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5457 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5458 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5460 expr.value = comptypes (e1, e2)
5461 ? build_int_cst (NULL_TREE, 1)
5462 : build_int_cst (NULL_TREE, 0);
5463 expr.original_code = ERROR_MARK;
5466 case RID_AT_SELECTOR:
5467 gcc_assert (c_dialect_objc ());
5468 c_parser_consume_token (parser);
5469 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5471 expr.value = error_mark_node;
5472 expr.original_code = ERROR_MARK;
5476 tree sel = c_parser_objc_selector_arg (parser);
5477 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5479 expr.value = objc_build_selector_expr (sel);
5480 expr.original_code = ERROR_MARK;
5483 case RID_AT_PROTOCOL:
5484 gcc_assert (c_dialect_objc ());
5485 c_parser_consume_token (parser);
5486 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5488 expr.value = error_mark_node;
5489 expr.original_code = ERROR_MARK;
5492 if (c_parser_next_token_is_not (parser, CPP_NAME))
5494 c_parser_error (parser, "expected identifier");
5495 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5496 expr.value = error_mark_node;
5497 expr.original_code = ERROR_MARK;
5501 tree id = c_parser_peek_token (parser)->value;
5502 c_parser_consume_token (parser);
5503 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5505 expr.value = objc_build_protocol_expr (id);
5506 expr.original_code = ERROR_MARK;
5510 /* Extension to support C-structures in the archiver. */
5511 gcc_assert (c_dialect_objc ());
5512 c_parser_consume_token (parser);
5513 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5515 expr.value = error_mark_node;
5516 expr.original_code = ERROR_MARK;
5519 t1 = c_parser_type_name (parser);
5522 expr.value = error_mark_node;
5523 expr.original_code = ERROR_MARK;
5524 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5527 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5530 tree type = groktypename (t1);
5531 expr.value = objc_build_encode_expr (type);
5532 expr.original_code = ERROR_MARK;
5536 c_parser_error (parser, "expected expression");
5537 expr.value = error_mark_node;
5538 expr.original_code = ERROR_MARK;
5542 case CPP_OPEN_SQUARE:
5543 if (c_dialect_objc ())
5545 tree receiver, args;
5546 c_parser_consume_token (parser);
5547 receiver = c_parser_objc_receiver (parser);
5548 args = c_parser_objc_message_args (parser);
5549 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5551 expr.value = objc_build_message_expr (build_tree_list (receiver,
5553 expr.original_code = ERROR_MARK;
5556 /* Else fall through to report error. */
5558 c_parser_error (parser, "expected expression");
5559 expr.value = error_mark_node;
5560 expr.original_code = ERROR_MARK;
5563 return c_parser_postfix_expression_after_primary (parser, expr);
5566 /* Parse a postfix expression after a parenthesized type name: the
5567 brace-enclosed initializer of a compound literal, possibly followed
5568 by some postfix operators. This is separate because it is not
5569 possible to tell until after the type name whether a cast
5570 expression has a cast or a compound literal, or whether the operand
5571 of sizeof is a parenthesized type name or starts with a compound
5574 static struct c_expr
5575 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5576 struct c_type_name *type_name)
5581 location_t start_loc;
5582 start_init (NULL_TREE, NULL, 0);
5583 type = groktypename (type_name);
5584 start_loc = c_parser_peek_token (parser)->location;
5585 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5587 error ("%Hcompound literal has variable size", &start_loc);
5588 type = error_mark_node;
5590 init = c_parser_braced_init (parser, type, false);
5592 maybe_warn_string_init (type, init);
5594 if (pedantic && !flag_isoc99)
5595 pedwarn ("%HISO C90 forbids compound literals", &start_loc);
5596 expr.value = build_compound_literal (type, init.value);
5597 expr.original_code = ERROR_MARK;
5598 return c_parser_postfix_expression_after_primary (parser, expr);
5601 /* Parse a postfix expression after the initial primary or compound
5602 literal; that is, parse a series of postfix operators. */
5604 static struct c_expr
5605 c_parser_postfix_expression_after_primary (c_parser *parser,
5608 tree ident, idx, exprlist;
5611 switch (c_parser_peek_token (parser)->type)
5613 case CPP_OPEN_SQUARE:
5614 /* Array reference. */
5615 c_parser_consume_token (parser);
5616 idx = c_parser_expression (parser).value;
5617 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5619 expr.value = build_array_ref (expr.value, idx);
5620 expr.original_code = ERROR_MARK;
5622 case CPP_OPEN_PAREN:
5623 /* Function call. */
5624 c_parser_consume_token (parser);
5625 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5626 exprlist = NULL_TREE;
5628 exprlist = c_parser_expr_list (parser, true);
5629 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5631 expr.value = build_function_call (expr.value, exprlist);
5632 expr.original_code = ERROR_MARK;
5635 /* Structure element reference. */
5636 c_parser_consume_token (parser);
5637 expr = default_function_array_conversion (expr);
5638 if (c_parser_next_token_is (parser, CPP_NAME))
5639 ident = c_parser_peek_token (parser)->value;
5642 c_parser_error (parser, "expected identifier");
5643 expr.value = error_mark_node;
5644 expr.original_code = ERROR_MARK;
5647 c_parser_consume_token (parser);
5648 expr.value = build_component_ref (expr.value, ident);
5649 expr.original_code = ERROR_MARK;
5652 /* Structure element reference. */
5653 c_parser_consume_token (parser);
5654 expr = default_function_array_conversion (expr);
5655 if (c_parser_next_token_is (parser, CPP_NAME))
5656 ident = c_parser_peek_token (parser)->value;
5659 c_parser_error (parser, "expected identifier");
5660 expr.value = error_mark_node;
5661 expr.original_code = ERROR_MARK;
5664 c_parser_consume_token (parser);
5665 expr.value = build_component_ref (build_indirect_ref (expr.value,
5667 expr.original_code = ERROR_MARK;
5670 /* Postincrement. */
5671 c_parser_consume_token (parser);
5672 expr = default_function_array_conversion (expr);
5673 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5674 expr.original_code = ERROR_MARK;
5676 case CPP_MINUS_MINUS:
5677 /* Postdecrement. */
5678 c_parser_consume_token (parser);
5679 expr = default_function_array_conversion (expr);
5680 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5681 expr.original_code = ERROR_MARK;
5689 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5692 assignment-expression
5693 expression , assignment-expression
5696 static struct c_expr
5697 c_parser_expression (c_parser *parser)
5700 expr = c_parser_expr_no_commas (parser, NULL);
5701 while (c_parser_next_token_is (parser, CPP_COMMA))
5704 c_parser_consume_token (parser);
5705 next = c_parser_expr_no_commas (parser, NULL);
5706 next = default_function_array_conversion (next);
5707 expr.value = build_compound_expr (expr.value, next.value);
5708 expr.original_code = COMPOUND_EXPR;
5713 /* Parse an expression and convert functions or arrays to
5716 static struct c_expr
5717 c_parser_expression_conv (c_parser *parser)
5720 expr = c_parser_expression (parser);
5721 expr = default_function_array_conversion (expr);
5725 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5726 functions and arrays to pointers.
5729 assignment-expression
5730 nonempty-expr-list , assignment-expression
5734 c_parser_expr_list (c_parser *parser, bool convert_p)
5738 expr = c_parser_expr_no_commas (parser, NULL);
5740 expr = default_function_array_conversion (expr);
5741 ret = cur = build_tree_list (NULL_TREE, expr.value);
5742 while (c_parser_next_token_is (parser, CPP_COMMA))
5744 c_parser_consume_token (parser);
5745 expr = c_parser_expr_no_commas (parser, NULL);
5747 expr = default_function_array_conversion (expr);
5748 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5754 /* Parse Objective-C-specific constructs. */
5756 /* Parse an objc-class-definition.
5758 objc-class-definition:
5759 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5760 objc-class-instance-variables[opt] objc-methodprotolist @end
5761 @implementation identifier objc-superclass[opt]
5762 objc-class-instance-variables[opt]
5763 @interface identifier ( identifier ) objc-protocol-refs[opt]
5764 objc-methodprotolist @end
5765 @implementation identifier ( identifier )
5770 "@interface identifier (" must start "@interface identifier (
5771 identifier ) ...": objc-methodprotolist in the first production may
5772 not start with a parenthesized identifier as a declarator of a data
5773 definition with no declaration specifiers if the objc-superclass,
5774 objc-protocol-refs and objc-class-instance-variables are omitted. */
5777 c_parser_objc_class_definition (c_parser *parser)
5782 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5784 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5788 c_parser_consume_token (parser);
5789 if (c_parser_next_token_is_not (parser, CPP_NAME))
5791 c_parser_error (parser, "expected identifier");
5794 id1 = c_parser_peek_token (parser)->value;
5795 c_parser_consume_token (parser);
5796 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5799 tree proto = NULL_TREE;
5800 c_parser_consume_token (parser);
5801 if (c_parser_next_token_is_not (parser, CPP_NAME))
5803 c_parser_error (parser, "expected identifier");
5804 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5807 id2 = c_parser_peek_token (parser)->value;
5808 c_parser_consume_token (parser);
5809 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5812 objc_start_category_implementation (id1, id2);
5815 if (c_parser_next_token_is (parser, CPP_LESS))
5816 proto = c_parser_objc_protocol_refs (parser);
5817 objc_start_category_interface (id1, id2, proto);
5818 c_parser_objc_methodprotolist (parser);
5819 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5820 objc_finish_interface ();
5823 if (c_parser_next_token_is (parser, CPP_COLON))
5825 c_parser_consume_token (parser);
5826 if (c_parser_next_token_is_not (parser, CPP_NAME))
5828 c_parser_error (parser, "expected identifier");
5831 superclass = c_parser_peek_token (parser)->value;
5832 c_parser_consume_token (parser);
5835 superclass = NULL_TREE;
5838 tree proto = NULL_TREE;
5839 if (c_parser_next_token_is (parser, CPP_LESS))
5840 proto = c_parser_objc_protocol_refs (parser);
5841 objc_start_class_interface (id1, superclass, proto);
5844 objc_start_class_implementation (id1, superclass);
5845 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5846 c_parser_objc_class_instance_variables (parser);
5849 objc_continue_interface ();
5850 c_parser_objc_methodprotolist (parser);
5851 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5852 objc_finish_interface ();
5856 objc_continue_implementation ();
5861 /* Parse objc-class-instance-variables.
5863 objc-class-instance-variables:
5864 { objc-instance-variable-decl-list[opt] }
5866 objc-instance-variable-decl-list:
5867 objc-visibility-spec
5868 objc-instance-variable-decl ;
5870 objc-instance-variable-decl-list objc-visibility-spec
5871 objc-instance-variable-decl-list objc-instance-variable-decl ;
5872 objc-instance-variable-decl-list ;
5874 objc-visibility-spec:
5879 objc-instance-variable-decl:
5884 c_parser_objc_class_instance_variables (c_parser *parser)
5886 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5887 c_parser_consume_token (parser);
5888 while (c_parser_next_token_is_not (parser, CPP_EOF))
5891 /* Parse any stray semicolon. */
5892 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5895 pedwarn ("%Hextra semicolon in struct or union specified",
5896 &c_parser_peek_token (parser)->location);
5897 c_parser_consume_token (parser);
5900 /* Stop if at the end of the instance variables. */
5901 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5903 c_parser_consume_token (parser);
5906 /* Parse any objc-visibility-spec. */
5907 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5909 c_parser_consume_token (parser);
5910 objc_set_visibility (2);
5913 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5915 c_parser_consume_token (parser);
5916 objc_set_visibility (0);
5919 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5921 c_parser_consume_token (parser);
5922 objc_set_visibility (1);
5925 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5927 c_parser_pragma (parser, pragma_external);
5931 /* Parse some comma-separated declarations. */
5932 decls = c_parser_struct_declaration (parser);
5934 /* Comma-separated instance variables are chained together in
5935 reverse order; add them one by one. */
5936 tree ivar = nreverse (decls);
5937 for (; ivar; ivar = TREE_CHAIN (ivar))
5938 objc_add_instance_variable (copy_node (ivar));
5940 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5944 /* Parse an objc-class-declaration.
5946 objc-class-declaration:
5947 @class identifier-list ;
5951 c_parser_objc_class_declaration (c_parser *parser)
5953 tree list = NULL_TREE;
5954 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5955 c_parser_consume_token (parser);
5956 /* Any identifiers, including those declared as type names, are OK
5961 if (c_parser_next_token_is_not (parser, CPP_NAME))
5963 c_parser_error (parser, "expected identifier");
5966 id = c_parser_peek_token (parser)->value;
5967 list = chainon (list, build_tree_list (NULL_TREE, id));
5968 c_parser_consume_token (parser);
5969 if (c_parser_next_token_is (parser, CPP_COMMA))
5970 c_parser_consume_token (parser);
5974 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5975 objc_declare_class (list);
5978 /* Parse an objc-alias-declaration.
5980 objc-alias-declaration:
5981 @compatibility_alias identifier identifier ;
5985 c_parser_objc_alias_declaration (c_parser *parser)
5988 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5989 c_parser_consume_token (parser);
5990 if (c_parser_next_token_is_not (parser, CPP_NAME))
5992 c_parser_error (parser, "expected identifier");
5993 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5996 id1 = c_parser_peek_token (parser)->value;
5997 c_parser_consume_token (parser);
5998 if (c_parser_next_token_is_not (parser, CPP_NAME))
6000 c_parser_error (parser, "expected identifier");
6001 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6004 id2 = c_parser_peek_token (parser)->value;
6005 c_parser_consume_token (parser);
6006 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6007 objc_declare_alias (id1, id2);
6010 /* Parse an objc-protocol-definition.
6012 objc-protocol-definition:
6013 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6014 @protocol identifier-list ;
6016 "@protocol identifier ;" should be resolved as "@protocol
6017 identifier-list ;": objc-methodprotolist may not start with a
6018 semicolon in the first alternative if objc-protocol-refs are
6022 c_parser_objc_protocol_definition (c_parser *parser)
6024 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6025 c_parser_consume_token (parser);
6026 if (c_parser_next_token_is_not (parser, CPP_NAME))
6028 c_parser_error (parser, "expected identifier");
6031 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6032 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6034 tree list = NULL_TREE;
6035 /* Any identifiers, including those declared as type names, are
6040 if (c_parser_next_token_is_not (parser, CPP_NAME))
6042 c_parser_error (parser, "expected identifier");
6045 id = c_parser_peek_token (parser)->value;
6046 list = chainon (list, build_tree_list (NULL_TREE, id));
6047 c_parser_consume_token (parser);
6048 if (c_parser_next_token_is (parser, CPP_COMMA))
6049 c_parser_consume_token (parser);
6053 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6054 objc_declare_protocols (list);
6058 tree id = c_parser_peek_token (parser)->value;
6059 tree proto = NULL_TREE;
6060 c_parser_consume_token (parser);
6061 if (c_parser_next_token_is (parser, CPP_LESS))
6062 proto = c_parser_objc_protocol_refs (parser);
6063 parser->objc_pq_context = true;
6064 objc_start_protocol (id, proto);
6065 c_parser_objc_methodprotolist (parser);
6066 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6067 parser->objc_pq_context = false;
6068 objc_finish_interface ();
6072 /* Parse an objc-method-type.
6079 static enum tree_code
6080 c_parser_objc_method_type (c_parser *parser)
6082 switch (c_parser_peek_token (parser)->type)
6085 c_parser_consume_token (parser);
6088 c_parser_consume_token (parser);
6095 /* Parse an objc-method-definition.
6097 objc-method-definition:
6098 objc-method-type objc-method-decl ;[opt] compound-statement
6102 c_parser_objc_method_definition (c_parser *parser)
6104 enum tree_code type = c_parser_objc_method_type (parser);
6106 objc_set_method_type (type);
6107 parser->objc_pq_context = true;
6108 decl = c_parser_objc_method_decl (parser);
6109 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6111 c_parser_consume_token (parser);
6113 pedwarn ("%Hextra semicolon in method definition specified",
6114 &c_parser_peek_token (parser)->location);
6116 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6118 c_parser_error (parser, "expected %<{%>");
6121 parser->objc_pq_context = false;
6122 objc_start_method_definition (decl);
6123 add_stmt (c_parser_compound_statement (parser));
6124 objc_finish_method_definition (current_function_decl);
6127 /* Parse an objc-methodprotolist.
6129 objc-methodprotolist:
6131 objc-methodprotolist objc-methodproto
6132 objc-methodprotolist declaration
6133 objc-methodprotolist ;
6135 The declaration is a data definition, which may be missing
6136 declaration specifiers under the same rules and diagnostics as
6137 other data definitions outside functions, and the stray semicolon
6138 is diagnosed the same way as a stray semicolon outside a
6142 c_parser_objc_methodprotolist (c_parser *parser)
6146 /* The list is terminated by @end. */
6147 switch (c_parser_peek_token (parser)->type)
6151 pedwarn ("%HISO C does not allow extra %<;%> "
6152 "outside of a function",
6153 &c_parser_peek_token (parser)->location);
6154 c_parser_consume_token (parser);
6158 c_parser_objc_methodproto (parser);
6161 c_parser_pragma (parser, pragma_external);
6166 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6168 c_parser_declaration_or_fndef (parser, false, true, false, true);
6174 /* Parse an objc-methodproto.
6177 objc-method-type objc-method-decl ;
6181 c_parser_objc_methodproto (c_parser *parser)
6183 enum tree_code type = c_parser_objc_method_type (parser);
6185 objc_set_method_type (type);
6186 /* Remember protocol qualifiers in prototypes. */
6187 parser->objc_pq_context = true;
6188 decl = c_parser_objc_method_decl (parser);
6189 /* Forget protocol qualifiers here. */
6190 parser->objc_pq_context = false;
6191 objc_add_method_declaration (decl);
6192 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6195 /* Parse an objc-method-decl.
6198 ( objc-type-name ) objc-selector
6200 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6201 objc-keyword-selector objc-optparmlist
6203 objc-keyword-selector:
6205 objc-keyword-selector objc-keyword-decl
6208 objc-selector : ( objc-type-name ) identifier
6209 objc-selector : identifier
6210 : ( objc-type-name ) identifier
6214 objc-optparms objc-optellipsis
6218 objc-opt-parms , parameter-declaration
6226 c_parser_objc_method_decl (c_parser *parser)
6228 tree type = NULL_TREE;
6230 tree parms = NULL_TREE;
6231 bool ellipsis = false;
6233 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6235 c_parser_consume_token (parser);
6236 type = c_parser_objc_type_name (parser);
6237 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6239 sel = c_parser_objc_selector (parser);
6240 /* If there is no selector, or a colon follows, we have an
6241 objc-keyword-selector. If there is a selector, and a colon does
6242 not follow, that selector ends the objc-method-decl. */
6243 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6246 tree list = NULL_TREE;
6249 tree atype = NULL_TREE, id, keyworddecl;
6250 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6252 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6254 c_parser_consume_token (parser);
6255 atype = c_parser_objc_type_name (parser);
6256 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6259 if (c_parser_next_token_is_not (parser, CPP_NAME))
6261 c_parser_error (parser, "expected identifier");
6262 return error_mark_node;
6264 id = c_parser_peek_token (parser)->value;
6265 c_parser_consume_token (parser);
6266 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6267 list = chainon (list, keyworddecl);
6268 tsel = c_parser_objc_selector (parser);
6269 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6272 /* Parse the optional parameter list. Optional Objective-C
6273 method parameters follow the C syntax, and may include '...'
6274 to denote a variable number of arguments. */
6275 parms = make_node (TREE_LIST);
6276 while (c_parser_next_token_is (parser, CPP_COMMA))
6278 struct c_parm *parm;
6279 c_parser_consume_token (parser);
6280 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6283 c_parser_consume_token (parser);
6286 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6289 parms = chainon (parms,
6290 build_tree_list (NULL_TREE, grokparm (parm)));
6294 return objc_build_method_signature (type, sel, parms, ellipsis);
6297 /* Parse an objc-type-name.
6300 objc-type-qualifiers[opt] type-name
6301 objc-type-qualifiers[opt]
6303 objc-type-qualifiers:
6305 objc-type-qualifiers objc-type-qualifier
6307 objc-type-qualifier: one of
6308 in out inout bycopy byref oneway
6312 c_parser_objc_type_name (c_parser *parser)
6314 tree quals = NULL_TREE;
6315 struct c_type_name *typename = NULL;
6316 tree type = NULL_TREE;
6319 c_token *token = c_parser_peek_token (parser);
6320 if (token->type == CPP_KEYWORD
6321 && (token->keyword == RID_IN
6322 || token->keyword == RID_OUT
6323 || token->keyword == RID_INOUT
6324 || token->keyword == RID_BYCOPY
6325 || token->keyword == RID_BYREF
6326 || token->keyword == RID_ONEWAY))
6328 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6329 c_parser_consume_token (parser);
6334 if (c_parser_next_token_starts_typename (parser))
6335 typename = c_parser_type_name (parser);
6337 type = groktypename (typename);
6338 return build_tree_list (quals, type);
6341 /* Parse objc-protocol-refs.
6348 c_parser_objc_protocol_refs (c_parser *parser)
6350 tree list = NULL_TREE;
6351 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6352 c_parser_consume_token (parser);
6353 /* Any identifiers, including those declared as type names, are OK
6358 if (c_parser_next_token_is_not (parser, CPP_NAME))
6360 c_parser_error (parser, "expected identifier");
6363 id = c_parser_peek_token (parser)->value;
6364 list = chainon (list, build_tree_list (NULL_TREE, id));
6365 c_parser_consume_token (parser);
6366 if (c_parser_next_token_is (parser, CPP_COMMA))
6367 c_parser_consume_token (parser);
6371 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6375 /* Parse an objc-try-catch-statement.
6377 objc-try-catch-statement:
6378 @try compound-statement objc-catch-list[opt]
6379 @try compound-statement objc-catch-list[opt] @finally compound-statement
6382 @catch ( parameter-declaration ) compound-statement
6383 objc-catch-list @catch ( parameter-declaration ) compound-statement
6387 c_parser_objc_try_catch_statement (c_parser *parser)
6391 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6392 c_parser_consume_token (parser);
6393 loc = c_parser_peek_token (parser)->location;
6394 stmt = c_parser_compound_statement (parser);
6395 objc_begin_try_stmt (loc, stmt);
6396 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6398 struct c_parm *parm;
6399 c_parser_consume_token (parser);
6400 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6402 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6405 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6408 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6409 objc_begin_catch_clause (grokparm (parm));
6410 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6411 c_parser_compound_statement_nostart (parser);
6412 objc_finish_catch_clause ();
6414 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6418 c_parser_consume_token (parser);
6419 finloc = c_parser_peek_token (parser)->location;
6420 finstmt = c_parser_compound_statement (parser);
6421 objc_build_finally_clause (finloc, finstmt);
6423 objc_finish_try_stmt ();
6426 /* Parse an objc-synchronized-statement.
6428 objc-synchronized-statement:
6429 @synchronized ( expression ) compound-statement
6433 c_parser_objc_synchronized_statement (c_parser *parser)
6437 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6438 c_parser_consume_token (parser);
6439 loc = c_parser_peek_token (parser)->location;
6440 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6442 expr = c_parser_expression (parser).value;
6443 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6446 expr = error_mark_node;
6447 stmt = c_parser_compound_statement (parser);
6448 objc_build_synchronized (loc, expr, stmt);
6451 /* Parse an objc-selector; return NULL_TREE without an error if the
6452 next token is not an objc-selector.
6457 enum struct union if else while do for switch case default
6458 break continue return goto asm sizeof typeof __alignof
6459 unsigned long const short volatile signed restrict _Complex
6460 in out inout bycopy byref oneway int char float double void _Bool
6462 ??? Why this selection of keywords but not, for example, storage
6463 class specifiers? */
6466 c_parser_objc_selector (c_parser *parser)
6468 c_token *token = c_parser_peek_token (parser);
6469 tree value = token->value;
6470 if (token->type == CPP_NAME)
6472 c_parser_consume_token (parser);
6475 if (token->type != CPP_KEYWORD)
6477 switch (token->keyword)
6518 c_parser_consume_token (parser);
6525 /* Parse an objc-selector-arg.
6529 objc-keywordname-list
6531 objc-keywordname-list:
6533 objc-keywordname-list objc-keywordname
6541 c_parser_objc_selector_arg (c_parser *parser)
6543 tree sel = c_parser_objc_selector (parser);
6544 tree list = NULL_TREE;
6545 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6549 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6551 list = chainon (list, build_tree_list (sel, NULL_TREE));
6552 sel = c_parser_objc_selector (parser);
6553 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6559 /* Parse an objc-receiver.
6568 c_parser_objc_receiver (c_parser *parser)
6570 if (c_parser_peek_token (parser)->type == CPP_NAME
6571 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6572 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6574 tree id = c_parser_peek_token (parser)->value;
6575 c_parser_consume_token (parser);
6576 return objc_get_class_reference (id);
6578 return c_parser_expression (parser).value;
6581 /* Parse objc-message-args.
6585 objc-keywordarg-list
6587 objc-keywordarg-list:
6589 objc-keywordarg-list objc-keywordarg
6592 objc-selector : objc-keywordexpr
6597 c_parser_objc_message_args (c_parser *parser)
6599 tree sel = c_parser_objc_selector (parser);
6600 tree list = NULL_TREE;
6601 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6606 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6608 keywordexpr = c_parser_objc_keywordexpr (parser);
6609 list = chainon (list, build_tree_list (sel, keywordexpr));
6610 sel = c_parser_objc_selector (parser);
6611 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6617 /* Parse an objc-keywordexpr.
6624 c_parser_objc_keywordexpr (c_parser *parser)
6626 tree list = c_parser_expr_list (parser, true);
6627 if (TREE_CHAIN (list) == NULL_TREE)
6629 /* Just return the expression, remove a level of
6631 return TREE_VALUE (list);
6635 /* We have a comma expression, we will collapse later. */
6641 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6642 should be considered, statements. ALLOW_STMT is true if we're within
6643 the context of a function and such pragmas are to be allowed. Returns
6644 true if we actually parsed such a pragma. */
6647 c_parser_pragma (c_parser *parser, enum pragma_context context)
6651 id = c_parser_peek_token (parser)->pragma_kind;
6652 gcc_assert (id != PRAGMA_NONE);
6656 case PRAGMA_OMP_BARRIER:
6657 if (context != pragma_compound)
6659 if (context == pragma_stmt)
6660 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6661 "used in compound statements");
6664 c_parser_omp_barrier (parser);
6667 case PRAGMA_OMP_FLUSH:
6668 if (context != pragma_compound)
6670 if (context == pragma_stmt)
6671 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6672 "used in compound statements");
6675 c_parser_omp_flush (parser);
6678 case PRAGMA_OMP_TASKWAIT:
6679 if (context != pragma_compound)
6681 if (context == pragma_stmt)
6682 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6683 "used in compound statements");
6686 c_parser_omp_taskwait (parser);
6689 case PRAGMA_OMP_THREADPRIVATE:
6690 c_parser_omp_threadprivate (parser);
6693 case PRAGMA_OMP_SECTION:
6694 error ("%H%<#pragma omp section%> may only be used in "
6695 "%<#pragma omp sections%> construct",
6696 &c_parser_peek_token (parser)->location);
6697 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6700 case PRAGMA_GCC_PCH_PREPROCESS:
6701 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6702 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6706 if (id < PRAGMA_FIRST_EXTERNAL)
6708 if (context == pragma_external)
6711 c_parser_error (parser, "expected declaration specifiers");
6712 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6715 c_parser_omp_construct (parser);
6721 c_parser_consume_pragma (parser);
6722 c_invoke_pragma_handler (id);
6724 /* Skip to EOL, but suppress any error message. Those will have been
6725 generated by the handler routine through calling error, as opposed
6726 to calling c_parser_error. */
6727 parser->error = true;
6728 c_parser_skip_to_pragma_eol (parser);
6733 /* The interface the pragma parsers have to the lexer. */
6736 pragma_lex (tree *value)
6738 c_token *tok = c_parser_peek_token (the_parser);
6739 enum cpp_ttype ret = tok->type;
6741 *value = tok->value;
6742 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6746 if (ret == CPP_KEYWORD)
6748 c_parser_consume_token (the_parser);
6755 c_parser_pragma_pch_preprocess (c_parser *parser)
6759 c_parser_consume_pragma (parser);
6760 if (c_parser_next_token_is (parser, CPP_STRING))
6762 name = c_parser_peek_token (parser)->value;
6763 c_parser_consume_token (parser);
6766 c_parser_error (parser, "expected string literal");
6767 c_parser_skip_to_pragma_eol (parser);
6770 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6773 /* OpenMP 2.5 parsing routines. */
6775 /* Returns name of the next clause.
6776 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6777 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6778 returned and the token is consumed. */
6780 static pragma_omp_clause
6781 c_parser_omp_clause_name (c_parser *parser)
6783 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6785 if (c_parser_next_token_is_keyword (parser, RID_IF))
6786 result = PRAGMA_OMP_CLAUSE_IF;
6787 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6788 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6789 else if (c_parser_next_token_is (parser, CPP_NAME))
6791 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6796 if (!strcmp ("collapse", p))
6797 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
6798 else if (!strcmp ("copyin", p))
6799 result = PRAGMA_OMP_CLAUSE_COPYIN;
6800 else if (!strcmp ("copyprivate", p))
6801 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6804 if (!strcmp ("firstprivate", p))
6805 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6808 if (!strcmp ("lastprivate", p))
6809 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6812 if (!strcmp ("nowait", p))
6813 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6814 else if (!strcmp ("num_threads", p))
6815 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6818 if (!strcmp ("ordered", p))
6819 result = PRAGMA_OMP_CLAUSE_ORDERED;
6822 if (!strcmp ("private", p))
6823 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6826 if (!strcmp ("reduction", p))
6827 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6830 if (!strcmp ("schedule", p))
6831 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6832 else if (!strcmp ("shared", p))
6833 result = PRAGMA_OMP_CLAUSE_SHARED;
6836 if (!strcmp ("untied", p))
6837 result = PRAGMA_OMP_CLAUSE_UNTIED;
6842 if (result != PRAGMA_OMP_CLAUSE_NONE)
6843 c_parser_consume_token (parser);
6848 /* Validate that a clause of the given type does not already exist. */
6851 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6855 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6856 if (OMP_CLAUSE_CODE (c) == code)
6858 error ("too many %qs clauses", name);
6866 variable-list , identifier
6868 If KIND is nonzero, create the appropriate node and install the decl
6869 in OMP_CLAUSE_DECL and add the node to the head of the list.
6871 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6872 return the list created. */
6875 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6878 if (c_parser_next_token_is_not (parser, CPP_NAME)
6879 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6880 c_parser_error (parser, "expected identifier");
6882 while (c_parser_next_token_is (parser, CPP_NAME)
6883 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6885 tree t = lookup_name (c_parser_peek_token (parser)->value);
6888 undeclared_variable (c_parser_peek_token (parser)->value,
6889 c_parser_peek_token (parser)->location);
6890 else if (t == error_mark_node)
6894 tree u = build_omp_clause (kind);
6895 OMP_CLAUSE_DECL (u) = t;
6896 OMP_CLAUSE_CHAIN (u) = list;
6900 list = tree_cons (t, NULL_TREE, list);
6902 c_parser_consume_token (parser);
6904 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6907 c_parser_consume_token (parser);
6913 /* Similarly, but expect leading and trailing parenthesis. This is a very
6914 common case for omp clauses. */
6917 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6919 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6921 list = c_parser_omp_variable_list (parser, kind, list);
6922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6928 collapse ( constant-expression ) */
6931 c_parser_omp_clause_collapse (c_parser *parser, tree list)
6933 tree c, num = error_mark_node;
6937 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
6939 loc = c_parser_peek_token (parser)->location;
6940 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6942 num = c_parser_expr_no_commas (parser, NULL).value;
6943 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6945 if (num == error_mark_node)
6947 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
6948 || !host_integerp (num, 0)
6949 || (n = tree_low_cst (num, 0)) <= 0
6952 error ("%Hcollapse argument needs positive constant integer expression",
6956 c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
6957 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
6958 OMP_CLAUSE_CHAIN (c) = list;
6963 copyin ( variable-list ) */
6966 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6968 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6972 copyprivate ( variable-list ) */
6975 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6977 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6981 default ( shared | none ) */
6984 c_parser_omp_clause_default (c_parser *parser, tree list)
6986 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6989 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6991 if (c_parser_next_token_is (parser, CPP_NAME))
6993 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6998 if (strcmp ("none", p) != 0)
7000 kind = OMP_CLAUSE_DEFAULT_NONE;
7004 if (strcmp ("shared", p) != 0)
7006 kind = OMP_CLAUSE_DEFAULT_SHARED;
7013 c_parser_consume_token (parser);
7018 c_parser_error (parser, "expected %<none%> or %<shared%>");
7020 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7022 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7025 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7026 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
7027 OMP_CLAUSE_CHAIN (c) = list;
7028 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7034 firstprivate ( variable-list ) */
7037 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7039 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7043 if ( expression ) */
7046 c_parser_omp_clause_if (c_parser *parser, tree list)
7048 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7050 tree t = c_parser_paren_condition (parser);
7053 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7055 c = build_omp_clause (OMP_CLAUSE_IF);
7056 OMP_CLAUSE_IF_EXPR (c) = t;
7057 OMP_CLAUSE_CHAIN (c) = list;
7061 c_parser_error (parser, "expected %<(%>");
7067 lastprivate ( variable-list ) */
7070 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7072 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7079 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7083 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7085 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
7086 OMP_CLAUSE_CHAIN (c) = list;
7091 num_threads ( expression ) */
7094 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7096 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7098 location_t expr_loc = c_parser_peek_token (parser)->location;
7099 tree c, t = c_parser_expression (parser).value;
7101 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7103 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7105 c_parser_error (parser, "expected integer expression");
7109 /* Attempt to statically determine when the number isn't positive. */
7110 c = fold_build2 (LE_EXPR, boolean_type_node, t,
7111 build_int_cst (TREE_TYPE (t), 0));
7112 if (c == boolean_true_node)
7114 warning (0, "%H%<num_threads%> value must be positive", &expr_loc);
7115 t = integer_one_node;
7118 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7120 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
7121 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7122 OMP_CLAUSE_CHAIN (c) = list;
7133 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7137 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7139 c = build_omp_clause (OMP_CLAUSE_ORDERED);
7140 OMP_CLAUSE_CHAIN (c) = list;
7145 private ( variable-list ) */
7148 c_parser_omp_clause_private (c_parser *parser, tree list)
7150 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7154 reduction ( reduction-operator : variable-list )
7157 One of: + * - & ^ | && || */
7160 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7162 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7164 enum tree_code code;
7166 switch (c_parser_peek_token (parser)->type)
7178 code = BIT_AND_EXPR;
7181 code = BIT_XOR_EXPR;
7184 code = BIT_IOR_EXPR;
7187 code = TRUTH_ANDIF_EXPR;
7190 code = TRUTH_ORIF_EXPR;
7193 c_parser_error (parser,
7194 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7195 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7199 c_parser_consume_token (parser);
7200 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7204 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7205 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7206 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7210 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7216 schedule ( schedule-kind )
7217 schedule ( schedule-kind , expression )
7220 static | dynamic | guided | runtime | auto
7224 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7228 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7231 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7233 if (c_parser_next_token_is (parser, CPP_NAME))
7235 tree kind = c_parser_peek_token (parser)->value;
7236 const char *p = IDENTIFIER_POINTER (kind);
7241 if (strcmp ("dynamic", p) != 0)
7243 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7247 if (strcmp ("guided", p) != 0)
7249 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7253 if (strcmp ("runtime", p) != 0)
7255 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7262 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7263 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7264 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7265 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7269 c_parser_consume_token (parser);
7270 if (c_parser_next_token_is (parser, CPP_COMMA))
7273 c_parser_consume_token (parser);
7275 here = c_parser_peek_token (parser)->location;
7276 t = c_parser_expr_no_commas (parser, NULL).value;
7278 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7279 error ("%Hschedule %<runtime%> does not take "
7280 "a %<chunk_size%> parameter", &here);
7281 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7282 error ("%Hschedule %<auto%> does not take "
7283 "a %<chunk_size%> parameter", &here);
7284 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7285 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7287 c_parser_error (parser, "expected integer expression");
7289 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7292 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7293 "expected %<,%> or %<)%>");
7295 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7296 OMP_CLAUSE_CHAIN (c) = list;
7300 c_parser_error (parser, "invalid schedule kind");
7301 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7306 shared ( variable-list ) */
7309 c_parser_omp_clause_shared (c_parser *parser, tree list)
7311 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7318 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7322 /* FIXME: Should we allow duplicates? */
7323 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7325 c = build_omp_clause (OMP_CLAUSE_UNTIED);
7326 OMP_CLAUSE_CHAIN (c) = list;
7330 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7331 is a bitmask in MASK. Return the list of clauses found; the result
7332 of clause default goes in *pdefault. */
7335 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7338 tree clauses = NULL;
7341 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7344 pragma_omp_clause c_kind;
7346 tree prev = clauses;
7348 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7349 c_parser_consume_token (parser);
7352 here = c_parser_peek_token (parser)->location;
7353 c_kind = c_parser_omp_clause_name (parser);
7357 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7358 clauses = c_parser_omp_clause_collapse (parser, clauses);
7359 c_name = "collapse";
7361 case PRAGMA_OMP_CLAUSE_COPYIN:
7362 clauses = c_parser_omp_clause_copyin (parser, clauses);
7365 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7366 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7367 c_name = "copyprivate";
7369 case PRAGMA_OMP_CLAUSE_DEFAULT:
7370 clauses = c_parser_omp_clause_default (parser, clauses);
7373 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7374 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7375 c_name = "firstprivate";
7377 case PRAGMA_OMP_CLAUSE_IF:
7378 clauses = c_parser_omp_clause_if (parser, clauses);
7381 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7382 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7383 c_name = "lastprivate";
7385 case PRAGMA_OMP_CLAUSE_NOWAIT:
7386 clauses = c_parser_omp_clause_nowait (parser, clauses);
7389 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7390 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7391 c_name = "num_threads";
7393 case PRAGMA_OMP_CLAUSE_ORDERED:
7394 clauses = c_parser_omp_clause_ordered (parser, clauses);
7397 case PRAGMA_OMP_CLAUSE_PRIVATE:
7398 clauses = c_parser_omp_clause_private (parser, clauses);
7401 case PRAGMA_OMP_CLAUSE_REDUCTION:
7402 clauses = c_parser_omp_clause_reduction (parser, clauses);
7403 c_name = "reduction";
7405 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7406 clauses = c_parser_omp_clause_schedule (parser, clauses);
7407 c_name = "schedule";
7409 case PRAGMA_OMP_CLAUSE_SHARED:
7410 clauses = c_parser_omp_clause_shared (parser, clauses);
7413 case PRAGMA_OMP_CLAUSE_UNTIED:
7414 clauses = c_parser_omp_clause_untied (parser, clauses);
7418 c_parser_error (parser, "expected %<#pragma omp%> clause");
7422 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7424 /* Remove the invalid clause(s) from the list to avoid
7425 confusing the rest of the compiler. */
7427 error ("%H%qs is not valid for %qs", &here, c_name, where);
7432 c_parser_skip_to_pragma_eol (parser);
7434 return c_finish_omp_clauses (clauses);
7441 In practice, we're also interested in adding the statement to an
7442 outer node. So it is convenient if we work around the fact that
7443 c_parser_statement calls add_stmt. */
7446 c_parser_omp_structured_block (c_parser *parser)
7448 tree stmt = push_stmt_list ();
7449 c_parser_statement (parser);
7450 return pop_stmt_list (stmt);
7454 # pragma omp atomic new-line
7458 x binop= expr | x++ | ++x | x-- | --x
7460 +, *, -, /, &, ^, |, <<, >>
7462 where x is an lvalue expression with scalar type. */
7465 c_parser_omp_atomic (c_parser *parser)
7469 enum tree_code code;
7470 struct c_expr rhs_expr;
7472 c_parser_skip_to_pragma_eol (parser);
7474 lhs = c_parser_unary_expression (parser).value;
7475 switch (TREE_CODE (lhs))
7479 c_parser_skip_to_end_of_block_or_statement (parser);
7482 case PREINCREMENT_EXPR:
7483 case POSTINCREMENT_EXPR:
7484 lhs = TREE_OPERAND (lhs, 0);
7486 rhs = integer_one_node;
7489 case PREDECREMENT_EXPR:
7490 case POSTDECREMENT_EXPR:
7491 lhs = TREE_OPERAND (lhs, 0);
7493 rhs = integer_one_node;
7497 switch (c_parser_peek_token (parser)->type)
7503 code = TRUNC_DIV_EXPR;
7518 code = BIT_AND_EXPR;
7521 code = BIT_IOR_EXPR;
7524 code = BIT_XOR_EXPR;
7527 c_parser_error (parser,
7528 "invalid operator for %<#pragma omp atomic%>");
7532 c_parser_consume_token (parser);
7533 rhs_expr = c_parser_expression (parser);
7534 rhs_expr = default_function_array_conversion (rhs_expr);
7535 rhs = rhs_expr.value;
7538 stmt = c_finish_omp_atomic (code, lhs, rhs);
7539 if (stmt != error_mark_node)
7541 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7546 # pragma omp barrier new-line
7550 c_parser_omp_barrier (c_parser *parser)
7552 c_parser_consume_pragma (parser);
7553 c_parser_skip_to_pragma_eol (parser);
7555 c_finish_omp_barrier ();
7559 # pragma omp critical [(name)] new-line
7564 c_parser_omp_critical (c_parser *parser)
7566 tree stmt, name = NULL;
7568 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7570 c_parser_consume_token (parser);
7571 if (c_parser_next_token_is (parser, CPP_NAME))
7573 name = c_parser_peek_token (parser)->value;
7574 c_parser_consume_token (parser);
7575 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7578 c_parser_error (parser, "expected identifier");
7580 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7581 c_parser_error (parser, "expected %<(%> or end of line");
7582 c_parser_skip_to_pragma_eol (parser);
7584 stmt = c_parser_omp_structured_block (parser);
7585 return c_finish_omp_critical (stmt, name);
7589 # pragma omp flush flush-vars[opt] new-line
7592 ( variable-list ) */
7595 c_parser_omp_flush (c_parser *parser)
7597 c_parser_consume_pragma (parser);
7598 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7599 c_parser_omp_var_list_parens (parser, 0, NULL);
7600 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7601 c_parser_error (parser, "expected %<(%> or end of line");
7602 c_parser_skip_to_pragma_eol (parser);
7604 c_finish_omp_flush ();
7607 /* Parse the restricted form of the for statement allowed by OpenMP.
7608 The real trick here is to determine the loop control variable early
7609 so that we can push a new decl if necessary to make it private. */
7612 c_parser_omp_for_loop (c_parser *parser, tree clauses, tree *par_clauses)
7614 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7615 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7617 bool fail = false, open_brace_parsed = false;
7618 int i, collapse = 1, nbraces = 0;
7620 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7621 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7622 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7624 gcc_assert (collapse >= 1);
7626 declv = make_tree_vec (collapse);
7627 initv = make_tree_vec (collapse);
7628 condv = make_tree_vec (collapse);
7629 incrv = make_tree_vec (collapse);
7631 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7633 c_parser_error (parser, "for statement expected");
7636 loc = c_parser_peek_token (parser)->location;
7637 c_parser_consume_token (parser);
7639 for (i = 0; i < collapse; i++)
7643 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7646 /* Parse the initialization declaration or expression. */
7647 if (c_parser_next_token_starts_declspecs (parser))
7651 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7652 c_parser_declaration_or_fndef (parser, true, true, true, true);
7653 decl = check_for_loop_decls ();
7656 if (DECL_INITIAL (decl) == error_mark_node)
7657 decl = error_mark_node;
7660 else if (c_parser_next_token_is (parser, CPP_NAME)
7661 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7663 struct c_expr init_exp;
7665 decl = c_parser_postfix_expression (parser).value;
7667 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7669 init_exp = c_parser_expr_no_commas (parser, NULL);
7670 init_exp = default_function_array_conversion (init_exp);
7671 init = build_modify_expr (decl, NOP_EXPR, init_exp.value);
7672 init = c_process_expr_stmt (init);
7674 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7679 c_parser_error (parser,
7680 "expected iteration declaration or initialization");
7681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7687 /* Parse the loop condition. */
7689 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7691 cond = c_parser_expression_conv (parser).value;
7692 cond = c_objc_common_truthvalue_conversion (cond);
7693 if (CAN_HAVE_LOCATION_P (cond))
7694 SET_EXPR_LOCATION (cond, input_location);
7696 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7698 /* Parse the increment expression. */
7700 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7701 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7702 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7704 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
7708 TREE_VEC_ELT (declv, i) = decl;
7709 TREE_VEC_ELT (initv, i) = init;
7710 TREE_VEC_ELT (condv, i) = cond;
7711 TREE_VEC_ELT (incrv, i) = incr;
7715 if (i == collapse - 1)
7718 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7719 in between the collapsed for loops to be still considered perfectly
7720 nested. Hopefully the final version clarifies this.
7721 For now handle (multiple) {'s and empty statements. */
7724 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7726 c_parser_consume_token (parser);
7729 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7731 c_parser_consume_token (parser);
7735 && c_parser_next_token_is (parser, CPP_SEMICOLON))
7736 c_parser_consume_token (parser);
7739 c_parser_error (parser, "not enough perfectly nested loops");
7742 open_brace_parsed = true;
7752 nbraces += bracecount;
7755 save_break = c_break_label;
7756 c_break_label = size_one_node;
7757 save_cont = c_cont_label;
7758 c_cont_label = NULL_TREE;
7759 body = push_stmt_list ();
7761 if (open_brace_parsed)
7763 stmt = c_begin_compound_stmt (true);
7764 c_parser_compound_statement_nostart (parser);
7765 add_stmt (c_end_compound_stmt (stmt, true));
7768 add_stmt (c_parser_c99_block_statement (parser));
7770 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7772 body = pop_stmt_list (body);
7773 c_break_label = save_break;
7774 c_cont_label = save_cont;
7778 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7780 c_parser_consume_token (parser);
7783 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7784 c_parser_consume_token (parser);
7787 c_parser_error (parser, "collapsed loops not perfectly nested");
7790 stmt = c_begin_compound_stmt (true);
7792 c_parser_compound_statement_nostart (parser);
7793 body = c_end_compound_stmt (stmt, true);
7800 /* Only bother calling c_finish_omp_for if we haven't already generated
7801 an error from the initialization parsing. */
7804 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
7807 if (par_clauses != NULL)
7810 for (c = par_clauses; *c ; )
7811 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
7812 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
7813 c = &OMP_CLAUSE_CHAIN (*c);
7816 for (i = 0; i < collapse; i++)
7817 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
7820 c = &OMP_CLAUSE_CHAIN (*c);
7821 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
7823 error ("%Hiteration variable %qD should not be firstprivate",
7824 &loc, OMP_CLAUSE_DECL (*c));
7825 *c = OMP_CLAUSE_CHAIN (*c);
7829 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7830 change it to shared (decl) in
7831 OMP_PARALLEL_CLAUSES. */
7832 tree l = build_omp_clause (OMP_CLAUSE_LASTPRIVATE);
7833 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
7834 OMP_CLAUSE_CHAIN (l) = clauses;
7836 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
7840 OMP_FOR_CLAUSES (stmt) = clauses;
7847 stmt = c_end_compound_stmt (TREE_VALUE (for_block), true);
7849 for_block = TREE_CHAIN (for_block);
7855 #pragma omp for for-clause[optseq] new-line
7859 #define OMP_FOR_CLAUSE_MASK \
7860 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7861 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7862 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7863 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7864 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7865 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7866 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7867 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7870 c_parser_omp_for (c_parser *parser)
7872 tree block, clauses, ret;
7874 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7877 block = c_begin_compound_stmt (true);
7878 ret = c_parser_omp_for_loop (parser, clauses, NULL);
7879 block = c_end_compound_stmt (block, true);
7886 # pragma omp master new-line
7891 c_parser_omp_master (c_parser *parser)
7893 c_parser_skip_to_pragma_eol (parser);
7894 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7898 # pragma omp ordered new-line
7903 c_parser_omp_ordered (c_parser *parser)
7905 c_parser_skip_to_pragma_eol (parser);
7906 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7912 { section-sequence }
7915 section-directive[opt] structured-block
7916 section-sequence section-directive structured-block */
7919 c_parser_omp_sections_scope (c_parser *parser)
7922 bool error_suppress = false;
7925 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7927 /* Avoid skipping until the end of the block. */
7928 parser->error = false;
7932 stmt = push_stmt_list ();
7934 loc = c_parser_peek_token (parser)->location;
7935 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7937 substmt = push_stmt_list ();
7941 c_parser_statement (parser);
7943 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7945 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7947 if (c_parser_next_token_is (parser, CPP_EOF))
7951 substmt = pop_stmt_list (substmt);
7952 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7953 SET_EXPR_LOCATION (substmt, loc);
7959 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7961 if (c_parser_next_token_is (parser, CPP_EOF))
7964 loc = c_parser_peek_token (parser)->location;
7965 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7967 c_parser_consume_pragma (parser);
7968 c_parser_skip_to_pragma_eol (parser);
7969 error_suppress = false;
7971 else if (!error_suppress)
7973 error ("%Hexpected %<#pragma omp section%> or %<}%>",
7975 error_suppress = true;
7978 substmt = c_parser_omp_structured_block (parser);
7979 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7980 SET_EXPR_LOCATION (substmt, loc);
7983 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7984 "expected %<#pragma omp section%> or %<}%>");
7986 substmt = pop_stmt_list (stmt);
7988 stmt = make_node (OMP_SECTIONS);
7989 TREE_TYPE (stmt) = void_type_node;
7990 OMP_SECTIONS_BODY (stmt) = substmt;
7992 return add_stmt (stmt);
7996 # pragma omp sections sections-clause[optseq] newline
8000 #define OMP_SECTIONS_CLAUSE_MASK \
8001 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8002 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8003 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8004 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8005 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8008 c_parser_omp_sections (c_parser *parser)
8010 tree block, clauses, ret;
8012 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8013 "#pragma omp sections");
8015 block = c_begin_compound_stmt (true);
8016 ret = c_parser_omp_sections_scope (parser);
8018 OMP_SECTIONS_CLAUSES (ret) = clauses;
8019 block = c_end_compound_stmt (block, true);
8026 # pragma parallel parallel-clause new-line
8027 # pragma parallel for parallel-for-clause new-line
8028 # pragma parallel sections parallel-sections-clause new-line
8031 #define OMP_PARALLEL_CLAUSE_MASK \
8032 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8033 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8034 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8035 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8036 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8037 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8038 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8039 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8042 c_parser_omp_parallel (c_parser *parser)
8044 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8045 const char *p_name = "#pragma omp parallel";
8046 tree stmt, clauses, par_clause, ws_clause, block;
8047 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8049 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8051 c_parser_consume_token (parser);
8052 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8053 p_name = "#pragma omp parallel for";
8054 mask |= OMP_FOR_CLAUSE_MASK;
8055 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8057 else if (c_parser_next_token_is (parser, CPP_NAME))
8059 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8060 if (strcmp (p, "sections") == 0)
8062 c_parser_consume_token (parser);
8063 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8064 p_name = "#pragma omp parallel sections";
8065 mask |= OMP_SECTIONS_CLAUSE_MASK;
8066 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8070 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8074 case PRAGMA_OMP_PARALLEL:
8075 block = c_begin_omp_parallel ();
8076 c_parser_statement (parser);
8077 stmt = c_finish_omp_parallel (clauses, block);
8080 case PRAGMA_OMP_PARALLEL_FOR:
8081 block = c_begin_omp_parallel ();
8082 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8083 c_parser_omp_for_loop (parser, ws_clause, &par_clause);
8084 stmt = c_finish_omp_parallel (par_clause, block);
8085 OMP_PARALLEL_COMBINED (stmt) = 1;
8088 case PRAGMA_OMP_PARALLEL_SECTIONS:
8089 block = c_begin_omp_parallel ();
8090 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
8091 stmt = c_parser_omp_sections_scope (parser);
8093 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8094 stmt = c_finish_omp_parallel (par_clause, block);
8095 OMP_PARALLEL_COMBINED (stmt) = 1;
8106 # pragma omp single single-clause[optseq] new-line
8110 #define OMP_SINGLE_CLAUSE_MASK \
8111 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8112 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8113 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8114 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8117 c_parser_omp_single (c_parser *parser)
8119 tree stmt = make_node (OMP_SINGLE);
8120 TREE_TYPE (stmt) = void_type_node;
8122 OMP_SINGLE_CLAUSES (stmt)
8123 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8124 "#pragma omp single");
8125 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8127 return add_stmt (stmt);
8131 # pragma omp task task-clause[optseq] new-line
8134 #define OMP_TASK_CLAUSE_MASK \
8135 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8136 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8137 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8138 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8139 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8140 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8143 c_parser_omp_task (c_parser *parser)
8145 tree clauses, block;
8147 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8148 "#pragma omp task");
8150 block = c_begin_omp_task ();
8151 c_parser_statement (parser);
8152 return c_finish_omp_task (clauses, block);
8156 # pragma omp taskwait new-line
8160 c_parser_omp_taskwait (c_parser *parser)
8162 c_parser_consume_pragma (parser);
8163 c_parser_skip_to_pragma_eol (parser);
8165 c_finish_omp_taskwait ();
8168 /* Main entry point to parsing most OpenMP pragmas. */
8171 c_parser_omp_construct (c_parser *parser)
8173 enum pragma_kind p_kind;
8177 loc = c_parser_peek_token (parser)->location;
8178 p_kind = c_parser_peek_token (parser)->pragma_kind;
8179 c_parser_consume_pragma (parser);
8181 /* For all constructs below except #pragma omp atomic
8182 MUST_NOT_THROW catch handlers are needed when exceptions
8184 if (p_kind != PRAGMA_OMP_ATOMIC)
8185 c_maybe_initialize_eh ();
8189 case PRAGMA_OMP_ATOMIC:
8190 c_parser_omp_atomic (parser);
8192 case PRAGMA_OMP_CRITICAL:
8193 stmt = c_parser_omp_critical (parser);
8195 case PRAGMA_OMP_FOR:
8196 stmt = c_parser_omp_for (parser);
8198 case PRAGMA_OMP_MASTER:
8199 stmt = c_parser_omp_master (parser);
8201 case PRAGMA_OMP_ORDERED:
8202 stmt = c_parser_omp_ordered (parser);
8204 case PRAGMA_OMP_PARALLEL:
8205 stmt = c_parser_omp_parallel (parser);
8207 case PRAGMA_OMP_SECTIONS:
8208 stmt = c_parser_omp_sections (parser);
8210 case PRAGMA_OMP_SINGLE:
8211 stmt = c_parser_omp_single (parser);
8213 case PRAGMA_OMP_TASK:
8214 stmt = c_parser_omp_task (parser);
8221 SET_EXPR_LOCATION (stmt, loc);
8226 # pragma omp threadprivate (variable-list) */
8229 c_parser_omp_threadprivate (c_parser *parser)
8233 c_parser_consume_pragma (parser);
8234 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
8236 /* Mark every variable in VARS to be assigned thread local storage. */
8237 for (t = vars; t; t = TREE_CHAIN (t))
8239 tree v = TREE_PURPOSE (t);
8241 /* If V had already been marked threadprivate, it doesn't matter
8242 whether it had been used prior to this point. */
8243 if (TREE_CODE (v) != VAR_DECL)
8244 error ("%qD is not a variable", v);
8245 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8246 error ("%qE declared %<threadprivate%> after first use", v);
8247 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8248 error ("automatic variable %qE cannot be %<threadprivate%>", v);
8249 else if (TREE_TYPE (v) == error_mark_node)
8251 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8252 error ("%<threadprivate%> %qE has incomplete type", v);
8255 if (! DECL_THREAD_LOCAL_P (v))
8257 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8258 /* If rtl has been already set for this var, call
8259 make_decl_rtl once again, so that encode_section_info
8260 has a chance to look at the new decl flags. */
8261 if (DECL_RTL_SET_P (v))
8264 C_DECL_THREADPRIVATE_P (v) = 1;
8268 c_parser_skip_to_pragma_eol (parser);
8272 /* Parse a single source file. */
8277 /* Use local storage to begin. If the first token is a pragma, parse it.
8278 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8279 which will cause garbage collection. */
8282 memset (&tparser, 0, sizeof tparser);
8283 the_parser = &tparser;
8285 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8286 c_parser_pragma_pch_preprocess (&tparser);
8288 the_parser = GGC_NEW (c_parser);
8289 *the_parser = tparser;
8291 c_parser_translation_unit (the_parser);
8295 #include "gt-c-parser.h"