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"
54 #include "c-family/c-common.h"
61 /* Initialization routine for this file. */
66 /* The only initialization required is of the reserved word
72 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
73 the c_token structure. */
74 gcc_assert (RID_MAX <= 255);
81 mask |= D_ASM | D_EXT;
85 if (!c_dialect_objc ())
86 mask |= D_OBJC | D_CXX_OBJC;
88 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
89 for (i = 0; i < num_c_common_reswords; i++)
91 /* If a keyword is disabled, do not enter it into the table
92 and so create a canonical spelling that isn't a keyword. */
93 if (c_common_reswords[i].disable & mask)
96 && (c_common_reswords[i].disable & D_CXXWARN))
98 id = get_identifier (c_common_reswords[i].word);
99 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
100 C_IS_RESERVED_WORD (id) = 1;
105 id = get_identifier (c_common_reswords[i].word);
106 C_SET_RID_CODE (id, c_common_reswords[i].rid);
107 C_IS_RESERVED_WORD (id) = 1;
108 ridpointers [(int) c_common_reswords[i].rid] = id;
112 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
113 and the C parser. Unlike the C++ lexer, the parser structure
114 stores the lexer information instead of using a separate structure.
115 Identifiers are separated into ordinary identifiers, type names,
116 keywords and some other Objective-C types of identifiers, and some
117 look-ahead is maintained.
119 ??? It might be a good idea to lex the whole file up front (as for
120 C++). It would then be possible to share more of the C and C++
121 lexer code, if desired. */
123 /* The following local token type is used. */
126 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
128 /* More information about the type of a CPP_NAME token. */
129 typedef enum c_id_kind {
130 /* An ordinary identifier. */
132 /* An identifier declared as a typedef name. */
134 /* An identifier declared as an Objective-C class name. */
136 /* An address space identifier. */
138 /* Not an identifier. */
142 /* A single C token after string literal concatenation and conversion
143 of preprocessing tokens to tokens. */
144 typedef struct GTY (()) c_token {
145 /* The kind of token. */
146 ENUM_BITFIELD (cpp_ttype) type : 8;
147 /* If this token is a CPP_NAME, this value indicates whether also
148 declared as some kind of type. Otherwise, it is C_ID_NONE. */
149 ENUM_BITFIELD (c_id_kind) id_kind : 8;
150 /* If this token is a keyword, this value indicates which keyword.
151 Otherwise, this value is RID_MAX. */
152 ENUM_BITFIELD (rid) keyword : 8;
153 /* If this token is a CPP_PRAGMA, this indicates the pragma that
154 was seen. Otherwise it is PRAGMA_NONE. */
155 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
156 /* The location at which this token was found. */
158 /* The value associated with this token, if any. */
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 typedef struct GTY(()) c_parser {
166 /* The look-ahead tokens. */
168 /* How many look-ahead tokens are available (0, 1 or 2). */
170 /* True if a syntax error is being recovered from; false otherwise.
171 c_parser_error sets this flag. It should clear this flag when
172 enough tokens have been consumed to recover from the error. */
173 BOOL_BITFIELD error : 1;
174 /* True if we're processing a pragma, and shouldn't automatically
175 consume CPP_PRAGMA_EOL. */
176 BOOL_BITFIELD in_pragma : 1;
177 /* True if we're parsing the outermost block of an if statement. */
178 BOOL_BITFIELD in_if_block : 1;
179 /* True if we want to lex an untranslated string. */
180 BOOL_BITFIELD lex_untranslated_string : 1;
182 /* Objective-C specific parser/lexer information. */
184 /* True if we are in a context where the Objective-C "PQ" keywords
185 are considered keywords. */
186 BOOL_BITFIELD objc_pq_context : 1;
187 /* True if we are parsing a (potential) Objective-C foreach
188 statement. This is set to true after we parsed 'for (' and while
189 we wait for 'in' or ';' to decide if it's a standard C for loop or an
190 Objective-C foreach loop. */
191 BOOL_BITFIELD objc_could_be_foreach_context : 1;
192 /* The following flag is needed to contextualize Objective-C lexical
193 analysis. In some cases (e.g., 'int NSObject;'), it is
194 undesirable to bind an identifier to an Objective-C class, even
195 if a class with that name exists. */
196 BOOL_BITFIELD objc_need_raw_identifier : 1;
197 /* True if we are in a context where the Objective-C "Property attribute"
198 keywords are valid. */
199 BOOL_BITFIELD objc_property_attr_context : 1;
203 /* The actual parser and external interface. ??? Does this need to be
204 garbage-collected? */
206 static GTY (()) c_parser *the_parser;
208 /* Read in and lex a single token, storing it in *TOKEN. */
211 c_lex_one_token (c_parser *parser, c_token *token)
213 timevar_push (TV_LEX);
215 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
216 (parser->lex_untranslated_string
217 ? C_LEX_STRING_NO_TRANSLATE : 0));
218 token->id_kind = C_ID_NONE;
219 token->keyword = RID_MAX;
220 token->pragma_kind = PRAGMA_NONE;
228 bool objc_force_identifier = parser->objc_need_raw_identifier;
229 if (c_dialect_objc ())
230 parser->objc_need_raw_identifier = false;
232 if (C_IS_RESERVED_WORD (token->value))
234 enum rid rid_code = C_RID_CODE (token->value);
236 if (rid_code == RID_CXX_COMPAT_WARN)
238 warning_at (token->location,
240 "identifier %qE conflicts with C++ keyword",
243 else if (rid_code >= RID_FIRST_ADDR_SPACE
244 && rid_code <= RID_LAST_ADDR_SPACE)
246 token->id_kind = C_ID_ADDRSPACE;
247 token->keyword = rid_code;
250 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
252 /* We found an Objective-C "pq" keyword (in, out,
253 inout, bycopy, byref, oneway). They need special
254 care because the interpretation depends on the
257 if (parser->objc_pq_context)
259 token->type = CPP_KEYWORD;
260 token->keyword = rid_code;
263 else if (parser->objc_could_be_foreach_context
264 && rid_code == RID_IN)
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation.
279 token->type = CPP_KEYWORD;
280 token->keyword = rid_code;
283 /* Else, "pq" keywords outside of the "pq" context are
284 not keywords, and we fall through to the code for
288 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
290 /* We found an Objective-C "property attribute" keyword
291 (readonly, copies, getter, setter, ivar). These are
292 only valid in the property context. */
293 if (parser->objc_property_attr_context)
295 token->type = CPP_KEYWORD;
296 token->keyword = rid_code;
299 /* Else they are not special keywords.
302 else if (c_dialect_objc ()
303 && (OBJC_IS_AT_KEYWORD (rid_code)
304 || OBJC_IS_CXX_KEYWORD (rid_code)))
306 /* We found one of the Objective-C "@" keywords (defs,
307 selector, synchronized, etc) or one of the
308 Objective-C "cxx" keywords (class, private,
309 protected, public, try, catch, throw) without a
310 preceding '@' sign. Do nothing and fall through to
311 the code for normal tokens (in C++ we would still
312 consider the CXX ones keywords, but not in C).
318 token->type = CPP_KEYWORD;
319 token->keyword = rid_code;
324 decl = lookup_name (token->value);
327 if (TREE_CODE (decl) == TYPE_DECL)
329 token->id_kind = C_ID_TYPENAME;
333 else if (c_dialect_objc ())
335 tree objc_interface_decl = objc_is_class_name (token->value);
336 /* Objective-C class names are in the same namespace as
337 variables and typedefs, and hence are shadowed by local
339 if (objc_interface_decl
340 && (global_bindings_p ()
341 || (!objc_force_identifier && !decl)))
343 token->value = objc_interface_decl;
344 token->id_kind = C_ID_CLASSNAME;
348 token->id_kind = C_ID_ID;
352 /* This only happens in Objective-C; it must be a keyword. */
353 token->type = CPP_KEYWORD;
354 switch (C_RID_CODE (token->value))
356 /* Replace 'class' with '@class', 'private' with '@private',
357 etc. This prevents confusion with the C++ keyword
358 'class', and makes the tokens consistent with other
359 Objective-C 'AT' keywords. For example '@class' is
360 reported as RID_AT_CLASS which is consistent with
361 '@synchronized', which is reported as
364 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
365 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
366 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
367 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
368 case RID_THROW: token->keyword = RID_AT_THROW; break;
369 case RID_TRY: token->keyword = RID_AT_TRY; break;
370 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
371 default: token->keyword = C_RID_CODE (token->value);
376 case CPP_CLOSE_PAREN:
378 /* These tokens may affect the interpretation of any identifiers
379 following, if doing Objective-C. */
380 if (c_dialect_objc ())
381 parser->objc_need_raw_identifier = false;
384 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
385 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
391 timevar_pop (TV_LEX);
394 /* Return a pointer to the next token from PARSER, reading it in if
397 static inline c_token *
398 c_parser_peek_token (c_parser *parser)
400 if (parser->tokens_avail == 0)
402 c_lex_one_token (parser, &parser->tokens[0]);
403 parser->tokens_avail = 1;
405 return &parser->tokens[0];
408 /* Return true if the next token from PARSER has the indicated
412 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
414 return c_parser_peek_token (parser)->type == type;
417 /* Return true if the next token from PARSER does not have the
421 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
423 return !c_parser_next_token_is (parser, type);
426 /* Return true if the next token from PARSER is the indicated
430 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
432 return c_parser_peek_token (parser)->keyword == keyword;
435 /* Return true if TOKEN can start a type name,
438 c_token_starts_typename (c_token *token)
443 switch (token->id_kind)
452 gcc_assert (c_dialect_objc ());
458 switch (token->keyword)
491 if (c_dialect_objc ())
499 /* Return true if the next token from PARSER can start a type name,
502 c_parser_next_token_starts_typename (c_parser *parser)
504 c_token *token = c_parser_peek_token (parser);
505 return c_token_starts_typename (token);
508 /* Return true if TOKEN is a type qualifier, false otherwise. */
510 c_token_is_qualifier (c_token *token)
515 switch (token->id_kind)
523 switch (token->keyword)
540 /* Return true if the next token from PARSER is a type qualifier,
543 c_parser_next_token_is_qualifier (c_parser *parser)
545 c_token *token = c_parser_peek_token (parser);
546 return c_token_is_qualifier (token);
549 /* Return true if TOKEN can start declaration specifiers, false
552 c_token_starts_declspecs (c_token *token)
557 switch (token->id_kind)
566 gcc_assert (c_dialect_objc ());
572 switch (token->keyword)
612 if (c_dialect_objc ())
621 /* Return true if TOKEN can start declaration specifiers or a static
622 assertion, false otherwise. */
624 c_token_starts_declaration (c_token *token)
626 if (c_token_starts_declspecs (token)
627 || token->keyword == RID_STATIC_ASSERT)
633 static c_token *c_parser_peek_2nd_token (c_parser *parser);
635 /* Return true if the next token from PARSER can start declaration
636 specifiers, false otherwise. */
638 c_parser_next_token_starts_declspecs (c_parser *parser)
640 c_token *token = c_parser_peek_token (parser);
642 /* In Objective-C, a classname normally starts a declspecs unless it
643 is immediately followed by a dot. In that case, it is the
644 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
645 setter/getter on the class. c_token_starts_declspecs() can't
646 differentiate between the two cases because it only checks the
647 current token, so we have a special check here. */
648 if (c_dialect_objc ()
649 && token->type == CPP_NAME
650 && token->id_kind == C_ID_CLASSNAME
651 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
654 return c_token_starts_declspecs (token);
657 /* Return true if the next tokens from PARSER can start declaration
658 specifiers or a static assertion, false otherwise. */
660 c_parser_next_tokens_start_declaration (c_parser *parser)
662 c_token *token = c_parser_peek_token (parser);
665 if (c_dialect_objc ()
666 && token->type == CPP_NAME
667 && token->id_kind == C_ID_CLASSNAME
668 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
671 /* Labels do not start declarations. */
672 if (token->type == CPP_NAME
673 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
676 if (c_token_starts_declaration (token))
679 /* Try a bit harder to detect an unknown typename. */
680 if (token->type == CPP_NAME
681 && token->id_kind == C_ID_ID
682 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
683 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
684 && !lookup_name (token->value)
686 /* Do not try too hard when we could have "object in array". */
687 && !parser->objc_could_be_foreach_context)
693 /* Return a pointer to the next-but-one token from PARSER, reading it
694 in if necessary. The next token is already read in. */
697 c_parser_peek_2nd_token (c_parser *parser)
699 if (parser->tokens_avail >= 2)
700 return &parser->tokens[1];
701 gcc_assert (parser->tokens_avail == 1);
702 gcc_assert (parser->tokens[0].type != CPP_EOF);
703 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
704 c_lex_one_token (parser, &parser->tokens[1]);
705 parser->tokens_avail = 2;
706 return &parser->tokens[1];
709 /* Consume the next token from PARSER. */
712 c_parser_consume_token (c_parser *parser)
714 gcc_assert (parser->tokens_avail >= 1);
715 gcc_assert (parser->tokens[0].type != CPP_EOF);
716 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
717 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
718 if (parser->tokens_avail == 2)
719 parser->tokens[0] = parser->tokens[1];
720 parser->tokens_avail--;
723 /* Expect the current token to be a #pragma. Consume it and remember
724 that we've begun parsing a pragma. */
727 c_parser_consume_pragma (c_parser *parser)
729 gcc_assert (!parser->in_pragma);
730 gcc_assert (parser->tokens_avail >= 1);
731 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
732 if (parser->tokens_avail == 2)
733 parser->tokens[0] = parser->tokens[1];
734 parser->tokens_avail--;
735 parser->in_pragma = true;
738 /* Update the globals input_location and in_system_header from
741 c_parser_set_source_position_from_token (c_token *token)
743 if (token->type != CPP_EOF)
745 input_location = token->location;
749 /* Issue a diagnostic of the form
750 FILE:LINE: MESSAGE before TOKEN
751 where TOKEN is the next token in the input stream of PARSER.
752 MESSAGE (specified by the caller) is usually of the form "expected
755 Do not issue a diagnostic if still recovering from an error.
757 ??? This is taken from the C++ parser, but building up messages in
758 this way is not i18n-friendly and some other approach should be
762 c_parser_error (c_parser *parser, const char *gmsgid)
764 c_token *token = c_parser_peek_token (parser);
767 parser->error = true;
770 /* This diagnostic makes more sense if it is tagged to the line of
771 the token we just peeked at. */
772 c_parser_set_source_position_from_token (token);
773 c_parse_error (gmsgid,
774 /* Because c_parse_error does not understand
775 CPP_KEYWORD, keywords are treated like
777 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
778 /* ??? The C parser does not save the cpp flags of a
779 token, we need to pass 0 here and we will not get
780 the source spelling of some tokens but rather the
781 canonical spelling. */
782 token->value, /*flags=*/0);
785 /* If the next token is of the indicated TYPE, consume it. Otherwise,
786 issue the error MSGID. If MSGID is NULL then a message has already
787 been produced and no message will be produced this time. Returns
788 true if found, false otherwise. */
791 c_parser_require (c_parser *parser,
795 if (c_parser_next_token_is (parser, type))
797 c_parser_consume_token (parser);
802 c_parser_error (parser, msgid);
807 /* If the next token is the indicated keyword, consume it. Otherwise,
808 issue the error MSGID. Returns true if found, false otherwise. */
811 c_parser_require_keyword (c_parser *parser,
815 if (c_parser_next_token_is_keyword (parser, keyword))
817 c_parser_consume_token (parser);
822 c_parser_error (parser, msgid);
827 /* Like c_parser_require, except that tokens will be skipped until the
828 desired token is found. An error message is still produced if the
829 next token is not as expected. If MSGID is NULL then a message has
830 already been produced and no message will be produced this
834 c_parser_skip_until_found (c_parser *parser,
838 unsigned nesting_depth = 0;
840 if (c_parser_require (parser, type, msgid))
843 /* Skip tokens until the desired token is found. */
846 /* Peek at the next token. */
847 c_token *token = c_parser_peek_token (parser);
848 /* If we've reached the token we want, consume it and stop. */
849 if (token->type == type && !nesting_depth)
851 c_parser_consume_token (parser);
855 /* If we've run out of tokens, stop. */
856 if (token->type == CPP_EOF)
858 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
860 if (token->type == CPP_OPEN_BRACE
861 || token->type == CPP_OPEN_PAREN
862 || token->type == CPP_OPEN_SQUARE)
864 else if (token->type == CPP_CLOSE_BRACE
865 || token->type == CPP_CLOSE_PAREN
866 || token->type == CPP_CLOSE_SQUARE)
868 if (nesting_depth-- == 0)
871 /* Consume this token. */
872 c_parser_consume_token (parser);
874 parser->error = false;
877 /* Skip tokens until the end of a parameter is found, but do not
878 consume the comma, semicolon or closing delimiter. */
881 c_parser_skip_to_end_of_parameter (c_parser *parser)
883 unsigned nesting_depth = 0;
887 c_token *token = c_parser_peek_token (parser);
888 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
891 /* If we've run out of tokens, stop. */
892 if (token->type == CPP_EOF)
894 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
896 if (token->type == CPP_OPEN_BRACE
897 || token->type == CPP_OPEN_PAREN
898 || token->type == CPP_OPEN_SQUARE)
900 else if (token->type == CPP_CLOSE_BRACE
901 || token->type == CPP_CLOSE_PAREN
902 || token->type == CPP_CLOSE_SQUARE)
904 if (nesting_depth-- == 0)
907 /* Consume this token. */
908 c_parser_consume_token (parser);
910 parser->error = false;
913 /* Expect to be at the end of the pragma directive and consume an
914 end of line marker. */
917 c_parser_skip_to_pragma_eol (c_parser *parser)
919 gcc_assert (parser->in_pragma);
920 parser->in_pragma = false;
922 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
925 c_token *token = c_parser_peek_token (parser);
926 if (token->type == CPP_EOF)
928 if (token->type == CPP_PRAGMA_EOL)
930 c_parser_consume_token (parser);
933 c_parser_consume_token (parser);
936 parser->error = false;
939 /* Skip tokens until we have consumed an entire block, or until we
940 have consumed a non-nested ';'. */
943 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
945 unsigned nesting_depth = 0;
946 bool save_error = parser->error;
952 /* Peek at the next token. */
953 token = c_parser_peek_token (parser);
961 if (parser->in_pragma)
966 /* If the next token is a ';', we have reached the
967 end of the statement. */
970 /* Consume the ';'. */
971 c_parser_consume_token (parser);
976 case CPP_CLOSE_BRACE:
977 /* If the next token is a non-nested '}', then we have
978 reached the end of the current block. */
979 if (nesting_depth == 0 || --nesting_depth == 0)
981 c_parser_consume_token (parser);
987 /* If it the next token is a '{', then we are entering a new
988 block. Consume the entire block. */
993 /* If we see a pragma, consume the whole thing at once. We
994 have some safeguards against consuming pragmas willy-nilly.
995 Normally, we'd expect to be here with parser->error set,
996 which disables these safeguards. But it's possible to get
997 here for secondary error recovery, after parser->error has
999 c_parser_consume_pragma (parser);
1000 c_parser_skip_to_pragma_eol (parser);
1001 parser->error = save_error;
1008 c_parser_consume_token (parser);
1012 parser->error = false;
1015 /* CPP's options (initialized by c-opts.c). */
1016 extern cpp_options *cpp_opts;
1018 /* Save the warning flags which are controlled by __extension__. */
1021 disable_extension_diagnostics (void)
1024 | (warn_pointer_arith << 1)
1025 | (warn_traditional << 2)
1027 | (warn_long_long << 4)
1028 | (warn_cxx_compat << 5));
1029 cpp_opts->cpp_pedantic = pedantic = 0;
1030 warn_pointer_arith = 0;
1031 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1033 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1034 warn_cxx_compat = 0;
1038 /* Restore the warning flags which are controlled by __extension__.
1039 FLAGS is the return value from disable_extension_diagnostics. */
1042 restore_extension_diagnostics (int flags)
1044 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1045 warn_pointer_arith = (flags >> 1) & 1;
1046 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1047 flag_iso = (flags >> 3) & 1;
1048 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1049 warn_cxx_compat = (flags >> 5) & 1;
1052 /* Possibly kinds of declarator to parse. */
1053 typedef enum c_dtr_syn {
1054 /* A normal declarator with an identifier. */
1056 /* An abstract declarator (maybe empty). */
1058 /* A parameter declarator: may be either, but after a type name does
1059 not redeclare a typedef name as an identifier if it can
1060 alternatively be interpreted as a typedef name; see DR#009,
1061 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1062 following DR#249. For example, given a typedef T, "int T" and
1063 "int *T" are valid parameter declarations redeclaring T, while
1064 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1065 abstract declarators rather than involving redundant parentheses;
1066 the same applies with attributes inside the parentheses before
1071 static void c_parser_external_declaration (c_parser *);
1072 static void c_parser_asm_definition (c_parser *);
1073 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1074 bool, bool, tree *);
1075 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1076 static void c_parser_static_assert_declaration (c_parser *);
1077 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1079 static struct c_typespec c_parser_enum_specifier (c_parser *);
1080 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1081 static tree c_parser_struct_declaration (c_parser *);
1082 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1083 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1085 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1087 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1089 struct c_declarator *);
1090 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1091 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1092 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1093 static tree c_parser_simple_asm_expr (c_parser *);
1094 static tree c_parser_attributes (c_parser *);
1095 static struct c_type_name *c_parser_type_name (c_parser *);
1096 static struct c_expr c_parser_initializer (c_parser *);
1097 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1098 static void c_parser_initelt (c_parser *, struct obstack *);
1099 static void c_parser_initval (c_parser *, struct c_expr *,
1101 static tree c_parser_compound_statement (c_parser *);
1102 static void c_parser_compound_statement_nostart (c_parser *);
1103 static void c_parser_label (c_parser *);
1104 static void c_parser_statement (c_parser *);
1105 static void c_parser_statement_after_labels (c_parser *);
1106 static void c_parser_if_statement (c_parser *);
1107 static void c_parser_switch_statement (c_parser *);
1108 static void c_parser_while_statement (c_parser *);
1109 static void c_parser_do_statement (c_parser *);
1110 static void c_parser_for_statement (c_parser *);
1111 static tree c_parser_asm_statement (c_parser *);
1112 static tree c_parser_asm_operands (c_parser *, bool);
1113 static tree c_parser_asm_goto_operands (c_parser *);
1114 static tree c_parser_asm_clobbers (c_parser *);
1115 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1116 static struct c_expr c_parser_conditional_expression (c_parser *,
1118 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1119 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1120 static struct c_expr c_parser_unary_expression (c_parser *);
1121 static struct c_expr c_parser_sizeof_expression (c_parser *);
1122 static struct c_expr c_parser_alignof_expression (c_parser *);
1123 static struct c_expr c_parser_postfix_expression (c_parser *);
1124 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1125 struct c_type_name *,
1127 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1130 static struct c_expr c_parser_expression (c_parser *);
1131 static struct c_expr c_parser_expression_conv (c_parser *);
1132 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1134 static void c_parser_omp_construct (c_parser *);
1135 static void c_parser_omp_threadprivate (c_parser *);
1136 static void c_parser_omp_barrier (c_parser *);
1137 static void c_parser_omp_flush (c_parser *);
1138 static void c_parser_omp_taskwait (c_parser *);
1140 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1141 static bool c_parser_pragma (c_parser *, enum pragma_context);
1143 /* These Objective-C parser functions are only ever called when
1144 compiling Objective-C. */
1145 static void c_parser_objc_class_definition (c_parser *, tree);
1146 static void c_parser_objc_class_instance_variables (c_parser *);
1147 static void c_parser_objc_class_declaration (c_parser *);
1148 static void c_parser_objc_alias_declaration (c_parser *);
1149 static void c_parser_objc_protocol_definition (c_parser *, tree);
1150 static bool c_parser_objc_method_type (c_parser *);
1151 static void c_parser_objc_method_definition (c_parser *);
1152 static void c_parser_objc_methodprotolist (c_parser *);
1153 static void c_parser_objc_methodproto (c_parser *);
1154 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
1155 static tree c_parser_objc_type_name (c_parser *);
1156 static tree c_parser_objc_protocol_refs (c_parser *);
1157 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1158 static void c_parser_objc_synchronized_statement (c_parser *);
1159 static tree c_parser_objc_selector (c_parser *);
1160 static tree c_parser_objc_selector_arg (c_parser *);
1161 static tree c_parser_objc_receiver (c_parser *);
1162 static tree c_parser_objc_message_args (c_parser *);
1163 static tree c_parser_objc_keywordexpr (c_parser *);
1164 static void c_parser_objc_at_property_declaration (c_parser *);
1165 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1166 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1167 static bool c_parser_objc_diagnose_bad_element_prefix
1168 (c_parser *, struct c_declspecs *);
1170 /* Parse a translation unit (C90 6.7, C99 6.9).
1173 external-declarations
1175 external-declarations:
1176 external-declaration
1177 external-declarations external-declaration
1186 c_parser_translation_unit (c_parser *parser)
1188 if (c_parser_next_token_is (parser, CPP_EOF))
1190 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1191 "ISO C forbids an empty translation unit");
1195 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1196 mark_valid_location_for_stdc_pragma (false);
1200 c_parser_external_declaration (parser);
1201 obstack_free (&parser_obstack, obstack_position);
1203 while (c_parser_next_token_is_not (parser, CPP_EOF));
1207 /* Parse an external declaration (C90 6.7, C99 6.9).
1209 external-declaration:
1215 external-declaration:
1218 __extension__ external-declaration
1222 external-declaration:
1223 objc-class-definition
1224 objc-class-declaration
1225 objc-alias-declaration
1226 objc-protocol-definition
1227 objc-method-definition
1232 c_parser_external_declaration (c_parser *parser)
1235 switch (c_parser_peek_token (parser)->type)
1238 switch (c_parser_peek_token (parser)->keyword)
1241 ext = disable_extension_diagnostics ();
1242 c_parser_consume_token (parser);
1243 c_parser_external_declaration (parser);
1244 restore_extension_diagnostics (ext);
1247 c_parser_asm_definition (parser);
1249 case RID_AT_INTERFACE:
1250 case RID_AT_IMPLEMENTATION:
1251 gcc_assert (c_dialect_objc ());
1252 c_parser_objc_class_definition (parser, NULL_TREE);
1255 gcc_assert (c_dialect_objc ());
1256 c_parser_objc_class_declaration (parser);
1259 gcc_assert (c_dialect_objc ());
1260 c_parser_objc_alias_declaration (parser);
1262 case RID_AT_PROTOCOL:
1263 gcc_assert (c_dialect_objc ());
1264 c_parser_objc_protocol_definition (parser, NULL_TREE);
1266 case RID_AT_PROPERTY:
1267 gcc_assert (c_dialect_objc ());
1268 c_parser_objc_at_property_declaration (parser);
1270 case RID_AT_SYNTHESIZE:
1271 gcc_assert (c_dialect_objc ());
1272 c_parser_objc_at_synthesize_declaration (parser);
1274 case RID_AT_DYNAMIC:
1275 gcc_assert (c_dialect_objc ());
1276 c_parser_objc_at_dynamic_declaration (parser);
1279 gcc_assert (c_dialect_objc ());
1280 c_parser_consume_token (parser);
1281 objc_finish_implementation ();
1288 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1289 "ISO C does not allow extra %<;%> outside of a function");
1290 c_parser_consume_token (parser);
1293 mark_valid_location_for_stdc_pragma (true);
1294 c_parser_pragma (parser, pragma_external);
1295 mark_valid_location_for_stdc_pragma (false);
1299 if (c_dialect_objc ())
1301 c_parser_objc_method_definition (parser);
1304 /* Else fall through, and yield a syntax error trying to parse
1305 as a declaration or function definition. */
1308 /* A declaration or a function definition (or, in Objective-C,
1309 an @interface or @protocol with prefix attributes). We can
1310 only tell which after parsing the declaration specifiers, if
1311 any, and the first declarator. */
1312 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1317 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1318 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1319 accepted; otherwise (old-style parameter declarations) only other
1320 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1321 assertion is accepted; otherwise (old-style parameter declarations)
1322 it is not. If NESTED is true, we are inside a function or parsing
1323 old-style parameter declarations; any functions encountered are
1324 nested functions and declaration specifiers are required; otherwise
1325 we are at top level and functions are normal functions and
1326 declaration specifiers may be optional. If EMPTY_OK is true, empty
1327 declarations are OK (subject to all other constraints); otherwise
1328 (old-style parameter declarations) they are diagnosed. If
1329 START_ATTR_OK is true, the declaration specifiers may start with
1330 attributes; otherwise they may not.
1331 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1332 declaration when parsing an Objective-C foreach statement.
1335 declaration-specifiers init-declarator-list[opt] ;
1336 static_assert-declaration
1338 function-definition:
1339 declaration-specifiers[opt] declarator declaration-list[opt]
1344 declaration-list declaration
1346 init-declarator-list:
1348 init-declarator-list , init-declarator
1351 declarator simple-asm-expr[opt] attributes[opt]
1352 declarator simple-asm-expr[opt] attributes[opt] = initializer
1356 nested-function-definition:
1357 declaration-specifiers declarator declaration-list[opt]
1361 attributes objc-class-definition
1362 attributes objc-category-definition
1363 attributes objc-protocol-definition
1365 The simple-asm-expr and attributes are GNU extensions.
1367 This function does not handle __extension__; that is handled in its
1368 callers. ??? Following the old parser, __extension__ may start
1369 external declarations, declarations in functions and declarations
1370 at the start of "for" loops, but not old-style parameter
1373 C99 requires declaration specifiers in a function definition; the
1374 absence is diagnosed through the diagnosis of implicit int. In GNU
1375 C we also allow but diagnose declarations without declaration
1376 specifiers, but only at top level (elsewhere they conflict with
1379 In Objective-C, declarations of the looping variable in a foreach
1380 statement are exceptionally terminated by 'in' (for example, 'for
1381 (NSObject *object in array) { ... }').
1386 threadprivate-directive */
1389 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1390 bool static_assert_ok, bool empty_ok,
1391 bool nested, bool start_attr_ok,
1392 tree *objc_foreach_object_declaration)
1394 struct c_declspecs *specs;
1396 tree all_prefix_attrs;
1397 bool diagnosed_no_specs = false;
1398 location_t here = c_parser_peek_token (parser)->location;
1400 if (static_assert_ok
1401 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1403 c_parser_static_assert_declaration (parser);
1406 specs = build_null_declspecs ();
1408 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1409 if (c_parser_peek_token (parser)->type == CPP_NAME
1410 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1411 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1412 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1413 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1415 error_at (here, "unknown type name %qE",
1416 c_parser_peek_token (parser)->value);
1418 /* Parse declspecs normally to get a correct pointer type, but avoid
1419 a further "fails to be a type name" error. Refuse nested functions
1420 since it is not how the user likely wants us to recover. */
1421 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1422 c_parser_peek_token (parser)->keyword = RID_VOID;
1423 c_parser_peek_token (parser)->value = error_mark_node;
1427 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1430 c_parser_skip_to_end_of_block_or_statement (parser);
1433 if (nested && !specs->declspecs_seen_p)
1435 c_parser_error (parser, "expected declaration specifiers");
1436 c_parser_skip_to_end_of_block_or_statement (parser);
1439 finish_declspecs (specs);
1440 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1446 shadow_tag_warned (specs, 1);
1447 pedwarn (here, 0, "empty declaration");
1449 c_parser_consume_token (parser);
1453 /* Provide better error recovery. Note that a type name here is usually
1454 better diagnosed as a redeclaration. */
1456 && specs->typespec_kind == ctsk_tagdef
1457 && c_parser_next_token_starts_declspecs (parser)
1458 && !c_parser_next_token_is (parser, CPP_NAME))
1460 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1461 parser->error = false;
1462 shadow_tag_warned (specs, 1);
1465 else if (c_dialect_objc ())
1467 /* Prefix attributes are an error on method decls. */
1468 switch (c_parser_peek_token (parser)->type)
1472 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1476 warning_at (c_parser_peek_token (parser)->location,
1478 "prefix attributes are ignored for methods");
1479 specs->attrs = NULL_TREE;
1482 c_parser_objc_method_definition (parser);
1484 c_parser_objc_methodproto (parser);
1490 /* This is where we parse 'attributes @interface ...',
1491 'attributes @implementation ...', 'attributes @protocol ...'
1492 (where attributes could be, for example, __attribute__
1495 switch (c_parser_peek_token (parser)->keyword)
1497 case RID_AT_INTERFACE:
1499 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1501 c_parser_objc_class_definition (parser, specs->attrs);
1505 case RID_AT_IMPLEMENTATION:
1507 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1511 warning_at (c_parser_peek_token (parser)->location,
1513 "prefix attributes are ignored for implementations");
1514 specs->attrs = NULL_TREE;
1516 c_parser_objc_class_definition (parser, NULL_TREE);
1520 case RID_AT_PROTOCOL:
1522 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1524 c_parser_objc_protocol_definition (parser, specs->attrs);
1531 case RID_AT_PROPERTY:
1534 c_parser_error (parser,
1535 "attributes may not be specified before" );
1536 specs->attrs = NULL;
1544 pending_xref_error ();
1545 prefix_attrs = specs->attrs;
1546 all_prefix_attrs = prefix_attrs;
1547 specs->attrs = NULL_TREE;
1550 struct c_declarator *declarator;
1553 /* Declaring either one or more declarators (in which case we
1554 should diagnose if there were no declaration specifiers) or a
1555 function definition (in which case the diagnostic for
1556 implicit int suffices). */
1557 declarator = c_parser_declarator (parser,
1558 specs->typespec_kind != ctsk_none,
1559 C_DTR_NORMAL, &dummy);
1560 if (declarator == NULL)
1562 c_parser_skip_to_end_of_block_or_statement (parser);
1565 if (c_parser_next_token_is (parser, CPP_EQ)
1566 || c_parser_next_token_is (parser, CPP_COMMA)
1567 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1568 || c_parser_next_token_is_keyword (parser, RID_ASM)
1569 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1570 || c_parser_next_token_is_keyword (parser, RID_IN))
1572 tree asm_name = NULL_TREE;
1573 tree postfix_attrs = NULL_TREE;
1574 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1576 diagnosed_no_specs = true;
1577 pedwarn (here, 0, "data definition has no type or storage class");
1579 /* Having seen a data definition, there cannot now be a
1580 function definition. */
1582 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1583 asm_name = c_parser_simple_asm_expr (parser);
1584 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1585 postfix_attrs = c_parser_attributes (parser);
1586 if (c_parser_next_token_is (parser, CPP_EQ))
1590 location_t init_loc;
1591 c_parser_consume_token (parser);
1592 /* The declaration of the variable is in effect while
1593 its initializer is parsed. */
1594 d = start_decl (declarator, specs, true,
1595 chainon (postfix_attrs, all_prefix_attrs));
1597 d = error_mark_node;
1598 start_init (d, asm_name, global_bindings_p ());
1599 init_loc = c_parser_peek_token (parser)->location;
1600 init = c_parser_initializer (parser);
1602 if (d != error_mark_node)
1604 maybe_warn_string_init (TREE_TYPE (d), init);
1605 finish_decl (d, init_loc, init.value,
1606 init.original_type, asm_name);
1611 tree d = start_decl (declarator, specs, false,
1612 chainon (postfix_attrs,
1615 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1616 NULL_TREE, asm_name);
1618 if (c_parser_next_token_is_keyword (parser, RID_IN))
1621 *objc_foreach_object_declaration = d;
1623 *objc_foreach_object_declaration = error_mark_node;
1626 if (c_parser_next_token_is (parser, CPP_COMMA))
1628 c_parser_consume_token (parser);
1629 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1630 all_prefix_attrs = chainon (c_parser_attributes (parser),
1633 all_prefix_attrs = prefix_attrs;
1636 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1638 c_parser_consume_token (parser);
1641 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1643 /* This can only happen in Objective-C: we found the
1644 'in' that terminates the declaration inside an
1645 Objective-C foreach statement. Do not consume the
1646 token, so that the caller can use it to determine
1647 that this indeed is a foreach context. */
1652 c_parser_error (parser, "expected %<,%> or %<;%>");
1653 c_parser_skip_to_end_of_block_or_statement (parser);
1659 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1660 "%<asm%> or %<__attribute__%>");
1661 c_parser_skip_to_end_of_block_or_statement (parser);
1664 /* Function definition (nested or otherwise). */
1667 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1668 c_push_function_context ();
1670 if (!start_function (specs, declarator, all_prefix_attrs))
1672 /* This can appear in many cases looking nothing like a
1673 function definition, so we don't give a more specific
1674 error suggesting there was one. */
1675 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1676 "or %<__attribute__%>");
1678 c_pop_function_context ();
1681 /* Parse old-style parameter declarations. ??? Attributes are
1682 not allowed to start declaration specifiers here because of a
1683 syntax conflict between a function declaration with attribute
1684 suffix and a function definition with an attribute prefix on
1685 first old-style parameter declaration. Following the old
1686 parser, they are not accepted on subsequent old-style
1687 parameter declarations either. However, there is no
1688 ambiguity after the first declaration, nor indeed on the
1689 first as long as we don't allow postfix attributes after a
1690 declarator with a nonempty identifier list in a definition;
1691 and postfix attributes have never been accepted here in
1692 function definitions either. */
1693 while (c_parser_next_token_is_not (parser, CPP_EOF)
1694 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1695 c_parser_declaration_or_fndef (parser, false, false, false,
1697 store_parm_decls ();
1698 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1699 = c_parser_peek_token (parser)->location;
1700 fnbody = c_parser_compound_statement (parser);
1703 tree decl = current_function_decl;
1704 /* Mark nested functions as needing static-chain initially.
1705 lower_nested_functions will recompute it but the
1706 DECL_STATIC_CHAIN flag is also used before that happens,
1707 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1708 DECL_STATIC_CHAIN (decl) = 1;
1711 c_pop_function_context ();
1712 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1723 /* Parse an asm-definition (asm() outside a function body). This is a
1731 c_parser_asm_definition (c_parser *parser)
1733 tree asm_str = c_parser_simple_asm_expr (parser);
1735 cgraph_add_asm_node (asm_str);
1736 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1739 /* Parse a static assertion (C1X N1425 6.7.10).
1741 static_assert-declaration:
1742 static_assert-declaration-no-semi ;
1746 c_parser_static_assert_declaration (c_parser *parser)
1748 c_parser_static_assert_declaration_no_semi (parser);
1750 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1751 c_parser_skip_to_end_of_block_or_statement (parser);
1754 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1757 static_assert-declaration-no-semi:
1758 _Static_assert ( constant-expression , string-literal )
1762 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1764 location_t assert_loc, value_loc;
1768 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1769 assert_loc = c_parser_peek_token (parser)->location;
1773 pedwarn (assert_loc, OPT_pedantic,
1774 "ISO C99 does not support %<_Static_assert%>");
1776 pedwarn (assert_loc, OPT_pedantic,
1777 "ISO C90 does not support %<_Static_assert%>");
1779 c_parser_consume_token (parser);
1780 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1782 value_loc = c_parser_peek_token (parser)->location;
1783 value = c_parser_expr_no_commas (parser, NULL).value;
1784 parser->lex_untranslated_string = true;
1785 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1787 parser->lex_untranslated_string = false;
1790 switch (c_parser_peek_token (parser)->type)
1796 case CPP_UTF8STRING:
1797 string = c_parser_peek_token (parser)->value;
1798 c_parser_consume_token (parser);
1799 parser->lex_untranslated_string = false;
1802 c_parser_error (parser, "expected string literal");
1803 parser->lex_untranslated_string = false;
1806 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1808 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1810 error_at (value_loc, "expression in static assertion is not an integer");
1813 if (TREE_CODE (value) != INTEGER_CST)
1815 value = c_fully_fold (value, false, NULL);
1816 if (TREE_CODE (value) == INTEGER_CST)
1817 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1818 "is not an integer constant expression");
1820 if (TREE_CODE (value) != INTEGER_CST)
1822 error_at (value_loc, "expression in static assertion is not constant");
1825 constant_expression_warning (value);
1826 if (integer_zerop (value))
1827 error_at (assert_loc, "static assertion failed: %E", string);
1830 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1831 6.7), adding them to SPECS (which may already include some).
1832 Storage class specifiers are accepted iff SCSPEC_OK; type
1833 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1834 the start iff START_ATTR_OK.
1836 declaration-specifiers:
1837 storage-class-specifier declaration-specifiers[opt]
1838 type-specifier declaration-specifiers[opt]
1839 type-qualifier declaration-specifiers[opt]
1840 function-specifier declaration-specifiers[opt]
1842 Function specifiers (inline) are from C99, and are currently
1843 handled as storage class specifiers, as is __thread.
1845 C90 6.5.1, C99 6.7.1:
1846 storage-class-specifier:
1857 C90 6.5.2, C99 6.7.2:
1870 [_Imaginary removed in C99 TC2]
1871 struct-or-union-specifier
1875 (_Bool and _Complex are new in C99.)
1877 C90 6.5.3, C99 6.7.3:
1883 address-space-qualifier
1885 (restrict is new in C99.)
1889 declaration-specifiers:
1890 attributes declaration-specifiers[opt]
1896 identifier recognized by the target
1898 storage-class-specifier:
1911 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1912 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1917 class-name objc-protocol-refs[opt]
1918 typedef-name objc-protocol-refs
1923 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1924 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1926 bool attrs_ok = start_attr_ok;
1927 bool seen_type = specs->typespec_kind != ctsk_none;
1928 while ((c_parser_next_token_is (parser, CPP_NAME)
1929 && c_parser_peek_token (parser)->id_kind != C_ID_ID)
1930 || c_parser_next_token_is (parser, CPP_KEYWORD)
1931 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1933 struct c_typespec t;
1935 location_t loc = c_parser_peek_token (parser)->location;
1937 if (!c_parser_next_token_is_qualifier (parser))
1939 /* Exit for TYPENAMEs after any type because they can appear as a
1941 if (seen_type && c_parser_next_token_is (parser, CPP_NAME))
1944 /* If we cannot accept a type, and the next token must start one,
1945 exit. Do the same if we already have seen a tagged definition,
1946 since it would be an error anyway and likely the user has simply
1947 forgotten a semicolon. */
1948 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1949 && c_parser_next_token_starts_typename (parser))
1953 if (c_parser_next_token_is (parser, CPP_NAME))
1955 tree value = c_parser_peek_token (parser)->value;
1956 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1958 if (kind == C_ID_ADDRSPACE)
1961 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1962 declspecs_add_addrspace (specs, as);
1963 c_parser_consume_token (parser);
1968 /* Now at a C_ID_TYPENAME or C_ID_CLASSNAME. */
1969 c_parser_consume_token (parser);
1972 if (kind == C_ID_TYPENAME
1973 && (!c_dialect_objc ()
1974 || c_parser_next_token_is_not (parser, CPP_LESS)))
1976 t.kind = ctsk_typedef;
1977 /* For a typedef name, record the meaning, not the name.
1978 In case of 'foo foo, bar;'. */
1979 t.spec = lookup_name (value);
1981 t.expr_const_operands = true;
1985 tree proto = NULL_TREE;
1986 gcc_assert (c_dialect_objc ());
1988 if (c_parser_next_token_is (parser, CPP_LESS))
1989 proto = c_parser_objc_protocol_refs (parser);
1990 t.spec = objc_get_protocol_qualified_type (value, proto);
1992 t.expr_const_operands = true;
1994 declspecs_add_type (loc, specs, t);
1997 if (c_parser_next_token_is (parser, CPP_LESS))
1999 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2000 nisse@lysator.liu.se. */
2002 gcc_assert (c_dialect_objc ());
2003 if (!typespec_ok || seen_type)
2005 proto = c_parser_objc_protocol_refs (parser);
2007 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2009 t.expr_const_operands = true;
2010 declspecs_add_type (loc, specs, t);
2013 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2014 switch (c_parser_peek_token (parser)->keyword)
2026 /* TODO: Distinguish between function specifiers (inline)
2027 and storage class specifiers, either here or in
2028 declspecs_add_scspec. */
2029 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2030 c_parser_consume_token (parser);
2054 if (c_dialect_objc ())
2055 parser->objc_need_raw_identifier = true;
2056 t.kind = ctsk_resword;
2057 t.spec = c_parser_peek_token (parser)->value;
2059 t.expr_const_operands = true;
2060 declspecs_add_type (loc, specs, t);
2061 c_parser_consume_token (parser);
2068 t = c_parser_enum_specifier (parser);
2069 declspecs_add_type (loc, specs, t);
2077 t = c_parser_struct_or_union_specifier (parser);
2078 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2079 declspecs_add_type (loc, specs, t);
2082 /* ??? The old parser rejected typeof after other type
2083 specifiers, but is a syntax error the best way of
2085 if (!typespec_ok || seen_type)
2089 t = c_parser_typeof_specifier (parser);
2090 declspecs_add_type (loc, specs, t);
2096 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2097 c_parser_consume_token (parser);
2102 attrs = c_parser_attributes (parser);
2103 declspecs_add_attrs (specs, attrs);
2112 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2115 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2116 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2117 enum attributes[opt] identifier
2119 The form with trailing comma is new in C99. The forms with
2120 attributes are GNU extensions. In GNU C, we accept any expression
2121 without commas in the syntax (assignment expressions, not just
2122 conditional expressions); assignment expressions will be diagnosed
2127 enumerator-list , enumerator
2130 enumeration-constant
2131 enumeration-constant = constant-expression
2134 static struct c_typespec
2135 c_parser_enum_specifier (c_parser *parser)
2137 struct c_typespec ret;
2139 tree ident = NULL_TREE;
2140 location_t enum_loc;
2141 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2142 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2143 enum_loc = c_parser_peek_token (parser)->location;
2144 c_parser_consume_token (parser);
2145 attrs = c_parser_attributes (parser);
2146 enum_loc = c_parser_peek_token (parser)->location;
2147 /* Set the location in case we create a decl now. */
2148 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2149 if (c_parser_next_token_is (parser, CPP_NAME))
2151 ident = c_parser_peek_token (parser)->value;
2152 ident_loc = c_parser_peek_token (parser)->location;
2153 enum_loc = ident_loc;
2154 c_parser_consume_token (parser);
2156 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2158 /* Parse an enum definition. */
2159 struct c_enum_contents the_enum;
2160 tree type = start_enum (enum_loc, &the_enum, ident);
2162 /* We chain the enumerators in reverse order, then put them in
2163 forward order at the end. */
2164 tree values = NULL_TREE;
2165 c_parser_consume_token (parser);
2173 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2174 location_t decl_loc, value_loc;
2175 if (c_parser_next_token_is_not (parser, CPP_NAME))
2177 c_parser_error (parser, "expected identifier");
2178 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2179 values = error_mark_node;
2182 token = c_parser_peek_token (parser);
2183 enum_id = token->value;
2184 /* Set the location in case we create a decl now. */
2185 c_parser_set_source_position_from_token (token);
2186 decl_loc = value_loc = token->location;
2187 c_parser_consume_token (parser);
2188 if (c_parser_next_token_is (parser, CPP_EQ))
2190 c_parser_consume_token (parser);
2191 value_loc = c_parser_peek_token (parser)->location;
2192 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2195 enum_value = NULL_TREE;
2196 enum_decl = build_enumerator (decl_loc, value_loc,
2197 &the_enum, enum_id, enum_value);
2198 TREE_CHAIN (enum_decl) = values;
2201 if (c_parser_next_token_is (parser, CPP_COMMA))
2203 comma_loc = c_parser_peek_token (parser)->location;
2205 c_parser_consume_token (parser);
2207 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2209 if (seen_comma && !flag_isoc99)
2210 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2211 c_parser_consume_token (parser);
2216 c_parser_error (parser, "expected %<,%> or %<}%>");
2217 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2218 values = error_mark_node;
2222 postfix_attrs = c_parser_attributes (parser);
2223 ret.spec = finish_enum (type, nreverse (values),
2224 chainon (attrs, postfix_attrs));
2225 ret.kind = ctsk_tagdef;
2226 ret.expr = NULL_TREE;
2227 ret.expr_const_operands = true;
2232 c_parser_error (parser, "expected %<{%>");
2233 ret.spec = error_mark_node;
2234 ret.kind = ctsk_tagref;
2235 ret.expr = NULL_TREE;
2236 ret.expr_const_operands = true;
2239 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2240 /* In ISO C, enumerated types can be referred to only if already
2242 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2245 pedwarn (enum_loc, OPT_pedantic,
2246 "ISO C forbids forward references to %<enum%> types");
2251 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2253 struct-or-union-specifier:
2254 struct-or-union attributes[opt] identifier[opt]
2255 { struct-contents } attributes[opt]
2256 struct-or-union attributes[opt] identifier
2259 struct-declaration-list
2261 struct-declaration-list:
2262 struct-declaration ;
2263 struct-declaration-list struct-declaration ;
2270 struct-declaration-list struct-declaration
2272 struct-declaration-list:
2273 struct-declaration-list ;
2276 (Note that in the syntax here, unlike that in ISO C, the semicolons
2277 are included here rather than in struct-declaration, in order to
2278 describe the syntax with extra semicolons and missing semicolon at
2283 struct-declaration-list:
2284 @defs ( class-name )
2286 (Note this does not include a trailing semicolon, but can be
2287 followed by further declarations, and gets a pedwarn-if-pedantic
2288 when followed by a semicolon.) */
2290 static struct c_typespec
2291 c_parser_struct_or_union_specifier (c_parser *parser)
2293 struct c_typespec ret;
2295 tree ident = NULL_TREE;
2296 location_t struct_loc;
2297 location_t ident_loc = UNKNOWN_LOCATION;
2298 enum tree_code code;
2299 switch (c_parser_peek_token (parser)->keyword)
2310 struct_loc = c_parser_peek_token (parser)->location;
2311 c_parser_consume_token (parser);
2312 attrs = c_parser_attributes (parser);
2314 /* Set the location in case we create a decl now. */
2315 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2317 if (c_parser_next_token_is (parser, CPP_NAME))
2319 ident = c_parser_peek_token (parser)->value;
2320 ident_loc = c_parser_peek_token (parser)->location;
2321 struct_loc = ident_loc;
2322 c_parser_consume_token (parser);
2324 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2326 /* Parse a struct or union definition. Start the scope of the
2327 tag before parsing components. */
2328 struct c_struct_parse_info *struct_info;
2329 tree type = start_struct (struct_loc, code, ident, &struct_info);
2331 /* We chain the components in reverse order, then put them in
2332 forward order at the end. Each struct-declaration may
2333 declare multiple components (comma-separated), so we must use
2334 chainon to join them, although when parsing each
2335 struct-declaration we can use TREE_CHAIN directly.
2337 The theory behind all this is that there will be more
2338 semicolon separated fields than comma separated fields, and
2339 so we'll be minimizing the number of node traversals required
2341 tree contents = NULL_TREE;
2342 c_parser_consume_token (parser);
2343 /* Handle the Objective-C @defs construct,
2344 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2345 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2348 gcc_assert (c_dialect_objc ());
2349 c_parser_consume_token (parser);
2350 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2352 if (c_parser_next_token_is (parser, CPP_NAME)
2353 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2355 name = c_parser_peek_token (parser)->value;
2356 c_parser_consume_token (parser);
2360 c_parser_error (parser, "expected class name");
2361 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2364 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2366 contents = nreverse (objc_get_class_ivars (name));
2369 /* Parse the struct-declarations and semicolons. Problems with
2370 semicolons are diagnosed here; empty structures are diagnosed
2375 /* Parse any stray semicolon. */
2376 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2378 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2379 "extra semicolon in struct or union specified");
2380 c_parser_consume_token (parser);
2383 /* Stop if at the end of the struct or union contents. */
2384 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2386 c_parser_consume_token (parser);
2389 /* Accept #pragmas at struct scope. */
2390 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2392 c_parser_pragma (parser, pragma_external);
2395 /* Parse some comma-separated declarations, but not the
2396 trailing semicolon if any. */
2397 decls = c_parser_struct_declaration (parser);
2398 contents = chainon (decls, contents);
2399 /* If no semicolon follows, either we have a parse error or
2400 are at the end of the struct or union and should
2402 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2403 c_parser_consume_token (parser);
2406 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2407 pedwarn (c_parser_peek_token (parser)->location, 0,
2408 "no semicolon at end of struct or union");
2409 else if (parser->error
2410 || !c_parser_next_token_starts_declspecs (parser))
2412 c_parser_error (parser, "expected %<;%>");
2413 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2417 /* If we come here, we have already emitted an error
2418 for an expected `;', identifier or `(', and we also
2419 recovered already. Go on with the next field. */
2422 postfix_attrs = c_parser_attributes (parser);
2423 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2424 chainon (attrs, postfix_attrs), struct_info);
2425 ret.kind = ctsk_tagdef;
2426 ret.expr = NULL_TREE;
2427 ret.expr_const_operands = true;
2432 c_parser_error (parser, "expected %<{%>");
2433 ret.spec = error_mark_node;
2434 ret.kind = ctsk_tagref;
2435 ret.expr = NULL_TREE;
2436 ret.expr_const_operands = true;
2439 ret = parser_xref_tag (ident_loc, code, ident);
2443 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2444 the trailing semicolon.
2447 specifier-qualifier-list struct-declarator-list
2448 static_assert-declaration-no-semi
2450 specifier-qualifier-list:
2451 type-specifier specifier-qualifier-list[opt]
2452 type-qualifier specifier-qualifier-list[opt]
2453 attributes specifier-qualifier-list[opt]
2455 struct-declarator-list:
2457 struct-declarator-list , attributes[opt] struct-declarator
2460 declarator attributes[opt]
2461 declarator[opt] : constant-expression attributes[opt]
2466 __extension__ struct-declaration
2467 specifier-qualifier-list
2469 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2470 of attributes where shown is a GNU extension. In GNU C, we accept
2471 any expression without commas in the syntax (assignment
2472 expressions, not just conditional expressions); assignment
2473 expressions will be diagnosed as non-constant. */
2476 c_parser_struct_declaration (c_parser *parser)
2478 struct c_declspecs *specs;
2480 tree all_prefix_attrs;
2482 location_t decl_loc;
2483 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2487 ext = disable_extension_diagnostics ();
2488 c_parser_consume_token (parser);
2489 decl = c_parser_struct_declaration (parser);
2490 restore_extension_diagnostics (ext);
2493 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2495 c_parser_static_assert_declaration_no_semi (parser);
2498 specs = build_null_declspecs ();
2499 decl_loc = c_parser_peek_token (parser)->location;
2500 c_parser_declspecs (parser, specs, false, true, true);
2503 if (!specs->declspecs_seen_p)
2505 c_parser_error (parser, "expected specifier-qualifier-list");
2508 finish_declspecs (specs);
2509 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2510 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2513 if (specs->typespec_kind == ctsk_none)
2515 pedwarn (decl_loc, OPT_pedantic,
2516 "ISO C forbids member declarations with no members");
2517 shadow_tag_warned (specs, pedantic);
2522 /* Support for unnamed structs or unions as members of
2523 structs or unions (which is [a] useful and [b] supports
2527 ret = grokfield (c_parser_peek_token (parser)->location,
2528 build_id_declarator (NULL_TREE), specs,
2531 decl_attributes (&ret, attrs, 0);
2536 /* Provide better error recovery. Note that a type name here is valid,
2537 and will be treated as a field name. */
2538 if (specs->typespec_kind == ctsk_tagdef
2539 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2540 && c_parser_next_token_starts_declspecs (parser)
2541 && !c_parser_next_token_is (parser, CPP_NAME))
2543 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2544 parser->error = false;
2548 pending_xref_error ();
2549 prefix_attrs = specs->attrs;
2550 all_prefix_attrs = prefix_attrs;
2551 specs->attrs = NULL_TREE;
2555 /* Declaring one or more declarators or un-named bit-fields. */
2556 struct c_declarator *declarator;
2558 if (c_parser_next_token_is (parser, CPP_COLON))
2559 declarator = build_id_declarator (NULL_TREE);
2561 declarator = c_parser_declarator (parser,
2562 specs->typespec_kind != ctsk_none,
2563 C_DTR_NORMAL, &dummy);
2564 if (declarator == NULL)
2566 c_parser_skip_to_end_of_block_or_statement (parser);
2569 if (c_parser_next_token_is (parser, CPP_COLON)
2570 || c_parser_next_token_is (parser, CPP_COMMA)
2571 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2572 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2573 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2575 tree postfix_attrs = NULL_TREE;
2576 tree width = NULL_TREE;
2578 if (c_parser_next_token_is (parser, CPP_COLON))
2580 c_parser_consume_token (parser);
2581 width = c_parser_expr_no_commas (parser, NULL).value;
2583 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2584 postfix_attrs = c_parser_attributes (parser);
2585 d = grokfield (c_parser_peek_token (parser)->location,
2586 declarator, specs, width, &all_prefix_attrs);
2587 decl_attributes (&d, chainon (postfix_attrs,
2588 all_prefix_attrs), 0);
2589 DECL_CHAIN (d) = decls;
2591 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2592 all_prefix_attrs = chainon (c_parser_attributes (parser),
2595 all_prefix_attrs = prefix_attrs;
2596 if (c_parser_next_token_is (parser, CPP_COMMA))
2597 c_parser_consume_token (parser);
2598 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2599 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2601 /* Semicolon consumed in caller. */
2606 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2612 c_parser_error (parser,
2613 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2614 "%<__attribute__%>");
2621 /* Parse a typeof specifier (a GNU extension).
2624 typeof ( expression )
2625 typeof ( type-name )
2628 static struct c_typespec
2629 c_parser_typeof_specifier (c_parser *parser)
2631 struct c_typespec ret;
2632 ret.kind = ctsk_typeof;
2633 ret.spec = error_mark_node;
2634 ret.expr = NULL_TREE;
2635 ret.expr_const_operands = true;
2636 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2637 c_parser_consume_token (parser);
2638 c_inhibit_evaluation_warnings++;
2640 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2642 c_inhibit_evaluation_warnings--;
2646 if (c_parser_next_token_starts_typename (parser))
2648 struct c_type_name *type = c_parser_type_name (parser);
2649 c_inhibit_evaluation_warnings--;
2653 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2654 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2660 location_t here = c_parser_peek_token (parser)->location;
2661 struct c_expr expr = c_parser_expression (parser);
2662 c_inhibit_evaluation_warnings--;
2664 if (TREE_CODE (expr.value) == COMPONENT_REF
2665 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2666 error_at (here, "%<typeof%> applied to a bit-field");
2667 mark_exp_read (expr.value);
2668 ret.spec = TREE_TYPE (expr.value);
2669 if (c_dialect_objc()
2670 && ret.spec != error_mark_node
2671 && lookup_attribute ("objc_volatilized", TYPE_ATTRIBUTES (ret.spec)))
2672 ret.spec = build_qualified_type
2673 (ret.spec, (TYPE_QUALS (ret.spec) & ~TYPE_QUAL_VOLATILE));
2674 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2675 /* This is returned with the type so that when the type is
2676 evaluated, this can be evaluated. */
2678 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2679 pop_maybe_used (was_vm);
2681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2685 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2686 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2687 be redeclared; otherwise it may not. KIND indicates which kind of
2688 declarator is wanted. Returns a valid declarator except in the
2689 case of a syntax error in which case NULL is returned. *SEEN_ID is
2690 set to true if an identifier being declared is seen; this is used
2691 to diagnose bad forms of abstract array declarators and to
2692 determine whether an identifier list is syntactically permitted.
2695 pointer[opt] direct-declarator
2699 ( attributes[opt] declarator )
2700 direct-declarator array-declarator
2701 direct-declarator ( parameter-type-list )
2702 direct-declarator ( identifier-list[opt] )
2705 * type-qualifier-list[opt]
2706 * type-qualifier-list[opt] pointer
2708 type-qualifier-list:
2711 type-qualifier-list type-qualifier
2712 type-qualifier-list attributes
2714 parameter-type-list:
2716 parameter-list , ...
2719 parameter-declaration
2720 parameter-list , parameter-declaration
2722 parameter-declaration:
2723 declaration-specifiers declarator attributes[opt]
2724 declaration-specifiers abstract-declarator[opt] attributes[opt]
2728 identifier-list , identifier
2730 abstract-declarator:
2732 pointer[opt] direct-abstract-declarator
2734 direct-abstract-declarator:
2735 ( attributes[opt] abstract-declarator )
2736 direct-abstract-declarator[opt] array-declarator
2737 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2742 direct-declarator ( parameter-forward-declarations
2743 parameter-type-list[opt] )
2745 direct-abstract-declarator:
2746 direct-abstract-declarator[opt] ( parameter-forward-declarations
2747 parameter-type-list[opt] )
2749 parameter-forward-declarations:
2751 parameter-forward-declarations parameter-list ;
2753 The uses of attributes shown above are GNU extensions.
2755 Some forms of array declarator are not included in C99 in the
2756 syntax for abstract declarators; these are disallowed elsewhere.
2757 This may be a defect (DR#289).
2759 This function also accepts an omitted abstract declarator as being
2760 an abstract declarator, although not part of the formal syntax. */
2762 static struct c_declarator *
2763 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2766 /* Parse any initial pointer part. */
2767 if (c_parser_next_token_is (parser, CPP_MULT))
2769 struct c_declspecs *quals_attrs = build_null_declspecs ();
2770 struct c_declarator *inner;
2771 c_parser_consume_token (parser);
2772 c_parser_declspecs (parser, quals_attrs, false, false, true);
2773 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2777 return make_pointer_declarator (quals_attrs, inner);
2779 /* Now we have a direct declarator, direct abstract declarator or
2780 nothing (which counts as a direct abstract declarator here). */
2781 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2784 /* Parse a direct declarator or direct abstract declarator; arguments
2785 as c_parser_declarator. */
2787 static struct c_declarator *
2788 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2791 /* The direct declarator must start with an identifier (possibly
2792 omitted) or a parenthesized declarator (possibly abstract). In
2793 an ordinary declarator, initial parentheses must start a
2794 parenthesized declarator. In an abstract declarator or parameter
2795 declarator, they could start a parenthesized declarator or a
2796 parameter list. To tell which, the open parenthesis and any
2797 following attributes must be read. If a declaration specifier
2798 follows, then it is a parameter list; if the specifier is a
2799 typedef name, there might be an ambiguity about redeclaring it,
2800 which is resolved in the direction of treating it as a typedef
2801 name. If a close parenthesis follows, it is also an empty
2802 parameter list, as the syntax does not permit empty abstract
2803 declarators. Otherwise, it is a parenthesized declarator (in
2804 which case the analysis may be repeated inside it, recursively).
2806 ??? There is an ambiguity in a parameter declaration "int
2807 (__attribute__((foo)) x)", where x is not a typedef name: it
2808 could be an abstract declarator for a function, or declare x with
2809 parentheses. The proper resolution of this ambiguity needs
2810 documenting. At present we follow an accident of the old
2811 parser's implementation, whereby the first parameter must have
2812 some declaration specifiers other than just attributes. Thus as
2813 a parameter declaration it is treated as a parenthesized
2814 parameter named x, and as an abstract declarator it is
2817 ??? Also following the old parser, attributes inside an empty
2818 parameter list are ignored, making it a list not yielding a
2819 prototype, rather than giving an error or making it have one
2820 parameter with implicit type int.
2822 ??? Also following the old parser, typedef names may be
2823 redeclared in declarators, but not Objective-C class names. */
2825 if (kind != C_DTR_ABSTRACT
2826 && c_parser_next_token_is (parser, CPP_NAME)
2828 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2829 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2830 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2832 struct c_declarator *inner
2833 = build_id_declarator (c_parser_peek_token (parser)->value);
2835 inner->id_loc = c_parser_peek_token (parser)->location;
2836 c_parser_consume_token (parser);
2837 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2840 if (kind != C_DTR_NORMAL
2841 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2843 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2844 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2847 /* Either we are at the end of an abstract declarator, or we have
2850 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2853 struct c_declarator *inner;
2854 c_parser_consume_token (parser);
2855 attrs = c_parser_attributes (parser);
2856 if (kind != C_DTR_NORMAL
2857 && (c_parser_next_token_starts_declspecs (parser)
2858 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2860 struct c_arg_info *args
2861 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2868 = build_function_declarator (args,
2869 build_id_declarator (NULL_TREE));
2870 return c_parser_direct_declarator_inner (parser, *seen_id,
2874 /* A parenthesized declarator. */
2875 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2876 if (inner != NULL && attrs != NULL)
2877 inner = build_attrs_declarator (attrs, inner);
2878 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2880 c_parser_consume_token (parser);
2884 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2888 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2895 if (kind == C_DTR_NORMAL)
2897 c_parser_error (parser, "expected identifier or %<(%>");
2901 return build_id_declarator (NULL_TREE);
2905 /* Parse part of a direct declarator or direct abstract declarator,
2906 given that some (in INNER) has already been parsed; ID_PRESENT is
2907 true if an identifier is present, false for an abstract
2910 static struct c_declarator *
2911 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2912 struct c_declarator *inner)
2914 /* Parse a sequence of array declarators and parameter lists. */
2915 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2917 location_t brace_loc = c_parser_peek_token (parser)->location;
2918 struct c_declarator *declarator;
2919 struct c_declspecs *quals_attrs = build_null_declspecs ();
2923 c_parser_consume_token (parser);
2924 c_parser_declspecs (parser, quals_attrs, false, false, true);
2925 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2927 c_parser_consume_token (parser);
2928 if (static_seen && !quals_attrs->declspecs_seen_p)
2929 c_parser_declspecs (parser, quals_attrs, false, false, true);
2930 if (!quals_attrs->declspecs_seen_p)
2932 /* If "static" is present, there must be an array dimension.
2933 Otherwise, there may be a dimension, "*", or no
2938 dimen = c_parser_expr_no_commas (parser, NULL).value;
2942 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2947 else if (c_parser_next_token_is (parser, CPP_MULT))
2949 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2953 c_parser_consume_token (parser);
2958 dimen = c_parser_expr_no_commas (parser, NULL).value;
2964 dimen = c_parser_expr_no_commas (parser, NULL).value;
2967 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2968 c_parser_consume_token (parser);
2971 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2976 mark_exp_read (dimen);
2977 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2978 static_seen, star_seen);
2979 if (declarator == NULL)
2981 inner = set_array_declarator_inner (declarator, inner);
2982 return c_parser_direct_declarator_inner (parser, id_present, inner);
2984 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2987 struct c_arg_info *args;
2988 c_parser_consume_token (parser);
2989 attrs = c_parser_attributes (parser);
2990 args = c_parser_parms_declarator (parser, id_present, attrs);
2995 inner = build_function_declarator (args, inner);
2996 return c_parser_direct_declarator_inner (parser, id_present, inner);
3002 /* Parse a parameter list or identifier list, including the closing
3003 parenthesis but not the opening one. ATTRS are the attributes at
3004 the start of the list. ID_LIST_OK is true if an identifier list is
3005 acceptable; such a list must not have attributes at the start. */
3007 static struct c_arg_info *
3008 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3011 declare_parm_level ();
3012 /* If the list starts with an identifier, it is an identifier list.
3013 Otherwise, it is either a prototype list or an empty list. */
3016 && c_parser_next_token_is (parser, CPP_NAME)
3017 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3019 tree list = NULL_TREE, *nextp = &list;
3020 while (c_parser_next_token_is (parser, CPP_NAME)
3021 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3023 *nextp = build_tree_list (NULL_TREE,
3024 c_parser_peek_token (parser)->value);
3025 nextp = & TREE_CHAIN (*nextp);
3026 c_parser_consume_token (parser);
3027 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3029 c_parser_consume_token (parser);
3030 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3032 c_parser_error (parser, "expected identifier");
3036 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3038 struct c_arg_info *ret = build_arg_info ();
3040 c_parser_consume_token (parser);
3046 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3054 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
3060 /* Parse a parameter list (possibly empty), including the closing
3061 parenthesis but not the opening one. ATTRS are the attributes at
3062 the start of the list. */
3064 static struct c_arg_info *
3065 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
3067 bool bad_parm = false;
3068 /* ??? Following the old parser, forward parameter declarations may
3069 use abstract declarators, and if no real parameter declarations
3070 follow the forward declarations then this is not diagnosed. Also
3071 note as above that attributes are ignored as the only contents of
3072 the parentheses, or as the only contents after forward
3074 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3076 struct c_arg_info *ret = build_arg_info ();
3077 c_parser_consume_token (parser);
3080 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3082 struct c_arg_info *ret = build_arg_info ();
3083 /* Suppress -Wold-style-definition for this case. */
3084 ret->types = error_mark_node;
3085 error_at (c_parser_peek_token (parser)->location,
3086 "ISO C requires a named argument before %<...%>");
3087 c_parser_consume_token (parser);
3088 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3090 c_parser_consume_token (parser);
3095 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3100 /* Nonempty list of parameters, either terminated with semicolon
3101 (forward declarations; recurse) or with close parenthesis (normal
3102 function) or with ", ... )" (variadic function). */
3105 /* Parse a parameter. */
3106 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3111 push_parm_decl (parm);
3112 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3115 c_parser_consume_token (parser);
3116 mark_forward_parm_decls ();
3117 new_attrs = c_parser_attributes (parser);
3118 return c_parser_parms_list_declarator (parser, new_attrs);
3120 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3122 c_parser_consume_token (parser);
3125 get_pending_sizes ();
3129 return get_parm_info (false);
3131 if (!c_parser_require (parser, CPP_COMMA,
3132 "expected %<;%>, %<,%> or %<)%>"))
3134 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3135 get_pending_sizes ();
3138 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3140 c_parser_consume_token (parser);
3141 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3143 c_parser_consume_token (parser);
3146 get_pending_sizes ();
3150 return get_parm_info (true);
3154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3156 get_pending_sizes ();
3163 /* Parse a parameter declaration. ATTRS are the attributes at the
3164 start of the declaration if it is the first parameter. */
3166 static struct c_parm *
3167 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3169 struct c_declspecs *specs;
3170 struct c_declarator *declarator;
3172 tree postfix_attrs = NULL_TREE;
3174 if (!c_parser_next_token_starts_declspecs (parser))
3176 c_token *token = c_parser_peek_token (parser);
3179 c_parser_set_source_position_from_token (token);
3180 if (token->type == CPP_NAME
3181 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
3182 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
3184 error ("unknown type name %qE", token->value);
3185 parser->error = true;
3187 /* ??? In some Objective-C cases '...' isn't applicable so there
3188 should be a different message. */
3190 c_parser_error (parser,
3191 "expected declaration specifiers or %<...%>");
3192 c_parser_skip_to_end_of_parameter (parser);
3195 specs = build_null_declspecs ();
3198 declspecs_add_attrs (specs, attrs);
3201 c_parser_declspecs (parser, specs, true, true, true);
3202 finish_declspecs (specs);
3203 pending_xref_error ();
3204 prefix_attrs = specs->attrs;
3205 specs->attrs = NULL_TREE;
3206 declarator = c_parser_declarator (parser,
3207 specs->typespec_kind != ctsk_none,
3208 C_DTR_PARM, &dummy);
3209 if (declarator == NULL)
3211 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3214 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3215 postfix_attrs = c_parser_attributes (parser);
3216 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3220 /* Parse a string literal in an asm expression. It should not be
3221 translated, and wide string literals are an error although
3222 permitted by the syntax. This is a GNU extension.
3227 ??? At present, following the old parser, the caller needs to have
3228 set lex_untranslated_string to 1. It would be better to follow the
3229 C++ parser rather than using this kludge. */
3232 c_parser_asm_string_literal (c_parser *parser)
3235 if (c_parser_next_token_is (parser, CPP_STRING))
3237 str = c_parser_peek_token (parser)->value;
3238 c_parser_consume_token (parser);
3240 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3242 error_at (c_parser_peek_token (parser)->location,
3243 "wide string literal in %<asm%>");
3244 str = build_string (1, "");
3245 c_parser_consume_token (parser);
3249 c_parser_error (parser, "expected string literal");
3255 /* Parse a simple asm expression. This is used in restricted
3256 contexts, where a full expression with inputs and outputs does not
3257 make sense. This is a GNU extension.
3260 asm ( asm-string-literal )
3264 c_parser_simple_asm_expr (c_parser *parser)
3267 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3268 /* ??? Follow the C++ parser rather than using the
3269 lex_untranslated_string kludge. */
3270 parser->lex_untranslated_string = true;
3271 c_parser_consume_token (parser);
3272 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3274 parser->lex_untranslated_string = false;
3277 str = c_parser_asm_string_literal (parser);
3278 parser->lex_untranslated_string = false;
3279 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3281 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3287 /* Parse (possibly empty) attributes. This is a GNU extension.
3291 attributes attribute
3294 __attribute__ ( ( attribute-list ) )
3298 attribute_list , attrib
3303 any-word ( identifier )
3304 any-word ( identifier , nonempty-expr-list )
3305 any-word ( expr-list )
3307 where the "identifier" must not be declared as a type, and
3308 "any-word" may be any identifier (including one declared as a
3309 type), a reserved word storage class specifier, type specifier or
3310 type qualifier. ??? This still leaves out most reserved keywords
3311 (following the old parser), shouldn't we include them, and why not
3312 allow identifiers declared as types to start the arguments? */
3315 c_parser_attributes (c_parser *parser)
3317 tree attrs = NULL_TREE;
3318 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3320 /* ??? Follow the C++ parser rather than using the
3321 lex_untranslated_string kludge. */
3322 parser->lex_untranslated_string = true;
3323 c_parser_consume_token (parser);
3324 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3326 parser->lex_untranslated_string = false;
3329 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3331 parser->lex_untranslated_string = false;
3332 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3335 /* Parse the attribute list. */
3336 while (c_parser_next_token_is (parser, CPP_COMMA)
3337 || c_parser_next_token_is (parser, CPP_NAME)
3338 || c_parser_next_token_is (parser, CPP_KEYWORD))
3340 tree attr, attr_name, attr_args;
3341 VEC(tree,gc) *expr_list;
3342 if (c_parser_next_token_is (parser, CPP_COMMA))
3344 c_parser_consume_token (parser);
3347 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3349 /* ??? See comment above about what keywords are
3352 switch (c_parser_peek_token (parser)->keyword)
3390 /* Accept __attribute__((__const)) as __attribute__((const))
3393 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3396 attr_name = c_parser_peek_token (parser)->value;
3397 c_parser_consume_token (parser);
3398 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3400 attr = build_tree_list (attr_name, NULL_TREE);
3401 attrs = chainon (attrs, attr);
3404 c_parser_consume_token (parser);
3405 /* Parse the attribute contents. If they start with an
3406 identifier which is followed by a comma or close
3407 parenthesis, then the arguments start with that
3408 identifier; otherwise they are an expression list.
3409 In objective-c the identifier may be a classname. */
3410 if (c_parser_next_token_is (parser, CPP_NAME)
3411 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3412 || (c_dialect_objc ()
3413 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3414 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3415 || (c_parser_peek_2nd_token (parser)->type
3416 == CPP_CLOSE_PAREN)))
3418 tree arg1 = c_parser_peek_token (parser)->value;
3419 c_parser_consume_token (parser);
3420 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3421 attr_args = build_tree_list (NULL_TREE, arg1);
3425 c_parser_consume_token (parser);
3426 expr_list = c_parser_expr_list (parser, false, true, NULL);
3427 tree_list = build_tree_list_vec (expr_list);
3428 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3429 release_tree_vector (expr_list);
3434 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3435 attr_args = NULL_TREE;
3438 expr_list = c_parser_expr_list (parser, false, true, NULL);
3439 attr_args = build_tree_list_vec (expr_list);
3440 release_tree_vector (expr_list);
3443 attr = build_tree_list (attr_name, attr_args);
3444 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3445 c_parser_consume_token (parser);
3448 parser->lex_untranslated_string = false;
3449 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3453 attrs = chainon (attrs, attr);
3455 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3456 c_parser_consume_token (parser);
3459 parser->lex_untranslated_string = false;
3460 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3464 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3465 c_parser_consume_token (parser);
3468 parser->lex_untranslated_string = false;
3469 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3473 parser->lex_untranslated_string = false;
3478 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3481 specifier-qualifier-list abstract-declarator[opt]
3484 static struct c_type_name *
3485 c_parser_type_name (c_parser *parser)
3487 struct c_declspecs *specs = build_null_declspecs ();
3488 struct c_declarator *declarator;
3489 struct c_type_name *ret;
3491 c_parser_declspecs (parser, specs, false, true, true);
3492 if (!specs->declspecs_seen_p)
3494 c_parser_error (parser, "expected specifier-qualifier-list");
3497 pending_xref_error ();
3498 finish_declspecs (specs);
3499 declarator = c_parser_declarator (parser,
3500 specs->typespec_kind != ctsk_none,
3501 C_DTR_ABSTRACT, &dummy);
3502 if (declarator == NULL)
3504 ret = XOBNEW (&parser_obstack, struct c_type_name);
3506 ret->declarator = declarator;
3510 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3513 assignment-expression
3514 { initializer-list }
3515 { initializer-list , }
3518 designation[opt] initializer
3519 initializer-list , designation[opt] initializer
3526 designator-list designator
3533 [ constant-expression ]
3545 [ constant-expression ... constant-expression ]
3547 Any expression without commas is accepted in the syntax for the
3548 constant-expressions, with non-constant expressions rejected later.
3550 This function is only used for top-level initializers; for nested
3551 ones, see c_parser_initval. */
3553 static struct c_expr
3554 c_parser_initializer (c_parser *parser)
3556 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3557 return c_parser_braced_init (parser, NULL_TREE, false);
3561 location_t loc = c_parser_peek_token (parser)->location;
3562 ret = c_parser_expr_no_commas (parser, NULL);
3563 if (TREE_CODE (ret.value) != STRING_CST
3564 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3565 ret = default_function_array_read_conversion (loc, ret);
3570 /* Parse a braced initializer list. TYPE is the type specified for a
3571 compound literal, and NULL_TREE for other initializers and for
3572 nested braced lists. NESTED_P is true for nested braced lists,
3573 false for the list of a compound literal or the list that is the
3574 top-level initializer in a declaration. */
3576 static struct c_expr
3577 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3580 struct obstack braced_init_obstack;
3581 location_t brace_loc = c_parser_peek_token (parser)->location;
3582 gcc_obstack_init (&braced_init_obstack);
3583 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3584 c_parser_consume_token (parser);
3586 push_init_level (0, &braced_init_obstack);
3588 really_start_incremental_init (type);
3589 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3591 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3595 /* Parse a non-empty initializer list, possibly with a trailing
3599 c_parser_initelt (parser, &braced_init_obstack);
3602 if (c_parser_next_token_is (parser, CPP_COMMA))
3603 c_parser_consume_token (parser);
3606 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3610 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3612 ret.value = error_mark_node;
3613 ret.original_code = ERROR_MARK;
3614 ret.original_type = NULL;
3615 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3616 pop_init_level (0, &braced_init_obstack);
3617 obstack_free (&braced_init_obstack, NULL);
3620 c_parser_consume_token (parser);
3621 ret = pop_init_level (0, &braced_init_obstack);
3622 obstack_free (&braced_init_obstack, NULL);
3626 /* Parse a nested initializer, including designators. */
3629 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3631 /* Parse any designator or designator list. A single array
3632 designator may have the subsequent "=" omitted in GNU C, but a
3633 longer list or a structure member designator may not. */
3634 if (c_parser_next_token_is (parser, CPP_NAME)
3635 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3637 /* Old-style structure member designator. */
3638 set_init_label (c_parser_peek_token (parser)->value,
3639 braced_init_obstack);
3640 /* Use the colon as the error location. */
3641 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3642 "obsolete use of designated initializer with %<:%>");
3643 c_parser_consume_token (parser);
3644 c_parser_consume_token (parser);
3648 /* des_seen is 0 if there have been no designators, 1 if there
3649 has been a single array designator and 2 otherwise. */
3651 /* Location of a designator. */
3652 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3653 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3654 || c_parser_next_token_is (parser, CPP_DOT))
3656 int des_prev = des_seen;
3658 des_loc = c_parser_peek_token (parser)->location;
3661 if (c_parser_next_token_is (parser, CPP_DOT))
3664 c_parser_consume_token (parser);
3665 if (c_parser_next_token_is (parser, CPP_NAME))
3667 set_init_label (c_parser_peek_token (parser)->value,
3668 braced_init_obstack);
3669 c_parser_consume_token (parser);
3674 init.value = error_mark_node;
3675 init.original_code = ERROR_MARK;
3676 init.original_type = NULL;
3677 c_parser_error (parser, "expected identifier");
3678 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3679 process_init_element (init, false, braced_init_obstack);
3686 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3687 /* ??? Following the old parser, [ objc-receiver
3688 objc-message-args ] is accepted as an initializer,
3689 being distinguished from a designator by what follows
3690 the first assignment expression inside the square
3691 brackets, but after a first array designator a
3692 subsequent square bracket is for Objective-C taken to
3693 start an expression, using the obsolete form of
3694 designated initializer without '=', rather than
3695 possibly being a second level of designation: in LALR
3696 terms, the '[' is shifted rather than reducing
3697 designator to designator-list. */
3698 if (des_prev == 1 && c_dialect_objc ())
3700 des_seen = des_prev;
3703 if (des_prev == 0 && c_dialect_objc ())
3705 /* This might be an array designator or an
3706 Objective-C message expression. If the former,
3707 continue parsing here; if the latter, parse the
3708 remainder of the initializer given the starting
3709 primary-expression. ??? It might make sense to
3710 distinguish when des_prev == 1 as well; see
3711 previous comment. */
3713 struct c_expr mexpr;
3714 c_parser_consume_token (parser);
3715 if (c_parser_peek_token (parser)->type == CPP_NAME
3716 && ((c_parser_peek_token (parser)->id_kind
3718 || (c_parser_peek_token (parser)->id_kind
3719 == C_ID_CLASSNAME)))
3721 /* Type name receiver. */
3722 tree id = c_parser_peek_token (parser)->value;
3723 c_parser_consume_token (parser);
3724 rec = objc_get_class_reference (id);
3725 goto parse_message_args;
3727 first = c_parser_expr_no_commas (parser, NULL).value;
3728 mark_exp_read (first);
3729 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3730 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3731 goto array_desig_after_first;
3732 /* Expression receiver. So far only one part
3733 without commas has been parsed; there might be
3734 more of the expression. */
3736 while (c_parser_next_token_is (parser, CPP_COMMA))
3739 location_t comma_loc, exp_loc;
3740 comma_loc = c_parser_peek_token (parser)->location;
3741 c_parser_consume_token (parser);
3742 exp_loc = c_parser_peek_token (parser)->location;
3743 next = c_parser_expr_no_commas (parser, NULL);
3744 next = default_function_array_read_conversion (exp_loc,
3746 rec = build_compound_expr (comma_loc, rec, next.value);
3749 /* Now parse the objc-message-args. */
3750 args = c_parser_objc_message_args (parser);
3751 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3754 = objc_build_message_expr (build_tree_list (rec, args));
3755 mexpr.original_code = ERROR_MARK;
3756 mexpr.original_type = NULL;
3757 /* Now parse and process the remainder of the
3758 initializer, starting with this message
3759 expression as a primary-expression. */
3760 c_parser_initval (parser, &mexpr, braced_init_obstack);
3763 c_parser_consume_token (parser);
3764 first = c_parser_expr_no_commas (parser, NULL).value;
3765 mark_exp_read (first);
3766 array_desig_after_first:
3767 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3769 ellipsis_loc = c_parser_peek_token (parser)->location;
3770 c_parser_consume_token (parser);
3771 second = c_parser_expr_no_commas (parser, NULL).value;
3772 mark_exp_read (second);
3776 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3778 c_parser_consume_token (parser);
3779 set_init_index (first, second, braced_init_obstack);
3781 pedwarn (ellipsis_loc, OPT_pedantic,
3782 "ISO C forbids specifying range of elements to initialize");
3785 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3791 if (c_parser_next_token_is (parser, CPP_EQ))
3794 pedwarn (des_loc, OPT_pedantic,
3795 "ISO C90 forbids specifying subobject to initialize");
3796 c_parser_consume_token (parser);
3801 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3802 "obsolete use of designated initializer without %<=%>");
3806 init.value = error_mark_node;
3807 init.original_code = ERROR_MARK;
3808 init.original_type = NULL;
3809 c_parser_error (parser, "expected %<=%>");
3810 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3811 process_init_element (init, false, braced_init_obstack);
3817 c_parser_initval (parser, NULL, braced_init_obstack);
3820 /* Parse a nested initializer; as c_parser_initializer but parses
3821 initializers within braced lists, after any designators have been
3822 applied. If AFTER is not NULL then it is an Objective-C message
3823 expression which is the primary-expression starting the
3827 c_parser_initval (c_parser *parser, struct c_expr *after,
3828 struct obstack * braced_init_obstack)
3831 gcc_assert (!after || c_dialect_objc ());
3832 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3833 init = c_parser_braced_init (parser, NULL_TREE, true);
3836 location_t loc = c_parser_peek_token (parser)->location;
3837 init = c_parser_expr_no_commas (parser, after);
3838 if (init.value != NULL_TREE
3839 && TREE_CODE (init.value) != STRING_CST
3840 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3841 init = default_function_array_read_conversion (loc, init);
3843 process_init_element (init, false, braced_init_obstack);
3846 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3850 { block-item-list[opt] }
3851 { label-declarations block-item-list }
3855 block-item-list block-item
3867 { label-declarations block-item-list }
3870 __extension__ nested-declaration
3871 nested-function-definition
3875 label-declarations label-declaration
3878 __label__ identifier-list ;
3880 Allowing the mixing of declarations and code is new in C99. The
3881 GNU syntax also permits (not shown above) labels at the end of
3882 compound statements, which yield an error. We don't allow labels
3883 on declarations; this might seem like a natural extension, but
3884 there would be a conflict between attributes on the label and
3885 prefix attributes on the declaration. ??? The syntax follows the
3886 old parser in requiring something after label declarations.
3887 Although they are erroneous if the labels declared aren't defined,
3888 is it useful for the syntax to be this way?
3900 c_parser_compound_statement (c_parser *parser)
3903 location_t brace_loc;
3904 brace_loc = c_parser_peek_token (parser)->location;
3905 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3907 /* Ensure a scope is entered and left anyway to avoid confusion
3908 if we have just prepared to enter a function body. */
3909 stmt = c_begin_compound_stmt (true);
3910 c_end_compound_stmt (brace_loc, stmt, true);
3911 return error_mark_node;
3913 stmt = c_begin_compound_stmt (true);
3914 c_parser_compound_statement_nostart (parser);
3915 return c_end_compound_stmt (brace_loc, stmt, true);
3918 /* Parse a compound statement except for the opening brace. This is
3919 used for parsing both compound statements and statement expressions
3920 (which follow different paths to handling the opening). */
3923 c_parser_compound_statement_nostart (c_parser *parser)
3925 bool last_stmt = false;
3926 bool last_label = false;
3927 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3928 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3929 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3931 c_parser_consume_token (parser);
3934 mark_valid_location_for_stdc_pragma (true);
3935 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3937 /* Read zero or more forward-declarations for labels that nested
3938 functions can jump to. */
3939 mark_valid_location_for_stdc_pragma (false);
3940 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3942 label_loc = c_parser_peek_token (parser)->location;
3943 c_parser_consume_token (parser);
3944 /* Any identifiers, including those declared as type names,
3949 if (c_parser_next_token_is_not (parser, CPP_NAME))
3951 c_parser_error (parser, "expected identifier");
3955 = declare_label (c_parser_peek_token (parser)->value);
3956 C_DECLARED_LABEL_FLAG (label) = 1;
3957 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3958 c_parser_consume_token (parser);
3959 if (c_parser_next_token_is (parser, CPP_COMMA))
3960 c_parser_consume_token (parser);
3964 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3966 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3968 /* We must now have at least one statement, label or declaration. */
3969 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3971 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3972 c_parser_error (parser, "expected declaration or statement");
3973 c_parser_consume_token (parser);
3976 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3978 location_t loc = c_parser_peek_token (parser)->location;
3979 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3980 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3981 || (c_parser_next_token_is (parser, CPP_NAME)
3982 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3984 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3985 label_loc = c_parser_peek_2nd_token (parser)->location;
3987 label_loc = c_parser_peek_token (parser)->location;
3990 mark_valid_location_for_stdc_pragma (false);
3991 c_parser_label (parser);
3993 else if (!last_label
3994 && c_parser_next_tokens_start_declaration (parser))
3997 mark_valid_location_for_stdc_pragma (false);
3998 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4001 (pedantic && !flag_isoc99)
4003 : OPT_Wdeclaration_after_statement,
4004 "ISO C90 forbids mixed declarations and code");
4007 else if (!last_label
4008 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4010 /* __extension__ can start a declaration, but is also an
4011 unary operator that can start an expression. Consume all
4012 but the last of a possible series of __extension__ to
4014 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4015 && (c_parser_peek_2nd_token (parser)->keyword
4017 c_parser_consume_token (parser);
4018 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4021 ext = disable_extension_diagnostics ();
4022 c_parser_consume_token (parser);
4024 mark_valid_location_for_stdc_pragma (false);
4025 c_parser_declaration_or_fndef (parser, true, true, true, true,
4027 /* Following the old parser, __extension__ does not
4028 disable this diagnostic. */
4029 restore_extension_diagnostics (ext);
4031 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4033 : OPT_Wdeclaration_after_statement,
4034 "ISO C90 forbids mixed declarations and code");
4040 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4042 /* External pragmas, and some omp pragmas, are not associated
4043 with regular c code, and so are not to be considered statements
4044 syntactically. This ensures that the user doesn't put them
4045 places that would turn into syntax errors if the directive
4047 if (c_parser_pragma (parser, pragma_compound))
4048 last_label = false, last_stmt = true;
4050 else if (c_parser_next_token_is (parser, CPP_EOF))
4052 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4053 c_parser_error (parser, "expected declaration or statement");
4056 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4058 if (parser->in_if_block)
4060 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4061 error_at (loc, """expected %<}%> before %<else%>");
4066 error_at (loc, "%<else%> without a previous %<if%>");
4067 c_parser_consume_token (parser);
4076 mark_valid_location_for_stdc_pragma (false);
4077 c_parser_statement_after_labels (parser);
4080 parser->error = false;
4083 error_at (label_loc, "label at end of compound statement");
4084 c_parser_consume_token (parser);
4085 /* Restore the value we started with. */
4086 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4089 /* Parse a label (C90 6.6.1, C99 6.8.1).
4092 identifier : attributes[opt]
4093 case constant-expression :
4099 case constant-expression ... constant-expression :
4101 The use of attributes on labels is a GNU extension. The syntax in
4102 GNU C accepts any expressions without commas, non-constant
4103 expressions being rejected later. */
4106 c_parser_label (c_parser *parser)
4108 location_t loc1 = c_parser_peek_token (parser)->location;
4109 tree label = NULL_TREE;
4110 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4113 c_parser_consume_token (parser);
4114 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4115 if (c_parser_next_token_is (parser, CPP_COLON))
4117 c_parser_consume_token (parser);
4118 label = do_case (loc1, exp1, NULL_TREE);
4120 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4122 c_parser_consume_token (parser);
4123 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4124 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4125 label = do_case (loc1, exp1, exp2);
4128 c_parser_error (parser, "expected %<:%> or %<...%>");
4130 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4132 c_parser_consume_token (parser);
4133 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4134 label = do_case (loc1, NULL_TREE, NULL_TREE);
4138 tree name = c_parser_peek_token (parser)->value;
4141 location_t loc2 = c_parser_peek_token (parser)->location;
4142 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4143 c_parser_consume_token (parser);
4144 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4145 c_parser_consume_token (parser);
4146 attrs = c_parser_attributes (parser);
4147 tlab = define_label (loc2, name);
4150 decl_attributes (&tlab, attrs, 0);
4151 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4156 if (c_parser_next_tokens_start_declaration (parser))
4158 error_at (c_parser_peek_token (parser)->location,
4159 "a label can only be part of a statement and "
4160 "a declaration is not a statement");
4161 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4162 /*static_assert_ok*/ true,
4163 /*nested*/ true, /*empty_ok*/ false,
4164 /*start_attr_ok*/ true, NULL);
4169 /* Parse a statement (C90 6.6, C99 6.8).
4174 expression-statement
4182 expression-statement:
4185 selection-statement:
4189 iteration-statement:
4198 return expression[opt] ;
4211 objc-throw-statement
4212 objc-try-catch-statement
4213 objc-synchronized-statement
4215 objc-throw-statement:
4229 parallel-for-construct
4230 parallel-sections-construct
4237 parallel-directive structured-block
4240 for-directive iteration-statement
4243 sections-directive section-scope
4246 single-directive structured-block
4248 parallel-for-construct:
4249 parallel-for-directive iteration-statement
4251 parallel-sections-construct:
4252 parallel-sections-directive section-scope
4255 master-directive structured-block
4258 critical-directive structured-block
4261 atomic-directive expression-statement
4264 ordered-directive structured-block */
4267 c_parser_statement (c_parser *parser)
4269 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4270 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4271 || (c_parser_next_token_is (parser, CPP_NAME)
4272 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4273 c_parser_label (parser);
4274 c_parser_statement_after_labels (parser);
4277 /* Parse a statement, other than a labeled statement. */
4280 c_parser_statement_after_labels (c_parser *parser)
4282 location_t loc = c_parser_peek_token (parser)->location;
4283 tree stmt = NULL_TREE;
4284 bool in_if_block = parser->in_if_block;
4285 parser->in_if_block = false;
4286 switch (c_parser_peek_token (parser)->type)
4288 case CPP_OPEN_BRACE:
4289 add_stmt (c_parser_compound_statement (parser));
4292 switch (c_parser_peek_token (parser)->keyword)
4295 c_parser_if_statement (parser);
4298 c_parser_switch_statement (parser);
4301 c_parser_while_statement (parser);
4304 c_parser_do_statement (parser);
4307 c_parser_for_statement (parser);
4310 c_parser_consume_token (parser);
4311 if (c_parser_next_token_is (parser, CPP_NAME))
4313 stmt = c_finish_goto_label (loc,
4314 c_parser_peek_token (parser)->value);
4315 c_parser_consume_token (parser);
4317 else if (c_parser_next_token_is (parser, CPP_MULT))
4321 c_parser_consume_token (parser);
4322 val = c_parser_expression (parser).value;
4323 mark_exp_read (val);
4324 stmt = c_finish_goto_ptr (loc, val);
4327 c_parser_error (parser, "expected identifier or %<*%>");
4328 goto expect_semicolon;
4330 c_parser_consume_token (parser);
4331 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4332 goto expect_semicolon;
4334 c_parser_consume_token (parser);
4335 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4336 goto expect_semicolon;
4338 c_parser_consume_token (parser);
4339 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4341 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4342 c_parser_consume_token (parser);
4346 struct c_expr expr = c_parser_expression_conv (parser);
4347 mark_exp_read (expr.value);
4348 stmt = c_finish_return (loc, expr.value, expr.original_type);
4349 goto expect_semicolon;
4353 stmt = c_parser_asm_statement (parser);
4356 gcc_assert (c_dialect_objc ());
4357 c_parser_consume_token (parser);
4358 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4360 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4361 c_parser_consume_token (parser);
4365 tree expr = c_parser_expression (parser).value;
4366 expr = c_fully_fold (expr, false, NULL);
4367 stmt = objc_build_throw_stmt (loc, expr);
4368 goto expect_semicolon;
4372 gcc_assert (c_dialect_objc ());
4373 c_parser_objc_try_catch_finally_statement (parser);
4375 case RID_AT_SYNCHRONIZED:
4376 gcc_assert (c_dialect_objc ());
4377 c_parser_objc_synchronized_statement (parser);
4384 c_parser_consume_token (parser);
4386 case CPP_CLOSE_PAREN:
4387 case CPP_CLOSE_SQUARE:
4388 /* Avoid infinite loop in error recovery:
4389 c_parser_skip_until_found stops at a closing nesting
4390 delimiter without consuming it, but here we need to consume
4391 it to proceed further. */
4392 c_parser_error (parser, "expected statement");
4393 c_parser_consume_token (parser);
4396 c_parser_pragma (parser, pragma_stmt);
4400 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4402 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4405 /* Two cases cannot and do not have line numbers associated: If stmt
4406 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4407 cannot hold line numbers. But that's OK because the statement
4408 will either be changed to a MODIFY_EXPR during gimplification of
4409 the statement expr, or discarded. If stmt was compound, but
4410 without new variables, we will have skipped the creation of a
4411 BIND and will have a bare STATEMENT_LIST. But that's OK because
4412 (recursively) all of the component statements should already have
4413 line numbers assigned. ??? Can we discard no-op statements
4415 if (CAN_HAVE_LOCATION_P (stmt)
4416 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4417 SET_EXPR_LOCATION (stmt, loc);
4419 parser->in_if_block = in_if_block;
4422 /* Parse the condition from an if, do, while or for statements. */
4425 c_parser_condition (c_parser *parser)
4427 location_t loc = c_parser_peek_token (parser)->location;
4429 cond = c_parser_expression_conv (parser).value;
4430 cond = c_objc_common_truthvalue_conversion (loc, cond);
4431 cond = c_fully_fold (cond, false, NULL);
4432 if (warn_sequence_point)
4433 verify_sequence_points (cond);
4437 /* Parse a parenthesized condition from an if, do or while statement.
4443 c_parser_paren_condition (c_parser *parser)
4446 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4447 return error_mark_node;
4448 cond = c_parser_condition (parser);
4449 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4453 /* Parse a statement which is a block in C99. */
4456 c_parser_c99_block_statement (c_parser *parser)
4458 tree block = c_begin_compound_stmt (flag_isoc99);
4459 location_t loc = c_parser_peek_token (parser)->location;
4460 c_parser_statement (parser);
4461 return c_end_compound_stmt (loc, block, flag_isoc99);
4464 /* Parse the body of an if statement. This is just parsing a
4465 statement but (a) it is a block in C99, (b) we track whether the
4466 body is an if statement for the sake of -Wparentheses warnings, (c)
4467 we handle an empty body specially for the sake of -Wempty-body
4468 warnings, and (d) we call parser_compound_statement directly
4469 because c_parser_statement_after_labels resets
4470 parser->in_if_block. */
4473 c_parser_if_body (c_parser *parser, bool *if_p)
4475 tree block = c_begin_compound_stmt (flag_isoc99);
4476 location_t body_loc = c_parser_peek_token (parser)->location;
4477 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4478 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4479 || (c_parser_next_token_is (parser, CPP_NAME)
4480 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4481 c_parser_label (parser);
4482 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4483 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4485 location_t loc = c_parser_peek_token (parser)->location;
4486 add_stmt (build_empty_stmt (loc));
4487 c_parser_consume_token (parser);
4488 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4489 warning_at (loc, OPT_Wempty_body,
4490 "suggest braces around empty body in an %<if%> statement");
4492 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4493 add_stmt (c_parser_compound_statement (parser));
4495 c_parser_statement_after_labels (parser);
4496 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4499 /* Parse the else body of an if statement. This is just parsing a
4500 statement but (a) it is a block in C99, (b) we handle an empty body
4501 specially for the sake of -Wempty-body warnings. */
4504 c_parser_else_body (c_parser *parser)
4506 location_t else_loc = c_parser_peek_token (parser)->location;
4507 tree block = c_begin_compound_stmt (flag_isoc99);
4508 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4509 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4510 || (c_parser_next_token_is (parser, CPP_NAME)
4511 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4512 c_parser_label (parser);
4513 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4515 location_t loc = c_parser_peek_token (parser)->location;
4518 "suggest braces around empty body in an %<else%> statement");
4519 add_stmt (build_empty_stmt (loc));
4520 c_parser_consume_token (parser);
4523 c_parser_statement_after_labels (parser);
4524 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4527 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4530 if ( expression ) statement
4531 if ( expression ) statement else statement
4535 c_parser_if_statement (c_parser *parser)
4540 bool first_if = false;
4541 tree first_body, second_body;
4544 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4545 c_parser_consume_token (parser);
4546 block = c_begin_compound_stmt (flag_isoc99);
4547 loc = c_parser_peek_token (parser)->location;
4548 cond = c_parser_paren_condition (parser);
4549 in_if_block = parser->in_if_block;
4550 parser->in_if_block = true;
4551 first_body = c_parser_if_body (parser, &first_if);
4552 parser->in_if_block = in_if_block;
4553 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4555 c_parser_consume_token (parser);
4556 second_body = c_parser_else_body (parser);
4559 second_body = NULL_TREE;
4560 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4561 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4564 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4567 switch (expression) statement
4571 c_parser_switch_statement (c_parser *parser)
4573 tree block, expr, body, save_break;
4574 location_t switch_loc = c_parser_peek_token (parser)->location;
4575 location_t switch_cond_loc;
4576 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4577 c_parser_consume_token (parser);
4578 block = c_begin_compound_stmt (flag_isoc99);
4579 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4581 switch_cond_loc = c_parser_peek_token (parser)->location;
4582 expr = c_parser_expression (parser).value;
4583 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4587 switch_cond_loc = UNKNOWN_LOCATION;
4588 expr = error_mark_node;
4590 c_start_case (switch_loc, switch_cond_loc, expr);
4591 save_break = c_break_label;
4592 c_break_label = NULL_TREE;
4593 body = c_parser_c99_block_statement (parser);
4594 c_finish_case (body);
4597 location_t here = c_parser_peek_token (parser)->location;
4598 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4599 SET_EXPR_LOCATION (t, here);
4602 c_break_label = save_break;
4603 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4606 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4609 while (expression) statement
4613 c_parser_while_statement (c_parser *parser)
4615 tree block, cond, body, save_break, save_cont;
4617 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4618 c_parser_consume_token (parser);
4619 block = c_begin_compound_stmt (flag_isoc99);
4620 loc = c_parser_peek_token (parser)->location;
4621 cond = c_parser_paren_condition (parser);
4622 save_break = c_break_label;
4623 c_break_label = NULL_TREE;
4624 save_cont = c_cont_label;
4625 c_cont_label = NULL_TREE;
4626 body = c_parser_c99_block_statement (parser);
4627 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4628 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4629 c_break_label = save_break;
4630 c_cont_label = save_cont;
4633 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4636 do statement while ( expression ) ;
4640 c_parser_do_statement (c_parser *parser)
4642 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4644 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4645 c_parser_consume_token (parser);
4646 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4647 warning_at (c_parser_peek_token (parser)->location,
4649 "suggest braces around empty body in %<do%> statement");
4650 block = c_begin_compound_stmt (flag_isoc99);
4651 loc = c_parser_peek_token (parser)->location;
4652 save_break = c_break_label;
4653 c_break_label = NULL_TREE;
4654 save_cont = c_cont_label;
4655 c_cont_label = NULL_TREE;
4656 body = c_parser_c99_block_statement (parser);
4657 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4658 new_break = c_break_label;
4659 c_break_label = save_break;
4660 new_cont = c_cont_label;
4661 c_cont_label = save_cont;
4662 cond = c_parser_paren_condition (parser);
4663 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4664 c_parser_skip_to_end_of_block_or_statement (parser);
4665 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4666 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4669 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4672 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4673 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4675 The form with a declaration is new in C99.
4677 ??? In accordance with the old parser, the declaration may be a
4678 nested function, which is then rejected in check_for_loop_decls,
4679 but does it make any sense for this to be included in the grammar?
4680 Note in particular that the nested function does not include a
4681 trailing ';', whereas the "declaration" production includes one.
4682 Also, can we reject bad declarations earlier and cheaper than
4683 check_for_loop_decls?
4685 In Objective-C, there are two additional variants:
4688 for ( expression in expresssion ) statement
4689 for ( declaration in expression ) statement
4691 This is inconsistent with C, because the second variant is allowed
4692 even if c99 is not enabled.
4694 The rest of the comment documents these Objective-C foreach-statement.
4696 Here is the canonical example of the first variant:
4697 for (object in array) { do something with object }
4698 we call the first expression ("object") the "object_expression" and
4699 the second expression ("array") the "collection_expression".
4700 object_expression must be an lvalue of type "id" (a generic Objective-C
4701 object) because the loop works by assigning to object_expression the
4702 various objects from the collection_expression. collection_expression
4703 must evaluate to something of type "id" which responds to the method
4704 countByEnumeratingWithState:objects:count:.
4706 The canonical example of the second variant is:
4707 for (id object in array) { do something with object }
4708 which is completely equivalent to
4711 for (object in array) { do something with object }
4713 Note that initizializing 'object' in some way (eg, "for ((object =
4714 xxx) in array) { do something with object }") is possibly
4715 technically valid, but completely pointless as 'object' will be
4716 assigned to something else as soon as the loop starts. We should
4717 most likely reject it (TODO).
4719 The beginning of the Objective-C foreach-statement looks exactly
4720 like the beginning of the for-statement, and we can tell it is a
4721 foreach-statement only because the initial declaration or
4722 expression is terminated by 'in' instead of ';'.
4726 c_parser_for_statement (c_parser *parser)
4728 tree block, cond, incr, save_break, save_cont, body;
4729 /* The following are only used when parsing an ObjC foreach statement. */
4730 tree object_expression, collection_expression;
4731 location_t loc = c_parser_peek_token (parser)->location;
4732 location_t for_loc = c_parser_peek_token (parser)->location;
4733 bool is_foreach_statement = false;
4734 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4735 c_parser_consume_token (parser);
4736 /* Open a compound statement in Objective-C as well, just in case this is
4737 as foreach expression. */
4738 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4739 cond = error_mark_node;
4740 incr = error_mark_node;
4741 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4743 /* Parse the initialization declaration or expression. */
4744 object_expression = error_mark_node;
4745 parser->objc_could_be_foreach_context = c_dialect_objc ();
4746 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4748 parser->objc_could_be_foreach_context = false;
4749 c_parser_consume_token (parser);
4750 c_finish_expr_stmt (loc, NULL_TREE);
4752 else if (c_parser_next_tokens_start_declaration (parser))
4754 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4755 &object_expression);
4756 parser->objc_could_be_foreach_context = false;
4758 if (c_parser_next_token_is_keyword (parser, RID_IN))
4760 c_parser_consume_token (parser);
4761 is_foreach_statement = true;
4762 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4763 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4766 check_for_loop_decls (for_loc, flag_isoc99);
4768 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4770 /* __extension__ can start a declaration, but is also an
4771 unary operator that can start an expression. Consume all
4772 but the last of a possible series of __extension__ to
4774 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4775 && (c_parser_peek_2nd_token (parser)->keyword
4777 c_parser_consume_token (parser);
4778 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4781 ext = disable_extension_diagnostics ();
4782 c_parser_consume_token (parser);
4783 c_parser_declaration_or_fndef (parser, true, true, true, true,
4784 true, &object_expression);
4785 parser->objc_could_be_foreach_context = false;
4787 restore_extension_diagnostics (ext);
4788 if (c_parser_next_token_is_keyword (parser, RID_IN))
4790 c_parser_consume_token (parser);
4791 is_foreach_statement = true;
4792 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4793 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4796 check_for_loop_decls (for_loc, flag_isoc99);
4805 tree init_expression;
4806 init_expression = c_parser_expression (parser).value;
4807 parser->objc_could_be_foreach_context = false;
4808 if (c_parser_next_token_is_keyword (parser, RID_IN))
4810 c_parser_consume_token (parser);
4811 is_foreach_statement = true;
4812 if (! lvalue_p (init_expression))
4813 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4814 object_expression = c_process_expr_stmt (loc, init_expression);
4819 c_finish_expr_stmt (loc, init_expression);
4820 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4824 /* Parse the loop condition. In the case of a foreach
4825 statement, there is no loop condition. */
4826 gcc_assert (!parser->objc_could_be_foreach_context);
4827 if (!is_foreach_statement)
4829 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4831 c_parser_consume_token (parser);
4836 cond = c_parser_condition (parser);
4837 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4840 /* Parse the increment expression (the third expression in a
4841 for-statement). In the case of a foreach-statement, this is
4842 the expression that follows the 'in'. */
4843 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4845 if (is_foreach_statement)
4847 c_parser_error (parser, "missing collection in fast enumeration");
4848 collection_expression = error_mark_node;
4851 incr = c_process_expr_stmt (loc, NULL_TREE);
4855 if (is_foreach_statement)
4856 collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4858 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4860 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4862 save_break = c_break_label;
4863 c_break_label = NULL_TREE;
4864 save_cont = c_cont_label;
4865 c_cont_label = NULL_TREE;
4866 body = c_parser_c99_block_statement (parser);
4867 if (is_foreach_statement)
4868 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4870 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4871 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4872 c_break_label = save_break;
4873 c_cont_label = save_cont;
4876 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4877 statement with inputs, outputs, clobbers, and volatile tag
4881 asm type-qualifier[opt] ( asm-argument ) ;
4882 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4886 asm-string-literal : asm-operands[opt]
4887 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4888 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4891 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4894 Qualifiers other than volatile are accepted in the syntax but
4898 c_parser_asm_statement (c_parser *parser)
4900 tree quals, str, outputs, inputs, clobbers, labels, ret;
4901 bool simple, is_goto;
4902 location_t asm_loc = c_parser_peek_token (parser)->location;
4903 int section, nsections;
4905 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4906 c_parser_consume_token (parser);
4907 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4909 quals = c_parser_peek_token (parser)->value;
4910 c_parser_consume_token (parser);
4912 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4913 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4915 warning_at (c_parser_peek_token (parser)->location,
4917 "%E qualifier ignored on asm",
4918 c_parser_peek_token (parser)->value);
4920 c_parser_consume_token (parser);
4926 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4928 c_parser_consume_token (parser);
4932 /* ??? Follow the C++ parser rather than using the
4933 lex_untranslated_string kludge. */
4934 parser->lex_untranslated_string = true;
4937 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4940 str = c_parser_asm_string_literal (parser);
4941 if (str == NULL_TREE)
4942 goto error_close_paren;
4945 outputs = NULL_TREE;
4947 clobbers = NULL_TREE;
4950 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4953 /* Parse each colon-delimited section of operands. */
4954 nsections = 3 + is_goto;
4955 for (section = 0; section < nsections; ++section)
4957 if (!c_parser_require (parser, CPP_COLON,
4960 : "expected %<:%> or %<)%>"))
4961 goto error_close_paren;
4963 /* Once past any colon, we're no longer a simple asm. */
4966 if ((!c_parser_next_token_is (parser, CPP_COLON)
4967 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4972 /* For asm goto, we don't allow output operands, but reserve
4973 the slot for a future extension that does allow them. */
4975 outputs = c_parser_asm_operands (parser, false);
4978 inputs = c_parser_asm_operands (parser, true);
4981 clobbers = c_parser_asm_clobbers (parser);
4984 labels = c_parser_asm_goto_operands (parser);
4990 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4995 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4997 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5001 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5002 c_parser_skip_to_end_of_block_or_statement (parser);
5004 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5005 clobbers, labels, simple));
5008 parser->lex_untranslated_string = false;
5012 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5016 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5017 not outputs), apply the default conversion of functions and arrays
5022 asm-operands , asm-operand
5025 asm-string-literal ( expression )
5026 [ identifier ] asm-string-literal ( expression )
5030 c_parser_asm_operands (c_parser *parser, bool convert_p)
5032 tree list = NULL_TREE;
5038 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5040 c_parser_consume_token (parser);
5041 if (c_parser_next_token_is (parser, CPP_NAME))
5043 tree id = c_parser_peek_token (parser)->value;
5044 c_parser_consume_token (parser);
5045 name = build_string (IDENTIFIER_LENGTH (id),
5046 IDENTIFIER_POINTER (id));
5050 c_parser_error (parser, "expected identifier");
5051 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5054 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5059 str = c_parser_asm_string_literal (parser);
5060 if (str == NULL_TREE)
5062 parser->lex_untranslated_string = false;
5063 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5065 parser->lex_untranslated_string = true;
5068 loc = c_parser_peek_token (parser)->location;
5069 expr = c_parser_expression (parser);
5070 mark_exp_read (expr.value);
5072 expr = default_function_array_conversion (loc, expr);
5073 expr.value = c_fully_fold (expr.value, false, NULL);
5074 parser->lex_untranslated_string = true;
5075 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5077 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5080 list = chainon (list, build_tree_list (build_tree_list (name, str),
5082 if (c_parser_next_token_is (parser, CPP_COMMA))
5083 c_parser_consume_token (parser);
5090 /* Parse asm clobbers, a GNU extension.
5094 asm-clobbers , asm-string-literal
5098 c_parser_asm_clobbers (c_parser *parser)
5100 tree list = NULL_TREE;
5103 tree str = c_parser_asm_string_literal (parser);
5105 list = tree_cons (NULL_TREE, str, list);
5108 if (c_parser_next_token_is (parser, CPP_COMMA))
5109 c_parser_consume_token (parser);
5116 /* Parse asm goto labels, a GNU extension.
5120 asm-goto-operands , identifier
5124 c_parser_asm_goto_operands (c_parser *parser)
5126 tree list = NULL_TREE;
5131 if (c_parser_next_token_is (parser, CPP_NAME))
5133 c_token *tok = c_parser_peek_token (parser);
5135 label = lookup_label_for_goto (tok->location, name);
5136 c_parser_consume_token (parser);
5137 TREE_USED (label) = 1;
5141 c_parser_error (parser, "expected identifier");
5145 name = build_string (IDENTIFIER_LENGTH (name),
5146 IDENTIFIER_POINTER (name));
5147 list = tree_cons (name, label, list);
5148 if (c_parser_next_token_is (parser, CPP_COMMA))
5149 c_parser_consume_token (parser);
5151 return nreverse (list);
5155 /* Parse an expression other than a compound expression; that is, an
5156 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5157 NULL then it is an Objective-C message expression which is the
5158 primary-expression starting the expression as an initializer.
5160 assignment-expression:
5161 conditional-expression
5162 unary-expression assignment-operator assignment-expression
5164 assignment-operator: one of
5165 = *= /= %= += -= <<= >>= &= ^= |=
5167 In GNU C we accept any conditional expression on the LHS and
5168 diagnose the invalid lvalue rather than producing a syntax
5171 static struct c_expr
5172 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5174 struct c_expr lhs, rhs, ret;
5175 enum tree_code code;
5176 location_t op_location, exp_location;
5177 gcc_assert (!after || c_dialect_objc ());
5178 lhs = c_parser_conditional_expression (parser, after);
5179 op_location = c_parser_peek_token (parser)->location;
5180 switch (c_parser_peek_token (parser)->type)
5189 code = TRUNC_DIV_EXPR;
5192 code = TRUNC_MOD_EXPR;
5207 code = BIT_AND_EXPR;
5210 code = BIT_XOR_EXPR;
5213 code = BIT_IOR_EXPR;
5218 c_parser_consume_token (parser);
5219 exp_location = c_parser_peek_token (parser)->location;
5220 rhs = c_parser_expr_no_commas (parser, NULL);
5221 rhs = default_function_array_read_conversion (exp_location, rhs);
5222 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5223 code, exp_location, rhs.value,
5225 if (code == NOP_EXPR)
5226 ret.original_code = MODIFY_EXPR;
5229 TREE_NO_WARNING (ret.value) = 1;
5230 ret.original_code = ERROR_MARK;
5232 ret.original_type = NULL;
5236 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5237 is not NULL then it is an Objective-C message expression which is
5238 the primary-expression starting the expression as an initializer.
5240 conditional-expression:
5241 logical-OR-expression
5242 logical-OR-expression ? expression : conditional-expression
5246 conditional-expression:
5247 logical-OR-expression ? : conditional-expression
5250 static struct c_expr
5251 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5253 struct c_expr cond, exp1, exp2, ret;
5254 location_t cond_loc, colon_loc, middle_loc;
5256 gcc_assert (!after || c_dialect_objc ());
5258 cond = c_parser_binary_expression (parser, after);
5260 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5262 cond_loc = c_parser_peek_token (parser)->location;
5263 cond = default_function_array_read_conversion (cond_loc, cond);
5264 c_parser_consume_token (parser);
5265 if (c_parser_next_token_is (parser, CPP_COLON))
5267 tree eptype = NULL_TREE;
5269 middle_loc = c_parser_peek_token (parser)->location;
5270 pedwarn (middle_loc, OPT_pedantic,
5271 "ISO C forbids omitting the middle term of a ?: expression");
5272 warn_for_omitted_condop (middle_loc, cond.value);
5273 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5275 eptype = TREE_TYPE (cond.value);
5276 cond.value = TREE_OPERAND (cond.value, 0);
5278 /* Make sure first operand is calculated only once. */
5279 exp1.value = c_save_expr (default_conversion (cond.value));
5281 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5282 exp1.original_type = NULL;
5283 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5284 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5289 = c_objc_common_truthvalue_conversion
5290 (cond_loc, default_conversion (cond.value));
5291 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5292 exp1 = c_parser_expression_conv (parser);
5293 mark_exp_read (exp1.value);
5294 c_inhibit_evaluation_warnings +=
5295 ((cond.value == truthvalue_true_node)
5296 - (cond.value == truthvalue_false_node));
5299 colon_loc = c_parser_peek_token (parser)->location;
5300 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5302 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5303 ret.value = error_mark_node;
5304 ret.original_code = ERROR_MARK;
5305 ret.original_type = NULL;
5309 location_t exp2_loc = c_parser_peek_token (parser)->location;
5310 exp2 = c_parser_conditional_expression (parser, NULL);
5311 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5313 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5314 ret.value = build_conditional_expr (colon_loc, cond.value,
5315 cond.original_code == C_MAYBE_CONST_EXPR,
5316 exp1.value, exp1.original_type,
5317 exp2.value, exp2.original_type);
5318 ret.original_code = ERROR_MARK;
5319 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5320 ret.original_type = NULL;
5325 /* If both sides are enum type, the default conversion will have
5326 made the type of the result be an integer type. We want to
5327 remember the enum types we started with. */
5328 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5329 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5330 ret.original_type = ((t1 != error_mark_node
5331 && t2 != error_mark_node
5332 && (TYPE_MAIN_VARIANT (t1)
5333 == TYPE_MAIN_VARIANT (t2)))
5340 /* Parse a binary expression; that is, a logical-OR-expression (C90
5341 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5342 an Objective-C message expression which is the primary-expression
5343 starting the expression as an initializer.
5345 multiplicative-expression:
5347 multiplicative-expression * cast-expression
5348 multiplicative-expression / cast-expression
5349 multiplicative-expression % cast-expression
5351 additive-expression:
5352 multiplicative-expression
5353 additive-expression + multiplicative-expression
5354 additive-expression - multiplicative-expression
5358 shift-expression << additive-expression
5359 shift-expression >> additive-expression
5361 relational-expression:
5363 relational-expression < shift-expression
5364 relational-expression > shift-expression
5365 relational-expression <= shift-expression
5366 relational-expression >= shift-expression
5368 equality-expression:
5369 relational-expression
5370 equality-expression == relational-expression
5371 equality-expression != relational-expression
5375 AND-expression & equality-expression
5377 exclusive-OR-expression:
5379 exclusive-OR-expression ^ AND-expression
5381 inclusive-OR-expression:
5382 exclusive-OR-expression
5383 inclusive-OR-expression | exclusive-OR-expression
5385 logical-AND-expression:
5386 inclusive-OR-expression
5387 logical-AND-expression && inclusive-OR-expression
5389 logical-OR-expression:
5390 logical-AND-expression
5391 logical-OR-expression || logical-AND-expression
5394 static struct c_expr
5395 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5397 /* A binary expression is parsed using operator-precedence parsing,
5398 with the operands being cast expressions. All the binary
5399 operators are left-associative. Thus a binary expression is of
5402 E0 op1 E1 op2 E2 ...
5404 which we represent on a stack. On the stack, the precedence
5405 levels are strictly increasing. When a new operator is
5406 encountered of higher precedence than that at the top of the
5407 stack, it is pushed; its LHS is the top expression, and its RHS
5408 is everything parsed until it is popped. When a new operator is
5409 encountered with precedence less than or equal to that at the top
5410 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5411 by the result of the operation until the operator at the top of
5412 the stack has lower precedence than the new operator or there is
5413 only one element on the stack; then the top expression is the LHS
5414 of the new operator. In the case of logical AND and OR
5415 expressions, we also need to adjust c_inhibit_evaluation_warnings
5416 as appropriate when the operators are pushed and popped. */
5418 /* The precedence levels, where 0 is a dummy lowest level used for
5419 the bottom of the stack. */
5435 /* The expression at this stack level. */
5437 /* The precedence of the operator on its left, PREC_NONE at the
5438 bottom of the stack. */
5440 /* The operation on its left. */
5442 /* The source location of this operation. */
5446 /* Location of the binary operator. */
5447 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5450 switch (stack[sp].op) \
5452 case TRUTH_ANDIF_EXPR: \
5453 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5454 == truthvalue_false_node); \
5456 case TRUTH_ORIF_EXPR: \
5457 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5458 == truthvalue_true_node); \
5463 stack[sp - 1].expr \
5464 = default_function_array_read_conversion (stack[sp - 1].loc, \
5465 stack[sp - 1].expr); \
5467 = default_function_array_read_conversion (stack[sp].loc, \
5469 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5471 stack[sp - 1].expr, \
5475 gcc_assert (!after || c_dialect_objc ());
5476 stack[0].loc = c_parser_peek_token (parser)->location;
5477 stack[0].expr = c_parser_cast_expression (parser, after);
5478 stack[0].prec = PREC_NONE;
5483 enum tree_code ocode;
5486 switch (c_parser_peek_token (parser)->type)
5494 ocode = TRUNC_DIV_EXPR;
5498 ocode = TRUNC_MOD_EXPR;
5510 ocode = LSHIFT_EXPR;
5514 ocode = RSHIFT_EXPR;
5528 case CPP_GREATER_EQ:
5541 oprec = PREC_BITAND;
5542 ocode = BIT_AND_EXPR;
5545 oprec = PREC_BITXOR;
5546 ocode = BIT_XOR_EXPR;
5550 ocode = BIT_IOR_EXPR;
5553 oprec = PREC_LOGAND;
5554 ocode = TRUTH_ANDIF_EXPR;
5558 ocode = TRUTH_ORIF_EXPR;
5561 /* Not a binary operator, so end of the binary
5565 binary_loc = c_parser_peek_token (parser)->location;
5566 c_parser_consume_token (parser);
5567 while (oprec <= stack[sp].prec)
5571 case TRUTH_ANDIF_EXPR:
5573 = default_function_array_read_conversion (stack[sp].loc,
5575 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5576 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5577 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5578 == truthvalue_false_node);
5580 case TRUTH_ORIF_EXPR:
5582 = default_function_array_read_conversion (stack[sp].loc,
5584 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5585 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5586 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5587 == truthvalue_true_node);
5593 stack[sp].loc = binary_loc;
5594 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5595 stack[sp].prec = oprec;
5596 stack[sp].op = ocode;
5597 stack[sp].loc = binary_loc;
5602 return stack[0].expr;
5606 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5607 NULL then it is an Objective-C message expression which is the
5608 primary-expression starting the expression as an initializer.
5612 ( type-name ) unary-expression
5615 static struct c_expr
5616 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5618 location_t cast_loc = c_parser_peek_token (parser)->location;
5619 gcc_assert (!after || c_dialect_objc ());
5621 return c_parser_postfix_expression_after_primary (parser,
5623 /* If the expression begins with a parenthesized type name, it may
5624 be either a cast or a compound literal; we need to see whether
5625 the next character is '{' to tell the difference. If not, it is
5626 an unary expression. */
5627 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5628 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5630 struct c_type_name *type_name;
5633 c_parser_consume_token (parser);
5634 type_name = c_parser_type_name (parser);
5635 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5636 if (type_name == NULL)
5638 ret.value = error_mark_node;
5639 ret.original_code = ERROR_MARK;
5640 ret.original_type = NULL;
5644 /* Save casted types in the function's used types hash table. */
5645 used_types_insert (type_name->specs->type);
5647 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5648 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5651 location_t expr_loc = c_parser_peek_token (parser)->location;
5652 expr = c_parser_cast_expression (parser, NULL);
5653 expr = default_function_array_read_conversion (expr_loc, expr);
5655 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5656 ret.original_code = ERROR_MARK;
5657 ret.original_type = NULL;
5661 return c_parser_unary_expression (parser);
5664 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5670 unary-operator cast-expression
5671 sizeof unary-expression
5672 sizeof ( type-name )
5674 unary-operator: one of
5680 __alignof__ unary-expression
5681 __alignof__ ( type-name )
5684 unary-operator: one of
5685 __extension__ __real__ __imag__
5687 In addition, the GNU syntax treats ++ and -- as unary operators, so
5688 they may be applied to cast expressions with errors for non-lvalues
5691 static struct c_expr
5692 c_parser_unary_expression (c_parser *parser)
5695 struct c_expr ret, op;
5696 location_t op_loc = c_parser_peek_token (parser)->location;
5698 ret.original_code = ERROR_MARK;
5699 ret.original_type = NULL;
5700 switch (c_parser_peek_token (parser)->type)
5703 c_parser_consume_token (parser);
5704 exp_loc = c_parser_peek_token (parser)->location;
5705 op = c_parser_cast_expression (parser, NULL);
5706 op = default_function_array_read_conversion (exp_loc, op);
5707 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5708 case CPP_MINUS_MINUS:
5709 c_parser_consume_token (parser);
5710 exp_loc = c_parser_peek_token (parser)->location;
5711 op = c_parser_cast_expression (parser, NULL);
5712 op = default_function_array_read_conversion (exp_loc, op);
5713 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5715 c_parser_consume_token (parser);
5716 op = c_parser_cast_expression (parser, NULL);
5717 mark_exp_read (op.value);
5718 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5720 c_parser_consume_token (parser);
5721 exp_loc = c_parser_peek_token (parser)->location;
5722 op = c_parser_cast_expression (parser, NULL);
5723 op = default_function_array_read_conversion (exp_loc, op);
5724 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5727 if (!c_dialect_objc () && !in_system_header)
5730 "traditional C rejects the unary plus operator");
5731 c_parser_consume_token (parser);
5732 exp_loc = c_parser_peek_token (parser)->location;
5733 op = c_parser_cast_expression (parser, NULL);
5734 op = default_function_array_read_conversion (exp_loc, op);
5735 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5737 c_parser_consume_token (parser);
5738 exp_loc = c_parser_peek_token (parser)->location;
5739 op = c_parser_cast_expression (parser, NULL);
5740 op = default_function_array_read_conversion (exp_loc, op);
5741 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5743 c_parser_consume_token (parser);
5744 exp_loc = c_parser_peek_token (parser)->location;
5745 op = c_parser_cast_expression (parser, NULL);
5746 op = default_function_array_read_conversion (exp_loc, op);
5747 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5749 c_parser_consume_token (parser);
5750 exp_loc = c_parser_peek_token (parser)->location;
5751 op = c_parser_cast_expression (parser, NULL);
5752 op = default_function_array_read_conversion (exp_loc, op);
5753 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5755 /* Refer to the address of a label as a pointer. */
5756 c_parser_consume_token (parser);
5757 if (c_parser_next_token_is (parser, CPP_NAME))
5759 ret.value = finish_label_address_expr
5760 (c_parser_peek_token (parser)->value, op_loc);
5761 c_parser_consume_token (parser);
5765 c_parser_error (parser, "expected identifier");
5766 ret.value = error_mark_node;
5770 switch (c_parser_peek_token (parser)->keyword)
5773 return c_parser_sizeof_expression (parser);
5775 return c_parser_alignof_expression (parser);
5777 c_parser_consume_token (parser);
5778 ext = disable_extension_diagnostics ();
5779 ret = c_parser_cast_expression (parser, NULL);
5780 restore_extension_diagnostics (ext);
5783 c_parser_consume_token (parser);
5784 exp_loc = c_parser_peek_token (parser)->location;
5785 op = c_parser_cast_expression (parser, NULL);
5786 op = default_function_array_conversion (exp_loc, op);
5787 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5789 c_parser_consume_token (parser);
5790 exp_loc = c_parser_peek_token (parser)->location;
5791 op = c_parser_cast_expression (parser, NULL);
5792 op = default_function_array_conversion (exp_loc, op);
5793 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5795 return c_parser_postfix_expression (parser);
5798 return c_parser_postfix_expression (parser);
5802 /* Parse a sizeof expression. */
5804 static struct c_expr
5805 c_parser_sizeof_expression (c_parser *parser)
5808 location_t expr_loc;
5809 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5810 c_parser_consume_token (parser);
5811 c_inhibit_evaluation_warnings++;
5813 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5814 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5816 /* Either sizeof ( type-name ) or sizeof unary-expression
5817 starting with a compound literal. */
5818 struct c_type_name *type_name;
5819 c_parser_consume_token (parser);
5820 expr_loc = c_parser_peek_token (parser)->location;
5821 type_name = c_parser_type_name (parser);
5822 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5823 if (type_name == NULL)
5826 c_inhibit_evaluation_warnings--;
5828 ret.value = error_mark_node;
5829 ret.original_code = ERROR_MARK;
5830 ret.original_type = NULL;
5833 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5835 expr = c_parser_postfix_expression_after_paren_type (parser,
5840 /* sizeof ( type-name ). */
5841 c_inhibit_evaluation_warnings--;
5843 return c_expr_sizeof_type (expr_loc, type_name);
5847 expr_loc = c_parser_peek_token (parser)->location;
5848 expr = c_parser_unary_expression (parser);
5850 c_inhibit_evaluation_warnings--;
5852 mark_exp_read (expr.value);
5853 if (TREE_CODE (expr.value) == COMPONENT_REF
5854 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5855 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5856 return c_expr_sizeof_expr (expr_loc, expr);
5860 /* Parse an alignof expression. */
5862 static struct c_expr
5863 c_parser_alignof_expression (c_parser *parser)
5866 location_t loc = c_parser_peek_token (parser)->location;
5867 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5868 c_parser_consume_token (parser);
5869 c_inhibit_evaluation_warnings++;
5871 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5872 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5874 /* Either __alignof__ ( type-name ) or __alignof__
5875 unary-expression starting with a compound literal. */
5877 struct c_type_name *type_name;
5879 c_parser_consume_token (parser);
5880 loc = c_parser_peek_token (parser)->location;
5881 type_name = c_parser_type_name (parser);
5882 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5883 if (type_name == NULL)
5886 c_inhibit_evaluation_warnings--;
5888 ret.value = error_mark_node;
5889 ret.original_code = ERROR_MARK;
5890 ret.original_type = NULL;
5893 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5895 expr = c_parser_postfix_expression_after_paren_type (parser,
5900 /* alignof ( type-name ). */
5901 c_inhibit_evaluation_warnings--;
5903 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5904 ret.original_code = ERROR_MARK;
5905 ret.original_type = NULL;
5911 expr = c_parser_unary_expression (parser);
5913 mark_exp_read (expr.value);
5914 c_inhibit_evaluation_warnings--;
5916 ret.value = c_alignof_expr (loc, expr.value);
5917 ret.original_code = ERROR_MARK;
5918 ret.original_type = NULL;
5923 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5927 postfix-expression [ expression ]
5928 postfix-expression ( argument-expression-list[opt] )
5929 postfix-expression . identifier
5930 postfix-expression -> identifier
5931 postfix-expression ++
5932 postfix-expression --
5933 ( type-name ) { initializer-list }
5934 ( type-name ) { initializer-list , }
5936 argument-expression-list:
5938 argument-expression-list , argument-expression
5950 (treated as a keyword in GNU C)
5953 ( compound-statement )
5954 __builtin_va_arg ( assignment-expression , type-name )
5955 __builtin_offsetof ( type-name , offsetof-member-designator )
5956 __builtin_choose_expr ( assignment-expression ,
5957 assignment-expression ,
5958 assignment-expression )
5959 __builtin_types_compatible_p ( type-name , type-name )
5961 offsetof-member-designator:
5963 offsetof-member-designator . identifier
5964 offsetof-member-designator [ expression ]
5969 [ objc-receiver objc-message-args ]
5970 @selector ( objc-selector-arg )
5971 @protocol ( identifier )
5972 @encode ( type-name )
5974 Classname . identifier
5977 static struct c_expr
5978 c_parser_postfix_expression (c_parser *parser)
5980 struct c_expr expr, e1, e2, e3;
5981 struct c_type_name *t1, *t2;
5982 location_t loc = c_parser_peek_token (parser)->location;;
5983 expr.original_code = ERROR_MARK;
5984 expr.original_type = NULL;
5985 switch (c_parser_peek_token (parser)->type)
5988 expr.value = c_parser_peek_token (parser)->value;
5989 loc = c_parser_peek_token (parser)->location;
5990 c_parser_consume_token (parser);
5991 if (TREE_CODE (expr.value) == FIXED_CST
5992 && !targetm.fixed_point_supported_p ())
5994 error_at (loc, "fixed-point types not supported for this target");
5995 expr.value = error_mark_node;
6002 expr.value = c_parser_peek_token (parser)->value;
6003 c_parser_consume_token (parser);
6009 case CPP_UTF8STRING:
6010 expr.value = c_parser_peek_token (parser)->value;
6011 expr.original_code = STRING_CST;
6012 c_parser_consume_token (parser);
6014 case CPP_OBJC_STRING:
6015 gcc_assert (c_dialect_objc ());
6017 = objc_build_string_object (c_parser_peek_token (parser)->value);
6018 c_parser_consume_token (parser);
6021 switch (c_parser_peek_token (parser)->id_kind)
6025 tree id = c_parser_peek_token (parser)->value;
6026 c_parser_consume_token (parser);
6027 expr.value = build_external_ref (loc, id,
6028 (c_parser_peek_token (parser)->type
6030 &expr.original_type);
6033 case C_ID_CLASSNAME:
6035 /* Here we parse the Objective-C 2.0 Class.name dot
6037 tree class_name = c_parser_peek_token (parser)->value;
6039 c_parser_consume_token (parser);
6040 gcc_assert (c_dialect_objc ());
6041 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6043 expr.value = error_mark_node;
6046 if (c_parser_next_token_is_not (parser, CPP_NAME))
6048 c_parser_error (parser, "expected identifier");
6049 expr.value = error_mark_node;
6052 component = c_parser_peek_token (parser)->value;
6053 c_parser_consume_token (parser);
6054 expr.value = objc_build_class_component_ref (class_name,
6059 c_parser_error (parser, "expected expression");
6060 expr.value = error_mark_node;
6064 case CPP_OPEN_PAREN:
6065 /* A parenthesized expression, statement expression or compound
6067 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6069 /* A statement expression. */
6071 location_t brace_loc;
6072 c_parser_consume_token (parser);
6073 brace_loc = c_parser_peek_token (parser)->location;
6074 c_parser_consume_token (parser);
6075 if (cur_stmt_list == NULL)
6077 error_at (loc, "braced-group within expression allowed "
6078 "only inside a function");
6079 parser->error = true;
6080 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6081 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6082 expr.value = error_mark_node;
6085 stmt = c_begin_stmt_expr ();
6086 c_parser_compound_statement_nostart (parser);
6087 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6089 pedwarn (loc, OPT_pedantic,
6090 "ISO C forbids braced-groups within expressions");
6091 expr.value = c_finish_stmt_expr (brace_loc, stmt);
6092 mark_exp_read (expr.value);
6094 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6096 /* A compound literal. ??? Can we actually get here rather
6097 than going directly to
6098 c_parser_postfix_expression_after_paren_type from
6101 struct c_type_name *type_name;
6102 c_parser_consume_token (parser);
6103 loc = c_parser_peek_token (parser)->location;
6104 type_name = c_parser_type_name (parser);
6105 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6107 if (type_name == NULL)
6109 expr.value = error_mark_node;
6112 expr = c_parser_postfix_expression_after_paren_type (parser,
6118 /* A parenthesized expression. */
6119 c_parser_consume_token (parser);
6120 expr = c_parser_expression (parser);
6121 if (TREE_CODE (expr.value) == MODIFY_EXPR)
6122 TREE_NO_WARNING (expr.value) = 1;
6123 if (expr.original_code != C_MAYBE_CONST_EXPR)
6124 expr.original_code = ERROR_MARK;
6125 /* Don't change EXPR.ORIGINAL_TYPE. */
6126 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6131 switch (c_parser_peek_token (parser)->keyword)
6133 case RID_FUNCTION_NAME:
6134 case RID_PRETTY_FUNCTION_NAME:
6135 case RID_C99_FUNCTION_NAME:
6136 expr.value = fname_decl (loc,
6137 c_parser_peek_token (parser)->keyword,
6138 c_parser_peek_token (parser)->value);
6139 c_parser_consume_token (parser);
6142 c_parser_consume_token (parser);
6143 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6145 expr.value = error_mark_node;
6148 e1 = c_parser_expr_no_commas (parser, NULL);
6149 mark_exp_read (e1.value);
6150 e1.value = c_fully_fold (e1.value, false, NULL);
6151 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6154 expr.value = error_mark_node;
6157 loc = c_parser_peek_token (parser)->location;
6158 t1 = c_parser_type_name (parser);
6159 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6163 expr.value = error_mark_node;
6167 tree type_expr = NULL_TREE;
6168 expr.value = c_build_va_arg (loc, e1.value,
6169 groktypename (t1, &type_expr, NULL));
6172 expr.value = build2 (C_MAYBE_CONST_EXPR,
6173 TREE_TYPE (expr.value), type_expr,
6175 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6180 c_parser_consume_token (parser);
6181 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6183 expr.value = error_mark_node;
6186 t1 = c_parser_type_name (parser);
6189 expr.value = error_mark_node;
6192 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6194 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6195 expr.value = error_mark_node;
6199 tree type = groktypename (t1, NULL, NULL);
6201 if (type == error_mark_node)
6202 offsetof_ref = error_mark_node;
6205 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6206 SET_EXPR_LOCATION (offsetof_ref, loc);
6208 /* Parse the second argument to __builtin_offsetof. We
6209 must have one identifier, and beyond that we want to
6210 accept sub structure and sub array references. */
6211 if (c_parser_next_token_is (parser, CPP_NAME))
6213 offsetof_ref = build_component_ref
6214 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6215 c_parser_consume_token (parser);
6216 while (c_parser_next_token_is (parser, CPP_DOT)
6217 || c_parser_next_token_is (parser,
6219 || c_parser_next_token_is (parser,
6222 if (c_parser_next_token_is (parser, CPP_DEREF))
6224 loc = c_parser_peek_token (parser)->location;
6225 offsetof_ref = build_array_ref (loc,
6230 else if (c_parser_next_token_is (parser, CPP_DOT))
6233 c_parser_consume_token (parser);
6234 if (c_parser_next_token_is_not (parser,
6237 c_parser_error (parser, "expected identifier");
6240 offsetof_ref = build_component_ref
6242 c_parser_peek_token (parser)->value);
6243 c_parser_consume_token (parser);
6248 loc = c_parser_peek_token (parser)->location;
6249 c_parser_consume_token (parser);
6250 idx = c_parser_expression (parser).value;
6251 idx = c_fully_fold (idx, false, NULL);
6252 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6254 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6259 c_parser_error (parser, "expected identifier");
6260 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6262 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6265 case RID_CHOOSE_EXPR:
6266 c_parser_consume_token (parser);
6267 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6269 expr.value = error_mark_node;
6272 loc = c_parser_peek_token (parser)->location;
6273 e1 = c_parser_expr_no_commas (parser, NULL);
6274 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6277 expr.value = error_mark_node;
6280 e2 = c_parser_expr_no_commas (parser, NULL);
6281 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6284 expr.value = error_mark_node;
6287 e3 = c_parser_expr_no_commas (parser, NULL);
6288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6294 mark_exp_read (e2.value);
6295 mark_exp_read (e3.value);
6296 if (TREE_CODE (c) != INTEGER_CST
6297 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6299 "first argument to %<__builtin_choose_expr%> not"
6301 constant_expression_warning (c);
6302 expr = integer_zerop (c) ? e3 : e2;
6305 case RID_TYPES_COMPATIBLE_P:
6306 c_parser_consume_token (parser);
6307 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6309 expr.value = error_mark_node;
6312 t1 = c_parser_type_name (parser);
6315 expr.value = error_mark_node;
6318 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6320 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6321 expr.value = error_mark_node;
6324 t2 = c_parser_type_name (parser);
6327 expr.value = error_mark_node;
6330 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6335 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6336 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6339 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6342 case RID_AT_SELECTOR:
6343 gcc_assert (c_dialect_objc ());
6344 c_parser_consume_token (parser);
6345 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6347 expr.value = error_mark_node;
6351 tree sel = c_parser_objc_selector_arg (parser);
6352 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6354 expr.value = objc_build_selector_expr (loc, sel);
6357 case RID_AT_PROTOCOL:
6358 gcc_assert (c_dialect_objc ());
6359 c_parser_consume_token (parser);
6360 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6362 expr.value = error_mark_node;
6365 if (c_parser_next_token_is_not (parser, CPP_NAME))
6367 c_parser_error (parser, "expected identifier");
6368 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6369 expr.value = error_mark_node;
6373 tree id = c_parser_peek_token (parser)->value;
6374 c_parser_consume_token (parser);
6375 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6377 expr.value = objc_build_protocol_expr (id);
6381 /* Extension to support C-structures in the archiver. */
6382 gcc_assert (c_dialect_objc ());
6383 c_parser_consume_token (parser);
6384 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6386 expr.value = error_mark_node;
6389 t1 = c_parser_type_name (parser);
6392 expr.value = error_mark_node;
6393 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6399 tree type = groktypename (t1, NULL, NULL);
6400 expr.value = objc_build_encode_expr (type);
6404 c_parser_error (parser, "expected expression");
6405 expr.value = error_mark_node;
6409 case CPP_OPEN_SQUARE:
6410 if (c_dialect_objc ())
6412 tree receiver, args;
6413 c_parser_consume_token (parser);
6414 receiver = c_parser_objc_receiver (parser);
6415 args = c_parser_objc_message_args (parser);
6416 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6418 expr.value = objc_build_message_expr (build_tree_list (receiver,
6422 /* Else fall through to report error. */
6424 c_parser_error (parser, "expected expression");
6425 expr.value = error_mark_node;
6428 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6431 /* Parse a postfix expression after a parenthesized type name: the
6432 brace-enclosed initializer of a compound literal, possibly followed
6433 by some postfix operators. This is separate because it is not
6434 possible to tell until after the type name whether a cast
6435 expression has a cast or a compound literal, or whether the operand
6436 of sizeof is a parenthesized type name or starts with a compound
6437 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6438 location of the first token after the parentheses around the type
6441 static struct c_expr
6442 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6443 struct c_type_name *type_name,
6444 location_t type_loc)
6450 location_t start_loc;
6451 tree type_expr = NULL_TREE;
6452 bool type_expr_const = true;
6453 check_compound_literal_type (type_loc, type_name);
6454 start_init (NULL_TREE, NULL, 0);
6455 type = groktypename (type_name, &type_expr, &type_expr_const);
6456 start_loc = c_parser_peek_token (parser)->location;
6457 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6459 error_at (type_loc, "compound literal has variable size");
6460 type = error_mark_node;
6462 init = c_parser_braced_init (parser, type, false);
6464 maybe_warn_string_init (type, init);
6466 if (type != error_mark_node
6467 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6468 && current_function_decl)
6470 error ("compound literal qualified by address-space qualifier");
6471 type = error_mark_node;
6475 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6476 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6477 ? CONSTRUCTOR_NON_CONST (init.value)
6478 : init.original_code == C_MAYBE_CONST_EXPR);
6479 non_const |= !type_expr_const;
6480 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6481 expr.original_code = ERROR_MARK;
6482 expr.original_type = NULL;
6485 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6487 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6488 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6492 gcc_assert (!non_const);
6493 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6494 type_expr, expr.value);
6497 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6500 /* Parse a postfix expression after the initial primary or compound
6501 literal; that is, parse a series of postfix operators.
6503 EXPR_LOC is the location of the primary expression. */
6505 static struct c_expr
6506 c_parser_postfix_expression_after_primary (c_parser *parser,
6507 location_t expr_loc,
6510 struct c_expr orig_expr;
6512 VEC(tree,gc) *exprlist;
6513 VEC(tree,gc) *origtypes;
6516 location_t op_loc = c_parser_peek_token (parser)->location;
6517 switch (c_parser_peek_token (parser)->type)
6519 case CPP_OPEN_SQUARE:
6520 /* Array reference. */
6521 c_parser_consume_token (parser);
6522 idx = c_parser_expression (parser).value;
6523 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6525 expr.value = build_array_ref (op_loc, expr.value, idx);
6526 expr.original_code = ERROR_MARK;
6527 expr.original_type = NULL;
6529 case CPP_OPEN_PAREN:
6530 /* Function call. */
6531 c_parser_consume_token (parser);
6532 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6535 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6536 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6539 mark_exp_read (expr.value);
6540 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6541 "(" after the FUNCNAME, which is what we have now. */
6542 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6544 expr.original_code = ERROR_MARK;
6545 if (TREE_CODE (expr.value) == INTEGER_CST
6546 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6547 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6548 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6549 expr.original_code = C_MAYBE_CONST_EXPR;
6550 expr.original_type = NULL;
6551 if (exprlist != NULL)
6553 release_tree_vector (exprlist);
6554 release_tree_vector (origtypes);
6558 /* Structure element reference. */
6559 c_parser_consume_token (parser);
6560 expr = default_function_array_conversion (expr_loc, expr);
6561 if (c_parser_next_token_is (parser, CPP_NAME))
6562 ident = c_parser_peek_token (parser)->value;
6565 c_parser_error (parser, "expected identifier");
6566 expr.value = error_mark_node;
6567 expr.original_code = ERROR_MARK;
6568 expr.original_type = NULL;
6571 c_parser_consume_token (parser);
6572 expr.value = build_component_ref (op_loc, expr.value, ident);
6573 expr.original_code = ERROR_MARK;
6574 if (TREE_CODE (expr.value) != COMPONENT_REF)
6575 expr.original_type = NULL;
6578 /* Remember the original type of a bitfield. */
6579 tree field = TREE_OPERAND (expr.value, 1);
6580 if (TREE_CODE (field) != FIELD_DECL)
6581 expr.original_type = NULL;
6583 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6587 /* Structure element reference. */
6588 c_parser_consume_token (parser);
6589 expr = default_function_array_conversion (expr_loc, expr);
6590 if (c_parser_next_token_is (parser, CPP_NAME))
6591 ident = c_parser_peek_token (parser)->value;
6594 c_parser_error (parser, "expected identifier");
6595 expr.value = error_mark_node;
6596 expr.original_code = ERROR_MARK;
6597 expr.original_type = NULL;
6600 c_parser_consume_token (parser);
6601 expr.value = build_component_ref (op_loc,
6602 build_indirect_ref (op_loc,
6606 expr.original_code = ERROR_MARK;
6607 if (TREE_CODE (expr.value) != COMPONENT_REF)
6608 expr.original_type = NULL;
6611 /* Remember the original type of a bitfield. */
6612 tree field = TREE_OPERAND (expr.value, 1);
6613 if (TREE_CODE (field) != FIELD_DECL)
6614 expr.original_type = NULL;
6616 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6620 /* Postincrement. */
6621 c_parser_consume_token (parser);
6622 expr = default_function_array_read_conversion (expr_loc, expr);
6623 expr.value = build_unary_op (op_loc,
6624 POSTINCREMENT_EXPR, expr.value, 0);
6625 expr.original_code = ERROR_MARK;
6626 expr.original_type = NULL;
6628 case CPP_MINUS_MINUS:
6629 /* Postdecrement. */
6630 c_parser_consume_token (parser);
6631 expr = default_function_array_read_conversion (expr_loc, expr);
6632 expr.value = build_unary_op (op_loc,
6633 POSTDECREMENT_EXPR, expr.value, 0);
6634 expr.original_code = ERROR_MARK;
6635 expr.original_type = NULL;
6643 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6646 assignment-expression
6647 expression , assignment-expression
6650 static struct c_expr
6651 c_parser_expression (c_parser *parser)
6654 expr = c_parser_expr_no_commas (parser, NULL);
6655 while (c_parser_next_token_is (parser, CPP_COMMA))
6659 location_t loc = c_parser_peek_token (parser)->location;
6660 location_t expr_loc;
6661 c_parser_consume_token (parser);
6662 expr_loc = c_parser_peek_token (parser)->location;
6663 lhsval = expr.value;
6664 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6665 lhsval = TREE_OPERAND (lhsval, 1);
6666 if (DECL_P (lhsval) || handled_component_p (lhsval))
6667 mark_exp_read (lhsval);
6668 next = c_parser_expr_no_commas (parser, NULL);
6669 next = default_function_array_conversion (expr_loc, next);
6670 expr.value = build_compound_expr (loc, expr.value, next.value);
6671 expr.original_code = COMPOUND_EXPR;
6672 expr.original_type = next.original_type;
6677 /* Parse an expression and convert functions or arrays to
6680 static struct c_expr
6681 c_parser_expression_conv (c_parser *parser)
6684 location_t loc = c_parser_peek_token (parser)->location;
6685 expr = c_parser_expression (parser);
6686 expr = default_function_array_conversion (loc, expr);
6690 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6691 functions and arrays to pointers. If FOLD_P, fold the expressions.
6694 assignment-expression
6695 nonempty-expr-list , assignment-expression
6698 static VEC(tree,gc) *
6699 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6700 VEC(tree,gc) **p_orig_types)
6703 VEC(tree,gc) *orig_types;
6705 location_t loc = c_parser_peek_token (parser)->location;
6707 ret = make_tree_vector ();
6708 if (p_orig_types == NULL)
6711 orig_types = make_tree_vector ();
6713 expr = c_parser_expr_no_commas (parser, NULL);
6715 expr = default_function_array_read_conversion (loc, expr);
6717 expr.value = c_fully_fold (expr.value, false, NULL);
6718 VEC_quick_push (tree, ret, expr.value);
6719 if (orig_types != NULL)
6720 VEC_quick_push (tree, orig_types, expr.original_type);
6721 while (c_parser_next_token_is (parser, CPP_COMMA))
6723 c_parser_consume_token (parser);
6724 loc = c_parser_peek_token (parser)->location;
6725 expr = c_parser_expr_no_commas (parser, NULL);
6727 expr = default_function_array_read_conversion (loc, expr);
6729 expr.value = c_fully_fold (expr.value, false, NULL);
6730 VEC_safe_push (tree, gc, ret, expr.value);
6731 if (orig_types != NULL)
6732 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6734 if (orig_types != NULL)
6735 *p_orig_types = orig_types;
6739 /* Parse Objective-C-specific constructs. */
6741 /* Parse an objc-class-definition.
6743 objc-class-definition:
6744 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6745 objc-class-instance-variables[opt] objc-methodprotolist @end
6746 @implementation identifier objc-superclass[opt]
6747 objc-class-instance-variables[opt]
6748 @interface identifier ( identifier ) objc-protocol-refs[opt]
6749 objc-methodprotolist @end
6750 @implementation identifier ( identifier )
6755 "@interface identifier (" must start "@interface identifier (
6756 identifier ) ...": objc-methodprotolist in the first production may
6757 not start with a parenthesized identifier as a declarator of a data
6758 definition with no declaration specifiers if the objc-superclass,
6759 objc-protocol-refs and objc-class-instance-variables are omitted. */
6762 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6767 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6769 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6774 c_parser_consume_token (parser);
6775 if (c_parser_next_token_is_not (parser, CPP_NAME))
6777 c_parser_error (parser, "expected identifier");
6780 id1 = c_parser_peek_token (parser)->value;
6781 c_parser_consume_token (parser);
6782 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6785 tree proto = NULL_TREE;
6786 c_parser_consume_token (parser);
6787 if (c_parser_next_token_is_not (parser, CPP_NAME))
6789 c_parser_error (parser, "expected identifier");
6790 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6793 id2 = c_parser_peek_token (parser)->value;
6794 c_parser_consume_token (parser);
6795 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6798 objc_start_category_implementation (id1, id2);
6801 if (c_parser_next_token_is (parser, CPP_LESS))
6802 proto = c_parser_objc_protocol_refs (parser);
6803 objc_start_category_interface (id1, id2, proto, attributes);
6804 c_parser_objc_methodprotolist (parser);
6805 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6806 objc_finish_interface ();
6809 if (c_parser_next_token_is (parser, CPP_COLON))
6811 c_parser_consume_token (parser);
6812 if (c_parser_next_token_is_not (parser, CPP_NAME))
6814 c_parser_error (parser, "expected identifier");
6817 superclass = c_parser_peek_token (parser)->value;
6818 c_parser_consume_token (parser);
6821 superclass = NULL_TREE;
6824 tree proto = NULL_TREE;
6825 if (c_parser_next_token_is (parser, CPP_LESS))
6826 proto = c_parser_objc_protocol_refs (parser);
6827 objc_start_class_interface (id1, superclass, proto, attributes);
6830 objc_start_class_implementation (id1, superclass);
6831 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6832 c_parser_objc_class_instance_variables (parser);
6835 objc_continue_interface ();
6836 c_parser_objc_methodprotolist (parser);
6837 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6838 objc_finish_interface ();
6842 objc_continue_implementation ();
6847 /* Parse objc-class-instance-variables.
6849 objc-class-instance-variables:
6850 { objc-instance-variable-decl-list[opt] }
6852 objc-instance-variable-decl-list:
6853 objc-visibility-spec
6854 objc-instance-variable-decl ;
6856 objc-instance-variable-decl-list objc-visibility-spec
6857 objc-instance-variable-decl-list objc-instance-variable-decl ;
6858 objc-instance-variable-decl-list ;
6860 objc-visibility-spec:
6865 objc-instance-variable-decl:
6870 c_parser_objc_class_instance_variables (c_parser *parser)
6872 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6873 c_parser_consume_token (parser);
6874 while (c_parser_next_token_is_not (parser, CPP_EOF))
6877 /* Parse any stray semicolon. */
6878 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6880 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6881 "extra semicolon in struct or union specified");
6882 c_parser_consume_token (parser);
6885 /* Stop if at the end of the instance variables. */
6886 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6888 c_parser_consume_token (parser);
6891 /* Parse any objc-visibility-spec. */
6892 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6894 c_parser_consume_token (parser);
6895 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6898 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6900 c_parser_consume_token (parser);
6901 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6904 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6906 c_parser_consume_token (parser);
6907 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6910 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6912 c_parser_consume_token (parser);
6913 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6916 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6918 c_parser_pragma (parser, pragma_external);
6922 /* Parse some comma-separated declarations. */
6923 decls = c_parser_struct_declaration (parser);
6925 /* Comma-separated instance variables are chained together in
6926 reverse order; add them one by one. */
6927 tree ivar = nreverse (decls);
6928 for (; ivar; ivar = DECL_CHAIN (ivar))
6929 objc_add_instance_variable (copy_node (ivar));
6931 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6935 /* Parse an objc-class-declaration.
6937 objc-class-declaration:
6938 @class identifier-list ;
6942 c_parser_objc_class_declaration (c_parser *parser)
6944 tree list = NULL_TREE;
6945 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6946 c_parser_consume_token (parser);
6947 /* Any identifiers, including those declared as type names, are OK
6952 if (c_parser_next_token_is_not (parser, CPP_NAME))
6954 c_parser_error (parser, "expected identifier");
6955 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6956 parser->error = false;
6959 id = c_parser_peek_token (parser)->value;
6960 list = chainon (list, build_tree_list (NULL_TREE, id));
6961 c_parser_consume_token (parser);
6962 if (c_parser_next_token_is (parser, CPP_COMMA))
6963 c_parser_consume_token (parser);
6967 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6968 objc_declare_class (list);
6971 /* Parse an objc-alias-declaration.
6973 objc-alias-declaration:
6974 @compatibility_alias identifier identifier ;
6978 c_parser_objc_alias_declaration (c_parser *parser)
6981 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6982 c_parser_consume_token (parser);
6983 if (c_parser_next_token_is_not (parser, CPP_NAME))
6985 c_parser_error (parser, "expected identifier");
6986 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6989 id1 = c_parser_peek_token (parser)->value;
6990 c_parser_consume_token (parser);
6991 if (c_parser_next_token_is_not (parser, CPP_NAME))
6993 c_parser_error (parser, "expected identifier");
6994 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6997 id2 = c_parser_peek_token (parser)->value;
6998 c_parser_consume_token (parser);
6999 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7000 objc_declare_alias (id1, id2);
7003 /* Parse an objc-protocol-definition.
7005 objc-protocol-definition:
7006 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7007 @protocol identifier-list ;
7009 "@protocol identifier ;" should be resolved as "@protocol
7010 identifier-list ;": objc-methodprotolist may not start with a
7011 semicolon in the first alternative if objc-protocol-refs are
7015 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7017 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7019 c_parser_consume_token (parser);
7020 if (c_parser_next_token_is_not (parser, CPP_NAME))
7022 c_parser_error (parser, "expected identifier");
7025 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7026 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7028 tree list = NULL_TREE;
7029 /* Any identifiers, including those declared as type names, are
7034 if (c_parser_next_token_is_not (parser, CPP_NAME))
7036 c_parser_error (parser, "expected identifier");
7039 id = c_parser_peek_token (parser)->value;
7040 list = chainon (list, build_tree_list (NULL_TREE, id));
7041 c_parser_consume_token (parser);
7042 if (c_parser_next_token_is (parser, CPP_COMMA))
7043 c_parser_consume_token (parser);
7047 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7048 objc_declare_protocols (list, attributes);
7052 tree id = c_parser_peek_token (parser)->value;
7053 tree proto = NULL_TREE;
7054 c_parser_consume_token (parser);
7055 if (c_parser_next_token_is (parser, CPP_LESS))
7056 proto = c_parser_objc_protocol_refs (parser);
7057 parser->objc_pq_context = true;
7058 objc_start_protocol (id, proto, attributes);
7059 c_parser_objc_methodprotolist (parser);
7060 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7061 parser->objc_pq_context = false;
7062 objc_finish_interface ();
7066 /* Parse an objc-method-type.
7072 Return true if it is a class method (+) and false if it is
7073 an instance method (-).
7076 c_parser_objc_method_type (c_parser *parser)
7078 switch (c_parser_peek_token (parser)->type)
7081 c_parser_consume_token (parser);
7084 c_parser_consume_token (parser);
7091 /* Parse an objc-method-definition.
7093 objc-method-definition:
7094 objc-method-type objc-method-decl ;[opt] compound-statement
7098 c_parser_objc_method_definition (c_parser *parser)
7100 bool is_class_method = c_parser_objc_method_type (parser);
7101 tree decl, attributes = NULL_TREE;
7102 parser->objc_pq_context = true;
7103 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7104 if (decl == error_mark_node)
7105 return; /* Bail here. */
7107 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7109 c_parser_consume_token (parser);
7110 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7111 "extra semicolon in method definition specified");
7114 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7116 c_parser_error (parser, "expected %<{%>");
7120 parser->objc_pq_context = false;
7121 if (objc_start_method_definition (is_class_method, decl, attributes))
7123 add_stmt (c_parser_compound_statement (parser));
7124 objc_finish_method_definition (current_function_decl);
7128 /* This code is executed when we find a method definition
7129 outside of an @implementation context (or invalid for other
7130 reasons). Parse the method (to keep going) but do not emit
7133 c_parser_compound_statement (parser);
7137 /* Parse an objc-methodprotolist.
7139 objc-methodprotolist:
7141 objc-methodprotolist objc-methodproto
7142 objc-methodprotolist declaration
7143 objc-methodprotolist ;
7147 The declaration is a data definition, which may be missing
7148 declaration specifiers under the same rules and diagnostics as
7149 other data definitions outside functions, and the stray semicolon
7150 is diagnosed the same way as a stray semicolon outside a
7154 c_parser_objc_methodprotolist (c_parser *parser)
7158 /* The list is terminated by @end. */
7159 switch (c_parser_peek_token (parser)->type)
7162 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7163 "ISO C does not allow extra %<;%> outside of a function");
7164 c_parser_consume_token (parser);
7168 c_parser_objc_methodproto (parser);
7171 c_parser_pragma (parser, pragma_external);
7176 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7178 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7179 c_parser_objc_at_property_declaration (parser);
7180 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7182 objc_set_method_opt (true);
7183 c_parser_consume_token (parser);
7185 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7187 objc_set_method_opt (false);
7188 c_parser_consume_token (parser);
7191 c_parser_declaration_or_fndef (parser, false, false, true,
7198 /* Parse an objc-methodproto.
7201 objc-method-type objc-method-decl ;
7205 c_parser_objc_methodproto (c_parser *parser)
7207 bool is_class_method = c_parser_objc_method_type (parser);
7208 tree decl, attributes = NULL_TREE;
7210 /* Remember protocol qualifiers in prototypes. */
7211 parser->objc_pq_context = true;
7212 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7213 /* Forget protocol qualifiers now. */
7214 parser->objc_pq_context = false;
7216 /* Do not allow the presence of attributes to hide an erroneous
7217 method implementation in the interface section. */
7218 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7220 c_parser_error (parser, "expected %<;%>");
7224 if (decl != error_mark_node)
7225 objc_add_method_declaration (is_class_method, decl, attributes);
7227 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7230 /* If we are at a position that method attributes may be present, check that
7231 there are not any parsed already (a syntax error) and then collect any
7232 specified at the current location. Finally, if new attributes were present,
7233 check that the next token is legal ( ';' for decls and '{' for defs). */
7236 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7241 c_parser_error (parser,
7242 "method attributes must be specified at the end only");
7243 *attributes = NULL_TREE;
7247 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7248 *attributes = c_parser_attributes (parser);
7250 /* If there were no attributes here, just report any earlier error. */
7251 if (*attributes == NULL_TREE || bad)
7254 /* If the attributes are followed by a ; or {, then just report any earlier
7256 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7257 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7260 /* We've got attributes, but not at the end. */
7261 c_parser_error (parser,
7262 "expected %<;%> or %<{%> after method attribute definition");
7266 /* Parse an objc-method-decl.
7269 ( objc-type-name ) objc-selector
7271 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7272 objc-keyword-selector objc-optparmlist
7275 objc-keyword-selector:
7277 objc-keyword-selector objc-keyword-decl
7280 objc-selector : ( objc-type-name ) identifier
7281 objc-selector : identifier
7282 : ( objc-type-name ) identifier
7286 objc-optparms objc-optellipsis
7290 objc-opt-parms , parameter-declaration
7298 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7300 tree type = NULL_TREE;
7302 tree parms = NULL_TREE;
7303 bool ellipsis = false;
7304 bool attr_err = false;
7306 *attributes = NULL_TREE;
7307 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7309 c_parser_consume_token (parser);
7310 type = c_parser_objc_type_name (parser);
7311 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7313 sel = c_parser_objc_selector (parser);
7314 /* If there is no selector, or a colon follows, we have an
7315 objc-keyword-selector. If there is a selector, and a colon does
7316 not follow, that selector ends the objc-method-decl. */
7317 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7320 tree list = NULL_TREE;
7323 tree atype = NULL_TREE, id, keyworddecl;
7324 tree param_attr = NULL_TREE;
7325 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7327 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7329 c_parser_consume_token (parser);
7330 atype = c_parser_objc_type_name (parser);
7331 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7334 /* New ObjC allows attributes on method parameters. */
7335 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7336 param_attr = c_parser_attributes (parser);
7337 if (c_parser_next_token_is_not (parser, CPP_NAME))
7339 c_parser_error (parser, "expected identifier");
7340 return error_mark_node;
7342 id = c_parser_peek_token (parser)->value;
7343 c_parser_consume_token (parser);
7344 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7345 list = chainon (list, keyworddecl);
7346 tsel = c_parser_objc_selector (parser);
7347 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7351 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7353 /* Parse the optional parameter list. Optional Objective-C
7354 method parameters follow the C syntax, and may include '...'
7355 to denote a variable number of arguments. */
7356 parms = make_node (TREE_LIST);
7357 while (c_parser_next_token_is (parser, CPP_COMMA))
7359 struct c_parm *parm;
7360 c_parser_consume_token (parser);
7361 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7364 c_parser_consume_token (parser);
7365 attr_err |= c_parser_objc_maybe_method_attributes
7366 (parser, attributes) ;
7369 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7372 parms = chainon (parms,
7373 build_tree_list (NULL_TREE, grokparm (parm)));
7378 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7382 c_parser_error (parser, "objective-c method declaration is expected");
7383 return error_mark_node;
7387 return error_mark_node;
7389 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7392 /* Parse an objc-type-name.
7395 objc-type-qualifiers[opt] type-name
7396 objc-type-qualifiers[opt]
7398 objc-type-qualifiers:
7400 objc-type-qualifiers objc-type-qualifier
7402 objc-type-qualifier: one of
7403 in out inout bycopy byref oneway
7407 c_parser_objc_type_name (c_parser *parser)
7409 tree quals = NULL_TREE;
7410 struct c_type_name *type_name = NULL;
7411 tree type = NULL_TREE;
7414 c_token *token = c_parser_peek_token (parser);
7415 if (token->type == CPP_KEYWORD
7416 && (token->keyword == RID_IN
7417 || token->keyword == RID_OUT
7418 || token->keyword == RID_INOUT
7419 || token->keyword == RID_BYCOPY
7420 || token->keyword == RID_BYREF
7421 || token->keyword == RID_ONEWAY))
7423 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7424 c_parser_consume_token (parser);
7429 if (c_parser_next_token_starts_typename (parser))
7430 type_name = c_parser_type_name (parser);
7432 type = groktypename (type_name, NULL, NULL);
7433 return build_tree_list (quals, type);
7436 /* Parse objc-protocol-refs.
7443 c_parser_objc_protocol_refs (c_parser *parser)
7445 tree list = NULL_TREE;
7446 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7447 c_parser_consume_token (parser);
7448 /* Any identifiers, including those declared as type names, are OK
7453 if (c_parser_next_token_is_not (parser, CPP_NAME))
7455 c_parser_error (parser, "expected identifier");
7458 id = c_parser_peek_token (parser)->value;
7459 list = chainon (list, build_tree_list (NULL_TREE, id));
7460 c_parser_consume_token (parser);
7461 if (c_parser_next_token_is (parser, CPP_COMMA))
7462 c_parser_consume_token (parser);
7466 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7470 /* Parse an objc-try-catch-finally-statement.
7472 objc-try-catch-finally-statement:
7473 @try compound-statement objc-catch-list[opt]
7474 @try compound-statement objc-catch-list[opt] @finally compound-statement
7477 @catch ( objc-catch-parameter-declaration ) compound-statement
7478 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7480 objc-catch-parameter-declaration:
7481 parameter-declaration
7484 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7486 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7487 for C++. Keep them in sync. */
7490 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7492 location_t location;
7495 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7496 c_parser_consume_token (parser);
7497 location = c_parser_peek_token (parser)->location;
7498 stmt = c_parser_compound_statement (parser);
7499 objc_begin_try_stmt (location, stmt);
7501 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7503 struct c_parm *parm;
7504 tree parameter_declaration = error_mark_node;
7505 bool seen_open_paren = false;
7507 c_parser_consume_token (parser);
7508 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7509 seen_open_paren = true;
7510 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7512 /* We have "@catch (...)" (where the '...' are literally
7513 what is in the code). Skip the '...'.
7514 parameter_declaration is set to NULL_TREE, and
7515 objc_being_catch_clauses() knows that that means
7517 c_parser_consume_token (parser);
7518 parameter_declaration = NULL_TREE;
7522 /* We have "@catch (NSException *exception)" or something
7523 like that. Parse the parameter declaration. */
7524 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7526 parameter_declaration = error_mark_node;
7528 parameter_declaration = grokparm (parm);
7530 if (seen_open_paren)
7531 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7534 /* If there was no open parenthesis, we are recovering from
7535 an error, and we are trying to figure out what mistake
7536 the user has made. */
7538 /* If there is an immediate closing parenthesis, the user
7539 probably forgot the opening one (ie, they typed "@catch
7540 NSException *e)". Parse the closing parenthesis and keep
7542 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7543 c_parser_consume_token (parser);
7545 /* If these is no immediate closing parenthesis, the user
7546 probably doesn't know that parenthesis are required at
7547 all (ie, they typed "@catch NSException *e"). So, just
7548 forget about the closing parenthesis and keep going. */
7550 objc_begin_catch_clause (parameter_declaration);
7551 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7552 c_parser_compound_statement_nostart (parser);
7553 objc_finish_catch_clause ();
7555 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7557 c_parser_consume_token (parser);
7558 location = c_parser_peek_token (parser)->location;
7559 stmt = c_parser_compound_statement (parser);
7560 objc_build_finally_clause (location, stmt);
7562 objc_finish_try_stmt ();
7565 /* Parse an objc-synchronized-statement.
7567 objc-synchronized-statement:
7568 @synchronized ( expression ) compound-statement
7572 c_parser_objc_synchronized_statement (c_parser *parser)
7576 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7577 c_parser_consume_token (parser);
7578 loc = c_parser_peek_token (parser)->location;
7579 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7581 expr = c_parser_expression (parser).value;
7582 expr = c_fully_fold (expr, false, NULL);
7583 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7586 expr = error_mark_node;
7587 stmt = c_parser_compound_statement (parser);
7588 objc_build_synchronized (loc, expr, stmt);
7591 /* Parse an objc-selector; return NULL_TREE without an error if the
7592 next token is not an objc-selector.
7597 enum struct union if else while do for switch case default
7598 break continue return goto asm sizeof typeof __alignof
7599 unsigned long const short volatile signed restrict _Complex
7600 in out inout bycopy byref oneway int char float double void _Bool
7602 ??? Why this selection of keywords but not, for example, storage
7603 class specifiers? */
7606 c_parser_objc_selector (c_parser *parser)
7608 c_token *token = c_parser_peek_token (parser);
7609 tree value = token->value;
7610 if (token->type == CPP_NAME)
7612 c_parser_consume_token (parser);
7615 if (token->type != CPP_KEYWORD)
7617 switch (token->keyword)
7659 c_parser_consume_token (parser);
7666 /* Parse an objc-selector-arg.
7670 objc-keywordname-list
7672 objc-keywordname-list:
7674 objc-keywordname-list objc-keywordname
7682 c_parser_objc_selector_arg (c_parser *parser)
7684 tree sel = c_parser_objc_selector (parser);
7685 tree list = NULL_TREE;
7686 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7690 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7692 list = chainon (list, build_tree_list (sel, NULL_TREE));
7693 sel = c_parser_objc_selector (parser);
7694 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7700 /* Parse an objc-receiver.
7709 c_parser_objc_receiver (c_parser *parser)
7711 if (c_parser_peek_token (parser)->type == CPP_NAME
7712 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7713 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7715 tree id = c_parser_peek_token (parser)->value;
7716 c_parser_consume_token (parser);
7717 return objc_get_class_reference (id);
7719 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7722 /* Parse objc-message-args.
7726 objc-keywordarg-list
7728 objc-keywordarg-list:
7730 objc-keywordarg-list objc-keywordarg
7733 objc-selector : objc-keywordexpr
7738 c_parser_objc_message_args (c_parser *parser)
7740 tree sel = c_parser_objc_selector (parser);
7741 tree list = NULL_TREE;
7742 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7747 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7748 return error_mark_node;
7749 keywordexpr = c_parser_objc_keywordexpr (parser);
7750 list = chainon (list, build_tree_list (sel, keywordexpr));
7751 sel = c_parser_objc_selector (parser);
7752 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7758 /* Parse an objc-keywordexpr.
7765 c_parser_objc_keywordexpr (c_parser *parser)
7768 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7769 if (VEC_length (tree, expr_list) == 1)
7771 /* Just return the expression, remove a level of
7773 ret = VEC_index (tree, expr_list, 0);
7777 /* We have a comma expression, we will collapse later. */
7778 ret = build_tree_list_vec (expr_list);
7780 release_tree_vector (expr_list);
7784 /* A check, needed in several places, that ObjC interface, implementation or
7785 method definitions are not prefixed by incorrect items. */
7787 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7788 struct c_declspecs *specs)
7790 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7791 || specs->typespec_kind != ctsk_none)
7793 c_parser_error (parser,
7794 "no type or storage class may be specified here,");
7795 c_parser_skip_to_end_of_block_or_statement (parser);
7801 /* Parse an Objective-C @property declaration. The syntax is:
7803 objc-property-declaration:
7804 '@property' objc-property-attributes[opt] struct-declaration ;
7806 objc-property-attributes:
7807 '(' objc-property-attribute-list ')'
7809 objc-property-attribute-list:
7810 objc-property-attribute
7811 objc-property-attribute-list, objc-property-attribute
7813 objc-property-attribute
7814 'getter' = identifier
7815 'setter' = identifier
7824 @property NSString *name;
7825 @property (readonly) id object;
7826 @property (retain, nonatomic, getter=getTheName) id name;
7827 @property int a, b, c;
7829 PS: This function is identical to cp_parser_objc_at_propery_declaration
7830 for C++. Keep them in sync. */
7832 c_parser_objc_at_property_declaration (c_parser *parser)
7834 /* The following variables hold the attributes of the properties as
7835 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7836 seen. When we see an attribute, we set them to 'true' (if they
7837 are boolean properties) or to the identifier (if they have an
7838 argument, ie, for getter and setter). Note that here we only
7839 parse the list of attributes, check the syntax and accumulate the
7840 attributes that we find. objc_add_property_declaration() will
7841 then process the information. */
7842 bool property_assign = false;
7843 bool property_copy = false;
7844 tree property_getter_ident = NULL_TREE;
7845 bool property_nonatomic = false;
7846 bool property_readonly = false;
7847 bool property_readwrite = false;
7848 bool property_retain = false;
7849 tree property_setter_ident = NULL_TREE;
7851 /* 'properties' is the list of properties that we read. Usually a
7852 single one, but maybe more (eg, in "@property int a, b, c;" there
7857 loc = c_parser_peek_token (parser)->location;
7858 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7860 c_parser_consume_token (parser); /* Eat '@property'. */
7862 /* Parse the optional attribute list... */
7863 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7866 c_parser_consume_token (parser);
7868 /* Property attribute keywords are valid now. */
7869 parser->objc_property_attr_context = true;
7873 bool syntax_error = false;
7874 c_token *token = c_parser_peek_token (parser);
7877 if (token->type != CPP_KEYWORD)
7879 if (token->type == CPP_CLOSE_PAREN)
7880 c_parser_error (parser, "expected identifier");
7883 c_parser_consume_token (parser);
7884 c_parser_error (parser, "unknown property attribute");
7888 keyword = token->keyword;
7889 c_parser_consume_token (parser);
7892 case RID_ASSIGN: property_assign = true; break;
7893 case RID_COPY: property_copy = true; break;
7894 case RID_NONATOMIC: property_nonatomic = true; break;
7895 case RID_READONLY: property_readonly = true; break;
7896 case RID_READWRITE: property_readwrite = true; break;
7897 case RID_RETAIN: property_retain = true; break;
7901 if (c_parser_next_token_is_not (parser, CPP_EQ))
7903 c_parser_error (parser,
7904 "getter/setter attribute must be followed by %<=%>");
7905 syntax_error = true;
7908 c_parser_consume_token (parser); /* eat the = */
7909 if (c_parser_next_token_is_not (parser, CPP_NAME))
7911 c_parser_error (parser, "expected identifier");
7912 syntax_error = true;
7915 if (keyword == RID_SETTER)
7917 if (property_setter_ident != NULL_TREE)
7918 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7920 property_setter_ident = c_parser_peek_token (parser)->value;
7921 c_parser_consume_token (parser);
7922 if (c_parser_next_token_is_not (parser, CPP_COLON))
7923 c_parser_error (parser, "setter name must terminate with %<:%>");
7925 c_parser_consume_token (parser);
7929 if (property_getter_ident != NULL_TREE)
7930 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7932 property_getter_ident = c_parser_peek_token (parser)->value;
7933 c_parser_consume_token (parser);
7937 c_parser_error (parser, "unknown property attribute");
7938 syntax_error = true;
7945 if (c_parser_next_token_is (parser, CPP_COMMA))
7946 c_parser_consume_token (parser);
7950 parser->objc_property_attr_context = false;
7951 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7953 /* ... and the property declaration(s). */
7954 properties = c_parser_struct_declaration (parser);
7956 if (properties == error_mark_node)
7958 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7959 parser->error = false;
7963 if (properties == NULL_TREE)
7964 c_parser_error (parser, "expected identifier");
7967 /* Comma-separated properties are chained together in
7968 reverse order; add them one by one. */
7969 properties = nreverse (properties);
7971 for (; properties; properties = TREE_CHAIN (properties))
7972 objc_add_property_declaration (loc, copy_node (properties),
7973 property_readonly, property_readwrite,
7974 property_assign, property_retain,
7975 property_copy, property_nonatomic,
7976 property_getter_ident, property_setter_ident);
7979 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7980 parser->error = false;
7983 /* Parse an Objective-C @synthesize declaration. The syntax is:
7985 objc-synthesize-declaration:
7986 @synthesize objc-synthesize-identifier-list ;
7988 objc-synthesize-identifier-list:
7989 objc-synthesize-identifier
7990 objc-synthesize-identifier-list, objc-synthesize-identifier
7992 objc-synthesize-identifier
7994 identifier = identifier
7997 @synthesize MyProperty;
7998 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8000 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8001 for C++. Keep them in sync.
8004 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8006 tree list = NULL_TREE;
8008 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8009 loc = c_parser_peek_token (parser)->location;
8011 c_parser_consume_token (parser);
8014 tree property, ivar;
8015 if (c_parser_next_token_is_not (parser, CPP_NAME))
8017 c_parser_error (parser, "expected identifier");
8018 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8019 /* Once we find the semicolon, we can resume normal parsing.
8020 We have to reset parser->error manually because
8021 c_parser_skip_until_found() won't reset it for us if the
8022 next token is precisely a semicolon. */
8023 parser->error = false;
8026 property = c_parser_peek_token (parser)->value;
8027 c_parser_consume_token (parser);
8028 if (c_parser_next_token_is (parser, CPP_EQ))
8030 c_parser_consume_token (parser);
8031 if (c_parser_next_token_is_not (parser, CPP_NAME))
8033 c_parser_error (parser, "expected identifier");
8034 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8035 parser->error = false;
8038 ivar = c_parser_peek_token (parser)->value;
8039 c_parser_consume_token (parser);
8043 list = chainon (list, build_tree_list (ivar, property));
8044 if (c_parser_next_token_is (parser, CPP_COMMA))
8045 c_parser_consume_token (parser);
8049 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8050 objc_add_synthesize_declaration (loc, list);
8053 /* Parse an Objective-C @dynamic declaration. The syntax is:
8055 objc-dynamic-declaration:
8056 @dynamic identifier-list ;
8059 @dynamic MyProperty;
8060 @dynamic MyProperty, AnotherProperty;
8062 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8063 for C++. Keep them in sync.
8066 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8068 tree list = NULL_TREE;
8070 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8071 loc = c_parser_peek_token (parser)->location;
8073 c_parser_consume_token (parser);
8077 if (c_parser_next_token_is_not (parser, CPP_NAME))
8079 c_parser_error (parser, "expected identifier");
8080 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8081 parser->error = false;
8084 property = c_parser_peek_token (parser)->value;
8085 list = chainon (list, build_tree_list (NULL_TREE, property));
8086 c_parser_consume_token (parser);
8087 if (c_parser_next_token_is (parser, CPP_COMMA))
8088 c_parser_consume_token (parser);
8092 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8093 objc_add_dynamic_declaration (loc, list);
8097 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8098 should be considered, statements. ALLOW_STMT is true if we're within
8099 the context of a function and such pragmas are to be allowed. Returns
8100 true if we actually parsed such a pragma. */
8103 c_parser_pragma (c_parser *parser, enum pragma_context context)
8107 id = c_parser_peek_token (parser)->pragma_kind;
8108 gcc_assert (id != PRAGMA_NONE);
8112 case PRAGMA_OMP_BARRIER:
8113 if (context != pragma_compound)
8115 if (context == pragma_stmt)
8116 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8117 "used in compound statements");
8120 c_parser_omp_barrier (parser);
8123 case PRAGMA_OMP_FLUSH:
8124 if (context != pragma_compound)
8126 if (context == pragma_stmt)
8127 c_parser_error (parser, "%<#pragma omp flush%> may only be "
8128 "used in compound statements");
8131 c_parser_omp_flush (parser);
8134 case PRAGMA_OMP_TASKWAIT:
8135 if (context != pragma_compound)
8137 if (context == pragma_stmt)
8138 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8139 "used in compound statements");
8142 c_parser_omp_taskwait (parser);
8145 case PRAGMA_OMP_THREADPRIVATE:
8146 c_parser_omp_threadprivate (parser);
8149 case PRAGMA_OMP_SECTION:
8150 error_at (c_parser_peek_token (parser)->location,
8151 "%<#pragma omp section%> may only be used in "
8152 "%<#pragma omp sections%> construct");
8153 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8156 case PRAGMA_GCC_PCH_PREPROCESS:
8157 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8158 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8162 if (id < PRAGMA_FIRST_EXTERNAL)
8164 if (context == pragma_external)
8167 c_parser_error (parser, "expected declaration specifiers");
8168 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8171 c_parser_omp_construct (parser);
8177 c_parser_consume_pragma (parser);
8178 c_invoke_pragma_handler (id);
8180 /* Skip to EOL, but suppress any error message. Those will have been
8181 generated by the handler routine through calling error, as opposed
8182 to calling c_parser_error. */
8183 parser->error = true;
8184 c_parser_skip_to_pragma_eol (parser);
8189 /* The interface the pragma parsers have to the lexer. */
8192 pragma_lex (tree *value)
8194 c_token *tok = c_parser_peek_token (the_parser);
8195 enum cpp_ttype ret = tok->type;
8197 *value = tok->value;
8198 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8202 if (ret == CPP_KEYWORD)
8204 c_parser_consume_token (the_parser);
8211 c_parser_pragma_pch_preprocess (c_parser *parser)
8215 c_parser_consume_pragma (parser);
8216 if (c_parser_next_token_is (parser, CPP_STRING))
8218 name = c_parser_peek_token (parser)->value;
8219 c_parser_consume_token (parser);
8222 c_parser_error (parser, "expected string literal");
8223 c_parser_skip_to_pragma_eol (parser);
8226 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8229 /* OpenMP 2.5 parsing routines. */
8231 /* Returns name of the next clause.
8232 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8233 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8234 returned and the token is consumed. */
8236 static pragma_omp_clause
8237 c_parser_omp_clause_name (c_parser *parser)
8239 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8241 if (c_parser_next_token_is_keyword (parser, RID_IF))
8242 result = PRAGMA_OMP_CLAUSE_IF;
8243 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8244 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8245 else if (c_parser_next_token_is (parser, CPP_NAME))
8247 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8252 if (!strcmp ("collapse", p))
8253 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8254 else if (!strcmp ("copyin", p))
8255 result = PRAGMA_OMP_CLAUSE_COPYIN;
8256 else if (!strcmp ("copyprivate", p))
8257 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8260 if (!strcmp ("firstprivate", p))
8261 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8264 if (!strcmp ("lastprivate", p))
8265 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8268 if (!strcmp ("nowait", p))
8269 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8270 else if (!strcmp ("num_threads", p))
8271 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8274 if (!strcmp ("ordered", p))
8275 result = PRAGMA_OMP_CLAUSE_ORDERED;
8278 if (!strcmp ("private", p))
8279 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8282 if (!strcmp ("reduction", p))
8283 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8286 if (!strcmp ("schedule", p))
8287 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8288 else if (!strcmp ("shared", p))
8289 result = PRAGMA_OMP_CLAUSE_SHARED;
8292 if (!strcmp ("untied", p))
8293 result = PRAGMA_OMP_CLAUSE_UNTIED;
8298 if (result != PRAGMA_OMP_CLAUSE_NONE)
8299 c_parser_consume_token (parser);
8304 /* Validate that a clause of the given type does not already exist. */
8307 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8312 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8313 if (OMP_CLAUSE_CODE (c) == code)
8315 location_t loc = OMP_CLAUSE_LOCATION (c);
8316 error_at (loc, "too many %qs clauses", name);
8324 variable-list , identifier
8326 If KIND is nonzero, create the appropriate node and install the
8327 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8328 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8330 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8331 return the list created. */
8334 c_parser_omp_variable_list (c_parser *parser,
8335 location_t clause_loc,
8336 enum omp_clause_code kind,
8339 if (c_parser_next_token_is_not (parser, CPP_NAME)
8340 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8341 c_parser_error (parser, "expected identifier");
8343 while (c_parser_next_token_is (parser, CPP_NAME)
8344 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8346 tree t = lookup_name (c_parser_peek_token (parser)->value);
8349 undeclared_variable (c_parser_peek_token (parser)->location,
8350 c_parser_peek_token (parser)->value);
8351 else if (t == error_mark_node)
8355 tree u = build_omp_clause (clause_loc, kind);
8356 OMP_CLAUSE_DECL (u) = t;
8357 OMP_CLAUSE_CHAIN (u) = list;
8361 list = tree_cons (t, NULL_TREE, list);
8363 c_parser_consume_token (parser);
8365 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8368 c_parser_consume_token (parser);
8374 /* Similarly, but expect leading and trailing parenthesis. This is a very
8375 common case for omp clauses. */
8378 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8381 /* The clauses location. */
8382 location_t loc = c_parser_peek_token (parser)->location;
8384 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8386 list = c_parser_omp_variable_list (parser, loc, kind, list);
8387 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8393 collapse ( constant-expression ) */
8396 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8398 tree c, num = error_mark_node;
8402 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8404 loc = c_parser_peek_token (parser)->location;
8405 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8407 num = c_parser_expr_no_commas (parser, NULL).value;
8408 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8410 if (num == error_mark_node)
8412 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8413 || !host_integerp (num, 0)
8414 || (n = tree_low_cst (num, 0)) <= 0
8418 "collapse argument needs positive constant integer expression");
8421 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8422 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8423 OMP_CLAUSE_CHAIN (c) = list;
8428 copyin ( variable-list ) */
8431 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8433 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8437 copyprivate ( variable-list ) */
8440 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8442 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8446 default ( shared | none ) */
8449 c_parser_omp_clause_default (c_parser *parser, tree list)
8451 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8452 location_t loc = c_parser_peek_token (parser)->location;
8455 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8457 if (c_parser_next_token_is (parser, CPP_NAME))
8459 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8464 if (strcmp ("none", p) != 0)
8466 kind = OMP_CLAUSE_DEFAULT_NONE;
8470 if (strcmp ("shared", p) != 0)
8472 kind = OMP_CLAUSE_DEFAULT_SHARED;
8479 c_parser_consume_token (parser);
8484 c_parser_error (parser, "expected %<none%> or %<shared%>");
8486 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8488 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8491 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8492 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8493 OMP_CLAUSE_CHAIN (c) = list;
8494 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8500 firstprivate ( variable-list ) */
8503 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8505 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8509 if ( expression ) */
8512 c_parser_omp_clause_if (c_parser *parser, tree list)
8514 location_t loc = c_parser_peek_token (parser)->location;
8515 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8517 tree t = c_parser_paren_condition (parser);
8520 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8522 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8523 OMP_CLAUSE_IF_EXPR (c) = t;
8524 OMP_CLAUSE_CHAIN (c) = list;
8528 c_parser_error (parser, "expected %<(%>");
8534 lastprivate ( variable-list ) */
8537 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8539 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8546 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8549 location_t loc = c_parser_peek_token (parser)->location;
8551 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8553 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8554 OMP_CLAUSE_CHAIN (c) = list;
8559 num_threads ( expression ) */
8562 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8564 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8565 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8567 location_t expr_loc = c_parser_peek_token (parser)->location;
8568 tree c, t = c_parser_expression (parser).value;
8569 t = c_fully_fold (t, false, NULL);
8571 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8573 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8575 c_parser_error (parser, "expected integer expression");
8579 /* Attempt to statically determine when the number isn't positive. */
8580 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8581 build_int_cst (TREE_TYPE (t), 0));
8582 if (CAN_HAVE_LOCATION_P (c))
8583 SET_EXPR_LOCATION (c, expr_loc);
8584 if (c == boolean_true_node)
8586 warning_at (expr_loc, 0,
8587 "%<num_threads%> value must be positive");
8588 t = integer_one_node;
8591 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8593 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8594 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8595 OMP_CLAUSE_CHAIN (c) = list;
8606 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8610 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8612 c = build_omp_clause (c_parser_peek_token (parser)->location,
8613 OMP_CLAUSE_ORDERED);
8614 OMP_CLAUSE_CHAIN (c) = list;
8620 private ( variable-list ) */
8623 c_parser_omp_clause_private (c_parser *parser, tree list)
8625 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8629 reduction ( reduction-operator : variable-list )
8632 One of: + * - & ^ | && || */
8635 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8637 location_t clause_loc = c_parser_peek_token (parser)->location;
8638 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8640 enum tree_code code;
8642 switch (c_parser_peek_token (parser)->type)
8654 code = BIT_AND_EXPR;
8657 code = BIT_XOR_EXPR;
8660 code = BIT_IOR_EXPR;
8663 code = TRUTH_ANDIF_EXPR;
8666 code = TRUTH_ORIF_EXPR;
8669 c_parser_error (parser,
8670 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8671 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8672 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8675 c_parser_consume_token (parser);
8676 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8680 nl = c_parser_omp_variable_list (parser, clause_loc,
8681 OMP_CLAUSE_REDUCTION, list);
8682 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8683 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8687 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8693 schedule ( schedule-kind )
8694 schedule ( schedule-kind , expression )
8697 static | dynamic | guided | runtime | auto
8701 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8704 location_t loc = c_parser_peek_token (parser)->location;
8706 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8709 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8711 if (c_parser_next_token_is (parser, CPP_NAME))
8713 tree kind = c_parser_peek_token (parser)->value;
8714 const char *p = IDENTIFIER_POINTER (kind);
8719 if (strcmp ("dynamic", p) != 0)
8721 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8725 if (strcmp ("guided", p) != 0)
8727 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8731 if (strcmp ("runtime", p) != 0)
8733 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8740 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8741 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8742 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8743 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8747 c_parser_consume_token (parser);
8748 if (c_parser_next_token_is (parser, CPP_COMMA))
8751 c_parser_consume_token (parser);
8753 here = c_parser_peek_token (parser)->location;
8754 t = c_parser_expr_no_commas (parser, NULL).value;
8755 t = c_fully_fold (t, false, NULL);
8757 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8758 error_at (here, "schedule %<runtime%> does not take "
8759 "a %<chunk_size%> parameter");
8760 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8762 "schedule %<auto%> does not take "
8763 "a %<chunk_size%> parameter");
8764 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8765 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8767 c_parser_error (parser, "expected integer expression");
8769 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8772 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8773 "expected %<,%> or %<)%>");
8775 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8776 OMP_CLAUSE_CHAIN (c) = list;
8780 c_parser_error (parser, "invalid schedule kind");
8781 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8786 shared ( variable-list ) */
8789 c_parser_omp_clause_shared (c_parser *parser, tree list)
8791 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8798 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8802 /* FIXME: Should we allow duplicates? */
8803 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8805 c = build_omp_clause (c_parser_peek_token (parser)->location,
8807 OMP_CLAUSE_CHAIN (c) = list;
8812 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8813 is a bitmask in MASK. Return the list of clauses found; the result
8814 of clause default goes in *pdefault. */
8817 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8820 tree clauses = NULL;
8823 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8826 pragma_omp_clause c_kind;
8828 tree prev = clauses;
8830 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8831 c_parser_consume_token (parser);
8834 here = c_parser_peek_token (parser)->location;
8835 c_kind = c_parser_omp_clause_name (parser);
8839 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8840 clauses = c_parser_omp_clause_collapse (parser, clauses);
8841 c_name = "collapse";
8843 case PRAGMA_OMP_CLAUSE_COPYIN:
8844 clauses = c_parser_omp_clause_copyin (parser, clauses);
8847 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8848 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8849 c_name = "copyprivate";
8851 case PRAGMA_OMP_CLAUSE_DEFAULT:
8852 clauses = c_parser_omp_clause_default (parser, clauses);
8855 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8856 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8857 c_name = "firstprivate";
8859 case PRAGMA_OMP_CLAUSE_IF:
8860 clauses = c_parser_omp_clause_if (parser, clauses);
8863 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8864 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8865 c_name = "lastprivate";
8867 case PRAGMA_OMP_CLAUSE_NOWAIT:
8868 clauses = c_parser_omp_clause_nowait (parser, clauses);
8871 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8872 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8873 c_name = "num_threads";
8875 case PRAGMA_OMP_CLAUSE_ORDERED:
8876 clauses = c_parser_omp_clause_ordered (parser, clauses);
8879 case PRAGMA_OMP_CLAUSE_PRIVATE:
8880 clauses = c_parser_omp_clause_private (parser, clauses);
8883 case PRAGMA_OMP_CLAUSE_REDUCTION:
8884 clauses = c_parser_omp_clause_reduction (parser, clauses);
8885 c_name = "reduction";
8887 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8888 clauses = c_parser_omp_clause_schedule (parser, clauses);
8889 c_name = "schedule";
8891 case PRAGMA_OMP_CLAUSE_SHARED:
8892 clauses = c_parser_omp_clause_shared (parser, clauses);
8895 case PRAGMA_OMP_CLAUSE_UNTIED:
8896 clauses = c_parser_omp_clause_untied (parser, clauses);
8900 c_parser_error (parser, "expected %<#pragma omp%> clause");
8904 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8906 /* Remove the invalid clause(s) from the list to avoid
8907 confusing the rest of the compiler. */
8909 error_at (here, "%qs is not valid for %qs", c_name, where);
8914 c_parser_skip_to_pragma_eol (parser);
8916 return c_finish_omp_clauses (clauses);
8923 In practice, we're also interested in adding the statement to an
8924 outer node. So it is convenient if we work around the fact that
8925 c_parser_statement calls add_stmt. */
8928 c_parser_omp_structured_block (c_parser *parser)
8930 tree stmt = push_stmt_list ();
8931 c_parser_statement (parser);
8932 return pop_stmt_list (stmt);
8936 # pragma omp atomic new-line
8940 x binop= expr | x++ | ++x | x-- | --x
8942 +, *, -, /, &, ^, |, <<, >>
8944 where x is an lvalue expression with scalar type.
8946 LOC is the location of the #pragma token. */
8949 c_parser_omp_atomic (location_t loc, c_parser *parser)
8953 enum tree_code code;
8954 struct c_expr rhs_expr;
8956 c_parser_skip_to_pragma_eol (parser);
8958 lhs = c_parser_unary_expression (parser).value;
8959 lhs = c_fully_fold (lhs, false, NULL);
8960 switch (TREE_CODE (lhs))
8964 c_parser_skip_to_end_of_block_or_statement (parser);
8967 case PREINCREMENT_EXPR:
8968 case POSTINCREMENT_EXPR:
8969 lhs = TREE_OPERAND (lhs, 0);
8971 rhs = integer_one_node;
8974 case PREDECREMENT_EXPR:
8975 case POSTDECREMENT_EXPR:
8976 lhs = TREE_OPERAND (lhs, 0);
8978 rhs = integer_one_node;
8982 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8983 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8984 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8985 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8986 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8987 (TREE_OPERAND (lhs, 1), 0), 0)))
8989 /* Undo effects of boolean_increment for post {in,de}crement. */
8990 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8993 if (TREE_CODE (lhs) == MODIFY_EXPR
8994 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8996 /* Undo effects of boolean_increment. */
8997 if (integer_onep (TREE_OPERAND (lhs, 1)))
8999 /* This is pre or post increment. */
9000 rhs = TREE_OPERAND (lhs, 1);
9001 lhs = TREE_OPERAND (lhs, 0);
9005 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9006 && TREE_OPERAND (lhs, 0)
9007 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9009 /* This is pre or post decrement. */
9010 rhs = TREE_OPERAND (lhs, 1);
9011 lhs = TREE_OPERAND (lhs, 0);
9018 switch (c_parser_peek_token (parser)->type)
9024 code = TRUNC_DIV_EXPR;
9039 code = BIT_AND_EXPR;
9042 code = BIT_IOR_EXPR;
9045 code = BIT_XOR_EXPR;
9048 c_parser_error (parser,
9049 "invalid operator for %<#pragma omp atomic%>");
9053 c_parser_consume_token (parser);
9055 location_t rhs_loc = c_parser_peek_token (parser)->location;
9056 rhs_expr = c_parser_expression (parser);
9057 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9059 rhs = rhs_expr.value;
9060 rhs = c_fully_fold (rhs, false, NULL);
9063 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
9064 if (stmt != error_mark_node)
9066 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9071 # pragma omp barrier new-line
9075 c_parser_omp_barrier (c_parser *parser)
9077 location_t loc = c_parser_peek_token (parser)->location;
9078 c_parser_consume_pragma (parser);
9079 c_parser_skip_to_pragma_eol (parser);
9081 c_finish_omp_barrier (loc);
9085 # pragma omp critical [(name)] new-line
9088 LOC is the location of the #pragma itself. */
9091 c_parser_omp_critical (location_t loc, c_parser *parser)
9093 tree stmt, name = NULL;
9095 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9097 c_parser_consume_token (parser);
9098 if (c_parser_next_token_is (parser, CPP_NAME))
9100 name = c_parser_peek_token (parser)->value;
9101 c_parser_consume_token (parser);
9102 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9105 c_parser_error (parser, "expected identifier");
9107 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9108 c_parser_error (parser, "expected %<(%> or end of line");
9109 c_parser_skip_to_pragma_eol (parser);
9111 stmt = c_parser_omp_structured_block (parser);
9112 return c_finish_omp_critical (loc, stmt, name);
9116 # pragma omp flush flush-vars[opt] new-line
9119 ( variable-list ) */
9122 c_parser_omp_flush (c_parser *parser)
9124 location_t loc = c_parser_peek_token (parser)->location;
9125 c_parser_consume_pragma (parser);
9126 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9127 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9128 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9129 c_parser_error (parser, "expected %<(%> or end of line");
9130 c_parser_skip_to_pragma_eol (parser);
9132 c_finish_omp_flush (loc);
9135 /* Parse the restricted form of the for statement allowed by OpenMP.
9136 The real trick here is to determine the loop control variable early
9137 so that we can push a new decl if necessary to make it private.
9138 LOC is the location of the OMP in "#pragma omp". */
9141 c_parser_omp_for_loop (location_t loc,
9142 c_parser *parser, tree clauses, tree *par_clauses)
9144 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9145 tree declv, condv, incrv, initv, ret = NULL;
9146 bool fail = false, open_brace_parsed = false;
9147 int i, collapse = 1, nbraces = 0;
9149 VEC(tree,gc) *for_block = make_tree_vector ();
9151 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9152 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9153 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9155 gcc_assert (collapse >= 1);
9157 declv = make_tree_vec (collapse);
9158 initv = make_tree_vec (collapse);
9159 condv = make_tree_vec (collapse);
9160 incrv = make_tree_vec (collapse);
9162 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9164 c_parser_error (parser, "for statement expected");
9167 for_loc = c_parser_peek_token (parser)->location;
9168 c_parser_consume_token (parser);
9170 for (i = 0; i < collapse; i++)
9174 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9177 /* Parse the initialization declaration or expression. */
9178 if (c_parser_next_tokens_start_declaration (parser))
9181 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9182 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9183 decl = check_for_loop_decls (for_loc, flag_isoc99);
9186 if (DECL_INITIAL (decl) == error_mark_node)
9187 decl = error_mark_node;
9190 else if (c_parser_next_token_is (parser, CPP_NAME)
9191 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9193 struct c_expr decl_exp;
9194 struct c_expr init_exp;
9195 location_t init_loc;
9197 decl_exp = c_parser_postfix_expression (parser);
9198 decl = decl_exp.value;
9200 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9202 init_loc = c_parser_peek_token (parser)->location;
9203 init_exp = c_parser_expr_no_commas (parser, NULL);
9204 init_exp = default_function_array_read_conversion (init_loc,
9206 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9207 NOP_EXPR, init_loc, init_exp.value,
9208 init_exp.original_type);
9209 init = c_process_expr_stmt (init_loc, init);
9211 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9216 c_parser_error (parser,
9217 "expected iteration declaration or initialization");
9218 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9224 /* Parse the loop condition. */
9226 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9228 location_t cond_loc = c_parser_peek_token (parser)->location;
9229 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
9231 cond = cond_expr.value;
9232 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9233 cond = c_fully_fold (cond, false, NULL);
9234 switch (cond_expr.original_code)
9242 /* Can't be cond = error_mark_node, because we want to preserve
9243 the location until c_finish_omp_for. */
9244 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9247 protected_set_expr_location (cond, cond_loc);
9249 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9251 /* Parse the increment expression. */
9253 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9255 location_t incr_loc = c_parser_peek_token (parser)->location;
9257 incr = c_process_expr_stmt (incr_loc,
9258 c_parser_expression (parser).value);
9260 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9262 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9266 TREE_VEC_ELT (declv, i) = decl;
9267 TREE_VEC_ELT (initv, i) = init;
9268 TREE_VEC_ELT (condv, i) = cond;
9269 TREE_VEC_ELT (incrv, i) = incr;
9273 if (i == collapse - 1)
9276 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9277 in between the collapsed for loops to be still considered perfectly
9278 nested. Hopefully the final version clarifies this.
9279 For now handle (multiple) {'s and empty statements. */
9282 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9284 c_parser_consume_token (parser);
9287 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9289 c_parser_consume_token (parser);
9293 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9294 c_parser_consume_token (parser);
9297 c_parser_error (parser, "not enough perfectly nested loops");
9300 open_brace_parsed = true;
9310 nbraces += bracecount;
9313 save_break = c_break_label;
9314 c_break_label = size_one_node;
9315 save_cont = c_cont_label;
9316 c_cont_label = NULL_TREE;
9317 body = push_stmt_list ();
9319 if (open_brace_parsed)
9321 location_t here = c_parser_peek_token (parser)->location;
9322 stmt = c_begin_compound_stmt (true);
9323 c_parser_compound_statement_nostart (parser);
9324 add_stmt (c_end_compound_stmt (here, stmt, true));
9327 add_stmt (c_parser_c99_block_statement (parser));
9330 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9331 SET_EXPR_LOCATION (t, loc);
9335 body = pop_stmt_list (body);
9336 c_break_label = save_break;
9337 c_cont_label = save_cont;
9341 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9343 c_parser_consume_token (parser);
9346 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9347 c_parser_consume_token (parser);
9350 c_parser_error (parser, "collapsed loops not perfectly nested");
9353 location_t here = c_parser_peek_token (parser)->location;
9354 stmt = c_begin_compound_stmt (true);
9356 c_parser_compound_statement_nostart (parser);
9357 body = c_end_compound_stmt (here, stmt, true);
9364 /* Only bother calling c_finish_omp_for if we haven't already generated
9365 an error from the initialization parsing. */
9368 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9371 if (par_clauses != NULL)
9374 for (c = par_clauses; *c ; )
9375 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9376 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9377 c = &OMP_CLAUSE_CHAIN (*c);
9380 for (i = 0; i < collapse; i++)
9381 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9384 c = &OMP_CLAUSE_CHAIN (*c);
9385 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9388 "iteration variable %qD should not be firstprivate",
9389 OMP_CLAUSE_DECL (*c));
9390 *c = OMP_CLAUSE_CHAIN (*c);
9394 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9395 change it to shared (decl) in
9396 OMP_PARALLEL_CLAUSES. */
9397 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9398 OMP_CLAUSE_LASTPRIVATE);
9399 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9400 OMP_CLAUSE_CHAIN (l) = clauses;
9402 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9406 OMP_FOR_CLAUSES (stmt) = clauses;
9411 while (!VEC_empty (tree, for_block))
9413 /* FIXME diagnostics: LOC below should be the actual location of
9414 this particular for block. We need to build a list of
9415 locations to go along with FOR_BLOCK. */
9416 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9419 release_tree_vector (for_block);
9424 #pragma omp for for-clause[optseq] new-line
9427 LOC is the location of the #pragma token.
9430 #define OMP_FOR_CLAUSE_MASK \
9431 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9432 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9433 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9434 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9435 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9436 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9437 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9438 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9441 c_parser_omp_for (location_t loc, c_parser *parser)
9443 tree block, clauses, ret;
9445 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9448 block = c_begin_compound_stmt (true);
9449 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9450 block = c_end_compound_stmt (loc, block, true);
9457 # pragma omp master new-line
9460 LOC is the location of the #pragma token.
9464 c_parser_omp_master (location_t loc, c_parser *parser)
9466 c_parser_skip_to_pragma_eol (parser);
9467 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9471 # pragma omp ordered new-line
9474 LOC is the location of the #pragma itself.
9478 c_parser_omp_ordered (location_t loc, c_parser *parser)
9480 c_parser_skip_to_pragma_eol (parser);
9481 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9487 { section-sequence }
9490 section-directive[opt] structured-block
9491 section-sequence section-directive structured-block
9493 SECTIONS_LOC is the location of the #pragma omp sections. */
9496 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9499 bool error_suppress = false;
9502 loc = c_parser_peek_token (parser)->location;
9503 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9505 /* Avoid skipping until the end of the block. */
9506 parser->error = false;
9510 stmt = push_stmt_list ();
9512 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9514 substmt = push_stmt_list ();
9518 c_parser_statement (parser);
9520 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9522 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9524 if (c_parser_next_token_is (parser, CPP_EOF))
9528 substmt = pop_stmt_list (substmt);
9529 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9530 SET_EXPR_LOCATION (substmt, loc);
9536 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9538 if (c_parser_next_token_is (parser, CPP_EOF))
9541 loc = c_parser_peek_token (parser)->location;
9542 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9544 c_parser_consume_pragma (parser);
9545 c_parser_skip_to_pragma_eol (parser);
9546 error_suppress = false;
9548 else if (!error_suppress)
9550 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9551 error_suppress = true;
9554 substmt = c_parser_omp_structured_block (parser);
9555 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9556 SET_EXPR_LOCATION (substmt, loc);
9559 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9560 "expected %<#pragma omp section%> or %<}%>");
9562 substmt = pop_stmt_list (stmt);
9564 stmt = make_node (OMP_SECTIONS);
9565 SET_EXPR_LOCATION (stmt, sections_loc);
9566 TREE_TYPE (stmt) = void_type_node;
9567 OMP_SECTIONS_BODY (stmt) = substmt;
9569 return add_stmt (stmt);
9573 # pragma omp sections sections-clause[optseq] newline
9576 LOC is the location of the #pragma token.
9579 #define OMP_SECTIONS_CLAUSE_MASK \
9580 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9581 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9582 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9583 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9584 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9587 c_parser_omp_sections (location_t loc, c_parser *parser)
9589 tree block, clauses, ret;
9591 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9592 "#pragma omp sections");
9594 block = c_begin_compound_stmt (true);
9595 ret = c_parser_omp_sections_scope (loc, parser);
9597 OMP_SECTIONS_CLAUSES (ret) = clauses;
9598 block = c_end_compound_stmt (loc, block, true);
9605 # pragma parallel parallel-clause new-line
9606 # pragma parallel for parallel-for-clause new-line
9607 # pragma parallel sections parallel-sections-clause new-line
9609 LOC is the location of the #pragma token.
9612 #define OMP_PARALLEL_CLAUSE_MASK \
9613 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9614 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9615 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9616 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9617 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9618 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9619 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9620 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9623 c_parser_omp_parallel (location_t loc, c_parser *parser)
9625 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9626 const char *p_name = "#pragma omp parallel";
9627 tree stmt, clauses, par_clause, ws_clause, block;
9628 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9630 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9632 c_parser_consume_token (parser);
9633 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9634 p_name = "#pragma omp parallel for";
9635 mask |= OMP_FOR_CLAUSE_MASK;
9636 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9638 else if (c_parser_next_token_is (parser, CPP_NAME))
9640 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9641 if (strcmp (p, "sections") == 0)
9643 c_parser_consume_token (parser);
9644 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9645 p_name = "#pragma omp parallel sections";
9646 mask |= OMP_SECTIONS_CLAUSE_MASK;
9647 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9651 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9655 case PRAGMA_OMP_PARALLEL:
9656 block = c_begin_omp_parallel ();
9657 c_parser_statement (parser);
9658 stmt = c_finish_omp_parallel (loc, clauses, block);
9661 case PRAGMA_OMP_PARALLEL_FOR:
9662 block = c_begin_omp_parallel ();
9663 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9664 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9665 stmt = c_finish_omp_parallel (loc, par_clause, block);
9666 OMP_PARALLEL_COMBINED (stmt) = 1;
9669 case PRAGMA_OMP_PARALLEL_SECTIONS:
9670 block = c_begin_omp_parallel ();
9671 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9672 stmt = c_parser_omp_sections_scope (loc, parser);
9674 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9675 stmt = c_finish_omp_parallel (loc, par_clause, block);
9676 OMP_PARALLEL_COMBINED (stmt) = 1;
9687 # pragma omp single single-clause[optseq] new-line
9690 LOC is the location of the #pragma.
9693 #define OMP_SINGLE_CLAUSE_MASK \
9694 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9695 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9696 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9697 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9700 c_parser_omp_single (location_t loc, c_parser *parser)
9702 tree stmt = make_node (OMP_SINGLE);
9703 SET_EXPR_LOCATION (stmt, loc);
9704 TREE_TYPE (stmt) = void_type_node;
9706 OMP_SINGLE_CLAUSES (stmt)
9707 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9708 "#pragma omp single");
9709 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9711 return add_stmt (stmt);
9715 # pragma omp task task-clause[optseq] new-line
9717 LOC is the location of the #pragma.
9720 #define OMP_TASK_CLAUSE_MASK \
9721 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9722 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9723 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9724 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9725 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9726 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9729 c_parser_omp_task (location_t loc, c_parser *parser)
9731 tree clauses, block;
9733 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9734 "#pragma omp task");
9736 block = c_begin_omp_task ();
9737 c_parser_statement (parser);
9738 return c_finish_omp_task (loc, clauses, block);
9742 # pragma omp taskwait new-line
9746 c_parser_omp_taskwait (c_parser *parser)
9748 location_t loc = c_parser_peek_token (parser)->location;
9749 c_parser_consume_pragma (parser);
9750 c_parser_skip_to_pragma_eol (parser);
9752 c_finish_omp_taskwait (loc);
9755 /* Main entry point to parsing most OpenMP pragmas. */
9758 c_parser_omp_construct (c_parser *parser)
9760 enum pragma_kind p_kind;
9764 loc = c_parser_peek_token (parser)->location;
9765 p_kind = c_parser_peek_token (parser)->pragma_kind;
9766 c_parser_consume_pragma (parser);
9770 case PRAGMA_OMP_ATOMIC:
9771 c_parser_omp_atomic (loc, parser);
9773 case PRAGMA_OMP_CRITICAL:
9774 stmt = c_parser_omp_critical (loc, parser);
9776 case PRAGMA_OMP_FOR:
9777 stmt = c_parser_omp_for (loc, parser);
9779 case PRAGMA_OMP_MASTER:
9780 stmt = c_parser_omp_master (loc, parser);
9782 case PRAGMA_OMP_ORDERED:
9783 stmt = c_parser_omp_ordered (loc, parser);
9785 case PRAGMA_OMP_PARALLEL:
9786 stmt = c_parser_omp_parallel (loc, parser);
9788 case PRAGMA_OMP_SECTIONS:
9789 stmt = c_parser_omp_sections (loc, parser);
9791 case PRAGMA_OMP_SINGLE:
9792 stmt = c_parser_omp_single (loc, parser);
9794 case PRAGMA_OMP_TASK:
9795 stmt = c_parser_omp_task (loc, parser);
9802 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9807 # pragma omp threadprivate (variable-list) */
9810 c_parser_omp_threadprivate (c_parser *parser)
9815 c_parser_consume_pragma (parser);
9816 loc = c_parser_peek_token (parser)->location;
9817 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9819 /* Mark every variable in VARS to be assigned thread local storage. */
9820 for (t = vars; t; t = TREE_CHAIN (t))
9822 tree v = TREE_PURPOSE (t);
9824 /* FIXME diagnostics: Ideally we should keep individual
9825 locations for all the variables in the var list to make the
9826 following errors more precise. Perhaps
9827 c_parser_omp_var_list_parens() should construct a list of
9828 locations to go along with the var list. */
9830 /* If V had already been marked threadprivate, it doesn't matter
9831 whether it had been used prior to this point. */
9832 if (TREE_CODE (v) != VAR_DECL)
9833 error_at (loc, "%qD is not a variable", v);
9834 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9835 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9836 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9837 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9838 else if (TREE_TYPE (v) == error_mark_node)
9840 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9841 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9844 if (! DECL_THREAD_LOCAL_P (v))
9846 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9847 /* If rtl has been already set for this var, call
9848 make_decl_rtl once again, so that encode_section_info
9849 has a chance to look at the new decl flags. */
9850 if (DECL_RTL_SET_P (v))
9853 C_DECL_THREADPRIVATE_P (v) = 1;
9857 c_parser_skip_to_pragma_eol (parser);
9861 /* Parse a single source file. */
9866 /* Use local storage to begin. If the first token is a pragma, parse it.
9867 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9868 which will cause garbage collection. */
9871 memset (&tparser, 0, sizeof tparser);
9872 the_parser = &tparser;
9874 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9875 c_parser_pragma_pch_preprocess (&tparser);
9877 the_parser = ggc_alloc_c_parser ();
9878 *the_parser = tparser;
9880 /* Initialize EH, if we've been told to do so. */
9881 if (flag_exceptions)
9882 using_eh_for_cleanups ();
9884 c_parser_translation_unit (the_parser);
9888 #include "gt-c-parser.h"