1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
5 Parser actions based on the old Bison parser; structure somewhat
6 influenced by and fragments based on the C++ parser.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 Make sure all relevant comments, and all relevant code from all
27 actions, brought over from old parser. Verify exact correspondence
30 Add testcases covering every input symbol in every state in old and
33 Include full syntax for GNU C, including erroneous cases accepted
34 with error messages, in syntax productions in comments.
36 Make more diagnostics in the front end generally take an explicit
37 location rather than implicitly using input_location. */
41 #include "coretypes.h"
45 #include "langhooks.h"
61 /* The reserved keyword table. */
65 ENUM_BITFIELD(rid) rid : 16;
66 unsigned int disable : 16;
69 /* Disable mask. Keywords are disabled if (reswords[i].disable &
71 #define D_C89 0x01 /* not in C89 */
72 #define D_EXT 0x02 /* GCC extension */
73 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
74 #define D_OBJC 0x08 /* Objective C only */
76 static const struct resword reswords[] =
78 { "_Bool", RID_BOOL, 0 },
79 { "_Complex", RID_COMPLEX, 0 },
80 { "_Decimal32", RID_DFLOAT32, D_EXT },
81 { "_Decimal64", RID_DFLOAT64, D_EXT },
82 { "_Decimal128", RID_DFLOAT128, D_EXT },
83 { "_Fract", RID_FRACT, D_EXT },
84 { "_Accum", RID_ACCUM, D_EXT },
85 { "_Sat", RID_SAT, D_EXT },
86 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
87 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
88 { "__alignof", RID_ALIGNOF, 0 },
89 { "__alignof__", RID_ALIGNOF, 0 },
90 { "__asm", RID_ASM, 0 },
91 { "__asm__", RID_ASM, 0 },
92 { "__attribute", RID_ATTRIBUTE, 0 },
93 { "__attribute__", RID_ATTRIBUTE, 0 },
94 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
95 { "__builtin_offsetof", RID_OFFSETOF, 0 },
96 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
97 { "__builtin_va_arg", RID_VA_ARG, 0 },
98 { "__complex", RID_COMPLEX, 0 },
99 { "__complex__", RID_COMPLEX, 0 },
100 { "__const", RID_CONST, 0 },
101 { "__const__", RID_CONST, 0 },
102 { "__extension__", RID_EXTENSION, 0 },
103 { "__func__", RID_C99_FUNCTION_NAME, 0 },
104 { "__imag", RID_IMAGPART, 0 },
105 { "__imag__", RID_IMAGPART, 0 },
106 { "__inline", RID_INLINE, 0 },
107 { "__inline__", RID_INLINE, 0 },
108 { "__label__", RID_LABEL, 0 },
109 { "__real", RID_REALPART, 0 },
110 { "__real__", RID_REALPART, 0 },
111 { "__restrict", RID_RESTRICT, 0 },
112 { "__restrict__", RID_RESTRICT, 0 },
113 { "__signed", RID_SIGNED, 0 },
114 { "__signed__", RID_SIGNED, 0 },
115 { "__thread", RID_THREAD, 0 },
116 { "__typeof", RID_TYPEOF, 0 },
117 { "__typeof__", RID_TYPEOF, 0 },
118 { "__volatile", RID_VOLATILE, 0 },
119 { "__volatile__", RID_VOLATILE, 0 },
120 { "asm", RID_ASM, D_EXT },
121 { "auto", RID_AUTO, 0 },
122 { "break", RID_BREAK, 0 },
123 { "case", RID_CASE, 0 },
124 { "char", RID_CHAR, 0 },
125 { "const", RID_CONST, 0 },
126 { "continue", RID_CONTINUE, 0 },
127 { "default", RID_DEFAULT, 0 },
129 { "double", RID_DOUBLE, 0 },
130 { "else", RID_ELSE, 0 },
131 { "enum", RID_ENUM, 0 },
132 { "extern", RID_EXTERN, 0 },
133 { "float", RID_FLOAT, 0 },
134 { "for", RID_FOR, 0 },
135 { "goto", RID_GOTO, 0 },
137 { "inline", RID_INLINE, D_EXT89 },
138 { "int", RID_INT, 0 },
139 { "long", RID_LONG, 0 },
140 { "register", RID_REGISTER, 0 },
141 { "restrict", RID_RESTRICT, D_C89 },
142 { "return", RID_RETURN, 0 },
143 { "short", RID_SHORT, 0 },
144 { "signed", RID_SIGNED, 0 },
145 { "sizeof", RID_SIZEOF, 0 },
146 { "static", RID_STATIC, 0 },
147 { "struct", RID_STRUCT, 0 },
148 { "switch", RID_SWITCH, 0 },
149 { "typedef", RID_TYPEDEF, 0 },
150 { "typeof", RID_TYPEOF, D_EXT },
151 { "union", RID_UNION, 0 },
152 { "unsigned", RID_UNSIGNED, 0 },
153 { "void", RID_VOID, 0 },
154 { "volatile", RID_VOLATILE, 0 },
155 { "while", RID_WHILE, 0 },
156 /* These Objective-C keywords are recognized only immediately after
158 { "class", RID_AT_CLASS, D_OBJC },
159 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
160 { "defs", RID_AT_DEFS, D_OBJC },
161 { "encode", RID_AT_ENCODE, D_OBJC },
162 { "end", RID_AT_END, D_OBJC },
163 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
164 { "interface", RID_AT_INTERFACE, D_OBJC },
165 { "private", RID_AT_PRIVATE, D_OBJC },
166 { "protected", RID_AT_PROTECTED, D_OBJC },
167 { "protocol", RID_AT_PROTOCOL, D_OBJC },
168 { "public", RID_AT_PUBLIC, D_OBJC },
169 { "selector", RID_AT_SELECTOR, D_OBJC },
170 { "throw", RID_AT_THROW, D_OBJC },
171 { "try", RID_AT_TRY, D_OBJC },
172 { "catch", RID_AT_CATCH, D_OBJC },
173 { "finally", RID_AT_FINALLY, D_OBJC },
174 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
175 /* These are recognized only in protocol-qualifier context
177 { "bycopy", RID_BYCOPY, D_OBJC },
178 { "byref", RID_BYREF, D_OBJC },
179 { "in", RID_IN, D_OBJC },
180 { "inout", RID_INOUT, D_OBJC },
181 { "oneway", RID_ONEWAY, D_OBJC },
182 { "out", RID_OUT, D_OBJC },
184 #define N_reswords (sizeof reswords / sizeof (struct resword))
186 /* Initialization routine for this file. */
191 /* The only initialization required is of the reserved word
195 int mask = (flag_isoc99 ? 0 : D_C89)
196 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
198 if (!c_dialect_objc ())
201 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
202 for (i = 0; i < N_reswords; i++)
204 /* If a keyword is disabled, do not enter it into the table
205 and so create a canonical spelling that isn't a keyword. */
206 if (reswords[i].disable & mask)
209 id = get_identifier (reswords[i].word);
210 C_RID_CODE (id) = reswords[i].rid;
211 C_IS_RESERVED_WORD (id) = 1;
212 ridpointers [(int) reswords[i].rid] = id;
216 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
217 and the C parser. Unlike the C++ lexer, the parser structure
218 stores the lexer information instead of using a separate structure.
219 Identifiers are separated into ordinary identifiers, type names,
220 keywords and some other Objective-C types of identifiers, and some
221 look-ahead is maintained.
223 ??? It might be a good idea to lex the whole file up front (as for
224 C++). It would then be possible to share more of the C and C++
225 lexer code, if desired. */
227 /* The following local token type is used. */
230 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
232 /* More information about the type of a CPP_NAME token. */
233 typedef enum c_id_kind {
234 /* An ordinary identifier. */
236 /* An identifier declared as a typedef name. */
238 /* An identifier declared as an Objective-C class name. */
240 /* Not an identifier. */
244 /* A single C token after string literal concatenation and conversion
245 of preprocessing tokens to tokens. */
246 typedef struct c_token GTY (())
248 /* The kind of token. */
249 ENUM_BITFIELD (cpp_ttype) type : 8;
250 /* If this token is a CPP_NAME, this value indicates whether also
251 declared as some kind of type. Otherwise, it is C_ID_NONE. */
252 ENUM_BITFIELD (c_id_kind) id_kind : 8;
253 /* If this token is a keyword, this value indicates which keyword.
254 Otherwise, this value is RID_MAX. */
255 ENUM_BITFIELD (rid) keyword : 8;
256 /* If this token is a CPP_PRAGMA, this indicates the pragma that
257 was seen. Otherwise it is PRAGMA_NONE. */
258 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
259 /* True if this token is from a system header. */
260 BOOL_BITFIELD in_system_header : 1;
261 /* The value associated with this token, if any. */
263 /* The location at which this token was found. */
267 /* A parser structure recording information about the state and
268 context of parsing. Includes lexer information with up to two
269 tokens of look-ahead; more are not needed for C. */
270 typedef struct c_parser GTY(())
272 /* The look-ahead tokens. */
274 /* How many look-ahead tokens are available (0, 1 or 2). */
276 /* True if a syntax error is being recovered from; false otherwise.
277 c_parser_error sets this flag. It should clear this flag when
278 enough tokens have been consumed to recover from the error. */
279 BOOL_BITFIELD error : 1;
280 /* True if we're processing a pragma, and shouldn't automatically
281 consume CPP_PRAGMA_EOL. */
282 BOOL_BITFIELD in_pragma : 1;
283 /* Objective-C specific parser/lexer information. */
284 BOOL_BITFIELD objc_pq_context : 1;
285 /* The following flag is needed to contextualize Objective-C lexical
286 analysis. In some cases (e.g., 'int NSObject;'), it is
287 undesirable to bind an identifier to an Objective-C class, even
288 if a class with that name exists. */
289 BOOL_BITFIELD objc_need_raw_identifier : 1;
293 /* The actual parser and external interface. ??? Does this need to be
294 garbage-collected? */
296 static GTY (()) c_parser *the_parser;
299 /* Read in and lex a single token, storing it in *TOKEN. */
302 c_lex_one_token (c_parser *parser, c_token *token)
304 timevar_push (TV_LEX);
306 token->type = c_lex_with_flags (&token->value, &token->location, NULL);
307 token->id_kind = C_ID_NONE;
308 token->keyword = RID_MAX;
309 token->pragma_kind = PRAGMA_NONE;
310 token->in_system_header = in_system_header;
318 bool objc_force_identifier = parser->objc_need_raw_identifier;
319 if (c_dialect_objc ())
320 parser->objc_need_raw_identifier = false;
322 if (C_IS_RESERVED_WORD (token->value))
324 enum rid rid_code = C_RID_CODE (token->value);
326 if (c_dialect_objc ())
328 if (!OBJC_IS_AT_KEYWORD (rid_code)
329 && (!OBJC_IS_PQ_KEYWORD (rid_code)
330 || parser->objc_pq_context))
332 /* Return the canonical spelling for this keyword. */
333 token->value = ridpointers[(int) rid_code];
334 token->type = CPP_KEYWORD;
335 token->keyword = rid_code;
341 /* Return the canonical spelling for this keyword. */
342 token->value = ridpointers[(int) rid_code];
343 token->type = CPP_KEYWORD;
344 token->keyword = rid_code;
349 decl = lookup_name (token->value);
352 if (TREE_CODE (decl) == TYPE_DECL)
354 token->id_kind = C_ID_TYPENAME;
358 else if (c_dialect_objc ())
360 tree objc_interface_decl = objc_is_class_name (token->value);
361 /* Objective-C class names are in the same namespace as
362 variables and typedefs, and hence are shadowed by local
364 if (objc_interface_decl
365 && (global_bindings_p ()
366 || (!objc_force_identifier && !decl)))
368 token->value = objc_interface_decl;
369 token->id_kind = C_ID_CLASSNAME;
373 token->id_kind = C_ID_ID;
377 /* This only happens in Objective-C; it must be a keyword. */
378 token->type = CPP_KEYWORD;
379 token->keyword = C_RID_CODE (token->value);
383 case CPP_CLOSE_PAREN:
385 /* These tokens may affect the interpretation of any identifiers
386 following, if doing Objective-C. */
387 if (c_dialect_objc ())
388 parser->objc_need_raw_identifier = false;
391 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
392 token->pragma_kind = TREE_INT_CST_LOW (token->value);
398 timevar_pop (TV_LEX);
401 /* Return a pointer to the next token from PARSER, reading it in if
404 static inline c_token *
405 c_parser_peek_token (c_parser *parser)
407 if (parser->tokens_avail == 0)
409 c_lex_one_token (parser, &parser->tokens[0]);
410 parser->tokens_avail = 1;
412 return &parser->tokens[0];
415 /* Return true if the next token from PARSER has the indicated
419 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
421 return c_parser_peek_token (parser)->type == type;
424 /* Return true if the next token from PARSER does not have the
428 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
430 return !c_parser_next_token_is (parser, type);
433 /* Return true if the next token from PARSER is the indicated
437 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
441 /* Peek at the next token. */
442 token = c_parser_peek_token (parser);
443 /* Check to see if it is the indicated keyword. */
444 return token->keyword == keyword;
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token *token)
455 switch (token->id_kind)
462 gcc_assert (c_dialect_objc ());
468 switch (token->keyword)
500 if (c_dialect_objc ())
508 /* Return true if the next token from PARSER can start a type name,
511 c_parser_next_token_starts_typename (c_parser *parser)
513 c_token *token = c_parser_peek_token (parser);
514 return c_token_starts_typename (token);
517 /* Return true if TOKEN can start declaration specifiers, false
520 c_token_starts_declspecs (c_token *token)
525 switch (token->id_kind)
532 gcc_assert (c_dialect_objc ());
538 switch (token->keyword)
577 if (c_dialect_objc ())
585 /* Return true if the next token from PARSER can start declaration
586 specifiers, false otherwise. */
588 c_parser_next_token_starts_declspecs (c_parser *parser)
590 c_token *token = c_parser_peek_token (parser);
591 return c_token_starts_declspecs (token);
594 /* Return a pointer to the next-but-one token from PARSER, reading it
595 in if necessary. The next token is already read in. */
598 c_parser_peek_2nd_token (c_parser *parser)
600 if (parser->tokens_avail >= 2)
601 return &parser->tokens[1];
602 gcc_assert (parser->tokens_avail == 1);
603 gcc_assert (parser->tokens[0].type != CPP_EOF);
604 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
605 c_lex_one_token (parser, &parser->tokens[1]);
606 parser->tokens_avail = 2;
607 return &parser->tokens[1];
610 /* Consume the next token from PARSER. */
613 c_parser_consume_token (c_parser *parser)
615 gcc_assert (parser->tokens_avail >= 1);
616 gcc_assert (parser->tokens[0].type != CPP_EOF);
617 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
618 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
619 if (parser->tokens_avail == 2)
620 parser->tokens[0] = parser->tokens[1];
621 parser->tokens_avail--;
624 /* Expect the current token to be a #pragma. Consume it and remember
625 that we've begun parsing a pragma. */
628 c_parser_consume_pragma (c_parser *parser)
630 gcc_assert (!parser->in_pragma);
631 gcc_assert (parser->tokens_avail >= 1);
632 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
633 if (parser->tokens_avail == 2)
634 parser->tokens[0] = parser->tokens[1];
635 parser->tokens_avail--;
636 parser->in_pragma = true;
639 /* Update the globals input_location and in_system_header from
642 c_parser_set_source_position_from_token (c_token *token)
644 if (token->type != CPP_EOF)
646 input_location = token->location;
647 in_system_header = token->in_system_header;
651 /* Issue a diagnostic of the form
652 FILE:LINE: MESSAGE before TOKEN
653 where TOKEN is the next token in the input stream of PARSER.
654 MESSAGE (specified by the caller) is usually of the form "expected
657 Do not issue a diagnostic if still recovering from an error.
659 ??? This is taken from the C++ parser, but building up messages in
660 this way is not i18n-friendly and some other approach should be
664 c_parser_error (c_parser *parser, const char *gmsgid)
666 c_token *token = c_parser_peek_token (parser);
669 parser->error = true;
672 /* This diagnostic makes more sense if it is tagged to the line of
673 the token we just peeked at. */
674 c_parser_set_source_position_from_token (token);
675 c_parse_error (gmsgid,
676 /* Because c_parse_error does not understand
677 CPP_KEYWORD, keywords are treated like
679 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
683 /* If the next token is of the indicated TYPE, consume it. Otherwise,
684 issue the error MSGID. If MSGID is NULL then a message has already
685 been produced and no message will be produced this time. Returns
686 true if found, false otherwise. */
689 c_parser_require (c_parser *parser,
693 if (c_parser_next_token_is (parser, type))
695 c_parser_consume_token (parser);
700 c_parser_error (parser, msgid);
705 /* If the next token is the indicated keyword, consume it. Otherwise,
706 issue the error MSGID. Returns true if found, false otherwise. */
709 c_parser_require_keyword (c_parser *parser,
713 if (c_parser_next_token_is_keyword (parser, keyword))
715 c_parser_consume_token (parser);
720 c_parser_error (parser, msgid);
725 /* Like c_parser_require, except that tokens will be skipped until the
726 desired token is found. An error message is still produced if the
727 next token is not as expected. If MSGID is NULL then a message has
728 already been produced and no message will be produced this
732 c_parser_skip_until_found (c_parser *parser,
736 unsigned nesting_depth = 0;
738 if (c_parser_require (parser, type, msgid))
741 /* Skip tokens until the desired token is found. */
744 /* Peek at the next token. */
745 c_token *token = c_parser_peek_token (parser);
746 /* If we've reached the token we want, consume it and stop. */
747 if (token->type == type && !nesting_depth)
749 c_parser_consume_token (parser);
753 /* If we've run out of tokens, stop. */
754 if (token->type == CPP_EOF)
756 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
758 if (token->type == CPP_OPEN_BRACE
759 || token->type == CPP_OPEN_PAREN
760 || token->type == CPP_OPEN_SQUARE)
762 else if (token->type == CPP_CLOSE_BRACE
763 || token->type == CPP_CLOSE_PAREN
764 || token->type == CPP_CLOSE_SQUARE)
766 if (nesting_depth-- == 0)
769 /* Consume this token. */
770 c_parser_consume_token (parser);
772 parser->error = false;
775 /* Skip tokens until the end of a parameter is found, but do not
776 consume the comma, semicolon or closing delimiter. */
779 c_parser_skip_to_end_of_parameter (c_parser *parser)
781 unsigned nesting_depth = 0;
785 c_token *token = c_parser_peek_token (parser);
786 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
789 /* If we've run out of tokens, stop. */
790 if (token->type == CPP_EOF)
792 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
794 if (token->type == CPP_OPEN_BRACE
795 || token->type == CPP_OPEN_PAREN
796 || token->type == CPP_OPEN_SQUARE)
798 else if (token->type == CPP_CLOSE_BRACE
799 || token->type == CPP_CLOSE_PAREN
800 || token->type == CPP_CLOSE_SQUARE)
802 if (nesting_depth-- == 0)
805 /* Consume this token. */
806 c_parser_consume_token (parser);
808 parser->error = false;
811 /* Expect to be at the end of the pragma directive and consume an
812 end of line marker. */
815 c_parser_skip_to_pragma_eol (c_parser *parser)
817 gcc_assert (parser->in_pragma);
818 parser->in_pragma = false;
820 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
823 c_token *token = c_parser_peek_token (parser);
824 if (token->type == CPP_EOF)
826 if (token->type == CPP_PRAGMA_EOL)
828 c_parser_consume_token (parser);
831 c_parser_consume_token (parser);
834 parser->error = false;
837 /* Skip tokens until we have consumed an entire block, or until we
838 have consumed a non-nested ';'. */
841 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
843 unsigned nesting_depth = 0;
844 bool save_error = parser->error;
850 /* Peek at the next token. */
851 token = c_parser_peek_token (parser);
859 if (parser->in_pragma)
864 /* If the next token is a ';', we have reached the
865 end of the statement. */
868 /* Consume the ';'. */
869 c_parser_consume_token (parser);
874 case CPP_CLOSE_BRACE:
875 /* If the next token is a non-nested '}', then we have
876 reached the end of the current block. */
877 if (nesting_depth == 0 || --nesting_depth == 0)
879 c_parser_consume_token (parser);
885 /* If it the next token is a '{', then we are entering a new
886 block. Consume the entire block. */
891 /* If we see a pragma, consume the whole thing at once. We
892 have some safeguards against consuming pragmas willy-nilly.
893 Normally, we'd expect to be here with parser->error set,
894 which disables these safeguards. But it's possible to get
895 here for secondary error recovery, after parser->error has
897 c_parser_consume_pragma (parser);
898 c_parser_skip_to_pragma_eol (parser);
899 parser->error = save_error;
906 c_parser_consume_token (parser);
910 parser->error = false;
913 /* Save the warning flags which are controlled by __extension__. */
916 disable_extension_diagnostics (void)
919 | (warn_pointer_arith << 1)
920 | (warn_traditional << 2)
923 warn_pointer_arith = 0;
924 warn_traditional = 0;
929 /* Restore the warning flags which are controlled by __extension__.
930 FLAGS is the return value from disable_extension_diagnostics. */
933 restore_extension_diagnostics (int flags)
935 pedantic = flags & 1;
936 warn_pointer_arith = (flags >> 1) & 1;
937 warn_traditional = (flags >> 2) & 1;
938 flag_iso = (flags >> 3) & 1;
941 /* Possibly kinds of declarator to parse. */
942 typedef enum c_dtr_syn {
943 /* A normal declarator with an identifier. */
945 /* An abstract declarator (maybe empty). */
947 /* A parameter declarator: may be either, but after a type name does
948 not redeclare a typedef name as an identifier if it can
949 alternatively be interpreted as a typedef name; see DR#009,
950 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
951 following DR#249. For example, given a typedef T, "int T" and
952 "int *T" are valid parameter declarations redeclaring T, while
953 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
954 abstract declarators rather than involving redundant parentheses;
955 the same applies with attributes inside the parentheses before
960 static void c_parser_external_declaration (c_parser *);
961 static void c_parser_asm_definition (c_parser *);
962 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
963 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
965 static struct c_typespec c_parser_enum_specifier (c_parser *);
966 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
967 static tree c_parser_struct_declaration (c_parser *);
968 static struct c_typespec c_parser_typeof_specifier (c_parser *);
969 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
971 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
973 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
975 struct c_declarator *);
976 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
977 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
978 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
979 static tree c_parser_simple_asm_expr (c_parser *);
980 static tree c_parser_attributes (c_parser *);
981 static struct c_type_name *c_parser_type_name (c_parser *);
982 static struct c_expr c_parser_initializer (c_parser *);
983 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
984 static void c_parser_initelt (c_parser *);
985 static void c_parser_initval (c_parser *, struct c_expr *);
986 static tree c_parser_compound_statement (c_parser *);
987 static void c_parser_compound_statement_nostart (c_parser *);
988 static void c_parser_label (c_parser *);
989 static void c_parser_statement (c_parser *);
990 static void c_parser_statement_after_labels (c_parser *);
991 static void c_parser_if_statement (c_parser *);
992 static void c_parser_switch_statement (c_parser *);
993 static void c_parser_while_statement (c_parser *);
994 static void c_parser_do_statement (c_parser *);
995 static void c_parser_for_statement (c_parser *);
996 static tree c_parser_asm_statement (c_parser *);
997 static tree c_parser_asm_operands (c_parser *, bool);
998 static tree c_parser_asm_clobbers (c_parser *);
999 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1000 static struct c_expr c_parser_conditional_expression (c_parser *,
1002 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1003 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1004 static struct c_expr c_parser_unary_expression (c_parser *);
1005 static struct c_expr c_parser_sizeof_expression (c_parser *);
1006 static struct c_expr c_parser_alignof_expression (c_parser *);
1007 static struct c_expr c_parser_postfix_expression (c_parser *);
1008 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1009 struct c_type_name *);
1010 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1012 static struct c_expr c_parser_expression (c_parser *);
1013 static struct c_expr c_parser_expression_conv (c_parser *);
1014 static tree c_parser_expr_list (c_parser *, bool);
1015 static void c_parser_omp_construct (c_parser *);
1016 static void c_parser_omp_threadprivate (c_parser *);
1017 static void c_parser_omp_barrier (c_parser *);
1018 static void c_parser_omp_flush (c_parser *);
1020 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1021 static bool c_parser_pragma (c_parser *, enum pragma_context);
1023 /* These Objective-C parser functions are only ever called when
1024 compiling Objective-C. */
1025 static void c_parser_objc_class_definition (c_parser *);
1026 static void c_parser_objc_class_instance_variables (c_parser *);
1027 static void c_parser_objc_class_declaration (c_parser *);
1028 static void c_parser_objc_alias_declaration (c_parser *);
1029 static void c_parser_objc_protocol_definition (c_parser *);
1030 static enum tree_code c_parser_objc_method_type (c_parser *);
1031 static void c_parser_objc_method_definition (c_parser *);
1032 static void c_parser_objc_methodprotolist (c_parser *);
1033 static void c_parser_objc_methodproto (c_parser *);
1034 static tree c_parser_objc_method_decl (c_parser *);
1035 static tree c_parser_objc_type_name (c_parser *);
1036 static tree c_parser_objc_protocol_refs (c_parser *);
1037 static void c_parser_objc_try_catch_statement (c_parser *);
1038 static void c_parser_objc_synchronized_statement (c_parser *);
1039 static tree c_parser_objc_selector (c_parser *);
1040 static tree c_parser_objc_selector_arg (c_parser *);
1041 static tree c_parser_objc_receiver (c_parser *);
1042 static tree c_parser_objc_message_args (c_parser *);
1043 static tree c_parser_objc_keywordexpr (c_parser *);
1045 /* Parse a translation unit (C90 6.7, C99 6.9).
1048 external-declarations
1050 external-declarations:
1051 external-declaration
1052 external-declarations external-declaration
1061 c_parser_translation_unit (c_parser *parser)
1063 if (c_parser_next_token_is (parser, CPP_EOF))
1066 pedwarn ("ISO C forbids an empty source file");
1070 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1074 c_parser_external_declaration (parser);
1075 obstack_free (&parser_obstack, obstack_position);
1077 while (c_parser_next_token_is_not (parser, CPP_EOF));
1081 /* Parse an external declaration (C90 6.7, C99 6.9).
1083 external-declaration:
1089 external-declaration:
1092 __extension__ external-declaration
1096 external-declaration:
1097 objc-class-definition
1098 objc-class-declaration
1099 objc-alias-declaration
1100 objc-protocol-definition
1101 objc-method-definition
1106 c_parser_external_declaration (c_parser *parser)
1109 switch (c_parser_peek_token (parser)->type)
1112 switch (c_parser_peek_token (parser)->keyword)
1115 ext = disable_extension_diagnostics ();
1116 c_parser_consume_token (parser);
1117 c_parser_external_declaration (parser);
1118 restore_extension_diagnostics (ext);
1121 c_parser_asm_definition (parser);
1123 case RID_AT_INTERFACE:
1124 case RID_AT_IMPLEMENTATION:
1125 gcc_assert (c_dialect_objc ());
1126 c_parser_objc_class_definition (parser);
1129 gcc_assert (c_dialect_objc ());
1130 c_parser_objc_class_declaration (parser);
1133 gcc_assert (c_dialect_objc ());
1134 c_parser_objc_alias_declaration (parser);
1136 case RID_AT_PROTOCOL:
1137 gcc_assert (c_dialect_objc ());
1138 c_parser_objc_protocol_definition (parser);
1141 gcc_assert (c_dialect_objc ());
1142 c_parser_consume_token (parser);
1143 objc_finish_implementation ();
1151 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1152 c_parser_consume_token (parser);
1155 c_parser_pragma (parser, pragma_external);
1159 if (c_dialect_objc ())
1161 c_parser_objc_method_definition (parser);
1164 /* Else fall through, and yield a syntax error trying to parse
1165 as a declaration or function definition. */
1168 /* A declaration or a function definition. We can only tell
1169 which after parsing the declaration specifiers, if any, and
1170 the first declarator. */
1171 c_parser_declaration_or_fndef (parser, true, true, false, true);
1177 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1178 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1179 accepted; otherwise (old-style parameter declarations) only other
1180 declarations are accepted. If NESTED is true, we are inside a
1181 function or parsing old-style parameter declarations; any functions
1182 encountered are nested functions and declaration specifiers are
1183 required; otherwise we are at top level and functions are normal
1184 functions and declaration specifiers may be optional. If EMPTY_OK
1185 is true, empty declarations are OK (subject to all other
1186 constraints); otherwise (old-style parameter declarations) they are
1187 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1188 may start with attributes; otherwise they may not.
1191 declaration-specifiers init-declarator-list[opt] ;
1193 function-definition:
1194 declaration-specifiers[opt] declarator declaration-list[opt]
1199 declaration-list declaration
1201 init-declarator-list:
1203 init-declarator-list , init-declarator
1206 declarator simple-asm-expr[opt] attributes[opt]
1207 declarator simple-asm-expr[opt] attributes[opt] = initializer
1211 nested-function-definition:
1212 declaration-specifiers declarator declaration-list[opt]
1215 The simple-asm-expr and attributes are GNU extensions.
1217 This function does not handle __extension__; that is handled in its
1218 callers. ??? Following the old parser, __extension__ may start
1219 external declarations, declarations in functions and declarations
1220 at the start of "for" loops, but not old-style parameter
1223 C99 requires declaration specifiers in a function definition; the
1224 absence is diagnosed through the diagnosis of implicit int. In GNU
1225 C we also allow but diagnose declarations without declaration
1226 specifiers, but only at top level (elsewhere they conflict with
1232 threadprivate-directive */
1235 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1236 bool nested, bool start_attr_ok)
1238 struct c_declspecs *specs;
1240 tree all_prefix_attrs;
1241 bool diagnosed_no_specs = false;
1243 specs = build_null_declspecs ();
1244 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1247 c_parser_skip_to_end_of_block_or_statement (parser);
1250 if (nested && !specs->declspecs_seen_p)
1252 c_parser_error (parser, "expected declaration specifiers");
1253 c_parser_skip_to_end_of_block_or_statement (parser);
1256 finish_declspecs (specs);
1257 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1263 shadow_tag_warned (specs, 1);
1264 pedwarn ("empty declaration");
1266 c_parser_consume_token (parser);
1269 pending_xref_error ();
1270 prefix_attrs = specs->attrs;
1271 all_prefix_attrs = prefix_attrs;
1272 specs->attrs = NULL_TREE;
1275 struct c_declarator *declarator;
1278 /* Declaring either one or more declarators (in which case we
1279 should diagnose if there were no declaration specifiers) or a
1280 function definition (in which case the diagnostic for
1281 implicit int suffices). */
1282 declarator = c_parser_declarator (parser, specs->type_seen_p,
1283 C_DTR_NORMAL, &dummy);
1284 if (declarator == NULL)
1286 c_parser_skip_to_end_of_block_or_statement (parser);
1289 if (c_parser_next_token_is (parser, CPP_EQ)
1290 || c_parser_next_token_is (parser, CPP_COMMA)
1291 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1292 || c_parser_next_token_is_keyword (parser, RID_ASM)
1293 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1295 tree asm_name = NULL_TREE;
1296 tree postfix_attrs = NULL_TREE;
1297 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1299 diagnosed_no_specs = true;
1300 pedwarn ("data definition has no type or storage class");
1302 /* Having seen a data definition, there cannot now be a
1303 function definition. */
1305 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1306 asm_name = c_parser_simple_asm_expr (parser);
1307 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1308 postfix_attrs = c_parser_attributes (parser);
1309 if (c_parser_next_token_is (parser, CPP_EQ))
1313 c_parser_consume_token (parser);
1314 /* The declaration of the variable is in effect while
1315 its initializer is parsed. */
1316 d = start_decl (declarator, specs, true,
1317 chainon (postfix_attrs, all_prefix_attrs));
1319 d = error_mark_node;
1320 start_init (d, asm_name, global_bindings_p ());
1321 init = c_parser_initializer (parser);
1323 if (d != error_mark_node)
1325 maybe_warn_string_init (TREE_TYPE (d), init);
1326 finish_decl (d, init.value, asm_name);
1331 tree d = start_decl (declarator, specs, false,
1332 chainon (postfix_attrs,
1335 finish_decl (d, NULL_TREE, asm_name);
1337 if (c_parser_next_token_is (parser, CPP_COMMA))
1339 c_parser_consume_token (parser);
1340 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1341 all_prefix_attrs = chainon (c_parser_attributes (parser),
1344 all_prefix_attrs = prefix_attrs;
1347 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1349 c_parser_consume_token (parser);
1354 c_parser_error (parser, "expected %<,%> or %<;%>");
1355 c_parser_skip_to_end_of_block_or_statement (parser);
1361 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1362 "%<asm%> or %<__attribute__%>");
1363 c_parser_skip_to_end_of_block_or_statement (parser);
1366 /* Function definition (nested or otherwise). */
1370 pedwarn ("ISO C forbids nested functions");
1371 push_function_context ();
1373 if (!start_function (specs, declarator, all_prefix_attrs))
1375 /* This can appear in many cases looking nothing like a
1376 function definition, so we don't give a more specific
1377 error suggesting there was one. */
1378 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1379 "or %<__attribute__%>");
1381 pop_function_context ();
1384 /* Parse old-style parameter declarations. ??? Attributes are
1385 not allowed to start declaration specifiers here because of a
1386 syntax conflict between a function declaration with attribute
1387 suffix and a function definition with an attribute prefix on
1388 first old-style parameter declaration. Following the old
1389 parser, they are not accepted on subsequent old-style
1390 parameter declarations either. However, there is no
1391 ambiguity after the first declaration, nor indeed on the
1392 first as long as we don't allow postfix attributes after a
1393 declarator with a nonempty identifier list in a definition;
1394 and postfix attributes have never been accepted here in
1395 function definitions either. */
1396 while (c_parser_next_token_is_not (parser, CPP_EOF)
1397 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1398 c_parser_declaration_or_fndef (parser, false, false, true, false);
1399 DECL_SOURCE_LOCATION (current_function_decl)
1400 = c_parser_peek_token (parser)->location;
1401 store_parm_decls ();
1402 fnbody = c_parser_compound_statement (parser);
1405 tree decl = current_function_decl;
1408 pop_function_context ();
1409 add_stmt (build_stmt (DECL_EXPR, decl));
1420 /* Parse an asm-definition (asm() outside a function body). This is a
1428 c_parser_asm_definition (c_parser *parser)
1430 tree asm_str = c_parser_simple_asm_expr (parser);
1432 cgraph_add_asm_node (asm_str);
1433 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1436 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1437 6.7), adding them to SPECS (which may already include some).
1438 Storage class specifiers are accepted iff SCSPEC_OK; type
1439 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1440 the start iff START_ATTR_OK.
1442 declaration-specifiers:
1443 storage-class-specifier declaration-specifiers[opt]
1444 type-specifier declaration-specifiers[opt]
1445 type-qualifier declaration-specifiers[opt]
1446 function-specifier declaration-specifiers[opt]
1448 Function specifiers (inline) are from C99, and are currently
1449 handled as storage class specifiers, as is __thread.
1451 C90 6.5.1, C99 6.7.1:
1452 storage-class-specifier:
1463 C90 6.5.2, C99 6.7.2:
1476 [_Imaginary removed in C99 TC2]
1477 struct-or-union-specifier
1481 (_Bool and _Complex are new in C99.)
1483 C90 6.5.3, C99 6.7.3:
1490 (restrict is new in C99.)
1494 declaration-specifiers:
1495 attributes declaration-specifiers[opt]
1497 storage-class-specifier:
1509 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1510 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1515 class-name objc-protocol-refs[opt]
1516 typedef-name objc-protocol-refs
1521 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1522 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1524 bool attrs_ok = start_attr_ok;
1525 bool seen_type = specs->type_seen_p;
1526 while (c_parser_next_token_is (parser, CPP_NAME)
1527 || c_parser_next_token_is (parser, CPP_KEYWORD)
1528 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1530 struct c_typespec t;
1532 if (c_parser_next_token_is (parser, CPP_NAME))
1534 tree value = c_parser_peek_token (parser)->value;
1535 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1536 /* This finishes the specifiers unless a type name is OK, it
1537 is declared as a type name and a type name hasn't yet
1539 if (!typespec_ok || seen_type
1540 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1542 c_parser_consume_token (parser);
1545 if (kind == C_ID_TYPENAME
1546 && (!c_dialect_objc ()
1547 || c_parser_next_token_is_not (parser, CPP_LESS)))
1549 t.kind = ctsk_typedef;
1550 /* For a typedef name, record the meaning, not the name.
1551 In case of 'foo foo, bar;'. */
1552 t.spec = lookup_name (value);
1556 tree proto = NULL_TREE;
1557 gcc_assert (c_dialect_objc ());
1559 if (c_parser_next_token_is (parser, CPP_LESS))
1560 proto = c_parser_objc_protocol_refs (parser);
1561 t.spec = objc_get_protocol_qualified_type (value, proto);
1563 declspecs_add_type (specs, t);
1566 if (c_parser_next_token_is (parser, CPP_LESS))
1568 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1569 nisse@lysator.liu.se. */
1571 gcc_assert (c_dialect_objc ());
1572 if (!typespec_ok || seen_type)
1574 proto = c_parser_objc_protocol_refs (parser);
1576 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1577 declspecs_add_type (specs, t);
1580 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1581 switch (c_parser_peek_token (parser)->keyword)
1593 /* TODO: Distinguish between function specifiers (inline)
1594 and storage class specifiers, either here or in
1595 declspecs_add_scspec. */
1596 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1597 c_parser_consume_token (parser);
1620 if (c_dialect_objc ())
1621 parser->objc_need_raw_identifier = true;
1622 t.kind = ctsk_resword;
1623 t.spec = c_parser_peek_token (parser)->value;
1624 declspecs_add_type (specs, t);
1625 c_parser_consume_token (parser);
1632 t = c_parser_enum_specifier (parser);
1633 declspecs_add_type (specs, t);
1641 t = c_parser_struct_or_union_specifier (parser);
1642 declspecs_add_type (specs, t);
1645 /* ??? The old parser rejected typeof after other type
1646 specifiers, but is a syntax error the best way of
1648 if (!typespec_ok || seen_type)
1652 t = c_parser_typeof_specifier (parser);
1653 declspecs_add_type (specs, t);
1659 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1660 c_parser_consume_token (parser);
1665 attrs = c_parser_attributes (parser);
1666 declspecs_add_attrs (specs, attrs);
1675 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1678 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1679 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1680 enum attributes[opt] identifier
1682 The form with trailing comma is new in C99. The forms with
1683 attributes are GNU extensions. In GNU C, we accept any expression
1684 without commas in the syntax (assignment expressions, not just
1685 conditional expressions); assignment expressions will be diagnosed
1690 enumerator-list , enumerator
1693 enumeration-constant
1694 enumeration-constant = constant-expression
1697 static struct c_typespec
1698 c_parser_enum_specifier (c_parser *parser)
1700 struct c_typespec ret;
1702 tree ident = NULL_TREE;
1703 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1704 c_parser_consume_token (parser);
1705 attrs = c_parser_attributes (parser);
1706 if (c_parser_next_token_is (parser, CPP_NAME))
1708 ident = c_parser_peek_token (parser)->value;
1709 c_parser_consume_token (parser);
1711 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1713 /* Parse an enum definition. */
1714 struct c_enum_contents the_enum;
1715 tree type = start_enum (&the_enum, ident);
1717 /* We chain the enumerators in reverse order, then put them in
1718 forward order at the end. */
1719 tree values = NULL_TREE;
1720 c_parser_consume_token (parser);
1727 if (c_parser_next_token_is_not (parser, CPP_NAME))
1729 c_parser_error (parser, "expected identifier");
1730 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1731 values = error_mark_node;
1734 enum_id = c_parser_peek_token (parser)->value;
1735 c_parser_consume_token (parser);
1736 if (c_parser_next_token_is (parser, CPP_EQ))
1738 c_parser_consume_token (parser);
1739 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1742 enum_value = NULL_TREE;
1743 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1744 TREE_CHAIN (enum_decl) = values;
1747 if (c_parser_next_token_is (parser, CPP_COMMA))
1750 c_parser_consume_token (parser);
1752 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1754 if (seen_comma && pedantic && !flag_isoc99)
1755 pedwarn ("comma at end of enumerator list");
1756 c_parser_consume_token (parser);
1761 c_parser_error (parser, "expected %<,%> or %<}%>");
1762 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1763 values = error_mark_node;
1767 postfix_attrs = c_parser_attributes (parser);
1768 ret.spec = finish_enum (type, nreverse (values),
1769 chainon (attrs, postfix_attrs));
1770 ret.kind = ctsk_tagdef;
1775 c_parser_error (parser, "expected %<{%>");
1776 ret.spec = error_mark_node;
1777 ret.kind = ctsk_tagref;
1780 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1781 /* In ISO C, enumerated types can be referred to only if already
1783 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1784 pedwarn ("ISO C forbids forward references to %<enum%> types");
1788 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1790 struct-or-union-specifier:
1791 struct-or-union attributes[opt] identifier[opt]
1792 { struct-contents } attributes[opt]
1793 struct-or-union attributes[opt] identifier
1796 struct-declaration-list
1798 struct-declaration-list:
1799 struct-declaration ;
1800 struct-declaration-list struct-declaration ;
1807 struct-declaration-list struct-declaration
1809 struct-declaration-list:
1810 struct-declaration-list ;
1813 (Note that in the syntax here, unlike that in ISO C, the semicolons
1814 are included here rather than in struct-declaration, in order to
1815 describe the syntax with extra semicolons and missing semicolon at
1820 struct-declaration-list:
1821 @defs ( class-name )
1823 (Note this does not include a trailing semicolon, but can be
1824 followed by further declarations, and gets a pedwarn-if-pedantic
1825 when followed by a semicolon.) */
1827 static struct c_typespec
1828 c_parser_struct_or_union_specifier (c_parser *parser)
1830 struct c_typespec ret;
1832 tree ident = NULL_TREE;
1833 enum tree_code code;
1834 switch (c_parser_peek_token (parser)->keyword)
1845 c_parser_consume_token (parser);
1846 attrs = c_parser_attributes (parser);
1847 if (c_parser_next_token_is (parser, CPP_NAME))
1849 ident = c_parser_peek_token (parser)->value;
1850 c_parser_consume_token (parser);
1852 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1854 /* Parse a struct or union definition. Start the scope of the
1855 tag before parsing components. */
1856 tree type = start_struct (code, ident);
1858 /* We chain the components in reverse order, then put them in
1859 forward order at the end. Each struct-declaration may
1860 declare multiple components (comma-separated), so we must use
1861 chainon to join them, although when parsing each
1862 struct-declaration we can use TREE_CHAIN directly.
1864 The theory behind all this is that there will be more
1865 semicolon separated fields than comma separated fields, and
1866 so we'll be minimizing the number of node traversals required
1868 tree contents = NULL_TREE;
1869 c_parser_consume_token (parser);
1870 /* Handle the Objective-C @defs construct,
1871 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1872 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1875 gcc_assert (c_dialect_objc ());
1876 c_parser_consume_token (parser);
1877 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1879 if (c_parser_next_token_is (parser, CPP_NAME)
1880 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1882 name = c_parser_peek_token (parser)->value;
1883 c_parser_consume_token (parser);
1887 c_parser_error (parser, "expected class name");
1888 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1891 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1893 contents = nreverse (objc_get_class_ivars (name));
1896 /* Parse the struct-declarations and semicolons. Problems with
1897 semicolons are diagnosed here; empty structures are diagnosed
1902 /* Parse any stray semicolon. */
1903 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1906 pedwarn ("extra semicolon in struct or union specified");
1907 c_parser_consume_token (parser);
1910 /* Stop if at the end of the struct or union contents. */
1911 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1913 c_parser_consume_token (parser);
1916 /* Accept #pragmas at struct scope. */
1917 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1919 c_parser_pragma (parser, pragma_external);
1922 /* Parse some comma-separated declarations, but not the
1923 trailing semicolon if any. */
1924 decls = c_parser_struct_declaration (parser);
1925 contents = chainon (decls, contents);
1926 /* If no semicolon follows, either we have a parse error or
1927 are at the end of the struct or union and should
1929 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1930 c_parser_consume_token (parser);
1933 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1934 pedwarn ("no semicolon at end of struct or union");
1937 c_parser_error (parser, "expected %<;%>");
1938 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1943 postfix_attrs = c_parser_attributes (parser);
1944 ret.spec = finish_struct (type, nreverse (contents),
1945 chainon (attrs, postfix_attrs));
1946 ret.kind = ctsk_tagdef;
1951 c_parser_error (parser, "expected %<{%>");
1952 ret.spec = error_mark_node;
1953 ret.kind = ctsk_tagref;
1956 ret = parser_xref_tag (code, ident);
1960 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1961 the trailing semicolon.
1964 specifier-qualifier-list struct-declarator-list
1966 specifier-qualifier-list:
1967 type-specifier specifier-qualifier-list[opt]
1968 type-qualifier specifier-qualifier-list[opt]
1969 attributes specifier-qualifier-list[opt]
1971 struct-declarator-list:
1973 struct-declarator-list , attributes[opt] struct-declarator
1976 declarator attributes[opt]
1977 declarator[opt] : constant-expression attributes[opt]
1982 __extension__ struct-declaration
1983 specifier-qualifier-list
1985 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1986 of attributes where shown is a GNU extension. In GNU C, we accept
1987 any expression without commas in the syntax (assignment
1988 expressions, not just conditional expressions); assignment
1989 expressions will be diagnosed as non-constant. */
1992 c_parser_struct_declaration (c_parser *parser)
1994 struct c_declspecs *specs;
1996 tree all_prefix_attrs;
1998 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2002 ext = disable_extension_diagnostics ();
2003 c_parser_consume_token (parser);
2004 decl = c_parser_struct_declaration (parser);
2005 restore_extension_diagnostics (ext);
2008 specs = build_null_declspecs ();
2009 c_parser_declspecs (parser, specs, false, true, true);
2012 if (!specs->declspecs_seen_p)
2014 c_parser_error (parser, "expected specifier-qualifier-list");
2017 finish_declspecs (specs);
2018 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2021 if (!specs->type_seen_p)
2024 pedwarn ("ISO C forbids member declarations with no members");
2025 shadow_tag_warned (specs, pedantic);
2030 /* Support for unnamed structs or unions as members of
2031 structs or unions (which is [a] useful and [b] supports
2034 ret = grokfield (build_id_declarator (NULL_TREE), specs,
2037 decl_attributes (&ret, attrs, 0);
2041 pending_xref_error ();
2042 prefix_attrs = specs->attrs;
2043 all_prefix_attrs = prefix_attrs;
2044 specs->attrs = NULL_TREE;
2048 /* Declaring one or more declarators or un-named bit-fields. */
2049 struct c_declarator *declarator;
2051 if (c_parser_next_token_is (parser, CPP_COLON))
2052 declarator = build_id_declarator (NULL_TREE);
2054 declarator = c_parser_declarator (parser, specs->type_seen_p,
2055 C_DTR_NORMAL, &dummy);
2056 if (declarator == NULL)
2058 c_parser_skip_to_end_of_block_or_statement (parser);
2061 if (c_parser_next_token_is (parser, CPP_COLON)
2062 || c_parser_next_token_is (parser, CPP_COMMA)
2063 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2064 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2065 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2067 tree postfix_attrs = NULL_TREE;
2068 tree width = NULL_TREE;
2070 if (c_parser_next_token_is (parser, CPP_COLON))
2072 c_parser_consume_token (parser);
2073 width = c_parser_expr_no_commas (parser, NULL).value;
2075 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2076 postfix_attrs = c_parser_attributes (parser);
2077 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2078 decl_attributes (&d, chainon (postfix_attrs,
2079 all_prefix_attrs), 0);
2080 TREE_CHAIN (d) = decls;
2082 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2083 all_prefix_attrs = chainon (c_parser_attributes (parser),
2086 all_prefix_attrs = prefix_attrs;
2087 if (c_parser_next_token_is (parser, CPP_COMMA))
2088 c_parser_consume_token (parser);
2089 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2090 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2092 /* Semicolon consumed in caller. */
2097 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2103 c_parser_error (parser,
2104 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2105 "%<__attribute__%>");
2112 /* Parse a typeof specifier (a GNU extension).
2115 typeof ( expression )
2116 typeof ( type-name )
2119 static struct c_typespec
2120 c_parser_typeof_specifier (c_parser *parser)
2122 struct c_typespec ret;
2123 ret.kind = ctsk_typeof;
2124 ret.spec = error_mark_node;
2125 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2126 c_parser_consume_token (parser);
2129 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2135 if (c_parser_next_token_starts_typename (parser))
2137 struct c_type_name *type = c_parser_type_name (parser);
2142 ret.spec = groktypename (type);
2143 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2149 struct c_expr expr = c_parser_expression (parser);
2152 if (TREE_CODE (expr.value) == COMPONENT_REF
2153 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2154 error ("%<typeof%> applied to a bit-field");
2155 ret.spec = TREE_TYPE (expr.value);
2156 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2157 /* This should be returned with the type so that when the type
2158 is evaluated, this can be evaluated. For now, we avoid
2159 evaluation when the context might. */
2160 if (!skip_evaluation && was_vm)
2162 tree e = expr.value;
2164 /* If the expression is not of a type to which we cannot assign a line
2165 number, wrap the thing in a no-op NOP_EXPR. */
2166 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2167 e = build1 (NOP_EXPR, void_type_node, e);
2169 if (CAN_HAVE_LOCATION_P (e))
2170 SET_EXPR_LOCATION (e, input_location);
2174 pop_maybe_used (was_vm);
2176 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2180 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2181 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2182 be redeclared; otherwise it may not. KIND indicates which kind of
2183 declarator is wanted. Returns a valid declarator except in the
2184 case of a syntax error in which case NULL is returned. *SEEN_ID is
2185 set to true if an identifier being declared is seen; this is used
2186 to diagnose bad forms of abstract array declarators and to
2187 determine whether an identifier list is syntactically permitted.
2190 pointer[opt] direct-declarator
2194 ( attributes[opt] declarator )
2195 direct-declarator array-declarator
2196 direct-declarator ( parameter-type-list )
2197 direct-declarator ( identifier-list[opt] )
2200 * type-qualifier-list[opt]
2201 * type-qualifier-list[opt] pointer
2203 type-qualifier-list:
2206 type-qualifier-list type-qualifier
2207 type-qualifier-list attributes
2209 parameter-type-list:
2211 parameter-list , ...
2214 parameter-declaration
2215 parameter-list , parameter-declaration
2217 parameter-declaration:
2218 declaration-specifiers declarator attributes[opt]
2219 declaration-specifiers abstract-declarator[opt] attributes[opt]
2223 identifier-list , identifier
2225 abstract-declarator:
2227 pointer[opt] direct-abstract-declarator
2229 direct-abstract-declarator:
2230 ( attributes[opt] abstract-declarator )
2231 direct-abstract-declarator[opt] array-declarator
2232 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2237 direct-declarator ( parameter-forward-declarations
2238 parameter-type-list[opt] )
2240 direct-abstract-declarator:
2241 direct-abstract-declarator[opt] ( parameter-forward-declarations
2242 parameter-type-list[opt] )
2244 parameter-forward-declarations:
2246 parameter-forward-declarations parameter-list ;
2248 The uses of attributes shown above are GNU extensions.
2250 Some forms of array declarator are not included in C99 in the
2251 syntax for abstract declarators; these are disallowed elsewhere.
2252 This may be a defect (DR#289).
2254 This function also accepts an omitted abstract declarator as being
2255 an abstract declarator, although not part of the formal syntax. */
2257 static struct c_declarator *
2258 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2261 /* Parse any initial pointer part. */
2262 if (c_parser_next_token_is (parser, CPP_MULT))
2264 struct c_declspecs *quals_attrs = build_null_declspecs ();
2265 struct c_declarator *inner;
2266 c_parser_consume_token (parser);
2267 c_parser_declspecs (parser, quals_attrs, false, false, true);
2268 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2272 return make_pointer_declarator (quals_attrs, inner);
2274 /* Now we have a direct declarator, direct abstract declarator or
2275 nothing (which counts as a direct abstract declarator here). */
2276 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2279 /* Parse a direct declarator or direct abstract declarator; arguments
2280 as c_parser_declarator. */
2282 static struct c_declarator *
2283 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2286 /* The direct declarator must start with an identifier (possibly
2287 omitted) or a parenthesized declarator (possibly abstract). In
2288 an ordinary declarator, initial parentheses must start a
2289 parenthesized declarator. In an abstract declarator or parameter
2290 declarator, they could start a parenthesized declarator or a
2291 parameter list. To tell which, the open parenthesis and any
2292 following attributes must be read. If a declaration specifier
2293 follows, then it is a parameter list; if the specifier is a
2294 typedef name, there might be an ambiguity about redeclaring it,
2295 which is resolved in the direction of treating it as a typedef
2296 name. If a close parenthesis follows, it is also an empty
2297 parameter list, as the syntax does not permit empty abstract
2298 declarators. Otherwise, it is a parenthesized declarator (in
2299 which case the analysis may be repeated inside it, recursively).
2301 ??? There is an ambiguity in a parameter declaration "int
2302 (__attribute__((foo)) x)", where x is not a typedef name: it
2303 could be an abstract declarator for a function, or declare x with
2304 parentheses. The proper resolution of this ambiguity needs
2305 documenting. At present we follow an accident of the old
2306 parser's implementation, whereby the first parameter must have
2307 some declaration specifiers other than just attributes. Thus as
2308 a parameter declaration it is treated as a parenthesized
2309 parameter named x, and as an abstract declarator it is
2312 ??? Also following the old parser, attributes inside an empty
2313 parameter list are ignored, making it a list not yielding a
2314 prototype, rather than giving an error or making it have one
2315 parameter with implicit type int.
2317 ??? Also following the old parser, typedef names may be
2318 redeclared in declarators, but not Objective-C class names. */
2320 if (kind != C_DTR_ABSTRACT
2321 && c_parser_next_token_is (parser, CPP_NAME)
2323 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2324 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2326 struct c_declarator *inner
2327 = build_id_declarator (c_parser_peek_token (parser)->value);
2329 inner->id_loc = c_parser_peek_token (parser)->location;
2330 c_parser_consume_token (parser);
2331 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2334 if (kind != C_DTR_NORMAL
2335 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2337 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2338 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2341 /* Either we are at the end of an abstract declarator, or we have
2344 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2347 struct c_declarator *inner;
2348 c_parser_consume_token (parser);
2349 attrs = c_parser_attributes (parser);
2350 if (kind != C_DTR_NORMAL
2351 && (c_parser_next_token_starts_declspecs (parser)
2352 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2354 struct c_arg_info *args
2355 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2362 = build_function_declarator (args,
2363 build_id_declarator (NULL_TREE));
2364 return c_parser_direct_declarator_inner (parser, *seen_id,
2368 /* A parenthesized declarator. */
2369 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2370 if (inner != NULL && attrs != NULL)
2371 inner = build_attrs_declarator (attrs, inner);
2372 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2374 c_parser_consume_token (parser);
2378 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2382 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2389 if (kind == C_DTR_NORMAL)
2391 c_parser_error (parser, "expected identifier or %<(%>");
2395 return build_id_declarator (NULL_TREE);
2399 /* Parse part of a direct declarator or direct abstract declarator,
2400 given that some (in INNER) has already been parsed; ID_PRESENT is
2401 true if an identifier is present, false for an abstract
2404 static struct c_declarator *
2405 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2406 struct c_declarator *inner)
2408 /* Parse a sequence of array declarators and parameter lists. */
2409 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2411 struct c_declarator *declarator;
2412 struct c_declspecs *quals_attrs = build_null_declspecs ();
2416 c_parser_consume_token (parser);
2417 c_parser_declspecs (parser, quals_attrs, false, false, true);
2418 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2420 c_parser_consume_token (parser);
2421 if (static_seen && !quals_attrs->declspecs_seen_p)
2422 c_parser_declspecs (parser, quals_attrs, false, false, true);
2423 if (!quals_attrs->declspecs_seen_p)
2425 /* If "static" is present, there must be an array dimension.
2426 Otherwise, there may be a dimension, "*", or no
2431 dimen = c_parser_expr_no_commas (parser, NULL).value;
2435 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2440 else if (c_parser_next_token_is (parser, CPP_MULT))
2442 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2446 c_parser_consume_token (parser);
2451 dimen = c_parser_expr_no_commas (parser, NULL).value;
2457 dimen = c_parser_expr_no_commas (parser, NULL).value;
2460 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2461 c_parser_consume_token (parser);
2464 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2468 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2470 if (declarator == NULL)
2472 inner = set_array_declarator_inner (declarator, inner, !id_present);
2473 return c_parser_direct_declarator_inner (parser, id_present, inner);
2475 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2478 struct c_arg_info *args;
2479 c_parser_consume_token (parser);
2480 attrs = c_parser_attributes (parser);
2481 args = c_parser_parms_declarator (parser, id_present, attrs);
2486 inner = build_function_declarator (args, inner);
2487 return c_parser_direct_declarator_inner (parser, id_present, inner);
2493 /* Parse a parameter list or identifier list, including the closing
2494 parenthesis but not the opening one. ATTRS are the attributes at
2495 the start of the list. ID_LIST_OK is true if an identifier list is
2496 acceptable; such a list must not have attributes at the start. */
2498 static struct c_arg_info *
2499 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2502 declare_parm_level ();
2503 /* If the list starts with an identifier, it is an identifier list.
2504 Otherwise, it is either a prototype list or an empty list. */
2507 && c_parser_next_token_is (parser, CPP_NAME)
2508 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2510 tree list = NULL_TREE, *nextp = &list;
2511 while (c_parser_next_token_is (parser, CPP_NAME)
2512 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2514 *nextp = build_tree_list (NULL_TREE,
2515 c_parser_peek_token (parser)->value);
2516 nextp = & TREE_CHAIN (*nextp);
2517 c_parser_consume_token (parser);
2518 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2520 c_parser_consume_token (parser);
2521 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2523 c_parser_error (parser, "expected identifier");
2527 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2529 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2534 ret->pending_sizes = 0;
2535 ret->had_vla_unspec = 0;
2536 c_parser_consume_token (parser);
2542 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2550 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2556 /* Parse a parameter list (possibly empty), including the closing
2557 parenthesis but not the opening one. ATTRS are the attributes at
2558 the start of the list. */
2560 static struct c_arg_info *
2561 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2563 bool good_parm = false;
2564 /* ??? Following the old parser, forward parameter declarations may
2565 use abstract declarators, and if no real parameter declarations
2566 follow the forward declarations then this is not diagnosed. Also
2567 note as above that attributes are ignored as the only contents of
2568 the parentheses, or as the only contents after forward
2570 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2572 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2577 ret->pending_sizes = 0;
2578 ret->had_vla_unspec = 0;
2579 c_parser_consume_token (parser);
2582 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2584 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2588 ret->pending_sizes = 0;
2589 ret->had_vla_unspec = 0;
2590 /* Suppress -Wold-style-definition for this case. */
2591 ret->types = error_mark_node;
2592 error ("ISO C requires a named argument before %<...%>");
2593 c_parser_consume_token (parser);
2594 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2596 c_parser_consume_token (parser);
2601 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2606 /* Nonempty list of parameters, either terminated with semicolon
2607 (forward declarations; recurse) or with close parenthesis (normal
2608 function) or with ", ... )" (variadic function). */
2611 /* Parse a parameter. */
2612 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2617 push_parm_decl (parm);
2619 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2622 c_parser_consume_token (parser);
2623 mark_forward_parm_decls ();
2624 new_attrs = c_parser_attributes (parser);
2625 return c_parser_parms_list_declarator (parser, new_attrs);
2627 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2629 c_parser_consume_token (parser);
2631 return get_parm_info (false);
2634 struct c_arg_info *ret
2635 = XOBNEW (&parser_obstack, struct c_arg_info);
2640 ret->pending_sizes = 0;
2641 ret->had_vla_unspec = 0;
2645 if (!c_parser_require (parser, CPP_COMMA,
2646 "expected %<;%>, %<,%> or %<)%>"))
2648 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2651 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2653 c_parser_consume_token (parser);
2654 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2656 c_parser_consume_token (parser);
2658 return get_parm_info (true);
2661 struct c_arg_info *ret
2662 = XOBNEW (&parser_obstack, struct c_arg_info);
2667 ret->pending_sizes = 0;
2668 ret->had_vla_unspec = 0;
2674 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2682 /* Parse a parameter declaration. ATTRS are the attributes at the
2683 start of the declaration if it is the first parameter. */
2685 static struct c_parm *
2686 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2688 struct c_declspecs *specs;
2689 struct c_declarator *declarator;
2691 tree postfix_attrs = NULL_TREE;
2693 if (!c_parser_next_token_starts_declspecs (parser))
2695 /* ??? In some Objective-C cases '...' isn't applicable so there
2696 should be a different message. */
2697 c_parser_error (parser,
2698 "expected declaration specifiers or %<...%>");
2699 c_parser_skip_to_end_of_parameter (parser);
2702 specs = build_null_declspecs ();
2705 declspecs_add_attrs (specs, attrs);
2708 c_parser_declspecs (parser, specs, true, true, true);
2709 finish_declspecs (specs);
2710 pending_xref_error ();
2711 prefix_attrs = specs->attrs;
2712 specs->attrs = NULL_TREE;
2713 declarator = c_parser_declarator (parser, specs->type_seen_p,
2714 C_DTR_PARM, &dummy);
2715 if (declarator == NULL)
2717 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2720 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2721 postfix_attrs = c_parser_attributes (parser);
2722 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2726 /* Parse a string literal in an asm expression. It should not be
2727 translated, and wide string literals are an error although
2728 permitted by the syntax. This is a GNU extension.
2733 ??? At present, following the old parser, the caller needs to have
2734 set c_lex_string_translate to 0. It would be better to follow the
2735 C++ parser rather than using the c_lex_string_translate kludge. */
2738 c_parser_asm_string_literal (c_parser *parser)
2741 if (c_parser_next_token_is (parser, CPP_STRING))
2743 str = c_parser_peek_token (parser)->value;
2744 c_parser_consume_token (parser);
2746 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2748 error ("wide string literal in %<asm%>");
2749 str = build_string (1, "");
2750 c_parser_consume_token (parser);
2754 c_parser_error (parser, "expected string literal");
2760 /* Parse a simple asm expression. This is used in restricted
2761 contexts, where a full expression with inputs and outputs does not
2762 make sense. This is a GNU extension.
2765 asm ( asm-string-literal )
2769 c_parser_simple_asm_expr (c_parser *parser)
2772 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2773 /* ??? Follow the C++ parser rather than using the
2774 c_lex_string_translate kludge. */
2775 c_lex_string_translate = 0;
2776 c_parser_consume_token (parser);
2777 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2779 c_lex_string_translate = 1;
2782 str = c_parser_asm_string_literal (parser);
2783 c_lex_string_translate = 1;
2784 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2786 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2792 /* Parse (possibly empty) attributes. This is a GNU extension.
2796 attributes attribute
2799 __attribute__ ( ( attribute-list ) )
2803 attribute_list , attrib
2808 any-word ( identifier )
2809 any-word ( identifier , nonempty-expr-list )
2810 any-word ( expr-list )
2812 where the "identifier" must not be declared as a type, and
2813 "any-word" may be any identifier (including one declared as a
2814 type), a reserved word storage class specifier, type specifier or
2815 type qualifier. ??? This still leaves out most reserved keywords
2816 (following the old parser), shouldn't we include them, and why not
2817 allow identifiers declared as types to start the arguments? */
2820 c_parser_attributes (c_parser *parser)
2822 tree attrs = NULL_TREE;
2823 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2825 /* ??? Follow the C++ parser rather than using the
2826 c_lex_string_translate kludge. */
2827 c_lex_string_translate = 0;
2828 c_parser_consume_token (parser);
2829 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2831 c_lex_string_translate = 1;
2834 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2836 c_lex_string_translate = 1;
2837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2840 /* Parse the attribute list. */
2841 while (c_parser_next_token_is (parser, CPP_COMMA)
2842 || c_parser_next_token_is (parser, CPP_NAME)
2843 || c_parser_next_token_is (parser, CPP_KEYWORD))
2845 tree attr, attr_name, attr_args;
2846 if (c_parser_next_token_is (parser, CPP_COMMA))
2848 c_parser_consume_token (parser);
2851 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2853 /* ??? See comment above about what keywords are
2856 switch (c_parser_peek_token (parser)->keyword)
2894 attr_name = c_parser_peek_token (parser)->value;
2895 c_parser_consume_token (parser);
2896 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2898 attr = build_tree_list (attr_name, NULL_TREE);
2899 attrs = chainon (attrs, attr);
2902 c_parser_consume_token (parser);
2903 /* Parse the attribute contents. If they start with an
2904 identifier which is followed by a comma or close
2905 parenthesis, then the arguments start with that
2906 identifier; otherwise they are an expression list. */
2907 if (c_parser_next_token_is (parser, CPP_NAME)
2908 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2909 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2910 || (c_parser_peek_2nd_token (parser)->type
2911 == CPP_CLOSE_PAREN)))
2913 tree arg1 = c_parser_peek_token (parser)->value;
2914 c_parser_consume_token (parser);
2915 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2916 attr_args = build_tree_list (NULL_TREE, arg1);
2919 c_parser_consume_token (parser);
2920 attr_args = tree_cons (NULL_TREE, arg1,
2921 c_parser_expr_list (parser, false));
2926 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2927 attr_args = NULL_TREE;
2929 attr_args = c_parser_expr_list (parser, false);
2931 attr = build_tree_list (attr_name, attr_args);
2932 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2933 c_parser_consume_token (parser);
2936 c_lex_string_translate = 1;
2937 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2941 attrs = chainon (attrs, attr);
2943 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2944 c_parser_consume_token (parser);
2947 c_lex_string_translate = 1;
2948 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2952 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2953 c_parser_consume_token (parser);
2956 c_lex_string_translate = 1;
2957 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2961 c_lex_string_translate = 1;
2966 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2969 specifier-qualifier-list abstract-declarator[opt]
2972 static struct c_type_name *
2973 c_parser_type_name (c_parser *parser)
2975 struct c_declspecs *specs = build_null_declspecs ();
2976 struct c_declarator *declarator;
2977 struct c_type_name *ret;
2979 c_parser_declspecs (parser, specs, false, true, true);
2980 if (!specs->declspecs_seen_p)
2982 c_parser_error (parser, "expected specifier-qualifier-list");
2985 pending_xref_error ();
2986 finish_declspecs (specs);
2987 declarator = c_parser_declarator (parser, specs->type_seen_p,
2988 C_DTR_ABSTRACT, &dummy);
2989 if (declarator == NULL)
2991 ret = XOBNEW (&parser_obstack, struct c_type_name);
2993 ret->declarator = declarator;
2997 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3000 assignment-expression
3001 { initializer-list }
3002 { initializer-list , }
3005 designation[opt] initializer
3006 initializer-list , designation[opt] initializer
3013 designator-list designator
3020 [ constant-expression ]
3032 [ constant-expression ... constant-expression ]
3034 Any expression without commas is accepted in the syntax for the
3035 constant-expressions, with non-constant expressions rejected later.
3037 This function is only used for top-level initializers; for nested
3038 ones, see c_parser_initval. */
3040 static struct c_expr
3041 c_parser_initializer (c_parser *parser)
3043 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3044 return c_parser_braced_init (parser, NULL_TREE, false);
3048 ret = c_parser_expr_no_commas (parser, NULL);
3049 if (TREE_CODE (ret.value) != STRING_CST
3050 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3051 ret = default_function_array_conversion (ret);
3056 /* Parse a braced initializer list. TYPE is the type specified for a
3057 compound literal, and NULL_TREE for other initializers and for
3058 nested braced lists. NESTED_P is true for nested braced lists,
3059 false for the list of a compound literal or the list that is the
3060 top-level initializer in a declaration. */
3062 static struct c_expr
3063 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3065 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3066 c_parser_consume_token (parser);
3068 push_init_level (0);
3070 really_start_incremental_init (type);
3071 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3074 pedwarn ("ISO C forbids empty initializer braces");
3078 /* Parse a non-empty initializer list, possibly with a trailing
3082 c_parser_initelt (parser);
3085 if (c_parser_next_token_is (parser, CPP_COMMA))
3086 c_parser_consume_token (parser);
3089 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3093 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3096 ret.value = error_mark_node;
3097 ret.original_code = ERROR_MARK;
3098 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3101 c_parser_consume_token (parser);
3102 return pop_init_level (0);
3105 /* Parse a nested initializer, including designators. */
3108 c_parser_initelt (c_parser *parser)
3110 /* Parse any designator or designator list. A single array
3111 designator may have the subsequent "=" omitted in GNU C, but a
3112 longer list or a structure member designator may not. */
3113 if (c_parser_next_token_is (parser, CPP_NAME)
3114 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3116 /* Old-style structure member designator. */
3117 set_init_label (c_parser_peek_token (parser)->value);
3119 pedwarn ("obsolete use of designated initializer with %<:%>");
3120 c_parser_consume_token (parser);
3121 c_parser_consume_token (parser);
3125 /* des_seen is 0 if there have been no designators, 1 if there
3126 has been a single array designator and 2 otherwise. */
3128 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3129 || c_parser_next_token_is (parser, CPP_DOT))
3131 int des_prev = des_seen;
3134 if (c_parser_next_token_is (parser, CPP_DOT))
3137 c_parser_consume_token (parser);
3138 if (c_parser_next_token_is (parser, CPP_NAME))
3140 set_init_label (c_parser_peek_token (parser)->value);
3141 c_parser_consume_token (parser);
3146 init.value = error_mark_node;
3147 init.original_code = ERROR_MARK;
3148 c_parser_error (parser, "expected identifier");
3149 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3150 process_init_element (init);
3157 /* ??? Following the old parser, [ objc-receiver
3158 objc-message-args ] is accepted as an initializer,
3159 being distinguished from a designator by what follows
3160 the first assignment expression inside the square
3161 brackets, but after a first array designator a
3162 subsequent square bracket is for Objective-C taken to
3163 start an expression, using the obsolete form of
3164 designated initializer without '=', rather than
3165 possibly being a second level of designation: in LALR
3166 terms, the '[' is shifted rather than reducing
3167 designator to designator-list. */
3168 if (des_prev == 1 && c_dialect_objc ())
3170 des_seen = des_prev;
3173 if (des_prev == 0 && c_dialect_objc ())
3175 /* This might be an array designator or an
3176 Objective-C message expression. If the former,
3177 continue parsing here; if the latter, parse the
3178 remainder of the initializer given the starting
3179 primary-expression. ??? It might make sense to
3180 distinguish when des_prev == 1 as well; see
3181 previous comment. */
3183 struct c_expr mexpr;
3184 c_parser_consume_token (parser);
3185 if (c_parser_peek_token (parser)->type == CPP_NAME
3186 && ((c_parser_peek_token (parser)->id_kind
3188 || (c_parser_peek_token (parser)->id_kind
3189 == C_ID_CLASSNAME)))
3191 /* Type name receiver. */
3192 tree id = c_parser_peek_token (parser)->value;
3193 c_parser_consume_token (parser);
3194 rec = objc_get_class_reference (id);
3195 goto parse_message_args;
3197 first = c_parser_expr_no_commas (parser, NULL).value;
3198 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3199 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3200 goto array_desig_after_first;
3201 /* Expression receiver. So far only one part
3202 without commas has been parsed; there might be
3203 more of the expression. */
3205 while (c_parser_next_token_is (parser, CPP_COMMA))
3208 c_parser_consume_token (parser);
3209 next = c_parser_expr_no_commas (parser, NULL);
3210 next = default_function_array_conversion (next);
3211 rec = build_compound_expr (rec, next.value);
3214 /* Now parse the objc-message-args. */
3215 args = c_parser_objc_message_args (parser);
3216 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3219 = objc_build_message_expr (build_tree_list (rec, args));
3220 mexpr.original_code = ERROR_MARK;
3221 /* Now parse and process the remainder of the
3222 initializer, starting with this message
3223 expression as a primary-expression. */
3224 c_parser_initval (parser, &mexpr);
3227 c_parser_consume_token (parser);
3228 first = c_parser_expr_no_commas (parser, NULL).value;
3229 array_desig_after_first:
3230 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3232 c_parser_consume_token (parser);
3233 second = c_parser_expr_no_commas (parser, NULL).value;
3237 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3239 c_parser_consume_token (parser);
3240 set_init_index (first, second);
3241 if (pedantic && second)
3242 pedwarn ("ISO C forbids specifying range of "
3243 "elements to initialize");
3246 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3252 if (c_parser_next_token_is (parser, CPP_EQ))
3254 if (pedantic && !flag_isoc99)
3255 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3256 c_parser_consume_token (parser);
3263 pedwarn ("obsolete use of designated initializer "
3269 init.value = error_mark_node;
3270 init.original_code = ERROR_MARK;
3271 c_parser_error (parser, "expected %<=%>");
3272 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3273 process_init_element (init);
3279 c_parser_initval (parser, NULL);
3282 /* Parse a nested initializer; as c_parser_initializer but parses
3283 initializers within braced lists, after any designators have been
3284 applied. If AFTER is not NULL then it is an Objective-C message
3285 expression which is the primary-expression starting the
3289 c_parser_initval (c_parser *parser, struct c_expr *after)
3292 gcc_assert (!after || c_dialect_objc ());
3293 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3294 init = c_parser_braced_init (parser, NULL_TREE, true);
3297 init = c_parser_expr_no_commas (parser, after);
3298 if (init.value != NULL_TREE
3299 && TREE_CODE (init.value) != STRING_CST
3300 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3301 init = default_function_array_conversion (init);
3303 process_init_element (init);
3306 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3310 { block-item-list[opt] }
3311 { label-declarations block-item-list }
3315 block-item-list block-item
3327 { label-declarations block-item-list }
3330 __extension__ nested-declaration
3331 nested-function-definition
3335 label-declarations label-declaration
3338 __label__ identifier-list ;
3340 Allowing the mixing of declarations and code is new in C99. The
3341 GNU syntax also permits (not shown above) labels at the end of
3342 compound statements, which yield an error. We don't allow labels
3343 on declarations; this might seem like a natural extension, but
3344 there would be a conflict between attributes on the label and
3345 prefix attributes on the declaration. ??? The syntax follows the
3346 old parser in requiring something after label declarations.
3347 Although they are erroneous if the labels declared aren't defined,
3348 is it useful for the syntax to be this way?
3360 c_parser_compound_statement (c_parser *parser)
3363 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3364 return error_mark_node;
3365 stmt = c_begin_compound_stmt (true);
3366 c_parser_compound_statement_nostart (parser);
3367 return c_end_compound_stmt (stmt, true);
3370 /* Parse a compound statement except for the opening brace. This is
3371 used for parsing both compound statements and statement expressions
3372 (which follow different paths to handling the opening). */
3375 c_parser_compound_statement_nostart (c_parser *parser)
3377 bool last_stmt = false;
3378 bool last_label = false;
3379 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3381 c_parser_consume_token (parser);
3384 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3386 /* Read zero or more forward-declarations for labels that nested
3387 functions can jump to. */
3388 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3390 c_parser_consume_token (parser);
3391 /* Any identifiers, including those declared as type names,
3396 if (c_parser_next_token_is_not (parser, CPP_NAME))
3398 c_parser_error (parser, "expected identifier");
3402 = declare_label (c_parser_peek_token (parser)->value);
3403 C_DECLARED_LABEL_FLAG (label) = 1;
3404 add_stmt (build_stmt (DECL_EXPR, label));
3405 c_parser_consume_token (parser);
3406 if (c_parser_next_token_is (parser, CPP_COMMA))
3407 c_parser_consume_token (parser);
3411 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3413 /* ??? Locating this diagnostic on the token after the
3414 declarations end follows the old parser, but it might be
3415 better to locate it where the declarations start instead. */
3417 pedwarn ("ISO C forbids label declarations");
3419 /* We must now have at least one statement, label or declaration. */
3420 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3422 c_parser_error (parser, "expected declaration or statement");
3423 c_parser_consume_token (parser);
3426 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3428 location_t loc = c_parser_peek_token (parser)->location;
3429 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3430 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3431 || (c_parser_next_token_is (parser, CPP_NAME)
3432 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3436 c_parser_label (parser);
3438 else if (!last_label
3439 && c_parser_next_token_starts_declspecs (parser))
3442 c_parser_declaration_or_fndef (parser, true, true, true, true);
3444 && ((pedantic && !flag_isoc99)
3445 || warn_declaration_after_statement))
3446 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3450 else if (!last_label
3451 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3453 /* __extension__ can start a declaration, but is also an
3454 unary operator that can start an expression. Consume all
3455 but the last of a possible series of __extension__ to
3457 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3458 && (c_parser_peek_2nd_token (parser)->keyword
3460 c_parser_consume_token (parser);
3461 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3464 ext = disable_extension_diagnostics ();
3465 c_parser_consume_token (parser);
3467 c_parser_declaration_or_fndef (parser, true, true, true, true);
3468 /* Following the old parser, __extension__ does not
3469 disable this diagnostic. */
3470 restore_extension_diagnostics (ext);
3472 && ((pedantic && !flag_isoc99)
3473 || warn_declaration_after_statement))
3474 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3481 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3483 /* External pragmas, and some omp pragmas, are not associated
3484 with regular c code, and so are not to be considered statements
3485 syntactically. This ensures that the user doesn't put them
3486 places that would turn into syntax errors if the directive
3488 if (c_parser_pragma (parser, pragma_compound))
3489 last_label = false, last_stmt = true;
3491 else if (c_parser_next_token_is (parser, CPP_EOF))
3493 c_parser_error (parser, "expected declaration or statement");
3501 c_parser_statement_after_labels (parser);
3504 parser->error = false;
3507 error ("label at end of compound statement");
3508 c_parser_consume_token (parser);
3511 /* Parse a label (C90 6.6.1, C99 6.8.1).
3514 identifier : attributes[opt]
3515 case constant-expression :
3521 case constant-expression ... constant-expression :
3523 The use of attributes on labels is a GNU extension. The syntax in
3524 GNU C accepts any expressions without commas, non-constant
3525 expressions being rejected later. */
3528 c_parser_label (c_parser *parser)
3530 location_t loc1 = c_parser_peek_token (parser)->location;
3531 tree label = NULL_TREE;
3532 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3535 c_parser_consume_token (parser);
3536 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3537 if (c_parser_next_token_is (parser, CPP_COLON))
3539 c_parser_consume_token (parser);
3540 label = do_case (exp1, NULL_TREE);
3542 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3544 c_parser_consume_token (parser);
3545 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3546 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3547 label = do_case (exp1, exp2);
3550 c_parser_error (parser, "expected %<:%> or %<...%>");
3552 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3554 c_parser_consume_token (parser);
3555 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3556 label = do_case (NULL_TREE, NULL_TREE);
3560 tree name = c_parser_peek_token (parser)->value;
3564 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3565 c_parser_consume_token (parser);
3566 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3567 loc2 = c_parser_peek_token (parser)->location;
3568 c_parser_consume_token (parser);
3569 attrs = c_parser_attributes (parser);
3570 tlab = define_label (loc2, name);
3573 decl_attributes (&tlab, attrs, 0);
3574 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3578 SET_EXPR_LOCATION (label, loc1);
3581 /* Parse a statement (C90 6.6, C99 6.8).
3586 expression-statement
3594 expression-statement:
3597 selection-statement:
3601 iteration-statement:
3610 return expression[opt] ;
3623 objc-throw-statement
3624 objc-try-catch-statement
3625 objc-synchronized-statement
3627 objc-throw-statement:
3641 parallel-for-construct
3642 parallel-sections-construct
3649 parallel-directive structured-block
3652 for-directive iteration-statement
3655 sections-directive section-scope
3658 single-directive structured-block
3660 parallel-for-construct:
3661 parallel-for-directive iteration-statement
3663 parallel-sections-construct:
3664 parallel-sections-directive section-scope
3667 master-directive structured-block
3670 critical-directive structured-block
3673 atomic-directive expression-statement
3676 ordered-directive structured-block */
3679 c_parser_statement (c_parser *parser)
3681 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3682 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3683 || (c_parser_next_token_is (parser, CPP_NAME)
3684 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3685 c_parser_label (parser);
3686 c_parser_statement_after_labels (parser);
3689 /* Parse a statement, other than a labeled statement. */
3692 c_parser_statement_after_labels (c_parser *parser)
3694 location_t loc = c_parser_peek_token (parser)->location;
3695 tree stmt = NULL_TREE;
3696 switch (c_parser_peek_token (parser)->type)
3698 case CPP_OPEN_BRACE:
3699 add_stmt (c_parser_compound_statement (parser));
3702 switch (c_parser_peek_token (parser)->keyword)
3705 c_parser_if_statement (parser);
3708 c_parser_switch_statement (parser);
3711 c_parser_while_statement (parser);
3714 c_parser_do_statement (parser);
3717 c_parser_for_statement (parser);
3720 c_parser_consume_token (parser);
3721 if (c_parser_next_token_is (parser, CPP_NAME))
3723 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3724 c_parser_consume_token (parser);
3726 else if (c_parser_next_token_is (parser, CPP_MULT))
3728 c_parser_consume_token (parser);
3729 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3732 c_parser_error (parser, "expected identifier or %<*%>");
3733 goto expect_semicolon;
3735 c_parser_consume_token (parser);
3736 stmt = c_finish_bc_stmt (&c_cont_label, false);
3737 goto expect_semicolon;
3739 c_parser_consume_token (parser);
3740 stmt = c_finish_bc_stmt (&c_break_label, true);
3741 goto expect_semicolon;
3743 c_parser_consume_token (parser);
3744 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3746 stmt = c_finish_return (NULL_TREE);
3747 c_parser_consume_token (parser);
3751 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3752 goto expect_semicolon;
3756 stmt = c_parser_asm_statement (parser);
3759 gcc_assert (c_dialect_objc ());
3760 c_parser_consume_token (parser);
3761 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3763 stmt = objc_build_throw_stmt (NULL_TREE);
3764 c_parser_consume_token (parser);
3769 = objc_build_throw_stmt (c_parser_expression (parser).value);
3770 goto expect_semicolon;
3774 gcc_assert (c_dialect_objc ());
3775 c_parser_objc_try_catch_statement (parser);
3777 case RID_AT_SYNCHRONIZED:
3778 gcc_assert (c_dialect_objc ());
3779 c_parser_objc_synchronized_statement (parser);
3786 c_parser_consume_token (parser);
3788 case CPP_CLOSE_PAREN:
3789 case CPP_CLOSE_SQUARE:
3790 /* Avoid infinite loop in error recovery:
3791 c_parser_skip_until_found stops at a closing nesting
3792 delimiter without consuming it, but here we need to consume
3793 it to proceed further. */
3794 c_parser_error (parser, "expected statement");
3795 c_parser_consume_token (parser);
3798 c_parser_pragma (parser, pragma_stmt);
3802 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3804 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3807 /* Two cases cannot and do not have line numbers associated: If stmt
3808 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3809 cannot hold line numbers. But that's OK because the statement
3810 will either be changed to a MODIFY_EXPR during gimplification of
3811 the statement expr, or discarded. If stmt was compound, but
3812 without new variables, we will have skipped the creation of a
3813 BIND and will have a bare STATEMENT_LIST. But that's OK because
3814 (recursively) all of the component statements should already have
3815 line numbers assigned. ??? Can we discard no-op statements
3817 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3818 SET_EXPR_LOCATION (stmt, loc);
3821 /* Parse a parenthesized condition from an if, do or while statement.
3827 c_parser_paren_condition (c_parser *parser)
3831 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3832 return error_mark_node;
3833 loc = c_parser_peek_token (parser)->location;
3834 cond = c_objc_common_truthvalue_conversion
3835 (c_parser_expression_conv (parser).value);
3836 if (CAN_HAVE_LOCATION_P (cond))
3837 SET_EXPR_LOCATION (cond, loc);
3838 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3842 /* Parse a statement which is a block in C99. */
3845 c_parser_c99_block_statement (c_parser *parser)
3847 tree block = c_begin_compound_stmt (flag_isoc99);
3848 c_parser_statement (parser);
3849 return c_end_compound_stmt (block, flag_isoc99);
3852 /* Parse the body of an if statement or the else half thereof. This
3853 is just parsing a statement but (a) it is a block in C99, (b) we
3854 track whether the body is an if statement for the sake of
3855 -Wparentheses warnings, (c) we handle an empty body specially for
3856 the sake of -Wempty-body warnings. */
3859 c_parser_if_body (c_parser *parser, bool *if_p)
3861 tree block = c_begin_compound_stmt (flag_isoc99);
3862 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3863 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3864 || (c_parser_next_token_is (parser, CPP_NAME)
3865 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3866 c_parser_label (parser);
3867 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3868 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3869 add_stmt (build_empty_stmt ());
3870 c_parser_statement_after_labels (parser);
3871 return c_end_compound_stmt (block, flag_isoc99);
3874 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3877 if ( expression ) statement
3878 if ( expression ) statement else statement
3882 c_parser_if_statement (c_parser *parser)
3887 bool first_if = false, second_if = false;
3888 tree first_body, second_body;
3889 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3890 c_parser_consume_token (parser);
3891 block = c_begin_compound_stmt (flag_isoc99);
3892 loc = c_parser_peek_token (parser)->location;
3893 cond = c_parser_paren_condition (parser);
3894 first_body = c_parser_if_body (parser, &first_if);
3895 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3897 c_parser_consume_token (parser);
3898 second_body = c_parser_if_body (parser, &second_if);
3901 second_body = NULL_TREE;
3902 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3903 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3906 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3909 switch (expression) statement
3913 c_parser_switch_statement (c_parser *parser)
3915 tree block, expr, body, save_break;
3916 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3917 c_parser_consume_token (parser);
3918 block = c_begin_compound_stmt (flag_isoc99);
3919 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3921 expr = c_parser_expression (parser).value;
3922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3925 expr = error_mark_node;
3926 c_start_case (expr);
3927 save_break = c_break_label;
3928 c_break_label = NULL_TREE;
3929 body = c_parser_c99_block_statement (parser);
3930 c_finish_case (body);
3932 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3933 c_break_label = save_break;
3934 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3937 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3940 while (expression) statement
3944 c_parser_while_statement (c_parser *parser)
3946 tree block, cond, body, save_break, save_cont;
3948 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3949 c_parser_consume_token (parser);
3950 block = c_begin_compound_stmt (flag_isoc99);
3951 loc = c_parser_peek_token (parser)->location;
3952 cond = c_parser_paren_condition (parser);
3953 save_break = c_break_label;
3954 c_break_label = NULL_TREE;
3955 save_cont = c_cont_label;
3956 c_cont_label = NULL_TREE;
3957 body = c_parser_c99_block_statement (parser);
3958 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3959 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3960 c_break_label = save_break;
3961 c_cont_label = save_cont;
3964 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3967 do statement while ( expression ) ;
3971 c_parser_do_statement (c_parser *parser)
3973 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3975 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3976 c_parser_consume_token (parser);
3977 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3978 warning (OPT_Wempty_body,
3979 "suggest braces around empty body in %<do%> statement");
3980 block = c_begin_compound_stmt (flag_isoc99);
3981 loc = c_parser_peek_token (parser)->location;
3982 save_break = c_break_label;
3983 c_break_label = NULL_TREE;
3984 save_cont = c_cont_label;
3985 c_cont_label = NULL_TREE;
3986 body = c_parser_c99_block_statement (parser);
3987 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
3988 new_break = c_break_label;
3989 c_break_label = save_break;
3990 new_cont = c_cont_label;
3991 c_cont_label = save_cont;
3992 cond = c_parser_paren_condition (parser);
3993 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3994 c_parser_skip_to_end_of_block_or_statement (parser);
3995 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
3996 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3999 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4002 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4003 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4005 The form with a declaration is new in C99.
4007 ??? In accordance with the old parser, the declaration may be a
4008 nested function, which is then rejected in check_for_loop_decls,
4009 but does it make any sense for this to be included in the grammar?
4010 Note in particular that the nested function does not include a
4011 trailing ';', whereas the "declaration" production includes one.
4012 Also, can we reject bad declarations earlier and cheaper than
4013 check_for_loop_decls? */
4016 c_parser_for_statement (c_parser *parser)
4018 tree block, cond, incr, save_break, save_cont, body;
4020 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4021 loc = c_parser_peek_token (parser)->location;
4022 c_parser_consume_token (parser);
4023 block = c_begin_compound_stmt (flag_isoc99);
4024 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4026 /* Parse the initialization declaration or expression. */
4027 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4029 c_parser_consume_token (parser);
4030 c_finish_expr_stmt (NULL_TREE);
4032 else if (c_parser_next_token_starts_declspecs (parser))
4034 c_parser_declaration_or_fndef (parser, true, true, true, true);
4035 check_for_loop_decls ();
4037 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4039 /* __extension__ can start a declaration, but is also an
4040 unary operator that can start an expression. Consume all
4041 but the last of a possible series of __extension__ to
4043 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4044 && (c_parser_peek_2nd_token (parser)->keyword
4046 c_parser_consume_token (parser);
4047 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4050 ext = disable_extension_diagnostics ();
4051 c_parser_consume_token (parser);
4052 c_parser_declaration_or_fndef (parser, true, true, true, true);
4053 restore_extension_diagnostics (ext);
4054 check_for_loop_decls ();
4062 c_finish_expr_stmt (c_parser_expression (parser).value);
4063 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4065 /* Parse the loop condition. */
4066 loc = c_parser_peek_token (parser)->location;
4067 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4069 c_parser_consume_token (parser);
4074 tree ocond = c_parser_expression_conv (parser).value;
4075 cond = c_objc_common_truthvalue_conversion (ocond);
4076 if (CAN_HAVE_LOCATION_P (cond))
4077 SET_EXPR_LOCATION (cond, loc);
4078 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4080 /* Parse the increment expression. */
4081 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4082 incr = c_process_expr_stmt (NULL_TREE);
4084 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4085 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4089 cond = error_mark_node;
4090 incr = error_mark_node;
4092 save_break = c_break_label;
4093 c_break_label = NULL_TREE;
4094 save_cont = c_cont_label;
4095 c_cont_label = NULL_TREE;
4096 body = c_parser_c99_block_statement (parser);
4097 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4098 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4099 c_break_label = save_break;
4100 c_cont_label = save_cont;
4103 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4104 statement with inputs, outputs, clobbers, and volatile tag
4108 asm type-qualifier[opt] ( asm-argument ) ;
4112 asm-string-literal : asm-operands[opt]
4113 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4114 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4116 Qualifiers other than volatile are accepted in the syntax but
4120 c_parser_asm_statement (c_parser *parser)
4122 tree quals, str, outputs, inputs, clobbers, ret;
4124 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4125 c_parser_consume_token (parser);
4126 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4128 quals = c_parser_peek_token (parser)->value;
4129 c_parser_consume_token (parser);
4131 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4132 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4134 warning (0, "%E qualifier ignored on asm",
4135 c_parser_peek_token (parser)->value);
4137 c_parser_consume_token (parser);
4141 /* ??? Follow the C++ parser rather than using the
4142 c_lex_string_translate kludge. */
4143 c_lex_string_translate = 0;
4144 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4146 c_lex_string_translate = 1;
4149 str = c_parser_asm_string_literal (parser);
4150 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4153 outputs = NULL_TREE;
4155 clobbers = NULL_TREE;
4158 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4160 c_lex_string_translate = 1;
4161 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4165 /* Parse outputs. */
4166 if (c_parser_next_token_is (parser, CPP_COLON)
4167 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4168 outputs = NULL_TREE;
4170 outputs = c_parser_asm_operands (parser, false);
4171 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4174 clobbers = NULL_TREE;
4177 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4179 c_lex_string_translate = 1;
4180 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4184 if (c_parser_next_token_is (parser, CPP_COLON)
4185 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4188 inputs = c_parser_asm_operands (parser, true);
4189 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4191 clobbers = NULL_TREE;
4194 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4196 c_lex_string_translate = 1;
4197 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4200 /* Parse clobbers. */
4201 clobbers = c_parser_asm_clobbers (parser);
4203 c_lex_string_translate = 1;
4204 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4209 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4210 c_parser_skip_to_end_of_block_or_statement (parser);
4211 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4216 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4217 not outputs), apply the default conversion of functions and arrays
4222 asm-operands , asm-operand
4225 asm-string-literal ( expression )
4226 [ identifier ] asm-string-literal ( expression )
4230 c_parser_asm_operands (c_parser *parser, bool convert_p)
4232 tree list = NULL_TREE;
4237 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4239 c_parser_consume_token (parser);
4240 if (c_parser_next_token_is (parser, CPP_NAME))
4242 tree id = c_parser_peek_token (parser)->value;
4243 c_parser_consume_token (parser);
4244 name = build_string (IDENTIFIER_LENGTH (id),
4245 IDENTIFIER_POINTER (id));
4249 c_parser_error (parser, "expected identifier");
4250 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4253 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4258 str = c_parser_asm_string_literal (parser);
4259 if (str == NULL_TREE)
4261 c_lex_string_translate = 1;
4262 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4264 c_lex_string_translate = 0;
4267 expr = c_parser_expression (parser);
4269 expr = default_function_array_conversion (expr);
4270 c_lex_string_translate = 0;
4271 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4273 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4276 list = chainon (list, build_tree_list (build_tree_list (name, str),
4278 if (c_parser_next_token_is (parser, CPP_COMMA))
4279 c_parser_consume_token (parser);
4286 /* Parse asm clobbers, a GNU extension.
4290 asm-clobbers , asm-string-literal
4294 c_parser_asm_clobbers (c_parser *parser)
4296 tree list = NULL_TREE;
4299 tree str = c_parser_asm_string_literal (parser);
4301 list = tree_cons (NULL_TREE, str, list);
4304 if (c_parser_next_token_is (parser, CPP_COMMA))
4305 c_parser_consume_token (parser);
4312 /* Parse an expression other than a compound expression; that is, an
4313 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4314 NULL then it is an Objective-C message expression which is the
4315 primary-expression starting the expression as an initializer.
4317 assignment-expression:
4318 conditional-expression
4319 unary-expression assignment-operator assignment-expression
4321 assignment-operator: one of
4322 = *= /= %= += -= <<= >>= &= ^= |=
4324 In GNU C we accept any conditional expression on the LHS and
4325 diagnose the invalid lvalue rather than producing a syntax
4328 static struct c_expr
4329 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4331 struct c_expr lhs, rhs, ret;
4332 enum tree_code code;
4333 gcc_assert (!after || c_dialect_objc ());
4334 lhs = c_parser_conditional_expression (parser, after);
4335 switch (c_parser_peek_token (parser)->type)
4344 code = TRUNC_DIV_EXPR;
4347 code = TRUNC_MOD_EXPR;
4362 code = BIT_AND_EXPR;
4365 code = BIT_XOR_EXPR;
4368 code = BIT_IOR_EXPR;
4373 c_parser_consume_token (parser);
4374 rhs = c_parser_expr_no_commas (parser, NULL);
4375 rhs = default_function_array_conversion (rhs);
4376 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4377 if (code == NOP_EXPR)
4378 ret.original_code = MODIFY_EXPR;
4381 TREE_NO_WARNING (ret.value) = 1;
4382 ret.original_code = ERROR_MARK;
4387 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4388 is not NULL then it is an Objective-C message expression which is
4389 the primary-expression starting the expression as an initializer.
4391 conditional-expression:
4392 logical-OR-expression
4393 logical-OR-expression ? expression : conditional-expression
4397 conditional-expression:
4398 logical-OR-expression ? : conditional-expression
4401 static struct c_expr
4402 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4404 struct c_expr cond, exp1, exp2, ret;
4405 gcc_assert (!after || c_dialect_objc ());
4406 cond = c_parser_binary_expression (parser, after);
4407 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4409 cond = default_function_array_conversion (cond);
4410 c_parser_consume_token (parser);
4411 if (c_parser_next_token_is (parser, CPP_COLON))
4414 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4415 /* Make sure first operand is calculated only once. */
4416 exp1.value = save_expr (default_conversion (cond.value));
4417 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4418 skip_evaluation += cond.value == truthvalue_true_node;
4423 = c_objc_common_truthvalue_conversion
4424 (default_conversion (cond.value));
4425 skip_evaluation += cond.value == truthvalue_false_node;
4426 exp1 = c_parser_expression_conv (parser);
4427 skip_evaluation += ((cond.value == truthvalue_true_node)
4428 - (cond.value == truthvalue_false_node));
4430 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4432 skip_evaluation -= cond.value == truthvalue_true_node;
4433 ret.value = error_mark_node;
4434 ret.original_code = ERROR_MARK;
4437 exp2 = c_parser_conditional_expression (parser, NULL);
4438 exp2 = default_function_array_conversion (exp2);
4439 skip_evaluation -= cond.value == truthvalue_true_node;
4440 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4441 ret.original_code = ERROR_MARK;
4445 /* Parse a binary expression; that is, a logical-OR-expression (C90
4446 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4447 an Objective-C message expression which is the primary-expression
4448 starting the expression as an initializer.
4450 multiplicative-expression:
4452 multiplicative-expression * cast-expression
4453 multiplicative-expression / cast-expression
4454 multiplicative-expression % cast-expression
4456 additive-expression:
4457 multiplicative-expression
4458 additive-expression + multiplicative-expression
4459 additive-expression - multiplicative-expression
4463 shift-expression << additive-expression
4464 shift-expression >> additive-expression
4466 relational-expression:
4468 relational-expression < shift-expression
4469 relational-expression > shift-expression
4470 relational-expression <= shift-expression
4471 relational-expression >= shift-expression
4473 equality-expression:
4474 relational-expression
4475 equality-expression == relational-expression
4476 equality-expression != relational-expression
4480 AND-expression & equality-expression
4482 exclusive-OR-expression:
4484 exclusive-OR-expression ^ AND-expression
4486 inclusive-OR-expression:
4487 exclusive-OR-expression
4488 inclusive-OR-expression | exclusive-OR-expression
4490 logical-AND-expression:
4491 inclusive-OR-expression
4492 logical-AND-expression && inclusive-OR-expression
4494 logical-OR-expression:
4495 logical-AND-expression
4496 logical-OR-expression || logical-AND-expression
4499 static struct c_expr
4500 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4502 /* A binary expression is parsed using operator-precedence parsing,
4503 with the operands being cast expressions. All the binary
4504 operators are left-associative. Thus a binary expression is of
4507 E0 op1 E1 op2 E2 ...
4509 which we represent on a stack. On the stack, the precedence
4510 levels are strictly increasing. When a new operator is
4511 encountered of higher precedence than that at the top of the
4512 stack, it is pushed; its LHS is the top expression, and its RHS
4513 is everything parsed until it is popped. When a new operator is
4514 encountered with precedence less than or equal to that at the top
4515 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4516 by the result of the operation until the operator at the top of
4517 the stack has lower precedence than the new operator or there is
4518 only one element on the stack; then the top expression is the LHS
4519 of the new operator. In the case of logical AND and OR
4520 expressions, we also need to adjust skip_evaluation as
4521 appropriate when the operators are pushed and popped. */
4523 /* The precedence levels, where 0 is a dummy lowest level used for
4524 the bottom of the stack. */
4540 /* The expression at this stack level. */
4542 /* The precedence of the operator on its left, PREC_NONE at the
4543 bottom of the stack. */
4545 /* The operation on its left. */
4551 switch (stack[sp].op) \
4553 case TRUTH_ANDIF_EXPR: \
4554 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4556 case TRUTH_ORIF_EXPR: \
4557 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4562 stack[sp - 1].expr \
4563 = default_function_array_conversion (stack[sp - 1].expr); \
4565 = default_function_array_conversion (stack[sp].expr); \
4566 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4567 stack[sp - 1].expr, \
4571 gcc_assert (!after || c_dialect_objc ());
4572 stack[0].expr = c_parser_cast_expression (parser, after);
4573 stack[0].prec = PREC_NONE;
4578 enum tree_code ocode;
4581 switch (c_parser_peek_token (parser)->type)
4589 ocode = TRUNC_DIV_EXPR;
4593 ocode = TRUNC_MOD_EXPR;
4605 ocode = LSHIFT_EXPR;
4609 ocode = RSHIFT_EXPR;
4623 case CPP_GREATER_EQ:
4636 oprec = PREC_BITAND;
4637 ocode = BIT_AND_EXPR;
4640 oprec = PREC_BITXOR;
4641 ocode = BIT_XOR_EXPR;
4645 ocode = BIT_IOR_EXPR;
4648 oprec = PREC_LOGAND;
4649 ocode = TRUTH_ANDIF_EXPR;
4653 ocode = TRUTH_ORIF_EXPR;
4656 /* Not a binary operator, so end of the binary
4660 c_parser_consume_token (parser);
4661 while (oprec <= stack[sp].prec)
4665 case TRUTH_ANDIF_EXPR:
4667 = default_function_array_conversion (stack[sp].expr);
4668 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4669 (default_conversion (stack[sp].expr.value));
4670 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4672 case TRUTH_ORIF_EXPR:
4674 = default_function_array_conversion (stack[sp].expr);
4675 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4676 (default_conversion (stack[sp].expr.value));
4677 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4683 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4684 stack[sp].prec = oprec;
4685 stack[sp].op = ocode;
4690 return stack[0].expr;
4694 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4695 NULL then it is an Objective-C message expression which is the
4696 primary-expression starting the expression as an initializer.
4700 ( type-name ) unary-expression
4703 static struct c_expr
4704 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4706 gcc_assert (!after || c_dialect_objc ());
4708 return c_parser_postfix_expression_after_primary (parser, *after);
4709 /* If the expression begins with a parenthesized type name, it may
4710 be either a cast or a compound literal; we need to see whether
4711 the next character is '{' to tell the difference. If not, it is
4712 an unary expression. */
4713 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4714 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4716 struct c_type_name *type_name;
4719 c_parser_consume_token (parser);
4720 type_name = c_parser_type_name (parser);
4721 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4722 if (type_name == NULL)
4724 ret.value = error_mark_node;
4725 ret.original_code = ERROR_MARK;
4729 /* Save casted types in the function's used types hash table. */
4730 used_types_insert (type_name->specs->type);
4732 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4733 return c_parser_postfix_expression_after_paren_type (parser,
4735 expr = c_parser_cast_expression (parser, NULL);
4736 expr = default_function_array_conversion (expr);
4737 ret.value = c_cast_expr (type_name, expr.value);
4738 ret.original_code = ERROR_MARK;
4742 return c_parser_unary_expression (parser);
4745 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4751 unary-operator cast-expression
4752 sizeof unary-expression
4753 sizeof ( type-name )
4755 unary-operator: one of
4761 __alignof__ unary-expression
4762 __alignof__ ( type-name )
4765 unary-operator: one of
4766 __extension__ __real__ __imag__
4768 In addition, the GNU syntax treats ++ and -- as unary operators, so
4769 they may be applied to cast expressions with errors for non-lvalues
4772 static struct c_expr
4773 c_parser_unary_expression (c_parser *parser)
4776 struct c_expr ret, op;
4777 switch (c_parser_peek_token (parser)->type)
4780 c_parser_consume_token (parser);
4781 op = c_parser_cast_expression (parser, NULL);
4782 op = default_function_array_conversion (op);
4783 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4784 case CPP_MINUS_MINUS:
4785 c_parser_consume_token (parser);
4786 op = c_parser_cast_expression (parser, NULL);
4787 op = default_function_array_conversion (op);
4788 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4790 c_parser_consume_token (parser);
4791 return parser_build_unary_op (ADDR_EXPR,
4792 c_parser_cast_expression (parser, NULL));
4794 c_parser_consume_token (parser);
4795 op = c_parser_cast_expression (parser, NULL);
4796 op = default_function_array_conversion (op);
4797 ret.value = build_indirect_ref (op.value, "unary *");
4798 ret.original_code = ERROR_MARK;
4801 c_parser_consume_token (parser);
4802 if (!c_dialect_objc () && !in_system_header)
4803 warning (OPT_Wtraditional,
4804 "traditional C rejects the unary plus operator");
4805 op = c_parser_cast_expression (parser, NULL);
4806 op = default_function_array_conversion (op);
4807 return parser_build_unary_op (CONVERT_EXPR, op);
4809 c_parser_consume_token (parser);
4810 op = c_parser_cast_expression (parser, NULL);
4811 op = default_function_array_conversion (op);
4812 return parser_build_unary_op (NEGATE_EXPR, op);
4814 c_parser_consume_token (parser);
4815 op = c_parser_cast_expression (parser, NULL);
4816 op = default_function_array_conversion (op);
4817 return parser_build_unary_op (BIT_NOT_EXPR, op);
4819 c_parser_consume_token (parser);
4820 op = c_parser_cast_expression (parser, NULL);
4821 op = default_function_array_conversion (op);
4822 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4824 /* Refer to the address of a label as a pointer. */
4825 c_parser_consume_token (parser);
4826 if (c_parser_next_token_is (parser, CPP_NAME))
4828 ret.value = finish_label_address_expr
4829 (c_parser_peek_token (parser)->value);
4830 c_parser_consume_token (parser);
4834 c_parser_error (parser, "expected identifier");
4835 ret.value = error_mark_node;
4837 ret.original_code = ERROR_MARK;
4840 switch (c_parser_peek_token (parser)->keyword)
4843 return c_parser_sizeof_expression (parser);
4845 return c_parser_alignof_expression (parser);
4847 c_parser_consume_token (parser);
4848 ext = disable_extension_diagnostics ();
4849 ret = c_parser_cast_expression (parser, NULL);
4850 restore_extension_diagnostics (ext);
4853 c_parser_consume_token (parser);
4854 op = c_parser_cast_expression (parser, NULL);
4855 op = default_function_array_conversion (op);
4856 return parser_build_unary_op (REALPART_EXPR, op);
4858 c_parser_consume_token (parser);
4859 op = c_parser_cast_expression (parser, NULL);
4860 op = default_function_array_conversion (op);
4861 return parser_build_unary_op (IMAGPART_EXPR, op);
4863 return c_parser_postfix_expression (parser);
4866 return c_parser_postfix_expression (parser);
4870 /* Parse a sizeof expression. */
4872 static struct c_expr
4873 c_parser_sizeof_expression (c_parser *parser)
4876 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4877 c_parser_consume_token (parser);
4880 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4881 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4883 /* Either sizeof ( type-name ) or sizeof unary-expression
4884 starting with a compound literal. */
4885 struct c_type_name *type_name;
4886 c_parser_consume_token (parser);
4887 type_name = c_parser_type_name (parser);
4888 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4889 if (type_name == NULL)
4894 ret.value = error_mark_node;
4895 ret.original_code = ERROR_MARK;
4898 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4900 expr = c_parser_postfix_expression_after_paren_type (parser,
4904 /* sizeof ( type-name ). */
4907 if (type_name->declarator->kind == cdk_array
4908 && type_name->declarator->u.array.vla_unspec_p)
4911 error ("%<[*]%> not allowed in other than a declaration");
4913 return c_expr_sizeof_type (type_name);
4917 expr = c_parser_unary_expression (parser);
4921 if (TREE_CODE (expr.value) == COMPONENT_REF
4922 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4923 error ("%<sizeof%> applied to a bit-field");
4924 return c_expr_sizeof_expr (expr);
4928 /* Parse an alignof expression. */
4930 static struct c_expr
4931 c_parser_alignof_expression (c_parser *parser)
4934 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4935 c_parser_consume_token (parser);
4938 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4939 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4941 /* Either __alignof__ ( type-name ) or __alignof__
4942 unary-expression starting with a compound literal. */
4943 struct c_type_name *type_name;
4945 c_parser_consume_token (parser);
4946 type_name = c_parser_type_name (parser);
4947 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4948 if (type_name == NULL)
4953 ret.value = error_mark_node;
4954 ret.original_code = ERROR_MARK;
4957 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4959 expr = c_parser_postfix_expression_after_paren_type (parser,
4963 /* alignof ( type-name ). */
4966 ret.value = c_alignof (groktypename (type_name));
4967 ret.original_code = ERROR_MARK;
4973 expr = c_parser_unary_expression (parser);
4977 ret.value = c_alignof_expr (expr.value);
4978 ret.original_code = ERROR_MARK;
4983 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4987 postfix-expression [ expression ]
4988 postfix-expression ( argument-expression-list[opt] )
4989 postfix-expression . identifier
4990 postfix-expression -> identifier
4991 postfix-expression ++
4992 postfix-expression --
4993 ( type-name ) { initializer-list }
4994 ( type-name ) { initializer-list , }
4996 argument-expression-list:
4998 argument-expression-list , argument-expression
5010 (treated as a keyword in GNU C)
5013 ( compound-statement )
5014 __builtin_va_arg ( assignment-expression , type-name )
5015 __builtin_offsetof ( type-name , offsetof-member-designator )
5016 __builtin_choose_expr ( assignment-expression ,
5017 assignment-expression ,
5018 assignment-expression )
5019 __builtin_types_compatible_p ( type-name , type-name )
5021 offsetof-member-designator:
5023 offsetof-member-designator . identifier
5024 offsetof-member-designator [ expression ]
5029 [ objc-receiver objc-message-args ]
5030 @selector ( objc-selector-arg )
5031 @protocol ( identifier )
5032 @encode ( type-name )
5036 static struct c_expr
5037 c_parser_postfix_expression (c_parser *parser)
5039 struct c_expr expr, e1, e2, e3;
5040 struct c_type_name *t1, *t2;
5041 switch (c_parser_peek_token (parser)->type)
5046 expr.value = c_parser_peek_token (parser)->value;
5047 expr.original_code = ERROR_MARK;
5048 c_parser_consume_token (parser);
5052 expr.value = c_parser_peek_token (parser)->value;
5053 expr.original_code = STRING_CST;
5054 c_parser_consume_token (parser);
5056 case CPP_OBJC_STRING:
5057 gcc_assert (c_dialect_objc ());
5059 = objc_build_string_object (c_parser_peek_token (parser)->value);
5060 expr.original_code = ERROR_MARK;
5061 c_parser_consume_token (parser);
5064 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5066 c_parser_error (parser, "expected expression");
5067 expr.value = error_mark_node;
5068 expr.original_code = ERROR_MARK;
5072 tree id = c_parser_peek_token (parser)->value;
5073 location_t loc = c_parser_peek_token (parser)->location;
5074 c_parser_consume_token (parser);
5075 expr.value = build_external_ref (id,
5076 (c_parser_peek_token (parser)->type
5077 == CPP_OPEN_PAREN), loc);
5078 expr.original_code = ERROR_MARK;
5081 case CPP_OPEN_PAREN:
5082 /* A parenthesized expression, statement expression or compound
5084 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5086 /* A statement expression. */
5088 c_parser_consume_token (parser);
5089 c_parser_consume_token (parser);
5090 if (cur_stmt_list == NULL)
5092 error ("braced-group within expression allowed "
5093 "only inside a function");
5094 parser->error = true;
5095 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5096 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5097 expr.value = error_mark_node;
5098 expr.original_code = ERROR_MARK;
5101 stmt = c_begin_stmt_expr ();
5102 c_parser_compound_statement_nostart (parser);
5103 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5106 pedwarn ("ISO C forbids braced-groups within expressions");
5107 expr.value = c_finish_stmt_expr (stmt);
5108 expr.original_code = ERROR_MARK;
5110 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5112 /* A compound literal. ??? Can we actually get here rather
5113 than going directly to
5114 c_parser_postfix_expression_after_paren_type from
5116 struct c_type_name *type_name;
5117 c_parser_consume_token (parser);
5118 type_name = c_parser_type_name (parser);
5119 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5121 if (type_name == NULL)
5123 expr.value = error_mark_node;
5124 expr.original_code = ERROR_MARK;
5127 expr = c_parser_postfix_expression_after_paren_type (parser,
5132 /* A parenthesized expression. */
5133 c_parser_consume_token (parser);
5134 expr = c_parser_expression (parser);
5135 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5136 TREE_NO_WARNING (expr.value) = 1;
5137 expr.original_code = ERROR_MARK;
5138 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5143 switch (c_parser_peek_token (parser)->keyword)
5145 case RID_FUNCTION_NAME:
5146 case RID_PRETTY_FUNCTION_NAME:
5147 case RID_C99_FUNCTION_NAME:
5148 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5149 c_parser_peek_token (parser)->value);
5150 expr.original_code = ERROR_MARK;
5151 c_parser_consume_token (parser);
5154 c_parser_consume_token (parser);
5155 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5157 expr.value = error_mark_node;
5158 expr.original_code = ERROR_MARK;
5161 e1 = c_parser_expr_no_commas (parser, NULL);
5162 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5164 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5165 expr.value = error_mark_node;
5166 expr.original_code = ERROR_MARK;
5169 t1 = c_parser_type_name (parser);
5170 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5174 expr.value = error_mark_node;
5175 expr.original_code = ERROR_MARK;
5179 expr.value = build_va_arg (e1.value, groktypename (t1));
5180 expr.original_code = ERROR_MARK;
5184 c_parser_consume_token (parser);
5185 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5187 expr.value = error_mark_node;
5188 expr.original_code = ERROR_MARK;
5191 t1 = c_parser_type_name (parser);
5194 expr.value = error_mark_node;
5195 expr.original_code = ERROR_MARK;
5198 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5200 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5201 expr.value = error_mark_node;
5202 expr.original_code = ERROR_MARK;
5206 tree type = groktypename (t1);
5208 if (type == error_mark_node)
5209 offsetof_ref = error_mark_node;
5211 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5212 /* Parse the second argument to __builtin_offsetof. We
5213 must have one identifier, and beyond that we want to
5214 accept sub structure and sub array references. */
5215 if (c_parser_next_token_is (parser, CPP_NAME))
5217 offsetof_ref = build_component_ref
5218 (offsetof_ref, c_parser_peek_token (parser)->value);
5219 c_parser_consume_token (parser);
5220 while (c_parser_next_token_is (parser, CPP_DOT)
5221 || c_parser_next_token_is (parser,
5224 if (c_parser_next_token_is (parser, CPP_DOT))
5226 c_parser_consume_token (parser);
5227 if (c_parser_next_token_is_not (parser,
5230 c_parser_error (parser, "expected identifier");
5233 offsetof_ref = build_component_ref
5235 c_parser_peek_token (parser)->value);
5236 c_parser_consume_token (parser);
5241 c_parser_consume_token (parser);
5242 idx = c_parser_expression (parser).value;
5243 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5245 offsetof_ref = build_array_ref (offsetof_ref, idx);
5250 c_parser_error (parser, "expected identifier");
5251 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5253 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5254 expr.original_code = ERROR_MARK;
5257 case RID_CHOOSE_EXPR:
5258 c_parser_consume_token (parser);
5259 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5261 expr.value = error_mark_node;
5262 expr.original_code = ERROR_MARK;
5265 e1 = c_parser_expr_no_commas (parser, NULL);
5266 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5268 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5269 expr.value = error_mark_node;
5270 expr.original_code = ERROR_MARK;
5273 e2 = c_parser_expr_no_commas (parser, NULL);
5274 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5277 expr.value = error_mark_node;
5278 expr.original_code = ERROR_MARK;
5281 e3 = c_parser_expr_no_commas (parser, NULL);
5282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5287 c = fold (e1.value);
5288 if (TREE_CODE (c) != INTEGER_CST)
5289 error ("first argument to %<__builtin_choose_expr%> not"
5291 expr = integer_zerop (c) ? e3 : e2;
5294 case RID_TYPES_COMPATIBLE_P:
5295 c_parser_consume_token (parser);
5296 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5298 expr.value = error_mark_node;
5299 expr.original_code = ERROR_MARK;
5302 t1 = c_parser_type_name (parser);
5305 expr.value = error_mark_node;
5306 expr.original_code = ERROR_MARK;
5309 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5311 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5312 expr.value = error_mark_node;
5313 expr.original_code = ERROR_MARK;
5316 t2 = c_parser_type_name (parser);
5319 expr.value = error_mark_node;
5320 expr.original_code = ERROR_MARK;
5323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5328 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5329 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5331 expr.value = comptypes (e1, e2)
5332 ? build_int_cst (NULL_TREE, 1)
5333 : build_int_cst (NULL_TREE, 0);
5334 expr.original_code = ERROR_MARK;
5337 case RID_AT_SELECTOR:
5338 gcc_assert (c_dialect_objc ());
5339 c_parser_consume_token (parser);
5340 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5342 expr.value = error_mark_node;
5343 expr.original_code = ERROR_MARK;
5347 tree sel = c_parser_objc_selector_arg (parser);
5348 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5350 expr.value = objc_build_selector_expr (sel);
5351 expr.original_code = ERROR_MARK;
5354 case RID_AT_PROTOCOL:
5355 gcc_assert (c_dialect_objc ());
5356 c_parser_consume_token (parser);
5357 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5359 expr.value = error_mark_node;
5360 expr.original_code = ERROR_MARK;
5363 if (c_parser_next_token_is_not (parser, CPP_NAME))
5365 c_parser_error (parser, "expected identifier");
5366 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5367 expr.value = error_mark_node;
5368 expr.original_code = ERROR_MARK;
5372 tree id = c_parser_peek_token (parser)->value;
5373 c_parser_consume_token (parser);
5374 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5376 expr.value = objc_build_protocol_expr (id);
5377 expr.original_code = ERROR_MARK;
5381 /* Extension to support C-structures in the archiver. */
5382 gcc_assert (c_dialect_objc ());
5383 c_parser_consume_token (parser);
5384 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5386 expr.value = error_mark_node;
5387 expr.original_code = ERROR_MARK;
5390 t1 = c_parser_type_name (parser);
5393 expr.value = error_mark_node;
5394 expr.original_code = ERROR_MARK;
5395 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5401 tree type = groktypename (t1);
5402 expr.value = objc_build_encode_expr (type);
5403 expr.original_code = ERROR_MARK;
5407 c_parser_error (parser, "expected expression");
5408 expr.value = error_mark_node;
5409 expr.original_code = ERROR_MARK;
5413 case CPP_OPEN_SQUARE:
5414 if (c_dialect_objc ())
5416 tree receiver, args;
5417 c_parser_consume_token (parser);
5418 receiver = c_parser_objc_receiver (parser);
5419 args = c_parser_objc_message_args (parser);
5420 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5422 expr.value = objc_build_message_expr (build_tree_list (receiver,
5424 expr.original_code = ERROR_MARK;
5427 /* Else fall through to report error. */
5429 c_parser_error (parser, "expected expression");
5430 expr.value = error_mark_node;
5431 expr.original_code = ERROR_MARK;
5434 return c_parser_postfix_expression_after_primary (parser, expr);
5437 /* Parse a postfix expression after a parenthesized type name: the
5438 brace-enclosed initializer of a compound literal, possibly followed
5439 by some postfix operators. This is separate because it is not
5440 possible to tell until after the type name whether a cast
5441 expression has a cast or a compound literal, or whether the operand
5442 of sizeof is a parenthesized type name or starts with a compound
5445 static struct c_expr
5446 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5447 struct c_type_name *type_name)
5452 start_init (NULL_TREE, NULL, 0);
5453 type = groktypename (type_name);
5454 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5456 error ("compound literal has variable size");
5457 type = error_mark_node;
5459 init = c_parser_braced_init (parser, type, false);
5461 maybe_warn_string_init (type, init);
5463 if (pedantic && !flag_isoc99)
5464 pedwarn ("ISO C90 forbids compound literals");
5465 expr.value = build_compound_literal (type, init.value);
5466 expr.original_code = ERROR_MARK;
5467 return c_parser_postfix_expression_after_primary (parser, expr);
5470 /* Parse a postfix expression after the initial primary or compound
5471 literal; that is, parse a series of postfix operators. */
5473 static struct c_expr
5474 c_parser_postfix_expression_after_primary (c_parser *parser,
5477 tree ident, idx, exprlist;
5480 switch (c_parser_peek_token (parser)->type)
5482 case CPP_OPEN_SQUARE:
5483 /* Array reference. */
5484 c_parser_consume_token (parser);
5485 idx = c_parser_expression (parser).value;
5486 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5488 expr.value = build_array_ref (expr.value, idx);
5489 expr.original_code = ERROR_MARK;
5491 case CPP_OPEN_PAREN:
5492 /* Function call. */
5493 c_parser_consume_token (parser);
5494 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5495 exprlist = NULL_TREE;
5497 exprlist = c_parser_expr_list (parser, true);
5498 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5500 expr.value = build_function_call (expr.value, exprlist);
5501 expr.original_code = ERROR_MARK;
5504 /* Structure element reference. */
5505 c_parser_consume_token (parser);
5506 expr = default_function_array_conversion (expr);
5507 if (c_parser_next_token_is (parser, CPP_NAME))
5508 ident = c_parser_peek_token (parser)->value;
5511 c_parser_error (parser, "expected identifier");
5512 expr.value = error_mark_node;
5513 expr.original_code = ERROR_MARK;
5516 c_parser_consume_token (parser);
5517 expr.value = build_component_ref (expr.value, ident);
5518 expr.original_code = ERROR_MARK;
5521 /* Structure element reference. */
5522 c_parser_consume_token (parser);
5523 expr = default_function_array_conversion (expr);
5524 if (c_parser_next_token_is (parser, CPP_NAME))
5525 ident = c_parser_peek_token (parser)->value;
5528 c_parser_error (parser, "expected identifier");
5529 expr.value = error_mark_node;
5530 expr.original_code = ERROR_MARK;
5533 c_parser_consume_token (parser);
5534 expr.value = build_component_ref (build_indirect_ref (expr.value,
5536 expr.original_code = ERROR_MARK;
5539 /* Postincrement. */
5540 c_parser_consume_token (parser);
5541 expr = default_function_array_conversion (expr);
5542 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5543 expr.original_code = ERROR_MARK;
5545 case CPP_MINUS_MINUS:
5546 /* Postdecrement. */
5547 c_parser_consume_token (parser);
5548 expr = default_function_array_conversion (expr);
5549 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5550 expr.original_code = ERROR_MARK;
5558 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5561 assignment-expression
5562 expression , assignment-expression
5565 static struct c_expr
5566 c_parser_expression (c_parser *parser)
5569 expr = c_parser_expr_no_commas (parser, NULL);
5570 while (c_parser_next_token_is (parser, CPP_COMMA))
5573 c_parser_consume_token (parser);
5574 next = c_parser_expr_no_commas (parser, NULL);
5575 next = default_function_array_conversion (next);
5576 expr.value = build_compound_expr (expr.value, next.value);
5577 expr.original_code = COMPOUND_EXPR;
5582 /* Parse an expression and convert functions or arrays to
5585 static struct c_expr
5586 c_parser_expression_conv (c_parser *parser)
5589 expr = c_parser_expression (parser);
5590 expr = default_function_array_conversion (expr);
5594 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5595 functions and arrays to pointers.
5598 assignment-expression
5599 nonempty-expr-list , assignment-expression
5603 c_parser_expr_list (c_parser *parser, bool convert_p)
5607 expr = c_parser_expr_no_commas (parser, NULL);
5609 expr = default_function_array_conversion (expr);
5610 ret = cur = build_tree_list (NULL_TREE, expr.value);
5611 while (c_parser_next_token_is (parser, CPP_COMMA))
5613 c_parser_consume_token (parser);
5614 expr = c_parser_expr_no_commas (parser, NULL);
5616 expr = default_function_array_conversion (expr);
5617 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5623 /* Parse Objective-C-specific constructs. */
5625 /* Parse an objc-class-definition.
5627 objc-class-definition:
5628 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5629 objc-class-instance-variables[opt] objc-methodprotolist @end
5630 @implementation identifier objc-superclass[opt]
5631 objc-class-instance-variables[opt]
5632 @interface identifier ( identifier ) objc-protocol-refs[opt]
5633 objc-methodprotolist @end
5634 @implementation identifier ( identifier )
5639 "@interface identifier (" must start "@interface identifier (
5640 identifier ) ...": objc-methodprotolist in the first production may
5641 not start with a parenthesized identifier as a declarator of a data
5642 definition with no declaration specifiers if the objc-superclass,
5643 objc-protocol-refs and objc-class-instance-variables are omitted. */
5646 c_parser_objc_class_definition (c_parser *parser)
5651 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5653 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5657 c_parser_consume_token (parser);
5658 if (c_parser_next_token_is_not (parser, CPP_NAME))
5660 c_parser_error (parser, "expected identifier");
5663 id1 = c_parser_peek_token (parser)->value;
5664 c_parser_consume_token (parser);
5665 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5668 tree proto = NULL_TREE;
5669 c_parser_consume_token (parser);
5670 if (c_parser_next_token_is_not (parser, CPP_NAME))
5672 c_parser_error (parser, "expected identifier");
5673 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5676 id2 = c_parser_peek_token (parser)->value;
5677 c_parser_consume_token (parser);
5678 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5681 objc_start_category_implementation (id1, id2);
5684 if (c_parser_next_token_is (parser, CPP_LESS))
5685 proto = c_parser_objc_protocol_refs (parser);
5686 objc_start_category_interface (id1, id2, proto);
5687 c_parser_objc_methodprotolist (parser);
5688 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5689 objc_finish_interface ();
5692 if (c_parser_next_token_is (parser, CPP_COLON))
5694 c_parser_consume_token (parser);
5695 if (c_parser_next_token_is_not (parser, CPP_NAME))
5697 c_parser_error (parser, "expected identifier");
5700 superclass = c_parser_peek_token (parser)->value;
5701 c_parser_consume_token (parser);
5704 superclass = NULL_TREE;
5707 tree proto = NULL_TREE;
5708 if (c_parser_next_token_is (parser, CPP_LESS))
5709 proto = c_parser_objc_protocol_refs (parser);
5710 objc_start_class_interface (id1, superclass, proto);
5713 objc_start_class_implementation (id1, superclass);
5714 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5715 c_parser_objc_class_instance_variables (parser);
5718 objc_continue_interface ();
5719 c_parser_objc_methodprotolist (parser);
5720 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5721 objc_finish_interface ();
5725 objc_continue_implementation ();
5730 /* Parse objc-class-instance-variables.
5732 objc-class-instance-variables:
5733 { objc-instance-variable-decl-list[opt] }
5735 objc-instance-variable-decl-list:
5736 objc-visibility-spec
5737 objc-instance-variable-decl ;
5739 objc-instance-variable-decl-list objc-visibility-spec
5740 objc-instance-variable-decl-list objc-instance-variable-decl ;
5741 objc-instance-variable-decl-list ;
5743 objc-visibility-spec:
5748 objc-instance-variable-decl:
5753 c_parser_objc_class_instance_variables (c_parser *parser)
5755 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5756 c_parser_consume_token (parser);
5757 while (c_parser_next_token_is_not (parser, CPP_EOF))
5760 /* Parse any stray semicolon. */
5761 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5764 pedwarn ("extra semicolon in struct or union specified");
5765 c_parser_consume_token (parser);
5768 /* Stop if at the end of the instance variables. */
5769 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5771 c_parser_consume_token (parser);
5774 /* Parse any objc-visibility-spec. */
5775 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5777 c_parser_consume_token (parser);
5778 objc_set_visibility (2);
5781 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5783 c_parser_consume_token (parser);
5784 objc_set_visibility (0);
5787 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5789 c_parser_consume_token (parser);
5790 objc_set_visibility (1);
5793 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5795 c_parser_pragma (parser, pragma_external);
5799 /* Parse some comma-separated declarations. */
5800 decls = c_parser_struct_declaration (parser);
5802 /* Comma-separated instance variables are chained together in
5803 reverse order; add them one by one. */
5804 tree ivar = nreverse (decls);
5805 for (; ivar; ivar = TREE_CHAIN (ivar))
5806 objc_add_instance_variable (copy_node (ivar));
5808 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5812 /* Parse an objc-class-declaration.
5814 objc-class-declaration:
5815 @class identifier-list ;
5819 c_parser_objc_class_declaration (c_parser *parser)
5821 tree list = NULL_TREE;
5822 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5823 c_parser_consume_token (parser);
5824 /* Any identifiers, including those declared as type names, are OK
5829 if (c_parser_next_token_is_not (parser, CPP_NAME))
5831 c_parser_error (parser, "expected identifier");
5834 id = c_parser_peek_token (parser)->value;
5835 list = chainon (list, build_tree_list (NULL_TREE, id));
5836 c_parser_consume_token (parser);
5837 if (c_parser_next_token_is (parser, CPP_COMMA))
5838 c_parser_consume_token (parser);
5842 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5843 objc_declare_class (list);
5846 /* Parse an objc-alias-declaration.
5848 objc-alias-declaration:
5849 @compatibility_alias identifier identifier ;
5853 c_parser_objc_alias_declaration (c_parser *parser)
5856 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5857 c_parser_consume_token (parser);
5858 if (c_parser_next_token_is_not (parser, CPP_NAME))
5860 c_parser_error (parser, "expected identifier");
5861 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5864 id1 = c_parser_peek_token (parser)->value;
5865 c_parser_consume_token (parser);
5866 if (c_parser_next_token_is_not (parser, CPP_NAME))
5868 c_parser_error (parser, "expected identifier");
5869 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5872 id2 = c_parser_peek_token (parser)->value;
5873 c_parser_consume_token (parser);
5874 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5875 objc_declare_alias (id1, id2);
5878 /* Parse an objc-protocol-definition.
5880 objc-protocol-definition:
5881 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5882 @protocol identifier-list ;
5884 "@protocol identifier ;" should be resolved as "@protocol
5885 identifier-list ;": objc-methodprotolist may not start with a
5886 semicolon in the first alternative if objc-protocol-refs are
5890 c_parser_objc_protocol_definition (c_parser *parser)
5892 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5893 c_parser_consume_token (parser);
5894 if (c_parser_next_token_is_not (parser, CPP_NAME))
5896 c_parser_error (parser, "expected identifier");
5899 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5900 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5902 tree list = NULL_TREE;
5903 /* Any identifiers, including those declared as type names, are
5908 if (c_parser_next_token_is_not (parser, CPP_NAME))
5910 c_parser_error (parser, "expected identifier");
5913 id = c_parser_peek_token (parser)->value;
5914 list = chainon (list, build_tree_list (NULL_TREE, id));
5915 c_parser_consume_token (parser);
5916 if (c_parser_next_token_is (parser, CPP_COMMA))
5917 c_parser_consume_token (parser);
5921 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5922 objc_declare_protocols (list);
5926 tree id = c_parser_peek_token (parser)->value;
5927 tree proto = NULL_TREE;
5928 c_parser_consume_token (parser);
5929 if (c_parser_next_token_is (parser, CPP_LESS))
5930 proto = c_parser_objc_protocol_refs (parser);
5931 parser->objc_pq_context = true;
5932 objc_start_protocol (id, proto);
5933 c_parser_objc_methodprotolist (parser);
5934 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5935 parser->objc_pq_context = false;
5936 objc_finish_interface ();
5940 /* Parse an objc-method-type.
5947 static enum tree_code
5948 c_parser_objc_method_type (c_parser *parser)
5950 switch (c_parser_peek_token (parser)->type)
5953 c_parser_consume_token (parser);
5956 c_parser_consume_token (parser);
5963 /* Parse an objc-method-definition.
5965 objc-method-definition:
5966 objc-method-type objc-method-decl ;[opt] compound-statement
5970 c_parser_objc_method_definition (c_parser *parser)
5972 enum tree_code type = c_parser_objc_method_type (parser);
5974 objc_set_method_type (type);
5975 parser->objc_pq_context = true;
5976 decl = c_parser_objc_method_decl (parser);
5977 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5979 c_parser_consume_token (parser);
5981 pedwarn ("extra semicolon in method definition specified");
5983 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5985 c_parser_error (parser, "expected %<{%>");
5988 parser->objc_pq_context = false;
5989 objc_start_method_definition (decl);
5990 add_stmt (c_parser_compound_statement (parser));
5991 objc_finish_method_definition (current_function_decl);
5994 /* Parse an objc-methodprotolist.
5996 objc-methodprotolist:
5998 objc-methodprotolist objc-methodproto
5999 objc-methodprotolist declaration
6000 objc-methodprotolist ;
6002 The declaration is a data definition, which may be missing
6003 declaration specifiers under the same rules and diagnostics as
6004 other data definitions outside functions, and the stray semicolon
6005 is diagnosed the same way as a stray semicolon outside a
6009 c_parser_objc_methodprotolist (c_parser *parser)
6013 /* The list is terminated by @end. */
6014 switch (c_parser_peek_token (parser)->type)
6018 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6019 c_parser_consume_token (parser);
6023 c_parser_objc_methodproto (parser);
6026 c_parser_pragma (parser, pragma_external);
6031 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6033 c_parser_declaration_or_fndef (parser, false, true, false, true);
6039 /* Parse an objc-methodproto.
6042 objc-method-type objc-method-decl ;
6046 c_parser_objc_methodproto (c_parser *parser)
6048 enum tree_code type = c_parser_objc_method_type (parser);
6050 objc_set_method_type (type);
6051 /* Remember protocol qualifiers in prototypes. */
6052 parser->objc_pq_context = true;
6053 decl = c_parser_objc_method_decl (parser);
6054 /* Forget protocol qualifiers here. */
6055 parser->objc_pq_context = false;
6056 objc_add_method_declaration (decl);
6057 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6060 /* Parse an objc-method-decl.
6063 ( objc-type-name ) objc-selector
6065 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6066 objc-keyword-selector objc-optparmlist
6068 objc-keyword-selector:
6070 objc-keyword-selector objc-keyword-decl
6073 objc-selector : ( objc-type-name ) identifier
6074 objc-selector : identifier
6075 : ( objc-type-name ) identifier
6079 objc-optparms objc-optellipsis
6083 objc-opt-parms , parameter-declaration
6091 c_parser_objc_method_decl (c_parser *parser)
6093 tree type = NULL_TREE;
6095 tree parms = NULL_TREE;
6096 bool ellipsis = false;
6098 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6100 c_parser_consume_token (parser);
6101 type = c_parser_objc_type_name (parser);
6102 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6104 sel = c_parser_objc_selector (parser);
6105 /* If there is no selector, or a colon follows, we have an
6106 objc-keyword-selector. If there is a selector, and a colon does
6107 not follow, that selector ends the objc-method-decl. */
6108 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6111 tree list = NULL_TREE;
6114 tree atype = NULL_TREE, id, keyworddecl;
6115 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6117 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6119 c_parser_consume_token (parser);
6120 atype = c_parser_objc_type_name (parser);
6121 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6124 if (c_parser_next_token_is_not (parser, CPP_NAME))
6126 c_parser_error (parser, "expected identifier");
6127 return error_mark_node;
6129 id = c_parser_peek_token (parser)->value;
6130 c_parser_consume_token (parser);
6131 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6132 list = chainon (list, keyworddecl);
6133 tsel = c_parser_objc_selector (parser);
6134 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6137 /* Parse the optional parameter list. Optional Objective-C
6138 method parameters follow the C syntax, and may include '...'
6139 to denote a variable number of arguments. */
6140 parms = make_node (TREE_LIST);
6141 while (c_parser_next_token_is (parser, CPP_COMMA))
6143 struct c_parm *parm;
6144 c_parser_consume_token (parser);
6145 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6148 c_parser_consume_token (parser);
6151 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6154 parms = chainon (parms,
6155 build_tree_list (NULL_TREE, grokparm (parm)));
6159 return objc_build_method_signature (type, sel, parms, ellipsis);
6162 /* Parse an objc-type-name.
6165 objc-type-qualifiers[opt] type-name
6166 objc-type-qualifiers[opt]
6168 objc-type-qualifiers:
6170 objc-type-qualifiers objc-type-qualifier
6172 objc-type-qualifier: one of
6173 in out inout bycopy byref oneway
6177 c_parser_objc_type_name (c_parser *parser)
6179 tree quals = NULL_TREE;
6180 struct c_type_name *typename = NULL;
6181 tree type = NULL_TREE;
6184 c_token *token = c_parser_peek_token (parser);
6185 if (token->type == CPP_KEYWORD
6186 && (token->keyword == RID_IN
6187 || token->keyword == RID_OUT
6188 || token->keyword == RID_INOUT
6189 || token->keyword == RID_BYCOPY
6190 || token->keyword == RID_BYREF
6191 || token->keyword == RID_ONEWAY))
6193 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6194 c_parser_consume_token (parser);
6199 if (c_parser_next_token_starts_typename (parser))
6200 typename = c_parser_type_name (parser);
6202 type = groktypename (typename);
6203 return build_tree_list (quals, type);
6206 /* Parse objc-protocol-refs.
6213 c_parser_objc_protocol_refs (c_parser *parser)
6215 tree list = NULL_TREE;
6216 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6217 c_parser_consume_token (parser);
6218 /* Any identifiers, including those declared as type names, are OK
6223 if (c_parser_next_token_is_not (parser, CPP_NAME))
6225 c_parser_error (parser, "expected identifier");
6228 id = c_parser_peek_token (parser)->value;
6229 list = chainon (list, build_tree_list (NULL_TREE, id));
6230 c_parser_consume_token (parser);
6231 if (c_parser_next_token_is (parser, CPP_COMMA))
6232 c_parser_consume_token (parser);
6236 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6240 /* Parse an objc-try-catch-statement.
6242 objc-try-catch-statement:
6243 @try compound-statement objc-catch-list[opt]
6244 @try compound-statement objc-catch-list[opt] @finally compound-statement
6247 @catch ( parameter-declaration ) compound-statement
6248 objc-catch-list @catch ( parameter-declaration ) compound-statement
6252 c_parser_objc_try_catch_statement (c_parser *parser)
6256 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6257 c_parser_consume_token (parser);
6258 loc = c_parser_peek_token (parser)->location;
6259 stmt = c_parser_compound_statement (parser);
6260 objc_begin_try_stmt (loc, stmt);
6261 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6263 struct c_parm *parm;
6264 c_parser_consume_token (parser);
6265 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6267 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6270 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6273 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6274 objc_begin_catch_clause (grokparm (parm));
6275 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6276 c_parser_compound_statement_nostart (parser);
6277 objc_finish_catch_clause ();
6279 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6283 c_parser_consume_token (parser);
6284 finloc = c_parser_peek_token (parser)->location;
6285 finstmt = c_parser_compound_statement (parser);
6286 objc_build_finally_clause (finloc, finstmt);
6288 objc_finish_try_stmt ();
6291 /* Parse an objc-synchronized-statement.
6293 objc-synchronized-statement:
6294 @synchronized ( expression ) compound-statement
6298 c_parser_objc_synchronized_statement (c_parser *parser)
6302 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6303 c_parser_consume_token (parser);
6304 loc = c_parser_peek_token (parser)->location;
6305 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6307 expr = c_parser_expression (parser).value;
6308 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6311 expr = error_mark_node;
6312 stmt = c_parser_compound_statement (parser);
6313 objc_build_synchronized (loc, expr, stmt);
6316 /* Parse an objc-selector; return NULL_TREE without an error if the
6317 next token is not an objc-selector.
6322 enum struct union if else while do for switch case default
6323 break continue return goto asm sizeof typeof __alignof
6324 unsigned long const short volatile signed restrict _Complex
6325 in out inout bycopy byref oneway int char float double void _Bool
6327 ??? Why this selection of keywords but not, for example, storage
6328 class specifiers? */
6331 c_parser_objc_selector (c_parser *parser)
6333 c_token *token = c_parser_peek_token (parser);
6334 tree value = token->value;
6335 if (token->type == CPP_NAME)
6337 c_parser_consume_token (parser);
6340 if (token->type != CPP_KEYWORD)
6342 switch (token->keyword)
6383 c_parser_consume_token (parser);
6390 /* Parse an objc-selector-arg.
6394 objc-keywordname-list
6396 objc-keywordname-list:
6398 objc-keywordname-list objc-keywordname
6406 c_parser_objc_selector_arg (c_parser *parser)
6408 tree sel = c_parser_objc_selector (parser);
6409 tree list = NULL_TREE;
6410 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6414 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6416 list = chainon (list, build_tree_list (sel, NULL_TREE));
6417 sel = c_parser_objc_selector (parser);
6418 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6424 /* Parse an objc-receiver.
6433 c_parser_objc_receiver (c_parser *parser)
6435 if (c_parser_peek_token (parser)->type == CPP_NAME
6436 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6437 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6439 tree id = c_parser_peek_token (parser)->value;
6440 c_parser_consume_token (parser);
6441 return objc_get_class_reference (id);
6443 return c_parser_expression (parser).value;
6446 /* Parse objc-message-args.
6450 objc-keywordarg-list
6452 objc-keywordarg-list:
6454 objc-keywordarg-list objc-keywordarg
6457 objc-selector : objc-keywordexpr
6462 c_parser_objc_message_args (c_parser *parser)
6464 tree sel = c_parser_objc_selector (parser);
6465 tree list = NULL_TREE;
6466 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6471 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6473 keywordexpr = c_parser_objc_keywordexpr (parser);
6474 list = chainon (list, build_tree_list (sel, keywordexpr));
6475 sel = c_parser_objc_selector (parser);
6476 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6482 /* Parse an objc-keywordexpr.
6489 c_parser_objc_keywordexpr (c_parser *parser)
6491 tree list = c_parser_expr_list (parser, true);
6492 if (TREE_CHAIN (list) == NULL_TREE)
6494 /* Just return the expression, remove a level of
6496 return TREE_VALUE (list);
6500 /* We have a comma expression, we will collapse later. */
6506 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6507 should be considered, statements. ALLOW_STMT is true if we're within
6508 the context of a function and such pragmas are to be allowed. Returns
6509 true if we actually parsed such a pragma. */
6512 c_parser_pragma (c_parser *parser, enum pragma_context context)
6516 id = c_parser_peek_token (parser)->pragma_kind;
6517 gcc_assert (id != PRAGMA_NONE);
6521 case PRAGMA_OMP_BARRIER:
6522 if (context != pragma_compound)
6524 if (context == pragma_stmt)
6525 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6526 "used in compound statements");
6529 c_parser_omp_barrier (parser);
6532 case PRAGMA_OMP_FLUSH:
6533 if (context != pragma_compound)
6535 if (context == pragma_stmt)
6536 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6537 "used in compound statements");
6540 c_parser_omp_flush (parser);
6543 case PRAGMA_OMP_THREADPRIVATE:
6544 c_parser_omp_threadprivate (parser);
6547 case PRAGMA_OMP_SECTION:
6548 error ("%<#pragma omp section%> may only be used in "
6549 "%<#pragma omp sections%> construct");
6550 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6553 case PRAGMA_GCC_PCH_PREPROCESS:
6554 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6555 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6559 if (id < PRAGMA_FIRST_EXTERNAL)
6561 if (context == pragma_external)
6564 c_parser_error (parser, "expected declaration specifiers");
6565 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6568 c_parser_omp_construct (parser);
6574 c_parser_consume_pragma (parser);
6575 c_invoke_pragma_handler (id);
6577 /* Skip to EOL, but suppress any error message. Those will have been
6578 generated by the handler routine through calling error, as opposed
6579 to calling c_parser_error. */
6580 parser->error = true;
6581 c_parser_skip_to_pragma_eol (parser);
6586 /* The interface the pragma parsers have to the lexer. */
6589 pragma_lex (tree *value)
6591 c_token *tok = c_parser_peek_token (the_parser);
6592 enum cpp_ttype ret = tok->type;
6594 *value = tok->value;
6595 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6599 if (ret == CPP_KEYWORD)
6601 c_parser_consume_token (the_parser);
6608 c_parser_pragma_pch_preprocess (c_parser *parser)
6612 c_parser_consume_pragma (parser);
6613 if (c_parser_next_token_is (parser, CPP_STRING))
6615 name = c_parser_peek_token (parser)->value;
6616 c_parser_consume_token (parser);
6619 c_parser_error (parser, "expected string literal");
6620 c_parser_skip_to_pragma_eol (parser);
6623 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6626 /* OpenMP 2.5 parsing routines. */
6628 /* Returns name of the next clause.
6629 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6630 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6631 returned and the token is consumed. */
6633 static pragma_omp_clause
6634 c_parser_omp_clause_name (c_parser *parser)
6636 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6638 if (c_parser_next_token_is_keyword (parser, RID_IF))
6639 result = PRAGMA_OMP_CLAUSE_IF;
6640 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6641 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6642 else if (c_parser_next_token_is (parser, CPP_NAME))
6644 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6649 if (!strcmp ("copyin", p))
6650 result = PRAGMA_OMP_CLAUSE_COPYIN;
6651 else if (!strcmp ("copyprivate", p))
6652 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6655 if (!strcmp ("firstprivate", p))
6656 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6659 if (!strcmp ("lastprivate", p))
6660 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6663 if (!strcmp ("nowait", p))
6664 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6665 else if (!strcmp ("num_threads", p))
6666 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6669 if (!strcmp ("ordered", p))
6670 result = PRAGMA_OMP_CLAUSE_ORDERED;
6673 if (!strcmp ("private", p))
6674 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6677 if (!strcmp ("reduction", p))
6678 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6681 if (!strcmp ("schedule", p))
6682 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6683 else if (!strcmp ("shared", p))
6684 result = PRAGMA_OMP_CLAUSE_SHARED;
6689 if (result != PRAGMA_OMP_CLAUSE_NONE)
6690 c_parser_consume_token (parser);
6695 /* Validate that a clause of the given type does not already exist. */
6698 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6702 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6703 if (OMP_CLAUSE_CODE (c) == code)
6705 error ("too many %qs clauses", name);
6713 variable-list , identifier
6715 If KIND is nonzero, create the appropriate node and install the decl
6716 in OMP_CLAUSE_DECL and add the node to the head of the list.
6718 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6719 return the list created. */
6722 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6725 if (c_parser_next_token_is_not (parser, CPP_NAME)
6726 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6727 c_parser_error (parser, "expected identifier");
6729 while (c_parser_next_token_is (parser, CPP_NAME)
6730 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6732 tree t = lookup_name (c_parser_peek_token (parser)->value);
6735 undeclared_variable (c_parser_peek_token (parser)->value,
6736 c_parser_peek_token (parser)->location);
6737 else if (t == error_mark_node)
6741 tree u = build_omp_clause (kind);
6742 OMP_CLAUSE_DECL (u) = t;
6743 OMP_CLAUSE_CHAIN (u) = list;
6747 list = tree_cons (t, NULL_TREE, list);
6749 c_parser_consume_token (parser);
6751 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6754 c_parser_consume_token (parser);
6760 /* Similarly, but expect leading and trailing parenthesis. This is a very
6761 common case for omp clauses. */
6764 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6766 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6768 list = c_parser_omp_variable_list (parser, kind, list);
6769 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6775 copyin ( variable-list ) */
6778 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6780 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6784 copyprivate ( variable-list ) */
6787 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6789 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6793 default ( shared | none ) */
6796 c_parser_omp_clause_default (c_parser *parser, tree list)
6798 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6801 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6803 if (c_parser_next_token_is (parser, CPP_NAME))
6805 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6810 if (strcmp ("none", p) != 0)
6812 kind = OMP_CLAUSE_DEFAULT_NONE;
6816 if (strcmp ("shared", p) != 0)
6818 kind = OMP_CLAUSE_DEFAULT_SHARED;
6825 c_parser_consume_token (parser);
6830 c_parser_error (parser, "expected %<none%> or %<shared%>");
6832 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6834 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6837 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6838 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6839 OMP_CLAUSE_CHAIN (c) = list;
6840 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6846 firstprivate ( variable-list ) */
6849 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6851 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6855 if ( expression ) */
6858 c_parser_omp_clause_if (c_parser *parser, tree list)
6860 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6862 tree t = c_parser_paren_condition (parser);
6865 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6867 c = build_omp_clause (OMP_CLAUSE_IF);
6868 OMP_CLAUSE_IF_EXPR (c) = t;
6869 OMP_CLAUSE_CHAIN (c) = list;
6873 c_parser_error (parser, "expected %<(%>");
6879 lastprivate ( variable-list ) */
6882 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6884 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6891 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6895 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6897 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6898 OMP_CLAUSE_CHAIN (c) = list;
6903 num_threads ( expression ) */
6906 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6908 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6910 tree c, t = c_parser_expression (parser).value;
6912 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6914 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6916 c_parser_error (parser, "expected integer expression");
6920 /* Attempt to statically determine when the number isn't positive. */
6921 c = fold_build2 (LE_EXPR, boolean_type_node, t,
6922 build_int_cst (TREE_TYPE (t), 0));
6923 if (c == boolean_true_node)
6925 warning (0, "%<num_threads%> value must be positive");
6926 t = integer_one_node;
6929 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
6931 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
6932 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
6933 OMP_CLAUSE_CHAIN (c) = list;
6944 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6948 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
6950 c = build_omp_clause (OMP_CLAUSE_ORDERED);
6951 OMP_CLAUSE_CHAIN (c) = list;
6956 private ( variable-list ) */
6959 c_parser_omp_clause_private (c_parser *parser, tree list)
6961 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
6965 reduction ( reduction-operator : variable-list )
6968 One of: + * - & ^ | && || */
6971 c_parser_omp_clause_reduction (c_parser *parser, tree list)
6973 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6975 enum tree_code code;
6977 switch (c_parser_peek_token (parser)->type)
6989 code = BIT_AND_EXPR;
6992 code = BIT_XOR_EXPR;
6995 code = BIT_IOR_EXPR;
6998 code = TRUTH_ANDIF_EXPR;
7001 code = TRUTH_ORIF_EXPR;
7004 c_parser_error (parser,
7005 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7006 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7007 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7010 c_parser_consume_token (parser);
7011 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7015 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7016 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7017 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7021 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7027 schedule ( schedule-kind )
7028 schedule ( schedule-kind , expression )
7031 static | dynamic | guided | runtime
7035 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7039 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7042 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7044 if (c_parser_next_token_is (parser, CPP_NAME))
7046 tree kind = c_parser_peek_token (parser)->value;
7047 const char *p = IDENTIFIER_POINTER (kind);
7052 if (strcmp ("dynamic", p) != 0)
7054 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7058 if (strcmp ("guided", p) != 0)
7060 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7064 if (strcmp ("runtime", p) != 0)
7066 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7073 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7074 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7078 c_parser_consume_token (parser);
7079 if (c_parser_next_token_is (parser, CPP_COMMA))
7081 c_parser_consume_token (parser);
7083 t = c_parser_expr_no_commas (parser, NULL).value;
7085 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7086 error ("schedule %<runtime%> does not take "
7087 "a %<chunk_size%> parameter");
7088 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7089 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7091 c_parser_error (parser, "expected integer expression");
7093 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7096 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7097 "expected %<,%> or %<)%>");
7099 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7100 OMP_CLAUSE_CHAIN (c) = list;
7104 c_parser_error (parser, "invalid schedule kind");
7105 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7110 shared ( variable-list ) */
7113 c_parser_omp_clause_shared (c_parser *parser, tree list)
7115 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7118 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7119 is a bitmask in MASK. Return the list of clauses found; the result
7120 of clause default goes in *pdefault. */
7123 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7126 tree clauses = NULL;
7128 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7130 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7132 tree prev = clauses;
7136 case PRAGMA_OMP_CLAUSE_COPYIN:
7137 clauses = c_parser_omp_clause_copyin (parser, clauses);
7140 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7141 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7142 c_name = "copyprivate";
7144 case PRAGMA_OMP_CLAUSE_DEFAULT:
7145 clauses = c_parser_omp_clause_default (parser, clauses);
7148 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7149 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7150 c_name = "firstprivate";
7152 case PRAGMA_OMP_CLAUSE_IF:
7153 clauses = c_parser_omp_clause_if (parser, clauses);
7156 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7157 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7158 c_name = "lastprivate";
7160 case PRAGMA_OMP_CLAUSE_NOWAIT:
7161 clauses = c_parser_omp_clause_nowait (parser, clauses);
7164 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7165 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7166 c_name = "num_threads";
7168 case PRAGMA_OMP_CLAUSE_ORDERED:
7169 clauses = c_parser_omp_clause_ordered (parser, clauses);
7172 case PRAGMA_OMP_CLAUSE_PRIVATE:
7173 clauses = c_parser_omp_clause_private (parser, clauses);
7176 case PRAGMA_OMP_CLAUSE_REDUCTION:
7177 clauses = c_parser_omp_clause_reduction (parser, clauses);
7178 c_name = "reduction";
7180 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7181 clauses = c_parser_omp_clause_schedule (parser, clauses);
7182 c_name = "schedule";
7184 case PRAGMA_OMP_CLAUSE_SHARED:
7185 clauses = c_parser_omp_clause_shared (parser, clauses);
7189 c_parser_error (parser, "expected %<#pragma omp%> clause");
7193 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7195 /* Remove the invalid clause(s) from the list to avoid
7196 confusing the rest of the compiler. */
7198 error ("%qs is not valid for %qs", c_name, where);
7203 c_parser_skip_to_pragma_eol (parser);
7205 return c_finish_omp_clauses (clauses);
7212 In practice, we're also interested in adding the statement to an
7213 outer node. So it is convenient if we work around the fact that
7214 c_parser_statement calls add_stmt. */
7217 c_parser_omp_structured_block (c_parser *parser)
7219 tree stmt = push_stmt_list ();
7220 c_parser_statement (parser);
7221 return pop_stmt_list (stmt);
7225 # pragma omp atomic new-line
7229 x binop= expr | x++ | ++x | x-- | --x
7231 +, *, -, /, &, ^, |, <<, >>
7233 where x is an lvalue expression with scalar type. */
7236 c_parser_omp_atomic (c_parser *parser)
7240 enum tree_code code;
7242 c_parser_skip_to_pragma_eol (parser);
7244 lhs = c_parser_unary_expression (parser).value;
7245 switch (TREE_CODE (lhs))
7249 c_parser_skip_to_end_of_block_or_statement (parser);
7252 case PREINCREMENT_EXPR:
7253 case POSTINCREMENT_EXPR:
7254 lhs = TREE_OPERAND (lhs, 0);
7256 rhs = integer_one_node;
7259 case PREDECREMENT_EXPR:
7260 case POSTDECREMENT_EXPR:
7261 lhs = TREE_OPERAND (lhs, 0);
7263 rhs = integer_one_node;
7267 switch (c_parser_peek_token (parser)->type)
7273 code = TRUNC_DIV_EXPR;
7288 code = BIT_AND_EXPR;
7291 code = BIT_IOR_EXPR;
7294 code = BIT_XOR_EXPR;
7297 c_parser_error (parser,
7298 "invalid operator for %<#pragma omp atomic%>");
7302 c_parser_consume_token (parser);
7303 rhs = c_parser_expression (parser).value;
7306 stmt = c_finish_omp_atomic (code, lhs, rhs);
7307 if (stmt != error_mark_node)
7309 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7314 # pragma omp barrier new-line
7318 c_parser_omp_barrier (c_parser *parser)
7320 c_parser_consume_pragma (parser);
7321 c_parser_skip_to_pragma_eol (parser);
7323 c_finish_omp_barrier ();
7327 # pragma omp critical [(name)] new-line
7332 c_parser_omp_critical (c_parser *parser)
7334 tree stmt, name = NULL;
7336 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7338 c_parser_consume_token (parser);
7339 if (c_parser_next_token_is (parser, CPP_NAME))
7341 name = c_parser_peek_token (parser)->value;
7342 c_parser_consume_token (parser);
7343 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7346 c_parser_error (parser, "expected identifier");
7348 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7349 c_parser_error (parser, "expected %<(%> or end of line");
7350 c_parser_skip_to_pragma_eol (parser);
7352 stmt = c_parser_omp_structured_block (parser);
7353 return c_finish_omp_critical (stmt, name);
7357 # pragma omp flush flush-vars[opt] new-line
7360 ( variable-list ) */
7363 c_parser_omp_flush (c_parser *parser)
7365 c_parser_consume_pragma (parser);
7366 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7367 c_parser_omp_var_list_parens (parser, 0, NULL);
7368 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7369 c_parser_error (parser, "expected %<(%> or end of line");
7370 c_parser_skip_to_pragma_eol (parser);
7372 c_finish_omp_flush ();
7375 /* Parse the restricted form of the for statment allowed by OpenMP.
7376 The real trick here is to determine the loop control variable early
7377 so that we can push a new decl if necessary to make it private. */
7380 c_parser_omp_for_loop (c_parser *parser)
7382 tree decl, cond, incr, save_break, save_cont, body, init;
7385 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7387 c_parser_error (parser, "for statement expected");
7390 loc = c_parser_peek_token (parser)->location;
7391 c_parser_consume_token (parser);
7393 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7396 /* Parse the initialization declaration or expression. */
7397 if (c_parser_next_token_starts_declspecs (parser))
7399 c_parser_declaration_or_fndef (parser, true, true, true, true);
7400 decl = check_for_loop_decls ();
7405 else if (c_parser_next_token_is (parser, CPP_NAME)
7406 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7408 decl = c_parser_postfix_expression (parser).value;
7410 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7412 init = c_parser_expr_no_commas (parser, NULL).value;
7413 init = build_modify_expr (decl, NOP_EXPR, init);
7414 init = c_process_expr_stmt (init);
7416 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7421 /* Parse the loop condition. */
7423 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7425 cond = c_parser_expression_conv (parser).value;
7426 cond = c_objc_common_truthvalue_conversion (cond);
7427 if (CAN_HAVE_LOCATION_P (cond))
7428 SET_EXPR_LOCATION (cond, input_location);
7430 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7432 /* Parse the increment expression. */
7434 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7435 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7436 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7439 save_break = c_break_label;
7440 c_break_label = size_one_node;
7441 save_cont = c_cont_label;
7442 c_cont_label = NULL_TREE;
7443 body = push_stmt_list ();
7445 add_stmt (c_parser_c99_block_statement (parser));
7447 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7449 body = pop_stmt_list (body);
7450 c_break_label = save_break;
7451 c_cont_label = save_cont;
7453 /* Only bother calling c_finish_omp_for if we havn't already generated
7454 an error from the initialization parsing. */
7455 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7456 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7460 c_parser_error (parser, "expected iteration declaration or initialization");
7461 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7462 decl = init = cond = incr = NULL_TREE;
7467 #pragma omp for for-clause[optseq] new-line
7471 #define OMP_FOR_CLAUSE_MASK \
7472 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7473 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7474 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7475 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7476 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7477 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7478 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7481 c_parser_omp_for (c_parser *parser)
7483 tree block, clauses, ret;
7485 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7488 block = c_begin_compound_stmt (true);
7489 ret = c_parser_omp_for_loop (parser);
7491 OMP_FOR_CLAUSES (ret) = clauses;
7492 block = c_end_compound_stmt (block, true);
7499 # pragma omp master new-line
7504 c_parser_omp_master (c_parser *parser)
7506 c_parser_skip_to_pragma_eol (parser);
7507 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7511 # pragma omp ordered new-line
7516 c_parser_omp_ordered (c_parser *parser)
7518 c_parser_skip_to_pragma_eol (parser);
7519 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7525 { section-sequence }
7528 section-directive[opt] structured-block
7529 section-sequence section-directive structured-block */
7532 c_parser_omp_sections_scope (c_parser *parser)
7535 bool error_suppress = false;
7538 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7540 /* Avoid skipping until the end of the block. */
7541 parser->error = false;
7545 stmt = push_stmt_list ();
7547 loc = c_parser_peek_token (parser)->location;
7548 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7550 substmt = push_stmt_list ();
7554 c_parser_statement (parser);
7556 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7558 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7560 if (c_parser_next_token_is (parser, CPP_EOF))
7564 substmt = pop_stmt_list (substmt);
7565 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7566 SET_EXPR_LOCATION (substmt, loc);
7572 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7574 if (c_parser_next_token_is (parser, CPP_EOF))
7577 loc = c_parser_peek_token (parser)->location;
7578 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7580 c_parser_consume_pragma (parser);
7581 c_parser_skip_to_pragma_eol (parser);
7582 error_suppress = false;
7584 else if (!error_suppress)
7586 error ("expected %<#pragma omp section%> or %<}%>");
7587 error_suppress = true;
7590 substmt = c_parser_omp_structured_block (parser);
7591 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7592 SET_EXPR_LOCATION (substmt, loc);
7595 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7596 "expected %<#pragma omp section%> or %<}%>");
7598 substmt = pop_stmt_list (stmt);
7600 stmt = make_node (OMP_SECTIONS);
7601 TREE_TYPE (stmt) = void_type_node;
7602 OMP_SECTIONS_BODY (stmt) = substmt;
7604 return add_stmt (stmt);
7608 # pragma omp sections sections-clause[optseq] newline
7612 #define OMP_SECTIONS_CLAUSE_MASK \
7613 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7614 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7615 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7616 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7617 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7620 c_parser_omp_sections (c_parser *parser)
7622 tree block, clauses, ret;
7624 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7625 "#pragma omp sections");
7627 block = c_begin_compound_stmt (true);
7628 ret = c_parser_omp_sections_scope (parser);
7630 OMP_SECTIONS_CLAUSES (ret) = clauses;
7631 block = c_end_compound_stmt (block, true);
7638 # pragma parallel parallel-clause new-line
7639 # pragma parallel for parallel-for-clause new-line
7640 # pragma parallel sections parallel-sections-clause new-line
7643 #define OMP_PARALLEL_CLAUSE_MASK \
7644 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7645 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7646 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7647 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7648 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7649 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7650 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7651 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7654 c_parser_omp_parallel (c_parser *parser)
7656 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7657 const char *p_name = "#pragma omp parallel";
7658 tree stmt, clauses, par_clause, ws_clause, block;
7659 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7661 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7663 c_parser_consume_token (parser);
7664 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7665 p_name = "#pragma omp parallel for";
7666 mask |= OMP_FOR_CLAUSE_MASK;
7667 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7669 else if (c_parser_next_token_is (parser, CPP_NAME))
7671 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7672 if (strcmp (p, "sections") == 0)
7674 c_parser_consume_token (parser);
7675 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7676 p_name = "#pragma omp parallel sections";
7677 mask |= OMP_SECTIONS_CLAUSE_MASK;
7678 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7682 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7686 case PRAGMA_OMP_PARALLEL:
7687 block = c_begin_omp_parallel ();
7688 c_parser_statement (parser);
7689 stmt = c_finish_omp_parallel (clauses, block);
7692 case PRAGMA_OMP_PARALLEL_FOR:
7693 block = c_begin_omp_parallel ();
7694 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7695 stmt = c_parser_omp_for_loop (parser);
7697 OMP_FOR_CLAUSES (stmt) = ws_clause;
7698 stmt = c_finish_omp_parallel (par_clause, block);
7699 OMP_PARALLEL_COMBINED (stmt) = 1;
7702 case PRAGMA_OMP_PARALLEL_SECTIONS:
7703 block = c_begin_omp_parallel ();
7704 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7705 stmt = c_parser_omp_sections_scope (parser);
7707 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7708 stmt = c_finish_omp_parallel (par_clause, block);
7709 OMP_PARALLEL_COMBINED (stmt) = 1;
7720 # pragma omp single single-clause[optseq] new-line
7724 #define OMP_SINGLE_CLAUSE_MASK \
7725 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7726 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7727 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7728 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7731 c_parser_omp_single (c_parser *parser)
7733 tree stmt = make_node (OMP_SINGLE);
7734 TREE_TYPE (stmt) = void_type_node;
7736 OMP_SINGLE_CLAUSES (stmt)
7737 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7738 "#pragma omp single");
7739 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7741 return add_stmt (stmt);
7745 /* Main entry point to parsing most OpenMP pragmas. */
7748 c_parser_omp_construct (c_parser *parser)
7750 enum pragma_kind p_kind;
7754 loc = c_parser_peek_token (parser)->location;
7755 p_kind = c_parser_peek_token (parser)->pragma_kind;
7756 c_parser_consume_pragma (parser);
7758 /* For all constructs below except #pragma omp atomic
7759 MUST_NOT_THROW catch handlers are needed when exceptions
7761 if (p_kind != PRAGMA_OMP_ATOMIC)
7762 c_maybe_initialize_eh ();
7766 case PRAGMA_OMP_ATOMIC:
7767 c_parser_omp_atomic (parser);
7769 case PRAGMA_OMP_CRITICAL:
7770 stmt = c_parser_omp_critical (parser);
7772 case PRAGMA_OMP_FOR:
7773 stmt = c_parser_omp_for (parser);
7775 case PRAGMA_OMP_MASTER:
7776 stmt = c_parser_omp_master (parser);
7778 case PRAGMA_OMP_ORDERED:
7779 stmt = c_parser_omp_ordered (parser);
7781 case PRAGMA_OMP_PARALLEL:
7782 stmt = c_parser_omp_parallel (parser);
7784 case PRAGMA_OMP_SECTIONS:
7785 stmt = c_parser_omp_sections (parser);
7787 case PRAGMA_OMP_SINGLE:
7788 stmt = c_parser_omp_single (parser);
7795 SET_EXPR_LOCATION (stmt, loc);
7800 # pragma omp threadprivate (variable-list) */
7803 c_parser_omp_threadprivate (c_parser *parser)
7807 c_parser_consume_pragma (parser);
7808 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7810 /* Mark every variable in VARS to be assigned thread local storage. */
7811 for (t = vars; t; t = TREE_CHAIN (t))
7813 tree v = TREE_PURPOSE (t);
7815 /* If V had already been marked threadprivate, it doesn't matter
7816 whether it had been used prior to this point. */
7817 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7818 error ("%qE declared %<threadprivate%> after first use", v);
7819 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7820 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7821 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7822 error ("%<threadprivate%> %qE has incomplete type", v);
7825 if (! DECL_THREAD_LOCAL_P (v))
7827 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7828 /* If rtl has been already set for this var, call
7829 make_decl_rtl once again, so that encode_section_info
7830 has a chance to look at the new decl flags. */
7831 if (DECL_RTL_SET_P (v))
7834 C_DECL_THREADPRIVATE_P (v) = 1;
7838 c_parser_skip_to_pragma_eol (parser);
7842 /* Parse a single source file. */
7847 /* Use local storage to begin. If the first token is a pragma, parse it.
7848 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7849 which will cause garbage collection. */
7852 memset (&tparser, 0, sizeof tparser);
7853 the_parser = &tparser;
7855 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7856 c_parser_pragma_pch_preprocess (&tparser);
7858 the_parser = GGC_NEW (c_parser);
7859 *the_parser = tparser;
7861 c_parser_translation_unit (the_parser);
7865 #include "gt-c-parser.h"