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)
2399 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2402 if (!specs->type_seen_p)
2404 pedwarn (decl_loc, OPT_pedantic,
2405 "ISO C forbids member declarations with no members");
2406 shadow_tag_warned (specs, pedantic);
2411 /* Support for unnamed structs or unions as members of
2412 structs or unions (which is [a] useful and [b] supports
2416 ret = grokfield (c_parser_peek_token (parser)->location,
2417 build_id_declarator (NULL_TREE), specs,
2420 decl_attributes (&ret, attrs, 0);
2424 pending_xref_error ();
2425 prefix_attrs = specs->attrs;
2426 all_prefix_attrs = prefix_attrs;
2427 specs->attrs = NULL_TREE;
2431 /* Declaring one or more declarators or un-named bit-fields. */
2432 struct c_declarator *declarator;
2434 if (c_parser_next_token_is (parser, CPP_COLON))
2435 declarator = build_id_declarator (NULL_TREE);
2437 declarator = c_parser_declarator (parser, specs->type_seen_p,
2438 C_DTR_NORMAL, &dummy);
2439 if (declarator == NULL)
2441 c_parser_skip_to_end_of_block_or_statement (parser);
2444 if (c_parser_next_token_is (parser, CPP_COLON)
2445 || c_parser_next_token_is (parser, CPP_COMMA)
2446 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2447 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2448 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2450 tree postfix_attrs = NULL_TREE;
2451 tree width = NULL_TREE;
2453 if (c_parser_next_token_is (parser, CPP_COLON))
2455 c_parser_consume_token (parser);
2456 width = c_parser_expr_no_commas (parser, NULL).value;
2458 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2459 postfix_attrs = c_parser_attributes (parser);
2460 d = grokfield (c_parser_peek_token (parser)->location,
2461 declarator, specs, width, &all_prefix_attrs);
2462 decl_attributes (&d, chainon (postfix_attrs,
2463 all_prefix_attrs), 0);
2464 DECL_CHAIN (d) = decls;
2466 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2467 all_prefix_attrs = chainon (c_parser_attributes (parser),
2470 all_prefix_attrs = prefix_attrs;
2471 if (c_parser_next_token_is (parser, CPP_COMMA))
2472 c_parser_consume_token (parser);
2473 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2474 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2476 /* Semicolon consumed in caller. */
2481 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2487 c_parser_error (parser,
2488 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2489 "%<__attribute__%>");
2496 /* Parse a typeof specifier (a GNU extension).
2499 typeof ( expression )
2500 typeof ( type-name )
2503 static struct c_typespec
2504 c_parser_typeof_specifier (c_parser *parser)
2506 struct c_typespec ret;
2507 ret.kind = ctsk_typeof;
2508 ret.spec = error_mark_node;
2509 ret.expr = NULL_TREE;
2510 ret.expr_const_operands = true;
2511 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2512 c_parser_consume_token (parser);
2513 c_inhibit_evaluation_warnings++;
2515 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2517 c_inhibit_evaluation_warnings--;
2521 if (c_parser_next_token_starts_typename (parser))
2523 struct c_type_name *type = c_parser_type_name (parser);
2524 c_inhibit_evaluation_warnings--;
2528 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2529 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2535 location_t here = c_parser_peek_token (parser)->location;
2536 struct c_expr expr = c_parser_expression (parser);
2537 c_inhibit_evaluation_warnings--;
2539 if (TREE_CODE (expr.value) == COMPONENT_REF
2540 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2541 error_at (here, "%<typeof%> applied to a bit-field");
2542 mark_exp_read (expr.value);
2543 ret.spec = TREE_TYPE (expr.value);
2544 if (c_dialect_objc()
2545 && ret.spec != error_mark_node
2546 && lookup_attribute ("objc_volatilized", TYPE_ATTRIBUTES (ret.spec)))
2547 ret.spec = build_qualified_type
2548 (ret.spec, (TYPE_QUALS (ret.spec) & ~TYPE_QUAL_VOLATILE));
2549 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2550 /* This is returned with the type so that when the type is
2551 evaluated, this can be evaluated. */
2553 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2554 pop_maybe_used (was_vm);
2556 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2560 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2561 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2562 be redeclared; otherwise it may not. KIND indicates which kind of
2563 declarator is wanted. Returns a valid declarator except in the
2564 case of a syntax error in which case NULL is returned. *SEEN_ID is
2565 set to true if an identifier being declared is seen; this is used
2566 to diagnose bad forms of abstract array declarators and to
2567 determine whether an identifier list is syntactically permitted.
2570 pointer[opt] direct-declarator
2574 ( attributes[opt] declarator )
2575 direct-declarator array-declarator
2576 direct-declarator ( parameter-type-list )
2577 direct-declarator ( identifier-list[opt] )
2580 * type-qualifier-list[opt]
2581 * type-qualifier-list[opt] pointer
2583 type-qualifier-list:
2586 type-qualifier-list type-qualifier
2587 type-qualifier-list attributes
2589 parameter-type-list:
2591 parameter-list , ...
2594 parameter-declaration
2595 parameter-list , parameter-declaration
2597 parameter-declaration:
2598 declaration-specifiers declarator attributes[opt]
2599 declaration-specifiers abstract-declarator[opt] attributes[opt]
2603 identifier-list , identifier
2605 abstract-declarator:
2607 pointer[opt] direct-abstract-declarator
2609 direct-abstract-declarator:
2610 ( attributes[opt] abstract-declarator )
2611 direct-abstract-declarator[opt] array-declarator
2612 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2617 direct-declarator ( parameter-forward-declarations
2618 parameter-type-list[opt] )
2620 direct-abstract-declarator:
2621 direct-abstract-declarator[opt] ( parameter-forward-declarations
2622 parameter-type-list[opt] )
2624 parameter-forward-declarations:
2626 parameter-forward-declarations parameter-list ;
2628 The uses of attributes shown above are GNU extensions.
2630 Some forms of array declarator are not included in C99 in the
2631 syntax for abstract declarators; these are disallowed elsewhere.
2632 This may be a defect (DR#289).
2634 This function also accepts an omitted abstract declarator as being
2635 an abstract declarator, although not part of the formal syntax. */
2637 static struct c_declarator *
2638 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2641 /* Parse any initial pointer part. */
2642 if (c_parser_next_token_is (parser, CPP_MULT))
2644 struct c_declspecs *quals_attrs = build_null_declspecs ();
2645 struct c_declarator *inner;
2646 c_parser_consume_token (parser);
2647 c_parser_declspecs (parser, quals_attrs, false, false, true);
2648 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2652 return make_pointer_declarator (quals_attrs, inner);
2654 /* Now we have a direct declarator, direct abstract declarator or
2655 nothing (which counts as a direct abstract declarator here). */
2656 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2659 /* Parse a direct declarator or direct abstract declarator; arguments
2660 as c_parser_declarator. */
2662 static struct c_declarator *
2663 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2666 /* The direct declarator must start with an identifier (possibly
2667 omitted) or a parenthesized declarator (possibly abstract). In
2668 an ordinary declarator, initial parentheses must start a
2669 parenthesized declarator. In an abstract declarator or parameter
2670 declarator, they could start a parenthesized declarator or a
2671 parameter list. To tell which, the open parenthesis and any
2672 following attributes must be read. If a declaration specifier
2673 follows, then it is a parameter list; if the specifier is a
2674 typedef name, there might be an ambiguity about redeclaring it,
2675 which is resolved in the direction of treating it as a typedef
2676 name. If a close parenthesis follows, it is also an empty
2677 parameter list, as the syntax does not permit empty abstract
2678 declarators. Otherwise, it is a parenthesized declarator (in
2679 which case the analysis may be repeated inside it, recursively).
2681 ??? There is an ambiguity in a parameter declaration "int
2682 (__attribute__((foo)) x)", where x is not a typedef name: it
2683 could be an abstract declarator for a function, or declare x with
2684 parentheses. The proper resolution of this ambiguity needs
2685 documenting. At present we follow an accident of the old
2686 parser's implementation, whereby the first parameter must have
2687 some declaration specifiers other than just attributes. Thus as
2688 a parameter declaration it is treated as a parenthesized
2689 parameter named x, and as an abstract declarator it is
2692 ??? Also following the old parser, attributes inside an empty
2693 parameter list are ignored, making it a list not yielding a
2694 prototype, rather than giving an error or making it have one
2695 parameter with implicit type int.
2697 ??? Also following the old parser, typedef names may be
2698 redeclared in declarators, but not Objective-C class names. */
2700 if (kind != C_DTR_ABSTRACT
2701 && c_parser_next_token_is (parser, CPP_NAME)
2703 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2704 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2705 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2707 struct c_declarator *inner
2708 = build_id_declarator (c_parser_peek_token (parser)->value);
2710 inner->id_loc = c_parser_peek_token (parser)->location;
2711 c_parser_consume_token (parser);
2712 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2715 if (kind != C_DTR_NORMAL
2716 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2718 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2719 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2722 /* Either we are at the end of an abstract declarator, or we have
2725 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2728 struct c_declarator *inner;
2729 c_parser_consume_token (parser);
2730 attrs = c_parser_attributes (parser);
2731 if (kind != C_DTR_NORMAL
2732 && (c_parser_next_token_starts_declspecs (parser)
2733 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2735 struct c_arg_info *args
2736 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2743 = build_function_declarator (args,
2744 build_id_declarator (NULL_TREE));
2745 return c_parser_direct_declarator_inner (parser, *seen_id,
2749 /* A parenthesized declarator. */
2750 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2751 if (inner != NULL && attrs != NULL)
2752 inner = build_attrs_declarator (attrs, inner);
2753 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2755 c_parser_consume_token (parser);
2759 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2763 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2770 if (kind == C_DTR_NORMAL)
2772 c_parser_error (parser, "expected identifier or %<(%>");
2776 return build_id_declarator (NULL_TREE);
2780 /* Parse part of a direct declarator or direct abstract declarator,
2781 given that some (in INNER) has already been parsed; ID_PRESENT is
2782 true if an identifier is present, false for an abstract
2785 static struct c_declarator *
2786 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2787 struct c_declarator *inner)
2789 /* Parse a sequence of array declarators and parameter lists. */
2790 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2792 location_t brace_loc = c_parser_peek_token (parser)->location;
2793 struct c_declarator *declarator;
2794 struct c_declspecs *quals_attrs = build_null_declspecs ();
2798 c_parser_consume_token (parser);
2799 c_parser_declspecs (parser, quals_attrs, false, false, true);
2800 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2802 c_parser_consume_token (parser);
2803 if (static_seen && !quals_attrs->declspecs_seen_p)
2804 c_parser_declspecs (parser, quals_attrs, false, false, true);
2805 if (!quals_attrs->declspecs_seen_p)
2807 /* If "static" is present, there must be an array dimension.
2808 Otherwise, there may be a dimension, "*", or no
2813 dimen = c_parser_expr_no_commas (parser, NULL).value;
2817 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2822 else if (c_parser_next_token_is (parser, CPP_MULT))
2824 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2828 c_parser_consume_token (parser);
2833 dimen = c_parser_expr_no_commas (parser, NULL).value;
2839 dimen = c_parser_expr_no_commas (parser, NULL).value;
2842 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2843 c_parser_consume_token (parser);
2846 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2851 mark_exp_read (dimen);
2852 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2853 static_seen, star_seen);
2854 if (declarator == NULL)
2856 inner = set_array_declarator_inner (declarator, inner);
2857 return c_parser_direct_declarator_inner (parser, id_present, inner);
2859 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2862 struct c_arg_info *args;
2863 c_parser_consume_token (parser);
2864 attrs = c_parser_attributes (parser);
2865 args = c_parser_parms_declarator (parser, id_present, attrs);
2870 inner = build_function_declarator (args, inner);
2871 return c_parser_direct_declarator_inner (parser, id_present, inner);
2877 /* Parse a parameter list or identifier list, including the closing
2878 parenthesis but not the opening one. ATTRS are the attributes at
2879 the start of the list. ID_LIST_OK is true if an identifier list is
2880 acceptable; such a list must not have attributes at the start. */
2882 static struct c_arg_info *
2883 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2886 declare_parm_level ();
2887 /* If the list starts with an identifier, it is an identifier list.
2888 Otherwise, it is either a prototype list or an empty list. */
2891 && c_parser_next_token_is (parser, CPP_NAME)
2892 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2894 tree list = NULL_TREE, *nextp = &list;
2895 while (c_parser_next_token_is (parser, CPP_NAME)
2896 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2898 *nextp = build_tree_list (NULL_TREE,
2899 c_parser_peek_token (parser)->value);
2900 nextp = & TREE_CHAIN (*nextp);
2901 c_parser_consume_token (parser);
2902 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2904 c_parser_consume_token (parser);
2905 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2907 c_parser_error (parser, "expected identifier");
2911 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2913 struct c_arg_info *ret = build_arg_info ();
2915 c_parser_consume_token (parser);
2921 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2929 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2935 /* Parse a parameter list (possibly empty), including the closing
2936 parenthesis but not the opening one. ATTRS are the attributes at
2937 the start of the list. */
2939 static struct c_arg_info *
2940 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2942 bool bad_parm = false;
2943 /* ??? Following the old parser, forward parameter declarations may
2944 use abstract declarators, and if no real parameter declarations
2945 follow the forward declarations then this is not diagnosed. Also
2946 note as above that attributes are ignored as the only contents of
2947 the parentheses, or as the only contents after forward
2949 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2951 struct c_arg_info *ret = build_arg_info ();
2952 c_parser_consume_token (parser);
2955 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2957 struct c_arg_info *ret = build_arg_info ();
2958 /* Suppress -Wold-style-definition for this case. */
2959 ret->types = error_mark_node;
2960 error_at (c_parser_peek_token (parser)->location,
2961 "ISO C requires a named argument before %<...%>");
2962 c_parser_consume_token (parser);
2963 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2965 c_parser_consume_token (parser);
2970 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2975 /* Nonempty list of parameters, either terminated with semicolon
2976 (forward declarations; recurse) or with close parenthesis (normal
2977 function) or with ", ... )" (variadic function). */
2980 /* Parse a parameter. */
2981 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2986 push_parm_decl (parm);
2987 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2990 c_parser_consume_token (parser);
2991 mark_forward_parm_decls ();
2992 new_attrs = c_parser_attributes (parser);
2993 return c_parser_parms_list_declarator (parser, new_attrs);
2995 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2997 c_parser_consume_token (parser);
3000 get_pending_sizes ();
3004 return get_parm_info (false);
3006 if (!c_parser_require (parser, CPP_COMMA,
3007 "expected %<;%>, %<,%> or %<)%>"))
3009 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3010 get_pending_sizes ();
3013 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3015 c_parser_consume_token (parser);
3016 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3018 c_parser_consume_token (parser);
3021 get_pending_sizes ();
3025 return get_parm_info (true);
3029 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3031 get_pending_sizes ();
3038 /* Parse a parameter declaration. ATTRS are the attributes at the
3039 start of the declaration if it is the first parameter. */
3041 static struct c_parm *
3042 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3044 struct c_declspecs *specs;
3045 struct c_declarator *declarator;
3047 tree postfix_attrs = NULL_TREE;
3049 if (!c_parser_next_token_starts_declspecs (parser))
3051 c_token *token = c_parser_peek_token (parser);
3054 c_parser_set_source_position_from_token (token);
3055 if (token->type == CPP_NAME
3056 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
3057 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
3059 error ("unknown type name %qE", token->value);
3060 parser->error = true;
3062 /* ??? In some Objective-C cases '...' isn't applicable so there
3063 should be a different message. */
3065 c_parser_error (parser,
3066 "expected declaration specifiers or %<...%>");
3067 c_parser_skip_to_end_of_parameter (parser);
3070 specs = build_null_declspecs ();
3073 declspecs_add_attrs (specs, attrs);
3076 c_parser_declspecs (parser, specs, true, true, true);
3077 finish_declspecs (specs);
3078 pending_xref_error ();
3079 prefix_attrs = specs->attrs;
3080 specs->attrs = NULL_TREE;
3081 declarator = c_parser_declarator (parser, specs->type_seen_p,
3082 C_DTR_PARM, &dummy);
3083 if (declarator == NULL)
3085 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3088 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3089 postfix_attrs = c_parser_attributes (parser);
3090 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3094 /* Parse a string literal in an asm expression. It should not be
3095 translated, and wide string literals are an error although
3096 permitted by the syntax. This is a GNU extension.
3101 ??? At present, following the old parser, the caller needs to have
3102 set lex_untranslated_string to 1. It would be better to follow the
3103 C++ parser rather than using this kludge. */
3106 c_parser_asm_string_literal (c_parser *parser)
3109 if (c_parser_next_token_is (parser, CPP_STRING))
3111 str = c_parser_peek_token (parser)->value;
3112 c_parser_consume_token (parser);
3114 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3116 error_at (c_parser_peek_token (parser)->location,
3117 "wide string literal in %<asm%>");
3118 str = build_string (1, "");
3119 c_parser_consume_token (parser);
3123 c_parser_error (parser, "expected string literal");
3129 /* Parse a simple asm expression. This is used in restricted
3130 contexts, where a full expression with inputs and outputs does not
3131 make sense. This is a GNU extension.
3134 asm ( asm-string-literal )
3138 c_parser_simple_asm_expr (c_parser *parser)
3141 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3142 /* ??? Follow the C++ parser rather than using the
3143 lex_untranslated_string kludge. */
3144 parser->lex_untranslated_string = true;
3145 c_parser_consume_token (parser);
3146 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3148 parser->lex_untranslated_string = false;
3151 str = c_parser_asm_string_literal (parser);
3152 parser->lex_untranslated_string = false;
3153 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3155 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3161 /* Parse (possibly empty) attributes. This is a GNU extension.
3165 attributes attribute
3168 __attribute__ ( ( attribute-list ) )
3172 attribute_list , attrib
3177 any-word ( identifier )
3178 any-word ( identifier , nonempty-expr-list )
3179 any-word ( expr-list )
3181 where the "identifier" must not be declared as a type, and
3182 "any-word" may be any identifier (including one declared as a
3183 type), a reserved word storage class specifier, type specifier or
3184 type qualifier. ??? This still leaves out most reserved keywords
3185 (following the old parser), shouldn't we include them, and why not
3186 allow identifiers declared as types to start the arguments? */
3189 c_parser_attributes (c_parser *parser)
3191 tree attrs = NULL_TREE;
3192 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3194 /* ??? Follow the C++ parser rather than using the
3195 lex_untranslated_string kludge. */
3196 parser->lex_untranslated_string = true;
3197 c_parser_consume_token (parser);
3198 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3200 parser->lex_untranslated_string = false;
3203 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3205 parser->lex_untranslated_string = false;
3206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3209 /* Parse the attribute list. */
3210 while (c_parser_next_token_is (parser, CPP_COMMA)
3211 || c_parser_next_token_is (parser, CPP_NAME)
3212 || c_parser_next_token_is (parser, CPP_KEYWORD))
3214 tree attr, attr_name, attr_args;
3215 VEC(tree,gc) *expr_list;
3216 if (c_parser_next_token_is (parser, CPP_COMMA))
3218 c_parser_consume_token (parser);
3221 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3223 /* ??? See comment above about what keywords are
3226 switch (c_parser_peek_token (parser)->keyword)
3264 /* Accept __attribute__((__const)) as __attribute__((const))
3267 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3270 attr_name = c_parser_peek_token (parser)->value;
3271 c_parser_consume_token (parser);
3272 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3274 attr = build_tree_list (attr_name, NULL_TREE);
3275 attrs = chainon (attrs, attr);
3278 c_parser_consume_token (parser);
3279 /* Parse the attribute contents. If they start with an
3280 identifier which is followed by a comma or close
3281 parenthesis, then the arguments start with that
3282 identifier; otherwise they are an expression list.
3283 In objective-c the identifier may be a classname. */
3284 if (c_parser_next_token_is (parser, CPP_NAME)
3285 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3286 || (c_dialect_objc ()
3287 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3288 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3289 || (c_parser_peek_2nd_token (parser)->type
3290 == CPP_CLOSE_PAREN)))
3292 tree arg1 = c_parser_peek_token (parser)->value;
3293 c_parser_consume_token (parser);
3294 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3295 attr_args = build_tree_list (NULL_TREE, arg1);
3299 c_parser_consume_token (parser);
3300 expr_list = c_parser_expr_list (parser, false, true, NULL);
3301 tree_list = build_tree_list_vec (expr_list);
3302 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3303 release_tree_vector (expr_list);
3308 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3309 attr_args = NULL_TREE;
3312 expr_list = c_parser_expr_list (parser, false, true, NULL);
3313 attr_args = build_tree_list_vec (expr_list);
3314 release_tree_vector (expr_list);
3317 attr = build_tree_list (attr_name, attr_args);
3318 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3319 c_parser_consume_token (parser);
3322 parser->lex_untranslated_string = false;
3323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3327 attrs = chainon (attrs, attr);
3329 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3330 c_parser_consume_token (parser);
3333 parser->lex_untranslated_string = false;
3334 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3338 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3339 c_parser_consume_token (parser);
3342 parser->lex_untranslated_string = false;
3343 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3347 parser->lex_untranslated_string = false;
3352 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3355 specifier-qualifier-list abstract-declarator[opt]
3358 static struct c_type_name *
3359 c_parser_type_name (c_parser *parser)
3361 struct c_declspecs *specs = build_null_declspecs ();
3362 struct c_declarator *declarator;
3363 struct c_type_name *ret;
3365 c_parser_declspecs (parser, specs, false, true, true);
3366 if (!specs->declspecs_seen_p)
3368 c_parser_error (parser, "expected specifier-qualifier-list");
3371 pending_xref_error ();
3372 finish_declspecs (specs);
3373 declarator = c_parser_declarator (parser, specs->type_seen_p,
3374 C_DTR_ABSTRACT, &dummy);
3375 if (declarator == NULL)
3377 ret = XOBNEW (&parser_obstack, struct c_type_name);
3379 ret->declarator = declarator;
3383 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3386 assignment-expression
3387 { initializer-list }
3388 { initializer-list , }
3391 designation[opt] initializer
3392 initializer-list , designation[opt] initializer
3399 designator-list designator
3406 [ constant-expression ]
3418 [ constant-expression ... constant-expression ]
3420 Any expression without commas is accepted in the syntax for the
3421 constant-expressions, with non-constant expressions rejected later.
3423 This function is only used for top-level initializers; for nested
3424 ones, see c_parser_initval. */
3426 static struct c_expr
3427 c_parser_initializer (c_parser *parser)
3429 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3430 return c_parser_braced_init (parser, NULL_TREE, false);
3434 location_t loc = c_parser_peek_token (parser)->location;
3435 ret = c_parser_expr_no_commas (parser, NULL);
3436 if (TREE_CODE (ret.value) != STRING_CST
3437 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3438 ret = default_function_array_read_conversion (loc, ret);
3443 /* Parse a braced initializer list. TYPE is the type specified for a
3444 compound literal, and NULL_TREE for other initializers and for
3445 nested braced lists. NESTED_P is true for nested braced lists,
3446 false for the list of a compound literal or the list that is the
3447 top-level initializer in a declaration. */
3449 static struct c_expr
3450 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3453 struct obstack braced_init_obstack;
3454 location_t brace_loc = c_parser_peek_token (parser)->location;
3455 gcc_obstack_init (&braced_init_obstack);
3456 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3457 c_parser_consume_token (parser);
3459 push_init_level (0, &braced_init_obstack);
3461 really_start_incremental_init (type);
3462 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3464 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3468 /* Parse a non-empty initializer list, possibly with a trailing
3472 c_parser_initelt (parser, &braced_init_obstack);
3475 if (c_parser_next_token_is (parser, CPP_COMMA))
3476 c_parser_consume_token (parser);
3479 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3483 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3485 ret.value = error_mark_node;
3486 ret.original_code = ERROR_MARK;
3487 ret.original_type = NULL;
3488 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3489 pop_init_level (0, &braced_init_obstack);
3490 obstack_free (&braced_init_obstack, NULL);
3493 c_parser_consume_token (parser);
3494 ret = pop_init_level (0, &braced_init_obstack);
3495 obstack_free (&braced_init_obstack, NULL);
3499 /* Parse a nested initializer, including designators. */
3502 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3504 /* Parse any designator or designator list. A single array
3505 designator may have the subsequent "=" omitted in GNU C, but a
3506 longer list or a structure member designator may not. */
3507 if (c_parser_next_token_is (parser, CPP_NAME)
3508 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3510 /* Old-style structure member designator. */
3511 set_init_label (c_parser_peek_token (parser)->value,
3512 braced_init_obstack);
3513 /* Use the colon as the error location. */
3514 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3515 "obsolete use of designated initializer with %<:%>");
3516 c_parser_consume_token (parser);
3517 c_parser_consume_token (parser);
3521 /* des_seen is 0 if there have been no designators, 1 if there
3522 has been a single array designator and 2 otherwise. */
3524 /* Location of a designator. */
3525 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3526 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3527 || c_parser_next_token_is (parser, CPP_DOT))
3529 int des_prev = des_seen;
3531 des_loc = c_parser_peek_token (parser)->location;
3534 if (c_parser_next_token_is (parser, CPP_DOT))
3537 c_parser_consume_token (parser);
3538 if (c_parser_next_token_is (parser, CPP_NAME))
3540 set_init_label (c_parser_peek_token (parser)->value,
3541 braced_init_obstack);
3542 c_parser_consume_token (parser);
3547 init.value = error_mark_node;
3548 init.original_code = ERROR_MARK;
3549 init.original_type = NULL;
3550 c_parser_error (parser, "expected identifier");
3551 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3552 process_init_element (init, false, braced_init_obstack);
3559 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3560 /* ??? Following the old parser, [ objc-receiver
3561 objc-message-args ] is accepted as an initializer,
3562 being distinguished from a designator by what follows
3563 the first assignment expression inside the square
3564 brackets, but after a first array designator a
3565 subsequent square bracket is for Objective-C taken to
3566 start an expression, using the obsolete form of
3567 designated initializer without '=', rather than
3568 possibly being a second level of designation: in LALR
3569 terms, the '[' is shifted rather than reducing
3570 designator to designator-list. */
3571 if (des_prev == 1 && c_dialect_objc ())
3573 des_seen = des_prev;
3576 if (des_prev == 0 && c_dialect_objc ())
3578 /* This might be an array designator or an
3579 Objective-C message expression. If the former,
3580 continue parsing here; if the latter, parse the
3581 remainder of the initializer given the starting
3582 primary-expression. ??? It might make sense to
3583 distinguish when des_prev == 1 as well; see
3584 previous comment. */
3586 struct c_expr mexpr;
3587 c_parser_consume_token (parser);
3588 if (c_parser_peek_token (parser)->type == CPP_NAME
3589 && ((c_parser_peek_token (parser)->id_kind
3591 || (c_parser_peek_token (parser)->id_kind
3592 == C_ID_CLASSNAME)))
3594 /* Type name receiver. */
3595 tree id = c_parser_peek_token (parser)->value;
3596 c_parser_consume_token (parser);
3597 rec = objc_get_class_reference (id);
3598 goto parse_message_args;
3600 first = c_parser_expr_no_commas (parser, NULL).value;
3601 mark_exp_read (first);
3602 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3603 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3604 goto array_desig_after_first;
3605 /* Expression receiver. So far only one part
3606 without commas has been parsed; there might be
3607 more of the expression. */
3609 while (c_parser_next_token_is (parser, CPP_COMMA))
3612 location_t comma_loc, exp_loc;
3613 comma_loc = c_parser_peek_token (parser)->location;
3614 c_parser_consume_token (parser);
3615 exp_loc = c_parser_peek_token (parser)->location;
3616 next = c_parser_expr_no_commas (parser, NULL);
3617 next = default_function_array_read_conversion (exp_loc,
3619 rec = build_compound_expr (comma_loc, rec, next.value);
3622 /* Now parse the objc-message-args. */
3623 args = c_parser_objc_message_args (parser);
3624 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3627 = objc_build_message_expr (build_tree_list (rec, args));
3628 mexpr.original_code = ERROR_MARK;
3629 mexpr.original_type = NULL;
3630 /* Now parse and process the remainder of the
3631 initializer, starting with this message
3632 expression as a primary-expression. */
3633 c_parser_initval (parser, &mexpr, braced_init_obstack);
3636 c_parser_consume_token (parser);
3637 first = c_parser_expr_no_commas (parser, NULL).value;
3638 mark_exp_read (first);
3639 array_desig_after_first:
3640 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3642 ellipsis_loc = c_parser_peek_token (parser)->location;
3643 c_parser_consume_token (parser);
3644 second = c_parser_expr_no_commas (parser, NULL).value;
3645 mark_exp_read (second);
3649 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3651 c_parser_consume_token (parser);
3652 set_init_index (first, second, braced_init_obstack);
3654 pedwarn (ellipsis_loc, OPT_pedantic,
3655 "ISO C forbids specifying range of elements to initialize");
3658 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3664 if (c_parser_next_token_is (parser, CPP_EQ))
3667 pedwarn (des_loc, OPT_pedantic,
3668 "ISO C90 forbids specifying subobject to initialize");
3669 c_parser_consume_token (parser);
3674 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3675 "obsolete use of designated initializer without %<=%>");
3679 init.value = error_mark_node;
3680 init.original_code = ERROR_MARK;
3681 init.original_type = NULL;
3682 c_parser_error (parser, "expected %<=%>");
3683 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3684 process_init_element (init, false, braced_init_obstack);
3690 c_parser_initval (parser, NULL, braced_init_obstack);
3693 /* Parse a nested initializer; as c_parser_initializer but parses
3694 initializers within braced lists, after any designators have been
3695 applied. If AFTER is not NULL then it is an Objective-C message
3696 expression which is the primary-expression starting the
3700 c_parser_initval (c_parser *parser, struct c_expr *after,
3701 struct obstack * braced_init_obstack)
3704 gcc_assert (!after || c_dialect_objc ());
3705 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3706 init = c_parser_braced_init (parser, NULL_TREE, true);
3709 location_t loc = c_parser_peek_token (parser)->location;
3710 init = c_parser_expr_no_commas (parser, after);
3711 if (init.value != NULL_TREE
3712 && TREE_CODE (init.value) != STRING_CST
3713 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3714 init = default_function_array_read_conversion (loc, init);
3716 process_init_element (init, false, braced_init_obstack);
3719 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3723 { block-item-list[opt] }
3724 { label-declarations block-item-list }
3728 block-item-list block-item
3740 { label-declarations block-item-list }
3743 __extension__ nested-declaration
3744 nested-function-definition
3748 label-declarations label-declaration
3751 __label__ identifier-list ;
3753 Allowing the mixing of declarations and code is new in C99. The
3754 GNU syntax also permits (not shown above) labels at the end of
3755 compound statements, which yield an error. We don't allow labels
3756 on declarations; this might seem like a natural extension, but
3757 there would be a conflict between attributes on the label and
3758 prefix attributes on the declaration. ??? The syntax follows the
3759 old parser in requiring something after label declarations.
3760 Although they are erroneous if the labels declared aren't defined,
3761 is it useful for the syntax to be this way?
3773 c_parser_compound_statement (c_parser *parser)
3776 location_t brace_loc;
3777 brace_loc = c_parser_peek_token (parser)->location;
3778 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3780 /* Ensure a scope is entered and left anyway to avoid confusion
3781 if we have just prepared to enter a function body. */
3782 stmt = c_begin_compound_stmt (true);
3783 c_end_compound_stmt (brace_loc, stmt, true);
3784 return error_mark_node;
3786 stmt = c_begin_compound_stmt (true);
3787 c_parser_compound_statement_nostart (parser);
3788 return c_end_compound_stmt (brace_loc, stmt, true);
3791 /* Parse a compound statement except for the opening brace. This is
3792 used for parsing both compound statements and statement expressions
3793 (which follow different paths to handling the opening). */
3796 c_parser_compound_statement_nostart (c_parser *parser)
3798 bool last_stmt = false;
3799 bool last_label = false;
3800 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3801 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3802 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3804 c_parser_consume_token (parser);
3807 mark_valid_location_for_stdc_pragma (true);
3808 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3810 /* Read zero or more forward-declarations for labels that nested
3811 functions can jump to. */
3812 mark_valid_location_for_stdc_pragma (false);
3813 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3815 label_loc = c_parser_peek_token (parser)->location;
3816 c_parser_consume_token (parser);
3817 /* Any identifiers, including those declared as type names,
3822 if (c_parser_next_token_is_not (parser, CPP_NAME))
3824 c_parser_error (parser, "expected identifier");
3828 = declare_label (c_parser_peek_token (parser)->value);
3829 C_DECLARED_LABEL_FLAG (label) = 1;
3830 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3831 c_parser_consume_token (parser);
3832 if (c_parser_next_token_is (parser, CPP_COMMA))
3833 c_parser_consume_token (parser);
3837 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3839 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3841 /* We must now have at least one statement, label or declaration. */
3842 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3844 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3845 c_parser_error (parser, "expected declaration or statement");
3846 c_parser_consume_token (parser);
3849 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3851 location_t loc = c_parser_peek_token (parser)->location;
3852 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3853 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3854 || (c_parser_next_token_is (parser, CPP_NAME)
3855 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3857 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3858 label_loc = c_parser_peek_2nd_token (parser)->location;
3860 label_loc = c_parser_peek_token (parser)->location;
3863 mark_valid_location_for_stdc_pragma (false);
3864 c_parser_label (parser);
3866 else if (!last_label
3867 && c_parser_next_token_starts_declaration (parser))
3870 mark_valid_location_for_stdc_pragma (false);
3871 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
3874 (pedantic && !flag_isoc99)
3876 : OPT_Wdeclaration_after_statement,
3877 "ISO C90 forbids mixed declarations and code");
3880 else if (!last_label
3881 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3883 /* __extension__ can start a declaration, but is also an
3884 unary operator that can start an expression. Consume all
3885 but the last of a possible series of __extension__ to
3887 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3888 && (c_parser_peek_2nd_token (parser)->keyword
3890 c_parser_consume_token (parser);
3891 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3894 ext = disable_extension_diagnostics ();
3895 c_parser_consume_token (parser);
3897 mark_valid_location_for_stdc_pragma (false);
3898 c_parser_declaration_or_fndef (parser, true, true, true, true,
3900 /* Following the old parser, __extension__ does not
3901 disable this diagnostic. */
3902 restore_extension_diagnostics (ext);
3904 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3906 : OPT_Wdeclaration_after_statement,
3907 "ISO C90 forbids mixed declarations and code");
3913 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3915 /* External pragmas, and some omp pragmas, are not associated
3916 with regular c code, and so are not to be considered statements
3917 syntactically. This ensures that the user doesn't put them
3918 places that would turn into syntax errors if the directive
3920 if (c_parser_pragma (parser, pragma_compound))
3921 last_label = false, last_stmt = true;
3923 else if (c_parser_next_token_is (parser, CPP_EOF))
3925 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3926 c_parser_error (parser, "expected declaration or statement");
3929 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3931 if (parser->in_if_block)
3933 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3934 error_at (loc, """expected %<}%> before %<else%>");
3939 error_at (loc, "%<else%> without a previous %<if%>");
3940 c_parser_consume_token (parser);
3949 mark_valid_location_for_stdc_pragma (false);
3950 c_parser_statement_after_labels (parser);
3953 parser->error = false;
3956 error_at (label_loc, "label at end of compound statement");
3957 c_parser_consume_token (parser);
3958 /* Restore the value we started with. */
3959 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3962 /* Parse a label (C90 6.6.1, C99 6.8.1).
3965 identifier : attributes[opt]
3966 case constant-expression :
3972 case constant-expression ... constant-expression :
3974 The use of attributes on labels is a GNU extension. The syntax in
3975 GNU C accepts any expressions without commas, non-constant
3976 expressions being rejected later. */
3979 c_parser_label (c_parser *parser)
3981 location_t loc1 = c_parser_peek_token (parser)->location;
3982 tree label = NULL_TREE;
3983 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3986 c_parser_consume_token (parser);
3987 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3988 if (c_parser_next_token_is (parser, CPP_COLON))
3990 c_parser_consume_token (parser);
3991 label = do_case (loc1, exp1, NULL_TREE);
3993 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3995 c_parser_consume_token (parser);
3996 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3997 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3998 label = do_case (loc1, exp1, exp2);
4001 c_parser_error (parser, "expected %<:%> or %<...%>");
4003 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4005 c_parser_consume_token (parser);
4006 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4007 label = do_case (loc1, NULL_TREE, NULL_TREE);
4011 tree name = c_parser_peek_token (parser)->value;
4014 location_t loc2 = c_parser_peek_token (parser)->location;
4015 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4016 c_parser_consume_token (parser);
4017 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4018 c_parser_consume_token (parser);
4019 attrs = c_parser_attributes (parser);
4020 tlab = define_label (loc2, name);
4023 decl_attributes (&tlab, attrs, 0);
4024 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4029 if (c_parser_next_token_starts_declaration (parser)
4030 && !(c_parser_next_token_is (parser, CPP_NAME)
4031 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4033 error_at (c_parser_peek_token (parser)->location,
4034 "a label can only be part of a statement and "
4035 "a declaration is not a statement");
4036 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4037 /*static_assert_ok*/ true,
4038 /*nested*/ true, /*empty_ok*/ false,
4039 /*start_attr_ok*/ true, NULL);
4044 /* Parse a statement (C90 6.6, C99 6.8).
4049 expression-statement
4057 expression-statement:
4060 selection-statement:
4064 iteration-statement:
4073 return expression[opt] ;
4086 objc-throw-statement
4087 objc-try-catch-statement
4088 objc-synchronized-statement
4090 objc-throw-statement:
4104 parallel-for-construct
4105 parallel-sections-construct
4112 parallel-directive structured-block
4115 for-directive iteration-statement
4118 sections-directive section-scope
4121 single-directive structured-block
4123 parallel-for-construct:
4124 parallel-for-directive iteration-statement
4126 parallel-sections-construct:
4127 parallel-sections-directive section-scope
4130 master-directive structured-block
4133 critical-directive structured-block
4136 atomic-directive expression-statement
4139 ordered-directive structured-block */
4142 c_parser_statement (c_parser *parser)
4144 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4145 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4146 || (c_parser_next_token_is (parser, CPP_NAME)
4147 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4148 c_parser_label (parser);
4149 c_parser_statement_after_labels (parser);
4152 /* Parse a statement, other than a labeled statement. */
4155 c_parser_statement_after_labels (c_parser *parser)
4157 location_t loc = c_parser_peek_token (parser)->location;
4158 tree stmt = NULL_TREE;
4159 bool in_if_block = parser->in_if_block;
4160 parser->in_if_block = false;
4161 switch (c_parser_peek_token (parser)->type)
4163 case CPP_OPEN_BRACE:
4164 add_stmt (c_parser_compound_statement (parser));
4167 switch (c_parser_peek_token (parser)->keyword)
4170 c_parser_if_statement (parser);
4173 c_parser_switch_statement (parser);
4176 c_parser_while_statement (parser);
4179 c_parser_do_statement (parser);
4182 c_parser_for_statement (parser);
4185 c_parser_consume_token (parser);
4186 if (c_parser_next_token_is (parser, CPP_NAME))
4188 stmt = c_finish_goto_label (loc,
4189 c_parser_peek_token (parser)->value);
4190 c_parser_consume_token (parser);
4192 else if (c_parser_next_token_is (parser, CPP_MULT))
4196 c_parser_consume_token (parser);
4197 val = c_parser_expression (parser).value;
4198 mark_exp_read (val);
4199 stmt = c_finish_goto_ptr (loc, val);
4202 c_parser_error (parser, "expected identifier or %<*%>");
4203 goto expect_semicolon;
4205 c_parser_consume_token (parser);
4206 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4207 goto expect_semicolon;
4209 c_parser_consume_token (parser);
4210 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4211 goto expect_semicolon;
4213 c_parser_consume_token (parser);
4214 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4216 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4217 c_parser_consume_token (parser);
4221 struct c_expr expr = c_parser_expression_conv (parser);
4222 mark_exp_read (expr.value);
4223 stmt = c_finish_return (loc, expr.value, expr.original_type);
4224 goto expect_semicolon;
4228 stmt = c_parser_asm_statement (parser);
4231 gcc_assert (c_dialect_objc ());
4232 c_parser_consume_token (parser);
4233 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4235 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4236 c_parser_consume_token (parser);
4240 tree expr = c_parser_expression (parser).value;
4241 expr = c_fully_fold (expr, false, NULL);
4242 stmt = objc_build_throw_stmt (loc, expr);
4243 goto expect_semicolon;
4247 gcc_assert (c_dialect_objc ());
4248 c_parser_objc_try_catch_statement (parser);
4250 case RID_AT_SYNCHRONIZED:
4251 gcc_assert (c_dialect_objc ());
4252 c_parser_objc_synchronized_statement (parser);
4259 c_parser_consume_token (parser);
4261 case CPP_CLOSE_PAREN:
4262 case CPP_CLOSE_SQUARE:
4263 /* Avoid infinite loop in error recovery:
4264 c_parser_skip_until_found stops at a closing nesting
4265 delimiter without consuming it, but here we need to consume
4266 it to proceed further. */
4267 c_parser_error (parser, "expected statement");
4268 c_parser_consume_token (parser);
4271 c_parser_pragma (parser, pragma_stmt);
4275 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4277 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4280 /* Two cases cannot and do not have line numbers associated: If stmt
4281 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4282 cannot hold line numbers. But that's OK because the statement
4283 will either be changed to a MODIFY_EXPR during gimplification of
4284 the statement expr, or discarded. If stmt was compound, but
4285 without new variables, we will have skipped the creation of a
4286 BIND and will have a bare STATEMENT_LIST. But that's OK because
4287 (recursively) all of the component statements should already have
4288 line numbers assigned. ??? Can we discard no-op statements
4290 if (CAN_HAVE_LOCATION_P (stmt)
4291 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4292 SET_EXPR_LOCATION (stmt, loc);
4294 parser->in_if_block = in_if_block;
4297 /* Parse the condition from an if, do, while or for statements. */
4300 c_parser_condition (c_parser *parser)
4302 location_t loc = c_parser_peek_token (parser)->location;
4304 cond = c_parser_expression_conv (parser).value;
4305 cond = c_objc_common_truthvalue_conversion (loc, cond);
4306 cond = c_fully_fold (cond, false, NULL);
4307 if (warn_sequence_point)
4308 verify_sequence_points (cond);
4312 /* Parse a parenthesized condition from an if, do or while statement.
4318 c_parser_paren_condition (c_parser *parser)
4321 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4322 return error_mark_node;
4323 cond = c_parser_condition (parser);
4324 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4328 /* Parse a statement which is a block in C99. */
4331 c_parser_c99_block_statement (c_parser *parser)
4333 tree block = c_begin_compound_stmt (flag_isoc99);
4334 location_t loc = c_parser_peek_token (parser)->location;
4335 c_parser_statement (parser);
4336 return c_end_compound_stmt (loc, block, flag_isoc99);
4339 /* Parse the body of an if statement. This is just parsing a
4340 statement but (a) it is a block in C99, (b) we track whether the
4341 body is an if statement for the sake of -Wparentheses warnings, (c)
4342 we handle an empty body specially for the sake of -Wempty-body
4343 warnings, and (d) we call parser_compound_statement directly
4344 because c_parser_statement_after_labels resets
4345 parser->in_if_block. */
4348 c_parser_if_body (c_parser *parser, bool *if_p)
4350 tree block = c_begin_compound_stmt (flag_isoc99);
4351 location_t body_loc = c_parser_peek_token (parser)->location;
4352 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4353 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4354 || (c_parser_next_token_is (parser, CPP_NAME)
4355 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4356 c_parser_label (parser);
4357 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4358 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4360 location_t loc = c_parser_peek_token (parser)->location;
4361 add_stmt (build_empty_stmt (loc));
4362 c_parser_consume_token (parser);
4363 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4364 warning_at (loc, OPT_Wempty_body,
4365 "suggest braces around empty body in an %<if%> statement");
4367 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4368 add_stmt (c_parser_compound_statement (parser));
4370 c_parser_statement_after_labels (parser);
4371 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4374 /* Parse the else body of an if statement. This is just parsing a
4375 statement but (a) it is a block in C99, (b) we handle an empty body
4376 specially for the sake of -Wempty-body warnings. */
4379 c_parser_else_body (c_parser *parser)
4381 location_t else_loc = c_parser_peek_token (parser)->location;
4382 tree block = c_begin_compound_stmt (flag_isoc99);
4383 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4384 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4385 || (c_parser_next_token_is (parser, CPP_NAME)
4386 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4387 c_parser_label (parser);
4388 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4390 location_t loc = c_parser_peek_token (parser)->location;
4393 "suggest braces around empty body in an %<else%> statement");
4394 add_stmt (build_empty_stmt (loc));
4395 c_parser_consume_token (parser);
4398 c_parser_statement_after_labels (parser);
4399 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4402 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4405 if ( expression ) statement
4406 if ( expression ) statement else statement
4410 c_parser_if_statement (c_parser *parser)
4415 bool first_if = false;
4416 tree first_body, second_body;
4419 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4420 c_parser_consume_token (parser);
4421 block = c_begin_compound_stmt (flag_isoc99);
4422 loc = c_parser_peek_token (parser)->location;
4423 cond = c_parser_paren_condition (parser);
4424 in_if_block = parser->in_if_block;
4425 parser->in_if_block = true;
4426 first_body = c_parser_if_body (parser, &first_if);
4427 parser->in_if_block = in_if_block;
4428 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4430 c_parser_consume_token (parser);
4431 second_body = c_parser_else_body (parser);
4434 second_body = NULL_TREE;
4435 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4436 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4439 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4442 switch (expression) statement
4446 c_parser_switch_statement (c_parser *parser)
4448 tree block, expr, body, save_break;
4449 location_t switch_loc = c_parser_peek_token (parser)->location;
4450 location_t switch_cond_loc;
4451 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4452 c_parser_consume_token (parser);
4453 block = c_begin_compound_stmt (flag_isoc99);
4454 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4456 switch_cond_loc = c_parser_peek_token (parser)->location;
4457 expr = c_parser_expression (parser).value;
4458 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4462 switch_cond_loc = UNKNOWN_LOCATION;
4463 expr = error_mark_node;
4465 c_start_case (switch_loc, switch_cond_loc, expr);
4466 save_break = c_break_label;
4467 c_break_label = NULL_TREE;
4468 body = c_parser_c99_block_statement (parser);
4469 c_finish_case (body);
4472 location_t here = c_parser_peek_token (parser)->location;
4473 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4474 SET_EXPR_LOCATION (t, here);
4477 c_break_label = save_break;
4478 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4481 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4484 while (expression) statement
4488 c_parser_while_statement (c_parser *parser)
4490 tree block, cond, body, save_break, save_cont;
4492 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4493 c_parser_consume_token (parser);
4494 block = c_begin_compound_stmt (flag_isoc99);
4495 loc = c_parser_peek_token (parser)->location;
4496 cond = c_parser_paren_condition (parser);
4497 save_break = c_break_label;
4498 c_break_label = NULL_TREE;
4499 save_cont = c_cont_label;
4500 c_cont_label = NULL_TREE;
4501 body = c_parser_c99_block_statement (parser);
4502 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4503 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4504 c_break_label = save_break;
4505 c_cont_label = save_cont;
4508 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4511 do statement while ( expression ) ;
4515 c_parser_do_statement (c_parser *parser)
4517 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4519 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4520 c_parser_consume_token (parser);
4521 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4522 warning_at (c_parser_peek_token (parser)->location,
4524 "suggest braces around empty body in %<do%> statement");
4525 block = c_begin_compound_stmt (flag_isoc99);
4526 loc = c_parser_peek_token (parser)->location;
4527 save_break = c_break_label;
4528 c_break_label = NULL_TREE;
4529 save_cont = c_cont_label;
4530 c_cont_label = NULL_TREE;
4531 body = c_parser_c99_block_statement (parser);
4532 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4533 new_break = c_break_label;
4534 c_break_label = save_break;
4535 new_cont = c_cont_label;
4536 c_cont_label = save_cont;
4537 cond = c_parser_paren_condition (parser);
4538 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4539 c_parser_skip_to_end_of_block_or_statement (parser);
4540 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4541 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4544 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4547 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4548 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4550 The form with a declaration is new in C99.
4552 ??? In accordance with the old parser, the declaration may be a
4553 nested function, which is then rejected in check_for_loop_decls,
4554 but does it make any sense for this to be included in the grammar?
4555 Note in particular that the nested function does not include a
4556 trailing ';', whereas the "declaration" production includes one.
4557 Also, can we reject bad declarations earlier and cheaper than
4558 check_for_loop_decls?
4560 In Objective-C, there are two additional variants:
4563 for ( expression in expresssion ) statement
4564 for ( declaration in expression ) statement
4566 This is inconsistent with C, because the second variant is allowed
4567 even if c99 is not enabled.
4569 The rest of the comment documents these Objective-C foreach-statement.
4571 Here is the canonical example of the first variant:
4572 for (object in array) { do something with object }
4573 we call the first expression ("object") the "object_expression" and
4574 the second expression ("array") the "collection_expression".
4575 object_expression must be an lvalue of type "id" (a generic Objective-C
4576 object) because the loop works by assigning to object_expression the
4577 various objects from the collection_expression. collection_expression
4578 must evaluate to something of type "id" which responds to the method
4579 countByEnumeratingWithState:objects:count:.
4581 The canonical example of the second variant is:
4582 for (id object in array) { do something with object }
4583 which is completely equivalent to
4586 for (object in array) { do something with object }
4588 Note that initizializing 'object' in some way (eg, "for ((object =
4589 xxx) in array) { do something with object }") is possibly
4590 technically valid, but completely pointless as 'object' will be
4591 assigned to something else as soon as the loop starts. We should
4592 most likely reject it (TODO).
4594 The beginning of the Objective-C foreach-statement looks exactly
4595 like the beginning of the for-statement, and we can tell it is a
4596 foreach-statement only because the initial declaration or
4597 expression is terminated by 'in' instead of ';'.
4601 c_parser_for_statement (c_parser *parser)
4603 tree block, cond, incr, save_break, save_cont, body;
4604 /* The following are only used when parsing an ObjC foreach statement. */
4605 tree object_expression, collection_expression;
4606 location_t loc = c_parser_peek_token (parser)->location;
4607 location_t for_loc = c_parser_peek_token (parser)->location;
4608 bool is_foreach_statement = false;
4609 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4610 c_parser_consume_token (parser);
4611 /* Open a compound statement in Objective-C as well, just in case this is
4612 as foreach expression. */
4613 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4614 cond = error_mark_node;
4615 incr = error_mark_node;
4616 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4618 /* Parse the initialization declaration or expression. */
4619 object_expression = error_mark_node;
4620 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4622 c_parser_consume_token (parser);
4623 c_finish_expr_stmt (loc, NULL_TREE);
4625 else if (c_parser_next_token_starts_declaration (parser))
4627 parser->objc_could_be_foreach_context = true;
4628 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4629 &object_expression);
4630 parser->objc_could_be_foreach_context = false;
4632 if (c_parser_next_token_is_keyword (parser, RID_IN))
4634 c_parser_consume_token (parser);
4635 is_foreach_statement = true;
4636 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4637 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4640 check_for_loop_decls (for_loc, flag_isoc99);
4642 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4644 /* __extension__ can start a declaration, but is also an
4645 unary operator that can start an expression. Consume all
4646 but the last of a possible series of __extension__ to
4648 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4649 && (c_parser_peek_2nd_token (parser)->keyword
4651 c_parser_consume_token (parser);
4652 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4655 ext = disable_extension_diagnostics ();
4656 c_parser_consume_token (parser);
4657 parser->objc_could_be_foreach_context = true;
4658 c_parser_declaration_or_fndef (parser, true, true, true, true,
4659 true, &object_expression);
4660 parser->objc_could_be_foreach_context = false;
4662 restore_extension_diagnostics (ext);
4663 if (c_parser_next_token_is_keyword (parser, RID_IN))
4665 c_parser_consume_token (parser);
4666 is_foreach_statement = true;
4667 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4668 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4671 check_for_loop_decls (for_loc, flag_isoc99);
4680 tree init_expression;
4681 parser->objc_could_be_foreach_context = true;
4682 init_expression = c_parser_expression (parser).value;
4683 parser->objc_could_be_foreach_context = false;
4684 if (c_parser_next_token_is_keyword (parser, RID_IN))
4686 c_parser_consume_token (parser);
4687 is_foreach_statement = true;
4688 if (! lvalue_p (init_expression))
4689 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4690 object_expression = c_process_expr_stmt (loc, init_expression);
4695 c_finish_expr_stmt (loc, init_expression);
4696 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4700 /* Parse the loop condition. In the case of a foreach
4701 statement, there is no loop condition. */
4702 if (!is_foreach_statement)
4704 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4706 c_parser_consume_token (parser);
4711 cond = c_parser_condition (parser);
4712 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4715 /* Parse the increment expression (the third expression in a
4716 for-statement). In the case of a foreach-statement, this is
4717 the expression that follows the 'in'. */
4718 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4720 if (is_foreach_statement)
4722 c_parser_error (parser, "missing collection in fast enumeration");
4723 collection_expression = error_mark_node;
4726 incr = c_process_expr_stmt (loc, NULL_TREE);
4730 if (is_foreach_statement)
4731 collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4733 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4735 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4737 save_break = c_break_label;
4738 c_break_label = NULL_TREE;
4739 save_cont = c_cont_label;
4740 c_cont_label = NULL_TREE;
4741 body = c_parser_c99_block_statement (parser);
4742 if (is_foreach_statement)
4743 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4745 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4746 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4747 c_break_label = save_break;
4748 c_cont_label = save_cont;
4751 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4752 statement with inputs, outputs, clobbers, and volatile tag
4756 asm type-qualifier[opt] ( asm-argument ) ;
4757 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4761 asm-string-literal : asm-operands[opt]
4762 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4763 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4766 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4769 Qualifiers other than volatile are accepted in the syntax but
4773 c_parser_asm_statement (c_parser *parser)
4775 tree quals, str, outputs, inputs, clobbers, labels, ret;
4776 bool simple, is_goto;
4777 location_t asm_loc = c_parser_peek_token (parser)->location;
4778 int section, nsections;
4780 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4781 c_parser_consume_token (parser);
4782 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4784 quals = c_parser_peek_token (parser)->value;
4785 c_parser_consume_token (parser);
4787 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4788 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4790 warning_at (c_parser_peek_token (parser)->location,
4792 "%E qualifier ignored on asm",
4793 c_parser_peek_token (parser)->value);
4795 c_parser_consume_token (parser);
4801 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4803 c_parser_consume_token (parser);
4807 /* ??? Follow the C++ parser rather than using the
4808 lex_untranslated_string kludge. */
4809 parser->lex_untranslated_string = true;
4812 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4815 str = c_parser_asm_string_literal (parser);
4816 if (str == NULL_TREE)
4817 goto error_close_paren;
4820 outputs = NULL_TREE;
4822 clobbers = NULL_TREE;
4825 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4828 /* Parse each colon-delimited section of operands. */
4829 nsections = 3 + is_goto;
4830 for (section = 0; section < nsections; ++section)
4832 if (!c_parser_require (parser, CPP_COLON,
4835 : "expected %<:%> or %<)%>"))
4836 goto error_close_paren;
4838 /* Once past any colon, we're no longer a simple asm. */
4841 if ((!c_parser_next_token_is (parser, CPP_COLON)
4842 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4847 /* For asm goto, we don't allow output operands, but reserve
4848 the slot for a future extension that does allow them. */
4850 outputs = c_parser_asm_operands (parser, false);
4853 inputs = c_parser_asm_operands (parser, true);
4856 clobbers = c_parser_asm_clobbers (parser);
4859 labels = c_parser_asm_goto_operands (parser);
4865 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4870 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4872 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4876 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4877 c_parser_skip_to_end_of_block_or_statement (parser);
4879 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4880 clobbers, labels, simple));
4883 parser->lex_untranslated_string = false;
4887 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4891 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4892 not outputs), apply the default conversion of functions and arrays
4897 asm-operands , asm-operand
4900 asm-string-literal ( expression )
4901 [ identifier ] asm-string-literal ( expression )
4905 c_parser_asm_operands (c_parser *parser, bool convert_p)
4907 tree list = NULL_TREE;
4913 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4915 c_parser_consume_token (parser);
4916 if (c_parser_next_token_is (parser, CPP_NAME))
4918 tree id = c_parser_peek_token (parser)->value;
4919 c_parser_consume_token (parser);
4920 name = build_string (IDENTIFIER_LENGTH (id),
4921 IDENTIFIER_POINTER (id));
4925 c_parser_error (parser, "expected identifier");
4926 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4929 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4934 str = c_parser_asm_string_literal (parser);
4935 if (str == NULL_TREE)
4937 parser->lex_untranslated_string = false;
4938 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4940 parser->lex_untranslated_string = true;
4943 loc = c_parser_peek_token (parser)->location;
4944 expr = c_parser_expression (parser);
4945 mark_exp_read (expr.value);
4947 expr = default_function_array_conversion (loc, expr);
4948 expr.value = c_fully_fold (expr.value, false, NULL);
4949 parser->lex_untranslated_string = true;
4950 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4952 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4955 list = chainon (list, build_tree_list (build_tree_list (name, str),
4957 if (c_parser_next_token_is (parser, CPP_COMMA))
4958 c_parser_consume_token (parser);
4965 /* Parse asm clobbers, a GNU extension.
4969 asm-clobbers , asm-string-literal
4973 c_parser_asm_clobbers (c_parser *parser)
4975 tree list = NULL_TREE;
4978 tree str = c_parser_asm_string_literal (parser);
4980 list = tree_cons (NULL_TREE, str, list);
4983 if (c_parser_next_token_is (parser, CPP_COMMA))
4984 c_parser_consume_token (parser);
4991 /* Parse asm goto labels, a GNU extension.
4995 asm-goto-operands , identifier
4999 c_parser_asm_goto_operands (c_parser *parser)
5001 tree list = NULL_TREE;
5006 if (c_parser_next_token_is (parser, CPP_NAME))
5008 c_token *tok = c_parser_peek_token (parser);
5010 label = lookup_label_for_goto (tok->location, name);
5011 c_parser_consume_token (parser);
5012 TREE_USED (label) = 1;
5016 c_parser_error (parser, "expected identifier");
5020 name = build_string (IDENTIFIER_LENGTH (name),
5021 IDENTIFIER_POINTER (name));
5022 list = tree_cons (name, label, list);
5023 if (c_parser_next_token_is (parser, CPP_COMMA))
5024 c_parser_consume_token (parser);
5026 return nreverse (list);
5030 /* Parse an expression other than a compound expression; that is, an
5031 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5032 NULL then it is an Objective-C message expression which is the
5033 primary-expression starting the expression as an initializer.
5035 assignment-expression:
5036 conditional-expression
5037 unary-expression assignment-operator assignment-expression
5039 assignment-operator: one of
5040 = *= /= %= += -= <<= >>= &= ^= |=
5042 In GNU C we accept any conditional expression on the LHS and
5043 diagnose the invalid lvalue rather than producing a syntax
5046 static struct c_expr
5047 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5049 struct c_expr lhs, rhs, ret;
5050 enum tree_code code;
5051 location_t op_location, exp_location;
5052 gcc_assert (!after || c_dialect_objc ());
5053 lhs = c_parser_conditional_expression (parser, after);
5054 op_location = c_parser_peek_token (parser)->location;
5055 switch (c_parser_peek_token (parser)->type)
5064 code = TRUNC_DIV_EXPR;
5067 code = TRUNC_MOD_EXPR;
5082 code = BIT_AND_EXPR;
5085 code = BIT_XOR_EXPR;
5088 code = BIT_IOR_EXPR;
5093 c_parser_consume_token (parser);
5094 exp_location = c_parser_peek_token (parser)->location;
5095 rhs = c_parser_expr_no_commas (parser, NULL);
5096 rhs = default_function_array_read_conversion (exp_location, rhs);
5097 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5098 code, exp_location, rhs.value,
5100 if (code == NOP_EXPR)
5101 ret.original_code = MODIFY_EXPR;
5104 TREE_NO_WARNING (ret.value) = 1;
5105 ret.original_code = ERROR_MARK;
5107 ret.original_type = NULL;
5111 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5112 is not NULL then it is an Objective-C message expression which is
5113 the primary-expression starting the expression as an initializer.
5115 conditional-expression:
5116 logical-OR-expression
5117 logical-OR-expression ? expression : conditional-expression
5121 conditional-expression:
5122 logical-OR-expression ? : conditional-expression
5125 static struct c_expr
5126 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5128 struct c_expr cond, exp1, exp2, ret;
5129 location_t cond_loc, colon_loc, middle_loc;
5131 gcc_assert (!after || c_dialect_objc ());
5133 cond = c_parser_binary_expression (parser, after);
5135 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5137 cond_loc = c_parser_peek_token (parser)->location;
5138 cond = default_function_array_read_conversion (cond_loc, cond);
5139 c_parser_consume_token (parser);
5140 if (c_parser_next_token_is (parser, CPP_COLON))
5142 tree eptype = NULL_TREE;
5144 middle_loc = c_parser_peek_token (parser)->location;
5145 pedwarn (middle_loc, OPT_pedantic,
5146 "ISO C forbids omitting the middle term of a ?: expression");
5147 warn_for_omitted_condop (middle_loc, cond.value);
5148 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5150 eptype = TREE_TYPE (cond.value);
5151 cond.value = TREE_OPERAND (cond.value, 0);
5153 /* Make sure first operand is calculated only once. */
5154 exp1.value = c_save_expr (default_conversion (cond.value));
5156 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5157 exp1.original_type = NULL;
5158 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5159 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5164 = c_objc_common_truthvalue_conversion
5165 (cond_loc, default_conversion (cond.value));
5166 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5167 exp1 = c_parser_expression_conv (parser);
5168 mark_exp_read (exp1.value);
5169 c_inhibit_evaluation_warnings +=
5170 ((cond.value == truthvalue_true_node)
5171 - (cond.value == truthvalue_false_node));
5174 colon_loc = c_parser_peek_token (parser)->location;
5175 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5177 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5178 ret.value = error_mark_node;
5179 ret.original_code = ERROR_MARK;
5180 ret.original_type = NULL;
5184 location_t exp2_loc = c_parser_peek_token (parser)->location;
5185 exp2 = c_parser_conditional_expression (parser, NULL);
5186 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5188 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5189 ret.value = build_conditional_expr (colon_loc, cond.value,
5190 cond.original_code == C_MAYBE_CONST_EXPR,
5191 exp1.value, exp1.original_type,
5192 exp2.value, exp2.original_type);
5193 ret.original_code = ERROR_MARK;
5194 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5195 ret.original_type = NULL;
5200 /* If both sides are enum type, the default conversion will have
5201 made the type of the result be an integer type. We want to
5202 remember the enum types we started with. */
5203 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5204 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5205 ret.original_type = ((t1 != error_mark_node
5206 && t2 != error_mark_node
5207 && (TYPE_MAIN_VARIANT (t1)
5208 == TYPE_MAIN_VARIANT (t2)))
5215 /* Parse a binary expression; that is, a logical-OR-expression (C90
5216 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5217 an Objective-C message expression which is the primary-expression
5218 starting the expression as an initializer.
5220 multiplicative-expression:
5222 multiplicative-expression * cast-expression
5223 multiplicative-expression / cast-expression
5224 multiplicative-expression % cast-expression
5226 additive-expression:
5227 multiplicative-expression
5228 additive-expression + multiplicative-expression
5229 additive-expression - multiplicative-expression
5233 shift-expression << additive-expression
5234 shift-expression >> additive-expression
5236 relational-expression:
5238 relational-expression < shift-expression
5239 relational-expression > shift-expression
5240 relational-expression <= shift-expression
5241 relational-expression >= shift-expression
5243 equality-expression:
5244 relational-expression
5245 equality-expression == relational-expression
5246 equality-expression != relational-expression
5250 AND-expression & equality-expression
5252 exclusive-OR-expression:
5254 exclusive-OR-expression ^ AND-expression
5256 inclusive-OR-expression:
5257 exclusive-OR-expression
5258 inclusive-OR-expression | exclusive-OR-expression
5260 logical-AND-expression:
5261 inclusive-OR-expression
5262 logical-AND-expression && inclusive-OR-expression
5264 logical-OR-expression:
5265 logical-AND-expression
5266 logical-OR-expression || logical-AND-expression
5269 static struct c_expr
5270 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5272 /* A binary expression is parsed using operator-precedence parsing,
5273 with the operands being cast expressions. All the binary
5274 operators are left-associative. Thus a binary expression is of
5277 E0 op1 E1 op2 E2 ...
5279 which we represent on a stack. On the stack, the precedence
5280 levels are strictly increasing. When a new operator is
5281 encountered of higher precedence than that at the top of the
5282 stack, it is pushed; its LHS is the top expression, and its RHS
5283 is everything parsed until it is popped. When a new operator is
5284 encountered with precedence less than or equal to that at the top
5285 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5286 by the result of the operation until the operator at the top of
5287 the stack has lower precedence than the new operator or there is
5288 only one element on the stack; then the top expression is the LHS
5289 of the new operator. In the case of logical AND and OR
5290 expressions, we also need to adjust c_inhibit_evaluation_warnings
5291 as appropriate when the operators are pushed and popped. */
5293 /* The precedence levels, where 0 is a dummy lowest level used for
5294 the bottom of the stack. */
5310 /* The expression at this stack level. */
5312 /* The precedence of the operator on its left, PREC_NONE at the
5313 bottom of the stack. */
5315 /* The operation on its left. */
5317 /* The source location of this operation. */
5321 /* Location of the binary operator. */
5322 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5325 switch (stack[sp].op) \
5327 case TRUTH_ANDIF_EXPR: \
5328 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5329 == truthvalue_false_node); \
5331 case TRUTH_ORIF_EXPR: \
5332 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5333 == truthvalue_true_node); \
5338 stack[sp - 1].expr \
5339 = default_function_array_read_conversion (stack[sp - 1].loc, \
5340 stack[sp - 1].expr); \
5342 = default_function_array_read_conversion (stack[sp].loc, \
5344 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5346 stack[sp - 1].expr, \
5350 gcc_assert (!after || c_dialect_objc ());
5351 stack[0].loc = c_parser_peek_token (parser)->location;
5352 stack[0].expr = c_parser_cast_expression (parser, after);
5353 stack[0].prec = PREC_NONE;
5358 enum tree_code ocode;
5361 switch (c_parser_peek_token (parser)->type)
5369 ocode = TRUNC_DIV_EXPR;
5373 ocode = TRUNC_MOD_EXPR;
5385 ocode = LSHIFT_EXPR;
5389 ocode = RSHIFT_EXPR;
5403 case CPP_GREATER_EQ:
5416 oprec = PREC_BITAND;
5417 ocode = BIT_AND_EXPR;
5420 oprec = PREC_BITXOR;
5421 ocode = BIT_XOR_EXPR;
5425 ocode = BIT_IOR_EXPR;
5428 oprec = PREC_LOGAND;
5429 ocode = TRUTH_ANDIF_EXPR;
5433 ocode = TRUTH_ORIF_EXPR;
5436 /* Not a binary operator, so end of the binary
5440 binary_loc = c_parser_peek_token (parser)->location;
5441 c_parser_consume_token (parser);
5442 while (oprec <= stack[sp].prec)
5446 case TRUTH_ANDIF_EXPR:
5448 = default_function_array_read_conversion (stack[sp].loc,
5450 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5451 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5452 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5453 == truthvalue_false_node);
5455 case TRUTH_ORIF_EXPR:
5457 = default_function_array_read_conversion (stack[sp].loc,
5459 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5460 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5461 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5462 == truthvalue_true_node);
5468 stack[sp].loc = binary_loc;
5469 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5470 stack[sp].prec = oprec;
5471 stack[sp].op = ocode;
5472 stack[sp].loc = binary_loc;
5477 return stack[0].expr;
5481 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5482 NULL then it is an Objective-C message expression which is the
5483 primary-expression starting the expression as an initializer.
5487 ( type-name ) unary-expression
5490 static struct c_expr
5491 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5493 location_t cast_loc = c_parser_peek_token (parser)->location;
5494 gcc_assert (!after || c_dialect_objc ());
5496 return c_parser_postfix_expression_after_primary (parser,
5498 /* If the expression begins with a parenthesized type name, it may
5499 be either a cast or a compound literal; we need to see whether
5500 the next character is '{' to tell the difference. If not, it is
5501 an unary expression. */
5502 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5503 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5505 struct c_type_name *type_name;
5508 c_parser_consume_token (parser);
5509 type_name = c_parser_type_name (parser);
5510 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5511 if (type_name == NULL)
5513 ret.value = error_mark_node;
5514 ret.original_code = ERROR_MARK;
5515 ret.original_type = NULL;
5519 /* Save casted types in the function's used types hash table. */
5520 used_types_insert (type_name->specs->type);
5522 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5523 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5526 location_t expr_loc = c_parser_peek_token (parser)->location;
5527 expr = c_parser_cast_expression (parser, NULL);
5528 expr = default_function_array_read_conversion (expr_loc, expr);
5530 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5531 ret.original_code = ERROR_MARK;
5532 ret.original_type = NULL;
5536 return c_parser_unary_expression (parser);
5539 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5545 unary-operator cast-expression
5546 sizeof unary-expression
5547 sizeof ( type-name )
5549 unary-operator: one of
5555 __alignof__ unary-expression
5556 __alignof__ ( type-name )
5559 unary-operator: one of
5560 __extension__ __real__ __imag__
5562 In addition, the GNU syntax treats ++ and -- as unary operators, so
5563 they may be applied to cast expressions with errors for non-lvalues
5566 static struct c_expr
5567 c_parser_unary_expression (c_parser *parser)
5570 struct c_expr ret, op;
5571 location_t op_loc = c_parser_peek_token (parser)->location;
5573 ret.original_code = ERROR_MARK;
5574 ret.original_type = NULL;
5575 switch (c_parser_peek_token (parser)->type)
5578 c_parser_consume_token (parser);
5579 exp_loc = c_parser_peek_token (parser)->location;
5580 op = c_parser_cast_expression (parser, NULL);
5581 op = default_function_array_read_conversion (exp_loc, op);
5582 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5583 case CPP_MINUS_MINUS:
5584 c_parser_consume_token (parser);
5585 exp_loc = c_parser_peek_token (parser)->location;
5586 op = c_parser_cast_expression (parser, NULL);
5587 op = default_function_array_read_conversion (exp_loc, op);
5588 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5590 c_parser_consume_token (parser);
5591 op = c_parser_cast_expression (parser, NULL);
5592 mark_exp_read (op.value);
5593 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5595 c_parser_consume_token (parser);
5596 exp_loc = c_parser_peek_token (parser)->location;
5597 op = c_parser_cast_expression (parser, NULL);
5598 op = default_function_array_read_conversion (exp_loc, op);
5599 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5602 if (!c_dialect_objc () && !in_system_header)
5605 "traditional C rejects the unary plus operator");
5606 c_parser_consume_token (parser);
5607 exp_loc = c_parser_peek_token (parser)->location;
5608 op = c_parser_cast_expression (parser, NULL);
5609 op = default_function_array_read_conversion (exp_loc, op);
5610 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5612 c_parser_consume_token (parser);
5613 exp_loc = c_parser_peek_token (parser)->location;
5614 op = c_parser_cast_expression (parser, NULL);
5615 op = default_function_array_read_conversion (exp_loc, op);
5616 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5618 c_parser_consume_token (parser);
5619 exp_loc = c_parser_peek_token (parser)->location;
5620 op = c_parser_cast_expression (parser, NULL);
5621 op = default_function_array_read_conversion (exp_loc, op);
5622 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5624 c_parser_consume_token (parser);
5625 exp_loc = c_parser_peek_token (parser)->location;
5626 op = c_parser_cast_expression (parser, NULL);
5627 op = default_function_array_read_conversion (exp_loc, op);
5628 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5630 /* Refer to the address of a label as a pointer. */
5631 c_parser_consume_token (parser);
5632 if (c_parser_next_token_is (parser, CPP_NAME))
5634 ret.value = finish_label_address_expr
5635 (c_parser_peek_token (parser)->value, op_loc);
5636 c_parser_consume_token (parser);
5640 c_parser_error (parser, "expected identifier");
5641 ret.value = error_mark_node;
5645 switch (c_parser_peek_token (parser)->keyword)
5648 return c_parser_sizeof_expression (parser);
5650 return c_parser_alignof_expression (parser);
5652 c_parser_consume_token (parser);
5653 ext = disable_extension_diagnostics ();
5654 ret = c_parser_cast_expression (parser, NULL);
5655 restore_extension_diagnostics (ext);
5658 c_parser_consume_token (parser);
5659 exp_loc = c_parser_peek_token (parser)->location;
5660 op = c_parser_cast_expression (parser, NULL);
5661 op = default_function_array_conversion (exp_loc, op);
5662 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5664 c_parser_consume_token (parser);
5665 exp_loc = c_parser_peek_token (parser)->location;
5666 op = c_parser_cast_expression (parser, NULL);
5667 op = default_function_array_conversion (exp_loc, op);
5668 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5670 return c_parser_postfix_expression (parser);
5673 return c_parser_postfix_expression (parser);
5677 /* Parse a sizeof expression. */
5679 static struct c_expr
5680 c_parser_sizeof_expression (c_parser *parser)
5683 location_t expr_loc;
5684 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5685 c_parser_consume_token (parser);
5686 c_inhibit_evaluation_warnings++;
5688 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5689 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5691 /* Either sizeof ( type-name ) or sizeof unary-expression
5692 starting with a compound literal. */
5693 struct c_type_name *type_name;
5694 c_parser_consume_token (parser);
5695 expr_loc = c_parser_peek_token (parser)->location;
5696 type_name = c_parser_type_name (parser);
5697 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5698 if (type_name == NULL)
5701 c_inhibit_evaluation_warnings--;
5703 ret.value = error_mark_node;
5704 ret.original_code = ERROR_MARK;
5705 ret.original_type = NULL;
5708 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5710 expr = c_parser_postfix_expression_after_paren_type (parser,
5715 /* sizeof ( type-name ). */
5716 c_inhibit_evaluation_warnings--;
5718 return c_expr_sizeof_type (expr_loc, type_name);
5722 expr_loc = c_parser_peek_token (parser)->location;
5723 expr = c_parser_unary_expression (parser);
5725 c_inhibit_evaluation_warnings--;
5727 mark_exp_read (expr.value);
5728 if (TREE_CODE (expr.value) == COMPONENT_REF
5729 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5730 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5731 return c_expr_sizeof_expr (expr_loc, expr);
5735 /* Parse an alignof expression. */
5737 static struct c_expr
5738 c_parser_alignof_expression (c_parser *parser)
5741 location_t loc = c_parser_peek_token (parser)->location;
5742 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5743 c_parser_consume_token (parser);
5744 c_inhibit_evaluation_warnings++;
5746 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5747 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5749 /* Either __alignof__ ( type-name ) or __alignof__
5750 unary-expression starting with a compound literal. */
5752 struct c_type_name *type_name;
5754 c_parser_consume_token (parser);
5755 loc = c_parser_peek_token (parser)->location;
5756 type_name = c_parser_type_name (parser);
5757 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5758 if (type_name == NULL)
5761 c_inhibit_evaluation_warnings--;
5763 ret.value = error_mark_node;
5764 ret.original_code = ERROR_MARK;
5765 ret.original_type = NULL;
5768 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5770 expr = c_parser_postfix_expression_after_paren_type (parser,
5775 /* alignof ( type-name ). */
5776 c_inhibit_evaluation_warnings--;
5778 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5779 ret.original_code = ERROR_MARK;
5780 ret.original_type = NULL;
5786 expr = c_parser_unary_expression (parser);
5788 mark_exp_read (expr.value);
5789 c_inhibit_evaluation_warnings--;
5791 ret.value = c_alignof_expr (loc, expr.value);
5792 ret.original_code = ERROR_MARK;
5793 ret.original_type = NULL;
5798 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5802 postfix-expression [ expression ]
5803 postfix-expression ( argument-expression-list[opt] )
5804 postfix-expression . identifier
5805 postfix-expression -> identifier
5806 postfix-expression ++
5807 postfix-expression --
5808 ( type-name ) { initializer-list }
5809 ( type-name ) { initializer-list , }
5811 argument-expression-list:
5813 argument-expression-list , argument-expression
5825 (treated as a keyword in GNU C)
5828 ( compound-statement )
5829 __builtin_va_arg ( assignment-expression , type-name )
5830 __builtin_offsetof ( type-name , offsetof-member-designator )
5831 __builtin_choose_expr ( assignment-expression ,
5832 assignment-expression ,
5833 assignment-expression )
5834 __builtin_types_compatible_p ( type-name , type-name )
5836 offsetof-member-designator:
5838 offsetof-member-designator . identifier
5839 offsetof-member-designator [ expression ]
5844 [ objc-receiver objc-message-args ]
5845 @selector ( objc-selector-arg )
5846 @protocol ( identifier )
5847 @encode ( type-name )
5849 Classname . identifier
5852 static struct c_expr
5853 c_parser_postfix_expression (c_parser *parser)
5855 struct c_expr expr, e1, e2, e3;
5856 struct c_type_name *t1, *t2;
5857 location_t loc = c_parser_peek_token (parser)->location;;
5858 expr.original_code = ERROR_MARK;
5859 expr.original_type = NULL;
5860 switch (c_parser_peek_token (parser)->type)
5863 expr.value = c_parser_peek_token (parser)->value;
5864 loc = c_parser_peek_token (parser)->location;
5865 c_parser_consume_token (parser);
5866 if (TREE_CODE (expr.value) == FIXED_CST
5867 && !targetm.fixed_point_supported_p ())
5869 error_at (loc, "fixed-point types not supported for this target");
5870 expr.value = error_mark_node;
5877 expr.value = c_parser_peek_token (parser)->value;
5878 c_parser_consume_token (parser);
5884 case CPP_UTF8STRING:
5885 expr.value = c_parser_peek_token (parser)->value;
5886 expr.original_code = STRING_CST;
5887 c_parser_consume_token (parser);
5889 case CPP_OBJC_STRING:
5890 gcc_assert (c_dialect_objc ());
5892 = objc_build_string_object (c_parser_peek_token (parser)->value);
5893 c_parser_consume_token (parser);
5896 switch (c_parser_peek_token (parser)->id_kind)
5900 tree id = c_parser_peek_token (parser)->value;
5901 c_parser_consume_token (parser);
5902 expr.value = build_external_ref (loc, id,
5903 (c_parser_peek_token (parser)->type
5905 &expr.original_type);
5908 case C_ID_CLASSNAME:
5910 /* Here we parse the Objective-C 2.0 Class.name dot
5912 tree class_name = c_parser_peek_token (parser)->value;
5914 c_parser_consume_token (parser);
5915 gcc_assert (c_dialect_objc ());
5916 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
5918 expr.value = error_mark_node;
5921 if (c_parser_next_token_is_not (parser, CPP_NAME))
5923 c_parser_error (parser, "expected identifier");
5924 expr.value = error_mark_node;
5927 component = c_parser_peek_token (parser)->value;
5928 c_parser_consume_token (parser);
5929 expr.value = objc_build_class_component_ref (class_name,
5934 c_parser_error (parser, "expected expression");
5935 expr.value = error_mark_node;
5939 case CPP_OPEN_PAREN:
5940 /* A parenthesized expression, statement expression or compound
5942 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5944 /* A statement expression. */
5946 location_t brace_loc;
5947 c_parser_consume_token (parser);
5948 brace_loc = c_parser_peek_token (parser)->location;
5949 c_parser_consume_token (parser);
5950 if (cur_stmt_list == NULL)
5952 error_at (loc, "braced-group within expression allowed "
5953 "only inside a function");
5954 parser->error = true;
5955 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5956 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5957 expr.value = error_mark_node;
5960 stmt = c_begin_stmt_expr ();
5961 c_parser_compound_statement_nostart (parser);
5962 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5964 pedwarn (loc, OPT_pedantic,
5965 "ISO C forbids braced-groups within expressions");
5966 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5967 mark_exp_read (expr.value);
5969 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5971 /* A compound literal. ??? Can we actually get here rather
5972 than going directly to
5973 c_parser_postfix_expression_after_paren_type from
5976 struct c_type_name *type_name;
5977 c_parser_consume_token (parser);
5978 loc = c_parser_peek_token (parser)->location;
5979 type_name = c_parser_type_name (parser);
5980 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5982 if (type_name == NULL)
5984 expr.value = error_mark_node;
5987 expr = c_parser_postfix_expression_after_paren_type (parser,
5993 /* A parenthesized expression. */
5994 c_parser_consume_token (parser);
5995 expr = c_parser_expression (parser);
5996 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5997 TREE_NO_WARNING (expr.value) = 1;
5998 if (expr.original_code != C_MAYBE_CONST_EXPR)
5999 expr.original_code = ERROR_MARK;
6000 /* Don't change EXPR.ORIGINAL_TYPE. */
6001 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6006 switch (c_parser_peek_token (parser)->keyword)
6008 case RID_FUNCTION_NAME:
6009 case RID_PRETTY_FUNCTION_NAME:
6010 case RID_C99_FUNCTION_NAME:
6011 expr.value = fname_decl (loc,
6012 c_parser_peek_token (parser)->keyword,
6013 c_parser_peek_token (parser)->value);
6014 c_parser_consume_token (parser);
6017 c_parser_consume_token (parser);
6018 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6020 expr.value = error_mark_node;
6023 e1 = c_parser_expr_no_commas (parser, NULL);
6024 mark_exp_read (e1.value);
6025 e1.value = c_fully_fold (e1.value, false, NULL);
6026 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6028 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6029 expr.value = error_mark_node;
6032 loc = c_parser_peek_token (parser)->location;
6033 t1 = c_parser_type_name (parser);
6034 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6038 expr.value = error_mark_node;
6042 tree type_expr = NULL_TREE;
6043 expr.value = c_build_va_arg (loc, e1.value,
6044 groktypename (t1, &type_expr, NULL));
6047 expr.value = build2 (C_MAYBE_CONST_EXPR,
6048 TREE_TYPE (expr.value), type_expr,
6050 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6055 c_parser_consume_token (parser);
6056 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6058 expr.value = error_mark_node;
6061 t1 = c_parser_type_name (parser);
6064 expr.value = error_mark_node;
6067 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6069 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6070 expr.value = error_mark_node;
6074 tree type = groktypename (t1, NULL, NULL);
6076 if (type == error_mark_node)
6077 offsetof_ref = error_mark_node;
6080 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6081 SET_EXPR_LOCATION (offsetof_ref, loc);
6083 /* Parse the second argument to __builtin_offsetof. We
6084 must have one identifier, and beyond that we want to
6085 accept sub structure and sub array references. */
6086 if (c_parser_next_token_is (parser, CPP_NAME))
6088 offsetof_ref = build_component_ref
6089 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6090 c_parser_consume_token (parser);
6091 while (c_parser_next_token_is (parser, CPP_DOT)
6092 || c_parser_next_token_is (parser,
6094 || c_parser_next_token_is (parser,
6097 if (c_parser_next_token_is (parser, CPP_DEREF))
6099 loc = c_parser_peek_token (parser)->location;
6100 offsetof_ref = build_array_ref (loc,
6105 else if (c_parser_next_token_is (parser, CPP_DOT))
6108 c_parser_consume_token (parser);
6109 if (c_parser_next_token_is_not (parser,
6112 c_parser_error (parser, "expected identifier");
6115 offsetof_ref = build_component_ref
6117 c_parser_peek_token (parser)->value);
6118 c_parser_consume_token (parser);
6123 loc = c_parser_peek_token (parser)->location;
6124 c_parser_consume_token (parser);
6125 idx = c_parser_expression (parser).value;
6126 idx = c_fully_fold (idx, false, NULL);
6127 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6129 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6134 c_parser_error (parser, "expected identifier");
6135 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6137 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6140 case RID_CHOOSE_EXPR:
6141 c_parser_consume_token (parser);
6142 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6144 expr.value = error_mark_node;
6147 loc = c_parser_peek_token (parser)->location;
6148 e1 = c_parser_expr_no_commas (parser, NULL);
6149 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6151 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6152 expr.value = error_mark_node;
6155 e2 = c_parser_expr_no_commas (parser, NULL);
6156 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6158 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6159 expr.value = error_mark_node;
6162 e3 = c_parser_expr_no_commas (parser, NULL);
6163 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6169 mark_exp_read (e2.value);
6170 mark_exp_read (e3.value);
6171 if (TREE_CODE (c) != INTEGER_CST
6172 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6174 "first argument to %<__builtin_choose_expr%> not"
6176 constant_expression_warning (c);
6177 expr = integer_zerop (c) ? e3 : e2;
6180 case RID_TYPES_COMPATIBLE_P:
6181 c_parser_consume_token (parser);
6182 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6184 expr.value = error_mark_node;
6187 t1 = c_parser_type_name (parser);
6190 expr.value = error_mark_node;
6193 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6195 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6196 expr.value = error_mark_node;
6199 t2 = c_parser_type_name (parser);
6202 expr.value = error_mark_node;
6205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6210 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6211 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6214 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6217 case RID_AT_SELECTOR:
6218 gcc_assert (c_dialect_objc ());
6219 c_parser_consume_token (parser);
6220 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6222 expr.value = error_mark_node;
6226 tree sel = c_parser_objc_selector_arg (parser);
6227 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6229 expr.value = objc_build_selector_expr (loc, sel);
6232 case RID_AT_PROTOCOL:
6233 gcc_assert (c_dialect_objc ());
6234 c_parser_consume_token (parser);
6235 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6237 expr.value = error_mark_node;
6240 if (c_parser_next_token_is_not (parser, CPP_NAME))
6242 c_parser_error (parser, "expected identifier");
6243 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6244 expr.value = error_mark_node;
6248 tree id = c_parser_peek_token (parser)->value;
6249 c_parser_consume_token (parser);
6250 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6252 expr.value = objc_build_protocol_expr (id);
6256 /* Extension to support C-structures in the archiver. */
6257 gcc_assert (c_dialect_objc ());
6258 c_parser_consume_token (parser);
6259 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6261 expr.value = error_mark_node;
6264 t1 = c_parser_type_name (parser);
6267 expr.value = error_mark_node;
6268 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6271 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6274 tree type = groktypename (t1, NULL, NULL);
6275 expr.value = objc_build_encode_expr (type);
6279 c_parser_error (parser, "expected expression");
6280 expr.value = error_mark_node;
6284 case CPP_OPEN_SQUARE:
6285 if (c_dialect_objc ())
6287 tree receiver, args;
6288 c_parser_consume_token (parser);
6289 receiver = c_parser_objc_receiver (parser);
6290 args = c_parser_objc_message_args (parser);
6291 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6293 expr.value = objc_build_message_expr (build_tree_list (receiver,
6297 /* Else fall through to report error. */
6299 c_parser_error (parser, "expected expression");
6300 expr.value = error_mark_node;
6303 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6306 /* Parse a postfix expression after a parenthesized type name: the
6307 brace-enclosed initializer of a compound literal, possibly followed
6308 by some postfix operators. This is separate because it is not
6309 possible to tell until after the type name whether a cast
6310 expression has a cast or a compound literal, or whether the operand
6311 of sizeof is a parenthesized type name or starts with a compound
6312 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6313 location of the first token after the parentheses around the type
6316 static struct c_expr
6317 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6318 struct c_type_name *type_name,
6319 location_t type_loc)
6325 location_t start_loc;
6326 tree type_expr = NULL_TREE;
6327 bool type_expr_const = true;
6328 check_compound_literal_type (type_loc, type_name);
6329 start_init (NULL_TREE, NULL, 0);
6330 type = groktypename (type_name, &type_expr, &type_expr_const);
6331 start_loc = c_parser_peek_token (parser)->location;
6332 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6334 error_at (type_loc, "compound literal has variable size");
6335 type = error_mark_node;
6337 init = c_parser_braced_init (parser, type, false);
6339 maybe_warn_string_init (type, init);
6341 if (type != error_mark_node
6342 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6343 && current_function_decl)
6345 error ("compound literal qualified by address-space qualifier");
6346 type = error_mark_node;
6350 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6351 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6352 ? CONSTRUCTOR_NON_CONST (init.value)
6353 : init.original_code == C_MAYBE_CONST_EXPR);
6354 non_const |= !type_expr_const;
6355 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6356 expr.original_code = ERROR_MARK;
6357 expr.original_type = NULL;
6360 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6362 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6363 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6367 gcc_assert (!non_const);
6368 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6369 type_expr, expr.value);
6372 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6375 /* Parse a postfix expression after the initial primary or compound
6376 literal; that is, parse a series of postfix operators.
6378 EXPR_LOC is the location of the primary expression. */
6380 static struct c_expr
6381 c_parser_postfix_expression_after_primary (c_parser *parser,
6382 location_t expr_loc,
6385 struct c_expr orig_expr;
6387 VEC(tree,gc) *exprlist;
6388 VEC(tree,gc) *origtypes;
6391 location_t op_loc = c_parser_peek_token (parser)->location;
6392 switch (c_parser_peek_token (parser)->type)
6394 case CPP_OPEN_SQUARE:
6395 /* Array reference. */
6396 c_parser_consume_token (parser);
6397 idx = c_parser_expression (parser).value;
6398 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6400 expr.value = build_array_ref (op_loc, expr.value, idx);
6401 expr.original_code = ERROR_MARK;
6402 expr.original_type = NULL;
6404 case CPP_OPEN_PAREN:
6405 /* Function call. */
6406 c_parser_consume_token (parser);
6407 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6410 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6411 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6414 mark_exp_read (expr.value);
6415 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6416 "(" after the FUNCNAME, which is what we have now. */
6417 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6419 expr.original_code = ERROR_MARK;
6420 if (TREE_CODE (expr.value) == INTEGER_CST
6421 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6422 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6423 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6424 expr.original_code = C_MAYBE_CONST_EXPR;
6425 expr.original_type = NULL;
6426 if (exprlist != NULL)
6428 release_tree_vector (exprlist);
6429 release_tree_vector (origtypes);
6433 /* Structure element reference. */
6434 c_parser_consume_token (parser);
6435 expr = default_function_array_conversion (expr_loc, expr);
6436 if (c_parser_next_token_is (parser, CPP_NAME))
6437 ident = c_parser_peek_token (parser)->value;
6440 c_parser_error (parser, "expected identifier");
6441 expr.value = error_mark_node;
6442 expr.original_code = ERROR_MARK;
6443 expr.original_type = NULL;
6446 c_parser_consume_token (parser);
6447 expr.value = build_component_ref (op_loc, expr.value, ident);
6448 expr.original_code = ERROR_MARK;
6449 if (TREE_CODE (expr.value) != COMPONENT_REF)
6450 expr.original_type = NULL;
6453 /* Remember the original type of a bitfield. */
6454 tree field = TREE_OPERAND (expr.value, 1);
6455 if (TREE_CODE (field) != FIELD_DECL)
6456 expr.original_type = NULL;
6458 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6462 /* Structure element reference. */
6463 c_parser_consume_token (parser);
6464 expr = default_function_array_conversion (expr_loc, expr);
6465 if (c_parser_next_token_is (parser, CPP_NAME))
6466 ident = c_parser_peek_token (parser)->value;
6469 c_parser_error (parser, "expected identifier");
6470 expr.value = error_mark_node;
6471 expr.original_code = ERROR_MARK;
6472 expr.original_type = NULL;
6475 c_parser_consume_token (parser);
6476 expr.value = build_component_ref (op_loc,
6477 build_indirect_ref (op_loc,
6481 expr.original_code = ERROR_MARK;
6482 if (TREE_CODE (expr.value) != COMPONENT_REF)
6483 expr.original_type = NULL;
6486 /* Remember the original type of a bitfield. */
6487 tree field = TREE_OPERAND (expr.value, 1);
6488 if (TREE_CODE (field) != FIELD_DECL)
6489 expr.original_type = NULL;
6491 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6495 /* Postincrement. */
6496 c_parser_consume_token (parser);
6497 expr = default_function_array_read_conversion (expr_loc, expr);
6498 expr.value = build_unary_op (op_loc,
6499 POSTINCREMENT_EXPR, expr.value, 0);
6500 expr.original_code = ERROR_MARK;
6501 expr.original_type = NULL;
6503 case CPP_MINUS_MINUS:
6504 /* Postdecrement. */
6505 c_parser_consume_token (parser);
6506 expr = default_function_array_read_conversion (expr_loc, expr);
6507 expr.value = build_unary_op (op_loc,
6508 POSTDECREMENT_EXPR, expr.value, 0);
6509 expr.original_code = ERROR_MARK;
6510 expr.original_type = NULL;
6518 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6521 assignment-expression
6522 expression , assignment-expression
6525 static struct c_expr
6526 c_parser_expression (c_parser *parser)
6529 expr = c_parser_expr_no_commas (parser, NULL);
6530 while (c_parser_next_token_is (parser, CPP_COMMA))
6534 location_t loc = c_parser_peek_token (parser)->location;
6535 location_t expr_loc;
6536 c_parser_consume_token (parser);
6537 expr_loc = c_parser_peek_token (parser)->location;
6538 lhsval = expr.value;
6539 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6540 lhsval = TREE_OPERAND (lhsval, 1);
6541 if (DECL_P (lhsval) || handled_component_p (lhsval))
6542 mark_exp_read (lhsval);
6543 next = c_parser_expr_no_commas (parser, NULL);
6544 next = default_function_array_conversion (expr_loc, next);
6545 expr.value = build_compound_expr (loc, expr.value, next.value);
6546 expr.original_code = COMPOUND_EXPR;
6547 expr.original_type = next.original_type;
6552 /* Parse an expression and convert functions or arrays to
6555 static struct c_expr
6556 c_parser_expression_conv (c_parser *parser)
6559 location_t loc = c_parser_peek_token (parser)->location;
6560 expr = c_parser_expression (parser);
6561 expr = default_function_array_conversion (loc, expr);
6565 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6566 functions and arrays to pointers. If FOLD_P, fold the expressions.
6569 assignment-expression
6570 nonempty-expr-list , assignment-expression
6573 static VEC(tree,gc) *
6574 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6575 VEC(tree,gc) **p_orig_types)
6578 VEC(tree,gc) *orig_types;
6580 location_t loc = c_parser_peek_token (parser)->location;
6582 ret = make_tree_vector ();
6583 if (p_orig_types == NULL)
6586 orig_types = make_tree_vector ();
6588 expr = c_parser_expr_no_commas (parser, NULL);
6590 expr = default_function_array_read_conversion (loc, expr);
6592 expr.value = c_fully_fold (expr.value, false, NULL);
6593 VEC_quick_push (tree, ret, expr.value);
6594 if (orig_types != NULL)
6595 VEC_quick_push (tree, orig_types, expr.original_type);
6596 while (c_parser_next_token_is (parser, CPP_COMMA))
6598 c_parser_consume_token (parser);
6599 loc = c_parser_peek_token (parser)->location;
6600 expr = c_parser_expr_no_commas (parser, NULL);
6602 expr = default_function_array_read_conversion (loc, expr);
6604 expr.value = c_fully_fold (expr.value, false, NULL);
6605 VEC_safe_push (tree, gc, ret, expr.value);
6606 if (orig_types != NULL)
6607 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6609 if (orig_types != NULL)
6610 *p_orig_types = orig_types;
6614 /* Parse Objective-C-specific constructs. */
6616 /* Parse an objc-class-definition.
6618 objc-class-definition:
6619 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6620 objc-class-instance-variables[opt] objc-methodprotolist @end
6621 @implementation identifier objc-superclass[opt]
6622 objc-class-instance-variables[opt]
6623 @interface identifier ( identifier ) objc-protocol-refs[opt]
6624 objc-methodprotolist @end
6625 @implementation identifier ( identifier )
6630 "@interface identifier (" must start "@interface identifier (
6631 identifier ) ...": objc-methodprotolist in the first production may
6632 not start with a parenthesized identifier as a declarator of a data
6633 definition with no declaration specifiers if the objc-superclass,
6634 objc-protocol-refs and objc-class-instance-variables are omitted. */
6637 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6642 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6644 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6649 c_parser_consume_token (parser);
6650 if (c_parser_next_token_is_not (parser, CPP_NAME))
6652 c_parser_error (parser, "expected identifier");
6655 id1 = c_parser_peek_token (parser)->value;
6656 c_parser_consume_token (parser);
6657 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6660 tree proto = NULL_TREE;
6661 c_parser_consume_token (parser);
6662 if (c_parser_next_token_is_not (parser, CPP_NAME))
6664 c_parser_error (parser, "expected identifier");
6665 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6668 id2 = c_parser_peek_token (parser)->value;
6669 c_parser_consume_token (parser);
6670 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6673 objc_start_category_implementation (id1, id2);
6676 if (c_parser_next_token_is (parser, CPP_LESS))
6677 proto = c_parser_objc_protocol_refs (parser);
6678 objc_start_category_interface (id1, id2, proto, attributes);
6679 c_parser_objc_methodprotolist (parser);
6680 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6681 objc_finish_interface ();
6684 if (c_parser_next_token_is (parser, CPP_COLON))
6686 c_parser_consume_token (parser);
6687 if (c_parser_next_token_is_not (parser, CPP_NAME))
6689 c_parser_error (parser, "expected identifier");
6692 superclass = c_parser_peek_token (parser)->value;
6693 c_parser_consume_token (parser);
6696 superclass = NULL_TREE;
6699 tree proto = NULL_TREE;
6700 if (c_parser_next_token_is (parser, CPP_LESS))
6701 proto = c_parser_objc_protocol_refs (parser);
6702 objc_start_class_interface (id1, superclass, proto, attributes);
6705 objc_start_class_implementation (id1, superclass);
6706 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6707 c_parser_objc_class_instance_variables (parser);
6710 objc_continue_interface ();
6711 c_parser_objc_methodprotolist (parser);
6712 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6713 objc_finish_interface ();
6717 objc_continue_implementation ();
6722 /* Parse objc-class-instance-variables.
6724 objc-class-instance-variables:
6725 { objc-instance-variable-decl-list[opt] }
6727 objc-instance-variable-decl-list:
6728 objc-visibility-spec
6729 objc-instance-variable-decl ;
6731 objc-instance-variable-decl-list objc-visibility-spec
6732 objc-instance-variable-decl-list objc-instance-variable-decl ;
6733 objc-instance-variable-decl-list ;
6735 objc-visibility-spec:
6740 objc-instance-variable-decl:
6745 c_parser_objc_class_instance_variables (c_parser *parser)
6747 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6748 c_parser_consume_token (parser);
6749 while (c_parser_next_token_is_not (parser, CPP_EOF))
6752 /* Parse any stray semicolon. */
6753 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6755 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6756 "extra semicolon in struct or union specified");
6757 c_parser_consume_token (parser);
6760 /* Stop if at the end of the instance variables. */
6761 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6763 c_parser_consume_token (parser);
6766 /* Parse any objc-visibility-spec. */
6767 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6769 c_parser_consume_token (parser);
6770 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6773 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6775 c_parser_consume_token (parser);
6776 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6779 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6781 c_parser_consume_token (parser);
6782 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6785 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6787 c_parser_consume_token (parser);
6788 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6791 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6793 c_parser_pragma (parser, pragma_external);
6797 /* Parse some comma-separated declarations. */
6798 decls = c_parser_struct_declaration (parser);
6800 /* Comma-separated instance variables are chained together in
6801 reverse order; add them one by one. */
6802 tree ivar = nreverse (decls);
6803 for (; ivar; ivar = DECL_CHAIN (ivar))
6804 objc_add_instance_variable (copy_node (ivar));
6806 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6810 /* Parse an objc-class-declaration.
6812 objc-class-declaration:
6813 @class identifier-list ;
6817 c_parser_objc_class_declaration (c_parser *parser)
6819 tree list = NULL_TREE;
6820 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6821 c_parser_consume_token (parser);
6822 /* Any identifiers, including those declared as type names, are OK
6827 if (c_parser_next_token_is_not (parser, CPP_NAME))
6829 c_parser_error (parser, "expected identifier");
6830 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6831 parser->error = false;
6834 id = c_parser_peek_token (parser)->value;
6835 list = chainon (list, build_tree_list (NULL_TREE, id));
6836 c_parser_consume_token (parser);
6837 if (c_parser_next_token_is (parser, CPP_COMMA))
6838 c_parser_consume_token (parser);
6842 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6843 objc_declare_class (list);
6846 /* Parse an objc-alias-declaration.
6848 objc-alias-declaration:
6849 @compatibility_alias identifier identifier ;
6853 c_parser_objc_alias_declaration (c_parser *parser)
6856 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6857 c_parser_consume_token (parser);
6858 if (c_parser_next_token_is_not (parser, CPP_NAME))
6860 c_parser_error (parser, "expected identifier");
6861 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6864 id1 = c_parser_peek_token (parser)->value;
6865 c_parser_consume_token (parser);
6866 if (c_parser_next_token_is_not (parser, CPP_NAME))
6868 c_parser_error (parser, "expected identifier");
6869 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6872 id2 = c_parser_peek_token (parser)->value;
6873 c_parser_consume_token (parser);
6874 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6875 objc_declare_alias (id1, id2);
6878 /* Parse an objc-protocol-definition.
6880 objc-protocol-definition:
6881 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6882 @protocol identifier-list ;
6884 "@protocol identifier ;" should be resolved as "@protocol
6885 identifier-list ;": objc-methodprotolist may not start with a
6886 semicolon in the first alternative if objc-protocol-refs are
6890 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6892 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6894 c_parser_consume_token (parser);
6895 if (c_parser_next_token_is_not (parser, CPP_NAME))
6897 c_parser_error (parser, "expected identifier");
6900 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6901 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6903 tree list = NULL_TREE;
6904 /* Any identifiers, including those declared as type names, are
6909 if (c_parser_next_token_is_not (parser, CPP_NAME))
6911 c_parser_error (parser, "expected identifier");
6914 id = c_parser_peek_token (parser)->value;
6915 list = chainon (list, build_tree_list (NULL_TREE, id));
6916 c_parser_consume_token (parser);
6917 if (c_parser_next_token_is (parser, CPP_COMMA))
6918 c_parser_consume_token (parser);
6922 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6923 objc_declare_protocols (list);
6927 tree id = c_parser_peek_token (parser)->value;
6928 tree proto = NULL_TREE;
6929 c_parser_consume_token (parser);
6930 if (c_parser_next_token_is (parser, CPP_LESS))
6931 proto = c_parser_objc_protocol_refs (parser);
6932 parser->objc_pq_context = true;
6933 objc_start_protocol (id, proto, attributes);
6934 c_parser_objc_methodprotolist (parser);
6935 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6936 parser->objc_pq_context = false;
6937 objc_finish_interface ();
6941 /* Parse an objc-method-type.
6947 Return true if it is a class method (+) and false if it is
6948 an instance method (-).
6951 c_parser_objc_method_type (c_parser *parser)
6953 switch (c_parser_peek_token (parser)->type)
6956 c_parser_consume_token (parser);
6959 c_parser_consume_token (parser);
6966 /* Parse an objc-method-definition.
6968 objc-method-definition:
6969 objc-method-type objc-method-decl ;[opt] compound-statement
6973 c_parser_objc_method_definition (c_parser *parser)
6975 bool is_class_method = c_parser_objc_method_type (parser);
6976 tree decl, attributes = NULL_TREE;
6977 parser->objc_pq_context = true;
6978 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
6979 if (decl == error_mark_node)
6980 return; /* Bail here. */
6982 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6984 c_parser_consume_token (parser);
6985 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6986 "extra semicolon in method definition specified");
6989 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6991 c_parser_error (parser, "expected %<{%>");
6995 parser->objc_pq_context = false;
6996 if (objc_start_method_definition (is_class_method, decl, attributes))
6998 add_stmt (c_parser_compound_statement (parser));
6999 objc_finish_method_definition (current_function_decl);
7003 /* This code is executed when we find a method definition
7004 outside of an @implementation context (or invalid for other
7005 reasons). Parse the method (to keep going) but do not emit
7008 c_parser_compound_statement (parser);
7012 /* Parse an objc-methodprotolist.
7014 objc-methodprotolist:
7016 objc-methodprotolist objc-methodproto
7017 objc-methodprotolist declaration
7018 objc-methodprotolist ;
7022 The declaration is a data definition, which may be missing
7023 declaration specifiers under the same rules and diagnostics as
7024 other data definitions outside functions, and the stray semicolon
7025 is diagnosed the same way as a stray semicolon outside a
7029 c_parser_objc_methodprotolist (c_parser *parser)
7033 /* The list is terminated by @end. */
7034 switch (c_parser_peek_token (parser)->type)
7037 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7038 "ISO C does not allow extra %<;%> outside of a function");
7039 c_parser_consume_token (parser);
7043 c_parser_objc_methodproto (parser);
7046 c_parser_pragma (parser, pragma_external);
7051 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7053 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7054 c_parser_objc_at_property_declaration (parser);
7055 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7057 objc_set_method_opt (true);
7058 c_parser_consume_token (parser);
7060 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7062 objc_set_method_opt (false);
7063 c_parser_consume_token (parser);
7066 c_parser_declaration_or_fndef (parser, false, false, true,
7073 /* Parse an objc-methodproto.
7076 objc-method-type objc-method-decl ;
7080 c_parser_objc_methodproto (c_parser *parser)
7082 bool is_class_method = c_parser_objc_method_type (parser);
7083 tree decl, attributes = NULL_TREE;
7085 /* Remember protocol qualifiers in prototypes. */
7086 parser->objc_pq_context = true;
7087 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7088 /* Forget protocol qualifiers now. */
7089 parser->objc_pq_context = false;
7091 /* Do not allow the presence of attributes to hide an erroneous
7092 method implementation in the interface section. */
7093 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7095 c_parser_error (parser, "expected %<;%>");
7099 if (decl != error_mark_node)
7100 objc_add_method_declaration (is_class_method, decl, attributes);
7102 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7105 /* If we are at a position that method attributes may be present, check that
7106 there are not any parsed already (a syntax error) and then collect any
7107 specified at the current location. Finally, if new attributes were present,
7108 check that the next token is legal ( ';' for decls and '{' for defs). */
7111 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7116 c_parser_error (parser,
7117 "method attributes must be specified at the end only");
7118 *attributes = NULL_TREE;
7122 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7123 *attributes = c_parser_attributes (parser);
7125 /* If there were no attributes here, just report any earlier error. */
7126 if (*attributes == NULL_TREE || bad)
7129 /* If the attributes are followed by a ; or {, then just report any earlier
7131 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7132 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7135 /* We've got attributes, but not at the end. */
7136 c_parser_error (parser,
7137 "expected %<;%> or %<{%> after method attribute definition");
7141 /* Parse an objc-method-decl.
7144 ( objc-type-name ) objc-selector
7146 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7147 objc-keyword-selector objc-optparmlist
7150 objc-keyword-selector:
7152 objc-keyword-selector objc-keyword-decl
7155 objc-selector : ( objc-type-name ) identifier
7156 objc-selector : identifier
7157 : ( objc-type-name ) identifier
7161 objc-optparms objc-optellipsis
7165 objc-opt-parms , parameter-declaration
7173 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7175 tree type = NULL_TREE;
7177 tree parms = NULL_TREE;
7178 bool ellipsis = false;
7179 bool attr_err = false;
7181 *attributes = NULL_TREE;
7182 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7184 c_parser_consume_token (parser);
7185 type = c_parser_objc_type_name (parser);
7186 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7188 sel = c_parser_objc_selector (parser);
7189 /* If there is no selector, or a colon follows, we have an
7190 objc-keyword-selector. If there is a selector, and a colon does
7191 not follow, that selector ends the objc-method-decl. */
7192 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7195 tree list = NULL_TREE;
7198 tree atype = NULL_TREE, id, keyworddecl;
7199 tree param_attr = NULL_TREE;
7200 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7202 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7204 c_parser_consume_token (parser);
7205 atype = c_parser_objc_type_name (parser);
7206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7209 /* New ObjC allows attributes on method parameters. */
7210 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7211 param_attr = c_parser_attributes (parser);
7212 if (c_parser_next_token_is_not (parser, CPP_NAME))
7214 c_parser_error (parser, "expected identifier");
7215 return error_mark_node;
7217 id = c_parser_peek_token (parser)->value;
7218 c_parser_consume_token (parser);
7219 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7220 list = chainon (list, keyworddecl);
7221 tsel = c_parser_objc_selector (parser);
7222 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7226 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7228 /* Parse the optional parameter list. Optional Objective-C
7229 method parameters follow the C syntax, and may include '...'
7230 to denote a variable number of arguments. */
7231 parms = make_node (TREE_LIST);
7232 while (c_parser_next_token_is (parser, CPP_COMMA))
7234 struct c_parm *parm;
7235 c_parser_consume_token (parser);
7236 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7239 c_parser_consume_token (parser);
7240 attr_err |= c_parser_objc_maybe_method_attributes
7241 (parser, attributes) ;
7244 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7247 parms = chainon (parms,
7248 build_tree_list (NULL_TREE, grokparm (parm)));
7253 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7257 c_parser_error (parser, "objective-c method declaration is expected");
7258 return error_mark_node;
7262 return error_mark_node;
7264 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7267 /* Parse an objc-type-name.
7270 objc-type-qualifiers[opt] type-name
7271 objc-type-qualifiers[opt]
7273 objc-type-qualifiers:
7275 objc-type-qualifiers objc-type-qualifier
7277 objc-type-qualifier: one of
7278 in out inout bycopy byref oneway
7282 c_parser_objc_type_name (c_parser *parser)
7284 tree quals = NULL_TREE;
7285 struct c_type_name *type_name = NULL;
7286 tree type = NULL_TREE;
7289 c_token *token = c_parser_peek_token (parser);
7290 if (token->type == CPP_KEYWORD
7291 && (token->keyword == RID_IN
7292 || token->keyword == RID_OUT
7293 || token->keyword == RID_INOUT
7294 || token->keyword == RID_BYCOPY
7295 || token->keyword == RID_BYREF
7296 || token->keyword == RID_ONEWAY))
7298 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7299 c_parser_consume_token (parser);
7304 if (c_parser_next_token_starts_typename (parser))
7305 type_name = c_parser_type_name (parser);
7307 type = groktypename (type_name, NULL, NULL);
7308 return build_tree_list (quals, type);
7311 /* Parse objc-protocol-refs.
7318 c_parser_objc_protocol_refs (c_parser *parser)
7320 tree list = NULL_TREE;
7321 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7322 c_parser_consume_token (parser);
7323 /* Any identifiers, including those declared as type names, are OK
7328 if (c_parser_next_token_is_not (parser, CPP_NAME))
7330 c_parser_error (parser, "expected identifier");
7333 id = c_parser_peek_token (parser)->value;
7334 list = chainon (list, build_tree_list (NULL_TREE, id));
7335 c_parser_consume_token (parser);
7336 if (c_parser_next_token_is (parser, CPP_COMMA))
7337 c_parser_consume_token (parser);
7341 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7345 /* Parse an objc-try-catch-statement.
7347 objc-try-catch-statement:
7348 @try compound-statement objc-catch-list[opt]
7349 @try compound-statement objc-catch-list[opt] @finally compound-statement
7352 @catch ( parameter-declaration ) compound-statement
7353 objc-catch-list @catch ( parameter-declaration ) compound-statement
7357 c_parser_objc_try_catch_statement (c_parser *parser)
7361 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7362 c_parser_consume_token (parser);
7363 loc = c_parser_peek_token (parser)->location;
7364 stmt = c_parser_compound_statement (parser);
7365 objc_begin_try_stmt (loc, stmt);
7366 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7368 struct c_parm *parm;
7369 c_parser_consume_token (parser);
7370 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7372 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7375 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7378 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7379 objc_begin_catch_clause (grokparm (parm));
7380 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7381 c_parser_compound_statement_nostart (parser);
7382 objc_finish_catch_clause ();
7384 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7388 c_parser_consume_token (parser);
7389 finloc = c_parser_peek_token (parser)->location;
7390 finstmt = c_parser_compound_statement (parser);
7391 objc_build_finally_clause (finloc, finstmt);
7393 objc_finish_try_stmt ();
7396 /* Parse an objc-synchronized-statement.
7398 objc-synchronized-statement:
7399 @synchronized ( expression ) compound-statement
7403 c_parser_objc_synchronized_statement (c_parser *parser)
7407 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7408 c_parser_consume_token (parser);
7409 loc = c_parser_peek_token (parser)->location;
7410 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7412 expr = c_parser_expression (parser).value;
7413 expr = c_fully_fold (expr, false, NULL);
7414 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7417 expr = error_mark_node;
7418 stmt = c_parser_compound_statement (parser);
7419 objc_build_synchronized (loc, expr, stmt);
7422 /* Parse an objc-selector; return NULL_TREE without an error if the
7423 next token is not an objc-selector.
7428 enum struct union if else while do for switch case default
7429 break continue return goto asm sizeof typeof __alignof
7430 unsigned long const short volatile signed restrict _Complex
7431 in out inout bycopy byref oneway int char float double void _Bool
7433 ??? Why this selection of keywords but not, for example, storage
7434 class specifiers? */
7437 c_parser_objc_selector (c_parser *parser)
7439 c_token *token = c_parser_peek_token (parser);
7440 tree value = token->value;
7441 if (token->type == CPP_NAME)
7443 c_parser_consume_token (parser);
7446 if (token->type != CPP_KEYWORD)
7448 switch (token->keyword)
7490 c_parser_consume_token (parser);
7497 /* Parse an objc-selector-arg.
7501 objc-keywordname-list
7503 objc-keywordname-list:
7505 objc-keywordname-list objc-keywordname
7513 c_parser_objc_selector_arg (c_parser *parser)
7515 tree sel = c_parser_objc_selector (parser);
7516 tree list = NULL_TREE;
7517 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7521 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7523 list = chainon (list, build_tree_list (sel, NULL_TREE));
7524 sel = c_parser_objc_selector (parser);
7525 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7531 /* Parse an objc-receiver.
7540 c_parser_objc_receiver (c_parser *parser)
7542 if (c_parser_peek_token (parser)->type == CPP_NAME
7543 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7544 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7546 tree id = c_parser_peek_token (parser)->value;
7547 c_parser_consume_token (parser);
7548 return objc_get_class_reference (id);
7550 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7553 /* Parse objc-message-args.
7557 objc-keywordarg-list
7559 objc-keywordarg-list:
7561 objc-keywordarg-list objc-keywordarg
7564 objc-selector : objc-keywordexpr
7569 c_parser_objc_message_args (c_parser *parser)
7571 tree sel = c_parser_objc_selector (parser);
7572 tree list = NULL_TREE;
7573 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7578 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7579 return error_mark_node;
7580 keywordexpr = c_parser_objc_keywordexpr (parser);
7581 list = chainon (list, build_tree_list (sel, keywordexpr));
7582 sel = c_parser_objc_selector (parser);
7583 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7589 /* Parse an objc-keywordexpr.
7596 c_parser_objc_keywordexpr (c_parser *parser)
7599 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7600 if (VEC_length (tree, expr_list) == 1)
7602 /* Just return the expression, remove a level of
7604 ret = VEC_index (tree, expr_list, 0);
7608 /* We have a comma expression, we will collapse later. */
7609 ret = build_tree_list_vec (expr_list);
7611 release_tree_vector (expr_list);
7615 /* A check, needed in several places, that ObjC interface, implementation or
7616 method definitions are not prefixed by incorrect items. */
7618 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7619 struct c_declspecs *specs)
7621 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7623 c_parser_error (parser,
7624 "no type or storage class may be specified here,");
7625 c_parser_skip_to_end_of_block_or_statement (parser);
7631 /* Parse an Objective-C @property declaration. The syntax is:
7633 objc-property-declaration:
7634 '@property' objc-property-attributes[opt] struct-declaration ;
7636 objc-property-attributes:
7637 '(' objc-property-attribute-list ')'
7639 objc-property-attribute-list:
7640 objc-property-attribute
7641 objc-property-attribute-list, objc-property-attribute
7643 objc-property-attribute
7644 'getter' = identifier
7645 'setter' = identifier
7654 @property NSString *name;
7655 @property (readonly) id object;
7656 @property (retain, nonatomic, getter=getTheName) id name;
7657 @property int a, b, c;
7659 PS: This function is identical to cp_parser_objc_at_propery_declaration
7660 for C++. Keep them in sync. */
7662 c_parser_objc_at_property_declaration (c_parser *parser)
7664 /* The following variables hold the attributes of the properties as
7665 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7666 seen. When we see an attribute, we set them to 'true' (if they
7667 are boolean properties) or to the identifier (if they have an
7668 argument, ie, for getter and setter). Note that here we only
7669 parse the list of attributes, check the syntax and accumulate the
7670 attributes that we find. objc_add_property_declaration() will
7671 then process the information. */
7672 bool property_assign = false;
7673 bool property_copy = false;
7674 tree property_getter_ident = NULL_TREE;
7675 bool property_nonatomic = false;
7676 bool property_readonly = false;
7677 bool property_readwrite = false;
7678 bool property_retain = false;
7679 tree property_setter_ident = NULL_TREE;
7681 /* 'properties' is the list of properties that we read. Usually a
7682 single one, but maybe more (eg, in "@property int a, b, c;" there
7687 loc = c_parser_peek_token (parser)->location;
7688 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7690 c_parser_consume_token (parser); /* Eat '@property'. */
7692 /* Parse the optional attribute list... */
7693 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7696 c_parser_consume_token (parser);
7698 /* Property attribute keywords are valid now. */
7699 parser->objc_property_attr_context = true;
7703 bool syntax_error = false;
7704 c_token *token = c_parser_peek_token (parser);
7707 if (token->type != CPP_KEYWORD)
7709 if (token->type == CPP_CLOSE_PAREN)
7710 c_parser_error (parser, "expected identifier");
7713 c_parser_consume_token (parser);
7714 c_parser_error (parser, "unknown property attribute");
7718 keyword = token->keyword;
7719 c_parser_consume_token (parser);
7722 case RID_ASSIGN: property_assign = true; break;
7723 case RID_COPY: property_copy = true; break;
7724 case RID_NONATOMIC: property_nonatomic = true; break;
7725 case RID_READONLY: property_readonly = true; break;
7726 case RID_READWRITE: property_readwrite = true; break;
7727 case RID_RETAIN: property_retain = true; break;
7731 if (c_parser_next_token_is_not (parser, CPP_EQ))
7733 c_parser_error (parser,
7734 "getter/setter attribute must be followed by %<=%>");
7735 syntax_error = true;
7738 c_parser_consume_token (parser); /* eat the = */
7739 if (c_parser_next_token_is_not (parser, CPP_NAME))
7741 c_parser_error (parser, "expected identifier");
7742 syntax_error = true;
7745 if (keyword == RID_SETTER)
7747 if (property_setter_ident != NULL_TREE)
7748 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7750 property_setter_ident = c_parser_peek_token (parser)->value;
7751 c_parser_consume_token (parser);
7752 if (c_parser_next_token_is_not (parser, CPP_COLON))
7753 c_parser_error (parser, "setter name must terminate with %<:%>");
7755 c_parser_consume_token (parser);
7759 if (property_getter_ident != NULL_TREE)
7760 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7762 property_getter_ident = c_parser_peek_token (parser)->value;
7763 c_parser_consume_token (parser);
7767 c_parser_error (parser, "unknown property attribute");
7768 syntax_error = true;
7775 if (c_parser_next_token_is (parser, CPP_COMMA))
7776 c_parser_consume_token (parser);
7780 parser->objc_property_attr_context = false;
7781 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7783 /* ... and the property declaration(s). */
7784 properties = c_parser_struct_declaration (parser);
7786 if (properties == error_mark_node)
7788 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7789 parser->error = false;
7793 if (properties == NULL_TREE)
7794 c_parser_error (parser, "expected identifier");
7797 /* Comma-separated properties are chained together in
7798 reverse order; add them one by one. */
7799 properties = nreverse (properties);
7801 for (; properties; properties = TREE_CHAIN (properties))
7802 objc_add_property_declaration (loc, copy_node (properties),
7803 property_readonly, property_readwrite,
7804 property_assign, property_retain,
7805 property_copy, property_nonatomic,
7806 property_getter_ident, property_setter_ident);
7809 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7810 parser->error = false;
7813 /* Parse an Objective-C @synthesize declaration. The syntax is:
7815 objc-synthesize-declaration:
7816 @synthesize objc-synthesize-identifier-list ;
7818 objc-synthesize-identifier-list:
7819 objc-synthesize-identifier
7820 objc-synthesize-identifier-list, objc-synthesize-identifier
7822 objc-synthesize-identifier
7824 identifier = identifier
7827 @synthesize MyProperty;
7828 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
7830 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
7831 for C++. Keep them in sync.
7834 c_parser_objc_at_synthesize_declaration (c_parser *parser)
7836 tree list = NULL_TREE;
7838 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
7839 loc = c_parser_peek_token (parser)->location;
7841 c_parser_consume_token (parser);
7844 tree property, ivar;
7845 if (c_parser_next_token_is_not (parser, CPP_NAME))
7847 c_parser_error (parser, "expected identifier");
7848 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7849 /* Once we find the semicolon, we can resume normal parsing.
7850 We have to reset parser->error manually because
7851 c_parser_skip_until_found() won't reset it for us if the
7852 next token is precisely a semicolon. */
7853 parser->error = false;
7856 property = c_parser_peek_token (parser)->value;
7857 c_parser_consume_token (parser);
7858 if (c_parser_next_token_is (parser, CPP_EQ))
7860 c_parser_consume_token (parser);
7861 if (c_parser_next_token_is_not (parser, CPP_NAME))
7863 c_parser_error (parser, "expected identifier");
7864 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7865 parser->error = false;
7868 ivar = c_parser_peek_token (parser)->value;
7869 c_parser_consume_token (parser);
7873 list = chainon (list, build_tree_list (ivar, property));
7874 if (c_parser_next_token_is (parser, CPP_COMMA))
7875 c_parser_consume_token (parser);
7879 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7880 objc_add_synthesize_declaration (loc, list);
7883 /* Parse an Objective-C @dynamic declaration. The syntax is:
7885 objc-dynamic-declaration:
7886 @dynamic identifier-list ;
7889 @dynamic MyProperty;
7890 @dynamic MyProperty, AnotherProperty;
7892 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
7893 for C++. Keep them in sync.
7896 c_parser_objc_at_dynamic_declaration (c_parser *parser)
7898 tree list = NULL_TREE;
7900 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
7901 loc = c_parser_peek_token (parser)->location;
7903 c_parser_consume_token (parser);
7907 if (c_parser_next_token_is_not (parser, CPP_NAME))
7909 c_parser_error (parser, "expected identifier");
7910 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7911 parser->error = false;
7914 property = c_parser_peek_token (parser)->value;
7915 list = chainon (list, build_tree_list (NULL_TREE, property));
7916 c_parser_consume_token (parser);
7917 if (c_parser_next_token_is (parser, CPP_COMMA))
7918 c_parser_consume_token (parser);
7922 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7923 objc_add_dynamic_declaration (loc, list);
7927 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7928 should be considered, statements. ALLOW_STMT is true if we're within
7929 the context of a function and such pragmas are to be allowed. Returns
7930 true if we actually parsed such a pragma. */
7933 c_parser_pragma (c_parser *parser, enum pragma_context context)
7937 id = c_parser_peek_token (parser)->pragma_kind;
7938 gcc_assert (id != PRAGMA_NONE);
7942 case PRAGMA_OMP_BARRIER:
7943 if (context != pragma_compound)
7945 if (context == pragma_stmt)
7946 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7947 "used in compound statements");
7950 c_parser_omp_barrier (parser);
7953 case PRAGMA_OMP_FLUSH:
7954 if (context != pragma_compound)
7956 if (context == pragma_stmt)
7957 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7958 "used in compound statements");
7961 c_parser_omp_flush (parser);
7964 case PRAGMA_OMP_TASKWAIT:
7965 if (context != pragma_compound)
7967 if (context == pragma_stmt)
7968 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7969 "used in compound statements");
7972 c_parser_omp_taskwait (parser);
7975 case PRAGMA_OMP_THREADPRIVATE:
7976 c_parser_omp_threadprivate (parser);
7979 case PRAGMA_OMP_SECTION:
7980 error_at (c_parser_peek_token (parser)->location,
7981 "%<#pragma omp section%> may only be used in "
7982 "%<#pragma omp sections%> construct");
7983 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7986 case PRAGMA_GCC_PCH_PREPROCESS:
7987 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7988 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7992 if (id < PRAGMA_FIRST_EXTERNAL)
7994 if (context == pragma_external)
7997 c_parser_error (parser, "expected declaration specifiers");
7998 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8001 c_parser_omp_construct (parser);
8007 c_parser_consume_pragma (parser);
8008 c_invoke_pragma_handler (id);
8010 /* Skip to EOL, but suppress any error message. Those will have been
8011 generated by the handler routine through calling error, as opposed
8012 to calling c_parser_error. */
8013 parser->error = true;
8014 c_parser_skip_to_pragma_eol (parser);
8019 /* The interface the pragma parsers have to the lexer. */
8022 pragma_lex (tree *value)
8024 c_token *tok = c_parser_peek_token (the_parser);
8025 enum cpp_ttype ret = tok->type;
8027 *value = tok->value;
8028 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8032 if (ret == CPP_KEYWORD)
8034 c_parser_consume_token (the_parser);
8041 c_parser_pragma_pch_preprocess (c_parser *parser)
8045 c_parser_consume_pragma (parser);
8046 if (c_parser_next_token_is (parser, CPP_STRING))
8048 name = c_parser_peek_token (parser)->value;
8049 c_parser_consume_token (parser);
8052 c_parser_error (parser, "expected string literal");
8053 c_parser_skip_to_pragma_eol (parser);
8056 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8059 /* OpenMP 2.5 parsing routines. */
8061 /* Returns name of the next clause.
8062 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8063 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8064 returned and the token is consumed. */
8066 static pragma_omp_clause
8067 c_parser_omp_clause_name (c_parser *parser)
8069 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8071 if (c_parser_next_token_is_keyword (parser, RID_IF))
8072 result = PRAGMA_OMP_CLAUSE_IF;
8073 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8074 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8075 else if (c_parser_next_token_is (parser, CPP_NAME))
8077 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8082 if (!strcmp ("collapse", p))
8083 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8084 else if (!strcmp ("copyin", p))
8085 result = PRAGMA_OMP_CLAUSE_COPYIN;
8086 else if (!strcmp ("copyprivate", p))
8087 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8090 if (!strcmp ("firstprivate", p))
8091 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8094 if (!strcmp ("lastprivate", p))
8095 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8098 if (!strcmp ("nowait", p))
8099 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8100 else if (!strcmp ("num_threads", p))
8101 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8104 if (!strcmp ("ordered", p))
8105 result = PRAGMA_OMP_CLAUSE_ORDERED;
8108 if (!strcmp ("private", p))
8109 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8112 if (!strcmp ("reduction", p))
8113 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8116 if (!strcmp ("schedule", p))
8117 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8118 else if (!strcmp ("shared", p))
8119 result = PRAGMA_OMP_CLAUSE_SHARED;
8122 if (!strcmp ("untied", p))
8123 result = PRAGMA_OMP_CLAUSE_UNTIED;
8128 if (result != PRAGMA_OMP_CLAUSE_NONE)
8129 c_parser_consume_token (parser);
8134 /* Validate that a clause of the given type does not already exist. */
8137 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8142 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8143 if (OMP_CLAUSE_CODE (c) == code)
8145 location_t loc = OMP_CLAUSE_LOCATION (c);
8146 error_at (loc, "too many %qs clauses", name);
8154 variable-list , identifier
8156 If KIND is nonzero, create the appropriate node and install the
8157 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8158 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8160 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8161 return the list created. */
8164 c_parser_omp_variable_list (c_parser *parser,
8165 location_t clause_loc,
8166 enum omp_clause_code kind,
8169 if (c_parser_next_token_is_not (parser, CPP_NAME)
8170 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8171 c_parser_error (parser, "expected identifier");
8173 while (c_parser_next_token_is (parser, CPP_NAME)
8174 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8176 tree t = lookup_name (c_parser_peek_token (parser)->value);
8179 undeclared_variable (c_parser_peek_token (parser)->location,
8180 c_parser_peek_token (parser)->value);
8181 else if (t == error_mark_node)
8185 tree u = build_omp_clause (clause_loc, kind);
8186 OMP_CLAUSE_DECL (u) = t;
8187 OMP_CLAUSE_CHAIN (u) = list;
8191 list = tree_cons (t, NULL_TREE, list);
8193 c_parser_consume_token (parser);
8195 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8198 c_parser_consume_token (parser);
8204 /* Similarly, but expect leading and trailing parenthesis. This is a very
8205 common case for omp clauses. */
8208 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8211 /* The clauses location. */
8212 location_t loc = c_parser_peek_token (parser)->location;
8214 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8216 list = c_parser_omp_variable_list (parser, loc, kind, list);
8217 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8223 collapse ( constant-expression ) */
8226 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8228 tree c, num = error_mark_node;
8232 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8234 loc = c_parser_peek_token (parser)->location;
8235 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8237 num = c_parser_expr_no_commas (parser, NULL).value;
8238 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8240 if (num == error_mark_node)
8242 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8243 || !host_integerp (num, 0)
8244 || (n = tree_low_cst (num, 0)) <= 0
8248 "collapse argument needs positive constant integer expression");
8251 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8252 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8253 OMP_CLAUSE_CHAIN (c) = list;
8258 copyin ( variable-list ) */
8261 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8263 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8267 copyprivate ( variable-list ) */
8270 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8272 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8276 default ( shared | none ) */
8279 c_parser_omp_clause_default (c_parser *parser, tree list)
8281 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8282 location_t loc = c_parser_peek_token (parser)->location;
8285 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8287 if (c_parser_next_token_is (parser, CPP_NAME))
8289 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8294 if (strcmp ("none", p) != 0)
8296 kind = OMP_CLAUSE_DEFAULT_NONE;
8300 if (strcmp ("shared", p) != 0)
8302 kind = OMP_CLAUSE_DEFAULT_SHARED;
8309 c_parser_consume_token (parser);
8314 c_parser_error (parser, "expected %<none%> or %<shared%>");
8316 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8318 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8321 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8322 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8323 OMP_CLAUSE_CHAIN (c) = list;
8324 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8330 firstprivate ( variable-list ) */
8333 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8335 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8339 if ( expression ) */
8342 c_parser_omp_clause_if (c_parser *parser, tree list)
8344 location_t loc = c_parser_peek_token (parser)->location;
8345 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8347 tree t = c_parser_paren_condition (parser);
8350 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8352 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8353 OMP_CLAUSE_IF_EXPR (c) = t;
8354 OMP_CLAUSE_CHAIN (c) = list;
8358 c_parser_error (parser, "expected %<(%>");
8364 lastprivate ( variable-list ) */
8367 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8369 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8376 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8379 location_t loc = c_parser_peek_token (parser)->location;
8381 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8383 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8384 OMP_CLAUSE_CHAIN (c) = list;
8389 num_threads ( expression ) */
8392 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8394 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8395 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8397 location_t expr_loc = c_parser_peek_token (parser)->location;
8398 tree c, t = c_parser_expression (parser).value;
8399 t = c_fully_fold (t, false, NULL);
8401 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8403 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8405 c_parser_error (parser, "expected integer expression");
8409 /* Attempt to statically determine when the number isn't positive. */
8410 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8411 build_int_cst (TREE_TYPE (t), 0));
8412 if (CAN_HAVE_LOCATION_P (c))
8413 SET_EXPR_LOCATION (c, expr_loc);
8414 if (c == boolean_true_node)
8416 warning_at (expr_loc, 0,
8417 "%<num_threads%> value must be positive");
8418 t = integer_one_node;
8421 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8423 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8424 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8425 OMP_CLAUSE_CHAIN (c) = list;
8436 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8440 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8442 c = build_omp_clause (c_parser_peek_token (parser)->location,
8443 OMP_CLAUSE_ORDERED);
8444 OMP_CLAUSE_CHAIN (c) = list;
8450 private ( variable-list ) */
8453 c_parser_omp_clause_private (c_parser *parser, tree list)
8455 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8459 reduction ( reduction-operator : variable-list )
8462 One of: + * - & ^ | && || */
8465 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8467 location_t clause_loc = c_parser_peek_token (parser)->location;
8468 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8470 enum tree_code code;
8472 switch (c_parser_peek_token (parser)->type)
8484 code = BIT_AND_EXPR;
8487 code = BIT_XOR_EXPR;
8490 code = BIT_IOR_EXPR;
8493 code = TRUTH_ANDIF_EXPR;
8496 code = TRUTH_ORIF_EXPR;
8499 c_parser_error (parser,
8500 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8501 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8502 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8505 c_parser_consume_token (parser);
8506 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8510 nl = c_parser_omp_variable_list (parser, clause_loc,
8511 OMP_CLAUSE_REDUCTION, list);
8512 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8513 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8517 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8523 schedule ( schedule-kind )
8524 schedule ( schedule-kind , expression )
8527 static | dynamic | guided | runtime | auto
8531 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8534 location_t loc = c_parser_peek_token (parser)->location;
8536 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8539 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8541 if (c_parser_next_token_is (parser, CPP_NAME))
8543 tree kind = c_parser_peek_token (parser)->value;
8544 const char *p = IDENTIFIER_POINTER (kind);
8549 if (strcmp ("dynamic", p) != 0)
8551 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8555 if (strcmp ("guided", p) != 0)
8557 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8561 if (strcmp ("runtime", p) != 0)
8563 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8570 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8571 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8572 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8573 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8577 c_parser_consume_token (parser);
8578 if (c_parser_next_token_is (parser, CPP_COMMA))
8581 c_parser_consume_token (parser);
8583 here = c_parser_peek_token (parser)->location;
8584 t = c_parser_expr_no_commas (parser, NULL).value;
8585 t = c_fully_fold (t, false, NULL);
8587 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8588 error_at (here, "schedule %<runtime%> does not take "
8589 "a %<chunk_size%> parameter");
8590 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8592 "schedule %<auto%> does not take "
8593 "a %<chunk_size%> parameter");
8594 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8595 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8597 c_parser_error (parser, "expected integer expression");
8599 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8602 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8603 "expected %<,%> or %<)%>");
8605 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8606 OMP_CLAUSE_CHAIN (c) = list;
8610 c_parser_error (parser, "invalid schedule kind");
8611 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8616 shared ( variable-list ) */
8619 c_parser_omp_clause_shared (c_parser *parser, tree list)
8621 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8628 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8632 /* FIXME: Should we allow duplicates? */
8633 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8635 c = build_omp_clause (c_parser_peek_token (parser)->location,
8637 OMP_CLAUSE_CHAIN (c) = list;
8642 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8643 is a bitmask in MASK. Return the list of clauses found; the result
8644 of clause default goes in *pdefault. */
8647 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8650 tree clauses = NULL;
8653 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8656 pragma_omp_clause c_kind;
8658 tree prev = clauses;
8660 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8661 c_parser_consume_token (parser);
8664 here = c_parser_peek_token (parser)->location;
8665 c_kind = c_parser_omp_clause_name (parser);
8669 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8670 clauses = c_parser_omp_clause_collapse (parser, clauses);
8671 c_name = "collapse";
8673 case PRAGMA_OMP_CLAUSE_COPYIN:
8674 clauses = c_parser_omp_clause_copyin (parser, clauses);
8677 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8678 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8679 c_name = "copyprivate";
8681 case PRAGMA_OMP_CLAUSE_DEFAULT:
8682 clauses = c_parser_omp_clause_default (parser, clauses);
8685 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8686 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8687 c_name = "firstprivate";
8689 case PRAGMA_OMP_CLAUSE_IF:
8690 clauses = c_parser_omp_clause_if (parser, clauses);
8693 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8694 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8695 c_name = "lastprivate";
8697 case PRAGMA_OMP_CLAUSE_NOWAIT:
8698 clauses = c_parser_omp_clause_nowait (parser, clauses);
8701 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8702 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8703 c_name = "num_threads";
8705 case PRAGMA_OMP_CLAUSE_ORDERED:
8706 clauses = c_parser_omp_clause_ordered (parser, clauses);
8709 case PRAGMA_OMP_CLAUSE_PRIVATE:
8710 clauses = c_parser_omp_clause_private (parser, clauses);
8713 case PRAGMA_OMP_CLAUSE_REDUCTION:
8714 clauses = c_parser_omp_clause_reduction (parser, clauses);
8715 c_name = "reduction";
8717 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8718 clauses = c_parser_omp_clause_schedule (parser, clauses);
8719 c_name = "schedule";
8721 case PRAGMA_OMP_CLAUSE_SHARED:
8722 clauses = c_parser_omp_clause_shared (parser, clauses);
8725 case PRAGMA_OMP_CLAUSE_UNTIED:
8726 clauses = c_parser_omp_clause_untied (parser, clauses);
8730 c_parser_error (parser, "expected %<#pragma omp%> clause");
8734 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8736 /* Remove the invalid clause(s) from the list to avoid
8737 confusing the rest of the compiler. */
8739 error_at (here, "%qs is not valid for %qs", c_name, where);
8744 c_parser_skip_to_pragma_eol (parser);
8746 return c_finish_omp_clauses (clauses);
8753 In practice, we're also interested in adding the statement to an
8754 outer node. So it is convenient if we work around the fact that
8755 c_parser_statement calls add_stmt. */
8758 c_parser_omp_structured_block (c_parser *parser)
8760 tree stmt = push_stmt_list ();
8761 c_parser_statement (parser);
8762 return pop_stmt_list (stmt);
8766 # pragma omp atomic new-line
8770 x binop= expr | x++ | ++x | x-- | --x
8772 +, *, -, /, &, ^, |, <<, >>
8774 where x is an lvalue expression with scalar type.
8776 LOC is the location of the #pragma token. */
8779 c_parser_omp_atomic (location_t loc, c_parser *parser)
8783 enum tree_code code;
8784 struct c_expr rhs_expr;
8786 c_parser_skip_to_pragma_eol (parser);
8788 lhs = c_parser_unary_expression (parser).value;
8789 lhs = c_fully_fold (lhs, false, NULL);
8790 switch (TREE_CODE (lhs))
8794 c_parser_skip_to_end_of_block_or_statement (parser);
8797 case PREINCREMENT_EXPR:
8798 case POSTINCREMENT_EXPR:
8799 lhs = TREE_OPERAND (lhs, 0);
8801 rhs = integer_one_node;
8804 case PREDECREMENT_EXPR:
8805 case POSTDECREMENT_EXPR:
8806 lhs = TREE_OPERAND (lhs, 0);
8808 rhs = integer_one_node;
8812 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8813 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8814 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8815 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8816 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8817 (TREE_OPERAND (lhs, 1), 0), 0)))
8819 /* Undo effects of boolean_increment for post {in,de}crement. */
8820 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8823 if (TREE_CODE (lhs) == MODIFY_EXPR
8824 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8826 /* Undo effects of boolean_increment. */
8827 if (integer_onep (TREE_OPERAND (lhs, 1)))
8829 /* This is pre or post increment. */
8830 rhs = TREE_OPERAND (lhs, 1);
8831 lhs = TREE_OPERAND (lhs, 0);
8835 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8836 && TREE_OPERAND (lhs, 0)
8837 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8839 /* This is pre or post decrement. */
8840 rhs = TREE_OPERAND (lhs, 1);
8841 lhs = TREE_OPERAND (lhs, 0);
8848 switch (c_parser_peek_token (parser)->type)
8854 code = TRUNC_DIV_EXPR;
8869 code = BIT_AND_EXPR;
8872 code = BIT_IOR_EXPR;
8875 code = BIT_XOR_EXPR;
8878 c_parser_error (parser,
8879 "invalid operator for %<#pragma omp atomic%>");
8883 c_parser_consume_token (parser);
8885 location_t rhs_loc = c_parser_peek_token (parser)->location;
8886 rhs_expr = c_parser_expression (parser);
8887 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8889 rhs = rhs_expr.value;
8890 rhs = c_fully_fold (rhs, false, NULL);
8893 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8894 if (stmt != error_mark_node)
8896 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8901 # pragma omp barrier new-line
8905 c_parser_omp_barrier (c_parser *parser)
8907 location_t loc = c_parser_peek_token (parser)->location;
8908 c_parser_consume_pragma (parser);
8909 c_parser_skip_to_pragma_eol (parser);
8911 c_finish_omp_barrier (loc);
8915 # pragma omp critical [(name)] new-line
8918 LOC is the location of the #pragma itself. */
8921 c_parser_omp_critical (location_t loc, c_parser *parser)
8923 tree stmt, name = NULL;
8925 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8927 c_parser_consume_token (parser);
8928 if (c_parser_next_token_is (parser, CPP_NAME))
8930 name = c_parser_peek_token (parser)->value;
8931 c_parser_consume_token (parser);
8932 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8935 c_parser_error (parser, "expected identifier");
8937 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8938 c_parser_error (parser, "expected %<(%> or end of line");
8939 c_parser_skip_to_pragma_eol (parser);
8941 stmt = c_parser_omp_structured_block (parser);
8942 return c_finish_omp_critical (loc, stmt, name);
8946 # pragma omp flush flush-vars[opt] new-line
8949 ( variable-list ) */
8952 c_parser_omp_flush (c_parser *parser)
8954 location_t loc = c_parser_peek_token (parser)->location;
8955 c_parser_consume_pragma (parser);
8956 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8957 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8958 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8959 c_parser_error (parser, "expected %<(%> or end of line");
8960 c_parser_skip_to_pragma_eol (parser);
8962 c_finish_omp_flush (loc);
8965 /* Parse the restricted form of the for statement allowed by OpenMP.
8966 The real trick here is to determine the loop control variable early
8967 so that we can push a new decl if necessary to make it private.
8968 LOC is the location of the OMP in "#pragma omp". */
8971 c_parser_omp_for_loop (location_t loc,
8972 c_parser *parser, tree clauses, tree *par_clauses)
8974 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8975 tree declv, condv, incrv, initv, ret = NULL;
8976 bool fail = false, open_brace_parsed = false;
8977 int i, collapse = 1, nbraces = 0;
8979 VEC(tree,gc) *for_block = make_tree_vector ();
8981 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8982 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8983 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8985 gcc_assert (collapse >= 1);
8987 declv = make_tree_vec (collapse);
8988 initv = make_tree_vec (collapse);
8989 condv = make_tree_vec (collapse);
8990 incrv = make_tree_vec (collapse);
8992 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8994 c_parser_error (parser, "for statement expected");
8997 for_loc = c_parser_peek_token (parser)->location;
8998 c_parser_consume_token (parser);
9000 for (i = 0; i < collapse; i++)
9004 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9007 /* Parse the initialization declaration or expression. */
9008 if (c_parser_next_token_starts_declaration (parser))
9011 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9012 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9013 decl = check_for_loop_decls (for_loc, flag_isoc99);
9016 if (DECL_INITIAL (decl) == error_mark_node)
9017 decl = error_mark_node;
9020 else if (c_parser_next_token_is (parser, CPP_NAME)
9021 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9023 struct c_expr decl_exp;
9024 struct c_expr init_exp;
9025 location_t init_loc;
9027 decl_exp = c_parser_postfix_expression (parser);
9028 decl = decl_exp.value;
9030 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9032 init_loc = c_parser_peek_token (parser)->location;
9033 init_exp = c_parser_expr_no_commas (parser, NULL);
9034 init_exp = default_function_array_read_conversion (init_loc,
9036 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9037 NOP_EXPR, init_loc, init_exp.value,
9038 init_exp.original_type);
9039 init = c_process_expr_stmt (init_loc, init);
9041 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9046 c_parser_error (parser,
9047 "expected iteration declaration or initialization");
9048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9054 /* Parse the loop condition. */
9056 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9058 location_t cond_loc = c_parser_peek_token (parser)->location;
9059 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
9061 cond = cond_expr.value;
9062 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9063 cond = c_fully_fold (cond, false, NULL);
9064 switch (cond_expr.original_code)
9072 /* Can't be cond = error_mark_node, because we want to preserve
9073 the location until c_finish_omp_for. */
9074 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9077 protected_set_expr_location (cond, cond_loc);
9079 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9081 /* Parse the increment expression. */
9083 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9085 location_t incr_loc = c_parser_peek_token (parser)->location;
9087 incr = c_process_expr_stmt (incr_loc,
9088 c_parser_expression (parser).value);
9090 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9092 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9096 TREE_VEC_ELT (declv, i) = decl;
9097 TREE_VEC_ELT (initv, i) = init;
9098 TREE_VEC_ELT (condv, i) = cond;
9099 TREE_VEC_ELT (incrv, i) = incr;
9103 if (i == collapse - 1)
9106 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9107 in between the collapsed for loops to be still considered perfectly
9108 nested. Hopefully the final version clarifies this.
9109 For now handle (multiple) {'s and empty statements. */
9112 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9114 c_parser_consume_token (parser);
9117 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9119 c_parser_consume_token (parser);
9123 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9124 c_parser_consume_token (parser);
9127 c_parser_error (parser, "not enough perfectly nested loops");
9130 open_brace_parsed = true;
9140 nbraces += bracecount;
9143 save_break = c_break_label;
9144 c_break_label = size_one_node;
9145 save_cont = c_cont_label;
9146 c_cont_label = NULL_TREE;
9147 body = push_stmt_list ();
9149 if (open_brace_parsed)
9151 location_t here = c_parser_peek_token (parser)->location;
9152 stmt = c_begin_compound_stmt (true);
9153 c_parser_compound_statement_nostart (parser);
9154 add_stmt (c_end_compound_stmt (here, stmt, true));
9157 add_stmt (c_parser_c99_block_statement (parser));
9160 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9161 SET_EXPR_LOCATION (t, loc);
9165 body = pop_stmt_list (body);
9166 c_break_label = save_break;
9167 c_cont_label = save_cont;
9171 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9173 c_parser_consume_token (parser);
9176 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9177 c_parser_consume_token (parser);
9180 c_parser_error (parser, "collapsed loops not perfectly nested");
9183 location_t here = c_parser_peek_token (parser)->location;
9184 stmt = c_begin_compound_stmt (true);
9186 c_parser_compound_statement_nostart (parser);
9187 body = c_end_compound_stmt (here, stmt, true);
9194 /* Only bother calling c_finish_omp_for if we haven't already generated
9195 an error from the initialization parsing. */
9198 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9201 if (par_clauses != NULL)
9204 for (c = par_clauses; *c ; )
9205 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9206 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9207 c = &OMP_CLAUSE_CHAIN (*c);
9210 for (i = 0; i < collapse; i++)
9211 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9214 c = &OMP_CLAUSE_CHAIN (*c);
9215 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9218 "iteration variable %qD should not be firstprivate",
9219 OMP_CLAUSE_DECL (*c));
9220 *c = OMP_CLAUSE_CHAIN (*c);
9224 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9225 change it to shared (decl) in
9226 OMP_PARALLEL_CLAUSES. */
9227 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9228 OMP_CLAUSE_LASTPRIVATE);
9229 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9230 OMP_CLAUSE_CHAIN (l) = clauses;
9232 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9236 OMP_FOR_CLAUSES (stmt) = clauses;
9241 while (!VEC_empty (tree, for_block))
9243 /* FIXME diagnostics: LOC below should be the actual location of
9244 this particular for block. We need to build a list of
9245 locations to go along with FOR_BLOCK. */
9246 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9249 release_tree_vector (for_block);
9254 #pragma omp for for-clause[optseq] new-line
9257 LOC is the location of the #pragma token.
9260 #define OMP_FOR_CLAUSE_MASK \
9261 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9262 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9263 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9264 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9265 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9266 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9267 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9268 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9271 c_parser_omp_for (location_t loc, c_parser *parser)
9273 tree block, clauses, ret;
9275 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9278 block = c_begin_compound_stmt (true);
9279 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9280 block = c_end_compound_stmt (loc, block, true);
9287 # pragma omp master new-line
9290 LOC is the location of the #pragma token.
9294 c_parser_omp_master (location_t loc, c_parser *parser)
9296 c_parser_skip_to_pragma_eol (parser);
9297 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9301 # pragma omp ordered new-line
9304 LOC is the location of the #pragma itself.
9308 c_parser_omp_ordered (location_t loc, c_parser *parser)
9310 c_parser_skip_to_pragma_eol (parser);
9311 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9317 { section-sequence }
9320 section-directive[opt] structured-block
9321 section-sequence section-directive structured-block
9323 SECTIONS_LOC is the location of the #pragma omp sections. */
9326 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9329 bool error_suppress = false;
9332 loc = c_parser_peek_token (parser)->location;
9333 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9335 /* Avoid skipping until the end of the block. */
9336 parser->error = false;
9340 stmt = push_stmt_list ();
9342 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9344 substmt = push_stmt_list ();
9348 c_parser_statement (parser);
9350 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9352 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9354 if (c_parser_next_token_is (parser, CPP_EOF))
9358 substmt = pop_stmt_list (substmt);
9359 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9360 SET_EXPR_LOCATION (substmt, loc);
9366 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9368 if (c_parser_next_token_is (parser, CPP_EOF))
9371 loc = c_parser_peek_token (parser)->location;
9372 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9374 c_parser_consume_pragma (parser);
9375 c_parser_skip_to_pragma_eol (parser);
9376 error_suppress = false;
9378 else if (!error_suppress)
9380 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9381 error_suppress = true;
9384 substmt = c_parser_omp_structured_block (parser);
9385 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9386 SET_EXPR_LOCATION (substmt, loc);
9389 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9390 "expected %<#pragma omp section%> or %<}%>");
9392 substmt = pop_stmt_list (stmt);
9394 stmt = make_node (OMP_SECTIONS);
9395 SET_EXPR_LOCATION (stmt, sections_loc);
9396 TREE_TYPE (stmt) = void_type_node;
9397 OMP_SECTIONS_BODY (stmt) = substmt;
9399 return add_stmt (stmt);
9403 # pragma omp sections sections-clause[optseq] newline
9406 LOC is the location of the #pragma token.
9409 #define OMP_SECTIONS_CLAUSE_MASK \
9410 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9411 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9412 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9413 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9414 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9417 c_parser_omp_sections (location_t loc, c_parser *parser)
9419 tree block, clauses, ret;
9421 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9422 "#pragma omp sections");
9424 block = c_begin_compound_stmt (true);
9425 ret = c_parser_omp_sections_scope (loc, parser);
9427 OMP_SECTIONS_CLAUSES (ret) = clauses;
9428 block = c_end_compound_stmt (loc, block, true);
9435 # pragma parallel parallel-clause new-line
9436 # pragma parallel for parallel-for-clause new-line
9437 # pragma parallel sections parallel-sections-clause new-line
9439 LOC is the location of the #pragma token.
9442 #define OMP_PARALLEL_CLAUSE_MASK \
9443 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9444 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9445 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9446 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9447 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9448 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9449 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9450 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9453 c_parser_omp_parallel (location_t loc, c_parser *parser)
9455 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9456 const char *p_name = "#pragma omp parallel";
9457 tree stmt, clauses, par_clause, ws_clause, block;
9458 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9460 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9462 c_parser_consume_token (parser);
9463 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9464 p_name = "#pragma omp parallel for";
9465 mask |= OMP_FOR_CLAUSE_MASK;
9466 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9468 else if (c_parser_next_token_is (parser, CPP_NAME))
9470 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9471 if (strcmp (p, "sections") == 0)
9473 c_parser_consume_token (parser);
9474 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9475 p_name = "#pragma omp parallel sections";
9476 mask |= OMP_SECTIONS_CLAUSE_MASK;
9477 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9481 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9485 case PRAGMA_OMP_PARALLEL:
9486 block = c_begin_omp_parallel ();
9487 c_parser_statement (parser);
9488 stmt = c_finish_omp_parallel (loc, clauses, block);
9491 case PRAGMA_OMP_PARALLEL_FOR:
9492 block = c_begin_omp_parallel ();
9493 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9494 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9495 stmt = c_finish_omp_parallel (loc, par_clause, block);
9496 OMP_PARALLEL_COMBINED (stmt) = 1;
9499 case PRAGMA_OMP_PARALLEL_SECTIONS:
9500 block = c_begin_omp_parallel ();
9501 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9502 stmt = c_parser_omp_sections_scope (loc, parser);
9504 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9505 stmt = c_finish_omp_parallel (loc, par_clause, block);
9506 OMP_PARALLEL_COMBINED (stmt) = 1;
9517 # pragma omp single single-clause[optseq] new-line
9520 LOC is the location of the #pragma.
9523 #define OMP_SINGLE_CLAUSE_MASK \
9524 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9525 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9526 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9527 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9530 c_parser_omp_single (location_t loc, c_parser *parser)
9532 tree stmt = make_node (OMP_SINGLE);
9533 SET_EXPR_LOCATION (stmt, loc);
9534 TREE_TYPE (stmt) = void_type_node;
9536 OMP_SINGLE_CLAUSES (stmt)
9537 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9538 "#pragma omp single");
9539 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9541 return add_stmt (stmt);
9545 # pragma omp task task-clause[optseq] new-line
9547 LOC is the location of the #pragma.
9550 #define OMP_TASK_CLAUSE_MASK \
9551 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9552 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9553 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9554 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9555 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9556 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9559 c_parser_omp_task (location_t loc, c_parser *parser)
9561 tree clauses, block;
9563 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9564 "#pragma omp task");
9566 block = c_begin_omp_task ();
9567 c_parser_statement (parser);
9568 return c_finish_omp_task (loc, clauses, block);
9572 # pragma omp taskwait new-line
9576 c_parser_omp_taskwait (c_parser *parser)
9578 location_t loc = c_parser_peek_token (parser)->location;
9579 c_parser_consume_pragma (parser);
9580 c_parser_skip_to_pragma_eol (parser);
9582 c_finish_omp_taskwait (loc);
9585 /* Main entry point to parsing most OpenMP pragmas. */
9588 c_parser_omp_construct (c_parser *parser)
9590 enum pragma_kind p_kind;
9594 loc = c_parser_peek_token (parser)->location;
9595 p_kind = c_parser_peek_token (parser)->pragma_kind;
9596 c_parser_consume_pragma (parser);
9600 case PRAGMA_OMP_ATOMIC:
9601 c_parser_omp_atomic (loc, parser);
9603 case PRAGMA_OMP_CRITICAL:
9604 stmt = c_parser_omp_critical (loc, parser);
9606 case PRAGMA_OMP_FOR:
9607 stmt = c_parser_omp_for (loc, parser);
9609 case PRAGMA_OMP_MASTER:
9610 stmt = c_parser_omp_master (loc, parser);
9612 case PRAGMA_OMP_ORDERED:
9613 stmt = c_parser_omp_ordered (loc, parser);
9615 case PRAGMA_OMP_PARALLEL:
9616 stmt = c_parser_omp_parallel (loc, parser);
9618 case PRAGMA_OMP_SECTIONS:
9619 stmt = c_parser_omp_sections (loc, parser);
9621 case PRAGMA_OMP_SINGLE:
9622 stmt = c_parser_omp_single (loc, parser);
9624 case PRAGMA_OMP_TASK:
9625 stmt = c_parser_omp_task (loc, parser);
9632 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9637 # pragma omp threadprivate (variable-list) */
9640 c_parser_omp_threadprivate (c_parser *parser)
9645 c_parser_consume_pragma (parser);
9646 loc = c_parser_peek_token (parser)->location;
9647 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9649 /* Mark every variable in VARS to be assigned thread local storage. */
9650 for (t = vars; t; t = TREE_CHAIN (t))
9652 tree v = TREE_PURPOSE (t);
9654 /* FIXME diagnostics: Ideally we should keep individual
9655 locations for all the variables in the var list to make the
9656 following errors more precise. Perhaps
9657 c_parser_omp_var_list_parens() should construct a list of
9658 locations to go along with the var list. */
9660 /* If V had already been marked threadprivate, it doesn't matter
9661 whether it had been used prior to this point. */
9662 if (TREE_CODE (v) != VAR_DECL)
9663 error_at (loc, "%qD is not a variable", v);
9664 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9665 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9666 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9667 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9668 else if (TREE_TYPE (v) == error_mark_node)
9670 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9671 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9674 if (! DECL_THREAD_LOCAL_P (v))
9676 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9677 /* If rtl has been already set for this var, call
9678 make_decl_rtl once again, so that encode_section_info
9679 has a chance to look at the new decl flags. */
9680 if (DECL_RTL_SET_P (v))
9683 C_DECL_THREADPRIVATE_P (v) = 1;
9687 c_parser_skip_to_pragma_eol (parser);
9691 /* Parse a single source file. */
9696 /* Use local storage to begin. If the first token is a pragma, parse it.
9697 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9698 which will cause garbage collection. */
9701 memset (&tparser, 0, sizeof tparser);
9702 the_parser = &tparser;
9704 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9705 c_parser_pragma_pch_preprocess (&tparser);
9707 the_parser = ggc_alloc_c_parser ();
9708 *the_parser = tparser;
9710 /* Initialize EH, if we've been told to do so. */
9711 if (flag_exceptions)
9712 using_eh_for_cleanups ();
9714 c_parser_translation_unit (the_parser);
9718 #include "gt-c-parser.h"