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 /* True if we want to lex an untranslated string. */
284 BOOL_BITFIELD lex_untranslated_string : 1;
285 /* Objective-C specific parser/lexer information. */
286 BOOL_BITFIELD objc_pq_context : 1;
287 /* The following flag is needed to contextualize Objective-C lexical
288 analysis. In some cases (e.g., 'int NSObject;'), it is
289 undesirable to bind an identifier to an Objective-C class, even
290 if a class with that name exists. */
291 BOOL_BITFIELD objc_need_raw_identifier : 1;
295 /* The actual parser and external interface. ??? Does this need to be
296 garbage-collected? */
298 static GTY (()) c_parser *the_parser;
301 /* Read in and lex a single token, storing it in *TOKEN. */
304 c_lex_one_token (c_parser *parser, c_token *token)
306 timevar_push (TV_LEX);
308 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
309 (parser->lex_untranslated_string
310 ? C_LEX_STRING_NO_TRANSLATE : 0));
311 token->id_kind = C_ID_NONE;
312 token->keyword = RID_MAX;
313 token->pragma_kind = PRAGMA_NONE;
314 token->in_system_header = in_system_header;
322 bool objc_force_identifier = parser->objc_need_raw_identifier;
323 if (c_dialect_objc ())
324 parser->objc_need_raw_identifier = false;
326 if (C_IS_RESERVED_WORD (token->value))
328 enum rid rid_code = C_RID_CODE (token->value);
330 if (c_dialect_objc ())
332 if (!OBJC_IS_AT_KEYWORD (rid_code)
333 && (!OBJC_IS_PQ_KEYWORD (rid_code)
334 || parser->objc_pq_context))
336 /* Return the canonical spelling for this keyword. */
337 token->value = ridpointers[(int) rid_code];
338 token->type = CPP_KEYWORD;
339 token->keyword = rid_code;
345 /* Return the canonical spelling for this keyword. */
346 token->value = ridpointers[(int) rid_code];
347 token->type = CPP_KEYWORD;
348 token->keyword = rid_code;
353 decl = lookup_name (token->value);
356 if (TREE_CODE (decl) == TYPE_DECL)
358 token->id_kind = C_ID_TYPENAME;
362 else if (c_dialect_objc ())
364 tree objc_interface_decl = objc_is_class_name (token->value);
365 /* Objective-C class names are in the same namespace as
366 variables and typedefs, and hence are shadowed by local
368 if (objc_interface_decl
369 && (global_bindings_p ()
370 || (!objc_force_identifier && !decl)))
372 token->value = objc_interface_decl;
373 token->id_kind = C_ID_CLASSNAME;
377 token->id_kind = C_ID_ID;
381 /* This only happens in Objective-C; it must be a keyword. */
382 token->type = CPP_KEYWORD;
383 token->keyword = C_RID_CODE (token->value);
387 case CPP_CLOSE_PAREN:
389 /* These tokens may affect the interpretation of any identifiers
390 following, if doing Objective-C. */
391 if (c_dialect_objc ())
392 parser->objc_need_raw_identifier = false;
395 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
396 token->pragma_kind = TREE_INT_CST_LOW (token->value);
402 timevar_pop (TV_LEX);
405 /* Return a pointer to the next token from PARSER, reading it in if
408 static inline c_token *
409 c_parser_peek_token (c_parser *parser)
411 if (parser->tokens_avail == 0)
413 c_lex_one_token (parser, &parser->tokens[0]);
414 parser->tokens_avail = 1;
416 return &parser->tokens[0];
419 /* Return true if the next token from PARSER has the indicated
423 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
425 return c_parser_peek_token (parser)->type == type;
428 /* Return true if the next token from PARSER does not have the
432 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
434 return !c_parser_next_token_is (parser, type);
437 /* Return true if the next token from PARSER is the indicated
441 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
445 /* Peek at the next token. */
446 token = c_parser_peek_token (parser);
447 /* Check to see if it is the indicated keyword. */
448 return token->keyword == keyword;
451 /* Return true if TOKEN can start a type name,
454 c_token_starts_typename (c_token *token)
459 switch (token->id_kind)
466 gcc_assert (c_dialect_objc ());
472 switch (token->keyword)
504 if (c_dialect_objc ())
512 /* Return true if the next token from PARSER can start a type name,
515 c_parser_next_token_starts_typename (c_parser *parser)
517 c_token *token = c_parser_peek_token (parser);
518 return c_token_starts_typename (token);
521 /* Return true if TOKEN can start declaration specifiers, false
524 c_token_starts_declspecs (c_token *token)
529 switch (token->id_kind)
536 gcc_assert (c_dialect_objc ());
542 switch (token->keyword)
581 if (c_dialect_objc ())
589 /* Return true if the next token from PARSER can start declaration
590 specifiers, false otherwise. */
592 c_parser_next_token_starts_declspecs (c_parser *parser)
594 c_token *token = c_parser_peek_token (parser);
595 return c_token_starts_declspecs (token);
598 /* Return a pointer to the next-but-one token from PARSER, reading it
599 in if necessary. The next token is already read in. */
602 c_parser_peek_2nd_token (c_parser *parser)
604 if (parser->tokens_avail >= 2)
605 return &parser->tokens[1];
606 gcc_assert (parser->tokens_avail == 1);
607 gcc_assert (parser->tokens[0].type != CPP_EOF);
608 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
609 c_lex_one_token (parser, &parser->tokens[1]);
610 parser->tokens_avail = 2;
611 return &parser->tokens[1];
614 /* Consume the next token from PARSER. */
617 c_parser_consume_token (c_parser *parser)
619 gcc_assert (parser->tokens_avail >= 1);
620 gcc_assert (parser->tokens[0].type != CPP_EOF);
621 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
622 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
623 if (parser->tokens_avail == 2)
624 parser->tokens[0] = parser->tokens[1];
625 parser->tokens_avail--;
628 /* Expect the current token to be a #pragma. Consume it and remember
629 that we've begun parsing a pragma. */
632 c_parser_consume_pragma (c_parser *parser)
634 gcc_assert (!parser->in_pragma);
635 gcc_assert (parser->tokens_avail >= 1);
636 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
637 if (parser->tokens_avail == 2)
638 parser->tokens[0] = parser->tokens[1];
639 parser->tokens_avail--;
640 parser->in_pragma = true;
643 /* Update the globals input_location and in_system_header from
646 c_parser_set_source_position_from_token (c_token *token)
648 if (token->type != CPP_EOF)
650 input_location = token->location;
651 in_system_header = token->in_system_header;
655 /* Issue a diagnostic of the form
656 FILE:LINE: MESSAGE before TOKEN
657 where TOKEN is the next token in the input stream of PARSER.
658 MESSAGE (specified by the caller) is usually of the form "expected
661 Do not issue a diagnostic if still recovering from an error.
663 ??? This is taken from the C++ parser, but building up messages in
664 this way is not i18n-friendly and some other approach should be
668 c_parser_error (c_parser *parser, const char *gmsgid)
670 c_token *token = c_parser_peek_token (parser);
673 parser->error = true;
676 /* This diagnostic makes more sense if it is tagged to the line of
677 the token we just peeked at. */
678 c_parser_set_source_position_from_token (token);
679 c_parse_error (gmsgid,
680 /* Because c_parse_error does not understand
681 CPP_KEYWORD, keywords are treated like
683 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
687 /* If the next token is of the indicated TYPE, consume it. Otherwise,
688 issue the error MSGID. If MSGID is NULL then a message has already
689 been produced and no message will be produced this time. Returns
690 true if found, false otherwise. */
693 c_parser_require (c_parser *parser,
697 if (c_parser_next_token_is (parser, type))
699 c_parser_consume_token (parser);
704 c_parser_error (parser, msgid);
709 /* If the next token is the indicated keyword, consume it. Otherwise,
710 issue the error MSGID. Returns true if found, false otherwise. */
713 c_parser_require_keyword (c_parser *parser,
717 if (c_parser_next_token_is_keyword (parser, keyword))
719 c_parser_consume_token (parser);
724 c_parser_error (parser, msgid);
729 /* Like c_parser_require, except that tokens will be skipped until the
730 desired token is found. An error message is still produced if the
731 next token is not as expected. If MSGID is NULL then a message has
732 already been produced and no message will be produced this
736 c_parser_skip_until_found (c_parser *parser,
740 unsigned nesting_depth = 0;
742 if (c_parser_require (parser, type, msgid))
745 /* Skip tokens until the desired token is found. */
748 /* Peek at the next token. */
749 c_token *token = c_parser_peek_token (parser);
750 /* If we've reached the token we want, consume it and stop. */
751 if (token->type == type && !nesting_depth)
753 c_parser_consume_token (parser);
757 /* If we've run out of tokens, stop. */
758 if (token->type == CPP_EOF)
760 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
762 if (token->type == CPP_OPEN_BRACE
763 || token->type == CPP_OPEN_PAREN
764 || token->type == CPP_OPEN_SQUARE)
766 else if (token->type == CPP_CLOSE_BRACE
767 || token->type == CPP_CLOSE_PAREN
768 || token->type == CPP_CLOSE_SQUARE)
770 if (nesting_depth-- == 0)
773 /* Consume this token. */
774 c_parser_consume_token (parser);
776 parser->error = false;
779 /* Skip tokens until the end of a parameter is found, but do not
780 consume the comma, semicolon or closing delimiter. */
783 c_parser_skip_to_end_of_parameter (c_parser *parser)
785 unsigned nesting_depth = 0;
789 c_token *token = c_parser_peek_token (parser);
790 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
793 /* If we've run out of tokens, stop. */
794 if (token->type == CPP_EOF)
796 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
798 if (token->type == CPP_OPEN_BRACE
799 || token->type == CPP_OPEN_PAREN
800 || token->type == CPP_OPEN_SQUARE)
802 else if (token->type == CPP_CLOSE_BRACE
803 || token->type == CPP_CLOSE_PAREN
804 || token->type == CPP_CLOSE_SQUARE)
806 if (nesting_depth-- == 0)
809 /* Consume this token. */
810 c_parser_consume_token (parser);
812 parser->error = false;
815 /* Expect to be at the end of the pragma directive and consume an
816 end of line marker. */
819 c_parser_skip_to_pragma_eol (c_parser *parser)
821 gcc_assert (parser->in_pragma);
822 parser->in_pragma = false;
824 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
827 c_token *token = c_parser_peek_token (parser);
828 if (token->type == CPP_EOF)
830 if (token->type == CPP_PRAGMA_EOL)
832 c_parser_consume_token (parser);
835 c_parser_consume_token (parser);
838 parser->error = false;
841 /* Skip tokens until we have consumed an entire block, or until we
842 have consumed a non-nested ';'. */
845 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
847 unsigned nesting_depth = 0;
848 bool save_error = parser->error;
854 /* Peek at the next token. */
855 token = c_parser_peek_token (parser);
863 if (parser->in_pragma)
868 /* If the next token is a ';', we have reached the
869 end of the statement. */
872 /* Consume the ';'. */
873 c_parser_consume_token (parser);
878 case CPP_CLOSE_BRACE:
879 /* If the next token is a non-nested '}', then we have
880 reached the end of the current block. */
881 if (nesting_depth == 0 || --nesting_depth == 0)
883 c_parser_consume_token (parser);
889 /* If it the next token is a '{', then we are entering a new
890 block. Consume the entire block. */
895 /* If we see a pragma, consume the whole thing at once. We
896 have some safeguards against consuming pragmas willy-nilly.
897 Normally, we'd expect to be here with parser->error set,
898 which disables these safeguards. But it's possible to get
899 here for secondary error recovery, after parser->error has
901 c_parser_consume_pragma (parser);
902 c_parser_skip_to_pragma_eol (parser);
903 parser->error = save_error;
910 c_parser_consume_token (parser);
914 parser->error = false;
917 /* Save the warning flags which are controlled by __extension__. */
920 disable_extension_diagnostics (void)
923 | (warn_pointer_arith << 1)
924 | (warn_traditional << 2)
927 warn_pointer_arith = 0;
928 warn_traditional = 0;
933 /* Restore the warning flags which are controlled by __extension__.
934 FLAGS is the return value from disable_extension_diagnostics. */
937 restore_extension_diagnostics (int flags)
939 pedantic = flags & 1;
940 warn_pointer_arith = (flags >> 1) & 1;
941 warn_traditional = (flags >> 2) & 1;
942 flag_iso = (flags >> 3) & 1;
945 /* Possibly kinds of declarator to parse. */
946 typedef enum c_dtr_syn {
947 /* A normal declarator with an identifier. */
949 /* An abstract declarator (maybe empty). */
951 /* A parameter declarator: may be either, but after a type name does
952 not redeclare a typedef name as an identifier if it can
953 alternatively be interpreted as a typedef name; see DR#009,
954 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
955 following DR#249. For example, given a typedef T, "int T" and
956 "int *T" are valid parameter declarations redeclaring T, while
957 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
958 abstract declarators rather than involving redundant parentheses;
959 the same applies with attributes inside the parentheses before
964 static void c_parser_external_declaration (c_parser *);
965 static void c_parser_asm_definition (c_parser *);
966 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
967 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
969 static struct c_typespec c_parser_enum_specifier (c_parser *);
970 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
971 static tree c_parser_struct_declaration (c_parser *);
972 static struct c_typespec c_parser_typeof_specifier (c_parser *);
973 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
975 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
977 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
979 struct c_declarator *);
980 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
981 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
982 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
983 static tree c_parser_simple_asm_expr (c_parser *);
984 static tree c_parser_attributes (c_parser *);
985 static struct c_type_name *c_parser_type_name (c_parser *);
986 static struct c_expr c_parser_initializer (c_parser *);
987 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
988 static void c_parser_initelt (c_parser *);
989 static void c_parser_initval (c_parser *, struct c_expr *);
990 static tree c_parser_compound_statement (c_parser *);
991 static void c_parser_compound_statement_nostart (c_parser *);
992 static void c_parser_label (c_parser *);
993 static void c_parser_statement (c_parser *);
994 static void c_parser_statement_after_labels (c_parser *);
995 static void c_parser_if_statement (c_parser *);
996 static void c_parser_switch_statement (c_parser *);
997 static void c_parser_while_statement (c_parser *);
998 static void c_parser_do_statement (c_parser *);
999 static void c_parser_for_statement (c_parser *);
1000 static tree c_parser_asm_statement (c_parser *);
1001 static tree c_parser_asm_operands (c_parser *, bool);
1002 static tree c_parser_asm_clobbers (c_parser *);
1003 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1004 static struct c_expr c_parser_conditional_expression (c_parser *,
1006 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1007 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1008 static struct c_expr c_parser_unary_expression (c_parser *);
1009 static struct c_expr c_parser_sizeof_expression (c_parser *);
1010 static struct c_expr c_parser_alignof_expression (c_parser *);
1011 static struct c_expr c_parser_postfix_expression (c_parser *);
1012 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1013 struct c_type_name *);
1014 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1016 static struct c_expr c_parser_expression (c_parser *);
1017 static struct c_expr c_parser_expression_conv (c_parser *);
1018 static tree c_parser_expr_list (c_parser *, bool);
1019 static void c_parser_omp_construct (c_parser *);
1020 static void c_parser_omp_threadprivate (c_parser *);
1021 static void c_parser_omp_barrier (c_parser *);
1022 static void c_parser_omp_flush (c_parser *);
1024 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1025 static bool c_parser_pragma (c_parser *, enum pragma_context);
1027 /* These Objective-C parser functions are only ever called when
1028 compiling Objective-C. */
1029 static void c_parser_objc_class_definition (c_parser *);
1030 static void c_parser_objc_class_instance_variables (c_parser *);
1031 static void c_parser_objc_class_declaration (c_parser *);
1032 static void c_parser_objc_alias_declaration (c_parser *);
1033 static void c_parser_objc_protocol_definition (c_parser *);
1034 static enum tree_code c_parser_objc_method_type (c_parser *);
1035 static void c_parser_objc_method_definition (c_parser *);
1036 static void c_parser_objc_methodprotolist (c_parser *);
1037 static void c_parser_objc_methodproto (c_parser *);
1038 static tree c_parser_objc_method_decl (c_parser *);
1039 static tree c_parser_objc_type_name (c_parser *);
1040 static tree c_parser_objc_protocol_refs (c_parser *);
1041 static void c_parser_objc_try_catch_statement (c_parser *);
1042 static void c_parser_objc_synchronized_statement (c_parser *);
1043 static tree c_parser_objc_selector (c_parser *);
1044 static tree c_parser_objc_selector_arg (c_parser *);
1045 static tree c_parser_objc_receiver (c_parser *);
1046 static tree c_parser_objc_message_args (c_parser *);
1047 static tree c_parser_objc_keywordexpr (c_parser *);
1049 /* Parse a translation unit (C90 6.7, C99 6.9).
1052 external-declarations
1054 external-declarations:
1055 external-declaration
1056 external-declarations external-declaration
1065 c_parser_translation_unit (c_parser *parser)
1067 if (c_parser_next_token_is (parser, CPP_EOF))
1070 pedwarn ("ISO C forbids an empty source file");
1074 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1078 c_parser_external_declaration (parser);
1079 obstack_free (&parser_obstack, obstack_position);
1081 while (c_parser_next_token_is_not (parser, CPP_EOF));
1085 /* Parse an external declaration (C90 6.7, C99 6.9).
1087 external-declaration:
1093 external-declaration:
1096 __extension__ external-declaration
1100 external-declaration:
1101 objc-class-definition
1102 objc-class-declaration
1103 objc-alias-declaration
1104 objc-protocol-definition
1105 objc-method-definition
1110 c_parser_external_declaration (c_parser *parser)
1113 switch (c_parser_peek_token (parser)->type)
1116 switch (c_parser_peek_token (parser)->keyword)
1119 ext = disable_extension_diagnostics ();
1120 c_parser_consume_token (parser);
1121 c_parser_external_declaration (parser);
1122 restore_extension_diagnostics (ext);
1125 c_parser_asm_definition (parser);
1127 case RID_AT_INTERFACE:
1128 case RID_AT_IMPLEMENTATION:
1129 gcc_assert (c_dialect_objc ());
1130 c_parser_objc_class_definition (parser);
1133 gcc_assert (c_dialect_objc ());
1134 c_parser_objc_class_declaration (parser);
1137 gcc_assert (c_dialect_objc ());
1138 c_parser_objc_alias_declaration (parser);
1140 case RID_AT_PROTOCOL:
1141 gcc_assert (c_dialect_objc ());
1142 c_parser_objc_protocol_definition (parser);
1145 gcc_assert (c_dialect_objc ());
1146 c_parser_consume_token (parser);
1147 objc_finish_implementation ();
1155 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1156 c_parser_consume_token (parser);
1159 c_parser_pragma (parser, pragma_external);
1163 if (c_dialect_objc ())
1165 c_parser_objc_method_definition (parser);
1168 /* Else fall through, and yield a syntax error trying to parse
1169 as a declaration or function definition. */
1172 /* A declaration or a function definition. We can only tell
1173 which after parsing the declaration specifiers, if any, and
1174 the first declarator. */
1175 c_parser_declaration_or_fndef (parser, true, true, false, true);
1181 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1182 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1183 accepted; otherwise (old-style parameter declarations) only other
1184 declarations are accepted. If NESTED is true, we are inside a
1185 function or parsing old-style parameter declarations; any functions
1186 encountered are nested functions and declaration specifiers are
1187 required; otherwise we are at top level and functions are normal
1188 functions and declaration specifiers may be optional. If EMPTY_OK
1189 is true, empty declarations are OK (subject to all other
1190 constraints); otherwise (old-style parameter declarations) they are
1191 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1192 may start with attributes; otherwise they may not.
1195 declaration-specifiers init-declarator-list[opt] ;
1197 function-definition:
1198 declaration-specifiers[opt] declarator declaration-list[opt]
1203 declaration-list declaration
1205 init-declarator-list:
1207 init-declarator-list , init-declarator
1210 declarator simple-asm-expr[opt] attributes[opt]
1211 declarator simple-asm-expr[opt] attributes[opt] = initializer
1215 nested-function-definition:
1216 declaration-specifiers declarator declaration-list[opt]
1219 The simple-asm-expr and attributes are GNU extensions.
1221 This function does not handle __extension__; that is handled in its
1222 callers. ??? Following the old parser, __extension__ may start
1223 external declarations, declarations in functions and declarations
1224 at the start of "for" loops, but not old-style parameter
1227 C99 requires declaration specifiers in a function definition; the
1228 absence is diagnosed through the diagnosis of implicit int. In GNU
1229 C we also allow but diagnose declarations without declaration
1230 specifiers, but only at top level (elsewhere they conflict with
1236 threadprivate-directive */
1239 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1240 bool nested, bool start_attr_ok)
1242 struct c_declspecs *specs;
1244 tree all_prefix_attrs;
1245 bool diagnosed_no_specs = false;
1247 specs = build_null_declspecs ();
1248 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1251 c_parser_skip_to_end_of_block_or_statement (parser);
1254 if (nested && !specs->declspecs_seen_p)
1256 c_parser_error (parser, "expected declaration specifiers");
1257 c_parser_skip_to_end_of_block_or_statement (parser);
1260 finish_declspecs (specs);
1261 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1267 shadow_tag_warned (specs, 1);
1268 pedwarn ("empty declaration");
1270 c_parser_consume_token (parser);
1273 pending_xref_error ();
1274 prefix_attrs = specs->attrs;
1275 all_prefix_attrs = prefix_attrs;
1276 specs->attrs = NULL_TREE;
1279 struct c_declarator *declarator;
1282 /* Declaring either one or more declarators (in which case we
1283 should diagnose if there were no declaration specifiers) or a
1284 function definition (in which case the diagnostic for
1285 implicit int suffices). */
1286 declarator = c_parser_declarator (parser, specs->type_seen_p,
1287 C_DTR_NORMAL, &dummy);
1288 if (declarator == NULL)
1290 c_parser_skip_to_end_of_block_or_statement (parser);
1293 if (c_parser_next_token_is (parser, CPP_EQ)
1294 || c_parser_next_token_is (parser, CPP_COMMA)
1295 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1296 || c_parser_next_token_is_keyword (parser, RID_ASM)
1297 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1299 tree asm_name = NULL_TREE;
1300 tree postfix_attrs = NULL_TREE;
1301 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1303 diagnosed_no_specs = true;
1304 pedwarn ("data definition has no type or storage class");
1306 /* Having seen a data definition, there cannot now be a
1307 function definition. */
1309 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1310 asm_name = c_parser_simple_asm_expr (parser);
1311 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1312 postfix_attrs = c_parser_attributes (parser);
1313 if (c_parser_next_token_is (parser, CPP_EQ))
1317 c_parser_consume_token (parser);
1318 /* The declaration of the variable is in effect while
1319 its initializer is parsed. */
1320 d = start_decl (declarator, specs, true,
1321 chainon (postfix_attrs, all_prefix_attrs));
1323 d = error_mark_node;
1324 start_init (d, asm_name, global_bindings_p ());
1325 init = c_parser_initializer (parser);
1327 if (d != error_mark_node)
1329 maybe_warn_string_init (TREE_TYPE (d), init);
1330 finish_decl (d, init.value, asm_name);
1335 tree d = start_decl (declarator, specs, false,
1336 chainon (postfix_attrs,
1339 finish_decl (d, NULL_TREE, asm_name);
1341 if (c_parser_next_token_is (parser, CPP_COMMA))
1343 c_parser_consume_token (parser);
1344 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1345 all_prefix_attrs = chainon (c_parser_attributes (parser),
1348 all_prefix_attrs = prefix_attrs;
1351 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1353 c_parser_consume_token (parser);
1358 c_parser_error (parser, "expected %<,%> or %<;%>");
1359 c_parser_skip_to_end_of_block_or_statement (parser);
1365 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1366 "%<asm%> or %<__attribute__%>");
1367 c_parser_skip_to_end_of_block_or_statement (parser);
1370 /* Function definition (nested or otherwise). */
1374 pedwarn ("ISO C forbids nested functions");
1375 push_function_context ();
1377 if (!start_function (specs, declarator, all_prefix_attrs))
1379 /* This can appear in many cases looking nothing like a
1380 function definition, so we don't give a more specific
1381 error suggesting there was one. */
1382 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1383 "or %<__attribute__%>");
1385 pop_function_context ();
1388 /* Parse old-style parameter declarations. ??? Attributes are
1389 not allowed to start declaration specifiers here because of a
1390 syntax conflict between a function declaration with attribute
1391 suffix and a function definition with an attribute prefix on
1392 first old-style parameter declaration. Following the old
1393 parser, they are not accepted on subsequent old-style
1394 parameter declarations either. However, there is no
1395 ambiguity after the first declaration, nor indeed on the
1396 first as long as we don't allow postfix attributes after a
1397 declarator with a nonempty identifier list in a definition;
1398 and postfix attributes have never been accepted here in
1399 function definitions either. */
1400 while (c_parser_next_token_is_not (parser, CPP_EOF)
1401 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1402 c_parser_declaration_or_fndef (parser, false, false, true, false);
1403 DECL_SOURCE_LOCATION (current_function_decl)
1404 = c_parser_peek_token (parser)->location;
1405 store_parm_decls ();
1406 fnbody = c_parser_compound_statement (parser);
1409 tree decl = current_function_decl;
1412 pop_function_context ();
1413 add_stmt (build_stmt (DECL_EXPR, decl));
1424 /* Parse an asm-definition (asm() outside a function body). This is a
1432 c_parser_asm_definition (c_parser *parser)
1434 tree asm_str = c_parser_simple_asm_expr (parser);
1436 cgraph_add_asm_node (asm_str);
1437 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1440 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1441 6.7), adding them to SPECS (which may already include some).
1442 Storage class specifiers are accepted iff SCSPEC_OK; type
1443 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1444 the start iff START_ATTR_OK.
1446 declaration-specifiers:
1447 storage-class-specifier declaration-specifiers[opt]
1448 type-specifier declaration-specifiers[opt]
1449 type-qualifier declaration-specifiers[opt]
1450 function-specifier declaration-specifiers[opt]
1452 Function specifiers (inline) are from C99, and are currently
1453 handled as storage class specifiers, as is __thread.
1455 C90 6.5.1, C99 6.7.1:
1456 storage-class-specifier:
1467 C90 6.5.2, C99 6.7.2:
1480 [_Imaginary removed in C99 TC2]
1481 struct-or-union-specifier
1485 (_Bool and _Complex are new in C99.)
1487 C90 6.5.3, C99 6.7.3:
1494 (restrict is new in C99.)
1498 declaration-specifiers:
1499 attributes declaration-specifiers[opt]
1501 storage-class-specifier:
1513 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1514 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1519 class-name objc-protocol-refs[opt]
1520 typedef-name objc-protocol-refs
1525 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1526 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1528 bool attrs_ok = start_attr_ok;
1529 bool seen_type = specs->type_seen_p;
1530 while (c_parser_next_token_is (parser, CPP_NAME)
1531 || c_parser_next_token_is (parser, CPP_KEYWORD)
1532 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1534 struct c_typespec t;
1536 if (c_parser_next_token_is (parser, CPP_NAME))
1538 tree value = c_parser_peek_token (parser)->value;
1539 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1540 /* This finishes the specifiers unless a type name is OK, it
1541 is declared as a type name and a type name hasn't yet
1543 if (!typespec_ok || seen_type
1544 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1546 c_parser_consume_token (parser);
1549 if (kind == C_ID_TYPENAME
1550 && (!c_dialect_objc ()
1551 || c_parser_next_token_is_not (parser, CPP_LESS)))
1553 t.kind = ctsk_typedef;
1554 /* For a typedef name, record the meaning, not the name.
1555 In case of 'foo foo, bar;'. */
1556 t.spec = lookup_name (value);
1560 tree proto = NULL_TREE;
1561 gcc_assert (c_dialect_objc ());
1563 if (c_parser_next_token_is (parser, CPP_LESS))
1564 proto = c_parser_objc_protocol_refs (parser);
1565 t.spec = objc_get_protocol_qualified_type (value, proto);
1567 declspecs_add_type (specs, t);
1570 if (c_parser_next_token_is (parser, CPP_LESS))
1572 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1573 nisse@lysator.liu.se. */
1575 gcc_assert (c_dialect_objc ());
1576 if (!typespec_ok || seen_type)
1578 proto = c_parser_objc_protocol_refs (parser);
1580 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1581 declspecs_add_type (specs, t);
1584 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1585 switch (c_parser_peek_token (parser)->keyword)
1597 /* TODO: Distinguish between function specifiers (inline)
1598 and storage class specifiers, either here or in
1599 declspecs_add_scspec. */
1600 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1601 c_parser_consume_token (parser);
1624 if (c_dialect_objc ())
1625 parser->objc_need_raw_identifier = true;
1626 t.kind = ctsk_resword;
1627 t.spec = c_parser_peek_token (parser)->value;
1628 declspecs_add_type (specs, t);
1629 c_parser_consume_token (parser);
1636 t = c_parser_enum_specifier (parser);
1637 declspecs_add_type (specs, t);
1645 t = c_parser_struct_or_union_specifier (parser);
1646 declspecs_add_type (specs, t);
1649 /* ??? The old parser rejected typeof after other type
1650 specifiers, but is a syntax error the best way of
1652 if (!typespec_ok || seen_type)
1656 t = c_parser_typeof_specifier (parser);
1657 declspecs_add_type (specs, t);
1663 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1664 c_parser_consume_token (parser);
1669 attrs = c_parser_attributes (parser);
1670 declspecs_add_attrs (specs, attrs);
1679 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1682 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1683 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1684 enum attributes[opt] identifier
1686 The form with trailing comma is new in C99. The forms with
1687 attributes are GNU extensions. In GNU C, we accept any expression
1688 without commas in the syntax (assignment expressions, not just
1689 conditional expressions); assignment expressions will be diagnosed
1694 enumerator-list , enumerator
1697 enumeration-constant
1698 enumeration-constant = constant-expression
1701 static struct c_typespec
1702 c_parser_enum_specifier (c_parser *parser)
1704 struct c_typespec ret;
1706 tree ident = NULL_TREE;
1707 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1708 c_parser_consume_token (parser);
1709 attrs = c_parser_attributes (parser);
1710 /* Set the location in case we create a decl now. */
1711 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1712 if (c_parser_next_token_is (parser, CPP_NAME))
1714 ident = c_parser_peek_token (parser)->value;
1715 c_parser_consume_token (parser);
1717 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1719 /* Parse an enum definition. */
1720 struct c_enum_contents the_enum;
1721 tree type = start_enum (&the_enum, ident);
1723 /* We chain the enumerators in reverse order, then put them in
1724 forward order at the end. */
1725 tree values = NULL_TREE;
1726 c_parser_consume_token (parser);
1734 if (c_parser_next_token_is_not (parser, CPP_NAME))
1736 c_parser_error (parser, "expected identifier");
1737 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1738 values = error_mark_node;
1741 token = c_parser_peek_token (parser);
1742 enum_id = token->value;
1743 /* Set the location in case we create a decl now. */
1744 c_parser_set_source_position_from_token (token);
1745 c_parser_consume_token (parser);
1746 if (c_parser_next_token_is (parser, CPP_EQ))
1748 c_parser_consume_token (parser);
1749 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1752 enum_value = NULL_TREE;
1753 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1754 TREE_CHAIN (enum_decl) = values;
1757 if (c_parser_next_token_is (parser, CPP_COMMA))
1760 c_parser_consume_token (parser);
1762 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1764 if (seen_comma && pedantic && !flag_isoc99)
1765 pedwarn ("comma at end of enumerator list");
1766 c_parser_consume_token (parser);
1771 c_parser_error (parser, "expected %<,%> or %<}%>");
1772 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1773 values = error_mark_node;
1777 postfix_attrs = c_parser_attributes (parser);
1778 ret.spec = finish_enum (type, nreverse (values),
1779 chainon (attrs, postfix_attrs));
1780 ret.kind = ctsk_tagdef;
1785 c_parser_error (parser, "expected %<{%>");
1786 ret.spec = error_mark_node;
1787 ret.kind = ctsk_tagref;
1790 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1791 /* In ISO C, enumerated types can be referred to only if already
1793 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1794 pedwarn ("ISO C forbids forward references to %<enum%> types");
1798 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1800 struct-or-union-specifier:
1801 struct-or-union attributes[opt] identifier[opt]
1802 { struct-contents } attributes[opt]
1803 struct-or-union attributes[opt] identifier
1806 struct-declaration-list
1808 struct-declaration-list:
1809 struct-declaration ;
1810 struct-declaration-list struct-declaration ;
1817 struct-declaration-list struct-declaration
1819 struct-declaration-list:
1820 struct-declaration-list ;
1823 (Note that in the syntax here, unlike that in ISO C, the semicolons
1824 are included here rather than in struct-declaration, in order to
1825 describe the syntax with extra semicolons and missing semicolon at
1830 struct-declaration-list:
1831 @defs ( class-name )
1833 (Note this does not include a trailing semicolon, but can be
1834 followed by further declarations, and gets a pedwarn-if-pedantic
1835 when followed by a semicolon.) */
1837 static struct c_typespec
1838 c_parser_struct_or_union_specifier (c_parser *parser)
1840 struct c_typespec ret;
1842 tree ident = NULL_TREE;
1843 enum tree_code code;
1844 switch (c_parser_peek_token (parser)->keyword)
1855 c_parser_consume_token (parser);
1856 attrs = c_parser_attributes (parser);
1857 /* Set the location in case we create a decl now. */
1858 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1859 if (c_parser_next_token_is (parser, CPP_NAME))
1861 ident = c_parser_peek_token (parser)->value;
1862 c_parser_consume_token (parser);
1864 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1866 /* Parse a struct or union definition. Start the scope of the
1867 tag before parsing components. */
1868 tree type = start_struct (code, ident);
1870 /* We chain the components in reverse order, then put them in
1871 forward order at the end. Each struct-declaration may
1872 declare multiple components (comma-separated), so we must use
1873 chainon to join them, although when parsing each
1874 struct-declaration we can use TREE_CHAIN directly.
1876 The theory behind all this is that there will be more
1877 semicolon separated fields than comma separated fields, and
1878 so we'll be minimizing the number of node traversals required
1880 tree contents = NULL_TREE;
1881 c_parser_consume_token (parser);
1882 /* Handle the Objective-C @defs construct,
1883 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1884 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1887 gcc_assert (c_dialect_objc ());
1888 c_parser_consume_token (parser);
1889 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1891 if (c_parser_next_token_is (parser, CPP_NAME)
1892 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1894 name = c_parser_peek_token (parser)->value;
1895 c_parser_consume_token (parser);
1899 c_parser_error (parser, "expected class name");
1900 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1903 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1905 contents = nreverse (objc_get_class_ivars (name));
1908 /* Parse the struct-declarations and semicolons. Problems with
1909 semicolons are diagnosed here; empty structures are diagnosed
1914 /* Parse any stray semicolon. */
1915 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1918 pedwarn ("extra semicolon in struct or union specified");
1919 c_parser_consume_token (parser);
1922 /* Stop if at the end of the struct or union contents. */
1923 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1925 c_parser_consume_token (parser);
1928 /* Accept #pragmas at struct scope. */
1929 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1931 c_parser_pragma (parser, pragma_external);
1934 /* Parse some comma-separated declarations, but not the
1935 trailing semicolon if any. */
1936 decls = c_parser_struct_declaration (parser);
1937 contents = chainon (decls, contents);
1938 /* If no semicolon follows, either we have a parse error or
1939 are at the end of the struct or union and should
1941 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1942 c_parser_consume_token (parser);
1945 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1946 pedwarn ("no semicolon at end of struct or union");
1949 c_parser_error (parser, "expected %<;%>");
1950 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1955 postfix_attrs = c_parser_attributes (parser);
1956 ret.spec = finish_struct (type, nreverse (contents),
1957 chainon (attrs, postfix_attrs));
1958 ret.kind = ctsk_tagdef;
1963 c_parser_error (parser, "expected %<{%>");
1964 ret.spec = error_mark_node;
1965 ret.kind = ctsk_tagref;
1968 ret = parser_xref_tag (code, ident);
1972 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1973 the trailing semicolon.
1976 specifier-qualifier-list struct-declarator-list
1978 specifier-qualifier-list:
1979 type-specifier specifier-qualifier-list[opt]
1980 type-qualifier specifier-qualifier-list[opt]
1981 attributes specifier-qualifier-list[opt]
1983 struct-declarator-list:
1985 struct-declarator-list , attributes[opt] struct-declarator
1988 declarator attributes[opt]
1989 declarator[opt] : constant-expression attributes[opt]
1994 __extension__ struct-declaration
1995 specifier-qualifier-list
1997 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1998 of attributes where shown is a GNU extension. In GNU C, we accept
1999 any expression without commas in the syntax (assignment
2000 expressions, not just conditional expressions); assignment
2001 expressions will be diagnosed as non-constant. */
2004 c_parser_struct_declaration (c_parser *parser)
2006 struct c_declspecs *specs;
2008 tree all_prefix_attrs;
2010 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2014 ext = disable_extension_diagnostics ();
2015 c_parser_consume_token (parser);
2016 decl = c_parser_struct_declaration (parser);
2017 restore_extension_diagnostics (ext);
2020 specs = build_null_declspecs ();
2021 c_parser_declspecs (parser, specs, false, true, true);
2024 if (!specs->declspecs_seen_p)
2026 c_parser_error (parser, "expected specifier-qualifier-list");
2029 finish_declspecs (specs);
2030 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2033 if (!specs->type_seen_p)
2036 pedwarn ("ISO C forbids member declarations with no members");
2037 shadow_tag_warned (specs, pedantic);
2042 /* Support for unnamed structs or unions as members of
2043 structs or unions (which is [a] useful and [b] supports
2046 ret = grokfield (build_id_declarator (NULL_TREE), specs,
2049 decl_attributes (&ret, attrs, 0);
2053 pending_xref_error ();
2054 prefix_attrs = specs->attrs;
2055 all_prefix_attrs = prefix_attrs;
2056 specs->attrs = NULL_TREE;
2060 /* Declaring one or more declarators or un-named bit-fields. */
2061 struct c_declarator *declarator;
2063 if (c_parser_next_token_is (parser, CPP_COLON))
2064 declarator = build_id_declarator (NULL_TREE);
2066 declarator = c_parser_declarator (parser, specs->type_seen_p,
2067 C_DTR_NORMAL, &dummy);
2068 if (declarator == NULL)
2070 c_parser_skip_to_end_of_block_or_statement (parser);
2073 if (c_parser_next_token_is (parser, CPP_COLON)
2074 || c_parser_next_token_is (parser, CPP_COMMA)
2075 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2076 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2077 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2079 tree postfix_attrs = NULL_TREE;
2080 tree width = NULL_TREE;
2082 if (c_parser_next_token_is (parser, CPP_COLON))
2084 c_parser_consume_token (parser);
2085 width = c_parser_expr_no_commas (parser, NULL).value;
2087 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2088 postfix_attrs = c_parser_attributes (parser);
2089 d = grokfield (declarator, specs, width, &all_prefix_attrs);
2090 decl_attributes (&d, chainon (postfix_attrs,
2091 all_prefix_attrs), 0);
2092 TREE_CHAIN (d) = decls;
2094 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2095 all_prefix_attrs = chainon (c_parser_attributes (parser),
2098 all_prefix_attrs = prefix_attrs;
2099 if (c_parser_next_token_is (parser, CPP_COMMA))
2100 c_parser_consume_token (parser);
2101 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2102 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2104 /* Semicolon consumed in caller. */
2109 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2115 c_parser_error (parser,
2116 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2117 "%<__attribute__%>");
2124 /* Parse a typeof specifier (a GNU extension).
2127 typeof ( expression )
2128 typeof ( type-name )
2131 static struct c_typespec
2132 c_parser_typeof_specifier (c_parser *parser)
2134 struct c_typespec ret;
2135 ret.kind = ctsk_typeof;
2136 ret.spec = error_mark_node;
2137 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2138 c_parser_consume_token (parser);
2141 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2147 if (c_parser_next_token_starts_typename (parser))
2149 struct c_type_name *type = c_parser_type_name (parser);
2154 ret.spec = groktypename (type);
2155 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2161 struct c_expr expr = c_parser_expression (parser);
2164 if (TREE_CODE (expr.value) == COMPONENT_REF
2165 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2166 error ("%<typeof%> applied to a bit-field");
2167 ret.spec = TREE_TYPE (expr.value);
2168 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2169 /* This should be returned with the type so that when the type
2170 is evaluated, this can be evaluated. For now, we avoid
2171 evaluation when the context might. */
2172 if (!skip_evaluation && was_vm)
2174 tree e = expr.value;
2176 /* If the expression is not of a type to which we cannot assign a line
2177 number, wrap the thing in a no-op NOP_EXPR. */
2178 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2179 e = build1 (NOP_EXPR, void_type_node, e);
2181 if (CAN_HAVE_LOCATION_P (e))
2182 SET_EXPR_LOCATION (e, input_location);
2186 pop_maybe_used (was_vm);
2188 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2192 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2193 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2194 be redeclared; otherwise it may not. KIND indicates which kind of
2195 declarator is wanted. Returns a valid declarator except in the
2196 case of a syntax error in which case NULL is returned. *SEEN_ID is
2197 set to true if an identifier being declared is seen; this is used
2198 to diagnose bad forms of abstract array declarators and to
2199 determine whether an identifier list is syntactically permitted.
2202 pointer[opt] direct-declarator
2206 ( attributes[opt] declarator )
2207 direct-declarator array-declarator
2208 direct-declarator ( parameter-type-list )
2209 direct-declarator ( identifier-list[opt] )
2212 * type-qualifier-list[opt]
2213 * type-qualifier-list[opt] pointer
2215 type-qualifier-list:
2218 type-qualifier-list type-qualifier
2219 type-qualifier-list attributes
2221 parameter-type-list:
2223 parameter-list , ...
2226 parameter-declaration
2227 parameter-list , parameter-declaration
2229 parameter-declaration:
2230 declaration-specifiers declarator attributes[opt]
2231 declaration-specifiers abstract-declarator[opt] attributes[opt]
2235 identifier-list , identifier
2237 abstract-declarator:
2239 pointer[opt] direct-abstract-declarator
2241 direct-abstract-declarator:
2242 ( attributes[opt] abstract-declarator )
2243 direct-abstract-declarator[opt] array-declarator
2244 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2249 direct-declarator ( parameter-forward-declarations
2250 parameter-type-list[opt] )
2252 direct-abstract-declarator:
2253 direct-abstract-declarator[opt] ( parameter-forward-declarations
2254 parameter-type-list[opt] )
2256 parameter-forward-declarations:
2258 parameter-forward-declarations parameter-list ;
2260 The uses of attributes shown above are GNU extensions.
2262 Some forms of array declarator are not included in C99 in the
2263 syntax for abstract declarators; these are disallowed elsewhere.
2264 This may be a defect (DR#289).
2266 This function also accepts an omitted abstract declarator as being
2267 an abstract declarator, although not part of the formal syntax. */
2269 static struct c_declarator *
2270 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2273 /* Parse any initial pointer part. */
2274 if (c_parser_next_token_is (parser, CPP_MULT))
2276 struct c_declspecs *quals_attrs = build_null_declspecs ();
2277 struct c_declarator *inner;
2278 c_parser_consume_token (parser);
2279 c_parser_declspecs (parser, quals_attrs, false, false, true);
2280 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2284 return make_pointer_declarator (quals_attrs, inner);
2286 /* Now we have a direct declarator, direct abstract declarator or
2287 nothing (which counts as a direct abstract declarator here). */
2288 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2291 /* Parse a direct declarator or direct abstract declarator; arguments
2292 as c_parser_declarator. */
2294 static struct c_declarator *
2295 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2298 /* The direct declarator must start with an identifier (possibly
2299 omitted) or a parenthesized declarator (possibly abstract). In
2300 an ordinary declarator, initial parentheses must start a
2301 parenthesized declarator. In an abstract declarator or parameter
2302 declarator, they could start a parenthesized declarator or a
2303 parameter list. To tell which, the open parenthesis and any
2304 following attributes must be read. If a declaration specifier
2305 follows, then it is a parameter list; if the specifier is a
2306 typedef name, there might be an ambiguity about redeclaring it,
2307 which is resolved in the direction of treating it as a typedef
2308 name. If a close parenthesis follows, it is also an empty
2309 parameter list, as the syntax does not permit empty abstract
2310 declarators. Otherwise, it is a parenthesized declarator (in
2311 which case the analysis may be repeated inside it, recursively).
2313 ??? There is an ambiguity in a parameter declaration "int
2314 (__attribute__((foo)) x)", where x is not a typedef name: it
2315 could be an abstract declarator for a function, or declare x with
2316 parentheses. The proper resolution of this ambiguity needs
2317 documenting. At present we follow an accident of the old
2318 parser's implementation, whereby the first parameter must have
2319 some declaration specifiers other than just attributes. Thus as
2320 a parameter declaration it is treated as a parenthesized
2321 parameter named x, and as an abstract declarator it is
2324 ??? Also following the old parser, attributes inside an empty
2325 parameter list are ignored, making it a list not yielding a
2326 prototype, rather than giving an error or making it have one
2327 parameter with implicit type int.
2329 ??? Also following the old parser, typedef names may be
2330 redeclared in declarators, but not Objective-C class names. */
2332 if (kind != C_DTR_ABSTRACT
2333 && c_parser_next_token_is (parser, CPP_NAME)
2335 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2336 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2338 struct c_declarator *inner
2339 = build_id_declarator (c_parser_peek_token (parser)->value);
2341 inner->id_loc = c_parser_peek_token (parser)->location;
2342 c_parser_consume_token (parser);
2343 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2346 if (kind != C_DTR_NORMAL
2347 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2349 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2350 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2353 /* Either we are at the end of an abstract declarator, or we have
2356 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2359 struct c_declarator *inner;
2360 c_parser_consume_token (parser);
2361 attrs = c_parser_attributes (parser);
2362 if (kind != C_DTR_NORMAL
2363 && (c_parser_next_token_starts_declspecs (parser)
2364 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2366 struct c_arg_info *args
2367 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2374 = build_function_declarator (args,
2375 build_id_declarator (NULL_TREE));
2376 return c_parser_direct_declarator_inner (parser, *seen_id,
2380 /* A parenthesized declarator. */
2381 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2382 if (inner != NULL && attrs != NULL)
2383 inner = build_attrs_declarator (attrs, inner);
2384 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2386 c_parser_consume_token (parser);
2390 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2394 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2401 if (kind == C_DTR_NORMAL)
2403 c_parser_error (parser, "expected identifier or %<(%>");
2407 return build_id_declarator (NULL_TREE);
2411 /* Parse part of a direct declarator or direct abstract declarator,
2412 given that some (in INNER) has already been parsed; ID_PRESENT is
2413 true if an identifier is present, false for an abstract
2416 static struct c_declarator *
2417 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2418 struct c_declarator *inner)
2420 /* Parse a sequence of array declarators and parameter lists. */
2421 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2423 struct c_declarator *declarator;
2424 struct c_declspecs *quals_attrs = build_null_declspecs ();
2428 c_parser_consume_token (parser);
2429 c_parser_declspecs (parser, quals_attrs, false, false, true);
2430 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2432 c_parser_consume_token (parser);
2433 if (static_seen && !quals_attrs->declspecs_seen_p)
2434 c_parser_declspecs (parser, quals_attrs, false, false, true);
2435 if (!quals_attrs->declspecs_seen_p)
2437 /* If "static" is present, there must be an array dimension.
2438 Otherwise, there may be a dimension, "*", or no
2443 dimen = c_parser_expr_no_commas (parser, NULL).value;
2447 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2452 else if (c_parser_next_token_is (parser, CPP_MULT))
2454 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2458 c_parser_consume_token (parser);
2463 dimen = c_parser_expr_no_commas (parser, NULL).value;
2469 dimen = c_parser_expr_no_commas (parser, NULL).value;
2472 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2473 c_parser_consume_token (parser);
2476 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2480 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2482 if (declarator == NULL)
2484 inner = set_array_declarator_inner (declarator, inner, !id_present);
2485 return c_parser_direct_declarator_inner (parser, id_present, inner);
2487 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2490 struct c_arg_info *args;
2491 c_parser_consume_token (parser);
2492 attrs = c_parser_attributes (parser);
2493 args = c_parser_parms_declarator (parser, id_present, attrs);
2498 inner = build_function_declarator (args, inner);
2499 return c_parser_direct_declarator_inner (parser, id_present, inner);
2505 /* Parse a parameter list or identifier list, including the closing
2506 parenthesis but not the opening one. ATTRS are the attributes at
2507 the start of the list. ID_LIST_OK is true if an identifier list is
2508 acceptable; such a list must not have attributes at the start. */
2510 static struct c_arg_info *
2511 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2514 declare_parm_level ();
2515 /* If the list starts with an identifier, it is an identifier list.
2516 Otherwise, it is either a prototype list or an empty list. */
2519 && c_parser_next_token_is (parser, CPP_NAME)
2520 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2522 tree list = NULL_TREE, *nextp = &list;
2523 while (c_parser_next_token_is (parser, CPP_NAME)
2524 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2526 *nextp = build_tree_list (NULL_TREE,
2527 c_parser_peek_token (parser)->value);
2528 nextp = & TREE_CHAIN (*nextp);
2529 c_parser_consume_token (parser);
2530 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2532 c_parser_consume_token (parser);
2533 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2535 c_parser_error (parser, "expected identifier");
2539 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2541 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2546 ret->pending_sizes = 0;
2547 ret->had_vla_unspec = 0;
2548 c_parser_consume_token (parser);
2554 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2562 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2568 /* Parse a parameter list (possibly empty), including the closing
2569 parenthesis but not the opening one. ATTRS are the attributes at
2570 the start of the list. */
2572 static struct c_arg_info *
2573 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2575 bool good_parm = false;
2576 /* ??? Following the old parser, forward parameter declarations may
2577 use abstract declarators, and if no real parameter declarations
2578 follow the forward declarations then this is not diagnosed. Also
2579 note as above that attributes are ignored as the only contents of
2580 the parentheses, or as the only contents after forward
2582 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2584 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2589 ret->pending_sizes = 0;
2590 ret->had_vla_unspec = 0;
2591 c_parser_consume_token (parser);
2594 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2596 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2600 ret->pending_sizes = 0;
2601 ret->had_vla_unspec = 0;
2602 /* Suppress -Wold-style-definition for this case. */
2603 ret->types = error_mark_node;
2604 error ("ISO C requires a named argument before %<...%>");
2605 c_parser_consume_token (parser);
2606 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2608 c_parser_consume_token (parser);
2613 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2618 /* Nonempty list of parameters, either terminated with semicolon
2619 (forward declarations; recurse) or with close parenthesis (normal
2620 function) or with ", ... )" (variadic function). */
2623 /* Parse a parameter. */
2624 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2629 push_parm_decl (parm);
2631 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2634 c_parser_consume_token (parser);
2635 mark_forward_parm_decls ();
2636 new_attrs = c_parser_attributes (parser);
2637 return c_parser_parms_list_declarator (parser, new_attrs);
2639 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2641 c_parser_consume_token (parser);
2643 return get_parm_info (false);
2646 struct c_arg_info *ret
2647 = XOBNEW (&parser_obstack, struct c_arg_info);
2652 ret->pending_sizes = 0;
2653 ret->had_vla_unspec = 0;
2657 if (!c_parser_require (parser, CPP_COMMA,
2658 "expected %<;%>, %<,%> or %<)%>"))
2660 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2663 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2665 c_parser_consume_token (parser);
2666 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2668 c_parser_consume_token (parser);
2670 return get_parm_info (true);
2673 struct c_arg_info *ret
2674 = XOBNEW (&parser_obstack, struct c_arg_info);
2679 ret->pending_sizes = 0;
2680 ret->had_vla_unspec = 0;
2686 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2694 /* Parse a parameter declaration. ATTRS are the attributes at the
2695 start of the declaration if it is the first parameter. */
2697 static struct c_parm *
2698 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2700 struct c_declspecs *specs;
2701 struct c_declarator *declarator;
2703 tree postfix_attrs = NULL_TREE;
2705 if (!c_parser_next_token_starts_declspecs (parser))
2707 /* ??? In some Objective-C cases '...' isn't applicable so there
2708 should be a different message. */
2709 c_parser_error (parser,
2710 "expected declaration specifiers or %<...%>");
2711 c_parser_skip_to_end_of_parameter (parser);
2714 specs = build_null_declspecs ();
2717 declspecs_add_attrs (specs, attrs);
2720 c_parser_declspecs (parser, specs, true, true, true);
2721 finish_declspecs (specs);
2722 pending_xref_error ();
2723 prefix_attrs = specs->attrs;
2724 specs->attrs = NULL_TREE;
2725 declarator = c_parser_declarator (parser, specs->type_seen_p,
2726 C_DTR_PARM, &dummy);
2727 if (declarator == NULL)
2729 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2732 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2733 postfix_attrs = c_parser_attributes (parser);
2734 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2738 /* Parse a string literal in an asm expression. It should not be
2739 translated, and wide string literals are an error although
2740 permitted by the syntax. This is a GNU extension.
2745 ??? At present, following the old parser, the caller needs to have
2746 set lex_untranslated_string to 1. It would be better to follow the
2747 C++ parser rather than using this kludge. */
2750 c_parser_asm_string_literal (c_parser *parser)
2753 if (c_parser_next_token_is (parser, CPP_STRING))
2755 str = c_parser_peek_token (parser)->value;
2756 c_parser_consume_token (parser);
2758 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2760 error ("wide string literal in %<asm%>");
2761 str = build_string (1, "");
2762 c_parser_consume_token (parser);
2766 c_parser_error (parser, "expected string literal");
2772 /* Parse a simple asm expression. This is used in restricted
2773 contexts, where a full expression with inputs and outputs does not
2774 make sense. This is a GNU extension.
2777 asm ( asm-string-literal )
2781 c_parser_simple_asm_expr (c_parser *parser)
2784 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2785 /* ??? Follow the C++ parser rather than using the
2786 lex_untranslated_string kludge. */
2787 parser->lex_untranslated_string = true;
2788 c_parser_consume_token (parser);
2789 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2791 parser->lex_untranslated_string = false;
2794 str = c_parser_asm_string_literal (parser);
2795 parser->lex_untranslated_string = false;
2796 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2798 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2804 /* Parse (possibly empty) attributes. This is a GNU extension.
2808 attributes attribute
2811 __attribute__ ( ( attribute-list ) )
2815 attribute_list , attrib
2820 any-word ( identifier )
2821 any-word ( identifier , nonempty-expr-list )
2822 any-word ( expr-list )
2824 where the "identifier" must not be declared as a type, and
2825 "any-word" may be any identifier (including one declared as a
2826 type), a reserved word storage class specifier, type specifier or
2827 type qualifier. ??? This still leaves out most reserved keywords
2828 (following the old parser), shouldn't we include them, and why not
2829 allow identifiers declared as types to start the arguments? */
2832 c_parser_attributes (c_parser *parser)
2834 tree attrs = NULL_TREE;
2835 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2837 /* ??? Follow the C++ parser rather than using the
2838 lex_untranslated_string kludge. */
2839 parser->lex_untranslated_string = true;
2840 c_parser_consume_token (parser);
2841 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2843 parser->lex_untranslated_string = false;
2846 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2848 parser->lex_untranslated_string = false;
2849 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2852 /* Parse the attribute list. */
2853 while (c_parser_next_token_is (parser, CPP_COMMA)
2854 || c_parser_next_token_is (parser, CPP_NAME)
2855 || c_parser_next_token_is (parser, CPP_KEYWORD))
2857 tree attr, attr_name, attr_args;
2858 if (c_parser_next_token_is (parser, CPP_COMMA))
2860 c_parser_consume_token (parser);
2863 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2865 /* ??? See comment above about what keywords are
2868 switch (c_parser_peek_token (parser)->keyword)
2906 attr_name = c_parser_peek_token (parser)->value;
2907 c_parser_consume_token (parser);
2908 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2910 attr = build_tree_list (attr_name, NULL_TREE);
2911 attrs = chainon (attrs, attr);
2914 c_parser_consume_token (parser);
2915 /* Parse the attribute contents. If they start with an
2916 identifier which is followed by a comma or close
2917 parenthesis, then the arguments start with that
2918 identifier; otherwise they are an expression list. */
2919 if (c_parser_next_token_is (parser, CPP_NAME)
2920 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2921 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2922 || (c_parser_peek_2nd_token (parser)->type
2923 == CPP_CLOSE_PAREN)))
2925 tree arg1 = c_parser_peek_token (parser)->value;
2926 c_parser_consume_token (parser);
2927 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2928 attr_args = build_tree_list (NULL_TREE, arg1);
2931 c_parser_consume_token (parser);
2932 attr_args = tree_cons (NULL_TREE, arg1,
2933 c_parser_expr_list (parser, false));
2938 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2939 attr_args = NULL_TREE;
2941 attr_args = c_parser_expr_list (parser, false);
2943 attr = build_tree_list (attr_name, attr_args);
2944 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2945 c_parser_consume_token (parser);
2948 parser->lex_untranslated_string = false;
2949 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2953 attrs = chainon (attrs, attr);
2955 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2956 c_parser_consume_token (parser);
2959 parser->lex_untranslated_string = false;
2960 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2964 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2965 c_parser_consume_token (parser);
2968 parser->lex_untranslated_string = false;
2969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2973 parser->lex_untranslated_string = false;
2978 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2981 specifier-qualifier-list abstract-declarator[opt]
2984 static struct c_type_name *
2985 c_parser_type_name (c_parser *parser)
2987 struct c_declspecs *specs = build_null_declspecs ();
2988 struct c_declarator *declarator;
2989 struct c_type_name *ret;
2991 c_parser_declspecs (parser, specs, false, true, true);
2992 if (!specs->declspecs_seen_p)
2994 c_parser_error (parser, "expected specifier-qualifier-list");
2997 pending_xref_error ();
2998 finish_declspecs (specs);
2999 declarator = c_parser_declarator (parser, specs->type_seen_p,
3000 C_DTR_ABSTRACT, &dummy);
3001 if (declarator == NULL)
3003 ret = XOBNEW (&parser_obstack, struct c_type_name);
3005 ret->declarator = declarator;
3009 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3012 assignment-expression
3013 { initializer-list }
3014 { initializer-list , }
3017 designation[opt] initializer
3018 initializer-list , designation[opt] initializer
3025 designator-list designator
3032 [ constant-expression ]
3044 [ constant-expression ... constant-expression ]
3046 Any expression without commas is accepted in the syntax for the
3047 constant-expressions, with non-constant expressions rejected later.
3049 This function is only used for top-level initializers; for nested
3050 ones, see c_parser_initval. */
3052 static struct c_expr
3053 c_parser_initializer (c_parser *parser)
3055 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3056 return c_parser_braced_init (parser, NULL_TREE, false);
3060 ret = c_parser_expr_no_commas (parser, NULL);
3061 if (TREE_CODE (ret.value) != STRING_CST
3062 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3063 ret = default_function_array_conversion (ret);
3068 /* Parse a braced initializer list. TYPE is the type specified for a
3069 compound literal, and NULL_TREE for other initializers and for
3070 nested braced lists. NESTED_P is true for nested braced lists,
3071 false for the list of a compound literal or the list that is the
3072 top-level initializer in a declaration. */
3074 static struct c_expr
3075 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3077 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3078 c_parser_consume_token (parser);
3080 push_init_level (0);
3082 really_start_incremental_init (type);
3083 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3086 pedwarn ("ISO C forbids empty initializer braces");
3090 /* Parse a non-empty initializer list, possibly with a trailing
3094 c_parser_initelt (parser);
3097 if (c_parser_next_token_is (parser, CPP_COMMA))
3098 c_parser_consume_token (parser);
3101 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3105 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3108 ret.value = error_mark_node;
3109 ret.original_code = ERROR_MARK;
3110 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3113 c_parser_consume_token (parser);
3114 return pop_init_level (0);
3117 /* Parse a nested initializer, including designators. */
3120 c_parser_initelt (c_parser *parser)
3122 /* Parse any designator or designator list. A single array
3123 designator may have the subsequent "=" omitted in GNU C, but a
3124 longer list or a structure member designator may not. */
3125 if (c_parser_next_token_is (parser, CPP_NAME)
3126 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3128 /* Old-style structure member designator. */
3129 set_init_label (c_parser_peek_token (parser)->value);
3131 pedwarn ("obsolete use of designated initializer with %<:%>");
3132 c_parser_consume_token (parser);
3133 c_parser_consume_token (parser);
3137 /* des_seen is 0 if there have been no designators, 1 if there
3138 has been a single array designator and 2 otherwise. */
3140 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3141 || c_parser_next_token_is (parser, CPP_DOT))
3143 int des_prev = des_seen;
3146 if (c_parser_next_token_is (parser, CPP_DOT))
3149 c_parser_consume_token (parser);
3150 if (c_parser_next_token_is (parser, CPP_NAME))
3152 set_init_label (c_parser_peek_token (parser)->value);
3153 c_parser_consume_token (parser);
3158 init.value = error_mark_node;
3159 init.original_code = ERROR_MARK;
3160 c_parser_error (parser, "expected identifier");
3161 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3162 process_init_element (init);
3169 /* ??? Following the old parser, [ objc-receiver
3170 objc-message-args ] is accepted as an initializer,
3171 being distinguished from a designator by what follows
3172 the first assignment expression inside the square
3173 brackets, but after a first array designator a
3174 subsequent square bracket is for Objective-C taken to
3175 start an expression, using the obsolete form of
3176 designated initializer without '=', rather than
3177 possibly being a second level of designation: in LALR
3178 terms, the '[' is shifted rather than reducing
3179 designator to designator-list. */
3180 if (des_prev == 1 && c_dialect_objc ())
3182 des_seen = des_prev;
3185 if (des_prev == 0 && c_dialect_objc ())
3187 /* This might be an array designator or an
3188 Objective-C message expression. If the former,
3189 continue parsing here; if the latter, parse the
3190 remainder of the initializer given the starting
3191 primary-expression. ??? It might make sense to
3192 distinguish when des_prev == 1 as well; see
3193 previous comment. */
3195 struct c_expr mexpr;
3196 c_parser_consume_token (parser);
3197 if (c_parser_peek_token (parser)->type == CPP_NAME
3198 && ((c_parser_peek_token (parser)->id_kind
3200 || (c_parser_peek_token (parser)->id_kind
3201 == C_ID_CLASSNAME)))
3203 /* Type name receiver. */
3204 tree id = c_parser_peek_token (parser)->value;
3205 c_parser_consume_token (parser);
3206 rec = objc_get_class_reference (id);
3207 goto parse_message_args;
3209 first = c_parser_expr_no_commas (parser, NULL).value;
3210 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3211 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3212 goto array_desig_after_first;
3213 /* Expression receiver. So far only one part
3214 without commas has been parsed; there might be
3215 more of the expression. */
3217 while (c_parser_next_token_is (parser, CPP_COMMA))
3220 c_parser_consume_token (parser);
3221 next = c_parser_expr_no_commas (parser, NULL);
3222 next = default_function_array_conversion (next);
3223 rec = build_compound_expr (rec, next.value);
3226 /* Now parse the objc-message-args. */
3227 args = c_parser_objc_message_args (parser);
3228 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3231 = objc_build_message_expr (build_tree_list (rec, args));
3232 mexpr.original_code = ERROR_MARK;
3233 /* Now parse and process the remainder of the
3234 initializer, starting with this message
3235 expression as a primary-expression. */
3236 c_parser_initval (parser, &mexpr);
3239 c_parser_consume_token (parser);
3240 first = c_parser_expr_no_commas (parser, NULL).value;
3241 array_desig_after_first:
3242 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3244 c_parser_consume_token (parser);
3245 second = c_parser_expr_no_commas (parser, NULL).value;
3249 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3251 c_parser_consume_token (parser);
3252 set_init_index (first, second);
3253 if (pedantic && second)
3254 pedwarn ("ISO C forbids specifying range of "
3255 "elements to initialize");
3258 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3264 if (c_parser_next_token_is (parser, CPP_EQ))
3266 if (pedantic && !flag_isoc99)
3267 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3268 c_parser_consume_token (parser);
3275 pedwarn ("obsolete use of designated initializer "
3281 init.value = error_mark_node;
3282 init.original_code = ERROR_MARK;
3283 c_parser_error (parser, "expected %<=%>");
3284 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3285 process_init_element (init);
3291 c_parser_initval (parser, NULL);
3294 /* Parse a nested initializer; as c_parser_initializer but parses
3295 initializers within braced lists, after any designators have been
3296 applied. If AFTER is not NULL then it is an Objective-C message
3297 expression which is the primary-expression starting the
3301 c_parser_initval (c_parser *parser, struct c_expr *after)
3304 gcc_assert (!after || c_dialect_objc ());
3305 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3306 init = c_parser_braced_init (parser, NULL_TREE, true);
3309 init = c_parser_expr_no_commas (parser, after);
3310 if (init.value != NULL_TREE
3311 && TREE_CODE (init.value) != STRING_CST
3312 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3313 init = default_function_array_conversion (init);
3315 process_init_element (init);
3318 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3322 { block-item-list[opt] }
3323 { label-declarations block-item-list }
3327 block-item-list block-item
3339 { label-declarations block-item-list }
3342 __extension__ nested-declaration
3343 nested-function-definition
3347 label-declarations label-declaration
3350 __label__ identifier-list ;
3352 Allowing the mixing of declarations and code is new in C99. The
3353 GNU syntax also permits (not shown above) labels at the end of
3354 compound statements, which yield an error. We don't allow labels
3355 on declarations; this might seem like a natural extension, but
3356 there would be a conflict between attributes on the label and
3357 prefix attributes on the declaration. ??? The syntax follows the
3358 old parser in requiring something after label declarations.
3359 Although they are erroneous if the labels declared aren't defined,
3360 is it useful for the syntax to be this way?
3372 c_parser_compound_statement (c_parser *parser)
3375 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3376 return error_mark_node;
3377 stmt = c_begin_compound_stmt (true);
3378 c_parser_compound_statement_nostart (parser);
3379 return c_end_compound_stmt (stmt, true);
3382 /* Parse a compound statement except for the opening brace. This is
3383 used for parsing both compound statements and statement expressions
3384 (which follow different paths to handling the opening). */
3387 c_parser_compound_statement_nostart (c_parser *parser)
3389 bool last_stmt = false;
3390 bool last_label = false;
3391 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3393 c_parser_consume_token (parser);
3396 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3398 /* Read zero or more forward-declarations for labels that nested
3399 functions can jump to. */
3400 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3402 c_parser_consume_token (parser);
3403 /* Any identifiers, including those declared as type names,
3408 if (c_parser_next_token_is_not (parser, CPP_NAME))
3410 c_parser_error (parser, "expected identifier");
3414 = declare_label (c_parser_peek_token (parser)->value);
3415 C_DECLARED_LABEL_FLAG (label) = 1;
3416 add_stmt (build_stmt (DECL_EXPR, label));
3417 c_parser_consume_token (parser);
3418 if (c_parser_next_token_is (parser, CPP_COMMA))
3419 c_parser_consume_token (parser);
3423 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3425 /* ??? Locating this diagnostic on the token after the
3426 declarations end follows the old parser, but it might be
3427 better to locate it where the declarations start instead. */
3429 pedwarn ("ISO C forbids label declarations");
3431 /* We must now have at least one statement, label or declaration. */
3432 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3434 c_parser_error (parser, "expected declaration or statement");
3435 c_parser_consume_token (parser);
3438 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3440 location_t loc = c_parser_peek_token (parser)->location;
3441 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3442 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3443 || (c_parser_next_token_is (parser, CPP_NAME)
3444 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3448 c_parser_label (parser);
3450 else if (!last_label
3451 && c_parser_next_token_starts_declspecs (parser))
3454 c_parser_declaration_or_fndef (parser, true, true, true, true);
3456 && ((pedantic && !flag_isoc99)
3457 || warn_declaration_after_statement))
3458 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3462 else if (!last_label
3463 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3465 /* __extension__ can start a declaration, but is also an
3466 unary operator that can start an expression. Consume all
3467 but the last of a possible series of __extension__ to
3469 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3470 && (c_parser_peek_2nd_token (parser)->keyword
3472 c_parser_consume_token (parser);
3473 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3476 ext = disable_extension_diagnostics ();
3477 c_parser_consume_token (parser);
3479 c_parser_declaration_or_fndef (parser, true, true, true, true);
3480 /* Following the old parser, __extension__ does not
3481 disable this diagnostic. */
3482 restore_extension_diagnostics (ext);
3484 && ((pedantic && !flag_isoc99)
3485 || warn_declaration_after_statement))
3486 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3493 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3495 /* External pragmas, and some omp pragmas, are not associated
3496 with regular c code, and so are not to be considered statements
3497 syntactically. This ensures that the user doesn't put them
3498 places that would turn into syntax errors if the directive
3500 if (c_parser_pragma (parser, pragma_compound))
3501 last_label = false, last_stmt = true;
3503 else if (c_parser_next_token_is (parser, CPP_EOF))
3505 c_parser_error (parser, "expected declaration or statement");
3513 c_parser_statement_after_labels (parser);
3516 parser->error = false;
3519 error ("label at end of compound statement");
3520 c_parser_consume_token (parser);
3523 /* Parse a label (C90 6.6.1, C99 6.8.1).
3526 identifier : attributes[opt]
3527 case constant-expression :
3533 case constant-expression ... constant-expression :
3535 The use of attributes on labels is a GNU extension. The syntax in
3536 GNU C accepts any expressions without commas, non-constant
3537 expressions being rejected later. */
3540 c_parser_label (c_parser *parser)
3542 location_t loc1 = c_parser_peek_token (parser)->location;
3543 tree label = NULL_TREE;
3544 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3547 c_parser_consume_token (parser);
3548 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3549 if (c_parser_next_token_is (parser, CPP_COLON))
3551 c_parser_consume_token (parser);
3552 label = do_case (exp1, NULL_TREE);
3554 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3556 c_parser_consume_token (parser);
3557 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3558 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3559 label = do_case (exp1, exp2);
3562 c_parser_error (parser, "expected %<:%> or %<...%>");
3564 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3566 c_parser_consume_token (parser);
3567 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3568 label = do_case (NULL_TREE, NULL_TREE);
3572 tree name = c_parser_peek_token (parser)->value;
3576 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3577 c_parser_consume_token (parser);
3578 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3579 loc2 = c_parser_peek_token (parser)->location;
3580 c_parser_consume_token (parser);
3581 attrs = c_parser_attributes (parser);
3582 tlab = define_label (loc2, name);
3585 decl_attributes (&tlab, attrs, 0);
3586 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3590 SET_EXPR_LOCATION (label, loc1);
3593 /* Parse a statement (C90 6.6, C99 6.8).
3598 expression-statement
3606 expression-statement:
3609 selection-statement:
3613 iteration-statement:
3622 return expression[opt] ;
3635 objc-throw-statement
3636 objc-try-catch-statement
3637 objc-synchronized-statement
3639 objc-throw-statement:
3653 parallel-for-construct
3654 parallel-sections-construct
3661 parallel-directive structured-block
3664 for-directive iteration-statement
3667 sections-directive section-scope
3670 single-directive structured-block
3672 parallel-for-construct:
3673 parallel-for-directive iteration-statement
3675 parallel-sections-construct:
3676 parallel-sections-directive section-scope
3679 master-directive structured-block
3682 critical-directive structured-block
3685 atomic-directive expression-statement
3688 ordered-directive structured-block */
3691 c_parser_statement (c_parser *parser)
3693 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3694 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3695 || (c_parser_next_token_is (parser, CPP_NAME)
3696 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3697 c_parser_label (parser);
3698 c_parser_statement_after_labels (parser);
3701 /* Parse a statement, other than a labeled statement. */
3704 c_parser_statement_after_labels (c_parser *parser)
3706 location_t loc = c_parser_peek_token (parser)->location;
3707 tree stmt = NULL_TREE;
3708 switch (c_parser_peek_token (parser)->type)
3710 case CPP_OPEN_BRACE:
3711 add_stmt (c_parser_compound_statement (parser));
3714 switch (c_parser_peek_token (parser)->keyword)
3717 c_parser_if_statement (parser);
3720 c_parser_switch_statement (parser);
3723 c_parser_while_statement (parser);
3726 c_parser_do_statement (parser);
3729 c_parser_for_statement (parser);
3732 c_parser_consume_token (parser);
3733 if (c_parser_next_token_is (parser, CPP_NAME))
3735 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3736 c_parser_consume_token (parser);
3738 else if (c_parser_next_token_is (parser, CPP_MULT))
3740 c_parser_consume_token (parser);
3741 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3744 c_parser_error (parser, "expected identifier or %<*%>");
3745 goto expect_semicolon;
3747 c_parser_consume_token (parser);
3748 stmt = c_finish_bc_stmt (&c_cont_label, false);
3749 goto expect_semicolon;
3751 c_parser_consume_token (parser);
3752 stmt = c_finish_bc_stmt (&c_break_label, true);
3753 goto expect_semicolon;
3755 c_parser_consume_token (parser);
3756 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3758 stmt = c_finish_return (NULL_TREE);
3759 c_parser_consume_token (parser);
3763 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3764 goto expect_semicolon;
3768 stmt = c_parser_asm_statement (parser);
3771 gcc_assert (c_dialect_objc ());
3772 c_parser_consume_token (parser);
3773 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3775 stmt = objc_build_throw_stmt (NULL_TREE);
3776 c_parser_consume_token (parser);
3781 = objc_build_throw_stmt (c_parser_expression (parser).value);
3782 goto expect_semicolon;
3786 gcc_assert (c_dialect_objc ());
3787 c_parser_objc_try_catch_statement (parser);
3789 case RID_AT_SYNCHRONIZED:
3790 gcc_assert (c_dialect_objc ());
3791 c_parser_objc_synchronized_statement (parser);
3798 c_parser_consume_token (parser);
3800 case CPP_CLOSE_PAREN:
3801 case CPP_CLOSE_SQUARE:
3802 /* Avoid infinite loop in error recovery:
3803 c_parser_skip_until_found stops at a closing nesting
3804 delimiter without consuming it, but here we need to consume
3805 it to proceed further. */
3806 c_parser_error (parser, "expected statement");
3807 c_parser_consume_token (parser);
3810 c_parser_pragma (parser, pragma_stmt);
3814 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3816 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3819 /* Two cases cannot and do not have line numbers associated: If stmt
3820 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3821 cannot hold line numbers. But that's OK because the statement
3822 will either be changed to a MODIFY_EXPR during gimplification of
3823 the statement expr, or discarded. If stmt was compound, but
3824 without new variables, we will have skipped the creation of a
3825 BIND and will have a bare STATEMENT_LIST. But that's OK because
3826 (recursively) all of the component statements should already have
3827 line numbers assigned. ??? Can we discard no-op statements
3829 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3830 SET_EXPR_LOCATION (stmt, loc);
3833 /* Parse a parenthesized condition from an if, do or while statement.
3839 c_parser_paren_condition (c_parser *parser)
3843 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3844 return error_mark_node;
3845 loc = c_parser_peek_token (parser)->location;
3846 cond = c_objc_common_truthvalue_conversion
3847 (c_parser_expression_conv (parser).value);
3848 if (CAN_HAVE_LOCATION_P (cond))
3849 SET_EXPR_LOCATION (cond, loc);
3850 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3854 /* Parse a statement which is a block in C99. */
3857 c_parser_c99_block_statement (c_parser *parser)
3859 tree block = c_begin_compound_stmt (flag_isoc99);
3860 c_parser_statement (parser);
3861 return c_end_compound_stmt (block, flag_isoc99);
3864 /* Parse the body of an if statement or the else half thereof. This
3865 is just parsing a statement but (a) it is a block in C99, (b) we
3866 track whether the body is an if statement for the sake of
3867 -Wparentheses warnings, (c) we handle an empty body specially for
3868 the sake of -Wempty-body warnings. */
3871 c_parser_if_body (c_parser *parser, bool *if_p)
3873 tree block = c_begin_compound_stmt (flag_isoc99);
3874 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3875 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3876 || (c_parser_next_token_is (parser, CPP_NAME)
3877 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3878 c_parser_label (parser);
3879 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3880 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3881 add_stmt (build_empty_stmt ());
3882 c_parser_statement_after_labels (parser);
3883 return c_end_compound_stmt (block, flag_isoc99);
3886 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3889 if ( expression ) statement
3890 if ( expression ) statement else statement
3894 c_parser_if_statement (c_parser *parser)
3899 bool first_if = false, second_if = false;
3900 tree first_body, second_body;
3901 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3902 c_parser_consume_token (parser);
3903 block = c_begin_compound_stmt (flag_isoc99);
3904 loc = c_parser_peek_token (parser)->location;
3905 cond = c_parser_paren_condition (parser);
3906 first_body = c_parser_if_body (parser, &first_if);
3907 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3909 c_parser_consume_token (parser);
3910 second_body = c_parser_if_body (parser, &second_if);
3913 second_body = NULL_TREE;
3914 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3915 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3918 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3921 switch (expression) statement
3925 c_parser_switch_statement (c_parser *parser)
3927 tree block, expr, body, save_break;
3928 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3929 c_parser_consume_token (parser);
3930 block = c_begin_compound_stmt (flag_isoc99);
3931 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3933 expr = c_parser_expression (parser).value;
3934 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3937 expr = error_mark_node;
3938 c_start_case (expr);
3939 save_break = c_break_label;
3940 c_break_label = NULL_TREE;
3941 body = c_parser_c99_block_statement (parser);
3942 c_finish_case (body);
3944 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3945 c_break_label = save_break;
3946 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3949 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3952 while (expression) statement
3956 c_parser_while_statement (c_parser *parser)
3958 tree block, cond, body, save_break, save_cont;
3960 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3961 c_parser_consume_token (parser);
3962 block = c_begin_compound_stmt (flag_isoc99);
3963 loc = c_parser_peek_token (parser)->location;
3964 cond = c_parser_paren_condition (parser);
3965 save_break = c_break_label;
3966 c_break_label = NULL_TREE;
3967 save_cont = c_cont_label;
3968 c_cont_label = NULL_TREE;
3969 body = c_parser_c99_block_statement (parser);
3970 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3971 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3972 c_break_label = save_break;
3973 c_cont_label = save_cont;
3976 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3979 do statement while ( expression ) ;
3983 c_parser_do_statement (c_parser *parser)
3985 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3987 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3988 c_parser_consume_token (parser);
3989 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3990 warning (OPT_Wempty_body,
3991 "suggest braces around empty body in %<do%> statement");
3992 block = c_begin_compound_stmt (flag_isoc99);
3993 loc = c_parser_peek_token (parser)->location;
3994 save_break = c_break_label;
3995 c_break_label = NULL_TREE;
3996 save_cont = c_cont_label;
3997 c_cont_label = NULL_TREE;
3998 body = c_parser_c99_block_statement (parser);
3999 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4000 new_break = c_break_label;
4001 c_break_label = save_break;
4002 new_cont = c_cont_label;
4003 c_cont_label = save_cont;
4004 cond = c_parser_paren_condition (parser);
4005 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4006 c_parser_skip_to_end_of_block_or_statement (parser);
4007 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4008 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4011 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4014 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4015 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4017 The form with a declaration is new in C99.
4019 ??? In accordance with the old parser, the declaration may be a
4020 nested function, which is then rejected in check_for_loop_decls,
4021 but does it make any sense for this to be included in the grammar?
4022 Note in particular that the nested function does not include a
4023 trailing ';', whereas the "declaration" production includes one.
4024 Also, can we reject bad declarations earlier and cheaper than
4025 check_for_loop_decls? */
4028 c_parser_for_statement (c_parser *parser)
4030 tree block, cond, incr, save_break, save_cont, body;
4032 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4033 loc = c_parser_peek_token (parser)->location;
4034 c_parser_consume_token (parser);
4035 block = c_begin_compound_stmt (flag_isoc99);
4036 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4038 /* Parse the initialization declaration or expression. */
4039 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4041 c_parser_consume_token (parser);
4042 c_finish_expr_stmt (NULL_TREE);
4044 else if (c_parser_next_token_starts_declspecs (parser))
4046 c_parser_declaration_or_fndef (parser, true, true, true, true);
4047 check_for_loop_decls ();
4049 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4051 /* __extension__ can start a declaration, but is also an
4052 unary operator that can start an expression. Consume all
4053 but the last of a possible series of __extension__ to
4055 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4056 && (c_parser_peek_2nd_token (parser)->keyword
4058 c_parser_consume_token (parser);
4059 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4062 ext = disable_extension_diagnostics ();
4063 c_parser_consume_token (parser);
4064 c_parser_declaration_or_fndef (parser, true, true, true, true);
4065 restore_extension_diagnostics (ext);
4066 check_for_loop_decls ();
4074 c_finish_expr_stmt (c_parser_expression (parser).value);
4075 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4077 /* Parse the loop condition. */
4078 loc = c_parser_peek_token (parser)->location;
4079 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4081 c_parser_consume_token (parser);
4086 tree ocond = c_parser_expression_conv (parser).value;
4087 cond = c_objc_common_truthvalue_conversion (ocond);
4088 if (CAN_HAVE_LOCATION_P (cond))
4089 SET_EXPR_LOCATION (cond, loc);
4090 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4092 /* Parse the increment expression. */
4093 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4094 incr = c_process_expr_stmt (NULL_TREE);
4096 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4097 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4101 cond = error_mark_node;
4102 incr = error_mark_node;
4104 save_break = c_break_label;
4105 c_break_label = NULL_TREE;
4106 save_cont = c_cont_label;
4107 c_cont_label = NULL_TREE;
4108 body = c_parser_c99_block_statement (parser);
4109 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4110 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4111 c_break_label = save_break;
4112 c_cont_label = save_cont;
4115 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4116 statement with inputs, outputs, clobbers, and volatile tag
4120 asm type-qualifier[opt] ( asm-argument ) ;
4124 asm-string-literal : asm-operands[opt]
4125 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4126 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4128 Qualifiers other than volatile are accepted in the syntax but
4132 c_parser_asm_statement (c_parser *parser)
4134 tree quals, str, outputs, inputs, clobbers, ret;
4136 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4137 c_parser_consume_token (parser);
4138 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4140 quals = c_parser_peek_token (parser)->value;
4141 c_parser_consume_token (parser);
4143 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4144 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4146 warning (0, "%E qualifier ignored on asm",
4147 c_parser_peek_token (parser)->value);
4149 c_parser_consume_token (parser);
4153 /* ??? Follow the C++ parser rather than using the
4154 lex_untranslated_string kludge. */
4155 parser->lex_untranslated_string = true;
4156 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4158 parser->lex_untranslated_string = false;
4161 str = c_parser_asm_string_literal (parser);
4162 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4165 outputs = NULL_TREE;
4167 clobbers = NULL_TREE;
4170 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4172 parser->lex_untranslated_string = false;
4173 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4177 /* Parse outputs. */
4178 if (c_parser_next_token_is (parser, CPP_COLON)
4179 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4180 outputs = NULL_TREE;
4182 outputs = c_parser_asm_operands (parser, false);
4183 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4186 clobbers = NULL_TREE;
4189 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4191 parser->lex_untranslated_string = false;
4192 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4196 if (c_parser_next_token_is (parser, CPP_COLON)
4197 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4200 inputs = c_parser_asm_operands (parser, true);
4201 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4203 clobbers = NULL_TREE;
4206 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4208 parser->lex_untranslated_string = false;
4209 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4212 /* Parse clobbers. */
4213 clobbers = c_parser_asm_clobbers (parser);
4215 parser->lex_untranslated_string = false;
4216 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4218 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4221 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4222 c_parser_skip_to_end_of_block_or_statement (parser);
4223 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4228 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4229 not outputs), apply the default conversion of functions and arrays
4234 asm-operands , asm-operand
4237 asm-string-literal ( expression )
4238 [ identifier ] asm-string-literal ( expression )
4242 c_parser_asm_operands (c_parser *parser, bool convert_p)
4244 tree list = NULL_TREE;
4249 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4251 c_parser_consume_token (parser);
4252 if (c_parser_next_token_is (parser, CPP_NAME))
4254 tree id = c_parser_peek_token (parser)->value;
4255 c_parser_consume_token (parser);
4256 name = build_string (IDENTIFIER_LENGTH (id),
4257 IDENTIFIER_POINTER (id));
4261 c_parser_error (parser, "expected identifier");
4262 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4265 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4270 str = c_parser_asm_string_literal (parser);
4271 if (str == NULL_TREE)
4273 parser->lex_untranslated_string = false;
4274 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4276 parser->lex_untranslated_string = true;
4279 expr = c_parser_expression (parser);
4281 expr = default_function_array_conversion (expr);
4282 parser->lex_untranslated_string = true;
4283 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4285 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4288 list = chainon (list, build_tree_list (build_tree_list (name, str),
4290 if (c_parser_next_token_is (parser, CPP_COMMA))
4291 c_parser_consume_token (parser);
4298 /* Parse asm clobbers, a GNU extension.
4302 asm-clobbers , asm-string-literal
4306 c_parser_asm_clobbers (c_parser *parser)
4308 tree list = NULL_TREE;
4311 tree str = c_parser_asm_string_literal (parser);
4313 list = tree_cons (NULL_TREE, str, list);
4316 if (c_parser_next_token_is (parser, CPP_COMMA))
4317 c_parser_consume_token (parser);
4324 /* Parse an expression other than a compound expression; that is, an
4325 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4326 NULL then it is an Objective-C message expression which is the
4327 primary-expression starting the expression as an initializer.
4329 assignment-expression:
4330 conditional-expression
4331 unary-expression assignment-operator assignment-expression
4333 assignment-operator: one of
4334 = *= /= %= += -= <<= >>= &= ^= |=
4336 In GNU C we accept any conditional expression on the LHS and
4337 diagnose the invalid lvalue rather than producing a syntax
4340 static struct c_expr
4341 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4343 struct c_expr lhs, rhs, ret;
4344 enum tree_code code;
4345 gcc_assert (!after || c_dialect_objc ());
4346 lhs = c_parser_conditional_expression (parser, after);
4347 switch (c_parser_peek_token (parser)->type)
4356 code = TRUNC_DIV_EXPR;
4359 code = TRUNC_MOD_EXPR;
4374 code = BIT_AND_EXPR;
4377 code = BIT_XOR_EXPR;
4380 code = BIT_IOR_EXPR;
4385 c_parser_consume_token (parser);
4386 rhs = c_parser_expr_no_commas (parser, NULL);
4387 rhs = default_function_array_conversion (rhs);
4388 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4389 if (code == NOP_EXPR)
4390 ret.original_code = MODIFY_EXPR;
4393 TREE_NO_WARNING (ret.value) = 1;
4394 ret.original_code = ERROR_MARK;
4399 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4400 is not NULL then it is an Objective-C message expression which is
4401 the primary-expression starting the expression as an initializer.
4403 conditional-expression:
4404 logical-OR-expression
4405 logical-OR-expression ? expression : conditional-expression
4409 conditional-expression:
4410 logical-OR-expression ? : conditional-expression
4413 static struct c_expr
4414 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4416 struct c_expr cond, exp1, exp2, ret;
4417 gcc_assert (!after || c_dialect_objc ());
4418 cond = c_parser_binary_expression (parser, after);
4419 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4421 cond = default_function_array_conversion (cond);
4422 c_parser_consume_token (parser);
4423 if (c_parser_next_token_is (parser, CPP_COLON))
4426 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4427 /* Make sure first operand is calculated only once. */
4428 exp1.value = save_expr (default_conversion (cond.value));
4429 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4430 skip_evaluation += cond.value == truthvalue_true_node;
4435 = c_objc_common_truthvalue_conversion
4436 (default_conversion (cond.value));
4437 skip_evaluation += cond.value == truthvalue_false_node;
4438 exp1 = c_parser_expression_conv (parser);
4439 skip_evaluation += ((cond.value == truthvalue_true_node)
4440 - (cond.value == truthvalue_false_node));
4442 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4444 skip_evaluation -= cond.value == truthvalue_true_node;
4445 ret.value = error_mark_node;
4446 ret.original_code = ERROR_MARK;
4449 exp2 = c_parser_conditional_expression (parser, NULL);
4450 exp2 = default_function_array_conversion (exp2);
4451 skip_evaluation -= cond.value == truthvalue_true_node;
4452 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4453 ret.original_code = ERROR_MARK;
4457 /* Parse a binary expression; that is, a logical-OR-expression (C90
4458 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4459 an Objective-C message expression which is the primary-expression
4460 starting the expression as an initializer.
4462 multiplicative-expression:
4464 multiplicative-expression * cast-expression
4465 multiplicative-expression / cast-expression
4466 multiplicative-expression % cast-expression
4468 additive-expression:
4469 multiplicative-expression
4470 additive-expression + multiplicative-expression
4471 additive-expression - multiplicative-expression
4475 shift-expression << additive-expression
4476 shift-expression >> additive-expression
4478 relational-expression:
4480 relational-expression < shift-expression
4481 relational-expression > shift-expression
4482 relational-expression <= shift-expression
4483 relational-expression >= shift-expression
4485 equality-expression:
4486 relational-expression
4487 equality-expression == relational-expression
4488 equality-expression != relational-expression
4492 AND-expression & equality-expression
4494 exclusive-OR-expression:
4496 exclusive-OR-expression ^ AND-expression
4498 inclusive-OR-expression:
4499 exclusive-OR-expression
4500 inclusive-OR-expression | exclusive-OR-expression
4502 logical-AND-expression:
4503 inclusive-OR-expression
4504 logical-AND-expression && inclusive-OR-expression
4506 logical-OR-expression:
4507 logical-AND-expression
4508 logical-OR-expression || logical-AND-expression
4511 static struct c_expr
4512 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4514 /* A binary expression is parsed using operator-precedence parsing,
4515 with the operands being cast expressions. All the binary
4516 operators are left-associative. Thus a binary expression is of
4519 E0 op1 E1 op2 E2 ...
4521 which we represent on a stack. On the stack, the precedence
4522 levels are strictly increasing. When a new operator is
4523 encountered of higher precedence than that at the top of the
4524 stack, it is pushed; its LHS is the top expression, and its RHS
4525 is everything parsed until it is popped. When a new operator is
4526 encountered with precedence less than or equal to that at the top
4527 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4528 by the result of the operation until the operator at the top of
4529 the stack has lower precedence than the new operator or there is
4530 only one element on the stack; then the top expression is the LHS
4531 of the new operator. In the case of logical AND and OR
4532 expressions, we also need to adjust skip_evaluation as
4533 appropriate when the operators are pushed and popped. */
4535 /* The precedence levels, where 0 is a dummy lowest level used for
4536 the bottom of the stack. */
4552 /* The expression at this stack level. */
4554 /* The precedence of the operator on its left, PREC_NONE at the
4555 bottom of the stack. */
4557 /* The operation on its left. */
4563 switch (stack[sp].op) \
4565 case TRUTH_ANDIF_EXPR: \
4566 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4568 case TRUTH_ORIF_EXPR: \
4569 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4574 stack[sp - 1].expr \
4575 = default_function_array_conversion (stack[sp - 1].expr); \
4577 = default_function_array_conversion (stack[sp].expr); \
4578 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4579 stack[sp - 1].expr, \
4583 gcc_assert (!after || c_dialect_objc ());
4584 stack[0].expr = c_parser_cast_expression (parser, after);
4585 stack[0].prec = PREC_NONE;
4590 enum tree_code ocode;
4593 switch (c_parser_peek_token (parser)->type)
4601 ocode = TRUNC_DIV_EXPR;
4605 ocode = TRUNC_MOD_EXPR;
4617 ocode = LSHIFT_EXPR;
4621 ocode = RSHIFT_EXPR;
4635 case CPP_GREATER_EQ:
4648 oprec = PREC_BITAND;
4649 ocode = BIT_AND_EXPR;
4652 oprec = PREC_BITXOR;
4653 ocode = BIT_XOR_EXPR;
4657 ocode = BIT_IOR_EXPR;
4660 oprec = PREC_LOGAND;
4661 ocode = TRUTH_ANDIF_EXPR;
4665 ocode = TRUTH_ORIF_EXPR;
4668 /* Not a binary operator, so end of the binary
4672 c_parser_consume_token (parser);
4673 while (oprec <= stack[sp].prec)
4677 case TRUTH_ANDIF_EXPR:
4679 = default_function_array_conversion (stack[sp].expr);
4680 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4681 (default_conversion (stack[sp].expr.value));
4682 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4684 case TRUTH_ORIF_EXPR:
4686 = default_function_array_conversion (stack[sp].expr);
4687 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4688 (default_conversion (stack[sp].expr.value));
4689 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4695 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4696 stack[sp].prec = oprec;
4697 stack[sp].op = ocode;
4702 return stack[0].expr;
4706 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4707 NULL then it is an Objective-C message expression which is the
4708 primary-expression starting the expression as an initializer.
4712 ( type-name ) unary-expression
4715 static struct c_expr
4716 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4718 gcc_assert (!after || c_dialect_objc ());
4720 return c_parser_postfix_expression_after_primary (parser, *after);
4721 /* If the expression begins with a parenthesized type name, it may
4722 be either a cast or a compound literal; we need to see whether
4723 the next character is '{' to tell the difference. If not, it is
4724 an unary expression. */
4725 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4726 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4728 struct c_type_name *type_name;
4731 c_parser_consume_token (parser);
4732 type_name = c_parser_type_name (parser);
4733 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4734 if (type_name == NULL)
4736 ret.value = error_mark_node;
4737 ret.original_code = ERROR_MARK;
4741 /* Save casted types in the function's used types hash table. */
4742 used_types_insert (type_name->specs->type);
4744 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4745 return c_parser_postfix_expression_after_paren_type (parser,
4747 expr = c_parser_cast_expression (parser, NULL);
4748 expr = default_function_array_conversion (expr);
4749 ret.value = c_cast_expr (type_name, expr.value);
4750 ret.original_code = ERROR_MARK;
4754 return c_parser_unary_expression (parser);
4757 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4763 unary-operator cast-expression
4764 sizeof unary-expression
4765 sizeof ( type-name )
4767 unary-operator: one of
4773 __alignof__ unary-expression
4774 __alignof__ ( type-name )
4777 unary-operator: one of
4778 __extension__ __real__ __imag__
4780 In addition, the GNU syntax treats ++ and -- as unary operators, so
4781 they may be applied to cast expressions with errors for non-lvalues
4784 static struct c_expr
4785 c_parser_unary_expression (c_parser *parser)
4788 struct c_expr ret, op;
4789 switch (c_parser_peek_token (parser)->type)
4792 c_parser_consume_token (parser);
4793 op = c_parser_cast_expression (parser, NULL);
4794 op = default_function_array_conversion (op);
4795 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4796 case CPP_MINUS_MINUS:
4797 c_parser_consume_token (parser);
4798 op = c_parser_cast_expression (parser, NULL);
4799 op = default_function_array_conversion (op);
4800 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4802 c_parser_consume_token (parser);
4803 return parser_build_unary_op (ADDR_EXPR,
4804 c_parser_cast_expression (parser, NULL));
4806 c_parser_consume_token (parser);
4807 op = c_parser_cast_expression (parser, NULL);
4808 op = default_function_array_conversion (op);
4809 ret.value = build_indirect_ref (op.value, "unary *");
4810 ret.original_code = ERROR_MARK;
4813 c_parser_consume_token (parser);
4814 if (!c_dialect_objc () && !in_system_header)
4815 warning (OPT_Wtraditional,
4816 "traditional C rejects the unary plus operator");
4817 op = c_parser_cast_expression (parser, NULL);
4818 op = default_function_array_conversion (op);
4819 return parser_build_unary_op (CONVERT_EXPR, op);
4821 c_parser_consume_token (parser);
4822 op = c_parser_cast_expression (parser, NULL);
4823 op = default_function_array_conversion (op);
4824 return parser_build_unary_op (NEGATE_EXPR, op);
4826 c_parser_consume_token (parser);
4827 op = c_parser_cast_expression (parser, NULL);
4828 op = default_function_array_conversion (op);
4829 return parser_build_unary_op (BIT_NOT_EXPR, op);
4831 c_parser_consume_token (parser);
4832 op = c_parser_cast_expression (parser, NULL);
4833 op = default_function_array_conversion (op);
4834 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4836 /* Refer to the address of a label as a pointer. */
4837 c_parser_consume_token (parser);
4838 if (c_parser_next_token_is (parser, CPP_NAME))
4840 ret.value = finish_label_address_expr
4841 (c_parser_peek_token (parser)->value);
4842 c_parser_consume_token (parser);
4846 c_parser_error (parser, "expected identifier");
4847 ret.value = error_mark_node;
4849 ret.original_code = ERROR_MARK;
4852 switch (c_parser_peek_token (parser)->keyword)
4855 return c_parser_sizeof_expression (parser);
4857 return c_parser_alignof_expression (parser);
4859 c_parser_consume_token (parser);
4860 ext = disable_extension_diagnostics ();
4861 ret = c_parser_cast_expression (parser, NULL);
4862 restore_extension_diagnostics (ext);
4865 c_parser_consume_token (parser);
4866 op = c_parser_cast_expression (parser, NULL);
4867 op = default_function_array_conversion (op);
4868 return parser_build_unary_op (REALPART_EXPR, op);
4870 c_parser_consume_token (parser);
4871 op = c_parser_cast_expression (parser, NULL);
4872 op = default_function_array_conversion (op);
4873 return parser_build_unary_op (IMAGPART_EXPR, op);
4875 return c_parser_postfix_expression (parser);
4878 return c_parser_postfix_expression (parser);
4882 /* Parse a sizeof expression. */
4884 static struct c_expr
4885 c_parser_sizeof_expression (c_parser *parser)
4888 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4889 c_parser_consume_token (parser);
4892 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4893 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4895 /* Either sizeof ( type-name ) or sizeof unary-expression
4896 starting with a compound literal. */
4897 struct c_type_name *type_name;
4898 c_parser_consume_token (parser);
4899 type_name = c_parser_type_name (parser);
4900 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4901 if (type_name == NULL)
4906 ret.value = error_mark_node;
4907 ret.original_code = ERROR_MARK;
4910 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4912 expr = c_parser_postfix_expression_after_paren_type (parser,
4916 /* sizeof ( type-name ). */
4919 if (type_name->declarator->kind == cdk_array
4920 && type_name->declarator->u.array.vla_unspec_p)
4923 error ("%<[*]%> not allowed in other than a declaration");
4925 return c_expr_sizeof_type (type_name);
4929 expr = c_parser_unary_expression (parser);
4933 if (TREE_CODE (expr.value) == COMPONENT_REF
4934 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4935 error ("%<sizeof%> applied to a bit-field");
4936 return c_expr_sizeof_expr (expr);
4940 /* Parse an alignof expression. */
4942 static struct c_expr
4943 c_parser_alignof_expression (c_parser *parser)
4946 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4947 c_parser_consume_token (parser);
4950 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4951 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4953 /* Either __alignof__ ( type-name ) or __alignof__
4954 unary-expression starting with a compound literal. */
4955 struct c_type_name *type_name;
4957 c_parser_consume_token (parser);
4958 type_name = c_parser_type_name (parser);
4959 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4960 if (type_name == NULL)
4965 ret.value = error_mark_node;
4966 ret.original_code = ERROR_MARK;
4969 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4971 expr = c_parser_postfix_expression_after_paren_type (parser,
4975 /* alignof ( type-name ). */
4978 ret.value = c_alignof (groktypename (type_name));
4979 ret.original_code = ERROR_MARK;
4985 expr = c_parser_unary_expression (parser);
4989 ret.value = c_alignof_expr (expr.value);
4990 ret.original_code = ERROR_MARK;
4995 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4999 postfix-expression [ expression ]
5000 postfix-expression ( argument-expression-list[opt] )
5001 postfix-expression . identifier
5002 postfix-expression -> identifier
5003 postfix-expression ++
5004 postfix-expression --
5005 ( type-name ) { initializer-list }
5006 ( type-name ) { initializer-list , }
5008 argument-expression-list:
5010 argument-expression-list , argument-expression
5022 (treated as a keyword in GNU C)
5025 ( compound-statement )
5026 __builtin_va_arg ( assignment-expression , type-name )
5027 __builtin_offsetof ( type-name , offsetof-member-designator )
5028 __builtin_choose_expr ( assignment-expression ,
5029 assignment-expression ,
5030 assignment-expression )
5031 __builtin_types_compatible_p ( type-name , type-name )
5033 offsetof-member-designator:
5035 offsetof-member-designator . identifier
5036 offsetof-member-designator [ expression ]
5041 [ objc-receiver objc-message-args ]
5042 @selector ( objc-selector-arg )
5043 @protocol ( identifier )
5044 @encode ( type-name )
5048 static struct c_expr
5049 c_parser_postfix_expression (c_parser *parser)
5051 struct c_expr expr, e1, e2, e3;
5052 struct c_type_name *t1, *t2;
5053 switch (c_parser_peek_token (parser)->type)
5058 expr.value = c_parser_peek_token (parser)->value;
5059 expr.original_code = ERROR_MARK;
5060 c_parser_consume_token (parser);
5064 expr.value = c_parser_peek_token (parser)->value;
5065 expr.original_code = STRING_CST;
5066 c_parser_consume_token (parser);
5068 case CPP_OBJC_STRING:
5069 gcc_assert (c_dialect_objc ());
5071 = objc_build_string_object (c_parser_peek_token (parser)->value);
5072 expr.original_code = ERROR_MARK;
5073 c_parser_consume_token (parser);
5076 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5078 c_parser_error (parser, "expected expression");
5079 expr.value = error_mark_node;
5080 expr.original_code = ERROR_MARK;
5084 tree id = c_parser_peek_token (parser)->value;
5085 location_t loc = c_parser_peek_token (parser)->location;
5086 c_parser_consume_token (parser);
5087 expr.value = build_external_ref (id,
5088 (c_parser_peek_token (parser)->type
5089 == CPP_OPEN_PAREN), loc);
5090 expr.original_code = ERROR_MARK;
5093 case CPP_OPEN_PAREN:
5094 /* A parenthesized expression, statement expression or compound
5096 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5098 /* A statement expression. */
5100 c_parser_consume_token (parser);
5101 c_parser_consume_token (parser);
5102 if (cur_stmt_list == NULL)
5104 error ("braced-group within expression allowed "
5105 "only inside a function");
5106 parser->error = true;
5107 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5108 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5109 expr.value = error_mark_node;
5110 expr.original_code = ERROR_MARK;
5113 stmt = c_begin_stmt_expr ();
5114 c_parser_compound_statement_nostart (parser);
5115 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5118 pedwarn ("ISO C forbids braced-groups within expressions");
5119 expr.value = c_finish_stmt_expr (stmt);
5120 expr.original_code = ERROR_MARK;
5122 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5124 /* A compound literal. ??? Can we actually get here rather
5125 than going directly to
5126 c_parser_postfix_expression_after_paren_type from
5128 struct c_type_name *type_name;
5129 c_parser_consume_token (parser);
5130 type_name = c_parser_type_name (parser);
5131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5133 if (type_name == NULL)
5135 expr.value = error_mark_node;
5136 expr.original_code = ERROR_MARK;
5139 expr = c_parser_postfix_expression_after_paren_type (parser,
5144 /* A parenthesized expression. */
5145 c_parser_consume_token (parser);
5146 expr = c_parser_expression (parser);
5147 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5148 TREE_NO_WARNING (expr.value) = 1;
5149 expr.original_code = ERROR_MARK;
5150 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5155 switch (c_parser_peek_token (parser)->keyword)
5157 case RID_FUNCTION_NAME:
5158 case RID_PRETTY_FUNCTION_NAME:
5159 case RID_C99_FUNCTION_NAME:
5160 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5161 c_parser_peek_token (parser)->value);
5162 expr.original_code = ERROR_MARK;
5163 c_parser_consume_token (parser);
5166 c_parser_consume_token (parser);
5167 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5169 expr.value = error_mark_node;
5170 expr.original_code = ERROR_MARK;
5173 e1 = c_parser_expr_no_commas (parser, NULL);
5174 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5176 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5177 expr.value = error_mark_node;
5178 expr.original_code = ERROR_MARK;
5181 t1 = c_parser_type_name (parser);
5182 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5186 expr.value = error_mark_node;
5187 expr.original_code = ERROR_MARK;
5191 expr.value = build_va_arg (e1.value, groktypename (t1));
5192 expr.original_code = ERROR_MARK;
5196 c_parser_consume_token (parser);
5197 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5199 expr.value = error_mark_node;
5200 expr.original_code = ERROR_MARK;
5203 t1 = c_parser_type_name (parser);
5206 expr.value = error_mark_node;
5207 expr.original_code = ERROR_MARK;
5210 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5212 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5213 expr.value = error_mark_node;
5214 expr.original_code = ERROR_MARK;
5218 tree type = groktypename (t1);
5220 if (type == error_mark_node)
5221 offsetof_ref = error_mark_node;
5223 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5224 /* Parse the second argument to __builtin_offsetof. We
5225 must have one identifier, and beyond that we want to
5226 accept sub structure and sub array references. */
5227 if (c_parser_next_token_is (parser, CPP_NAME))
5229 offsetof_ref = build_component_ref
5230 (offsetof_ref, c_parser_peek_token (parser)->value);
5231 c_parser_consume_token (parser);
5232 while (c_parser_next_token_is (parser, CPP_DOT)
5233 || c_parser_next_token_is (parser,
5236 if (c_parser_next_token_is (parser, CPP_DOT))
5238 c_parser_consume_token (parser);
5239 if (c_parser_next_token_is_not (parser,
5242 c_parser_error (parser, "expected identifier");
5245 offsetof_ref = build_component_ref
5247 c_parser_peek_token (parser)->value);
5248 c_parser_consume_token (parser);
5253 c_parser_consume_token (parser);
5254 idx = c_parser_expression (parser).value;
5255 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5257 offsetof_ref = build_array_ref (offsetof_ref, idx);
5262 c_parser_error (parser, "expected identifier");
5263 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5265 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5266 expr.original_code = ERROR_MARK;
5269 case RID_CHOOSE_EXPR:
5270 c_parser_consume_token (parser);
5271 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5273 expr.value = error_mark_node;
5274 expr.original_code = ERROR_MARK;
5277 e1 = c_parser_expr_no_commas (parser, NULL);
5278 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5280 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5281 expr.value = error_mark_node;
5282 expr.original_code = ERROR_MARK;
5285 e2 = c_parser_expr_no_commas (parser, NULL);
5286 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5289 expr.value = error_mark_node;
5290 expr.original_code = ERROR_MARK;
5293 e3 = c_parser_expr_no_commas (parser, NULL);
5294 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5299 c = fold (e1.value);
5300 if (TREE_CODE (c) != INTEGER_CST)
5301 error ("first argument to %<__builtin_choose_expr%> not"
5303 expr = integer_zerop (c) ? e3 : e2;
5306 case RID_TYPES_COMPATIBLE_P:
5307 c_parser_consume_token (parser);
5308 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5310 expr.value = error_mark_node;
5311 expr.original_code = ERROR_MARK;
5314 t1 = c_parser_type_name (parser);
5317 expr.value = error_mark_node;
5318 expr.original_code = ERROR_MARK;
5321 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5324 expr.value = error_mark_node;
5325 expr.original_code = ERROR_MARK;
5328 t2 = c_parser_type_name (parser);
5331 expr.value = error_mark_node;
5332 expr.original_code = ERROR_MARK;
5335 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5340 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5341 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5343 expr.value = comptypes (e1, e2)
5344 ? build_int_cst (NULL_TREE, 1)
5345 : build_int_cst (NULL_TREE, 0);
5346 expr.original_code = ERROR_MARK;
5349 case RID_AT_SELECTOR:
5350 gcc_assert (c_dialect_objc ());
5351 c_parser_consume_token (parser);
5352 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5354 expr.value = error_mark_node;
5355 expr.original_code = ERROR_MARK;
5359 tree sel = c_parser_objc_selector_arg (parser);
5360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5362 expr.value = objc_build_selector_expr (sel);
5363 expr.original_code = ERROR_MARK;
5366 case RID_AT_PROTOCOL:
5367 gcc_assert (c_dialect_objc ());
5368 c_parser_consume_token (parser);
5369 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5371 expr.value = error_mark_node;
5372 expr.original_code = ERROR_MARK;
5375 if (c_parser_next_token_is_not (parser, CPP_NAME))
5377 c_parser_error (parser, "expected identifier");
5378 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5379 expr.value = error_mark_node;
5380 expr.original_code = ERROR_MARK;
5384 tree id = c_parser_peek_token (parser)->value;
5385 c_parser_consume_token (parser);
5386 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5388 expr.value = objc_build_protocol_expr (id);
5389 expr.original_code = ERROR_MARK;
5393 /* Extension to support C-structures in the archiver. */
5394 gcc_assert (c_dialect_objc ());
5395 c_parser_consume_token (parser);
5396 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5398 expr.value = error_mark_node;
5399 expr.original_code = ERROR_MARK;
5402 t1 = c_parser_type_name (parser);
5405 expr.value = error_mark_node;
5406 expr.original_code = ERROR_MARK;
5407 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5413 tree type = groktypename (t1);
5414 expr.value = objc_build_encode_expr (type);
5415 expr.original_code = ERROR_MARK;
5419 c_parser_error (parser, "expected expression");
5420 expr.value = error_mark_node;
5421 expr.original_code = ERROR_MARK;
5425 case CPP_OPEN_SQUARE:
5426 if (c_dialect_objc ())
5428 tree receiver, args;
5429 c_parser_consume_token (parser);
5430 receiver = c_parser_objc_receiver (parser);
5431 args = c_parser_objc_message_args (parser);
5432 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5434 expr.value = objc_build_message_expr (build_tree_list (receiver,
5436 expr.original_code = ERROR_MARK;
5439 /* Else fall through to report error. */
5441 c_parser_error (parser, "expected expression");
5442 expr.value = error_mark_node;
5443 expr.original_code = ERROR_MARK;
5446 return c_parser_postfix_expression_after_primary (parser, expr);
5449 /* Parse a postfix expression after a parenthesized type name: the
5450 brace-enclosed initializer of a compound literal, possibly followed
5451 by some postfix operators. This is separate because it is not
5452 possible to tell until after the type name whether a cast
5453 expression has a cast or a compound literal, or whether the operand
5454 of sizeof is a parenthesized type name or starts with a compound
5457 static struct c_expr
5458 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5459 struct c_type_name *type_name)
5464 start_init (NULL_TREE, NULL, 0);
5465 type = groktypename (type_name);
5466 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5468 error ("compound literal has variable size");
5469 type = error_mark_node;
5471 init = c_parser_braced_init (parser, type, false);
5473 maybe_warn_string_init (type, init);
5475 if (pedantic && !flag_isoc99)
5476 pedwarn ("ISO C90 forbids compound literals");
5477 expr.value = build_compound_literal (type, init.value);
5478 expr.original_code = ERROR_MARK;
5479 return c_parser_postfix_expression_after_primary (parser, expr);
5482 /* Parse a postfix expression after the initial primary or compound
5483 literal; that is, parse a series of postfix operators. */
5485 static struct c_expr
5486 c_parser_postfix_expression_after_primary (c_parser *parser,
5489 tree ident, idx, exprlist;
5492 switch (c_parser_peek_token (parser)->type)
5494 case CPP_OPEN_SQUARE:
5495 /* Array reference. */
5496 c_parser_consume_token (parser);
5497 idx = c_parser_expression (parser).value;
5498 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5500 expr.value = build_array_ref (expr.value, idx);
5501 expr.original_code = ERROR_MARK;
5503 case CPP_OPEN_PAREN:
5504 /* Function call. */
5505 c_parser_consume_token (parser);
5506 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5507 exprlist = NULL_TREE;
5509 exprlist = c_parser_expr_list (parser, true);
5510 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5512 expr.value = build_function_call (expr.value, exprlist);
5513 expr.original_code = ERROR_MARK;
5516 /* Structure element reference. */
5517 c_parser_consume_token (parser);
5518 expr = default_function_array_conversion (expr);
5519 if (c_parser_next_token_is (parser, CPP_NAME))
5520 ident = c_parser_peek_token (parser)->value;
5523 c_parser_error (parser, "expected identifier");
5524 expr.value = error_mark_node;
5525 expr.original_code = ERROR_MARK;
5528 c_parser_consume_token (parser);
5529 expr.value = build_component_ref (expr.value, ident);
5530 expr.original_code = ERROR_MARK;
5533 /* Structure element reference. */
5534 c_parser_consume_token (parser);
5535 expr = default_function_array_conversion (expr);
5536 if (c_parser_next_token_is (parser, CPP_NAME))
5537 ident = c_parser_peek_token (parser)->value;
5540 c_parser_error (parser, "expected identifier");
5541 expr.value = error_mark_node;
5542 expr.original_code = ERROR_MARK;
5545 c_parser_consume_token (parser);
5546 expr.value = build_component_ref (build_indirect_ref (expr.value,
5548 expr.original_code = ERROR_MARK;
5551 /* Postincrement. */
5552 c_parser_consume_token (parser);
5553 expr = default_function_array_conversion (expr);
5554 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5555 expr.original_code = ERROR_MARK;
5557 case CPP_MINUS_MINUS:
5558 /* Postdecrement. */
5559 c_parser_consume_token (parser);
5560 expr = default_function_array_conversion (expr);
5561 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5562 expr.original_code = ERROR_MARK;
5570 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5573 assignment-expression
5574 expression , assignment-expression
5577 static struct c_expr
5578 c_parser_expression (c_parser *parser)
5581 expr = c_parser_expr_no_commas (parser, NULL);
5582 while (c_parser_next_token_is (parser, CPP_COMMA))
5585 c_parser_consume_token (parser);
5586 next = c_parser_expr_no_commas (parser, NULL);
5587 next = default_function_array_conversion (next);
5588 expr.value = build_compound_expr (expr.value, next.value);
5589 expr.original_code = COMPOUND_EXPR;
5594 /* Parse an expression and convert functions or arrays to
5597 static struct c_expr
5598 c_parser_expression_conv (c_parser *parser)
5601 expr = c_parser_expression (parser);
5602 expr = default_function_array_conversion (expr);
5606 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5607 functions and arrays to pointers.
5610 assignment-expression
5611 nonempty-expr-list , assignment-expression
5615 c_parser_expr_list (c_parser *parser, bool convert_p)
5619 expr = c_parser_expr_no_commas (parser, NULL);
5621 expr = default_function_array_conversion (expr);
5622 ret = cur = build_tree_list (NULL_TREE, expr.value);
5623 while (c_parser_next_token_is (parser, CPP_COMMA))
5625 c_parser_consume_token (parser);
5626 expr = c_parser_expr_no_commas (parser, NULL);
5628 expr = default_function_array_conversion (expr);
5629 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5635 /* Parse Objective-C-specific constructs. */
5637 /* Parse an objc-class-definition.
5639 objc-class-definition:
5640 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5641 objc-class-instance-variables[opt] objc-methodprotolist @end
5642 @implementation identifier objc-superclass[opt]
5643 objc-class-instance-variables[opt]
5644 @interface identifier ( identifier ) objc-protocol-refs[opt]
5645 objc-methodprotolist @end
5646 @implementation identifier ( identifier )
5651 "@interface identifier (" must start "@interface identifier (
5652 identifier ) ...": objc-methodprotolist in the first production may
5653 not start with a parenthesized identifier as a declarator of a data
5654 definition with no declaration specifiers if the objc-superclass,
5655 objc-protocol-refs and objc-class-instance-variables are omitted. */
5658 c_parser_objc_class_definition (c_parser *parser)
5663 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5665 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5669 c_parser_consume_token (parser);
5670 if (c_parser_next_token_is_not (parser, CPP_NAME))
5672 c_parser_error (parser, "expected identifier");
5675 id1 = c_parser_peek_token (parser)->value;
5676 c_parser_consume_token (parser);
5677 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5680 tree proto = NULL_TREE;
5681 c_parser_consume_token (parser);
5682 if (c_parser_next_token_is_not (parser, CPP_NAME))
5684 c_parser_error (parser, "expected identifier");
5685 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5688 id2 = c_parser_peek_token (parser)->value;
5689 c_parser_consume_token (parser);
5690 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5693 objc_start_category_implementation (id1, id2);
5696 if (c_parser_next_token_is (parser, CPP_LESS))
5697 proto = c_parser_objc_protocol_refs (parser);
5698 objc_start_category_interface (id1, id2, proto);
5699 c_parser_objc_methodprotolist (parser);
5700 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5701 objc_finish_interface ();
5704 if (c_parser_next_token_is (parser, CPP_COLON))
5706 c_parser_consume_token (parser);
5707 if (c_parser_next_token_is_not (parser, CPP_NAME))
5709 c_parser_error (parser, "expected identifier");
5712 superclass = c_parser_peek_token (parser)->value;
5713 c_parser_consume_token (parser);
5716 superclass = NULL_TREE;
5719 tree proto = NULL_TREE;
5720 if (c_parser_next_token_is (parser, CPP_LESS))
5721 proto = c_parser_objc_protocol_refs (parser);
5722 objc_start_class_interface (id1, superclass, proto);
5725 objc_start_class_implementation (id1, superclass);
5726 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5727 c_parser_objc_class_instance_variables (parser);
5730 objc_continue_interface ();
5731 c_parser_objc_methodprotolist (parser);
5732 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5733 objc_finish_interface ();
5737 objc_continue_implementation ();
5742 /* Parse objc-class-instance-variables.
5744 objc-class-instance-variables:
5745 { objc-instance-variable-decl-list[opt] }
5747 objc-instance-variable-decl-list:
5748 objc-visibility-spec
5749 objc-instance-variable-decl ;
5751 objc-instance-variable-decl-list objc-visibility-spec
5752 objc-instance-variable-decl-list objc-instance-variable-decl ;
5753 objc-instance-variable-decl-list ;
5755 objc-visibility-spec:
5760 objc-instance-variable-decl:
5765 c_parser_objc_class_instance_variables (c_parser *parser)
5767 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5768 c_parser_consume_token (parser);
5769 while (c_parser_next_token_is_not (parser, CPP_EOF))
5772 /* Parse any stray semicolon. */
5773 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5776 pedwarn ("extra semicolon in struct or union specified");
5777 c_parser_consume_token (parser);
5780 /* Stop if at the end of the instance variables. */
5781 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5783 c_parser_consume_token (parser);
5786 /* Parse any objc-visibility-spec. */
5787 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5789 c_parser_consume_token (parser);
5790 objc_set_visibility (2);
5793 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5795 c_parser_consume_token (parser);
5796 objc_set_visibility (0);
5799 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5801 c_parser_consume_token (parser);
5802 objc_set_visibility (1);
5805 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5807 c_parser_pragma (parser, pragma_external);
5811 /* Parse some comma-separated declarations. */
5812 decls = c_parser_struct_declaration (parser);
5814 /* Comma-separated instance variables are chained together in
5815 reverse order; add them one by one. */
5816 tree ivar = nreverse (decls);
5817 for (; ivar; ivar = TREE_CHAIN (ivar))
5818 objc_add_instance_variable (copy_node (ivar));
5820 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5824 /* Parse an objc-class-declaration.
5826 objc-class-declaration:
5827 @class identifier-list ;
5831 c_parser_objc_class_declaration (c_parser *parser)
5833 tree list = NULL_TREE;
5834 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5835 c_parser_consume_token (parser);
5836 /* Any identifiers, including those declared as type names, are OK
5841 if (c_parser_next_token_is_not (parser, CPP_NAME))
5843 c_parser_error (parser, "expected identifier");
5846 id = c_parser_peek_token (parser)->value;
5847 list = chainon (list, build_tree_list (NULL_TREE, id));
5848 c_parser_consume_token (parser);
5849 if (c_parser_next_token_is (parser, CPP_COMMA))
5850 c_parser_consume_token (parser);
5854 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5855 objc_declare_class (list);
5858 /* Parse an objc-alias-declaration.
5860 objc-alias-declaration:
5861 @compatibility_alias identifier identifier ;
5865 c_parser_objc_alias_declaration (c_parser *parser)
5868 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5869 c_parser_consume_token (parser);
5870 if (c_parser_next_token_is_not (parser, CPP_NAME))
5872 c_parser_error (parser, "expected identifier");
5873 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5876 id1 = c_parser_peek_token (parser)->value;
5877 c_parser_consume_token (parser);
5878 if (c_parser_next_token_is_not (parser, CPP_NAME))
5880 c_parser_error (parser, "expected identifier");
5881 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5884 id2 = c_parser_peek_token (parser)->value;
5885 c_parser_consume_token (parser);
5886 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5887 objc_declare_alias (id1, id2);
5890 /* Parse an objc-protocol-definition.
5892 objc-protocol-definition:
5893 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5894 @protocol identifier-list ;
5896 "@protocol identifier ;" should be resolved as "@protocol
5897 identifier-list ;": objc-methodprotolist may not start with a
5898 semicolon in the first alternative if objc-protocol-refs are
5902 c_parser_objc_protocol_definition (c_parser *parser)
5904 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5905 c_parser_consume_token (parser);
5906 if (c_parser_next_token_is_not (parser, CPP_NAME))
5908 c_parser_error (parser, "expected identifier");
5911 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5912 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5914 tree list = NULL_TREE;
5915 /* Any identifiers, including those declared as type names, are
5920 if (c_parser_next_token_is_not (parser, CPP_NAME))
5922 c_parser_error (parser, "expected identifier");
5925 id = c_parser_peek_token (parser)->value;
5926 list = chainon (list, build_tree_list (NULL_TREE, id));
5927 c_parser_consume_token (parser);
5928 if (c_parser_next_token_is (parser, CPP_COMMA))
5929 c_parser_consume_token (parser);
5933 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5934 objc_declare_protocols (list);
5938 tree id = c_parser_peek_token (parser)->value;
5939 tree proto = NULL_TREE;
5940 c_parser_consume_token (parser);
5941 if (c_parser_next_token_is (parser, CPP_LESS))
5942 proto = c_parser_objc_protocol_refs (parser);
5943 parser->objc_pq_context = true;
5944 objc_start_protocol (id, proto);
5945 c_parser_objc_methodprotolist (parser);
5946 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5947 parser->objc_pq_context = false;
5948 objc_finish_interface ();
5952 /* Parse an objc-method-type.
5959 static enum tree_code
5960 c_parser_objc_method_type (c_parser *parser)
5962 switch (c_parser_peek_token (parser)->type)
5965 c_parser_consume_token (parser);
5968 c_parser_consume_token (parser);
5975 /* Parse an objc-method-definition.
5977 objc-method-definition:
5978 objc-method-type objc-method-decl ;[opt] compound-statement
5982 c_parser_objc_method_definition (c_parser *parser)
5984 enum tree_code type = c_parser_objc_method_type (parser);
5986 objc_set_method_type (type);
5987 parser->objc_pq_context = true;
5988 decl = c_parser_objc_method_decl (parser);
5989 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5991 c_parser_consume_token (parser);
5993 pedwarn ("extra semicolon in method definition specified");
5995 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5997 c_parser_error (parser, "expected %<{%>");
6000 parser->objc_pq_context = false;
6001 objc_start_method_definition (decl);
6002 add_stmt (c_parser_compound_statement (parser));
6003 objc_finish_method_definition (current_function_decl);
6006 /* Parse an objc-methodprotolist.
6008 objc-methodprotolist:
6010 objc-methodprotolist objc-methodproto
6011 objc-methodprotolist declaration
6012 objc-methodprotolist ;
6014 The declaration is a data definition, which may be missing
6015 declaration specifiers under the same rules and diagnostics as
6016 other data definitions outside functions, and the stray semicolon
6017 is diagnosed the same way as a stray semicolon outside a
6021 c_parser_objc_methodprotolist (c_parser *parser)
6025 /* The list is terminated by @end. */
6026 switch (c_parser_peek_token (parser)->type)
6030 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6031 c_parser_consume_token (parser);
6035 c_parser_objc_methodproto (parser);
6038 c_parser_pragma (parser, pragma_external);
6043 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6045 c_parser_declaration_or_fndef (parser, false, true, false, true);
6051 /* Parse an objc-methodproto.
6054 objc-method-type objc-method-decl ;
6058 c_parser_objc_methodproto (c_parser *parser)
6060 enum tree_code type = c_parser_objc_method_type (parser);
6062 objc_set_method_type (type);
6063 /* Remember protocol qualifiers in prototypes. */
6064 parser->objc_pq_context = true;
6065 decl = c_parser_objc_method_decl (parser);
6066 /* Forget protocol qualifiers here. */
6067 parser->objc_pq_context = false;
6068 objc_add_method_declaration (decl);
6069 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6072 /* Parse an objc-method-decl.
6075 ( objc-type-name ) objc-selector
6077 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6078 objc-keyword-selector objc-optparmlist
6080 objc-keyword-selector:
6082 objc-keyword-selector objc-keyword-decl
6085 objc-selector : ( objc-type-name ) identifier
6086 objc-selector : identifier
6087 : ( objc-type-name ) identifier
6091 objc-optparms objc-optellipsis
6095 objc-opt-parms , parameter-declaration
6103 c_parser_objc_method_decl (c_parser *parser)
6105 tree type = NULL_TREE;
6107 tree parms = NULL_TREE;
6108 bool ellipsis = false;
6110 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6112 c_parser_consume_token (parser);
6113 type = c_parser_objc_type_name (parser);
6114 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6116 sel = c_parser_objc_selector (parser);
6117 /* If there is no selector, or a colon follows, we have an
6118 objc-keyword-selector. If there is a selector, and a colon does
6119 not follow, that selector ends the objc-method-decl. */
6120 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6123 tree list = NULL_TREE;
6126 tree atype = NULL_TREE, id, keyworddecl;
6127 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6129 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6131 c_parser_consume_token (parser);
6132 atype = c_parser_objc_type_name (parser);
6133 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6136 if (c_parser_next_token_is_not (parser, CPP_NAME))
6138 c_parser_error (parser, "expected identifier");
6139 return error_mark_node;
6141 id = c_parser_peek_token (parser)->value;
6142 c_parser_consume_token (parser);
6143 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6144 list = chainon (list, keyworddecl);
6145 tsel = c_parser_objc_selector (parser);
6146 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6149 /* Parse the optional parameter list. Optional Objective-C
6150 method parameters follow the C syntax, and may include '...'
6151 to denote a variable number of arguments. */
6152 parms = make_node (TREE_LIST);
6153 while (c_parser_next_token_is (parser, CPP_COMMA))
6155 struct c_parm *parm;
6156 c_parser_consume_token (parser);
6157 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6160 c_parser_consume_token (parser);
6163 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6166 parms = chainon (parms,
6167 build_tree_list (NULL_TREE, grokparm (parm)));
6171 return objc_build_method_signature (type, sel, parms, ellipsis);
6174 /* Parse an objc-type-name.
6177 objc-type-qualifiers[opt] type-name
6178 objc-type-qualifiers[opt]
6180 objc-type-qualifiers:
6182 objc-type-qualifiers objc-type-qualifier
6184 objc-type-qualifier: one of
6185 in out inout bycopy byref oneway
6189 c_parser_objc_type_name (c_parser *parser)
6191 tree quals = NULL_TREE;
6192 struct c_type_name *typename = NULL;
6193 tree type = NULL_TREE;
6196 c_token *token = c_parser_peek_token (parser);
6197 if (token->type == CPP_KEYWORD
6198 && (token->keyword == RID_IN
6199 || token->keyword == RID_OUT
6200 || token->keyword == RID_INOUT
6201 || token->keyword == RID_BYCOPY
6202 || token->keyword == RID_BYREF
6203 || token->keyword == RID_ONEWAY))
6205 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6206 c_parser_consume_token (parser);
6211 if (c_parser_next_token_starts_typename (parser))
6212 typename = c_parser_type_name (parser);
6214 type = groktypename (typename);
6215 return build_tree_list (quals, type);
6218 /* Parse objc-protocol-refs.
6225 c_parser_objc_protocol_refs (c_parser *parser)
6227 tree list = NULL_TREE;
6228 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6229 c_parser_consume_token (parser);
6230 /* Any identifiers, including those declared as type names, are OK
6235 if (c_parser_next_token_is_not (parser, CPP_NAME))
6237 c_parser_error (parser, "expected identifier");
6240 id = c_parser_peek_token (parser)->value;
6241 list = chainon (list, build_tree_list (NULL_TREE, id));
6242 c_parser_consume_token (parser);
6243 if (c_parser_next_token_is (parser, CPP_COMMA))
6244 c_parser_consume_token (parser);
6248 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6252 /* Parse an objc-try-catch-statement.
6254 objc-try-catch-statement:
6255 @try compound-statement objc-catch-list[opt]
6256 @try compound-statement objc-catch-list[opt] @finally compound-statement
6259 @catch ( parameter-declaration ) compound-statement
6260 objc-catch-list @catch ( parameter-declaration ) compound-statement
6264 c_parser_objc_try_catch_statement (c_parser *parser)
6268 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6269 c_parser_consume_token (parser);
6270 loc = c_parser_peek_token (parser)->location;
6271 stmt = c_parser_compound_statement (parser);
6272 objc_begin_try_stmt (loc, stmt);
6273 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6275 struct c_parm *parm;
6276 c_parser_consume_token (parser);
6277 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6279 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6285 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6286 objc_begin_catch_clause (grokparm (parm));
6287 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6288 c_parser_compound_statement_nostart (parser);
6289 objc_finish_catch_clause ();
6291 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6295 c_parser_consume_token (parser);
6296 finloc = c_parser_peek_token (parser)->location;
6297 finstmt = c_parser_compound_statement (parser);
6298 objc_build_finally_clause (finloc, finstmt);
6300 objc_finish_try_stmt ();
6303 /* Parse an objc-synchronized-statement.
6305 objc-synchronized-statement:
6306 @synchronized ( expression ) compound-statement
6310 c_parser_objc_synchronized_statement (c_parser *parser)
6314 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6315 c_parser_consume_token (parser);
6316 loc = c_parser_peek_token (parser)->location;
6317 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6319 expr = c_parser_expression (parser).value;
6320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6323 expr = error_mark_node;
6324 stmt = c_parser_compound_statement (parser);
6325 objc_build_synchronized (loc, expr, stmt);
6328 /* Parse an objc-selector; return NULL_TREE without an error if the
6329 next token is not an objc-selector.
6334 enum struct union if else while do for switch case default
6335 break continue return goto asm sizeof typeof __alignof
6336 unsigned long const short volatile signed restrict _Complex
6337 in out inout bycopy byref oneway int char float double void _Bool
6339 ??? Why this selection of keywords but not, for example, storage
6340 class specifiers? */
6343 c_parser_objc_selector (c_parser *parser)
6345 c_token *token = c_parser_peek_token (parser);
6346 tree value = token->value;
6347 if (token->type == CPP_NAME)
6349 c_parser_consume_token (parser);
6352 if (token->type != CPP_KEYWORD)
6354 switch (token->keyword)
6395 c_parser_consume_token (parser);
6402 /* Parse an objc-selector-arg.
6406 objc-keywordname-list
6408 objc-keywordname-list:
6410 objc-keywordname-list objc-keywordname
6418 c_parser_objc_selector_arg (c_parser *parser)
6420 tree sel = c_parser_objc_selector (parser);
6421 tree list = NULL_TREE;
6422 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6426 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6428 list = chainon (list, build_tree_list (sel, NULL_TREE));
6429 sel = c_parser_objc_selector (parser);
6430 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6436 /* Parse an objc-receiver.
6445 c_parser_objc_receiver (c_parser *parser)
6447 if (c_parser_peek_token (parser)->type == CPP_NAME
6448 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6449 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6451 tree id = c_parser_peek_token (parser)->value;
6452 c_parser_consume_token (parser);
6453 return objc_get_class_reference (id);
6455 return c_parser_expression (parser).value;
6458 /* Parse objc-message-args.
6462 objc-keywordarg-list
6464 objc-keywordarg-list:
6466 objc-keywordarg-list objc-keywordarg
6469 objc-selector : objc-keywordexpr
6474 c_parser_objc_message_args (c_parser *parser)
6476 tree sel = c_parser_objc_selector (parser);
6477 tree list = NULL_TREE;
6478 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6483 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6485 keywordexpr = c_parser_objc_keywordexpr (parser);
6486 list = chainon (list, build_tree_list (sel, keywordexpr));
6487 sel = c_parser_objc_selector (parser);
6488 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6494 /* Parse an objc-keywordexpr.
6501 c_parser_objc_keywordexpr (c_parser *parser)
6503 tree list = c_parser_expr_list (parser, true);
6504 if (TREE_CHAIN (list) == NULL_TREE)
6506 /* Just return the expression, remove a level of
6508 return TREE_VALUE (list);
6512 /* We have a comma expression, we will collapse later. */
6518 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6519 should be considered, statements. ALLOW_STMT is true if we're within
6520 the context of a function and such pragmas are to be allowed. Returns
6521 true if we actually parsed such a pragma. */
6524 c_parser_pragma (c_parser *parser, enum pragma_context context)
6528 id = c_parser_peek_token (parser)->pragma_kind;
6529 gcc_assert (id != PRAGMA_NONE);
6533 case PRAGMA_OMP_BARRIER:
6534 if (context != pragma_compound)
6536 if (context == pragma_stmt)
6537 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6538 "used in compound statements");
6541 c_parser_omp_barrier (parser);
6544 case PRAGMA_OMP_FLUSH:
6545 if (context != pragma_compound)
6547 if (context == pragma_stmt)
6548 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6549 "used in compound statements");
6552 c_parser_omp_flush (parser);
6555 case PRAGMA_OMP_THREADPRIVATE:
6556 c_parser_omp_threadprivate (parser);
6559 case PRAGMA_OMP_SECTION:
6560 error ("%<#pragma omp section%> may only be used in "
6561 "%<#pragma omp sections%> construct");
6562 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6565 case PRAGMA_GCC_PCH_PREPROCESS:
6566 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6567 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6571 if (id < PRAGMA_FIRST_EXTERNAL)
6573 if (context == pragma_external)
6576 c_parser_error (parser, "expected declaration specifiers");
6577 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6580 c_parser_omp_construct (parser);
6586 c_parser_consume_pragma (parser);
6587 c_invoke_pragma_handler (id);
6589 /* Skip to EOL, but suppress any error message. Those will have been
6590 generated by the handler routine through calling error, as opposed
6591 to calling c_parser_error. */
6592 parser->error = true;
6593 c_parser_skip_to_pragma_eol (parser);
6598 /* The interface the pragma parsers have to the lexer. */
6601 pragma_lex (tree *value)
6603 c_token *tok = c_parser_peek_token (the_parser);
6604 enum cpp_ttype ret = tok->type;
6606 *value = tok->value;
6607 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6611 if (ret == CPP_KEYWORD)
6613 c_parser_consume_token (the_parser);
6620 c_parser_pragma_pch_preprocess (c_parser *parser)
6624 c_parser_consume_pragma (parser);
6625 if (c_parser_next_token_is (parser, CPP_STRING))
6627 name = c_parser_peek_token (parser)->value;
6628 c_parser_consume_token (parser);
6631 c_parser_error (parser, "expected string literal");
6632 c_parser_skip_to_pragma_eol (parser);
6635 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6638 /* OpenMP 2.5 parsing routines. */
6640 /* Returns name of the next clause.
6641 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6642 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6643 returned and the token is consumed. */
6645 static pragma_omp_clause
6646 c_parser_omp_clause_name (c_parser *parser)
6648 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6650 if (c_parser_next_token_is_keyword (parser, RID_IF))
6651 result = PRAGMA_OMP_CLAUSE_IF;
6652 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6653 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6654 else if (c_parser_next_token_is (parser, CPP_NAME))
6656 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6661 if (!strcmp ("copyin", p))
6662 result = PRAGMA_OMP_CLAUSE_COPYIN;
6663 else if (!strcmp ("copyprivate", p))
6664 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6667 if (!strcmp ("firstprivate", p))
6668 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6671 if (!strcmp ("lastprivate", p))
6672 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6675 if (!strcmp ("nowait", p))
6676 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6677 else if (!strcmp ("num_threads", p))
6678 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6681 if (!strcmp ("ordered", p))
6682 result = PRAGMA_OMP_CLAUSE_ORDERED;
6685 if (!strcmp ("private", p))
6686 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6689 if (!strcmp ("reduction", p))
6690 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6693 if (!strcmp ("schedule", p))
6694 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6695 else if (!strcmp ("shared", p))
6696 result = PRAGMA_OMP_CLAUSE_SHARED;
6701 if (result != PRAGMA_OMP_CLAUSE_NONE)
6702 c_parser_consume_token (parser);
6707 /* Validate that a clause of the given type does not already exist. */
6710 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6714 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6715 if (OMP_CLAUSE_CODE (c) == code)
6717 error ("too many %qs clauses", name);
6725 variable-list , identifier
6727 If KIND is nonzero, create the appropriate node and install the decl
6728 in OMP_CLAUSE_DECL and add the node to the head of the list.
6730 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6731 return the list created. */
6734 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6737 if (c_parser_next_token_is_not (parser, CPP_NAME)
6738 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6739 c_parser_error (parser, "expected identifier");
6741 while (c_parser_next_token_is (parser, CPP_NAME)
6742 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6744 tree t = lookup_name (c_parser_peek_token (parser)->value);
6747 undeclared_variable (c_parser_peek_token (parser)->value,
6748 c_parser_peek_token (parser)->location);
6749 else if (t == error_mark_node)
6753 tree u = build_omp_clause (kind);
6754 OMP_CLAUSE_DECL (u) = t;
6755 OMP_CLAUSE_CHAIN (u) = list;
6759 list = tree_cons (t, NULL_TREE, list);
6761 c_parser_consume_token (parser);
6763 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6766 c_parser_consume_token (parser);
6772 /* Similarly, but expect leading and trailing parenthesis. This is a very
6773 common case for omp clauses. */
6776 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6778 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6780 list = c_parser_omp_variable_list (parser, kind, list);
6781 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6787 copyin ( variable-list ) */
6790 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6792 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6796 copyprivate ( variable-list ) */
6799 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6801 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6805 default ( shared | none ) */
6808 c_parser_omp_clause_default (c_parser *parser, tree list)
6810 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6813 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6815 if (c_parser_next_token_is (parser, CPP_NAME))
6817 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6822 if (strcmp ("none", p) != 0)
6824 kind = OMP_CLAUSE_DEFAULT_NONE;
6828 if (strcmp ("shared", p) != 0)
6830 kind = OMP_CLAUSE_DEFAULT_SHARED;
6837 c_parser_consume_token (parser);
6842 c_parser_error (parser, "expected %<none%> or %<shared%>");
6844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6846 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6849 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6850 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6851 OMP_CLAUSE_CHAIN (c) = list;
6852 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6858 firstprivate ( variable-list ) */
6861 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6863 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6867 if ( expression ) */
6870 c_parser_omp_clause_if (c_parser *parser, tree list)
6872 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6874 tree t = c_parser_paren_condition (parser);
6877 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6879 c = build_omp_clause (OMP_CLAUSE_IF);
6880 OMP_CLAUSE_IF_EXPR (c) = t;
6881 OMP_CLAUSE_CHAIN (c) = list;
6885 c_parser_error (parser, "expected %<(%>");
6891 lastprivate ( variable-list ) */
6894 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6896 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6903 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6907 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6909 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6910 OMP_CLAUSE_CHAIN (c) = list;
6915 num_threads ( expression ) */
6918 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6920 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6922 tree c, t = c_parser_expression (parser).value;
6924 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6926 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6928 c_parser_error (parser, "expected integer expression");
6932 /* Attempt to statically determine when the number isn't positive. */
6933 c = fold_build2 (LE_EXPR, boolean_type_node, t,
6934 build_int_cst (TREE_TYPE (t), 0));
6935 if (c == boolean_true_node)
6937 warning (0, "%<num_threads%> value must be positive");
6938 t = integer_one_node;
6941 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
6943 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
6944 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
6945 OMP_CLAUSE_CHAIN (c) = list;
6956 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6960 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
6962 c = build_omp_clause (OMP_CLAUSE_ORDERED);
6963 OMP_CLAUSE_CHAIN (c) = list;
6968 private ( variable-list ) */
6971 c_parser_omp_clause_private (c_parser *parser, tree list)
6973 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
6977 reduction ( reduction-operator : variable-list )
6980 One of: + * - & ^ | && || */
6983 c_parser_omp_clause_reduction (c_parser *parser, tree list)
6985 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6987 enum tree_code code;
6989 switch (c_parser_peek_token (parser)->type)
7001 code = BIT_AND_EXPR;
7004 code = BIT_XOR_EXPR;
7007 code = BIT_IOR_EXPR;
7010 code = TRUTH_ANDIF_EXPR;
7013 code = TRUTH_ORIF_EXPR;
7016 c_parser_error (parser,
7017 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7018 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7019 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7022 c_parser_consume_token (parser);
7023 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7027 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
7028 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7029 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7033 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7039 schedule ( schedule-kind )
7040 schedule ( schedule-kind , expression )
7043 static | dynamic | guided | runtime
7047 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7051 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7054 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7056 if (c_parser_next_token_is (parser, CPP_NAME))
7058 tree kind = c_parser_peek_token (parser)->value;
7059 const char *p = IDENTIFIER_POINTER (kind);
7064 if (strcmp ("dynamic", p) != 0)
7066 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7070 if (strcmp ("guided", p) != 0)
7072 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7076 if (strcmp ("runtime", p) != 0)
7078 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7085 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7086 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7090 c_parser_consume_token (parser);
7091 if (c_parser_next_token_is (parser, CPP_COMMA))
7093 c_parser_consume_token (parser);
7095 t = c_parser_expr_no_commas (parser, NULL).value;
7097 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7098 error ("schedule %<runtime%> does not take "
7099 "a %<chunk_size%> parameter");
7100 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7101 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7103 c_parser_error (parser, "expected integer expression");
7105 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7108 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7109 "expected %<,%> or %<)%>");
7111 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7112 OMP_CLAUSE_CHAIN (c) = list;
7116 c_parser_error (parser, "invalid schedule kind");
7117 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7122 shared ( variable-list ) */
7125 c_parser_omp_clause_shared (c_parser *parser, tree list)
7127 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7130 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7131 is a bitmask in MASK. Return the list of clauses found; the result
7132 of clause default goes in *pdefault. */
7135 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7138 tree clauses = NULL;
7140 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7142 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7144 tree prev = clauses;
7148 case PRAGMA_OMP_CLAUSE_COPYIN:
7149 clauses = c_parser_omp_clause_copyin (parser, clauses);
7152 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7153 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7154 c_name = "copyprivate";
7156 case PRAGMA_OMP_CLAUSE_DEFAULT:
7157 clauses = c_parser_omp_clause_default (parser, clauses);
7160 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7161 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7162 c_name = "firstprivate";
7164 case PRAGMA_OMP_CLAUSE_IF:
7165 clauses = c_parser_omp_clause_if (parser, clauses);
7168 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7169 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7170 c_name = "lastprivate";
7172 case PRAGMA_OMP_CLAUSE_NOWAIT:
7173 clauses = c_parser_omp_clause_nowait (parser, clauses);
7176 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7177 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7178 c_name = "num_threads";
7180 case PRAGMA_OMP_CLAUSE_ORDERED:
7181 clauses = c_parser_omp_clause_ordered (parser, clauses);
7184 case PRAGMA_OMP_CLAUSE_PRIVATE:
7185 clauses = c_parser_omp_clause_private (parser, clauses);
7188 case PRAGMA_OMP_CLAUSE_REDUCTION:
7189 clauses = c_parser_omp_clause_reduction (parser, clauses);
7190 c_name = "reduction";
7192 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7193 clauses = c_parser_omp_clause_schedule (parser, clauses);
7194 c_name = "schedule";
7196 case PRAGMA_OMP_CLAUSE_SHARED:
7197 clauses = c_parser_omp_clause_shared (parser, clauses);
7201 c_parser_error (parser, "expected %<#pragma omp%> clause");
7205 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7207 /* Remove the invalid clause(s) from the list to avoid
7208 confusing the rest of the compiler. */
7210 error ("%qs is not valid for %qs", c_name, where);
7215 c_parser_skip_to_pragma_eol (parser);
7217 return c_finish_omp_clauses (clauses);
7224 In practice, we're also interested in adding the statement to an
7225 outer node. So it is convenient if we work around the fact that
7226 c_parser_statement calls add_stmt. */
7229 c_parser_omp_structured_block (c_parser *parser)
7231 tree stmt = push_stmt_list ();
7232 c_parser_statement (parser);
7233 return pop_stmt_list (stmt);
7237 # pragma omp atomic new-line
7241 x binop= expr | x++ | ++x | x-- | --x
7243 +, *, -, /, &, ^, |, <<, >>
7245 where x is an lvalue expression with scalar type. */
7248 c_parser_omp_atomic (c_parser *parser)
7252 enum tree_code code;
7254 c_parser_skip_to_pragma_eol (parser);
7256 lhs = c_parser_unary_expression (parser).value;
7257 switch (TREE_CODE (lhs))
7261 c_parser_skip_to_end_of_block_or_statement (parser);
7264 case PREINCREMENT_EXPR:
7265 case POSTINCREMENT_EXPR:
7266 lhs = TREE_OPERAND (lhs, 0);
7268 rhs = integer_one_node;
7271 case PREDECREMENT_EXPR:
7272 case POSTDECREMENT_EXPR:
7273 lhs = TREE_OPERAND (lhs, 0);
7275 rhs = integer_one_node;
7279 switch (c_parser_peek_token (parser)->type)
7285 code = TRUNC_DIV_EXPR;
7300 code = BIT_AND_EXPR;
7303 code = BIT_IOR_EXPR;
7306 code = BIT_XOR_EXPR;
7309 c_parser_error (parser,
7310 "invalid operator for %<#pragma omp atomic%>");
7314 c_parser_consume_token (parser);
7315 rhs = c_parser_expression (parser).value;
7318 stmt = c_finish_omp_atomic (code, lhs, rhs);
7319 if (stmt != error_mark_node)
7321 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7326 # pragma omp barrier new-line
7330 c_parser_omp_barrier (c_parser *parser)
7332 c_parser_consume_pragma (parser);
7333 c_parser_skip_to_pragma_eol (parser);
7335 c_finish_omp_barrier ();
7339 # pragma omp critical [(name)] new-line
7344 c_parser_omp_critical (c_parser *parser)
7346 tree stmt, name = NULL;
7348 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7350 c_parser_consume_token (parser);
7351 if (c_parser_next_token_is (parser, CPP_NAME))
7353 name = c_parser_peek_token (parser)->value;
7354 c_parser_consume_token (parser);
7355 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7358 c_parser_error (parser, "expected identifier");
7360 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7361 c_parser_error (parser, "expected %<(%> or end of line");
7362 c_parser_skip_to_pragma_eol (parser);
7364 stmt = c_parser_omp_structured_block (parser);
7365 return c_finish_omp_critical (stmt, name);
7369 # pragma omp flush flush-vars[opt] new-line
7372 ( variable-list ) */
7375 c_parser_omp_flush (c_parser *parser)
7377 c_parser_consume_pragma (parser);
7378 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7379 c_parser_omp_var_list_parens (parser, 0, NULL);
7380 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7381 c_parser_error (parser, "expected %<(%> or end of line");
7382 c_parser_skip_to_pragma_eol (parser);
7384 c_finish_omp_flush ();
7387 /* Parse the restricted form of the for statment allowed by OpenMP.
7388 The real trick here is to determine the loop control variable early
7389 so that we can push a new decl if necessary to make it private. */
7392 c_parser_omp_for_loop (c_parser *parser)
7394 tree decl, cond, incr, save_break, save_cont, body, init;
7397 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7399 c_parser_error (parser, "for statement expected");
7402 loc = c_parser_peek_token (parser)->location;
7403 c_parser_consume_token (parser);
7405 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7408 /* Parse the initialization declaration or expression. */
7409 if (c_parser_next_token_starts_declspecs (parser))
7411 c_parser_declaration_or_fndef (parser, true, true, true, true);
7412 decl = check_for_loop_decls ();
7417 else if (c_parser_next_token_is (parser, CPP_NAME)
7418 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7420 decl = c_parser_postfix_expression (parser).value;
7422 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7424 init = c_parser_expr_no_commas (parser, NULL).value;
7425 init = build_modify_expr (decl, NOP_EXPR, init);
7426 init = c_process_expr_stmt (init);
7428 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7433 /* Parse the loop condition. */
7435 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7437 cond = c_parser_expression_conv (parser).value;
7438 cond = c_objc_common_truthvalue_conversion (cond);
7439 if (CAN_HAVE_LOCATION_P (cond))
7440 SET_EXPR_LOCATION (cond, input_location);
7442 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7444 /* Parse the increment expression. */
7446 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7447 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7448 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7451 save_break = c_break_label;
7452 c_break_label = size_one_node;
7453 save_cont = c_cont_label;
7454 c_cont_label = NULL_TREE;
7455 body = push_stmt_list ();
7457 add_stmt (c_parser_c99_block_statement (parser));
7459 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7461 body = pop_stmt_list (body);
7462 c_break_label = save_break;
7463 c_cont_label = save_cont;
7465 /* Only bother calling c_finish_omp_for if we havn't already generated
7466 an error from the initialization parsing. */
7467 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7468 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7472 c_parser_error (parser, "expected iteration declaration or initialization");
7473 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7474 decl = init = cond = incr = NULL_TREE;
7479 #pragma omp for for-clause[optseq] new-line
7483 #define OMP_FOR_CLAUSE_MASK \
7484 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7485 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7486 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7487 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7488 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7489 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7490 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7493 c_parser_omp_for (c_parser *parser)
7495 tree block, clauses, ret;
7497 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7500 block = c_begin_compound_stmt (true);
7501 ret = c_parser_omp_for_loop (parser);
7503 OMP_FOR_CLAUSES (ret) = clauses;
7504 block = c_end_compound_stmt (block, true);
7511 # pragma omp master new-line
7516 c_parser_omp_master (c_parser *parser)
7518 c_parser_skip_to_pragma_eol (parser);
7519 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7523 # pragma omp ordered new-line
7528 c_parser_omp_ordered (c_parser *parser)
7530 c_parser_skip_to_pragma_eol (parser);
7531 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7537 { section-sequence }
7540 section-directive[opt] structured-block
7541 section-sequence section-directive structured-block */
7544 c_parser_omp_sections_scope (c_parser *parser)
7547 bool error_suppress = false;
7550 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7552 /* Avoid skipping until the end of the block. */
7553 parser->error = false;
7557 stmt = push_stmt_list ();
7559 loc = c_parser_peek_token (parser)->location;
7560 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7562 substmt = push_stmt_list ();
7566 c_parser_statement (parser);
7568 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7570 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7572 if (c_parser_next_token_is (parser, CPP_EOF))
7576 substmt = pop_stmt_list (substmt);
7577 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7578 SET_EXPR_LOCATION (substmt, loc);
7584 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7586 if (c_parser_next_token_is (parser, CPP_EOF))
7589 loc = c_parser_peek_token (parser)->location;
7590 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7592 c_parser_consume_pragma (parser);
7593 c_parser_skip_to_pragma_eol (parser);
7594 error_suppress = false;
7596 else if (!error_suppress)
7598 error ("expected %<#pragma omp section%> or %<}%>");
7599 error_suppress = true;
7602 substmt = c_parser_omp_structured_block (parser);
7603 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7604 SET_EXPR_LOCATION (substmt, loc);
7607 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7608 "expected %<#pragma omp section%> or %<}%>");
7610 substmt = pop_stmt_list (stmt);
7612 stmt = make_node (OMP_SECTIONS);
7613 TREE_TYPE (stmt) = void_type_node;
7614 OMP_SECTIONS_BODY (stmt) = substmt;
7616 return add_stmt (stmt);
7620 # pragma omp sections sections-clause[optseq] newline
7624 #define OMP_SECTIONS_CLAUSE_MASK \
7625 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7626 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7627 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7628 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7629 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7632 c_parser_omp_sections (c_parser *parser)
7634 tree block, clauses, ret;
7636 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7637 "#pragma omp sections");
7639 block = c_begin_compound_stmt (true);
7640 ret = c_parser_omp_sections_scope (parser);
7642 OMP_SECTIONS_CLAUSES (ret) = clauses;
7643 block = c_end_compound_stmt (block, true);
7650 # pragma parallel parallel-clause new-line
7651 # pragma parallel for parallel-for-clause new-line
7652 # pragma parallel sections parallel-sections-clause new-line
7655 #define OMP_PARALLEL_CLAUSE_MASK \
7656 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7657 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7658 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7659 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7660 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7661 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7662 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7663 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7666 c_parser_omp_parallel (c_parser *parser)
7668 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7669 const char *p_name = "#pragma omp parallel";
7670 tree stmt, clauses, par_clause, ws_clause, block;
7671 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7673 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7675 c_parser_consume_token (parser);
7676 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7677 p_name = "#pragma omp parallel for";
7678 mask |= OMP_FOR_CLAUSE_MASK;
7679 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7681 else if (c_parser_next_token_is (parser, CPP_NAME))
7683 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7684 if (strcmp (p, "sections") == 0)
7686 c_parser_consume_token (parser);
7687 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7688 p_name = "#pragma omp parallel sections";
7689 mask |= OMP_SECTIONS_CLAUSE_MASK;
7690 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7694 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7698 case PRAGMA_OMP_PARALLEL:
7699 block = c_begin_omp_parallel ();
7700 c_parser_statement (parser);
7701 stmt = c_finish_omp_parallel (clauses, block);
7704 case PRAGMA_OMP_PARALLEL_FOR:
7705 block = c_begin_omp_parallel ();
7706 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7707 stmt = c_parser_omp_for_loop (parser);
7709 OMP_FOR_CLAUSES (stmt) = ws_clause;
7710 stmt = c_finish_omp_parallel (par_clause, block);
7711 OMP_PARALLEL_COMBINED (stmt) = 1;
7714 case PRAGMA_OMP_PARALLEL_SECTIONS:
7715 block = c_begin_omp_parallel ();
7716 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7717 stmt = c_parser_omp_sections_scope (parser);
7719 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7720 stmt = c_finish_omp_parallel (par_clause, block);
7721 OMP_PARALLEL_COMBINED (stmt) = 1;
7732 # pragma omp single single-clause[optseq] new-line
7736 #define OMP_SINGLE_CLAUSE_MASK \
7737 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7738 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7739 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7740 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7743 c_parser_omp_single (c_parser *parser)
7745 tree stmt = make_node (OMP_SINGLE);
7746 TREE_TYPE (stmt) = void_type_node;
7748 OMP_SINGLE_CLAUSES (stmt)
7749 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7750 "#pragma omp single");
7751 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7753 return add_stmt (stmt);
7757 /* Main entry point to parsing most OpenMP pragmas. */
7760 c_parser_omp_construct (c_parser *parser)
7762 enum pragma_kind p_kind;
7766 loc = c_parser_peek_token (parser)->location;
7767 p_kind = c_parser_peek_token (parser)->pragma_kind;
7768 c_parser_consume_pragma (parser);
7770 /* For all constructs below except #pragma omp atomic
7771 MUST_NOT_THROW catch handlers are needed when exceptions
7773 if (p_kind != PRAGMA_OMP_ATOMIC)
7774 c_maybe_initialize_eh ();
7778 case PRAGMA_OMP_ATOMIC:
7779 c_parser_omp_atomic (parser);
7781 case PRAGMA_OMP_CRITICAL:
7782 stmt = c_parser_omp_critical (parser);
7784 case PRAGMA_OMP_FOR:
7785 stmt = c_parser_omp_for (parser);
7787 case PRAGMA_OMP_MASTER:
7788 stmt = c_parser_omp_master (parser);
7790 case PRAGMA_OMP_ORDERED:
7791 stmt = c_parser_omp_ordered (parser);
7793 case PRAGMA_OMP_PARALLEL:
7794 stmt = c_parser_omp_parallel (parser);
7796 case PRAGMA_OMP_SECTIONS:
7797 stmt = c_parser_omp_sections (parser);
7799 case PRAGMA_OMP_SINGLE:
7800 stmt = c_parser_omp_single (parser);
7807 SET_EXPR_LOCATION (stmt, loc);
7812 # pragma omp threadprivate (variable-list) */
7815 c_parser_omp_threadprivate (c_parser *parser)
7819 c_parser_consume_pragma (parser);
7820 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7822 /* Mark every variable in VARS to be assigned thread local storage. */
7823 for (t = vars; t; t = TREE_CHAIN (t))
7825 tree v = TREE_PURPOSE (t);
7827 /* If V had already been marked threadprivate, it doesn't matter
7828 whether it had been used prior to this point. */
7829 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7830 error ("%qE declared %<threadprivate%> after first use", v);
7831 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7832 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7833 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7834 error ("%<threadprivate%> %qE has incomplete type", v);
7837 if (! DECL_THREAD_LOCAL_P (v))
7839 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7840 /* If rtl has been already set for this var, call
7841 make_decl_rtl once again, so that encode_section_info
7842 has a chance to look at the new decl flags. */
7843 if (DECL_RTL_SET_P (v))
7846 C_DECL_THREADPRIVATE_P (v) = 1;
7850 c_parser_skip_to_pragma_eol (parser);
7854 /* Parse a single source file. */
7859 /* Use local storage to begin. If the first token is a pragma, parse it.
7860 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7861 which will cause garbage collection. */
7864 memset (&tparser, 0, sizeof tparser);
7865 the_parser = &tparser;
7867 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7868 c_parser_pragma_pch_preprocess (&tparser);
7870 the_parser = GGC_NEW (c_parser);
7871 *the_parser = tparser;
7873 c_parser_translation_unit (the_parser);
7877 #include "gt-c-parser.h"