1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
55 #include "c-family/c-common.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX <= 255);
82 mask |= D_ASM | D_EXT;
86 if (!c_dialect_objc ())
87 mask |= D_OBJC | D_CXX_OBJC;
89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
90 for (i = 0; i < num_c_common_reswords; i++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords[i].disable & mask)
97 && (c_common_reswords[i].disable & D_CXXWARN))
99 id = get_identifier (c_common_reswords[i].word);
100 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
101 C_IS_RESERVED_WORD (id) = 1;
106 id = get_identifier (c_common_reswords[i].word);
107 C_SET_RID_CODE (id, c_common_reswords[i].rid);
108 C_IS_RESERVED_WORD (id) = 1;
109 ridpointers [(int) c_common_reswords[i].rid] = id;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind {
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token {
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype) type : 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind) id_kind : 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid) keyword : 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser {
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error : 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma : 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block : 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string : 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context : 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context : 1;
193 /* The following flag is needed to contextualize Objective-C lexical
194 analysis. In some cases (e.g., 'int NSObject;'), it is
195 undesirable to bind an identifier to an Objective-C class, even
196 if a class with that name exists. */
197 BOOL_BITFIELD objc_need_raw_identifier : 1;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context : 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser *the_parser;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser *parser, c_token *token)
214 timevar_push (TV_LEX);
216 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
217 (parser->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE : 0));
219 token->id_kind = C_ID_NONE;
220 token->keyword = RID_MAX;
221 token->pragma_kind = PRAGMA_NONE;
229 bool objc_force_identifier = parser->objc_need_raw_identifier;
230 if (c_dialect_objc ())
231 parser->objc_need_raw_identifier = false;
233 if (C_IS_RESERVED_WORD (token->value))
235 enum rid rid_code = C_RID_CODE (token->value);
237 if (rid_code == RID_CXX_COMPAT_WARN)
239 warning_at (token->location,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code >= RID_FIRST_ADDR_SPACE
245 && rid_code <= RID_LAST_ADDR_SPACE)
247 token->id_kind = C_ID_ADDRSPACE;
248 token->keyword = rid_code;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
258 if (parser->objc_pq_context)
260 token->type = CPP_KEYWORD;
261 token->keyword = rid_code;
264 else if (parser->objc_could_be_foreach_context
265 && rid_code == RID_IN)
267 /* We are in Objective-C, inside a (potential)
268 foreach context (which means after having
269 parsed 'for (', but before having parsed ';'),
270 and we found 'in'. We consider it the keyword
271 which terminates the declaration at the
272 beginning of a foreach-statement. Note that
273 this means you can't use 'in' for anything else
274 in that context; in particular, in Objective-C
275 you can't use 'in' as the name of the running
276 variable in a C for loop. We could potentially
277 try to add code here to disambiguate, but it
278 seems a reasonable limitation.
280 token->type = CPP_KEYWORD;
281 token->keyword = rid_code;
284 /* Else, "pq" keywords outside of the "pq" context are
285 not keywords, and we fall through to the code for
289 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
291 /* We found an Objective-C "property attribute" keyword
292 (readonly, copies, getter, setter, ivar). These are
293 only valid in the property context. */
294 if (parser->objc_property_attr_context)
296 token->type = CPP_KEYWORD;
297 token->keyword = rid_code;
300 /* Else they are not special keywords.
303 else if (c_dialect_objc ()
304 && (OBJC_IS_AT_KEYWORD (rid_code)
305 || OBJC_IS_CXX_KEYWORD (rid_code)))
307 /* We found one of the Objective-C "@" keywords (defs,
308 selector, synchronized, etc) or one of the
309 Objective-C "cxx" keywords (class, private,
310 protected, public, try, catch, throw) without a
311 preceding '@' sign. Do nothing and fall through to
312 the code for normal tokens (in C++ we would still
313 consider the CXX ones keywords, but not in C).
319 token->type = CPP_KEYWORD;
320 token->keyword = rid_code;
325 decl = lookup_name (token->value);
328 if (TREE_CODE (decl) == TYPE_DECL)
330 token->id_kind = C_ID_TYPENAME;
334 else if (c_dialect_objc ())
336 tree objc_interface_decl = objc_is_class_name (token->value);
337 /* Objective-C class names are in the same namespace as
338 variables and typedefs, and hence are shadowed by local
340 if (objc_interface_decl
341 && (global_bindings_p ()
342 || (!objc_force_identifier && !decl)))
344 token->value = objc_interface_decl;
345 token->id_kind = C_ID_CLASSNAME;
349 token->id_kind = C_ID_ID;
353 /* This only happens in Objective-C; it must be a keyword. */
354 token->type = CPP_KEYWORD;
355 switch (C_RID_CODE (token->value))
357 /* Replace 'class' with '@class', 'private' with '@private',
358 etc. This prevents confusion with the C++ keyword
359 'class', and makes the tokens consistent with other
360 Objective-C 'AT' keywords. For example '@class' is
361 reported as RID_AT_CLASS which is consistent with
362 '@synchronized', which is reported as
365 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
366 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
367 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
368 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
369 case RID_THROW: token->keyword = RID_AT_THROW; break;
370 case RID_TRY: token->keyword = RID_AT_TRY; break;
371 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
372 default: token->keyword = C_RID_CODE (token->value);
377 case CPP_CLOSE_PAREN:
379 /* These tokens may affect the interpretation of any identifiers
380 following, if doing Objective-C. */
381 if (c_dialect_objc ())
382 parser->objc_need_raw_identifier = false;
385 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
386 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
392 timevar_pop (TV_LEX);
395 /* Return a pointer to the next token from PARSER, reading it in if
398 static inline c_token *
399 c_parser_peek_token (c_parser *parser)
401 if (parser->tokens_avail == 0)
403 c_lex_one_token (parser, &parser->tokens[0]);
404 parser->tokens_avail = 1;
406 return &parser->tokens[0];
409 /* Return true if the next token from PARSER has the indicated
413 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
415 return c_parser_peek_token (parser)->type == type;
418 /* Return true if the next token from PARSER does not have the
422 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
424 return !c_parser_next_token_is (parser, type);
427 /* Return true if the next token from PARSER is the indicated
431 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
433 return c_parser_peek_token (parser)->keyword == keyword;
436 /* Return true if TOKEN can start a type name,
439 c_token_starts_typename (c_token *token)
444 switch (token->id_kind)
453 gcc_assert (c_dialect_objc ());
459 switch (token->keyword)
492 if (c_dialect_objc ())
500 /* Return true if the next token from PARSER can start a type name,
503 c_parser_next_token_starts_typename (c_parser *parser)
505 c_token *token = c_parser_peek_token (parser);
506 return c_token_starts_typename (token);
509 /* Return true if TOKEN can start declaration specifiers, false
512 c_token_starts_declspecs (c_token *token)
517 switch (token->id_kind)
526 gcc_assert (c_dialect_objc ());
532 switch (token->keyword)
572 if (c_dialect_objc ())
581 /* Return true if TOKEN can start declaration specifiers or a static
582 assertion, false otherwise. */
584 c_token_starts_declaration (c_token *token)
586 if (c_token_starts_declspecs (token)
587 || token->keyword == RID_STATIC_ASSERT)
593 static c_token *c_parser_peek_2nd_token (c_parser *parser);
595 /* Return true if the next token from PARSER can start declaration
596 specifiers, false otherwise. */
598 c_parser_next_token_starts_declspecs (c_parser *parser)
600 c_token *token = c_parser_peek_token (parser);
601 return c_token_starts_declspecs (token);
604 /* Return true if the next token from PARSER can start declaration
605 specifiers or a static assertion, false otherwise. */
607 c_parser_next_token_starts_declaration (c_parser *parser)
609 c_token *token = c_parser_peek_token (parser);
610 return c_token_starts_declaration (token);
613 /* Return a pointer to the next-but-one token from PARSER, reading it
614 in if necessary. The next token is already read in. */
617 c_parser_peek_2nd_token (c_parser *parser)
619 if (parser->tokens_avail >= 2)
620 return &parser->tokens[1];
621 gcc_assert (parser->tokens_avail == 1);
622 gcc_assert (parser->tokens[0].type != CPP_EOF);
623 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
624 c_lex_one_token (parser, &parser->tokens[1]);
625 parser->tokens_avail = 2;
626 return &parser->tokens[1];
629 /* Consume the next token from PARSER. */
632 c_parser_consume_token (c_parser *parser)
634 gcc_assert (parser->tokens_avail >= 1);
635 gcc_assert (parser->tokens[0].type != CPP_EOF);
636 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
637 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
638 if (parser->tokens_avail == 2)
639 parser->tokens[0] = parser->tokens[1];
640 parser->tokens_avail--;
643 /* Expect the current token to be a #pragma. Consume it and remember
644 that we've begun parsing a pragma. */
647 c_parser_consume_pragma (c_parser *parser)
649 gcc_assert (!parser->in_pragma);
650 gcc_assert (parser->tokens_avail >= 1);
651 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
652 if (parser->tokens_avail == 2)
653 parser->tokens[0] = parser->tokens[1];
654 parser->tokens_avail--;
655 parser->in_pragma = true;
658 /* Update the globals input_location and in_system_header from
661 c_parser_set_source_position_from_token (c_token *token)
663 if (token->type != CPP_EOF)
665 input_location = token->location;
669 /* Issue a diagnostic of the form
670 FILE:LINE: MESSAGE before TOKEN
671 where TOKEN is the next token in the input stream of PARSER.
672 MESSAGE (specified by the caller) is usually of the form "expected
675 Do not issue a diagnostic if still recovering from an error.
677 ??? This is taken from the C++ parser, but building up messages in
678 this way is not i18n-friendly and some other approach should be
682 c_parser_error (c_parser *parser, const char *gmsgid)
684 c_token *token = c_parser_peek_token (parser);
687 parser->error = true;
690 /* This diagnostic makes more sense if it is tagged to the line of
691 the token we just peeked at. */
692 c_parser_set_source_position_from_token (token);
693 c_parse_error (gmsgid,
694 /* Because c_parse_error does not understand
695 CPP_KEYWORD, keywords are treated like
697 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
698 /* ??? The C parser does not save the cpp flags of a
699 token, we need to pass 0 here and we will not get
700 the source spelling of some tokens but rather the
701 canonical spelling. */
702 token->value, /*flags=*/0);
705 /* If the next token is of the indicated TYPE, consume it. Otherwise,
706 issue the error MSGID. If MSGID is NULL then a message has already
707 been produced and no message will be produced this time. Returns
708 true if found, false otherwise. */
711 c_parser_require (c_parser *parser,
715 if (c_parser_next_token_is (parser, type))
717 c_parser_consume_token (parser);
722 c_parser_error (parser, msgid);
727 /* If the next token is the indicated keyword, consume it. Otherwise,
728 issue the error MSGID. Returns true if found, false otherwise. */
731 c_parser_require_keyword (c_parser *parser,
735 if (c_parser_next_token_is_keyword (parser, keyword))
737 c_parser_consume_token (parser);
742 c_parser_error (parser, msgid);
747 /* Like c_parser_require, except that tokens will be skipped until the
748 desired token is found. An error message is still produced if the
749 next token is not as expected. If MSGID is NULL then a message has
750 already been produced and no message will be produced this
754 c_parser_skip_until_found (c_parser *parser,
758 unsigned nesting_depth = 0;
760 if (c_parser_require (parser, type, msgid))
763 /* Skip tokens until the desired token is found. */
766 /* Peek at the next token. */
767 c_token *token = c_parser_peek_token (parser);
768 /* If we've reached the token we want, consume it and stop. */
769 if (token->type == type && !nesting_depth)
771 c_parser_consume_token (parser);
775 /* If we've run out of tokens, stop. */
776 if (token->type == CPP_EOF)
778 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
780 if (token->type == CPP_OPEN_BRACE
781 || token->type == CPP_OPEN_PAREN
782 || token->type == CPP_OPEN_SQUARE)
784 else if (token->type == CPP_CLOSE_BRACE
785 || token->type == CPP_CLOSE_PAREN
786 || token->type == CPP_CLOSE_SQUARE)
788 if (nesting_depth-- == 0)
791 /* Consume this token. */
792 c_parser_consume_token (parser);
794 parser->error = false;
797 /* Skip tokens until the end of a parameter is found, but do not
798 consume the comma, semicolon or closing delimiter. */
801 c_parser_skip_to_end_of_parameter (c_parser *parser)
803 unsigned nesting_depth = 0;
807 c_token *token = c_parser_peek_token (parser);
808 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
811 /* If we've run out of tokens, stop. */
812 if (token->type == CPP_EOF)
814 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
816 if (token->type == CPP_OPEN_BRACE
817 || token->type == CPP_OPEN_PAREN
818 || token->type == CPP_OPEN_SQUARE)
820 else if (token->type == CPP_CLOSE_BRACE
821 || token->type == CPP_CLOSE_PAREN
822 || token->type == CPP_CLOSE_SQUARE)
824 if (nesting_depth-- == 0)
827 /* Consume this token. */
828 c_parser_consume_token (parser);
830 parser->error = false;
833 /* Expect to be at the end of the pragma directive and consume an
834 end of line marker. */
837 c_parser_skip_to_pragma_eol (c_parser *parser)
839 gcc_assert (parser->in_pragma);
840 parser->in_pragma = false;
842 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
845 c_token *token = c_parser_peek_token (parser);
846 if (token->type == CPP_EOF)
848 if (token->type == CPP_PRAGMA_EOL)
850 c_parser_consume_token (parser);
853 c_parser_consume_token (parser);
856 parser->error = false;
859 /* Skip tokens until we have consumed an entire block, or until we
860 have consumed a non-nested ';'. */
863 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
865 unsigned nesting_depth = 0;
866 bool save_error = parser->error;
872 /* Peek at the next token. */
873 token = c_parser_peek_token (parser);
881 if (parser->in_pragma)
886 /* If the next token is a ';', we have reached the
887 end of the statement. */
890 /* Consume the ';'. */
891 c_parser_consume_token (parser);
896 case CPP_CLOSE_BRACE:
897 /* If the next token is a non-nested '}', then we have
898 reached the end of the current block. */
899 if (nesting_depth == 0 || --nesting_depth == 0)
901 c_parser_consume_token (parser);
907 /* If it the next token is a '{', then we are entering a new
908 block. Consume the entire block. */
913 /* If we see a pragma, consume the whole thing at once. We
914 have some safeguards against consuming pragmas willy-nilly.
915 Normally, we'd expect to be here with parser->error set,
916 which disables these safeguards. But it's possible to get
917 here for secondary error recovery, after parser->error has
919 c_parser_consume_pragma (parser);
920 c_parser_skip_to_pragma_eol (parser);
921 parser->error = save_error;
928 c_parser_consume_token (parser);
932 parser->error = false;
935 /* CPP's options (initialized by c-opts.c). */
936 extern cpp_options *cpp_opts;
938 /* Save the warning flags which are controlled by __extension__. */
941 disable_extension_diagnostics (void)
944 | (warn_pointer_arith << 1)
945 | (warn_traditional << 2)
947 | (warn_long_long << 4)
948 | (warn_cxx_compat << 5));
949 cpp_opts->cpp_pedantic = pedantic = 0;
950 warn_pointer_arith = 0;
951 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
953 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
958 /* Restore the warning flags which are controlled by __extension__.
959 FLAGS is the return value from disable_extension_diagnostics. */
962 restore_extension_diagnostics (int flags)
964 cpp_opts->cpp_pedantic = pedantic = flags & 1;
965 warn_pointer_arith = (flags >> 1) & 1;
966 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
967 flag_iso = (flags >> 3) & 1;
968 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
969 warn_cxx_compat = (flags >> 5) & 1;
972 /* Possibly kinds of declarator to parse. */
973 typedef enum c_dtr_syn {
974 /* A normal declarator with an identifier. */
976 /* An abstract declarator (maybe empty). */
978 /* A parameter declarator: may be either, but after a type name does
979 not redeclare a typedef name as an identifier if it can
980 alternatively be interpreted as a typedef name; see DR#009,
981 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
982 following DR#249. For example, given a typedef T, "int T" and
983 "int *T" are valid parameter declarations redeclaring T, while
984 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
985 abstract declarators rather than involving redundant parentheses;
986 the same applies with attributes inside the parentheses before
991 static void c_parser_external_declaration (c_parser *);
992 static void c_parser_asm_definition (c_parser *);
993 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
995 static void c_parser_static_assert_declaration_no_semi (c_parser *);
996 static void c_parser_static_assert_declaration (c_parser *);
997 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
999 static struct c_typespec c_parser_enum_specifier (c_parser *);
1000 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1001 static tree c_parser_struct_declaration (c_parser *);
1002 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1003 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1005 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1007 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1009 struct c_declarator *);
1010 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1011 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1012 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1013 static tree c_parser_simple_asm_expr (c_parser *);
1014 static tree c_parser_attributes (c_parser *);
1015 static struct c_type_name *c_parser_type_name (c_parser *);
1016 static struct c_expr c_parser_initializer (c_parser *);
1017 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1018 static void c_parser_initelt (c_parser *, struct obstack *);
1019 static void c_parser_initval (c_parser *, struct c_expr *,
1021 static tree c_parser_compound_statement (c_parser *);
1022 static void c_parser_compound_statement_nostart (c_parser *);
1023 static void c_parser_label (c_parser *);
1024 static void c_parser_statement (c_parser *);
1025 static void c_parser_statement_after_labels (c_parser *);
1026 static void c_parser_if_statement (c_parser *);
1027 static void c_parser_switch_statement (c_parser *);
1028 static void c_parser_while_statement (c_parser *);
1029 static void c_parser_do_statement (c_parser *);
1030 static void c_parser_for_statement (c_parser *);
1031 static tree c_parser_asm_statement (c_parser *);
1032 static tree c_parser_asm_operands (c_parser *, bool);
1033 static tree c_parser_asm_goto_operands (c_parser *);
1034 static tree c_parser_asm_clobbers (c_parser *);
1035 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1036 static struct c_expr c_parser_conditional_expression (c_parser *,
1038 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1039 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1040 static struct c_expr c_parser_unary_expression (c_parser *);
1041 static struct c_expr c_parser_sizeof_expression (c_parser *);
1042 static struct c_expr c_parser_alignof_expression (c_parser *);
1043 static struct c_expr c_parser_postfix_expression (c_parser *);
1044 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1045 struct c_type_name *,
1047 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1050 static struct c_expr c_parser_expression (c_parser *);
1051 static struct c_expr c_parser_expression_conv (c_parser *);
1052 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1054 static void c_parser_omp_construct (c_parser *);
1055 static void c_parser_omp_threadprivate (c_parser *);
1056 static void c_parser_omp_barrier (c_parser *);
1057 static void c_parser_omp_flush (c_parser *);
1058 static void c_parser_omp_taskwait (c_parser *);
1060 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1061 static bool c_parser_pragma (c_parser *, enum pragma_context);
1063 /* These Objective-C parser functions are only ever called when
1064 compiling Objective-C. */
1065 static void c_parser_objc_class_definition (c_parser *, tree);
1066 static void c_parser_objc_class_instance_variables (c_parser *);
1067 static void c_parser_objc_class_declaration (c_parser *);
1068 static void c_parser_objc_alias_declaration (c_parser *);
1069 static void c_parser_objc_protocol_definition (c_parser *, tree);
1070 static enum tree_code c_parser_objc_method_type (c_parser *);
1071 static void c_parser_objc_method_definition (c_parser *);
1072 static void c_parser_objc_methodprotolist (c_parser *);
1073 static void c_parser_objc_methodproto (c_parser *);
1074 static tree c_parser_objc_method_decl (c_parser *, tree *);
1075 static tree c_parser_objc_type_name (c_parser *);
1076 static tree c_parser_objc_protocol_refs (c_parser *);
1077 static void c_parser_objc_try_catch_statement (c_parser *);
1078 static void c_parser_objc_synchronized_statement (c_parser *);
1079 static tree c_parser_objc_selector (c_parser *);
1080 static tree c_parser_objc_selector_arg (c_parser *);
1081 static tree c_parser_objc_receiver (c_parser *);
1082 static tree c_parser_objc_message_args (c_parser *);
1083 static tree c_parser_objc_keywordexpr (c_parser *);
1084 static void c_parser_objc_at_property (c_parser *) ;
1085 static bool c_parser_objc_diagnose_bad_element_prefix
1086 (c_parser *, struct c_declspecs *);
1088 /* Parse a translation unit (C90 6.7, C99 6.9).
1091 external-declarations
1093 external-declarations:
1094 external-declaration
1095 external-declarations external-declaration
1104 c_parser_translation_unit (c_parser *parser)
1106 if (c_parser_next_token_is (parser, CPP_EOF))
1108 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1109 "ISO C forbids an empty translation unit");
1113 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1114 mark_valid_location_for_stdc_pragma (false);
1118 c_parser_external_declaration (parser);
1119 obstack_free (&parser_obstack, obstack_position);
1121 while (c_parser_next_token_is_not (parser, CPP_EOF));
1125 /* Parse an external declaration (C90 6.7, C99 6.9).
1127 external-declaration:
1133 external-declaration:
1136 __extension__ external-declaration
1140 external-declaration:
1141 objc-class-definition
1142 objc-class-declaration
1143 objc-alias-declaration
1144 objc-protocol-definition
1145 objc-method-definition
1150 c_parser_external_declaration (c_parser *parser)
1153 switch (c_parser_peek_token (parser)->type)
1156 switch (c_parser_peek_token (parser)->keyword)
1159 ext = disable_extension_diagnostics ();
1160 c_parser_consume_token (parser);
1161 c_parser_external_declaration (parser);
1162 restore_extension_diagnostics (ext);
1165 c_parser_asm_definition (parser);
1167 case RID_AT_INTERFACE:
1168 case RID_AT_IMPLEMENTATION:
1169 gcc_assert (c_dialect_objc ());
1170 c_parser_objc_class_definition (parser, NULL_TREE);
1173 gcc_assert (c_dialect_objc ());
1174 c_parser_objc_class_declaration (parser);
1177 gcc_assert (c_dialect_objc ());
1178 c_parser_objc_alias_declaration (parser);
1180 case RID_AT_PROTOCOL:
1181 gcc_assert (c_dialect_objc ());
1182 c_parser_objc_protocol_definition (parser, NULL_TREE);
1184 case RID_AT_PROPERTY:
1185 gcc_assert (c_dialect_objc ());
1186 c_parser_objc_at_property (parser);
1189 gcc_assert (c_dialect_objc ());
1190 c_parser_consume_token (parser);
1191 objc_finish_implementation ();
1198 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1199 "ISO C does not allow extra %<;%> outside of a function");
1200 c_parser_consume_token (parser);
1203 mark_valid_location_for_stdc_pragma (true);
1204 c_parser_pragma (parser, pragma_external);
1205 mark_valid_location_for_stdc_pragma (false);
1209 if (c_dialect_objc ())
1211 c_parser_objc_method_definition (parser);
1214 /* Else fall through, and yield a syntax error trying to parse
1215 as a declaration or function definition. */
1218 /* A declaration or a function definition (or, in Objective-C,
1219 an @interface or @protocol with prefix attributes). We can
1220 only tell which after parsing the declaration specifiers, if
1221 any, and the first declarator. */
1222 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1227 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1228 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1229 accepted; otherwise (old-style parameter declarations) only other
1230 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1231 assertion is accepted; otherwise (old-style parameter declarations)
1232 it is not. If NESTED is true, we are inside a function or parsing
1233 old-style parameter declarations; any functions encountered are
1234 nested functions and declaration specifiers are required; otherwise
1235 we are at top level and functions are normal functions and
1236 declaration specifiers may be optional. If EMPTY_OK is true, empty
1237 declarations are OK (subject to all other constraints); otherwise
1238 (old-style parameter declarations) they are diagnosed. If
1239 START_ATTR_OK is true, the declaration specifiers may start with
1240 attributes; otherwise they may not.
1241 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1242 declaration when parsing an Objective-C foreach statement.
1245 declaration-specifiers init-declarator-list[opt] ;
1246 static_assert-declaration
1248 function-definition:
1249 declaration-specifiers[opt] declarator declaration-list[opt]
1254 declaration-list declaration
1256 init-declarator-list:
1258 init-declarator-list , init-declarator
1261 declarator simple-asm-expr[opt] attributes[opt]
1262 declarator simple-asm-expr[opt] attributes[opt] = initializer
1266 nested-function-definition:
1267 declaration-specifiers declarator declaration-list[opt]
1271 attributes objc-class-definition
1272 attributes objc-category-definition
1273 attributes objc-protocol-definition
1275 The simple-asm-expr and attributes are GNU extensions.
1277 This function does not handle __extension__; that is handled in its
1278 callers. ??? Following the old parser, __extension__ may start
1279 external declarations, declarations in functions and declarations
1280 at the start of "for" loops, but not old-style parameter
1283 C99 requires declaration specifiers in a function definition; the
1284 absence is diagnosed through the diagnosis of implicit int. In GNU
1285 C we also allow but diagnose declarations without declaration
1286 specifiers, but only at top level (elsewhere they conflict with
1289 In Objective-C, declarations of the looping variable in a foreach
1290 statement are exceptionally terminated by 'in' (for example, 'for
1291 (NSObject *object in array) { ... }').
1296 threadprivate-directive */
1299 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1300 bool static_assert_ok, bool empty_ok,
1301 bool nested, bool start_attr_ok,
1302 tree *objc_foreach_object_declaration)
1304 struct c_declspecs *specs;
1306 tree all_prefix_attrs;
1307 bool diagnosed_no_specs = false;
1308 location_t here = c_parser_peek_token (parser)->location;
1310 if (static_assert_ok
1311 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1313 c_parser_static_assert_declaration (parser);
1316 specs = build_null_declspecs ();
1317 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1320 c_parser_skip_to_end_of_block_or_statement (parser);
1323 if (nested && !specs->declspecs_seen_p)
1325 c_parser_error (parser, "expected declaration specifiers");
1326 c_parser_skip_to_end_of_block_or_statement (parser);
1329 finish_declspecs (specs);
1330 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1336 shadow_tag_warned (specs, 1);
1337 pedwarn (here, 0, "empty declaration");
1339 c_parser_consume_token (parser);
1342 else if (c_dialect_objc ())
1344 /* Prefix attributes are an error on method decls. */
1345 switch (c_parser_peek_token (parser)->type)
1349 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1353 warning_at (c_parser_peek_token (parser)->location,
1355 "prefix attributes are ignored for methods");
1356 specs->attrs = NULL_TREE;
1359 c_parser_objc_method_definition (parser);
1361 c_parser_objc_methodproto (parser);
1367 /* This is where we parse 'attributes @interface ...',
1368 'attributes @implementation ...', 'attributes @protocol ...'
1369 (where attributes could be, for example, __attribute__
1372 switch (c_parser_peek_token (parser)->keyword)
1374 case RID_AT_INTERFACE:
1376 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1378 c_parser_objc_class_definition (parser, specs->attrs);
1382 case RID_AT_IMPLEMENTATION:
1384 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1388 warning_at (c_parser_peek_token (parser)->location,
1390 "prefix attributes are ignored for implementations");
1391 specs->attrs = NULL_TREE;
1393 c_parser_objc_class_definition (parser, NULL_TREE);
1397 case RID_AT_PROTOCOL:
1399 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1401 c_parser_objc_protocol_definition (parser, specs->attrs);
1408 case RID_AT_PROPERTY:
1411 c_parser_error (parser,
1412 "attributes may not be specified before" );
1413 specs->attrs = NULL;
1421 pending_xref_error ();
1422 prefix_attrs = specs->attrs;
1423 all_prefix_attrs = prefix_attrs;
1424 specs->attrs = NULL_TREE;
1427 struct c_declarator *declarator;
1430 /* Declaring either one or more declarators (in which case we
1431 should diagnose if there were no declaration specifiers) or a
1432 function definition (in which case the diagnostic for
1433 implicit int suffices). */
1434 declarator = c_parser_declarator (parser, specs->type_seen_p,
1435 C_DTR_NORMAL, &dummy);
1436 if (declarator == NULL)
1438 c_parser_skip_to_end_of_block_or_statement (parser);
1441 if (c_parser_next_token_is (parser, CPP_EQ)
1442 || c_parser_next_token_is (parser, CPP_COMMA)
1443 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1444 || c_parser_next_token_is_keyword (parser, RID_ASM)
1445 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1446 || c_parser_next_token_is_keyword (parser, RID_IN))
1448 tree asm_name = NULL_TREE;
1449 tree postfix_attrs = NULL_TREE;
1450 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1452 diagnosed_no_specs = true;
1453 pedwarn (here, 0, "data definition has no type or storage class");
1455 /* Having seen a data definition, there cannot now be a
1456 function definition. */
1458 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1459 asm_name = c_parser_simple_asm_expr (parser);
1460 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1461 postfix_attrs = c_parser_attributes (parser);
1462 if (c_parser_next_token_is (parser, CPP_EQ))
1466 location_t init_loc;
1467 c_parser_consume_token (parser);
1468 /* The declaration of the variable is in effect while
1469 its initializer is parsed. */
1470 d = start_decl (declarator, specs, true,
1471 chainon (postfix_attrs, all_prefix_attrs));
1473 d = error_mark_node;
1474 start_init (d, asm_name, global_bindings_p ());
1475 init_loc = c_parser_peek_token (parser)->location;
1476 init = c_parser_initializer (parser);
1478 if (d != error_mark_node)
1480 maybe_warn_string_init (TREE_TYPE (d), init);
1481 finish_decl (d, init_loc, init.value,
1482 init.original_type, asm_name);
1487 tree d = start_decl (declarator, specs, false,
1488 chainon (postfix_attrs,
1491 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1492 NULL_TREE, asm_name);
1494 if (c_parser_next_token_is_keyword (parser, RID_IN))
1497 *objc_foreach_object_declaration = d;
1499 *objc_foreach_object_declaration = error_mark_node;
1502 if (c_parser_next_token_is (parser, CPP_COMMA))
1504 c_parser_consume_token (parser);
1505 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1506 all_prefix_attrs = chainon (c_parser_attributes (parser),
1509 all_prefix_attrs = prefix_attrs;
1512 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1514 c_parser_consume_token (parser);
1517 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1519 /* This can only happen in Objective-C: we found the
1520 'in' that terminates the declaration inside an
1521 Objective-C foreach statement. Do not consume the
1522 token, so that the caller can use it to determine
1523 that this indeed is a foreach context. */
1528 c_parser_error (parser, "expected %<,%> or %<;%>");
1529 c_parser_skip_to_end_of_block_or_statement (parser);
1535 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1536 "%<asm%> or %<__attribute__%>");
1537 c_parser_skip_to_end_of_block_or_statement (parser);
1540 /* Function definition (nested or otherwise). */
1543 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1544 c_push_function_context ();
1546 if (!start_function (specs, declarator, all_prefix_attrs))
1548 /* This can appear in many cases looking nothing like a
1549 function definition, so we don't give a more specific
1550 error suggesting there was one. */
1551 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1552 "or %<__attribute__%>");
1554 c_pop_function_context ();
1557 /* Parse old-style parameter declarations. ??? Attributes are
1558 not allowed to start declaration specifiers here because of a
1559 syntax conflict between a function declaration with attribute
1560 suffix and a function definition with an attribute prefix on
1561 first old-style parameter declaration. Following the old
1562 parser, they are not accepted on subsequent old-style
1563 parameter declarations either. However, there is no
1564 ambiguity after the first declaration, nor indeed on the
1565 first as long as we don't allow postfix attributes after a
1566 declarator with a nonempty identifier list in a definition;
1567 and postfix attributes have never been accepted here in
1568 function definitions either. */
1569 while (c_parser_next_token_is_not (parser, CPP_EOF)
1570 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1571 c_parser_declaration_or_fndef (parser, false, false, false,
1573 store_parm_decls ();
1574 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1575 = c_parser_peek_token (parser)->location;
1576 fnbody = c_parser_compound_statement (parser);
1579 tree decl = current_function_decl;
1580 /* Mark nested functions as needing static-chain initially.
1581 lower_nested_functions will recompute it but the
1582 DECL_STATIC_CHAIN flag is also used before that happens,
1583 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1584 DECL_STATIC_CHAIN (decl) = 1;
1587 c_pop_function_context ();
1588 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1599 /* Parse an asm-definition (asm() outside a function body). This is a
1607 c_parser_asm_definition (c_parser *parser)
1609 tree asm_str = c_parser_simple_asm_expr (parser);
1611 cgraph_add_asm_node (asm_str);
1612 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1615 /* Parse a static assertion (C1X N1425 6.7.10).
1617 static_assert-declaration:
1618 static_assert-declaration-no-semi ;
1622 c_parser_static_assert_declaration (c_parser *parser)
1624 c_parser_static_assert_declaration_no_semi (parser);
1626 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1627 c_parser_skip_to_end_of_block_or_statement (parser);
1630 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1633 static_assert-declaration-no-semi:
1634 _Static_assert ( constant-expression , string-literal )
1638 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1640 location_t assert_loc, value_loc;
1644 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1645 assert_loc = c_parser_peek_token (parser)->location;
1649 pedwarn (assert_loc, OPT_pedantic,
1650 "ISO C99 does not support %<_Static_assert%>");
1652 pedwarn (assert_loc, OPT_pedantic,
1653 "ISO C90 does not support %<_Static_assert%>");
1655 c_parser_consume_token (parser);
1656 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1658 value_loc = c_parser_peek_token (parser)->location;
1659 value = c_parser_expr_no_commas (parser, NULL).value;
1660 parser->lex_untranslated_string = true;
1661 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1663 parser->lex_untranslated_string = false;
1666 switch (c_parser_peek_token (parser)->type)
1672 case CPP_UTF8STRING:
1673 string = c_parser_peek_token (parser)->value;
1674 c_parser_consume_token (parser);
1675 parser->lex_untranslated_string = false;
1678 c_parser_error (parser, "expected string literal");
1679 parser->lex_untranslated_string = false;
1682 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1684 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1686 error_at (value_loc, "expression in static assertion is not an integer");
1689 if (TREE_CODE (value) != INTEGER_CST)
1691 value = c_fully_fold (value, false, NULL);
1692 if (TREE_CODE (value) == INTEGER_CST)
1693 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1694 "is not an integer constant expression");
1696 if (TREE_CODE (value) != INTEGER_CST)
1698 error_at (value_loc, "expression in static assertion is not constant");
1701 constant_expression_warning (value);
1702 if (integer_zerop (value))
1703 error_at (assert_loc, "static assertion failed: %E", string);
1706 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1707 6.7), adding them to SPECS (which may already include some).
1708 Storage class specifiers are accepted iff SCSPEC_OK; type
1709 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1710 the start iff START_ATTR_OK.
1712 declaration-specifiers:
1713 storage-class-specifier declaration-specifiers[opt]
1714 type-specifier declaration-specifiers[opt]
1715 type-qualifier declaration-specifiers[opt]
1716 function-specifier declaration-specifiers[opt]
1718 Function specifiers (inline) are from C99, and are currently
1719 handled as storage class specifiers, as is __thread.
1721 C90 6.5.1, C99 6.7.1:
1722 storage-class-specifier:
1733 C90 6.5.2, C99 6.7.2:
1746 [_Imaginary removed in C99 TC2]
1747 struct-or-union-specifier
1751 (_Bool and _Complex are new in C99.)
1753 C90 6.5.3, C99 6.7.3:
1759 address-space-qualifier
1761 (restrict is new in C99.)
1765 declaration-specifiers:
1766 attributes declaration-specifiers[opt]
1772 identifier recognized by the target
1774 storage-class-specifier:
1787 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1788 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1793 class-name objc-protocol-refs[opt]
1794 typedef-name objc-protocol-refs
1799 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1800 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1802 bool attrs_ok = start_attr_ok;
1803 bool seen_type = specs->type_seen_p;
1804 while (c_parser_next_token_is (parser, CPP_NAME)
1805 || c_parser_next_token_is (parser, CPP_KEYWORD)
1806 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1808 struct c_typespec t;
1810 location_t loc = c_parser_peek_token (parser)->location;
1811 if (c_parser_next_token_is (parser, CPP_NAME))
1813 tree value = c_parser_peek_token (parser)->value;
1814 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1816 if (kind == C_ID_ADDRSPACE)
1819 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1820 declspecs_add_addrspace (specs, as);
1821 c_parser_consume_token (parser);
1826 /* This finishes the specifiers unless a type name is OK, it
1827 is declared as a type name and a type name hasn't yet
1829 if (!typespec_ok || seen_type
1830 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1832 c_parser_consume_token (parser);
1835 if (kind == C_ID_TYPENAME
1836 && (!c_dialect_objc ()
1837 || c_parser_next_token_is_not (parser, CPP_LESS)))
1839 t.kind = ctsk_typedef;
1840 /* For a typedef name, record the meaning, not the name.
1841 In case of 'foo foo, bar;'. */
1842 t.spec = lookup_name (value);
1844 t.expr_const_operands = true;
1848 tree proto = NULL_TREE;
1849 gcc_assert (c_dialect_objc ());
1851 if (c_parser_next_token_is (parser, CPP_LESS))
1852 proto = c_parser_objc_protocol_refs (parser);
1853 t.spec = objc_get_protocol_qualified_type (value, proto);
1855 t.expr_const_operands = true;
1857 declspecs_add_type (loc, specs, t);
1860 if (c_parser_next_token_is (parser, CPP_LESS))
1862 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1863 nisse@lysator.liu.se. */
1865 gcc_assert (c_dialect_objc ());
1866 if (!typespec_ok || seen_type)
1868 proto = c_parser_objc_protocol_refs (parser);
1870 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1872 t.expr_const_operands = true;
1873 declspecs_add_type (loc, specs, t);
1876 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1877 switch (c_parser_peek_token (parser)->keyword)
1889 /* TODO: Distinguish between function specifiers (inline)
1890 and storage class specifiers, either here or in
1891 declspecs_add_scspec. */
1892 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1893 c_parser_consume_token (parser);
1917 if (c_dialect_objc ())
1918 parser->objc_need_raw_identifier = true;
1919 t.kind = ctsk_resword;
1920 t.spec = c_parser_peek_token (parser)->value;
1922 t.expr_const_operands = true;
1923 declspecs_add_type (loc, specs, t);
1924 c_parser_consume_token (parser);
1931 t = c_parser_enum_specifier (parser);
1932 declspecs_add_type (loc, specs, t);
1940 t = c_parser_struct_or_union_specifier (parser);
1941 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1942 declspecs_add_type (loc, specs, t);
1945 /* ??? The old parser rejected typeof after other type
1946 specifiers, but is a syntax error the best way of
1948 if (!typespec_ok || seen_type)
1952 t = c_parser_typeof_specifier (parser);
1953 declspecs_add_type (loc, specs, t);
1959 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1960 c_parser_consume_token (parser);
1965 attrs = c_parser_attributes (parser);
1966 declspecs_add_attrs (specs, attrs);
1975 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1978 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1979 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1980 enum attributes[opt] identifier
1982 The form with trailing comma is new in C99. The forms with
1983 attributes are GNU extensions. In GNU C, we accept any expression
1984 without commas in the syntax (assignment expressions, not just
1985 conditional expressions); assignment expressions will be diagnosed
1990 enumerator-list , enumerator
1993 enumeration-constant
1994 enumeration-constant = constant-expression
1997 static struct c_typespec
1998 c_parser_enum_specifier (c_parser *parser)
2000 struct c_typespec ret;
2002 tree ident = NULL_TREE;
2003 location_t enum_loc;
2004 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2005 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2006 enum_loc = c_parser_peek_token (parser)->location;
2007 c_parser_consume_token (parser);
2008 attrs = c_parser_attributes (parser);
2009 enum_loc = c_parser_peek_token (parser)->location;
2010 /* Set the location in case we create a decl now. */
2011 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2012 if (c_parser_next_token_is (parser, CPP_NAME))
2014 ident = c_parser_peek_token (parser)->value;
2015 ident_loc = c_parser_peek_token (parser)->location;
2016 enum_loc = ident_loc;
2017 c_parser_consume_token (parser);
2019 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2021 /* Parse an enum definition. */
2022 struct c_enum_contents the_enum;
2023 tree type = start_enum (enum_loc, &the_enum, ident);
2025 /* We chain the enumerators in reverse order, then put them in
2026 forward order at the end. */
2027 tree values = NULL_TREE;
2028 c_parser_consume_token (parser);
2036 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2037 location_t decl_loc, value_loc;
2038 if (c_parser_next_token_is_not (parser, CPP_NAME))
2040 c_parser_error (parser, "expected identifier");
2041 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2042 values = error_mark_node;
2045 token = c_parser_peek_token (parser);
2046 enum_id = token->value;
2047 /* Set the location in case we create a decl now. */
2048 c_parser_set_source_position_from_token (token);
2049 decl_loc = value_loc = token->location;
2050 c_parser_consume_token (parser);
2051 if (c_parser_next_token_is (parser, CPP_EQ))
2053 c_parser_consume_token (parser);
2054 value_loc = c_parser_peek_token (parser)->location;
2055 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2058 enum_value = NULL_TREE;
2059 enum_decl = build_enumerator (decl_loc, value_loc,
2060 &the_enum, enum_id, enum_value);
2061 TREE_CHAIN (enum_decl) = values;
2064 if (c_parser_next_token_is (parser, CPP_COMMA))
2066 comma_loc = c_parser_peek_token (parser)->location;
2068 c_parser_consume_token (parser);
2070 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2072 if (seen_comma && !flag_isoc99)
2073 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2074 c_parser_consume_token (parser);
2079 c_parser_error (parser, "expected %<,%> or %<}%>");
2080 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2081 values = error_mark_node;
2085 postfix_attrs = c_parser_attributes (parser);
2086 ret.spec = finish_enum (type, nreverse (values),
2087 chainon (attrs, postfix_attrs));
2088 ret.kind = ctsk_tagdef;
2089 ret.expr = NULL_TREE;
2090 ret.expr_const_operands = true;
2095 c_parser_error (parser, "expected %<{%>");
2096 ret.spec = error_mark_node;
2097 ret.kind = ctsk_tagref;
2098 ret.expr = NULL_TREE;
2099 ret.expr_const_operands = true;
2102 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2103 /* In ISO C, enumerated types can be referred to only if already
2105 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2108 pedwarn (enum_loc, OPT_pedantic,
2109 "ISO C forbids forward references to %<enum%> types");
2114 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2116 struct-or-union-specifier:
2117 struct-or-union attributes[opt] identifier[opt]
2118 { struct-contents } attributes[opt]
2119 struct-or-union attributes[opt] identifier
2122 struct-declaration-list
2124 struct-declaration-list:
2125 struct-declaration ;
2126 struct-declaration-list struct-declaration ;
2133 struct-declaration-list struct-declaration
2135 struct-declaration-list:
2136 struct-declaration-list ;
2139 (Note that in the syntax here, unlike that in ISO C, the semicolons
2140 are included here rather than in struct-declaration, in order to
2141 describe the syntax with extra semicolons and missing semicolon at
2146 struct-declaration-list:
2147 @defs ( class-name )
2149 (Note this does not include a trailing semicolon, but can be
2150 followed by further declarations, and gets a pedwarn-if-pedantic
2151 when followed by a semicolon.) */
2153 static struct c_typespec
2154 c_parser_struct_or_union_specifier (c_parser *parser)
2156 struct c_typespec ret;
2158 tree ident = NULL_TREE;
2159 location_t struct_loc;
2160 location_t ident_loc = UNKNOWN_LOCATION;
2161 enum tree_code code;
2162 switch (c_parser_peek_token (parser)->keyword)
2173 struct_loc = c_parser_peek_token (parser)->location;
2174 c_parser_consume_token (parser);
2175 attrs = c_parser_attributes (parser);
2177 /* Set the location in case we create a decl now. */
2178 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2180 if (c_parser_next_token_is (parser, CPP_NAME))
2182 ident = c_parser_peek_token (parser)->value;
2183 ident_loc = c_parser_peek_token (parser)->location;
2184 struct_loc = ident_loc;
2185 c_parser_consume_token (parser);
2187 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2189 /* Parse a struct or union definition. Start the scope of the
2190 tag before parsing components. */
2191 struct c_struct_parse_info *struct_info;
2192 tree type = start_struct (struct_loc, code, ident, &struct_info);
2194 /* We chain the components in reverse order, then put them in
2195 forward order at the end. Each struct-declaration may
2196 declare multiple components (comma-separated), so we must use
2197 chainon to join them, although when parsing each
2198 struct-declaration we can use TREE_CHAIN directly.
2200 The theory behind all this is that there will be more
2201 semicolon separated fields than comma separated fields, and
2202 so we'll be minimizing the number of node traversals required
2204 tree contents = NULL_TREE;
2205 c_parser_consume_token (parser);
2206 /* Handle the Objective-C @defs construct,
2207 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2208 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2211 gcc_assert (c_dialect_objc ());
2212 c_parser_consume_token (parser);
2213 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2215 if (c_parser_next_token_is (parser, CPP_NAME)
2216 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2218 name = c_parser_peek_token (parser)->value;
2219 c_parser_consume_token (parser);
2223 c_parser_error (parser, "expected class name");
2224 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2227 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2229 contents = nreverse (objc_get_class_ivars (name));
2232 /* Parse the struct-declarations and semicolons. Problems with
2233 semicolons are diagnosed here; empty structures are diagnosed
2238 /* Parse any stray semicolon. */
2239 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2241 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2242 "extra semicolon in struct or union specified");
2243 c_parser_consume_token (parser);
2246 /* Stop if at the end of the struct or union contents. */
2247 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2249 c_parser_consume_token (parser);
2252 /* Accept #pragmas at struct scope. */
2253 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2255 c_parser_pragma (parser, pragma_external);
2258 /* Parse some comma-separated declarations, but not the
2259 trailing semicolon if any. */
2260 decls = c_parser_struct_declaration (parser);
2261 contents = chainon (decls, contents);
2262 /* If no semicolon follows, either we have a parse error or
2263 are at the end of the struct or union and should
2265 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2266 c_parser_consume_token (parser);
2269 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2270 pedwarn (c_parser_peek_token (parser)->location, 0,
2271 "no semicolon at end of struct or union");
2274 c_parser_error (parser, "expected %<;%>");
2275 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2280 postfix_attrs = c_parser_attributes (parser);
2281 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2282 chainon (attrs, postfix_attrs), struct_info);
2283 ret.kind = ctsk_tagdef;
2284 ret.expr = NULL_TREE;
2285 ret.expr_const_operands = true;
2290 c_parser_error (parser, "expected %<{%>");
2291 ret.spec = error_mark_node;
2292 ret.kind = ctsk_tagref;
2293 ret.expr = NULL_TREE;
2294 ret.expr_const_operands = true;
2297 ret = parser_xref_tag (ident_loc, code, ident);
2301 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2302 the trailing semicolon.
2305 specifier-qualifier-list struct-declarator-list
2306 static_assert-declaration-no-semi
2308 specifier-qualifier-list:
2309 type-specifier specifier-qualifier-list[opt]
2310 type-qualifier specifier-qualifier-list[opt]
2311 attributes specifier-qualifier-list[opt]
2313 struct-declarator-list:
2315 struct-declarator-list , attributes[opt] struct-declarator
2318 declarator attributes[opt]
2319 declarator[opt] : constant-expression attributes[opt]
2324 __extension__ struct-declaration
2325 specifier-qualifier-list
2327 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2328 of attributes where shown is a GNU extension. In GNU C, we accept
2329 any expression without commas in the syntax (assignment
2330 expressions, not just conditional expressions); assignment
2331 expressions will be diagnosed as non-constant. */
2334 c_parser_struct_declaration (c_parser *parser)
2336 struct c_declspecs *specs;
2338 tree all_prefix_attrs;
2340 location_t decl_loc;
2341 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2345 ext = disable_extension_diagnostics ();
2346 c_parser_consume_token (parser);
2347 decl = c_parser_struct_declaration (parser);
2348 restore_extension_diagnostics (ext);
2351 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2353 c_parser_static_assert_declaration_no_semi (parser);
2356 specs = build_null_declspecs ();
2357 decl_loc = c_parser_peek_token (parser)->location;
2358 c_parser_declspecs (parser, specs, false, true, true);
2361 if (!specs->declspecs_seen_p)
2363 c_parser_error (parser, "expected specifier-qualifier-list");
2366 finish_declspecs (specs);
2367 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2370 if (!specs->type_seen_p)
2372 pedwarn (decl_loc, OPT_pedantic,
2373 "ISO C forbids member declarations with no members");
2374 shadow_tag_warned (specs, pedantic);
2379 /* Support for unnamed structs or unions as members of
2380 structs or unions (which is [a] useful and [b] supports
2384 ret = grokfield (c_parser_peek_token (parser)->location,
2385 build_id_declarator (NULL_TREE), specs,
2388 decl_attributes (&ret, attrs, 0);
2392 pending_xref_error ();
2393 prefix_attrs = specs->attrs;
2394 all_prefix_attrs = prefix_attrs;
2395 specs->attrs = NULL_TREE;
2399 /* Declaring one or more declarators or un-named bit-fields. */
2400 struct c_declarator *declarator;
2402 if (c_parser_next_token_is (parser, CPP_COLON))
2403 declarator = build_id_declarator (NULL_TREE);
2405 declarator = c_parser_declarator (parser, specs->type_seen_p,
2406 C_DTR_NORMAL, &dummy);
2407 if (declarator == NULL)
2409 c_parser_skip_to_end_of_block_or_statement (parser);
2412 if (c_parser_next_token_is (parser, CPP_COLON)
2413 || c_parser_next_token_is (parser, CPP_COMMA)
2414 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2415 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2416 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2418 tree postfix_attrs = NULL_TREE;
2419 tree width = NULL_TREE;
2421 if (c_parser_next_token_is (parser, CPP_COLON))
2423 c_parser_consume_token (parser);
2424 width = c_parser_expr_no_commas (parser, NULL).value;
2426 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2427 postfix_attrs = c_parser_attributes (parser);
2428 d = grokfield (c_parser_peek_token (parser)->location,
2429 declarator, specs, width, &all_prefix_attrs);
2430 decl_attributes (&d, chainon (postfix_attrs,
2431 all_prefix_attrs), 0);
2432 DECL_CHAIN (d) = decls;
2434 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2435 all_prefix_attrs = chainon (c_parser_attributes (parser),
2438 all_prefix_attrs = prefix_attrs;
2439 if (c_parser_next_token_is (parser, CPP_COMMA))
2440 c_parser_consume_token (parser);
2441 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2442 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2444 /* Semicolon consumed in caller. */
2449 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2455 c_parser_error (parser,
2456 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2457 "%<__attribute__%>");
2464 /* Parse a typeof specifier (a GNU extension).
2467 typeof ( expression )
2468 typeof ( type-name )
2471 static struct c_typespec
2472 c_parser_typeof_specifier (c_parser *parser)
2474 struct c_typespec ret;
2475 ret.kind = ctsk_typeof;
2476 ret.spec = error_mark_node;
2477 ret.expr = NULL_TREE;
2478 ret.expr_const_operands = true;
2479 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2480 c_parser_consume_token (parser);
2481 c_inhibit_evaluation_warnings++;
2483 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2485 c_inhibit_evaluation_warnings--;
2489 if (c_parser_next_token_starts_typename (parser))
2491 struct c_type_name *type = c_parser_type_name (parser);
2492 c_inhibit_evaluation_warnings--;
2496 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2497 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2503 location_t here = c_parser_peek_token (parser)->location;
2504 struct c_expr expr = c_parser_expression (parser);
2505 c_inhibit_evaluation_warnings--;
2507 if (TREE_CODE (expr.value) == COMPONENT_REF
2508 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2509 error_at (here, "%<typeof%> applied to a bit-field");
2510 mark_exp_read (expr.value);
2511 ret.spec = TREE_TYPE (expr.value);
2512 if (c_dialect_objc()
2513 && ret.spec != error_mark_node
2514 && lookup_attribute ("objc_volatilized", TYPE_ATTRIBUTES (ret.spec)))
2515 ret.spec = build_qualified_type
2516 (ret.spec, (TYPE_QUALS (ret.spec) & ~TYPE_QUAL_VOLATILE));
2517 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2518 /* This is returned with the type so that when the type is
2519 evaluated, this can be evaluated. */
2521 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2522 pop_maybe_used (was_vm);
2524 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2528 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2529 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2530 be redeclared; otherwise it may not. KIND indicates which kind of
2531 declarator is wanted. Returns a valid declarator except in the
2532 case of a syntax error in which case NULL is returned. *SEEN_ID is
2533 set to true if an identifier being declared is seen; this is used
2534 to diagnose bad forms of abstract array declarators and to
2535 determine whether an identifier list is syntactically permitted.
2538 pointer[opt] direct-declarator
2542 ( attributes[opt] declarator )
2543 direct-declarator array-declarator
2544 direct-declarator ( parameter-type-list )
2545 direct-declarator ( identifier-list[opt] )
2548 * type-qualifier-list[opt]
2549 * type-qualifier-list[opt] pointer
2551 type-qualifier-list:
2554 type-qualifier-list type-qualifier
2555 type-qualifier-list attributes
2557 parameter-type-list:
2559 parameter-list , ...
2562 parameter-declaration
2563 parameter-list , parameter-declaration
2565 parameter-declaration:
2566 declaration-specifiers declarator attributes[opt]
2567 declaration-specifiers abstract-declarator[opt] attributes[opt]
2571 identifier-list , identifier
2573 abstract-declarator:
2575 pointer[opt] direct-abstract-declarator
2577 direct-abstract-declarator:
2578 ( attributes[opt] abstract-declarator )
2579 direct-abstract-declarator[opt] array-declarator
2580 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2585 direct-declarator ( parameter-forward-declarations
2586 parameter-type-list[opt] )
2588 direct-abstract-declarator:
2589 direct-abstract-declarator[opt] ( parameter-forward-declarations
2590 parameter-type-list[opt] )
2592 parameter-forward-declarations:
2594 parameter-forward-declarations parameter-list ;
2596 The uses of attributes shown above are GNU extensions.
2598 Some forms of array declarator are not included in C99 in the
2599 syntax for abstract declarators; these are disallowed elsewhere.
2600 This may be a defect (DR#289).
2602 This function also accepts an omitted abstract declarator as being
2603 an abstract declarator, although not part of the formal syntax. */
2605 static struct c_declarator *
2606 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2609 /* Parse any initial pointer part. */
2610 if (c_parser_next_token_is (parser, CPP_MULT))
2612 struct c_declspecs *quals_attrs = build_null_declspecs ();
2613 struct c_declarator *inner;
2614 c_parser_consume_token (parser);
2615 c_parser_declspecs (parser, quals_attrs, false, false, true);
2616 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2620 return make_pointer_declarator (quals_attrs, inner);
2622 /* Now we have a direct declarator, direct abstract declarator or
2623 nothing (which counts as a direct abstract declarator here). */
2624 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2627 /* Parse a direct declarator or direct abstract declarator; arguments
2628 as c_parser_declarator. */
2630 static struct c_declarator *
2631 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2634 /* The direct declarator must start with an identifier (possibly
2635 omitted) or a parenthesized declarator (possibly abstract). In
2636 an ordinary declarator, initial parentheses must start a
2637 parenthesized declarator. In an abstract declarator or parameter
2638 declarator, they could start a parenthesized declarator or a
2639 parameter list. To tell which, the open parenthesis and any
2640 following attributes must be read. If a declaration specifier
2641 follows, then it is a parameter list; if the specifier is a
2642 typedef name, there might be an ambiguity about redeclaring it,
2643 which is resolved in the direction of treating it as a typedef
2644 name. If a close parenthesis follows, it is also an empty
2645 parameter list, as the syntax does not permit empty abstract
2646 declarators. Otherwise, it is a parenthesized declarator (in
2647 which case the analysis may be repeated inside it, recursively).
2649 ??? There is an ambiguity in a parameter declaration "int
2650 (__attribute__((foo)) x)", where x is not a typedef name: it
2651 could be an abstract declarator for a function, or declare x with
2652 parentheses. The proper resolution of this ambiguity needs
2653 documenting. At present we follow an accident of the old
2654 parser's implementation, whereby the first parameter must have
2655 some declaration specifiers other than just attributes. Thus as
2656 a parameter declaration it is treated as a parenthesized
2657 parameter named x, and as an abstract declarator it is
2660 ??? Also following the old parser, attributes inside an empty
2661 parameter list are ignored, making it a list not yielding a
2662 prototype, rather than giving an error or making it have one
2663 parameter with implicit type int.
2665 ??? Also following the old parser, typedef names may be
2666 redeclared in declarators, but not Objective-C class names. */
2668 if (kind != C_DTR_ABSTRACT
2669 && c_parser_next_token_is (parser, CPP_NAME)
2671 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2672 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2673 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2675 struct c_declarator *inner
2676 = build_id_declarator (c_parser_peek_token (parser)->value);
2678 inner->id_loc = c_parser_peek_token (parser)->location;
2679 c_parser_consume_token (parser);
2680 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2683 if (kind != C_DTR_NORMAL
2684 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2686 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2687 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2690 /* Either we are at the end of an abstract declarator, or we have
2693 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2696 struct c_declarator *inner;
2697 c_parser_consume_token (parser);
2698 attrs = c_parser_attributes (parser);
2699 if (kind != C_DTR_NORMAL
2700 && (c_parser_next_token_starts_declspecs (parser)
2701 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2703 struct c_arg_info *args
2704 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2711 = build_function_declarator (args,
2712 build_id_declarator (NULL_TREE));
2713 return c_parser_direct_declarator_inner (parser, *seen_id,
2717 /* A parenthesized declarator. */
2718 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2719 if (inner != NULL && attrs != NULL)
2720 inner = build_attrs_declarator (attrs, inner);
2721 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2723 c_parser_consume_token (parser);
2727 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2731 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2738 if (kind == C_DTR_NORMAL)
2740 c_parser_error (parser, "expected identifier or %<(%>");
2744 return build_id_declarator (NULL_TREE);
2748 /* Parse part of a direct declarator or direct abstract declarator,
2749 given that some (in INNER) has already been parsed; ID_PRESENT is
2750 true if an identifier is present, false for an abstract
2753 static struct c_declarator *
2754 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2755 struct c_declarator *inner)
2757 /* Parse a sequence of array declarators and parameter lists. */
2758 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2760 location_t brace_loc = c_parser_peek_token (parser)->location;
2761 struct c_declarator *declarator;
2762 struct c_declspecs *quals_attrs = build_null_declspecs ();
2766 c_parser_consume_token (parser);
2767 c_parser_declspecs (parser, quals_attrs, false, false, true);
2768 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2770 c_parser_consume_token (parser);
2771 if (static_seen && !quals_attrs->declspecs_seen_p)
2772 c_parser_declspecs (parser, quals_attrs, false, false, true);
2773 if (!quals_attrs->declspecs_seen_p)
2775 /* If "static" is present, there must be an array dimension.
2776 Otherwise, there may be a dimension, "*", or no
2781 dimen = c_parser_expr_no_commas (parser, NULL).value;
2785 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2790 else if (c_parser_next_token_is (parser, CPP_MULT))
2792 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2796 c_parser_consume_token (parser);
2801 dimen = c_parser_expr_no_commas (parser, NULL).value;
2807 dimen = c_parser_expr_no_commas (parser, NULL).value;
2810 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2811 c_parser_consume_token (parser);
2814 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2819 mark_exp_read (dimen);
2820 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2821 static_seen, star_seen);
2822 if (declarator == NULL)
2824 inner = set_array_declarator_inner (declarator, inner);
2825 return c_parser_direct_declarator_inner (parser, id_present, inner);
2827 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2830 struct c_arg_info *args;
2831 c_parser_consume_token (parser);
2832 attrs = c_parser_attributes (parser);
2833 args = c_parser_parms_declarator (parser, id_present, attrs);
2838 inner = build_function_declarator (args, inner);
2839 return c_parser_direct_declarator_inner (parser, id_present, inner);
2845 /* Parse a parameter list or identifier list, including the closing
2846 parenthesis but not the opening one. ATTRS are the attributes at
2847 the start of the list. ID_LIST_OK is true if an identifier list is
2848 acceptable; such a list must not have attributes at the start. */
2850 static struct c_arg_info *
2851 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2854 declare_parm_level ();
2855 /* If the list starts with an identifier, it is an identifier list.
2856 Otherwise, it is either a prototype list or an empty list. */
2859 && c_parser_next_token_is (parser, CPP_NAME)
2860 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2862 tree list = NULL_TREE, *nextp = &list;
2863 while (c_parser_next_token_is (parser, CPP_NAME)
2864 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2866 *nextp = build_tree_list (NULL_TREE,
2867 c_parser_peek_token (parser)->value);
2868 nextp = & TREE_CHAIN (*nextp);
2869 c_parser_consume_token (parser);
2870 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2872 c_parser_consume_token (parser);
2873 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2875 c_parser_error (parser, "expected identifier");
2879 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2881 struct c_arg_info *ret = build_arg_info ();
2883 c_parser_consume_token (parser);
2889 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2897 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2903 /* Parse a parameter list (possibly empty), including the closing
2904 parenthesis but not the opening one. ATTRS are the attributes at
2905 the start of the list. */
2907 static struct c_arg_info *
2908 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2910 bool bad_parm = false;
2911 /* ??? Following the old parser, forward parameter declarations may
2912 use abstract declarators, and if no real parameter declarations
2913 follow the forward declarations then this is not diagnosed. Also
2914 note as above that attributes are ignored as the only contents of
2915 the parentheses, or as the only contents after forward
2917 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2919 struct c_arg_info *ret = build_arg_info ();
2920 c_parser_consume_token (parser);
2923 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2925 struct c_arg_info *ret = build_arg_info ();
2926 /* Suppress -Wold-style-definition for this case. */
2927 ret->types = error_mark_node;
2928 error_at (c_parser_peek_token (parser)->location,
2929 "ISO C requires a named argument before %<...%>");
2930 c_parser_consume_token (parser);
2931 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2933 c_parser_consume_token (parser);
2938 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2943 /* Nonempty list of parameters, either terminated with semicolon
2944 (forward declarations; recurse) or with close parenthesis (normal
2945 function) or with ", ... )" (variadic function). */
2948 /* Parse a parameter. */
2949 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2954 push_parm_decl (parm);
2955 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2958 c_parser_consume_token (parser);
2959 mark_forward_parm_decls ();
2960 new_attrs = c_parser_attributes (parser);
2961 return c_parser_parms_list_declarator (parser, new_attrs);
2963 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2965 c_parser_consume_token (parser);
2968 get_pending_sizes ();
2972 return get_parm_info (false);
2974 if (!c_parser_require (parser, CPP_COMMA,
2975 "expected %<;%>, %<,%> or %<)%>"))
2977 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2978 get_pending_sizes ();
2981 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2983 c_parser_consume_token (parser);
2984 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2986 c_parser_consume_token (parser);
2989 get_pending_sizes ();
2993 return get_parm_info (true);
2997 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2999 get_pending_sizes ();
3006 /* Parse a parameter declaration. ATTRS are the attributes at the
3007 start of the declaration if it is the first parameter. */
3009 static struct c_parm *
3010 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3012 struct c_declspecs *specs;
3013 struct c_declarator *declarator;
3015 tree postfix_attrs = NULL_TREE;
3017 if (!c_parser_next_token_starts_declspecs (parser))
3019 c_token *token = c_parser_peek_token (parser);
3022 c_parser_set_source_position_from_token (token);
3023 if (token->type == CPP_NAME
3024 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
3025 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
3027 error ("unknown type name %qE", token->value);
3028 parser->error = true;
3030 /* ??? In some Objective-C cases '...' isn't applicable so there
3031 should be a different message. */
3033 c_parser_error (parser,
3034 "expected declaration specifiers or %<...%>");
3035 c_parser_skip_to_end_of_parameter (parser);
3038 specs = build_null_declspecs ();
3041 declspecs_add_attrs (specs, attrs);
3044 c_parser_declspecs (parser, specs, true, true, true);
3045 finish_declspecs (specs);
3046 pending_xref_error ();
3047 prefix_attrs = specs->attrs;
3048 specs->attrs = NULL_TREE;
3049 declarator = c_parser_declarator (parser, specs->type_seen_p,
3050 C_DTR_PARM, &dummy);
3051 if (declarator == NULL)
3053 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3056 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3057 postfix_attrs = c_parser_attributes (parser);
3058 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3062 /* Parse a string literal in an asm expression. It should not be
3063 translated, and wide string literals are an error although
3064 permitted by the syntax. This is a GNU extension.
3069 ??? At present, following the old parser, the caller needs to have
3070 set lex_untranslated_string to 1. It would be better to follow the
3071 C++ parser rather than using this kludge. */
3074 c_parser_asm_string_literal (c_parser *parser)
3077 if (c_parser_next_token_is (parser, CPP_STRING))
3079 str = c_parser_peek_token (parser)->value;
3080 c_parser_consume_token (parser);
3082 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3084 error_at (c_parser_peek_token (parser)->location,
3085 "wide string literal in %<asm%>");
3086 str = build_string (1, "");
3087 c_parser_consume_token (parser);
3091 c_parser_error (parser, "expected string literal");
3097 /* Parse a simple asm expression. This is used in restricted
3098 contexts, where a full expression with inputs and outputs does not
3099 make sense. This is a GNU extension.
3102 asm ( asm-string-literal )
3106 c_parser_simple_asm_expr (c_parser *parser)
3109 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3110 /* ??? Follow the C++ parser rather than using the
3111 lex_untranslated_string kludge. */
3112 parser->lex_untranslated_string = true;
3113 c_parser_consume_token (parser);
3114 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3116 parser->lex_untranslated_string = false;
3119 str = c_parser_asm_string_literal (parser);
3120 parser->lex_untranslated_string = false;
3121 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3123 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3129 /* Parse (possibly empty) attributes. This is a GNU extension.
3133 attributes attribute
3136 __attribute__ ( ( attribute-list ) )
3140 attribute_list , attrib
3145 any-word ( identifier )
3146 any-word ( identifier , nonempty-expr-list )
3147 any-word ( expr-list )
3149 where the "identifier" must not be declared as a type, and
3150 "any-word" may be any identifier (including one declared as a
3151 type), a reserved word storage class specifier, type specifier or
3152 type qualifier. ??? This still leaves out most reserved keywords
3153 (following the old parser), shouldn't we include them, and why not
3154 allow identifiers declared as types to start the arguments? */
3157 c_parser_attributes (c_parser *parser)
3159 tree attrs = NULL_TREE;
3160 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3162 /* ??? Follow the C++ parser rather than using the
3163 lex_untranslated_string kludge. */
3164 parser->lex_untranslated_string = true;
3165 c_parser_consume_token (parser);
3166 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3168 parser->lex_untranslated_string = false;
3171 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3173 parser->lex_untranslated_string = false;
3174 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3177 /* Parse the attribute list. */
3178 while (c_parser_next_token_is (parser, CPP_COMMA)
3179 || c_parser_next_token_is (parser, CPP_NAME)
3180 || c_parser_next_token_is (parser, CPP_KEYWORD))
3182 tree attr, attr_name, attr_args;
3183 VEC(tree,gc) *expr_list;
3184 if (c_parser_next_token_is (parser, CPP_COMMA))
3186 c_parser_consume_token (parser);
3189 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3191 /* ??? See comment above about what keywords are
3194 switch (c_parser_peek_token (parser)->keyword)
3232 /* Accept __attribute__((__const)) as __attribute__((const))
3235 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3238 attr_name = c_parser_peek_token (parser)->value;
3239 c_parser_consume_token (parser);
3240 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3242 attr = build_tree_list (attr_name, NULL_TREE);
3243 attrs = chainon (attrs, attr);
3246 c_parser_consume_token (parser);
3247 /* Parse the attribute contents. If they start with an
3248 identifier which is followed by a comma or close
3249 parenthesis, then the arguments start with that
3250 identifier; otherwise they are an expression list. */
3251 if (c_parser_next_token_is (parser, CPP_NAME)
3252 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3253 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3254 || (c_parser_peek_2nd_token (parser)->type
3255 == CPP_CLOSE_PAREN)))
3257 tree arg1 = c_parser_peek_token (parser)->value;
3258 c_parser_consume_token (parser);
3259 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3260 attr_args = build_tree_list (NULL_TREE, arg1);
3264 c_parser_consume_token (parser);
3265 expr_list = c_parser_expr_list (parser, false, true, NULL);
3266 tree_list = build_tree_list_vec (expr_list);
3267 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3268 release_tree_vector (expr_list);
3273 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3274 attr_args = NULL_TREE;
3277 expr_list = c_parser_expr_list (parser, false, true, NULL);
3278 attr_args = build_tree_list_vec (expr_list);
3279 release_tree_vector (expr_list);
3282 attr = build_tree_list (attr_name, attr_args);
3283 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3284 c_parser_consume_token (parser);
3287 parser->lex_untranslated_string = false;
3288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3292 attrs = chainon (attrs, attr);
3294 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3295 c_parser_consume_token (parser);
3298 parser->lex_untranslated_string = false;
3299 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3303 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3304 c_parser_consume_token (parser);
3307 parser->lex_untranslated_string = false;
3308 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3312 parser->lex_untranslated_string = false;
3317 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3320 specifier-qualifier-list abstract-declarator[opt]
3323 static struct c_type_name *
3324 c_parser_type_name (c_parser *parser)
3326 struct c_declspecs *specs = build_null_declspecs ();
3327 struct c_declarator *declarator;
3328 struct c_type_name *ret;
3330 c_parser_declspecs (parser, specs, false, true, true);
3331 if (!specs->declspecs_seen_p)
3333 c_parser_error (parser, "expected specifier-qualifier-list");
3336 pending_xref_error ();
3337 finish_declspecs (specs);
3338 declarator = c_parser_declarator (parser, specs->type_seen_p,
3339 C_DTR_ABSTRACT, &dummy);
3340 if (declarator == NULL)
3342 ret = XOBNEW (&parser_obstack, struct c_type_name);
3344 ret->declarator = declarator;
3348 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3351 assignment-expression
3352 { initializer-list }
3353 { initializer-list , }
3356 designation[opt] initializer
3357 initializer-list , designation[opt] initializer
3364 designator-list designator
3371 [ constant-expression ]
3383 [ constant-expression ... constant-expression ]
3385 Any expression without commas is accepted in the syntax for the
3386 constant-expressions, with non-constant expressions rejected later.
3388 This function is only used for top-level initializers; for nested
3389 ones, see c_parser_initval. */
3391 static struct c_expr
3392 c_parser_initializer (c_parser *parser)
3394 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3395 return c_parser_braced_init (parser, NULL_TREE, false);
3399 location_t loc = c_parser_peek_token (parser)->location;
3400 ret = c_parser_expr_no_commas (parser, NULL);
3401 if (TREE_CODE (ret.value) != STRING_CST
3402 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3403 ret = default_function_array_read_conversion (loc, ret);
3408 /* Parse a braced initializer list. TYPE is the type specified for a
3409 compound literal, and NULL_TREE for other initializers and for
3410 nested braced lists. NESTED_P is true for nested braced lists,
3411 false for the list of a compound literal or the list that is the
3412 top-level initializer in a declaration. */
3414 static struct c_expr
3415 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3418 struct obstack braced_init_obstack;
3419 location_t brace_loc = c_parser_peek_token (parser)->location;
3420 gcc_obstack_init (&braced_init_obstack);
3421 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3422 c_parser_consume_token (parser);
3424 push_init_level (0, &braced_init_obstack);
3426 really_start_incremental_init (type);
3427 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3429 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3433 /* Parse a non-empty initializer list, possibly with a trailing
3437 c_parser_initelt (parser, &braced_init_obstack);
3440 if (c_parser_next_token_is (parser, CPP_COMMA))
3441 c_parser_consume_token (parser);
3444 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3448 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3450 ret.value = error_mark_node;
3451 ret.original_code = ERROR_MARK;
3452 ret.original_type = NULL;
3453 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3454 pop_init_level (0, &braced_init_obstack);
3455 obstack_free (&braced_init_obstack, NULL);
3458 c_parser_consume_token (parser);
3459 ret = pop_init_level (0, &braced_init_obstack);
3460 obstack_free (&braced_init_obstack, NULL);
3464 /* Parse a nested initializer, including designators. */
3467 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3469 /* Parse any designator or designator list. A single array
3470 designator may have the subsequent "=" omitted in GNU C, but a
3471 longer list or a structure member designator may not. */
3472 if (c_parser_next_token_is (parser, CPP_NAME)
3473 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3475 /* Old-style structure member designator. */
3476 set_init_label (c_parser_peek_token (parser)->value,
3477 braced_init_obstack);
3478 /* Use the colon as the error location. */
3479 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3480 "obsolete use of designated initializer with %<:%>");
3481 c_parser_consume_token (parser);
3482 c_parser_consume_token (parser);
3486 /* des_seen is 0 if there have been no designators, 1 if there
3487 has been a single array designator and 2 otherwise. */
3489 /* Location of a designator. */
3490 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3491 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3492 || c_parser_next_token_is (parser, CPP_DOT))
3494 int des_prev = des_seen;
3496 des_loc = c_parser_peek_token (parser)->location;
3499 if (c_parser_next_token_is (parser, CPP_DOT))
3502 c_parser_consume_token (parser);
3503 if (c_parser_next_token_is (parser, CPP_NAME))
3505 set_init_label (c_parser_peek_token (parser)->value,
3506 braced_init_obstack);
3507 c_parser_consume_token (parser);
3512 init.value = error_mark_node;
3513 init.original_code = ERROR_MARK;
3514 init.original_type = NULL;
3515 c_parser_error (parser, "expected identifier");
3516 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3517 process_init_element (init, false, braced_init_obstack);
3524 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3525 /* ??? Following the old parser, [ objc-receiver
3526 objc-message-args ] is accepted as an initializer,
3527 being distinguished from a designator by what follows
3528 the first assignment expression inside the square
3529 brackets, but after a first array designator a
3530 subsequent square bracket is for Objective-C taken to
3531 start an expression, using the obsolete form of
3532 designated initializer without '=', rather than
3533 possibly being a second level of designation: in LALR
3534 terms, the '[' is shifted rather than reducing
3535 designator to designator-list. */
3536 if (des_prev == 1 && c_dialect_objc ())
3538 des_seen = des_prev;
3541 if (des_prev == 0 && c_dialect_objc ())
3543 /* This might be an array designator or an
3544 Objective-C message expression. If the former,
3545 continue parsing here; if the latter, parse the
3546 remainder of the initializer given the starting
3547 primary-expression. ??? It might make sense to
3548 distinguish when des_prev == 1 as well; see
3549 previous comment. */
3551 struct c_expr mexpr;
3552 c_parser_consume_token (parser);
3553 if (c_parser_peek_token (parser)->type == CPP_NAME
3554 && ((c_parser_peek_token (parser)->id_kind
3556 || (c_parser_peek_token (parser)->id_kind
3557 == C_ID_CLASSNAME)))
3559 /* Type name receiver. */
3560 tree id = c_parser_peek_token (parser)->value;
3561 c_parser_consume_token (parser);
3562 rec = objc_get_class_reference (id);
3563 goto parse_message_args;
3565 first = c_parser_expr_no_commas (parser, NULL).value;
3566 mark_exp_read (first);
3567 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3568 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3569 goto array_desig_after_first;
3570 /* Expression receiver. So far only one part
3571 without commas has been parsed; there might be
3572 more of the expression. */
3574 while (c_parser_next_token_is (parser, CPP_COMMA))
3577 location_t comma_loc, exp_loc;
3578 comma_loc = c_parser_peek_token (parser)->location;
3579 c_parser_consume_token (parser);
3580 exp_loc = c_parser_peek_token (parser)->location;
3581 next = c_parser_expr_no_commas (parser, NULL);
3582 next = default_function_array_read_conversion (exp_loc,
3584 rec = build_compound_expr (comma_loc, rec, next.value);
3587 /* Now parse the objc-message-args. */
3588 args = c_parser_objc_message_args (parser);
3589 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3592 = objc_build_message_expr (build_tree_list (rec, args));
3593 mexpr.original_code = ERROR_MARK;
3594 mexpr.original_type = NULL;
3595 /* Now parse and process the remainder of the
3596 initializer, starting with this message
3597 expression as a primary-expression. */
3598 c_parser_initval (parser, &mexpr, braced_init_obstack);
3601 c_parser_consume_token (parser);
3602 first = c_parser_expr_no_commas (parser, NULL).value;
3603 mark_exp_read (first);
3604 array_desig_after_first:
3605 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3607 ellipsis_loc = c_parser_peek_token (parser)->location;
3608 c_parser_consume_token (parser);
3609 second = c_parser_expr_no_commas (parser, NULL).value;
3610 mark_exp_read (second);
3614 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3616 c_parser_consume_token (parser);
3617 set_init_index (first, second, braced_init_obstack);
3619 pedwarn (ellipsis_loc, OPT_pedantic,
3620 "ISO C forbids specifying range of elements to initialize");
3623 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3629 if (c_parser_next_token_is (parser, CPP_EQ))
3632 pedwarn (des_loc, OPT_pedantic,
3633 "ISO C90 forbids specifying subobject to initialize");
3634 c_parser_consume_token (parser);
3639 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3640 "obsolete use of designated initializer without %<=%>");
3644 init.value = error_mark_node;
3645 init.original_code = ERROR_MARK;
3646 init.original_type = NULL;
3647 c_parser_error (parser, "expected %<=%>");
3648 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3649 process_init_element (init, false, braced_init_obstack);
3655 c_parser_initval (parser, NULL, braced_init_obstack);
3658 /* Parse a nested initializer; as c_parser_initializer but parses
3659 initializers within braced lists, after any designators have been
3660 applied. If AFTER is not NULL then it is an Objective-C message
3661 expression which is the primary-expression starting the
3665 c_parser_initval (c_parser *parser, struct c_expr *after,
3666 struct obstack * braced_init_obstack)
3669 gcc_assert (!after || c_dialect_objc ());
3670 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3671 init = c_parser_braced_init (parser, NULL_TREE, true);
3674 location_t loc = c_parser_peek_token (parser)->location;
3675 init = c_parser_expr_no_commas (parser, after);
3676 if (init.value != NULL_TREE
3677 && TREE_CODE (init.value) != STRING_CST
3678 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3679 init = default_function_array_read_conversion (loc, init);
3681 process_init_element (init, false, braced_init_obstack);
3684 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3688 { block-item-list[opt] }
3689 { label-declarations block-item-list }
3693 block-item-list block-item
3705 { label-declarations block-item-list }
3708 __extension__ nested-declaration
3709 nested-function-definition
3713 label-declarations label-declaration
3716 __label__ identifier-list ;
3718 Allowing the mixing of declarations and code is new in C99. The
3719 GNU syntax also permits (not shown above) labels at the end of
3720 compound statements, which yield an error. We don't allow labels
3721 on declarations; this might seem like a natural extension, but
3722 there would be a conflict between attributes on the label and
3723 prefix attributes on the declaration. ??? The syntax follows the
3724 old parser in requiring something after label declarations.
3725 Although they are erroneous if the labels declared aren't defined,
3726 is it useful for the syntax to be this way?
3738 c_parser_compound_statement (c_parser *parser)
3741 location_t brace_loc;
3742 brace_loc = c_parser_peek_token (parser)->location;
3743 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3745 /* Ensure a scope is entered and left anyway to avoid confusion
3746 if we have just prepared to enter a function body. */
3747 stmt = c_begin_compound_stmt (true);
3748 c_end_compound_stmt (brace_loc, stmt, true);
3749 return error_mark_node;
3751 stmt = c_begin_compound_stmt (true);
3752 c_parser_compound_statement_nostart (parser);
3753 return c_end_compound_stmt (brace_loc, stmt, true);
3756 /* Parse a compound statement except for the opening brace. This is
3757 used for parsing both compound statements and statement expressions
3758 (which follow different paths to handling the opening). */
3761 c_parser_compound_statement_nostart (c_parser *parser)
3763 bool last_stmt = false;
3764 bool last_label = false;
3765 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3766 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3767 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3769 c_parser_consume_token (parser);
3772 mark_valid_location_for_stdc_pragma (true);
3773 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3775 /* Read zero or more forward-declarations for labels that nested
3776 functions can jump to. */
3777 mark_valid_location_for_stdc_pragma (false);
3778 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3780 label_loc = c_parser_peek_token (parser)->location;
3781 c_parser_consume_token (parser);
3782 /* Any identifiers, including those declared as type names,
3787 if (c_parser_next_token_is_not (parser, CPP_NAME))
3789 c_parser_error (parser, "expected identifier");
3793 = declare_label (c_parser_peek_token (parser)->value);
3794 C_DECLARED_LABEL_FLAG (label) = 1;
3795 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3796 c_parser_consume_token (parser);
3797 if (c_parser_next_token_is (parser, CPP_COMMA))
3798 c_parser_consume_token (parser);
3802 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3804 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3806 /* We must now have at least one statement, label or declaration. */
3807 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3809 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3810 c_parser_error (parser, "expected declaration or statement");
3811 c_parser_consume_token (parser);
3814 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3816 location_t loc = c_parser_peek_token (parser)->location;
3817 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3818 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3819 || (c_parser_next_token_is (parser, CPP_NAME)
3820 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3822 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3823 label_loc = c_parser_peek_2nd_token (parser)->location;
3825 label_loc = c_parser_peek_token (parser)->location;
3828 mark_valid_location_for_stdc_pragma (false);
3829 c_parser_label (parser);
3831 else if (!last_label
3832 && c_parser_next_token_starts_declaration (parser))
3835 mark_valid_location_for_stdc_pragma (false);
3836 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
3839 (pedantic && !flag_isoc99)
3841 : OPT_Wdeclaration_after_statement,
3842 "ISO C90 forbids mixed declarations and code");
3845 else if (!last_label
3846 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3848 /* __extension__ can start a declaration, but is also an
3849 unary operator that can start an expression. Consume all
3850 but the last of a possible series of __extension__ to
3852 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3853 && (c_parser_peek_2nd_token (parser)->keyword
3855 c_parser_consume_token (parser);
3856 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3859 ext = disable_extension_diagnostics ();
3860 c_parser_consume_token (parser);
3862 mark_valid_location_for_stdc_pragma (false);
3863 c_parser_declaration_or_fndef (parser, true, true, true, true,
3865 /* Following the old parser, __extension__ does not
3866 disable this diagnostic. */
3867 restore_extension_diagnostics (ext);
3869 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3871 : OPT_Wdeclaration_after_statement,
3872 "ISO C90 forbids mixed declarations and code");
3878 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3880 /* External pragmas, and some omp pragmas, are not associated
3881 with regular c code, and so are not to be considered statements
3882 syntactically. This ensures that the user doesn't put them
3883 places that would turn into syntax errors if the directive
3885 if (c_parser_pragma (parser, pragma_compound))
3886 last_label = false, last_stmt = true;
3888 else if (c_parser_next_token_is (parser, CPP_EOF))
3890 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3891 c_parser_error (parser, "expected declaration or statement");
3894 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3896 if (parser->in_if_block)
3898 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3899 error_at (loc, """expected %<}%> before %<else%>");
3904 error_at (loc, "%<else%> without a previous %<if%>");
3905 c_parser_consume_token (parser);
3914 mark_valid_location_for_stdc_pragma (false);
3915 c_parser_statement_after_labels (parser);
3918 parser->error = false;
3921 error_at (label_loc, "label at end of compound statement");
3922 c_parser_consume_token (parser);
3923 /* Restore the value we started with. */
3924 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3927 /* Parse a label (C90 6.6.1, C99 6.8.1).
3930 identifier : attributes[opt]
3931 case constant-expression :
3937 case constant-expression ... constant-expression :
3939 The use of attributes on labels is a GNU extension. The syntax in
3940 GNU C accepts any expressions without commas, non-constant
3941 expressions being rejected later. */
3944 c_parser_label (c_parser *parser)
3946 location_t loc1 = c_parser_peek_token (parser)->location;
3947 tree label = NULL_TREE;
3948 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3951 c_parser_consume_token (parser);
3952 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3953 if (c_parser_next_token_is (parser, CPP_COLON))
3955 c_parser_consume_token (parser);
3956 label = do_case (loc1, exp1, NULL_TREE);
3958 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3960 c_parser_consume_token (parser);
3961 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3962 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3963 label = do_case (loc1, exp1, exp2);
3966 c_parser_error (parser, "expected %<:%> or %<...%>");
3968 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3970 c_parser_consume_token (parser);
3971 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3972 label = do_case (loc1, NULL_TREE, NULL_TREE);
3976 tree name = c_parser_peek_token (parser)->value;
3979 location_t loc2 = c_parser_peek_token (parser)->location;
3980 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3981 c_parser_consume_token (parser);
3982 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3983 c_parser_consume_token (parser);
3984 attrs = c_parser_attributes (parser);
3985 tlab = define_label (loc2, name);
3988 decl_attributes (&tlab, attrs, 0);
3989 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3994 if (c_parser_next_token_starts_declaration (parser)
3995 && !(c_parser_next_token_is (parser, CPP_NAME)
3996 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3998 error_at (c_parser_peek_token (parser)->location,
3999 "a label can only be part of a statement and "
4000 "a declaration is not a statement");
4001 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4002 /*static_assert_ok*/ true,
4003 /*nested*/ true, /*empty_ok*/ false,
4004 /*start_attr_ok*/ true, NULL);
4009 /* Parse a statement (C90 6.6, C99 6.8).
4014 expression-statement
4022 expression-statement:
4025 selection-statement:
4029 iteration-statement:
4038 return expression[opt] ;
4051 objc-throw-statement
4052 objc-try-catch-statement
4053 objc-synchronized-statement
4055 objc-throw-statement:
4069 parallel-for-construct
4070 parallel-sections-construct
4077 parallel-directive structured-block
4080 for-directive iteration-statement
4083 sections-directive section-scope
4086 single-directive structured-block
4088 parallel-for-construct:
4089 parallel-for-directive iteration-statement
4091 parallel-sections-construct:
4092 parallel-sections-directive section-scope
4095 master-directive structured-block
4098 critical-directive structured-block
4101 atomic-directive expression-statement
4104 ordered-directive structured-block */
4107 c_parser_statement (c_parser *parser)
4109 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4110 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4111 || (c_parser_next_token_is (parser, CPP_NAME)
4112 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4113 c_parser_label (parser);
4114 c_parser_statement_after_labels (parser);
4117 /* Parse a statement, other than a labeled statement. */
4120 c_parser_statement_after_labels (c_parser *parser)
4122 location_t loc = c_parser_peek_token (parser)->location;
4123 tree stmt = NULL_TREE;
4124 bool in_if_block = parser->in_if_block;
4125 parser->in_if_block = false;
4126 switch (c_parser_peek_token (parser)->type)
4128 case CPP_OPEN_BRACE:
4129 add_stmt (c_parser_compound_statement (parser));
4132 switch (c_parser_peek_token (parser)->keyword)
4135 c_parser_if_statement (parser);
4138 c_parser_switch_statement (parser);
4141 c_parser_while_statement (parser);
4144 c_parser_do_statement (parser);
4147 c_parser_for_statement (parser);
4150 c_parser_consume_token (parser);
4151 if (c_parser_next_token_is (parser, CPP_NAME))
4153 stmt = c_finish_goto_label (loc,
4154 c_parser_peek_token (parser)->value);
4155 c_parser_consume_token (parser);
4157 else if (c_parser_next_token_is (parser, CPP_MULT))
4161 c_parser_consume_token (parser);
4162 val = c_parser_expression (parser).value;
4163 mark_exp_read (val);
4164 stmt = c_finish_goto_ptr (loc, val);
4167 c_parser_error (parser, "expected identifier or %<*%>");
4168 goto expect_semicolon;
4170 c_parser_consume_token (parser);
4171 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4172 goto expect_semicolon;
4174 c_parser_consume_token (parser);
4175 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4176 goto expect_semicolon;
4178 c_parser_consume_token (parser);
4179 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4181 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4182 c_parser_consume_token (parser);
4186 struct c_expr expr = c_parser_expression_conv (parser);
4187 mark_exp_read (expr.value);
4188 stmt = c_finish_return (loc, expr.value, expr.original_type);
4189 goto expect_semicolon;
4193 stmt = c_parser_asm_statement (parser);
4196 gcc_assert (c_dialect_objc ());
4197 c_parser_consume_token (parser);
4198 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4200 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4201 c_parser_consume_token (parser);
4205 tree expr = c_parser_expression (parser).value;
4206 expr = c_fully_fold (expr, false, NULL);
4207 stmt = objc_build_throw_stmt (loc, expr);
4208 goto expect_semicolon;
4212 gcc_assert (c_dialect_objc ());
4213 c_parser_objc_try_catch_statement (parser);
4215 case RID_AT_SYNCHRONIZED:
4216 gcc_assert (c_dialect_objc ());
4217 c_parser_objc_synchronized_statement (parser);
4224 c_parser_consume_token (parser);
4226 case CPP_CLOSE_PAREN:
4227 case CPP_CLOSE_SQUARE:
4228 /* Avoid infinite loop in error recovery:
4229 c_parser_skip_until_found stops at a closing nesting
4230 delimiter without consuming it, but here we need to consume
4231 it to proceed further. */
4232 c_parser_error (parser, "expected statement");
4233 c_parser_consume_token (parser);
4236 c_parser_pragma (parser, pragma_stmt);
4240 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4242 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4245 /* Two cases cannot and do not have line numbers associated: If stmt
4246 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4247 cannot hold line numbers. But that's OK because the statement
4248 will either be changed to a MODIFY_EXPR during gimplification of
4249 the statement expr, or discarded. If stmt was compound, but
4250 without new variables, we will have skipped the creation of a
4251 BIND and will have a bare STATEMENT_LIST. But that's OK because
4252 (recursively) all of the component statements should already have
4253 line numbers assigned. ??? Can we discard no-op statements
4255 if (CAN_HAVE_LOCATION_P (stmt)
4256 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4257 SET_EXPR_LOCATION (stmt, loc);
4259 parser->in_if_block = in_if_block;
4262 /* Parse the condition from an if, do, while or for statements. */
4265 c_parser_condition (c_parser *parser)
4267 location_t loc = c_parser_peek_token (parser)->location;
4269 cond = c_parser_expression_conv (parser).value;
4270 cond = c_objc_common_truthvalue_conversion (loc, cond);
4271 cond = c_fully_fold (cond, false, NULL);
4272 if (warn_sequence_point)
4273 verify_sequence_points (cond);
4277 /* Parse a parenthesized condition from an if, do or while statement.
4283 c_parser_paren_condition (c_parser *parser)
4286 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4287 return error_mark_node;
4288 cond = c_parser_condition (parser);
4289 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4293 /* Parse a statement which is a block in C99. */
4296 c_parser_c99_block_statement (c_parser *parser)
4298 tree block = c_begin_compound_stmt (flag_isoc99);
4299 location_t loc = c_parser_peek_token (parser)->location;
4300 c_parser_statement (parser);
4301 return c_end_compound_stmt (loc, block, flag_isoc99);
4304 /* Parse the body of an if statement. This is just parsing a
4305 statement but (a) it is a block in C99, (b) we track whether the
4306 body is an if statement for the sake of -Wparentheses warnings, (c)
4307 we handle an empty body specially for the sake of -Wempty-body
4308 warnings, and (d) we call parser_compound_statement directly
4309 because c_parser_statement_after_labels resets
4310 parser->in_if_block. */
4313 c_parser_if_body (c_parser *parser, bool *if_p)
4315 tree block = c_begin_compound_stmt (flag_isoc99);
4316 location_t body_loc = c_parser_peek_token (parser)->location;
4317 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4318 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4319 || (c_parser_next_token_is (parser, CPP_NAME)
4320 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4321 c_parser_label (parser);
4322 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4323 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4325 location_t loc = c_parser_peek_token (parser)->location;
4326 add_stmt (build_empty_stmt (loc));
4327 c_parser_consume_token (parser);
4328 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4329 warning_at (loc, OPT_Wempty_body,
4330 "suggest braces around empty body in an %<if%> statement");
4332 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4333 add_stmt (c_parser_compound_statement (parser));
4335 c_parser_statement_after_labels (parser);
4336 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4339 /* Parse the else body of an if statement. This is just parsing a
4340 statement but (a) it is a block in C99, (b) we handle an empty body
4341 specially for the sake of -Wempty-body warnings. */
4344 c_parser_else_body (c_parser *parser)
4346 location_t else_loc = c_parser_peek_token (parser)->location;
4347 tree block = c_begin_compound_stmt (flag_isoc99);
4348 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4349 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4350 || (c_parser_next_token_is (parser, CPP_NAME)
4351 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4352 c_parser_label (parser);
4353 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4355 location_t loc = c_parser_peek_token (parser)->location;
4358 "suggest braces around empty body in an %<else%> statement");
4359 add_stmt (build_empty_stmt (loc));
4360 c_parser_consume_token (parser);
4363 c_parser_statement_after_labels (parser);
4364 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4367 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4370 if ( expression ) statement
4371 if ( expression ) statement else statement
4375 c_parser_if_statement (c_parser *parser)
4380 bool first_if = false;
4381 tree first_body, second_body;
4384 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4385 c_parser_consume_token (parser);
4386 block = c_begin_compound_stmt (flag_isoc99);
4387 loc = c_parser_peek_token (parser)->location;
4388 cond = c_parser_paren_condition (parser);
4389 in_if_block = parser->in_if_block;
4390 parser->in_if_block = true;
4391 first_body = c_parser_if_body (parser, &first_if);
4392 parser->in_if_block = in_if_block;
4393 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4395 c_parser_consume_token (parser);
4396 second_body = c_parser_else_body (parser);
4399 second_body = NULL_TREE;
4400 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4401 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4404 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4407 switch (expression) statement
4411 c_parser_switch_statement (c_parser *parser)
4413 tree block, expr, body, save_break;
4414 location_t switch_loc = c_parser_peek_token (parser)->location;
4415 location_t switch_cond_loc;
4416 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4417 c_parser_consume_token (parser);
4418 block = c_begin_compound_stmt (flag_isoc99);
4419 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4421 switch_cond_loc = c_parser_peek_token (parser)->location;
4422 expr = c_parser_expression (parser).value;
4423 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4427 switch_cond_loc = UNKNOWN_LOCATION;
4428 expr = error_mark_node;
4430 c_start_case (switch_loc, switch_cond_loc, expr);
4431 save_break = c_break_label;
4432 c_break_label = NULL_TREE;
4433 body = c_parser_c99_block_statement (parser);
4434 c_finish_case (body);
4437 location_t here = c_parser_peek_token (parser)->location;
4438 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4439 SET_EXPR_LOCATION (t, here);
4442 c_break_label = save_break;
4443 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4446 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4449 while (expression) statement
4453 c_parser_while_statement (c_parser *parser)
4455 tree block, cond, body, save_break, save_cont;
4457 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4458 c_parser_consume_token (parser);
4459 block = c_begin_compound_stmt (flag_isoc99);
4460 loc = c_parser_peek_token (parser)->location;
4461 cond = c_parser_paren_condition (parser);
4462 save_break = c_break_label;
4463 c_break_label = NULL_TREE;
4464 save_cont = c_cont_label;
4465 c_cont_label = NULL_TREE;
4466 body = c_parser_c99_block_statement (parser);
4467 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4468 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4469 c_break_label = save_break;
4470 c_cont_label = save_cont;
4473 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4476 do statement while ( expression ) ;
4480 c_parser_do_statement (c_parser *parser)
4482 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4484 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4485 c_parser_consume_token (parser);
4486 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4487 warning_at (c_parser_peek_token (parser)->location,
4489 "suggest braces around empty body in %<do%> statement");
4490 block = c_begin_compound_stmt (flag_isoc99);
4491 loc = c_parser_peek_token (parser)->location;
4492 save_break = c_break_label;
4493 c_break_label = NULL_TREE;
4494 save_cont = c_cont_label;
4495 c_cont_label = NULL_TREE;
4496 body = c_parser_c99_block_statement (parser);
4497 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4498 new_break = c_break_label;
4499 c_break_label = save_break;
4500 new_cont = c_cont_label;
4501 c_cont_label = save_cont;
4502 cond = c_parser_paren_condition (parser);
4503 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4504 c_parser_skip_to_end_of_block_or_statement (parser);
4505 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4506 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4509 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4512 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4513 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4515 The form with a declaration is new in C99.
4517 ??? In accordance with the old parser, the declaration may be a
4518 nested function, which is then rejected in check_for_loop_decls,
4519 but does it make any sense for this to be included in the grammar?
4520 Note in particular that the nested function does not include a
4521 trailing ';', whereas the "declaration" production includes one.
4522 Also, can we reject bad declarations earlier and cheaper than
4523 check_for_loop_decls?
4525 In Objective-C, there are two additional variants:
4528 for ( expression in expresssion ) statement
4529 for ( declaration in expression ) statement
4531 This is inconsistent with C, because the second variant is allowed
4532 even if c99 is not enabled.
4534 The rest of the comment documents these Objective-C foreach-statement.
4536 Here is the canonical example of the first variant:
4537 for (object in array) { do something with object }
4538 we call the first expression ("object") the "object_expression" and
4539 the second expression ("array") the "collection_expression".
4540 object_expression must be an lvalue of type "id" (a generic Objective-C
4541 object) because the loop works by assigning to object_expression the
4542 various objects from the collection_expression. collection_expression
4543 must evaluate to something of type "id" which responds to the method
4544 countByEnumeratingWithState:objects:count:.
4546 The canonical example of the second variant is:
4547 for (id object in array) { do something with object }
4548 which is completely equivalent to
4551 for (object in array) { do something with object }
4553 Note that initizializing 'object' in some way (eg, "for ((object =
4554 xxx) in array) { do something with object }") is possibly
4555 technically valid, but completely pointless as 'object' will be
4556 assigned to something else as soon as the loop starts. We should
4557 most likely reject it (TODO).
4559 The beginning of the Objective-C foreach-statement looks exactly
4560 like the beginning of the for-statement, and we can tell it is a
4561 foreach-statement only because the initial declaration or
4562 expression is terminated by 'in' instead of ';'.
4566 c_parser_for_statement (c_parser *parser)
4568 tree block, cond, incr, save_break, save_cont, body;
4569 /* The following are only used when parsing an ObjC foreach statement. */
4570 tree object_expression, collection_expression;
4571 location_t loc = c_parser_peek_token (parser)->location;
4572 location_t for_loc = c_parser_peek_token (parser)->location;
4573 bool is_foreach_statement = false;
4574 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4575 c_parser_consume_token (parser);
4576 /* Open a compound statement in Objective-C as well, just in case this is
4577 as foreach expression. */
4578 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4579 cond = error_mark_node;
4580 incr = error_mark_node;
4581 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4583 /* Parse the initialization declaration or expression. */
4584 object_expression = error_mark_node;
4585 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4587 c_parser_consume_token (parser);
4588 c_finish_expr_stmt (loc, NULL_TREE);
4590 else if (c_parser_next_token_starts_declaration (parser))
4592 parser->objc_could_be_foreach_context = true;
4593 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4594 &object_expression);
4595 parser->objc_could_be_foreach_context = false;
4597 if (c_parser_next_token_is_keyword (parser, RID_IN))
4599 c_parser_consume_token (parser);
4600 is_foreach_statement = true;
4601 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4602 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4605 check_for_loop_decls (for_loc, flag_isoc99);
4607 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4609 /* __extension__ can start a declaration, but is also an
4610 unary operator that can start an expression. Consume all
4611 but the last of a possible series of __extension__ to
4613 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4614 && (c_parser_peek_2nd_token (parser)->keyword
4616 c_parser_consume_token (parser);
4617 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4620 ext = disable_extension_diagnostics ();
4621 c_parser_consume_token (parser);
4622 parser->objc_could_be_foreach_context = true;
4623 c_parser_declaration_or_fndef (parser, true, true, true, true,
4624 true, &object_expression);
4625 parser->objc_could_be_foreach_context = false;
4627 restore_extension_diagnostics (ext);
4628 if (c_parser_next_token_is_keyword (parser, RID_IN))
4630 c_parser_consume_token (parser);
4631 is_foreach_statement = true;
4632 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4633 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4636 check_for_loop_decls (for_loc, flag_isoc99);
4645 tree init_expression;
4646 parser->objc_could_be_foreach_context = true;
4647 init_expression = c_parser_expression (parser).value;
4648 parser->objc_could_be_foreach_context = false;
4649 if (c_parser_next_token_is_keyword (parser, RID_IN))
4651 c_parser_consume_token (parser);
4652 is_foreach_statement = true;
4653 if (! lvalue_p (init_expression))
4654 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4655 object_expression = c_process_expr_stmt (loc, init_expression);
4660 c_finish_expr_stmt (loc, init_expression);
4661 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4665 /* Parse the loop condition. In the case of a foreach
4666 statement, there is no loop condition. */
4667 if (!is_foreach_statement)
4669 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4671 c_parser_consume_token (parser);
4676 cond = c_parser_condition (parser);
4677 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4680 /* Parse the increment expression (the third expression in a
4681 for-statement). In the case of a foreach-statement, this is
4682 the expression that follows the 'in'. */
4683 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4685 if (is_foreach_statement)
4687 c_parser_error (parser, "missing collection in fast enumeration");
4688 collection_expression = error_mark_node;
4691 incr = c_process_expr_stmt (loc, NULL_TREE);
4695 if (is_foreach_statement)
4696 collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4698 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4700 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4702 save_break = c_break_label;
4703 c_break_label = NULL_TREE;
4704 save_cont = c_cont_label;
4705 c_cont_label = NULL_TREE;
4706 body = c_parser_c99_block_statement (parser);
4707 if (is_foreach_statement)
4708 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4710 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4711 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4712 c_break_label = save_break;
4713 c_cont_label = save_cont;
4716 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4717 statement with inputs, outputs, clobbers, and volatile tag
4721 asm type-qualifier[opt] ( asm-argument ) ;
4722 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4726 asm-string-literal : asm-operands[opt]
4727 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4728 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4731 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4734 Qualifiers other than volatile are accepted in the syntax but
4738 c_parser_asm_statement (c_parser *parser)
4740 tree quals, str, outputs, inputs, clobbers, labels, ret;
4741 bool simple, is_goto;
4742 location_t asm_loc = c_parser_peek_token (parser)->location;
4743 int section, nsections;
4745 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4746 c_parser_consume_token (parser);
4747 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4749 quals = c_parser_peek_token (parser)->value;
4750 c_parser_consume_token (parser);
4752 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4753 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4755 warning_at (c_parser_peek_token (parser)->location,
4757 "%E qualifier ignored on asm",
4758 c_parser_peek_token (parser)->value);
4760 c_parser_consume_token (parser);
4766 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4768 c_parser_consume_token (parser);
4772 /* ??? Follow the C++ parser rather than using the
4773 lex_untranslated_string kludge. */
4774 parser->lex_untranslated_string = true;
4777 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4780 str = c_parser_asm_string_literal (parser);
4781 if (str == NULL_TREE)
4782 goto error_close_paren;
4785 outputs = NULL_TREE;
4787 clobbers = NULL_TREE;
4790 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4793 /* Parse each colon-delimited section of operands. */
4794 nsections = 3 + is_goto;
4795 for (section = 0; section < nsections; ++section)
4797 if (!c_parser_require (parser, CPP_COLON,
4800 : "expected %<:%> or %<)%>"))
4801 goto error_close_paren;
4803 /* Once past any colon, we're no longer a simple asm. */
4806 if ((!c_parser_next_token_is (parser, CPP_COLON)
4807 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4812 /* For asm goto, we don't allow output operands, but reserve
4813 the slot for a future extension that does allow them. */
4815 outputs = c_parser_asm_operands (parser, false);
4818 inputs = c_parser_asm_operands (parser, true);
4821 clobbers = c_parser_asm_clobbers (parser);
4824 labels = c_parser_asm_goto_operands (parser);
4830 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4835 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4841 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4842 c_parser_skip_to_end_of_block_or_statement (parser);
4844 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4845 clobbers, labels, simple));
4848 parser->lex_untranslated_string = false;
4852 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4856 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4857 not outputs), apply the default conversion of functions and arrays
4862 asm-operands , asm-operand
4865 asm-string-literal ( expression )
4866 [ identifier ] asm-string-literal ( expression )
4870 c_parser_asm_operands (c_parser *parser, bool convert_p)
4872 tree list = NULL_TREE;
4878 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4880 c_parser_consume_token (parser);
4881 if (c_parser_next_token_is (parser, CPP_NAME))
4883 tree id = c_parser_peek_token (parser)->value;
4884 c_parser_consume_token (parser);
4885 name = build_string (IDENTIFIER_LENGTH (id),
4886 IDENTIFIER_POINTER (id));
4890 c_parser_error (parser, "expected identifier");
4891 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4894 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4899 str = c_parser_asm_string_literal (parser);
4900 if (str == NULL_TREE)
4902 parser->lex_untranslated_string = false;
4903 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4905 parser->lex_untranslated_string = true;
4908 loc = c_parser_peek_token (parser)->location;
4909 expr = c_parser_expression (parser);
4910 mark_exp_read (expr.value);
4912 expr = default_function_array_conversion (loc, expr);
4913 expr.value = c_fully_fold (expr.value, false, NULL);
4914 parser->lex_untranslated_string = true;
4915 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4917 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4920 list = chainon (list, build_tree_list (build_tree_list (name, str),
4922 if (c_parser_next_token_is (parser, CPP_COMMA))
4923 c_parser_consume_token (parser);
4930 /* Parse asm clobbers, a GNU extension.
4934 asm-clobbers , asm-string-literal
4938 c_parser_asm_clobbers (c_parser *parser)
4940 tree list = NULL_TREE;
4943 tree str = c_parser_asm_string_literal (parser);
4945 list = tree_cons (NULL_TREE, str, list);
4948 if (c_parser_next_token_is (parser, CPP_COMMA))
4949 c_parser_consume_token (parser);
4956 /* Parse asm goto labels, a GNU extension.
4960 asm-goto-operands , identifier
4964 c_parser_asm_goto_operands (c_parser *parser)
4966 tree list = NULL_TREE;
4971 if (c_parser_next_token_is (parser, CPP_NAME))
4973 c_token *tok = c_parser_peek_token (parser);
4975 label = lookup_label_for_goto (tok->location, name);
4976 c_parser_consume_token (parser);
4977 TREE_USED (label) = 1;
4981 c_parser_error (parser, "expected identifier");
4985 name = build_string (IDENTIFIER_LENGTH (name),
4986 IDENTIFIER_POINTER (name));
4987 list = tree_cons (name, label, list);
4988 if (c_parser_next_token_is (parser, CPP_COMMA))
4989 c_parser_consume_token (parser);
4991 return nreverse (list);
4995 /* Parse an expression other than a compound expression; that is, an
4996 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4997 NULL then it is an Objective-C message expression which is the
4998 primary-expression starting the expression as an initializer.
5000 assignment-expression:
5001 conditional-expression
5002 unary-expression assignment-operator assignment-expression
5004 assignment-operator: one of
5005 = *= /= %= += -= <<= >>= &= ^= |=
5007 In GNU C we accept any conditional expression on the LHS and
5008 diagnose the invalid lvalue rather than producing a syntax
5011 static struct c_expr
5012 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5014 struct c_expr lhs, rhs, ret;
5015 enum tree_code code;
5016 location_t op_location, exp_location;
5017 gcc_assert (!after || c_dialect_objc ());
5018 lhs = c_parser_conditional_expression (parser, after);
5019 op_location = c_parser_peek_token (parser)->location;
5020 switch (c_parser_peek_token (parser)->type)
5029 code = TRUNC_DIV_EXPR;
5032 code = TRUNC_MOD_EXPR;
5047 code = BIT_AND_EXPR;
5050 code = BIT_XOR_EXPR;
5053 code = BIT_IOR_EXPR;
5058 c_parser_consume_token (parser);
5059 exp_location = c_parser_peek_token (parser)->location;
5060 rhs = c_parser_expr_no_commas (parser, NULL);
5061 rhs = default_function_array_read_conversion (exp_location, rhs);
5062 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5063 code, exp_location, rhs.value,
5065 if (code == NOP_EXPR)
5066 ret.original_code = MODIFY_EXPR;
5069 TREE_NO_WARNING (ret.value) = 1;
5070 ret.original_code = ERROR_MARK;
5072 ret.original_type = NULL;
5076 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5077 is not NULL then it is an Objective-C message expression which is
5078 the primary-expression starting the expression as an initializer.
5080 conditional-expression:
5081 logical-OR-expression
5082 logical-OR-expression ? expression : conditional-expression
5086 conditional-expression:
5087 logical-OR-expression ? : conditional-expression
5090 static struct c_expr
5091 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5093 struct c_expr cond, exp1, exp2, ret;
5094 location_t cond_loc, colon_loc, middle_loc;
5096 gcc_assert (!after || c_dialect_objc ());
5098 cond = c_parser_binary_expression (parser, after);
5100 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5102 cond_loc = c_parser_peek_token (parser)->location;
5103 cond = default_function_array_read_conversion (cond_loc, cond);
5104 c_parser_consume_token (parser);
5105 if (c_parser_next_token_is (parser, CPP_COLON))
5107 tree eptype = NULL_TREE;
5109 middle_loc = c_parser_peek_token (parser)->location;
5110 pedwarn (middle_loc, OPT_pedantic,
5111 "ISO C forbids omitting the middle term of a ?: expression");
5112 warn_for_omitted_condop (middle_loc, cond.value);
5113 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5115 eptype = TREE_TYPE (cond.value);
5116 cond.value = TREE_OPERAND (cond.value, 0);
5118 /* Make sure first operand is calculated only once. */
5119 exp1.value = c_save_expr (default_conversion (cond.value));
5121 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5122 exp1.original_type = NULL;
5123 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5124 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5129 = c_objc_common_truthvalue_conversion
5130 (cond_loc, default_conversion (cond.value));
5131 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5132 exp1 = c_parser_expression_conv (parser);
5133 mark_exp_read (exp1.value);
5134 c_inhibit_evaluation_warnings +=
5135 ((cond.value == truthvalue_true_node)
5136 - (cond.value == truthvalue_false_node));
5139 colon_loc = c_parser_peek_token (parser)->location;
5140 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5142 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5143 ret.value = error_mark_node;
5144 ret.original_code = ERROR_MARK;
5145 ret.original_type = NULL;
5149 location_t exp2_loc = c_parser_peek_token (parser)->location;
5150 exp2 = c_parser_conditional_expression (parser, NULL);
5151 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5153 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5154 ret.value = build_conditional_expr (colon_loc, cond.value,
5155 cond.original_code == C_MAYBE_CONST_EXPR,
5156 exp1.value, exp1.original_type,
5157 exp2.value, exp2.original_type);
5158 ret.original_code = ERROR_MARK;
5159 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5160 ret.original_type = NULL;
5165 /* If both sides are enum type, the default conversion will have
5166 made the type of the result be an integer type. We want to
5167 remember the enum types we started with. */
5168 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5169 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5170 ret.original_type = ((t1 != error_mark_node
5171 && t2 != error_mark_node
5172 && (TYPE_MAIN_VARIANT (t1)
5173 == TYPE_MAIN_VARIANT (t2)))
5180 /* Parse a binary expression; that is, a logical-OR-expression (C90
5181 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5182 an Objective-C message expression which is the primary-expression
5183 starting the expression as an initializer.
5185 multiplicative-expression:
5187 multiplicative-expression * cast-expression
5188 multiplicative-expression / cast-expression
5189 multiplicative-expression % cast-expression
5191 additive-expression:
5192 multiplicative-expression
5193 additive-expression + multiplicative-expression
5194 additive-expression - multiplicative-expression
5198 shift-expression << additive-expression
5199 shift-expression >> additive-expression
5201 relational-expression:
5203 relational-expression < shift-expression
5204 relational-expression > shift-expression
5205 relational-expression <= shift-expression
5206 relational-expression >= shift-expression
5208 equality-expression:
5209 relational-expression
5210 equality-expression == relational-expression
5211 equality-expression != relational-expression
5215 AND-expression & equality-expression
5217 exclusive-OR-expression:
5219 exclusive-OR-expression ^ AND-expression
5221 inclusive-OR-expression:
5222 exclusive-OR-expression
5223 inclusive-OR-expression | exclusive-OR-expression
5225 logical-AND-expression:
5226 inclusive-OR-expression
5227 logical-AND-expression && inclusive-OR-expression
5229 logical-OR-expression:
5230 logical-AND-expression
5231 logical-OR-expression || logical-AND-expression
5234 static struct c_expr
5235 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5237 /* A binary expression is parsed using operator-precedence parsing,
5238 with the operands being cast expressions. All the binary
5239 operators are left-associative. Thus a binary expression is of
5242 E0 op1 E1 op2 E2 ...
5244 which we represent on a stack. On the stack, the precedence
5245 levels are strictly increasing. When a new operator is
5246 encountered of higher precedence than that at the top of the
5247 stack, it is pushed; its LHS is the top expression, and its RHS
5248 is everything parsed until it is popped. When a new operator is
5249 encountered with precedence less than or equal to that at the top
5250 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5251 by the result of the operation until the operator at the top of
5252 the stack has lower precedence than the new operator or there is
5253 only one element on the stack; then the top expression is the LHS
5254 of the new operator. In the case of logical AND and OR
5255 expressions, we also need to adjust c_inhibit_evaluation_warnings
5256 as appropriate when the operators are pushed and popped. */
5258 /* The precedence levels, where 0 is a dummy lowest level used for
5259 the bottom of the stack. */
5275 /* The expression at this stack level. */
5277 /* The precedence of the operator on its left, PREC_NONE at the
5278 bottom of the stack. */
5280 /* The operation on its left. */
5282 /* The source location of this operation. */
5286 /* Location of the binary operator. */
5287 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5290 switch (stack[sp].op) \
5292 case TRUTH_ANDIF_EXPR: \
5293 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5294 == truthvalue_false_node); \
5296 case TRUTH_ORIF_EXPR: \
5297 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5298 == truthvalue_true_node); \
5303 stack[sp - 1].expr \
5304 = default_function_array_read_conversion (stack[sp - 1].loc, \
5305 stack[sp - 1].expr); \
5307 = default_function_array_read_conversion (stack[sp].loc, \
5309 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5311 stack[sp - 1].expr, \
5315 gcc_assert (!after || c_dialect_objc ());
5316 stack[0].loc = c_parser_peek_token (parser)->location;
5317 stack[0].expr = c_parser_cast_expression (parser, after);
5318 stack[0].prec = PREC_NONE;
5323 enum tree_code ocode;
5326 switch (c_parser_peek_token (parser)->type)
5334 ocode = TRUNC_DIV_EXPR;
5338 ocode = TRUNC_MOD_EXPR;
5350 ocode = LSHIFT_EXPR;
5354 ocode = RSHIFT_EXPR;
5368 case CPP_GREATER_EQ:
5381 oprec = PREC_BITAND;
5382 ocode = BIT_AND_EXPR;
5385 oprec = PREC_BITXOR;
5386 ocode = BIT_XOR_EXPR;
5390 ocode = BIT_IOR_EXPR;
5393 oprec = PREC_LOGAND;
5394 ocode = TRUTH_ANDIF_EXPR;
5398 ocode = TRUTH_ORIF_EXPR;
5401 /* Not a binary operator, so end of the binary
5405 binary_loc = c_parser_peek_token (parser)->location;
5406 c_parser_consume_token (parser);
5407 while (oprec <= stack[sp].prec)
5411 case TRUTH_ANDIF_EXPR:
5413 = default_function_array_read_conversion (stack[sp].loc,
5415 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5416 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5417 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5418 == truthvalue_false_node);
5420 case TRUTH_ORIF_EXPR:
5422 = default_function_array_read_conversion (stack[sp].loc,
5424 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5425 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5426 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5427 == truthvalue_true_node);
5433 stack[sp].loc = binary_loc;
5434 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5435 stack[sp].prec = oprec;
5436 stack[sp].op = ocode;
5437 stack[sp].loc = binary_loc;
5442 return stack[0].expr;
5446 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5447 NULL then it is an Objective-C message expression which is the
5448 primary-expression starting the expression as an initializer.
5452 ( type-name ) unary-expression
5455 static struct c_expr
5456 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5458 location_t cast_loc = c_parser_peek_token (parser)->location;
5459 gcc_assert (!after || c_dialect_objc ());
5461 return c_parser_postfix_expression_after_primary (parser,
5463 /* If the expression begins with a parenthesized type name, it may
5464 be either a cast or a compound literal; we need to see whether
5465 the next character is '{' to tell the difference. If not, it is
5466 an unary expression. */
5467 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5468 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5470 struct c_type_name *type_name;
5473 c_parser_consume_token (parser);
5474 type_name = c_parser_type_name (parser);
5475 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5476 if (type_name == NULL)
5478 ret.value = error_mark_node;
5479 ret.original_code = ERROR_MARK;
5480 ret.original_type = NULL;
5484 /* Save casted types in the function's used types hash table. */
5485 used_types_insert (type_name->specs->type);
5487 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5488 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5491 location_t expr_loc = c_parser_peek_token (parser)->location;
5492 expr = c_parser_cast_expression (parser, NULL);
5493 expr = default_function_array_read_conversion (expr_loc, expr);
5495 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5496 ret.original_code = ERROR_MARK;
5497 ret.original_type = NULL;
5501 return c_parser_unary_expression (parser);
5504 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5510 unary-operator cast-expression
5511 sizeof unary-expression
5512 sizeof ( type-name )
5514 unary-operator: one of
5520 __alignof__ unary-expression
5521 __alignof__ ( type-name )
5524 unary-operator: one of
5525 __extension__ __real__ __imag__
5527 In addition, the GNU syntax treats ++ and -- as unary operators, so
5528 they may be applied to cast expressions with errors for non-lvalues
5531 static struct c_expr
5532 c_parser_unary_expression (c_parser *parser)
5535 struct c_expr ret, op;
5536 location_t op_loc = c_parser_peek_token (parser)->location;
5538 ret.original_code = ERROR_MARK;
5539 ret.original_type = NULL;
5540 switch (c_parser_peek_token (parser)->type)
5543 c_parser_consume_token (parser);
5544 exp_loc = c_parser_peek_token (parser)->location;
5545 op = c_parser_cast_expression (parser, NULL);
5546 op = default_function_array_read_conversion (exp_loc, op);
5547 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5548 case CPP_MINUS_MINUS:
5549 c_parser_consume_token (parser);
5550 exp_loc = c_parser_peek_token (parser)->location;
5551 op = c_parser_cast_expression (parser, NULL);
5552 op = default_function_array_read_conversion (exp_loc, op);
5553 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5555 c_parser_consume_token (parser);
5556 op = c_parser_cast_expression (parser, NULL);
5557 mark_exp_read (op.value);
5558 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5560 c_parser_consume_token (parser);
5561 exp_loc = c_parser_peek_token (parser)->location;
5562 op = c_parser_cast_expression (parser, NULL);
5563 op = default_function_array_read_conversion (exp_loc, op);
5564 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5567 if (!c_dialect_objc () && !in_system_header)
5570 "traditional C rejects the unary plus operator");
5571 c_parser_consume_token (parser);
5572 exp_loc = c_parser_peek_token (parser)->location;
5573 op = c_parser_cast_expression (parser, NULL);
5574 op = default_function_array_read_conversion (exp_loc, op);
5575 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5577 c_parser_consume_token (parser);
5578 exp_loc = c_parser_peek_token (parser)->location;
5579 op = c_parser_cast_expression (parser, NULL);
5580 op = default_function_array_read_conversion (exp_loc, op);
5581 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5583 c_parser_consume_token (parser);
5584 exp_loc = c_parser_peek_token (parser)->location;
5585 op = c_parser_cast_expression (parser, NULL);
5586 op = default_function_array_read_conversion (exp_loc, op);
5587 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5589 c_parser_consume_token (parser);
5590 exp_loc = c_parser_peek_token (parser)->location;
5591 op = c_parser_cast_expression (parser, NULL);
5592 op = default_function_array_read_conversion (exp_loc, op);
5593 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5595 /* Refer to the address of a label as a pointer. */
5596 c_parser_consume_token (parser);
5597 if (c_parser_next_token_is (parser, CPP_NAME))
5599 ret.value = finish_label_address_expr
5600 (c_parser_peek_token (parser)->value, op_loc);
5601 c_parser_consume_token (parser);
5605 c_parser_error (parser, "expected identifier");
5606 ret.value = error_mark_node;
5610 switch (c_parser_peek_token (parser)->keyword)
5613 return c_parser_sizeof_expression (parser);
5615 return c_parser_alignof_expression (parser);
5617 c_parser_consume_token (parser);
5618 ext = disable_extension_diagnostics ();
5619 ret = c_parser_cast_expression (parser, NULL);
5620 restore_extension_diagnostics (ext);
5623 c_parser_consume_token (parser);
5624 exp_loc = c_parser_peek_token (parser)->location;
5625 op = c_parser_cast_expression (parser, NULL);
5626 op = default_function_array_conversion (exp_loc, op);
5627 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5629 c_parser_consume_token (parser);
5630 exp_loc = c_parser_peek_token (parser)->location;
5631 op = c_parser_cast_expression (parser, NULL);
5632 op = default_function_array_conversion (exp_loc, op);
5633 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5635 return c_parser_postfix_expression (parser);
5638 return c_parser_postfix_expression (parser);
5642 /* Parse a sizeof expression. */
5644 static struct c_expr
5645 c_parser_sizeof_expression (c_parser *parser)
5648 location_t expr_loc;
5649 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5650 c_parser_consume_token (parser);
5651 c_inhibit_evaluation_warnings++;
5653 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5654 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5656 /* Either sizeof ( type-name ) or sizeof unary-expression
5657 starting with a compound literal. */
5658 struct c_type_name *type_name;
5659 c_parser_consume_token (parser);
5660 expr_loc = c_parser_peek_token (parser)->location;
5661 type_name = c_parser_type_name (parser);
5662 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5663 if (type_name == NULL)
5666 c_inhibit_evaluation_warnings--;
5668 ret.value = error_mark_node;
5669 ret.original_code = ERROR_MARK;
5670 ret.original_type = NULL;
5673 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5675 expr = c_parser_postfix_expression_after_paren_type (parser,
5680 /* sizeof ( type-name ). */
5681 c_inhibit_evaluation_warnings--;
5683 return c_expr_sizeof_type (expr_loc, type_name);
5687 expr_loc = c_parser_peek_token (parser)->location;
5688 expr = c_parser_unary_expression (parser);
5690 c_inhibit_evaluation_warnings--;
5692 mark_exp_read (expr.value);
5693 if (TREE_CODE (expr.value) == COMPONENT_REF
5694 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5695 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5696 return c_expr_sizeof_expr (expr_loc, expr);
5700 /* Parse an alignof expression. */
5702 static struct c_expr
5703 c_parser_alignof_expression (c_parser *parser)
5706 location_t loc = c_parser_peek_token (parser)->location;
5707 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5708 c_parser_consume_token (parser);
5709 c_inhibit_evaluation_warnings++;
5711 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5712 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5714 /* Either __alignof__ ( type-name ) or __alignof__
5715 unary-expression starting with a compound literal. */
5717 struct c_type_name *type_name;
5719 c_parser_consume_token (parser);
5720 loc = c_parser_peek_token (parser)->location;
5721 type_name = c_parser_type_name (parser);
5722 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5723 if (type_name == NULL)
5726 c_inhibit_evaluation_warnings--;
5728 ret.value = error_mark_node;
5729 ret.original_code = ERROR_MARK;
5730 ret.original_type = NULL;
5733 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5735 expr = c_parser_postfix_expression_after_paren_type (parser,
5740 /* alignof ( type-name ). */
5741 c_inhibit_evaluation_warnings--;
5743 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5744 ret.original_code = ERROR_MARK;
5745 ret.original_type = NULL;
5751 expr = c_parser_unary_expression (parser);
5753 mark_exp_read (expr.value);
5754 c_inhibit_evaluation_warnings--;
5756 ret.value = c_alignof_expr (loc, expr.value);
5757 ret.original_code = ERROR_MARK;
5758 ret.original_type = NULL;
5763 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5767 postfix-expression [ expression ]
5768 postfix-expression ( argument-expression-list[opt] )
5769 postfix-expression . identifier
5770 postfix-expression -> identifier
5771 postfix-expression ++
5772 postfix-expression --
5773 ( type-name ) { initializer-list }
5774 ( type-name ) { initializer-list , }
5776 argument-expression-list:
5778 argument-expression-list , argument-expression
5790 (treated as a keyword in GNU C)
5793 ( compound-statement )
5794 __builtin_va_arg ( assignment-expression , type-name )
5795 __builtin_offsetof ( type-name , offsetof-member-designator )
5796 __builtin_choose_expr ( assignment-expression ,
5797 assignment-expression ,
5798 assignment-expression )
5799 __builtin_types_compatible_p ( type-name , type-name )
5801 offsetof-member-designator:
5803 offsetof-member-designator . identifier
5804 offsetof-member-designator [ expression ]
5809 [ objc-receiver objc-message-args ]
5810 @selector ( objc-selector-arg )
5811 @protocol ( identifier )
5812 @encode ( type-name )
5816 static struct c_expr
5817 c_parser_postfix_expression (c_parser *parser)
5819 struct c_expr expr, e1, e2, e3;
5820 struct c_type_name *t1, *t2;
5821 location_t loc = c_parser_peek_token (parser)->location;;
5822 expr.original_code = ERROR_MARK;
5823 expr.original_type = NULL;
5824 switch (c_parser_peek_token (parser)->type)
5827 expr.value = c_parser_peek_token (parser)->value;
5828 loc = c_parser_peek_token (parser)->location;
5829 c_parser_consume_token (parser);
5830 if (TREE_CODE (expr.value) == FIXED_CST
5831 && !targetm.fixed_point_supported_p ())
5833 error_at (loc, "fixed-point types not supported for this target");
5834 expr.value = error_mark_node;
5841 expr.value = c_parser_peek_token (parser)->value;
5842 c_parser_consume_token (parser);
5848 case CPP_UTF8STRING:
5849 expr.value = c_parser_peek_token (parser)->value;
5850 expr.original_code = STRING_CST;
5851 c_parser_consume_token (parser);
5853 case CPP_OBJC_STRING:
5854 gcc_assert (c_dialect_objc ());
5856 = objc_build_string_object (c_parser_peek_token (parser)->value);
5857 c_parser_consume_token (parser);
5860 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5862 c_parser_error (parser, "expected expression");
5863 expr.value = error_mark_node;
5867 tree id = c_parser_peek_token (parser)->value;
5868 c_parser_consume_token (parser);
5869 expr.value = build_external_ref (loc, id,
5870 (c_parser_peek_token (parser)->type
5872 &expr.original_type);
5875 case CPP_OPEN_PAREN:
5876 /* A parenthesized expression, statement expression or compound
5878 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5880 /* A statement expression. */
5882 location_t brace_loc;
5883 c_parser_consume_token (parser);
5884 brace_loc = c_parser_peek_token (parser)->location;
5885 c_parser_consume_token (parser);
5886 if (cur_stmt_list == NULL)
5888 error_at (loc, "braced-group within expression allowed "
5889 "only inside a function");
5890 parser->error = true;
5891 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5892 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5893 expr.value = error_mark_node;
5896 stmt = c_begin_stmt_expr ();
5897 c_parser_compound_statement_nostart (parser);
5898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5900 pedwarn (loc, OPT_pedantic,
5901 "ISO C forbids braced-groups within expressions");
5902 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5903 mark_exp_read (expr.value);
5905 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5907 /* A compound literal. ??? Can we actually get here rather
5908 than going directly to
5909 c_parser_postfix_expression_after_paren_type from
5912 struct c_type_name *type_name;
5913 c_parser_consume_token (parser);
5914 loc = c_parser_peek_token (parser)->location;
5915 type_name = c_parser_type_name (parser);
5916 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5918 if (type_name == NULL)
5920 expr.value = error_mark_node;
5923 expr = c_parser_postfix_expression_after_paren_type (parser,
5929 /* A parenthesized expression. */
5930 c_parser_consume_token (parser);
5931 expr = c_parser_expression (parser);
5932 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5933 TREE_NO_WARNING (expr.value) = 1;
5934 if (expr.original_code != C_MAYBE_CONST_EXPR)
5935 expr.original_code = ERROR_MARK;
5936 /* Don't change EXPR.ORIGINAL_TYPE. */
5937 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5942 switch (c_parser_peek_token (parser)->keyword)
5944 case RID_FUNCTION_NAME:
5945 case RID_PRETTY_FUNCTION_NAME:
5946 case RID_C99_FUNCTION_NAME:
5947 expr.value = fname_decl (loc,
5948 c_parser_peek_token (parser)->keyword,
5949 c_parser_peek_token (parser)->value);
5950 c_parser_consume_token (parser);
5953 c_parser_consume_token (parser);
5954 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5956 expr.value = error_mark_node;
5959 e1 = c_parser_expr_no_commas (parser, NULL);
5960 mark_exp_read (e1.value);
5961 e1.value = c_fully_fold (e1.value, false, NULL);
5962 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5964 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5965 expr.value = error_mark_node;
5968 loc = c_parser_peek_token (parser)->location;
5969 t1 = c_parser_type_name (parser);
5970 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5974 expr.value = error_mark_node;
5978 tree type_expr = NULL_TREE;
5979 expr.value = c_build_va_arg (loc, e1.value,
5980 groktypename (t1, &type_expr, NULL));
5983 expr.value = build2 (C_MAYBE_CONST_EXPR,
5984 TREE_TYPE (expr.value), type_expr,
5986 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5991 c_parser_consume_token (parser);
5992 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5994 expr.value = error_mark_node;
5997 t1 = c_parser_type_name (parser);
6000 expr.value = error_mark_node;
6003 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6005 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6006 expr.value = error_mark_node;
6010 tree type = groktypename (t1, NULL, NULL);
6012 if (type == error_mark_node)
6013 offsetof_ref = error_mark_node;
6016 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6017 SET_EXPR_LOCATION (offsetof_ref, loc);
6019 /* Parse the second argument to __builtin_offsetof. We
6020 must have one identifier, and beyond that we want to
6021 accept sub structure and sub array references. */
6022 if (c_parser_next_token_is (parser, CPP_NAME))
6024 offsetof_ref = build_component_ref
6025 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6026 c_parser_consume_token (parser);
6027 while (c_parser_next_token_is (parser, CPP_DOT)
6028 || c_parser_next_token_is (parser,
6030 || c_parser_next_token_is (parser,
6033 if (c_parser_next_token_is (parser, CPP_DEREF))
6035 loc = c_parser_peek_token (parser)->location;
6036 offsetof_ref = build_array_ref (loc,
6041 else if (c_parser_next_token_is (parser, CPP_DOT))
6044 c_parser_consume_token (parser);
6045 if (c_parser_next_token_is_not (parser,
6048 c_parser_error (parser, "expected identifier");
6051 offsetof_ref = build_component_ref
6053 c_parser_peek_token (parser)->value);
6054 c_parser_consume_token (parser);
6059 loc = c_parser_peek_token (parser)->location;
6060 c_parser_consume_token (parser);
6061 idx = c_parser_expression (parser).value;
6062 idx = c_fully_fold (idx, false, NULL);
6063 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6065 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6070 c_parser_error (parser, "expected identifier");
6071 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6073 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6076 case RID_CHOOSE_EXPR:
6077 c_parser_consume_token (parser);
6078 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6080 expr.value = error_mark_node;
6083 loc = c_parser_peek_token (parser)->location;
6084 e1 = c_parser_expr_no_commas (parser, NULL);
6085 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6087 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6088 expr.value = error_mark_node;
6091 e2 = c_parser_expr_no_commas (parser, NULL);
6092 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6094 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6095 expr.value = error_mark_node;
6098 e3 = c_parser_expr_no_commas (parser, NULL);
6099 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6105 mark_exp_read (e2.value);
6106 mark_exp_read (e3.value);
6107 if (TREE_CODE (c) != INTEGER_CST
6108 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6110 "first argument to %<__builtin_choose_expr%> not"
6112 constant_expression_warning (c);
6113 expr = integer_zerop (c) ? e3 : e2;
6116 case RID_TYPES_COMPATIBLE_P:
6117 c_parser_consume_token (parser);
6118 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6120 expr.value = error_mark_node;
6123 t1 = c_parser_type_name (parser);
6126 expr.value = error_mark_node;
6129 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6132 expr.value = error_mark_node;
6135 t2 = c_parser_type_name (parser);
6138 expr.value = error_mark_node;
6141 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6146 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6147 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6150 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6153 case RID_AT_SELECTOR:
6154 gcc_assert (c_dialect_objc ());
6155 c_parser_consume_token (parser);
6156 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6158 expr.value = error_mark_node;
6162 tree sel = c_parser_objc_selector_arg (parser);
6163 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6165 expr.value = objc_build_selector_expr (loc, sel);
6168 case RID_AT_PROTOCOL:
6169 gcc_assert (c_dialect_objc ());
6170 c_parser_consume_token (parser);
6171 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6173 expr.value = error_mark_node;
6176 if (c_parser_next_token_is_not (parser, CPP_NAME))
6178 c_parser_error (parser, "expected identifier");
6179 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6180 expr.value = error_mark_node;
6184 tree id = c_parser_peek_token (parser)->value;
6185 c_parser_consume_token (parser);
6186 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6188 expr.value = objc_build_protocol_expr (id);
6192 /* Extension to support C-structures in the archiver. */
6193 gcc_assert (c_dialect_objc ());
6194 c_parser_consume_token (parser);
6195 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6197 expr.value = error_mark_node;
6200 t1 = c_parser_type_name (parser);
6203 expr.value = error_mark_node;
6204 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6210 tree type = groktypename (t1, NULL, NULL);
6211 expr.value = objc_build_encode_expr (type);
6215 c_parser_error (parser, "expected expression");
6216 expr.value = error_mark_node;
6220 case CPP_OPEN_SQUARE:
6221 if (c_dialect_objc ())
6223 tree receiver, args;
6224 c_parser_consume_token (parser);
6225 receiver = c_parser_objc_receiver (parser);
6226 args = c_parser_objc_message_args (parser);
6227 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6229 expr.value = objc_build_message_expr (build_tree_list (receiver,
6233 /* Else fall through to report error. */
6235 c_parser_error (parser, "expected expression");
6236 expr.value = error_mark_node;
6239 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6242 /* Parse a postfix expression after a parenthesized type name: the
6243 brace-enclosed initializer of a compound literal, possibly followed
6244 by some postfix operators. This is separate because it is not
6245 possible to tell until after the type name whether a cast
6246 expression has a cast or a compound literal, or whether the operand
6247 of sizeof is a parenthesized type name or starts with a compound
6248 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6249 location of the first token after the parentheses around the type
6252 static struct c_expr
6253 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6254 struct c_type_name *type_name,
6255 location_t type_loc)
6261 location_t start_loc;
6262 tree type_expr = NULL_TREE;
6263 bool type_expr_const = true;
6264 check_compound_literal_type (type_loc, type_name);
6265 start_init (NULL_TREE, NULL, 0);
6266 type = groktypename (type_name, &type_expr, &type_expr_const);
6267 start_loc = c_parser_peek_token (parser)->location;
6268 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6270 error_at (type_loc, "compound literal has variable size");
6271 type = error_mark_node;
6273 init = c_parser_braced_init (parser, type, false);
6275 maybe_warn_string_init (type, init);
6277 if (type != error_mark_node
6278 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6279 && current_function_decl)
6281 error ("compound literal qualified by address-space qualifier");
6282 type = error_mark_node;
6286 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6287 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6288 ? CONSTRUCTOR_NON_CONST (init.value)
6289 : init.original_code == C_MAYBE_CONST_EXPR);
6290 non_const |= !type_expr_const;
6291 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6292 expr.original_code = ERROR_MARK;
6293 expr.original_type = NULL;
6296 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6298 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6299 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6303 gcc_assert (!non_const);
6304 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6305 type_expr, expr.value);
6308 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6311 /* Parse a postfix expression after the initial primary or compound
6312 literal; that is, parse a series of postfix operators.
6314 EXPR_LOC is the location of the primary expression. */
6316 static struct c_expr
6317 c_parser_postfix_expression_after_primary (c_parser *parser,
6318 location_t expr_loc,
6321 struct c_expr orig_expr;
6323 VEC(tree,gc) *exprlist;
6324 VEC(tree,gc) *origtypes;
6327 location_t op_loc = c_parser_peek_token (parser)->location;
6328 switch (c_parser_peek_token (parser)->type)
6330 case CPP_OPEN_SQUARE:
6331 /* Array reference. */
6332 c_parser_consume_token (parser);
6333 idx = c_parser_expression (parser).value;
6334 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6336 expr.value = build_array_ref (op_loc, expr.value, idx);
6337 expr.original_code = ERROR_MARK;
6338 expr.original_type = NULL;
6340 case CPP_OPEN_PAREN:
6341 /* Function call. */
6342 c_parser_consume_token (parser);
6343 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6346 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6347 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6350 mark_exp_read (expr.value);
6351 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6352 "(" after the FUNCNAME, which is what we have now. */
6353 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6355 expr.original_code = ERROR_MARK;
6356 if (TREE_CODE (expr.value) == INTEGER_CST
6357 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6358 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6359 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6360 expr.original_code = C_MAYBE_CONST_EXPR;
6361 expr.original_type = NULL;
6362 if (exprlist != NULL)
6364 release_tree_vector (exprlist);
6365 release_tree_vector (origtypes);
6369 /* Structure element reference. */
6370 c_parser_consume_token (parser);
6371 expr = default_function_array_conversion (expr_loc, expr);
6372 if (c_parser_next_token_is (parser, CPP_NAME))
6373 ident = c_parser_peek_token (parser)->value;
6376 c_parser_error (parser, "expected identifier");
6377 expr.value = error_mark_node;
6378 expr.original_code = ERROR_MARK;
6379 expr.original_type = NULL;
6382 c_parser_consume_token (parser);
6383 expr.value = build_component_ref (op_loc, expr.value, ident);
6384 expr.original_code = ERROR_MARK;
6385 if (TREE_CODE (expr.value) != COMPONENT_REF)
6386 expr.original_type = NULL;
6389 /* Remember the original type of a bitfield. */
6390 tree field = TREE_OPERAND (expr.value, 1);
6391 if (TREE_CODE (field) != FIELD_DECL)
6392 expr.original_type = NULL;
6394 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6398 /* Structure element reference. */
6399 c_parser_consume_token (parser);
6400 expr = default_function_array_conversion (expr_loc, expr);
6401 if (c_parser_next_token_is (parser, CPP_NAME))
6402 ident = c_parser_peek_token (parser)->value;
6405 c_parser_error (parser, "expected identifier");
6406 expr.value = error_mark_node;
6407 expr.original_code = ERROR_MARK;
6408 expr.original_type = NULL;
6411 c_parser_consume_token (parser);
6412 expr.value = build_component_ref (op_loc,
6413 build_indirect_ref (op_loc,
6417 expr.original_code = ERROR_MARK;
6418 if (TREE_CODE (expr.value) != COMPONENT_REF)
6419 expr.original_type = NULL;
6422 /* Remember the original type of a bitfield. */
6423 tree field = TREE_OPERAND (expr.value, 1);
6424 if (TREE_CODE (field) != FIELD_DECL)
6425 expr.original_type = NULL;
6427 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6431 /* Postincrement. */
6432 c_parser_consume_token (parser);
6433 expr = default_function_array_read_conversion (expr_loc, expr);
6434 expr.value = build_unary_op (op_loc,
6435 POSTINCREMENT_EXPR, expr.value, 0);
6436 expr.original_code = ERROR_MARK;
6437 expr.original_type = NULL;
6439 case CPP_MINUS_MINUS:
6440 /* Postdecrement. */
6441 c_parser_consume_token (parser);
6442 expr = default_function_array_read_conversion (expr_loc, expr);
6443 expr.value = build_unary_op (op_loc,
6444 POSTDECREMENT_EXPR, expr.value, 0);
6445 expr.original_code = ERROR_MARK;
6446 expr.original_type = NULL;
6454 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6457 assignment-expression
6458 expression , assignment-expression
6461 static struct c_expr
6462 c_parser_expression (c_parser *parser)
6465 expr = c_parser_expr_no_commas (parser, NULL);
6466 while (c_parser_next_token_is (parser, CPP_COMMA))
6470 location_t loc = c_parser_peek_token (parser)->location;
6471 location_t expr_loc;
6472 c_parser_consume_token (parser);
6473 expr_loc = c_parser_peek_token (parser)->location;
6474 lhsval = expr.value;
6475 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6476 lhsval = TREE_OPERAND (lhsval, 1);
6477 if (DECL_P (lhsval) || handled_component_p (lhsval))
6478 mark_exp_read (lhsval);
6479 next = c_parser_expr_no_commas (parser, NULL);
6480 next = default_function_array_conversion (expr_loc, next);
6481 expr.value = build_compound_expr (loc, expr.value, next.value);
6482 expr.original_code = COMPOUND_EXPR;
6483 expr.original_type = next.original_type;
6488 /* Parse an expression and convert functions or arrays to
6491 static struct c_expr
6492 c_parser_expression_conv (c_parser *parser)
6495 location_t loc = c_parser_peek_token (parser)->location;
6496 expr = c_parser_expression (parser);
6497 expr = default_function_array_conversion (loc, expr);
6501 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6502 functions and arrays to pointers. If FOLD_P, fold the expressions.
6505 assignment-expression
6506 nonempty-expr-list , assignment-expression
6509 static VEC(tree,gc) *
6510 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6511 VEC(tree,gc) **p_orig_types)
6514 VEC(tree,gc) *orig_types;
6516 location_t loc = c_parser_peek_token (parser)->location;
6518 ret = make_tree_vector ();
6519 if (p_orig_types == NULL)
6522 orig_types = make_tree_vector ();
6524 expr = c_parser_expr_no_commas (parser, NULL);
6526 expr = default_function_array_read_conversion (loc, expr);
6528 expr.value = c_fully_fold (expr.value, false, NULL);
6529 VEC_quick_push (tree, ret, expr.value);
6530 if (orig_types != NULL)
6531 VEC_quick_push (tree, orig_types, expr.original_type);
6532 while (c_parser_next_token_is (parser, CPP_COMMA))
6534 c_parser_consume_token (parser);
6535 loc = c_parser_peek_token (parser)->location;
6536 expr = c_parser_expr_no_commas (parser, NULL);
6538 expr = default_function_array_read_conversion (loc, expr);
6540 expr.value = c_fully_fold (expr.value, false, NULL);
6541 VEC_safe_push (tree, gc, ret, expr.value);
6542 if (orig_types != NULL)
6543 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6545 if (orig_types != NULL)
6546 *p_orig_types = orig_types;
6550 /* Parse Objective-C-specific constructs. */
6552 /* Parse an objc-class-definition.
6554 objc-class-definition:
6555 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6556 objc-class-instance-variables[opt] objc-methodprotolist @end
6557 @implementation identifier objc-superclass[opt]
6558 objc-class-instance-variables[opt]
6559 @interface identifier ( identifier ) objc-protocol-refs[opt]
6560 objc-methodprotolist @end
6561 @implementation identifier ( identifier )
6566 "@interface identifier (" must start "@interface identifier (
6567 identifier ) ...": objc-methodprotolist in the first production may
6568 not start with a parenthesized identifier as a declarator of a data
6569 definition with no declaration specifiers if the objc-superclass,
6570 objc-protocol-refs and objc-class-instance-variables are omitted. */
6573 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6578 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6580 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6585 c_parser_consume_token (parser);
6586 if (c_parser_next_token_is_not (parser, CPP_NAME))
6588 c_parser_error (parser, "expected identifier");
6591 id1 = c_parser_peek_token (parser)->value;
6592 c_parser_consume_token (parser);
6593 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6596 tree proto = NULL_TREE;
6597 c_parser_consume_token (parser);
6598 if (c_parser_next_token_is_not (parser, CPP_NAME))
6600 c_parser_error (parser, "expected identifier");
6601 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6604 id2 = c_parser_peek_token (parser)->value;
6605 c_parser_consume_token (parser);
6606 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6609 objc_start_category_implementation (id1, id2);
6612 if (c_parser_next_token_is (parser, CPP_LESS))
6613 proto = c_parser_objc_protocol_refs (parser);
6614 objc_start_category_interface (id1, id2, proto, attributes);
6615 c_parser_objc_methodprotolist (parser);
6616 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6617 objc_finish_interface ();
6620 if (c_parser_next_token_is (parser, CPP_COLON))
6622 c_parser_consume_token (parser);
6623 if (c_parser_next_token_is_not (parser, CPP_NAME))
6625 c_parser_error (parser, "expected identifier");
6628 superclass = c_parser_peek_token (parser)->value;
6629 c_parser_consume_token (parser);
6632 superclass = NULL_TREE;
6635 tree proto = NULL_TREE;
6636 if (c_parser_next_token_is (parser, CPP_LESS))
6637 proto = c_parser_objc_protocol_refs (parser);
6638 objc_start_class_interface (id1, superclass, proto, attributes);
6641 objc_start_class_implementation (id1, superclass);
6642 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6643 c_parser_objc_class_instance_variables (parser);
6646 objc_continue_interface ();
6647 c_parser_objc_methodprotolist (parser);
6648 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6649 objc_finish_interface ();
6653 objc_continue_implementation ();
6658 /* Parse objc-class-instance-variables.
6660 objc-class-instance-variables:
6661 { objc-instance-variable-decl-list[opt] }
6663 objc-instance-variable-decl-list:
6664 objc-visibility-spec
6665 objc-instance-variable-decl ;
6667 objc-instance-variable-decl-list objc-visibility-spec
6668 objc-instance-variable-decl-list objc-instance-variable-decl ;
6669 objc-instance-variable-decl-list ;
6671 objc-visibility-spec:
6676 objc-instance-variable-decl:
6681 c_parser_objc_class_instance_variables (c_parser *parser)
6683 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6684 c_parser_consume_token (parser);
6685 while (c_parser_next_token_is_not (parser, CPP_EOF))
6688 /* Parse any stray semicolon. */
6689 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6691 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6692 "extra semicolon in struct or union specified");
6693 c_parser_consume_token (parser);
6696 /* Stop if at the end of the instance variables. */
6697 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6699 c_parser_consume_token (parser);
6702 /* Parse any objc-visibility-spec. */
6703 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6705 c_parser_consume_token (parser);
6706 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6709 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6711 c_parser_consume_token (parser);
6712 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6715 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6717 c_parser_consume_token (parser);
6718 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6721 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6723 c_parser_consume_token (parser);
6724 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6727 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6729 c_parser_pragma (parser, pragma_external);
6733 /* Parse some comma-separated declarations. */
6734 decls = c_parser_struct_declaration (parser);
6736 /* Comma-separated instance variables are chained together in
6737 reverse order; add them one by one. */
6738 tree ivar = nreverse (decls);
6739 for (; ivar; ivar = DECL_CHAIN (ivar))
6740 objc_add_instance_variable (copy_node (ivar));
6742 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6746 /* Parse an objc-class-declaration.
6748 objc-class-declaration:
6749 @class identifier-list ;
6753 c_parser_objc_class_declaration (c_parser *parser)
6755 tree list = NULL_TREE;
6756 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6757 c_parser_consume_token (parser);
6758 /* Any identifiers, including those declared as type names, are OK
6763 if (c_parser_next_token_is_not (parser, CPP_NAME))
6765 c_parser_error (parser, "expected identifier");
6768 id = c_parser_peek_token (parser)->value;
6769 list = chainon (list, build_tree_list (NULL_TREE, id));
6770 c_parser_consume_token (parser);
6771 if (c_parser_next_token_is (parser, CPP_COMMA))
6772 c_parser_consume_token (parser);
6776 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6777 objc_declare_class (list);
6780 /* Parse an objc-alias-declaration.
6782 objc-alias-declaration:
6783 @compatibility_alias identifier identifier ;
6787 c_parser_objc_alias_declaration (c_parser *parser)
6790 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6791 c_parser_consume_token (parser);
6792 if (c_parser_next_token_is_not (parser, CPP_NAME))
6794 c_parser_error (parser, "expected identifier");
6795 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6798 id1 = c_parser_peek_token (parser)->value;
6799 c_parser_consume_token (parser);
6800 if (c_parser_next_token_is_not (parser, CPP_NAME))
6802 c_parser_error (parser, "expected identifier");
6803 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6806 id2 = c_parser_peek_token (parser)->value;
6807 c_parser_consume_token (parser);
6808 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6809 objc_declare_alias (id1, id2);
6812 /* Parse an objc-protocol-definition.
6814 objc-protocol-definition:
6815 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6816 @protocol identifier-list ;
6818 "@protocol identifier ;" should be resolved as "@protocol
6819 identifier-list ;": objc-methodprotolist may not start with a
6820 semicolon in the first alternative if objc-protocol-refs are
6824 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6826 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6828 c_parser_consume_token (parser);
6829 if (c_parser_next_token_is_not (parser, CPP_NAME))
6831 c_parser_error (parser, "expected identifier");
6834 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6835 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6837 tree list = NULL_TREE;
6838 /* Any identifiers, including those declared as type names, are
6843 if (c_parser_next_token_is_not (parser, CPP_NAME))
6845 c_parser_error (parser, "expected identifier");
6848 id = c_parser_peek_token (parser)->value;
6849 list = chainon (list, build_tree_list (NULL_TREE, id));
6850 c_parser_consume_token (parser);
6851 if (c_parser_next_token_is (parser, CPP_COMMA))
6852 c_parser_consume_token (parser);
6856 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6857 objc_declare_protocols (list);
6861 tree id = c_parser_peek_token (parser)->value;
6862 tree proto = NULL_TREE;
6863 c_parser_consume_token (parser);
6864 if (c_parser_next_token_is (parser, CPP_LESS))
6865 proto = c_parser_objc_protocol_refs (parser);
6866 parser->objc_pq_context = true;
6867 objc_start_protocol (id, proto, attributes);
6868 c_parser_objc_methodprotolist (parser);
6869 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6870 parser->objc_pq_context = false;
6871 objc_finish_interface ();
6875 /* Parse an objc-method-type.
6882 static enum tree_code
6883 c_parser_objc_method_type (c_parser *parser)
6885 switch (c_parser_peek_token (parser)->type)
6888 c_parser_consume_token (parser);
6891 c_parser_consume_token (parser);
6898 /* Parse an objc-method-definition.
6900 objc-method-definition:
6901 objc-method-type objc-method-decl ;[opt] compound-statement
6905 c_parser_objc_method_definition (c_parser *parser)
6907 enum tree_code type = c_parser_objc_method_type (parser);
6908 tree decl, attributes = NULL_TREE;
6909 objc_set_method_type (type);
6910 parser->objc_pq_context = true;
6911 decl = c_parser_objc_method_decl (parser, &attributes);
6912 if (decl == error_mark_node)
6913 return; /* Bail here. */
6915 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6917 c_parser_consume_token (parser);
6918 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6919 "extra semicolon in method definition specified");
6922 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6924 c_parser_error (parser, "expected %<{%>");
6928 parser->objc_pq_context = false;
6929 if (objc_start_method_definition (decl, attributes))
6931 add_stmt (c_parser_compound_statement (parser));
6932 objc_finish_method_definition (current_function_decl);
6936 /* This code is executed when we find a method definition
6937 outside of an @implementation context (or invalid for other
6938 reasons). Parse the method (to keep going) but do not emit
6941 c_parser_compound_statement (parser);
6945 /* Parse an objc-methodprotolist.
6947 objc-methodprotolist:
6949 objc-methodprotolist objc-methodproto
6950 objc-methodprotolist declaration
6951 objc-methodprotolist ;
6955 The declaration is a data definition, which may be missing
6956 declaration specifiers under the same rules and diagnostics as
6957 other data definitions outside functions, and the stray semicolon
6958 is diagnosed the same way as a stray semicolon outside a
6962 c_parser_objc_methodprotolist (c_parser *parser)
6966 /* The list is terminated by @end. */
6967 switch (c_parser_peek_token (parser)->type)
6970 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6971 "ISO C does not allow extra %<;%> outside of a function");
6972 c_parser_consume_token (parser);
6976 c_parser_objc_methodproto (parser);
6979 c_parser_pragma (parser, pragma_external);
6984 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6986 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
6987 c_parser_objc_at_property (parser);
6988 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
6990 objc_set_method_opt (true);
6991 c_parser_consume_token (parser);
6993 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
6995 objc_set_method_opt (false);
6996 c_parser_consume_token (parser);
6999 c_parser_declaration_or_fndef (parser, false, false, true,
7006 /* Parse an objc-methodproto.
7009 objc-method-type objc-method-decl ;
7013 c_parser_objc_methodproto (c_parser *parser)
7015 enum tree_code type = c_parser_objc_method_type (parser);
7016 tree decl, attributes = NULL_TREE;
7017 objc_set_method_type (type);
7018 /* Remember protocol qualifiers in prototypes. */
7019 parser->objc_pq_context = true;
7020 decl = c_parser_objc_method_decl (parser, &attributes);
7021 /* Forget protocol qualifiers now. */
7022 parser->objc_pq_context = false;
7024 /* Do not allow the presence of attributes to hide an erroneous
7025 method implementation in the interface section. */
7026 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7028 c_parser_error (parser, "expected %<;%>");
7032 if (decl != error_mark_node)
7033 objc_add_method_declaration (decl, attributes);
7035 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7038 /* If we are at a position that method attributes may be present, check that
7039 there are not any parsed already (a syntax error) and then collect any
7040 specified at the current location. Finally, if new attributes were present,
7041 check that the next token is legal ( ';' for decls and '{' for defs). */
7044 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7049 c_parser_error (parser,
7050 "method attributes must be specified at the end only");
7051 *attributes = NULL_TREE;
7055 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7056 *attributes = c_parser_attributes (parser);
7058 /* If there were no attributes here, just report any earlier error. */
7059 if (*attributes == NULL_TREE || bad)
7062 /* If the attributes are followed by a ; or {, then just report any earlier
7064 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7065 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7068 /* We've got attributes, but not at the end. */
7069 c_parser_error (parser,
7070 "expected %<;%> or %<{%> after method attribute definition");
7074 /* Parse an objc-method-decl.
7077 ( objc-type-name ) objc-selector
7079 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7080 objc-keyword-selector objc-optparmlist
7083 objc-keyword-selector:
7085 objc-keyword-selector objc-keyword-decl
7088 objc-selector : ( objc-type-name ) identifier
7089 objc-selector : identifier
7090 : ( objc-type-name ) identifier
7094 objc-optparms objc-optellipsis
7098 objc-opt-parms , parameter-declaration
7106 c_parser_objc_method_decl (c_parser *parser, tree *attributes)
7108 tree type = NULL_TREE;
7110 tree parms = NULL_TREE;
7111 bool ellipsis = false;
7112 bool attr_err = false;
7114 *attributes = NULL_TREE;
7115 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7117 c_parser_consume_token (parser);
7118 type = c_parser_objc_type_name (parser);
7119 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7121 sel = c_parser_objc_selector (parser);
7122 /* If there is no selector, or a colon follows, we have an
7123 objc-keyword-selector. If there is a selector, and a colon does
7124 not follow, that selector ends the objc-method-decl. */
7125 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7128 tree list = NULL_TREE;
7131 tree atype = NULL_TREE, id, keyworddecl;
7132 tree param_attr = NULL_TREE;
7133 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7135 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7137 c_parser_consume_token (parser);
7138 atype = c_parser_objc_type_name (parser);
7139 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7142 /* New ObjC allows attributes on method parameters. */
7143 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7144 param_attr = c_parser_attributes (parser);
7145 if (c_parser_next_token_is_not (parser, CPP_NAME))
7147 c_parser_error (parser, "expected identifier");
7148 return error_mark_node;
7150 id = c_parser_peek_token (parser)->value;
7151 c_parser_consume_token (parser);
7152 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7153 list = chainon (list, keyworddecl);
7154 tsel = c_parser_objc_selector (parser);
7155 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7159 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7161 /* Parse the optional parameter list. Optional Objective-C
7162 method parameters follow the C syntax, and may include '...'
7163 to denote a variable number of arguments. */
7164 parms = make_node (TREE_LIST);
7165 while (c_parser_next_token_is (parser, CPP_COMMA))
7167 struct c_parm *parm;
7168 c_parser_consume_token (parser);
7169 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7172 c_parser_consume_token (parser);
7173 attr_err |= c_parser_objc_maybe_method_attributes
7174 (parser, attributes) ;
7177 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7180 parms = chainon (parms,
7181 build_tree_list (NULL_TREE, grokparm (parm)));
7186 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7190 c_parser_error (parser, "objective-c method declaration is expected");
7191 return error_mark_node;
7195 return error_mark_node;
7197 return objc_build_method_signature (type, sel, parms, ellipsis);
7200 /* Parse an objc-type-name.
7203 objc-type-qualifiers[opt] type-name
7204 objc-type-qualifiers[opt]
7206 objc-type-qualifiers:
7208 objc-type-qualifiers objc-type-qualifier
7210 objc-type-qualifier: one of
7211 in out inout bycopy byref oneway
7215 c_parser_objc_type_name (c_parser *parser)
7217 tree quals = NULL_TREE;
7218 struct c_type_name *type_name = NULL;
7219 tree type = NULL_TREE;
7222 c_token *token = c_parser_peek_token (parser);
7223 if (token->type == CPP_KEYWORD
7224 && (token->keyword == RID_IN
7225 || token->keyword == RID_OUT
7226 || token->keyword == RID_INOUT
7227 || token->keyword == RID_BYCOPY
7228 || token->keyword == RID_BYREF
7229 || token->keyword == RID_ONEWAY))
7231 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
7232 c_parser_consume_token (parser);
7237 if (c_parser_next_token_starts_typename (parser))
7238 type_name = c_parser_type_name (parser);
7240 type = groktypename (type_name, NULL, NULL);
7241 return build_tree_list (quals, type);
7244 /* Parse objc-protocol-refs.
7251 c_parser_objc_protocol_refs (c_parser *parser)
7253 tree list = NULL_TREE;
7254 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7255 c_parser_consume_token (parser);
7256 /* Any identifiers, including those declared as type names, are OK
7261 if (c_parser_next_token_is_not (parser, CPP_NAME))
7263 c_parser_error (parser, "expected identifier");
7266 id = c_parser_peek_token (parser)->value;
7267 list = chainon (list, build_tree_list (NULL_TREE, id));
7268 c_parser_consume_token (parser);
7269 if (c_parser_next_token_is (parser, CPP_COMMA))
7270 c_parser_consume_token (parser);
7274 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7278 /* Parse an objc-try-catch-statement.
7280 objc-try-catch-statement:
7281 @try compound-statement objc-catch-list[opt]
7282 @try compound-statement objc-catch-list[opt] @finally compound-statement
7285 @catch ( parameter-declaration ) compound-statement
7286 objc-catch-list @catch ( parameter-declaration ) compound-statement
7290 c_parser_objc_try_catch_statement (c_parser *parser)
7294 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7295 c_parser_consume_token (parser);
7296 loc = c_parser_peek_token (parser)->location;
7297 stmt = c_parser_compound_statement (parser);
7298 objc_begin_try_stmt (loc, stmt);
7299 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7301 struct c_parm *parm;
7302 c_parser_consume_token (parser);
7303 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7305 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7308 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7311 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7312 objc_begin_catch_clause (grokparm (parm));
7313 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7314 c_parser_compound_statement_nostart (parser);
7315 objc_finish_catch_clause ();
7317 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7321 c_parser_consume_token (parser);
7322 finloc = c_parser_peek_token (parser)->location;
7323 finstmt = c_parser_compound_statement (parser);
7324 objc_build_finally_clause (finloc, finstmt);
7326 objc_finish_try_stmt ();
7329 /* Parse an objc-synchronized-statement.
7331 objc-synchronized-statement:
7332 @synchronized ( expression ) compound-statement
7336 c_parser_objc_synchronized_statement (c_parser *parser)
7340 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7341 c_parser_consume_token (parser);
7342 loc = c_parser_peek_token (parser)->location;
7343 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7345 expr = c_parser_expression (parser).value;
7346 expr = c_fully_fold (expr, false, NULL);
7347 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7350 expr = error_mark_node;
7351 stmt = c_parser_compound_statement (parser);
7352 objc_build_synchronized (loc, expr, stmt);
7355 /* Parse an objc-selector; return NULL_TREE without an error if the
7356 next token is not an objc-selector.
7361 enum struct union if else while do for switch case default
7362 break continue return goto asm sizeof typeof __alignof
7363 unsigned long const short volatile signed restrict _Complex
7364 in out inout bycopy byref oneway int char float double void _Bool
7366 ??? Why this selection of keywords but not, for example, storage
7367 class specifiers? */
7370 c_parser_objc_selector (c_parser *parser)
7372 c_token *token = c_parser_peek_token (parser);
7373 tree value = token->value;
7374 if (token->type == CPP_NAME)
7376 c_parser_consume_token (parser);
7379 if (token->type != CPP_KEYWORD)
7381 switch (token->keyword)
7423 c_parser_consume_token (parser);
7430 /* Parse an objc-selector-arg.
7434 objc-keywordname-list
7436 objc-keywordname-list:
7438 objc-keywordname-list objc-keywordname
7446 c_parser_objc_selector_arg (c_parser *parser)
7448 tree sel = c_parser_objc_selector (parser);
7449 tree list = NULL_TREE;
7450 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7454 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7456 list = chainon (list, build_tree_list (sel, NULL_TREE));
7457 sel = c_parser_objc_selector (parser);
7458 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7464 /* Parse an objc-receiver.
7473 c_parser_objc_receiver (c_parser *parser)
7475 if (c_parser_peek_token (parser)->type == CPP_NAME
7476 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7477 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7479 tree id = c_parser_peek_token (parser)->value;
7480 c_parser_consume_token (parser);
7481 return objc_get_class_reference (id);
7483 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7486 /* Parse objc-message-args.
7490 objc-keywordarg-list
7492 objc-keywordarg-list:
7494 objc-keywordarg-list objc-keywordarg
7497 objc-selector : objc-keywordexpr
7502 c_parser_objc_message_args (c_parser *parser)
7504 tree sel = c_parser_objc_selector (parser);
7505 tree list = NULL_TREE;
7506 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7511 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7512 return error_mark_node;
7513 keywordexpr = c_parser_objc_keywordexpr (parser);
7514 list = chainon (list, build_tree_list (sel, keywordexpr));
7515 sel = c_parser_objc_selector (parser);
7516 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7522 /* Parse an objc-keywordexpr.
7529 c_parser_objc_keywordexpr (c_parser *parser)
7532 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7533 if (VEC_length (tree, expr_list) == 1)
7535 /* Just return the expression, remove a level of
7537 ret = VEC_index (tree, expr_list, 0);
7541 /* We have a comma expression, we will collapse later. */
7542 ret = build_tree_list_vec (expr_list);
7544 release_tree_vector (expr_list);
7548 /* A check, needed in several places, that ObjC interface, implementation or
7549 method definitions are not prefixed by incorrect items. */
7551 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7552 struct c_declspecs *specs)
7554 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7556 c_parser_error (parser,
7557 "no type or storage class may be specified here,");
7558 c_parser_skip_to_end_of_block_or_statement (parser);
7564 /* ObjC @property. */
7566 /* Parse a comma-separated list of property attributes. */
7569 c_parser_objc_property_attrlist (c_parser *parser)
7572 /* Initialize to an empty list. */
7573 objc_set_property_attr (c_parser_peek_token (parser)->location,
7574 OBJC_PATTR_INIT, NULL_TREE);
7576 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7580 c_parser_consume_token (parser);
7582 /* Property attribute keywords are valid now. */
7583 parser->objc_property_attr_context = true;
7584 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)
7585 && c_parser_next_token_is_not (parser, CPP_EOF)
7590 if (c_parser_peek_token (parser)->type != CPP_KEYWORD)
7592 c_parser_error (parser, "expected a property attribute");
7593 c_parser_consume_token (parser);
7597 keywd = c_parser_peek_token (parser)->keyword;
7598 /* Initially, make diagnostics point to the attribute. */
7599 loc = c_parser_peek_token (parser)->location;
7603 objc_property_attribute_kind pkind;
7605 objc_set_property_attr (loc, OBJC_PATTR_READONLY, NULL_TREE);
7610 c_parser_consume_token (parser);
7611 if (c_parser_next_token_is_not (parser, CPP_EQ))
7613 c_parser_error (parser,
7614 "getter/setter/ivar attribute must be followed by %<=%>");
7618 c_parser_consume_token (parser); /* eat the = */
7619 if (c_parser_next_token_is_not (parser, CPP_NAME))
7621 c_parser_error (parser, "expected an identifier");
7625 ident = c_parser_peek_token (parser)->value;
7626 if (keywd == RID_SETTER)
7628 pkind = OBJC_PATTR_SETTER;
7629 /* Eat the identifier, and look for the following : */
7630 c_parser_consume_token (parser);
7631 if (c_parser_next_token_is_not (parser, CPP_COLON))
7633 c_parser_error (parser,
7634 "setter name must be followed by %<:%>");
7638 else if (keywd == RID_GETTER)
7639 pkind = OBJC_PATTR_GETTER;
7641 pkind = OBJC_PATTR_IVAR;
7643 objc_set_property_attr (loc, pkind, ident);
7646 objc_set_property_attr (loc, OBJC_PATTR_COPIES, NULL_TREE);
7649 c_parser_error (parser, "unknown property attribute");
7653 /* Eat the attribute,identifier or colon that's been used. */
7654 c_parser_consume_token (parser);
7658 if (c_parser_next_token_is (parser, CPP_COMMA))
7659 c_parser_consume_token (parser);
7660 else if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7661 warning_at (c_parser_peek_token (parser)->location, 0,
7662 "property attributes should be separated by a %<,%>");
7664 parser->objc_property_attr_context = false;
7665 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7668 /* Parse property attributes and then the definition. */
7671 c_parser_objc_at_property (c_parser *parser)
7674 /* We should only arrive here with the property keyword. */
7675 c_parser_require_keyword (parser, RID_AT_PROPERTY, "expected %<@property%>");
7677 /* Process the optional attribute list... */
7678 c_parser_objc_property_attrlist (parser) ;
7679 /* ... and the property var decls. */
7680 props = c_parser_struct_declaration (parser);
7682 /* Comma-separated properties are chained together in
7683 reverse order; add them one by one. */
7684 props = nreverse (props);
7686 for (; props; props = TREE_CHAIN (props))
7687 objc_add_property_variable (copy_node (props));
7689 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7693 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7694 should be considered, statements. ALLOW_STMT is true if we're within
7695 the context of a function and such pragmas are to be allowed. Returns
7696 true if we actually parsed such a pragma. */
7699 c_parser_pragma (c_parser *parser, enum pragma_context context)
7703 id = c_parser_peek_token (parser)->pragma_kind;
7704 gcc_assert (id != PRAGMA_NONE);
7708 case PRAGMA_OMP_BARRIER:
7709 if (context != pragma_compound)
7711 if (context == pragma_stmt)
7712 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7713 "used in compound statements");
7716 c_parser_omp_barrier (parser);
7719 case PRAGMA_OMP_FLUSH:
7720 if (context != pragma_compound)
7722 if (context == pragma_stmt)
7723 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7724 "used in compound statements");
7727 c_parser_omp_flush (parser);
7730 case PRAGMA_OMP_TASKWAIT:
7731 if (context != pragma_compound)
7733 if (context == pragma_stmt)
7734 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7735 "used in compound statements");
7738 c_parser_omp_taskwait (parser);
7741 case PRAGMA_OMP_THREADPRIVATE:
7742 c_parser_omp_threadprivate (parser);
7745 case PRAGMA_OMP_SECTION:
7746 error_at (c_parser_peek_token (parser)->location,
7747 "%<#pragma omp section%> may only be used in "
7748 "%<#pragma omp sections%> construct");
7749 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7752 case PRAGMA_GCC_PCH_PREPROCESS:
7753 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7754 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7758 if (id < PRAGMA_FIRST_EXTERNAL)
7760 if (context == pragma_external)
7763 c_parser_error (parser, "expected declaration specifiers");
7764 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7767 c_parser_omp_construct (parser);
7773 c_parser_consume_pragma (parser);
7774 c_invoke_pragma_handler (id);
7776 /* Skip to EOL, but suppress any error message. Those will have been
7777 generated by the handler routine through calling error, as opposed
7778 to calling c_parser_error. */
7779 parser->error = true;
7780 c_parser_skip_to_pragma_eol (parser);
7785 /* The interface the pragma parsers have to the lexer. */
7788 pragma_lex (tree *value)
7790 c_token *tok = c_parser_peek_token (the_parser);
7791 enum cpp_ttype ret = tok->type;
7793 *value = tok->value;
7794 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7798 if (ret == CPP_KEYWORD)
7800 c_parser_consume_token (the_parser);
7807 c_parser_pragma_pch_preprocess (c_parser *parser)
7811 c_parser_consume_pragma (parser);
7812 if (c_parser_next_token_is (parser, CPP_STRING))
7814 name = c_parser_peek_token (parser)->value;
7815 c_parser_consume_token (parser);
7818 c_parser_error (parser, "expected string literal");
7819 c_parser_skip_to_pragma_eol (parser);
7822 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7825 /* OpenMP 2.5 parsing routines. */
7827 /* Returns name of the next clause.
7828 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7829 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7830 returned and the token is consumed. */
7832 static pragma_omp_clause
7833 c_parser_omp_clause_name (c_parser *parser)
7835 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7837 if (c_parser_next_token_is_keyword (parser, RID_IF))
7838 result = PRAGMA_OMP_CLAUSE_IF;
7839 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7840 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7841 else if (c_parser_next_token_is (parser, CPP_NAME))
7843 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7848 if (!strcmp ("collapse", p))
7849 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7850 else if (!strcmp ("copyin", p))
7851 result = PRAGMA_OMP_CLAUSE_COPYIN;
7852 else if (!strcmp ("copyprivate", p))
7853 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7856 if (!strcmp ("firstprivate", p))
7857 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7860 if (!strcmp ("lastprivate", p))
7861 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7864 if (!strcmp ("nowait", p))
7865 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7866 else if (!strcmp ("num_threads", p))
7867 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7870 if (!strcmp ("ordered", p))
7871 result = PRAGMA_OMP_CLAUSE_ORDERED;
7874 if (!strcmp ("private", p))
7875 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7878 if (!strcmp ("reduction", p))
7879 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7882 if (!strcmp ("schedule", p))
7883 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7884 else if (!strcmp ("shared", p))
7885 result = PRAGMA_OMP_CLAUSE_SHARED;
7888 if (!strcmp ("untied", p))
7889 result = PRAGMA_OMP_CLAUSE_UNTIED;
7894 if (result != PRAGMA_OMP_CLAUSE_NONE)
7895 c_parser_consume_token (parser);
7900 /* Validate that a clause of the given type does not already exist. */
7903 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7908 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7909 if (OMP_CLAUSE_CODE (c) == code)
7911 location_t loc = OMP_CLAUSE_LOCATION (c);
7912 error_at (loc, "too many %qs clauses", name);
7920 variable-list , identifier
7922 If KIND is nonzero, create the appropriate node and install the
7923 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7924 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7926 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7927 return the list created. */
7930 c_parser_omp_variable_list (c_parser *parser,
7931 location_t clause_loc,
7932 enum omp_clause_code kind,
7935 if (c_parser_next_token_is_not (parser, CPP_NAME)
7936 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7937 c_parser_error (parser, "expected identifier");
7939 while (c_parser_next_token_is (parser, CPP_NAME)
7940 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7942 tree t = lookup_name (c_parser_peek_token (parser)->value);
7945 undeclared_variable (c_parser_peek_token (parser)->location,
7946 c_parser_peek_token (parser)->value);
7947 else if (t == error_mark_node)
7951 tree u = build_omp_clause (clause_loc, kind);
7952 OMP_CLAUSE_DECL (u) = t;
7953 OMP_CLAUSE_CHAIN (u) = list;
7957 list = tree_cons (t, NULL_TREE, list);
7959 c_parser_consume_token (parser);
7961 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7964 c_parser_consume_token (parser);
7970 /* Similarly, but expect leading and trailing parenthesis. This is a very
7971 common case for omp clauses. */
7974 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7977 /* The clauses location. */
7978 location_t loc = c_parser_peek_token (parser)->location;
7980 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7982 list = c_parser_omp_variable_list (parser, loc, kind, list);
7983 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7989 collapse ( constant-expression ) */
7992 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7994 tree c, num = error_mark_node;
7998 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8000 loc = c_parser_peek_token (parser)->location;
8001 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8003 num = c_parser_expr_no_commas (parser, NULL).value;
8004 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8006 if (num == error_mark_node)
8008 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8009 || !host_integerp (num, 0)
8010 || (n = tree_low_cst (num, 0)) <= 0
8014 "collapse argument needs positive constant integer expression");
8017 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8018 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8019 OMP_CLAUSE_CHAIN (c) = list;
8024 copyin ( variable-list ) */
8027 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8029 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8033 copyprivate ( variable-list ) */
8036 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8038 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8042 default ( shared | none ) */
8045 c_parser_omp_clause_default (c_parser *parser, tree list)
8047 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8048 location_t loc = c_parser_peek_token (parser)->location;
8051 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8053 if (c_parser_next_token_is (parser, CPP_NAME))
8055 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8060 if (strcmp ("none", p) != 0)
8062 kind = OMP_CLAUSE_DEFAULT_NONE;
8066 if (strcmp ("shared", p) != 0)
8068 kind = OMP_CLAUSE_DEFAULT_SHARED;
8075 c_parser_consume_token (parser);
8080 c_parser_error (parser, "expected %<none%> or %<shared%>");
8082 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8084 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8087 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8088 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8089 OMP_CLAUSE_CHAIN (c) = list;
8090 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8096 firstprivate ( variable-list ) */
8099 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8101 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8105 if ( expression ) */
8108 c_parser_omp_clause_if (c_parser *parser, tree list)
8110 location_t loc = c_parser_peek_token (parser)->location;
8111 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8113 tree t = c_parser_paren_condition (parser);
8116 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8118 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8119 OMP_CLAUSE_IF_EXPR (c) = t;
8120 OMP_CLAUSE_CHAIN (c) = list;
8124 c_parser_error (parser, "expected %<(%>");
8130 lastprivate ( variable-list ) */
8133 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8135 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8142 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8145 location_t loc = c_parser_peek_token (parser)->location;
8147 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8149 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8150 OMP_CLAUSE_CHAIN (c) = list;
8155 num_threads ( expression ) */
8158 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8160 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8161 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8163 location_t expr_loc = c_parser_peek_token (parser)->location;
8164 tree c, t = c_parser_expression (parser).value;
8165 t = c_fully_fold (t, false, NULL);
8167 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8169 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8171 c_parser_error (parser, "expected integer expression");
8175 /* Attempt to statically determine when the number isn't positive. */
8176 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8177 build_int_cst (TREE_TYPE (t), 0));
8178 if (CAN_HAVE_LOCATION_P (c))
8179 SET_EXPR_LOCATION (c, expr_loc);
8180 if (c == boolean_true_node)
8182 warning_at (expr_loc, 0,
8183 "%<num_threads%> value must be positive");
8184 t = integer_one_node;
8187 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8189 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8190 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8191 OMP_CLAUSE_CHAIN (c) = list;
8202 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8206 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8208 c = build_omp_clause (c_parser_peek_token (parser)->location,
8209 OMP_CLAUSE_ORDERED);
8210 OMP_CLAUSE_CHAIN (c) = list;
8216 private ( variable-list ) */
8219 c_parser_omp_clause_private (c_parser *parser, tree list)
8221 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8225 reduction ( reduction-operator : variable-list )
8228 One of: + * - & ^ | && || */
8231 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8233 location_t clause_loc = c_parser_peek_token (parser)->location;
8234 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8236 enum tree_code code;
8238 switch (c_parser_peek_token (parser)->type)
8250 code = BIT_AND_EXPR;
8253 code = BIT_XOR_EXPR;
8256 code = BIT_IOR_EXPR;
8259 code = TRUTH_ANDIF_EXPR;
8262 code = TRUTH_ORIF_EXPR;
8265 c_parser_error (parser,
8266 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8267 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8268 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8271 c_parser_consume_token (parser);
8272 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8276 nl = c_parser_omp_variable_list (parser, clause_loc,
8277 OMP_CLAUSE_REDUCTION, list);
8278 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8279 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8289 schedule ( schedule-kind )
8290 schedule ( schedule-kind , expression )
8293 static | dynamic | guided | runtime | auto
8297 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8300 location_t loc = c_parser_peek_token (parser)->location;
8302 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8305 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8307 if (c_parser_next_token_is (parser, CPP_NAME))
8309 tree kind = c_parser_peek_token (parser)->value;
8310 const char *p = IDENTIFIER_POINTER (kind);
8315 if (strcmp ("dynamic", p) != 0)
8317 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8321 if (strcmp ("guided", p) != 0)
8323 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8327 if (strcmp ("runtime", p) != 0)
8329 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8336 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8337 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8338 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8339 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8343 c_parser_consume_token (parser);
8344 if (c_parser_next_token_is (parser, CPP_COMMA))
8347 c_parser_consume_token (parser);
8349 here = c_parser_peek_token (parser)->location;
8350 t = c_parser_expr_no_commas (parser, NULL).value;
8351 t = c_fully_fold (t, false, NULL);
8353 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8354 error_at (here, "schedule %<runtime%> does not take "
8355 "a %<chunk_size%> parameter");
8356 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8358 "schedule %<auto%> does not take "
8359 "a %<chunk_size%> parameter");
8360 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8361 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8363 c_parser_error (parser, "expected integer expression");
8365 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8368 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8369 "expected %<,%> or %<)%>");
8371 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8372 OMP_CLAUSE_CHAIN (c) = list;
8376 c_parser_error (parser, "invalid schedule kind");
8377 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8382 shared ( variable-list ) */
8385 c_parser_omp_clause_shared (c_parser *parser, tree list)
8387 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8394 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8398 /* FIXME: Should we allow duplicates? */
8399 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8401 c = build_omp_clause (c_parser_peek_token (parser)->location,
8403 OMP_CLAUSE_CHAIN (c) = list;
8408 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8409 is a bitmask in MASK. Return the list of clauses found; the result
8410 of clause default goes in *pdefault. */
8413 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8416 tree clauses = NULL;
8419 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8422 pragma_omp_clause c_kind;
8424 tree prev = clauses;
8426 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8427 c_parser_consume_token (parser);
8430 here = c_parser_peek_token (parser)->location;
8431 c_kind = c_parser_omp_clause_name (parser);
8435 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8436 clauses = c_parser_omp_clause_collapse (parser, clauses);
8437 c_name = "collapse";
8439 case PRAGMA_OMP_CLAUSE_COPYIN:
8440 clauses = c_parser_omp_clause_copyin (parser, clauses);
8443 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8444 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8445 c_name = "copyprivate";
8447 case PRAGMA_OMP_CLAUSE_DEFAULT:
8448 clauses = c_parser_omp_clause_default (parser, clauses);
8451 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8452 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8453 c_name = "firstprivate";
8455 case PRAGMA_OMP_CLAUSE_IF:
8456 clauses = c_parser_omp_clause_if (parser, clauses);
8459 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8460 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8461 c_name = "lastprivate";
8463 case PRAGMA_OMP_CLAUSE_NOWAIT:
8464 clauses = c_parser_omp_clause_nowait (parser, clauses);
8467 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8468 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8469 c_name = "num_threads";
8471 case PRAGMA_OMP_CLAUSE_ORDERED:
8472 clauses = c_parser_omp_clause_ordered (parser, clauses);
8475 case PRAGMA_OMP_CLAUSE_PRIVATE:
8476 clauses = c_parser_omp_clause_private (parser, clauses);
8479 case PRAGMA_OMP_CLAUSE_REDUCTION:
8480 clauses = c_parser_omp_clause_reduction (parser, clauses);
8481 c_name = "reduction";
8483 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8484 clauses = c_parser_omp_clause_schedule (parser, clauses);
8485 c_name = "schedule";
8487 case PRAGMA_OMP_CLAUSE_SHARED:
8488 clauses = c_parser_omp_clause_shared (parser, clauses);
8491 case PRAGMA_OMP_CLAUSE_UNTIED:
8492 clauses = c_parser_omp_clause_untied (parser, clauses);
8496 c_parser_error (parser, "expected %<#pragma omp%> clause");
8500 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8502 /* Remove the invalid clause(s) from the list to avoid
8503 confusing the rest of the compiler. */
8505 error_at (here, "%qs is not valid for %qs", c_name, where);
8510 c_parser_skip_to_pragma_eol (parser);
8512 return c_finish_omp_clauses (clauses);
8519 In practice, we're also interested in adding the statement to an
8520 outer node. So it is convenient if we work around the fact that
8521 c_parser_statement calls add_stmt. */
8524 c_parser_omp_structured_block (c_parser *parser)
8526 tree stmt = push_stmt_list ();
8527 c_parser_statement (parser);
8528 return pop_stmt_list (stmt);
8532 # pragma omp atomic new-line
8536 x binop= expr | x++ | ++x | x-- | --x
8538 +, *, -, /, &, ^, |, <<, >>
8540 where x is an lvalue expression with scalar type.
8542 LOC is the location of the #pragma token. */
8545 c_parser_omp_atomic (location_t loc, c_parser *parser)
8549 enum tree_code code;
8550 struct c_expr rhs_expr;
8552 c_parser_skip_to_pragma_eol (parser);
8554 lhs = c_parser_unary_expression (parser).value;
8555 lhs = c_fully_fold (lhs, false, NULL);
8556 switch (TREE_CODE (lhs))
8560 c_parser_skip_to_end_of_block_or_statement (parser);
8563 case PREINCREMENT_EXPR:
8564 case POSTINCREMENT_EXPR:
8565 lhs = TREE_OPERAND (lhs, 0);
8567 rhs = integer_one_node;
8570 case PREDECREMENT_EXPR:
8571 case POSTDECREMENT_EXPR:
8572 lhs = TREE_OPERAND (lhs, 0);
8574 rhs = integer_one_node;
8578 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8579 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8580 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8581 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8582 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8583 (TREE_OPERAND (lhs, 1), 0), 0)))
8585 /* Undo effects of boolean_increment for post {in,de}crement. */
8586 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8589 if (TREE_CODE (lhs) == MODIFY_EXPR
8590 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8592 /* Undo effects of boolean_increment. */
8593 if (integer_onep (TREE_OPERAND (lhs, 1)))
8595 /* This is pre or post increment. */
8596 rhs = TREE_OPERAND (lhs, 1);
8597 lhs = TREE_OPERAND (lhs, 0);
8601 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8602 && TREE_OPERAND (lhs, 0)
8603 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8605 /* This is pre or post decrement. */
8606 rhs = TREE_OPERAND (lhs, 1);
8607 lhs = TREE_OPERAND (lhs, 0);
8614 switch (c_parser_peek_token (parser)->type)
8620 code = TRUNC_DIV_EXPR;
8635 code = BIT_AND_EXPR;
8638 code = BIT_IOR_EXPR;
8641 code = BIT_XOR_EXPR;
8644 c_parser_error (parser,
8645 "invalid operator for %<#pragma omp atomic%>");
8649 c_parser_consume_token (parser);
8651 location_t rhs_loc = c_parser_peek_token (parser)->location;
8652 rhs_expr = c_parser_expression (parser);
8653 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8655 rhs = rhs_expr.value;
8656 rhs = c_fully_fold (rhs, false, NULL);
8659 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8660 if (stmt != error_mark_node)
8662 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8667 # pragma omp barrier new-line
8671 c_parser_omp_barrier (c_parser *parser)
8673 location_t loc = c_parser_peek_token (parser)->location;
8674 c_parser_consume_pragma (parser);
8675 c_parser_skip_to_pragma_eol (parser);
8677 c_finish_omp_barrier (loc);
8681 # pragma omp critical [(name)] new-line
8684 LOC is the location of the #pragma itself. */
8687 c_parser_omp_critical (location_t loc, c_parser *parser)
8689 tree stmt, name = NULL;
8691 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8693 c_parser_consume_token (parser);
8694 if (c_parser_next_token_is (parser, CPP_NAME))
8696 name = c_parser_peek_token (parser)->value;
8697 c_parser_consume_token (parser);
8698 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8701 c_parser_error (parser, "expected identifier");
8703 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8704 c_parser_error (parser, "expected %<(%> or end of line");
8705 c_parser_skip_to_pragma_eol (parser);
8707 stmt = c_parser_omp_structured_block (parser);
8708 return c_finish_omp_critical (loc, stmt, name);
8712 # pragma omp flush flush-vars[opt] new-line
8715 ( variable-list ) */
8718 c_parser_omp_flush (c_parser *parser)
8720 location_t loc = c_parser_peek_token (parser)->location;
8721 c_parser_consume_pragma (parser);
8722 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8723 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8724 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8725 c_parser_error (parser, "expected %<(%> or end of line");
8726 c_parser_skip_to_pragma_eol (parser);
8728 c_finish_omp_flush (loc);
8731 /* Parse the restricted form of the for statement allowed by OpenMP.
8732 The real trick here is to determine the loop control variable early
8733 so that we can push a new decl if necessary to make it private.
8734 LOC is the location of the OMP in "#pragma omp". */
8737 c_parser_omp_for_loop (location_t loc,
8738 c_parser *parser, tree clauses, tree *par_clauses)
8740 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8741 tree declv, condv, incrv, initv, ret = NULL;
8742 bool fail = false, open_brace_parsed = false;
8743 int i, collapse = 1, nbraces = 0;
8745 VEC(tree,gc) *for_block = make_tree_vector ();
8747 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8748 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8749 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8751 gcc_assert (collapse >= 1);
8753 declv = make_tree_vec (collapse);
8754 initv = make_tree_vec (collapse);
8755 condv = make_tree_vec (collapse);
8756 incrv = make_tree_vec (collapse);
8758 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8760 c_parser_error (parser, "for statement expected");
8763 for_loc = c_parser_peek_token (parser)->location;
8764 c_parser_consume_token (parser);
8766 for (i = 0; i < collapse; i++)
8770 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8773 /* Parse the initialization declaration or expression. */
8774 if (c_parser_next_token_starts_declaration (parser))
8777 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
8778 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
8779 decl = check_for_loop_decls (for_loc, flag_isoc99);
8782 if (DECL_INITIAL (decl) == error_mark_node)
8783 decl = error_mark_node;
8786 else if (c_parser_next_token_is (parser, CPP_NAME)
8787 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8789 struct c_expr decl_exp;
8790 struct c_expr init_exp;
8791 location_t init_loc;
8793 decl_exp = c_parser_postfix_expression (parser);
8794 decl = decl_exp.value;
8796 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8798 init_loc = c_parser_peek_token (parser)->location;
8799 init_exp = c_parser_expr_no_commas (parser, NULL);
8800 init_exp = default_function_array_read_conversion (init_loc,
8802 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8803 NOP_EXPR, init_loc, init_exp.value,
8804 init_exp.original_type);
8805 init = c_process_expr_stmt (init_loc, init);
8807 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8812 c_parser_error (parser,
8813 "expected iteration declaration or initialization");
8814 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8820 /* Parse the loop condition. */
8822 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8824 location_t cond_loc = c_parser_peek_token (parser)->location;
8825 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8827 cond = cond_expr.value;
8828 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8829 cond = c_fully_fold (cond, false, NULL);
8830 switch (cond_expr.original_code)
8838 /* Can't be cond = error_mark_node, because we want to preserve
8839 the location until c_finish_omp_for. */
8840 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8843 protected_set_expr_location (cond, cond_loc);
8845 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8847 /* Parse the increment expression. */
8849 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8851 location_t incr_loc = c_parser_peek_token (parser)->location;
8853 incr = c_process_expr_stmt (incr_loc,
8854 c_parser_expression (parser).value);
8856 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8858 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8862 TREE_VEC_ELT (declv, i) = decl;
8863 TREE_VEC_ELT (initv, i) = init;
8864 TREE_VEC_ELT (condv, i) = cond;
8865 TREE_VEC_ELT (incrv, i) = incr;
8869 if (i == collapse - 1)
8872 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8873 in between the collapsed for loops to be still considered perfectly
8874 nested. Hopefully the final version clarifies this.
8875 For now handle (multiple) {'s and empty statements. */
8878 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8880 c_parser_consume_token (parser);
8883 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8885 c_parser_consume_token (parser);
8889 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8890 c_parser_consume_token (parser);
8893 c_parser_error (parser, "not enough perfectly nested loops");
8896 open_brace_parsed = true;
8906 nbraces += bracecount;
8909 save_break = c_break_label;
8910 c_break_label = size_one_node;
8911 save_cont = c_cont_label;
8912 c_cont_label = NULL_TREE;
8913 body = push_stmt_list ();
8915 if (open_brace_parsed)
8917 location_t here = c_parser_peek_token (parser)->location;
8918 stmt = c_begin_compound_stmt (true);
8919 c_parser_compound_statement_nostart (parser);
8920 add_stmt (c_end_compound_stmt (here, stmt, true));
8923 add_stmt (c_parser_c99_block_statement (parser));
8926 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8927 SET_EXPR_LOCATION (t, loc);
8931 body = pop_stmt_list (body);
8932 c_break_label = save_break;
8933 c_cont_label = save_cont;
8937 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8939 c_parser_consume_token (parser);
8942 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8943 c_parser_consume_token (parser);
8946 c_parser_error (parser, "collapsed loops not perfectly nested");
8949 location_t here = c_parser_peek_token (parser)->location;
8950 stmt = c_begin_compound_stmt (true);
8952 c_parser_compound_statement_nostart (parser);
8953 body = c_end_compound_stmt (here, stmt, true);
8960 /* Only bother calling c_finish_omp_for if we haven't already generated
8961 an error from the initialization parsing. */
8964 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8967 if (par_clauses != NULL)
8970 for (c = par_clauses; *c ; )
8971 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8972 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8973 c = &OMP_CLAUSE_CHAIN (*c);
8976 for (i = 0; i < collapse; i++)
8977 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8980 c = &OMP_CLAUSE_CHAIN (*c);
8981 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8984 "iteration variable %qD should not be firstprivate",
8985 OMP_CLAUSE_DECL (*c));
8986 *c = OMP_CLAUSE_CHAIN (*c);
8990 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8991 change it to shared (decl) in
8992 OMP_PARALLEL_CLAUSES. */
8993 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8994 OMP_CLAUSE_LASTPRIVATE);
8995 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8996 OMP_CLAUSE_CHAIN (l) = clauses;
8998 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9002 OMP_FOR_CLAUSES (stmt) = clauses;
9007 while (!VEC_empty (tree, for_block))
9009 /* FIXME diagnostics: LOC below should be the actual location of
9010 this particular for block. We need to build a list of
9011 locations to go along with FOR_BLOCK. */
9012 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9015 release_tree_vector (for_block);
9020 #pragma omp for for-clause[optseq] new-line
9023 LOC is the location of the #pragma token.
9026 #define OMP_FOR_CLAUSE_MASK \
9027 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9028 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9029 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9030 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9031 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9032 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9033 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9034 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9037 c_parser_omp_for (location_t loc, c_parser *parser)
9039 tree block, clauses, ret;
9041 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9044 block = c_begin_compound_stmt (true);
9045 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9046 block = c_end_compound_stmt (loc, block, true);
9053 # pragma omp master new-line
9056 LOC is the location of the #pragma token.
9060 c_parser_omp_master (location_t loc, c_parser *parser)
9062 c_parser_skip_to_pragma_eol (parser);
9063 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9067 # pragma omp ordered new-line
9070 LOC is the location of the #pragma itself.
9074 c_parser_omp_ordered (location_t loc, c_parser *parser)
9076 c_parser_skip_to_pragma_eol (parser);
9077 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9083 { section-sequence }
9086 section-directive[opt] structured-block
9087 section-sequence section-directive structured-block
9089 SECTIONS_LOC is the location of the #pragma omp sections. */
9092 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9095 bool error_suppress = false;
9098 loc = c_parser_peek_token (parser)->location;
9099 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9101 /* Avoid skipping until the end of the block. */
9102 parser->error = false;
9106 stmt = push_stmt_list ();
9108 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9110 substmt = push_stmt_list ();
9114 c_parser_statement (parser);
9116 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9118 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9120 if (c_parser_next_token_is (parser, CPP_EOF))
9124 substmt = pop_stmt_list (substmt);
9125 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9126 SET_EXPR_LOCATION (substmt, loc);
9132 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9134 if (c_parser_next_token_is (parser, CPP_EOF))
9137 loc = c_parser_peek_token (parser)->location;
9138 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9140 c_parser_consume_pragma (parser);
9141 c_parser_skip_to_pragma_eol (parser);
9142 error_suppress = false;
9144 else if (!error_suppress)
9146 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9147 error_suppress = true;
9150 substmt = c_parser_omp_structured_block (parser);
9151 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9152 SET_EXPR_LOCATION (substmt, loc);
9155 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9156 "expected %<#pragma omp section%> or %<}%>");
9158 substmt = pop_stmt_list (stmt);
9160 stmt = make_node (OMP_SECTIONS);
9161 SET_EXPR_LOCATION (stmt, sections_loc);
9162 TREE_TYPE (stmt) = void_type_node;
9163 OMP_SECTIONS_BODY (stmt) = substmt;
9165 return add_stmt (stmt);
9169 # pragma omp sections sections-clause[optseq] newline
9172 LOC is the location of the #pragma token.
9175 #define OMP_SECTIONS_CLAUSE_MASK \
9176 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9177 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9178 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9179 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9180 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9183 c_parser_omp_sections (location_t loc, c_parser *parser)
9185 tree block, clauses, ret;
9187 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9188 "#pragma omp sections");
9190 block = c_begin_compound_stmt (true);
9191 ret = c_parser_omp_sections_scope (loc, parser);
9193 OMP_SECTIONS_CLAUSES (ret) = clauses;
9194 block = c_end_compound_stmt (loc, block, true);
9201 # pragma parallel parallel-clause new-line
9202 # pragma parallel for parallel-for-clause new-line
9203 # pragma parallel sections parallel-sections-clause new-line
9205 LOC is the location of the #pragma token.
9208 #define OMP_PARALLEL_CLAUSE_MASK \
9209 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9210 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9211 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9212 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9213 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9214 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9215 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9216 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9219 c_parser_omp_parallel (location_t loc, c_parser *parser)
9221 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9222 const char *p_name = "#pragma omp parallel";
9223 tree stmt, clauses, par_clause, ws_clause, block;
9224 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9226 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9228 c_parser_consume_token (parser);
9229 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9230 p_name = "#pragma omp parallel for";
9231 mask |= OMP_FOR_CLAUSE_MASK;
9232 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9234 else if (c_parser_next_token_is (parser, CPP_NAME))
9236 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9237 if (strcmp (p, "sections") == 0)
9239 c_parser_consume_token (parser);
9240 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9241 p_name = "#pragma omp parallel sections";
9242 mask |= OMP_SECTIONS_CLAUSE_MASK;
9243 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9247 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9251 case PRAGMA_OMP_PARALLEL:
9252 block = c_begin_omp_parallel ();
9253 c_parser_statement (parser);
9254 stmt = c_finish_omp_parallel (loc, clauses, block);
9257 case PRAGMA_OMP_PARALLEL_FOR:
9258 block = c_begin_omp_parallel ();
9259 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9260 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9261 stmt = c_finish_omp_parallel (loc, par_clause, block);
9262 OMP_PARALLEL_COMBINED (stmt) = 1;
9265 case PRAGMA_OMP_PARALLEL_SECTIONS:
9266 block = c_begin_omp_parallel ();
9267 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9268 stmt = c_parser_omp_sections_scope (loc, parser);
9270 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9271 stmt = c_finish_omp_parallel (loc, par_clause, block);
9272 OMP_PARALLEL_COMBINED (stmt) = 1;
9283 # pragma omp single single-clause[optseq] new-line
9286 LOC is the location of the #pragma.
9289 #define OMP_SINGLE_CLAUSE_MASK \
9290 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9291 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9292 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9293 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9296 c_parser_omp_single (location_t loc, c_parser *parser)
9298 tree stmt = make_node (OMP_SINGLE);
9299 SET_EXPR_LOCATION (stmt, loc);
9300 TREE_TYPE (stmt) = void_type_node;
9302 OMP_SINGLE_CLAUSES (stmt)
9303 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9304 "#pragma omp single");
9305 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9307 return add_stmt (stmt);
9311 # pragma omp task task-clause[optseq] new-line
9313 LOC is the location of the #pragma.
9316 #define OMP_TASK_CLAUSE_MASK \
9317 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9318 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9319 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9320 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9321 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9322 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9325 c_parser_omp_task (location_t loc, c_parser *parser)
9327 tree clauses, block;
9329 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9330 "#pragma omp task");
9332 block = c_begin_omp_task ();
9333 c_parser_statement (parser);
9334 return c_finish_omp_task (loc, clauses, block);
9338 # pragma omp taskwait new-line
9342 c_parser_omp_taskwait (c_parser *parser)
9344 location_t loc = c_parser_peek_token (parser)->location;
9345 c_parser_consume_pragma (parser);
9346 c_parser_skip_to_pragma_eol (parser);
9348 c_finish_omp_taskwait (loc);
9351 /* Main entry point to parsing most OpenMP pragmas. */
9354 c_parser_omp_construct (c_parser *parser)
9356 enum pragma_kind p_kind;
9360 loc = c_parser_peek_token (parser)->location;
9361 p_kind = c_parser_peek_token (parser)->pragma_kind;
9362 c_parser_consume_pragma (parser);
9366 case PRAGMA_OMP_ATOMIC:
9367 c_parser_omp_atomic (loc, parser);
9369 case PRAGMA_OMP_CRITICAL:
9370 stmt = c_parser_omp_critical (loc, parser);
9372 case PRAGMA_OMP_FOR:
9373 stmt = c_parser_omp_for (loc, parser);
9375 case PRAGMA_OMP_MASTER:
9376 stmt = c_parser_omp_master (loc, parser);
9378 case PRAGMA_OMP_ORDERED:
9379 stmt = c_parser_omp_ordered (loc, parser);
9381 case PRAGMA_OMP_PARALLEL:
9382 stmt = c_parser_omp_parallel (loc, parser);
9384 case PRAGMA_OMP_SECTIONS:
9385 stmt = c_parser_omp_sections (loc, parser);
9387 case PRAGMA_OMP_SINGLE:
9388 stmt = c_parser_omp_single (loc, parser);
9390 case PRAGMA_OMP_TASK:
9391 stmt = c_parser_omp_task (loc, parser);
9398 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9403 # pragma omp threadprivate (variable-list) */
9406 c_parser_omp_threadprivate (c_parser *parser)
9411 c_parser_consume_pragma (parser);
9412 loc = c_parser_peek_token (parser)->location;
9413 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9415 /* Mark every variable in VARS to be assigned thread local storage. */
9416 for (t = vars; t; t = TREE_CHAIN (t))
9418 tree v = TREE_PURPOSE (t);
9420 /* FIXME diagnostics: Ideally we should keep individual
9421 locations for all the variables in the var list to make the
9422 following errors more precise. Perhaps
9423 c_parser_omp_var_list_parens() should construct a list of
9424 locations to go along with the var list. */
9426 /* If V had already been marked threadprivate, it doesn't matter
9427 whether it had been used prior to this point. */
9428 if (TREE_CODE (v) != VAR_DECL)
9429 error_at (loc, "%qD is not a variable", v);
9430 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9431 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9432 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9433 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9434 else if (TREE_TYPE (v) == error_mark_node)
9436 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9437 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9440 if (! DECL_THREAD_LOCAL_P (v))
9442 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9443 /* If rtl has been already set for this var, call
9444 make_decl_rtl once again, so that encode_section_info
9445 has a chance to look at the new decl flags. */
9446 if (DECL_RTL_SET_P (v))
9449 C_DECL_THREADPRIVATE_P (v) = 1;
9453 c_parser_skip_to_pragma_eol (parser);
9457 /* Parse a single source file. */
9462 /* Use local storage to begin. If the first token is a pragma, parse it.
9463 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9464 which will cause garbage collection. */
9467 memset (&tparser, 0, sizeof tparser);
9468 the_parser = &tparser;
9470 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9471 c_parser_pragma_pch_preprocess (&tparser);
9473 the_parser = ggc_alloc_c_parser ();
9474 *the_parser = tparser;
9476 /* Initialize EH, if we've been told to do so. */
9477 if (flag_exceptions)
9478 using_eh_for_cleanups ();
9480 c_parser_translation_unit (the_parser);
9484 #include "gt-c-parser.h"