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);
602 /* In Objective-C, a classname normally starts a declspecs unless it
603 is immediately followed by a dot. In that case, it is the
604 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
605 setter/getter on the class. c_token_starts_declspecs() can't
606 differentiate between the two cases because it only checks the
607 current token, so we have a special check here. */
608 if (c_dialect_objc ()
609 && token->type == CPP_NAME
610 && token->id_kind == C_ID_CLASSNAME
611 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
614 return c_token_starts_declspecs (token);
617 /* Return true if the next token from PARSER can start declaration
618 specifiers or a static assertion, false otherwise. */
620 c_parser_next_token_starts_declaration (c_parser *parser)
622 c_token *token = c_parser_peek_token (parser);
625 if (c_dialect_objc ()
626 && token->type == CPP_NAME
627 && token->id_kind == C_ID_CLASSNAME
628 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
631 return c_token_starts_declaration (token);
634 /* Return a pointer to the next-but-one token from PARSER, reading it
635 in if necessary. The next token is already read in. */
638 c_parser_peek_2nd_token (c_parser *parser)
640 if (parser->tokens_avail >= 2)
641 return &parser->tokens[1];
642 gcc_assert (parser->tokens_avail == 1);
643 gcc_assert (parser->tokens[0].type != CPP_EOF);
644 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
645 c_lex_one_token (parser, &parser->tokens[1]);
646 parser->tokens_avail = 2;
647 return &parser->tokens[1];
650 /* Consume the next token from PARSER. */
653 c_parser_consume_token (c_parser *parser)
655 gcc_assert (parser->tokens_avail >= 1);
656 gcc_assert (parser->tokens[0].type != CPP_EOF);
657 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
658 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
659 if (parser->tokens_avail == 2)
660 parser->tokens[0] = parser->tokens[1];
661 parser->tokens_avail--;
664 /* Expect the current token to be a #pragma. Consume it and remember
665 that we've begun parsing a pragma. */
668 c_parser_consume_pragma (c_parser *parser)
670 gcc_assert (!parser->in_pragma);
671 gcc_assert (parser->tokens_avail >= 1);
672 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
673 if (parser->tokens_avail == 2)
674 parser->tokens[0] = parser->tokens[1];
675 parser->tokens_avail--;
676 parser->in_pragma = true;
679 /* Update the globals input_location and in_system_header from
682 c_parser_set_source_position_from_token (c_token *token)
684 if (token->type != CPP_EOF)
686 input_location = token->location;
690 /* Issue a diagnostic of the form
691 FILE:LINE: MESSAGE before TOKEN
692 where TOKEN is the next token in the input stream of PARSER.
693 MESSAGE (specified by the caller) is usually of the form "expected
696 Do not issue a diagnostic if still recovering from an error.
698 ??? This is taken from the C++ parser, but building up messages in
699 this way is not i18n-friendly and some other approach should be
703 c_parser_error (c_parser *parser, const char *gmsgid)
705 c_token *token = c_parser_peek_token (parser);
708 parser->error = true;
711 /* This diagnostic makes more sense if it is tagged to the line of
712 the token we just peeked at. */
713 c_parser_set_source_position_from_token (token);
714 c_parse_error (gmsgid,
715 /* Because c_parse_error does not understand
716 CPP_KEYWORD, keywords are treated like
718 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
719 /* ??? The C parser does not save the cpp flags of a
720 token, we need to pass 0 here and we will not get
721 the source spelling of some tokens but rather the
722 canonical spelling. */
723 token->value, /*flags=*/0);
726 /* If the next token is of the indicated TYPE, consume it. Otherwise,
727 issue the error MSGID. If MSGID is NULL then a message has already
728 been produced and no message will be produced this time. Returns
729 true if found, false otherwise. */
732 c_parser_require (c_parser *parser,
736 if (c_parser_next_token_is (parser, type))
738 c_parser_consume_token (parser);
743 c_parser_error (parser, msgid);
748 /* If the next token is the indicated keyword, consume it. Otherwise,
749 issue the error MSGID. Returns true if found, false otherwise. */
752 c_parser_require_keyword (c_parser *parser,
756 if (c_parser_next_token_is_keyword (parser, keyword))
758 c_parser_consume_token (parser);
763 c_parser_error (parser, msgid);
768 /* Like c_parser_require, except that tokens will be skipped until the
769 desired token is found. An error message is still produced if the
770 next token is not as expected. If MSGID is NULL then a message has
771 already been produced and no message will be produced this
775 c_parser_skip_until_found (c_parser *parser,
779 unsigned nesting_depth = 0;
781 if (c_parser_require (parser, type, msgid))
784 /* Skip tokens until the desired token is found. */
787 /* Peek at the next token. */
788 c_token *token = c_parser_peek_token (parser);
789 /* If we've reached the token we want, consume it and stop. */
790 if (token->type == type && !nesting_depth)
792 c_parser_consume_token (parser);
796 /* If we've run out of tokens, stop. */
797 if (token->type == CPP_EOF)
799 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
801 if (token->type == CPP_OPEN_BRACE
802 || token->type == CPP_OPEN_PAREN
803 || token->type == CPP_OPEN_SQUARE)
805 else if (token->type == CPP_CLOSE_BRACE
806 || token->type == CPP_CLOSE_PAREN
807 || token->type == CPP_CLOSE_SQUARE)
809 if (nesting_depth-- == 0)
812 /* Consume this token. */
813 c_parser_consume_token (parser);
815 parser->error = false;
818 /* Skip tokens until the end of a parameter is found, but do not
819 consume the comma, semicolon or closing delimiter. */
822 c_parser_skip_to_end_of_parameter (c_parser *parser)
824 unsigned nesting_depth = 0;
828 c_token *token = c_parser_peek_token (parser);
829 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
832 /* If we've run out of tokens, stop. */
833 if (token->type == CPP_EOF)
835 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
837 if (token->type == CPP_OPEN_BRACE
838 || token->type == CPP_OPEN_PAREN
839 || token->type == CPP_OPEN_SQUARE)
841 else if (token->type == CPP_CLOSE_BRACE
842 || token->type == CPP_CLOSE_PAREN
843 || token->type == CPP_CLOSE_SQUARE)
845 if (nesting_depth-- == 0)
848 /* Consume this token. */
849 c_parser_consume_token (parser);
851 parser->error = false;
854 /* Expect to be at the end of the pragma directive and consume an
855 end of line marker. */
858 c_parser_skip_to_pragma_eol (c_parser *parser)
860 gcc_assert (parser->in_pragma);
861 parser->in_pragma = false;
863 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
866 c_token *token = c_parser_peek_token (parser);
867 if (token->type == CPP_EOF)
869 if (token->type == CPP_PRAGMA_EOL)
871 c_parser_consume_token (parser);
874 c_parser_consume_token (parser);
877 parser->error = false;
880 /* Skip tokens until we have consumed an entire block, or until we
881 have consumed a non-nested ';'. */
884 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
886 unsigned nesting_depth = 0;
887 bool save_error = parser->error;
893 /* Peek at the next token. */
894 token = c_parser_peek_token (parser);
902 if (parser->in_pragma)
907 /* If the next token is a ';', we have reached the
908 end of the statement. */
911 /* Consume the ';'. */
912 c_parser_consume_token (parser);
917 case CPP_CLOSE_BRACE:
918 /* If the next token is a non-nested '}', then we have
919 reached the end of the current block. */
920 if (nesting_depth == 0 || --nesting_depth == 0)
922 c_parser_consume_token (parser);
928 /* If it the next token is a '{', then we are entering a new
929 block. Consume the entire block. */
934 /* If we see a pragma, consume the whole thing at once. We
935 have some safeguards against consuming pragmas willy-nilly.
936 Normally, we'd expect to be here with parser->error set,
937 which disables these safeguards. But it's possible to get
938 here for secondary error recovery, after parser->error has
940 c_parser_consume_pragma (parser);
941 c_parser_skip_to_pragma_eol (parser);
942 parser->error = save_error;
949 c_parser_consume_token (parser);
953 parser->error = false;
956 /* CPP's options (initialized by c-opts.c). */
957 extern cpp_options *cpp_opts;
959 /* Save the warning flags which are controlled by __extension__. */
962 disable_extension_diagnostics (void)
965 | (warn_pointer_arith << 1)
966 | (warn_traditional << 2)
968 | (warn_long_long << 4)
969 | (warn_cxx_compat << 5));
970 cpp_opts->cpp_pedantic = pedantic = 0;
971 warn_pointer_arith = 0;
972 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
974 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
979 /* Restore the warning flags which are controlled by __extension__.
980 FLAGS is the return value from disable_extension_diagnostics. */
983 restore_extension_diagnostics (int flags)
985 cpp_opts->cpp_pedantic = pedantic = flags & 1;
986 warn_pointer_arith = (flags >> 1) & 1;
987 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
988 flag_iso = (flags >> 3) & 1;
989 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
990 warn_cxx_compat = (flags >> 5) & 1;
993 /* Possibly kinds of declarator to parse. */
994 typedef enum c_dtr_syn {
995 /* A normal declarator with an identifier. */
997 /* An abstract declarator (maybe empty). */
999 /* A parameter declarator: may be either, but after a type name does
1000 not redeclare a typedef name as an identifier if it can
1001 alternatively be interpreted as a typedef name; see DR#009,
1002 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1003 following DR#249. For example, given a typedef T, "int T" and
1004 "int *T" are valid parameter declarations redeclaring T, while
1005 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1006 abstract declarators rather than involving redundant parentheses;
1007 the same applies with attributes inside the parentheses before
1012 static void c_parser_external_declaration (c_parser *);
1013 static void c_parser_asm_definition (c_parser *);
1014 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1015 bool, bool, tree *);
1016 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1017 static void c_parser_static_assert_declaration (c_parser *);
1018 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1020 static struct c_typespec c_parser_enum_specifier (c_parser *);
1021 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1022 static tree c_parser_struct_declaration (c_parser *);
1023 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1024 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1026 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1028 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1030 struct c_declarator *);
1031 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1032 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1033 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1034 static tree c_parser_simple_asm_expr (c_parser *);
1035 static tree c_parser_attributes (c_parser *);
1036 static struct c_type_name *c_parser_type_name (c_parser *);
1037 static struct c_expr c_parser_initializer (c_parser *);
1038 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1039 static void c_parser_initelt (c_parser *, struct obstack *);
1040 static void c_parser_initval (c_parser *, struct c_expr *,
1042 static tree c_parser_compound_statement (c_parser *);
1043 static void c_parser_compound_statement_nostart (c_parser *);
1044 static void c_parser_label (c_parser *);
1045 static void c_parser_statement (c_parser *);
1046 static void c_parser_statement_after_labels (c_parser *);
1047 static void c_parser_if_statement (c_parser *);
1048 static void c_parser_switch_statement (c_parser *);
1049 static void c_parser_while_statement (c_parser *);
1050 static void c_parser_do_statement (c_parser *);
1051 static void c_parser_for_statement (c_parser *);
1052 static tree c_parser_asm_statement (c_parser *);
1053 static tree c_parser_asm_operands (c_parser *, bool);
1054 static tree c_parser_asm_goto_operands (c_parser *);
1055 static tree c_parser_asm_clobbers (c_parser *);
1056 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1057 static struct c_expr c_parser_conditional_expression (c_parser *,
1059 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1060 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1061 static struct c_expr c_parser_unary_expression (c_parser *);
1062 static struct c_expr c_parser_sizeof_expression (c_parser *);
1063 static struct c_expr c_parser_alignof_expression (c_parser *);
1064 static struct c_expr c_parser_postfix_expression (c_parser *);
1065 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1066 struct c_type_name *,
1068 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1071 static struct c_expr c_parser_expression (c_parser *);
1072 static struct c_expr c_parser_expression_conv (c_parser *);
1073 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1075 static void c_parser_omp_construct (c_parser *);
1076 static void c_parser_omp_threadprivate (c_parser *);
1077 static void c_parser_omp_barrier (c_parser *);
1078 static void c_parser_omp_flush (c_parser *);
1079 static void c_parser_omp_taskwait (c_parser *);
1081 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1082 static bool c_parser_pragma (c_parser *, enum pragma_context);
1084 /* These Objective-C parser functions are only ever called when
1085 compiling Objective-C. */
1086 static void c_parser_objc_class_definition (c_parser *, tree);
1087 static void c_parser_objc_class_instance_variables (c_parser *);
1088 static void c_parser_objc_class_declaration (c_parser *);
1089 static void c_parser_objc_alias_declaration (c_parser *);
1090 static void c_parser_objc_protocol_definition (c_parser *, tree);
1091 static bool c_parser_objc_method_type (c_parser *);
1092 static void c_parser_objc_method_definition (c_parser *);
1093 static void c_parser_objc_methodprotolist (c_parser *);
1094 static void c_parser_objc_methodproto (c_parser *);
1095 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
1096 static tree c_parser_objc_type_name (c_parser *);
1097 static tree c_parser_objc_protocol_refs (c_parser *);
1098 static void c_parser_objc_try_catch_statement (c_parser *);
1099 static void c_parser_objc_synchronized_statement (c_parser *);
1100 static tree c_parser_objc_selector (c_parser *);
1101 static tree c_parser_objc_selector_arg (c_parser *);
1102 static tree c_parser_objc_receiver (c_parser *);
1103 static tree c_parser_objc_message_args (c_parser *);
1104 static tree c_parser_objc_keywordexpr (c_parser *);
1105 static void c_parser_objc_at_property_declaration (c_parser *);
1106 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1107 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1108 static bool c_parser_objc_diagnose_bad_element_prefix
1109 (c_parser *, struct c_declspecs *);
1111 /* Parse a translation unit (C90 6.7, C99 6.9).
1114 external-declarations
1116 external-declarations:
1117 external-declaration
1118 external-declarations external-declaration
1127 c_parser_translation_unit (c_parser *parser)
1129 if (c_parser_next_token_is (parser, CPP_EOF))
1131 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1132 "ISO C forbids an empty translation unit");
1136 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1137 mark_valid_location_for_stdc_pragma (false);
1141 c_parser_external_declaration (parser);
1142 obstack_free (&parser_obstack, obstack_position);
1144 while (c_parser_next_token_is_not (parser, CPP_EOF));
1148 /* Parse an external declaration (C90 6.7, C99 6.9).
1150 external-declaration:
1156 external-declaration:
1159 __extension__ external-declaration
1163 external-declaration:
1164 objc-class-definition
1165 objc-class-declaration
1166 objc-alias-declaration
1167 objc-protocol-definition
1168 objc-method-definition
1173 c_parser_external_declaration (c_parser *parser)
1176 switch (c_parser_peek_token (parser)->type)
1179 switch (c_parser_peek_token (parser)->keyword)
1182 ext = disable_extension_diagnostics ();
1183 c_parser_consume_token (parser);
1184 c_parser_external_declaration (parser);
1185 restore_extension_diagnostics (ext);
1188 c_parser_asm_definition (parser);
1190 case RID_AT_INTERFACE:
1191 case RID_AT_IMPLEMENTATION:
1192 gcc_assert (c_dialect_objc ());
1193 c_parser_objc_class_definition (parser, NULL_TREE);
1196 gcc_assert (c_dialect_objc ());
1197 c_parser_objc_class_declaration (parser);
1200 gcc_assert (c_dialect_objc ());
1201 c_parser_objc_alias_declaration (parser);
1203 case RID_AT_PROTOCOL:
1204 gcc_assert (c_dialect_objc ());
1205 c_parser_objc_protocol_definition (parser, NULL_TREE);
1207 case RID_AT_PROPERTY:
1208 gcc_assert (c_dialect_objc ());
1209 c_parser_objc_at_property_declaration (parser);
1211 case RID_AT_SYNTHESIZE:
1212 gcc_assert (c_dialect_objc ());
1213 c_parser_objc_at_synthesize_declaration (parser);
1215 case RID_AT_DYNAMIC:
1216 gcc_assert (c_dialect_objc ());
1217 c_parser_objc_at_dynamic_declaration (parser);
1220 gcc_assert (c_dialect_objc ());
1221 c_parser_consume_token (parser);
1222 objc_finish_implementation ();
1229 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1230 "ISO C does not allow extra %<;%> outside of a function");
1231 c_parser_consume_token (parser);
1234 mark_valid_location_for_stdc_pragma (true);
1235 c_parser_pragma (parser, pragma_external);
1236 mark_valid_location_for_stdc_pragma (false);
1240 if (c_dialect_objc ())
1242 c_parser_objc_method_definition (parser);
1245 /* Else fall through, and yield a syntax error trying to parse
1246 as a declaration or function definition. */
1249 /* A declaration or a function definition (or, in Objective-C,
1250 an @interface or @protocol with prefix attributes). We can
1251 only tell which after parsing the declaration specifiers, if
1252 any, and the first declarator. */
1253 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1258 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1259 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1260 accepted; otherwise (old-style parameter declarations) only other
1261 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1262 assertion is accepted; otherwise (old-style parameter declarations)
1263 it is not. If NESTED is true, we are inside a function or parsing
1264 old-style parameter declarations; any functions encountered are
1265 nested functions and declaration specifiers are required; otherwise
1266 we are at top level and functions are normal functions and
1267 declaration specifiers may be optional. If EMPTY_OK is true, empty
1268 declarations are OK (subject to all other constraints); otherwise
1269 (old-style parameter declarations) they are diagnosed. If
1270 START_ATTR_OK is true, the declaration specifiers may start with
1271 attributes; otherwise they may not.
1272 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1273 declaration when parsing an Objective-C foreach statement.
1276 declaration-specifiers init-declarator-list[opt] ;
1277 static_assert-declaration
1279 function-definition:
1280 declaration-specifiers[opt] declarator declaration-list[opt]
1285 declaration-list declaration
1287 init-declarator-list:
1289 init-declarator-list , init-declarator
1292 declarator simple-asm-expr[opt] attributes[opt]
1293 declarator simple-asm-expr[opt] attributes[opt] = initializer
1297 nested-function-definition:
1298 declaration-specifiers declarator declaration-list[opt]
1302 attributes objc-class-definition
1303 attributes objc-category-definition
1304 attributes objc-protocol-definition
1306 The simple-asm-expr and attributes are GNU extensions.
1308 This function does not handle __extension__; that is handled in its
1309 callers. ??? Following the old parser, __extension__ may start
1310 external declarations, declarations in functions and declarations
1311 at the start of "for" loops, but not old-style parameter
1314 C99 requires declaration specifiers in a function definition; the
1315 absence is diagnosed through the diagnosis of implicit int. In GNU
1316 C we also allow but diagnose declarations without declaration
1317 specifiers, but only at top level (elsewhere they conflict with
1320 In Objective-C, declarations of the looping variable in a foreach
1321 statement are exceptionally terminated by 'in' (for example, 'for
1322 (NSObject *object in array) { ... }').
1327 threadprivate-directive */
1330 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1331 bool static_assert_ok, bool empty_ok,
1332 bool nested, bool start_attr_ok,
1333 tree *objc_foreach_object_declaration)
1335 struct c_declspecs *specs;
1337 tree all_prefix_attrs;
1338 bool diagnosed_no_specs = false;
1339 location_t here = c_parser_peek_token (parser)->location;
1341 if (static_assert_ok
1342 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1344 c_parser_static_assert_declaration (parser);
1347 specs = build_null_declspecs ();
1348 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1351 c_parser_skip_to_end_of_block_or_statement (parser);
1354 if (nested && !specs->declspecs_seen_p)
1356 c_parser_error (parser, "expected declaration specifiers");
1357 c_parser_skip_to_end_of_block_or_statement (parser);
1360 finish_declspecs (specs);
1361 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1367 shadow_tag_warned (specs, 1);
1368 pedwarn (here, 0, "empty declaration");
1370 c_parser_consume_token (parser);
1373 else if (c_dialect_objc ())
1375 /* Prefix attributes are an error on method decls. */
1376 switch (c_parser_peek_token (parser)->type)
1380 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1384 warning_at (c_parser_peek_token (parser)->location,
1386 "prefix attributes are ignored for methods");
1387 specs->attrs = NULL_TREE;
1390 c_parser_objc_method_definition (parser);
1392 c_parser_objc_methodproto (parser);
1398 /* This is where we parse 'attributes @interface ...',
1399 'attributes @implementation ...', 'attributes @protocol ...'
1400 (where attributes could be, for example, __attribute__
1403 switch (c_parser_peek_token (parser)->keyword)
1405 case RID_AT_INTERFACE:
1407 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1409 c_parser_objc_class_definition (parser, specs->attrs);
1413 case RID_AT_IMPLEMENTATION:
1415 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1419 warning_at (c_parser_peek_token (parser)->location,
1421 "prefix attributes are ignored for implementations");
1422 specs->attrs = NULL_TREE;
1424 c_parser_objc_class_definition (parser, NULL_TREE);
1428 case RID_AT_PROTOCOL:
1430 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1432 c_parser_objc_protocol_definition (parser, specs->attrs);
1439 case RID_AT_PROPERTY:
1442 c_parser_error (parser,
1443 "attributes may not be specified before" );
1444 specs->attrs = NULL;
1452 pending_xref_error ();
1453 prefix_attrs = specs->attrs;
1454 all_prefix_attrs = prefix_attrs;
1455 specs->attrs = NULL_TREE;
1458 struct c_declarator *declarator;
1461 /* Declaring either one or more declarators (in which case we
1462 should diagnose if there were no declaration specifiers) or a
1463 function definition (in which case the diagnostic for
1464 implicit int suffices). */
1465 declarator = c_parser_declarator (parser, specs->type_seen_p,
1466 C_DTR_NORMAL, &dummy);
1467 if (declarator == NULL)
1469 c_parser_skip_to_end_of_block_or_statement (parser);
1472 if (c_parser_next_token_is (parser, CPP_EQ)
1473 || c_parser_next_token_is (parser, CPP_COMMA)
1474 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1475 || c_parser_next_token_is_keyword (parser, RID_ASM)
1476 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1477 || c_parser_next_token_is_keyword (parser, RID_IN))
1479 tree asm_name = NULL_TREE;
1480 tree postfix_attrs = NULL_TREE;
1481 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1483 diagnosed_no_specs = true;
1484 pedwarn (here, 0, "data definition has no type or storage class");
1486 /* Having seen a data definition, there cannot now be a
1487 function definition. */
1489 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1490 asm_name = c_parser_simple_asm_expr (parser);
1491 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1492 postfix_attrs = c_parser_attributes (parser);
1493 if (c_parser_next_token_is (parser, CPP_EQ))
1497 location_t init_loc;
1498 c_parser_consume_token (parser);
1499 /* The declaration of the variable is in effect while
1500 its initializer is parsed. */
1501 d = start_decl (declarator, specs, true,
1502 chainon (postfix_attrs, all_prefix_attrs));
1504 d = error_mark_node;
1505 start_init (d, asm_name, global_bindings_p ());
1506 init_loc = c_parser_peek_token (parser)->location;
1507 init = c_parser_initializer (parser);
1509 if (d != error_mark_node)
1511 maybe_warn_string_init (TREE_TYPE (d), init);
1512 finish_decl (d, init_loc, init.value,
1513 init.original_type, asm_name);
1518 tree d = start_decl (declarator, specs, false,
1519 chainon (postfix_attrs,
1522 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1523 NULL_TREE, asm_name);
1525 if (c_parser_next_token_is_keyword (parser, RID_IN))
1528 *objc_foreach_object_declaration = d;
1530 *objc_foreach_object_declaration = error_mark_node;
1533 if (c_parser_next_token_is (parser, CPP_COMMA))
1535 c_parser_consume_token (parser);
1536 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1537 all_prefix_attrs = chainon (c_parser_attributes (parser),
1540 all_prefix_attrs = prefix_attrs;
1543 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1545 c_parser_consume_token (parser);
1548 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1550 /* This can only happen in Objective-C: we found the
1551 'in' that terminates the declaration inside an
1552 Objective-C foreach statement. Do not consume the
1553 token, so that the caller can use it to determine
1554 that this indeed is a foreach context. */
1559 c_parser_error (parser, "expected %<,%> or %<;%>");
1560 c_parser_skip_to_end_of_block_or_statement (parser);
1566 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1567 "%<asm%> or %<__attribute__%>");
1568 c_parser_skip_to_end_of_block_or_statement (parser);
1571 /* Function definition (nested or otherwise). */
1574 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1575 c_push_function_context ();
1577 if (!start_function (specs, declarator, all_prefix_attrs))
1579 /* This can appear in many cases looking nothing like a
1580 function definition, so we don't give a more specific
1581 error suggesting there was one. */
1582 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1583 "or %<__attribute__%>");
1585 c_pop_function_context ();
1588 /* Parse old-style parameter declarations. ??? Attributes are
1589 not allowed to start declaration specifiers here because of a
1590 syntax conflict between a function declaration with attribute
1591 suffix and a function definition with an attribute prefix on
1592 first old-style parameter declaration. Following the old
1593 parser, they are not accepted on subsequent old-style
1594 parameter declarations either. However, there is no
1595 ambiguity after the first declaration, nor indeed on the
1596 first as long as we don't allow postfix attributes after a
1597 declarator with a nonempty identifier list in a definition;
1598 and postfix attributes have never been accepted here in
1599 function definitions either. */
1600 while (c_parser_next_token_is_not (parser, CPP_EOF)
1601 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1602 c_parser_declaration_or_fndef (parser, false, false, false,
1604 store_parm_decls ();
1605 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1606 = c_parser_peek_token (parser)->location;
1607 fnbody = c_parser_compound_statement (parser);
1610 tree decl = current_function_decl;
1611 /* Mark nested functions as needing static-chain initially.
1612 lower_nested_functions will recompute it but the
1613 DECL_STATIC_CHAIN flag is also used before that happens,
1614 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1615 DECL_STATIC_CHAIN (decl) = 1;
1618 c_pop_function_context ();
1619 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1630 /* Parse an asm-definition (asm() outside a function body). This is a
1638 c_parser_asm_definition (c_parser *parser)
1640 tree asm_str = c_parser_simple_asm_expr (parser);
1642 cgraph_add_asm_node (asm_str);
1643 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1646 /* Parse a static assertion (C1X N1425 6.7.10).
1648 static_assert-declaration:
1649 static_assert-declaration-no-semi ;
1653 c_parser_static_assert_declaration (c_parser *parser)
1655 c_parser_static_assert_declaration_no_semi (parser);
1657 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1658 c_parser_skip_to_end_of_block_or_statement (parser);
1661 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1664 static_assert-declaration-no-semi:
1665 _Static_assert ( constant-expression , string-literal )
1669 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1671 location_t assert_loc, value_loc;
1675 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1676 assert_loc = c_parser_peek_token (parser)->location;
1680 pedwarn (assert_loc, OPT_pedantic,
1681 "ISO C99 does not support %<_Static_assert%>");
1683 pedwarn (assert_loc, OPT_pedantic,
1684 "ISO C90 does not support %<_Static_assert%>");
1686 c_parser_consume_token (parser);
1687 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1689 value_loc = c_parser_peek_token (parser)->location;
1690 value = c_parser_expr_no_commas (parser, NULL).value;
1691 parser->lex_untranslated_string = true;
1692 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1694 parser->lex_untranslated_string = false;
1697 switch (c_parser_peek_token (parser)->type)
1703 case CPP_UTF8STRING:
1704 string = c_parser_peek_token (parser)->value;
1705 c_parser_consume_token (parser);
1706 parser->lex_untranslated_string = false;
1709 c_parser_error (parser, "expected string literal");
1710 parser->lex_untranslated_string = false;
1713 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1715 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1717 error_at (value_loc, "expression in static assertion is not an integer");
1720 if (TREE_CODE (value) != INTEGER_CST)
1722 value = c_fully_fold (value, false, NULL);
1723 if (TREE_CODE (value) == INTEGER_CST)
1724 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1725 "is not an integer constant expression");
1727 if (TREE_CODE (value) != INTEGER_CST)
1729 error_at (value_loc, "expression in static assertion is not constant");
1732 constant_expression_warning (value);
1733 if (integer_zerop (value))
1734 error_at (assert_loc, "static assertion failed: %E", string);
1737 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1738 6.7), adding them to SPECS (which may already include some).
1739 Storage class specifiers are accepted iff SCSPEC_OK; type
1740 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1741 the start iff START_ATTR_OK.
1743 declaration-specifiers:
1744 storage-class-specifier declaration-specifiers[opt]
1745 type-specifier declaration-specifiers[opt]
1746 type-qualifier declaration-specifiers[opt]
1747 function-specifier declaration-specifiers[opt]
1749 Function specifiers (inline) are from C99, and are currently
1750 handled as storage class specifiers, as is __thread.
1752 C90 6.5.1, C99 6.7.1:
1753 storage-class-specifier:
1764 C90 6.5.2, C99 6.7.2:
1777 [_Imaginary removed in C99 TC2]
1778 struct-or-union-specifier
1782 (_Bool and _Complex are new in C99.)
1784 C90 6.5.3, C99 6.7.3:
1790 address-space-qualifier
1792 (restrict is new in C99.)
1796 declaration-specifiers:
1797 attributes declaration-specifiers[opt]
1803 identifier recognized by the target
1805 storage-class-specifier:
1818 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1819 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1824 class-name objc-protocol-refs[opt]
1825 typedef-name objc-protocol-refs
1830 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1831 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1833 bool attrs_ok = start_attr_ok;
1834 bool seen_type = specs->type_seen_p;
1835 while (c_parser_next_token_is (parser, CPP_NAME)
1836 || c_parser_next_token_is (parser, CPP_KEYWORD)
1837 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1839 struct c_typespec t;
1841 location_t loc = c_parser_peek_token (parser)->location;
1842 if (c_parser_next_token_is (parser, CPP_NAME))
1844 tree value = c_parser_peek_token (parser)->value;
1845 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1847 if (kind == C_ID_ADDRSPACE)
1850 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1851 declspecs_add_addrspace (specs, as);
1852 c_parser_consume_token (parser);
1857 /* This finishes the specifiers unless a type name is OK, it
1858 is declared as a type name and a type name hasn't yet
1860 if (!typespec_ok || seen_type
1861 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1863 c_parser_consume_token (parser);
1866 if (kind == C_ID_TYPENAME
1867 && (!c_dialect_objc ()
1868 || c_parser_next_token_is_not (parser, CPP_LESS)))
1870 t.kind = ctsk_typedef;
1871 /* For a typedef name, record the meaning, not the name.
1872 In case of 'foo foo, bar;'. */
1873 t.spec = lookup_name (value);
1875 t.expr_const_operands = true;
1879 tree proto = NULL_TREE;
1880 gcc_assert (c_dialect_objc ());
1882 if (c_parser_next_token_is (parser, CPP_LESS))
1883 proto = c_parser_objc_protocol_refs (parser);
1884 t.spec = objc_get_protocol_qualified_type (value, proto);
1886 t.expr_const_operands = true;
1888 declspecs_add_type (loc, specs, t);
1891 if (c_parser_next_token_is (parser, CPP_LESS))
1893 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1894 nisse@lysator.liu.se. */
1896 gcc_assert (c_dialect_objc ());
1897 if (!typespec_ok || seen_type)
1899 proto = c_parser_objc_protocol_refs (parser);
1901 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1903 t.expr_const_operands = true;
1904 declspecs_add_type (loc, specs, t);
1907 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1908 switch (c_parser_peek_token (parser)->keyword)
1920 /* TODO: Distinguish between function specifiers (inline)
1921 and storage class specifiers, either here or in
1922 declspecs_add_scspec. */
1923 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1924 c_parser_consume_token (parser);
1948 if (c_dialect_objc ())
1949 parser->objc_need_raw_identifier = true;
1950 t.kind = ctsk_resword;
1951 t.spec = c_parser_peek_token (parser)->value;
1953 t.expr_const_operands = true;
1954 declspecs_add_type (loc, specs, t);
1955 c_parser_consume_token (parser);
1962 t = c_parser_enum_specifier (parser);
1963 declspecs_add_type (loc, specs, t);
1971 t = c_parser_struct_or_union_specifier (parser);
1972 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1973 declspecs_add_type (loc, specs, t);
1976 /* ??? The old parser rejected typeof after other type
1977 specifiers, but is a syntax error the best way of
1979 if (!typespec_ok || seen_type)
1983 t = c_parser_typeof_specifier (parser);
1984 declspecs_add_type (loc, specs, t);
1990 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1991 c_parser_consume_token (parser);
1996 attrs = c_parser_attributes (parser);
1997 declspecs_add_attrs (specs, attrs);
2006 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2009 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2010 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2011 enum attributes[opt] identifier
2013 The form with trailing comma is new in C99. The forms with
2014 attributes are GNU extensions. In GNU C, we accept any expression
2015 without commas in the syntax (assignment expressions, not just
2016 conditional expressions); assignment expressions will be diagnosed
2021 enumerator-list , enumerator
2024 enumeration-constant
2025 enumeration-constant = constant-expression
2028 static struct c_typespec
2029 c_parser_enum_specifier (c_parser *parser)
2031 struct c_typespec ret;
2033 tree ident = NULL_TREE;
2034 location_t enum_loc;
2035 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2036 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2037 enum_loc = c_parser_peek_token (parser)->location;
2038 c_parser_consume_token (parser);
2039 attrs = c_parser_attributes (parser);
2040 enum_loc = c_parser_peek_token (parser)->location;
2041 /* Set the location in case we create a decl now. */
2042 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2043 if (c_parser_next_token_is (parser, CPP_NAME))
2045 ident = c_parser_peek_token (parser)->value;
2046 ident_loc = c_parser_peek_token (parser)->location;
2047 enum_loc = ident_loc;
2048 c_parser_consume_token (parser);
2050 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2052 /* Parse an enum definition. */
2053 struct c_enum_contents the_enum;
2054 tree type = start_enum (enum_loc, &the_enum, ident);
2056 /* We chain the enumerators in reverse order, then put them in
2057 forward order at the end. */
2058 tree values = NULL_TREE;
2059 c_parser_consume_token (parser);
2067 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2068 location_t decl_loc, value_loc;
2069 if (c_parser_next_token_is_not (parser, CPP_NAME))
2071 c_parser_error (parser, "expected identifier");
2072 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2073 values = error_mark_node;
2076 token = c_parser_peek_token (parser);
2077 enum_id = token->value;
2078 /* Set the location in case we create a decl now. */
2079 c_parser_set_source_position_from_token (token);
2080 decl_loc = value_loc = token->location;
2081 c_parser_consume_token (parser);
2082 if (c_parser_next_token_is (parser, CPP_EQ))
2084 c_parser_consume_token (parser);
2085 value_loc = c_parser_peek_token (parser)->location;
2086 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2089 enum_value = NULL_TREE;
2090 enum_decl = build_enumerator (decl_loc, value_loc,
2091 &the_enum, enum_id, enum_value);
2092 TREE_CHAIN (enum_decl) = values;
2095 if (c_parser_next_token_is (parser, CPP_COMMA))
2097 comma_loc = c_parser_peek_token (parser)->location;
2099 c_parser_consume_token (parser);
2101 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2103 if (seen_comma && !flag_isoc99)
2104 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2105 c_parser_consume_token (parser);
2110 c_parser_error (parser, "expected %<,%> or %<}%>");
2111 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2112 values = error_mark_node;
2116 postfix_attrs = c_parser_attributes (parser);
2117 ret.spec = finish_enum (type, nreverse (values),
2118 chainon (attrs, postfix_attrs));
2119 ret.kind = ctsk_tagdef;
2120 ret.expr = NULL_TREE;
2121 ret.expr_const_operands = true;
2126 c_parser_error (parser, "expected %<{%>");
2127 ret.spec = error_mark_node;
2128 ret.kind = ctsk_tagref;
2129 ret.expr = NULL_TREE;
2130 ret.expr_const_operands = true;
2133 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2134 /* In ISO C, enumerated types can be referred to only if already
2136 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2139 pedwarn (enum_loc, OPT_pedantic,
2140 "ISO C forbids forward references to %<enum%> types");
2145 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2147 struct-or-union-specifier:
2148 struct-or-union attributes[opt] identifier[opt]
2149 { struct-contents } attributes[opt]
2150 struct-or-union attributes[opt] identifier
2153 struct-declaration-list
2155 struct-declaration-list:
2156 struct-declaration ;
2157 struct-declaration-list struct-declaration ;
2164 struct-declaration-list struct-declaration
2166 struct-declaration-list:
2167 struct-declaration-list ;
2170 (Note that in the syntax here, unlike that in ISO C, the semicolons
2171 are included here rather than in struct-declaration, in order to
2172 describe the syntax with extra semicolons and missing semicolon at
2177 struct-declaration-list:
2178 @defs ( class-name )
2180 (Note this does not include a trailing semicolon, but can be
2181 followed by further declarations, and gets a pedwarn-if-pedantic
2182 when followed by a semicolon.) */
2184 static struct c_typespec
2185 c_parser_struct_or_union_specifier (c_parser *parser)
2187 struct c_typespec ret;
2189 tree ident = NULL_TREE;
2190 location_t struct_loc;
2191 location_t ident_loc = UNKNOWN_LOCATION;
2192 enum tree_code code;
2193 switch (c_parser_peek_token (parser)->keyword)
2204 struct_loc = c_parser_peek_token (parser)->location;
2205 c_parser_consume_token (parser);
2206 attrs = c_parser_attributes (parser);
2208 /* Set the location in case we create a decl now. */
2209 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2211 if (c_parser_next_token_is (parser, CPP_NAME))
2213 ident = c_parser_peek_token (parser)->value;
2214 ident_loc = c_parser_peek_token (parser)->location;
2215 struct_loc = ident_loc;
2216 c_parser_consume_token (parser);
2218 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2220 /* Parse a struct or union definition. Start the scope of the
2221 tag before parsing components. */
2222 struct c_struct_parse_info *struct_info;
2223 tree type = start_struct (struct_loc, code, ident, &struct_info);
2225 /* We chain the components in reverse order, then put them in
2226 forward order at the end. Each struct-declaration may
2227 declare multiple components (comma-separated), so we must use
2228 chainon to join them, although when parsing each
2229 struct-declaration we can use TREE_CHAIN directly.
2231 The theory behind all this is that there will be more
2232 semicolon separated fields than comma separated fields, and
2233 so we'll be minimizing the number of node traversals required
2235 tree contents = NULL_TREE;
2236 c_parser_consume_token (parser);
2237 /* Handle the Objective-C @defs construct,
2238 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2239 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2242 gcc_assert (c_dialect_objc ());
2243 c_parser_consume_token (parser);
2244 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2246 if (c_parser_next_token_is (parser, CPP_NAME)
2247 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2249 name = c_parser_peek_token (parser)->value;
2250 c_parser_consume_token (parser);
2254 c_parser_error (parser, "expected class name");
2255 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2258 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2260 contents = nreverse (objc_get_class_ivars (name));
2263 /* Parse the struct-declarations and semicolons. Problems with
2264 semicolons are diagnosed here; empty structures are diagnosed
2269 /* Parse any stray semicolon. */
2270 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2272 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2273 "extra semicolon in struct or union specified");
2274 c_parser_consume_token (parser);
2277 /* Stop if at the end of the struct or union contents. */
2278 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2280 c_parser_consume_token (parser);
2283 /* Accept #pragmas at struct scope. */
2284 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2286 c_parser_pragma (parser, pragma_external);
2289 /* Parse some comma-separated declarations, but not the
2290 trailing semicolon if any. */
2291 decls = c_parser_struct_declaration (parser);
2292 contents = chainon (decls, contents);
2293 /* If no semicolon follows, either we have a parse error or
2294 are at the end of the struct or union and should
2296 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2297 c_parser_consume_token (parser);
2300 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2301 pedwarn (c_parser_peek_token (parser)->location, 0,
2302 "no semicolon at end of struct or union");
2305 c_parser_error (parser, "expected %<;%>");
2306 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2311 postfix_attrs = c_parser_attributes (parser);
2312 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2313 chainon (attrs, postfix_attrs), struct_info);
2314 ret.kind = ctsk_tagdef;
2315 ret.expr = NULL_TREE;
2316 ret.expr_const_operands = true;
2321 c_parser_error (parser, "expected %<{%>");
2322 ret.spec = error_mark_node;
2323 ret.kind = ctsk_tagref;
2324 ret.expr = NULL_TREE;
2325 ret.expr_const_operands = true;
2328 ret = parser_xref_tag (ident_loc, code, ident);
2332 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2333 the trailing semicolon.
2336 specifier-qualifier-list struct-declarator-list
2337 static_assert-declaration-no-semi
2339 specifier-qualifier-list:
2340 type-specifier specifier-qualifier-list[opt]
2341 type-qualifier specifier-qualifier-list[opt]
2342 attributes specifier-qualifier-list[opt]
2344 struct-declarator-list:
2346 struct-declarator-list , attributes[opt] struct-declarator
2349 declarator attributes[opt]
2350 declarator[opt] : constant-expression attributes[opt]
2355 __extension__ struct-declaration
2356 specifier-qualifier-list
2358 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2359 of attributes where shown is a GNU extension. In GNU C, we accept
2360 any expression without commas in the syntax (assignment
2361 expressions, not just conditional expressions); assignment
2362 expressions will be diagnosed as non-constant. */
2365 c_parser_struct_declaration (c_parser *parser)
2367 struct c_declspecs *specs;
2369 tree all_prefix_attrs;
2371 location_t decl_loc;
2372 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2376 ext = disable_extension_diagnostics ();
2377 c_parser_consume_token (parser);
2378 decl = c_parser_struct_declaration (parser);
2379 restore_extension_diagnostics (ext);
2382 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2384 c_parser_static_assert_declaration_no_semi (parser);
2387 specs = build_null_declspecs ();
2388 decl_loc = c_parser_peek_token (parser)->location;
2389 c_parser_declspecs (parser, specs, false, true, true);
2392 if (!specs->declspecs_seen_p)
2394 c_parser_error (parser, "expected specifier-qualifier-list");
2397 finish_declspecs (specs);
2398 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2401 if (!specs->type_seen_p)
2403 pedwarn (decl_loc, OPT_pedantic,
2404 "ISO C forbids member declarations with no members");
2405 shadow_tag_warned (specs, pedantic);
2410 /* Support for unnamed structs or unions as members of
2411 structs or unions (which is [a] useful and [b] supports
2415 ret = grokfield (c_parser_peek_token (parser)->location,
2416 build_id_declarator (NULL_TREE), specs,
2419 decl_attributes (&ret, attrs, 0);
2423 pending_xref_error ();
2424 prefix_attrs = specs->attrs;
2425 all_prefix_attrs = prefix_attrs;
2426 specs->attrs = NULL_TREE;
2430 /* Declaring one or more declarators or un-named bit-fields. */
2431 struct c_declarator *declarator;
2433 if (c_parser_next_token_is (parser, CPP_COLON))
2434 declarator = build_id_declarator (NULL_TREE);
2436 declarator = c_parser_declarator (parser, specs->type_seen_p,
2437 C_DTR_NORMAL, &dummy);
2438 if (declarator == NULL)
2440 c_parser_skip_to_end_of_block_or_statement (parser);
2443 if (c_parser_next_token_is (parser, CPP_COLON)
2444 || c_parser_next_token_is (parser, CPP_COMMA)
2445 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2446 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2447 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2449 tree postfix_attrs = NULL_TREE;
2450 tree width = NULL_TREE;
2452 if (c_parser_next_token_is (parser, CPP_COLON))
2454 c_parser_consume_token (parser);
2455 width = c_parser_expr_no_commas (parser, NULL).value;
2457 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2458 postfix_attrs = c_parser_attributes (parser);
2459 d = grokfield (c_parser_peek_token (parser)->location,
2460 declarator, specs, width, &all_prefix_attrs);
2461 decl_attributes (&d, chainon (postfix_attrs,
2462 all_prefix_attrs), 0);
2463 DECL_CHAIN (d) = decls;
2465 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2466 all_prefix_attrs = chainon (c_parser_attributes (parser),
2469 all_prefix_attrs = prefix_attrs;
2470 if (c_parser_next_token_is (parser, CPP_COMMA))
2471 c_parser_consume_token (parser);
2472 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2473 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2475 /* Semicolon consumed in caller. */
2480 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2486 c_parser_error (parser,
2487 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2488 "%<__attribute__%>");
2495 /* Parse a typeof specifier (a GNU extension).
2498 typeof ( expression )
2499 typeof ( type-name )
2502 static struct c_typespec
2503 c_parser_typeof_specifier (c_parser *parser)
2505 struct c_typespec ret;
2506 ret.kind = ctsk_typeof;
2507 ret.spec = error_mark_node;
2508 ret.expr = NULL_TREE;
2509 ret.expr_const_operands = true;
2510 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2511 c_parser_consume_token (parser);
2512 c_inhibit_evaluation_warnings++;
2514 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2516 c_inhibit_evaluation_warnings--;
2520 if (c_parser_next_token_starts_typename (parser))
2522 struct c_type_name *type = c_parser_type_name (parser);
2523 c_inhibit_evaluation_warnings--;
2527 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2528 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2534 location_t here = c_parser_peek_token (parser)->location;
2535 struct c_expr expr = c_parser_expression (parser);
2536 c_inhibit_evaluation_warnings--;
2538 if (TREE_CODE (expr.value) == COMPONENT_REF
2539 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2540 error_at (here, "%<typeof%> applied to a bit-field");
2541 mark_exp_read (expr.value);
2542 ret.spec = TREE_TYPE (expr.value);
2543 if (c_dialect_objc()
2544 && ret.spec != error_mark_node
2545 && lookup_attribute ("objc_volatilized", TYPE_ATTRIBUTES (ret.spec)))
2546 ret.spec = build_qualified_type
2547 (ret.spec, (TYPE_QUALS (ret.spec) & ~TYPE_QUAL_VOLATILE));
2548 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2549 /* This is returned with the type so that when the type is
2550 evaluated, this can be evaluated. */
2552 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2553 pop_maybe_used (was_vm);
2555 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2559 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2560 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2561 be redeclared; otherwise it may not. KIND indicates which kind of
2562 declarator is wanted. Returns a valid declarator except in the
2563 case of a syntax error in which case NULL is returned. *SEEN_ID is
2564 set to true if an identifier being declared is seen; this is used
2565 to diagnose bad forms of abstract array declarators and to
2566 determine whether an identifier list is syntactically permitted.
2569 pointer[opt] direct-declarator
2573 ( attributes[opt] declarator )
2574 direct-declarator array-declarator
2575 direct-declarator ( parameter-type-list )
2576 direct-declarator ( identifier-list[opt] )
2579 * type-qualifier-list[opt]
2580 * type-qualifier-list[opt] pointer
2582 type-qualifier-list:
2585 type-qualifier-list type-qualifier
2586 type-qualifier-list attributes
2588 parameter-type-list:
2590 parameter-list , ...
2593 parameter-declaration
2594 parameter-list , parameter-declaration
2596 parameter-declaration:
2597 declaration-specifiers declarator attributes[opt]
2598 declaration-specifiers abstract-declarator[opt] attributes[opt]
2602 identifier-list , identifier
2604 abstract-declarator:
2606 pointer[opt] direct-abstract-declarator
2608 direct-abstract-declarator:
2609 ( attributes[opt] abstract-declarator )
2610 direct-abstract-declarator[opt] array-declarator
2611 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2616 direct-declarator ( parameter-forward-declarations
2617 parameter-type-list[opt] )
2619 direct-abstract-declarator:
2620 direct-abstract-declarator[opt] ( parameter-forward-declarations
2621 parameter-type-list[opt] )
2623 parameter-forward-declarations:
2625 parameter-forward-declarations parameter-list ;
2627 The uses of attributes shown above are GNU extensions.
2629 Some forms of array declarator are not included in C99 in the
2630 syntax for abstract declarators; these are disallowed elsewhere.
2631 This may be a defect (DR#289).
2633 This function also accepts an omitted abstract declarator as being
2634 an abstract declarator, although not part of the formal syntax. */
2636 static struct c_declarator *
2637 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2640 /* Parse any initial pointer part. */
2641 if (c_parser_next_token_is (parser, CPP_MULT))
2643 struct c_declspecs *quals_attrs = build_null_declspecs ();
2644 struct c_declarator *inner;
2645 c_parser_consume_token (parser);
2646 c_parser_declspecs (parser, quals_attrs, false, false, true);
2647 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2651 return make_pointer_declarator (quals_attrs, inner);
2653 /* Now we have a direct declarator, direct abstract declarator or
2654 nothing (which counts as a direct abstract declarator here). */
2655 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2658 /* Parse a direct declarator or direct abstract declarator; arguments
2659 as c_parser_declarator. */
2661 static struct c_declarator *
2662 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2665 /* The direct declarator must start with an identifier (possibly
2666 omitted) or a parenthesized declarator (possibly abstract). In
2667 an ordinary declarator, initial parentheses must start a
2668 parenthesized declarator. In an abstract declarator or parameter
2669 declarator, they could start a parenthesized declarator or a
2670 parameter list. To tell which, the open parenthesis and any
2671 following attributes must be read. If a declaration specifier
2672 follows, then it is a parameter list; if the specifier is a
2673 typedef name, there might be an ambiguity about redeclaring it,
2674 which is resolved in the direction of treating it as a typedef
2675 name. If a close parenthesis follows, it is also an empty
2676 parameter list, as the syntax does not permit empty abstract
2677 declarators. Otherwise, it is a parenthesized declarator (in
2678 which case the analysis may be repeated inside it, recursively).
2680 ??? There is an ambiguity in a parameter declaration "int
2681 (__attribute__((foo)) x)", where x is not a typedef name: it
2682 could be an abstract declarator for a function, or declare x with
2683 parentheses. The proper resolution of this ambiguity needs
2684 documenting. At present we follow an accident of the old
2685 parser's implementation, whereby the first parameter must have
2686 some declaration specifiers other than just attributes. Thus as
2687 a parameter declaration it is treated as a parenthesized
2688 parameter named x, and as an abstract declarator it is
2691 ??? Also following the old parser, attributes inside an empty
2692 parameter list are ignored, making it a list not yielding a
2693 prototype, rather than giving an error or making it have one
2694 parameter with implicit type int.
2696 ??? Also following the old parser, typedef names may be
2697 redeclared in declarators, but not Objective-C class names. */
2699 if (kind != C_DTR_ABSTRACT
2700 && c_parser_next_token_is (parser, CPP_NAME)
2702 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2703 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2704 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2706 struct c_declarator *inner
2707 = build_id_declarator (c_parser_peek_token (parser)->value);
2709 inner->id_loc = c_parser_peek_token (parser)->location;
2710 c_parser_consume_token (parser);
2711 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2714 if (kind != C_DTR_NORMAL
2715 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2717 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2718 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2721 /* Either we are at the end of an abstract declarator, or we have
2724 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2727 struct c_declarator *inner;
2728 c_parser_consume_token (parser);
2729 attrs = c_parser_attributes (parser);
2730 if (kind != C_DTR_NORMAL
2731 && (c_parser_next_token_starts_declspecs (parser)
2732 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2734 struct c_arg_info *args
2735 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2742 = build_function_declarator (args,
2743 build_id_declarator (NULL_TREE));
2744 return c_parser_direct_declarator_inner (parser, *seen_id,
2748 /* A parenthesized declarator. */
2749 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2750 if (inner != NULL && attrs != NULL)
2751 inner = build_attrs_declarator (attrs, inner);
2752 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2754 c_parser_consume_token (parser);
2758 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2762 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2769 if (kind == C_DTR_NORMAL)
2771 c_parser_error (parser, "expected identifier or %<(%>");
2775 return build_id_declarator (NULL_TREE);
2779 /* Parse part of a direct declarator or direct abstract declarator,
2780 given that some (in INNER) has already been parsed; ID_PRESENT is
2781 true if an identifier is present, false for an abstract
2784 static struct c_declarator *
2785 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2786 struct c_declarator *inner)
2788 /* Parse a sequence of array declarators and parameter lists. */
2789 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2791 location_t brace_loc = c_parser_peek_token (parser)->location;
2792 struct c_declarator *declarator;
2793 struct c_declspecs *quals_attrs = build_null_declspecs ();
2797 c_parser_consume_token (parser);
2798 c_parser_declspecs (parser, quals_attrs, false, false, true);
2799 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2801 c_parser_consume_token (parser);
2802 if (static_seen && !quals_attrs->declspecs_seen_p)
2803 c_parser_declspecs (parser, quals_attrs, false, false, true);
2804 if (!quals_attrs->declspecs_seen_p)
2806 /* If "static" is present, there must be an array dimension.
2807 Otherwise, there may be a dimension, "*", or no
2812 dimen = c_parser_expr_no_commas (parser, NULL).value;
2816 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2821 else if (c_parser_next_token_is (parser, CPP_MULT))
2823 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2827 c_parser_consume_token (parser);
2832 dimen = c_parser_expr_no_commas (parser, NULL).value;
2838 dimen = c_parser_expr_no_commas (parser, NULL).value;
2841 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2842 c_parser_consume_token (parser);
2845 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2850 mark_exp_read (dimen);
2851 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2852 static_seen, star_seen);
2853 if (declarator == NULL)
2855 inner = set_array_declarator_inner (declarator, inner);
2856 return c_parser_direct_declarator_inner (parser, id_present, inner);
2858 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2861 struct c_arg_info *args;
2862 c_parser_consume_token (parser);
2863 attrs = c_parser_attributes (parser);
2864 args = c_parser_parms_declarator (parser, id_present, attrs);
2869 inner = build_function_declarator (args, inner);
2870 return c_parser_direct_declarator_inner (parser, id_present, inner);
2876 /* Parse a parameter list or identifier list, including the closing
2877 parenthesis but not the opening one. ATTRS are the attributes at
2878 the start of the list. ID_LIST_OK is true if an identifier list is
2879 acceptable; such a list must not have attributes at the start. */
2881 static struct c_arg_info *
2882 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2885 declare_parm_level ();
2886 /* If the list starts with an identifier, it is an identifier list.
2887 Otherwise, it is either a prototype list or an empty list. */
2890 && c_parser_next_token_is (parser, CPP_NAME)
2891 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2893 tree list = NULL_TREE, *nextp = &list;
2894 while (c_parser_next_token_is (parser, CPP_NAME)
2895 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2897 *nextp = build_tree_list (NULL_TREE,
2898 c_parser_peek_token (parser)->value);
2899 nextp = & TREE_CHAIN (*nextp);
2900 c_parser_consume_token (parser);
2901 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2903 c_parser_consume_token (parser);
2904 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2906 c_parser_error (parser, "expected identifier");
2910 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2912 struct c_arg_info *ret = build_arg_info ();
2914 c_parser_consume_token (parser);
2920 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2928 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2934 /* Parse a parameter list (possibly empty), including the closing
2935 parenthesis but not the opening one. ATTRS are the attributes at
2936 the start of the list. */
2938 static struct c_arg_info *
2939 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2941 bool bad_parm = false;
2942 /* ??? Following the old parser, forward parameter declarations may
2943 use abstract declarators, and if no real parameter declarations
2944 follow the forward declarations then this is not diagnosed. Also
2945 note as above that attributes are ignored as the only contents of
2946 the parentheses, or as the only contents after forward
2948 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2950 struct c_arg_info *ret = build_arg_info ();
2951 c_parser_consume_token (parser);
2954 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2956 struct c_arg_info *ret = build_arg_info ();
2957 /* Suppress -Wold-style-definition for this case. */
2958 ret->types = error_mark_node;
2959 error_at (c_parser_peek_token (parser)->location,
2960 "ISO C requires a named argument before %<...%>");
2961 c_parser_consume_token (parser);
2962 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2964 c_parser_consume_token (parser);
2969 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2974 /* Nonempty list of parameters, either terminated with semicolon
2975 (forward declarations; recurse) or with close parenthesis (normal
2976 function) or with ", ... )" (variadic function). */
2979 /* Parse a parameter. */
2980 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2985 push_parm_decl (parm);
2986 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2989 c_parser_consume_token (parser);
2990 mark_forward_parm_decls ();
2991 new_attrs = c_parser_attributes (parser);
2992 return c_parser_parms_list_declarator (parser, new_attrs);
2994 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2996 c_parser_consume_token (parser);
2999 get_pending_sizes ();
3003 return get_parm_info (false);
3005 if (!c_parser_require (parser, CPP_COMMA,
3006 "expected %<;%>, %<,%> or %<)%>"))
3008 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3009 get_pending_sizes ();
3012 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3014 c_parser_consume_token (parser);
3015 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3017 c_parser_consume_token (parser);
3020 get_pending_sizes ();
3024 return get_parm_info (true);
3028 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3030 get_pending_sizes ();
3037 /* Parse a parameter declaration. ATTRS are the attributes at the
3038 start of the declaration if it is the first parameter. */
3040 static struct c_parm *
3041 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3043 struct c_declspecs *specs;
3044 struct c_declarator *declarator;
3046 tree postfix_attrs = NULL_TREE;
3048 if (!c_parser_next_token_starts_declspecs (parser))
3050 c_token *token = c_parser_peek_token (parser);
3053 c_parser_set_source_position_from_token (token);
3054 if (token->type == CPP_NAME
3055 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
3056 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
3058 error ("unknown type name %qE", token->value);
3059 parser->error = true;
3061 /* ??? In some Objective-C cases '...' isn't applicable so there
3062 should be a different message. */
3064 c_parser_error (parser,
3065 "expected declaration specifiers or %<...%>");
3066 c_parser_skip_to_end_of_parameter (parser);
3069 specs = build_null_declspecs ();
3072 declspecs_add_attrs (specs, attrs);
3075 c_parser_declspecs (parser, specs, true, true, true);
3076 finish_declspecs (specs);
3077 pending_xref_error ();
3078 prefix_attrs = specs->attrs;
3079 specs->attrs = NULL_TREE;
3080 declarator = c_parser_declarator (parser, specs->type_seen_p,
3081 C_DTR_PARM, &dummy);
3082 if (declarator == NULL)
3084 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3087 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3088 postfix_attrs = c_parser_attributes (parser);
3089 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3093 /* Parse a string literal in an asm expression. It should not be
3094 translated, and wide string literals are an error although
3095 permitted by the syntax. This is a GNU extension.
3100 ??? At present, following the old parser, the caller needs to have
3101 set lex_untranslated_string to 1. It would be better to follow the
3102 C++ parser rather than using this kludge. */
3105 c_parser_asm_string_literal (c_parser *parser)
3108 if (c_parser_next_token_is (parser, CPP_STRING))
3110 str = c_parser_peek_token (parser)->value;
3111 c_parser_consume_token (parser);
3113 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3115 error_at (c_parser_peek_token (parser)->location,
3116 "wide string literal in %<asm%>");
3117 str = build_string (1, "");
3118 c_parser_consume_token (parser);
3122 c_parser_error (parser, "expected string literal");
3128 /* Parse a simple asm expression. This is used in restricted
3129 contexts, where a full expression with inputs and outputs does not
3130 make sense. This is a GNU extension.
3133 asm ( asm-string-literal )
3137 c_parser_simple_asm_expr (c_parser *parser)
3140 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3141 /* ??? Follow the C++ parser rather than using the
3142 lex_untranslated_string kludge. */
3143 parser->lex_untranslated_string = true;
3144 c_parser_consume_token (parser);
3145 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3147 parser->lex_untranslated_string = false;
3150 str = c_parser_asm_string_literal (parser);
3151 parser->lex_untranslated_string = false;
3152 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3160 /* Parse (possibly empty) attributes. This is a GNU extension.
3164 attributes attribute
3167 __attribute__ ( ( attribute-list ) )
3171 attribute_list , attrib
3176 any-word ( identifier )
3177 any-word ( identifier , nonempty-expr-list )
3178 any-word ( expr-list )
3180 where the "identifier" must not be declared as a type, and
3181 "any-word" may be any identifier (including one declared as a
3182 type), a reserved word storage class specifier, type specifier or
3183 type qualifier. ??? This still leaves out most reserved keywords
3184 (following the old parser), shouldn't we include them, and why not
3185 allow identifiers declared as types to start the arguments? */
3188 c_parser_attributes (c_parser *parser)
3190 tree attrs = NULL_TREE;
3191 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3193 /* ??? Follow the C++ parser rather than using the
3194 lex_untranslated_string kludge. */
3195 parser->lex_untranslated_string = true;
3196 c_parser_consume_token (parser);
3197 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3199 parser->lex_untranslated_string = false;
3202 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3204 parser->lex_untranslated_string = false;
3205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3208 /* Parse the attribute list. */
3209 while (c_parser_next_token_is (parser, CPP_COMMA)
3210 || c_parser_next_token_is (parser, CPP_NAME)
3211 || c_parser_next_token_is (parser, CPP_KEYWORD))
3213 tree attr, attr_name, attr_args;
3214 VEC(tree,gc) *expr_list;
3215 if (c_parser_next_token_is (parser, CPP_COMMA))
3217 c_parser_consume_token (parser);
3220 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3222 /* ??? See comment above about what keywords are
3225 switch (c_parser_peek_token (parser)->keyword)
3263 /* Accept __attribute__((__const)) as __attribute__((const))
3266 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3269 attr_name = c_parser_peek_token (parser)->value;
3270 c_parser_consume_token (parser);
3271 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3273 attr = build_tree_list (attr_name, NULL_TREE);
3274 attrs = chainon (attrs, attr);
3277 c_parser_consume_token (parser);
3278 /* Parse the attribute contents. If they start with an
3279 identifier which is followed by a comma or close
3280 parenthesis, then the arguments start with that
3281 identifier; otherwise they are an expression list. */
3282 if (c_parser_next_token_is (parser, CPP_NAME)
3283 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3284 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3285 || (c_parser_peek_2nd_token (parser)->type
3286 == CPP_CLOSE_PAREN)))
3288 tree arg1 = c_parser_peek_token (parser)->value;
3289 c_parser_consume_token (parser);
3290 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3291 attr_args = build_tree_list (NULL_TREE, arg1);
3295 c_parser_consume_token (parser);
3296 expr_list = c_parser_expr_list (parser, false, true, NULL);
3297 tree_list = build_tree_list_vec (expr_list);
3298 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3299 release_tree_vector (expr_list);
3304 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3305 attr_args = NULL_TREE;
3308 expr_list = c_parser_expr_list (parser, false, true, NULL);
3309 attr_args = build_tree_list_vec (expr_list);
3310 release_tree_vector (expr_list);
3313 attr = build_tree_list (attr_name, attr_args);
3314 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3315 c_parser_consume_token (parser);
3318 parser->lex_untranslated_string = false;
3319 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3323 attrs = chainon (attrs, attr);
3325 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3326 c_parser_consume_token (parser);
3329 parser->lex_untranslated_string = false;
3330 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3334 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3335 c_parser_consume_token (parser);
3338 parser->lex_untranslated_string = false;
3339 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3343 parser->lex_untranslated_string = false;
3348 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3351 specifier-qualifier-list abstract-declarator[opt]
3354 static struct c_type_name *
3355 c_parser_type_name (c_parser *parser)
3357 struct c_declspecs *specs = build_null_declspecs ();
3358 struct c_declarator *declarator;
3359 struct c_type_name *ret;
3361 c_parser_declspecs (parser, specs, false, true, true);
3362 if (!specs->declspecs_seen_p)
3364 c_parser_error (parser, "expected specifier-qualifier-list");
3367 pending_xref_error ();
3368 finish_declspecs (specs);
3369 declarator = c_parser_declarator (parser, specs->type_seen_p,
3370 C_DTR_ABSTRACT, &dummy);
3371 if (declarator == NULL)
3373 ret = XOBNEW (&parser_obstack, struct c_type_name);
3375 ret->declarator = declarator;
3379 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3382 assignment-expression
3383 { initializer-list }
3384 { initializer-list , }
3387 designation[opt] initializer
3388 initializer-list , designation[opt] initializer
3395 designator-list designator
3402 [ constant-expression ]
3414 [ constant-expression ... constant-expression ]
3416 Any expression without commas is accepted in the syntax for the
3417 constant-expressions, with non-constant expressions rejected later.
3419 This function is only used for top-level initializers; for nested
3420 ones, see c_parser_initval. */
3422 static struct c_expr
3423 c_parser_initializer (c_parser *parser)
3425 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3426 return c_parser_braced_init (parser, NULL_TREE, false);
3430 location_t loc = c_parser_peek_token (parser)->location;
3431 ret = c_parser_expr_no_commas (parser, NULL);
3432 if (TREE_CODE (ret.value) != STRING_CST
3433 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3434 ret = default_function_array_read_conversion (loc, ret);
3439 /* Parse a braced initializer list. TYPE is the type specified for a
3440 compound literal, and NULL_TREE for other initializers and for
3441 nested braced lists. NESTED_P is true for nested braced lists,
3442 false for the list of a compound literal or the list that is the
3443 top-level initializer in a declaration. */
3445 static struct c_expr
3446 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3449 struct obstack braced_init_obstack;
3450 location_t brace_loc = c_parser_peek_token (parser)->location;
3451 gcc_obstack_init (&braced_init_obstack);
3452 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3453 c_parser_consume_token (parser);
3455 push_init_level (0, &braced_init_obstack);
3457 really_start_incremental_init (type);
3458 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3460 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3464 /* Parse a non-empty initializer list, possibly with a trailing
3468 c_parser_initelt (parser, &braced_init_obstack);
3471 if (c_parser_next_token_is (parser, CPP_COMMA))
3472 c_parser_consume_token (parser);
3475 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3479 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3481 ret.value = error_mark_node;
3482 ret.original_code = ERROR_MARK;
3483 ret.original_type = NULL;
3484 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3485 pop_init_level (0, &braced_init_obstack);
3486 obstack_free (&braced_init_obstack, NULL);
3489 c_parser_consume_token (parser);
3490 ret = pop_init_level (0, &braced_init_obstack);
3491 obstack_free (&braced_init_obstack, NULL);
3495 /* Parse a nested initializer, including designators. */
3498 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3500 /* Parse any designator or designator list. A single array
3501 designator may have the subsequent "=" omitted in GNU C, but a
3502 longer list or a structure member designator may not. */
3503 if (c_parser_next_token_is (parser, CPP_NAME)
3504 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3506 /* Old-style structure member designator. */
3507 set_init_label (c_parser_peek_token (parser)->value,
3508 braced_init_obstack);
3509 /* Use the colon as the error location. */
3510 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3511 "obsolete use of designated initializer with %<:%>");
3512 c_parser_consume_token (parser);
3513 c_parser_consume_token (parser);
3517 /* des_seen is 0 if there have been no designators, 1 if there
3518 has been a single array designator and 2 otherwise. */
3520 /* Location of a designator. */
3521 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3522 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3523 || c_parser_next_token_is (parser, CPP_DOT))
3525 int des_prev = des_seen;
3527 des_loc = c_parser_peek_token (parser)->location;
3530 if (c_parser_next_token_is (parser, CPP_DOT))
3533 c_parser_consume_token (parser);
3534 if (c_parser_next_token_is (parser, CPP_NAME))
3536 set_init_label (c_parser_peek_token (parser)->value,
3537 braced_init_obstack);
3538 c_parser_consume_token (parser);
3543 init.value = error_mark_node;
3544 init.original_code = ERROR_MARK;
3545 init.original_type = NULL;
3546 c_parser_error (parser, "expected identifier");
3547 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3548 process_init_element (init, false, braced_init_obstack);
3555 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3556 /* ??? Following the old parser, [ objc-receiver
3557 objc-message-args ] is accepted as an initializer,
3558 being distinguished from a designator by what follows
3559 the first assignment expression inside the square
3560 brackets, but after a first array designator a
3561 subsequent square bracket is for Objective-C taken to
3562 start an expression, using the obsolete form of
3563 designated initializer without '=', rather than
3564 possibly being a second level of designation: in LALR
3565 terms, the '[' is shifted rather than reducing
3566 designator to designator-list. */
3567 if (des_prev == 1 && c_dialect_objc ())
3569 des_seen = des_prev;
3572 if (des_prev == 0 && c_dialect_objc ())
3574 /* This might be an array designator or an
3575 Objective-C message expression. If the former,
3576 continue parsing here; if the latter, parse the
3577 remainder of the initializer given the starting
3578 primary-expression. ??? It might make sense to
3579 distinguish when des_prev == 1 as well; see
3580 previous comment. */
3582 struct c_expr mexpr;
3583 c_parser_consume_token (parser);
3584 if (c_parser_peek_token (parser)->type == CPP_NAME
3585 && ((c_parser_peek_token (parser)->id_kind
3587 || (c_parser_peek_token (parser)->id_kind
3588 == C_ID_CLASSNAME)))
3590 /* Type name receiver. */
3591 tree id = c_parser_peek_token (parser)->value;
3592 c_parser_consume_token (parser);
3593 rec = objc_get_class_reference (id);
3594 goto parse_message_args;
3596 first = c_parser_expr_no_commas (parser, NULL).value;
3597 mark_exp_read (first);
3598 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3599 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3600 goto array_desig_after_first;
3601 /* Expression receiver. So far only one part
3602 without commas has been parsed; there might be
3603 more of the expression. */
3605 while (c_parser_next_token_is (parser, CPP_COMMA))
3608 location_t comma_loc, exp_loc;
3609 comma_loc = c_parser_peek_token (parser)->location;
3610 c_parser_consume_token (parser);
3611 exp_loc = c_parser_peek_token (parser)->location;
3612 next = c_parser_expr_no_commas (parser, NULL);
3613 next = default_function_array_read_conversion (exp_loc,
3615 rec = build_compound_expr (comma_loc, rec, next.value);
3618 /* Now parse the objc-message-args. */
3619 args = c_parser_objc_message_args (parser);
3620 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3623 = objc_build_message_expr (build_tree_list (rec, args));
3624 mexpr.original_code = ERROR_MARK;
3625 mexpr.original_type = NULL;
3626 /* Now parse and process the remainder of the
3627 initializer, starting with this message
3628 expression as a primary-expression. */
3629 c_parser_initval (parser, &mexpr, braced_init_obstack);
3632 c_parser_consume_token (parser);
3633 first = c_parser_expr_no_commas (parser, NULL).value;
3634 mark_exp_read (first);
3635 array_desig_after_first:
3636 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3638 ellipsis_loc = c_parser_peek_token (parser)->location;
3639 c_parser_consume_token (parser);
3640 second = c_parser_expr_no_commas (parser, NULL).value;
3641 mark_exp_read (second);
3645 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3647 c_parser_consume_token (parser);
3648 set_init_index (first, second, braced_init_obstack);
3650 pedwarn (ellipsis_loc, OPT_pedantic,
3651 "ISO C forbids specifying range of elements to initialize");
3654 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3660 if (c_parser_next_token_is (parser, CPP_EQ))
3663 pedwarn (des_loc, OPT_pedantic,
3664 "ISO C90 forbids specifying subobject to initialize");
3665 c_parser_consume_token (parser);
3670 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3671 "obsolete use of designated initializer without %<=%>");
3675 init.value = error_mark_node;
3676 init.original_code = ERROR_MARK;
3677 init.original_type = NULL;
3678 c_parser_error (parser, "expected %<=%>");
3679 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3680 process_init_element (init, false, braced_init_obstack);
3686 c_parser_initval (parser, NULL, braced_init_obstack);
3689 /* Parse a nested initializer; as c_parser_initializer but parses
3690 initializers within braced lists, after any designators have been
3691 applied. If AFTER is not NULL then it is an Objective-C message
3692 expression which is the primary-expression starting the
3696 c_parser_initval (c_parser *parser, struct c_expr *after,
3697 struct obstack * braced_init_obstack)
3700 gcc_assert (!after || c_dialect_objc ());
3701 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3702 init = c_parser_braced_init (parser, NULL_TREE, true);
3705 location_t loc = c_parser_peek_token (parser)->location;
3706 init = c_parser_expr_no_commas (parser, after);
3707 if (init.value != NULL_TREE
3708 && TREE_CODE (init.value) != STRING_CST
3709 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3710 init = default_function_array_read_conversion (loc, init);
3712 process_init_element (init, false, braced_init_obstack);
3715 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3719 { block-item-list[opt] }
3720 { label-declarations block-item-list }
3724 block-item-list block-item
3736 { label-declarations block-item-list }
3739 __extension__ nested-declaration
3740 nested-function-definition
3744 label-declarations label-declaration
3747 __label__ identifier-list ;
3749 Allowing the mixing of declarations and code is new in C99. The
3750 GNU syntax also permits (not shown above) labels at the end of
3751 compound statements, which yield an error. We don't allow labels
3752 on declarations; this might seem like a natural extension, but
3753 there would be a conflict between attributes on the label and
3754 prefix attributes on the declaration. ??? The syntax follows the
3755 old parser in requiring something after label declarations.
3756 Although they are erroneous if the labels declared aren't defined,
3757 is it useful for the syntax to be this way?
3769 c_parser_compound_statement (c_parser *parser)
3772 location_t brace_loc;
3773 brace_loc = c_parser_peek_token (parser)->location;
3774 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3776 /* Ensure a scope is entered and left anyway to avoid confusion
3777 if we have just prepared to enter a function body. */
3778 stmt = c_begin_compound_stmt (true);
3779 c_end_compound_stmt (brace_loc, stmt, true);
3780 return error_mark_node;
3782 stmt = c_begin_compound_stmt (true);
3783 c_parser_compound_statement_nostart (parser);
3784 return c_end_compound_stmt (brace_loc, stmt, true);
3787 /* Parse a compound statement except for the opening brace. This is
3788 used for parsing both compound statements and statement expressions
3789 (which follow different paths to handling the opening). */
3792 c_parser_compound_statement_nostart (c_parser *parser)
3794 bool last_stmt = false;
3795 bool last_label = false;
3796 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3797 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3798 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3800 c_parser_consume_token (parser);
3803 mark_valid_location_for_stdc_pragma (true);
3804 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3806 /* Read zero or more forward-declarations for labels that nested
3807 functions can jump to. */
3808 mark_valid_location_for_stdc_pragma (false);
3809 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3811 label_loc = c_parser_peek_token (parser)->location;
3812 c_parser_consume_token (parser);
3813 /* Any identifiers, including those declared as type names,
3818 if (c_parser_next_token_is_not (parser, CPP_NAME))
3820 c_parser_error (parser, "expected identifier");
3824 = declare_label (c_parser_peek_token (parser)->value);
3825 C_DECLARED_LABEL_FLAG (label) = 1;
3826 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3827 c_parser_consume_token (parser);
3828 if (c_parser_next_token_is (parser, CPP_COMMA))
3829 c_parser_consume_token (parser);
3833 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3835 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3837 /* We must now have at least one statement, label or declaration. */
3838 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3840 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3841 c_parser_error (parser, "expected declaration or statement");
3842 c_parser_consume_token (parser);
3845 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3847 location_t loc = c_parser_peek_token (parser)->location;
3848 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3849 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3850 || (c_parser_next_token_is (parser, CPP_NAME)
3851 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3853 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3854 label_loc = c_parser_peek_2nd_token (parser)->location;
3856 label_loc = c_parser_peek_token (parser)->location;
3859 mark_valid_location_for_stdc_pragma (false);
3860 c_parser_label (parser);
3862 else if (!last_label
3863 && c_parser_next_token_starts_declaration (parser))
3866 mark_valid_location_for_stdc_pragma (false);
3867 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
3870 (pedantic && !flag_isoc99)
3872 : OPT_Wdeclaration_after_statement,
3873 "ISO C90 forbids mixed declarations and code");
3876 else if (!last_label
3877 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3879 /* __extension__ can start a declaration, but is also an
3880 unary operator that can start an expression. Consume all
3881 but the last of a possible series of __extension__ to
3883 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3884 && (c_parser_peek_2nd_token (parser)->keyword
3886 c_parser_consume_token (parser);
3887 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3890 ext = disable_extension_diagnostics ();
3891 c_parser_consume_token (parser);
3893 mark_valid_location_for_stdc_pragma (false);
3894 c_parser_declaration_or_fndef (parser, true, true, true, true,
3896 /* Following the old parser, __extension__ does not
3897 disable this diagnostic. */
3898 restore_extension_diagnostics (ext);
3900 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3902 : OPT_Wdeclaration_after_statement,
3903 "ISO C90 forbids mixed declarations and code");
3909 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3911 /* External pragmas, and some omp pragmas, are not associated
3912 with regular c code, and so are not to be considered statements
3913 syntactically. This ensures that the user doesn't put them
3914 places that would turn into syntax errors if the directive
3916 if (c_parser_pragma (parser, pragma_compound))
3917 last_label = false, last_stmt = true;
3919 else if (c_parser_next_token_is (parser, CPP_EOF))
3921 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3922 c_parser_error (parser, "expected declaration or statement");
3925 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3927 if (parser->in_if_block)
3929 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3930 error_at (loc, """expected %<}%> before %<else%>");
3935 error_at (loc, "%<else%> without a previous %<if%>");
3936 c_parser_consume_token (parser);
3945 mark_valid_location_for_stdc_pragma (false);
3946 c_parser_statement_after_labels (parser);
3949 parser->error = false;
3952 error_at (label_loc, "label at end of compound statement");
3953 c_parser_consume_token (parser);
3954 /* Restore the value we started with. */
3955 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3958 /* Parse a label (C90 6.6.1, C99 6.8.1).
3961 identifier : attributes[opt]
3962 case constant-expression :
3968 case constant-expression ... constant-expression :
3970 The use of attributes on labels is a GNU extension. The syntax in
3971 GNU C accepts any expressions without commas, non-constant
3972 expressions being rejected later. */
3975 c_parser_label (c_parser *parser)
3977 location_t loc1 = c_parser_peek_token (parser)->location;
3978 tree label = NULL_TREE;
3979 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3982 c_parser_consume_token (parser);
3983 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3984 if (c_parser_next_token_is (parser, CPP_COLON))
3986 c_parser_consume_token (parser);
3987 label = do_case (loc1, exp1, NULL_TREE);
3989 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3991 c_parser_consume_token (parser);
3992 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3993 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3994 label = do_case (loc1, exp1, exp2);
3997 c_parser_error (parser, "expected %<:%> or %<...%>");
3999 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4001 c_parser_consume_token (parser);
4002 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4003 label = do_case (loc1, NULL_TREE, NULL_TREE);
4007 tree name = c_parser_peek_token (parser)->value;
4010 location_t loc2 = c_parser_peek_token (parser)->location;
4011 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4012 c_parser_consume_token (parser);
4013 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4014 c_parser_consume_token (parser);
4015 attrs = c_parser_attributes (parser);
4016 tlab = define_label (loc2, name);
4019 decl_attributes (&tlab, attrs, 0);
4020 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4025 if (c_parser_next_token_starts_declaration (parser)
4026 && !(c_parser_next_token_is (parser, CPP_NAME)
4027 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4029 error_at (c_parser_peek_token (parser)->location,
4030 "a label can only be part of a statement and "
4031 "a declaration is not a statement");
4032 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4033 /*static_assert_ok*/ true,
4034 /*nested*/ true, /*empty_ok*/ false,
4035 /*start_attr_ok*/ true, NULL);
4040 /* Parse a statement (C90 6.6, C99 6.8).
4045 expression-statement
4053 expression-statement:
4056 selection-statement:
4060 iteration-statement:
4069 return expression[opt] ;
4082 objc-throw-statement
4083 objc-try-catch-statement
4084 objc-synchronized-statement
4086 objc-throw-statement:
4100 parallel-for-construct
4101 parallel-sections-construct
4108 parallel-directive structured-block
4111 for-directive iteration-statement
4114 sections-directive section-scope
4117 single-directive structured-block
4119 parallel-for-construct:
4120 parallel-for-directive iteration-statement
4122 parallel-sections-construct:
4123 parallel-sections-directive section-scope
4126 master-directive structured-block
4129 critical-directive structured-block
4132 atomic-directive expression-statement
4135 ordered-directive structured-block */
4138 c_parser_statement (c_parser *parser)
4140 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4141 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4142 || (c_parser_next_token_is (parser, CPP_NAME)
4143 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4144 c_parser_label (parser);
4145 c_parser_statement_after_labels (parser);
4148 /* Parse a statement, other than a labeled statement. */
4151 c_parser_statement_after_labels (c_parser *parser)
4153 location_t loc = c_parser_peek_token (parser)->location;
4154 tree stmt = NULL_TREE;
4155 bool in_if_block = parser->in_if_block;
4156 parser->in_if_block = false;
4157 switch (c_parser_peek_token (parser)->type)
4159 case CPP_OPEN_BRACE:
4160 add_stmt (c_parser_compound_statement (parser));
4163 switch (c_parser_peek_token (parser)->keyword)
4166 c_parser_if_statement (parser);
4169 c_parser_switch_statement (parser);
4172 c_parser_while_statement (parser);
4175 c_parser_do_statement (parser);
4178 c_parser_for_statement (parser);
4181 c_parser_consume_token (parser);
4182 if (c_parser_next_token_is (parser, CPP_NAME))
4184 stmt = c_finish_goto_label (loc,
4185 c_parser_peek_token (parser)->value);
4186 c_parser_consume_token (parser);
4188 else if (c_parser_next_token_is (parser, CPP_MULT))
4192 c_parser_consume_token (parser);
4193 val = c_parser_expression (parser).value;
4194 mark_exp_read (val);
4195 stmt = c_finish_goto_ptr (loc, val);
4198 c_parser_error (parser, "expected identifier or %<*%>");
4199 goto expect_semicolon;
4201 c_parser_consume_token (parser);
4202 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4203 goto expect_semicolon;
4205 c_parser_consume_token (parser);
4206 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4207 goto expect_semicolon;
4209 c_parser_consume_token (parser);
4210 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4212 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4213 c_parser_consume_token (parser);
4217 struct c_expr expr = c_parser_expression_conv (parser);
4218 mark_exp_read (expr.value);
4219 stmt = c_finish_return (loc, expr.value, expr.original_type);
4220 goto expect_semicolon;
4224 stmt = c_parser_asm_statement (parser);
4227 gcc_assert (c_dialect_objc ());
4228 c_parser_consume_token (parser);
4229 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4231 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4232 c_parser_consume_token (parser);
4236 tree expr = c_parser_expression (parser).value;
4237 expr = c_fully_fold (expr, false, NULL);
4238 stmt = objc_build_throw_stmt (loc, expr);
4239 goto expect_semicolon;
4243 gcc_assert (c_dialect_objc ());
4244 c_parser_objc_try_catch_statement (parser);
4246 case RID_AT_SYNCHRONIZED:
4247 gcc_assert (c_dialect_objc ());
4248 c_parser_objc_synchronized_statement (parser);
4255 c_parser_consume_token (parser);
4257 case CPP_CLOSE_PAREN:
4258 case CPP_CLOSE_SQUARE:
4259 /* Avoid infinite loop in error recovery:
4260 c_parser_skip_until_found stops at a closing nesting
4261 delimiter without consuming it, but here we need to consume
4262 it to proceed further. */
4263 c_parser_error (parser, "expected statement");
4264 c_parser_consume_token (parser);
4267 c_parser_pragma (parser, pragma_stmt);
4271 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4273 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4276 /* Two cases cannot and do not have line numbers associated: If stmt
4277 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4278 cannot hold line numbers. But that's OK because the statement
4279 will either be changed to a MODIFY_EXPR during gimplification of
4280 the statement expr, or discarded. If stmt was compound, but
4281 without new variables, we will have skipped the creation of a
4282 BIND and will have a bare STATEMENT_LIST. But that's OK because
4283 (recursively) all of the component statements should already have
4284 line numbers assigned. ??? Can we discard no-op statements
4286 if (CAN_HAVE_LOCATION_P (stmt)
4287 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4288 SET_EXPR_LOCATION (stmt, loc);
4290 parser->in_if_block = in_if_block;
4293 /* Parse the condition from an if, do, while or for statements. */
4296 c_parser_condition (c_parser *parser)
4298 location_t loc = c_parser_peek_token (parser)->location;
4300 cond = c_parser_expression_conv (parser).value;
4301 cond = c_objc_common_truthvalue_conversion (loc, cond);
4302 cond = c_fully_fold (cond, false, NULL);
4303 if (warn_sequence_point)
4304 verify_sequence_points (cond);
4308 /* Parse a parenthesized condition from an if, do or while statement.
4314 c_parser_paren_condition (c_parser *parser)
4317 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4318 return error_mark_node;
4319 cond = c_parser_condition (parser);
4320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4324 /* Parse a statement which is a block in C99. */
4327 c_parser_c99_block_statement (c_parser *parser)
4329 tree block = c_begin_compound_stmt (flag_isoc99);
4330 location_t loc = c_parser_peek_token (parser)->location;
4331 c_parser_statement (parser);
4332 return c_end_compound_stmt (loc, block, flag_isoc99);
4335 /* Parse the body of an if statement. This is just parsing a
4336 statement but (a) it is a block in C99, (b) we track whether the
4337 body is an if statement for the sake of -Wparentheses warnings, (c)
4338 we handle an empty body specially for the sake of -Wempty-body
4339 warnings, and (d) we call parser_compound_statement directly
4340 because c_parser_statement_after_labels resets
4341 parser->in_if_block. */
4344 c_parser_if_body (c_parser *parser, bool *if_p)
4346 tree block = c_begin_compound_stmt (flag_isoc99);
4347 location_t body_loc = c_parser_peek_token (parser)->location;
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_p = c_parser_next_token_is_keyword (parser, RID_IF);
4354 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4356 location_t loc = c_parser_peek_token (parser)->location;
4357 add_stmt (build_empty_stmt (loc));
4358 c_parser_consume_token (parser);
4359 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4360 warning_at (loc, OPT_Wempty_body,
4361 "suggest braces around empty body in an %<if%> statement");
4363 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4364 add_stmt (c_parser_compound_statement (parser));
4366 c_parser_statement_after_labels (parser);
4367 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4370 /* Parse the else body of an if statement. This is just parsing a
4371 statement but (a) it is a block in C99, (b) we handle an empty body
4372 specially for the sake of -Wempty-body warnings. */
4375 c_parser_else_body (c_parser *parser)
4377 location_t else_loc = c_parser_peek_token (parser)->location;
4378 tree block = c_begin_compound_stmt (flag_isoc99);
4379 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4380 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4381 || (c_parser_next_token_is (parser, CPP_NAME)
4382 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4383 c_parser_label (parser);
4384 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4386 location_t loc = c_parser_peek_token (parser)->location;
4389 "suggest braces around empty body in an %<else%> statement");
4390 add_stmt (build_empty_stmt (loc));
4391 c_parser_consume_token (parser);
4394 c_parser_statement_after_labels (parser);
4395 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4398 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4401 if ( expression ) statement
4402 if ( expression ) statement else statement
4406 c_parser_if_statement (c_parser *parser)
4411 bool first_if = false;
4412 tree first_body, second_body;
4415 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4416 c_parser_consume_token (parser);
4417 block = c_begin_compound_stmt (flag_isoc99);
4418 loc = c_parser_peek_token (parser)->location;
4419 cond = c_parser_paren_condition (parser);
4420 in_if_block = parser->in_if_block;
4421 parser->in_if_block = true;
4422 first_body = c_parser_if_body (parser, &first_if);
4423 parser->in_if_block = in_if_block;
4424 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4426 c_parser_consume_token (parser);
4427 second_body = c_parser_else_body (parser);
4430 second_body = NULL_TREE;
4431 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4432 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4435 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4438 switch (expression) statement
4442 c_parser_switch_statement (c_parser *parser)
4444 tree block, expr, body, save_break;
4445 location_t switch_loc = c_parser_peek_token (parser)->location;
4446 location_t switch_cond_loc;
4447 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4448 c_parser_consume_token (parser);
4449 block = c_begin_compound_stmt (flag_isoc99);
4450 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4452 switch_cond_loc = c_parser_peek_token (parser)->location;
4453 expr = c_parser_expression (parser).value;
4454 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4458 switch_cond_loc = UNKNOWN_LOCATION;
4459 expr = error_mark_node;
4461 c_start_case (switch_loc, switch_cond_loc, expr);
4462 save_break = c_break_label;
4463 c_break_label = NULL_TREE;
4464 body = c_parser_c99_block_statement (parser);
4465 c_finish_case (body);
4468 location_t here = c_parser_peek_token (parser)->location;
4469 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4470 SET_EXPR_LOCATION (t, here);
4473 c_break_label = save_break;
4474 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4477 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4480 while (expression) statement
4484 c_parser_while_statement (c_parser *parser)
4486 tree block, cond, body, save_break, save_cont;
4488 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4489 c_parser_consume_token (parser);
4490 block = c_begin_compound_stmt (flag_isoc99);
4491 loc = c_parser_peek_token (parser)->location;
4492 cond = c_parser_paren_condition (parser);
4493 save_break = c_break_label;
4494 c_break_label = NULL_TREE;
4495 save_cont = c_cont_label;
4496 c_cont_label = NULL_TREE;
4497 body = c_parser_c99_block_statement (parser);
4498 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4499 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4500 c_break_label = save_break;
4501 c_cont_label = save_cont;
4504 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4507 do statement while ( expression ) ;
4511 c_parser_do_statement (c_parser *parser)
4513 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4515 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4516 c_parser_consume_token (parser);
4517 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4518 warning_at (c_parser_peek_token (parser)->location,
4520 "suggest braces around empty body in %<do%> statement");
4521 block = c_begin_compound_stmt (flag_isoc99);
4522 loc = c_parser_peek_token (parser)->location;
4523 save_break = c_break_label;
4524 c_break_label = NULL_TREE;
4525 save_cont = c_cont_label;
4526 c_cont_label = NULL_TREE;
4527 body = c_parser_c99_block_statement (parser);
4528 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4529 new_break = c_break_label;
4530 c_break_label = save_break;
4531 new_cont = c_cont_label;
4532 c_cont_label = save_cont;
4533 cond = c_parser_paren_condition (parser);
4534 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4535 c_parser_skip_to_end_of_block_or_statement (parser);
4536 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4537 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4540 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4543 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4544 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4546 The form with a declaration is new in C99.
4548 ??? In accordance with the old parser, the declaration may be a
4549 nested function, which is then rejected in check_for_loop_decls,
4550 but does it make any sense for this to be included in the grammar?
4551 Note in particular that the nested function does not include a
4552 trailing ';', whereas the "declaration" production includes one.
4553 Also, can we reject bad declarations earlier and cheaper than
4554 check_for_loop_decls?
4556 In Objective-C, there are two additional variants:
4559 for ( expression in expresssion ) statement
4560 for ( declaration in expression ) statement
4562 This is inconsistent with C, because the second variant is allowed
4563 even if c99 is not enabled.
4565 The rest of the comment documents these Objective-C foreach-statement.
4567 Here is the canonical example of the first variant:
4568 for (object in array) { do something with object }
4569 we call the first expression ("object") the "object_expression" and
4570 the second expression ("array") the "collection_expression".
4571 object_expression must be an lvalue of type "id" (a generic Objective-C
4572 object) because the loop works by assigning to object_expression the
4573 various objects from the collection_expression. collection_expression
4574 must evaluate to something of type "id" which responds to the method
4575 countByEnumeratingWithState:objects:count:.
4577 The canonical example of the second variant is:
4578 for (id object in array) { do something with object }
4579 which is completely equivalent to
4582 for (object in array) { do something with object }
4584 Note that initizializing 'object' in some way (eg, "for ((object =
4585 xxx) in array) { do something with object }") is possibly
4586 technically valid, but completely pointless as 'object' will be
4587 assigned to something else as soon as the loop starts. We should
4588 most likely reject it (TODO).
4590 The beginning of the Objective-C foreach-statement looks exactly
4591 like the beginning of the for-statement, and we can tell it is a
4592 foreach-statement only because the initial declaration or
4593 expression is terminated by 'in' instead of ';'.
4597 c_parser_for_statement (c_parser *parser)
4599 tree block, cond, incr, save_break, save_cont, body;
4600 /* The following are only used when parsing an ObjC foreach statement. */
4601 tree object_expression, collection_expression;
4602 location_t loc = c_parser_peek_token (parser)->location;
4603 location_t for_loc = c_parser_peek_token (parser)->location;
4604 bool is_foreach_statement = false;
4605 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4606 c_parser_consume_token (parser);
4607 /* Open a compound statement in Objective-C as well, just in case this is
4608 as foreach expression. */
4609 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4610 cond = error_mark_node;
4611 incr = error_mark_node;
4612 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4614 /* Parse the initialization declaration or expression. */
4615 object_expression = error_mark_node;
4616 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4618 c_parser_consume_token (parser);
4619 c_finish_expr_stmt (loc, NULL_TREE);
4621 else if (c_parser_next_token_starts_declaration (parser))
4623 parser->objc_could_be_foreach_context = true;
4624 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4625 &object_expression);
4626 parser->objc_could_be_foreach_context = false;
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);
4638 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4640 /* __extension__ can start a declaration, but is also an
4641 unary operator that can start an expression. Consume all
4642 but the last of a possible series of __extension__ to
4644 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4645 && (c_parser_peek_2nd_token (parser)->keyword
4647 c_parser_consume_token (parser);
4648 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4651 ext = disable_extension_diagnostics ();
4652 c_parser_consume_token (parser);
4653 parser->objc_could_be_foreach_context = true;
4654 c_parser_declaration_or_fndef (parser, true, true, true, true,
4655 true, &object_expression);
4656 parser->objc_could_be_foreach_context = false;
4658 restore_extension_diagnostics (ext);
4659 if (c_parser_next_token_is_keyword (parser, RID_IN))
4661 c_parser_consume_token (parser);
4662 is_foreach_statement = true;
4663 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4664 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4667 check_for_loop_decls (for_loc, flag_isoc99);
4676 tree init_expression;
4677 parser->objc_could_be_foreach_context = true;
4678 init_expression = c_parser_expression (parser).value;
4679 parser->objc_could_be_foreach_context = false;
4680 if (c_parser_next_token_is_keyword (parser, RID_IN))
4682 c_parser_consume_token (parser);
4683 is_foreach_statement = true;
4684 if (! lvalue_p (init_expression))
4685 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4686 object_expression = c_process_expr_stmt (loc, init_expression);
4691 c_finish_expr_stmt (loc, init_expression);
4692 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4696 /* Parse the loop condition. In the case of a foreach
4697 statement, there is no loop condition. */
4698 if (!is_foreach_statement)
4700 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4702 c_parser_consume_token (parser);
4707 cond = c_parser_condition (parser);
4708 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4711 /* Parse the increment expression (the third expression in a
4712 for-statement). In the case of a foreach-statement, this is
4713 the expression that follows the 'in'. */
4714 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4716 if (is_foreach_statement)
4718 c_parser_error (parser, "missing collection in fast enumeration");
4719 collection_expression = error_mark_node;
4722 incr = c_process_expr_stmt (loc, NULL_TREE);
4726 if (is_foreach_statement)
4727 collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4729 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4731 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4733 save_break = c_break_label;
4734 c_break_label = NULL_TREE;
4735 save_cont = c_cont_label;
4736 c_cont_label = NULL_TREE;
4737 body = c_parser_c99_block_statement (parser);
4738 if (is_foreach_statement)
4739 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4741 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4742 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4743 c_break_label = save_break;
4744 c_cont_label = save_cont;
4747 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4748 statement with inputs, outputs, clobbers, and volatile tag
4752 asm type-qualifier[opt] ( asm-argument ) ;
4753 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4757 asm-string-literal : asm-operands[opt]
4758 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4759 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4762 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4765 Qualifiers other than volatile are accepted in the syntax but
4769 c_parser_asm_statement (c_parser *parser)
4771 tree quals, str, outputs, inputs, clobbers, labels, ret;
4772 bool simple, is_goto;
4773 location_t asm_loc = c_parser_peek_token (parser)->location;
4774 int section, nsections;
4776 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4777 c_parser_consume_token (parser);
4778 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4780 quals = c_parser_peek_token (parser)->value;
4781 c_parser_consume_token (parser);
4783 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4784 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4786 warning_at (c_parser_peek_token (parser)->location,
4788 "%E qualifier ignored on asm",
4789 c_parser_peek_token (parser)->value);
4791 c_parser_consume_token (parser);
4797 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4799 c_parser_consume_token (parser);
4803 /* ??? Follow the C++ parser rather than using the
4804 lex_untranslated_string kludge. */
4805 parser->lex_untranslated_string = true;
4808 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4811 str = c_parser_asm_string_literal (parser);
4812 if (str == NULL_TREE)
4813 goto error_close_paren;
4816 outputs = NULL_TREE;
4818 clobbers = NULL_TREE;
4821 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4824 /* Parse each colon-delimited section of operands. */
4825 nsections = 3 + is_goto;
4826 for (section = 0; section < nsections; ++section)
4828 if (!c_parser_require (parser, CPP_COLON,
4831 : "expected %<:%> or %<)%>"))
4832 goto error_close_paren;
4834 /* Once past any colon, we're no longer a simple asm. */
4837 if ((!c_parser_next_token_is (parser, CPP_COLON)
4838 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4843 /* For asm goto, we don't allow output operands, but reserve
4844 the slot for a future extension that does allow them. */
4846 outputs = c_parser_asm_operands (parser, false);
4849 inputs = c_parser_asm_operands (parser, true);
4852 clobbers = c_parser_asm_clobbers (parser);
4855 labels = c_parser_asm_goto_operands (parser);
4861 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4866 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4868 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4872 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4873 c_parser_skip_to_end_of_block_or_statement (parser);
4875 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4876 clobbers, labels, simple));
4879 parser->lex_untranslated_string = false;
4883 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4887 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4888 not outputs), apply the default conversion of functions and arrays
4893 asm-operands , asm-operand
4896 asm-string-literal ( expression )
4897 [ identifier ] asm-string-literal ( expression )
4901 c_parser_asm_operands (c_parser *parser, bool convert_p)
4903 tree list = NULL_TREE;
4909 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4911 c_parser_consume_token (parser);
4912 if (c_parser_next_token_is (parser, CPP_NAME))
4914 tree id = c_parser_peek_token (parser)->value;
4915 c_parser_consume_token (parser);
4916 name = build_string (IDENTIFIER_LENGTH (id),
4917 IDENTIFIER_POINTER (id));
4921 c_parser_error (parser, "expected identifier");
4922 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4925 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4930 str = c_parser_asm_string_literal (parser);
4931 if (str == NULL_TREE)
4933 parser->lex_untranslated_string = false;
4934 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4936 parser->lex_untranslated_string = true;
4939 loc = c_parser_peek_token (parser)->location;
4940 expr = c_parser_expression (parser);
4941 mark_exp_read (expr.value);
4943 expr = default_function_array_conversion (loc, expr);
4944 expr.value = c_fully_fold (expr.value, false, NULL);
4945 parser->lex_untranslated_string = true;
4946 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4948 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4951 list = chainon (list, build_tree_list (build_tree_list (name, str),
4953 if (c_parser_next_token_is (parser, CPP_COMMA))
4954 c_parser_consume_token (parser);
4961 /* Parse asm clobbers, a GNU extension.
4965 asm-clobbers , asm-string-literal
4969 c_parser_asm_clobbers (c_parser *parser)
4971 tree list = NULL_TREE;
4974 tree str = c_parser_asm_string_literal (parser);
4976 list = tree_cons (NULL_TREE, str, list);
4979 if (c_parser_next_token_is (parser, CPP_COMMA))
4980 c_parser_consume_token (parser);
4987 /* Parse asm goto labels, a GNU extension.
4991 asm-goto-operands , identifier
4995 c_parser_asm_goto_operands (c_parser *parser)
4997 tree list = NULL_TREE;
5002 if (c_parser_next_token_is (parser, CPP_NAME))
5004 c_token *tok = c_parser_peek_token (parser);
5006 label = lookup_label_for_goto (tok->location, name);
5007 c_parser_consume_token (parser);
5008 TREE_USED (label) = 1;
5012 c_parser_error (parser, "expected identifier");
5016 name = build_string (IDENTIFIER_LENGTH (name),
5017 IDENTIFIER_POINTER (name));
5018 list = tree_cons (name, label, list);
5019 if (c_parser_next_token_is (parser, CPP_COMMA))
5020 c_parser_consume_token (parser);
5022 return nreverse (list);
5026 /* Parse an expression other than a compound expression; that is, an
5027 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5028 NULL then it is an Objective-C message expression which is the
5029 primary-expression starting the expression as an initializer.
5031 assignment-expression:
5032 conditional-expression
5033 unary-expression assignment-operator assignment-expression
5035 assignment-operator: one of
5036 = *= /= %= += -= <<= >>= &= ^= |=
5038 In GNU C we accept any conditional expression on the LHS and
5039 diagnose the invalid lvalue rather than producing a syntax
5042 static struct c_expr
5043 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5045 struct c_expr lhs, rhs, ret;
5046 enum tree_code code;
5047 location_t op_location, exp_location;
5048 gcc_assert (!after || c_dialect_objc ());
5049 lhs = c_parser_conditional_expression (parser, after);
5050 op_location = c_parser_peek_token (parser)->location;
5051 switch (c_parser_peek_token (parser)->type)
5060 code = TRUNC_DIV_EXPR;
5063 code = TRUNC_MOD_EXPR;
5078 code = BIT_AND_EXPR;
5081 code = BIT_XOR_EXPR;
5084 code = BIT_IOR_EXPR;
5089 c_parser_consume_token (parser);
5090 exp_location = c_parser_peek_token (parser)->location;
5091 rhs = c_parser_expr_no_commas (parser, NULL);
5092 rhs = default_function_array_read_conversion (exp_location, rhs);
5093 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5094 code, exp_location, rhs.value,
5096 if (code == NOP_EXPR)
5097 ret.original_code = MODIFY_EXPR;
5100 TREE_NO_WARNING (ret.value) = 1;
5101 ret.original_code = ERROR_MARK;
5103 ret.original_type = NULL;
5107 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5108 is not NULL then it is an Objective-C message expression which is
5109 the primary-expression starting the expression as an initializer.
5111 conditional-expression:
5112 logical-OR-expression
5113 logical-OR-expression ? expression : conditional-expression
5117 conditional-expression:
5118 logical-OR-expression ? : conditional-expression
5121 static struct c_expr
5122 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5124 struct c_expr cond, exp1, exp2, ret;
5125 location_t cond_loc, colon_loc, middle_loc;
5127 gcc_assert (!after || c_dialect_objc ());
5129 cond = c_parser_binary_expression (parser, after);
5131 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5133 cond_loc = c_parser_peek_token (parser)->location;
5134 cond = default_function_array_read_conversion (cond_loc, cond);
5135 c_parser_consume_token (parser);
5136 if (c_parser_next_token_is (parser, CPP_COLON))
5138 tree eptype = NULL_TREE;
5140 middle_loc = c_parser_peek_token (parser)->location;
5141 pedwarn (middle_loc, OPT_pedantic,
5142 "ISO C forbids omitting the middle term of a ?: expression");
5143 warn_for_omitted_condop (middle_loc, cond.value);
5144 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5146 eptype = TREE_TYPE (cond.value);
5147 cond.value = TREE_OPERAND (cond.value, 0);
5149 /* Make sure first operand is calculated only once. */
5150 exp1.value = c_save_expr (default_conversion (cond.value));
5152 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5153 exp1.original_type = NULL;
5154 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5155 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5160 = c_objc_common_truthvalue_conversion
5161 (cond_loc, default_conversion (cond.value));
5162 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5163 exp1 = c_parser_expression_conv (parser);
5164 mark_exp_read (exp1.value);
5165 c_inhibit_evaluation_warnings +=
5166 ((cond.value == truthvalue_true_node)
5167 - (cond.value == truthvalue_false_node));
5170 colon_loc = c_parser_peek_token (parser)->location;
5171 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5173 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5174 ret.value = error_mark_node;
5175 ret.original_code = ERROR_MARK;
5176 ret.original_type = NULL;
5180 location_t exp2_loc = c_parser_peek_token (parser)->location;
5181 exp2 = c_parser_conditional_expression (parser, NULL);
5182 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5184 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5185 ret.value = build_conditional_expr (colon_loc, cond.value,
5186 cond.original_code == C_MAYBE_CONST_EXPR,
5187 exp1.value, exp1.original_type,
5188 exp2.value, exp2.original_type);
5189 ret.original_code = ERROR_MARK;
5190 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5191 ret.original_type = NULL;
5196 /* If both sides are enum type, the default conversion will have
5197 made the type of the result be an integer type. We want to
5198 remember the enum types we started with. */
5199 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5200 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5201 ret.original_type = ((t1 != error_mark_node
5202 && t2 != error_mark_node
5203 && (TYPE_MAIN_VARIANT (t1)
5204 == TYPE_MAIN_VARIANT (t2)))
5211 /* Parse a binary expression; that is, a logical-OR-expression (C90
5212 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5213 an Objective-C message expression which is the primary-expression
5214 starting the expression as an initializer.
5216 multiplicative-expression:
5218 multiplicative-expression * cast-expression
5219 multiplicative-expression / cast-expression
5220 multiplicative-expression % cast-expression
5222 additive-expression:
5223 multiplicative-expression
5224 additive-expression + multiplicative-expression
5225 additive-expression - multiplicative-expression
5229 shift-expression << additive-expression
5230 shift-expression >> additive-expression
5232 relational-expression:
5234 relational-expression < shift-expression
5235 relational-expression > shift-expression
5236 relational-expression <= shift-expression
5237 relational-expression >= shift-expression
5239 equality-expression:
5240 relational-expression
5241 equality-expression == relational-expression
5242 equality-expression != relational-expression
5246 AND-expression & equality-expression
5248 exclusive-OR-expression:
5250 exclusive-OR-expression ^ AND-expression
5252 inclusive-OR-expression:
5253 exclusive-OR-expression
5254 inclusive-OR-expression | exclusive-OR-expression
5256 logical-AND-expression:
5257 inclusive-OR-expression
5258 logical-AND-expression && inclusive-OR-expression
5260 logical-OR-expression:
5261 logical-AND-expression
5262 logical-OR-expression || logical-AND-expression
5265 static struct c_expr
5266 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5268 /* A binary expression is parsed using operator-precedence parsing,
5269 with the operands being cast expressions. All the binary
5270 operators are left-associative. Thus a binary expression is of
5273 E0 op1 E1 op2 E2 ...
5275 which we represent on a stack. On the stack, the precedence
5276 levels are strictly increasing. When a new operator is
5277 encountered of higher precedence than that at the top of the
5278 stack, it is pushed; its LHS is the top expression, and its RHS
5279 is everything parsed until it is popped. When a new operator is
5280 encountered with precedence less than or equal to that at the top
5281 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5282 by the result of the operation until the operator at the top of
5283 the stack has lower precedence than the new operator or there is
5284 only one element on the stack; then the top expression is the LHS
5285 of the new operator. In the case of logical AND and OR
5286 expressions, we also need to adjust c_inhibit_evaluation_warnings
5287 as appropriate when the operators are pushed and popped. */
5289 /* The precedence levels, where 0 is a dummy lowest level used for
5290 the bottom of the stack. */
5306 /* The expression at this stack level. */
5308 /* The precedence of the operator on its left, PREC_NONE at the
5309 bottom of the stack. */
5311 /* The operation on its left. */
5313 /* The source location of this operation. */
5317 /* Location of the binary operator. */
5318 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5321 switch (stack[sp].op) \
5323 case TRUTH_ANDIF_EXPR: \
5324 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5325 == truthvalue_false_node); \
5327 case TRUTH_ORIF_EXPR: \
5328 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5329 == truthvalue_true_node); \
5334 stack[sp - 1].expr \
5335 = default_function_array_read_conversion (stack[sp - 1].loc, \
5336 stack[sp - 1].expr); \
5338 = default_function_array_read_conversion (stack[sp].loc, \
5340 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5342 stack[sp - 1].expr, \
5346 gcc_assert (!after || c_dialect_objc ());
5347 stack[0].loc = c_parser_peek_token (parser)->location;
5348 stack[0].expr = c_parser_cast_expression (parser, after);
5349 stack[0].prec = PREC_NONE;
5354 enum tree_code ocode;
5357 switch (c_parser_peek_token (parser)->type)
5365 ocode = TRUNC_DIV_EXPR;
5369 ocode = TRUNC_MOD_EXPR;
5381 ocode = LSHIFT_EXPR;
5385 ocode = RSHIFT_EXPR;
5399 case CPP_GREATER_EQ:
5412 oprec = PREC_BITAND;
5413 ocode = BIT_AND_EXPR;
5416 oprec = PREC_BITXOR;
5417 ocode = BIT_XOR_EXPR;
5421 ocode = BIT_IOR_EXPR;
5424 oprec = PREC_LOGAND;
5425 ocode = TRUTH_ANDIF_EXPR;
5429 ocode = TRUTH_ORIF_EXPR;
5432 /* Not a binary operator, so end of the binary
5436 binary_loc = c_parser_peek_token (parser)->location;
5437 c_parser_consume_token (parser);
5438 while (oprec <= stack[sp].prec)
5442 case TRUTH_ANDIF_EXPR:
5444 = default_function_array_read_conversion (stack[sp].loc,
5446 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5447 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5448 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5449 == truthvalue_false_node);
5451 case TRUTH_ORIF_EXPR:
5453 = default_function_array_read_conversion (stack[sp].loc,
5455 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5456 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5457 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5458 == truthvalue_true_node);
5464 stack[sp].loc = binary_loc;
5465 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5466 stack[sp].prec = oprec;
5467 stack[sp].op = ocode;
5468 stack[sp].loc = binary_loc;
5473 return stack[0].expr;
5477 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5478 NULL then it is an Objective-C message expression which is the
5479 primary-expression starting the expression as an initializer.
5483 ( type-name ) unary-expression
5486 static struct c_expr
5487 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5489 location_t cast_loc = c_parser_peek_token (parser)->location;
5490 gcc_assert (!after || c_dialect_objc ());
5492 return c_parser_postfix_expression_after_primary (parser,
5494 /* If the expression begins with a parenthesized type name, it may
5495 be either a cast or a compound literal; we need to see whether
5496 the next character is '{' to tell the difference. If not, it is
5497 an unary expression. */
5498 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5499 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5501 struct c_type_name *type_name;
5504 c_parser_consume_token (parser);
5505 type_name = c_parser_type_name (parser);
5506 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5507 if (type_name == NULL)
5509 ret.value = error_mark_node;
5510 ret.original_code = ERROR_MARK;
5511 ret.original_type = NULL;
5515 /* Save casted types in the function's used types hash table. */
5516 used_types_insert (type_name->specs->type);
5518 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5519 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5522 location_t expr_loc = c_parser_peek_token (parser)->location;
5523 expr = c_parser_cast_expression (parser, NULL);
5524 expr = default_function_array_read_conversion (expr_loc, expr);
5526 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5527 ret.original_code = ERROR_MARK;
5528 ret.original_type = NULL;
5532 return c_parser_unary_expression (parser);
5535 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5541 unary-operator cast-expression
5542 sizeof unary-expression
5543 sizeof ( type-name )
5545 unary-operator: one of
5551 __alignof__ unary-expression
5552 __alignof__ ( type-name )
5555 unary-operator: one of
5556 __extension__ __real__ __imag__
5558 In addition, the GNU syntax treats ++ and -- as unary operators, so
5559 they may be applied to cast expressions with errors for non-lvalues
5562 static struct c_expr
5563 c_parser_unary_expression (c_parser *parser)
5566 struct c_expr ret, op;
5567 location_t op_loc = c_parser_peek_token (parser)->location;
5569 ret.original_code = ERROR_MARK;
5570 ret.original_type = NULL;
5571 switch (c_parser_peek_token (parser)->type)
5574 c_parser_consume_token (parser);
5575 exp_loc = c_parser_peek_token (parser)->location;
5576 op = c_parser_cast_expression (parser, NULL);
5577 op = default_function_array_read_conversion (exp_loc, op);
5578 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5579 case CPP_MINUS_MINUS:
5580 c_parser_consume_token (parser);
5581 exp_loc = c_parser_peek_token (parser)->location;
5582 op = c_parser_cast_expression (parser, NULL);
5583 op = default_function_array_read_conversion (exp_loc, op);
5584 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5586 c_parser_consume_token (parser);
5587 op = c_parser_cast_expression (parser, NULL);
5588 mark_exp_read (op.value);
5589 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5591 c_parser_consume_token (parser);
5592 exp_loc = c_parser_peek_token (parser)->location;
5593 op = c_parser_cast_expression (parser, NULL);
5594 op = default_function_array_read_conversion (exp_loc, op);
5595 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5598 if (!c_dialect_objc () && !in_system_header)
5601 "traditional C rejects the unary plus operator");
5602 c_parser_consume_token (parser);
5603 exp_loc = c_parser_peek_token (parser)->location;
5604 op = c_parser_cast_expression (parser, NULL);
5605 op = default_function_array_read_conversion (exp_loc, op);
5606 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5608 c_parser_consume_token (parser);
5609 exp_loc = c_parser_peek_token (parser)->location;
5610 op = c_parser_cast_expression (parser, NULL);
5611 op = default_function_array_read_conversion (exp_loc, op);
5612 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5614 c_parser_consume_token (parser);
5615 exp_loc = c_parser_peek_token (parser)->location;
5616 op = c_parser_cast_expression (parser, NULL);
5617 op = default_function_array_read_conversion (exp_loc, op);
5618 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5620 c_parser_consume_token (parser);
5621 exp_loc = c_parser_peek_token (parser)->location;
5622 op = c_parser_cast_expression (parser, NULL);
5623 op = default_function_array_read_conversion (exp_loc, op);
5624 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5626 /* Refer to the address of a label as a pointer. */
5627 c_parser_consume_token (parser);
5628 if (c_parser_next_token_is (parser, CPP_NAME))
5630 ret.value = finish_label_address_expr
5631 (c_parser_peek_token (parser)->value, op_loc);
5632 c_parser_consume_token (parser);
5636 c_parser_error (parser, "expected identifier");
5637 ret.value = error_mark_node;
5641 switch (c_parser_peek_token (parser)->keyword)
5644 return c_parser_sizeof_expression (parser);
5646 return c_parser_alignof_expression (parser);
5648 c_parser_consume_token (parser);
5649 ext = disable_extension_diagnostics ();
5650 ret = c_parser_cast_expression (parser, NULL);
5651 restore_extension_diagnostics (ext);
5654 c_parser_consume_token (parser);
5655 exp_loc = c_parser_peek_token (parser)->location;
5656 op = c_parser_cast_expression (parser, NULL);
5657 op = default_function_array_conversion (exp_loc, op);
5658 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5660 c_parser_consume_token (parser);
5661 exp_loc = c_parser_peek_token (parser)->location;
5662 op = c_parser_cast_expression (parser, NULL);
5663 op = default_function_array_conversion (exp_loc, op);
5664 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5666 return c_parser_postfix_expression (parser);
5669 return c_parser_postfix_expression (parser);
5673 /* Parse a sizeof expression. */
5675 static struct c_expr
5676 c_parser_sizeof_expression (c_parser *parser)
5679 location_t expr_loc;
5680 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5681 c_parser_consume_token (parser);
5682 c_inhibit_evaluation_warnings++;
5684 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5685 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5687 /* Either sizeof ( type-name ) or sizeof unary-expression
5688 starting with a compound literal. */
5689 struct c_type_name *type_name;
5690 c_parser_consume_token (parser);
5691 expr_loc = c_parser_peek_token (parser)->location;
5692 type_name = c_parser_type_name (parser);
5693 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5694 if (type_name == NULL)
5697 c_inhibit_evaluation_warnings--;
5699 ret.value = error_mark_node;
5700 ret.original_code = ERROR_MARK;
5701 ret.original_type = NULL;
5704 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5706 expr = c_parser_postfix_expression_after_paren_type (parser,
5711 /* sizeof ( type-name ). */
5712 c_inhibit_evaluation_warnings--;
5714 return c_expr_sizeof_type (expr_loc, type_name);
5718 expr_loc = c_parser_peek_token (parser)->location;
5719 expr = c_parser_unary_expression (parser);
5721 c_inhibit_evaluation_warnings--;
5723 mark_exp_read (expr.value);
5724 if (TREE_CODE (expr.value) == COMPONENT_REF
5725 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5726 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5727 return c_expr_sizeof_expr (expr_loc, expr);
5731 /* Parse an alignof expression. */
5733 static struct c_expr
5734 c_parser_alignof_expression (c_parser *parser)
5737 location_t loc = c_parser_peek_token (parser)->location;
5738 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5739 c_parser_consume_token (parser);
5740 c_inhibit_evaluation_warnings++;
5742 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5743 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5745 /* Either __alignof__ ( type-name ) or __alignof__
5746 unary-expression starting with a compound literal. */
5748 struct c_type_name *type_name;
5750 c_parser_consume_token (parser);
5751 loc = c_parser_peek_token (parser)->location;
5752 type_name = c_parser_type_name (parser);
5753 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5754 if (type_name == NULL)
5757 c_inhibit_evaluation_warnings--;
5759 ret.value = error_mark_node;
5760 ret.original_code = ERROR_MARK;
5761 ret.original_type = NULL;
5764 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5766 expr = c_parser_postfix_expression_after_paren_type (parser,
5771 /* alignof ( type-name ). */
5772 c_inhibit_evaluation_warnings--;
5774 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5775 ret.original_code = ERROR_MARK;
5776 ret.original_type = NULL;
5782 expr = c_parser_unary_expression (parser);
5784 mark_exp_read (expr.value);
5785 c_inhibit_evaluation_warnings--;
5787 ret.value = c_alignof_expr (loc, expr.value);
5788 ret.original_code = ERROR_MARK;
5789 ret.original_type = NULL;
5794 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5798 postfix-expression [ expression ]
5799 postfix-expression ( argument-expression-list[opt] )
5800 postfix-expression . identifier
5801 postfix-expression -> identifier
5802 postfix-expression ++
5803 postfix-expression --
5804 ( type-name ) { initializer-list }
5805 ( type-name ) { initializer-list , }
5807 argument-expression-list:
5809 argument-expression-list , argument-expression
5821 (treated as a keyword in GNU C)
5824 ( compound-statement )
5825 __builtin_va_arg ( assignment-expression , type-name )
5826 __builtin_offsetof ( type-name , offsetof-member-designator )
5827 __builtin_choose_expr ( assignment-expression ,
5828 assignment-expression ,
5829 assignment-expression )
5830 __builtin_types_compatible_p ( type-name , type-name )
5832 offsetof-member-designator:
5834 offsetof-member-designator . identifier
5835 offsetof-member-designator [ expression ]
5840 [ objc-receiver objc-message-args ]
5841 @selector ( objc-selector-arg )
5842 @protocol ( identifier )
5843 @encode ( type-name )
5845 Classname . identifier
5848 static struct c_expr
5849 c_parser_postfix_expression (c_parser *parser)
5851 struct c_expr expr, e1, e2, e3;
5852 struct c_type_name *t1, *t2;
5853 location_t loc = c_parser_peek_token (parser)->location;;
5854 expr.original_code = ERROR_MARK;
5855 expr.original_type = NULL;
5856 switch (c_parser_peek_token (parser)->type)
5859 expr.value = c_parser_peek_token (parser)->value;
5860 loc = c_parser_peek_token (parser)->location;
5861 c_parser_consume_token (parser);
5862 if (TREE_CODE (expr.value) == FIXED_CST
5863 && !targetm.fixed_point_supported_p ())
5865 error_at (loc, "fixed-point types not supported for this target");
5866 expr.value = error_mark_node;
5873 expr.value = c_parser_peek_token (parser)->value;
5874 c_parser_consume_token (parser);
5880 case CPP_UTF8STRING:
5881 expr.value = c_parser_peek_token (parser)->value;
5882 expr.original_code = STRING_CST;
5883 c_parser_consume_token (parser);
5885 case CPP_OBJC_STRING:
5886 gcc_assert (c_dialect_objc ());
5888 = objc_build_string_object (c_parser_peek_token (parser)->value);
5889 c_parser_consume_token (parser);
5892 switch (c_parser_peek_token (parser)->id_kind)
5896 tree id = c_parser_peek_token (parser)->value;
5897 c_parser_consume_token (parser);
5898 expr.value = build_external_ref (loc, id,
5899 (c_parser_peek_token (parser)->type
5901 &expr.original_type);
5904 case C_ID_CLASSNAME:
5906 /* Here we parse the Objective-C 2.0 Class.name dot
5908 tree class_name = c_parser_peek_token (parser)->value;
5910 c_parser_consume_token (parser);
5911 gcc_assert (c_dialect_objc ());
5912 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
5914 expr.value = error_mark_node;
5917 if (c_parser_next_token_is_not (parser, CPP_NAME))
5919 c_parser_error (parser, "expected identifier");
5920 expr.value = error_mark_node;
5923 component = c_parser_peek_token (parser)->value;
5924 c_parser_consume_token (parser);
5925 expr.value = objc_build_class_component_ref (class_name,
5930 c_parser_error (parser, "expected expression");
5931 expr.value = error_mark_node;
5935 case CPP_OPEN_PAREN:
5936 /* A parenthesized expression, statement expression or compound
5938 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5940 /* A statement expression. */
5942 location_t brace_loc;
5943 c_parser_consume_token (parser);
5944 brace_loc = c_parser_peek_token (parser)->location;
5945 c_parser_consume_token (parser);
5946 if (cur_stmt_list == NULL)
5948 error_at (loc, "braced-group within expression allowed "
5949 "only inside a function");
5950 parser->error = true;
5951 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5952 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5953 expr.value = error_mark_node;
5956 stmt = c_begin_stmt_expr ();
5957 c_parser_compound_statement_nostart (parser);
5958 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5960 pedwarn (loc, OPT_pedantic,
5961 "ISO C forbids braced-groups within expressions");
5962 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5963 mark_exp_read (expr.value);
5965 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5967 /* A compound literal. ??? Can we actually get here rather
5968 than going directly to
5969 c_parser_postfix_expression_after_paren_type from
5972 struct c_type_name *type_name;
5973 c_parser_consume_token (parser);
5974 loc = c_parser_peek_token (parser)->location;
5975 type_name = c_parser_type_name (parser);
5976 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5978 if (type_name == NULL)
5980 expr.value = error_mark_node;
5983 expr = c_parser_postfix_expression_after_paren_type (parser,
5989 /* A parenthesized expression. */
5990 c_parser_consume_token (parser);
5991 expr = c_parser_expression (parser);
5992 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5993 TREE_NO_WARNING (expr.value) = 1;
5994 if (expr.original_code != C_MAYBE_CONST_EXPR)
5995 expr.original_code = ERROR_MARK;
5996 /* Don't change EXPR.ORIGINAL_TYPE. */
5997 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6002 switch (c_parser_peek_token (parser)->keyword)
6004 case RID_FUNCTION_NAME:
6005 case RID_PRETTY_FUNCTION_NAME:
6006 case RID_C99_FUNCTION_NAME:
6007 expr.value = fname_decl (loc,
6008 c_parser_peek_token (parser)->keyword,
6009 c_parser_peek_token (parser)->value);
6010 c_parser_consume_token (parser);
6013 c_parser_consume_token (parser);
6014 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6016 expr.value = error_mark_node;
6019 e1 = c_parser_expr_no_commas (parser, NULL);
6020 mark_exp_read (e1.value);
6021 e1.value = c_fully_fold (e1.value, false, NULL);
6022 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6025 expr.value = error_mark_node;
6028 loc = c_parser_peek_token (parser)->location;
6029 t1 = c_parser_type_name (parser);
6030 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6034 expr.value = error_mark_node;
6038 tree type_expr = NULL_TREE;
6039 expr.value = c_build_va_arg (loc, e1.value,
6040 groktypename (t1, &type_expr, NULL));
6043 expr.value = build2 (C_MAYBE_CONST_EXPR,
6044 TREE_TYPE (expr.value), type_expr,
6046 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6051 c_parser_consume_token (parser);
6052 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6054 expr.value = error_mark_node;
6057 t1 = c_parser_type_name (parser);
6060 expr.value = error_mark_node;
6063 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6065 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6066 expr.value = error_mark_node;
6070 tree type = groktypename (t1, NULL, NULL);
6072 if (type == error_mark_node)
6073 offsetof_ref = error_mark_node;
6076 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6077 SET_EXPR_LOCATION (offsetof_ref, loc);
6079 /* Parse the second argument to __builtin_offsetof. We
6080 must have one identifier, and beyond that we want to
6081 accept sub structure and sub array references. */
6082 if (c_parser_next_token_is (parser, CPP_NAME))
6084 offsetof_ref = build_component_ref
6085 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6086 c_parser_consume_token (parser);
6087 while (c_parser_next_token_is (parser, CPP_DOT)
6088 || c_parser_next_token_is (parser,
6090 || c_parser_next_token_is (parser,
6093 if (c_parser_next_token_is (parser, CPP_DEREF))
6095 loc = c_parser_peek_token (parser)->location;
6096 offsetof_ref = build_array_ref (loc,
6101 else if (c_parser_next_token_is (parser, CPP_DOT))
6104 c_parser_consume_token (parser);
6105 if (c_parser_next_token_is_not (parser,
6108 c_parser_error (parser, "expected identifier");
6111 offsetof_ref = build_component_ref
6113 c_parser_peek_token (parser)->value);
6114 c_parser_consume_token (parser);
6119 loc = c_parser_peek_token (parser)->location;
6120 c_parser_consume_token (parser);
6121 idx = c_parser_expression (parser).value;
6122 idx = c_fully_fold (idx, false, NULL);
6123 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6125 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6130 c_parser_error (parser, "expected identifier");
6131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6133 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6136 case RID_CHOOSE_EXPR:
6137 c_parser_consume_token (parser);
6138 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6140 expr.value = error_mark_node;
6143 loc = c_parser_peek_token (parser)->location;
6144 e1 = c_parser_expr_no_commas (parser, NULL);
6145 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6147 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6148 expr.value = error_mark_node;
6151 e2 = c_parser_expr_no_commas (parser, NULL);
6152 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6155 expr.value = error_mark_node;
6158 e3 = c_parser_expr_no_commas (parser, NULL);
6159 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6165 mark_exp_read (e2.value);
6166 mark_exp_read (e3.value);
6167 if (TREE_CODE (c) != INTEGER_CST
6168 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6170 "first argument to %<__builtin_choose_expr%> not"
6172 constant_expression_warning (c);
6173 expr = integer_zerop (c) ? e3 : e2;
6176 case RID_TYPES_COMPATIBLE_P:
6177 c_parser_consume_token (parser);
6178 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6180 expr.value = error_mark_node;
6183 t1 = c_parser_type_name (parser);
6186 expr.value = error_mark_node;
6189 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6191 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6192 expr.value = error_mark_node;
6195 t2 = c_parser_type_name (parser);
6198 expr.value = error_mark_node;
6201 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6206 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6207 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6210 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6213 case RID_AT_SELECTOR:
6214 gcc_assert (c_dialect_objc ());
6215 c_parser_consume_token (parser);
6216 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6218 expr.value = error_mark_node;
6222 tree sel = c_parser_objc_selector_arg (parser);
6223 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6225 expr.value = objc_build_selector_expr (loc, sel);
6228 case RID_AT_PROTOCOL:
6229 gcc_assert (c_dialect_objc ());
6230 c_parser_consume_token (parser);
6231 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6233 expr.value = error_mark_node;
6236 if (c_parser_next_token_is_not (parser, CPP_NAME))
6238 c_parser_error (parser, "expected identifier");
6239 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6240 expr.value = error_mark_node;
6244 tree id = c_parser_peek_token (parser)->value;
6245 c_parser_consume_token (parser);
6246 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6248 expr.value = objc_build_protocol_expr (id);
6252 /* Extension to support C-structures in the archiver. */
6253 gcc_assert (c_dialect_objc ());
6254 c_parser_consume_token (parser);
6255 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6257 expr.value = error_mark_node;
6260 t1 = c_parser_type_name (parser);
6263 expr.value = error_mark_node;
6264 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6267 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6270 tree type = groktypename (t1, NULL, NULL);
6271 expr.value = objc_build_encode_expr (type);
6275 c_parser_error (parser, "expected expression");
6276 expr.value = error_mark_node;
6280 case CPP_OPEN_SQUARE:
6281 if (c_dialect_objc ())
6283 tree receiver, args;
6284 c_parser_consume_token (parser);
6285 receiver = c_parser_objc_receiver (parser);
6286 args = c_parser_objc_message_args (parser);
6287 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6289 expr.value = objc_build_message_expr (build_tree_list (receiver,
6293 /* Else fall through to report error. */
6295 c_parser_error (parser, "expected expression");
6296 expr.value = error_mark_node;
6299 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6302 /* Parse a postfix expression after a parenthesized type name: the
6303 brace-enclosed initializer of a compound literal, possibly followed
6304 by some postfix operators. This is separate because it is not
6305 possible to tell until after the type name whether a cast
6306 expression has a cast or a compound literal, or whether the operand
6307 of sizeof is a parenthesized type name or starts with a compound
6308 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6309 location of the first token after the parentheses around the type
6312 static struct c_expr
6313 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6314 struct c_type_name *type_name,
6315 location_t type_loc)
6321 location_t start_loc;
6322 tree type_expr = NULL_TREE;
6323 bool type_expr_const = true;
6324 check_compound_literal_type (type_loc, type_name);
6325 start_init (NULL_TREE, NULL, 0);
6326 type = groktypename (type_name, &type_expr, &type_expr_const);
6327 start_loc = c_parser_peek_token (parser)->location;
6328 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6330 error_at (type_loc, "compound literal has variable size");
6331 type = error_mark_node;
6333 init = c_parser_braced_init (parser, type, false);
6335 maybe_warn_string_init (type, init);
6337 if (type != error_mark_node
6338 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6339 && current_function_decl)
6341 error ("compound literal qualified by address-space qualifier");
6342 type = error_mark_node;
6346 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6347 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6348 ? CONSTRUCTOR_NON_CONST (init.value)
6349 : init.original_code == C_MAYBE_CONST_EXPR);
6350 non_const |= !type_expr_const;
6351 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6352 expr.original_code = ERROR_MARK;
6353 expr.original_type = NULL;
6356 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6358 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6359 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6363 gcc_assert (!non_const);
6364 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6365 type_expr, expr.value);
6368 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6371 /* Parse a postfix expression after the initial primary or compound
6372 literal; that is, parse a series of postfix operators.
6374 EXPR_LOC is the location of the primary expression. */
6376 static struct c_expr
6377 c_parser_postfix_expression_after_primary (c_parser *parser,
6378 location_t expr_loc,
6381 struct c_expr orig_expr;
6383 VEC(tree,gc) *exprlist;
6384 VEC(tree,gc) *origtypes;
6387 location_t op_loc = c_parser_peek_token (parser)->location;
6388 switch (c_parser_peek_token (parser)->type)
6390 case CPP_OPEN_SQUARE:
6391 /* Array reference. */
6392 c_parser_consume_token (parser);
6393 idx = c_parser_expression (parser).value;
6394 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6396 expr.value = build_array_ref (op_loc, expr.value, idx);
6397 expr.original_code = ERROR_MARK;
6398 expr.original_type = NULL;
6400 case CPP_OPEN_PAREN:
6401 /* Function call. */
6402 c_parser_consume_token (parser);
6403 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6406 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6407 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6410 mark_exp_read (expr.value);
6411 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6412 "(" after the FUNCNAME, which is what we have now. */
6413 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6415 expr.original_code = ERROR_MARK;
6416 if (TREE_CODE (expr.value) == INTEGER_CST
6417 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6418 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6419 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6420 expr.original_code = C_MAYBE_CONST_EXPR;
6421 expr.original_type = NULL;
6422 if (exprlist != NULL)
6424 release_tree_vector (exprlist);
6425 release_tree_vector (origtypes);
6429 /* Structure element reference. */
6430 c_parser_consume_token (parser);
6431 expr = default_function_array_conversion (expr_loc, expr);
6432 if (c_parser_next_token_is (parser, CPP_NAME))
6433 ident = c_parser_peek_token (parser)->value;
6436 c_parser_error (parser, "expected identifier");
6437 expr.value = error_mark_node;
6438 expr.original_code = ERROR_MARK;
6439 expr.original_type = NULL;
6442 c_parser_consume_token (parser);
6443 expr.value = build_component_ref (op_loc, expr.value, ident);
6444 expr.original_code = ERROR_MARK;
6445 if (TREE_CODE (expr.value) != COMPONENT_REF)
6446 expr.original_type = NULL;
6449 /* Remember the original type of a bitfield. */
6450 tree field = TREE_OPERAND (expr.value, 1);
6451 if (TREE_CODE (field) != FIELD_DECL)
6452 expr.original_type = NULL;
6454 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6458 /* Structure element reference. */
6459 c_parser_consume_token (parser);
6460 expr = default_function_array_conversion (expr_loc, expr);
6461 if (c_parser_next_token_is (parser, CPP_NAME))
6462 ident = c_parser_peek_token (parser)->value;
6465 c_parser_error (parser, "expected identifier");
6466 expr.value = error_mark_node;
6467 expr.original_code = ERROR_MARK;
6468 expr.original_type = NULL;
6471 c_parser_consume_token (parser);
6472 expr.value = build_component_ref (op_loc,
6473 build_indirect_ref (op_loc,
6477 expr.original_code = ERROR_MARK;
6478 if (TREE_CODE (expr.value) != COMPONENT_REF)
6479 expr.original_type = NULL;
6482 /* Remember the original type of a bitfield. */
6483 tree field = TREE_OPERAND (expr.value, 1);
6484 if (TREE_CODE (field) != FIELD_DECL)
6485 expr.original_type = NULL;
6487 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6491 /* Postincrement. */
6492 c_parser_consume_token (parser);
6493 expr = default_function_array_read_conversion (expr_loc, expr);
6494 expr.value = build_unary_op (op_loc,
6495 POSTINCREMENT_EXPR, expr.value, 0);
6496 expr.original_code = ERROR_MARK;
6497 expr.original_type = NULL;
6499 case CPP_MINUS_MINUS:
6500 /* Postdecrement. */
6501 c_parser_consume_token (parser);
6502 expr = default_function_array_read_conversion (expr_loc, expr);
6503 expr.value = build_unary_op (op_loc,
6504 POSTDECREMENT_EXPR, expr.value, 0);
6505 expr.original_code = ERROR_MARK;
6506 expr.original_type = NULL;
6514 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6517 assignment-expression
6518 expression , assignment-expression
6521 static struct c_expr
6522 c_parser_expression (c_parser *parser)
6525 expr = c_parser_expr_no_commas (parser, NULL);
6526 while (c_parser_next_token_is (parser, CPP_COMMA))
6530 location_t loc = c_parser_peek_token (parser)->location;
6531 location_t expr_loc;
6532 c_parser_consume_token (parser);
6533 expr_loc = c_parser_peek_token (parser)->location;
6534 lhsval = expr.value;
6535 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6536 lhsval = TREE_OPERAND (lhsval, 1);
6537 if (DECL_P (lhsval) || handled_component_p (lhsval))
6538 mark_exp_read (lhsval);
6539 next = c_parser_expr_no_commas (parser, NULL);
6540 next = default_function_array_conversion (expr_loc, next);
6541 expr.value = build_compound_expr (loc, expr.value, next.value);
6542 expr.original_code = COMPOUND_EXPR;
6543 expr.original_type = next.original_type;
6548 /* Parse an expression and convert functions or arrays to
6551 static struct c_expr
6552 c_parser_expression_conv (c_parser *parser)
6555 location_t loc = c_parser_peek_token (parser)->location;
6556 expr = c_parser_expression (parser);
6557 expr = default_function_array_conversion (loc, expr);
6561 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6562 functions and arrays to pointers. If FOLD_P, fold the expressions.
6565 assignment-expression
6566 nonempty-expr-list , assignment-expression
6569 static VEC(tree,gc) *
6570 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6571 VEC(tree,gc) **p_orig_types)
6574 VEC(tree,gc) *orig_types;
6576 location_t loc = c_parser_peek_token (parser)->location;
6578 ret = make_tree_vector ();
6579 if (p_orig_types == NULL)
6582 orig_types = make_tree_vector ();
6584 expr = c_parser_expr_no_commas (parser, NULL);
6586 expr = default_function_array_read_conversion (loc, expr);
6588 expr.value = c_fully_fold (expr.value, false, NULL);
6589 VEC_quick_push (tree, ret, expr.value);
6590 if (orig_types != NULL)
6591 VEC_quick_push (tree, orig_types, expr.original_type);
6592 while (c_parser_next_token_is (parser, CPP_COMMA))
6594 c_parser_consume_token (parser);
6595 loc = c_parser_peek_token (parser)->location;
6596 expr = c_parser_expr_no_commas (parser, NULL);
6598 expr = default_function_array_read_conversion (loc, expr);
6600 expr.value = c_fully_fold (expr.value, false, NULL);
6601 VEC_safe_push (tree, gc, ret, expr.value);
6602 if (orig_types != NULL)
6603 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6605 if (orig_types != NULL)
6606 *p_orig_types = orig_types;
6610 /* Parse Objective-C-specific constructs. */
6612 /* Parse an objc-class-definition.
6614 objc-class-definition:
6615 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6616 objc-class-instance-variables[opt] objc-methodprotolist @end
6617 @implementation identifier objc-superclass[opt]
6618 objc-class-instance-variables[opt]
6619 @interface identifier ( identifier ) objc-protocol-refs[opt]
6620 objc-methodprotolist @end
6621 @implementation identifier ( identifier )
6626 "@interface identifier (" must start "@interface identifier (
6627 identifier ) ...": objc-methodprotolist in the first production may
6628 not start with a parenthesized identifier as a declarator of a data
6629 definition with no declaration specifiers if the objc-superclass,
6630 objc-protocol-refs and objc-class-instance-variables are omitted. */
6633 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6638 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6640 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6645 c_parser_consume_token (parser);
6646 if (c_parser_next_token_is_not (parser, CPP_NAME))
6648 c_parser_error (parser, "expected identifier");
6651 id1 = c_parser_peek_token (parser)->value;
6652 c_parser_consume_token (parser);
6653 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6656 tree proto = NULL_TREE;
6657 c_parser_consume_token (parser);
6658 if (c_parser_next_token_is_not (parser, CPP_NAME))
6660 c_parser_error (parser, "expected identifier");
6661 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6664 id2 = c_parser_peek_token (parser)->value;
6665 c_parser_consume_token (parser);
6666 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6669 objc_start_category_implementation (id1, id2);
6672 if (c_parser_next_token_is (parser, CPP_LESS))
6673 proto = c_parser_objc_protocol_refs (parser);
6674 objc_start_category_interface (id1, id2, proto, attributes);
6675 c_parser_objc_methodprotolist (parser);
6676 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6677 objc_finish_interface ();
6680 if (c_parser_next_token_is (parser, CPP_COLON))
6682 c_parser_consume_token (parser);
6683 if (c_parser_next_token_is_not (parser, CPP_NAME))
6685 c_parser_error (parser, "expected identifier");
6688 superclass = c_parser_peek_token (parser)->value;
6689 c_parser_consume_token (parser);
6692 superclass = NULL_TREE;
6695 tree proto = NULL_TREE;
6696 if (c_parser_next_token_is (parser, CPP_LESS))
6697 proto = c_parser_objc_protocol_refs (parser);
6698 objc_start_class_interface (id1, superclass, proto, attributes);
6701 objc_start_class_implementation (id1, superclass);
6702 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6703 c_parser_objc_class_instance_variables (parser);
6706 objc_continue_interface ();
6707 c_parser_objc_methodprotolist (parser);
6708 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6709 objc_finish_interface ();
6713 objc_continue_implementation ();
6718 /* Parse objc-class-instance-variables.
6720 objc-class-instance-variables:
6721 { objc-instance-variable-decl-list[opt] }
6723 objc-instance-variable-decl-list:
6724 objc-visibility-spec
6725 objc-instance-variable-decl ;
6727 objc-instance-variable-decl-list objc-visibility-spec
6728 objc-instance-variable-decl-list objc-instance-variable-decl ;
6729 objc-instance-variable-decl-list ;
6731 objc-visibility-spec:
6736 objc-instance-variable-decl:
6741 c_parser_objc_class_instance_variables (c_parser *parser)
6743 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6744 c_parser_consume_token (parser);
6745 while (c_parser_next_token_is_not (parser, CPP_EOF))
6748 /* Parse any stray semicolon. */
6749 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6751 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6752 "extra semicolon in struct or union specified");
6753 c_parser_consume_token (parser);
6756 /* Stop if at the end of the instance variables. */
6757 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6759 c_parser_consume_token (parser);
6762 /* Parse any objc-visibility-spec. */
6763 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6765 c_parser_consume_token (parser);
6766 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6769 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6771 c_parser_consume_token (parser);
6772 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6775 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6777 c_parser_consume_token (parser);
6778 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6781 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6783 c_parser_consume_token (parser);
6784 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6787 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6789 c_parser_pragma (parser, pragma_external);
6793 /* Parse some comma-separated declarations. */
6794 decls = c_parser_struct_declaration (parser);
6796 /* Comma-separated instance variables are chained together in
6797 reverse order; add them one by one. */
6798 tree ivar = nreverse (decls);
6799 for (; ivar; ivar = DECL_CHAIN (ivar))
6800 objc_add_instance_variable (copy_node (ivar));
6802 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6806 /* Parse an objc-class-declaration.
6808 objc-class-declaration:
6809 @class identifier-list ;
6813 c_parser_objc_class_declaration (c_parser *parser)
6815 tree list = NULL_TREE;
6816 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6817 c_parser_consume_token (parser);
6818 /* Any identifiers, including those declared as type names, are OK
6823 if (c_parser_next_token_is_not (parser, CPP_NAME))
6825 c_parser_error (parser, "expected identifier");
6826 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6827 parser->error = false;
6830 id = c_parser_peek_token (parser)->value;
6831 list = chainon (list, build_tree_list (NULL_TREE, id));
6832 c_parser_consume_token (parser);
6833 if (c_parser_next_token_is (parser, CPP_COMMA))
6834 c_parser_consume_token (parser);
6838 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6839 objc_declare_class (list);
6842 /* Parse an objc-alias-declaration.
6844 objc-alias-declaration:
6845 @compatibility_alias identifier identifier ;
6849 c_parser_objc_alias_declaration (c_parser *parser)
6852 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6853 c_parser_consume_token (parser);
6854 if (c_parser_next_token_is_not (parser, CPP_NAME))
6856 c_parser_error (parser, "expected identifier");
6857 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6860 id1 = c_parser_peek_token (parser)->value;
6861 c_parser_consume_token (parser);
6862 if (c_parser_next_token_is_not (parser, CPP_NAME))
6864 c_parser_error (parser, "expected identifier");
6865 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6868 id2 = c_parser_peek_token (parser)->value;
6869 c_parser_consume_token (parser);
6870 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6871 objc_declare_alias (id1, id2);
6874 /* Parse an objc-protocol-definition.
6876 objc-protocol-definition:
6877 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6878 @protocol identifier-list ;
6880 "@protocol identifier ;" should be resolved as "@protocol
6881 identifier-list ;": objc-methodprotolist may not start with a
6882 semicolon in the first alternative if objc-protocol-refs are
6886 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6888 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6890 c_parser_consume_token (parser);
6891 if (c_parser_next_token_is_not (parser, CPP_NAME))
6893 c_parser_error (parser, "expected identifier");
6896 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6897 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6899 tree list = NULL_TREE;
6900 /* Any identifiers, including those declared as type names, are
6905 if (c_parser_next_token_is_not (parser, CPP_NAME))
6907 c_parser_error (parser, "expected identifier");
6910 id = c_parser_peek_token (parser)->value;
6911 list = chainon (list, build_tree_list (NULL_TREE, id));
6912 c_parser_consume_token (parser);
6913 if (c_parser_next_token_is (parser, CPP_COMMA))
6914 c_parser_consume_token (parser);
6918 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6919 objc_declare_protocols (list);
6923 tree id = c_parser_peek_token (parser)->value;
6924 tree proto = NULL_TREE;
6925 c_parser_consume_token (parser);
6926 if (c_parser_next_token_is (parser, CPP_LESS))
6927 proto = c_parser_objc_protocol_refs (parser);
6928 parser->objc_pq_context = true;
6929 objc_start_protocol (id, proto, attributes);
6930 c_parser_objc_methodprotolist (parser);
6931 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6932 parser->objc_pq_context = false;
6933 objc_finish_interface ();
6937 /* Parse an objc-method-type.
6943 Return true if it is a class method (+) and false if it is
6944 an instance method (-).
6947 c_parser_objc_method_type (c_parser *parser)
6949 switch (c_parser_peek_token (parser)->type)
6952 c_parser_consume_token (parser);
6955 c_parser_consume_token (parser);
6962 /* Parse an objc-method-definition.
6964 objc-method-definition:
6965 objc-method-type objc-method-decl ;[opt] compound-statement
6969 c_parser_objc_method_definition (c_parser *parser)
6971 bool is_class_method = c_parser_objc_method_type (parser);
6972 tree decl, attributes = NULL_TREE;
6973 parser->objc_pq_context = true;
6974 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
6975 if (decl == error_mark_node)
6976 return; /* Bail here. */
6978 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6980 c_parser_consume_token (parser);
6981 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6982 "extra semicolon in method definition specified");
6985 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6987 c_parser_error (parser, "expected %<{%>");
6991 parser->objc_pq_context = false;
6992 if (objc_start_method_definition (is_class_method, decl, attributes))
6994 add_stmt (c_parser_compound_statement (parser));
6995 objc_finish_method_definition (current_function_decl);
6999 /* This code is executed when we find a method definition
7000 outside of an @implementation context (or invalid for other
7001 reasons). Parse the method (to keep going) but do not emit
7004 c_parser_compound_statement (parser);
7008 /* Parse an objc-methodprotolist.
7010 objc-methodprotolist:
7012 objc-methodprotolist objc-methodproto
7013 objc-methodprotolist declaration
7014 objc-methodprotolist ;
7018 The declaration is a data definition, which may be missing
7019 declaration specifiers under the same rules and diagnostics as
7020 other data definitions outside functions, and the stray semicolon
7021 is diagnosed the same way as a stray semicolon outside a
7025 c_parser_objc_methodprotolist (c_parser *parser)
7029 /* The list is terminated by @end. */
7030 switch (c_parser_peek_token (parser)->type)
7033 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7034 "ISO C does not allow extra %<;%> outside of a function");
7035 c_parser_consume_token (parser);
7039 c_parser_objc_methodproto (parser);
7042 c_parser_pragma (parser, pragma_external);
7047 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7049 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7050 c_parser_objc_at_property_declaration (parser);
7051 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7053 objc_set_method_opt (true);
7054 c_parser_consume_token (parser);
7056 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7058 objc_set_method_opt (false);
7059 c_parser_consume_token (parser);
7062 c_parser_declaration_or_fndef (parser, false, false, true,
7069 /* Parse an objc-methodproto.
7072 objc-method-type objc-method-decl ;
7076 c_parser_objc_methodproto (c_parser *parser)
7078 bool is_class_method = c_parser_objc_method_type (parser);
7079 tree decl, attributes = NULL_TREE;
7081 /* Remember protocol qualifiers in prototypes. */
7082 parser->objc_pq_context = true;
7083 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7084 /* Forget protocol qualifiers now. */
7085 parser->objc_pq_context = false;
7087 /* Do not allow the presence of attributes to hide an erroneous
7088 method implementation in the interface section. */
7089 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7091 c_parser_error (parser, "expected %<;%>");
7095 if (decl != error_mark_node)
7096 objc_add_method_declaration (is_class_method, decl, attributes);
7098 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7101 /* If we are at a position that method attributes may be present, check that
7102 there are not any parsed already (a syntax error) and then collect any
7103 specified at the current location. Finally, if new attributes were present,
7104 check that the next token is legal ( ';' for decls and '{' for defs). */
7107 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7112 c_parser_error (parser,
7113 "method attributes must be specified at the end only");
7114 *attributes = NULL_TREE;
7118 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7119 *attributes = c_parser_attributes (parser);
7121 /* If there were no attributes here, just report any earlier error. */
7122 if (*attributes == NULL_TREE || bad)
7125 /* If the attributes are followed by a ; or {, then just report any earlier
7127 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7128 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7131 /* We've got attributes, but not at the end. */
7132 c_parser_error (parser,
7133 "expected %<;%> or %<{%> after method attribute definition");
7137 /* Parse an objc-method-decl.
7140 ( objc-type-name ) objc-selector
7142 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7143 objc-keyword-selector objc-optparmlist
7146 objc-keyword-selector:
7148 objc-keyword-selector objc-keyword-decl
7151 objc-selector : ( objc-type-name ) identifier
7152 objc-selector : identifier
7153 : ( objc-type-name ) identifier
7157 objc-optparms objc-optellipsis
7161 objc-opt-parms , parameter-declaration
7169 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7171 tree type = NULL_TREE;
7173 tree parms = NULL_TREE;
7174 bool ellipsis = false;
7175 bool attr_err = false;
7177 *attributes = NULL_TREE;
7178 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7180 c_parser_consume_token (parser);
7181 type = c_parser_objc_type_name (parser);
7182 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7184 sel = c_parser_objc_selector (parser);
7185 /* If there is no selector, or a colon follows, we have an
7186 objc-keyword-selector. If there is a selector, and a colon does
7187 not follow, that selector ends the objc-method-decl. */
7188 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7191 tree list = NULL_TREE;
7194 tree atype = NULL_TREE, id, keyworddecl;
7195 tree param_attr = NULL_TREE;
7196 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7198 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7200 c_parser_consume_token (parser);
7201 atype = c_parser_objc_type_name (parser);
7202 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7205 /* New ObjC allows attributes on method parameters. */
7206 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7207 param_attr = c_parser_attributes (parser);
7208 if (c_parser_next_token_is_not (parser, CPP_NAME))
7210 c_parser_error (parser, "expected identifier");
7211 return error_mark_node;
7213 id = c_parser_peek_token (parser)->value;
7214 c_parser_consume_token (parser);
7215 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7216 list = chainon (list, keyworddecl);
7217 tsel = c_parser_objc_selector (parser);
7218 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7222 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7224 /* Parse the optional parameter list. Optional Objective-C
7225 method parameters follow the C syntax, and may include '...'
7226 to denote a variable number of arguments. */
7227 parms = make_node (TREE_LIST);
7228 while (c_parser_next_token_is (parser, CPP_COMMA))
7230 struct c_parm *parm;
7231 c_parser_consume_token (parser);
7232 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7235 c_parser_consume_token (parser);
7236 attr_err |= c_parser_objc_maybe_method_attributes
7237 (parser, attributes) ;
7240 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7243 parms = chainon (parms,
7244 build_tree_list (NULL_TREE, grokparm (parm)));
7249 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7253 c_parser_error (parser, "objective-c method declaration is expected");
7254 return error_mark_node;
7258 return error_mark_node;
7260 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7263 /* Parse an objc-type-name.
7266 objc-type-qualifiers[opt] type-name
7267 objc-type-qualifiers[opt]
7269 objc-type-qualifiers:
7271 objc-type-qualifiers objc-type-qualifier
7273 objc-type-qualifier: one of
7274 in out inout bycopy byref oneway
7278 c_parser_objc_type_name (c_parser *parser)
7280 tree quals = NULL_TREE;
7281 struct c_type_name *type_name = NULL;
7282 tree type = NULL_TREE;
7285 c_token *token = c_parser_peek_token (parser);
7286 if (token->type == CPP_KEYWORD
7287 && (token->keyword == RID_IN
7288 || token->keyword == RID_OUT
7289 || token->keyword == RID_INOUT
7290 || token->keyword == RID_BYCOPY
7291 || token->keyword == RID_BYREF
7292 || token->keyword == RID_ONEWAY))
7294 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7295 c_parser_consume_token (parser);
7300 if (c_parser_next_token_starts_typename (parser))
7301 type_name = c_parser_type_name (parser);
7303 type = groktypename (type_name, NULL, NULL);
7304 return build_tree_list (quals, type);
7307 /* Parse objc-protocol-refs.
7314 c_parser_objc_protocol_refs (c_parser *parser)
7316 tree list = NULL_TREE;
7317 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7318 c_parser_consume_token (parser);
7319 /* Any identifiers, including those declared as type names, are OK
7324 if (c_parser_next_token_is_not (parser, CPP_NAME))
7326 c_parser_error (parser, "expected identifier");
7329 id = c_parser_peek_token (parser)->value;
7330 list = chainon (list, build_tree_list (NULL_TREE, id));
7331 c_parser_consume_token (parser);
7332 if (c_parser_next_token_is (parser, CPP_COMMA))
7333 c_parser_consume_token (parser);
7337 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7341 /* Parse an objc-try-catch-statement.
7343 objc-try-catch-statement:
7344 @try compound-statement objc-catch-list[opt]
7345 @try compound-statement objc-catch-list[opt] @finally compound-statement
7348 @catch ( parameter-declaration ) compound-statement
7349 objc-catch-list @catch ( parameter-declaration ) compound-statement
7353 c_parser_objc_try_catch_statement (c_parser *parser)
7357 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7358 c_parser_consume_token (parser);
7359 loc = c_parser_peek_token (parser)->location;
7360 stmt = c_parser_compound_statement (parser);
7361 objc_begin_try_stmt (loc, stmt);
7362 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7364 struct c_parm *parm;
7365 c_parser_consume_token (parser);
7366 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7368 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7371 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7374 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7375 objc_begin_catch_clause (grokparm (parm));
7376 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7377 c_parser_compound_statement_nostart (parser);
7378 objc_finish_catch_clause ();
7380 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7384 c_parser_consume_token (parser);
7385 finloc = c_parser_peek_token (parser)->location;
7386 finstmt = c_parser_compound_statement (parser);
7387 objc_build_finally_clause (finloc, finstmt);
7389 objc_finish_try_stmt ();
7392 /* Parse an objc-synchronized-statement.
7394 objc-synchronized-statement:
7395 @synchronized ( expression ) compound-statement
7399 c_parser_objc_synchronized_statement (c_parser *parser)
7403 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7404 c_parser_consume_token (parser);
7405 loc = c_parser_peek_token (parser)->location;
7406 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7408 expr = c_parser_expression (parser).value;
7409 expr = c_fully_fold (expr, false, NULL);
7410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7413 expr = error_mark_node;
7414 stmt = c_parser_compound_statement (parser);
7415 objc_build_synchronized (loc, expr, stmt);
7418 /* Parse an objc-selector; return NULL_TREE without an error if the
7419 next token is not an objc-selector.
7424 enum struct union if else while do for switch case default
7425 break continue return goto asm sizeof typeof __alignof
7426 unsigned long const short volatile signed restrict _Complex
7427 in out inout bycopy byref oneway int char float double void _Bool
7429 ??? Why this selection of keywords but not, for example, storage
7430 class specifiers? */
7433 c_parser_objc_selector (c_parser *parser)
7435 c_token *token = c_parser_peek_token (parser);
7436 tree value = token->value;
7437 if (token->type == CPP_NAME)
7439 c_parser_consume_token (parser);
7442 if (token->type != CPP_KEYWORD)
7444 switch (token->keyword)
7486 c_parser_consume_token (parser);
7493 /* Parse an objc-selector-arg.
7497 objc-keywordname-list
7499 objc-keywordname-list:
7501 objc-keywordname-list objc-keywordname
7509 c_parser_objc_selector_arg (c_parser *parser)
7511 tree sel = c_parser_objc_selector (parser);
7512 tree list = NULL_TREE;
7513 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7517 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7519 list = chainon (list, build_tree_list (sel, NULL_TREE));
7520 sel = c_parser_objc_selector (parser);
7521 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7527 /* Parse an objc-receiver.
7536 c_parser_objc_receiver (c_parser *parser)
7538 if (c_parser_peek_token (parser)->type == CPP_NAME
7539 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7540 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7542 tree id = c_parser_peek_token (parser)->value;
7543 c_parser_consume_token (parser);
7544 return objc_get_class_reference (id);
7546 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7549 /* Parse objc-message-args.
7553 objc-keywordarg-list
7555 objc-keywordarg-list:
7557 objc-keywordarg-list objc-keywordarg
7560 objc-selector : objc-keywordexpr
7565 c_parser_objc_message_args (c_parser *parser)
7567 tree sel = c_parser_objc_selector (parser);
7568 tree list = NULL_TREE;
7569 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7574 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7575 return error_mark_node;
7576 keywordexpr = c_parser_objc_keywordexpr (parser);
7577 list = chainon (list, build_tree_list (sel, keywordexpr));
7578 sel = c_parser_objc_selector (parser);
7579 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7585 /* Parse an objc-keywordexpr.
7592 c_parser_objc_keywordexpr (c_parser *parser)
7595 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7596 if (VEC_length (tree, expr_list) == 1)
7598 /* Just return the expression, remove a level of
7600 ret = VEC_index (tree, expr_list, 0);
7604 /* We have a comma expression, we will collapse later. */
7605 ret = build_tree_list_vec (expr_list);
7607 release_tree_vector (expr_list);
7611 /* A check, needed in several places, that ObjC interface, implementation or
7612 method definitions are not prefixed by incorrect items. */
7614 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7615 struct c_declspecs *specs)
7617 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7619 c_parser_error (parser,
7620 "no type or storage class may be specified here,");
7621 c_parser_skip_to_end_of_block_or_statement (parser);
7627 /* Parse an Objective-C @property declaration. The syntax is:
7629 objc-property-declaration:
7630 '@property' objc-property-attributes[opt] struct-declaration ;
7632 objc-property-attributes:
7633 '(' objc-property-attribute-list ')'
7635 objc-property-attribute-list:
7636 objc-property-attribute
7637 objc-property-attribute-list, objc-property-attribute
7639 objc-property-attribute
7640 'getter' = identifier
7641 'setter' = identifier
7650 @property NSString *name;
7651 @property (readonly) id object;
7652 @property (retain, nonatomic, getter=getTheName) id name;
7653 @property int a, b, c;
7655 PS: This function is identical to cp_parser_objc_at_propery_declaration
7656 for C++. Keep them in sync. */
7658 c_parser_objc_at_property_declaration (c_parser *parser)
7660 /* The following variables hold the attributes of the properties as
7661 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7662 seen. When we see an attribute, we set them to 'true' (if they
7663 are boolean properties) or to the identifier (if they have an
7664 argument, ie, for getter and setter). Note that here we only
7665 parse the list of attributes, check the syntax and accumulate the
7666 attributes that we find. objc_add_property_declaration() will
7667 then process the information. */
7668 bool property_assign = false;
7669 bool property_copy = false;
7670 tree property_getter_ident = NULL_TREE;
7671 bool property_nonatomic = false;
7672 bool property_readonly = false;
7673 bool property_readwrite = false;
7674 bool property_retain = false;
7675 tree property_setter_ident = NULL_TREE;
7677 /* 'properties' is the list of properties that we read. Usually a
7678 single one, but maybe more (eg, in "@property int a, b, c;" there
7683 loc = c_parser_peek_token (parser)->location;
7684 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7686 c_parser_consume_token (parser); /* Eat '@property'. */
7688 /* Parse the optional attribute list... */
7689 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7692 c_parser_consume_token (parser);
7694 /* Property attribute keywords are valid now. */
7695 parser->objc_property_attr_context = true;
7699 bool syntax_error = false;
7700 c_token *token = c_parser_peek_token (parser);
7703 if (token->type != CPP_KEYWORD)
7705 if (token->type == CPP_CLOSE_PAREN)
7706 c_parser_error (parser, "expected identifier");
7709 c_parser_consume_token (parser);
7710 c_parser_error (parser, "unknown property attribute");
7714 keyword = token->keyword;
7715 c_parser_consume_token (parser);
7718 case RID_ASSIGN: property_assign = true; break;
7719 case RID_COPY: property_copy = true; break;
7720 case RID_NONATOMIC: property_nonatomic = true; break;
7721 case RID_READONLY: property_readonly = true; break;
7722 case RID_READWRITE: property_readwrite = true; break;
7723 case RID_RETAIN: property_retain = true; break;
7727 if (c_parser_next_token_is_not (parser, CPP_EQ))
7729 c_parser_error (parser,
7730 "getter/setter attribute must be followed by %<=%>");
7731 syntax_error = true;
7734 c_parser_consume_token (parser); /* eat the = */
7735 if (c_parser_next_token_is_not (parser, CPP_NAME))
7737 c_parser_error (parser, "expected identifier");
7738 syntax_error = true;
7741 if (keyword == RID_SETTER)
7743 if (property_setter_ident != NULL_TREE)
7744 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7746 property_setter_ident = c_parser_peek_token (parser)->value;
7747 c_parser_consume_token (parser);
7748 if (c_parser_next_token_is_not (parser, CPP_COLON))
7749 c_parser_error (parser, "setter name must terminate with %<:%>");
7751 c_parser_consume_token (parser);
7755 if (property_getter_ident != NULL_TREE)
7756 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7758 property_getter_ident = c_parser_peek_token (parser)->value;
7759 c_parser_consume_token (parser);
7763 c_parser_error (parser, "unknown property attribute");
7764 syntax_error = true;
7771 if (c_parser_next_token_is (parser, CPP_COMMA))
7772 c_parser_consume_token (parser);
7776 parser->objc_property_attr_context = false;
7777 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7779 /* ... and the property declaration(s). */
7780 properties = c_parser_struct_declaration (parser);
7782 if (properties == error_mark_node)
7784 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7785 parser->error = false;
7789 if (properties == NULL_TREE)
7790 c_parser_error (parser, "expected identifier");
7793 /* Comma-separated properties are chained together in
7794 reverse order; add them one by one. */
7795 properties = nreverse (properties);
7797 for (; properties; properties = TREE_CHAIN (properties))
7798 objc_add_property_declaration (loc, copy_node (properties),
7799 property_readonly, property_readwrite,
7800 property_assign, property_retain,
7801 property_copy, property_nonatomic,
7802 property_getter_ident, property_setter_ident);
7805 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7806 parser->error = false;
7809 /* Parse an Objective-C @synthesize declaration. The syntax is:
7811 objc-synthesize-declaration:
7812 @synthesize objc-synthesize-identifier-list ;
7814 objc-synthesize-identifier-list:
7815 objc-synthesize-identifier
7816 objc-synthesize-identifier-list, objc-synthesize-identifier
7818 objc-synthesize-identifier
7820 identifier = identifier
7823 @synthesize MyProperty;
7824 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
7826 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
7827 for C++. Keep them in sync.
7830 c_parser_objc_at_synthesize_declaration (c_parser *parser)
7832 tree list = NULL_TREE;
7834 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
7835 loc = c_parser_peek_token (parser)->location;
7837 c_parser_consume_token (parser);
7840 tree property, ivar;
7841 if (c_parser_next_token_is_not (parser, CPP_NAME))
7843 c_parser_error (parser, "expected identifier");
7844 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7845 /* Once we find the semicolon, we can resume normal parsing.
7846 We have to reset parser->error manually because
7847 c_parser_skip_until_found() won't reset it for us if the
7848 next token is precisely a semicolon. */
7849 parser->error = false;
7852 property = c_parser_peek_token (parser)->value;
7853 c_parser_consume_token (parser);
7854 if (c_parser_next_token_is (parser, CPP_EQ))
7856 c_parser_consume_token (parser);
7857 if (c_parser_next_token_is_not (parser, CPP_NAME))
7859 c_parser_error (parser, "expected identifier");
7860 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7861 parser->error = false;
7864 ivar = c_parser_peek_token (parser)->value;
7865 c_parser_consume_token (parser);
7869 list = chainon (list, build_tree_list (ivar, property));
7870 if (c_parser_next_token_is (parser, CPP_COMMA))
7871 c_parser_consume_token (parser);
7875 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7876 objc_add_synthesize_declaration (loc, list);
7879 /* Parse an Objective-C @dynamic declaration. The syntax is:
7881 objc-dynamic-declaration:
7882 @dynamic identifier-list ;
7885 @dynamic MyProperty;
7886 @dynamic MyProperty, AnotherProperty;
7888 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
7889 for C++. Keep them in sync.
7892 c_parser_objc_at_dynamic_declaration (c_parser *parser)
7894 tree list = NULL_TREE;
7896 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
7897 loc = c_parser_peek_token (parser)->location;
7899 c_parser_consume_token (parser);
7903 if (c_parser_next_token_is_not (parser, CPP_NAME))
7905 c_parser_error (parser, "expected identifier");
7906 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7907 parser->error = false;
7910 property = c_parser_peek_token (parser)->value;
7911 list = chainon (list, build_tree_list (NULL_TREE, property));
7912 c_parser_consume_token (parser);
7913 if (c_parser_next_token_is (parser, CPP_COMMA))
7914 c_parser_consume_token (parser);
7918 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7919 objc_add_dynamic_declaration (loc, list);
7923 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7924 should be considered, statements. ALLOW_STMT is true if we're within
7925 the context of a function and such pragmas are to be allowed. Returns
7926 true if we actually parsed such a pragma. */
7929 c_parser_pragma (c_parser *parser, enum pragma_context context)
7933 id = c_parser_peek_token (parser)->pragma_kind;
7934 gcc_assert (id != PRAGMA_NONE);
7938 case PRAGMA_OMP_BARRIER:
7939 if (context != pragma_compound)
7941 if (context == pragma_stmt)
7942 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7943 "used in compound statements");
7946 c_parser_omp_barrier (parser);
7949 case PRAGMA_OMP_FLUSH:
7950 if (context != pragma_compound)
7952 if (context == pragma_stmt)
7953 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7954 "used in compound statements");
7957 c_parser_omp_flush (parser);
7960 case PRAGMA_OMP_TASKWAIT:
7961 if (context != pragma_compound)
7963 if (context == pragma_stmt)
7964 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7965 "used in compound statements");
7968 c_parser_omp_taskwait (parser);
7971 case PRAGMA_OMP_THREADPRIVATE:
7972 c_parser_omp_threadprivate (parser);
7975 case PRAGMA_OMP_SECTION:
7976 error_at (c_parser_peek_token (parser)->location,
7977 "%<#pragma omp section%> may only be used in "
7978 "%<#pragma omp sections%> construct");
7979 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7982 case PRAGMA_GCC_PCH_PREPROCESS:
7983 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7984 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7988 if (id < PRAGMA_FIRST_EXTERNAL)
7990 if (context == pragma_external)
7993 c_parser_error (parser, "expected declaration specifiers");
7994 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7997 c_parser_omp_construct (parser);
8003 c_parser_consume_pragma (parser);
8004 c_invoke_pragma_handler (id);
8006 /* Skip to EOL, but suppress any error message. Those will have been
8007 generated by the handler routine through calling error, as opposed
8008 to calling c_parser_error. */
8009 parser->error = true;
8010 c_parser_skip_to_pragma_eol (parser);
8015 /* The interface the pragma parsers have to the lexer. */
8018 pragma_lex (tree *value)
8020 c_token *tok = c_parser_peek_token (the_parser);
8021 enum cpp_ttype ret = tok->type;
8023 *value = tok->value;
8024 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8028 if (ret == CPP_KEYWORD)
8030 c_parser_consume_token (the_parser);
8037 c_parser_pragma_pch_preprocess (c_parser *parser)
8041 c_parser_consume_pragma (parser);
8042 if (c_parser_next_token_is (parser, CPP_STRING))
8044 name = c_parser_peek_token (parser)->value;
8045 c_parser_consume_token (parser);
8048 c_parser_error (parser, "expected string literal");
8049 c_parser_skip_to_pragma_eol (parser);
8052 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8055 /* OpenMP 2.5 parsing routines. */
8057 /* Returns name of the next clause.
8058 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8059 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8060 returned and the token is consumed. */
8062 static pragma_omp_clause
8063 c_parser_omp_clause_name (c_parser *parser)
8065 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8067 if (c_parser_next_token_is_keyword (parser, RID_IF))
8068 result = PRAGMA_OMP_CLAUSE_IF;
8069 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8070 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8071 else if (c_parser_next_token_is (parser, CPP_NAME))
8073 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8078 if (!strcmp ("collapse", p))
8079 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8080 else if (!strcmp ("copyin", p))
8081 result = PRAGMA_OMP_CLAUSE_COPYIN;
8082 else if (!strcmp ("copyprivate", p))
8083 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8086 if (!strcmp ("firstprivate", p))
8087 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8090 if (!strcmp ("lastprivate", p))
8091 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8094 if (!strcmp ("nowait", p))
8095 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8096 else if (!strcmp ("num_threads", p))
8097 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8100 if (!strcmp ("ordered", p))
8101 result = PRAGMA_OMP_CLAUSE_ORDERED;
8104 if (!strcmp ("private", p))
8105 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8108 if (!strcmp ("reduction", p))
8109 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8112 if (!strcmp ("schedule", p))
8113 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8114 else if (!strcmp ("shared", p))
8115 result = PRAGMA_OMP_CLAUSE_SHARED;
8118 if (!strcmp ("untied", p))
8119 result = PRAGMA_OMP_CLAUSE_UNTIED;
8124 if (result != PRAGMA_OMP_CLAUSE_NONE)
8125 c_parser_consume_token (parser);
8130 /* Validate that a clause of the given type does not already exist. */
8133 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8138 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8139 if (OMP_CLAUSE_CODE (c) == code)
8141 location_t loc = OMP_CLAUSE_LOCATION (c);
8142 error_at (loc, "too many %qs clauses", name);
8150 variable-list , identifier
8152 If KIND is nonzero, create the appropriate node and install the
8153 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8154 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8156 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8157 return the list created. */
8160 c_parser_omp_variable_list (c_parser *parser,
8161 location_t clause_loc,
8162 enum omp_clause_code kind,
8165 if (c_parser_next_token_is_not (parser, CPP_NAME)
8166 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8167 c_parser_error (parser, "expected identifier");
8169 while (c_parser_next_token_is (parser, CPP_NAME)
8170 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8172 tree t = lookup_name (c_parser_peek_token (parser)->value);
8175 undeclared_variable (c_parser_peek_token (parser)->location,
8176 c_parser_peek_token (parser)->value);
8177 else if (t == error_mark_node)
8181 tree u = build_omp_clause (clause_loc, kind);
8182 OMP_CLAUSE_DECL (u) = t;
8183 OMP_CLAUSE_CHAIN (u) = list;
8187 list = tree_cons (t, NULL_TREE, list);
8189 c_parser_consume_token (parser);
8191 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8194 c_parser_consume_token (parser);
8200 /* Similarly, but expect leading and trailing parenthesis. This is a very
8201 common case for omp clauses. */
8204 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8207 /* The clauses location. */
8208 location_t loc = c_parser_peek_token (parser)->location;
8210 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8212 list = c_parser_omp_variable_list (parser, loc, kind, list);
8213 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8219 collapse ( constant-expression ) */
8222 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8224 tree c, num = error_mark_node;
8228 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8230 loc = c_parser_peek_token (parser)->location;
8231 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8233 num = c_parser_expr_no_commas (parser, NULL).value;
8234 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8236 if (num == error_mark_node)
8238 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8239 || !host_integerp (num, 0)
8240 || (n = tree_low_cst (num, 0)) <= 0
8244 "collapse argument needs positive constant integer expression");
8247 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8248 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8249 OMP_CLAUSE_CHAIN (c) = list;
8254 copyin ( variable-list ) */
8257 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8259 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8263 copyprivate ( variable-list ) */
8266 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8268 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8272 default ( shared | none ) */
8275 c_parser_omp_clause_default (c_parser *parser, tree list)
8277 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8278 location_t loc = c_parser_peek_token (parser)->location;
8281 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8283 if (c_parser_next_token_is (parser, CPP_NAME))
8285 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8290 if (strcmp ("none", p) != 0)
8292 kind = OMP_CLAUSE_DEFAULT_NONE;
8296 if (strcmp ("shared", p) != 0)
8298 kind = OMP_CLAUSE_DEFAULT_SHARED;
8305 c_parser_consume_token (parser);
8310 c_parser_error (parser, "expected %<none%> or %<shared%>");
8312 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8314 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8317 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8318 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8319 OMP_CLAUSE_CHAIN (c) = list;
8320 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8326 firstprivate ( variable-list ) */
8329 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8331 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8335 if ( expression ) */
8338 c_parser_omp_clause_if (c_parser *parser, tree list)
8340 location_t loc = c_parser_peek_token (parser)->location;
8341 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8343 tree t = c_parser_paren_condition (parser);
8346 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8348 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8349 OMP_CLAUSE_IF_EXPR (c) = t;
8350 OMP_CLAUSE_CHAIN (c) = list;
8354 c_parser_error (parser, "expected %<(%>");
8360 lastprivate ( variable-list ) */
8363 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8365 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8372 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8375 location_t loc = c_parser_peek_token (parser)->location;
8377 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8379 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8380 OMP_CLAUSE_CHAIN (c) = list;
8385 num_threads ( expression ) */
8388 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8390 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8391 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8393 location_t expr_loc = c_parser_peek_token (parser)->location;
8394 tree c, t = c_parser_expression (parser).value;
8395 t = c_fully_fold (t, false, NULL);
8397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8399 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8401 c_parser_error (parser, "expected integer expression");
8405 /* Attempt to statically determine when the number isn't positive. */
8406 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8407 build_int_cst (TREE_TYPE (t), 0));
8408 if (CAN_HAVE_LOCATION_P (c))
8409 SET_EXPR_LOCATION (c, expr_loc);
8410 if (c == boolean_true_node)
8412 warning_at (expr_loc, 0,
8413 "%<num_threads%> value must be positive");
8414 t = integer_one_node;
8417 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8419 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8420 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8421 OMP_CLAUSE_CHAIN (c) = list;
8432 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8436 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8438 c = build_omp_clause (c_parser_peek_token (parser)->location,
8439 OMP_CLAUSE_ORDERED);
8440 OMP_CLAUSE_CHAIN (c) = list;
8446 private ( variable-list ) */
8449 c_parser_omp_clause_private (c_parser *parser, tree list)
8451 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8455 reduction ( reduction-operator : variable-list )
8458 One of: + * - & ^ | && || */
8461 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8463 location_t clause_loc = c_parser_peek_token (parser)->location;
8464 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8466 enum tree_code code;
8468 switch (c_parser_peek_token (parser)->type)
8480 code = BIT_AND_EXPR;
8483 code = BIT_XOR_EXPR;
8486 code = BIT_IOR_EXPR;
8489 code = TRUTH_ANDIF_EXPR;
8492 code = TRUTH_ORIF_EXPR;
8495 c_parser_error (parser,
8496 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8497 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8498 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8501 c_parser_consume_token (parser);
8502 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8506 nl = c_parser_omp_variable_list (parser, clause_loc,
8507 OMP_CLAUSE_REDUCTION, list);
8508 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8509 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8513 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8519 schedule ( schedule-kind )
8520 schedule ( schedule-kind , expression )
8523 static | dynamic | guided | runtime | auto
8527 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8530 location_t loc = c_parser_peek_token (parser)->location;
8532 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8535 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8537 if (c_parser_next_token_is (parser, CPP_NAME))
8539 tree kind = c_parser_peek_token (parser)->value;
8540 const char *p = IDENTIFIER_POINTER (kind);
8545 if (strcmp ("dynamic", p) != 0)
8547 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8551 if (strcmp ("guided", p) != 0)
8553 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8557 if (strcmp ("runtime", p) != 0)
8559 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8566 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8567 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8568 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8569 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8573 c_parser_consume_token (parser);
8574 if (c_parser_next_token_is (parser, CPP_COMMA))
8577 c_parser_consume_token (parser);
8579 here = c_parser_peek_token (parser)->location;
8580 t = c_parser_expr_no_commas (parser, NULL).value;
8581 t = c_fully_fold (t, false, NULL);
8583 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8584 error_at (here, "schedule %<runtime%> does not take "
8585 "a %<chunk_size%> parameter");
8586 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8588 "schedule %<auto%> does not take "
8589 "a %<chunk_size%> parameter");
8590 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8591 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8593 c_parser_error (parser, "expected integer expression");
8595 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8598 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8599 "expected %<,%> or %<)%>");
8601 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8602 OMP_CLAUSE_CHAIN (c) = list;
8606 c_parser_error (parser, "invalid schedule kind");
8607 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8612 shared ( variable-list ) */
8615 c_parser_omp_clause_shared (c_parser *parser, tree list)
8617 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8624 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8628 /* FIXME: Should we allow duplicates? */
8629 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8631 c = build_omp_clause (c_parser_peek_token (parser)->location,
8633 OMP_CLAUSE_CHAIN (c) = list;
8638 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8639 is a bitmask in MASK. Return the list of clauses found; the result
8640 of clause default goes in *pdefault. */
8643 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8646 tree clauses = NULL;
8649 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8652 pragma_omp_clause c_kind;
8654 tree prev = clauses;
8656 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8657 c_parser_consume_token (parser);
8660 here = c_parser_peek_token (parser)->location;
8661 c_kind = c_parser_omp_clause_name (parser);
8665 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8666 clauses = c_parser_omp_clause_collapse (parser, clauses);
8667 c_name = "collapse";
8669 case PRAGMA_OMP_CLAUSE_COPYIN:
8670 clauses = c_parser_omp_clause_copyin (parser, clauses);
8673 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8674 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8675 c_name = "copyprivate";
8677 case PRAGMA_OMP_CLAUSE_DEFAULT:
8678 clauses = c_parser_omp_clause_default (parser, clauses);
8681 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8682 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8683 c_name = "firstprivate";
8685 case PRAGMA_OMP_CLAUSE_IF:
8686 clauses = c_parser_omp_clause_if (parser, clauses);
8689 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8690 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8691 c_name = "lastprivate";
8693 case PRAGMA_OMP_CLAUSE_NOWAIT:
8694 clauses = c_parser_omp_clause_nowait (parser, clauses);
8697 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8698 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8699 c_name = "num_threads";
8701 case PRAGMA_OMP_CLAUSE_ORDERED:
8702 clauses = c_parser_omp_clause_ordered (parser, clauses);
8705 case PRAGMA_OMP_CLAUSE_PRIVATE:
8706 clauses = c_parser_omp_clause_private (parser, clauses);
8709 case PRAGMA_OMP_CLAUSE_REDUCTION:
8710 clauses = c_parser_omp_clause_reduction (parser, clauses);
8711 c_name = "reduction";
8713 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8714 clauses = c_parser_omp_clause_schedule (parser, clauses);
8715 c_name = "schedule";
8717 case PRAGMA_OMP_CLAUSE_SHARED:
8718 clauses = c_parser_omp_clause_shared (parser, clauses);
8721 case PRAGMA_OMP_CLAUSE_UNTIED:
8722 clauses = c_parser_omp_clause_untied (parser, clauses);
8726 c_parser_error (parser, "expected %<#pragma omp%> clause");
8730 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8732 /* Remove the invalid clause(s) from the list to avoid
8733 confusing the rest of the compiler. */
8735 error_at (here, "%qs is not valid for %qs", c_name, where);
8740 c_parser_skip_to_pragma_eol (parser);
8742 return c_finish_omp_clauses (clauses);
8749 In practice, we're also interested in adding the statement to an
8750 outer node. So it is convenient if we work around the fact that
8751 c_parser_statement calls add_stmt. */
8754 c_parser_omp_structured_block (c_parser *parser)
8756 tree stmt = push_stmt_list ();
8757 c_parser_statement (parser);
8758 return pop_stmt_list (stmt);
8762 # pragma omp atomic new-line
8766 x binop= expr | x++ | ++x | x-- | --x
8768 +, *, -, /, &, ^, |, <<, >>
8770 where x is an lvalue expression with scalar type.
8772 LOC is the location of the #pragma token. */
8775 c_parser_omp_atomic (location_t loc, c_parser *parser)
8779 enum tree_code code;
8780 struct c_expr rhs_expr;
8782 c_parser_skip_to_pragma_eol (parser);
8784 lhs = c_parser_unary_expression (parser).value;
8785 lhs = c_fully_fold (lhs, false, NULL);
8786 switch (TREE_CODE (lhs))
8790 c_parser_skip_to_end_of_block_or_statement (parser);
8793 case PREINCREMENT_EXPR:
8794 case POSTINCREMENT_EXPR:
8795 lhs = TREE_OPERAND (lhs, 0);
8797 rhs = integer_one_node;
8800 case PREDECREMENT_EXPR:
8801 case POSTDECREMENT_EXPR:
8802 lhs = TREE_OPERAND (lhs, 0);
8804 rhs = integer_one_node;
8808 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8809 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8810 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8811 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8812 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8813 (TREE_OPERAND (lhs, 1), 0), 0)))
8815 /* Undo effects of boolean_increment for post {in,de}crement. */
8816 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8819 if (TREE_CODE (lhs) == MODIFY_EXPR
8820 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8822 /* Undo effects of boolean_increment. */
8823 if (integer_onep (TREE_OPERAND (lhs, 1)))
8825 /* This is pre or post increment. */
8826 rhs = TREE_OPERAND (lhs, 1);
8827 lhs = TREE_OPERAND (lhs, 0);
8831 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8832 && TREE_OPERAND (lhs, 0)
8833 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8835 /* This is pre or post decrement. */
8836 rhs = TREE_OPERAND (lhs, 1);
8837 lhs = TREE_OPERAND (lhs, 0);
8844 switch (c_parser_peek_token (parser)->type)
8850 code = TRUNC_DIV_EXPR;
8865 code = BIT_AND_EXPR;
8868 code = BIT_IOR_EXPR;
8871 code = BIT_XOR_EXPR;
8874 c_parser_error (parser,
8875 "invalid operator for %<#pragma omp atomic%>");
8879 c_parser_consume_token (parser);
8881 location_t rhs_loc = c_parser_peek_token (parser)->location;
8882 rhs_expr = c_parser_expression (parser);
8883 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8885 rhs = rhs_expr.value;
8886 rhs = c_fully_fold (rhs, false, NULL);
8889 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8890 if (stmt != error_mark_node)
8892 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8897 # pragma omp barrier new-line
8901 c_parser_omp_barrier (c_parser *parser)
8903 location_t loc = c_parser_peek_token (parser)->location;
8904 c_parser_consume_pragma (parser);
8905 c_parser_skip_to_pragma_eol (parser);
8907 c_finish_omp_barrier (loc);
8911 # pragma omp critical [(name)] new-line
8914 LOC is the location of the #pragma itself. */
8917 c_parser_omp_critical (location_t loc, c_parser *parser)
8919 tree stmt, name = NULL;
8921 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8923 c_parser_consume_token (parser);
8924 if (c_parser_next_token_is (parser, CPP_NAME))
8926 name = c_parser_peek_token (parser)->value;
8927 c_parser_consume_token (parser);
8928 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8931 c_parser_error (parser, "expected identifier");
8933 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8934 c_parser_error (parser, "expected %<(%> or end of line");
8935 c_parser_skip_to_pragma_eol (parser);
8937 stmt = c_parser_omp_structured_block (parser);
8938 return c_finish_omp_critical (loc, stmt, name);
8942 # pragma omp flush flush-vars[opt] new-line
8945 ( variable-list ) */
8948 c_parser_omp_flush (c_parser *parser)
8950 location_t loc = c_parser_peek_token (parser)->location;
8951 c_parser_consume_pragma (parser);
8952 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8953 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8954 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8955 c_parser_error (parser, "expected %<(%> or end of line");
8956 c_parser_skip_to_pragma_eol (parser);
8958 c_finish_omp_flush (loc);
8961 /* Parse the restricted form of the for statement allowed by OpenMP.
8962 The real trick here is to determine the loop control variable early
8963 so that we can push a new decl if necessary to make it private.
8964 LOC is the location of the OMP in "#pragma omp". */
8967 c_parser_omp_for_loop (location_t loc,
8968 c_parser *parser, tree clauses, tree *par_clauses)
8970 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8971 tree declv, condv, incrv, initv, ret = NULL;
8972 bool fail = false, open_brace_parsed = false;
8973 int i, collapse = 1, nbraces = 0;
8975 VEC(tree,gc) *for_block = make_tree_vector ();
8977 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8978 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8979 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8981 gcc_assert (collapse >= 1);
8983 declv = make_tree_vec (collapse);
8984 initv = make_tree_vec (collapse);
8985 condv = make_tree_vec (collapse);
8986 incrv = make_tree_vec (collapse);
8988 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8990 c_parser_error (parser, "for statement expected");
8993 for_loc = c_parser_peek_token (parser)->location;
8994 c_parser_consume_token (parser);
8996 for (i = 0; i < collapse; i++)
9000 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9003 /* Parse the initialization declaration or expression. */
9004 if (c_parser_next_token_starts_declaration (parser))
9007 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9008 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9009 decl = check_for_loop_decls (for_loc, flag_isoc99);
9012 if (DECL_INITIAL (decl) == error_mark_node)
9013 decl = error_mark_node;
9016 else if (c_parser_next_token_is (parser, CPP_NAME)
9017 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9019 struct c_expr decl_exp;
9020 struct c_expr init_exp;
9021 location_t init_loc;
9023 decl_exp = c_parser_postfix_expression (parser);
9024 decl = decl_exp.value;
9026 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9028 init_loc = c_parser_peek_token (parser)->location;
9029 init_exp = c_parser_expr_no_commas (parser, NULL);
9030 init_exp = default_function_array_read_conversion (init_loc,
9032 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9033 NOP_EXPR, init_loc, init_exp.value,
9034 init_exp.original_type);
9035 init = c_process_expr_stmt (init_loc, init);
9037 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9042 c_parser_error (parser,
9043 "expected iteration declaration or initialization");
9044 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9050 /* Parse the loop condition. */
9052 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9054 location_t cond_loc = c_parser_peek_token (parser)->location;
9055 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
9057 cond = cond_expr.value;
9058 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9059 cond = c_fully_fold (cond, false, NULL);
9060 switch (cond_expr.original_code)
9068 /* Can't be cond = error_mark_node, because we want to preserve
9069 the location until c_finish_omp_for. */
9070 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9073 protected_set_expr_location (cond, cond_loc);
9075 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9077 /* Parse the increment expression. */
9079 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9081 location_t incr_loc = c_parser_peek_token (parser)->location;
9083 incr = c_process_expr_stmt (incr_loc,
9084 c_parser_expression (parser).value);
9086 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9088 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9092 TREE_VEC_ELT (declv, i) = decl;
9093 TREE_VEC_ELT (initv, i) = init;
9094 TREE_VEC_ELT (condv, i) = cond;
9095 TREE_VEC_ELT (incrv, i) = incr;
9099 if (i == collapse - 1)
9102 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9103 in between the collapsed for loops to be still considered perfectly
9104 nested. Hopefully the final version clarifies this.
9105 For now handle (multiple) {'s and empty statements. */
9108 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9110 c_parser_consume_token (parser);
9113 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9115 c_parser_consume_token (parser);
9119 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9120 c_parser_consume_token (parser);
9123 c_parser_error (parser, "not enough perfectly nested loops");
9126 open_brace_parsed = true;
9136 nbraces += bracecount;
9139 save_break = c_break_label;
9140 c_break_label = size_one_node;
9141 save_cont = c_cont_label;
9142 c_cont_label = NULL_TREE;
9143 body = push_stmt_list ();
9145 if (open_brace_parsed)
9147 location_t here = c_parser_peek_token (parser)->location;
9148 stmt = c_begin_compound_stmt (true);
9149 c_parser_compound_statement_nostart (parser);
9150 add_stmt (c_end_compound_stmt (here, stmt, true));
9153 add_stmt (c_parser_c99_block_statement (parser));
9156 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9157 SET_EXPR_LOCATION (t, loc);
9161 body = pop_stmt_list (body);
9162 c_break_label = save_break;
9163 c_cont_label = save_cont;
9167 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9169 c_parser_consume_token (parser);
9172 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9173 c_parser_consume_token (parser);
9176 c_parser_error (parser, "collapsed loops not perfectly nested");
9179 location_t here = c_parser_peek_token (parser)->location;
9180 stmt = c_begin_compound_stmt (true);
9182 c_parser_compound_statement_nostart (parser);
9183 body = c_end_compound_stmt (here, stmt, true);
9190 /* Only bother calling c_finish_omp_for if we haven't already generated
9191 an error from the initialization parsing. */
9194 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9197 if (par_clauses != NULL)
9200 for (c = par_clauses; *c ; )
9201 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9202 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9203 c = &OMP_CLAUSE_CHAIN (*c);
9206 for (i = 0; i < collapse; i++)
9207 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9210 c = &OMP_CLAUSE_CHAIN (*c);
9211 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9214 "iteration variable %qD should not be firstprivate",
9215 OMP_CLAUSE_DECL (*c));
9216 *c = OMP_CLAUSE_CHAIN (*c);
9220 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9221 change it to shared (decl) in
9222 OMP_PARALLEL_CLAUSES. */
9223 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9224 OMP_CLAUSE_LASTPRIVATE);
9225 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9226 OMP_CLAUSE_CHAIN (l) = clauses;
9228 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9232 OMP_FOR_CLAUSES (stmt) = clauses;
9237 while (!VEC_empty (tree, for_block))
9239 /* FIXME diagnostics: LOC below should be the actual location of
9240 this particular for block. We need to build a list of
9241 locations to go along with FOR_BLOCK. */
9242 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9245 release_tree_vector (for_block);
9250 #pragma omp for for-clause[optseq] new-line
9253 LOC is the location of the #pragma token.
9256 #define OMP_FOR_CLAUSE_MASK \
9257 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9258 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9259 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9260 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9261 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9262 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9263 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9264 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9267 c_parser_omp_for (location_t loc, c_parser *parser)
9269 tree block, clauses, ret;
9271 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9274 block = c_begin_compound_stmt (true);
9275 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9276 block = c_end_compound_stmt (loc, block, true);
9283 # pragma omp master new-line
9286 LOC is the location of the #pragma token.
9290 c_parser_omp_master (location_t loc, c_parser *parser)
9292 c_parser_skip_to_pragma_eol (parser);
9293 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9297 # pragma omp ordered new-line
9300 LOC is the location of the #pragma itself.
9304 c_parser_omp_ordered (location_t loc, c_parser *parser)
9306 c_parser_skip_to_pragma_eol (parser);
9307 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9313 { section-sequence }
9316 section-directive[opt] structured-block
9317 section-sequence section-directive structured-block
9319 SECTIONS_LOC is the location of the #pragma omp sections. */
9322 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9325 bool error_suppress = false;
9328 loc = c_parser_peek_token (parser)->location;
9329 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9331 /* Avoid skipping until the end of the block. */
9332 parser->error = false;
9336 stmt = push_stmt_list ();
9338 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9340 substmt = push_stmt_list ();
9344 c_parser_statement (parser);
9346 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9348 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9350 if (c_parser_next_token_is (parser, CPP_EOF))
9354 substmt = pop_stmt_list (substmt);
9355 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9356 SET_EXPR_LOCATION (substmt, loc);
9362 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9364 if (c_parser_next_token_is (parser, CPP_EOF))
9367 loc = c_parser_peek_token (parser)->location;
9368 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9370 c_parser_consume_pragma (parser);
9371 c_parser_skip_to_pragma_eol (parser);
9372 error_suppress = false;
9374 else if (!error_suppress)
9376 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9377 error_suppress = true;
9380 substmt = c_parser_omp_structured_block (parser);
9381 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9382 SET_EXPR_LOCATION (substmt, loc);
9385 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9386 "expected %<#pragma omp section%> or %<}%>");
9388 substmt = pop_stmt_list (stmt);
9390 stmt = make_node (OMP_SECTIONS);
9391 SET_EXPR_LOCATION (stmt, sections_loc);
9392 TREE_TYPE (stmt) = void_type_node;
9393 OMP_SECTIONS_BODY (stmt) = substmt;
9395 return add_stmt (stmt);
9399 # pragma omp sections sections-clause[optseq] newline
9402 LOC is the location of the #pragma token.
9405 #define OMP_SECTIONS_CLAUSE_MASK \
9406 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9407 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9408 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9409 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9410 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9413 c_parser_omp_sections (location_t loc, c_parser *parser)
9415 tree block, clauses, ret;
9417 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9418 "#pragma omp sections");
9420 block = c_begin_compound_stmt (true);
9421 ret = c_parser_omp_sections_scope (loc, parser);
9423 OMP_SECTIONS_CLAUSES (ret) = clauses;
9424 block = c_end_compound_stmt (loc, block, true);
9431 # pragma parallel parallel-clause new-line
9432 # pragma parallel for parallel-for-clause new-line
9433 # pragma parallel sections parallel-sections-clause new-line
9435 LOC is the location of the #pragma token.
9438 #define OMP_PARALLEL_CLAUSE_MASK \
9439 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9440 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9441 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9442 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9443 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9444 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9445 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9446 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9449 c_parser_omp_parallel (location_t loc, c_parser *parser)
9451 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9452 const char *p_name = "#pragma omp parallel";
9453 tree stmt, clauses, par_clause, ws_clause, block;
9454 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9456 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9458 c_parser_consume_token (parser);
9459 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9460 p_name = "#pragma omp parallel for";
9461 mask |= OMP_FOR_CLAUSE_MASK;
9462 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9464 else if (c_parser_next_token_is (parser, CPP_NAME))
9466 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9467 if (strcmp (p, "sections") == 0)
9469 c_parser_consume_token (parser);
9470 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9471 p_name = "#pragma omp parallel sections";
9472 mask |= OMP_SECTIONS_CLAUSE_MASK;
9473 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9477 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9481 case PRAGMA_OMP_PARALLEL:
9482 block = c_begin_omp_parallel ();
9483 c_parser_statement (parser);
9484 stmt = c_finish_omp_parallel (loc, clauses, block);
9487 case PRAGMA_OMP_PARALLEL_FOR:
9488 block = c_begin_omp_parallel ();
9489 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9490 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9491 stmt = c_finish_omp_parallel (loc, par_clause, block);
9492 OMP_PARALLEL_COMBINED (stmt) = 1;
9495 case PRAGMA_OMP_PARALLEL_SECTIONS:
9496 block = c_begin_omp_parallel ();
9497 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9498 stmt = c_parser_omp_sections_scope (loc, parser);
9500 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9501 stmt = c_finish_omp_parallel (loc, par_clause, block);
9502 OMP_PARALLEL_COMBINED (stmt) = 1;
9513 # pragma omp single single-clause[optseq] new-line
9516 LOC is the location of the #pragma.
9519 #define OMP_SINGLE_CLAUSE_MASK \
9520 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9521 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9522 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9523 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9526 c_parser_omp_single (location_t loc, c_parser *parser)
9528 tree stmt = make_node (OMP_SINGLE);
9529 SET_EXPR_LOCATION (stmt, loc);
9530 TREE_TYPE (stmt) = void_type_node;
9532 OMP_SINGLE_CLAUSES (stmt)
9533 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9534 "#pragma omp single");
9535 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9537 return add_stmt (stmt);
9541 # pragma omp task task-clause[optseq] new-line
9543 LOC is the location of the #pragma.
9546 #define OMP_TASK_CLAUSE_MASK \
9547 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9548 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9549 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9550 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9551 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9552 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9555 c_parser_omp_task (location_t loc, c_parser *parser)
9557 tree clauses, block;
9559 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9560 "#pragma omp task");
9562 block = c_begin_omp_task ();
9563 c_parser_statement (parser);
9564 return c_finish_omp_task (loc, clauses, block);
9568 # pragma omp taskwait new-line
9572 c_parser_omp_taskwait (c_parser *parser)
9574 location_t loc = c_parser_peek_token (parser)->location;
9575 c_parser_consume_pragma (parser);
9576 c_parser_skip_to_pragma_eol (parser);
9578 c_finish_omp_taskwait (loc);
9581 /* Main entry point to parsing most OpenMP pragmas. */
9584 c_parser_omp_construct (c_parser *parser)
9586 enum pragma_kind p_kind;
9590 loc = c_parser_peek_token (parser)->location;
9591 p_kind = c_parser_peek_token (parser)->pragma_kind;
9592 c_parser_consume_pragma (parser);
9596 case PRAGMA_OMP_ATOMIC:
9597 c_parser_omp_atomic (loc, parser);
9599 case PRAGMA_OMP_CRITICAL:
9600 stmt = c_parser_omp_critical (loc, parser);
9602 case PRAGMA_OMP_FOR:
9603 stmt = c_parser_omp_for (loc, parser);
9605 case PRAGMA_OMP_MASTER:
9606 stmt = c_parser_omp_master (loc, parser);
9608 case PRAGMA_OMP_ORDERED:
9609 stmt = c_parser_omp_ordered (loc, parser);
9611 case PRAGMA_OMP_PARALLEL:
9612 stmt = c_parser_omp_parallel (loc, parser);
9614 case PRAGMA_OMP_SECTIONS:
9615 stmt = c_parser_omp_sections (loc, parser);
9617 case PRAGMA_OMP_SINGLE:
9618 stmt = c_parser_omp_single (loc, parser);
9620 case PRAGMA_OMP_TASK:
9621 stmt = c_parser_omp_task (loc, parser);
9628 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9633 # pragma omp threadprivate (variable-list) */
9636 c_parser_omp_threadprivate (c_parser *parser)
9641 c_parser_consume_pragma (parser);
9642 loc = c_parser_peek_token (parser)->location;
9643 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9645 /* Mark every variable in VARS to be assigned thread local storage. */
9646 for (t = vars; t; t = TREE_CHAIN (t))
9648 tree v = TREE_PURPOSE (t);
9650 /* FIXME diagnostics: Ideally we should keep individual
9651 locations for all the variables in the var list to make the
9652 following errors more precise. Perhaps
9653 c_parser_omp_var_list_parens() should construct a list of
9654 locations to go along with the var list. */
9656 /* If V had already been marked threadprivate, it doesn't matter
9657 whether it had been used prior to this point. */
9658 if (TREE_CODE (v) != VAR_DECL)
9659 error_at (loc, "%qD is not a variable", v);
9660 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9661 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9662 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9663 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9664 else if (TREE_TYPE (v) == error_mark_node)
9666 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9667 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9670 if (! DECL_THREAD_LOCAL_P (v))
9672 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9673 /* If rtl has been already set for this var, call
9674 make_decl_rtl once again, so that encode_section_info
9675 has a chance to look at the new decl flags. */
9676 if (DECL_RTL_SET_P (v))
9679 C_DECL_THREADPRIVATE_P (v) = 1;
9683 c_parser_skip_to_pragma_eol (parser);
9687 /* Parse a single source file. */
9692 /* Use local storage to begin. If the first token is a pragma, parse it.
9693 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9694 which will cause garbage collection. */
9697 memset (&tparser, 0, sizeof tparser);
9698 the_parser = &tparser;
9700 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9701 c_parser_pragma_pch_preprocess (&tparser);
9703 the_parser = ggc_alloc_c_parser ();
9704 *the_parser = tparser;
9706 /* Initialize EH, if we've been told to do so. */
9707 if (flag_exceptions)
9708 using_eh_for_cleanups ();
9710 c_parser_translation_unit (the_parser);
9714 #include "gt-c-parser.h"