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 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
84 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
85 { "__alignof", RID_ALIGNOF, 0 },
86 { "__alignof__", RID_ALIGNOF, 0 },
87 { "__asm", RID_ASM, 0 },
88 { "__asm__", RID_ASM, 0 },
89 { "__attribute", RID_ATTRIBUTE, 0 },
90 { "__attribute__", RID_ATTRIBUTE, 0 },
91 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
92 { "__builtin_offsetof", RID_OFFSETOF, 0 },
93 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
94 { "__builtin_va_arg", RID_VA_ARG, 0 },
95 { "__complex", RID_COMPLEX, 0 },
96 { "__complex__", RID_COMPLEX, 0 },
97 { "__const", RID_CONST, 0 },
98 { "__const__", RID_CONST, 0 },
99 { "__extension__", RID_EXTENSION, 0 },
100 { "__func__", RID_C99_FUNCTION_NAME, 0 },
101 { "__imag", RID_IMAGPART, 0 },
102 { "__imag__", RID_IMAGPART, 0 },
103 { "__inline", RID_INLINE, 0 },
104 { "__inline__", RID_INLINE, 0 },
105 { "__label__", RID_LABEL, 0 },
106 { "__real", RID_REALPART, 0 },
107 { "__real__", RID_REALPART, 0 },
108 { "__restrict", RID_RESTRICT, 0 },
109 { "__restrict__", RID_RESTRICT, 0 },
110 { "__signed", RID_SIGNED, 0 },
111 { "__signed__", RID_SIGNED, 0 },
112 { "__thread", RID_THREAD, 0 },
113 { "__typeof", RID_TYPEOF, 0 },
114 { "__typeof__", RID_TYPEOF, 0 },
115 { "__volatile", RID_VOLATILE, 0 },
116 { "__volatile__", RID_VOLATILE, 0 },
117 { "asm", RID_ASM, D_EXT },
118 { "auto", RID_AUTO, 0 },
119 { "break", RID_BREAK, 0 },
120 { "case", RID_CASE, 0 },
121 { "char", RID_CHAR, 0 },
122 { "const", RID_CONST, 0 },
123 { "continue", RID_CONTINUE, 0 },
124 { "default", RID_DEFAULT, 0 },
126 { "double", RID_DOUBLE, 0 },
127 { "else", RID_ELSE, 0 },
128 { "enum", RID_ENUM, 0 },
129 { "extern", RID_EXTERN, 0 },
130 { "float", RID_FLOAT, 0 },
131 { "for", RID_FOR, 0 },
132 { "goto", RID_GOTO, 0 },
134 { "inline", RID_INLINE, D_EXT89 },
135 { "int", RID_INT, 0 },
136 { "long", RID_LONG, 0 },
137 { "register", RID_REGISTER, 0 },
138 { "restrict", RID_RESTRICT, D_C89 },
139 { "return", RID_RETURN, 0 },
140 { "short", RID_SHORT, 0 },
141 { "signed", RID_SIGNED, 0 },
142 { "sizeof", RID_SIZEOF, 0 },
143 { "static", RID_STATIC, 0 },
144 { "struct", RID_STRUCT, 0 },
145 { "switch", RID_SWITCH, 0 },
146 { "typedef", RID_TYPEDEF, 0 },
147 { "typeof", RID_TYPEOF, D_EXT },
148 { "union", RID_UNION, 0 },
149 { "unsigned", RID_UNSIGNED, 0 },
150 { "void", RID_VOID, 0 },
151 { "volatile", RID_VOLATILE, 0 },
152 { "while", RID_WHILE, 0 },
153 /* These Objective-C keywords are recognized only immediately after
155 { "class", RID_AT_CLASS, D_OBJC },
156 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
157 { "defs", RID_AT_DEFS, D_OBJC },
158 { "encode", RID_AT_ENCODE, D_OBJC },
159 { "end", RID_AT_END, D_OBJC },
160 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
161 { "interface", RID_AT_INTERFACE, D_OBJC },
162 { "private", RID_AT_PRIVATE, D_OBJC },
163 { "protected", RID_AT_PROTECTED, D_OBJC },
164 { "protocol", RID_AT_PROTOCOL, D_OBJC },
165 { "public", RID_AT_PUBLIC, D_OBJC },
166 { "selector", RID_AT_SELECTOR, D_OBJC },
167 { "throw", RID_AT_THROW, D_OBJC },
168 { "try", RID_AT_TRY, D_OBJC },
169 { "catch", RID_AT_CATCH, D_OBJC },
170 { "finally", RID_AT_FINALLY, D_OBJC },
171 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
172 /* These are recognized only in protocol-qualifier context
174 { "bycopy", RID_BYCOPY, D_OBJC },
175 { "byref", RID_BYREF, D_OBJC },
176 { "in", RID_IN, D_OBJC },
177 { "inout", RID_INOUT, D_OBJC },
178 { "oneway", RID_ONEWAY, D_OBJC },
179 { "out", RID_OUT, D_OBJC },
181 #define N_reswords (sizeof reswords / sizeof (struct resword))
183 /* Initialization routine for this file. */
188 /* The only initialization required is of the reserved word
192 int mask = (flag_isoc99 ? 0 : D_C89)
193 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
195 if (!c_dialect_objc ())
198 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
199 for (i = 0; i < N_reswords; i++)
201 /* If a keyword is disabled, do not enter it into the table
202 and so create a canonical spelling that isn't a keyword. */
203 if (reswords[i].disable & mask)
206 id = get_identifier (reswords[i].word);
207 C_RID_CODE (id) = reswords[i].rid;
208 C_IS_RESERVED_WORD (id) = 1;
209 ridpointers [(int) reswords[i].rid] = id;
213 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
214 and the C parser. Unlike the C++ lexer, the parser structure
215 stores the lexer information instead of using a separate structure.
216 Identifiers are separated into ordinary identifiers, type names,
217 keywords and some other Objective-C types of identifiers, and some
218 look-ahead is maintained.
220 ??? It might be a good idea to lex the whole file up front (as for
221 C++). It would then be possible to share more of the C and C++
222 lexer code, if desired. */
224 /* The following local token type is used. */
227 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
229 /* More information about the type of a CPP_NAME token. */
230 typedef enum c_id_kind {
231 /* An ordinary identifier. */
233 /* An identifier declared as a typedef name. */
235 /* An identifier declared as an Objective-C class name. */
237 /* Not an identifier. */
241 /* A single C token after string literal concatenation and conversion
242 of preprocessing tokens to tokens. */
243 typedef struct c_token GTY (())
245 /* The kind of token. */
246 ENUM_BITFIELD (cpp_ttype) type : 8;
247 /* If this token is a CPP_NAME, this value indicates whether also
248 declared as some kind of type. Otherwise, it is C_ID_NONE. */
249 ENUM_BITFIELD (c_id_kind) id_kind : 8;
250 /* If this token is a keyword, this value indicates which keyword.
251 Otherwise, this value is RID_MAX. */
252 ENUM_BITFIELD (rid) keyword : 8;
253 /* If this token is a CPP_PRAGMA, this indicates the pragma that
254 was seen. Otherwise it is PRAGMA_NONE. */
255 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
256 /* True if this token is from a system header. */
257 BOOL_BITFIELD in_system_header : 1;
258 /* The value associated with this token, if any. */
260 /* The location at which this token was found. */
264 /* A parser structure recording information about the state and
265 context of parsing. Includes lexer information with up to two
266 tokens of look-ahead; more are not needed for C. */
267 typedef struct c_parser GTY(())
269 /* The look-ahead tokens. */
271 /* How many look-ahead tokens are available (0, 1 or 2). */
273 /* True if a syntax error is being recovered from; false otherwise.
274 c_parser_error sets this flag. It should clear this flag when
275 enough tokens have been consumed to recover from the error. */
276 BOOL_BITFIELD error : 1;
277 /* True if we're processing a pragma, and shouldn't automatically
278 consume CPP_PRAGMA_EOL. */
279 BOOL_BITFIELD in_pragma : 1;
280 /* Objective-C specific parser/lexer information. */
281 BOOL_BITFIELD objc_pq_context : 1;
282 /* The following flag is needed to contextualize Objective-C lexical
283 analysis. In some cases (e.g., 'int NSObject;'), it is
284 undesirable to bind an identifier to an Objective-C class, even
285 if a class with that name exists. */
286 BOOL_BITFIELD objc_need_raw_identifier : 1;
290 /* The actual parser and external interface. ??? Does this need to be
291 garbage-collected? */
293 static GTY (()) c_parser *the_parser;
296 /* Read in and lex a single token, storing it in *TOKEN. */
299 c_lex_one_token (c_parser *parser, c_token *token)
301 timevar_push (TV_LEX);
303 token->type = c_lex_with_flags (&token->value, &token->location, NULL);
304 token->id_kind = C_ID_NONE;
305 token->keyword = RID_MAX;
306 token->pragma_kind = PRAGMA_NONE;
307 token->in_system_header = in_system_header;
315 bool objc_force_identifier = parser->objc_need_raw_identifier;
316 if (c_dialect_objc ())
317 parser->objc_need_raw_identifier = false;
319 if (C_IS_RESERVED_WORD (token->value))
321 enum rid rid_code = C_RID_CODE (token->value);
323 if (c_dialect_objc ())
325 if (!OBJC_IS_AT_KEYWORD (rid_code)
326 && (!OBJC_IS_PQ_KEYWORD (rid_code)
327 || parser->objc_pq_context))
329 /* Return the canonical spelling for this keyword. */
330 token->value = ridpointers[(int) rid_code];
331 token->type = CPP_KEYWORD;
332 token->keyword = rid_code;
338 /* Return the canonical spelling for this keyword. */
339 token->value = ridpointers[(int) rid_code];
340 token->type = CPP_KEYWORD;
341 token->keyword = rid_code;
346 decl = lookup_name (token->value);
349 if (TREE_CODE (decl) == TYPE_DECL)
351 token->id_kind = C_ID_TYPENAME;
355 else if (c_dialect_objc ())
357 tree objc_interface_decl = objc_is_class_name (token->value);
358 /* Objective-C class names are in the same namespace as
359 variables and typedefs, and hence are shadowed by local
361 if (objc_interface_decl
362 && (global_bindings_p ()
363 || (!objc_force_identifier && !decl)))
365 token->value = objc_interface_decl;
366 token->id_kind = C_ID_CLASSNAME;
370 token->id_kind = C_ID_ID;
374 /* This only happens in Objective-C; it must be a keyword. */
375 token->type = CPP_KEYWORD;
376 token->keyword = C_RID_CODE (token->value);
380 case CPP_CLOSE_PAREN:
382 /* These tokens may affect the interpretation of any identifiers
383 following, if doing Objective-C. */
384 if (c_dialect_objc ())
385 parser->objc_need_raw_identifier = false;
388 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
389 token->pragma_kind = TREE_INT_CST_LOW (token->value);
395 timevar_pop (TV_LEX);
398 /* Return a pointer to the next token from PARSER, reading it in if
401 static inline c_token *
402 c_parser_peek_token (c_parser *parser)
404 if (parser->tokens_avail == 0)
406 c_lex_one_token (parser, &parser->tokens[0]);
407 parser->tokens_avail = 1;
409 return &parser->tokens[0];
412 /* Return true if the next token from PARSER has the indicated
416 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
418 return c_parser_peek_token (parser)->type == type;
421 /* Return true if the next token from PARSER does not have the
425 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
427 return !c_parser_next_token_is (parser, type);
430 /* Return true if the next token from PARSER is the indicated
434 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
438 /* Peek at the next token. */
439 token = c_parser_peek_token (parser);
440 /* Check to see if it is the indicated keyword. */
441 return token->keyword == keyword;
444 /* Return true if TOKEN can start a type name,
447 c_token_starts_typename (c_token *token)
452 switch (token->id_kind)
459 gcc_assert (c_dialect_objc ());
465 switch (token->keyword)
494 if (c_dialect_objc ())
502 /* Return true if the next token from PARSER can start a type name,
505 c_parser_next_token_starts_typename (c_parser *parser)
507 c_token *token = c_parser_peek_token (parser);
508 return c_token_starts_typename (token);
511 /* Return true if TOKEN can start declaration specifiers, false
514 c_token_starts_declspecs (c_token *token)
519 switch (token->id_kind)
526 gcc_assert (c_dialect_objc ());
532 switch (token->keyword)
568 if (c_dialect_objc ())
576 /* Return true if the next token from PARSER can start declaration
577 specifiers, false otherwise. */
579 c_parser_next_token_starts_declspecs (c_parser *parser)
581 c_token *token = c_parser_peek_token (parser);
582 return c_token_starts_declspecs (token);
585 /* Return a pointer to the next-but-one token from PARSER, reading it
586 in if necessary. The next token is already read in. */
589 c_parser_peek_2nd_token (c_parser *parser)
591 if (parser->tokens_avail >= 2)
592 return &parser->tokens[1];
593 gcc_assert (parser->tokens_avail == 1);
594 gcc_assert (parser->tokens[0].type != CPP_EOF);
595 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
596 c_lex_one_token (parser, &parser->tokens[1]);
597 parser->tokens_avail = 2;
598 return &parser->tokens[1];
601 /* Consume the next token from PARSER. */
604 c_parser_consume_token (c_parser *parser)
606 gcc_assert (parser->tokens_avail >= 1);
607 gcc_assert (parser->tokens[0].type != CPP_EOF);
608 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
609 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
610 if (parser->tokens_avail == 2)
611 parser->tokens[0] = parser->tokens[1];
612 parser->tokens_avail--;
615 /* Expect the current token to be a #pragma. Consume it and remember
616 that we've begun parsing a pragma. */
619 c_parser_consume_pragma (c_parser *parser)
621 gcc_assert (!parser->in_pragma);
622 gcc_assert (parser->tokens_avail >= 1);
623 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
624 if (parser->tokens_avail == 2)
625 parser->tokens[0] = parser->tokens[1];
626 parser->tokens_avail--;
627 parser->in_pragma = true;
630 /* Update the globals input_location and in_system_header from
633 c_parser_set_source_position_from_token (c_token *token)
635 if (token->type != CPP_EOF)
637 input_location = token->location;
638 in_system_header = token->in_system_header;
642 /* Issue a diagnostic of the form
643 FILE:LINE: MESSAGE before TOKEN
644 where TOKEN is the next token in the input stream of PARSER.
645 MESSAGE (specified by the caller) is usually of the form "expected
648 Do not issue a diagnostic if still recovering from an error.
650 ??? This is taken from the C++ parser, but building up messages in
651 this way is not i18n-friendly and some other approach should be
655 c_parser_error (c_parser *parser, const char *gmsgid)
657 c_token *token = c_parser_peek_token (parser);
660 parser->error = true;
663 /* This diagnostic makes more sense if it is tagged to the line of
664 the token we just peeked at. */
665 c_parser_set_source_position_from_token (token);
666 c_parse_error (gmsgid,
667 /* Because c_parse_error does not understand
668 CPP_KEYWORD, keywords are treated like
670 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
674 /* If the next token is of the indicated TYPE, consume it. Otherwise,
675 issue the error MSGID. If MSGID is NULL then a message has already
676 been produced and no message will be produced this time. Returns
677 true if found, false otherwise. */
680 c_parser_require (c_parser *parser,
684 if (c_parser_next_token_is (parser, type))
686 c_parser_consume_token (parser);
691 c_parser_error (parser, msgid);
696 /* If the next token is the indicated keyword, consume it. Otherwise,
697 issue the error MSGID. Returns true if found, false otherwise. */
700 c_parser_require_keyword (c_parser *parser,
704 if (c_parser_next_token_is_keyword (parser, keyword))
706 c_parser_consume_token (parser);
711 c_parser_error (parser, msgid);
716 /* Like c_parser_require, except that tokens will be skipped until the
717 desired token is found. An error message is still produced if the
718 next token is not as expected. If MSGID is NULL then a message has
719 already been produced and no message will be produced this
723 c_parser_skip_until_found (c_parser *parser,
727 unsigned nesting_depth = 0;
729 if (c_parser_require (parser, type, msgid))
732 /* Skip tokens until the desired token is found. */
735 /* Peek at the next token. */
736 c_token *token = c_parser_peek_token (parser);
737 /* If we've reached the token we want, consume it and stop. */
738 if (token->type == type && !nesting_depth)
740 c_parser_consume_token (parser);
744 /* If we've run out of tokens, stop. */
745 if (token->type == CPP_EOF)
747 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
749 if (token->type == CPP_OPEN_BRACE
750 || token->type == CPP_OPEN_PAREN
751 || token->type == CPP_OPEN_SQUARE)
753 else if (token->type == CPP_CLOSE_BRACE
754 || token->type == CPP_CLOSE_PAREN
755 || token->type == CPP_CLOSE_SQUARE)
757 if (nesting_depth-- == 0)
760 /* Consume this token. */
761 c_parser_consume_token (parser);
763 parser->error = false;
766 /* Skip tokens until the end of a parameter is found, but do not
767 consume the comma, semicolon or closing delimiter. */
770 c_parser_skip_to_end_of_parameter (c_parser *parser)
772 unsigned nesting_depth = 0;
776 c_token *token = c_parser_peek_token (parser);
777 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
780 /* If we've run out of tokens, stop. */
781 if (token->type == CPP_EOF)
783 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
785 if (token->type == CPP_OPEN_BRACE
786 || token->type == CPP_OPEN_PAREN
787 || token->type == CPP_OPEN_SQUARE)
789 else if (token->type == CPP_CLOSE_BRACE
790 || token->type == CPP_CLOSE_PAREN
791 || token->type == CPP_CLOSE_SQUARE)
793 if (nesting_depth-- == 0)
796 /* Consume this token. */
797 c_parser_consume_token (parser);
799 parser->error = false;
802 /* Expect to be at the end of the pragma directive and consume an
803 end of line marker. */
806 c_parser_skip_to_pragma_eol (c_parser *parser)
808 gcc_assert (parser->in_pragma);
809 parser->in_pragma = false;
811 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
814 c_token *token = c_parser_peek_token (parser);
815 if (token->type == CPP_EOF)
817 if (token->type == CPP_PRAGMA_EOL)
819 c_parser_consume_token (parser);
822 c_parser_consume_token (parser);
825 parser->error = false;
828 /* Skip tokens until we have consumed an entire block, or until we
829 have consumed a non-nested ';'. */
832 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
834 unsigned nesting_depth = 0;
835 bool save_error = parser->error;
841 /* Peek at the next token. */
842 token = c_parser_peek_token (parser);
850 if (parser->in_pragma)
855 /* If the next token is a ';', we have reached the
856 end of the statement. */
859 /* Consume the ';'. */
860 c_parser_consume_token (parser);
865 case CPP_CLOSE_BRACE:
866 /* If the next token is a non-nested '}', then we have
867 reached the end of the current block. */
868 if (nesting_depth == 0 || --nesting_depth == 0)
870 c_parser_consume_token (parser);
876 /* If it the next token is a '{', then we are entering a new
877 block. Consume the entire block. */
882 /* If we see a pragma, consume the whole thing at once. We
883 have some safeguards against consuming pragmas willy-nilly.
884 Normally, we'd expect to be here with parser->error set,
885 which disables these safeguards. But it's possible to get
886 here for secondary error recovery, after parser->error has
888 c_parser_consume_pragma (parser);
889 c_parser_skip_to_pragma_eol (parser);
890 parser->error = save_error;
897 c_parser_consume_token (parser);
901 parser->error = false;
904 /* Save the warning flags which are controlled by __extension__. */
907 disable_extension_diagnostics (void)
910 | (warn_pointer_arith << 1)
911 | (warn_traditional << 2)
914 warn_pointer_arith = 0;
915 warn_traditional = 0;
920 /* Restore the warning flags which are controlled by __extension__.
921 FLAGS is the return value from disable_extension_diagnostics. */
924 restore_extension_diagnostics (int flags)
926 pedantic = flags & 1;
927 warn_pointer_arith = (flags >> 1) & 1;
928 warn_traditional = (flags >> 2) & 1;
929 flag_iso = (flags >> 3) & 1;
932 /* Possibly kinds of declarator to parse. */
933 typedef enum c_dtr_syn {
934 /* A normal declarator with an identifier. */
936 /* An abstract declarator (maybe empty). */
938 /* A parameter declarator: may be either, but after a type name does
939 not redeclare a typedef name as an identifier if it can
940 alternatively be interpreted as a typedef name; see DR#009,
941 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
942 following DR#249. For example, given a typedef T, "int T" and
943 "int *T" are valid parameter declarations redeclaring T, while
944 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
945 abstract declarators rather than involving redundant parentheses;
946 the same applies with attributes inside the parentheses before
951 static void c_parser_external_declaration (c_parser *);
952 static void c_parser_asm_definition (c_parser *);
953 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
954 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
956 static struct c_typespec c_parser_enum_specifier (c_parser *);
957 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
958 static tree c_parser_struct_declaration (c_parser *);
959 static struct c_typespec c_parser_typeof_specifier (c_parser *);
960 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
962 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
964 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
966 struct c_declarator *);
967 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
968 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
969 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
970 static tree c_parser_simple_asm_expr (c_parser *);
971 static tree c_parser_attributes (c_parser *);
972 static struct c_type_name *c_parser_type_name (c_parser *);
973 static struct c_expr c_parser_initializer (c_parser *);
974 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
975 static void c_parser_initelt (c_parser *);
976 static void c_parser_initval (c_parser *, struct c_expr *);
977 static tree c_parser_compound_statement (c_parser *);
978 static void c_parser_compound_statement_nostart (c_parser *);
979 static void c_parser_label (c_parser *);
980 static void c_parser_statement (c_parser *);
981 static void c_parser_statement_after_labels (c_parser *);
982 static void c_parser_if_statement (c_parser *);
983 static void c_parser_switch_statement (c_parser *);
984 static void c_parser_while_statement (c_parser *);
985 static void c_parser_do_statement (c_parser *);
986 static void c_parser_for_statement (c_parser *);
987 static tree c_parser_asm_statement (c_parser *);
988 static tree c_parser_asm_operands (c_parser *, bool);
989 static tree c_parser_asm_clobbers (c_parser *);
990 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
991 static struct c_expr c_parser_conditional_expression (c_parser *,
993 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
994 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
995 static struct c_expr c_parser_unary_expression (c_parser *);
996 static struct c_expr c_parser_sizeof_expression (c_parser *);
997 static struct c_expr c_parser_alignof_expression (c_parser *);
998 static struct c_expr c_parser_postfix_expression (c_parser *);
999 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1000 struct c_type_name *);
1001 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1003 static struct c_expr c_parser_expression (c_parser *);
1004 static struct c_expr c_parser_expression_conv (c_parser *);
1005 static tree c_parser_expr_list (c_parser *, bool);
1006 static void c_parser_omp_construct (c_parser *);
1007 static void c_parser_omp_threadprivate (c_parser *);
1008 static void c_parser_omp_barrier (c_parser *);
1009 static void c_parser_omp_flush (c_parser *);
1011 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1012 static bool c_parser_pragma (c_parser *, enum pragma_context);
1014 /* These Objective-C parser functions are only ever called when
1015 compiling Objective-C. */
1016 static void c_parser_objc_class_definition (c_parser *);
1017 static void c_parser_objc_class_instance_variables (c_parser *);
1018 static void c_parser_objc_class_declaration (c_parser *);
1019 static void c_parser_objc_alias_declaration (c_parser *);
1020 static void c_parser_objc_protocol_definition (c_parser *);
1021 static enum tree_code c_parser_objc_method_type (c_parser *);
1022 static void c_parser_objc_method_definition (c_parser *);
1023 static void c_parser_objc_methodprotolist (c_parser *);
1024 static void c_parser_objc_methodproto (c_parser *);
1025 static tree c_parser_objc_method_decl (c_parser *);
1026 static tree c_parser_objc_type_name (c_parser *);
1027 static tree c_parser_objc_protocol_refs (c_parser *);
1028 static void c_parser_objc_try_catch_statement (c_parser *);
1029 static void c_parser_objc_synchronized_statement (c_parser *);
1030 static tree c_parser_objc_selector (c_parser *);
1031 static tree c_parser_objc_selector_arg (c_parser *);
1032 static tree c_parser_objc_receiver (c_parser *);
1033 static tree c_parser_objc_message_args (c_parser *);
1034 static tree c_parser_objc_keywordexpr (c_parser *);
1036 /* Parse a translation unit (C90 6.7, C99 6.9).
1039 external-declarations
1041 external-declarations:
1042 external-declaration
1043 external-declarations external-declaration
1052 c_parser_translation_unit (c_parser *parser)
1054 if (c_parser_next_token_is (parser, CPP_EOF))
1057 pedwarn ("ISO C forbids an empty source file");
1061 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1065 c_parser_external_declaration (parser);
1066 obstack_free (&parser_obstack, obstack_position);
1068 while (c_parser_next_token_is_not (parser, CPP_EOF));
1072 /* Parse an external declaration (C90 6.7, C99 6.9).
1074 external-declaration:
1080 external-declaration:
1083 __extension__ external-declaration
1087 external-declaration:
1088 objc-class-definition
1089 objc-class-declaration
1090 objc-alias-declaration
1091 objc-protocol-definition
1092 objc-method-definition
1097 c_parser_external_declaration (c_parser *parser)
1100 switch (c_parser_peek_token (parser)->type)
1103 switch (c_parser_peek_token (parser)->keyword)
1106 ext = disable_extension_diagnostics ();
1107 c_parser_consume_token (parser);
1108 c_parser_external_declaration (parser);
1109 restore_extension_diagnostics (ext);
1112 c_parser_asm_definition (parser);
1114 case RID_AT_INTERFACE:
1115 case RID_AT_IMPLEMENTATION:
1116 gcc_assert (c_dialect_objc ());
1117 c_parser_objc_class_definition (parser);
1120 gcc_assert (c_dialect_objc ());
1121 c_parser_objc_class_declaration (parser);
1124 gcc_assert (c_dialect_objc ());
1125 c_parser_objc_alias_declaration (parser);
1127 case RID_AT_PROTOCOL:
1128 gcc_assert (c_dialect_objc ());
1129 c_parser_objc_protocol_definition (parser);
1132 gcc_assert (c_dialect_objc ());
1133 c_parser_consume_token (parser);
1134 objc_finish_implementation ();
1142 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1143 c_parser_consume_token (parser);
1146 c_parser_pragma (parser, pragma_external);
1150 if (c_dialect_objc ())
1152 c_parser_objc_method_definition (parser);
1155 /* Else fall through, and yield a syntax error trying to parse
1156 as a declaration or function definition. */
1159 /* A declaration or a function definition. We can only tell
1160 which after parsing the declaration specifiers, if any, and
1161 the first declarator. */
1162 c_parser_declaration_or_fndef (parser, true, true, false, true);
1168 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1169 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1170 accepted; otherwise (old-style parameter declarations) only other
1171 declarations are accepted. If NESTED is true, we are inside a
1172 function or parsing old-style parameter declarations; any functions
1173 encountered are nested functions and declaration specifiers are
1174 required; otherwise we are at top level and functions are normal
1175 functions and declaration specifiers may be optional. If EMPTY_OK
1176 is true, empty declarations are OK (subject to all other
1177 constraints); otherwise (old-style parameter declarations) they are
1178 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1179 may start with attributes; otherwise they may not.
1182 declaration-specifiers init-declarator-list[opt] ;
1184 function-definition:
1185 declaration-specifiers[opt] declarator declaration-list[opt]
1190 declaration-list declaration
1192 init-declarator-list:
1194 init-declarator-list , init-declarator
1197 declarator simple-asm-expr[opt] attributes[opt]
1198 declarator simple-asm-expr[opt] attributes[opt] = initializer
1202 nested-function-definition:
1203 declaration-specifiers declarator declaration-list[opt]
1206 The simple-asm-expr and attributes are GNU extensions.
1208 This function does not handle __extension__; that is handled in its
1209 callers. ??? Following the old parser, __extension__ may start
1210 external declarations, declarations in functions and declarations
1211 at the start of "for" loops, but not old-style parameter
1214 C99 requires declaration specifiers in a function definition; the
1215 absence is diagnosed through the diagnosis of implicit int. In GNU
1216 C we also allow but diagnose declarations without declaration
1217 specifiers, but only at top level (elsewhere they conflict with
1223 threadprivate-directive */
1226 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1227 bool nested, bool start_attr_ok)
1229 struct c_declspecs *specs;
1231 tree all_prefix_attrs;
1232 bool diagnosed_no_specs = false;
1234 specs = build_null_declspecs ();
1235 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1238 c_parser_skip_to_end_of_block_or_statement (parser);
1241 if (nested && !specs->declspecs_seen_p)
1243 c_parser_error (parser, "expected declaration specifiers");
1244 c_parser_skip_to_end_of_block_or_statement (parser);
1247 finish_declspecs (specs);
1248 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1254 shadow_tag_warned (specs, 1);
1255 pedwarn ("empty declaration");
1257 c_parser_consume_token (parser);
1260 pending_xref_error ();
1261 prefix_attrs = specs->attrs;
1262 all_prefix_attrs = prefix_attrs;
1263 specs->attrs = NULL_TREE;
1266 struct c_declarator *declarator;
1269 /* Declaring either one or more declarators (in which case we
1270 should diagnose if there were no declaration specifiers) or a
1271 function definition (in which case the diagnostic for
1272 implicit int suffices). */
1273 declarator = c_parser_declarator (parser, specs->type_seen_p,
1274 C_DTR_NORMAL, &dummy);
1275 if (declarator == NULL)
1277 c_parser_skip_to_end_of_block_or_statement (parser);
1280 if (c_parser_next_token_is (parser, CPP_EQ)
1281 || c_parser_next_token_is (parser, CPP_COMMA)
1282 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1283 || c_parser_next_token_is_keyword (parser, RID_ASM)
1284 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1286 tree asm_name = NULL_TREE;
1287 tree postfix_attrs = NULL_TREE;
1288 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1290 diagnosed_no_specs = true;
1291 pedwarn ("data definition has no type or storage class");
1293 /* Having seen a data definition, there cannot now be a
1294 function definition. */
1296 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1297 asm_name = c_parser_simple_asm_expr (parser);
1298 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1299 postfix_attrs = c_parser_attributes (parser);
1300 if (c_parser_next_token_is (parser, CPP_EQ))
1304 c_parser_consume_token (parser);
1305 /* The declaration of the variable is in effect while
1306 its initializer is parsed. */
1307 d = start_decl (declarator, specs, true,
1308 chainon (postfix_attrs, all_prefix_attrs));
1310 d = error_mark_node;
1311 start_init (d, asm_name, global_bindings_p ());
1312 init = c_parser_initializer (parser);
1314 if (d != error_mark_node)
1316 maybe_warn_string_init (TREE_TYPE (d), init);
1317 finish_decl (d, init.value, asm_name);
1322 tree d = start_decl (declarator, specs, false,
1323 chainon (postfix_attrs,
1326 finish_decl (d, NULL_TREE, asm_name);
1328 if (c_parser_next_token_is (parser, CPP_COMMA))
1330 c_parser_consume_token (parser);
1331 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1332 all_prefix_attrs = chainon (c_parser_attributes (parser),
1335 all_prefix_attrs = prefix_attrs;
1338 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1340 c_parser_consume_token (parser);
1345 c_parser_error (parser, "expected %<,%> or %<;%>");
1346 c_parser_skip_to_end_of_block_or_statement (parser);
1352 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1353 "%<asm%> or %<__attribute__%>");
1354 c_parser_skip_to_end_of_block_or_statement (parser);
1357 /* Function definition (nested or otherwise). */
1361 pedwarn ("ISO C forbids nested functions");
1362 push_function_context ();
1364 if (!start_function (specs, declarator, all_prefix_attrs))
1366 /* This can appear in many cases looking nothing like a
1367 function definition, so we don't give a more specific
1368 error suggesting there was one. */
1369 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1370 "or %<__attribute__%>");
1372 pop_function_context ();
1375 /* Parse old-style parameter declarations. ??? Attributes are
1376 not allowed to start declaration specifiers here because of a
1377 syntax conflict between a function declaration with attribute
1378 suffix and a function definition with an attribute prefix on
1379 first old-style parameter declaration. Following the old
1380 parser, they are not accepted on subsequent old-style
1381 parameter declarations either. However, there is no
1382 ambiguity after the first declaration, nor indeed on the
1383 first as long as we don't allow postfix attributes after a
1384 declarator with a nonempty identifier list in a definition;
1385 and postfix attributes have never been accepted here in
1386 function definitions either. */
1387 while (c_parser_next_token_is_not (parser, CPP_EOF)
1388 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1389 c_parser_declaration_or_fndef (parser, false, false, true, false);
1390 DECL_SOURCE_LOCATION (current_function_decl)
1391 = c_parser_peek_token (parser)->location;
1392 store_parm_decls ();
1393 fnbody = c_parser_compound_statement (parser);
1396 tree decl = current_function_decl;
1399 pop_function_context ();
1400 add_stmt (build_stmt (DECL_EXPR, decl));
1411 /* Parse an asm-definition (asm() outside a function body). This is a
1419 c_parser_asm_definition (c_parser *parser)
1421 tree asm_str = c_parser_simple_asm_expr (parser);
1423 cgraph_add_asm_node (asm_str);
1424 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1427 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1428 6.7), adding them to SPECS (which may already include some).
1429 Storage class specifiers are accepted iff SCSPEC_OK; type
1430 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1431 the start iff START_ATTR_OK.
1433 declaration-specifiers:
1434 storage-class-specifier declaration-specifiers[opt]
1435 type-specifier declaration-specifiers[opt]
1436 type-qualifier declaration-specifiers[opt]
1437 function-specifier declaration-specifiers[opt]
1439 Function specifiers (inline) are from C99, and are currently
1440 handled as storage class specifiers, as is __thread.
1442 C90 6.5.1, C99 6.7.1:
1443 storage-class-specifier:
1454 C90 6.5.2, C99 6.7.2:
1467 [_Imaginary removed in C99 TC2]
1468 struct-or-union-specifier
1472 (_Bool and _Complex are new in C99.)
1474 C90 6.5.3, C99 6.7.3:
1481 (restrict is new in C99.)
1485 declaration-specifiers:
1486 attributes declaration-specifiers[opt]
1488 storage-class-specifier:
1500 class-name objc-protocol-refs[opt]
1501 typedef-name objc-protocol-refs
1506 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1507 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1509 bool attrs_ok = start_attr_ok;
1510 bool seen_type = specs->type_seen_p;
1511 while (c_parser_next_token_is (parser, CPP_NAME)
1512 || c_parser_next_token_is (parser, CPP_KEYWORD)
1513 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1515 struct c_typespec t;
1517 if (c_parser_next_token_is (parser, CPP_NAME))
1519 tree value = c_parser_peek_token (parser)->value;
1520 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1521 /* This finishes the specifiers unless a type name is OK, it
1522 is declared as a type name and a type name hasn't yet
1524 if (!typespec_ok || seen_type
1525 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1527 c_parser_consume_token (parser);
1530 if (kind == C_ID_TYPENAME
1531 && (!c_dialect_objc ()
1532 || c_parser_next_token_is_not (parser, CPP_LESS)))
1534 t.kind = ctsk_typedef;
1535 /* For a typedef name, record the meaning, not the name.
1536 In case of 'foo foo, bar;'. */
1537 t.spec = lookup_name (value);
1541 tree proto = NULL_TREE;
1542 gcc_assert (c_dialect_objc ());
1544 if (c_parser_next_token_is (parser, CPP_LESS))
1545 proto = c_parser_objc_protocol_refs (parser);
1546 t.spec = objc_get_protocol_qualified_type (value, proto);
1548 declspecs_add_type (specs, t);
1551 if (c_parser_next_token_is (parser, CPP_LESS))
1553 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1554 nisse@lysator.liu.se. */
1556 gcc_assert (c_dialect_objc ());
1557 if (!typespec_ok || seen_type)
1559 proto = c_parser_objc_protocol_refs (parser);
1561 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1562 declspecs_add_type (specs, t);
1565 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1566 switch (c_parser_peek_token (parser)->keyword)
1578 /* TODO: Distinguish between function specifiers (inline)
1579 and storage class specifiers, either here or in
1580 declspecs_add_scspec. */
1581 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1582 c_parser_consume_token (parser);
1602 if (c_dialect_objc ())
1603 parser->objc_need_raw_identifier = true;
1604 t.kind = ctsk_resword;
1605 t.spec = c_parser_peek_token (parser)->value;
1606 declspecs_add_type (specs, t);
1607 c_parser_consume_token (parser);
1614 t = c_parser_enum_specifier (parser);
1615 declspecs_add_type (specs, t);
1623 t = c_parser_struct_or_union_specifier (parser);
1624 declspecs_add_type (specs, t);
1627 /* ??? The old parser rejected typeof after other type
1628 specifiers, but is a syntax error the best way of
1630 if (!typespec_ok || seen_type)
1634 t = c_parser_typeof_specifier (parser);
1635 declspecs_add_type (specs, t);
1641 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1642 c_parser_consume_token (parser);
1647 attrs = c_parser_attributes (parser);
1648 declspecs_add_attrs (specs, attrs);
1657 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1660 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1661 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1662 enum attributes[opt] identifier
1664 The form with trailing comma is new in C99. The forms with
1665 attributes are GNU extensions. In GNU C, we accept any expression
1666 without commas in the syntax (assignment expressions, not just
1667 conditional expressions); assignment expressions will be diagnosed
1672 enumerator-list , enumerator
1675 enumeration-constant
1676 enumeration-constant = constant-expression
1679 static struct c_typespec
1680 c_parser_enum_specifier (c_parser *parser)
1682 struct c_typespec ret;
1684 tree ident = NULL_TREE;
1685 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1686 c_parser_consume_token (parser);
1687 attrs = c_parser_attributes (parser);
1688 if (c_parser_next_token_is (parser, CPP_NAME))
1690 ident = c_parser_peek_token (parser)->value;
1691 c_parser_consume_token (parser);
1693 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1695 /* Parse an enum definition. */
1696 struct c_enum_contents the_enum;
1697 tree type = start_enum (&the_enum, ident);
1699 /* We chain the enumerators in reverse order, then put them in
1700 forward order at the end. */
1701 tree values = NULL_TREE;
1702 c_parser_consume_token (parser);
1709 if (c_parser_next_token_is_not (parser, CPP_NAME))
1711 c_parser_error (parser, "expected identifier");
1712 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1713 values = error_mark_node;
1716 enum_id = c_parser_peek_token (parser)->value;
1717 c_parser_consume_token (parser);
1718 if (c_parser_next_token_is (parser, CPP_EQ))
1720 c_parser_consume_token (parser);
1721 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1724 enum_value = NULL_TREE;
1725 enum_decl = build_enumerator (&the_enum, enum_id, enum_value);
1726 TREE_CHAIN (enum_decl) = values;
1729 if (c_parser_next_token_is (parser, CPP_COMMA))
1732 c_parser_consume_token (parser);
1734 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1736 if (seen_comma && pedantic && !flag_isoc99)
1737 pedwarn ("comma at end of enumerator list");
1738 c_parser_consume_token (parser);
1743 c_parser_error (parser, "expected %<,%> or %<}%>");
1744 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1745 values = error_mark_node;
1749 postfix_attrs = c_parser_attributes (parser);
1750 ret.spec = finish_enum (type, nreverse (values),
1751 chainon (attrs, postfix_attrs));
1752 ret.kind = ctsk_tagdef;
1757 c_parser_error (parser, "expected %<{%>");
1758 ret.spec = error_mark_node;
1759 ret.kind = ctsk_tagref;
1762 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1763 /* In ISO C, enumerated types can be referred to only if already
1765 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1766 pedwarn ("ISO C forbids forward references to %<enum%> types");
1770 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1772 struct-or-union-specifier:
1773 struct-or-union attributes[opt] identifier[opt]
1774 { struct-contents } attributes[opt]
1775 struct-or-union attributes[opt] identifier
1778 struct-declaration-list
1780 struct-declaration-list:
1781 struct-declaration ;
1782 struct-declaration-list struct-declaration ;
1789 struct-declaration-list struct-declaration
1791 struct-declaration-list:
1792 struct-declaration-list ;
1795 (Note that in the syntax here, unlike that in ISO C, the semicolons
1796 are included here rather than in struct-declaration, in order to
1797 describe the syntax with extra semicolons and missing semicolon at
1802 struct-declaration-list:
1803 @defs ( class-name )
1805 (Note this does not include a trailing semicolon, but can be
1806 followed by further declarations, and gets a pedwarn-if-pedantic
1807 when followed by a semicolon.) */
1809 static struct c_typespec
1810 c_parser_struct_or_union_specifier (c_parser *parser)
1812 struct c_typespec ret;
1814 tree ident = NULL_TREE;
1815 enum tree_code code;
1816 switch (c_parser_peek_token (parser)->keyword)
1827 c_parser_consume_token (parser);
1828 attrs = c_parser_attributes (parser);
1829 if (c_parser_next_token_is (parser, CPP_NAME))
1831 ident = c_parser_peek_token (parser)->value;
1832 c_parser_consume_token (parser);
1834 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1836 /* Parse a struct or union definition. Start the scope of the
1837 tag before parsing components. */
1838 tree type = start_struct (code, ident);
1840 /* We chain the components in reverse order, then put them in
1841 forward order at the end. Each struct-declaration may
1842 declare multiple components (comma-separated), so we must use
1843 chainon to join them, although when parsing each
1844 struct-declaration we can use TREE_CHAIN directly.
1846 The theory behind all this is that there will be more
1847 semicolon separated fields than comma separated fields, and
1848 so we'll be minimizing the number of node traversals required
1850 tree contents = NULL_TREE;
1851 c_parser_consume_token (parser);
1852 /* Handle the Objective-C @defs construct,
1853 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1854 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1857 gcc_assert (c_dialect_objc ());
1858 c_parser_consume_token (parser);
1859 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1861 if (c_parser_next_token_is (parser, CPP_NAME)
1862 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1864 name = c_parser_peek_token (parser)->value;
1865 c_parser_consume_token (parser);
1869 c_parser_error (parser, "expected class name");
1870 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1873 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1875 contents = nreverse (objc_get_class_ivars (name));
1878 /* Parse the struct-declarations and semicolons. Problems with
1879 semicolons are diagnosed here; empty structures are diagnosed
1884 /* Parse any stray semicolon. */
1885 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1888 pedwarn ("extra semicolon in struct or union specified");
1889 c_parser_consume_token (parser);
1892 /* Stop if at the end of the struct or union contents. */
1893 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1895 c_parser_consume_token (parser);
1898 /* Accept #pragmas at struct scope. */
1899 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1901 c_parser_pragma (parser, pragma_external);
1904 /* Parse some comma-separated declarations, but not the
1905 trailing semicolon if any. */
1906 decls = c_parser_struct_declaration (parser);
1907 contents = chainon (decls, contents);
1908 /* If no semicolon follows, either we have a parse error or
1909 are at the end of the struct or union and should
1911 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1912 c_parser_consume_token (parser);
1915 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1916 pedwarn ("no semicolon at end of struct or union");
1919 c_parser_error (parser, "expected %<;%>");
1920 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1925 postfix_attrs = c_parser_attributes (parser);
1926 ret.spec = finish_struct (type, nreverse (contents),
1927 chainon (attrs, postfix_attrs));
1928 ret.kind = ctsk_tagdef;
1933 c_parser_error (parser, "expected %<{%>");
1934 ret.spec = error_mark_node;
1935 ret.kind = ctsk_tagref;
1938 ret = parser_xref_tag (code, ident);
1942 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1943 the trailing semicolon.
1946 specifier-qualifier-list struct-declarator-list
1948 specifier-qualifier-list:
1949 type-specifier specifier-qualifier-list[opt]
1950 type-qualifier specifier-qualifier-list[opt]
1951 attributes specifier-qualifier-list[opt]
1953 struct-declarator-list:
1955 struct-declarator-list , attributes[opt] struct-declarator
1958 declarator attributes[opt]
1959 declarator[opt] : constant-expression attributes[opt]
1964 __extension__ struct-declaration
1965 specifier-qualifier-list
1967 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1968 of attributes where shown is a GNU extension. In GNU C, we accept
1969 any expression without commas in the syntax (assignment
1970 expressions, not just conditional expressions); assignment
1971 expressions will be diagnosed as non-constant. */
1974 c_parser_struct_declaration (c_parser *parser)
1976 struct c_declspecs *specs;
1978 tree all_prefix_attrs;
1980 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1984 ext = disable_extension_diagnostics ();
1985 c_parser_consume_token (parser);
1986 decl = c_parser_struct_declaration (parser);
1987 restore_extension_diagnostics (ext);
1990 specs = build_null_declspecs ();
1991 c_parser_declspecs (parser, specs, false, true, true);
1994 if (!specs->declspecs_seen_p)
1996 c_parser_error (parser, "expected specifier-qualifier-list");
1999 finish_declspecs (specs);
2000 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2003 if (!specs->type_seen_p)
2006 pedwarn ("ISO C forbids member declarations with no members");
2007 shadow_tag_warned (specs, pedantic);
2012 /* Support for unnamed structs or unions as members of
2013 structs or unions (which is [a] useful and [b] supports
2015 ret = grokfield (build_id_declarator (NULL_TREE), specs, NULL_TREE);
2019 pending_xref_error ();
2020 prefix_attrs = specs->attrs;
2021 all_prefix_attrs = prefix_attrs;
2022 specs->attrs = NULL_TREE;
2026 /* Declaring one or more declarators or un-named bit-fields. */
2027 struct c_declarator *declarator;
2029 if (c_parser_next_token_is (parser, CPP_COLON))
2030 declarator = build_id_declarator (NULL_TREE);
2032 declarator = c_parser_declarator (parser, specs->type_seen_p,
2033 C_DTR_NORMAL, &dummy);
2034 if (declarator == NULL)
2036 c_parser_skip_to_end_of_block_or_statement (parser);
2039 if (c_parser_next_token_is (parser, CPP_COLON)
2040 || c_parser_next_token_is (parser, CPP_COMMA)
2041 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2042 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2043 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2045 tree postfix_attrs = NULL_TREE;
2046 tree width = NULL_TREE;
2048 if (c_parser_next_token_is (parser, CPP_COLON))
2050 c_parser_consume_token (parser);
2051 width = c_parser_expr_no_commas (parser, NULL).value;
2053 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2054 postfix_attrs = c_parser_attributes (parser);
2055 d = grokfield (declarator, specs, width);
2056 decl_attributes (&d, chainon (postfix_attrs,
2057 all_prefix_attrs), 0);
2058 TREE_CHAIN (d) = decls;
2060 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2061 all_prefix_attrs = chainon (c_parser_attributes (parser),
2064 all_prefix_attrs = prefix_attrs;
2065 if (c_parser_next_token_is (parser, CPP_COMMA))
2066 c_parser_consume_token (parser);
2067 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2068 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2070 /* Semicolon consumed in caller. */
2075 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2081 c_parser_error (parser,
2082 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2083 "%<__attribute__%>");
2090 /* Parse a typeof specifier (a GNU extension).
2093 typeof ( expression )
2094 typeof ( type-name )
2097 static struct c_typespec
2098 c_parser_typeof_specifier (c_parser *parser)
2100 struct c_typespec ret;
2101 ret.kind = ctsk_typeof;
2102 ret.spec = error_mark_node;
2103 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2104 c_parser_consume_token (parser);
2107 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2113 if (c_parser_next_token_starts_typename (parser))
2115 struct c_type_name *type = c_parser_type_name (parser);
2120 ret.spec = groktypename (type);
2121 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2127 struct c_expr expr = c_parser_expression (parser);
2130 if (TREE_CODE (expr.value) == COMPONENT_REF
2131 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2132 error ("%<typeof%> applied to a bit-field");
2133 ret.spec = TREE_TYPE (expr.value);
2134 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2135 /* This should be returned with the type so that when the type
2136 is evaluated, this can be evaluated. For now, we avoid
2137 evaluation when the context might. */
2138 if (!skip_evaluation && was_vm)
2140 tree e = expr.value;
2142 /* If the expression is not of a type to which we cannot assign a line
2143 number, wrap the thing in a no-op NOP_EXPR. */
2144 if (DECL_P (e) || CONSTANT_CLASS_P (e))
2145 e = build1 (NOP_EXPR, void_type_node, e);
2147 if (CAN_HAVE_LOCATION_P (e))
2148 SET_EXPR_LOCATION (e, input_location);
2152 pop_maybe_used (was_vm);
2154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2158 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2159 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2160 be redeclared; otherwise it may not. KIND indicates which kind of
2161 declarator is wanted. Returns a valid declarator except in the
2162 case of a syntax error in which case NULL is returned. *SEEN_ID is
2163 set to true if an identifier being declared is seen; this is used
2164 to diagnose bad forms of abstract array declarators and to
2165 determine whether an identifier list is syntactically permitted.
2168 pointer[opt] direct-declarator
2172 ( attributes[opt] declarator )
2173 direct-declarator array-declarator
2174 direct-declarator ( parameter-type-list )
2175 direct-declarator ( identifier-list[opt] )
2178 * type-qualifier-list[opt]
2179 * type-qualifier-list[opt] pointer
2181 type-qualifier-list:
2184 type-qualifier-list type-qualifier
2185 type-qualifier-list attributes
2187 parameter-type-list:
2189 parameter-list , ...
2192 parameter-declaration
2193 parameter-list , parameter-declaration
2195 parameter-declaration:
2196 declaration-specifiers declarator attributes[opt]
2197 declaration-specifiers abstract-declarator[opt] attributes[opt]
2201 identifier-list , identifier
2203 abstract-declarator:
2205 pointer[opt] direct-abstract-declarator
2207 direct-abstract-declarator:
2208 ( attributes[opt] abstract-declarator )
2209 direct-abstract-declarator[opt] array-declarator
2210 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2215 direct-declarator ( parameter-forward-declarations
2216 parameter-type-list[opt] )
2218 direct-abstract-declarator:
2219 direct-abstract-declarator[opt] ( parameter-forward-declarations
2220 parameter-type-list[opt] )
2222 parameter-forward-declarations:
2224 parameter-forward-declarations parameter-list ;
2226 The uses of attributes shown above are GNU extensions.
2228 Some forms of array declarator are not included in C99 in the
2229 syntax for abstract declarators; these are disallowed elsewhere.
2230 This may be a defect (DR#289).
2232 This function also accepts an omitted abstract declarator as being
2233 an abstract declarator, although not part of the formal syntax. */
2235 static struct c_declarator *
2236 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2239 /* Parse any initial pointer part. */
2240 if (c_parser_next_token_is (parser, CPP_MULT))
2242 struct c_declspecs *quals_attrs = build_null_declspecs ();
2243 struct c_declarator *inner;
2244 c_parser_consume_token (parser);
2245 c_parser_declspecs (parser, quals_attrs, false, false, true);
2246 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2250 return make_pointer_declarator (quals_attrs, inner);
2252 /* Now we have a direct declarator, direct abstract declarator or
2253 nothing (which counts as a direct abstract declarator here). */
2254 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2257 /* Parse a direct declarator or direct abstract declarator; arguments
2258 as c_parser_declarator. */
2260 static struct c_declarator *
2261 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2264 /* The direct declarator must start with an identifier (possibly
2265 omitted) or a parenthesized declarator (possibly abstract). In
2266 an ordinary declarator, initial parentheses must start a
2267 parenthesized declarator. In an abstract declarator or parameter
2268 declarator, they could start a parenthesized declarator or a
2269 parameter list. To tell which, the open parenthesis and any
2270 following attributes must be read. If a declaration specifier
2271 follows, then it is a parameter list; if the specifier is a
2272 typedef name, there might be an ambiguity about redeclaring it,
2273 which is resolved in the direction of treating it as a typedef
2274 name. If a close parenthesis follows, it is also an empty
2275 parameter list, as the syntax does not permit empty abstract
2276 declarators. Otherwise, it is a parenthesized declarator (in
2277 which case the analysis may be repeated inside it, recursively).
2279 ??? There is an ambiguity in a parameter declaration "int
2280 (__attribute__((foo)) x)", where x is not a typedef name: it
2281 could be an abstract declarator for a function, or declare x with
2282 parentheses. The proper resolution of this ambiguity needs
2283 documenting. At present we follow an accident of the old
2284 parser's implementation, whereby the first parameter must have
2285 some declaration specifiers other than just attributes. Thus as
2286 a parameter declaration it is treated as a parenthesized
2287 parameter named x, and as an abstract declarator it is
2290 ??? Also following the old parser, attributes inside an empty
2291 parameter list are ignored, making it a list not yielding a
2292 prototype, rather than giving an error or making it have one
2293 parameter with implicit type int.
2295 ??? Also following the old parser, typedef names may be
2296 redeclared in declarators, but not Objective-C class names. */
2298 if (kind != C_DTR_ABSTRACT
2299 && c_parser_next_token_is (parser, CPP_NAME)
2301 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2302 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2304 struct c_declarator *inner
2305 = build_id_declarator (c_parser_peek_token (parser)->value);
2307 inner->id_loc = c_parser_peek_token (parser)->location;
2308 c_parser_consume_token (parser);
2309 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2312 if (kind != C_DTR_NORMAL
2313 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2315 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2316 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2319 /* Either we are at the end of an abstract declarator, or we have
2322 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2325 struct c_declarator *inner;
2326 c_parser_consume_token (parser);
2327 attrs = c_parser_attributes (parser);
2328 if (kind != C_DTR_NORMAL
2329 && (c_parser_next_token_starts_declspecs (parser)
2330 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2332 struct c_arg_info *args
2333 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2340 = build_function_declarator (args,
2341 build_id_declarator (NULL_TREE));
2342 return c_parser_direct_declarator_inner (parser, *seen_id,
2346 /* A parenthesized declarator. */
2347 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2348 if (inner != NULL && attrs != NULL)
2349 inner = build_attrs_declarator (attrs, inner);
2350 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2352 c_parser_consume_token (parser);
2356 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2367 if (kind == C_DTR_NORMAL)
2369 c_parser_error (parser, "expected identifier or %<(%>");
2373 return build_id_declarator (NULL_TREE);
2377 /* Parse part of a direct declarator or direct abstract declarator,
2378 given that some (in INNER) has already been parsed; ID_PRESENT is
2379 true if an identifier is present, false for an abstract
2382 static struct c_declarator *
2383 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2384 struct c_declarator *inner)
2386 /* Parse a sequence of array declarators and parameter lists. */
2387 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2389 struct c_declarator *declarator;
2390 struct c_declspecs *quals_attrs = build_null_declspecs ();
2394 c_parser_consume_token (parser);
2395 c_parser_declspecs (parser, quals_attrs, false, false, true);
2396 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2398 c_parser_consume_token (parser);
2399 if (static_seen && !quals_attrs->declspecs_seen_p)
2400 c_parser_declspecs (parser, quals_attrs, false, false, true);
2401 if (!quals_attrs->declspecs_seen_p)
2403 /* If "static" is present, there must be an array dimension.
2404 Otherwise, there may be a dimension, "*", or no
2409 dimen = c_parser_expr_no_commas (parser, NULL).value;
2413 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2418 else if (c_parser_next_token_is (parser, CPP_MULT))
2420 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2424 c_parser_consume_token (parser);
2429 dimen = c_parser_expr_no_commas (parser, NULL).value;
2435 dimen = c_parser_expr_no_commas (parser, NULL).value;
2438 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2439 c_parser_consume_token (parser);
2442 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2446 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2448 if (declarator == NULL)
2450 inner = set_array_declarator_inner (declarator, inner, !id_present);
2451 return c_parser_direct_declarator_inner (parser, id_present, inner);
2453 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2456 struct c_arg_info *args;
2457 c_parser_consume_token (parser);
2458 attrs = c_parser_attributes (parser);
2459 args = c_parser_parms_declarator (parser, id_present, attrs);
2464 inner = build_function_declarator (args, inner);
2465 return c_parser_direct_declarator_inner (parser, id_present, inner);
2471 /* Parse a parameter list or identifier list, including the closing
2472 parenthesis but not the opening one. ATTRS are the attributes at
2473 the start of the list. ID_LIST_OK is true if an identifier list is
2474 acceptable; such a list must not have attributes at the start. */
2476 static struct c_arg_info *
2477 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2480 declare_parm_level ();
2481 /* If the list starts with an identifier, it is an identifier list.
2482 Otherwise, it is either a prototype list or an empty list. */
2485 && c_parser_next_token_is (parser, CPP_NAME)
2486 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2488 tree list = NULL_TREE, *nextp = &list;
2489 while (c_parser_next_token_is (parser, CPP_NAME)
2490 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2492 *nextp = build_tree_list (NULL_TREE,
2493 c_parser_peek_token (parser)->value);
2494 nextp = & TREE_CHAIN (*nextp);
2495 c_parser_consume_token (parser);
2496 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2498 c_parser_consume_token (parser);
2499 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2501 c_parser_error (parser, "expected identifier");
2505 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2507 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2512 ret->pending_sizes = 0;
2513 ret->had_vla_unspec = 0;
2514 c_parser_consume_token (parser);
2520 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2528 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2534 /* Parse a parameter list (possibly empty), including the closing
2535 parenthesis but not the opening one. ATTRS are the attributes at
2536 the start of the list. */
2538 static struct c_arg_info *
2539 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2541 bool good_parm = false;
2542 /* ??? Following the old parser, forward parameter declarations may
2543 use abstract declarators, and if no real parameter declarations
2544 follow the forward declarations then this is not diagnosed. Also
2545 note as above that attributes are ignored as the only contents of
2546 the parentheses, or as the only contents after forward
2548 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2550 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2555 ret->pending_sizes = 0;
2556 ret->had_vla_unspec = 0;
2557 c_parser_consume_token (parser);
2560 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2562 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2566 ret->pending_sizes = 0;
2567 ret->had_vla_unspec = 0;
2568 /* Suppress -Wold-style-definition for this case. */
2569 ret->types = error_mark_node;
2570 error ("ISO C requires a named argument before %<...%>");
2571 c_parser_consume_token (parser);
2572 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2574 c_parser_consume_token (parser);
2579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2584 /* Nonempty list of parameters, either terminated with semicolon
2585 (forward declarations; recurse) or with close parenthesis (normal
2586 function) or with ", ... )" (variadic function). */
2589 /* Parse a parameter. */
2590 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2595 push_parm_decl (parm);
2597 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2600 c_parser_consume_token (parser);
2601 mark_forward_parm_decls ();
2602 new_attrs = c_parser_attributes (parser);
2603 return c_parser_parms_list_declarator (parser, new_attrs);
2605 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2607 c_parser_consume_token (parser);
2609 return get_parm_info (false);
2612 struct c_arg_info *ret
2613 = XOBNEW (&parser_obstack, struct c_arg_info);
2618 ret->pending_sizes = 0;
2619 ret->had_vla_unspec = 0;
2623 if (!c_parser_require (parser, CPP_COMMA,
2624 "expected %<;%>, %<,%> or %<)%>"))
2626 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2629 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2631 c_parser_consume_token (parser);
2632 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2634 c_parser_consume_token (parser);
2636 return get_parm_info (true);
2639 struct c_arg_info *ret
2640 = XOBNEW (&parser_obstack, struct c_arg_info);
2645 ret->pending_sizes = 0;
2646 ret->had_vla_unspec = 0;
2652 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2660 /* Parse a parameter declaration. ATTRS are the attributes at the
2661 start of the declaration if it is the first parameter. */
2663 static struct c_parm *
2664 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2666 struct c_declspecs *specs;
2667 struct c_declarator *declarator;
2669 tree postfix_attrs = NULL_TREE;
2671 if (!c_parser_next_token_starts_declspecs (parser))
2673 /* ??? In some Objective-C cases '...' isn't applicable so there
2674 should be a different message. */
2675 c_parser_error (parser,
2676 "expected declaration specifiers or %<...%>");
2677 c_parser_skip_to_end_of_parameter (parser);
2680 specs = build_null_declspecs ();
2683 declspecs_add_attrs (specs, attrs);
2686 c_parser_declspecs (parser, specs, true, true, true);
2687 finish_declspecs (specs);
2688 pending_xref_error ();
2689 prefix_attrs = specs->attrs;
2690 specs->attrs = NULL_TREE;
2691 declarator = c_parser_declarator (parser, specs->type_seen_p,
2692 C_DTR_PARM, &dummy);
2693 if (declarator == NULL)
2695 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2698 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2699 postfix_attrs = c_parser_attributes (parser);
2700 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2704 /* Parse a string literal in an asm expression. It should not be
2705 translated, and wide string literals are an error although
2706 permitted by the syntax. This is a GNU extension.
2711 ??? At present, following the old parser, the caller needs to have
2712 set c_lex_string_translate to 0. It would be better to follow the
2713 C++ parser rather than using the c_lex_string_translate kludge. */
2716 c_parser_asm_string_literal (c_parser *parser)
2719 if (c_parser_next_token_is (parser, CPP_STRING))
2721 str = c_parser_peek_token (parser)->value;
2722 c_parser_consume_token (parser);
2724 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2726 error ("wide string literal in %<asm%>");
2727 str = build_string (1, "");
2728 c_parser_consume_token (parser);
2732 c_parser_error (parser, "expected string literal");
2738 /* Parse a simple asm expression. This is used in restricted
2739 contexts, where a full expression with inputs and outputs does not
2740 make sense. This is a GNU extension.
2743 asm ( asm-string-literal )
2747 c_parser_simple_asm_expr (c_parser *parser)
2750 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2751 /* ??? Follow the C++ parser rather than using the
2752 c_lex_string_translate kludge. */
2753 c_lex_string_translate = 0;
2754 c_parser_consume_token (parser);
2755 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2757 c_lex_string_translate = 1;
2760 str = c_parser_asm_string_literal (parser);
2761 c_lex_string_translate = 1;
2762 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2764 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2770 /* Parse (possibly empty) attributes. This is a GNU extension.
2774 attributes attribute
2777 __attribute__ ( ( attribute-list ) )
2781 attribute_list , attrib
2786 any-word ( identifier )
2787 any-word ( identifier , nonempty-expr-list )
2788 any-word ( expr-list )
2790 where the "identifier" must not be declared as a type, and
2791 "any-word" may be any identifier (including one declared as a
2792 type), a reserved word storage class specifier, type specifier or
2793 type qualifier. ??? This still leaves out most reserved keywords
2794 (following the old parser), shouldn't we include them, and why not
2795 allow identifiers declared as types to start the arguments? */
2798 c_parser_attributes (c_parser *parser)
2800 tree attrs = NULL_TREE;
2801 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2803 /* ??? Follow the C++ parser rather than using the
2804 c_lex_string_translate kludge. */
2805 c_lex_string_translate = 0;
2806 c_parser_consume_token (parser);
2807 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2809 c_lex_string_translate = 1;
2812 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2814 c_lex_string_translate = 1;
2815 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2818 /* Parse the attribute list. */
2819 while (c_parser_next_token_is (parser, CPP_COMMA)
2820 || c_parser_next_token_is (parser, CPP_NAME)
2821 || c_parser_next_token_is (parser, CPP_KEYWORD))
2823 tree attr, attr_name, attr_args;
2824 if (c_parser_next_token_is (parser, CPP_COMMA))
2826 c_parser_consume_token (parser);
2829 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2831 /* ??? See comment above about what keywords are
2834 switch (c_parser_peek_token (parser)->keyword)
2869 attr_name = c_parser_peek_token (parser)->value;
2870 c_parser_consume_token (parser);
2871 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2873 attr = build_tree_list (attr_name, NULL_TREE);
2874 attrs = chainon (attrs, attr);
2877 c_parser_consume_token (parser);
2878 /* Parse the attribute contents. If they start with an
2879 identifier which is followed by a comma or close
2880 parenthesis, then the arguments start with that
2881 identifier; otherwise they are an expression list. */
2882 if (c_parser_next_token_is (parser, CPP_NAME)
2883 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2884 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2885 || (c_parser_peek_2nd_token (parser)->type
2886 == CPP_CLOSE_PAREN)))
2888 tree arg1 = c_parser_peek_token (parser)->value;
2889 c_parser_consume_token (parser);
2890 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2891 attr_args = build_tree_list (NULL_TREE, arg1);
2894 c_parser_consume_token (parser);
2895 attr_args = tree_cons (NULL_TREE, arg1,
2896 c_parser_expr_list (parser, false));
2901 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2902 attr_args = NULL_TREE;
2904 attr_args = c_parser_expr_list (parser, false);
2906 attr = build_tree_list (attr_name, attr_args);
2907 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2908 c_parser_consume_token (parser);
2911 c_lex_string_translate = 1;
2912 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2916 attrs = chainon (attrs, attr);
2918 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2919 c_parser_consume_token (parser);
2922 c_lex_string_translate = 1;
2923 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2927 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2928 c_parser_consume_token (parser);
2931 c_lex_string_translate = 1;
2932 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2936 c_lex_string_translate = 1;
2941 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2944 specifier-qualifier-list abstract-declarator[opt]
2947 static struct c_type_name *
2948 c_parser_type_name (c_parser *parser)
2950 struct c_declspecs *specs = build_null_declspecs ();
2951 struct c_declarator *declarator;
2952 struct c_type_name *ret;
2954 c_parser_declspecs (parser, specs, false, true, true);
2955 if (!specs->declspecs_seen_p)
2957 c_parser_error (parser, "expected specifier-qualifier-list");
2960 pending_xref_error ();
2961 finish_declspecs (specs);
2962 declarator = c_parser_declarator (parser, specs->type_seen_p,
2963 C_DTR_ABSTRACT, &dummy);
2964 if (declarator == NULL)
2966 ret = XOBNEW (&parser_obstack, struct c_type_name);
2968 ret->declarator = declarator;
2972 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2975 assignment-expression
2976 { initializer-list }
2977 { initializer-list , }
2980 designation[opt] initializer
2981 initializer-list , designation[opt] initializer
2988 designator-list designator
2995 [ constant-expression ]
3007 [ constant-expression ... constant-expression ]
3009 Any expression without commas is accepted in the syntax for the
3010 constant-expressions, with non-constant expressions rejected later.
3012 This function is only used for top-level initializers; for nested
3013 ones, see c_parser_initval. */
3015 static struct c_expr
3016 c_parser_initializer (c_parser *parser)
3018 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3019 return c_parser_braced_init (parser, NULL_TREE, false);
3023 ret = c_parser_expr_no_commas (parser, NULL);
3024 if (TREE_CODE (ret.value) != STRING_CST
3025 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3026 ret = default_function_array_conversion (ret);
3031 /* Parse a braced initializer list. TYPE is the type specified for a
3032 compound literal, and NULL_TREE for other initializers and for
3033 nested braced lists. NESTED_P is true for nested braced lists,
3034 false for the list of a compound literal or the list that is the
3035 top-level initializer in a declaration. */
3037 static struct c_expr
3038 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3040 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3041 c_parser_consume_token (parser);
3043 push_init_level (0);
3045 really_start_incremental_init (type);
3046 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3049 pedwarn ("ISO C forbids empty initializer braces");
3053 /* Parse a non-empty initializer list, possibly with a trailing
3057 c_parser_initelt (parser);
3060 if (c_parser_next_token_is (parser, CPP_COMMA))
3061 c_parser_consume_token (parser);
3064 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3068 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3071 ret.value = error_mark_node;
3072 ret.original_code = ERROR_MARK;
3073 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3076 c_parser_consume_token (parser);
3077 return pop_init_level (0);
3080 /* Parse a nested initializer, including designators. */
3083 c_parser_initelt (c_parser *parser)
3085 /* Parse any designator or designator list. A single array
3086 designator may have the subsequent "=" omitted in GNU C, but a
3087 longer list or a structure member designator may not. */
3088 if (c_parser_next_token_is (parser, CPP_NAME)
3089 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3091 /* Old-style structure member designator. */
3092 set_init_label (c_parser_peek_token (parser)->value);
3094 pedwarn ("obsolete use of designated initializer with %<:%>");
3095 c_parser_consume_token (parser);
3096 c_parser_consume_token (parser);
3100 /* des_seen is 0 if there have been no designators, 1 if there
3101 has been a single array designator and 2 otherwise. */
3103 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3104 || c_parser_next_token_is (parser, CPP_DOT))
3106 int des_prev = des_seen;
3109 if (c_parser_next_token_is (parser, CPP_DOT))
3112 c_parser_consume_token (parser);
3113 if (c_parser_next_token_is (parser, CPP_NAME))
3115 set_init_label (c_parser_peek_token (parser)->value);
3116 c_parser_consume_token (parser);
3121 init.value = error_mark_node;
3122 init.original_code = ERROR_MARK;
3123 c_parser_error (parser, "expected identifier");
3124 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3125 process_init_element (init);
3132 /* ??? Following the old parser, [ objc-receiver
3133 objc-message-args ] is accepted as an initializer,
3134 being distinguished from a designator by what follows
3135 the first assignment expression inside the square
3136 brackets, but after a first array designator a
3137 subsequent square bracket is for Objective-C taken to
3138 start an expression, using the obsolete form of
3139 designated initializer without '=', rather than
3140 possibly being a second level of designation: in LALR
3141 terms, the '[' is shifted rather than reducing
3142 designator to designator-list. */
3143 if (des_prev == 1 && c_dialect_objc ())
3145 des_seen = des_prev;
3148 if (des_prev == 0 && c_dialect_objc ())
3150 /* This might be an array designator or an
3151 Objective-C message expression. If the former,
3152 continue parsing here; if the latter, parse the
3153 remainder of the initializer given the starting
3154 primary-expression. ??? It might make sense to
3155 distinguish when des_prev == 1 as well; see
3156 previous comment. */
3158 struct c_expr mexpr;
3159 c_parser_consume_token (parser);
3160 if (c_parser_peek_token (parser)->type == CPP_NAME
3161 && ((c_parser_peek_token (parser)->id_kind
3163 || (c_parser_peek_token (parser)->id_kind
3164 == C_ID_CLASSNAME)))
3166 /* Type name receiver. */
3167 tree id = c_parser_peek_token (parser)->value;
3168 c_parser_consume_token (parser);
3169 rec = objc_get_class_reference (id);
3170 goto parse_message_args;
3172 first = c_parser_expr_no_commas (parser, NULL).value;
3173 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3174 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3175 goto array_desig_after_first;
3176 /* Expression receiver. So far only one part
3177 without commas has been parsed; there might be
3178 more of the expression. */
3180 while (c_parser_next_token_is (parser, CPP_COMMA))
3183 c_parser_consume_token (parser);
3184 next = c_parser_expr_no_commas (parser, NULL);
3185 next = default_function_array_conversion (next);
3186 rec = build_compound_expr (rec, next.value);
3189 /* Now parse the objc-message-args. */
3190 args = c_parser_objc_message_args (parser);
3191 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3194 = objc_build_message_expr (build_tree_list (rec, args));
3195 mexpr.original_code = ERROR_MARK;
3196 /* Now parse and process the remainder of the
3197 initializer, starting with this message
3198 expression as a primary-expression. */
3199 c_parser_initval (parser, &mexpr);
3202 c_parser_consume_token (parser);
3203 first = c_parser_expr_no_commas (parser, NULL).value;
3204 array_desig_after_first:
3205 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3207 c_parser_consume_token (parser);
3208 second = c_parser_expr_no_commas (parser, NULL).value;
3212 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3214 c_parser_consume_token (parser);
3215 set_init_index (first, second);
3216 if (pedantic && second)
3217 pedwarn ("ISO C forbids specifying range of "
3218 "elements to initialize");
3221 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3227 if (c_parser_next_token_is (parser, CPP_EQ))
3229 if (pedantic && !flag_isoc99)
3230 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3231 c_parser_consume_token (parser);
3238 pedwarn ("obsolete use of designated initializer "
3244 init.value = error_mark_node;
3245 init.original_code = ERROR_MARK;
3246 c_parser_error (parser, "expected %<=%>");
3247 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3248 process_init_element (init);
3254 c_parser_initval (parser, NULL);
3257 /* Parse a nested initializer; as c_parser_initializer but parses
3258 initializers within braced lists, after any designators have been
3259 applied. If AFTER is not NULL then it is an Objective-C message
3260 expression which is the primary-expression starting the
3264 c_parser_initval (c_parser *parser, struct c_expr *after)
3267 gcc_assert (!after || c_dialect_objc ());
3268 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3269 init = c_parser_braced_init (parser, NULL_TREE, true);
3272 init = c_parser_expr_no_commas (parser, after);
3273 if (init.value != NULL_TREE
3274 && TREE_CODE (init.value) != STRING_CST
3275 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3276 init = default_function_array_conversion (init);
3278 process_init_element (init);
3281 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3285 { block-item-list[opt] }
3286 { label-declarations block-item-list }
3290 block-item-list block-item
3302 { label-declarations block-item-list }
3305 __extension__ nested-declaration
3306 nested-function-definition
3310 label-declarations label-declaration
3313 __label__ identifier-list ;
3315 Allowing the mixing of declarations and code is new in C99. The
3316 GNU syntax also permits (not shown above) labels at the end of
3317 compound statements, which yield an error. We don't allow labels
3318 on declarations; this might seem like a natural extension, but
3319 there would be a conflict between attributes on the label and
3320 prefix attributes on the declaration. ??? The syntax follows the
3321 old parser in requiring something after label declarations.
3322 Although they are erroneous if the labels declared aren't defined,
3323 is it useful for the syntax to be this way?
3335 c_parser_compound_statement (c_parser *parser)
3338 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3339 return error_mark_node;
3340 stmt = c_begin_compound_stmt (true);
3341 c_parser_compound_statement_nostart (parser);
3342 return c_end_compound_stmt (stmt, true);
3345 /* Parse a compound statement except for the opening brace. This is
3346 used for parsing both compound statements and statement expressions
3347 (which follow different paths to handling the opening). */
3350 c_parser_compound_statement_nostart (c_parser *parser)
3352 bool last_stmt = false;
3353 bool last_label = false;
3354 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3356 c_parser_consume_token (parser);
3359 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3361 /* Read zero or more forward-declarations for labels that nested
3362 functions can jump to. */
3363 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3365 c_parser_consume_token (parser);
3366 /* Any identifiers, including those declared as type names,
3371 if (c_parser_next_token_is_not (parser, CPP_NAME))
3373 c_parser_error (parser, "expected identifier");
3377 = declare_label (c_parser_peek_token (parser)->value);
3378 C_DECLARED_LABEL_FLAG (label) = 1;
3379 add_stmt (build_stmt (DECL_EXPR, label));
3380 c_parser_consume_token (parser);
3381 if (c_parser_next_token_is (parser, CPP_COMMA))
3382 c_parser_consume_token (parser);
3386 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3388 /* ??? Locating this diagnostic on the token after the
3389 declarations end follows the old parser, but it might be
3390 better to locate it where the declarations start instead. */
3392 pedwarn ("ISO C forbids label declarations");
3394 /* We must now have at least one statement, label or declaration. */
3395 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3397 c_parser_error (parser, "expected declaration or statement");
3398 c_parser_consume_token (parser);
3401 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3403 location_t loc = c_parser_peek_token (parser)->location;
3404 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3405 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3406 || (c_parser_next_token_is (parser, CPP_NAME)
3407 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3411 c_parser_label (parser);
3413 else if (!last_label
3414 && c_parser_next_token_starts_declspecs (parser))
3417 c_parser_declaration_or_fndef (parser, true, true, true, true);
3419 && ((pedantic && !flag_isoc99)
3420 || warn_declaration_after_statement))
3421 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3425 else if (!last_label
3426 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3428 /* __extension__ can start a declaration, but is also an
3429 unary operator that can start an expression. Consume all
3430 but the last of a possible series of __extension__ to
3432 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3433 && (c_parser_peek_2nd_token (parser)->keyword
3435 c_parser_consume_token (parser);
3436 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3439 ext = disable_extension_diagnostics ();
3440 c_parser_consume_token (parser);
3442 c_parser_declaration_or_fndef (parser, true, true, true, true);
3443 /* Following the old parser, __extension__ does not
3444 disable this diagnostic. */
3445 restore_extension_diagnostics (ext);
3447 && ((pedantic && !flag_isoc99)
3448 || warn_declaration_after_statement))
3449 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3456 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3458 /* External pragmas, and some omp pragmas, are not associated
3459 with regular c code, and so are not to be considered statements
3460 syntactically. This ensures that the user doesn't put them
3461 places that would turn into syntax errors if the directive
3463 if (c_parser_pragma (parser, pragma_compound))
3464 last_label = false, last_stmt = true;
3466 else if (c_parser_next_token_is (parser, CPP_EOF))
3468 c_parser_error (parser, "expected declaration or statement");
3476 c_parser_statement_after_labels (parser);
3479 parser->error = false;
3482 error ("label at end of compound statement");
3483 c_parser_consume_token (parser);
3486 /* Parse a label (C90 6.6.1, C99 6.8.1).
3489 identifier : attributes[opt]
3490 case constant-expression :
3496 case constant-expression ... constant-expression :
3498 The use of attributes on labels is a GNU extension. The syntax in
3499 GNU C accepts any expressions without commas, non-constant
3500 expressions being rejected later. */
3503 c_parser_label (c_parser *parser)
3505 location_t loc1 = c_parser_peek_token (parser)->location;
3506 tree label = NULL_TREE;
3507 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3510 c_parser_consume_token (parser);
3511 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3512 if (c_parser_next_token_is (parser, CPP_COLON))
3514 c_parser_consume_token (parser);
3515 label = do_case (exp1, NULL_TREE);
3517 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3519 c_parser_consume_token (parser);
3520 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3521 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3522 label = do_case (exp1, exp2);
3525 c_parser_error (parser, "expected %<:%> or %<...%>");
3527 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3529 c_parser_consume_token (parser);
3530 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3531 label = do_case (NULL_TREE, NULL_TREE);
3535 tree name = c_parser_peek_token (parser)->value;
3539 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3540 c_parser_consume_token (parser);
3541 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3542 loc2 = c_parser_peek_token (parser)->location;
3543 c_parser_consume_token (parser);
3544 attrs = c_parser_attributes (parser);
3545 tlab = define_label (loc2, name);
3548 decl_attributes (&tlab, attrs, 0);
3549 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3553 SET_EXPR_LOCATION (label, loc1);
3556 /* Parse a statement (C90 6.6, C99 6.8).
3561 expression-statement
3569 expression-statement:
3572 selection-statement:
3576 iteration-statement:
3585 return expression[opt] ;
3598 objc-throw-statement
3599 objc-try-catch-statement
3600 objc-synchronized-statement
3602 objc-throw-statement:
3616 parallel-for-construct
3617 parallel-sections-construct
3624 parallel-directive structured-block
3627 for-directive iteration-statement
3630 sections-directive section-scope
3633 single-directive structured-block
3635 parallel-for-construct:
3636 parallel-for-directive iteration-statement
3638 parallel-sections-construct:
3639 parallel-sections-directive section-scope
3642 master-directive structured-block
3645 critical-directive structured-block
3648 atomic-directive expression-statement
3651 ordered-directive structured-block */
3654 c_parser_statement (c_parser *parser)
3656 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3657 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3658 || (c_parser_next_token_is (parser, CPP_NAME)
3659 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3660 c_parser_label (parser);
3661 c_parser_statement_after_labels (parser);
3664 /* Parse a statement, other than a labeled statement. */
3667 c_parser_statement_after_labels (c_parser *parser)
3669 location_t loc = c_parser_peek_token (parser)->location;
3670 tree stmt = NULL_TREE;
3671 switch (c_parser_peek_token (parser)->type)
3673 case CPP_OPEN_BRACE:
3674 add_stmt (c_parser_compound_statement (parser));
3677 switch (c_parser_peek_token (parser)->keyword)
3680 c_parser_if_statement (parser);
3683 c_parser_switch_statement (parser);
3686 c_parser_while_statement (parser);
3689 c_parser_do_statement (parser);
3692 c_parser_for_statement (parser);
3695 c_parser_consume_token (parser);
3696 if (c_parser_next_token_is (parser, CPP_NAME))
3698 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3699 c_parser_consume_token (parser);
3701 else if (c_parser_next_token_is (parser, CPP_MULT))
3703 c_parser_consume_token (parser);
3704 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3707 c_parser_error (parser, "expected identifier or %<*%>");
3708 goto expect_semicolon;
3710 c_parser_consume_token (parser);
3711 stmt = c_finish_bc_stmt (&c_cont_label, false);
3712 goto expect_semicolon;
3714 c_parser_consume_token (parser);
3715 stmt = c_finish_bc_stmt (&c_break_label, true);
3716 goto expect_semicolon;
3718 c_parser_consume_token (parser);
3719 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3721 stmt = c_finish_return (NULL_TREE);
3722 c_parser_consume_token (parser);
3726 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3727 goto expect_semicolon;
3731 stmt = c_parser_asm_statement (parser);
3734 gcc_assert (c_dialect_objc ());
3735 c_parser_consume_token (parser);
3736 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3738 stmt = objc_build_throw_stmt (NULL_TREE);
3739 c_parser_consume_token (parser);
3744 = objc_build_throw_stmt (c_parser_expression (parser).value);
3745 goto expect_semicolon;
3749 gcc_assert (c_dialect_objc ());
3750 c_parser_objc_try_catch_statement (parser);
3752 case RID_AT_SYNCHRONIZED:
3753 gcc_assert (c_dialect_objc ());
3754 c_parser_objc_synchronized_statement (parser);
3761 c_parser_consume_token (parser);
3763 case CPP_CLOSE_PAREN:
3764 case CPP_CLOSE_SQUARE:
3765 /* Avoid infinite loop in error recovery:
3766 c_parser_skip_until_found stops at a closing nesting
3767 delimiter without consuming it, but here we need to consume
3768 it to proceed further. */
3769 c_parser_error (parser, "expected statement");
3770 c_parser_consume_token (parser);
3773 c_parser_pragma (parser, pragma_stmt);
3777 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3779 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3782 /* Two cases cannot and do not have line numbers associated: If stmt
3783 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3784 cannot hold line numbers. But that's OK because the statement
3785 will either be changed to a MODIFY_EXPR during gimplification of
3786 the statement expr, or discarded. If stmt was compound, but
3787 without new variables, we will have skipped the creation of a
3788 BIND and will have a bare STATEMENT_LIST. But that's OK because
3789 (recursively) all of the component statements should already have
3790 line numbers assigned. ??? Can we discard no-op statements
3792 if (stmt && CAN_HAVE_LOCATION_P (stmt))
3793 SET_EXPR_LOCATION (stmt, loc);
3796 /* Parse a parenthesized condition from an if, do or while statement.
3802 c_parser_paren_condition (c_parser *parser)
3806 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3807 return error_mark_node;
3808 loc = c_parser_peek_token (parser)->location;
3809 cond = c_objc_common_truthvalue_conversion
3810 (c_parser_expression_conv (parser).value);
3811 if (CAN_HAVE_LOCATION_P (cond))
3812 SET_EXPR_LOCATION (cond, loc);
3813 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3817 /* Parse a statement which is a block in C99. */
3820 c_parser_c99_block_statement (c_parser *parser)
3822 tree block = c_begin_compound_stmt (flag_isoc99);
3823 c_parser_statement (parser);
3824 return c_end_compound_stmt (block, flag_isoc99);
3827 /* Parse the body of an if statement or the else half thereof. This
3828 is just parsing a statement but (a) it is a block in C99, (b) we
3829 track whether the body is an if statement for the sake of
3830 -Wparentheses warnings, (c) we handle an empty body specially for
3831 the sake of -Wempty-body warnings. */
3834 c_parser_if_body (c_parser *parser, bool *if_p)
3836 tree block = c_begin_compound_stmt (flag_isoc99);
3837 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3838 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3839 || (c_parser_next_token_is (parser, CPP_NAME)
3840 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3841 c_parser_label (parser);
3842 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3843 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3844 add_stmt (build_empty_stmt ());
3845 c_parser_statement_after_labels (parser);
3846 return c_end_compound_stmt (block, flag_isoc99);
3849 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3852 if ( expression ) statement
3853 if ( expression ) statement else statement
3857 c_parser_if_statement (c_parser *parser)
3862 bool first_if = false, second_if = false;
3863 tree first_body, second_body;
3864 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3865 c_parser_consume_token (parser);
3866 block = c_begin_compound_stmt (flag_isoc99);
3867 loc = c_parser_peek_token (parser)->location;
3868 cond = c_parser_paren_condition (parser);
3869 first_body = c_parser_if_body (parser, &first_if);
3870 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3872 c_parser_consume_token (parser);
3873 second_body = c_parser_if_body (parser, &second_if);
3876 second_body = NULL_TREE;
3877 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3878 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3881 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3884 switch (expression) statement
3888 c_parser_switch_statement (c_parser *parser)
3890 tree block, expr, body, save_break;
3891 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3892 c_parser_consume_token (parser);
3893 block = c_begin_compound_stmt (flag_isoc99);
3894 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3896 expr = c_parser_expression (parser).value;
3897 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3900 expr = error_mark_node;
3901 c_start_case (expr);
3902 save_break = c_break_label;
3903 c_break_label = NULL_TREE;
3904 body = c_parser_c99_block_statement (parser);
3905 c_finish_case (body);
3907 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3908 c_break_label = save_break;
3909 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3912 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3915 while (expression) statement
3919 c_parser_while_statement (c_parser *parser)
3921 tree block, cond, body, save_break, save_cont;
3923 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3924 c_parser_consume_token (parser);
3925 block = c_begin_compound_stmt (flag_isoc99);
3926 loc = c_parser_peek_token (parser)->location;
3927 cond = c_parser_paren_condition (parser);
3928 save_break = c_break_label;
3929 c_break_label = NULL_TREE;
3930 save_cont = c_cont_label;
3931 c_cont_label = NULL_TREE;
3932 body = c_parser_c99_block_statement (parser);
3933 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3934 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3935 c_break_label = save_break;
3936 c_cont_label = save_cont;
3939 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3942 do statement while ( expression ) ;
3946 c_parser_do_statement (c_parser *parser)
3948 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3950 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3951 c_parser_consume_token (parser);
3952 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3953 warning (OPT_Wempty_body,
3954 "suggest braces around empty body in %<do%> statement");
3955 block = c_begin_compound_stmt (flag_isoc99);
3956 loc = c_parser_peek_token (parser)->location;
3957 save_break = c_break_label;
3958 c_break_label = NULL_TREE;
3959 save_cont = c_cont_label;
3960 c_cont_label = NULL_TREE;
3961 body = c_parser_c99_block_statement (parser);
3962 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
3963 new_break = c_break_label;
3964 c_break_label = save_break;
3965 new_cont = c_cont_label;
3966 c_cont_label = save_cont;
3967 cond = c_parser_paren_condition (parser);
3968 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3969 c_parser_skip_to_end_of_block_or_statement (parser);
3970 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
3971 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3974 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3977 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3978 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3980 The form with a declaration is new in C99.
3982 ??? In accordance with the old parser, the declaration may be a
3983 nested function, which is then rejected in check_for_loop_decls,
3984 but does it make any sense for this to be included in the grammar?
3985 Note in particular that the nested function does not include a
3986 trailing ';', whereas the "declaration" production includes one.
3987 Also, can we reject bad declarations earlier and cheaper than
3988 check_for_loop_decls? */
3991 c_parser_for_statement (c_parser *parser)
3993 tree block, cond, incr, save_break, save_cont, body;
3995 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
3996 loc = c_parser_peek_token (parser)->location;
3997 c_parser_consume_token (parser);
3998 block = c_begin_compound_stmt (flag_isoc99);
3999 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4001 /* Parse the initialization declaration or expression. */
4002 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4004 c_parser_consume_token (parser);
4005 c_finish_expr_stmt (NULL_TREE);
4007 else if (c_parser_next_token_starts_declspecs (parser))
4009 c_parser_declaration_or_fndef (parser, true, true, true, true);
4010 check_for_loop_decls ();
4012 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4014 /* __extension__ can start a declaration, but is also an
4015 unary operator that can start an expression. Consume all
4016 but the last of a possible series of __extension__ to
4018 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4019 && (c_parser_peek_2nd_token (parser)->keyword
4021 c_parser_consume_token (parser);
4022 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4025 ext = disable_extension_diagnostics ();
4026 c_parser_consume_token (parser);
4027 c_parser_declaration_or_fndef (parser, true, true, true, true);
4028 restore_extension_diagnostics (ext);
4029 check_for_loop_decls ();
4037 c_finish_expr_stmt (c_parser_expression (parser).value);
4038 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4040 /* Parse the loop condition. */
4041 loc = c_parser_peek_token (parser)->location;
4042 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4044 c_parser_consume_token (parser);
4049 tree ocond = c_parser_expression_conv (parser).value;
4050 cond = c_objc_common_truthvalue_conversion (ocond);
4051 if (CAN_HAVE_LOCATION_P (cond))
4052 SET_EXPR_LOCATION (cond, loc);
4053 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4055 /* Parse the increment expression. */
4056 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4057 incr = c_process_expr_stmt (NULL_TREE);
4059 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4060 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4064 cond = error_mark_node;
4065 incr = error_mark_node;
4067 save_break = c_break_label;
4068 c_break_label = NULL_TREE;
4069 save_cont = c_cont_label;
4070 c_cont_label = NULL_TREE;
4071 body = c_parser_c99_block_statement (parser);
4072 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4073 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4074 c_break_label = save_break;
4075 c_cont_label = save_cont;
4078 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4079 statement with inputs, outputs, clobbers, and volatile tag
4083 asm type-qualifier[opt] ( asm-argument ) ;
4087 asm-string-literal : asm-operands[opt]
4088 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4089 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4091 Qualifiers other than volatile are accepted in the syntax but
4095 c_parser_asm_statement (c_parser *parser)
4097 tree quals, str, outputs, inputs, clobbers, ret;
4099 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4100 c_parser_consume_token (parser);
4101 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4103 quals = c_parser_peek_token (parser)->value;
4104 c_parser_consume_token (parser);
4106 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4107 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4109 warning (0, "%E qualifier ignored on asm",
4110 c_parser_peek_token (parser)->value);
4112 c_parser_consume_token (parser);
4116 /* ??? Follow the C++ parser rather than using the
4117 c_lex_string_translate kludge. */
4118 c_lex_string_translate = 0;
4119 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4121 c_lex_string_translate = 1;
4124 str = c_parser_asm_string_literal (parser);
4125 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4128 outputs = NULL_TREE;
4130 clobbers = NULL_TREE;
4133 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4135 c_lex_string_translate = 1;
4136 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4140 /* Parse outputs. */
4141 if (c_parser_next_token_is (parser, CPP_COLON)
4142 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4143 outputs = NULL_TREE;
4145 outputs = c_parser_asm_operands (parser, false);
4146 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4149 clobbers = NULL_TREE;
4152 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4154 c_lex_string_translate = 1;
4155 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4159 if (c_parser_next_token_is (parser, CPP_COLON)
4160 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4163 inputs = c_parser_asm_operands (parser, true);
4164 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4166 clobbers = NULL_TREE;
4169 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4171 c_lex_string_translate = 1;
4172 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4175 /* Parse clobbers. */
4176 clobbers = c_parser_asm_clobbers (parser);
4178 c_lex_string_translate = 1;
4179 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4181 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4184 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4185 c_parser_skip_to_end_of_block_or_statement (parser);
4186 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4191 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4192 not outputs), apply the default conversion of functions and arrays
4197 asm-operands , asm-operand
4200 asm-string-literal ( expression )
4201 [ identifier ] asm-string-literal ( expression )
4205 c_parser_asm_operands (c_parser *parser, bool convert_p)
4207 tree list = NULL_TREE;
4212 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4214 c_parser_consume_token (parser);
4215 if (c_parser_next_token_is (parser, CPP_NAME))
4217 tree id = c_parser_peek_token (parser)->value;
4218 c_parser_consume_token (parser);
4219 name = build_string (IDENTIFIER_LENGTH (id),
4220 IDENTIFIER_POINTER (id));
4224 c_parser_error (parser, "expected identifier");
4225 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4228 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4233 str = c_parser_asm_string_literal (parser);
4234 if (str == NULL_TREE)
4236 c_lex_string_translate = 1;
4237 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4239 c_lex_string_translate = 0;
4242 expr = c_parser_expression (parser);
4244 expr = default_function_array_conversion (expr);
4245 c_lex_string_translate = 0;
4246 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4248 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4251 list = chainon (list, build_tree_list (build_tree_list (name, str),
4253 if (c_parser_next_token_is (parser, CPP_COMMA))
4254 c_parser_consume_token (parser);
4261 /* Parse asm clobbers, a GNU extension.
4265 asm-clobbers , asm-string-literal
4269 c_parser_asm_clobbers (c_parser *parser)
4271 tree list = NULL_TREE;
4274 tree str = c_parser_asm_string_literal (parser);
4276 list = tree_cons (NULL_TREE, str, list);
4279 if (c_parser_next_token_is (parser, CPP_COMMA))
4280 c_parser_consume_token (parser);
4287 /* Parse an expression other than a compound expression; that is, an
4288 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4289 NULL then it is an Objective-C message expression which is the
4290 primary-expression starting the expression as an initializer.
4292 assignment-expression:
4293 conditional-expression
4294 unary-expression assignment-operator assignment-expression
4296 assignment-operator: one of
4297 = *= /= %= += -= <<= >>= &= ^= |=
4299 In GNU C we accept any conditional expression on the LHS and
4300 diagnose the invalid lvalue rather than producing a syntax
4303 static struct c_expr
4304 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4306 struct c_expr lhs, rhs, ret;
4307 enum tree_code code;
4308 gcc_assert (!after || c_dialect_objc ());
4309 lhs = c_parser_conditional_expression (parser, after);
4310 switch (c_parser_peek_token (parser)->type)
4319 code = TRUNC_DIV_EXPR;
4322 code = TRUNC_MOD_EXPR;
4337 code = BIT_AND_EXPR;
4340 code = BIT_XOR_EXPR;
4343 code = BIT_IOR_EXPR;
4348 c_parser_consume_token (parser);
4349 rhs = c_parser_expr_no_commas (parser, NULL);
4350 rhs = default_function_array_conversion (rhs);
4351 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4352 if (code == NOP_EXPR)
4353 ret.original_code = MODIFY_EXPR;
4356 TREE_NO_WARNING (ret.value) = 1;
4357 ret.original_code = ERROR_MARK;
4362 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4363 is not NULL then it is an Objective-C message expression which is
4364 the primary-expression starting the expression as an initializer.
4366 conditional-expression:
4367 logical-OR-expression
4368 logical-OR-expression ? expression : conditional-expression
4372 conditional-expression:
4373 logical-OR-expression ? : conditional-expression
4376 static struct c_expr
4377 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4379 struct c_expr cond, exp1, exp2, ret;
4380 gcc_assert (!after || c_dialect_objc ());
4381 cond = c_parser_binary_expression (parser, after);
4382 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4384 cond = default_function_array_conversion (cond);
4385 c_parser_consume_token (parser);
4386 if (c_parser_next_token_is (parser, CPP_COLON))
4389 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4390 /* Make sure first operand is calculated only once. */
4391 exp1.value = save_expr (default_conversion (cond.value));
4392 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4393 skip_evaluation += cond.value == truthvalue_true_node;
4398 = c_objc_common_truthvalue_conversion
4399 (default_conversion (cond.value));
4400 skip_evaluation += cond.value == truthvalue_false_node;
4401 exp1 = c_parser_expression_conv (parser);
4402 skip_evaluation += ((cond.value == truthvalue_true_node)
4403 - (cond.value == truthvalue_false_node));
4405 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4407 skip_evaluation -= cond.value == truthvalue_true_node;
4408 ret.value = error_mark_node;
4409 ret.original_code = ERROR_MARK;
4412 exp2 = c_parser_conditional_expression (parser, NULL);
4413 exp2 = default_function_array_conversion (exp2);
4414 skip_evaluation -= cond.value == truthvalue_true_node;
4415 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4416 ret.original_code = ERROR_MARK;
4420 /* Parse a binary expression; that is, a logical-OR-expression (C90
4421 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4422 an Objective-C message expression which is the primary-expression
4423 starting the expression as an initializer.
4425 multiplicative-expression:
4427 multiplicative-expression * cast-expression
4428 multiplicative-expression / cast-expression
4429 multiplicative-expression % cast-expression
4431 additive-expression:
4432 multiplicative-expression
4433 additive-expression + multiplicative-expression
4434 additive-expression - multiplicative-expression
4438 shift-expression << additive-expression
4439 shift-expression >> additive-expression
4441 relational-expression:
4443 relational-expression < shift-expression
4444 relational-expression > shift-expression
4445 relational-expression <= shift-expression
4446 relational-expression >= shift-expression
4448 equality-expression:
4449 relational-expression
4450 equality-expression == relational-expression
4451 equality-expression != relational-expression
4455 AND-expression & equality-expression
4457 exclusive-OR-expression:
4459 exclusive-OR-expression ^ AND-expression
4461 inclusive-OR-expression:
4462 exclusive-OR-expression
4463 inclusive-OR-expression | exclusive-OR-expression
4465 logical-AND-expression:
4466 inclusive-OR-expression
4467 logical-AND-expression && inclusive-OR-expression
4469 logical-OR-expression:
4470 logical-AND-expression
4471 logical-OR-expression || logical-AND-expression
4474 static struct c_expr
4475 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4477 /* A binary expression is parsed using operator-precedence parsing,
4478 with the operands being cast expressions. All the binary
4479 operators are left-associative. Thus a binary expression is of
4482 E0 op1 E1 op2 E2 ...
4484 which we represent on a stack. On the stack, the precedence
4485 levels are strictly increasing. When a new operator is
4486 encountered of higher precedence than that at the top of the
4487 stack, it is pushed; its LHS is the top expression, and its RHS
4488 is everything parsed until it is popped. When a new operator is
4489 encountered with precedence less than or equal to that at the top
4490 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4491 by the result of the operation until the operator at the top of
4492 the stack has lower precedence than the new operator or there is
4493 only one element on the stack; then the top expression is the LHS
4494 of the new operator. In the case of logical AND and OR
4495 expressions, we also need to adjust skip_evaluation as
4496 appropriate when the operators are pushed and popped. */
4498 /* The precedence levels, where 0 is a dummy lowest level used for
4499 the bottom of the stack. */
4515 /* The expression at this stack level. */
4517 /* The precedence of the operator on its left, PREC_NONE at the
4518 bottom of the stack. */
4520 /* The operation on its left. */
4526 switch (stack[sp].op) \
4528 case TRUTH_ANDIF_EXPR: \
4529 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4531 case TRUTH_ORIF_EXPR: \
4532 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4537 stack[sp - 1].expr \
4538 = default_function_array_conversion (stack[sp - 1].expr); \
4540 = default_function_array_conversion (stack[sp].expr); \
4541 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4542 stack[sp - 1].expr, \
4546 gcc_assert (!after || c_dialect_objc ());
4547 stack[0].expr = c_parser_cast_expression (parser, after);
4548 stack[0].prec = PREC_NONE;
4553 enum tree_code ocode;
4556 switch (c_parser_peek_token (parser)->type)
4564 ocode = TRUNC_DIV_EXPR;
4568 ocode = TRUNC_MOD_EXPR;
4580 ocode = LSHIFT_EXPR;
4584 ocode = RSHIFT_EXPR;
4598 case CPP_GREATER_EQ:
4611 oprec = PREC_BITAND;
4612 ocode = BIT_AND_EXPR;
4615 oprec = PREC_BITXOR;
4616 ocode = BIT_XOR_EXPR;
4620 ocode = BIT_IOR_EXPR;
4623 oprec = PREC_LOGAND;
4624 ocode = TRUTH_ANDIF_EXPR;
4628 ocode = TRUTH_ORIF_EXPR;
4631 /* Not a binary operator, so end of the binary
4635 c_parser_consume_token (parser);
4636 while (oprec <= stack[sp].prec)
4640 case TRUTH_ANDIF_EXPR:
4642 = default_function_array_conversion (stack[sp].expr);
4643 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4644 (default_conversion (stack[sp].expr.value));
4645 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4647 case TRUTH_ORIF_EXPR:
4649 = default_function_array_conversion (stack[sp].expr);
4650 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4651 (default_conversion (stack[sp].expr.value));
4652 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4658 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4659 stack[sp].prec = oprec;
4660 stack[sp].op = ocode;
4665 return stack[0].expr;
4669 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4670 NULL then it is an Objective-C message expression which is the
4671 primary-expression starting the expression as an initializer.
4675 ( type-name ) unary-expression
4678 static struct c_expr
4679 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4681 gcc_assert (!after || c_dialect_objc ());
4683 return c_parser_postfix_expression_after_primary (parser, *after);
4684 /* If the expression begins with a parenthesized type name, it may
4685 be either a cast or a compound literal; we need to see whether
4686 the next character is '{' to tell the difference. If not, it is
4687 an unary expression. */
4688 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4689 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4691 struct c_type_name *type_name;
4694 c_parser_consume_token (parser);
4695 type_name = c_parser_type_name (parser);
4696 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4697 if (type_name == NULL)
4699 ret.value = error_mark_node;
4700 ret.original_code = ERROR_MARK;
4704 /* Save casted types in the function's used types hash table. */
4705 used_types_insert (type_name->specs->type);
4707 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4708 return c_parser_postfix_expression_after_paren_type (parser,
4710 expr = c_parser_cast_expression (parser, NULL);
4711 expr = default_function_array_conversion (expr);
4712 ret.value = c_cast_expr (type_name, expr.value);
4713 ret.original_code = ERROR_MARK;
4717 return c_parser_unary_expression (parser);
4720 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4726 unary-operator cast-expression
4727 sizeof unary-expression
4728 sizeof ( type-name )
4730 unary-operator: one of
4736 __alignof__ unary-expression
4737 __alignof__ ( type-name )
4740 unary-operator: one of
4741 __extension__ __real__ __imag__
4743 In addition, the GNU syntax treats ++ and -- as unary operators, so
4744 they may be applied to cast expressions with errors for non-lvalues
4747 static struct c_expr
4748 c_parser_unary_expression (c_parser *parser)
4751 struct c_expr ret, op;
4752 switch (c_parser_peek_token (parser)->type)
4755 c_parser_consume_token (parser);
4756 op = c_parser_cast_expression (parser, NULL);
4757 op = default_function_array_conversion (op);
4758 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4759 case CPP_MINUS_MINUS:
4760 c_parser_consume_token (parser);
4761 op = c_parser_cast_expression (parser, NULL);
4762 op = default_function_array_conversion (op);
4763 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4765 c_parser_consume_token (parser);
4766 return parser_build_unary_op (ADDR_EXPR,
4767 c_parser_cast_expression (parser, NULL));
4769 c_parser_consume_token (parser);
4770 op = c_parser_cast_expression (parser, NULL);
4771 op = default_function_array_conversion (op);
4772 ret.value = build_indirect_ref (op.value, "unary *");
4773 ret.original_code = ERROR_MARK;
4776 c_parser_consume_token (parser);
4777 if (!c_dialect_objc () && !in_system_header)
4778 warning (OPT_Wtraditional,
4779 "traditional C rejects the unary plus operator");
4780 op = c_parser_cast_expression (parser, NULL);
4781 op = default_function_array_conversion (op);
4782 return parser_build_unary_op (CONVERT_EXPR, op);
4784 c_parser_consume_token (parser);
4785 op = c_parser_cast_expression (parser, NULL);
4786 op = default_function_array_conversion (op);
4787 return parser_build_unary_op (NEGATE_EXPR, op);
4789 c_parser_consume_token (parser);
4790 op = c_parser_cast_expression (parser, NULL);
4791 op = default_function_array_conversion (op);
4792 return parser_build_unary_op (BIT_NOT_EXPR, op);
4794 c_parser_consume_token (parser);
4795 op = c_parser_cast_expression (parser, NULL);
4796 op = default_function_array_conversion (op);
4797 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4799 /* Refer to the address of a label as a pointer. */
4800 c_parser_consume_token (parser);
4801 if (c_parser_next_token_is (parser, CPP_NAME))
4803 ret.value = finish_label_address_expr
4804 (c_parser_peek_token (parser)->value);
4805 c_parser_consume_token (parser);
4809 c_parser_error (parser, "expected identifier");
4810 ret.value = error_mark_node;
4812 ret.original_code = ERROR_MARK;
4815 switch (c_parser_peek_token (parser)->keyword)
4818 return c_parser_sizeof_expression (parser);
4820 return c_parser_alignof_expression (parser);
4822 c_parser_consume_token (parser);
4823 ext = disable_extension_diagnostics ();
4824 ret = c_parser_cast_expression (parser, NULL);
4825 restore_extension_diagnostics (ext);
4828 c_parser_consume_token (parser);
4829 op = c_parser_cast_expression (parser, NULL);
4830 op = default_function_array_conversion (op);
4831 return parser_build_unary_op (REALPART_EXPR, op);
4833 c_parser_consume_token (parser);
4834 op = c_parser_cast_expression (parser, NULL);
4835 op = default_function_array_conversion (op);
4836 return parser_build_unary_op (IMAGPART_EXPR, op);
4838 return c_parser_postfix_expression (parser);
4841 return c_parser_postfix_expression (parser);
4845 /* Parse a sizeof expression. */
4847 static struct c_expr
4848 c_parser_sizeof_expression (c_parser *parser)
4851 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4852 c_parser_consume_token (parser);
4855 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4856 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4858 /* Either sizeof ( type-name ) or sizeof unary-expression
4859 starting with a compound literal. */
4860 struct c_type_name *type_name;
4861 c_parser_consume_token (parser);
4862 type_name = c_parser_type_name (parser);
4863 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4864 if (type_name == NULL)
4869 ret.value = error_mark_node;
4870 ret.original_code = ERROR_MARK;
4873 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4875 expr = c_parser_postfix_expression_after_paren_type (parser,
4879 /* sizeof ( type-name ). */
4882 if (type_name->declarator->kind == cdk_array
4883 && type_name->declarator->u.array.vla_unspec_p)
4886 error ("%<[*]%> not allowed in other than a declaration");
4888 return c_expr_sizeof_type (type_name);
4892 expr = c_parser_unary_expression (parser);
4896 if (TREE_CODE (expr.value) == COMPONENT_REF
4897 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4898 error ("%<sizeof%> applied to a bit-field");
4899 return c_expr_sizeof_expr (expr);
4903 /* Parse an alignof expression. */
4905 static struct c_expr
4906 c_parser_alignof_expression (c_parser *parser)
4909 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4910 c_parser_consume_token (parser);
4913 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4914 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4916 /* Either __alignof__ ( type-name ) or __alignof__
4917 unary-expression starting with a compound literal. */
4918 struct c_type_name *type_name;
4920 c_parser_consume_token (parser);
4921 type_name = c_parser_type_name (parser);
4922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4923 if (type_name == NULL)
4928 ret.value = error_mark_node;
4929 ret.original_code = ERROR_MARK;
4932 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4934 expr = c_parser_postfix_expression_after_paren_type (parser,
4938 /* alignof ( type-name ). */
4941 ret.value = c_alignof (groktypename (type_name));
4942 ret.original_code = ERROR_MARK;
4948 expr = c_parser_unary_expression (parser);
4952 ret.value = c_alignof_expr (expr.value);
4953 ret.original_code = ERROR_MARK;
4958 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4962 postfix-expression [ expression ]
4963 postfix-expression ( argument-expression-list[opt] )
4964 postfix-expression . identifier
4965 postfix-expression -> identifier
4966 postfix-expression ++
4967 postfix-expression --
4968 ( type-name ) { initializer-list }
4969 ( type-name ) { initializer-list , }
4971 argument-expression-list:
4973 argument-expression-list , argument-expression
4985 (treated as a keyword in GNU C)
4988 ( compound-statement )
4989 __builtin_va_arg ( assignment-expression , type-name )
4990 __builtin_offsetof ( type-name , offsetof-member-designator )
4991 __builtin_choose_expr ( assignment-expression ,
4992 assignment-expression ,
4993 assignment-expression )
4994 __builtin_types_compatible_p ( type-name , type-name )
4996 offsetof-member-designator:
4998 offsetof-member-designator . identifier
4999 offsetof-member-designator [ expression ]
5004 [ objc-receiver objc-message-args ]
5005 @selector ( objc-selector-arg )
5006 @protocol ( identifier )
5007 @encode ( type-name )
5011 static struct c_expr
5012 c_parser_postfix_expression (c_parser *parser)
5014 struct c_expr expr, e1, e2, e3;
5015 struct c_type_name *t1, *t2;
5016 switch (c_parser_peek_token (parser)->type)
5021 expr.value = c_parser_peek_token (parser)->value;
5022 expr.original_code = ERROR_MARK;
5023 c_parser_consume_token (parser);
5027 expr.value = c_parser_peek_token (parser)->value;
5028 expr.original_code = STRING_CST;
5029 c_parser_consume_token (parser);
5031 case CPP_OBJC_STRING:
5032 gcc_assert (c_dialect_objc ());
5034 = objc_build_string_object (c_parser_peek_token (parser)->value);
5035 expr.original_code = ERROR_MARK;
5036 c_parser_consume_token (parser);
5039 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5041 c_parser_error (parser, "expected expression");
5042 expr.value = error_mark_node;
5043 expr.original_code = ERROR_MARK;
5047 tree id = c_parser_peek_token (parser)->value;
5048 location_t loc = c_parser_peek_token (parser)->location;
5049 c_parser_consume_token (parser);
5050 expr.value = build_external_ref (id,
5051 (c_parser_peek_token (parser)->type
5052 == CPP_OPEN_PAREN), loc);
5053 expr.original_code = ERROR_MARK;
5056 case CPP_OPEN_PAREN:
5057 /* A parenthesized expression, statement expression or compound
5059 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5061 /* A statement expression. */
5063 c_parser_consume_token (parser);
5064 c_parser_consume_token (parser);
5065 if (cur_stmt_list == NULL)
5067 error ("braced-group within expression allowed "
5068 "only inside a function");
5069 parser->error = true;
5070 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5071 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5072 expr.value = error_mark_node;
5073 expr.original_code = ERROR_MARK;
5076 stmt = c_begin_stmt_expr ();
5077 c_parser_compound_statement_nostart (parser);
5078 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5081 pedwarn ("ISO C forbids braced-groups within expressions");
5082 expr.value = c_finish_stmt_expr (stmt);
5083 expr.original_code = ERROR_MARK;
5085 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5087 /* A compound literal. ??? Can we actually get here rather
5088 than going directly to
5089 c_parser_postfix_expression_after_paren_type from
5091 struct c_type_name *type_name;
5092 c_parser_consume_token (parser);
5093 type_name = c_parser_type_name (parser);
5094 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5096 if (type_name == NULL)
5098 expr.value = error_mark_node;
5099 expr.original_code = ERROR_MARK;
5102 expr = c_parser_postfix_expression_after_paren_type (parser,
5107 /* A parenthesized expression. */
5108 c_parser_consume_token (parser);
5109 expr = c_parser_expression (parser);
5110 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5111 TREE_NO_WARNING (expr.value) = 1;
5112 expr.original_code = ERROR_MARK;
5113 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5118 switch (c_parser_peek_token (parser)->keyword)
5120 case RID_FUNCTION_NAME:
5121 case RID_PRETTY_FUNCTION_NAME:
5122 case RID_C99_FUNCTION_NAME:
5123 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5124 c_parser_peek_token (parser)->value);
5125 expr.original_code = ERROR_MARK;
5126 c_parser_consume_token (parser);
5129 c_parser_consume_token (parser);
5130 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5132 expr.value = error_mark_node;
5133 expr.original_code = ERROR_MARK;
5136 e1 = c_parser_expr_no_commas (parser, NULL);
5137 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5139 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5140 expr.value = error_mark_node;
5141 expr.original_code = ERROR_MARK;
5144 t1 = c_parser_type_name (parser);
5145 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5149 expr.value = error_mark_node;
5150 expr.original_code = ERROR_MARK;
5154 expr.value = build_va_arg (e1.value, groktypename (t1));
5155 expr.original_code = ERROR_MARK;
5159 c_parser_consume_token (parser);
5160 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5162 expr.value = error_mark_node;
5163 expr.original_code = ERROR_MARK;
5166 t1 = c_parser_type_name (parser);
5169 expr.value = error_mark_node;
5170 expr.original_code = ERROR_MARK;
5173 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5175 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5176 expr.value = error_mark_node;
5177 expr.original_code = ERROR_MARK;
5181 tree type = groktypename (t1);
5183 if (type == error_mark_node)
5184 offsetof_ref = error_mark_node;
5186 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5187 /* Parse the second argument to __builtin_offsetof. We
5188 must have one identifier, and beyond that we want to
5189 accept sub structure and sub array references. */
5190 if (c_parser_next_token_is (parser, CPP_NAME))
5192 offsetof_ref = build_component_ref
5193 (offsetof_ref, c_parser_peek_token (parser)->value);
5194 c_parser_consume_token (parser);
5195 while (c_parser_next_token_is (parser, CPP_DOT)
5196 || c_parser_next_token_is (parser,
5199 if (c_parser_next_token_is (parser, CPP_DOT))
5201 c_parser_consume_token (parser);
5202 if (c_parser_next_token_is_not (parser,
5205 c_parser_error (parser, "expected identifier");
5208 offsetof_ref = build_component_ref
5210 c_parser_peek_token (parser)->value);
5211 c_parser_consume_token (parser);
5216 c_parser_consume_token (parser);
5217 idx = c_parser_expression (parser).value;
5218 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5220 offsetof_ref = build_array_ref (offsetof_ref, idx);
5225 c_parser_error (parser, "expected identifier");
5226 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5228 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5229 expr.original_code = ERROR_MARK;
5232 case RID_CHOOSE_EXPR:
5233 c_parser_consume_token (parser);
5234 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5236 expr.value = error_mark_node;
5237 expr.original_code = ERROR_MARK;
5240 e1 = c_parser_expr_no_commas (parser, NULL);
5241 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5244 expr.value = error_mark_node;
5245 expr.original_code = ERROR_MARK;
5248 e2 = c_parser_expr_no_commas (parser, NULL);
5249 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5251 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5252 expr.value = error_mark_node;
5253 expr.original_code = ERROR_MARK;
5256 e3 = c_parser_expr_no_commas (parser, NULL);
5257 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5262 c = fold (e1.value);
5263 if (TREE_CODE (c) != INTEGER_CST)
5264 error ("first argument to %<__builtin_choose_expr%> not"
5266 expr = integer_zerop (c) ? e3 : e2;
5269 case RID_TYPES_COMPATIBLE_P:
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 t1 = c_parser_type_name (parser);
5280 expr.value = error_mark_node;
5281 expr.original_code = ERROR_MARK;
5284 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5286 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5287 expr.value = error_mark_node;
5288 expr.original_code = ERROR_MARK;
5291 t2 = c_parser_type_name (parser);
5294 expr.value = error_mark_node;
5295 expr.original_code = ERROR_MARK;
5298 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5303 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5304 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5306 expr.value = comptypes (e1, e2)
5307 ? build_int_cst (NULL_TREE, 1)
5308 : build_int_cst (NULL_TREE, 0);
5309 expr.original_code = ERROR_MARK;
5312 case RID_AT_SELECTOR:
5313 gcc_assert (c_dialect_objc ());
5314 c_parser_consume_token (parser);
5315 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5317 expr.value = error_mark_node;
5318 expr.original_code = ERROR_MARK;
5322 tree sel = c_parser_objc_selector_arg (parser);
5323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5325 expr.value = objc_build_selector_expr (sel);
5326 expr.original_code = ERROR_MARK;
5329 case RID_AT_PROTOCOL:
5330 gcc_assert (c_dialect_objc ());
5331 c_parser_consume_token (parser);
5332 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5334 expr.value = error_mark_node;
5335 expr.original_code = ERROR_MARK;
5338 if (c_parser_next_token_is_not (parser, CPP_NAME))
5340 c_parser_error (parser, "expected identifier");
5341 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5342 expr.value = error_mark_node;
5343 expr.original_code = ERROR_MARK;
5347 tree id = c_parser_peek_token (parser)->value;
5348 c_parser_consume_token (parser);
5349 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5351 expr.value = objc_build_protocol_expr (id);
5352 expr.original_code = ERROR_MARK;
5356 /* Extension to support C-structures in the archiver. */
5357 gcc_assert (c_dialect_objc ());
5358 c_parser_consume_token (parser);
5359 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5361 expr.value = error_mark_node;
5362 expr.original_code = ERROR_MARK;
5365 t1 = c_parser_type_name (parser);
5368 expr.value = error_mark_node;
5369 expr.original_code = ERROR_MARK;
5370 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5373 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5376 tree type = groktypename (t1);
5377 expr.value = objc_build_encode_expr (type);
5378 expr.original_code = ERROR_MARK;
5382 c_parser_error (parser, "expected expression");
5383 expr.value = error_mark_node;
5384 expr.original_code = ERROR_MARK;
5388 case CPP_OPEN_SQUARE:
5389 if (c_dialect_objc ())
5391 tree receiver, args;
5392 c_parser_consume_token (parser);
5393 receiver = c_parser_objc_receiver (parser);
5394 args = c_parser_objc_message_args (parser);
5395 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5397 expr.value = objc_build_message_expr (build_tree_list (receiver,
5399 expr.original_code = ERROR_MARK;
5402 /* Else fall through to report error. */
5404 c_parser_error (parser, "expected expression");
5405 expr.value = error_mark_node;
5406 expr.original_code = ERROR_MARK;
5409 return c_parser_postfix_expression_after_primary (parser, expr);
5412 /* Parse a postfix expression after a parenthesized type name: the
5413 brace-enclosed initializer of a compound literal, possibly followed
5414 by some postfix operators. This is separate because it is not
5415 possible to tell until after the type name whether a cast
5416 expression has a cast or a compound literal, or whether the operand
5417 of sizeof is a parenthesized type name or starts with a compound
5420 static struct c_expr
5421 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5422 struct c_type_name *type_name)
5427 start_init (NULL_TREE, NULL, 0);
5428 type = groktypename (type_name);
5429 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5431 error ("compound literal has variable size");
5432 type = error_mark_node;
5434 init = c_parser_braced_init (parser, type, false);
5436 maybe_warn_string_init (type, init);
5438 if (pedantic && !flag_isoc99)
5439 pedwarn ("ISO C90 forbids compound literals");
5440 expr.value = build_compound_literal (type, init.value);
5441 expr.original_code = ERROR_MARK;
5442 return c_parser_postfix_expression_after_primary (parser, expr);
5445 /* Parse a postfix expression after the initial primary or compound
5446 literal; that is, parse a series of postfix operators. */
5448 static struct c_expr
5449 c_parser_postfix_expression_after_primary (c_parser *parser,
5452 tree ident, idx, exprlist;
5455 switch (c_parser_peek_token (parser)->type)
5457 case CPP_OPEN_SQUARE:
5458 /* Array reference. */
5459 c_parser_consume_token (parser);
5460 idx = c_parser_expression (parser).value;
5461 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5463 expr.value = build_array_ref (expr.value, idx);
5464 expr.original_code = ERROR_MARK;
5466 case CPP_OPEN_PAREN:
5467 /* Function call. */
5468 c_parser_consume_token (parser);
5469 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5470 exprlist = NULL_TREE;
5472 exprlist = c_parser_expr_list (parser, true);
5473 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5475 expr.value = build_function_call (expr.value, exprlist);
5476 expr.original_code = ERROR_MARK;
5479 /* Structure element reference. */
5480 c_parser_consume_token (parser);
5481 expr = default_function_array_conversion (expr);
5482 if (c_parser_next_token_is (parser, CPP_NAME))
5483 ident = c_parser_peek_token (parser)->value;
5486 c_parser_error (parser, "expected identifier");
5487 expr.value = error_mark_node;
5488 expr.original_code = ERROR_MARK;
5491 c_parser_consume_token (parser);
5492 expr.value = build_component_ref (expr.value, ident);
5493 expr.original_code = ERROR_MARK;
5496 /* Structure element reference. */
5497 c_parser_consume_token (parser);
5498 expr = default_function_array_conversion (expr);
5499 if (c_parser_next_token_is (parser, CPP_NAME))
5500 ident = c_parser_peek_token (parser)->value;
5503 c_parser_error (parser, "expected identifier");
5504 expr.value = error_mark_node;
5505 expr.original_code = ERROR_MARK;
5508 c_parser_consume_token (parser);
5509 expr.value = build_component_ref (build_indirect_ref (expr.value,
5511 expr.original_code = ERROR_MARK;
5514 /* Postincrement. */
5515 c_parser_consume_token (parser);
5516 expr = default_function_array_conversion (expr);
5517 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5518 expr.original_code = ERROR_MARK;
5520 case CPP_MINUS_MINUS:
5521 /* Postdecrement. */
5522 c_parser_consume_token (parser);
5523 expr = default_function_array_conversion (expr);
5524 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5525 expr.original_code = ERROR_MARK;
5533 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5536 assignment-expression
5537 expression , assignment-expression
5540 static struct c_expr
5541 c_parser_expression (c_parser *parser)
5544 expr = c_parser_expr_no_commas (parser, NULL);
5545 while (c_parser_next_token_is (parser, CPP_COMMA))
5548 c_parser_consume_token (parser);
5549 next = c_parser_expr_no_commas (parser, NULL);
5550 next = default_function_array_conversion (next);
5551 expr.value = build_compound_expr (expr.value, next.value);
5552 expr.original_code = COMPOUND_EXPR;
5557 /* Parse an expression and convert functions or arrays to
5560 static struct c_expr
5561 c_parser_expression_conv (c_parser *parser)
5564 expr = c_parser_expression (parser);
5565 expr = default_function_array_conversion (expr);
5569 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5570 functions and arrays to pointers.
5573 assignment-expression
5574 nonempty-expr-list , assignment-expression
5578 c_parser_expr_list (c_parser *parser, bool convert_p)
5582 expr = c_parser_expr_no_commas (parser, NULL);
5584 expr = default_function_array_conversion (expr);
5585 ret = cur = build_tree_list (NULL_TREE, expr.value);
5586 while (c_parser_next_token_is (parser, CPP_COMMA))
5588 c_parser_consume_token (parser);
5589 expr = c_parser_expr_no_commas (parser, NULL);
5591 expr = default_function_array_conversion (expr);
5592 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5598 /* Parse Objective-C-specific constructs. */
5600 /* Parse an objc-class-definition.
5602 objc-class-definition:
5603 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5604 objc-class-instance-variables[opt] objc-methodprotolist @end
5605 @implementation identifier objc-superclass[opt]
5606 objc-class-instance-variables[opt]
5607 @interface identifier ( identifier ) objc-protocol-refs[opt]
5608 objc-methodprotolist @end
5609 @implementation identifier ( identifier )
5614 "@interface identifier (" must start "@interface identifier (
5615 identifier ) ...": objc-methodprotolist in the first production may
5616 not start with a parenthesized identifier as a declarator of a data
5617 definition with no declaration specifiers if the objc-superclass,
5618 objc-protocol-refs and objc-class-instance-variables are omitted. */
5621 c_parser_objc_class_definition (c_parser *parser)
5626 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5628 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5632 c_parser_consume_token (parser);
5633 if (c_parser_next_token_is_not (parser, CPP_NAME))
5635 c_parser_error (parser, "expected identifier");
5638 id1 = c_parser_peek_token (parser)->value;
5639 c_parser_consume_token (parser);
5640 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5643 tree proto = NULL_TREE;
5644 c_parser_consume_token (parser);
5645 if (c_parser_next_token_is_not (parser, CPP_NAME))
5647 c_parser_error (parser, "expected identifier");
5648 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5651 id2 = c_parser_peek_token (parser)->value;
5652 c_parser_consume_token (parser);
5653 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5656 objc_start_category_implementation (id1, id2);
5659 if (c_parser_next_token_is (parser, CPP_LESS))
5660 proto = c_parser_objc_protocol_refs (parser);
5661 objc_start_category_interface (id1, id2, proto);
5662 c_parser_objc_methodprotolist (parser);
5663 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5664 objc_finish_interface ();
5667 if (c_parser_next_token_is (parser, CPP_COLON))
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 superclass = c_parser_peek_token (parser)->value;
5676 c_parser_consume_token (parser);
5679 superclass = NULL_TREE;
5682 tree proto = NULL_TREE;
5683 if (c_parser_next_token_is (parser, CPP_LESS))
5684 proto = c_parser_objc_protocol_refs (parser);
5685 objc_start_class_interface (id1, superclass, proto);
5688 objc_start_class_implementation (id1, superclass);
5689 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5690 c_parser_objc_class_instance_variables (parser);
5693 objc_continue_interface ();
5694 c_parser_objc_methodprotolist (parser);
5695 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5696 objc_finish_interface ();
5700 objc_continue_implementation ();
5705 /* Parse objc-class-instance-variables.
5707 objc-class-instance-variables:
5708 { objc-instance-variable-decl-list[opt] }
5710 objc-instance-variable-decl-list:
5711 objc-visibility-spec
5712 objc-instance-variable-decl ;
5714 objc-instance-variable-decl-list objc-visibility-spec
5715 objc-instance-variable-decl-list objc-instance-variable-decl ;
5716 objc-instance-variable-decl-list ;
5718 objc-visibility-spec:
5723 objc-instance-variable-decl:
5728 c_parser_objc_class_instance_variables (c_parser *parser)
5730 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5731 c_parser_consume_token (parser);
5732 while (c_parser_next_token_is_not (parser, CPP_EOF))
5735 /* Parse any stray semicolon. */
5736 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5739 pedwarn ("extra semicolon in struct or union specified");
5740 c_parser_consume_token (parser);
5743 /* Stop if at the end of the instance variables. */
5744 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5746 c_parser_consume_token (parser);
5749 /* Parse any objc-visibility-spec. */
5750 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5752 c_parser_consume_token (parser);
5753 objc_set_visibility (2);
5756 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5758 c_parser_consume_token (parser);
5759 objc_set_visibility (0);
5762 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5764 c_parser_consume_token (parser);
5765 objc_set_visibility (1);
5768 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5770 c_parser_pragma (parser, pragma_external);
5774 /* Parse some comma-separated declarations. */
5775 decls = c_parser_struct_declaration (parser);
5777 /* Comma-separated instance variables are chained together in
5778 reverse order; add them one by one. */
5779 tree ivar = nreverse (decls);
5780 for (; ivar; ivar = TREE_CHAIN (ivar))
5781 objc_add_instance_variable (copy_node (ivar));
5783 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5787 /* Parse an objc-class-declaration.
5789 objc-class-declaration:
5790 @class identifier-list ;
5794 c_parser_objc_class_declaration (c_parser *parser)
5796 tree list = NULL_TREE;
5797 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5798 c_parser_consume_token (parser);
5799 /* Any identifiers, including those declared as type names, are OK
5804 if (c_parser_next_token_is_not (parser, CPP_NAME))
5806 c_parser_error (parser, "expected identifier");
5809 id = c_parser_peek_token (parser)->value;
5810 list = chainon (list, build_tree_list (NULL_TREE, id));
5811 c_parser_consume_token (parser);
5812 if (c_parser_next_token_is (parser, CPP_COMMA))
5813 c_parser_consume_token (parser);
5817 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5818 objc_declare_class (list);
5821 /* Parse an objc-alias-declaration.
5823 objc-alias-declaration:
5824 @compatibility_alias identifier identifier ;
5828 c_parser_objc_alias_declaration (c_parser *parser)
5831 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5832 c_parser_consume_token (parser);
5833 if (c_parser_next_token_is_not (parser, CPP_NAME))
5835 c_parser_error (parser, "expected identifier");
5836 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5839 id1 = c_parser_peek_token (parser)->value;
5840 c_parser_consume_token (parser);
5841 if (c_parser_next_token_is_not (parser, CPP_NAME))
5843 c_parser_error (parser, "expected identifier");
5844 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5847 id2 = c_parser_peek_token (parser)->value;
5848 c_parser_consume_token (parser);
5849 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5850 objc_declare_alias (id1, id2);
5853 /* Parse an objc-protocol-definition.
5855 objc-protocol-definition:
5856 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5857 @protocol identifier-list ;
5859 "@protocol identifier ;" should be resolved as "@protocol
5860 identifier-list ;": objc-methodprotolist may not start with a
5861 semicolon in the first alternative if objc-protocol-refs are
5865 c_parser_objc_protocol_definition (c_parser *parser)
5867 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5868 c_parser_consume_token (parser);
5869 if (c_parser_next_token_is_not (parser, CPP_NAME))
5871 c_parser_error (parser, "expected identifier");
5874 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5875 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5877 tree list = NULL_TREE;
5878 /* Any identifiers, including those declared as type names, are
5883 if (c_parser_next_token_is_not (parser, CPP_NAME))
5885 c_parser_error (parser, "expected identifier");
5888 id = c_parser_peek_token (parser)->value;
5889 list = chainon (list, build_tree_list (NULL_TREE, id));
5890 c_parser_consume_token (parser);
5891 if (c_parser_next_token_is (parser, CPP_COMMA))
5892 c_parser_consume_token (parser);
5896 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5897 objc_declare_protocols (list);
5901 tree id = c_parser_peek_token (parser)->value;
5902 tree proto = NULL_TREE;
5903 c_parser_consume_token (parser);
5904 if (c_parser_next_token_is (parser, CPP_LESS))
5905 proto = c_parser_objc_protocol_refs (parser);
5906 parser->objc_pq_context = true;
5907 objc_start_protocol (id, proto);
5908 c_parser_objc_methodprotolist (parser);
5909 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5910 parser->objc_pq_context = false;
5911 objc_finish_interface ();
5915 /* Parse an objc-method-type.
5922 static enum tree_code
5923 c_parser_objc_method_type (c_parser *parser)
5925 switch (c_parser_peek_token (parser)->type)
5928 c_parser_consume_token (parser);
5931 c_parser_consume_token (parser);
5938 /* Parse an objc-method-definition.
5940 objc-method-definition:
5941 objc-method-type objc-method-decl ;[opt] compound-statement
5945 c_parser_objc_method_definition (c_parser *parser)
5947 enum tree_code type = c_parser_objc_method_type (parser);
5949 objc_set_method_type (type);
5950 parser->objc_pq_context = true;
5951 decl = c_parser_objc_method_decl (parser);
5952 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5954 c_parser_consume_token (parser);
5956 pedwarn ("extra semicolon in method definition specified");
5958 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5960 c_parser_error (parser, "expected %<{%>");
5963 parser->objc_pq_context = false;
5964 objc_start_method_definition (decl);
5965 add_stmt (c_parser_compound_statement (parser));
5966 objc_finish_method_definition (current_function_decl);
5969 /* Parse an objc-methodprotolist.
5971 objc-methodprotolist:
5973 objc-methodprotolist objc-methodproto
5974 objc-methodprotolist declaration
5975 objc-methodprotolist ;
5977 The declaration is a data definition, which may be missing
5978 declaration specifiers under the same rules and diagnostics as
5979 other data definitions outside functions, and the stray semicolon
5980 is diagnosed the same way as a stray semicolon outside a
5984 c_parser_objc_methodprotolist (c_parser *parser)
5988 /* The list is terminated by @end. */
5989 switch (c_parser_peek_token (parser)->type)
5993 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5994 c_parser_consume_token (parser);
5998 c_parser_objc_methodproto (parser);
6001 c_parser_pragma (parser, pragma_external);
6006 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6008 c_parser_declaration_or_fndef (parser, false, true, false, true);
6014 /* Parse an objc-methodproto.
6017 objc-method-type objc-method-decl ;
6021 c_parser_objc_methodproto (c_parser *parser)
6023 enum tree_code type = c_parser_objc_method_type (parser);
6025 objc_set_method_type (type);
6026 /* Remember protocol qualifiers in prototypes. */
6027 parser->objc_pq_context = true;
6028 decl = c_parser_objc_method_decl (parser);
6029 /* Forget protocol qualifiers here. */
6030 parser->objc_pq_context = false;
6031 objc_add_method_declaration (decl);
6032 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6035 /* Parse an objc-method-decl.
6038 ( objc-type-name ) objc-selector
6040 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6041 objc-keyword-selector objc-optparmlist
6043 objc-keyword-selector:
6045 objc-keyword-selector objc-keyword-decl
6048 objc-selector : ( objc-type-name ) identifier
6049 objc-selector : identifier
6050 : ( objc-type-name ) identifier
6054 objc-optparms objc-optellipsis
6058 objc-opt-parms , parameter-declaration
6066 c_parser_objc_method_decl (c_parser *parser)
6068 tree type = NULL_TREE;
6070 tree parms = NULL_TREE;
6071 bool ellipsis = false;
6073 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6075 c_parser_consume_token (parser);
6076 type = c_parser_objc_type_name (parser);
6077 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6079 sel = c_parser_objc_selector (parser);
6080 /* If there is no selector, or a colon follows, we have an
6081 objc-keyword-selector. If there is a selector, and a colon does
6082 not follow, that selector ends the objc-method-decl. */
6083 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6086 tree list = NULL_TREE;
6089 tree atype = NULL_TREE, id, keyworddecl;
6090 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6092 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6094 c_parser_consume_token (parser);
6095 atype = c_parser_objc_type_name (parser);
6096 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6099 if (c_parser_next_token_is_not (parser, CPP_NAME))
6101 c_parser_error (parser, "expected identifier");
6102 return error_mark_node;
6104 id = c_parser_peek_token (parser)->value;
6105 c_parser_consume_token (parser);
6106 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6107 list = chainon (list, keyworddecl);
6108 tsel = c_parser_objc_selector (parser);
6109 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6112 /* Parse the optional parameter list. Optional Objective-C
6113 method parameters follow the C syntax, and may include '...'
6114 to denote a variable number of arguments. */
6115 parms = make_node (TREE_LIST);
6116 while (c_parser_next_token_is (parser, CPP_COMMA))
6118 struct c_parm *parm;
6119 c_parser_consume_token (parser);
6120 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6123 c_parser_consume_token (parser);
6126 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6129 parms = chainon (parms,
6130 build_tree_list (NULL_TREE, grokparm (parm)));
6134 return objc_build_method_signature (type, sel, parms, ellipsis);
6137 /* Parse an objc-type-name.
6140 objc-type-qualifiers[opt] type-name
6141 objc-type-qualifiers[opt]
6143 objc-type-qualifiers:
6145 objc-type-qualifiers objc-type-qualifier
6147 objc-type-qualifier: one of
6148 in out inout bycopy byref oneway
6152 c_parser_objc_type_name (c_parser *parser)
6154 tree quals = NULL_TREE;
6155 struct c_type_name *typename = NULL;
6156 tree type = NULL_TREE;
6159 c_token *token = c_parser_peek_token (parser);
6160 if (token->type == CPP_KEYWORD
6161 && (token->keyword == RID_IN
6162 || token->keyword == RID_OUT
6163 || token->keyword == RID_INOUT
6164 || token->keyword == RID_BYCOPY
6165 || token->keyword == RID_BYREF
6166 || token->keyword == RID_ONEWAY))
6168 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6169 c_parser_consume_token (parser);
6174 if (c_parser_next_token_starts_typename (parser))
6175 typename = c_parser_type_name (parser);
6177 type = groktypename (typename);
6178 return build_tree_list (quals, type);
6181 /* Parse objc-protocol-refs.
6188 c_parser_objc_protocol_refs (c_parser *parser)
6190 tree list = NULL_TREE;
6191 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6192 c_parser_consume_token (parser);
6193 /* Any identifiers, including those declared as type names, are OK
6198 if (c_parser_next_token_is_not (parser, CPP_NAME))
6200 c_parser_error (parser, "expected identifier");
6203 id = c_parser_peek_token (parser)->value;
6204 list = chainon (list, build_tree_list (NULL_TREE, id));
6205 c_parser_consume_token (parser);
6206 if (c_parser_next_token_is (parser, CPP_COMMA))
6207 c_parser_consume_token (parser);
6211 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6215 /* Parse an objc-try-catch-statement.
6217 objc-try-catch-statement:
6218 @try compound-statement objc-catch-list[opt]
6219 @try compound-statement objc-catch-list[opt] @finally compound-statement
6222 @catch ( parameter-declaration ) compound-statement
6223 objc-catch-list @catch ( parameter-declaration ) compound-statement
6227 c_parser_objc_try_catch_statement (c_parser *parser)
6231 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6232 c_parser_consume_token (parser);
6233 loc = c_parser_peek_token (parser)->location;
6234 stmt = c_parser_compound_statement (parser);
6235 objc_begin_try_stmt (loc, stmt);
6236 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6238 struct c_parm *parm;
6239 c_parser_consume_token (parser);
6240 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6242 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6245 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6248 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6249 objc_begin_catch_clause (grokparm (parm));
6250 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6251 c_parser_compound_statement_nostart (parser);
6252 objc_finish_catch_clause ();
6254 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6258 c_parser_consume_token (parser);
6259 finloc = c_parser_peek_token (parser)->location;
6260 finstmt = c_parser_compound_statement (parser);
6261 objc_build_finally_clause (finloc, finstmt);
6263 objc_finish_try_stmt ();
6266 /* Parse an objc-synchronized-statement.
6268 objc-synchronized-statement:
6269 @synchronized ( expression ) compound-statement
6273 c_parser_objc_synchronized_statement (c_parser *parser)
6277 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6278 c_parser_consume_token (parser);
6279 loc = c_parser_peek_token (parser)->location;
6280 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6282 expr = c_parser_expression (parser).value;
6283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6286 expr = error_mark_node;
6287 stmt = c_parser_compound_statement (parser);
6288 objc_build_synchronized (loc, expr, stmt);
6291 /* Parse an objc-selector; return NULL_TREE without an error if the
6292 next token is not an objc-selector.
6297 enum struct union if else while do for switch case default
6298 break continue return goto asm sizeof typeof __alignof
6299 unsigned long const short volatile signed restrict _Complex
6300 in out inout bycopy byref oneway int char float double void _Bool
6302 ??? Why this selection of keywords but not, for example, storage
6303 class specifiers? */
6306 c_parser_objc_selector (c_parser *parser)
6308 c_token *token = c_parser_peek_token (parser);
6309 tree value = token->value;
6310 if (token->type == CPP_NAME)
6312 c_parser_consume_token (parser);
6315 if (token->type != CPP_KEYWORD)
6317 switch (token->keyword)
6358 c_parser_consume_token (parser);
6365 /* Parse an objc-selector-arg.
6369 objc-keywordname-list
6371 objc-keywordname-list:
6373 objc-keywordname-list objc-keywordname
6381 c_parser_objc_selector_arg (c_parser *parser)
6383 tree sel = c_parser_objc_selector (parser);
6384 tree list = NULL_TREE;
6385 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6389 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6391 list = chainon (list, build_tree_list (sel, NULL_TREE));
6392 sel = c_parser_objc_selector (parser);
6393 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6399 /* Parse an objc-receiver.
6408 c_parser_objc_receiver (c_parser *parser)
6410 if (c_parser_peek_token (parser)->type == CPP_NAME
6411 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6412 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6414 tree id = c_parser_peek_token (parser)->value;
6415 c_parser_consume_token (parser);
6416 return objc_get_class_reference (id);
6418 return c_parser_expression (parser).value;
6421 /* Parse objc-message-args.
6425 objc-keywordarg-list
6427 objc-keywordarg-list:
6429 objc-keywordarg-list objc-keywordarg
6432 objc-selector : objc-keywordexpr
6437 c_parser_objc_message_args (c_parser *parser)
6439 tree sel = c_parser_objc_selector (parser);
6440 tree list = NULL_TREE;
6441 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6446 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6448 keywordexpr = c_parser_objc_keywordexpr (parser);
6449 list = chainon (list, build_tree_list (sel, keywordexpr));
6450 sel = c_parser_objc_selector (parser);
6451 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6457 /* Parse an objc-keywordexpr.
6464 c_parser_objc_keywordexpr (c_parser *parser)
6466 tree list = c_parser_expr_list (parser, true);
6467 if (TREE_CHAIN (list) == NULL_TREE)
6469 /* Just return the expression, remove a level of
6471 return TREE_VALUE (list);
6475 /* We have a comma expression, we will collapse later. */
6481 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6482 should be considered, statements. ALLOW_STMT is true if we're within
6483 the context of a function and such pragmas are to be allowed. Returns
6484 true if we actually parsed such a pragma. */
6487 c_parser_pragma (c_parser *parser, enum pragma_context context)
6491 id = c_parser_peek_token (parser)->pragma_kind;
6492 gcc_assert (id != PRAGMA_NONE);
6496 case PRAGMA_OMP_BARRIER:
6497 if (context != pragma_compound)
6499 if (context == pragma_stmt)
6500 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6501 "used in compound statements");
6504 c_parser_omp_barrier (parser);
6507 case PRAGMA_OMP_FLUSH:
6508 if (context != pragma_compound)
6510 if (context == pragma_stmt)
6511 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6512 "used in compound statements");
6515 c_parser_omp_flush (parser);
6518 case PRAGMA_OMP_THREADPRIVATE:
6519 c_parser_omp_threadprivate (parser);
6522 case PRAGMA_OMP_SECTION:
6523 error ("%<#pragma omp section%> may only be used in "
6524 "%<#pragma omp sections%> construct");
6525 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6528 case PRAGMA_GCC_PCH_PREPROCESS:
6529 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6530 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6534 if (id < PRAGMA_FIRST_EXTERNAL)
6536 if (context == pragma_external)
6539 c_parser_error (parser, "expected declaration specifiers");
6540 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6543 c_parser_omp_construct (parser);
6549 c_parser_consume_pragma (parser);
6550 c_invoke_pragma_handler (id);
6552 /* Skip to EOL, but suppress any error message. Those will have been
6553 generated by the handler routine through calling error, as opposed
6554 to calling c_parser_error. */
6555 parser->error = true;
6556 c_parser_skip_to_pragma_eol (parser);
6561 /* The interface the pragma parsers have to the lexer. */
6564 pragma_lex (tree *value)
6566 c_token *tok = c_parser_peek_token (the_parser);
6567 enum cpp_ttype ret = tok->type;
6569 *value = tok->value;
6570 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6574 if (ret == CPP_KEYWORD)
6576 c_parser_consume_token (the_parser);
6583 c_parser_pragma_pch_preprocess (c_parser *parser)
6587 c_parser_consume_pragma (parser);
6588 if (c_parser_next_token_is (parser, CPP_STRING))
6590 name = c_parser_peek_token (parser)->value;
6591 c_parser_consume_token (parser);
6594 c_parser_error (parser, "expected string literal");
6595 c_parser_skip_to_pragma_eol (parser);
6598 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6601 /* OpenMP 2.5 parsing routines. */
6603 /* Returns name of the next clause.
6604 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6605 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6606 returned and the token is consumed. */
6608 static pragma_omp_clause
6609 c_parser_omp_clause_name (c_parser *parser)
6611 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6613 if (c_parser_next_token_is_keyword (parser, RID_IF))
6614 result = PRAGMA_OMP_CLAUSE_IF;
6615 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6616 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6617 else if (c_parser_next_token_is (parser, CPP_NAME))
6619 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6624 if (!strcmp ("copyin", p))
6625 result = PRAGMA_OMP_CLAUSE_COPYIN;
6626 else if (!strcmp ("copyprivate", p))
6627 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6630 if (!strcmp ("firstprivate", p))
6631 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6634 if (!strcmp ("lastprivate", p))
6635 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6638 if (!strcmp ("nowait", p))
6639 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6640 else if (!strcmp ("num_threads", p))
6641 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6644 if (!strcmp ("ordered", p))
6645 result = PRAGMA_OMP_CLAUSE_ORDERED;
6648 if (!strcmp ("private", p))
6649 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6652 if (!strcmp ("reduction", p))
6653 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6656 if (!strcmp ("schedule", p))
6657 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6658 else if (!strcmp ("shared", p))
6659 result = PRAGMA_OMP_CLAUSE_SHARED;
6664 if (result != PRAGMA_OMP_CLAUSE_NONE)
6665 c_parser_consume_token (parser);
6670 /* Validate that a clause of the given type does not already exist. */
6673 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6677 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6678 if (OMP_CLAUSE_CODE (c) == code)
6680 error ("too many %qs clauses", name);
6688 variable-list , identifier
6690 If KIND is nonzero, create the appropriate node and install the decl
6691 in OMP_CLAUSE_DECL and add the node to the head of the list.
6693 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6694 return the list created. */
6697 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6700 if (c_parser_next_token_is_not (parser, CPP_NAME)
6701 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6702 c_parser_error (parser, "expected identifier");
6704 while (c_parser_next_token_is (parser, CPP_NAME)
6705 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6707 tree t = lookup_name (c_parser_peek_token (parser)->value);
6710 undeclared_variable (c_parser_peek_token (parser)->value,
6711 c_parser_peek_token (parser)->location);
6712 else if (t == error_mark_node)
6716 tree u = build_omp_clause (kind);
6717 OMP_CLAUSE_DECL (u) = t;
6718 OMP_CLAUSE_CHAIN (u) = list;
6722 list = tree_cons (t, NULL_TREE, list);
6724 c_parser_consume_token (parser);
6726 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6729 c_parser_consume_token (parser);
6735 /* Similarly, but expect leading and trailing parenthesis. This is a very
6736 common case for omp clauses. */
6739 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6741 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6743 list = c_parser_omp_variable_list (parser, kind, list);
6744 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6750 copyin ( variable-list ) */
6753 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6755 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6759 copyprivate ( variable-list ) */
6762 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6764 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6768 default ( shared | none ) */
6771 c_parser_omp_clause_default (c_parser *parser, tree list)
6773 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6776 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6778 if (c_parser_next_token_is (parser, CPP_NAME))
6780 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6785 if (strcmp ("none", p) != 0)
6787 kind = OMP_CLAUSE_DEFAULT_NONE;
6791 if (strcmp ("shared", p) != 0)
6793 kind = OMP_CLAUSE_DEFAULT_SHARED;
6800 c_parser_consume_token (parser);
6805 c_parser_error (parser, "expected %<none%> or %<shared%>");
6807 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6809 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6812 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6813 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6814 OMP_CLAUSE_CHAIN (c) = list;
6815 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6821 firstprivate ( variable-list ) */
6824 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6826 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6830 if ( expression ) */
6833 c_parser_omp_clause_if (c_parser *parser, tree list)
6835 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6837 tree t = c_parser_paren_condition (parser);
6840 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6842 c = build_omp_clause (OMP_CLAUSE_IF);
6843 OMP_CLAUSE_IF_EXPR (c) = t;
6844 OMP_CLAUSE_CHAIN (c) = list;
6848 c_parser_error (parser, "expected %<(%>");
6854 lastprivate ( variable-list ) */
6857 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6859 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6866 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6870 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6872 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6873 OMP_CLAUSE_CHAIN (c) = list;
6878 num_threads ( expression ) */
6881 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6883 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6885 tree c, t = c_parser_expression (parser).value;
6887 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6889 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6891 c_parser_error (parser, "expected integer expression");
6895 /* Attempt to statically determine when the number isn't positive. */
6896 c = fold_build2 (LE_EXPR, boolean_type_node, t,
6897 build_int_cst (TREE_TYPE (t), 0));
6898 if (c == boolean_true_node)
6900 warning (0, "%<num_threads%> value must be positive");
6901 t = integer_one_node;
6904 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
6906 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
6907 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
6908 OMP_CLAUSE_CHAIN (c) = list;
6919 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6923 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
6925 c = build_omp_clause (OMP_CLAUSE_ORDERED);
6926 OMP_CLAUSE_CHAIN (c) = list;
6931 private ( variable-list ) */
6934 c_parser_omp_clause_private (c_parser *parser, tree list)
6936 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
6940 reduction ( reduction-operator : variable-list )
6943 One of: + * - & ^ | && || */
6946 c_parser_omp_clause_reduction (c_parser *parser, tree list)
6948 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6950 enum tree_code code;
6952 switch (c_parser_peek_token (parser)->type)
6964 code = BIT_AND_EXPR;
6967 code = BIT_XOR_EXPR;
6970 code = BIT_IOR_EXPR;
6973 code = TRUTH_ANDIF_EXPR;
6976 code = TRUTH_ORIF_EXPR;
6979 c_parser_error (parser,
6980 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
6981 "%<^%>, %<|%>, %<&&%>, or %<||%>");
6982 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
6985 c_parser_consume_token (parser);
6986 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6990 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
6991 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
6992 OMP_CLAUSE_REDUCTION_CODE (c) = code;
6996 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7002 schedule ( schedule-kind )
7003 schedule ( schedule-kind , expression )
7006 static | dynamic | guided | runtime
7010 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7014 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7017 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7019 if (c_parser_next_token_is (parser, CPP_NAME))
7021 tree kind = c_parser_peek_token (parser)->value;
7022 const char *p = IDENTIFIER_POINTER (kind);
7027 if (strcmp ("dynamic", p) != 0)
7029 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7033 if (strcmp ("guided", p) != 0)
7035 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7039 if (strcmp ("runtime", p) != 0)
7041 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7048 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7049 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7053 c_parser_consume_token (parser);
7054 if (c_parser_next_token_is (parser, CPP_COMMA))
7056 c_parser_consume_token (parser);
7058 t = c_parser_expr_no_commas (parser, NULL).value;
7060 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7061 error ("schedule %<runtime%> does not take "
7062 "a %<chunk_size%> parameter");
7063 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7064 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7066 c_parser_error (parser, "expected integer expression");
7068 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7071 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7072 "expected %<,%> or %<)%>");
7074 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7075 OMP_CLAUSE_CHAIN (c) = list;
7079 c_parser_error (parser, "invalid schedule kind");
7080 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7085 shared ( variable-list ) */
7088 c_parser_omp_clause_shared (c_parser *parser, tree list)
7090 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7093 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7094 is a bitmask in MASK. Return the list of clauses found; the result
7095 of clause default goes in *pdefault. */
7098 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7101 tree clauses = NULL;
7103 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7105 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7107 tree prev = clauses;
7111 case PRAGMA_OMP_CLAUSE_COPYIN:
7112 clauses = c_parser_omp_clause_copyin (parser, clauses);
7115 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7116 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7117 c_name = "copyprivate";
7119 case PRAGMA_OMP_CLAUSE_DEFAULT:
7120 clauses = c_parser_omp_clause_default (parser, clauses);
7123 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7124 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7125 c_name = "firstprivate";
7127 case PRAGMA_OMP_CLAUSE_IF:
7128 clauses = c_parser_omp_clause_if (parser, clauses);
7131 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7132 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7133 c_name = "lastprivate";
7135 case PRAGMA_OMP_CLAUSE_NOWAIT:
7136 clauses = c_parser_omp_clause_nowait (parser, clauses);
7139 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7140 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7141 c_name = "num_threads";
7143 case PRAGMA_OMP_CLAUSE_ORDERED:
7144 clauses = c_parser_omp_clause_ordered (parser, clauses);
7147 case PRAGMA_OMP_CLAUSE_PRIVATE:
7148 clauses = c_parser_omp_clause_private (parser, clauses);
7151 case PRAGMA_OMP_CLAUSE_REDUCTION:
7152 clauses = c_parser_omp_clause_reduction (parser, clauses);
7153 c_name = "reduction";
7155 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7156 clauses = c_parser_omp_clause_schedule (parser, clauses);
7157 c_name = "schedule";
7159 case PRAGMA_OMP_CLAUSE_SHARED:
7160 clauses = c_parser_omp_clause_shared (parser, clauses);
7164 c_parser_error (parser, "expected %<#pragma omp%> clause");
7168 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7170 /* Remove the invalid clause(s) from the list to avoid
7171 confusing the rest of the compiler. */
7173 error ("%qs is not valid for %qs", c_name, where);
7178 c_parser_skip_to_pragma_eol (parser);
7180 return c_finish_omp_clauses (clauses);
7187 In practice, we're also interested in adding the statement to an
7188 outer node. So it is convenient if we work around the fact that
7189 c_parser_statement calls add_stmt. */
7192 c_parser_omp_structured_block (c_parser *parser)
7194 tree stmt = push_stmt_list ();
7195 c_parser_statement (parser);
7196 return pop_stmt_list (stmt);
7200 # pragma omp atomic new-line
7204 x binop= expr | x++ | ++x | x-- | --x
7206 +, *, -, /, &, ^, |, <<, >>
7208 where x is an lvalue expression with scalar type. */
7211 c_parser_omp_atomic (c_parser *parser)
7215 enum tree_code code;
7217 c_parser_skip_to_pragma_eol (parser);
7219 lhs = c_parser_unary_expression (parser).value;
7220 switch (TREE_CODE (lhs))
7224 c_parser_skip_to_end_of_block_or_statement (parser);
7227 case PREINCREMENT_EXPR:
7228 case POSTINCREMENT_EXPR:
7229 lhs = TREE_OPERAND (lhs, 0);
7231 rhs = integer_one_node;
7234 case PREDECREMENT_EXPR:
7235 case POSTDECREMENT_EXPR:
7236 lhs = TREE_OPERAND (lhs, 0);
7238 rhs = integer_one_node;
7242 switch (c_parser_peek_token (parser)->type)
7248 code = TRUNC_DIV_EXPR;
7263 code = BIT_AND_EXPR;
7266 code = BIT_IOR_EXPR;
7269 code = BIT_XOR_EXPR;
7272 c_parser_error (parser,
7273 "invalid operator for %<#pragma omp atomic%>");
7277 c_parser_consume_token (parser);
7278 rhs = c_parser_expression (parser).value;
7281 stmt = c_finish_omp_atomic (code, lhs, rhs);
7282 if (stmt != error_mark_node)
7284 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7289 # pragma omp barrier new-line
7293 c_parser_omp_barrier (c_parser *parser)
7295 c_parser_consume_pragma (parser);
7296 c_parser_skip_to_pragma_eol (parser);
7298 c_finish_omp_barrier ();
7302 # pragma omp critical [(name)] new-line
7307 c_parser_omp_critical (c_parser *parser)
7309 tree stmt, name = NULL;
7311 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7313 c_parser_consume_token (parser);
7314 if (c_parser_next_token_is (parser, CPP_NAME))
7316 name = c_parser_peek_token (parser)->value;
7317 c_parser_consume_token (parser);
7318 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7321 c_parser_error (parser, "expected identifier");
7323 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7324 c_parser_error (parser, "expected %<(%> or end of line");
7325 c_parser_skip_to_pragma_eol (parser);
7327 stmt = c_parser_omp_structured_block (parser);
7328 return c_finish_omp_critical (stmt, name);
7332 # pragma omp flush flush-vars[opt] new-line
7335 ( variable-list ) */
7338 c_parser_omp_flush (c_parser *parser)
7340 c_parser_consume_pragma (parser);
7341 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7342 c_parser_omp_var_list_parens (parser, 0, NULL);
7343 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7344 c_parser_error (parser, "expected %<(%> or end of line");
7345 c_parser_skip_to_pragma_eol (parser);
7347 c_finish_omp_flush ();
7350 /* Parse the restricted form of the for statment allowed by OpenMP.
7351 The real trick here is to determine the loop control variable early
7352 so that we can push a new decl if necessary to make it private. */
7355 c_parser_omp_for_loop (c_parser *parser)
7357 tree decl, cond, incr, save_break, save_cont, body, init;
7360 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7362 c_parser_error (parser, "for statement expected");
7365 loc = c_parser_peek_token (parser)->location;
7366 c_parser_consume_token (parser);
7368 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7371 /* Parse the initialization declaration or expression. */
7372 if (c_parser_next_token_starts_declspecs (parser))
7374 c_parser_declaration_or_fndef (parser, true, true, true, true);
7375 decl = check_for_loop_decls ();
7380 else if (c_parser_next_token_is (parser, CPP_NAME)
7381 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7383 decl = c_parser_postfix_expression (parser).value;
7385 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7387 init = c_parser_expr_no_commas (parser, NULL).value;
7388 init = build_modify_expr (decl, NOP_EXPR, init);
7389 init = c_process_expr_stmt (init);
7391 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7396 /* Parse the loop condition. */
7398 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7400 cond = c_parser_expression_conv (parser).value;
7401 cond = c_objc_common_truthvalue_conversion (cond);
7402 if (CAN_HAVE_LOCATION_P (cond))
7403 SET_EXPR_LOCATION (cond, input_location);
7405 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7407 /* Parse the increment expression. */
7409 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7410 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7411 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7414 save_break = c_break_label;
7415 c_break_label = size_one_node;
7416 save_cont = c_cont_label;
7417 c_cont_label = NULL_TREE;
7418 body = push_stmt_list ();
7420 add_stmt (c_parser_c99_block_statement (parser));
7422 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7424 body = pop_stmt_list (body);
7425 c_break_label = save_break;
7426 c_cont_label = save_cont;
7428 /* Only bother calling c_finish_omp_for if we havn't already generated
7429 an error from the initialization parsing. */
7430 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7431 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7435 c_parser_error (parser, "expected iteration declaration or initialization");
7436 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7437 decl = init = cond = incr = NULL_TREE;
7442 #pragma omp for for-clause[optseq] new-line
7446 #define OMP_FOR_CLAUSE_MASK \
7447 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7448 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7449 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7450 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7451 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7452 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7453 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7456 c_parser_omp_for (c_parser *parser)
7458 tree block, clauses, ret;
7460 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7463 block = c_begin_compound_stmt (true);
7464 ret = c_parser_omp_for_loop (parser);
7466 OMP_FOR_CLAUSES (ret) = clauses;
7467 block = c_end_compound_stmt (block, true);
7474 # pragma omp master new-line
7479 c_parser_omp_master (c_parser *parser)
7481 c_parser_skip_to_pragma_eol (parser);
7482 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7486 # pragma omp ordered new-line
7491 c_parser_omp_ordered (c_parser *parser)
7493 c_parser_skip_to_pragma_eol (parser);
7494 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7500 { section-sequence }
7503 section-directive[opt] structured-block
7504 section-sequence section-directive structured-block */
7507 c_parser_omp_sections_scope (c_parser *parser)
7510 bool error_suppress = false;
7513 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7515 /* Avoid skipping until the end of the block. */
7516 parser->error = false;
7520 stmt = push_stmt_list ();
7522 loc = c_parser_peek_token (parser)->location;
7523 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7525 substmt = push_stmt_list ();
7529 c_parser_statement (parser);
7531 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7533 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7535 if (c_parser_next_token_is (parser, CPP_EOF))
7539 substmt = pop_stmt_list (substmt);
7540 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7541 SET_EXPR_LOCATION (substmt, loc);
7547 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7549 if (c_parser_next_token_is (parser, CPP_EOF))
7552 loc = c_parser_peek_token (parser)->location;
7553 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7555 c_parser_consume_pragma (parser);
7556 c_parser_skip_to_pragma_eol (parser);
7557 error_suppress = false;
7559 else if (!error_suppress)
7561 error ("expected %<#pragma omp section%> or %<}%>");
7562 error_suppress = true;
7565 substmt = c_parser_omp_structured_block (parser);
7566 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7567 SET_EXPR_LOCATION (substmt, loc);
7570 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7571 "expected %<#pragma omp section%> or %<}%>");
7573 substmt = pop_stmt_list (stmt);
7575 stmt = make_node (OMP_SECTIONS);
7576 TREE_TYPE (stmt) = void_type_node;
7577 OMP_SECTIONS_BODY (stmt) = substmt;
7579 return add_stmt (stmt);
7583 # pragma omp sections sections-clause[optseq] newline
7587 #define OMP_SECTIONS_CLAUSE_MASK \
7588 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7589 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7590 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7591 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7592 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7595 c_parser_omp_sections (c_parser *parser)
7597 tree block, clauses, ret;
7599 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7600 "#pragma omp sections");
7602 block = c_begin_compound_stmt (true);
7603 ret = c_parser_omp_sections_scope (parser);
7605 OMP_SECTIONS_CLAUSES (ret) = clauses;
7606 block = c_end_compound_stmt (block, true);
7613 # pragma parallel parallel-clause new-line
7614 # pragma parallel for parallel-for-clause new-line
7615 # pragma parallel sections parallel-sections-clause new-line
7618 #define OMP_PARALLEL_CLAUSE_MASK \
7619 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7620 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7621 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7622 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7623 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7624 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7625 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7626 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7629 c_parser_omp_parallel (c_parser *parser)
7631 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7632 const char *p_name = "#pragma omp parallel";
7633 tree stmt, clauses, par_clause, ws_clause, block;
7634 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7636 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7638 c_parser_consume_token (parser);
7639 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7640 p_name = "#pragma omp parallel for";
7641 mask |= OMP_FOR_CLAUSE_MASK;
7642 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7644 else if (c_parser_next_token_is (parser, CPP_NAME))
7646 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7647 if (strcmp (p, "sections") == 0)
7649 c_parser_consume_token (parser);
7650 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7651 p_name = "#pragma omp parallel sections";
7652 mask |= OMP_SECTIONS_CLAUSE_MASK;
7653 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7657 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7661 case PRAGMA_OMP_PARALLEL:
7662 block = c_begin_omp_parallel ();
7663 c_parser_statement (parser);
7664 stmt = c_finish_omp_parallel (clauses, block);
7667 case PRAGMA_OMP_PARALLEL_FOR:
7668 block = c_begin_omp_parallel ();
7669 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7670 stmt = c_parser_omp_for_loop (parser);
7672 OMP_FOR_CLAUSES (stmt) = ws_clause;
7673 stmt = c_finish_omp_parallel (par_clause, block);
7674 OMP_PARALLEL_COMBINED (stmt) = 1;
7677 case PRAGMA_OMP_PARALLEL_SECTIONS:
7678 block = c_begin_omp_parallel ();
7679 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7680 stmt = c_parser_omp_sections_scope (parser);
7682 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7683 stmt = c_finish_omp_parallel (par_clause, block);
7684 OMP_PARALLEL_COMBINED (stmt) = 1;
7695 # pragma omp single single-clause[optseq] new-line
7699 #define OMP_SINGLE_CLAUSE_MASK \
7700 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7701 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7702 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7703 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7706 c_parser_omp_single (c_parser *parser)
7708 tree stmt = make_node (OMP_SINGLE);
7709 TREE_TYPE (stmt) = void_type_node;
7711 OMP_SINGLE_CLAUSES (stmt)
7712 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7713 "#pragma omp single");
7714 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7716 return add_stmt (stmt);
7720 /* Main entry point to parsing most OpenMP pragmas. */
7723 c_parser_omp_construct (c_parser *parser)
7725 enum pragma_kind p_kind;
7729 loc = c_parser_peek_token (parser)->location;
7730 p_kind = c_parser_peek_token (parser)->pragma_kind;
7731 c_parser_consume_pragma (parser);
7733 /* For all constructs below except #pragma omp atomic
7734 MUST_NOT_THROW catch handlers are needed when exceptions
7736 if (p_kind != PRAGMA_OMP_ATOMIC)
7737 c_maybe_initialize_eh ();
7741 case PRAGMA_OMP_ATOMIC:
7742 c_parser_omp_atomic (parser);
7744 case PRAGMA_OMP_CRITICAL:
7745 stmt = c_parser_omp_critical (parser);
7747 case PRAGMA_OMP_FOR:
7748 stmt = c_parser_omp_for (parser);
7750 case PRAGMA_OMP_MASTER:
7751 stmt = c_parser_omp_master (parser);
7753 case PRAGMA_OMP_ORDERED:
7754 stmt = c_parser_omp_ordered (parser);
7756 case PRAGMA_OMP_PARALLEL:
7757 stmt = c_parser_omp_parallel (parser);
7759 case PRAGMA_OMP_SECTIONS:
7760 stmt = c_parser_omp_sections (parser);
7762 case PRAGMA_OMP_SINGLE:
7763 stmt = c_parser_omp_single (parser);
7770 SET_EXPR_LOCATION (stmt, loc);
7775 # pragma omp threadprivate (variable-list) */
7778 c_parser_omp_threadprivate (c_parser *parser)
7782 c_parser_consume_pragma (parser);
7783 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7785 /* Mark every variable in VARS to be assigned thread local storage. */
7786 for (t = vars; t; t = TREE_CHAIN (t))
7788 tree v = TREE_PURPOSE (t);
7790 /* If V had already been marked threadprivate, it doesn't matter
7791 whether it had been used prior to this point. */
7792 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7793 error ("%qE declared %<threadprivate%> after first use", v);
7794 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7795 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7796 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7797 error ("%<threadprivate%> %qE has incomplete type", v);
7800 if (! DECL_THREAD_LOCAL_P (v))
7802 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7803 /* If rtl has been already set for this var, call
7804 make_decl_rtl once again, so that encode_section_info
7805 has a chance to look at the new decl flags. */
7806 if (DECL_RTL_SET_P (v))
7809 C_DECL_THREADPRIVATE_P (v) = 1;
7813 c_parser_skip_to_pragma_eol (parser);
7817 /* Parse a single source file. */
7822 /* Use local storage to begin. If the first token is a pragma, parse it.
7823 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7824 which will cause garbage collection. */
7827 memset (&tparser, 0, sizeof tparser);
7828 the_parser = &tparser;
7830 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7831 c_parser_pragma_pch_preprocess (&tparser);
7833 the_parser = GGC_NEW (c_parser);
7834 *the_parser = tparser;
7836 c_parser_translation_unit (the_parser);
7840 #include "gt-c-parser.h"