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 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 2, 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 COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
62 /* Miscellaneous data and functions needed for the parser. */
66 /* Objective-C specific parser/lexer information. */
68 static int objc_pq_context = 0;
70 /* The following flag is needed to contextualize Objective-C lexical
71 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
72 to bind an identifier to an Objective-C class, even if a class with
74 static int objc_need_raw_identifier = 0;
75 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
77 if (c_dialect_objc ()) \
78 objc_need_raw_identifier = VAL; \
81 /* The reserved keyword table. */
85 ENUM_BITFIELD(rid) rid : 16;
86 unsigned int disable : 16;
89 /* Disable mask. Keywords are disabled if (reswords[i].disable &
91 #define D_C89 0x01 /* not in C89 */
92 #define D_EXT 0x02 /* GCC extension */
93 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
94 #define D_OBJC 0x08 /* Objective C only */
96 static const struct resword reswords[] =
98 { "_Bool", RID_BOOL, 0 },
99 { "_Complex", RID_COMPLEX, 0 },
100 { "_Decimal32", RID_DFLOAT32, D_EXT },
101 { "_Decimal64", RID_DFLOAT64, D_EXT },
102 { "_Decimal128", RID_DFLOAT128, D_EXT },
103 { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
104 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
105 { "__alignof", RID_ALIGNOF, 0 },
106 { "__alignof__", RID_ALIGNOF, 0 },
107 { "__asm", RID_ASM, 0 },
108 { "__asm__", RID_ASM, 0 },
109 { "__attribute", RID_ATTRIBUTE, 0 },
110 { "__attribute__", RID_ATTRIBUTE, 0 },
111 { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
112 { "__builtin_offsetof", RID_OFFSETOF, 0 },
113 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
114 { "__builtin_va_arg", RID_VA_ARG, 0 },
115 { "__complex", RID_COMPLEX, 0 },
116 { "__complex__", RID_COMPLEX, 0 },
117 { "__const", RID_CONST, 0 },
118 { "__const__", RID_CONST, 0 },
119 { "__extension__", RID_EXTENSION, 0 },
120 { "__func__", RID_C99_FUNCTION_NAME, 0 },
121 { "__imag", RID_IMAGPART, 0 },
122 { "__imag__", RID_IMAGPART, 0 },
123 { "__inline", RID_INLINE, 0 },
124 { "__inline__", RID_INLINE, 0 },
125 { "__label__", RID_LABEL, 0 },
126 { "__real", RID_REALPART, 0 },
127 { "__real__", RID_REALPART, 0 },
128 { "__restrict", RID_RESTRICT, 0 },
129 { "__restrict__", RID_RESTRICT, 0 },
130 { "__signed", RID_SIGNED, 0 },
131 { "__signed__", RID_SIGNED, 0 },
132 { "__thread", RID_THREAD, 0 },
133 { "__typeof", RID_TYPEOF, 0 },
134 { "__typeof__", RID_TYPEOF, 0 },
135 { "__volatile", RID_VOLATILE, 0 },
136 { "__volatile__", RID_VOLATILE, 0 },
137 { "asm", RID_ASM, D_EXT },
138 { "auto", RID_AUTO, 0 },
139 { "break", RID_BREAK, 0 },
140 { "case", RID_CASE, 0 },
141 { "char", RID_CHAR, 0 },
142 { "const", RID_CONST, 0 },
143 { "continue", RID_CONTINUE, 0 },
144 { "default", RID_DEFAULT, 0 },
146 { "double", RID_DOUBLE, 0 },
147 { "else", RID_ELSE, 0 },
148 { "enum", RID_ENUM, 0 },
149 { "extern", RID_EXTERN, 0 },
150 { "float", RID_FLOAT, 0 },
151 { "for", RID_FOR, 0 },
152 { "goto", RID_GOTO, 0 },
154 { "inline", RID_INLINE, D_EXT89 },
155 { "int", RID_INT, 0 },
156 { "long", RID_LONG, 0 },
157 { "register", RID_REGISTER, 0 },
158 { "restrict", RID_RESTRICT, D_C89 },
159 { "return", RID_RETURN, 0 },
160 { "short", RID_SHORT, 0 },
161 { "signed", RID_SIGNED, 0 },
162 { "sizeof", RID_SIZEOF, 0 },
163 { "static", RID_STATIC, 0 },
164 { "struct", RID_STRUCT, 0 },
165 { "switch", RID_SWITCH, 0 },
166 { "typedef", RID_TYPEDEF, 0 },
167 { "typeof", RID_TYPEOF, D_EXT },
168 { "union", RID_UNION, 0 },
169 { "unsigned", RID_UNSIGNED, 0 },
170 { "void", RID_VOID, 0 },
171 { "volatile", RID_VOLATILE, 0 },
172 { "while", RID_WHILE, 0 },
173 /* These Objective-C keywords are recognized only immediately after
175 { "class", RID_AT_CLASS, D_OBJC },
176 { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
177 { "defs", RID_AT_DEFS, D_OBJC },
178 { "encode", RID_AT_ENCODE, D_OBJC },
179 { "end", RID_AT_END, D_OBJC },
180 { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
181 { "interface", RID_AT_INTERFACE, D_OBJC },
182 { "private", RID_AT_PRIVATE, D_OBJC },
183 { "protected", RID_AT_PROTECTED, D_OBJC },
184 { "protocol", RID_AT_PROTOCOL, D_OBJC },
185 { "public", RID_AT_PUBLIC, D_OBJC },
186 { "selector", RID_AT_SELECTOR, D_OBJC },
187 { "throw", RID_AT_THROW, D_OBJC },
188 { "try", RID_AT_TRY, D_OBJC },
189 { "catch", RID_AT_CATCH, D_OBJC },
190 { "finally", RID_AT_FINALLY, D_OBJC },
191 { "synchronized", RID_AT_SYNCHRONIZED, D_OBJC },
192 /* These are recognized only in protocol-qualifier context
194 { "bycopy", RID_BYCOPY, D_OBJC },
195 { "byref", RID_BYREF, D_OBJC },
196 { "in", RID_IN, D_OBJC },
197 { "inout", RID_INOUT, D_OBJC },
198 { "oneway", RID_ONEWAY, D_OBJC },
199 { "out", RID_OUT, D_OBJC },
201 #define N_reswords (sizeof reswords / sizeof (struct resword))
203 /* All OpenMP clauses. OpenMP 2.5. */
204 typedef enum pragma_omp_clause {
205 PRAGMA_OMP_CLAUSE_NONE = 0,
207 PRAGMA_OMP_CLAUSE_COPYIN,
208 PRAGMA_OMP_CLAUSE_COPYPRIVATE,
209 PRAGMA_OMP_CLAUSE_DEFAULT,
210 PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
211 PRAGMA_OMP_CLAUSE_IF,
212 PRAGMA_OMP_CLAUSE_LASTPRIVATE,
213 PRAGMA_OMP_CLAUSE_NOWAIT,
214 PRAGMA_OMP_CLAUSE_NUM_THREADS,
215 PRAGMA_OMP_CLAUSE_ORDERED,
216 PRAGMA_OMP_CLAUSE_PRIVATE,
217 PRAGMA_OMP_CLAUSE_REDUCTION,
218 PRAGMA_OMP_CLAUSE_SCHEDULE,
219 PRAGMA_OMP_CLAUSE_SHARED
223 /* Initialization routine for this file. */
228 /* The only initialization required is of the reserved word
232 int mask = (flag_isoc99 ? 0 : D_C89)
233 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);
235 if (!c_dialect_objc ())
238 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
239 for (i = 0; i < N_reswords; i++)
241 /* If a keyword is disabled, do not enter it into the table
242 and so create a canonical spelling that isn't a keyword. */
243 if (reswords[i].disable & mask)
246 id = get_identifier (reswords[i].word);
247 C_RID_CODE (id) = reswords[i].rid;
248 C_IS_RESERVED_WORD (id) = 1;
249 ridpointers [(int) reswords[i].rid] = id;
253 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
254 and the C parser. Unlike the C++ lexer, the parser structure
255 stores the lexer information instead of using a separate structure.
256 Identifiers are separated into ordinary identifiers, type names,
257 keywords and some other Objective-C types of identifiers, and some
258 look-ahead is maintained.
260 ??? It might be a good idea to lex the whole file up front (as for
261 C++). It would then be possible to share more of the C and C++
262 lexer code, if desired. */
264 /* The following local token type is used. */
267 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
269 /* More information about the type of a CPP_NAME token. */
270 typedef enum c_id_kind {
271 /* An ordinary identifier. */
273 /* An identifier declared as a typedef name. */
275 /* An identifier declared as an Objective-C class name. */
277 /* Not an identifier. */
281 /* A single C token after string literal concatenation and conversion
282 of preprocessing tokens to tokens. */
283 typedef struct c_token GTY (())
285 /* The kind of token. */
286 ENUM_BITFIELD (cpp_ttype) type : 8;
287 /* If this token is a CPP_NAME, this value indicates whether also
288 declared as some kind of type. Otherwise, it is C_ID_NONE. */
289 ENUM_BITFIELD (c_id_kind) id_kind : 8;
290 /* If this token is a keyword, this value indicates which keyword.
291 Otherwise, this value is RID_MAX. */
292 ENUM_BITFIELD (rid) keyword : 8;
293 /* If this token is a CPP_PRAGMA, this indicates the pragma that
294 was seen. Otherwise it is PRAGMA_NONE. */
295 ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
296 /* True if this token is from a system header. */
297 BOOL_BITFIELD in_system_header : 1;
298 /* The value associated with this token, if any. */
300 /* The location at which this token was found. */
304 /* A parser structure recording information about the state and
305 context of parsing. Includes lexer information with up to two
306 tokens of look-ahead; more are not needed for C. */
307 typedef struct c_parser GTY(())
309 /* The look-ahead tokens. */
311 /* How many look-ahead tokens are available (0, 1 or 2). */
313 /* True if a syntax error is being recovered from; false otherwise.
314 c_parser_error sets this flag. It should clear this flag when
315 enough tokens have been consumed to recover from the error. */
316 BOOL_BITFIELD error : 1;
317 /* True if we're processing a pragma, and shouldn't automatically
318 consume CPP_PRAGMA_EOL. */
319 BOOL_BITFIELD in_pragma : 1;
323 /* The actual parser and external interface. ??? Does this need to be
324 garbage-collected? */
326 static GTY (()) c_parser *the_parser;
329 /* Read in and lex a single token, storing it in *TOKEN. */
332 c_lex_one_token (c_token *token)
334 timevar_push (TV_LEX);
336 token->type = c_lex_with_flags (&token->value, &token->location, NULL);
337 token->id_kind = C_ID_NONE;
338 token->keyword = RID_MAX;
339 token->pragma_kind = PRAGMA_NONE;
340 token->in_system_header = in_system_header;
348 int objc_force_identifier = objc_need_raw_identifier;
349 OBJC_NEED_RAW_IDENTIFIER (0);
351 if (C_IS_RESERVED_WORD (token->value))
353 enum rid rid_code = C_RID_CODE (token->value);
355 if (c_dialect_objc ())
357 if (!OBJC_IS_AT_KEYWORD (rid_code)
358 && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
360 /* Return the canonical spelling for this keyword. */
361 token->value = ridpointers[(int) rid_code];
362 token->type = CPP_KEYWORD;
363 token->keyword = rid_code;
369 /* Return the canonical spelling for this keyword. */
370 token->value = ridpointers[(int) rid_code];
371 token->type = CPP_KEYWORD;
372 token->keyword = rid_code;
377 decl = lookup_name (token->value);
380 if (TREE_CODE (decl) == TYPE_DECL)
382 token->id_kind = C_ID_TYPENAME;
386 else if (c_dialect_objc ())
388 tree objc_interface_decl = objc_is_class_name (token->value);
389 /* Objective-C class names are in the same namespace as
390 variables and typedefs, and hence are shadowed by local
392 if (objc_interface_decl
393 && (global_bindings_p ()
394 || (!objc_force_identifier && !decl)))
396 token->value = objc_interface_decl;
397 token->id_kind = C_ID_CLASSNAME;
401 token->id_kind = C_ID_ID;
405 /* This only happens in Objective-C; it must be a keyword. */
406 token->type = CPP_KEYWORD;
407 token->keyword = C_RID_CODE (token->value);
411 case CPP_CLOSE_PAREN:
413 /* These tokens may affect the interpretation of any identifiers
414 following, if doing Objective-C. */
415 OBJC_NEED_RAW_IDENTIFIER (0);
418 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
419 token->pragma_kind = TREE_INT_CST_LOW (token->value);
425 timevar_pop (TV_LEX);
428 /* Return a pointer to the next token from PARSER, reading it in if
431 static inline c_token *
432 c_parser_peek_token (c_parser *parser)
434 if (parser->tokens_avail == 0)
436 c_lex_one_token (&parser->tokens[0]);
437 parser->tokens_avail = 1;
439 return &parser->tokens[0];
442 /* Return true if the next token from PARSER has the indicated
446 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
448 return c_parser_peek_token (parser)->type == type;
451 /* Return true if the next token from PARSER does not have the
455 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
457 return !c_parser_next_token_is (parser, type);
460 /* Return true if the next token from PARSER is the indicated
464 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
468 /* Peek at the next token. */
469 token = c_parser_peek_token (parser);
470 /* Check to see if it is the indicated keyword. */
471 return token->keyword == keyword;
474 /* Return true if TOKEN can start a type name,
477 c_token_starts_typename (c_token *token)
482 switch (token->id_kind)
489 gcc_assert (c_dialect_objc ());
495 switch (token->keyword)
524 if (c_dialect_objc ())
532 /* Return true if the next token from PARSER can start a type name,
535 c_parser_next_token_starts_typename (c_parser *parser)
537 c_token *token = c_parser_peek_token (parser);
538 return c_token_starts_typename (token);
541 /* Return true if TOKEN can start declaration specifiers, false
544 c_token_starts_declspecs (c_token *token)
549 switch (token->id_kind)
556 gcc_assert (c_dialect_objc ());
562 switch (token->keyword)
598 if (c_dialect_objc ())
606 /* Return true if the next token from PARSER can start declaration
607 specifiers, false otherwise. */
609 c_parser_next_token_starts_declspecs (c_parser *parser)
611 c_token *token = c_parser_peek_token (parser);
612 return c_token_starts_declspecs (token);
615 /* Return a pointer to the next-but-one token from PARSER, reading it
616 in if necessary. The next token is already read in. */
619 c_parser_peek_2nd_token (c_parser *parser)
621 if (parser->tokens_avail >= 2)
622 return &parser->tokens[1];
623 gcc_assert (parser->tokens_avail == 1);
624 gcc_assert (parser->tokens[0].type != CPP_EOF);
625 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
626 c_lex_one_token (&parser->tokens[1]);
627 parser->tokens_avail = 2;
628 return &parser->tokens[1];
631 /* Consume the next token from PARSER. */
634 c_parser_consume_token (c_parser *parser)
636 gcc_assert (parser->tokens_avail >= 1);
637 gcc_assert (parser->tokens[0].type != CPP_EOF);
638 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
639 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
640 if (parser->tokens_avail == 2)
641 parser->tokens[0] = parser->tokens[1];
642 parser->tokens_avail--;
645 /* Expect the current token to be a #pragma. Consume it and remember
646 that we've begun parsing a pragma. */
649 c_parser_consume_pragma (c_parser *parser)
651 gcc_assert (!parser->in_pragma);
652 gcc_assert (parser->tokens_avail >= 1);
653 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
654 if (parser->tokens_avail == 2)
655 parser->tokens[0] = parser->tokens[1];
656 parser->tokens_avail--;
657 parser->in_pragma = true;
660 /* Update the globals input_location and in_system_header from
663 c_parser_set_source_position_from_token (c_token *token)
665 if (token->type != CPP_EOF)
667 input_location = token->location;
668 in_system_header = token->in_system_header;
672 /* Issue a diagnostic of the form
673 FILE:LINE: MESSAGE before TOKEN
674 where TOKEN is the next token in the input stream of PARSER.
675 MESSAGE (specified by the caller) is usually of the form "expected
678 Do not issue a diagnostic if still recovering from an error.
680 ??? This is taken from the C++ parser, but building up messages in
681 this way is not i18n-friendly and some other approach should be
685 c_parser_error (c_parser *parser, const char *gmsgid)
687 c_token *token = c_parser_peek_token (parser);
690 parser->error = true;
693 /* This diagnostic makes more sense if it is tagged to the line of
694 the token we just peeked at. */
695 c_parser_set_source_position_from_token (token);
696 c_parse_error (gmsgid,
697 /* Because c_parse_error does not understand
698 CPP_KEYWORD, keywords are treated like
700 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
704 /* If the next token is of the indicated TYPE, consume it. Otherwise,
705 issue the error MSGID. If MSGID is NULL then a message has already
706 been produced and no message will be produced this time. Returns
707 true if found, false otherwise. */
710 c_parser_require (c_parser *parser,
714 if (c_parser_next_token_is (parser, type))
716 c_parser_consume_token (parser);
721 c_parser_error (parser, msgid);
726 /* If the next token is the indicated keyword, consume it. Otherwise,
727 issue the error MSGID. Returns true if found, false otherwise. */
730 c_parser_require_keyword (c_parser *parser,
734 if (c_parser_next_token_is_keyword (parser, keyword))
736 c_parser_consume_token (parser);
741 c_parser_error (parser, msgid);
746 /* Like c_parser_require, except that tokens will be skipped until the
747 desired token is found. An error message is still produced if the
748 next token is not as expected. If MSGID is NULL then a message has
749 already been produced and no message will be produced this
753 c_parser_skip_until_found (c_parser *parser,
757 unsigned nesting_depth = 0;
759 if (c_parser_require (parser, type, msgid))
762 /* Skip tokens until the desired token is found. */
765 /* Peek at the next token. */
766 c_token *token = c_parser_peek_token (parser);
767 /* If we've reached the token we want, consume it and stop. */
768 if (token->type == type && !nesting_depth)
770 c_parser_consume_token (parser);
774 /* If we've run out of tokens, stop. */
775 if (token->type == CPP_EOF)
777 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
779 if (token->type == CPP_OPEN_BRACE
780 || token->type == CPP_OPEN_PAREN
781 || token->type == CPP_OPEN_SQUARE)
783 else if (token->type == CPP_CLOSE_BRACE
784 || token->type == CPP_CLOSE_PAREN
785 || token->type == CPP_CLOSE_SQUARE)
787 if (nesting_depth-- == 0)
790 /* Consume this token. */
791 c_parser_consume_token (parser);
793 parser->error = false;
796 /* Skip tokens until the end of a parameter is found, but do not
797 consume the comma, semicolon or closing delimiter. */
800 c_parser_skip_to_end_of_parameter (c_parser *parser)
802 unsigned nesting_depth = 0;
806 c_token *token = c_parser_peek_token (parser);
807 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
810 /* If we've run out of tokens, stop. */
811 if (token->type == CPP_EOF)
813 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
815 if (token->type == CPP_OPEN_BRACE
816 || token->type == CPP_OPEN_PAREN
817 || token->type == CPP_OPEN_SQUARE)
819 else if (token->type == CPP_CLOSE_BRACE
820 || token->type == CPP_CLOSE_PAREN
821 || token->type == CPP_CLOSE_SQUARE)
823 if (nesting_depth-- == 0)
826 /* Consume this token. */
827 c_parser_consume_token (parser);
829 parser->error = false;
832 /* Expect to be at the end of the pragma directive and consume an
833 end of line marker. */
836 c_parser_skip_to_pragma_eol (c_parser *parser)
838 gcc_assert (parser->in_pragma);
839 parser->in_pragma = false;
841 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
844 c_token *token = c_parser_peek_token (parser);
845 if (token->type == CPP_EOF)
847 if (token->type == CPP_PRAGMA_EOL)
849 c_parser_consume_token (parser);
852 c_parser_consume_token (parser);
855 parser->error = false;
858 /* Skip tokens until we have consumed an entire block, or until we
859 have consumed a non-nested ';'. */
862 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
864 unsigned nesting_depth = 0;
865 bool save_error = parser->error;
871 /* Peek at the next token. */
872 token = c_parser_peek_token (parser);
880 if (parser->in_pragma)
885 /* If the next token is a ';', we have reached the
886 end of the statement. */
889 /* Consume the ';'. */
890 c_parser_consume_token (parser);
895 case CPP_CLOSE_BRACE:
896 /* If the next token is a non-nested '}', then we have
897 reached the end of the current block. */
898 if (nesting_depth == 0 || --nesting_depth == 0)
900 c_parser_consume_token (parser);
906 /* If it the next token is a '{', then we are entering a new
907 block. Consume the entire block. */
912 /* If we see a pragma, consume the whole thing at once. We
913 have some safeguards against consuming pragmas willy-nilly.
914 Normally, we'd expect to be here with parser->error set,
915 which disables these safeguards. But it's possible to get
916 here for secondary error recovery, after parser->error has
918 c_parser_consume_pragma (parser);
919 c_parser_skip_to_pragma_eol (parser);
920 parser->error = save_error;
924 c_parser_consume_token (parser);
928 parser->error = false;
931 /* Save the warning flags which are controlled by __extension__. */
934 disable_extension_diagnostics (void)
937 | (warn_pointer_arith << 1)
938 | (warn_traditional << 2)
941 warn_pointer_arith = 0;
942 warn_traditional = 0;
947 /* Restore the warning flags which are controlled by __extension__.
948 FLAGS is the return value from disable_extension_diagnostics. */
951 restore_extension_diagnostics (int flags)
953 pedantic = flags & 1;
954 warn_pointer_arith = (flags >> 1) & 1;
955 warn_traditional = (flags >> 2) & 1;
956 flag_iso = (flags >> 3) & 1;
959 /* Possibly kinds of declarator to parse. */
960 typedef enum c_dtr_syn {
961 /* A normal declarator with an identifier. */
963 /* An abstract declarator (maybe empty). */
965 /* A parameter declarator: may be either, but after a type name does
966 not redeclare a typedef name as an identifier if it can
967 alternatively be interpreted as a typedef name; see DR#009,
968 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
969 following DR#249. For example, given a typedef T, "int T" and
970 "int *T" are valid parameter declarations redeclaring T, while
971 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
972 abstract declarators rather than involving redundant parentheses;
973 the same applies with attributes inside the parentheses before
978 static void c_parser_external_declaration (c_parser *);
979 static void c_parser_asm_definition (c_parser *);
980 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
981 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
983 static struct c_typespec c_parser_enum_specifier (c_parser *);
984 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
985 static tree c_parser_struct_declaration (c_parser *);
986 static struct c_typespec c_parser_typeof_specifier (c_parser *);
987 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
989 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
991 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
993 struct c_declarator *);
994 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
995 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
996 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
997 static tree c_parser_simple_asm_expr (c_parser *);
998 static tree c_parser_attributes (c_parser *);
999 static struct c_type_name *c_parser_type_name (c_parser *);
1000 static struct c_expr c_parser_initializer (c_parser *);
1001 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1002 static void c_parser_initelt (c_parser *);
1003 static void c_parser_initval (c_parser *, struct c_expr *);
1004 static tree c_parser_compound_statement (c_parser *);
1005 static void c_parser_compound_statement_nostart (c_parser *);
1006 static void c_parser_label (c_parser *);
1007 static void c_parser_statement (c_parser *);
1008 static void c_parser_statement_after_labels (c_parser *);
1009 static void c_parser_if_statement (c_parser *);
1010 static void c_parser_switch_statement (c_parser *);
1011 static void c_parser_while_statement (c_parser *);
1012 static void c_parser_do_statement (c_parser *);
1013 static void c_parser_for_statement (c_parser *);
1014 static tree c_parser_asm_statement (c_parser *);
1015 static tree c_parser_asm_operands (c_parser *, bool);
1016 static tree c_parser_asm_clobbers (c_parser *);
1017 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1018 static struct c_expr c_parser_conditional_expression (c_parser *,
1020 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1021 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1022 static struct c_expr c_parser_unary_expression (c_parser *);
1023 static struct c_expr c_parser_sizeof_expression (c_parser *);
1024 static struct c_expr c_parser_alignof_expression (c_parser *);
1025 static struct c_expr c_parser_postfix_expression (c_parser *);
1026 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1027 struct c_type_name *);
1028 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1030 static struct c_expr c_parser_expression (c_parser *);
1031 static struct c_expr c_parser_expression_conv (c_parser *);
1032 static tree c_parser_expr_list (c_parser *, bool);
1033 static void c_parser_omp_construct (c_parser *);
1034 static void c_parser_omp_threadprivate (c_parser *);
1035 static void c_parser_omp_barrier (c_parser *);
1036 static void c_parser_omp_flush (c_parser *);
1038 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1039 static bool c_parser_pragma (c_parser *, enum pragma_context);
1041 /* These Objective-C parser functions are only ever called when
1042 compiling Objective-C. */
1043 static void c_parser_objc_class_definition (c_parser *);
1044 static void c_parser_objc_class_instance_variables (c_parser *);
1045 static void c_parser_objc_class_declaration (c_parser *);
1046 static void c_parser_objc_alias_declaration (c_parser *);
1047 static void c_parser_objc_protocol_definition (c_parser *);
1048 static enum tree_code c_parser_objc_method_type (c_parser *);
1049 static void c_parser_objc_method_definition (c_parser *);
1050 static void c_parser_objc_methodprotolist (c_parser *);
1051 static void c_parser_objc_methodproto (c_parser *);
1052 static tree c_parser_objc_method_decl (c_parser *);
1053 static tree c_parser_objc_type_name (c_parser *);
1054 static tree c_parser_objc_protocol_refs (c_parser *);
1055 static void c_parser_objc_try_catch_statement (c_parser *);
1056 static void c_parser_objc_synchronized_statement (c_parser *);
1057 static tree c_parser_objc_selector (c_parser *);
1058 static tree c_parser_objc_selector_arg (c_parser *);
1059 static tree c_parser_objc_receiver (c_parser *);
1060 static tree c_parser_objc_message_args (c_parser *);
1061 static tree c_parser_objc_keywordexpr (c_parser *);
1063 /* Parse a translation unit (C90 6.7, C99 6.9).
1066 external-declarations
1068 external-declarations:
1069 external-declaration
1070 external-declarations external-declaration
1079 c_parser_translation_unit (c_parser *parser)
1081 if (c_parser_next_token_is (parser, CPP_EOF))
1084 pedwarn ("ISO C forbids an empty source file");
1088 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1092 c_parser_external_declaration (parser);
1093 obstack_free (&parser_obstack, obstack_position);
1095 while (c_parser_next_token_is_not (parser, CPP_EOF));
1099 /* Parse an external declaration (C90 6.7, C99 6.9).
1101 external-declaration:
1107 external-declaration:
1110 __extension__ external-declaration
1114 external-declaration:
1115 objc-class-definition
1116 objc-class-declaration
1117 objc-alias-declaration
1118 objc-protocol-definition
1119 objc-method-definition
1124 c_parser_external_declaration (c_parser *parser)
1127 switch (c_parser_peek_token (parser)->type)
1130 switch (c_parser_peek_token (parser)->keyword)
1133 ext = disable_extension_diagnostics ();
1134 c_parser_consume_token (parser);
1135 c_parser_external_declaration (parser);
1136 restore_extension_diagnostics (ext);
1139 c_parser_asm_definition (parser);
1141 case RID_AT_INTERFACE:
1142 case RID_AT_IMPLEMENTATION:
1143 gcc_assert (c_dialect_objc ());
1144 c_parser_objc_class_definition (parser);
1147 gcc_assert (c_dialect_objc ());
1148 c_parser_objc_class_declaration (parser);
1151 gcc_assert (c_dialect_objc ());
1152 c_parser_objc_alias_declaration (parser);
1154 case RID_AT_PROTOCOL:
1155 gcc_assert (c_dialect_objc ());
1156 c_parser_objc_protocol_definition (parser);
1159 gcc_assert (c_dialect_objc ());
1160 c_parser_consume_token (parser);
1161 objc_finish_implementation ();
1169 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1170 c_parser_consume_token (parser);
1173 c_parser_pragma (parser, pragma_external);
1177 if (c_dialect_objc ())
1179 c_parser_objc_method_definition (parser);
1182 /* Else fall through, and yield a syntax error trying to parse
1183 as a declaration or function definition. */
1186 /* A declaration or a function definition. We can only tell
1187 which after parsing the declaration specifiers, if any, and
1188 the first declarator. */
1189 c_parser_declaration_or_fndef (parser, true, true, false, true);
1195 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1196 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1197 accepted; otherwise (old-style parameter declarations) only other
1198 declarations are accepted. If NESTED is true, we are inside a
1199 function or parsing old-style parameter declarations; any functions
1200 encountered are nested functions and declaration specifiers are
1201 required; otherwise we are at top level and functions are normal
1202 functions and declaration specifiers may be optional. If EMPTY_OK
1203 is true, empty declarations are OK (subject to all other
1204 constraints); otherwise (old-style parameter declarations) they are
1205 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1206 may start with attributes; otherwise they may not.
1209 declaration-specifiers init-declarator-list[opt] ;
1211 function-definition:
1212 declaration-specifiers[opt] declarator declaration-list[opt]
1217 declaration-list declaration
1219 init-declarator-list:
1221 init-declarator-list , init-declarator
1224 declarator simple-asm-expr[opt] attributes[opt]
1225 declarator simple-asm-expr[opt] attributes[opt] = initializer
1229 nested-function-definition:
1230 declaration-specifiers declarator declaration-list[opt]
1233 The simple-asm-expr and attributes are GNU extensions.
1235 This function does not handle __extension__; that is handled in its
1236 callers. ??? Following the old parser, __extension__ may start
1237 external declarations, declarations in functions and declarations
1238 at the start of "for" loops, but not old-style parameter
1241 C99 requires declaration specifiers in a function definition; the
1242 absence is diagnosed through the diagnosis of implicit int. In GNU
1243 C we also allow but diagnose declarations without declaration
1244 specifiers, but only at top level (elsewhere they conflict with
1250 threadprivate-directive */
1253 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1254 bool nested, bool start_attr_ok)
1256 struct c_declspecs *specs;
1258 tree all_prefix_attrs;
1259 bool diagnosed_no_specs = false;
1261 specs = build_null_declspecs ();
1262 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1265 c_parser_skip_to_end_of_block_or_statement (parser);
1268 if (nested && !specs->declspecs_seen_p)
1270 c_parser_error (parser, "expected declaration specifiers");
1271 c_parser_skip_to_end_of_block_or_statement (parser);
1274 finish_declspecs (specs);
1275 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1281 shadow_tag_warned (specs, 1);
1282 pedwarn ("empty declaration");
1284 c_parser_consume_token (parser);
1287 pending_xref_error ();
1288 prefix_attrs = specs->attrs;
1289 all_prefix_attrs = prefix_attrs;
1290 specs->attrs = NULL_TREE;
1293 struct c_declarator *declarator;
1296 /* Declaring either one or more declarators (in which case we
1297 should diagnose if there were no declaration specifiers) or a
1298 function definition (in which case the diagnostic for
1299 implicit int suffices). */
1300 declarator = c_parser_declarator (parser, specs->type_seen_p,
1301 C_DTR_NORMAL, &dummy);
1302 if (declarator == NULL)
1304 c_parser_skip_to_end_of_block_or_statement (parser);
1307 if (c_parser_next_token_is (parser, CPP_EQ)
1308 || c_parser_next_token_is (parser, CPP_COMMA)
1309 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1310 || c_parser_next_token_is_keyword (parser, RID_ASM)
1311 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1313 tree asm_name = NULL_TREE;
1314 tree postfix_attrs = NULL_TREE;
1315 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1317 diagnosed_no_specs = true;
1318 pedwarn ("data definition has no type or storage class");
1320 /* Having seen a data definition, there cannot now be a
1321 function definition. */
1323 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1324 asm_name = c_parser_simple_asm_expr (parser);
1325 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1326 postfix_attrs = c_parser_attributes (parser);
1327 if (c_parser_next_token_is (parser, CPP_EQ))
1331 c_parser_consume_token (parser);
1332 /* The declaration of the variable is in effect while
1333 its initializer is parsed. */
1334 d = start_decl (declarator, specs, true,
1335 chainon (postfix_attrs, all_prefix_attrs));
1337 d = error_mark_node;
1338 start_init (d, asm_name, global_bindings_p ());
1339 init = c_parser_initializer (parser);
1341 if (d != error_mark_node)
1343 maybe_warn_string_init (TREE_TYPE (d), init);
1344 finish_decl (d, init.value, asm_name);
1349 tree d = start_decl (declarator, specs, false,
1350 chainon (postfix_attrs,
1353 finish_decl (d, NULL_TREE, asm_name);
1355 if (c_parser_next_token_is (parser, CPP_COMMA))
1357 c_parser_consume_token (parser);
1358 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1359 all_prefix_attrs = chainon (c_parser_attributes (parser),
1362 all_prefix_attrs = prefix_attrs;
1365 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1367 c_parser_consume_token (parser);
1372 c_parser_error (parser, "expected %<,%> or %<;%>");
1373 c_parser_skip_to_end_of_block_or_statement (parser);
1379 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1380 "%<asm%> or %<__attribute__%>");
1381 c_parser_skip_to_end_of_block_or_statement (parser);
1384 /* Function definition (nested or otherwise). */
1388 pedwarn ("ISO C forbids nested functions");
1389 push_function_context ();
1391 if (!start_function (specs, declarator, all_prefix_attrs))
1393 /* This can appear in many cases looking nothing like a
1394 function definition, so we don't give a more specific
1395 error suggesting there was one. */
1396 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1397 "or %<__attribute__%>");
1399 pop_function_context ();
1402 /* Parse old-style parameter declarations. ??? Attributes are
1403 not allowed to start declaration specifiers here because of a
1404 syntax conflict between a function declaration with attribute
1405 suffix and a function definition with an attribute prefix on
1406 first old-style parameter declaration. Following the old
1407 parser, they are not accepted on subsequent old-style
1408 parameter declarations either. However, there is no
1409 ambiguity after the first declaration, nor indeed on the
1410 first as long as we don't allow postfix attributes after a
1411 declarator with a nonempty identifier list in a definition;
1412 and postfix attributes have never been accepted here in
1413 function definitions either. */
1414 while (c_parser_next_token_is_not (parser, CPP_EOF)
1415 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1416 c_parser_declaration_or_fndef (parser, false, false, true, false);
1417 DECL_SOURCE_LOCATION (current_function_decl)
1418 = c_parser_peek_token (parser)->location;
1419 store_parm_decls ();
1420 fnbody = c_parser_compound_statement (parser);
1423 tree decl = current_function_decl;
1426 pop_function_context ();
1427 add_stmt (build_stmt (DECL_EXPR, decl));
1438 /* Parse an asm-definition (asm() outside a function body). This is a
1446 c_parser_asm_definition (c_parser *parser)
1448 tree asm_str = c_parser_simple_asm_expr (parser);
1450 cgraph_add_asm_node (asm_str);
1451 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1454 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1455 6.7), adding them to SPECS (which may already include some).
1456 Storage class specifiers are accepted iff SCSPEC_OK; type
1457 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1458 the start iff START_ATTR_OK.
1460 declaration-specifiers:
1461 storage-class-specifier declaration-specifiers[opt]
1462 type-specifier declaration-specifiers[opt]
1463 type-qualifier declaration-specifiers[opt]
1464 function-specifier declaration-specifiers[opt]
1466 Function specifiers (inline) are from C99, and are currently
1467 handled as storage class specifiers, as is __thread.
1469 C90 6.5.1, C99 6.7.1:
1470 storage-class-specifier:
1481 C90 6.5.2, C99 6.7.2:
1494 [_Imaginary removed in C99 TC2]
1495 struct-or-union-specifier
1499 (_Bool and _Complex are new in C99.)
1501 C90 6.5.3, C99 6.7.3:
1508 (restrict is new in C99.)
1512 declaration-specifiers:
1513 attributes declaration-specifiers[opt]
1515 storage-class-specifier:
1527 class-name objc-protocol-refs[opt]
1528 typedef-name objc-protocol-refs
1533 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1534 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1536 bool attrs_ok = start_attr_ok;
1537 bool seen_type = specs->type_seen_p;
1538 while (c_parser_next_token_is (parser, CPP_NAME)
1539 || c_parser_next_token_is (parser, CPP_KEYWORD)
1540 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1542 struct c_typespec t;
1544 if (c_parser_next_token_is (parser, CPP_NAME))
1546 tree value = c_parser_peek_token (parser)->value;
1547 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1548 /* This finishes the specifiers unless a type name is OK, it
1549 is declared as a type name and a type name hasn't yet
1551 if (!typespec_ok || seen_type
1552 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1554 c_parser_consume_token (parser);
1557 if (kind == C_ID_TYPENAME
1558 && (!c_dialect_objc ()
1559 || c_parser_next_token_is_not (parser, CPP_LESS)))
1561 t.kind = ctsk_typedef;
1562 /* For a typedef name, record the meaning, not the name.
1563 In case of 'foo foo, bar;'. */
1564 t.spec = lookup_name (value);
1568 tree proto = NULL_TREE;
1569 gcc_assert (c_dialect_objc ());
1571 if (c_parser_next_token_is (parser, CPP_LESS))
1572 proto = c_parser_objc_protocol_refs (parser);
1573 t.spec = objc_get_protocol_qualified_type (value, proto);
1575 declspecs_add_type (specs, t);
1578 if (c_parser_next_token_is (parser, CPP_LESS))
1580 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1581 nisse@lysator.liu.se. */
1583 gcc_assert (c_dialect_objc ());
1584 if (!typespec_ok || seen_type)
1586 proto = c_parser_objc_protocol_refs (parser);
1588 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1589 declspecs_add_type (specs, t);
1592 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1593 switch (c_parser_peek_token (parser)->keyword)
1605 /* TODO: Distinguish between function specifiers (inline)
1606 and storage class specifiers, either here or in
1607 declspecs_add_scspec. */
1608 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1609 c_parser_consume_token (parser);
1629 OBJC_NEED_RAW_IDENTIFIER (1);
1630 t.kind = ctsk_resword;
1631 t.spec = c_parser_peek_token (parser)->value;
1632 declspecs_add_type (specs, t);
1633 c_parser_consume_token (parser);
1640 t = c_parser_enum_specifier (parser);
1641 declspecs_add_type (specs, t);
1649 t = c_parser_struct_or_union_specifier (parser);
1650 declspecs_add_type (specs, t);
1653 /* ??? The old parser rejected typeof after other type
1654 specifiers, but is a syntax error the best way of
1656 if (!typespec_ok || seen_type)
1660 t = c_parser_typeof_specifier (parser);
1661 declspecs_add_type (specs, t);
1667 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1668 c_parser_consume_token (parser);
1673 attrs = c_parser_attributes (parser);
1674 declspecs_add_attrs (specs, attrs);
1683 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1686 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1687 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1688 enum attributes[opt] identifier
1690 The form with trailing comma is new in C99. The forms with
1691 attributes are GNU extensions. In GNU C, we accept any expression
1692 without commas in the syntax (assignment expressions, not just
1693 conditional expressions); assignment expressions will be diagnosed
1698 enumerator-list , enumerator
1701 enumeration-constant
1702 enumeration-constant = constant-expression
1705 static struct c_typespec
1706 c_parser_enum_specifier (c_parser *parser)
1708 struct c_typespec ret;
1710 tree ident = NULL_TREE;
1711 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1712 c_parser_consume_token (parser);
1713 attrs = c_parser_attributes (parser);
1714 if (c_parser_next_token_is (parser, CPP_NAME))
1716 ident = c_parser_peek_token (parser)->value;
1717 c_parser_consume_token (parser);
1719 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1721 /* Parse an enum definition. */
1722 tree type = start_enum (ident);
1724 /* We chain the enumerators in reverse order, then put them in
1725 forward order at the end. */
1726 tree values = NULL_TREE;
1727 c_parser_consume_token (parser);
1734 if (c_parser_next_token_is_not (parser, CPP_NAME))
1736 c_parser_error (parser, "expected identifier");
1737 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1738 values = error_mark_node;
1741 enum_id = c_parser_peek_token (parser)->value;
1742 c_parser_consume_token (parser);
1743 if (c_parser_next_token_is (parser, CPP_EQ))
1745 c_parser_consume_token (parser);
1746 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1749 enum_value = NULL_TREE;
1750 enum_decl = build_enumerator (enum_id, enum_value);
1751 TREE_CHAIN (enum_decl) = values;
1754 if (c_parser_next_token_is (parser, CPP_COMMA))
1757 c_parser_consume_token (parser);
1759 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1761 if (seen_comma && pedantic && !flag_isoc99)
1762 pedwarn ("comma at end of enumerator list");
1763 c_parser_consume_token (parser);
1768 c_parser_error (parser, "expected %<,%> or %<}%>");
1769 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1770 values = error_mark_node;
1774 postfix_attrs = c_parser_attributes (parser);
1775 ret.spec = finish_enum (type, nreverse (values),
1776 chainon (attrs, postfix_attrs));
1777 ret.kind = ctsk_tagdef;
1782 c_parser_error (parser, "expected %<{%>");
1783 ret.spec = error_mark_node;
1784 ret.kind = ctsk_tagref;
1787 ret = parser_xref_tag (ENUMERAL_TYPE, ident);
1788 /* In ISO C, enumerated types can be referred to only if already
1790 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1791 pedwarn ("ISO C forbids forward references to %<enum%> types");
1795 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1797 struct-or-union-specifier:
1798 struct-or-union attributes[opt] identifier[opt]
1799 { struct-contents } attributes[opt]
1800 struct-or-union attributes[opt] identifier
1803 struct-declaration-list
1805 struct-declaration-list:
1806 struct-declaration ;
1807 struct-declaration-list struct-declaration ;
1814 struct-declaration-list struct-declaration
1816 struct-declaration-list:
1817 struct-declaration-list ;
1820 (Note that in the syntax here, unlike that in ISO C, the semicolons
1821 are included here rather than in struct-declaration, in order to
1822 describe the syntax with extra semicolons and missing semicolon at
1827 struct-declaration-list:
1828 @defs ( class-name )
1830 (Note this does not include a trailing semicolon, but can be
1831 followed by further declarations, and gets a pedwarn-if-pedantic
1832 when followed by a semicolon.) */
1834 static struct c_typespec
1835 c_parser_struct_or_union_specifier (c_parser *parser)
1837 struct c_typespec ret;
1839 tree ident = NULL_TREE;
1840 enum tree_code code;
1841 switch (c_parser_peek_token (parser)->keyword)
1852 c_parser_consume_token (parser);
1853 attrs = c_parser_attributes (parser);
1854 if (c_parser_next_token_is (parser, CPP_NAME))
1856 ident = c_parser_peek_token (parser)->value;
1857 c_parser_consume_token (parser);
1859 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1861 /* Parse a struct or union definition. Start the scope of the
1862 tag before parsing components. */
1863 tree type = start_struct (code, ident);
1865 /* We chain the components in reverse order, then put them in
1866 forward order at the end. Each struct-declaration may
1867 declare multiple components (comma-separated), so we must use
1868 chainon to join them, although when parsing each
1869 struct-declaration we can use TREE_CHAIN directly.
1871 The theory behind all this is that there will be more
1872 semicolon separated fields than comma separated fields, and
1873 so we'll be minimizing the number of node traversals required
1875 tree contents = NULL_TREE;
1876 c_parser_consume_token (parser);
1877 /* Handle the Objective-C @defs construct,
1878 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1879 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1882 gcc_assert (c_dialect_objc ());
1883 c_parser_consume_token (parser);
1884 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1886 if (c_parser_next_token_is (parser, CPP_NAME)
1887 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1889 name = c_parser_peek_token (parser)->value;
1890 c_parser_consume_token (parser);
1894 c_parser_error (parser, "expected class name");
1895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1900 contents = nreverse (objc_get_class_ivars (name));
1903 /* Parse the struct-declarations and semicolons. Problems with
1904 semicolons are diagnosed here; empty structures are diagnosed
1909 /* Parse any stray semicolon. */
1910 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1913 pedwarn ("extra semicolon in struct or union specified");
1914 c_parser_consume_token (parser);
1917 /* Stop if at the end of the struct or union contents. */
1918 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1920 c_parser_consume_token (parser);
1923 /* Accept #pragmas at struct scope. */
1924 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1926 c_parser_pragma (parser, pragma_external);
1929 /* Parse some comma-separated declarations, but not the
1930 trailing semicolon if any. */
1931 decls = c_parser_struct_declaration (parser);
1932 contents = chainon (decls, contents);
1933 /* If no semicolon follows, either we have a parse error or
1934 are at the end of the struct or union and should
1936 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1937 c_parser_consume_token (parser);
1940 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1941 pedwarn ("no semicolon at end of struct or union");
1944 c_parser_error (parser, "expected %<;%>");
1945 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1950 postfix_attrs = c_parser_attributes (parser);
1951 ret.spec = finish_struct (type, nreverse (contents),
1952 chainon (attrs, postfix_attrs));
1953 ret.kind = ctsk_tagdef;
1958 c_parser_error (parser, "expected %<{%>");
1959 ret.spec = error_mark_node;
1960 ret.kind = ctsk_tagref;
1963 ret = parser_xref_tag (code, ident);
1967 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1968 the trailing semicolon.
1971 specifier-qualifier-list struct-declarator-list
1973 specifier-qualifier-list:
1974 type-specifier specifier-qualifier-list[opt]
1975 type-qualifier specifier-qualifier-list[opt]
1976 attributes specifier-qualifier-list[opt]
1978 struct-declarator-list:
1980 struct-declarator-list , attributes[opt] struct-declarator
1983 declarator attributes[opt]
1984 declarator[opt] : constant-expression attributes[opt]
1989 __extension__ struct-declaration
1990 specifier-qualifier-list
1992 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1993 of attributes where shown is a GNU extension. In GNU C, we accept
1994 any expression without commas in the syntax (assignment
1995 expressions, not just conditional expressions); assignment
1996 expressions will be diagnosed as non-constant. */
1999 c_parser_struct_declaration (c_parser *parser)
2001 struct c_declspecs *specs;
2003 tree all_prefix_attrs;
2005 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2009 ext = disable_extension_diagnostics ();
2010 c_parser_consume_token (parser);
2011 decl = c_parser_struct_declaration (parser);
2012 restore_extension_diagnostics (ext);
2015 specs = build_null_declspecs ();
2016 c_parser_declspecs (parser, specs, false, true, true);
2019 if (!specs->declspecs_seen_p)
2021 c_parser_error (parser, "expected specifier-qualifier-list");
2024 finish_declspecs (specs);
2025 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2028 if (!specs->type_seen_p)
2031 pedwarn ("ISO C forbids member declarations with no members");
2032 shadow_tag_warned (specs, pedantic);
2037 /* Support for unnamed structs or unions as members of
2038 structs or unions (which is [a] useful and [b] supports
2040 ret = grokfield (build_id_declarator (NULL_TREE), specs, NULL_TREE);
2044 pending_xref_error ();
2045 prefix_attrs = specs->attrs;
2046 all_prefix_attrs = prefix_attrs;
2047 specs->attrs = NULL_TREE;
2051 /* Declaring one or more declarators or un-named bit-fields. */
2052 struct c_declarator *declarator;
2054 if (c_parser_next_token_is (parser, CPP_COLON))
2055 declarator = build_id_declarator (NULL_TREE);
2057 declarator = c_parser_declarator (parser, specs->type_seen_p,
2058 C_DTR_NORMAL, &dummy);
2059 if (declarator == NULL)
2061 c_parser_skip_to_end_of_block_or_statement (parser);
2064 if (c_parser_next_token_is (parser, CPP_COLON)
2065 || c_parser_next_token_is (parser, CPP_COMMA)
2066 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2067 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2068 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2070 tree postfix_attrs = NULL_TREE;
2071 tree width = NULL_TREE;
2073 if (c_parser_next_token_is (parser, CPP_COLON))
2075 c_parser_consume_token (parser);
2076 width = c_parser_expr_no_commas (parser, NULL).value;
2078 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2079 postfix_attrs = c_parser_attributes (parser);
2080 d = grokfield (declarator, specs, width);
2081 decl_attributes (&d, chainon (postfix_attrs,
2082 all_prefix_attrs), 0);
2083 TREE_CHAIN (d) = decls;
2085 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2086 all_prefix_attrs = chainon (c_parser_attributes (parser),
2089 all_prefix_attrs = prefix_attrs;
2090 if (c_parser_next_token_is (parser, CPP_COMMA))
2091 c_parser_consume_token (parser);
2092 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2093 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2095 /* Semicolon consumed in caller. */
2100 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2106 c_parser_error (parser,
2107 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2108 "%<__attribute__%>");
2115 /* Parse a typeof specifier (a GNU extension).
2118 typeof ( expression )
2119 typeof ( type-name )
2122 static struct c_typespec
2123 c_parser_typeof_specifier (c_parser *parser)
2125 struct c_typespec ret;
2126 ret.kind = ctsk_typeof;
2127 ret.spec = error_mark_node;
2128 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2129 c_parser_consume_token (parser);
2132 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2138 if (c_parser_next_token_starts_typename (parser))
2140 struct c_type_name *type = c_parser_type_name (parser);
2145 ret.spec = groktypename (type);
2146 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2152 struct c_expr expr = c_parser_expression (parser);
2155 if (TREE_CODE (expr.value) == COMPONENT_REF
2156 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2157 error ("%<typeof%> applied to a bit-field");
2158 ret.spec = TREE_TYPE (expr.value);
2159 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2160 /* This should be returned with the type so that when the type
2161 is evaluated, this can be evaluated. For now, we avoid
2162 evaluation when the context might. */
2163 if (!skip_evaluation && was_vm)
2164 c_finish_expr_stmt (expr.value);
2165 pop_maybe_used (was_vm);
2167 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2171 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2172 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2173 be redeclared; otherwise it may not. KIND indicates which kind of
2174 declarator is wanted. Returns a valid declarator except in the
2175 case of a syntax error in which case NULL is returned. *SEEN_ID is
2176 set to true if an identifier being declared is seen; this is used
2177 to diagnose bad forms of abstract array declarators and to
2178 determine whether an identifier list is syntactically permitted.
2181 pointer[opt] direct-declarator
2185 ( attributes[opt] declarator )
2186 direct-declarator array-declarator
2187 direct-declarator ( parameter-type-list )
2188 direct-declarator ( identifier-list[opt] )
2191 * type-qualifier-list[opt]
2192 * type-qualifier-list[opt] pointer
2194 type-qualifier-list:
2197 type-qualifier-list type-qualifier
2198 type-qualifier-list attributes
2200 parameter-type-list:
2202 parameter-list , ...
2205 parameter-declaration
2206 parameter-list , parameter-declaration
2208 parameter-declaration:
2209 declaration-specifiers declarator attributes[opt]
2210 declaration-specifiers abstract-declarator[opt] attributes[opt]
2214 identifier-list , identifier
2216 abstract-declarator:
2218 pointer[opt] direct-abstract-declarator
2220 direct-abstract-declarator:
2221 ( attributes[opt] abstract-declarator )
2222 direct-abstract-declarator[opt] array-declarator
2223 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2228 direct-declarator ( parameter-forward-declarations
2229 parameter-type-list[opt] )
2231 direct-abstract-declarator:
2232 direct-abstract-declarator[opt] ( parameter-forward-declarations
2233 parameter-type-list[opt] )
2235 parameter-forward-declarations:
2237 parameter-forward-declarations parameter-list ;
2239 The uses of attributes shown above are GNU extensions.
2241 Some forms of array declarator are not included in C99 in the
2242 syntax for abstract declarators; these are disallowed elsewhere.
2243 This may be a defect (DR#289).
2245 This function also accepts an omitted abstract declarator as being
2246 an abstract declarator, although not part of the formal syntax. */
2248 static struct c_declarator *
2249 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2252 /* Parse any initial pointer part. */
2253 if (c_parser_next_token_is (parser, CPP_MULT))
2255 struct c_declspecs *quals_attrs = build_null_declspecs ();
2256 struct c_declarator *inner;
2257 c_parser_consume_token (parser);
2258 c_parser_declspecs (parser, quals_attrs, false, false, true);
2259 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2263 return make_pointer_declarator (quals_attrs, inner);
2265 /* Now we have a direct declarator, direct abstract declarator or
2266 nothing (which counts as a direct abstract declarator here). */
2267 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2270 /* Parse a direct declarator or direct abstract declarator; arguments
2271 as c_parser_declarator. */
2273 static struct c_declarator *
2274 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2277 /* The direct declarator must start with an identifier (possibly
2278 omitted) or a parenthesized declarator (possibly abstract). In
2279 an ordinary declarator, initial parentheses must start a
2280 parenthesized declarator. In an abstract declarator or parameter
2281 declarator, they could start a parenthesized declarator or a
2282 parameter list. To tell which, the open parenthesis and any
2283 following attributes must be read. If a declaration specifier
2284 follows, then it is a parameter list; if the specifier is a
2285 typedef name, there might be an ambiguity about redeclaring it,
2286 which is resolved in the direction of treating it as a typedef
2287 name. If a close parenthesis follows, it is also an empty
2288 parameter list, as the syntax does not permit empty abstract
2289 declarators. Otherwise, it is a parenthesized declarator (in
2290 which case the analysis may be repeated inside it, recursively).
2292 ??? There is an ambiguity in a parameter declaration "int
2293 (__attribute__((foo)) x)", where x is not a typedef name: it
2294 could be an abstract declarator for a function, or declare x with
2295 parentheses. The proper resolution of this ambiguity needs
2296 documenting. At present we follow an accident of the old
2297 parser's implementation, whereby the first parameter must have
2298 some declaration specifiers other than just attributes. Thus as
2299 a parameter declaration it is treated as a parenthesized
2300 parameter named x, and as an abstract declarator it is
2303 ??? Also following the old parser, attributes inside an empty
2304 parameter list are ignored, making it a list not yielding a
2305 prototype, rather than giving an error or making it have one
2306 parameter with implicit type int.
2308 ??? Also following the old parser, typedef names may be
2309 redeclared in declarators, but not Objective-C class names. */
2311 if (kind != C_DTR_ABSTRACT
2312 && c_parser_next_token_is (parser, CPP_NAME)
2314 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2315 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2317 struct c_declarator *inner
2318 = build_id_declarator (c_parser_peek_token (parser)->value);
2320 inner->id_loc = c_parser_peek_token (parser)->location;
2321 c_parser_consume_token (parser);
2322 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2325 if (kind != C_DTR_NORMAL
2326 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2328 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2329 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2332 /* Either we are at the end of an abstract declarator, or we have
2335 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2338 struct c_declarator *inner;
2339 c_parser_consume_token (parser);
2340 attrs = c_parser_attributes (parser);
2341 if (kind != C_DTR_NORMAL
2342 && (c_parser_next_token_starts_declspecs (parser)
2343 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2345 struct c_arg_info *args
2346 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2353 = build_function_declarator (args,
2354 build_id_declarator (NULL_TREE));
2355 return c_parser_direct_declarator_inner (parser, *seen_id,
2359 /* A parenthesized declarator. */
2360 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2361 if (inner != NULL && attrs != NULL)
2362 inner = build_attrs_declarator (attrs, inner);
2363 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2365 c_parser_consume_token (parser);
2369 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2373 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2380 if (kind == C_DTR_NORMAL)
2382 c_parser_error (parser, "expected identifier or %<(%>");
2386 return build_id_declarator (NULL_TREE);
2390 /* Parse part of a direct declarator or direct abstract declarator,
2391 given that some (in INNER) has already been parsed; ID_PRESENT is
2392 true if an identifier is present, false for an abstract
2395 static struct c_declarator *
2396 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2397 struct c_declarator *inner)
2399 /* Parse a sequence of array declarators and parameter lists. */
2400 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2402 struct c_declarator *declarator;
2403 struct c_declspecs *quals_attrs = build_null_declspecs ();
2407 c_parser_consume_token (parser);
2408 c_parser_declspecs (parser, quals_attrs, false, false, true);
2409 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2411 c_parser_consume_token (parser);
2412 if (static_seen && !quals_attrs->declspecs_seen_p)
2413 c_parser_declspecs (parser, quals_attrs, false, false, true);
2414 if (!quals_attrs->declspecs_seen_p)
2416 /* If "static" is present, there must be an array dimension.
2417 Otherwise, there may be a dimension, "*", or no
2422 dimen = c_parser_expr_no_commas (parser, NULL).value;
2426 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2431 else if (c_parser_next_token_is (parser, CPP_MULT))
2433 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2437 c_parser_consume_token (parser);
2442 dimen = c_parser_expr_no_commas (parser, NULL).value;
2448 dimen = c_parser_expr_no_commas (parser, NULL).value;
2451 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2452 c_parser_consume_token (parser);
2455 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2459 declarator = build_array_declarator (dimen, quals_attrs, static_seen,
2461 if (declarator == NULL)
2463 inner = set_array_declarator_inner (declarator, inner, !id_present);
2464 return c_parser_direct_declarator_inner (parser, id_present, inner);
2466 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2469 struct c_arg_info *args;
2470 c_parser_consume_token (parser);
2471 attrs = c_parser_attributes (parser);
2472 args = c_parser_parms_declarator (parser, id_present, attrs);
2477 inner = build_function_declarator (args, inner);
2478 return c_parser_direct_declarator_inner (parser, id_present, inner);
2484 /* Parse a parameter list or identifier list, including the closing
2485 parenthesis but not the opening one. ATTRS are the attributes at
2486 the start of the list. ID_LIST_OK is true if an identifier list is
2487 acceptable; such a list must not have attributes at the start. */
2489 static struct c_arg_info *
2490 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2493 declare_parm_level ();
2494 /* If the list starts with an identifier, it is an identifier list.
2495 Otherwise, it is either a prototype list or an empty list. */
2498 && c_parser_next_token_is (parser, CPP_NAME)
2499 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2501 tree list = NULL_TREE, *nextp = &list;
2502 while (c_parser_next_token_is (parser, CPP_NAME)
2503 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2505 *nextp = build_tree_list (NULL_TREE,
2506 c_parser_peek_token (parser)->value);
2507 nextp = & TREE_CHAIN (*nextp);
2508 c_parser_consume_token (parser);
2509 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2511 c_parser_consume_token (parser);
2512 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2514 c_parser_error (parser, "expected identifier");
2518 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2520 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2525 c_parser_consume_token (parser);
2531 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2539 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2545 /* Parse a parameter list (possibly empty), including the closing
2546 parenthesis but not the opening one. ATTRS are the attributes at
2547 the start of the list. */
2549 static struct c_arg_info *
2550 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2552 bool good_parm = false;
2553 /* ??? Following the old parser, forward parameter declarations may
2554 use abstract declarators, and if no real parameter declarations
2555 follow the forward declarations then this is not diagnosed. Also
2556 note as above that attributes are ignored as the only contents of
2557 the parentheses, or as the only contents after forward
2559 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2561 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2566 c_parser_consume_token (parser);
2569 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2571 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2575 /* Suppress -Wold-style-definition for this case. */
2576 ret->types = error_mark_node;
2577 error ("ISO C requires a named argument before %<...%>");
2578 c_parser_consume_token (parser);
2579 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2581 c_parser_consume_token (parser);
2586 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2591 /* Nonempty list of parameters, either terminated with semicolon
2592 (forward declarations; recurse) or with close parenthesis (normal
2593 function) or with ", ... )" (variadic function). */
2596 /* Parse a parameter. */
2597 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2602 push_parm_decl (parm);
2604 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2607 c_parser_consume_token (parser);
2608 mark_forward_parm_decls ();
2609 new_attrs = c_parser_attributes (parser);
2610 return c_parser_parms_list_declarator (parser, new_attrs);
2612 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2614 c_parser_consume_token (parser);
2616 return get_parm_info (false);
2619 struct c_arg_info *ret
2620 = XOBNEW (&parser_obstack, struct c_arg_info);
2628 if (!c_parser_require (parser, CPP_COMMA,
2629 "expected %<;%>, %<,%> or %<)%>"))
2631 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2634 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2636 c_parser_consume_token (parser);
2637 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2639 c_parser_consume_token (parser);
2641 return get_parm_info (true);
2644 struct c_arg_info *ret
2645 = XOBNEW (&parser_obstack, struct c_arg_info);
2655 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2663 /* Parse a parameter declaration. ATTRS are the attributes at the
2664 start of the declaration if it is the first parameter. */
2666 static struct c_parm *
2667 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2669 struct c_declspecs *specs;
2670 struct c_declarator *declarator;
2672 tree postfix_attrs = NULL_TREE;
2674 if (!c_parser_next_token_starts_declspecs (parser))
2676 /* ??? In some Objective-C cases '...' isn't applicable so there
2677 should be a different message. */
2678 c_parser_error (parser,
2679 "expected declaration specifiers or %<...%>");
2680 c_parser_skip_to_end_of_parameter (parser);
2683 specs = build_null_declspecs ();
2686 declspecs_add_attrs (specs, attrs);
2689 c_parser_declspecs (parser, specs, true, true, true);
2690 finish_declspecs (specs);
2691 pending_xref_error ();
2692 prefix_attrs = specs->attrs;
2693 specs->attrs = NULL_TREE;
2694 declarator = c_parser_declarator (parser, specs->type_seen_p,
2695 C_DTR_PARM, &dummy);
2696 if (declarator == NULL)
2698 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2701 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2702 postfix_attrs = c_parser_attributes (parser);
2703 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2707 /* Parse a string literal in an asm expression. It should not be
2708 translated, and wide string literals are an error although
2709 permitted by the syntax. This is a GNU extension.
2714 ??? At present, following the old parser, the caller needs to have
2715 set c_lex_string_translate to 0. It would be better to follow the
2716 C++ parser rather than using the c_lex_string_translate kludge. */
2719 c_parser_asm_string_literal (c_parser *parser)
2722 if (c_parser_next_token_is (parser, CPP_STRING))
2724 str = c_parser_peek_token (parser)->value;
2725 c_parser_consume_token (parser);
2727 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2729 error ("wide string literal in %<asm%>");
2730 str = build_string (1, "");
2731 c_parser_consume_token (parser);
2735 c_parser_error (parser, "expected string literal");
2741 /* Parse a simple asm expression. This is used in restricted
2742 contexts, where a full expression with inputs and outputs does not
2743 make sense. This is a GNU extension.
2746 asm ( asm-string-literal )
2750 c_parser_simple_asm_expr (c_parser *parser)
2753 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2754 /* ??? Follow the C++ parser rather than using the
2755 c_lex_string_translate kludge. */
2756 c_lex_string_translate = 0;
2757 c_parser_consume_token (parser);
2758 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2760 c_lex_string_translate = 1;
2763 str = c_parser_asm_string_literal (parser);
2764 c_lex_string_translate = 1;
2765 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2767 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2773 /* Parse (possibly empty) attributes. This is a GNU extension.
2777 attributes attribute
2780 __attribute__ ( ( attribute-list ) )
2784 attribute_list , attrib
2789 any-word ( identifier )
2790 any-word ( identifier , nonempty-expr-list )
2791 any-word ( expr-list )
2793 where the "identifier" must not be declared as a type, and
2794 "any-word" may be any identifier (including one declared as a
2795 type), a reserved word storage class specifier, type specifier or
2796 type qualifier. ??? This still leaves out most reserved keywords
2797 (following the old parser), shouldn't we include them, and why not
2798 allow identifiers declared as types to start the arguments? */
2801 c_parser_attributes (c_parser *parser)
2803 tree attrs = NULL_TREE;
2804 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2806 /* ??? Follow the C++ parser rather than using the
2807 c_lex_string_translate kludge. */
2808 c_lex_string_translate = 0;
2809 c_parser_consume_token (parser);
2810 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2812 c_lex_string_translate = 1;
2815 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2817 c_lex_string_translate = 1;
2818 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2821 /* Parse the attribute list. */
2822 while (c_parser_next_token_is (parser, CPP_COMMA)
2823 || c_parser_next_token_is (parser, CPP_NAME)
2824 || c_parser_next_token_is (parser, CPP_KEYWORD))
2826 tree attr, attr_name, attr_args;
2827 if (c_parser_next_token_is (parser, CPP_COMMA))
2829 c_parser_consume_token (parser);
2832 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2834 /* ??? See comment above about what keywords are
2837 switch (c_parser_peek_token (parser)->keyword)
2872 attr_name = c_parser_peek_token (parser)->value;
2873 c_parser_consume_token (parser);
2874 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2876 attr = build_tree_list (attr_name, NULL_TREE);
2877 attrs = chainon (attrs, attr);
2880 c_parser_consume_token (parser);
2881 /* Parse the attribute contents. If they start with an
2882 identifier which is followed by a comma or close
2883 parenthesis, then the arguments start with that
2884 identifier; otherwise they are an expression list. */
2885 if (c_parser_next_token_is (parser, CPP_NAME)
2886 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2887 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2888 || (c_parser_peek_2nd_token (parser)->type
2889 == CPP_CLOSE_PAREN)))
2891 tree arg1 = c_parser_peek_token (parser)->value;
2892 c_parser_consume_token (parser);
2893 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2894 attr_args = build_tree_list (NULL_TREE, arg1);
2897 c_parser_consume_token (parser);
2898 attr_args = tree_cons (NULL_TREE, arg1,
2899 c_parser_expr_list (parser, false));
2904 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2905 attr_args = NULL_TREE;
2907 attr_args = c_parser_expr_list (parser, false);
2909 attr = build_tree_list (attr_name, attr_args);
2910 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2911 c_parser_consume_token (parser);
2914 c_lex_string_translate = 1;
2915 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2919 attrs = chainon (attrs, attr);
2921 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2922 c_parser_consume_token (parser);
2925 c_lex_string_translate = 1;
2926 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2930 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2931 c_parser_consume_token (parser);
2934 c_lex_string_translate = 1;
2935 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2939 c_lex_string_translate = 1;
2944 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2947 specifier-qualifier-list abstract-declarator[opt]
2950 static struct c_type_name *
2951 c_parser_type_name (c_parser *parser)
2953 struct c_declspecs *specs = build_null_declspecs ();
2954 struct c_declarator *declarator;
2955 struct c_type_name *ret;
2957 c_parser_declspecs (parser, specs, false, true, true);
2958 if (!specs->declspecs_seen_p)
2960 c_parser_error (parser, "expected specifier-qualifier-list");
2963 pending_xref_error ();
2964 finish_declspecs (specs);
2965 declarator = c_parser_declarator (parser, specs->type_seen_p,
2966 C_DTR_ABSTRACT, &dummy);
2967 if (declarator == NULL)
2969 ret = XOBNEW (&parser_obstack, struct c_type_name);
2971 ret->declarator = declarator;
2975 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2978 assignment-expression
2979 { initializer-list }
2980 { initializer-list , }
2983 designation[opt] initializer
2984 initializer-list , designation[opt] initializer
2991 designator-list designator
2998 [ constant-expression ]
3010 [ constant-expression ... constant-expression ]
3012 Any expression without commas is accepted in the syntax for the
3013 constant-expressions, with non-constant expressions rejected later.
3015 This function is only used for top-level initializers; for nested
3016 ones, see c_parser_initval. */
3018 static struct c_expr
3019 c_parser_initializer (c_parser *parser)
3021 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3022 return c_parser_braced_init (parser, NULL_TREE, false);
3026 ret = c_parser_expr_no_commas (parser, NULL);
3027 if (TREE_CODE (ret.value) != STRING_CST
3028 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3029 ret = default_function_array_conversion (ret);
3034 /* Parse a braced initializer list. TYPE is the type specified for a
3035 compound literal, and NULL_TREE for other initializers and for
3036 nested braced lists. NESTED_P is true for nested braced lists,
3037 false for the list of a compound literal or the list that is the
3038 top-level initializer in a declaration. */
3040 static struct c_expr
3041 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3043 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3044 c_parser_consume_token (parser);
3046 push_init_level (0);
3048 really_start_incremental_init (type);
3049 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3052 pedwarn ("ISO C forbids empty initializer braces");
3056 /* Parse a non-empty initializer list, possibly with a trailing
3060 c_parser_initelt (parser);
3063 if (c_parser_next_token_is (parser, CPP_COMMA))
3064 c_parser_consume_token (parser);
3067 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3071 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3074 ret.value = error_mark_node;
3075 ret.original_code = ERROR_MARK;
3076 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3079 c_parser_consume_token (parser);
3080 return pop_init_level (0);
3083 /* Parse a nested initializer, including designators. */
3086 c_parser_initelt (c_parser *parser)
3088 /* Parse any designator or designator list. A single array
3089 designator may have the subsequent "=" omitted in GNU C, but a
3090 longer list or a structure member designator may not. */
3091 if (c_parser_next_token_is (parser, CPP_NAME)
3092 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3094 /* Old-style structure member designator. */
3095 set_init_label (c_parser_peek_token (parser)->value);
3097 pedwarn ("obsolete use of designated initializer with %<:%>");
3098 c_parser_consume_token (parser);
3099 c_parser_consume_token (parser);
3103 /* des_seen is 0 if there have been no designators, 1 if there
3104 has been a single array designator and 2 otherwise. */
3106 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3107 || c_parser_next_token_is (parser, CPP_DOT))
3109 int des_prev = des_seen;
3112 if (c_parser_next_token_is (parser, CPP_DOT))
3115 c_parser_consume_token (parser);
3116 if (c_parser_next_token_is (parser, CPP_NAME))
3118 set_init_label (c_parser_peek_token (parser)->value);
3119 c_parser_consume_token (parser);
3124 init.value = error_mark_node;
3125 init.original_code = ERROR_MARK;
3126 c_parser_error (parser, "expected identifier");
3127 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3128 process_init_element (init);
3135 /* ??? Following the old parser, [ objc-receiver
3136 objc-message-args ] is accepted as an initializer,
3137 being distinguished from a designator by what follows
3138 the first assignment expression inside the square
3139 brackets, but after a first array designator a
3140 subsequent square bracket is for Objective-C taken to
3141 start an expression, using the obsolete form of
3142 designated initializer without '=', rather than
3143 possibly being a second level of designation: in LALR
3144 terms, the '[' is shifted rather than reducing
3145 designator to designator-list. */
3146 if (des_prev == 1 && c_dialect_objc ())
3148 des_seen = des_prev;
3151 if (des_prev == 0 && c_dialect_objc ())
3153 /* This might be an array designator or an
3154 Objective-C message expression. If the former,
3155 continue parsing here; if the latter, parse the
3156 remainder of the initializer given the starting
3157 primary-expression. ??? It might make sense to
3158 distinguish when des_prev == 1 as well; see
3159 previous comment. */
3161 struct c_expr mexpr;
3162 c_parser_consume_token (parser);
3163 if (c_parser_peek_token (parser)->type == CPP_NAME
3164 && ((c_parser_peek_token (parser)->id_kind
3166 || (c_parser_peek_token (parser)->id_kind
3167 == C_ID_CLASSNAME)))
3169 /* Type name receiver. */
3170 tree id = c_parser_peek_token (parser)->value;
3171 c_parser_consume_token (parser);
3172 rec = objc_get_class_reference (id);
3173 goto parse_message_args;
3175 first = c_parser_expr_no_commas (parser, NULL).value;
3176 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3177 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3178 goto array_desig_after_first;
3179 /* Expression receiver. So far only one part
3180 without commas has been parsed; there might be
3181 more of the expression. */
3183 while (c_parser_next_token_is (parser, CPP_COMMA))
3186 c_parser_consume_token (parser);
3187 next = c_parser_expr_no_commas (parser, NULL);
3188 next = default_function_array_conversion (next);
3189 rec = build_compound_expr (rec, next.value);
3192 /* Now parse the objc-message-args. */
3193 args = c_parser_objc_message_args (parser);
3194 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3197 = objc_build_message_expr (build_tree_list (rec, args));
3198 mexpr.original_code = ERROR_MARK;
3199 /* Now parse and process the remainder of the
3200 initializer, starting with this message
3201 expression as a primary-expression. */
3202 c_parser_initval (parser, &mexpr);
3205 c_parser_consume_token (parser);
3206 first = c_parser_expr_no_commas (parser, NULL).value;
3207 array_desig_after_first:
3208 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3210 c_parser_consume_token (parser);
3211 second = c_parser_expr_no_commas (parser, NULL).value;
3215 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3217 c_parser_consume_token (parser);
3218 set_init_index (first, second);
3219 if (pedantic && second)
3220 pedwarn ("ISO C forbids specifying range of "
3221 "elements to initialize");
3224 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3230 if (c_parser_next_token_is (parser, CPP_EQ))
3232 if (pedantic && !flag_isoc99)
3233 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3234 c_parser_consume_token (parser);
3241 pedwarn ("obsolete use of designated initializer "
3247 init.value = error_mark_node;
3248 init.original_code = ERROR_MARK;
3249 c_parser_error (parser, "expected %<=%>");
3250 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3251 process_init_element (init);
3257 c_parser_initval (parser, NULL);
3260 /* Parse a nested initializer; as c_parser_initializer but parses
3261 initializers within braced lists, after any designators have been
3262 applied. If AFTER is not NULL then it is an Objective-C message
3263 expression which is the primary-expression starting the
3267 c_parser_initval (c_parser *parser, struct c_expr *after)
3270 gcc_assert (!after || c_dialect_objc ());
3271 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3272 init = c_parser_braced_init (parser, NULL_TREE, true);
3275 init = c_parser_expr_no_commas (parser, after);
3276 if (init.value != NULL_TREE
3277 && TREE_CODE (init.value) != STRING_CST
3278 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3279 init = default_function_array_conversion (init);
3281 process_init_element (init);
3284 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3288 { block-item-list[opt] }
3289 { label-declarations block-item-list }
3293 block-item-list block-item
3305 { label-declarations block-item-list }
3308 __extension__ nested-declaration
3309 nested-function-definition
3313 label-declarations label-declaration
3316 __label__ identifier-list ;
3318 Allowing the mixing of declarations and code is new in C99. The
3319 GNU syntax also permits (not shown above) labels at the end of
3320 compound statements, which yield an error. We don't allow labels
3321 on declarations; this might seem like a natural extension, but
3322 there would be a conflict between attributes on the label and
3323 prefix attributes on the declaration. ??? The syntax follows the
3324 old parser in requiring something after label declarations.
3325 Although they are erroneous if the labels declared aren't defined,
3326 is it useful for the syntax to be this way?
3338 c_parser_compound_statement (c_parser *parser)
3341 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3342 return error_mark_node;
3343 stmt = c_begin_compound_stmt (true);
3344 c_parser_compound_statement_nostart (parser);
3345 return c_end_compound_stmt (stmt, true);
3348 /* Parse a compound statement except for the opening brace. This is
3349 used for parsing both compound statements and statement expressions
3350 (which follow different paths to handling the opening). */
3353 c_parser_compound_statement_nostart (c_parser *parser)
3355 bool last_stmt = false;
3356 bool last_label = false;
3357 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3359 c_parser_consume_token (parser);
3362 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3364 /* Read zero or more forward-declarations for labels that nested
3365 functions can jump to. */
3366 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3368 c_parser_consume_token (parser);
3369 /* Any identifiers, including those declared as type names,
3374 if (c_parser_next_token_is_not (parser, CPP_NAME))
3376 c_parser_error (parser, "expected identifier");
3380 = declare_label (c_parser_peek_token (parser)->value);
3381 C_DECLARED_LABEL_FLAG (label) = 1;
3382 add_stmt (build_stmt (DECL_EXPR, label));
3383 c_parser_consume_token (parser);
3384 if (c_parser_next_token_is (parser, CPP_COMMA))
3385 c_parser_consume_token (parser);
3389 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3391 /* ??? Locating this diagnostic on the token after the
3392 declarations end follows the old parser, but it might be
3393 better to locate it where the declarations start instead. */
3395 pedwarn ("ISO C forbids label declarations");
3397 /* We must now have at least one statement, label or declaration. */
3398 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3400 c_parser_error (parser, "expected declaration or statement");
3401 c_parser_consume_token (parser);
3404 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3406 location_t loc = c_parser_peek_token (parser)->location;
3407 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3408 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3409 || (c_parser_next_token_is (parser, CPP_NAME)
3410 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3414 c_parser_label (parser);
3416 else if (!last_label
3417 && c_parser_next_token_starts_declspecs (parser))
3420 c_parser_declaration_or_fndef (parser, true, true, true, true);
3422 && ((pedantic && !flag_isoc99)
3423 || warn_declaration_after_statement))
3424 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3428 else if (!last_label
3429 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3431 /* __extension__ can start a declaration, but is also an
3432 unary operator that can start an expression. Consume all
3433 but the last of a possible series of __extension__ to
3435 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3436 && (c_parser_peek_2nd_token (parser)->keyword
3438 c_parser_consume_token (parser);
3439 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3442 ext = disable_extension_diagnostics ();
3443 c_parser_consume_token (parser);
3445 c_parser_declaration_or_fndef (parser, true, true, true, true);
3446 /* Following the old parser, __extension__ does not
3447 disable this diagnostic. */
3448 restore_extension_diagnostics (ext);
3450 && ((pedantic && !flag_isoc99)
3451 || warn_declaration_after_statement))
3452 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3459 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3461 /* External pragmas, and some omp pragmas, are not associated
3462 with regular c code, and so are not to be considered statements
3463 syntactically. This ensures that the user doesn't put them
3464 places that would turn into syntax errors if the directive
3466 if (c_parser_pragma (parser, pragma_compound))
3467 last_label = false, last_stmt = true;
3469 else if (c_parser_next_token_is (parser, CPP_EOF))
3471 c_parser_error (parser, "expected declaration or statement");
3479 c_parser_statement_after_labels (parser);
3483 error ("label at end of compound statement");
3484 c_parser_consume_token (parser);
3487 /* Parse a label (C90 6.6.1, C99 6.8.1).
3490 identifier : attributes[opt]
3491 case constant-expression :
3497 case constant-expression ... constant-expression :
3499 The use of attributes on labels is a GNU extension. The syntax in
3500 GNU C accepts any expressions without commas, non-constant
3501 expressions being rejected later. */
3504 c_parser_label (c_parser *parser)
3506 location_t loc1 = c_parser_peek_token (parser)->location;
3507 tree label = NULL_TREE;
3508 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3511 c_parser_consume_token (parser);
3512 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3513 if (c_parser_next_token_is (parser, CPP_COLON))
3515 c_parser_consume_token (parser);
3516 label = do_case (exp1, NULL_TREE);
3518 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3520 c_parser_consume_token (parser);
3521 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3522 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3523 label = do_case (exp1, exp2);
3526 c_parser_error (parser, "expected %<:%> or %<...%>");
3528 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3530 c_parser_consume_token (parser);
3531 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3532 label = do_case (NULL_TREE, NULL_TREE);
3536 tree name = c_parser_peek_token (parser)->value;
3540 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3541 c_parser_consume_token (parser);
3542 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3543 loc2 = c_parser_peek_token (parser)->location;
3544 c_parser_consume_token (parser);
3545 attrs = c_parser_attributes (parser);
3546 tlab = define_label (loc2, name);
3549 decl_attributes (&tlab, attrs, 0);
3550 label = add_stmt (build_stmt (LABEL_EXPR, tlab));
3554 SET_EXPR_LOCATION (label, loc1);
3557 /* Parse a statement (C90 6.6, C99 6.8).
3562 expression-statement
3570 expression-statement:
3573 selection-statement:
3577 iteration-statement:
3586 return expression[opt] ;
3599 objc-throw-statement
3600 objc-try-catch-statement
3601 objc-synchronized-statement
3603 objc-throw-statement:
3617 parallel-for-construct
3618 parallel-sections-construct
3625 parallel-directive structured-block
3628 for-directive iteration-statement
3631 sections-directive section-scope
3634 single-directive structured-block
3636 parallel-for-construct:
3637 parallel-for-directive iteration-statement
3639 parallel-sections-construct:
3640 parallel-sections-directive section-scope
3643 master-directive structured-block
3646 critical-directive structured-block
3649 atomic-directive expression-statement
3652 ordered-directive structured-block */
3655 c_parser_statement (c_parser *parser)
3657 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3658 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3659 || (c_parser_next_token_is (parser, CPP_NAME)
3660 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3661 c_parser_label (parser);
3662 c_parser_statement_after_labels (parser);
3665 /* Parse a statement, other than a labeled statement. */
3668 c_parser_statement_after_labels (c_parser *parser)
3670 location_t loc = c_parser_peek_token (parser)->location;
3671 tree stmt = NULL_TREE;
3672 switch (c_parser_peek_token (parser)->type)
3674 case CPP_OPEN_BRACE:
3675 add_stmt (c_parser_compound_statement (parser));
3678 switch (c_parser_peek_token (parser)->keyword)
3681 c_parser_if_statement (parser);
3684 c_parser_switch_statement (parser);
3687 c_parser_while_statement (parser);
3690 c_parser_do_statement (parser);
3693 c_parser_for_statement (parser);
3696 c_parser_consume_token (parser);
3697 if (c_parser_next_token_is (parser, CPP_NAME))
3699 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
3700 c_parser_consume_token (parser);
3702 else if (c_parser_next_token_is (parser, CPP_MULT))
3704 c_parser_consume_token (parser);
3705 stmt = c_finish_goto_ptr (c_parser_expression (parser).value);
3708 c_parser_error (parser, "expected identifier or %<*%>");
3709 goto expect_semicolon;
3711 c_parser_consume_token (parser);
3712 stmt = c_finish_bc_stmt (&c_cont_label, false);
3713 goto expect_semicolon;
3715 c_parser_consume_token (parser);
3716 stmt = c_finish_bc_stmt (&c_break_label, true);
3717 goto expect_semicolon;
3719 c_parser_consume_token (parser);
3720 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3722 stmt = c_finish_return (NULL_TREE);
3723 c_parser_consume_token (parser);
3727 stmt = c_finish_return (c_parser_expression_conv (parser).value);
3728 goto expect_semicolon;
3732 stmt = c_parser_asm_statement (parser);
3735 gcc_assert (c_dialect_objc ());
3736 c_parser_consume_token (parser);
3737 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3739 stmt = objc_build_throw_stmt (NULL_TREE);
3740 c_parser_consume_token (parser);
3745 = objc_build_throw_stmt (c_parser_expression (parser).value);
3746 goto expect_semicolon;
3750 gcc_assert (c_dialect_objc ());
3751 c_parser_objc_try_catch_statement (parser);
3753 case RID_AT_SYNCHRONIZED:
3754 gcc_assert (c_dialect_objc ());
3755 c_parser_objc_synchronized_statement (parser);
3762 c_parser_consume_token (parser);
3764 case CPP_CLOSE_PAREN:
3765 case CPP_CLOSE_SQUARE:
3766 /* Avoid infinite loop in error recovery:
3767 c_parser_skip_until_found stops at a closing nesting
3768 delimiter without consuming it, but here we need to consume
3769 it to proceed further. */
3770 c_parser_error (parser, "expected statement");
3771 c_parser_consume_token (parser);
3774 c_parser_pragma (parser, pragma_stmt);
3778 stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
3780 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3783 /* Two cases cannot and do not have line numbers associated: If stmt
3784 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3785 cannot hold line numbers. But that's OK because the statement
3786 will either be changed to a MODIFY_EXPR during gimplification of
3787 the statement expr, or discarded. If stmt was compound, but
3788 without new variables, we will have skipped the creation of a
3789 BIND and will have a bare STATEMENT_LIST. But that's OK because
3790 (recursively) all of the component statements should already have
3791 line numbers assigned. ??? Can we discard no-op statements
3793 if (stmt && EXPR_P (stmt))
3794 SET_EXPR_LOCATION (stmt, loc);
3797 /* Parse a parenthesized condition from an if, do or while statement.
3803 c_parser_paren_condition (c_parser *parser)
3807 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3808 return error_mark_node;
3809 loc = c_parser_peek_token (parser)->location;
3810 cond = c_objc_common_truthvalue_conversion
3811 (c_parser_expression_conv (parser).value);
3813 SET_EXPR_LOCATION (cond, loc);
3814 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3818 /* Parse a statement which is a block in C99. */
3821 c_parser_c99_block_statement (c_parser *parser)
3823 tree block = c_begin_compound_stmt (flag_isoc99);
3824 c_parser_statement (parser);
3825 return c_end_compound_stmt (block, flag_isoc99);
3828 /* Parse the body of an if statement or the else half thereof. This
3829 is just parsing a statement but (a) it is a block in C99, (b) we
3830 track whether the body is an if statement for the sake of
3831 -Wparentheses warnings, (c) we handle an empty body specially for
3832 the sake of -Wextra warnings. */
3835 c_parser_if_body (c_parser *parser, bool *if_p)
3837 tree block = c_begin_compound_stmt (flag_isoc99);
3838 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3839 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3840 || (c_parser_next_token_is (parser, CPP_NAME)
3841 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3842 c_parser_label (parser);
3843 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3844 if (extra_warnings && c_parser_next_token_is (parser, CPP_SEMICOLON))
3845 add_stmt (build_empty_stmt ());
3846 c_parser_statement_after_labels (parser);
3847 return c_end_compound_stmt (block, flag_isoc99);
3850 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3853 if ( expression ) statement
3854 if ( expression ) statement else statement
3858 c_parser_if_statement (c_parser *parser)
3863 bool first_if = false, second_if = false;
3864 tree first_body, second_body;
3865 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
3866 c_parser_consume_token (parser);
3867 block = c_begin_compound_stmt (flag_isoc99);
3868 loc = c_parser_peek_token (parser)->location;
3869 cond = c_parser_paren_condition (parser);
3870 first_body = c_parser_if_body (parser, &first_if);
3871 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3873 c_parser_consume_token (parser);
3874 second_body = c_parser_if_body (parser, &second_if);
3877 second_body = NULL_TREE;
3878 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
3879 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3882 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3885 switch (expression) statement
3889 c_parser_switch_statement (c_parser *parser)
3891 tree block, expr, body, save_break;
3892 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
3893 c_parser_consume_token (parser);
3894 block = c_begin_compound_stmt (flag_isoc99);
3895 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3897 expr = c_parser_expression (parser).value;
3898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3901 expr = error_mark_node;
3902 c_start_case (expr);
3903 save_break = c_break_label;
3904 c_break_label = NULL_TREE;
3905 body = c_parser_c99_block_statement (parser);
3906 c_finish_case (body);
3908 add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
3909 c_break_label = save_break;
3910 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3913 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3916 while (expression) statement
3920 c_parser_while_statement (c_parser *parser)
3922 tree block, cond, body, save_break, save_cont;
3924 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
3925 c_parser_consume_token (parser);
3926 block = c_begin_compound_stmt (flag_isoc99);
3927 loc = c_parser_peek_token (parser)->location;
3928 cond = c_parser_paren_condition (parser);
3929 save_break = c_break_label;
3930 c_break_label = NULL_TREE;
3931 save_cont = c_cont_label;
3932 c_cont_label = NULL_TREE;
3933 body = c_parser_c99_block_statement (parser);
3934 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
3935 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3936 c_break_label = save_break;
3937 c_cont_label = save_cont;
3940 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3943 do statement while ( expression ) ;
3947 c_parser_do_statement (c_parser *parser)
3949 tree block, cond, body, save_break, save_cont, new_break, new_cont;
3951 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
3952 c_parser_consume_token (parser);
3953 block = c_begin_compound_stmt (flag_isoc99);
3954 loc = c_parser_peek_token (parser)->location;
3955 save_break = c_break_label;
3956 c_break_label = NULL_TREE;
3957 save_cont = c_cont_label;
3958 c_cont_label = NULL_TREE;
3959 body = c_parser_c99_block_statement (parser);
3960 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
3961 new_break = c_break_label;
3962 c_break_label = save_break;
3963 new_cont = c_cont_label;
3964 c_cont_label = save_cont;
3965 cond = c_parser_paren_condition (parser);
3966 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
3967 c_parser_skip_to_end_of_block_or_statement (parser);
3968 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
3969 add_stmt (c_end_compound_stmt (block, flag_isoc99));
3972 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3975 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3976 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3978 The form with a declaration is new in C99.
3980 ??? In accordance with the old parser, the declaration may be a
3981 nested function, which is then rejected in check_for_loop_decls,
3982 but does it make any sense for this to be included in the grammar?
3983 Note in particular that the nested function does not include a
3984 trailing ';', whereas the "declaration" production includes one.
3985 Also, can we reject bad declarations earlier and cheaper than
3986 check_for_loop_decls? */
3989 c_parser_for_statement (c_parser *parser)
3991 tree block, cond, incr, save_break, save_cont, body;
3993 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
3994 loc = c_parser_peek_token (parser)->location;
3995 c_parser_consume_token (parser);
3996 block = c_begin_compound_stmt (flag_isoc99);
3997 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3999 /* Parse the initialization declaration or expression. */
4000 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4002 c_parser_consume_token (parser);
4003 c_finish_expr_stmt (NULL_TREE);
4005 else if (c_parser_next_token_starts_declspecs (parser))
4007 c_parser_declaration_or_fndef (parser, true, true, true, true);
4008 check_for_loop_decls ();
4010 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4012 /* __extension__ can start a declaration, but is also an
4013 unary operator that can start an expression. Consume all
4014 but the last of a possible series of __extension__ to
4016 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4017 && (c_parser_peek_2nd_token (parser)->keyword
4019 c_parser_consume_token (parser);
4020 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4023 ext = disable_extension_diagnostics ();
4024 c_parser_consume_token (parser);
4025 c_parser_declaration_or_fndef (parser, true, true, true, true);
4026 restore_extension_diagnostics (ext);
4027 check_for_loop_decls ();
4035 c_finish_expr_stmt (c_parser_expression (parser).value);
4036 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4038 /* Parse the loop condition. */
4039 loc = c_parser_peek_token (parser)->location;
4040 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4042 c_parser_consume_token (parser);
4047 tree ocond = c_parser_expression_conv (parser).value;
4048 cond = c_objc_common_truthvalue_conversion (ocond);
4050 SET_EXPR_LOCATION (cond, loc);
4051 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4053 /* Parse the increment expression. */
4054 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4055 incr = c_process_expr_stmt (NULL_TREE);
4057 incr = c_process_expr_stmt (c_parser_expression (parser).value);
4058 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4062 cond = error_mark_node;
4063 incr = error_mark_node;
4065 save_break = c_break_label;
4066 c_break_label = NULL_TREE;
4067 save_cont = c_cont_label;
4068 c_cont_label = NULL_TREE;
4069 body = c_parser_c99_block_statement (parser);
4070 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4071 add_stmt (c_end_compound_stmt (block, flag_isoc99));
4072 c_break_label = save_break;
4073 c_cont_label = save_cont;
4076 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4077 statement with inputs, outputs, clobbers, and volatile tag
4081 asm type-qualifier[opt] ( asm-argument ) ;
4085 asm-string-literal : asm-operands[opt]
4086 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4087 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4089 Qualifiers other than volatile are accepted in the syntax but
4093 c_parser_asm_statement (c_parser *parser)
4095 tree quals, str, outputs, inputs, clobbers, ret;
4097 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4098 c_parser_consume_token (parser);
4099 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4101 quals = c_parser_peek_token (parser)->value;
4102 c_parser_consume_token (parser);
4104 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4105 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4107 warning (0, "%E qualifier ignored on asm",
4108 c_parser_peek_token (parser)->value);
4110 c_parser_consume_token (parser);
4114 /* ??? Follow the C++ parser rather than using the
4115 c_lex_string_translate kludge. */
4116 c_lex_string_translate = 0;
4117 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4119 c_lex_string_translate = 1;
4122 str = c_parser_asm_string_literal (parser);
4123 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4126 outputs = NULL_TREE;
4128 clobbers = NULL_TREE;
4131 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4133 c_lex_string_translate = 1;
4134 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4138 /* Parse outputs. */
4139 if (c_parser_next_token_is (parser, CPP_COLON)
4140 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4141 outputs = NULL_TREE;
4143 outputs = c_parser_asm_operands (parser, false);
4144 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4147 clobbers = NULL_TREE;
4150 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4152 c_lex_string_translate = 1;
4153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4157 if (c_parser_next_token_is (parser, CPP_COLON)
4158 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4161 inputs = c_parser_asm_operands (parser, true);
4162 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4164 clobbers = NULL_TREE;
4167 if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>"))
4169 c_lex_string_translate = 1;
4170 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4173 /* Parse clobbers. */
4174 clobbers = c_parser_asm_clobbers (parser);
4176 c_lex_string_translate = 1;
4177 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4179 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4182 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4183 c_parser_skip_to_end_of_block_or_statement (parser);
4184 ret = build_asm_stmt (quals, build_asm_expr (str, outputs, inputs,
4189 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4190 not outputs), apply the default conversion of functions and arrays
4195 asm-operands , asm-operand
4198 asm-string-literal ( expression )
4199 [ identifier ] asm-string-literal ( expression )
4203 c_parser_asm_operands (c_parser *parser, bool convert_p)
4205 tree list = NULL_TREE;
4210 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4212 c_parser_consume_token (parser);
4213 if (c_parser_next_token_is (parser, CPP_NAME))
4215 tree id = c_parser_peek_token (parser)->value;
4216 c_parser_consume_token (parser);
4217 name = build_string (IDENTIFIER_LENGTH (id),
4218 IDENTIFIER_POINTER (id));
4222 c_parser_error (parser, "expected identifier");
4223 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4226 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4231 str = c_parser_asm_string_literal (parser);
4232 if (str == NULL_TREE)
4234 c_lex_string_translate = 1;
4235 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4237 c_lex_string_translate = 0;
4240 expr = c_parser_expression (parser);
4242 expr = default_function_array_conversion (expr);
4243 c_lex_string_translate = 0;
4244 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4246 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4249 list = chainon (list, build_tree_list (build_tree_list (name, str),
4251 if (c_parser_next_token_is (parser, CPP_COMMA))
4252 c_parser_consume_token (parser);
4259 /* Parse asm clobbers, a GNU extension.
4263 asm-clobbers , asm-string-literal
4267 c_parser_asm_clobbers (c_parser *parser)
4269 tree list = NULL_TREE;
4272 tree str = c_parser_asm_string_literal (parser);
4274 list = tree_cons (NULL_TREE, str, list);
4277 if (c_parser_next_token_is (parser, CPP_COMMA))
4278 c_parser_consume_token (parser);
4285 /* Parse an expression other than a compound expression; that is, an
4286 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4287 NULL then it is an Objective-C message expression which is the
4288 primary-expression starting the expression as an initializer.
4290 assignment-expression:
4291 conditional-expression
4292 unary-expression assignment-operator assignment-expression
4294 assignment-operator: one of
4295 = *= /= %= += -= <<= >>= &= ^= |=
4297 In GNU C we accept any conditional expression on the LHS and
4298 diagnose the invalid lvalue rather than producing a syntax
4301 static struct c_expr
4302 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4304 struct c_expr lhs, rhs, ret;
4305 enum tree_code code;
4306 gcc_assert (!after || c_dialect_objc ());
4307 lhs = c_parser_conditional_expression (parser, after);
4308 switch (c_parser_peek_token (parser)->type)
4317 code = TRUNC_DIV_EXPR;
4320 code = TRUNC_MOD_EXPR;
4335 code = BIT_AND_EXPR;
4338 code = BIT_XOR_EXPR;
4341 code = BIT_IOR_EXPR;
4346 c_parser_consume_token (parser);
4347 rhs = c_parser_expr_no_commas (parser, NULL);
4348 rhs = default_function_array_conversion (rhs);
4349 ret.value = build_modify_expr (lhs.value, code, rhs.value);
4350 if (code == NOP_EXPR)
4351 ret.original_code = MODIFY_EXPR;
4354 TREE_NO_WARNING (ret.value) = 1;
4355 ret.original_code = ERROR_MARK;
4360 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4361 is not NULL then it is an Objective-C message expression which is
4362 the primary-expression starting the expression as an initializer.
4364 conditional-expression:
4365 logical-OR-expression
4366 logical-OR-expression ? expression : conditional-expression
4370 conditional-expression:
4371 logical-OR-expression ? : conditional-expression
4374 static struct c_expr
4375 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4377 struct c_expr cond, exp1, exp2, ret;
4378 gcc_assert (!after || c_dialect_objc ());
4379 cond = c_parser_binary_expression (parser, after);
4380 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4382 cond = default_function_array_conversion (cond);
4383 c_parser_consume_token (parser);
4384 if (c_parser_next_token_is (parser, CPP_COLON))
4387 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4388 /* Make sure first operand is calculated only once. */
4389 exp1.value = save_expr (default_conversion (cond.value));
4390 cond.value = c_objc_common_truthvalue_conversion (exp1.value);
4391 skip_evaluation += cond.value == truthvalue_true_node;
4396 = c_objc_common_truthvalue_conversion
4397 (default_conversion (cond.value));
4398 skip_evaluation += cond.value == truthvalue_false_node;
4399 exp1 = c_parser_expression_conv (parser);
4400 skip_evaluation += ((cond.value == truthvalue_true_node)
4401 - (cond.value == truthvalue_false_node));
4403 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4405 skip_evaluation -= cond.value == truthvalue_true_node;
4406 ret.value = error_mark_node;
4407 ret.original_code = ERROR_MARK;
4410 exp2 = c_parser_conditional_expression (parser, NULL);
4411 exp2 = default_function_array_conversion (exp2);
4412 skip_evaluation -= cond.value == truthvalue_true_node;
4413 ret.value = build_conditional_expr (cond.value, exp1.value, exp2.value);
4414 ret.original_code = ERROR_MARK;
4418 /* Parse a binary expression; that is, a logical-OR-expression (C90
4419 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4420 an Objective-C message expression which is the primary-expression
4421 starting the expression as an initializer.
4423 multiplicative-expression:
4425 multiplicative-expression * cast-expression
4426 multiplicative-expression / cast-expression
4427 multiplicative-expression % cast-expression
4429 additive-expression:
4430 multiplicative-expression
4431 additive-expression + multiplicative-expression
4432 additive-expression - multiplicative-expression
4436 shift-expression << additive-expression
4437 shift-expression >> additive-expression
4439 relational-expression:
4441 relational-expression < shift-expression
4442 relational-expression > shift-expression
4443 relational-expression <= shift-expression
4444 relational-expression >= shift-expression
4446 equality-expression:
4447 relational-expression
4448 equality-expression == relational-expression
4449 equality-expression != relational-expression
4453 AND-expression & equality-expression
4455 exclusive-OR-expression:
4457 exclusive-OR-expression ^ AND-expression
4459 inclusive-OR-expression:
4460 exclusive-OR-expression
4461 inclusive-OR-expression | exclusive-OR-expression
4463 logical-AND-expression:
4464 inclusive-OR-expression
4465 logical-AND-expression && inclusive-OR-expression
4467 logical-OR-expression:
4468 logical-AND-expression
4469 logical-OR-expression || logical-AND-expression
4472 static struct c_expr
4473 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4475 /* A binary expression is parsed using operator-precedence parsing,
4476 with the operands being cast expressions. All the binary
4477 operators are left-associative. Thus a binary expression is of
4480 E0 op1 E1 op2 E2 ...
4482 which we represent on a stack. On the stack, the precedence
4483 levels are strictly increasing. When a new operator is
4484 encountered of higher precedence than that at the top of the
4485 stack, it is pushed; its LHS is the top expression, and its RHS
4486 is everything parsed until it is popped. When a new operator is
4487 encountered with precedence less than or equal to that at the top
4488 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4489 by the result of the operation until the operator at the top of
4490 the stack has lower precedence than the new operator or there is
4491 only one element on the stack; then the top expression is the LHS
4492 of the new operator. In the case of logical AND and OR
4493 expressions, we also need to adjust skip_evaluation as
4494 appropriate when the operators are pushed and popped. */
4496 /* The precedence levels, where 0 is a dummy lowest level used for
4497 the bottom of the stack. */
4513 /* The expression at this stack level. */
4515 /* The precedence of the operator on its left, PREC_NONE at the
4516 bottom of the stack. */
4518 /* The operation on its left. */
4524 switch (stack[sp].op) \
4526 case TRUTH_ANDIF_EXPR: \
4527 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4529 case TRUTH_ORIF_EXPR: \
4530 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4535 stack[sp - 1].expr \
4536 = default_function_array_conversion (stack[sp - 1].expr); \
4538 = default_function_array_conversion (stack[sp].expr); \
4539 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4540 stack[sp - 1].expr, \
4544 gcc_assert (!after || c_dialect_objc ());
4545 stack[0].expr = c_parser_cast_expression (parser, after);
4546 stack[0].prec = PREC_NONE;
4551 enum tree_code ocode;
4554 switch (c_parser_peek_token (parser)->type)
4562 ocode = TRUNC_DIV_EXPR;
4566 ocode = TRUNC_MOD_EXPR;
4578 ocode = LSHIFT_EXPR;
4582 ocode = RSHIFT_EXPR;
4596 case CPP_GREATER_EQ:
4609 oprec = PREC_BITAND;
4610 ocode = BIT_AND_EXPR;
4613 oprec = PREC_BITXOR;
4614 ocode = BIT_XOR_EXPR;
4618 ocode = BIT_IOR_EXPR;
4621 oprec = PREC_LOGAND;
4622 ocode = TRUTH_ANDIF_EXPR;
4626 ocode = TRUTH_ORIF_EXPR;
4629 /* Not a binary operator, so end of the binary
4633 c_parser_consume_token (parser);
4634 while (oprec <= stack[sp].prec)
4638 case TRUTH_ANDIF_EXPR:
4640 = default_function_array_conversion (stack[sp].expr);
4641 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4642 (default_conversion (stack[sp].expr.value));
4643 skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
4645 case TRUTH_ORIF_EXPR:
4647 = default_function_array_conversion (stack[sp].expr);
4648 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4649 (default_conversion (stack[sp].expr.value));
4650 skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
4656 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4657 stack[sp].prec = oprec;
4658 stack[sp].op = ocode;
4663 return stack[0].expr;
4667 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4668 NULL then it is an Objective-C message expression which is the
4669 primary-expression starting the expression as an initializer.
4673 ( type-name ) unary-expression
4676 static struct c_expr
4677 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4679 gcc_assert (!after || c_dialect_objc ());
4681 return c_parser_postfix_expression_after_primary (parser, *after);
4682 /* If the expression begins with a parenthesized type name, it may
4683 be either a cast or a compound literal; we need to see whether
4684 the next character is '{' to tell the difference. If not, it is
4685 an unary expression. */
4686 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4687 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4689 struct c_type_name *type_name;
4692 c_parser_consume_token (parser);
4693 type_name = c_parser_type_name (parser);
4694 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4695 if (type_name == NULL)
4697 ret.value = error_mark_node;
4698 ret.original_code = ERROR_MARK;
4702 /* Save casted types in the function's used types hash table. */
4703 used_types_insert (type_name->specs->type);
4705 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4706 return c_parser_postfix_expression_after_paren_type (parser,
4708 expr = c_parser_cast_expression (parser, NULL);
4709 expr = default_function_array_conversion (expr);
4710 ret.value = c_cast_expr (type_name, expr.value);
4711 ret.original_code = ERROR_MARK;
4715 return c_parser_unary_expression (parser);
4718 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4724 unary-operator cast-expression
4725 sizeof unary-expression
4726 sizeof ( type-name )
4728 unary-operator: one of
4734 __alignof__ unary-expression
4735 __alignof__ ( type-name )
4738 unary-operator: one of
4739 __extension__ __real__ __imag__
4741 In addition, the GNU syntax treats ++ and -- as unary operators, so
4742 they may be applied to cast expressions with errors for non-lvalues
4745 static struct c_expr
4746 c_parser_unary_expression (c_parser *parser)
4749 struct c_expr ret, op;
4750 switch (c_parser_peek_token (parser)->type)
4753 c_parser_consume_token (parser);
4754 op = c_parser_cast_expression (parser, NULL);
4755 op = default_function_array_conversion (op);
4756 return parser_build_unary_op (PREINCREMENT_EXPR, op);
4757 case CPP_MINUS_MINUS:
4758 c_parser_consume_token (parser);
4759 op = c_parser_cast_expression (parser, NULL);
4760 op = default_function_array_conversion (op);
4761 return parser_build_unary_op (PREDECREMENT_EXPR, op);
4763 c_parser_consume_token (parser);
4764 return parser_build_unary_op (ADDR_EXPR,
4765 c_parser_cast_expression (parser, NULL));
4767 c_parser_consume_token (parser);
4768 op = c_parser_cast_expression (parser, NULL);
4769 op = default_function_array_conversion (op);
4770 ret.value = build_indirect_ref (op.value, "unary *");
4771 ret.original_code = ERROR_MARK;
4774 c_parser_consume_token (parser);
4775 if (!c_dialect_objc () && !in_system_header)
4776 warning (OPT_Wtraditional,
4777 "traditional C rejects the unary plus operator");
4778 op = c_parser_cast_expression (parser, NULL);
4779 op = default_function_array_conversion (op);
4780 return parser_build_unary_op (CONVERT_EXPR, op);
4782 c_parser_consume_token (parser);
4783 op = c_parser_cast_expression (parser, NULL);
4784 op = default_function_array_conversion (op);
4785 return parser_build_unary_op (NEGATE_EXPR, op);
4787 c_parser_consume_token (parser);
4788 op = c_parser_cast_expression (parser, NULL);
4789 op = default_function_array_conversion (op);
4790 return parser_build_unary_op (BIT_NOT_EXPR, op);
4792 c_parser_consume_token (parser);
4793 op = c_parser_cast_expression (parser, NULL);
4794 op = default_function_array_conversion (op);
4795 return parser_build_unary_op (TRUTH_NOT_EXPR, op);
4797 /* Refer to the address of a label as a pointer. */
4798 c_parser_consume_token (parser);
4799 if (c_parser_next_token_is (parser, CPP_NAME))
4801 ret.value = finish_label_address_expr
4802 (c_parser_peek_token (parser)->value);
4803 c_parser_consume_token (parser);
4807 c_parser_error (parser, "expected identifier");
4808 ret.value = error_mark_node;
4810 ret.original_code = ERROR_MARK;
4813 switch (c_parser_peek_token (parser)->keyword)
4816 return c_parser_sizeof_expression (parser);
4818 return c_parser_alignof_expression (parser);
4820 c_parser_consume_token (parser);
4821 ext = disable_extension_diagnostics ();
4822 ret = c_parser_cast_expression (parser, NULL);
4823 restore_extension_diagnostics (ext);
4826 c_parser_consume_token (parser);
4827 op = c_parser_cast_expression (parser, NULL);
4828 op = default_function_array_conversion (op);
4829 return parser_build_unary_op (REALPART_EXPR, op);
4831 c_parser_consume_token (parser);
4832 op = c_parser_cast_expression (parser, NULL);
4833 op = default_function_array_conversion (op);
4834 return parser_build_unary_op (IMAGPART_EXPR, op);
4836 return c_parser_postfix_expression (parser);
4839 return c_parser_postfix_expression (parser);
4843 /* Parse a sizeof expression. */
4845 static struct c_expr
4846 c_parser_sizeof_expression (c_parser *parser)
4849 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
4850 c_parser_consume_token (parser);
4853 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4854 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4856 /* Either sizeof ( type-name ) or sizeof unary-expression
4857 starting with a compound literal. */
4858 struct c_type_name *type_name;
4859 c_parser_consume_token (parser);
4860 type_name = c_parser_type_name (parser);
4861 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4862 if (type_name == NULL)
4867 ret.value = error_mark_node;
4868 ret.original_code = ERROR_MARK;
4871 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4873 expr = c_parser_postfix_expression_after_paren_type (parser,
4877 /* sizeof ( type-name ). */
4880 if (type_name->declarator->kind == cdk_array
4881 && type_name->declarator->u.array.vla_unspec_p)
4884 error ("%<[*]%> not allowed in other than a declaration");
4886 return c_expr_sizeof_type (type_name);
4890 expr = c_parser_unary_expression (parser);
4894 if (TREE_CODE (expr.value) == COMPONENT_REF
4895 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
4896 error ("%<sizeof%> applied to a bit-field");
4897 return c_expr_sizeof_expr (expr);
4901 /* Parse an alignof expression. */
4903 static struct c_expr
4904 c_parser_alignof_expression (c_parser *parser)
4907 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
4908 c_parser_consume_token (parser);
4911 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4912 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4914 /* Either __alignof__ ( type-name ) or __alignof__
4915 unary-expression starting with a compound literal. */
4916 struct c_type_name *type_name;
4918 c_parser_consume_token (parser);
4919 type_name = c_parser_type_name (parser);
4920 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4921 if (type_name == NULL)
4926 ret.value = error_mark_node;
4927 ret.original_code = ERROR_MARK;
4930 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4932 expr = c_parser_postfix_expression_after_paren_type (parser,
4936 /* alignof ( type-name ). */
4939 ret.value = c_alignof (groktypename (type_name));
4940 ret.original_code = ERROR_MARK;
4946 expr = c_parser_unary_expression (parser);
4950 ret.value = c_alignof_expr (expr.value);
4951 ret.original_code = ERROR_MARK;
4956 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4960 postfix-expression [ expression ]
4961 postfix-expression ( argument-expression-list[opt] )
4962 postfix-expression . identifier
4963 postfix-expression -> identifier
4964 postfix-expression ++
4965 postfix-expression --
4966 ( type-name ) { initializer-list }
4967 ( type-name ) { initializer-list , }
4969 argument-expression-list:
4971 argument-expression-list , argument-expression
4983 (treated as a keyword in GNU C)
4986 ( compound-statement )
4987 __builtin_va_arg ( assignment-expression , type-name )
4988 __builtin_offsetof ( type-name , offsetof-member-designator )
4989 __builtin_choose_expr ( assignment-expression ,
4990 assignment-expression ,
4991 assignment-expression )
4992 __builtin_types_compatible_p ( type-name , type-name )
4994 offsetof-member-designator:
4996 offsetof-member-designator . identifier
4997 offsetof-member-designator [ expression ]
5002 [ objc-receiver objc-message-args ]
5003 @selector ( objc-selector-arg )
5004 @protocol ( identifier )
5005 @encode ( type-name )
5009 static struct c_expr
5010 c_parser_postfix_expression (c_parser *parser)
5012 struct c_expr expr, e1, e2, e3;
5013 struct c_type_name *t1, *t2;
5014 switch (c_parser_peek_token (parser)->type)
5019 expr.value = c_parser_peek_token (parser)->value;
5020 expr.original_code = ERROR_MARK;
5021 c_parser_consume_token (parser);
5025 expr.value = c_parser_peek_token (parser)->value;
5026 expr.original_code = STRING_CST;
5027 c_parser_consume_token (parser);
5029 case CPP_OBJC_STRING:
5030 gcc_assert (c_dialect_objc ());
5032 = objc_build_string_object (c_parser_peek_token (parser)->value);
5033 expr.original_code = ERROR_MARK;
5034 c_parser_consume_token (parser);
5037 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5039 c_parser_error (parser, "expected expression");
5040 expr.value = error_mark_node;
5041 expr.original_code = ERROR_MARK;
5045 tree id = c_parser_peek_token (parser)->value;
5046 location_t loc = c_parser_peek_token (parser)->location;
5047 c_parser_consume_token (parser);
5048 expr.value = build_external_ref (id,
5049 (c_parser_peek_token (parser)->type
5050 == CPP_OPEN_PAREN), loc);
5051 expr.original_code = ERROR_MARK;
5054 case CPP_OPEN_PAREN:
5055 /* A parenthesized expression, statement expression or compound
5057 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5059 /* A statement expression. */
5061 c_parser_consume_token (parser);
5062 c_parser_consume_token (parser);
5063 if (cur_stmt_list == NULL)
5065 error ("braced-group within expression allowed "
5066 "only inside a function");
5067 parser->error = true;
5068 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5069 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5070 expr.value = error_mark_node;
5071 expr.original_code = ERROR_MARK;
5074 stmt = c_begin_stmt_expr ();
5075 c_parser_compound_statement_nostart (parser);
5076 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5079 pedwarn ("ISO C forbids braced-groups within expressions");
5080 expr.value = c_finish_stmt_expr (stmt);
5081 expr.original_code = ERROR_MARK;
5083 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5085 /* A compound literal. ??? Can we actually get here rather
5086 than going directly to
5087 c_parser_postfix_expression_after_paren_type from
5089 struct c_type_name *type_name;
5090 c_parser_consume_token (parser);
5091 type_name = c_parser_type_name (parser);
5092 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5094 if (type_name == NULL)
5096 expr.value = error_mark_node;
5097 expr.original_code = ERROR_MARK;
5100 expr = c_parser_postfix_expression_after_paren_type (parser,
5105 /* A parenthesized expression. */
5106 c_parser_consume_token (parser);
5107 expr = c_parser_expression (parser);
5108 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5109 TREE_NO_WARNING (expr.value) = 1;
5110 expr.original_code = ERROR_MARK;
5111 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5116 switch (c_parser_peek_token (parser)->keyword)
5118 case RID_FUNCTION_NAME:
5119 case RID_PRETTY_FUNCTION_NAME:
5120 case RID_C99_FUNCTION_NAME:
5121 expr.value = fname_decl (c_parser_peek_token (parser)->keyword,
5122 c_parser_peek_token (parser)->value);
5123 expr.original_code = ERROR_MARK;
5124 c_parser_consume_token (parser);
5127 c_parser_consume_token (parser);
5128 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5130 expr.value = error_mark_node;
5131 expr.original_code = ERROR_MARK;
5134 e1 = c_parser_expr_no_commas (parser, NULL);
5135 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5137 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5138 expr.value = error_mark_node;
5139 expr.original_code = ERROR_MARK;
5142 t1 = c_parser_type_name (parser);
5143 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5147 expr.value = error_mark_node;
5148 expr.original_code = ERROR_MARK;
5152 expr.value = build_va_arg (e1.value, groktypename (t1));
5153 expr.original_code = ERROR_MARK;
5157 c_parser_consume_token (parser);
5158 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5160 expr.value = error_mark_node;
5161 expr.original_code = ERROR_MARK;
5164 t1 = c_parser_type_name (parser);
5167 expr.value = error_mark_node;
5168 expr.original_code = ERROR_MARK;
5171 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5173 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5174 expr.value = error_mark_node;
5175 expr.original_code = ERROR_MARK;
5179 tree type = groktypename (t1);
5181 if (type == error_mark_node)
5182 offsetof_ref = error_mark_node;
5184 offsetof_ref = build1 (INDIRECT_REF, type, NULL);
5185 /* Parse the second argument to __builtin_offsetof. We
5186 must have one identifier, and beyond that we want to
5187 accept sub structure and sub array references. */
5188 if (c_parser_next_token_is (parser, CPP_NAME))
5190 offsetof_ref = build_component_ref
5191 (offsetof_ref, c_parser_peek_token (parser)->value);
5192 c_parser_consume_token (parser);
5193 while (c_parser_next_token_is (parser, CPP_DOT)
5194 || c_parser_next_token_is (parser,
5197 if (c_parser_next_token_is (parser, CPP_DOT))
5199 c_parser_consume_token (parser);
5200 if (c_parser_next_token_is_not (parser,
5203 c_parser_error (parser, "expected identifier");
5206 offsetof_ref = build_component_ref
5208 c_parser_peek_token (parser)->value);
5209 c_parser_consume_token (parser);
5214 c_parser_consume_token (parser);
5215 idx = c_parser_expression (parser).value;
5216 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5218 offsetof_ref = build_array_ref (offsetof_ref, idx);
5223 c_parser_error (parser, "expected identifier");
5224 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5226 expr.value = fold_offsetof (offsetof_ref);
5227 expr.original_code = ERROR_MARK;
5230 case RID_CHOOSE_EXPR:
5231 c_parser_consume_token (parser);
5232 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5234 expr.value = error_mark_node;
5235 expr.original_code = ERROR_MARK;
5238 e1 = c_parser_expr_no_commas (parser, NULL);
5239 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5241 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5242 expr.value = error_mark_node;
5243 expr.original_code = ERROR_MARK;
5246 e2 = c_parser_expr_no_commas (parser, NULL);
5247 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5249 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5250 expr.value = error_mark_node;
5251 expr.original_code = ERROR_MARK;
5254 e3 = c_parser_expr_no_commas (parser, NULL);
5255 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5260 c = fold (e1.value);
5261 if (TREE_CODE (c) != INTEGER_CST)
5262 error ("first argument to %<__builtin_choose_expr%> not"
5264 expr = integer_zerop (c) ? e3 : e2;
5267 case RID_TYPES_COMPATIBLE_P:
5268 c_parser_consume_token (parser);
5269 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5271 expr.value = error_mark_node;
5272 expr.original_code = ERROR_MARK;
5275 t1 = c_parser_type_name (parser);
5278 expr.value = error_mark_node;
5279 expr.original_code = ERROR_MARK;
5282 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5284 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5285 expr.value = error_mark_node;
5286 expr.original_code = ERROR_MARK;
5289 t2 = c_parser_type_name (parser);
5292 expr.value = error_mark_node;
5293 expr.original_code = ERROR_MARK;
5296 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5301 e1 = TYPE_MAIN_VARIANT (groktypename (t1));
5302 e2 = TYPE_MAIN_VARIANT (groktypename (t2));
5304 expr.value = comptypes (e1, e2)
5305 ? build_int_cst (NULL_TREE, 1)
5306 : build_int_cst (NULL_TREE, 0);
5307 expr.original_code = ERROR_MARK;
5310 case RID_AT_SELECTOR:
5311 gcc_assert (c_dialect_objc ());
5312 c_parser_consume_token (parser);
5313 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5315 expr.value = error_mark_node;
5316 expr.original_code = ERROR_MARK;
5320 tree sel = c_parser_objc_selector_arg (parser);
5321 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5323 expr.value = objc_build_selector_expr (sel);
5324 expr.original_code = ERROR_MARK;
5327 case RID_AT_PROTOCOL:
5328 gcc_assert (c_dialect_objc ());
5329 c_parser_consume_token (parser);
5330 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5332 expr.value = error_mark_node;
5333 expr.original_code = ERROR_MARK;
5336 if (c_parser_next_token_is_not (parser, CPP_NAME))
5338 c_parser_error (parser, "expected identifier");
5339 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5340 expr.value = error_mark_node;
5341 expr.original_code = ERROR_MARK;
5345 tree id = c_parser_peek_token (parser)->value;
5346 c_parser_consume_token (parser);
5347 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5349 expr.value = objc_build_protocol_expr (id);
5350 expr.original_code = ERROR_MARK;
5354 /* Extension to support C-structures in the archiver. */
5355 gcc_assert (c_dialect_objc ());
5356 c_parser_consume_token (parser);
5357 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5359 expr.value = error_mark_node;
5360 expr.original_code = ERROR_MARK;
5363 t1 = c_parser_type_name (parser);
5366 expr.value = error_mark_node;
5367 expr.original_code = ERROR_MARK;
5368 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5371 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5374 tree type = groktypename (t1);
5375 expr.value = objc_build_encode_expr (type);
5376 expr.original_code = ERROR_MARK;
5380 c_parser_error (parser, "expected expression");
5381 expr.value = error_mark_node;
5382 expr.original_code = ERROR_MARK;
5386 case CPP_OPEN_SQUARE:
5387 if (c_dialect_objc ())
5389 tree receiver, args;
5390 c_parser_consume_token (parser);
5391 receiver = c_parser_objc_receiver (parser);
5392 args = c_parser_objc_message_args (parser);
5393 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5395 expr.value = objc_build_message_expr (build_tree_list (receiver,
5397 expr.original_code = ERROR_MARK;
5400 /* Else fall through to report error. */
5402 c_parser_error (parser, "expected expression");
5403 expr.value = error_mark_node;
5404 expr.original_code = ERROR_MARK;
5407 return c_parser_postfix_expression_after_primary (parser, expr);
5410 /* Parse a postfix expression after a parenthesized type name: the
5411 brace-enclosed initializer of a compound literal, possibly followed
5412 by some postfix operators. This is separate because it is not
5413 possible to tell until after the type name whether a cast
5414 expression has a cast or a compound literal, or whether the operand
5415 of sizeof is a parenthesized type name or starts with a compound
5418 static struct c_expr
5419 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5420 struct c_type_name *type_name)
5425 start_init (NULL_TREE, NULL, 0);
5426 type = groktypename (type_name);
5427 if (C_TYPE_VARIABLE_SIZE (type))
5429 error ("compound literal has variable size");
5430 type = error_mark_node;
5432 init = c_parser_braced_init (parser, type, false);
5434 maybe_warn_string_init (type, init);
5436 if (pedantic && !flag_isoc99)
5437 pedwarn ("ISO C90 forbids compound literals");
5438 expr.value = build_compound_literal (type, init.value);
5439 expr.original_code = ERROR_MARK;
5440 return c_parser_postfix_expression_after_primary (parser, expr);
5443 /* Parse a postfix expression after the initial primary or compound
5444 literal; that is, parse a series of postfix operators. */
5446 static struct c_expr
5447 c_parser_postfix_expression_after_primary (c_parser *parser,
5450 tree ident, idx, exprlist;
5453 switch (c_parser_peek_token (parser)->type)
5455 case CPP_OPEN_SQUARE:
5456 /* Array reference. */
5457 c_parser_consume_token (parser);
5458 idx = c_parser_expression (parser).value;
5459 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5461 expr.value = build_array_ref (expr.value, idx);
5462 expr.original_code = ERROR_MARK;
5464 case CPP_OPEN_PAREN:
5465 /* Function call. */
5466 c_parser_consume_token (parser);
5467 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5468 exprlist = NULL_TREE;
5470 exprlist = c_parser_expr_list (parser, true);
5471 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5473 expr.value = build_function_call (expr.value, exprlist);
5474 expr.original_code = ERROR_MARK;
5477 /* Structure element reference. */
5478 c_parser_consume_token (parser);
5479 expr = default_function_array_conversion (expr);
5480 if (c_parser_next_token_is (parser, CPP_NAME))
5481 ident = c_parser_peek_token (parser)->value;
5484 c_parser_error (parser, "expected identifier");
5485 expr.value = error_mark_node;
5486 expr.original_code = ERROR_MARK;
5489 c_parser_consume_token (parser);
5490 expr.value = build_component_ref (expr.value, ident);
5491 expr.original_code = ERROR_MARK;
5494 /* Structure element reference. */
5495 c_parser_consume_token (parser);
5496 expr = default_function_array_conversion (expr);
5497 if (c_parser_next_token_is (parser, CPP_NAME))
5498 ident = c_parser_peek_token (parser)->value;
5501 c_parser_error (parser, "expected identifier");
5502 expr.value = error_mark_node;
5503 expr.original_code = ERROR_MARK;
5506 c_parser_consume_token (parser);
5507 expr.value = build_component_ref (build_indirect_ref (expr.value,
5509 expr.original_code = ERROR_MARK;
5512 /* Postincrement. */
5513 c_parser_consume_token (parser);
5514 expr = default_function_array_conversion (expr);
5515 expr.value = build_unary_op (POSTINCREMENT_EXPR, expr.value, 0);
5516 expr.original_code = ERROR_MARK;
5518 case CPP_MINUS_MINUS:
5519 /* Postdecrement. */
5520 c_parser_consume_token (parser);
5521 expr = default_function_array_conversion (expr);
5522 expr.value = build_unary_op (POSTDECREMENT_EXPR, expr.value, 0);
5523 expr.original_code = ERROR_MARK;
5531 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5534 assignment-expression
5535 expression , assignment-expression
5538 static struct c_expr
5539 c_parser_expression (c_parser *parser)
5542 expr = c_parser_expr_no_commas (parser, NULL);
5543 while (c_parser_next_token_is (parser, CPP_COMMA))
5546 c_parser_consume_token (parser);
5547 next = c_parser_expr_no_commas (parser, NULL);
5548 next = default_function_array_conversion (next);
5549 expr.value = build_compound_expr (expr.value, next.value);
5550 expr.original_code = COMPOUND_EXPR;
5555 /* Parse an expression and convert functions or arrays to
5558 static struct c_expr
5559 c_parser_expression_conv (c_parser *parser)
5562 expr = c_parser_expression (parser);
5563 expr = default_function_array_conversion (expr);
5567 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5568 functions and arrays to pointers.
5571 assignment-expression
5572 nonempty-expr-list , assignment-expression
5576 c_parser_expr_list (c_parser *parser, bool convert_p)
5580 expr = c_parser_expr_no_commas (parser, NULL);
5582 expr = default_function_array_conversion (expr);
5583 ret = cur = build_tree_list (NULL_TREE, expr.value);
5584 while (c_parser_next_token_is (parser, CPP_COMMA))
5586 c_parser_consume_token (parser);
5587 expr = c_parser_expr_no_commas (parser, NULL);
5589 expr = default_function_array_conversion (expr);
5590 cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
5596 /* Parse Objective-C-specific constructs. */
5598 /* Parse an objc-class-definition.
5600 objc-class-definition:
5601 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5602 objc-class-instance-variables[opt] objc-methodprotolist @end
5603 @implementation identifier objc-superclass[opt]
5604 objc-class-instance-variables[opt]
5605 @interface identifier ( identifier ) objc-protocol-refs[opt]
5606 objc-methodprotolist @end
5607 @implementation identifier ( identifier )
5612 "@interface identifier (" must start "@interface identifier (
5613 identifier ) ...": objc-methodprotolist in the first production may
5614 not start with a parenthesized identifier as a declarator of a data
5615 definition with no declaration specifiers if the objc-superclass,
5616 objc-protocol-refs and objc-class-instance-variables are omitted. */
5619 c_parser_objc_class_definition (c_parser *parser)
5624 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
5626 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
5630 c_parser_consume_token (parser);
5631 if (c_parser_next_token_is_not (parser, CPP_NAME))
5633 c_parser_error (parser, "expected identifier");
5636 id1 = c_parser_peek_token (parser)->value;
5637 c_parser_consume_token (parser);
5638 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
5641 tree proto = NULL_TREE;
5642 c_parser_consume_token (parser);
5643 if (c_parser_next_token_is_not (parser, CPP_NAME))
5645 c_parser_error (parser, "expected identifier");
5646 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5649 id2 = c_parser_peek_token (parser)->value;
5650 c_parser_consume_token (parser);
5651 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5654 objc_start_category_implementation (id1, id2);
5657 if (c_parser_next_token_is (parser, CPP_LESS))
5658 proto = c_parser_objc_protocol_refs (parser);
5659 objc_start_category_interface (id1, id2, proto);
5660 c_parser_objc_methodprotolist (parser);
5661 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5662 objc_finish_interface ();
5665 if (c_parser_next_token_is (parser, CPP_COLON))
5667 c_parser_consume_token (parser);
5668 if (c_parser_next_token_is_not (parser, CPP_NAME))
5670 c_parser_error (parser, "expected identifier");
5673 superclass = c_parser_peek_token (parser)->value;
5674 c_parser_consume_token (parser);
5677 superclass = NULL_TREE;
5680 tree proto = NULL_TREE;
5681 if (c_parser_next_token_is (parser, CPP_LESS))
5682 proto = c_parser_objc_protocol_refs (parser);
5683 objc_start_class_interface (id1, superclass, proto);
5686 objc_start_class_implementation (id1, superclass);
5687 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5688 c_parser_objc_class_instance_variables (parser);
5691 objc_continue_interface ();
5692 c_parser_objc_methodprotolist (parser);
5693 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5694 objc_finish_interface ();
5698 objc_continue_implementation ();
5703 /* Parse objc-class-instance-variables.
5705 objc-class-instance-variables:
5706 { objc-instance-variable-decl-list[opt] }
5708 objc-instance-variable-decl-list:
5709 objc-visibility-spec
5710 objc-instance-variable-decl ;
5712 objc-instance-variable-decl-list objc-visibility-spec
5713 objc-instance-variable-decl-list objc-instance-variable-decl ;
5714 objc-instance-variable-decl-list ;
5716 objc-visibility-spec:
5721 objc-instance-variable-decl:
5726 c_parser_objc_class_instance_variables (c_parser *parser)
5728 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
5729 c_parser_consume_token (parser);
5730 while (c_parser_next_token_is_not (parser, CPP_EOF))
5733 /* Parse any stray semicolon. */
5734 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5737 pedwarn ("extra semicolon in struct or union specified");
5738 c_parser_consume_token (parser);
5741 /* Stop if at the end of the instance variables. */
5742 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
5744 c_parser_consume_token (parser);
5747 /* Parse any objc-visibility-spec. */
5748 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
5750 c_parser_consume_token (parser);
5751 objc_set_visibility (2);
5754 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
5756 c_parser_consume_token (parser);
5757 objc_set_visibility (0);
5760 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
5762 c_parser_consume_token (parser);
5763 objc_set_visibility (1);
5766 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
5768 c_parser_pragma (parser, pragma_external);
5772 /* Parse some comma-separated declarations. */
5773 decls = c_parser_struct_declaration (parser);
5775 /* Comma-separated instance variables are chained together in
5776 reverse order; add them one by one. */
5777 tree ivar = nreverse (decls);
5778 for (; ivar; ivar = TREE_CHAIN (ivar))
5779 objc_add_instance_variable (copy_node (ivar));
5781 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5785 /* Parse an objc-class-declaration.
5787 objc-class-declaration:
5788 @class identifier-list ;
5792 c_parser_objc_class_declaration (c_parser *parser)
5794 tree list = NULL_TREE;
5795 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
5796 c_parser_consume_token (parser);
5797 /* Any identifiers, including those declared as type names, are OK
5802 if (c_parser_next_token_is_not (parser, CPP_NAME))
5804 c_parser_error (parser, "expected identifier");
5807 id = c_parser_peek_token (parser)->value;
5808 list = chainon (list, build_tree_list (NULL_TREE, id));
5809 c_parser_consume_token (parser);
5810 if (c_parser_next_token_is (parser, CPP_COMMA))
5811 c_parser_consume_token (parser);
5815 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5816 objc_declare_class (list);
5819 /* Parse an objc-alias-declaration.
5821 objc-alias-declaration:
5822 @compatibility_alias identifier identifier ;
5826 c_parser_objc_alias_declaration (c_parser *parser)
5829 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
5830 c_parser_consume_token (parser);
5831 if (c_parser_next_token_is_not (parser, CPP_NAME))
5833 c_parser_error (parser, "expected identifier");
5834 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5837 id1 = c_parser_peek_token (parser)->value;
5838 c_parser_consume_token (parser);
5839 if (c_parser_next_token_is_not (parser, CPP_NAME))
5841 c_parser_error (parser, "expected identifier");
5842 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
5845 id2 = c_parser_peek_token (parser)->value;
5846 c_parser_consume_token (parser);
5847 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5848 objc_declare_alias (id1, id2);
5851 /* Parse an objc-protocol-definition.
5853 objc-protocol-definition:
5854 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5855 @protocol identifier-list ;
5857 "@protocol identifier ;" should be resolved as "@protocol
5858 identifier-list ;": objc-methodprotolist may not start with a
5859 semicolon in the first alternative if objc-protocol-refs are
5863 c_parser_objc_protocol_definition (c_parser *parser)
5865 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
5866 c_parser_consume_token (parser);
5867 if (c_parser_next_token_is_not (parser, CPP_NAME))
5869 c_parser_error (parser, "expected identifier");
5872 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
5873 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
5875 tree list = NULL_TREE;
5876 /* Any identifiers, including those declared as type names, are
5881 if (c_parser_next_token_is_not (parser, CPP_NAME))
5883 c_parser_error (parser, "expected identifier");
5886 id = c_parser_peek_token (parser)->value;
5887 list = chainon (list, build_tree_list (NULL_TREE, id));
5888 c_parser_consume_token (parser);
5889 if (c_parser_next_token_is (parser, CPP_COMMA))
5890 c_parser_consume_token (parser);
5894 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
5895 objc_declare_protocols (list);
5899 tree id = c_parser_peek_token (parser)->value;
5900 tree proto = NULL_TREE;
5901 c_parser_consume_token (parser);
5902 if (c_parser_next_token_is (parser, CPP_LESS))
5903 proto = c_parser_objc_protocol_refs (parser);
5904 objc_pq_context = 1;
5905 objc_start_protocol (id, proto);
5906 c_parser_objc_methodprotolist (parser);
5907 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
5908 objc_pq_context = 0;
5909 objc_finish_interface ();
5913 /* Parse an objc-method-type.
5920 static enum tree_code
5921 c_parser_objc_method_type (c_parser *parser)
5923 switch (c_parser_peek_token (parser)->type)
5926 c_parser_consume_token (parser);
5929 c_parser_consume_token (parser);
5936 /* Parse an objc-method-definition.
5938 objc-method-definition:
5939 objc-method-type objc-method-decl ;[opt] compound-statement
5943 c_parser_objc_method_definition (c_parser *parser)
5945 enum tree_code type = c_parser_objc_method_type (parser);
5947 objc_set_method_type (type);
5948 objc_pq_context = 1;
5949 decl = c_parser_objc_method_decl (parser);
5950 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
5952 c_parser_consume_token (parser);
5954 pedwarn ("extra semicolon in method definition specified");
5956 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5958 c_parser_error (parser, "expected %<{%>");
5961 objc_pq_context = 0;
5962 objc_start_method_definition (decl);
5963 add_stmt (c_parser_compound_statement (parser));
5964 objc_finish_method_definition (current_function_decl);
5967 /* Parse an objc-methodprotolist.
5969 objc-methodprotolist:
5971 objc-methodprotolist objc-methodproto
5972 objc-methodprotolist declaration
5973 objc-methodprotolist ;
5975 The declaration is a data definition, which may be missing
5976 declaration specifiers under the same rules and diagnostics as
5977 other data definitions outside functions, and the stray semicolon
5978 is diagnosed the same way as a stray semicolon outside a
5982 c_parser_objc_methodprotolist (c_parser *parser)
5986 /* The list is terminated by @end. */
5987 switch (c_parser_peek_token (parser)->type)
5991 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
5992 c_parser_consume_token (parser);
5996 c_parser_objc_methodproto (parser);
5999 c_parser_pragma (parser, pragma_external);
6004 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6006 c_parser_declaration_or_fndef (parser, false, true, false, true);
6012 /* Parse an objc-methodproto.
6015 objc-method-type objc-method-decl ;
6019 c_parser_objc_methodproto (c_parser *parser)
6021 enum tree_code type = c_parser_objc_method_type (parser);
6023 objc_set_method_type (type);
6024 /* Remember protocol qualifiers in prototypes. */
6025 objc_pq_context = 1;
6026 decl = c_parser_objc_method_decl (parser);
6027 /* Forget protocol qualifiers here. */
6028 objc_pq_context = 0;
6029 objc_add_method_declaration (decl);
6030 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6033 /* Parse an objc-method-decl.
6036 ( objc-type-name ) objc-selector
6038 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6039 objc-keyword-selector objc-optparmlist
6041 objc-keyword-selector:
6043 objc-keyword-selector objc-keyword-decl
6046 objc-selector : ( objc-type-name ) identifier
6047 objc-selector : identifier
6048 : ( objc-type-name ) identifier
6052 objc-optparms objc-optellipsis
6056 objc-opt-parms , parameter-declaration
6064 c_parser_objc_method_decl (c_parser *parser)
6066 tree type = NULL_TREE;
6068 tree parms = NULL_TREE;
6069 bool ellipsis = false;
6071 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6073 c_parser_consume_token (parser);
6074 type = c_parser_objc_type_name (parser);
6075 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6077 sel = c_parser_objc_selector (parser);
6078 /* If there is no selector, or a colon follows, we have an
6079 objc-keyword-selector. If there is a selector, and a colon does
6080 not follow, that selector ends the objc-method-decl. */
6081 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6084 tree list = NULL_TREE;
6087 tree atype = NULL_TREE, id, keyworddecl;
6088 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6090 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6092 c_parser_consume_token (parser);
6093 atype = c_parser_objc_type_name (parser);
6094 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6097 if (c_parser_next_token_is_not (parser, CPP_NAME))
6099 c_parser_error (parser, "expected identifier");
6100 return error_mark_node;
6102 id = c_parser_peek_token (parser)->value;
6103 c_parser_consume_token (parser);
6104 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6105 list = chainon (list, keyworddecl);
6106 tsel = c_parser_objc_selector (parser);
6107 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6110 /* Parse the optional parameter list. Optional Objective-C
6111 method parameters follow the C syntax, and may include '...'
6112 to denote a variable number of arguments. */
6113 parms = make_node (TREE_LIST);
6114 while (c_parser_next_token_is (parser, CPP_COMMA))
6116 struct c_parm *parm;
6117 c_parser_consume_token (parser);
6118 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6121 c_parser_consume_token (parser);
6124 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6127 parms = chainon (parms,
6128 build_tree_list (NULL_TREE, grokparm (parm)));
6132 return objc_build_method_signature (type, sel, parms, ellipsis);
6135 /* Parse an objc-type-name.
6138 objc-type-qualifiers[opt] type-name
6139 objc-type-qualifiers[opt]
6141 objc-type-qualifiers:
6143 objc-type-qualifiers objc-type-qualifier
6145 objc-type-qualifier: one of
6146 in out inout bycopy byref oneway
6150 c_parser_objc_type_name (c_parser *parser)
6152 tree quals = NULL_TREE;
6153 struct c_type_name *typename = NULL;
6154 tree type = NULL_TREE;
6157 c_token *token = c_parser_peek_token (parser);
6158 if (token->type == CPP_KEYWORD
6159 && (token->keyword == RID_IN
6160 || token->keyword == RID_OUT
6161 || token->keyword == RID_INOUT
6162 || token->keyword == RID_BYCOPY
6163 || token->keyword == RID_BYREF
6164 || token->keyword == RID_ONEWAY))
6166 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6167 c_parser_consume_token (parser);
6172 if (c_parser_next_token_starts_typename (parser))
6173 typename = c_parser_type_name (parser);
6175 type = groktypename (typename);
6176 return build_tree_list (quals, type);
6179 /* Parse objc-protocol-refs.
6186 c_parser_objc_protocol_refs (c_parser *parser)
6188 tree list = NULL_TREE;
6189 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6190 c_parser_consume_token (parser);
6191 /* Any identifiers, including those declared as type names, are OK
6196 if (c_parser_next_token_is_not (parser, CPP_NAME))
6198 c_parser_error (parser, "expected identifier");
6201 id = c_parser_peek_token (parser)->value;
6202 list = chainon (list, build_tree_list (NULL_TREE, id));
6203 c_parser_consume_token (parser);
6204 if (c_parser_next_token_is (parser, CPP_COMMA))
6205 c_parser_consume_token (parser);
6209 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6213 /* Parse an objc-try-catch-statement.
6215 objc-try-catch-statement:
6216 @try compound-statement objc-catch-list[opt]
6217 @try compound-statement objc-catch-list[opt] @finally compound-statement
6220 @catch ( parameter-declaration ) compound-statement
6221 objc-catch-list @catch ( parameter-declaration ) compound-statement
6225 c_parser_objc_try_catch_statement (c_parser *parser)
6229 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
6230 c_parser_consume_token (parser);
6231 loc = c_parser_peek_token (parser)->location;
6232 stmt = c_parser_compound_statement (parser);
6233 objc_begin_try_stmt (loc, stmt);
6234 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
6236 struct c_parm *parm;
6237 c_parser_consume_token (parser);
6238 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6240 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6246 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6247 objc_begin_catch_clause (grokparm (parm));
6248 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6249 c_parser_compound_statement_nostart (parser);
6250 objc_finish_catch_clause ();
6252 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6256 c_parser_consume_token (parser);
6257 finloc = c_parser_peek_token (parser)->location;
6258 finstmt = c_parser_compound_statement (parser);
6259 objc_build_finally_clause (finloc, finstmt);
6261 objc_finish_try_stmt ();
6264 /* Parse an objc-synchronized-statement.
6266 objc-synchronized-statement:
6267 @synchronized ( expression ) compound-statement
6271 c_parser_objc_synchronized_statement (c_parser *parser)
6275 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6276 c_parser_consume_token (parser);
6277 loc = c_parser_peek_token (parser)->location;
6278 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6280 expr = c_parser_expression (parser).value;
6281 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6284 expr = error_mark_node;
6285 stmt = c_parser_compound_statement (parser);
6286 objc_build_synchronized (loc, expr, stmt);
6289 /* Parse an objc-selector; return NULL_TREE without an error if the
6290 next token is not an objc-selector.
6295 enum struct union if else while do for switch case default
6296 break continue return goto asm sizeof typeof __alignof
6297 unsigned long const short volatile signed restrict _Complex
6298 in out inout bycopy byref oneway int char float double void _Bool
6300 ??? Why this selection of keywords but not, for example, storage
6301 class specifiers? */
6304 c_parser_objc_selector (c_parser *parser)
6306 c_token *token = c_parser_peek_token (parser);
6307 tree value = token->value;
6308 if (token->type == CPP_NAME)
6310 c_parser_consume_token (parser);
6313 if (token->type != CPP_KEYWORD)
6315 switch (token->keyword)
6356 c_parser_consume_token (parser);
6363 /* Parse an objc-selector-arg.
6367 objc-keywordname-list
6369 objc-keywordname-list:
6371 objc-keywordname-list objc-keywordname
6379 c_parser_objc_selector_arg (c_parser *parser)
6381 tree sel = c_parser_objc_selector (parser);
6382 tree list = NULL_TREE;
6383 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6387 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6389 list = chainon (list, build_tree_list (sel, NULL_TREE));
6390 sel = c_parser_objc_selector (parser);
6391 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6397 /* Parse an objc-receiver.
6406 c_parser_objc_receiver (c_parser *parser)
6408 if (c_parser_peek_token (parser)->type == CPP_NAME
6409 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6410 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6412 tree id = c_parser_peek_token (parser)->value;
6413 c_parser_consume_token (parser);
6414 return objc_get_class_reference (id);
6416 return c_parser_expression (parser).value;
6419 /* Parse objc-message-args.
6423 objc-keywordarg-list
6425 objc-keywordarg-list:
6427 objc-keywordarg-list objc-keywordarg
6430 objc-selector : objc-keywordexpr
6435 c_parser_objc_message_args (c_parser *parser)
6437 tree sel = c_parser_objc_selector (parser);
6438 tree list = NULL_TREE;
6439 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6444 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6446 keywordexpr = c_parser_objc_keywordexpr (parser);
6447 list = chainon (list, build_tree_list (sel, keywordexpr));
6448 sel = c_parser_objc_selector (parser);
6449 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6455 /* Parse an objc-keywordexpr.
6462 c_parser_objc_keywordexpr (c_parser *parser)
6464 tree list = c_parser_expr_list (parser, true);
6465 if (TREE_CHAIN (list) == NULL_TREE)
6467 /* Just return the expression, remove a level of
6469 return TREE_VALUE (list);
6473 /* We have a comma expression, we will collapse later. */
6479 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6480 should be considered, statements. ALLOW_STMT is true if we're within
6481 the context of a function and such pragmas are to be allowed. Returns
6482 true if we actually parsed such a pragma. */
6485 c_parser_pragma (c_parser *parser, enum pragma_context context)
6489 id = c_parser_peek_token (parser)->pragma_kind;
6490 gcc_assert (id != PRAGMA_NONE);
6494 case PRAGMA_OMP_BARRIER:
6495 if (context != pragma_compound)
6497 if (context == pragma_stmt)
6498 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6499 "used in compound statements");
6502 c_parser_omp_barrier (parser);
6505 case PRAGMA_OMP_FLUSH:
6506 if (context != pragma_compound)
6508 if (context == pragma_stmt)
6509 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6510 "used in compound statements");
6513 c_parser_omp_flush (parser);
6516 case PRAGMA_OMP_THREADPRIVATE:
6517 c_parser_omp_threadprivate (parser);
6520 case PRAGMA_OMP_SECTION:
6521 error ("%<#pragma omp section%> may only be used in "
6522 "%<#pragma omp sections%> construct");
6523 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6526 case PRAGMA_GCC_PCH_PREPROCESS:
6527 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6528 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6532 if (id < PRAGMA_FIRST_EXTERNAL)
6534 if (context == pragma_external)
6537 c_parser_error (parser, "expected declaration specifiers");
6538 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6541 c_parser_omp_construct (parser);
6547 c_parser_consume_pragma (parser);
6548 c_invoke_pragma_handler (id);
6550 /* Skip to EOL, but suppress any error message. Those will have been
6551 generated by the handler routine through calling error, as opposed
6552 to calling c_parser_error. */
6553 parser->error = true;
6554 c_parser_skip_to_pragma_eol (parser);
6559 /* The interface the pragma parsers have to the lexer. */
6562 pragma_lex (tree *value)
6564 c_token *tok = c_parser_peek_token (the_parser);
6565 enum cpp_ttype ret = tok->type;
6567 *value = tok->value;
6568 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
6572 if (ret == CPP_KEYWORD)
6574 c_parser_consume_token (the_parser);
6581 c_parser_pragma_pch_preprocess (c_parser *parser)
6585 c_parser_consume_pragma (parser);
6586 if (c_parser_next_token_is (parser, CPP_STRING))
6588 name = c_parser_peek_token (parser)->value;
6589 c_parser_consume_token (parser);
6592 c_parser_error (parser, "expected string literal");
6593 c_parser_skip_to_pragma_eol (parser);
6596 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
6599 /* OpenMP 2.5 parsing routines. */
6601 /* Returns name of the next clause.
6602 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6603 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6604 returned and the token is consumed. */
6606 static pragma_omp_clause
6607 c_parser_omp_clause_name (c_parser *parser)
6609 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
6611 if (c_parser_next_token_is_keyword (parser, RID_IF))
6612 result = PRAGMA_OMP_CLAUSE_IF;
6613 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
6614 result = PRAGMA_OMP_CLAUSE_DEFAULT;
6615 else if (c_parser_next_token_is (parser, CPP_NAME))
6617 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6622 if (!strcmp ("copyin", p))
6623 result = PRAGMA_OMP_CLAUSE_COPYIN;
6624 else if (!strcmp ("copyprivate", p))
6625 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
6628 if (!strcmp ("firstprivate", p))
6629 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
6632 if (!strcmp ("lastprivate", p))
6633 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
6636 if (!strcmp ("nowait", p))
6637 result = PRAGMA_OMP_CLAUSE_NOWAIT;
6638 else if (!strcmp ("num_threads", p))
6639 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
6642 if (!strcmp ("ordered", p))
6643 result = PRAGMA_OMP_CLAUSE_ORDERED;
6646 if (!strcmp ("private", p))
6647 result = PRAGMA_OMP_CLAUSE_PRIVATE;
6650 if (!strcmp ("reduction", p))
6651 result = PRAGMA_OMP_CLAUSE_REDUCTION;
6654 if (!strcmp ("schedule", p))
6655 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
6656 else if (!strcmp ("shared", p))
6657 result = PRAGMA_OMP_CLAUSE_SHARED;
6662 if (result != PRAGMA_OMP_CLAUSE_NONE)
6663 c_parser_consume_token (parser);
6668 /* Validate that a clause of the given type does not already exist. */
6671 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
6675 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6676 if (OMP_CLAUSE_CODE (c) == code)
6678 error ("too many %qs clauses", name);
6686 variable-list , identifier
6688 If KIND is nonzero, create the appropriate node and install the decl
6689 in OMP_CLAUSE_DECL and add the node to the head of the list.
6691 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6692 return the list created. */
6695 c_parser_omp_variable_list (c_parser *parser, enum omp_clause_code kind,
6698 if (c_parser_next_token_is_not (parser, CPP_NAME)
6699 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
6700 c_parser_error (parser, "expected identifier");
6702 while (c_parser_next_token_is (parser, CPP_NAME)
6703 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
6705 tree t = lookup_name (c_parser_peek_token (parser)->value);
6708 undeclared_variable (c_parser_peek_token (parser)->value,
6709 c_parser_peek_token (parser)->location);
6710 else if (t == error_mark_node)
6714 tree u = build_omp_clause (kind);
6715 OMP_CLAUSE_DECL (u) = t;
6716 OMP_CLAUSE_CHAIN (u) = list;
6720 list = tree_cons (t, NULL_TREE, list);
6722 c_parser_consume_token (parser);
6724 if (c_parser_next_token_is_not (parser, CPP_COMMA))
6727 c_parser_consume_token (parser);
6733 /* Similarly, but expect leading and trailing parenthesis. This is a very
6734 common case for omp clauses. */
6737 c_parser_omp_var_list_parens (c_parser *parser, enum tree_code kind, tree list)
6739 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6741 list = c_parser_omp_variable_list (parser, kind, list);
6742 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6748 copyin ( variable-list ) */
6751 c_parser_omp_clause_copyin (c_parser *parser, tree list)
6753 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
6757 copyprivate ( variable-list ) */
6760 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
6762 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
6766 default ( shared | none ) */
6769 c_parser_omp_clause_default (c_parser *parser, tree list)
6771 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
6774 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6776 if (c_parser_next_token_is (parser, CPP_NAME))
6778 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
6783 if (strcmp ("none", p) != 0)
6785 kind = OMP_CLAUSE_DEFAULT_NONE;
6789 if (strcmp ("shared", p) != 0)
6791 kind = OMP_CLAUSE_DEFAULT_SHARED;
6798 c_parser_consume_token (parser);
6803 c_parser_error (parser, "expected %<none%> or %<shared%>");
6805 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6807 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
6810 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
6811 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
6812 OMP_CLAUSE_CHAIN (c) = list;
6813 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
6819 firstprivate ( variable-list ) */
6822 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
6824 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
6828 if ( expression ) */
6831 c_parser_omp_clause_if (c_parser *parser, tree list)
6833 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6835 tree t = c_parser_paren_condition (parser);
6838 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
6840 c = build_omp_clause (OMP_CLAUSE_IF);
6841 OMP_CLAUSE_IF_EXPR (c) = t;
6842 OMP_CLAUSE_CHAIN (c) = list;
6846 c_parser_error (parser, "expected %<(%>");
6852 lastprivate ( variable-list ) */
6855 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
6857 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
6864 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6868 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
6870 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
6871 OMP_CLAUSE_CHAIN (c) = list;
6876 num_threads ( expression ) */
6879 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
6881 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6883 tree c, t = c_parser_expression (parser).value;
6885 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6887 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
6889 c_parser_error (parser, "expected integer expression");
6893 /* Attempt to statically determine when the number isn't positive. */
6894 c = fold_build2 (LE_EXPR, boolean_type_node, t,
6895 build_int_cst (TREE_TYPE (t), 0));
6896 if (c == boolean_true_node)
6898 warning (0, "%<num_threads%> value must be positive");
6899 t = integer_one_node;
6902 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
6904 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
6905 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
6906 OMP_CLAUSE_CHAIN (c) = list;
6917 c_parser_omp_clause_ordered (c_parser *parser ATTRIBUTE_UNUSED, tree list)
6921 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
6923 c = build_omp_clause (OMP_CLAUSE_ORDERED);
6924 OMP_CLAUSE_CHAIN (c) = list;
6929 private ( variable-list ) */
6932 c_parser_omp_clause_private (c_parser *parser, tree list)
6934 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
6938 reduction ( reduction-operator : variable-list )
6941 One of: + * - & ^ | && || */
6944 c_parser_omp_clause_reduction (c_parser *parser, tree list)
6946 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6948 enum tree_code code;
6950 switch (c_parser_peek_token (parser)->type)
6962 code = BIT_AND_EXPR;
6965 code = BIT_XOR_EXPR;
6968 code = BIT_IOR_EXPR;
6971 code = TRUTH_ANDIF_EXPR;
6974 code = TRUTH_ORIF_EXPR;
6977 c_parser_error (parser,
6978 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
6979 "%<^%>, %<|%>, %<&&%>, or %<||%>");
6980 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
6983 c_parser_consume_token (parser);
6984 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6988 nl = c_parser_omp_variable_list (parser, OMP_CLAUSE_REDUCTION, list);
6989 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
6990 OMP_CLAUSE_REDUCTION_CODE (c) = code;
6994 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7000 schedule ( schedule-kind )
7001 schedule ( schedule-kind , expression )
7004 static | dynamic | guided | runtime
7008 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7012 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7015 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
7017 if (c_parser_next_token_is (parser, CPP_NAME))
7019 tree kind = c_parser_peek_token (parser)->value;
7020 const char *p = IDENTIFIER_POINTER (kind);
7025 if (strcmp ("dynamic", p) != 0)
7027 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7031 if (strcmp ("guided", p) != 0)
7033 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7037 if (strcmp ("runtime", p) != 0)
7039 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7046 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7047 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7051 c_parser_consume_token (parser);
7052 if (c_parser_next_token_is (parser, CPP_COMMA))
7054 c_parser_consume_token (parser);
7056 t = c_parser_expr_no_commas (parser, NULL).value;
7058 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7059 error ("schedule %<runtime%> does not take "
7060 "a %<chunk_size%> parameter");
7061 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7062 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7064 c_parser_error (parser, "expected integer expression");
7066 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7069 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7070 "expected %<,%> or %<)%>");
7072 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7073 OMP_CLAUSE_CHAIN (c) = list;
7077 c_parser_error (parser, "invalid schedule kind");
7078 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7083 shared ( variable-list ) */
7086 c_parser_omp_clause_shared (c_parser *parser, tree list)
7088 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7091 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7092 is a bitmask in MASK. Return the list of clauses found; the result
7093 of clause default goes in *pdefault. */
7096 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7099 tree clauses = NULL;
7101 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7103 const pragma_omp_clause c_kind = c_parser_omp_clause_name (parser);
7105 tree prev = clauses;
7109 case PRAGMA_OMP_CLAUSE_COPYIN:
7110 clauses = c_parser_omp_clause_copyin (parser, clauses);
7113 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7114 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7115 c_name = "copyprivate";
7117 case PRAGMA_OMP_CLAUSE_DEFAULT:
7118 clauses = c_parser_omp_clause_default (parser, clauses);
7121 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7122 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7123 c_name = "firstprivate";
7125 case PRAGMA_OMP_CLAUSE_IF:
7126 clauses = c_parser_omp_clause_if (parser, clauses);
7129 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7130 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7131 c_name = "lastprivate";
7133 case PRAGMA_OMP_CLAUSE_NOWAIT:
7134 clauses = c_parser_omp_clause_nowait (parser, clauses);
7137 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7138 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7139 c_name = "num_threads";
7141 case PRAGMA_OMP_CLAUSE_ORDERED:
7142 clauses = c_parser_omp_clause_ordered (parser, clauses);
7145 case PRAGMA_OMP_CLAUSE_PRIVATE:
7146 clauses = c_parser_omp_clause_private (parser, clauses);
7149 case PRAGMA_OMP_CLAUSE_REDUCTION:
7150 clauses = c_parser_omp_clause_reduction (parser, clauses);
7151 c_name = "reduction";
7153 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7154 clauses = c_parser_omp_clause_schedule (parser, clauses);
7155 c_name = "schedule";
7157 case PRAGMA_OMP_CLAUSE_SHARED:
7158 clauses = c_parser_omp_clause_shared (parser, clauses);
7162 c_parser_error (parser, "expected %<#pragma omp%> clause");
7166 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7168 /* Remove the invalid clause(s) from the list to avoid
7169 confusing the rest of the compiler. */
7171 error ("%qs is not valid for %qs", c_name, where);
7176 c_parser_skip_to_pragma_eol (parser);
7178 return c_finish_omp_clauses (clauses);
7185 In practice, we're also interested in adding the statement to an
7186 outer node. So it is convenient if we work around the fact that
7187 c_parser_statement calls add_stmt. */
7190 c_parser_omp_structured_block (c_parser *parser)
7192 tree stmt = push_stmt_list ();
7193 c_parser_statement (parser);
7194 return pop_stmt_list (stmt);
7198 # pragma omp atomic new-line
7202 x binop= expr | x++ | ++x | x-- | --x
7204 +, *, -, /, &, ^, |, <<, >>
7206 where x is an lvalue expression with scalar type. */
7209 c_parser_omp_atomic (c_parser *parser)
7212 enum tree_code code;
7214 c_parser_skip_to_pragma_eol (parser);
7216 lhs = c_parser_unary_expression (parser).value;
7217 switch (TREE_CODE (lhs))
7221 c_parser_skip_to_end_of_block_or_statement (parser);
7224 case PREINCREMENT_EXPR:
7225 case POSTINCREMENT_EXPR:
7226 lhs = TREE_OPERAND (lhs, 0);
7228 rhs = integer_one_node;
7231 case PREDECREMENT_EXPR:
7232 case POSTDECREMENT_EXPR:
7233 lhs = TREE_OPERAND (lhs, 0);
7235 rhs = integer_one_node;
7239 switch (c_parser_peek_token (parser)->type)
7245 code = TRUNC_DIV_EXPR;
7260 code = BIT_AND_EXPR;
7263 code = BIT_IOR_EXPR;
7266 code = BIT_XOR_EXPR;
7269 c_parser_error (parser,
7270 "invalid operator for %<#pragma omp atomic%>");
7274 c_parser_consume_token (parser);
7275 rhs = c_parser_expression (parser).value;
7278 c_finish_omp_atomic (code, lhs, rhs);
7279 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7284 # pragma omp barrier new-line
7288 c_parser_omp_barrier (c_parser *parser)
7290 c_parser_consume_pragma (parser);
7291 c_parser_skip_to_pragma_eol (parser);
7293 c_finish_omp_barrier ();
7297 # pragma omp critical [(name)] new-line
7302 c_parser_omp_critical (c_parser *parser)
7304 tree stmt, name = NULL;
7306 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7308 c_parser_consume_token (parser);
7309 if (c_parser_next_token_is (parser, CPP_NAME))
7311 name = c_parser_peek_token (parser)->value;
7312 c_parser_consume_token (parser);
7313 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7316 c_parser_error (parser, "expected identifier");
7318 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7319 c_parser_error (parser, "expected %<(%> or end of line");
7320 c_parser_skip_to_pragma_eol (parser);
7322 stmt = c_parser_omp_structured_block (parser);
7323 return c_finish_omp_critical (stmt, name);
7327 # pragma omp flush flush-vars[opt] new-line
7330 ( variable-list ) */
7333 c_parser_omp_flush (c_parser *parser)
7335 c_parser_consume_pragma (parser);
7336 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7337 c_parser_omp_var_list_parens (parser, 0, NULL);
7338 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7339 c_parser_error (parser, "expected %<(%> or end of line");
7340 c_parser_skip_to_pragma_eol (parser);
7342 c_finish_omp_flush ();
7345 /* Parse the restricted form of the for statment allowed by OpenMP.
7346 The real trick here is to determine the loop control variable early
7347 so that we can push a new decl if necessary to make it private. */
7350 c_parser_omp_for_loop (c_parser *parser)
7352 tree decl, cond, incr, save_break, save_cont, body, init;
7355 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7357 c_parser_error (parser, "for statement expected");
7360 loc = c_parser_peek_token (parser)->location;
7361 c_parser_consume_token (parser);
7363 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7366 /* Parse the initialization declaration or expression. */
7367 if (c_parser_next_token_starts_declspecs (parser))
7369 c_parser_declaration_or_fndef (parser, true, true, true, true);
7370 decl = check_for_loop_decls ();
7375 else if (c_parser_next_token_is (parser, CPP_NAME)
7376 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7378 decl = c_parser_postfix_expression (parser).value;
7380 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7382 init = c_parser_expr_no_commas (parser, NULL).value;
7383 init = build_modify_expr (decl, NOP_EXPR, init);
7384 init = c_process_expr_stmt (init);
7386 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7391 /* Parse the loop condition. */
7393 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
7395 cond = c_parser_expression_conv (parser).value;
7396 cond = c_objc_common_truthvalue_conversion (cond);
7398 SET_EXPR_LOCATION (cond, input_location);
7400 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7402 /* Parse the increment expression. */
7404 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7405 incr = c_process_expr_stmt (c_parser_expression (parser).value);
7406 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7409 save_break = c_break_label;
7410 c_break_label = size_one_node;
7411 save_cont = c_cont_label;
7412 c_cont_label = NULL_TREE;
7413 body = push_stmt_list ();
7415 add_stmt (c_parser_c99_block_statement (parser));
7417 add_stmt (build1 (LABEL_EXPR, void_type_node, c_cont_label));
7419 body = pop_stmt_list (body);
7420 c_break_label = save_break;
7421 c_cont_label = save_cont;
7423 /* Only bother calling c_finish_omp_for if we havn't already generated
7424 an error from the initialization parsing. */
7425 if (decl != NULL && decl != error_mark_node && init != error_mark_node)
7426 return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
7430 c_parser_error (parser, "expected iteration declaration or initialization");
7431 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7432 decl = init = cond = incr = NULL_TREE;
7437 #pragma omp for for-clause[optseq] new-line
7441 #define OMP_FOR_CLAUSE_MASK \
7442 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7443 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7444 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7445 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7446 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7447 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7448 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7451 c_parser_omp_for (c_parser *parser)
7453 tree block, clauses, ret;
7455 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
7458 block = c_begin_compound_stmt (true);
7459 ret = c_parser_omp_for_loop (parser);
7461 OMP_FOR_CLAUSES (ret) = clauses;
7462 block = c_end_compound_stmt (block, true);
7469 # pragma omp master new-line
7474 c_parser_omp_master (c_parser *parser)
7476 c_parser_skip_to_pragma_eol (parser);
7477 return c_finish_omp_master (c_parser_omp_structured_block (parser));
7481 # pragma omp ordered new-line
7486 c_parser_omp_ordered (c_parser *parser)
7488 c_parser_skip_to_pragma_eol (parser);
7489 return c_finish_omp_ordered (c_parser_omp_structured_block (parser));
7495 { section-sequence }
7498 section-directive[opt] structured-block
7499 section-sequence section-directive structured-block */
7502 c_parser_omp_sections_scope (c_parser *parser)
7505 bool error_suppress = false;
7508 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7510 /* Avoid skipping until the end of the block. */
7511 parser->error = false;
7515 stmt = push_stmt_list ();
7517 loc = c_parser_peek_token (parser)->location;
7518 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
7520 substmt = push_stmt_list ();
7524 c_parser_statement (parser);
7526 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7528 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7530 if (c_parser_next_token_is (parser, CPP_EOF))
7534 substmt = pop_stmt_list (substmt);
7535 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7536 SET_EXPR_LOCATION (substmt, loc);
7542 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7544 if (c_parser_next_token_is (parser, CPP_EOF))
7547 loc = c_parser_peek_token (parser)->location;
7548 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
7550 c_parser_consume_pragma (parser);
7551 c_parser_skip_to_pragma_eol (parser);
7552 error_suppress = false;
7554 else if (!error_suppress)
7556 error ("expected %<#pragma omp section%> or %<}%>");
7557 error_suppress = true;
7560 substmt = c_parser_omp_structured_block (parser);
7561 substmt = build1 (OMP_SECTION, void_type_node, substmt);
7562 SET_EXPR_LOCATION (substmt, loc);
7565 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
7566 "expected %<#pragma omp section%> or %<}%>");
7568 substmt = pop_stmt_list (stmt);
7570 stmt = make_node (OMP_SECTIONS);
7571 TREE_TYPE (stmt) = void_type_node;
7572 OMP_SECTIONS_BODY (stmt) = substmt;
7574 return add_stmt (stmt);
7578 # pragma omp sections sections-clause[optseq] newline
7582 #define OMP_SECTIONS_CLAUSE_MASK \
7583 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7584 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7585 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7586 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7587 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7590 c_parser_omp_sections (c_parser *parser)
7592 tree block, clauses, ret;
7594 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
7595 "#pragma omp sections");
7597 block = c_begin_compound_stmt (true);
7598 ret = c_parser_omp_sections_scope (parser);
7600 OMP_SECTIONS_CLAUSES (ret) = clauses;
7601 block = c_end_compound_stmt (block, true);
7608 # pragma parallel parallel-clause new-line
7609 # pragma parallel for parallel-for-clause new-line
7610 # pragma parallel sections parallel-sections-clause new-line
7613 #define OMP_PARALLEL_CLAUSE_MASK \
7614 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7615 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7616 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7617 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7618 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7619 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7620 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7621 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7624 c_parser_omp_parallel (c_parser *parser)
7626 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
7627 const char *p_name = "#pragma omp parallel";
7628 tree stmt, clauses, par_clause, ws_clause, block;
7629 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
7631 if (c_parser_next_token_is_keyword (parser, RID_FOR))
7633 c_parser_consume_token (parser);
7634 p_kind = PRAGMA_OMP_PARALLEL_FOR;
7635 p_name = "#pragma omp parallel for";
7636 mask |= OMP_FOR_CLAUSE_MASK;
7637 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7639 else if (c_parser_next_token_is (parser, CPP_NAME))
7641 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7642 if (strcmp (p, "sections") == 0)
7644 c_parser_consume_token (parser);
7645 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
7646 p_name = "#pragma omp parallel sections";
7647 mask |= OMP_SECTIONS_CLAUSE_MASK;
7648 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
7652 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
7656 case PRAGMA_OMP_PARALLEL:
7657 block = c_begin_omp_parallel ();
7658 c_parser_statement (parser);
7659 stmt = c_finish_omp_parallel (clauses, block);
7662 case PRAGMA_OMP_PARALLEL_FOR:
7663 block = c_begin_omp_parallel ();
7664 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7665 stmt = c_parser_omp_for_loop (parser);
7667 OMP_FOR_CLAUSES (stmt) = ws_clause;
7668 stmt = c_finish_omp_parallel (par_clause, block);
7669 OMP_PARALLEL_COMBINED (stmt) = 1;
7672 case PRAGMA_OMP_PARALLEL_SECTIONS:
7673 block = c_begin_omp_parallel ();
7674 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
7675 stmt = c_parser_omp_sections_scope (parser);
7677 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
7678 stmt = c_finish_omp_parallel (par_clause, block);
7679 OMP_PARALLEL_COMBINED (stmt) = 1;
7690 # pragma omp single single-clause[optseq] new-line
7694 #define OMP_SINGLE_CLAUSE_MASK \
7695 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7696 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7697 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7698 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7701 c_parser_omp_single (c_parser *parser)
7703 tree stmt = make_node (OMP_SINGLE);
7704 TREE_TYPE (stmt) = void_type_node;
7706 OMP_SINGLE_CLAUSES (stmt)
7707 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
7708 "#pragma omp single");
7709 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
7711 return add_stmt (stmt);
7715 /* Main entry point to parsing most OpenMP pragmas. */
7718 c_parser_omp_construct (c_parser *parser)
7720 enum pragma_kind p_kind;
7724 loc = c_parser_peek_token (parser)->location;
7725 p_kind = c_parser_peek_token (parser)->pragma_kind;
7726 c_parser_consume_pragma (parser);
7730 case PRAGMA_OMP_ATOMIC:
7731 c_parser_omp_atomic (parser);
7733 case PRAGMA_OMP_CRITICAL:
7734 stmt = c_parser_omp_critical (parser);
7736 case PRAGMA_OMP_FOR:
7737 stmt = c_parser_omp_for (parser);
7739 case PRAGMA_OMP_MASTER:
7740 stmt = c_parser_omp_master (parser);
7742 case PRAGMA_OMP_ORDERED:
7743 stmt = c_parser_omp_ordered (parser);
7745 case PRAGMA_OMP_PARALLEL:
7746 stmt = c_parser_omp_parallel (parser);
7748 case PRAGMA_OMP_SECTIONS:
7749 stmt = c_parser_omp_sections (parser);
7751 case PRAGMA_OMP_SINGLE:
7752 stmt = c_parser_omp_single (parser);
7759 SET_EXPR_LOCATION (stmt, loc);
7764 # pragma omp threadprivate (variable-list) */
7767 c_parser_omp_threadprivate (c_parser *parser)
7771 c_parser_consume_pragma (parser);
7772 vars = c_parser_omp_var_list_parens (parser, 0, NULL);
7774 if (!targetm.have_tls)
7775 sorry ("threadprivate variables not supported in this target");
7777 /* Mark every variable in VARS to be assigned thread local storage. */
7778 for (t = vars; t; t = TREE_CHAIN (t))
7780 tree v = TREE_PURPOSE (t);
7782 /* If V had already been marked threadprivate, it doesn't matter
7783 whether it had been used prior to this point. */
7784 if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
7785 error ("%qE declared %<threadprivate%> after first use", v);
7786 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7787 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7788 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
7789 error ("%<threadprivate%> %qE has incomplete type", v);
7792 if (! DECL_THREAD_LOCAL_P (v))
7794 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
7795 /* If rtl has been already set for this var, call
7796 make_decl_rtl once again, so that encode_section_info
7797 has a chance to look at the new decl flags. */
7798 if (DECL_RTL_SET_P (v))
7801 C_DECL_THREADPRIVATE_P (v) = 1;
7805 c_parser_skip_to_pragma_eol (parser);
7809 /* Parse a single source file. */
7814 /* Use local storage to begin. If the first token is a pragma, parse it.
7815 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7816 which will cause garbage collection. */
7819 memset (&tparser, 0, sizeof tparser);
7820 the_parser = &tparser;
7822 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
7823 c_parser_pragma_pch_preprocess (&tparser);
7825 the_parser = GGC_NEW (c_parser);
7826 *the_parser = tparser;
7828 c_parser_translation_unit (the_parser);
7832 #include "gt-c-parser.h"