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, 2011
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"
55 #include "c-family/c-objc.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX <= 255);
82 mask |= D_ASM | D_EXT;
86 if (!c_dialect_objc ())
87 mask |= D_OBJC | D_CXX_OBJC;
89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
90 for (i = 0; i < num_c_common_reswords; i++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords[i].disable & mask)
97 && (c_common_reswords[i].disable & D_CXXWARN))
99 id = get_identifier (c_common_reswords[i].word);
100 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
101 C_IS_RESERVED_WORD (id) = 1;
106 id = get_identifier (c_common_reswords[i].word);
107 C_SET_RID_CODE (id, c_common_reswords[i].rid);
108 C_IS_RESERVED_WORD (id) = 1;
109 ridpointers [(int) c_common_reswords[i].rid] = id;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind {
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token {
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype) type : 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind) id_kind : 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid) keyword : 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser {
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error : 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma : 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block : 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string : 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context : 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context : 1;
193 /* The following flag is needed to contextualize Objective-C lexical
194 analysis. In some cases (e.g., 'int NSObject;'), it is
195 undesirable to bind an identifier to an Objective-C class, even
196 if a class with that name exists. */
197 BOOL_BITFIELD objc_need_raw_identifier : 1;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context : 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser *the_parser;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser *parser, c_token *token)
214 timevar_push (TV_LEX);
216 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
217 (parser->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE : 0));
219 token->id_kind = C_ID_NONE;
220 token->keyword = RID_MAX;
221 token->pragma_kind = PRAGMA_NONE;
229 bool objc_force_identifier = parser->objc_need_raw_identifier;
230 if (c_dialect_objc ())
231 parser->objc_need_raw_identifier = false;
233 if (C_IS_RESERVED_WORD (token->value))
235 enum rid rid_code = C_RID_CODE (token->value);
237 if (rid_code == RID_CXX_COMPAT_WARN)
239 warning_at (token->location,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code >= RID_FIRST_ADDR_SPACE
245 && rid_code <= RID_LAST_ADDR_SPACE)
247 token->id_kind = C_ID_ADDRSPACE;
248 token->keyword = rid_code;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
258 if (parser->objc_pq_context)
260 token->type = CPP_KEYWORD;
261 token->keyword = rid_code;
264 else if (parser->objc_could_be_foreach_context
265 && rid_code == RID_IN)
267 /* We are in Objective-C, inside a (potential)
268 foreach context (which means after having
269 parsed 'for (', but before having parsed ';'),
270 and we found 'in'. We consider it the keyword
271 which terminates the declaration at the
272 beginning of a foreach-statement. Note that
273 this means you can't use 'in' for anything else
274 in that context; in particular, in Objective-C
275 you can't use 'in' as the name of the running
276 variable in a C for loop. We could potentially
277 try to add code here to disambiguate, but it
278 seems a reasonable limitation.
280 token->type = CPP_KEYWORD;
281 token->keyword = rid_code;
284 /* Else, "pq" keywords outside of the "pq" context are
285 not keywords, and we fall through to the code for
289 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
291 /* We found an Objective-C "property attribute" keyword
292 (readonly, copies, getter, setter, ivar). These are
293 only valid in the property context. */
294 if (parser->objc_property_attr_context)
296 token->type = CPP_KEYWORD;
297 token->keyword = rid_code;
300 /* Else they are not special keywords.
303 else if (c_dialect_objc ()
304 && (OBJC_IS_AT_KEYWORD (rid_code)
305 || OBJC_IS_CXX_KEYWORD (rid_code)))
307 /* We found one of the Objective-C "@" keywords (defs,
308 selector, synchronized, etc) or one of the
309 Objective-C "cxx" keywords (class, private,
310 protected, public, try, catch, throw) without a
311 preceding '@' sign. Do nothing and fall through to
312 the code for normal tokens (in C++ we would still
313 consider the CXX ones keywords, but not in C).
319 token->type = CPP_KEYWORD;
320 token->keyword = rid_code;
325 decl = lookup_name (token->value);
328 if (TREE_CODE (decl) == TYPE_DECL)
330 token->id_kind = C_ID_TYPENAME;
334 else if (c_dialect_objc ())
336 tree objc_interface_decl = objc_is_class_name (token->value);
337 /* Objective-C class names are in the same namespace as
338 variables and typedefs, and hence are shadowed by local
340 if (objc_interface_decl
341 && (global_bindings_p ()
342 || (!objc_force_identifier && !decl)))
344 token->value = objc_interface_decl;
345 token->id_kind = C_ID_CLASSNAME;
349 token->id_kind = C_ID_ID;
353 /* This only happens in Objective-C; it must be a keyword. */
354 token->type = CPP_KEYWORD;
355 switch (C_RID_CODE (token->value))
357 /* Replace 'class' with '@class', 'private' with '@private',
358 etc. This prevents confusion with the C++ keyword
359 'class', and makes the tokens consistent with other
360 Objective-C 'AT' keywords. For example '@class' is
361 reported as RID_AT_CLASS which is consistent with
362 '@synchronized', which is reported as
365 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
366 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
367 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
368 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
369 case RID_THROW: token->keyword = RID_AT_THROW; break;
370 case RID_TRY: token->keyword = RID_AT_TRY; break;
371 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
372 default: token->keyword = C_RID_CODE (token->value);
377 case CPP_CLOSE_PAREN:
379 /* These tokens may affect the interpretation of any identifiers
380 following, if doing Objective-C. */
381 if (c_dialect_objc ())
382 parser->objc_need_raw_identifier = false;
385 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
386 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
392 timevar_pop (TV_LEX);
395 /* Return a pointer to the next token from PARSER, reading it in if
398 static inline c_token *
399 c_parser_peek_token (c_parser *parser)
401 if (parser->tokens_avail == 0)
403 c_lex_one_token (parser, &parser->tokens[0]);
404 parser->tokens_avail = 1;
406 return &parser->tokens[0];
409 /* Return true if the next token from PARSER has the indicated
413 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
415 return c_parser_peek_token (parser)->type == type;
418 /* Return true if the next token from PARSER does not have the
422 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
424 return !c_parser_next_token_is (parser, type);
427 /* Return true if the next token from PARSER is the indicated
431 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
433 return c_parser_peek_token (parser)->keyword == keyword;
436 /* Return a pointer to the next-but-one token from PARSER, reading it
437 in if necessary. The next token is already read in. */
440 c_parser_peek_2nd_token (c_parser *parser)
442 if (parser->tokens_avail >= 2)
443 return &parser->tokens[1];
444 gcc_assert (parser->tokens_avail == 1);
445 gcc_assert (parser->tokens[0].type != CPP_EOF);
446 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
447 c_lex_one_token (parser, &parser->tokens[1]);
448 parser->tokens_avail = 2;
449 return &parser->tokens[1];
452 /* Return true if TOKEN can start a type name,
455 c_token_starts_typename (c_token *token)
460 switch (token->id_kind)
469 gcc_assert (c_dialect_objc ());
475 switch (token->keyword)
508 if (c_dialect_objc ())
516 enum c_lookahead_kind {
517 /* Always treat unknown identifiers as typenames. */
520 /* Could be parsing a nonabstract declarator. Only treat an identifier
521 as a typename if followed by another identifier or a star. */
522 cla_nonabstract_decl,
524 /* Never treat identifiers as typenames. */
528 /* Return true if the next token from PARSER can start a type name,
529 false otherwise. LA specifies how to do lookahead in order to
530 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
533 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
535 c_token *token = c_parser_peek_token (parser);
536 if (c_token_starts_typename (token))
539 /* Try a bit harder to detect an unknown typename. */
540 if (la != cla_prefer_id
541 && token->type == CPP_NAME
542 && token->id_kind == C_ID_ID
544 /* Do not try too hard when we could have "object in array". */
545 && !parser->objc_could_be_foreach_context
547 && (la == cla_prefer_type
548 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
549 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
551 /* Only unknown identifiers. */
552 && !lookup_name (token->value))
558 /* Return true if TOKEN is a type qualifier, false otherwise. */
560 c_token_is_qualifier (c_token *token)
565 switch (token->id_kind)
573 switch (token->keyword)
590 /* Return true if the next token from PARSER is a type qualifier,
593 c_parser_next_token_is_qualifier (c_parser *parser)
595 c_token *token = c_parser_peek_token (parser);
596 return c_token_is_qualifier (token);
599 /* Return true if TOKEN can start declaration specifiers, false
602 c_token_starts_declspecs (c_token *token)
607 switch (token->id_kind)
616 gcc_assert (c_dialect_objc ());
622 switch (token->keyword)
662 if (c_dialect_objc ())
671 /* Return true if TOKEN can start declaration specifiers or a static
672 assertion, false otherwise. */
674 c_token_starts_declaration (c_token *token)
676 if (c_token_starts_declspecs (token)
677 || token->keyword == RID_STATIC_ASSERT)
683 /* Return true if the next token from PARSER can start declaration
684 specifiers, false otherwise. */
686 c_parser_next_token_starts_declspecs (c_parser *parser)
688 c_token *token = c_parser_peek_token (parser);
690 /* In Objective-C, a classname normally starts a declspecs unless it
691 is immediately followed by a dot. In that case, it is the
692 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
693 setter/getter on the class. c_token_starts_declspecs() can't
694 differentiate between the two cases because it only checks the
695 current token, so we have a special check here. */
696 if (c_dialect_objc ()
697 && token->type == CPP_NAME
698 && token->id_kind == C_ID_CLASSNAME
699 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
702 return c_token_starts_declspecs (token);
705 /* Return true if the next tokens from PARSER can start declaration
706 specifiers or a static assertion, false otherwise. */
708 c_parser_next_tokens_start_declaration (c_parser *parser)
710 c_token *token = c_parser_peek_token (parser);
713 if (c_dialect_objc ()
714 && token->type == CPP_NAME
715 && token->id_kind == C_ID_CLASSNAME
716 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
719 /* Labels do not start declarations. */
720 if (token->type == CPP_NAME
721 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
724 if (c_token_starts_declaration (token))
727 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
733 /* Consume the next token from PARSER. */
736 c_parser_consume_token (c_parser *parser)
738 gcc_assert (parser->tokens_avail >= 1);
739 gcc_assert (parser->tokens[0].type != CPP_EOF);
740 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
741 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
742 if (parser->tokens_avail == 2)
743 parser->tokens[0] = parser->tokens[1];
744 parser->tokens_avail--;
747 /* Expect the current token to be a #pragma. Consume it and remember
748 that we've begun parsing a pragma. */
751 c_parser_consume_pragma (c_parser *parser)
753 gcc_assert (!parser->in_pragma);
754 gcc_assert (parser->tokens_avail >= 1);
755 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
756 if (parser->tokens_avail == 2)
757 parser->tokens[0] = parser->tokens[1];
758 parser->tokens_avail--;
759 parser->in_pragma = true;
762 /* Update the globals input_location and in_system_header from
765 c_parser_set_source_position_from_token (c_token *token)
767 if (token->type != CPP_EOF)
769 input_location = token->location;
773 /* Issue a diagnostic of the form
774 FILE:LINE: MESSAGE before TOKEN
775 where TOKEN is the next token in the input stream of PARSER.
776 MESSAGE (specified by the caller) is usually of the form "expected
779 Do not issue a diagnostic if still recovering from an error.
781 ??? This is taken from the C++ parser, but building up messages in
782 this way is not i18n-friendly and some other approach should be
786 c_parser_error (c_parser *parser, const char *gmsgid)
788 c_token *token = c_parser_peek_token (parser);
791 parser->error = true;
794 /* This diagnostic makes more sense if it is tagged to the line of
795 the token we just peeked at. */
796 c_parser_set_source_position_from_token (token);
797 c_parse_error (gmsgid,
798 /* Because c_parse_error does not understand
799 CPP_KEYWORD, keywords are treated like
801 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
802 /* ??? The C parser does not save the cpp flags of a
803 token, we need to pass 0 here and we will not get
804 the source spelling of some tokens but rather the
805 canonical spelling. */
806 token->value, /*flags=*/0);
809 /* If the next token is of the indicated TYPE, consume it. Otherwise,
810 issue the error MSGID. If MSGID is NULL then a message has already
811 been produced and no message will be produced this time. Returns
812 true if found, false otherwise. */
815 c_parser_require (c_parser *parser,
819 if (c_parser_next_token_is (parser, type))
821 c_parser_consume_token (parser);
826 c_parser_error (parser, msgid);
831 /* If the next token is the indicated keyword, consume it. Otherwise,
832 issue the error MSGID. Returns true if found, false otherwise. */
835 c_parser_require_keyword (c_parser *parser,
839 if (c_parser_next_token_is_keyword (parser, keyword))
841 c_parser_consume_token (parser);
846 c_parser_error (parser, msgid);
851 /* Like c_parser_require, except that tokens will be skipped until the
852 desired token is found. An error message is still produced if the
853 next token is not as expected. If MSGID is NULL then a message has
854 already been produced and no message will be produced this
858 c_parser_skip_until_found (c_parser *parser,
862 unsigned nesting_depth = 0;
864 if (c_parser_require (parser, type, msgid))
867 /* Skip tokens until the desired token is found. */
870 /* Peek at the next token. */
871 c_token *token = c_parser_peek_token (parser);
872 /* If we've reached the token we want, consume it and stop. */
873 if (token->type == type && !nesting_depth)
875 c_parser_consume_token (parser);
879 /* If we've run out of tokens, stop. */
880 if (token->type == CPP_EOF)
882 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
884 if (token->type == CPP_OPEN_BRACE
885 || token->type == CPP_OPEN_PAREN
886 || token->type == CPP_OPEN_SQUARE)
888 else if (token->type == CPP_CLOSE_BRACE
889 || token->type == CPP_CLOSE_PAREN
890 || token->type == CPP_CLOSE_SQUARE)
892 if (nesting_depth-- == 0)
895 /* Consume this token. */
896 c_parser_consume_token (parser);
898 parser->error = false;
901 /* Skip tokens until the end of a parameter is found, but do not
902 consume the comma, semicolon or closing delimiter. */
905 c_parser_skip_to_end_of_parameter (c_parser *parser)
907 unsigned nesting_depth = 0;
911 c_token *token = c_parser_peek_token (parser);
912 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
915 /* If we've run out of tokens, stop. */
916 if (token->type == CPP_EOF)
918 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
920 if (token->type == CPP_OPEN_BRACE
921 || token->type == CPP_OPEN_PAREN
922 || token->type == CPP_OPEN_SQUARE)
924 else if (token->type == CPP_CLOSE_BRACE
925 || token->type == CPP_CLOSE_PAREN
926 || token->type == CPP_CLOSE_SQUARE)
928 if (nesting_depth-- == 0)
931 /* Consume this token. */
932 c_parser_consume_token (parser);
934 parser->error = false;
937 /* Expect to be at the end of the pragma directive and consume an
938 end of line marker. */
941 c_parser_skip_to_pragma_eol (c_parser *parser)
943 gcc_assert (parser->in_pragma);
944 parser->in_pragma = false;
946 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
949 c_token *token = c_parser_peek_token (parser);
950 if (token->type == CPP_EOF)
952 if (token->type == CPP_PRAGMA_EOL)
954 c_parser_consume_token (parser);
957 c_parser_consume_token (parser);
960 parser->error = false;
963 /* Skip tokens until we have consumed an entire block, or until we
964 have consumed a non-nested ';'. */
967 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
969 unsigned nesting_depth = 0;
970 bool save_error = parser->error;
976 /* Peek at the next token. */
977 token = c_parser_peek_token (parser);
985 if (parser->in_pragma)
990 /* If the next token is a ';', we have reached the
991 end of the statement. */
994 /* Consume the ';'. */
995 c_parser_consume_token (parser);
1000 case CPP_CLOSE_BRACE:
1001 /* If the next token is a non-nested '}', then we have
1002 reached the end of the current block. */
1003 if (nesting_depth == 0 || --nesting_depth == 0)
1005 c_parser_consume_token (parser);
1010 case CPP_OPEN_BRACE:
1011 /* If it the next token is a '{', then we are entering a new
1012 block. Consume the entire block. */
1017 /* If we see a pragma, consume the whole thing at once. We
1018 have some safeguards against consuming pragmas willy-nilly.
1019 Normally, we'd expect to be here with parser->error set,
1020 which disables these safeguards. But it's possible to get
1021 here for secondary error recovery, after parser->error has
1023 c_parser_consume_pragma (parser);
1024 c_parser_skip_to_pragma_eol (parser);
1025 parser->error = save_error;
1032 c_parser_consume_token (parser);
1036 parser->error = false;
1039 /* CPP's options (initialized by c-opts.c). */
1040 extern cpp_options *cpp_opts;
1042 /* Save the warning flags which are controlled by __extension__. */
1045 disable_extension_diagnostics (void)
1048 | (warn_pointer_arith << 1)
1049 | (warn_traditional << 2)
1051 | (warn_long_long << 4)
1052 | (warn_cxx_compat << 5));
1053 cpp_opts->cpp_pedantic = pedantic = 0;
1054 warn_pointer_arith = 0;
1055 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1057 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1058 warn_cxx_compat = 0;
1062 /* Restore the warning flags which are controlled by __extension__.
1063 FLAGS is the return value from disable_extension_diagnostics. */
1066 restore_extension_diagnostics (int flags)
1068 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1069 warn_pointer_arith = (flags >> 1) & 1;
1070 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1071 flag_iso = (flags >> 3) & 1;
1072 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1073 warn_cxx_compat = (flags >> 5) & 1;
1076 /* Possibly kinds of declarator to parse. */
1077 typedef enum c_dtr_syn {
1078 /* A normal declarator with an identifier. */
1080 /* An abstract declarator (maybe empty). */
1082 /* A parameter declarator: may be either, but after a type name does
1083 not redeclare a typedef name as an identifier if it can
1084 alternatively be interpreted as a typedef name; see DR#009,
1085 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086 following DR#249. For example, given a typedef T, "int T" and
1087 "int *T" are valid parameter declarations redeclaring T, while
1088 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089 abstract declarators rather than involving redundant parentheses;
1090 the same applies with attributes inside the parentheses before
1095 static void c_parser_external_declaration (c_parser *);
1096 static void c_parser_asm_definition (c_parser *);
1097 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1098 bool, bool, tree *);
1099 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1100 static void c_parser_static_assert_declaration (c_parser *);
1101 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1102 bool, enum c_lookahead_kind);
1103 static struct c_typespec c_parser_enum_specifier (c_parser *);
1104 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1105 static tree c_parser_struct_declaration (c_parser *);
1106 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1107 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1109 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1111 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1113 struct c_declarator *);
1114 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1115 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1116 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1117 static tree c_parser_simple_asm_expr (c_parser *);
1118 static tree c_parser_attributes (c_parser *);
1119 static struct c_type_name *c_parser_type_name (c_parser *);
1120 static struct c_expr c_parser_initializer (c_parser *);
1121 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1122 static void c_parser_initelt (c_parser *, struct obstack *);
1123 static void c_parser_initval (c_parser *, struct c_expr *,
1125 static tree c_parser_compound_statement (c_parser *);
1126 static void c_parser_compound_statement_nostart (c_parser *);
1127 static void c_parser_label (c_parser *);
1128 static void c_parser_statement (c_parser *);
1129 static void c_parser_statement_after_labels (c_parser *);
1130 static void c_parser_if_statement (c_parser *);
1131 static void c_parser_switch_statement (c_parser *);
1132 static void c_parser_while_statement (c_parser *);
1133 static void c_parser_do_statement (c_parser *);
1134 static void c_parser_for_statement (c_parser *);
1135 static tree c_parser_asm_statement (c_parser *);
1136 static tree c_parser_asm_operands (c_parser *, bool);
1137 static tree c_parser_asm_goto_operands (c_parser *);
1138 static tree c_parser_asm_clobbers (c_parser *);
1139 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1140 static struct c_expr c_parser_conditional_expression (c_parser *,
1142 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1143 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1144 static struct c_expr c_parser_unary_expression (c_parser *);
1145 static struct c_expr c_parser_sizeof_expression (c_parser *);
1146 static struct c_expr c_parser_alignof_expression (c_parser *);
1147 static struct c_expr c_parser_postfix_expression (c_parser *);
1148 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1149 struct c_type_name *,
1151 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1154 static struct c_expr c_parser_expression (c_parser *);
1155 static struct c_expr c_parser_expression_conv (c_parser *);
1156 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1158 static void c_parser_omp_construct (c_parser *);
1159 static void c_parser_omp_threadprivate (c_parser *);
1160 static void c_parser_omp_barrier (c_parser *);
1161 static void c_parser_omp_flush (c_parser *);
1162 static void c_parser_omp_taskwait (c_parser *);
1164 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1165 static bool c_parser_pragma (c_parser *, enum pragma_context);
1167 /* These Objective-C parser functions are only ever called when
1168 compiling Objective-C. */
1169 static void c_parser_objc_class_definition (c_parser *, tree);
1170 static void c_parser_objc_class_instance_variables (c_parser *);
1171 static void c_parser_objc_class_declaration (c_parser *);
1172 static void c_parser_objc_alias_declaration (c_parser *);
1173 static void c_parser_objc_protocol_definition (c_parser *, tree);
1174 static bool c_parser_objc_method_type (c_parser *);
1175 static void c_parser_objc_method_definition (c_parser *);
1176 static void c_parser_objc_methodprotolist (c_parser *);
1177 static void c_parser_objc_methodproto (c_parser *);
1178 static tree c_parser_objc_method_decl (c_parser *, bool, tree *);
1179 static tree c_parser_objc_type_name (c_parser *);
1180 static tree c_parser_objc_protocol_refs (c_parser *);
1181 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1182 static void c_parser_objc_synchronized_statement (c_parser *);
1183 static tree c_parser_objc_selector (c_parser *);
1184 static tree c_parser_objc_selector_arg (c_parser *);
1185 static tree c_parser_objc_receiver (c_parser *);
1186 static tree c_parser_objc_message_args (c_parser *);
1187 static tree c_parser_objc_keywordexpr (c_parser *);
1188 static void c_parser_objc_at_property_declaration (c_parser *);
1189 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1190 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1191 static bool c_parser_objc_diagnose_bad_element_prefix
1192 (c_parser *, struct c_declspecs *);
1194 /* Parse a translation unit (C90 6.7, C99 6.9).
1197 external-declarations
1199 external-declarations:
1200 external-declaration
1201 external-declarations external-declaration
1210 c_parser_translation_unit (c_parser *parser)
1212 if (c_parser_next_token_is (parser, CPP_EOF))
1214 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1215 "ISO C forbids an empty translation unit");
1219 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1220 mark_valid_location_for_stdc_pragma (false);
1224 c_parser_external_declaration (parser);
1225 obstack_free (&parser_obstack, obstack_position);
1227 while (c_parser_next_token_is_not (parser, CPP_EOF));
1231 /* Parse an external declaration (C90 6.7, C99 6.9).
1233 external-declaration:
1239 external-declaration:
1242 __extension__ external-declaration
1246 external-declaration:
1247 objc-class-definition
1248 objc-class-declaration
1249 objc-alias-declaration
1250 objc-protocol-definition
1251 objc-method-definition
1256 c_parser_external_declaration (c_parser *parser)
1259 switch (c_parser_peek_token (parser)->type)
1262 switch (c_parser_peek_token (parser)->keyword)
1265 ext = disable_extension_diagnostics ();
1266 c_parser_consume_token (parser);
1267 c_parser_external_declaration (parser);
1268 restore_extension_diagnostics (ext);
1271 c_parser_asm_definition (parser);
1273 case RID_AT_INTERFACE:
1274 case RID_AT_IMPLEMENTATION:
1275 gcc_assert (c_dialect_objc ());
1276 c_parser_objc_class_definition (parser, NULL_TREE);
1279 gcc_assert (c_dialect_objc ());
1280 c_parser_objc_class_declaration (parser);
1283 gcc_assert (c_dialect_objc ());
1284 c_parser_objc_alias_declaration (parser);
1286 case RID_AT_PROTOCOL:
1287 gcc_assert (c_dialect_objc ());
1288 c_parser_objc_protocol_definition (parser, NULL_TREE);
1290 case RID_AT_PROPERTY:
1291 gcc_assert (c_dialect_objc ());
1292 c_parser_objc_at_property_declaration (parser);
1294 case RID_AT_SYNTHESIZE:
1295 gcc_assert (c_dialect_objc ());
1296 c_parser_objc_at_synthesize_declaration (parser);
1298 case RID_AT_DYNAMIC:
1299 gcc_assert (c_dialect_objc ());
1300 c_parser_objc_at_dynamic_declaration (parser);
1303 gcc_assert (c_dialect_objc ());
1304 c_parser_consume_token (parser);
1305 objc_finish_implementation ();
1312 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1313 "ISO C does not allow extra %<;%> outside of a function");
1314 c_parser_consume_token (parser);
1317 mark_valid_location_for_stdc_pragma (true);
1318 c_parser_pragma (parser, pragma_external);
1319 mark_valid_location_for_stdc_pragma (false);
1323 if (c_dialect_objc ())
1325 c_parser_objc_method_definition (parser);
1328 /* Else fall through, and yield a syntax error trying to parse
1329 as a declaration or function definition. */
1332 /* A declaration or a function definition (or, in Objective-C,
1333 an @interface or @protocol with prefix attributes). We can
1334 only tell which after parsing the declaration specifiers, if
1335 any, and the first declarator. */
1336 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1341 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1342 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1343 accepted; otherwise (old-style parameter declarations) only other
1344 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1345 assertion is accepted; otherwise (old-style parameter declarations)
1346 it is not. If NESTED is true, we are inside a function or parsing
1347 old-style parameter declarations; any functions encountered are
1348 nested functions and declaration specifiers are required; otherwise
1349 we are at top level and functions are normal functions and
1350 declaration specifiers may be optional. If EMPTY_OK is true, empty
1351 declarations are OK (subject to all other constraints); otherwise
1352 (old-style parameter declarations) they are diagnosed. If
1353 START_ATTR_OK is true, the declaration specifiers may start with
1354 attributes; otherwise they may not.
1355 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1356 declaration when parsing an Objective-C foreach statement.
1359 declaration-specifiers init-declarator-list[opt] ;
1360 static_assert-declaration
1362 function-definition:
1363 declaration-specifiers[opt] declarator declaration-list[opt]
1368 declaration-list declaration
1370 init-declarator-list:
1372 init-declarator-list , init-declarator
1375 declarator simple-asm-expr[opt] attributes[opt]
1376 declarator simple-asm-expr[opt] attributes[opt] = initializer
1380 nested-function-definition:
1381 declaration-specifiers declarator declaration-list[opt]
1385 attributes objc-class-definition
1386 attributes objc-category-definition
1387 attributes objc-protocol-definition
1389 The simple-asm-expr and attributes are GNU extensions.
1391 This function does not handle __extension__; that is handled in its
1392 callers. ??? Following the old parser, __extension__ may start
1393 external declarations, declarations in functions and declarations
1394 at the start of "for" loops, but not old-style parameter
1397 C99 requires declaration specifiers in a function definition; the
1398 absence is diagnosed through the diagnosis of implicit int. In GNU
1399 C we also allow but diagnose declarations without declaration
1400 specifiers, but only at top level (elsewhere they conflict with
1403 In Objective-C, declarations of the looping variable in a foreach
1404 statement are exceptionally terminated by 'in' (for example, 'for
1405 (NSObject *object in array) { ... }').
1410 threadprivate-directive */
1413 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1414 bool static_assert_ok, bool empty_ok,
1415 bool nested, bool start_attr_ok,
1416 tree *objc_foreach_object_declaration)
1418 struct c_declspecs *specs;
1420 tree all_prefix_attrs;
1421 bool diagnosed_no_specs = false;
1422 location_t here = c_parser_peek_token (parser)->location;
1424 if (static_assert_ok
1425 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1427 c_parser_static_assert_declaration (parser);
1430 specs = build_null_declspecs ();
1432 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1433 if (c_parser_peek_token (parser)->type == CPP_NAME
1434 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1435 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1436 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1437 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1439 error_at (here, "unknown type name %qE",
1440 c_parser_peek_token (parser)->value);
1442 /* Parse declspecs normally to get a correct pointer type, but avoid
1443 a further "fails to be a type name" error. Refuse nested functions
1444 since it is not how the user likely wants us to recover. */
1445 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1446 c_parser_peek_token (parser)->keyword = RID_VOID;
1447 c_parser_peek_token (parser)->value = error_mark_node;
1451 c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1454 c_parser_skip_to_end_of_block_or_statement (parser);
1457 if (nested && !specs->declspecs_seen_p)
1459 c_parser_error (parser, "expected declaration specifiers");
1460 c_parser_skip_to_end_of_block_or_statement (parser);
1463 finish_declspecs (specs);
1464 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1470 shadow_tag_warned (specs, 1);
1471 pedwarn (here, 0, "empty declaration");
1473 c_parser_consume_token (parser);
1477 /* Provide better error recovery. Note that a type name here is usually
1478 better diagnosed as a redeclaration. */
1480 && specs->typespec_kind == ctsk_tagdef
1481 && c_parser_next_token_starts_declspecs (parser)
1482 && !c_parser_next_token_is (parser, CPP_NAME))
1484 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1485 parser->error = false;
1486 shadow_tag_warned (specs, 1);
1489 else if (c_dialect_objc ())
1491 /* Prefix attributes are an error on method decls. */
1492 switch (c_parser_peek_token (parser)->type)
1496 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1500 warning_at (c_parser_peek_token (parser)->location,
1502 "prefix attributes are ignored for methods");
1503 specs->attrs = NULL_TREE;
1506 c_parser_objc_method_definition (parser);
1508 c_parser_objc_methodproto (parser);
1514 /* This is where we parse 'attributes @interface ...',
1515 'attributes @implementation ...', 'attributes @protocol ...'
1516 (where attributes could be, for example, __attribute__
1519 switch (c_parser_peek_token (parser)->keyword)
1521 case RID_AT_INTERFACE:
1523 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1525 c_parser_objc_class_definition (parser, specs->attrs);
1529 case RID_AT_IMPLEMENTATION:
1531 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1535 warning_at (c_parser_peek_token (parser)->location,
1537 "prefix attributes are ignored for implementations");
1538 specs->attrs = NULL_TREE;
1540 c_parser_objc_class_definition (parser, NULL_TREE);
1544 case RID_AT_PROTOCOL:
1546 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1548 c_parser_objc_protocol_definition (parser, specs->attrs);
1555 case RID_AT_PROPERTY:
1558 c_parser_error (parser, "unexpected attribute");
1559 specs->attrs = NULL;
1567 pending_xref_error ();
1568 prefix_attrs = specs->attrs;
1569 all_prefix_attrs = prefix_attrs;
1570 specs->attrs = NULL_TREE;
1573 struct c_declarator *declarator;
1576 /* Declaring either one or more declarators (in which case we
1577 should diagnose if there were no declaration specifiers) or a
1578 function definition (in which case the diagnostic for
1579 implicit int suffices). */
1580 declarator = c_parser_declarator (parser,
1581 specs->typespec_kind != ctsk_none,
1582 C_DTR_NORMAL, &dummy);
1583 if (declarator == NULL)
1585 c_parser_skip_to_end_of_block_or_statement (parser);
1588 if (c_parser_next_token_is (parser, CPP_EQ)
1589 || c_parser_next_token_is (parser, CPP_COMMA)
1590 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1591 || c_parser_next_token_is_keyword (parser, RID_ASM)
1592 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1593 || c_parser_next_token_is_keyword (parser, RID_IN))
1595 tree asm_name = NULL_TREE;
1596 tree postfix_attrs = NULL_TREE;
1597 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1599 diagnosed_no_specs = true;
1600 pedwarn (here, 0, "data definition has no type or storage class");
1602 /* Having seen a data definition, there cannot now be a
1603 function definition. */
1605 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1606 asm_name = c_parser_simple_asm_expr (parser);
1607 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1608 postfix_attrs = c_parser_attributes (parser);
1609 if (c_parser_next_token_is (parser, CPP_EQ))
1613 location_t init_loc;
1614 c_parser_consume_token (parser);
1615 /* The declaration of the variable is in effect while
1616 its initializer is parsed. */
1617 d = start_decl (declarator, specs, true,
1618 chainon (postfix_attrs, all_prefix_attrs));
1620 d = error_mark_node;
1621 start_init (d, asm_name, global_bindings_p ());
1622 init_loc = c_parser_peek_token (parser)->location;
1623 init = c_parser_initializer (parser);
1625 if (d != error_mark_node)
1627 maybe_warn_string_init (TREE_TYPE (d), init);
1628 finish_decl (d, init_loc, init.value,
1629 init.original_type, asm_name);
1634 tree d = start_decl (declarator, specs, false,
1635 chainon (postfix_attrs,
1638 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1639 NULL_TREE, asm_name);
1641 if (c_parser_next_token_is_keyword (parser, RID_IN))
1644 *objc_foreach_object_declaration = d;
1646 *objc_foreach_object_declaration = error_mark_node;
1649 if (c_parser_next_token_is (parser, CPP_COMMA))
1651 c_parser_consume_token (parser);
1652 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1653 all_prefix_attrs = chainon (c_parser_attributes (parser),
1656 all_prefix_attrs = prefix_attrs;
1659 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1661 c_parser_consume_token (parser);
1664 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1666 /* This can only happen in Objective-C: we found the
1667 'in' that terminates the declaration inside an
1668 Objective-C foreach statement. Do not consume the
1669 token, so that the caller can use it to determine
1670 that this indeed is a foreach context. */
1675 c_parser_error (parser, "expected %<,%> or %<;%>");
1676 c_parser_skip_to_end_of_block_or_statement (parser);
1682 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1683 "%<asm%> or %<__attribute__%>");
1684 c_parser_skip_to_end_of_block_or_statement (parser);
1687 /* Function definition (nested or otherwise). */
1690 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1691 c_push_function_context ();
1693 if (!start_function (specs, declarator, all_prefix_attrs))
1695 /* This can appear in many cases looking nothing like a
1696 function definition, so we don't give a more specific
1697 error suggesting there was one. */
1698 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1699 "or %<__attribute__%>");
1701 c_pop_function_context ();
1704 /* Parse old-style parameter declarations. ??? Attributes are
1705 not allowed to start declaration specifiers here because of a
1706 syntax conflict between a function declaration with attribute
1707 suffix and a function definition with an attribute prefix on
1708 first old-style parameter declaration. Following the old
1709 parser, they are not accepted on subsequent old-style
1710 parameter declarations either. However, there is no
1711 ambiguity after the first declaration, nor indeed on the
1712 first as long as we don't allow postfix attributes after a
1713 declarator with a nonempty identifier list in a definition;
1714 and postfix attributes have never been accepted here in
1715 function definitions either. */
1716 while (c_parser_next_token_is_not (parser, CPP_EOF)
1717 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1718 c_parser_declaration_or_fndef (parser, false, false, false,
1720 store_parm_decls ();
1721 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1722 = c_parser_peek_token (parser)->location;
1723 fnbody = c_parser_compound_statement (parser);
1726 tree decl = current_function_decl;
1727 /* Mark nested functions as needing static-chain initially.
1728 lower_nested_functions will recompute it but the
1729 DECL_STATIC_CHAIN flag is also used before that happens,
1730 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1731 DECL_STATIC_CHAIN (decl) = 1;
1734 c_pop_function_context ();
1735 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1746 /* Parse an asm-definition (asm() outside a function body). This is a
1754 c_parser_asm_definition (c_parser *parser)
1756 tree asm_str = c_parser_simple_asm_expr (parser);
1758 cgraph_add_asm_node (asm_str);
1759 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1762 /* Parse a static assertion (C1X N1425 6.7.10).
1764 static_assert-declaration:
1765 static_assert-declaration-no-semi ;
1769 c_parser_static_assert_declaration (c_parser *parser)
1771 c_parser_static_assert_declaration_no_semi (parser);
1773 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1774 c_parser_skip_to_end_of_block_or_statement (parser);
1777 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1780 static_assert-declaration-no-semi:
1781 _Static_assert ( constant-expression , string-literal )
1785 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1787 location_t assert_loc, value_loc;
1791 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1792 assert_loc = c_parser_peek_token (parser)->location;
1796 pedwarn (assert_loc, OPT_pedantic,
1797 "ISO C99 does not support %<_Static_assert%>");
1799 pedwarn (assert_loc, OPT_pedantic,
1800 "ISO C90 does not support %<_Static_assert%>");
1802 c_parser_consume_token (parser);
1803 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1805 value_loc = c_parser_peek_token (parser)->location;
1806 value = c_parser_expr_no_commas (parser, NULL).value;
1807 parser->lex_untranslated_string = true;
1808 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1810 parser->lex_untranslated_string = false;
1813 switch (c_parser_peek_token (parser)->type)
1819 case CPP_UTF8STRING:
1820 string = c_parser_peek_token (parser)->value;
1821 c_parser_consume_token (parser);
1822 parser->lex_untranslated_string = false;
1825 c_parser_error (parser, "expected string literal");
1826 parser->lex_untranslated_string = false;
1829 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1831 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1833 error_at (value_loc, "expression in static assertion is not an integer");
1836 if (TREE_CODE (value) != INTEGER_CST)
1838 value = c_fully_fold (value, false, NULL);
1839 if (TREE_CODE (value) == INTEGER_CST)
1840 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1841 "is not an integer constant expression");
1843 if (TREE_CODE (value) != INTEGER_CST)
1845 error_at (value_loc, "expression in static assertion is not constant");
1848 constant_expression_warning (value);
1849 if (integer_zerop (value))
1850 error_at (assert_loc, "static assertion failed: %E", string);
1853 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1854 6.7), adding them to SPECS (which may already include some).
1855 Storage class specifiers are accepted iff SCSPEC_OK; type
1856 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1857 the start iff START_ATTR_OK.
1859 declaration-specifiers:
1860 storage-class-specifier declaration-specifiers[opt]
1861 type-specifier declaration-specifiers[opt]
1862 type-qualifier declaration-specifiers[opt]
1863 function-specifier declaration-specifiers[opt]
1865 Function specifiers (inline) are from C99, and are currently
1866 handled as storage class specifiers, as is __thread.
1868 C90 6.5.1, C99 6.7.1:
1869 storage-class-specifier:
1880 C90 6.5.2, C99 6.7.2:
1893 [_Imaginary removed in C99 TC2]
1894 struct-or-union-specifier
1898 (_Bool and _Complex are new in C99.)
1900 C90 6.5.3, C99 6.7.3:
1906 address-space-qualifier
1908 (restrict is new in C99.)
1912 declaration-specifiers:
1913 attributes declaration-specifiers[opt]
1919 identifier recognized by the target
1921 storage-class-specifier:
1934 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1935 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1940 class-name objc-protocol-refs[opt]
1941 typedef-name objc-protocol-refs
1946 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1947 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1948 enum c_lookahead_kind la)
1950 bool attrs_ok = start_attr_ok;
1951 bool seen_type = specs->typespec_kind != ctsk_none;
1954 gcc_assert (la == cla_prefer_id);
1956 while (c_parser_next_token_is (parser, CPP_NAME)
1957 || c_parser_next_token_is (parser, CPP_KEYWORD)
1958 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1960 struct c_typespec t;
1962 location_t loc = c_parser_peek_token (parser)->location;
1964 /* If we cannot accept a type, exit if the next token must start
1965 one. Also, if we already have seen a tagged definition,
1966 a typename would be an error anyway and likely the user
1967 has simply forgotten a semicolon, so we exit. */
1968 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1969 && c_parser_next_tokens_start_typename (parser, la)
1970 && !c_parser_next_token_is_qualifier (parser))
1973 if (c_parser_next_token_is (parser, CPP_NAME))
1975 tree value = c_parser_peek_token (parser)->value;
1976 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1978 if (kind == C_ID_ADDRSPACE)
1981 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1982 declspecs_add_addrspace (specs, as);
1983 c_parser_consume_token (parser);
1988 gcc_assert (!c_parser_next_token_is_qualifier (parser));
1990 /* If we cannot accept a type, and the next token must start one,
1991 exit. Do the same if we already have seen a tagged definition,
1992 since it would be an error anyway and likely the user has simply
1993 forgotten a semicolon. */
1994 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
1997 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
1998 a C_ID_CLASSNAME. */
1999 c_parser_consume_token (parser);
2002 if (kind == C_ID_ID)
2004 error ("unknown type name %qE", value);
2005 t.kind = ctsk_typedef;
2006 t.spec = error_mark_node;
2008 else if (kind == C_ID_TYPENAME
2009 && (!c_dialect_objc ()
2010 || c_parser_next_token_is_not (parser, CPP_LESS)))
2012 t.kind = ctsk_typedef;
2013 /* For a typedef name, record the meaning, not the name.
2014 In case of 'foo foo, bar;'. */
2015 t.spec = lookup_name (value);
2019 tree proto = NULL_TREE;
2020 gcc_assert (c_dialect_objc ());
2022 if (c_parser_next_token_is (parser, CPP_LESS))
2023 proto = c_parser_objc_protocol_refs (parser);
2024 t.spec = objc_get_protocol_qualified_type (value, proto);
2027 t.expr_const_operands = true;
2028 declspecs_add_type (loc, specs, t);
2031 if (c_parser_next_token_is (parser, CPP_LESS))
2033 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2034 nisse@lysator.liu.se. */
2036 gcc_assert (c_dialect_objc ());
2037 if (!typespec_ok || seen_type)
2039 proto = c_parser_objc_protocol_refs (parser);
2041 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2043 t.expr_const_operands = true;
2044 declspecs_add_type (loc, specs, t);
2047 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2048 switch (c_parser_peek_token (parser)->keyword)
2060 /* TODO: Distinguish between function specifiers (inline)
2061 and storage class specifiers, either here or in
2062 declspecs_add_scspec. */
2063 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2064 c_parser_consume_token (parser);
2088 if (c_dialect_objc ())
2089 parser->objc_need_raw_identifier = true;
2090 t.kind = ctsk_resword;
2091 t.spec = c_parser_peek_token (parser)->value;
2093 t.expr_const_operands = true;
2094 declspecs_add_type (loc, specs, t);
2095 c_parser_consume_token (parser);
2102 t = c_parser_enum_specifier (parser);
2103 declspecs_add_type (loc, specs, t);
2111 t = c_parser_struct_or_union_specifier (parser);
2112 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2113 declspecs_add_type (loc, specs, t);
2116 /* ??? The old parser rejected typeof after other type
2117 specifiers, but is a syntax error the best way of
2119 if (!typespec_ok || seen_type)
2123 t = c_parser_typeof_specifier (parser);
2124 declspecs_add_type (loc, specs, t);
2130 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2131 c_parser_consume_token (parser);
2136 attrs = c_parser_attributes (parser);
2137 declspecs_add_attrs (specs, attrs);
2146 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2149 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2150 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2151 enum attributes[opt] identifier
2153 The form with trailing comma is new in C99. The forms with
2154 attributes are GNU extensions. In GNU C, we accept any expression
2155 without commas in the syntax (assignment expressions, not just
2156 conditional expressions); assignment expressions will be diagnosed
2161 enumerator-list , enumerator
2164 enumeration-constant
2165 enumeration-constant = constant-expression
2168 static struct c_typespec
2169 c_parser_enum_specifier (c_parser *parser)
2171 struct c_typespec ret;
2173 tree ident = NULL_TREE;
2174 location_t enum_loc;
2175 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2176 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2177 enum_loc = c_parser_peek_token (parser)->location;
2178 c_parser_consume_token (parser);
2179 attrs = c_parser_attributes (parser);
2180 enum_loc = c_parser_peek_token (parser)->location;
2181 /* Set the location in case we create a decl now. */
2182 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2183 if (c_parser_next_token_is (parser, CPP_NAME))
2185 ident = c_parser_peek_token (parser)->value;
2186 ident_loc = c_parser_peek_token (parser)->location;
2187 enum_loc = ident_loc;
2188 c_parser_consume_token (parser);
2190 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2192 /* Parse an enum definition. */
2193 struct c_enum_contents the_enum;
2194 tree type = start_enum (enum_loc, &the_enum, ident);
2196 /* We chain the enumerators in reverse order, then put them in
2197 forward order at the end. */
2198 tree values = NULL_TREE;
2199 c_parser_consume_token (parser);
2207 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2208 location_t decl_loc, value_loc;
2209 if (c_parser_next_token_is_not (parser, CPP_NAME))
2211 c_parser_error (parser, "expected identifier");
2212 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2213 values = error_mark_node;
2216 token = c_parser_peek_token (parser);
2217 enum_id = token->value;
2218 /* Set the location in case we create a decl now. */
2219 c_parser_set_source_position_from_token (token);
2220 decl_loc = value_loc = token->location;
2221 c_parser_consume_token (parser);
2222 if (c_parser_next_token_is (parser, CPP_EQ))
2224 c_parser_consume_token (parser);
2225 value_loc = c_parser_peek_token (parser)->location;
2226 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2229 enum_value = NULL_TREE;
2230 enum_decl = build_enumerator (decl_loc, value_loc,
2231 &the_enum, enum_id, enum_value);
2232 TREE_CHAIN (enum_decl) = values;
2235 if (c_parser_next_token_is (parser, CPP_COMMA))
2237 comma_loc = c_parser_peek_token (parser)->location;
2239 c_parser_consume_token (parser);
2241 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2243 if (seen_comma && !flag_isoc99)
2244 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2245 c_parser_consume_token (parser);
2250 c_parser_error (parser, "expected %<,%> or %<}%>");
2251 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2252 values = error_mark_node;
2256 postfix_attrs = c_parser_attributes (parser);
2257 ret.spec = finish_enum (type, nreverse (values),
2258 chainon (attrs, postfix_attrs));
2259 ret.kind = ctsk_tagdef;
2260 ret.expr = NULL_TREE;
2261 ret.expr_const_operands = true;
2266 c_parser_error (parser, "expected %<{%>");
2267 ret.spec = error_mark_node;
2268 ret.kind = ctsk_tagref;
2269 ret.expr = NULL_TREE;
2270 ret.expr_const_operands = true;
2273 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2274 /* In ISO C, enumerated types can be referred to only if already
2276 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2279 pedwarn (enum_loc, OPT_pedantic,
2280 "ISO C forbids forward references to %<enum%> types");
2285 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2287 struct-or-union-specifier:
2288 struct-or-union attributes[opt] identifier[opt]
2289 { struct-contents } attributes[opt]
2290 struct-or-union attributes[opt] identifier
2293 struct-declaration-list
2295 struct-declaration-list:
2296 struct-declaration ;
2297 struct-declaration-list struct-declaration ;
2304 struct-declaration-list struct-declaration
2306 struct-declaration-list:
2307 struct-declaration-list ;
2310 (Note that in the syntax here, unlike that in ISO C, the semicolons
2311 are included here rather than in struct-declaration, in order to
2312 describe the syntax with extra semicolons and missing semicolon at
2317 struct-declaration-list:
2318 @defs ( class-name )
2320 (Note this does not include a trailing semicolon, but can be
2321 followed by further declarations, and gets a pedwarn-if-pedantic
2322 when followed by a semicolon.) */
2324 static struct c_typespec
2325 c_parser_struct_or_union_specifier (c_parser *parser)
2327 struct c_typespec ret;
2329 tree ident = NULL_TREE;
2330 location_t struct_loc;
2331 location_t ident_loc = UNKNOWN_LOCATION;
2332 enum tree_code code;
2333 switch (c_parser_peek_token (parser)->keyword)
2344 struct_loc = c_parser_peek_token (parser)->location;
2345 c_parser_consume_token (parser);
2346 attrs = c_parser_attributes (parser);
2348 /* Set the location in case we create a decl now. */
2349 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2351 if (c_parser_next_token_is (parser, CPP_NAME))
2353 ident = c_parser_peek_token (parser)->value;
2354 ident_loc = c_parser_peek_token (parser)->location;
2355 struct_loc = ident_loc;
2356 c_parser_consume_token (parser);
2358 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2360 /* Parse a struct or union definition. Start the scope of the
2361 tag before parsing components. */
2362 struct c_struct_parse_info *struct_info;
2363 tree type = start_struct (struct_loc, code, ident, &struct_info);
2365 /* We chain the components in reverse order, then put them in
2366 forward order at the end. Each struct-declaration may
2367 declare multiple components (comma-separated), so we must use
2368 chainon to join them, although when parsing each
2369 struct-declaration we can use TREE_CHAIN directly.
2371 The theory behind all this is that there will be more
2372 semicolon separated fields than comma separated fields, and
2373 so we'll be minimizing the number of node traversals required
2375 tree contents = NULL_TREE;
2376 c_parser_consume_token (parser);
2377 /* Handle the Objective-C @defs construct,
2378 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2379 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2382 gcc_assert (c_dialect_objc ());
2383 c_parser_consume_token (parser);
2384 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2386 if (c_parser_next_token_is (parser, CPP_NAME)
2387 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2389 name = c_parser_peek_token (parser)->value;
2390 c_parser_consume_token (parser);
2394 c_parser_error (parser, "expected class name");
2395 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2400 contents = nreverse (objc_get_class_ivars (name));
2403 /* Parse the struct-declarations and semicolons. Problems with
2404 semicolons are diagnosed here; empty structures are diagnosed
2409 /* Parse any stray semicolon. */
2410 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2412 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2413 "extra semicolon in struct or union specified");
2414 c_parser_consume_token (parser);
2417 /* Stop if at the end of the struct or union contents. */
2418 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2420 c_parser_consume_token (parser);
2423 /* Accept #pragmas at struct scope. */
2424 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2426 c_parser_pragma (parser, pragma_external);
2429 /* Parse some comma-separated declarations, but not the
2430 trailing semicolon if any. */
2431 decls = c_parser_struct_declaration (parser);
2432 contents = chainon (decls, contents);
2433 /* If no semicolon follows, either we have a parse error or
2434 are at the end of the struct or union and should
2436 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2437 c_parser_consume_token (parser);
2440 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2441 pedwarn (c_parser_peek_token (parser)->location, 0,
2442 "no semicolon at end of struct or union");
2443 else if (parser->error
2444 || !c_parser_next_token_starts_declspecs (parser))
2446 c_parser_error (parser, "expected %<;%>");
2447 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2451 /* If we come here, we have already emitted an error
2452 for an expected `;', identifier or `(', and we also
2453 recovered already. Go on with the next field. */
2456 postfix_attrs = c_parser_attributes (parser);
2457 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2458 chainon (attrs, postfix_attrs), struct_info);
2459 ret.kind = ctsk_tagdef;
2460 ret.expr = NULL_TREE;
2461 ret.expr_const_operands = true;
2466 c_parser_error (parser, "expected %<{%>");
2467 ret.spec = error_mark_node;
2468 ret.kind = ctsk_tagref;
2469 ret.expr = NULL_TREE;
2470 ret.expr_const_operands = true;
2473 ret = parser_xref_tag (ident_loc, code, ident);
2477 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2478 the trailing semicolon.
2481 specifier-qualifier-list struct-declarator-list
2482 static_assert-declaration-no-semi
2484 specifier-qualifier-list:
2485 type-specifier specifier-qualifier-list[opt]
2486 type-qualifier specifier-qualifier-list[opt]
2487 attributes specifier-qualifier-list[opt]
2489 struct-declarator-list:
2491 struct-declarator-list , attributes[opt] struct-declarator
2494 declarator attributes[opt]
2495 declarator[opt] : constant-expression attributes[opt]
2500 __extension__ struct-declaration
2501 specifier-qualifier-list
2503 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2504 of attributes where shown is a GNU extension. In GNU C, we accept
2505 any expression without commas in the syntax (assignment
2506 expressions, not just conditional expressions); assignment
2507 expressions will be diagnosed as non-constant. */
2510 c_parser_struct_declaration (c_parser *parser)
2512 struct c_declspecs *specs;
2514 tree all_prefix_attrs;
2516 location_t decl_loc;
2517 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2521 ext = disable_extension_diagnostics ();
2522 c_parser_consume_token (parser);
2523 decl = c_parser_struct_declaration (parser);
2524 restore_extension_diagnostics (ext);
2527 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2529 c_parser_static_assert_declaration_no_semi (parser);
2532 specs = build_null_declspecs ();
2533 decl_loc = c_parser_peek_token (parser)->location;
2534 c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2537 if (!specs->declspecs_seen_p)
2539 c_parser_error (parser, "expected specifier-qualifier-list");
2542 finish_declspecs (specs);
2543 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2544 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2547 if (specs->typespec_kind == ctsk_none)
2549 pedwarn (decl_loc, OPT_pedantic,
2550 "ISO C forbids member declarations with no members");
2551 shadow_tag_warned (specs, pedantic);
2556 /* Support for unnamed structs or unions as members of
2557 structs or unions (which is [a] useful and [b] supports
2561 ret = grokfield (c_parser_peek_token (parser)->location,
2562 build_id_declarator (NULL_TREE), specs,
2565 decl_attributes (&ret, attrs, 0);
2570 /* Provide better error recovery. Note that a type name here is valid,
2571 and will be treated as a field name. */
2572 if (specs->typespec_kind == ctsk_tagdef
2573 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2574 && c_parser_next_token_starts_declspecs (parser)
2575 && !c_parser_next_token_is (parser, CPP_NAME))
2577 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2578 parser->error = false;
2582 pending_xref_error ();
2583 prefix_attrs = specs->attrs;
2584 all_prefix_attrs = prefix_attrs;
2585 specs->attrs = NULL_TREE;
2589 /* Declaring one or more declarators or un-named bit-fields. */
2590 struct c_declarator *declarator;
2592 if (c_parser_next_token_is (parser, CPP_COLON))
2593 declarator = build_id_declarator (NULL_TREE);
2595 declarator = c_parser_declarator (parser,
2596 specs->typespec_kind != ctsk_none,
2597 C_DTR_NORMAL, &dummy);
2598 if (declarator == NULL)
2600 c_parser_skip_to_end_of_block_or_statement (parser);
2603 if (c_parser_next_token_is (parser, CPP_COLON)
2604 || c_parser_next_token_is (parser, CPP_COMMA)
2605 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2606 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2607 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2609 tree postfix_attrs = NULL_TREE;
2610 tree width = NULL_TREE;
2612 if (c_parser_next_token_is (parser, CPP_COLON))
2614 c_parser_consume_token (parser);
2615 width = c_parser_expr_no_commas (parser, NULL).value;
2617 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2618 postfix_attrs = c_parser_attributes (parser);
2619 d = grokfield (c_parser_peek_token (parser)->location,
2620 declarator, specs, width, &all_prefix_attrs);
2621 decl_attributes (&d, chainon (postfix_attrs,
2622 all_prefix_attrs), 0);
2623 DECL_CHAIN (d) = decls;
2625 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2626 all_prefix_attrs = chainon (c_parser_attributes (parser),
2629 all_prefix_attrs = prefix_attrs;
2630 if (c_parser_next_token_is (parser, CPP_COMMA))
2631 c_parser_consume_token (parser);
2632 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2633 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2635 /* Semicolon consumed in caller. */
2640 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2646 c_parser_error (parser,
2647 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2648 "%<__attribute__%>");
2655 /* Parse a typeof specifier (a GNU extension).
2658 typeof ( expression )
2659 typeof ( type-name )
2662 static struct c_typespec
2663 c_parser_typeof_specifier (c_parser *parser)
2665 struct c_typespec ret;
2666 ret.kind = ctsk_typeof;
2667 ret.spec = error_mark_node;
2668 ret.expr = NULL_TREE;
2669 ret.expr_const_operands = true;
2670 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2671 c_parser_consume_token (parser);
2672 c_inhibit_evaluation_warnings++;
2674 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2676 c_inhibit_evaluation_warnings--;
2680 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2682 struct c_type_name *type = c_parser_type_name (parser);
2683 c_inhibit_evaluation_warnings--;
2687 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2688 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2694 location_t here = c_parser_peek_token (parser)->location;
2695 struct c_expr expr = c_parser_expression (parser);
2696 c_inhibit_evaluation_warnings--;
2698 if (TREE_CODE (expr.value) == COMPONENT_REF
2699 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2700 error_at (here, "%<typeof%> applied to a bit-field");
2701 mark_exp_read (expr.value);
2702 ret.spec = TREE_TYPE (expr.value);
2703 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2704 /* This is returned with the type so that when the type is
2705 evaluated, this can be evaluated. */
2707 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2708 pop_maybe_used (was_vm);
2710 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2714 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2715 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2716 be redeclared; otherwise it may not. KIND indicates which kind of
2717 declarator is wanted. Returns a valid declarator except in the
2718 case of a syntax error in which case NULL is returned. *SEEN_ID is
2719 set to true if an identifier being declared is seen; this is used
2720 to diagnose bad forms of abstract array declarators and to
2721 determine whether an identifier list is syntactically permitted.
2724 pointer[opt] direct-declarator
2728 ( attributes[opt] declarator )
2729 direct-declarator array-declarator
2730 direct-declarator ( parameter-type-list )
2731 direct-declarator ( identifier-list[opt] )
2734 * type-qualifier-list[opt]
2735 * type-qualifier-list[opt] pointer
2737 type-qualifier-list:
2740 type-qualifier-list type-qualifier
2741 type-qualifier-list attributes
2743 parameter-type-list:
2745 parameter-list , ...
2748 parameter-declaration
2749 parameter-list , parameter-declaration
2751 parameter-declaration:
2752 declaration-specifiers declarator attributes[opt]
2753 declaration-specifiers abstract-declarator[opt] attributes[opt]
2757 identifier-list , identifier
2759 abstract-declarator:
2761 pointer[opt] direct-abstract-declarator
2763 direct-abstract-declarator:
2764 ( attributes[opt] abstract-declarator )
2765 direct-abstract-declarator[opt] array-declarator
2766 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2771 direct-declarator ( parameter-forward-declarations
2772 parameter-type-list[opt] )
2774 direct-abstract-declarator:
2775 direct-abstract-declarator[opt] ( parameter-forward-declarations
2776 parameter-type-list[opt] )
2778 parameter-forward-declarations:
2780 parameter-forward-declarations parameter-list ;
2782 The uses of attributes shown above are GNU extensions.
2784 Some forms of array declarator are not included in C99 in the
2785 syntax for abstract declarators; these are disallowed elsewhere.
2786 This may be a defect (DR#289).
2788 This function also accepts an omitted abstract declarator as being
2789 an abstract declarator, although not part of the formal syntax. */
2791 static struct c_declarator *
2792 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2795 /* Parse any initial pointer part. */
2796 if (c_parser_next_token_is (parser, CPP_MULT))
2798 struct c_declspecs *quals_attrs = build_null_declspecs ();
2799 struct c_declarator *inner;
2800 c_parser_consume_token (parser);
2801 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2802 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2806 return make_pointer_declarator (quals_attrs, inner);
2808 /* Now we have a direct declarator, direct abstract declarator or
2809 nothing (which counts as a direct abstract declarator here). */
2810 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2813 /* Parse a direct declarator or direct abstract declarator; arguments
2814 as c_parser_declarator. */
2816 static struct c_declarator *
2817 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2820 /* The direct declarator must start with an identifier (possibly
2821 omitted) or a parenthesized declarator (possibly abstract). In
2822 an ordinary declarator, initial parentheses must start a
2823 parenthesized declarator. In an abstract declarator or parameter
2824 declarator, they could start a parenthesized declarator or a
2825 parameter list. To tell which, the open parenthesis and any
2826 following attributes must be read. If a declaration specifier
2827 follows, then it is a parameter list; if the specifier is a
2828 typedef name, there might be an ambiguity about redeclaring it,
2829 which is resolved in the direction of treating it as a typedef
2830 name. If a close parenthesis follows, it is also an empty
2831 parameter list, as the syntax does not permit empty abstract
2832 declarators. Otherwise, it is a parenthesized declarator (in
2833 which case the analysis may be repeated inside it, recursively).
2835 ??? There is an ambiguity in a parameter declaration "int
2836 (__attribute__((foo)) x)", where x is not a typedef name: it
2837 could be an abstract declarator for a function, or declare x with
2838 parentheses. The proper resolution of this ambiguity needs
2839 documenting. At present we follow an accident of the old
2840 parser's implementation, whereby the first parameter must have
2841 some declaration specifiers other than just attributes. Thus as
2842 a parameter declaration it is treated as a parenthesized
2843 parameter named x, and as an abstract declarator it is
2846 ??? Also following the old parser, attributes inside an empty
2847 parameter list are ignored, making it a list not yielding a
2848 prototype, rather than giving an error or making it have one
2849 parameter with implicit type int.
2851 ??? Also following the old parser, typedef names may be
2852 redeclared in declarators, but not Objective-C class names. */
2854 if (kind != C_DTR_ABSTRACT
2855 && c_parser_next_token_is (parser, CPP_NAME)
2857 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2858 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2859 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2861 struct c_declarator *inner
2862 = build_id_declarator (c_parser_peek_token (parser)->value);
2864 inner->id_loc = c_parser_peek_token (parser)->location;
2865 c_parser_consume_token (parser);
2866 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2869 if (kind != C_DTR_NORMAL
2870 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2872 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2873 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2876 /* Either we are at the end of an abstract declarator, or we have
2879 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2882 struct c_declarator *inner;
2883 c_parser_consume_token (parser);
2884 attrs = c_parser_attributes (parser);
2885 if (kind != C_DTR_NORMAL
2886 && (c_parser_next_token_starts_declspecs (parser)
2887 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2889 struct c_arg_info *args
2890 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2897 = build_function_declarator (args,
2898 build_id_declarator (NULL_TREE));
2899 return c_parser_direct_declarator_inner (parser, *seen_id,
2903 /* A parenthesized declarator. */
2904 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2905 if (inner != NULL && attrs != NULL)
2906 inner = build_attrs_declarator (attrs, inner);
2907 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2909 c_parser_consume_token (parser);
2913 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2917 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2924 if (kind == C_DTR_NORMAL)
2926 c_parser_error (parser, "expected identifier or %<(%>");
2930 return build_id_declarator (NULL_TREE);
2934 /* Parse part of a direct declarator or direct abstract declarator,
2935 given that some (in INNER) has already been parsed; ID_PRESENT is
2936 true if an identifier is present, false for an abstract
2939 static struct c_declarator *
2940 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2941 struct c_declarator *inner)
2943 /* Parse a sequence of array declarators and parameter lists. */
2944 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2946 location_t brace_loc = c_parser_peek_token (parser)->location;
2947 struct c_declarator *declarator;
2948 struct c_declspecs *quals_attrs = build_null_declspecs ();
2952 c_parser_consume_token (parser);
2953 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2954 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2956 c_parser_consume_token (parser);
2957 if (static_seen && !quals_attrs->declspecs_seen_p)
2958 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2959 if (!quals_attrs->declspecs_seen_p)
2961 /* If "static" is present, there must be an array dimension.
2962 Otherwise, there may be a dimension, "*", or no
2967 dimen = c_parser_expr_no_commas (parser, NULL).value;
2971 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2976 else if (c_parser_next_token_is (parser, CPP_MULT))
2978 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2982 c_parser_consume_token (parser);
2987 dimen = c_parser_expr_no_commas (parser, NULL).value;
2993 dimen = c_parser_expr_no_commas (parser, NULL).value;
2996 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2997 c_parser_consume_token (parser);
3000 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3005 mark_exp_read (dimen);
3006 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3007 static_seen, star_seen);
3008 if (declarator == NULL)
3010 inner = set_array_declarator_inner (declarator, inner);
3011 return c_parser_direct_declarator_inner (parser, id_present, inner);
3013 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3016 struct c_arg_info *args;
3017 c_parser_consume_token (parser);
3018 attrs = c_parser_attributes (parser);
3019 args = c_parser_parms_declarator (parser, id_present, attrs);
3024 inner = build_function_declarator (args, inner);
3025 return c_parser_direct_declarator_inner (parser, id_present, inner);
3031 /* Parse a parameter list or identifier list, including the closing
3032 parenthesis but not the opening one. ATTRS are the attributes at
3033 the start of the list. ID_LIST_OK is true if an identifier list is
3034 acceptable; such a list must not have attributes at the start. */
3036 static struct c_arg_info *
3037 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3040 declare_parm_level ();
3041 /* If the list starts with an identifier, it is an identifier list.
3042 Otherwise, it is either a prototype list or an empty list. */
3045 && c_parser_next_token_is (parser, CPP_NAME)
3046 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3048 /* Look ahead to detect typos in type names. */
3049 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3050 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3051 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3052 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3054 tree list = NULL_TREE, *nextp = &list;
3055 while (c_parser_next_token_is (parser, CPP_NAME)
3056 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3058 *nextp = build_tree_list (NULL_TREE,
3059 c_parser_peek_token (parser)->value);
3060 nextp = & TREE_CHAIN (*nextp);
3061 c_parser_consume_token (parser);
3062 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3064 c_parser_consume_token (parser);
3065 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3067 c_parser_error (parser, "expected identifier");
3071 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3073 struct c_arg_info *ret = build_arg_info ();
3075 c_parser_consume_token (parser);
3081 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3089 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
3095 /* Parse a parameter list (possibly empty), including the closing
3096 parenthesis but not the opening one. ATTRS are the attributes at
3097 the start of the list. */
3099 static struct c_arg_info *
3100 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
3102 bool bad_parm = false;
3103 /* ??? Following the old parser, forward parameter declarations may
3104 use abstract declarators, and if no real parameter declarations
3105 follow the forward declarations then this is not diagnosed. Also
3106 note as above that attributes are ignored as the only contents of
3107 the parentheses, or as the only contents after forward
3109 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3111 struct c_arg_info *ret = build_arg_info ();
3112 c_parser_consume_token (parser);
3115 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3117 struct c_arg_info *ret = build_arg_info ();
3118 /* Suppress -Wold-style-definition for this case. */
3119 ret->types = error_mark_node;
3120 error_at (c_parser_peek_token (parser)->location,
3121 "ISO C requires a named argument before %<...%>");
3122 c_parser_consume_token (parser);
3123 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3125 c_parser_consume_token (parser);
3130 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3135 /* Nonempty list of parameters, either terminated with semicolon
3136 (forward declarations; recurse) or with close parenthesis (normal
3137 function) or with ", ... )" (variadic function). */
3140 /* Parse a parameter. */
3141 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3146 push_parm_decl (parm);
3147 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3150 c_parser_consume_token (parser);
3151 mark_forward_parm_decls ();
3152 new_attrs = c_parser_attributes (parser);
3153 return c_parser_parms_list_declarator (parser, new_attrs);
3155 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3157 c_parser_consume_token (parser);
3160 get_pending_sizes ();
3164 return get_parm_info (false);
3166 if (!c_parser_require (parser, CPP_COMMA,
3167 "expected %<;%>, %<,%> or %<)%>"))
3169 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3170 get_pending_sizes ();
3173 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3175 c_parser_consume_token (parser);
3176 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3178 c_parser_consume_token (parser);
3181 get_pending_sizes ();
3185 return get_parm_info (true);
3189 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3191 get_pending_sizes ();
3198 /* Parse a parameter declaration. ATTRS are the attributes at the
3199 start of the declaration if it is the first parameter. */
3201 static struct c_parm *
3202 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3204 struct c_declspecs *specs;
3205 struct c_declarator *declarator;
3207 tree postfix_attrs = NULL_TREE;
3209 if (!c_parser_next_token_starts_declspecs (parser))
3211 c_token *token = c_parser_peek_token (parser);
3214 c_parser_set_source_position_from_token (token);
3215 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3217 error ("unknown type name %qE", token->value);
3218 parser->error = true;
3220 /* ??? In some Objective-C cases '...' isn't applicable so there
3221 should be a different message. */
3223 c_parser_error (parser,
3224 "expected declaration specifiers or %<...%>");
3225 c_parser_skip_to_end_of_parameter (parser);
3228 specs = build_null_declspecs ();
3231 declspecs_add_attrs (specs, attrs);
3234 c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3235 finish_declspecs (specs);
3236 pending_xref_error ();
3237 prefix_attrs = specs->attrs;
3238 specs->attrs = NULL_TREE;
3239 declarator = c_parser_declarator (parser,
3240 specs->typespec_kind != ctsk_none,
3241 C_DTR_PARM, &dummy);
3242 if (declarator == NULL)
3244 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3247 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3248 postfix_attrs = c_parser_attributes (parser);
3249 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3253 /* Parse a string literal in an asm expression. It should not be
3254 translated, and wide string literals are an error although
3255 permitted by the syntax. This is a GNU extension.
3260 ??? At present, following the old parser, the caller needs to have
3261 set lex_untranslated_string to 1. It would be better to follow the
3262 C++ parser rather than using this kludge. */
3265 c_parser_asm_string_literal (c_parser *parser)
3268 if (c_parser_next_token_is (parser, CPP_STRING))
3270 str = c_parser_peek_token (parser)->value;
3271 c_parser_consume_token (parser);
3273 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3275 error_at (c_parser_peek_token (parser)->location,
3276 "wide string literal in %<asm%>");
3277 str = build_string (1, "");
3278 c_parser_consume_token (parser);
3282 c_parser_error (parser, "expected string literal");
3288 /* Parse a simple asm expression. This is used in restricted
3289 contexts, where a full expression with inputs and outputs does not
3290 make sense. This is a GNU extension.
3293 asm ( asm-string-literal )
3297 c_parser_simple_asm_expr (c_parser *parser)
3300 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3301 /* ??? Follow the C++ parser rather than using the
3302 lex_untranslated_string kludge. */
3303 parser->lex_untranslated_string = true;
3304 c_parser_consume_token (parser);
3305 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3307 parser->lex_untranslated_string = false;
3310 str = c_parser_asm_string_literal (parser);
3311 parser->lex_untranslated_string = false;
3312 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3314 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3320 /* Parse (possibly empty) attributes. This is a GNU extension.
3324 attributes attribute
3327 __attribute__ ( ( attribute-list ) )
3331 attribute_list , attrib
3336 any-word ( identifier )
3337 any-word ( identifier , nonempty-expr-list )
3338 any-word ( expr-list )
3340 where the "identifier" must not be declared as a type, and
3341 "any-word" may be any identifier (including one declared as a
3342 type), a reserved word storage class specifier, type specifier or
3343 type qualifier. ??? This still leaves out most reserved keywords
3344 (following the old parser), shouldn't we include them, and why not
3345 allow identifiers declared as types to start the arguments? */
3348 c_parser_attributes (c_parser *parser)
3350 tree attrs = NULL_TREE;
3351 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3353 /* ??? Follow the C++ parser rather than using the
3354 lex_untranslated_string kludge. */
3355 parser->lex_untranslated_string = true;
3356 c_parser_consume_token (parser);
3357 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3359 parser->lex_untranslated_string = false;
3362 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3364 parser->lex_untranslated_string = false;
3365 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3368 /* Parse the attribute list. */
3369 while (c_parser_next_token_is (parser, CPP_COMMA)
3370 || c_parser_next_token_is (parser, CPP_NAME)
3371 || c_parser_next_token_is (parser, CPP_KEYWORD))
3373 tree attr, attr_name, attr_args;
3374 VEC(tree,gc) *expr_list;
3375 if (c_parser_next_token_is (parser, CPP_COMMA))
3377 c_parser_consume_token (parser);
3380 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3382 /* ??? See comment above about what keywords are
3385 switch (c_parser_peek_token (parser)->keyword)
3423 /* Accept __attribute__((__const)) as __attribute__((const))
3426 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3429 attr_name = c_parser_peek_token (parser)->value;
3430 c_parser_consume_token (parser);
3431 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3433 attr = build_tree_list (attr_name, NULL_TREE);
3434 attrs = chainon (attrs, attr);
3437 c_parser_consume_token (parser);
3438 /* Parse the attribute contents. If they start with an
3439 identifier which is followed by a comma or close
3440 parenthesis, then the arguments start with that
3441 identifier; otherwise they are an expression list.
3442 In objective-c the identifier may be a classname. */
3443 if (c_parser_next_token_is (parser, CPP_NAME)
3444 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3445 || (c_dialect_objc ()
3446 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3447 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3448 || (c_parser_peek_2nd_token (parser)->type
3449 == CPP_CLOSE_PAREN)))
3451 tree arg1 = c_parser_peek_token (parser)->value;
3452 c_parser_consume_token (parser);
3453 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3454 attr_args = build_tree_list (NULL_TREE, arg1);
3458 c_parser_consume_token (parser);
3459 expr_list = c_parser_expr_list (parser, false, true, NULL);
3460 tree_list = build_tree_list_vec (expr_list);
3461 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3462 release_tree_vector (expr_list);
3467 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3468 attr_args = NULL_TREE;
3471 expr_list = c_parser_expr_list (parser, false, true, NULL);
3472 attr_args = build_tree_list_vec (expr_list);
3473 release_tree_vector (expr_list);
3476 attr = build_tree_list (attr_name, attr_args);
3477 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3478 c_parser_consume_token (parser);
3481 parser->lex_untranslated_string = false;
3482 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3486 attrs = chainon (attrs, attr);
3488 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3489 c_parser_consume_token (parser);
3492 parser->lex_untranslated_string = false;
3493 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3497 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3498 c_parser_consume_token (parser);
3501 parser->lex_untranslated_string = false;
3502 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3506 parser->lex_untranslated_string = false;
3511 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3514 specifier-qualifier-list abstract-declarator[opt]
3517 static struct c_type_name *
3518 c_parser_type_name (c_parser *parser)
3520 struct c_declspecs *specs = build_null_declspecs ();
3521 struct c_declarator *declarator;
3522 struct c_type_name *ret;
3524 c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3525 if (!specs->declspecs_seen_p)
3527 c_parser_error (parser, "expected specifier-qualifier-list");
3530 if (specs->type != error_mark_node)
3532 pending_xref_error ();
3533 finish_declspecs (specs);
3535 declarator = c_parser_declarator (parser,
3536 specs->typespec_kind != ctsk_none,
3537 C_DTR_ABSTRACT, &dummy);
3538 if (declarator == NULL)
3540 ret = XOBNEW (&parser_obstack, struct c_type_name);
3542 ret->declarator = declarator;
3546 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3549 assignment-expression
3550 { initializer-list }
3551 { initializer-list , }
3554 designation[opt] initializer
3555 initializer-list , designation[opt] initializer
3562 designator-list designator
3569 [ constant-expression ]
3581 [ constant-expression ... constant-expression ]
3583 Any expression without commas is accepted in the syntax for the
3584 constant-expressions, with non-constant expressions rejected later.
3586 This function is only used for top-level initializers; for nested
3587 ones, see c_parser_initval. */
3589 static struct c_expr
3590 c_parser_initializer (c_parser *parser)
3592 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3593 return c_parser_braced_init (parser, NULL_TREE, false);
3597 location_t loc = c_parser_peek_token (parser)->location;
3598 ret = c_parser_expr_no_commas (parser, NULL);
3599 if (TREE_CODE (ret.value) != STRING_CST
3600 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3601 ret = default_function_array_read_conversion (loc, ret);
3606 /* Parse a braced initializer list. TYPE is the type specified for a
3607 compound literal, and NULL_TREE for other initializers and for
3608 nested braced lists. NESTED_P is true for nested braced lists,
3609 false for the list of a compound literal or the list that is the
3610 top-level initializer in a declaration. */
3612 static struct c_expr
3613 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3616 struct obstack braced_init_obstack;
3617 location_t brace_loc = c_parser_peek_token (parser)->location;
3618 gcc_obstack_init (&braced_init_obstack);
3619 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3620 c_parser_consume_token (parser);
3622 push_init_level (0, &braced_init_obstack);
3624 really_start_incremental_init (type);
3625 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3627 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3631 /* Parse a non-empty initializer list, possibly with a trailing
3635 c_parser_initelt (parser, &braced_init_obstack);
3638 if (c_parser_next_token_is (parser, CPP_COMMA))
3639 c_parser_consume_token (parser);
3642 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3646 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3648 ret.value = error_mark_node;
3649 ret.original_code = ERROR_MARK;
3650 ret.original_type = NULL;
3651 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3652 pop_init_level (0, &braced_init_obstack);
3653 obstack_free (&braced_init_obstack, NULL);
3656 c_parser_consume_token (parser);
3657 ret = pop_init_level (0, &braced_init_obstack);
3658 obstack_free (&braced_init_obstack, NULL);
3662 /* Parse a nested initializer, including designators. */
3665 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3667 /* Parse any designator or designator list. A single array
3668 designator may have the subsequent "=" omitted in GNU C, but a
3669 longer list or a structure member designator may not. */
3670 if (c_parser_next_token_is (parser, CPP_NAME)
3671 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3673 /* Old-style structure member designator. */
3674 set_init_label (c_parser_peek_token (parser)->value,
3675 braced_init_obstack);
3676 /* Use the colon as the error location. */
3677 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3678 "obsolete use of designated initializer with %<:%>");
3679 c_parser_consume_token (parser);
3680 c_parser_consume_token (parser);
3684 /* des_seen is 0 if there have been no designators, 1 if there
3685 has been a single array designator and 2 otherwise. */
3687 /* Location of a designator. */
3688 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3689 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3690 || c_parser_next_token_is (parser, CPP_DOT))
3692 int des_prev = des_seen;
3694 des_loc = c_parser_peek_token (parser)->location;
3697 if (c_parser_next_token_is (parser, CPP_DOT))
3700 c_parser_consume_token (parser);
3701 if (c_parser_next_token_is (parser, CPP_NAME))
3703 set_init_label (c_parser_peek_token (parser)->value,
3704 braced_init_obstack);
3705 c_parser_consume_token (parser);
3710 init.value = error_mark_node;
3711 init.original_code = ERROR_MARK;
3712 init.original_type = NULL;
3713 c_parser_error (parser, "expected identifier");
3714 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3715 process_init_element (init, false, braced_init_obstack);
3722 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3723 /* ??? Following the old parser, [ objc-receiver
3724 objc-message-args ] is accepted as an initializer,
3725 being distinguished from a designator by what follows
3726 the first assignment expression inside the square
3727 brackets, but after a first array designator a
3728 subsequent square bracket is for Objective-C taken to
3729 start an expression, using the obsolete form of
3730 designated initializer without '=', rather than
3731 possibly being a second level of designation: in LALR
3732 terms, the '[' is shifted rather than reducing
3733 designator to designator-list. */
3734 if (des_prev == 1 && c_dialect_objc ())
3736 des_seen = des_prev;
3739 if (des_prev == 0 && c_dialect_objc ())
3741 /* This might be an array designator or an
3742 Objective-C message expression. If the former,
3743 continue parsing here; if the latter, parse the
3744 remainder of the initializer given the starting
3745 primary-expression. ??? It might make sense to
3746 distinguish when des_prev == 1 as well; see
3747 previous comment. */
3749 struct c_expr mexpr;
3750 c_parser_consume_token (parser);
3751 if (c_parser_peek_token (parser)->type == CPP_NAME
3752 && ((c_parser_peek_token (parser)->id_kind
3754 || (c_parser_peek_token (parser)->id_kind
3755 == C_ID_CLASSNAME)))
3757 /* Type name receiver. */
3758 tree id = c_parser_peek_token (parser)->value;
3759 c_parser_consume_token (parser);
3760 rec = objc_get_class_reference (id);
3761 goto parse_message_args;
3763 first = c_parser_expr_no_commas (parser, NULL).value;
3764 mark_exp_read (first);
3765 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3766 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3767 goto array_desig_after_first;
3768 /* Expression receiver. So far only one part
3769 without commas has been parsed; there might be
3770 more of the expression. */
3772 while (c_parser_next_token_is (parser, CPP_COMMA))
3775 location_t comma_loc, exp_loc;
3776 comma_loc = c_parser_peek_token (parser)->location;
3777 c_parser_consume_token (parser);
3778 exp_loc = c_parser_peek_token (parser)->location;
3779 next = c_parser_expr_no_commas (parser, NULL);
3780 next = default_function_array_read_conversion (exp_loc,
3782 rec = build_compound_expr (comma_loc, rec, next.value);
3785 /* Now parse the objc-message-args. */
3786 args = c_parser_objc_message_args (parser);
3787 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3790 = objc_build_message_expr (build_tree_list (rec, args));
3791 mexpr.original_code = ERROR_MARK;
3792 mexpr.original_type = NULL;
3793 /* Now parse and process the remainder of the
3794 initializer, starting with this message
3795 expression as a primary-expression. */
3796 c_parser_initval (parser, &mexpr, braced_init_obstack);
3799 c_parser_consume_token (parser);
3800 first = c_parser_expr_no_commas (parser, NULL).value;
3801 mark_exp_read (first);
3802 array_desig_after_first:
3803 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3805 ellipsis_loc = c_parser_peek_token (parser)->location;
3806 c_parser_consume_token (parser);
3807 second = c_parser_expr_no_commas (parser, NULL).value;
3808 mark_exp_read (second);
3812 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3814 c_parser_consume_token (parser);
3815 set_init_index (first, second, braced_init_obstack);
3817 pedwarn (ellipsis_loc, OPT_pedantic,
3818 "ISO C forbids specifying range of elements to initialize");
3821 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3827 if (c_parser_next_token_is (parser, CPP_EQ))
3830 pedwarn (des_loc, OPT_pedantic,
3831 "ISO C90 forbids specifying subobject to initialize");
3832 c_parser_consume_token (parser);
3837 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3838 "obsolete use of designated initializer without %<=%>");
3842 init.value = error_mark_node;
3843 init.original_code = ERROR_MARK;
3844 init.original_type = NULL;
3845 c_parser_error (parser, "expected %<=%>");
3846 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3847 process_init_element (init, false, braced_init_obstack);
3853 c_parser_initval (parser, NULL, braced_init_obstack);
3856 /* Parse a nested initializer; as c_parser_initializer but parses
3857 initializers within braced lists, after any designators have been
3858 applied. If AFTER is not NULL then it is an Objective-C message
3859 expression which is the primary-expression starting the
3863 c_parser_initval (c_parser *parser, struct c_expr *after,
3864 struct obstack * braced_init_obstack)
3867 gcc_assert (!after || c_dialect_objc ());
3868 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3869 init = c_parser_braced_init (parser, NULL_TREE, true);
3872 location_t loc = c_parser_peek_token (parser)->location;
3873 init = c_parser_expr_no_commas (parser, after);
3874 if (init.value != NULL_TREE
3875 && TREE_CODE (init.value) != STRING_CST
3876 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3877 init = default_function_array_read_conversion (loc, init);
3879 process_init_element (init, false, braced_init_obstack);
3882 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3886 { block-item-list[opt] }
3887 { label-declarations block-item-list }
3891 block-item-list block-item
3903 { label-declarations block-item-list }
3906 __extension__ nested-declaration
3907 nested-function-definition
3911 label-declarations label-declaration
3914 __label__ identifier-list ;
3916 Allowing the mixing of declarations and code is new in C99. The
3917 GNU syntax also permits (not shown above) labels at the end of
3918 compound statements, which yield an error. We don't allow labels
3919 on declarations; this might seem like a natural extension, but
3920 there would be a conflict between attributes on the label and
3921 prefix attributes on the declaration. ??? The syntax follows the
3922 old parser in requiring something after label declarations.
3923 Although they are erroneous if the labels declared aren't defined,
3924 is it useful for the syntax to be this way?
3936 c_parser_compound_statement (c_parser *parser)
3939 location_t brace_loc;
3940 brace_loc = c_parser_peek_token (parser)->location;
3941 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3943 /* Ensure a scope is entered and left anyway to avoid confusion
3944 if we have just prepared to enter a function body. */
3945 stmt = c_begin_compound_stmt (true);
3946 c_end_compound_stmt (brace_loc, stmt, true);
3947 return error_mark_node;
3949 stmt = c_begin_compound_stmt (true);
3950 c_parser_compound_statement_nostart (parser);
3951 return c_end_compound_stmt (brace_loc, stmt, true);
3954 /* Parse a compound statement except for the opening brace. This is
3955 used for parsing both compound statements and statement expressions
3956 (which follow different paths to handling the opening). */
3959 c_parser_compound_statement_nostart (c_parser *parser)
3961 bool last_stmt = false;
3962 bool last_label = false;
3963 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3964 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3965 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3967 c_parser_consume_token (parser);
3970 mark_valid_location_for_stdc_pragma (true);
3971 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3973 /* Read zero or more forward-declarations for labels that nested
3974 functions can jump to. */
3975 mark_valid_location_for_stdc_pragma (false);
3976 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3978 label_loc = c_parser_peek_token (parser)->location;
3979 c_parser_consume_token (parser);
3980 /* Any identifiers, including those declared as type names,
3985 if (c_parser_next_token_is_not (parser, CPP_NAME))
3987 c_parser_error (parser, "expected identifier");
3991 = declare_label (c_parser_peek_token (parser)->value);
3992 C_DECLARED_LABEL_FLAG (label) = 1;
3993 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3994 c_parser_consume_token (parser);
3995 if (c_parser_next_token_is (parser, CPP_COMMA))
3996 c_parser_consume_token (parser);
4000 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4002 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
4004 /* We must now have at least one statement, label or declaration. */
4005 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4007 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4008 c_parser_error (parser, "expected declaration or statement");
4009 c_parser_consume_token (parser);
4012 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4014 location_t loc = c_parser_peek_token (parser)->location;
4015 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4016 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4017 || (c_parser_next_token_is (parser, CPP_NAME)
4018 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4020 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4021 label_loc = c_parser_peek_2nd_token (parser)->location;
4023 label_loc = c_parser_peek_token (parser)->location;
4026 mark_valid_location_for_stdc_pragma (false);
4027 c_parser_label (parser);
4029 else if (!last_label
4030 && c_parser_next_tokens_start_declaration (parser))
4033 mark_valid_location_for_stdc_pragma (false);
4034 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4037 (pedantic && !flag_isoc99)
4039 : OPT_Wdeclaration_after_statement,
4040 "ISO C90 forbids mixed declarations and code");
4043 else if (!last_label
4044 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4046 /* __extension__ can start a declaration, but is also an
4047 unary operator that can start an expression. Consume all
4048 but the last of a possible series of __extension__ to
4050 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4051 && (c_parser_peek_2nd_token (parser)->keyword
4053 c_parser_consume_token (parser);
4054 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4057 ext = disable_extension_diagnostics ();
4058 c_parser_consume_token (parser);
4060 mark_valid_location_for_stdc_pragma (false);
4061 c_parser_declaration_or_fndef (parser, true, true, true, true,
4063 /* Following the old parser, __extension__ does not
4064 disable this diagnostic. */
4065 restore_extension_diagnostics (ext);
4067 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4069 : OPT_Wdeclaration_after_statement,
4070 "ISO C90 forbids mixed declarations and code");
4076 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4078 /* External pragmas, and some omp pragmas, are not associated
4079 with regular c code, and so are not to be considered statements
4080 syntactically. This ensures that the user doesn't put them
4081 places that would turn into syntax errors if the directive
4083 if (c_parser_pragma (parser, pragma_compound))
4084 last_label = false, last_stmt = true;
4086 else if (c_parser_next_token_is (parser, CPP_EOF))
4088 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4089 c_parser_error (parser, "expected declaration or statement");
4092 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4094 if (parser->in_if_block)
4096 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4097 error_at (loc, """expected %<}%> before %<else%>");
4102 error_at (loc, "%<else%> without a previous %<if%>");
4103 c_parser_consume_token (parser);
4112 mark_valid_location_for_stdc_pragma (false);
4113 c_parser_statement_after_labels (parser);
4116 parser->error = false;
4119 error_at (label_loc, "label at end of compound statement");
4120 c_parser_consume_token (parser);
4121 /* Restore the value we started with. */
4122 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4125 /* Parse a label (C90 6.6.1, C99 6.8.1).
4128 identifier : attributes[opt]
4129 case constant-expression :
4135 case constant-expression ... constant-expression :
4137 The use of attributes on labels is a GNU extension. The syntax in
4138 GNU C accepts any expressions without commas, non-constant
4139 expressions being rejected later. */
4142 c_parser_label (c_parser *parser)
4144 location_t loc1 = c_parser_peek_token (parser)->location;
4145 tree label = NULL_TREE;
4146 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4149 c_parser_consume_token (parser);
4150 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4151 if (c_parser_next_token_is (parser, CPP_COLON))
4153 c_parser_consume_token (parser);
4154 label = do_case (loc1, exp1, NULL_TREE);
4156 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4158 c_parser_consume_token (parser);
4159 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4160 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4161 label = do_case (loc1, exp1, exp2);
4164 c_parser_error (parser, "expected %<:%> or %<...%>");
4166 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4168 c_parser_consume_token (parser);
4169 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4170 label = do_case (loc1, NULL_TREE, NULL_TREE);
4174 tree name = c_parser_peek_token (parser)->value;
4177 location_t loc2 = c_parser_peek_token (parser)->location;
4178 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4179 c_parser_consume_token (parser);
4180 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4181 c_parser_consume_token (parser);
4182 attrs = c_parser_attributes (parser);
4183 tlab = define_label (loc2, name);
4186 decl_attributes (&tlab, attrs, 0);
4187 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4192 if (c_parser_next_tokens_start_declaration (parser))
4194 error_at (c_parser_peek_token (parser)->location,
4195 "a label can only be part of a statement and "
4196 "a declaration is not a statement");
4197 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4198 /*static_assert_ok*/ true,
4199 /*nested*/ true, /*empty_ok*/ false,
4200 /*start_attr_ok*/ true, NULL);
4205 /* Parse a statement (C90 6.6, C99 6.8).
4210 expression-statement
4218 expression-statement:
4221 selection-statement:
4225 iteration-statement:
4234 return expression[opt] ;
4247 objc-throw-statement
4248 objc-try-catch-statement
4249 objc-synchronized-statement
4251 objc-throw-statement:
4265 parallel-for-construct
4266 parallel-sections-construct
4273 parallel-directive structured-block
4276 for-directive iteration-statement
4279 sections-directive section-scope
4282 single-directive structured-block
4284 parallel-for-construct:
4285 parallel-for-directive iteration-statement
4287 parallel-sections-construct:
4288 parallel-sections-directive section-scope
4291 master-directive structured-block
4294 critical-directive structured-block
4297 atomic-directive expression-statement
4300 ordered-directive structured-block */
4303 c_parser_statement (c_parser *parser)
4305 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4306 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4307 || (c_parser_next_token_is (parser, CPP_NAME)
4308 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4309 c_parser_label (parser);
4310 c_parser_statement_after_labels (parser);
4313 /* Parse a statement, other than a labeled statement. */
4316 c_parser_statement_after_labels (c_parser *parser)
4318 location_t loc = c_parser_peek_token (parser)->location;
4319 tree stmt = NULL_TREE;
4320 bool in_if_block = parser->in_if_block;
4321 parser->in_if_block = false;
4322 switch (c_parser_peek_token (parser)->type)
4324 case CPP_OPEN_BRACE:
4325 add_stmt (c_parser_compound_statement (parser));
4328 switch (c_parser_peek_token (parser)->keyword)
4331 c_parser_if_statement (parser);
4334 c_parser_switch_statement (parser);
4337 c_parser_while_statement (parser);
4340 c_parser_do_statement (parser);
4343 c_parser_for_statement (parser);
4346 c_parser_consume_token (parser);
4347 if (c_parser_next_token_is (parser, CPP_NAME))
4349 stmt = c_finish_goto_label (loc,
4350 c_parser_peek_token (parser)->value);
4351 c_parser_consume_token (parser);
4353 else if (c_parser_next_token_is (parser, CPP_MULT))
4357 c_parser_consume_token (parser);
4358 val = c_parser_expression (parser).value;
4359 mark_exp_read (val);
4360 stmt = c_finish_goto_ptr (loc, val);
4363 c_parser_error (parser, "expected identifier or %<*%>");
4364 goto expect_semicolon;
4366 c_parser_consume_token (parser);
4367 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4368 goto expect_semicolon;
4370 c_parser_consume_token (parser);
4371 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4372 goto expect_semicolon;
4374 c_parser_consume_token (parser);
4375 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4377 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4378 c_parser_consume_token (parser);
4382 struct c_expr expr = c_parser_expression_conv (parser);
4383 mark_exp_read (expr.value);
4384 stmt = c_finish_return (loc, expr.value, expr.original_type);
4385 goto expect_semicolon;
4389 stmt = c_parser_asm_statement (parser);
4392 gcc_assert (c_dialect_objc ());
4393 c_parser_consume_token (parser);
4394 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4396 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4397 c_parser_consume_token (parser);
4401 tree expr = c_parser_expression (parser).value;
4402 expr = c_fully_fold (expr, false, NULL);
4403 stmt = objc_build_throw_stmt (loc, expr);
4404 goto expect_semicolon;
4408 gcc_assert (c_dialect_objc ());
4409 c_parser_objc_try_catch_finally_statement (parser);
4411 case RID_AT_SYNCHRONIZED:
4412 gcc_assert (c_dialect_objc ());
4413 c_parser_objc_synchronized_statement (parser);
4420 c_parser_consume_token (parser);
4422 case CPP_CLOSE_PAREN:
4423 case CPP_CLOSE_SQUARE:
4424 /* Avoid infinite loop in error recovery:
4425 c_parser_skip_until_found stops at a closing nesting
4426 delimiter without consuming it, but here we need to consume
4427 it to proceed further. */
4428 c_parser_error (parser, "expected statement");
4429 c_parser_consume_token (parser);
4432 c_parser_pragma (parser, pragma_stmt);
4436 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4438 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4441 /* Two cases cannot and do not have line numbers associated: If stmt
4442 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4443 cannot hold line numbers. But that's OK because the statement
4444 will either be changed to a MODIFY_EXPR during gimplification of
4445 the statement expr, or discarded. If stmt was compound, but
4446 without new variables, we will have skipped the creation of a
4447 BIND and will have a bare STATEMENT_LIST. But that's OK because
4448 (recursively) all of the component statements should already have
4449 line numbers assigned. ??? Can we discard no-op statements
4451 if (CAN_HAVE_LOCATION_P (stmt)
4452 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4453 SET_EXPR_LOCATION (stmt, loc);
4455 parser->in_if_block = in_if_block;
4458 /* Parse the condition from an if, do, while or for statements. */
4461 c_parser_condition (c_parser *parser)
4463 location_t loc = c_parser_peek_token (parser)->location;
4465 cond = c_parser_expression_conv (parser).value;
4466 cond = c_objc_common_truthvalue_conversion (loc, cond);
4467 cond = c_fully_fold (cond, false, NULL);
4468 if (warn_sequence_point)
4469 verify_sequence_points (cond);
4473 /* Parse a parenthesized condition from an if, do or while statement.
4479 c_parser_paren_condition (c_parser *parser)
4482 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4483 return error_mark_node;
4484 cond = c_parser_condition (parser);
4485 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4489 /* Parse a statement which is a block in C99. */
4492 c_parser_c99_block_statement (c_parser *parser)
4494 tree block = c_begin_compound_stmt (flag_isoc99);
4495 location_t loc = c_parser_peek_token (parser)->location;
4496 c_parser_statement (parser);
4497 return c_end_compound_stmt (loc, block, flag_isoc99);
4500 /* Parse the body of an if statement. This is just parsing a
4501 statement but (a) it is a block in C99, (b) we track whether the
4502 body is an if statement for the sake of -Wparentheses warnings, (c)
4503 we handle an empty body specially for the sake of -Wempty-body
4504 warnings, and (d) we call parser_compound_statement directly
4505 because c_parser_statement_after_labels resets
4506 parser->in_if_block. */
4509 c_parser_if_body (c_parser *parser, bool *if_p)
4511 tree block = c_begin_compound_stmt (flag_isoc99);
4512 location_t body_loc = c_parser_peek_token (parser)->location;
4513 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4514 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4515 || (c_parser_next_token_is (parser, CPP_NAME)
4516 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4517 c_parser_label (parser);
4518 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4519 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4521 location_t loc = c_parser_peek_token (parser)->location;
4522 add_stmt (build_empty_stmt (loc));
4523 c_parser_consume_token (parser);
4524 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4525 warning_at (loc, OPT_Wempty_body,
4526 "suggest braces around empty body in an %<if%> statement");
4528 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4529 add_stmt (c_parser_compound_statement (parser));
4531 c_parser_statement_after_labels (parser);
4532 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4535 /* Parse the else body of an if statement. This is just parsing a
4536 statement but (a) it is a block in C99, (b) we handle an empty body
4537 specially for the sake of -Wempty-body warnings. */
4540 c_parser_else_body (c_parser *parser)
4542 location_t else_loc = c_parser_peek_token (parser)->location;
4543 tree block = c_begin_compound_stmt (flag_isoc99);
4544 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4545 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4546 || (c_parser_next_token_is (parser, CPP_NAME)
4547 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4548 c_parser_label (parser);
4549 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4551 location_t loc = c_parser_peek_token (parser)->location;
4554 "suggest braces around empty body in an %<else%> statement");
4555 add_stmt (build_empty_stmt (loc));
4556 c_parser_consume_token (parser);
4559 c_parser_statement_after_labels (parser);
4560 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4563 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4566 if ( expression ) statement
4567 if ( expression ) statement else statement
4571 c_parser_if_statement (c_parser *parser)
4576 bool first_if = false;
4577 tree first_body, second_body;
4580 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4581 c_parser_consume_token (parser);
4582 block = c_begin_compound_stmt (flag_isoc99);
4583 loc = c_parser_peek_token (parser)->location;
4584 cond = c_parser_paren_condition (parser);
4585 in_if_block = parser->in_if_block;
4586 parser->in_if_block = true;
4587 first_body = c_parser_if_body (parser, &first_if);
4588 parser->in_if_block = in_if_block;
4589 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4591 c_parser_consume_token (parser);
4592 second_body = c_parser_else_body (parser);
4595 second_body = NULL_TREE;
4596 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4597 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4600 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4603 switch (expression) statement
4607 c_parser_switch_statement (c_parser *parser)
4609 tree block, expr, body, save_break;
4610 location_t switch_loc = c_parser_peek_token (parser)->location;
4611 location_t switch_cond_loc;
4612 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4613 c_parser_consume_token (parser);
4614 block = c_begin_compound_stmt (flag_isoc99);
4615 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4617 switch_cond_loc = c_parser_peek_token (parser)->location;
4618 expr = c_parser_expression (parser).value;
4619 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4623 switch_cond_loc = UNKNOWN_LOCATION;
4624 expr = error_mark_node;
4626 c_start_case (switch_loc, switch_cond_loc, expr);
4627 save_break = c_break_label;
4628 c_break_label = NULL_TREE;
4629 body = c_parser_c99_block_statement (parser);
4630 c_finish_case (body);
4633 location_t here = c_parser_peek_token (parser)->location;
4634 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4635 SET_EXPR_LOCATION (t, here);
4638 c_break_label = save_break;
4639 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4642 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4645 while (expression) statement
4649 c_parser_while_statement (c_parser *parser)
4651 tree block, cond, body, save_break, save_cont;
4653 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4654 c_parser_consume_token (parser);
4655 block = c_begin_compound_stmt (flag_isoc99);
4656 loc = c_parser_peek_token (parser)->location;
4657 cond = c_parser_paren_condition (parser);
4658 save_break = c_break_label;
4659 c_break_label = NULL_TREE;
4660 save_cont = c_cont_label;
4661 c_cont_label = NULL_TREE;
4662 body = c_parser_c99_block_statement (parser);
4663 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4664 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4665 c_break_label = save_break;
4666 c_cont_label = save_cont;
4669 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4672 do statement while ( expression ) ;
4676 c_parser_do_statement (c_parser *parser)
4678 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4680 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4681 c_parser_consume_token (parser);
4682 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4683 warning_at (c_parser_peek_token (parser)->location,
4685 "suggest braces around empty body in %<do%> statement");
4686 block = c_begin_compound_stmt (flag_isoc99);
4687 loc = c_parser_peek_token (parser)->location;
4688 save_break = c_break_label;
4689 c_break_label = NULL_TREE;
4690 save_cont = c_cont_label;
4691 c_cont_label = NULL_TREE;
4692 body = c_parser_c99_block_statement (parser);
4693 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4694 new_break = c_break_label;
4695 c_break_label = save_break;
4696 new_cont = c_cont_label;
4697 c_cont_label = save_cont;
4698 cond = c_parser_paren_condition (parser);
4699 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4700 c_parser_skip_to_end_of_block_or_statement (parser);
4701 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4702 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4705 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4708 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4709 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4711 The form with a declaration is new in C99.
4713 ??? In accordance with the old parser, the declaration may be a
4714 nested function, which is then rejected in check_for_loop_decls,
4715 but does it make any sense for this to be included in the grammar?
4716 Note in particular that the nested function does not include a
4717 trailing ';', whereas the "declaration" production includes one.
4718 Also, can we reject bad declarations earlier and cheaper than
4719 check_for_loop_decls?
4721 In Objective-C, there are two additional variants:
4724 for ( expression in expresssion ) statement
4725 for ( declaration in expression ) statement
4727 This is inconsistent with C, because the second variant is allowed
4728 even if c99 is not enabled.
4730 The rest of the comment documents these Objective-C foreach-statement.
4732 Here is the canonical example of the first variant:
4733 for (object in array) { do something with object }
4734 we call the first expression ("object") the "object_expression" and
4735 the second expression ("array") the "collection_expression".
4736 object_expression must be an lvalue of type "id" (a generic Objective-C
4737 object) because the loop works by assigning to object_expression the
4738 various objects from the collection_expression. collection_expression
4739 must evaluate to something of type "id" which responds to the method
4740 countByEnumeratingWithState:objects:count:.
4742 The canonical example of the second variant is:
4743 for (id object in array) { do something with object }
4744 which is completely equivalent to
4747 for (object in array) { do something with object }
4749 Note that initizializing 'object' in some way (eg, "for ((object =
4750 xxx) in array) { do something with object }") is possibly
4751 technically valid, but completely pointless as 'object' will be
4752 assigned to something else as soon as the loop starts. We should
4753 most likely reject it (TODO).
4755 The beginning of the Objective-C foreach-statement looks exactly
4756 like the beginning of the for-statement, and we can tell it is a
4757 foreach-statement only because the initial declaration or
4758 expression is terminated by 'in' instead of ';'.
4762 c_parser_for_statement (c_parser *parser)
4764 tree block, cond, incr, save_break, save_cont, body;
4765 /* The following are only used when parsing an ObjC foreach statement. */
4766 tree object_expression, collection_expression;
4767 location_t loc = c_parser_peek_token (parser)->location;
4768 location_t for_loc = c_parser_peek_token (parser)->location;
4769 bool is_foreach_statement = false;
4770 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4771 c_parser_consume_token (parser);
4772 /* Open a compound statement in Objective-C as well, just in case this is
4773 as foreach expression. */
4774 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4775 cond = error_mark_node;
4776 incr = error_mark_node;
4777 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4779 /* Parse the initialization declaration or expression. */
4780 object_expression = error_mark_node;
4781 parser->objc_could_be_foreach_context = c_dialect_objc ();
4782 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4784 parser->objc_could_be_foreach_context = false;
4785 c_parser_consume_token (parser);
4786 c_finish_expr_stmt (loc, NULL_TREE);
4788 else if (c_parser_next_tokens_start_declaration (parser))
4790 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4791 &object_expression);
4792 parser->objc_could_be_foreach_context = false;
4794 if (c_parser_next_token_is_keyword (parser, RID_IN))
4796 c_parser_consume_token (parser);
4797 is_foreach_statement = true;
4798 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4799 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4802 check_for_loop_decls (for_loc, flag_isoc99);
4804 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4806 /* __extension__ can start a declaration, but is also an
4807 unary operator that can start an expression. Consume all
4808 but the last of a possible series of __extension__ to
4810 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4811 && (c_parser_peek_2nd_token (parser)->keyword
4813 c_parser_consume_token (parser);
4814 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4817 ext = disable_extension_diagnostics ();
4818 c_parser_consume_token (parser);
4819 c_parser_declaration_or_fndef (parser, true, true, true, true,
4820 true, &object_expression);
4821 parser->objc_could_be_foreach_context = false;
4823 restore_extension_diagnostics (ext);
4824 if (c_parser_next_token_is_keyword (parser, RID_IN))
4826 c_parser_consume_token (parser);
4827 is_foreach_statement = true;
4828 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4829 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4832 check_for_loop_decls (for_loc, flag_isoc99);
4841 tree init_expression;
4842 init_expression = c_parser_expression (parser).value;
4843 parser->objc_could_be_foreach_context = false;
4844 if (c_parser_next_token_is_keyword (parser, RID_IN))
4846 c_parser_consume_token (parser);
4847 is_foreach_statement = true;
4848 if (! lvalue_p (init_expression))
4849 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4850 object_expression = c_fully_fold (init_expression, false, NULL);
4854 c_finish_expr_stmt (loc, init_expression);
4855 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4859 /* Parse the loop condition. In the case of a foreach
4860 statement, there is no loop condition. */
4861 gcc_assert (!parser->objc_could_be_foreach_context);
4862 if (!is_foreach_statement)
4864 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4866 c_parser_consume_token (parser);
4871 cond = c_parser_condition (parser);
4872 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4875 /* Parse the increment expression (the third expression in a
4876 for-statement). In the case of a foreach-statement, this is
4877 the expression that follows the 'in'. */
4878 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4880 if (is_foreach_statement)
4882 c_parser_error (parser, "missing collection in fast enumeration");
4883 collection_expression = error_mark_node;
4886 incr = c_process_expr_stmt (loc, NULL_TREE);
4890 if (is_foreach_statement)
4891 collection_expression = c_fully_fold (c_parser_expression (parser).value,
4894 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4896 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4898 save_break = c_break_label;
4899 c_break_label = NULL_TREE;
4900 save_cont = c_cont_label;
4901 c_cont_label = NULL_TREE;
4902 body = c_parser_c99_block_statement (parser);
4903 if (is_foreach_statement)
4904 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4906 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4907 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4908 c_break_label = save_break;
4909 c_cont_label = save_cont;
4912 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4913 statement with inputs, outputs, clobbers, and volatile tag
4917 asm type-qualifier[opt] ( asm-argument ) ;
4918 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4922 asm-string-literal : asm-operands[opt]
4923 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4924 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4927 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4930 Qualifiers other than volatile are accepted in the syntax but
4934 c_parser_asm_statement (c_parser *parser)
4936 tree quals, str, outputs, inputs, clobbers, labels, ret;
4937 bool simple, is_goto;
4938 location_t asm_loc = c_parser_peek_token (parser)->location;
4939 int section, nsections;
4941 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4942 c_parser_consume_token (parser);
4943 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4945 quals = c_parser_peek_token (parser)->value;
4946 c_parser_consume_token (parser);
4948 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4949 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4951 warning_at (c_parser_peek_token (parser)->location,
4953 "%E qualifier ignored on asm",
4954 c_parser_peek_token (parser)->value);
4956 c_parser_consume_token (parser);
4962 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4964 c_parser_consume_token (parser);
4968 /* ??? Follow the C++ parser rather than using the
4969 lex_untranslated_string kludge. */
4970 parser->lex_untranslated_string = true;
4973 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4976 str = c_parser_asm_string_literal (parser);
4977 if (str == NULL_TREE)
4978 goto error_close_paren;
4981 outputs = NULL_TREE;
4983 clobbers = NULL_TREE;
4986 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4989 /* Parse each colon-delimited section of operands. */
4990 nsections = 3 + is_goto;
4991 for (section = 0; section < nsections; ++section)
4993 if (!c_parser_require (parser, CPP_COLON,
4996 : "expected %<:%> or %<)%>"))
4997 goto error_close_paren;
4999 /* Once past any colon, we're no longer a simple asm. */
5002 if ((!c_parser_next_token_is (parser, CPP_COLON)
5003 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5008 /* For asm goto, we don't allow output operands, but reserve
5009 the slot for a future extension that does allow them. */
5011 outputs = c_parser_asm_operands (parser, false);
5014 inputs = c_parser_asm_operands (parser, true);
5017 clobbers = c_parser_asm_clobbers (parser);
5020 labels = c_parser_asm_goto_operands (parser);
5026 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5031 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5033 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5037 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5038 c_parser_skip_to_end_of_block_or_statement (parser);
5040 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5041 clobbers, labels, simple));
5044 parser->lex_untranslated_string = false;
5048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5052 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5053 not outputs), apply the default conversion of functions and arrays
5058 asm-operands , asm-operand
5061 asm-string-literal ( expression )
5062 [ identifier ] asm-string-literal ( expression )
5066 c_parser_asm_operands (c_parser *parser, bool convert_p)
5068 tree list = NULL_TREE;
5074 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5076 c_parser_consume_token (parser);
5077 if (c_parser_next_token_is (parser, CPP_NAME))
5079 tree id = c_parser_peek_token (parser)->value;
5080 c_parser_consume_token (parser);
5081 name = build_string (IDENTIFIER_LENGTH (id),
5082 IDENTIFIER_POINTER (id));
5086 c_parser_error (parser, "expected identifier");
5087 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5090 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5095 str = c_parser_asm_string_literal (parser);
5096 if (str == NULL_TREE)
5098 parser->lex_untranslated_string = false;
5099 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5101 parser->lex_untranslated_string = true;
5104 loc = c_parser_peek_token (parser)->location;
5105 expr = c_parser_expression (parser);
5106 mark_exp_read (expr.value);
5108 expr = default_function_array_conversion (loc, expr);
5109 expr.value = c_fully_fold (expr.value, false, NULL);
5110 parser->lex_untranslated_string = true;
5111 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5113 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5116 list = chainon (list, build_tree_list (build_tree_list (name, str),
5118 if (c_parser_next_token_is (parser, CPP_COMMA))
5119 c_parser_consume_token (parser);
5126 /* Parse asm clobbers, a GNU extension.
5130 asm-clobbers , asm-string-literal
5134 c_parser_asm_clobbers (c_parser *parser)
5136 tree list = NULL_TREE;
5139 tree str = c_parser_asm_string_literal (parser);
5141 list = tree_cons (NULL_TREE, str, list);
5144 if (c_parser_next_token_is (parser, CPP_COMMA))
5145 c_parser_consume_token (parser);
5152 /* Parse asm goto labels, a GNU extension.
5156 asm-goto-operands , identifier
5160 c_parser_asm_goto_operands (c_parser *parser)
5162 tree list = NULL_TREE;
5167 if (c_parser_next_token_is (parser, CPP_NAME))
5169 c_token *tok = c_parser_peek_token (parser);
5171 label = lookup_label_for_goto (tok->location, name);
5172 c_parser_consume_token (parser);
5173 TREE_USED (label) = 1;
5177 c_parser_error (parser, "expected identifier");
5181 name = build_string (IDENTIFIER_LENGTH (name),
5182 IDENTIFIER_POINTER (name));
5183 list = tree_cons (name, label, list);
5184 if (c_parser_next_token_is (parser, CPP_COMMA))
5185 c_parser_consume_token (parser);
5187 return nreverse (list);
5191 /* Parse an expression other than a compound expression; that is, an
5192 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5193 NULL then it is an Objective-C message expression which is the
5194 primary-expression starting the expression as an initializer.
5196 assignment-expression:
5197 conditional-expression
5198 unary-expression assignment-operator assignment-expression
5200 assignment-operator: one of
5201 = *= /= %= += -= <<= >>= &= ^= |=
5203 In GNU C we accept any conditional expression on the LHS and
5204 diagnose the invalid lvalue rather than producing a syntax
5207 static struct c_expr
5208 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5210 struct c_expr lhs, rhs, ret;
5211 enum tree_code code;
5212 location_t op_location, exp_location;
5213 gcc_assert (!after || c_dialect_objc ());
5214 lhs = c_parser_conditional_expression (parser, after);
5215 op_location = c_parser_peek_token (parser)->location;
5216 switch (c_parser_peek_token (parser)->type)
5225 code = TRUNC_DIV_EXPR;
5228 code = TRUNC_MOD_EXPR;
5243 code = BIT_AND_EXPR;
5246 code = BIT_XOR_EXPR;
5249 code = BIT_IOR_EXPR;
5254 c_parser_consume_token (parser);
5255 exp_location = c_parser_peek_token (parser)->location;
5256 rhs = c_parser_expr_no_commas (parser, NULL);
5257 rhs = default_function_array_read_conversion (exp_location, rhs);
5258 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5259 code, exp_location, rhs.value,
5261 if (code == NOP_EXPR)
5262 ret.original_code = MODIFY_EXPR;
5265 TREE_NO_WARNING (ret.value) = 1;
5266 ret.original_code = ERROR_MARK;
5268 ret.original_type = NULL;
5272 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5273 is not NULL then it is an Objective-C message expression which is
5274 the primary-expression starting the expression as an initializer.
5276 conditional-expression:
5277 logical-OR-expression
5278 logical-OR-expression ? expression : conditional-expression
5282 conditional-expression:
5283 logical-OR-expression ? : conditional-expression
5286 static struct c_expr
5287 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5289 struct c_expr cond, exp1, exp2, ret;
5290 location_t cond_loc, colon_loc, middle_loc;
5292 gcc_assert (!after || c_dialect_objc ());
5294 cond = c_parser_binary_expression (parser, after);
5296 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5298 cond_loc = c_parser_peek_token (parser)->location;
5299 cond = default_function_array_read_conversion (cond_loc, cond);
5300 c_parser_consume_token (parser);
5301 if (c_parser_next_token_is (parser, CPP_COLON))
5303 tree eptype = NULL_TREE;
5305 middle_loc = c_parser_peek_token (parser)->location;
5306 pedwarn (middle_loc, OPT_pedantic,
5307 "ISO C forbids omitting the middle term of a ?: expression");
5308 warn_for_omitted_condop (middle_loc, cond.value);
5309 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5311 eptype = TREE_TYPE (cond.value);
5312 cond.value = TREE_OPERAND (cond.value, 0);
5314 /* Make sure first operand is calculated only once. */
5315 exp1.value = c_save_expr (default_conversion (cond.value));
5317 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5318 exp1.original_type = NULL;
5319 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5320 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5325 = c_objc_common_truthvalue_conversion
5326 (cond_loc, default_conversion (cond.value));
5327 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5328 exp1 = c_parser_expression_conv (parser);
5329 mark_exp_read (exp1.value);
5330 c_inhibit_evaluation_warnings +=
5331 ((cond.value == truthvalue_true_node)
5332 - (cond.value == truthvalue_false_node));
5335 colon_loc = c_parser_peek_token (parser)->location;
5336 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5338 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5339 ret.value = error_mark_node;
5340 ret.original_code = ERROR_MARK;
5341 ret.original_type = NULL;
5345 location_t exp2_loc = c_parser_peek_token (parser)->location;
5346 exp2 = c_parser_conditional_expression (parser, NULL);
5347 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5349 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5350 ret.value = build_conditional_expr (colon_loc, cond.value,
5351 cond.original_code == C_MAYBE_CONST_EXPR,
5352 exp1.value, exp1.original_type,
5353 exp2.value, exp2.original_type);
5354 ret.original_code = ERROR_MARK;
5355 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5356 ret.original_type = NULL;
5361 /* If both sides are enum type, the default conversion will have
5362 made the type of the result be an integer type. We want to
5363 remember the enum types we started with. */
5364 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5365 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5366 ret.original_type = ((t1 != error_mark_node
5367 && t2 != error_mark_node
5368 && (TYPE_MAIN_VARIANT (t1)
5369 == TYPE_MAIN_VARIANT (t2)))
5376 /* Parse a binary expression; that is, a logical-OR-expression (C90
5377 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5378 an Objective-C message expression which is the primary-expression
5379 starting the expression as an initializer.
5381 multiplicative-expression:
5383 multiplicative-expression * cast-expression
5384 multiplicative-expression / cast-expression
5385 multiplicative-expression % cast-expression
5387 additive-expression:
5388 multiplicative-expression
5389 additive-expression + multiplicative-expression
5390 additive-expression - multiplicative-expression
5394 shift-expression << additive-expression
5395 shift-expression >> additive-expression
5397 relational-expression:
5399 relational-expression < shift-expression
5400 relational-expression > shift-expression
5401 relational-expression <= shift-expression
5402 relational-expression >= shift-expression
5404 equality-expression:
5405 relational-expression
5406 equality-expression == relational-expression
5407 equality-expression != relational-expression
5411 AND-expression & equality-expression
5413 exclusive-OR-expression:
5415 exclusive-OR-expression ^ AND-expression
5417 inclusive-OR-expression:
5418 exclusive-OR-expression
5419 inclusive-OR-expression | exclusive-OR-expression
5421 logical-AND-expression:
5422 inclusive-OR-expression
5423 logical-AND-expression && inclusive-OR-expression
5425 logical-OR-expression:
5426 logical-AND-expression
5427 logical-OR-expression || logical-AND-expression
5430 static struct c_expr
5431 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5433 /* A binary expression is parsed using operator-precedence parsing,
5434 with the operands being cast expressions. All the binary
5435 operators are left-associative. Thus a binary expression is of
5438 E0 op1 E1 op2 E2 ...
5440 which we represent on a stack. On the stack, the precedence
5441 levels are strictly increasing. When a new operator is
5442 encountered of higher precedence than that at the top of the
5443 stack, it is pushed; its LHS is the top expression, and its RHS
5444 is everything parsed until it is popped. When a new operator is
5445 encountered with precedence less than or equal to that at the top
5446 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5447 by the result of the operation until the operator at the top of
5448 the stack has lower precedence than the new operator or there is
5449 only one element on the stack; then the top expression is the LHS
5450 of the new operator. In the case of logical AND and OR
5451 expressions, we also need to adjust c_inhibit_evaluation_warnings
5452 as appropriate when the operators are pushed and popped. */
5454 /* The precedence levels, where 0 is a dummy lowest level used for
5455 the bottom of the stack. */
5471 /* The expression at this stack level. */
5473 /* The precedence of the operator on its left, PREC_NONE at the
5474 bottom of the stack. */
5476 /* The operation on its left. */
5478 /* The source location of this operation. */
5482 /* Location of the binary operator. */
5483 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5486 switch (stack[sp].op) \
5488 case TRUTH_ANDIF_EXPR: \
5489 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5490 == truthvalue_false_node); \
5492 case TRUTH_ORIF_EXPR: \
5493 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5494 == truthvalue_true_node); \
5499 stack[sp - 1].expr \
5500 = default_function_array_read_conversion (stack[sp - 1].loc, \
5501 stack[sp - 1].expr); \
5503 = default_function_array_read_conversion (stack[sp].loc, \
5505 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5507 stack[sp - 1].expr, \
5511 gcc_assert (!after || c_dialect_objc ());
5512 stack[0].loc = c_parser_peek_token (parser)->location;
5513 stack[0].expr = c_parser_cast_expression (parser, after);
5514 stack[0].prec = PREC_NONE;
5519 enum tree_code ocode;
5522 switch (c_parser_peek_token (parser)->type)
5530 ocode = TRUNC_DIV_EXPR;
5534 ocode = TRUNC_MOD_EXPR;
5546 ocode = LSHIFT_EXPR;
5550 ocode = RSHIFT_EXPR;
5564 case CPP_GREATER_EQ:
5577 oprec = PREC_BITAND;
5578 ocode = BIT_AND_EXPR;
5581 oprec = PREC_BITXOR;
5582 ocode = BIT_XOR_EXPR;
5586 ocode = BIT_IOR_EXPR;
5589 oprec = PREC_LOGAND;
5590 ocode = TRUTH_ANDIF_EXPR;
5594 ocode = TRUTH_ORIF_EXPR;
5597 /* Not a binary operator, so end of the binary
5601 binary_loc = c_parser_peek_token (parser)->location;
5602 c_parser_consume_token (parser);
5603 while (oprec <= stack[sp].prec)
5607 case TRUTH_ANDIF_EXPR:
5609 = default_function_array_read_conversion (stack[sp].loc,
5611 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5612 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5613 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5614 == truthvalue_false_node);
5616 case TRUTH_ORIF_EXPR:
5618 = default_function_array_read_conversion (stack[sp].loc,
5620 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5621 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5622 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5623 == truthvalue_true_node);
5629 stack[sp].loc = binary_loc;
5630 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5631 stack[sp].prec = oprec;
5632 stack[sp].op = ocode;
5633 stack[sp].loc = binary_loc;
5638 return stack[0].expr;
5642 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5643 NULL then it is an Objective-C message expression which is the
5644 primary-expression starting the expression as an initializer.
5648 ( type-name ) unary-expression
5651 static struct c_expr
5652 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5654 location_t cast_loc = c_parser_peek_token (parser)->location;
5655 gcc_assert (!after || c_dialect_objc ());
5657 return c_parser_postfix_expression_after_primary (parser,
5659 /* If the expression begins with a parenthesized type name, it may
5660 be either a cast or a compound literal; we need to see whether
5661 the next character is '{' to tell the difference. If not, it is
5662 an unary expression. Full detection of unknown typenames here
5663 would require a 3-token lookahead. */
5664 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5665 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5667 struct c_type_name *type_name;
5670 c_parser_consume_token (parser);
5671 type_name = c_parser_type_name (parser);
5672 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5673 if (type_name == NULL)
5675 ret.value = error_mark_node;
5676 ret.original_code = ERROR_MARK;
5677 ret.original_type = NULL;
5681 /* Save casted types in the function's used types hash table. */
5682 used_types_insert (type_name->specs->type);
5684 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5685 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5688 location_t expr_loc = c_parser_peek_token (parser)->location;
5689 expr = c_parser_cast_expression (parser, NULL);
5690 expr = default_function_array_read_conversion (expr_loc, expr);
5692 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5693 ret.original_code = ERROR_MARK;
5694 ret.original_type = NULL;
5698 return c_parser_unary_expression (parser);
5701 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5707 unary-operator cast-expression
5708 sizeof unary-expression
5709 sizeof ( type-name )
5711 unary-operator: one of
5717 __alignof__ unary-expression
5718 __alignof__ ( type-name )
5721 unary-operator: one of
5722 __extension__ __real__ __imag__
5724 In addition, the GNU syntax treats ++ and -- as unary operators, so
5725 they may be applied to cast expressions with errors for non-lvalues
5728 static struct c_expr
5729 c_parser_unary_expression (c_parser *parser)
5732 struct c_expr ret, op;
5733 location_t op_loc = c_parser_peek_token (parser)->location;
5735 ret.original_code = ERROR_MARK;
5736 ret.original_type = NULL;
5737 switch (c_parser_peek_token (parser)->type)
5740 c_parser_consume_token (parser);
5741 exp_loc = c_parser_peek_token (parser)->location;
5742 op = c_parser_cast_expression (parser, NULL);
5743 op = default_function_array_read_conversion (exp_loc, op);
5744 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5745 case CPP_MINUS_MINUS:
5746 c_parser_consume_token (parser);
5747 exp_loc = c_parser_peek_token (parser)->location;
5748 op = c_parser_cast_expression (parser, NULL);
5749 op = default_function_array_read_conversion (exp_loc, op);
5750 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5752 c_parser_consume_token (parser);
5753 op = c_parser_cast_expression (parser, NULL);
5754 mark_exp_read (op.value);
5755 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5757 c_parser_consume_token (parser);
5758 exp_loc = c_parser_peek_token (parser)->location;
5759 op = c_parser_cast_expression (parser, NULL);
5760 op = default_function_array_read_conversion (exp_loc, op);
5761 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5764 if (!c_dialect_objc () && !in_system_header)
5767 "traditional C rejects the unary plus operator");
5768 c_parser_consume_token (parser);
5769 exp_loc = c_parser_peek_token (parser)->location;
5770 op = c_parser_cast_expression (parser, NULL);
5771 op = default_function_array_read_conversion (exp_loc, op);
5772 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5774 c_parser_consume_token (parser);
5775 exp_loc = c_parser_peek_token (parser)->location;
5776 op = c_parser_cast_expression (parser, NULL);
5777 op = default_function_array_read_conversion (exp_loc, op);
5778 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5780 c_parser_consume_token (parser);
5781 exp_loc = c_parser_peek_token (parser)->location;
5782 op = c_parser_cast_expression (parser, NULL);
5783 op = default_function_array_read_conversion (exp_loc, op);
5784 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5786 c_parser_consume_token (parser);
5787 exp_loc = c_parser_peek_token (parser)->location;
5788 op = c_parser_cast_expression (parser, NULL);
5789 op = default_function_array_read_conversion (exp_loc, op);
5790 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5792 /* Refer to the address of a label as a pointer. */
5793 c_parser_consume_token (parser);
5794 if (c_parser_next_token_is (parser, CPP_NAME))
5796 ret.value = finish_label_address_expr
5797 (c_parser_peek_token (parser)->value, op_loc);
5798 c_parser_consume_token (parser);
5802 c_parser_error (parser, "expected identifier");
5803 ret.value = error_mark_node;
5807 switch (c_parser_peek_token (parser)->keyword)
5810 return c_parser_sizeof_expression (parser);
5812 return c_parser_alignof_expression (parser);
5814 c_parser_consume_token (parser);
5815 ext = disable_extension_diagnostics ();
5816 ret = c_parser_cast_expression (parser, NULL);
5817 restore_extension_diagnostics (ext);
5820 c_parser_consume_token (parser);
5821 exp_loc = c_parser_peek_token (parser)->location;
5822 op = c_parser_cast_expression (parser, NULL);
5823 op = default_function_array_conversion (exp_loc, op);
5824 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5826 c_parser_consume_token (parser);
5827 exp_loc = c_parser_peek_token (parser)->location;
5828 op = c_parser_cast_expression (parser, NULL);
5829 op = default_function_array_conversion (exp_loc, op);
5830 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5832 return c_parser_postfix_expression (parser);
5835 return c_parser_postfix_expression (parser);
5839 /* Parse a sizeof expression. */
5841 static struct c_expr
5842 c_parser_sizeof_expression (c_parser *parser)
5845 location_t expr_loc;
5846 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5847 c_parser_consume_token (parser);
5848 c_inhibit_evaluation_warnings++;
5850 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5851 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5853 /* Either sizeof ( type-name ) or sizeof unary-expression
5854 starting with a compound literal. */
5855 struct c_type_name *type_name;
5856 c_parser_consume_token (parser);
5857 expr_loc = c_parser_peek_token (parser)->location;
5858 type_name = c_parser_type_name (parser);
5859 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5860 if (type_name == NULL)
5863 c_inhibit_evaluation_warnings--;
5865 ret.value = error_mark_node;
5866 ret.original_code = ERROR_MARK;
5867 ret.original_type = NULL;
5870 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5872 expr = c_parser_postfix_expression_after_paren_type (parser,
5877 /* sizeof ( type-name ). */
5878 c_inhibit_evaluation_warnings--;
5880 return c_expr_sizeof_type (expr_loc, type_name);
5884 expr_loc = c_parser_peek_token (parser)->location;
5885 expr = c_parser_unary_expression (parser);
5887 c_inhibit_evaluation_warnings--;
5889 mark_exp_read (expr.value);
5890 if (TREE_CODE (expr.value) == COMPONENT_REF
5891 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5892 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5893 return c_expr_sizeof_expr (expr_loc, expr);
5897 /* Parse an alignof expression. */
5899 static struct c_expr
5900 c_parser_alignof_expression (c_parser *parser)
5903 location_t loc = c_parser_peek_token (parser)->location;
5904 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5905 c_parser_consume_token (parser);
5906 c_inhibit_evaluation_warnings++;
5908 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5909 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5911 /* Either __alignof__ ( type-name ) or __alignof__
5912 unary-expression starting with a compound literal. */
5914 struct c_type_name *type_name;
5916 c_parser_consume_token (parser);
5917 loc = c_parser_peek_token (parser)->location;
5918 type_name = c_parser_type_name (parser);
5919 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5920 if (type_name == NULL)
5923 c_inhibit_evaluation_warnings--;
5925 ret.value = error_mark_node;
5926 ret.original_code = ERROR_MARK;
5927 ret.original_type = NULL;
5930 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5932 expr = c_parser_postfix_expression_after_paren_type (parser,
5937 /* alignof ( type-name ). */
5938 c_inhibit_evaluation_warnings--;
5940 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5941 ret.original_code = ERROR_MARK;
5942 ret.original_type = NULL;
5948 expr = c_parser_unary_expression (parser);
5950 mark_exp_read (expr.value);
5951 c_inhibit_evaluation_warnings--;
5953 ret.value = c_alignof_expr (loc, expr.value);
5954 ret.original_code = ERROR_MARK;
5955 ret.original_type = NULL;
5960 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5964 postfix-expression [ expression ]
5965 postfix-expression ( argument-expression-list[opt] )
5966 postfix-expression . identifier
5967 postfix-expression -> identifier
5968 postfix-expression ++
5969 postfix-expression --
5970 ( type-name ) { initializer-list }
5971 ( type-name ) { initializer-list , }
5973 argument-expression-list:
5975 argument-expression-list , argument-expression
5987 (treated as a keyword in GNU C)
5990 ( compound-statement )
5991 __builtin_va_arg ( assignment-expression , type-name )
5992 __builtin_offsetof ( type-name , offsetof-member-designator )
5993 __builtin_choose_expr ( assignment-expression ,
5994 assignment-expression ,
5995 assignment-expression )
5996 __builtin_types_compatible_p ( type-name , type-name )
5998 offsetof-member-designator:
6000 offsetof-member-designator . identifier
6001 offsetof-member-designator [ expression ]
6006 [ objc-receiver objc-message-args ]
6007 @selector ( objc-selector-arg )
6008 @protocol ( identifier )
6009 @encode ( type-name )
6011 Classname . identifier
6014 static struct c_expr
6015 c_parser_postfix_expression (c_parser *parser)
6017 struct c_expr expr, e1, e2, e3;
6018 struct c_type_name *t1, *t2;
6019 location_t loc = c_parser_peek_token (parser)->location;;
6020 expr.original_code = ERROR_MARK;
6021 expr.original_type = NULL;
6022 switch (c_parser_peek_token (parser)->type)
6025 expr.value = c_parser_peek_token (parser)->value;
6026 loc = c_parser_peek_token (parser)->location;
6027 c_parser_consume_token (parser);
6028 if (TREE_CODE (expr.value) == FIXED_CST
6029 && !targetm.fixed_point_supported_p ())
6031 error_at (loc, "fixed-point types not supported for this target");
6032 expr.value = error_mark_node;
6039 expr.value = c_parser_peek_token (parser)->value;
6040 c_parser_consume_token (parser);
6046 case CPP_UTF8STRING:
6047 expr.value = c_parser_peek_token (parser)->value;
6048 expr.original_code = STRING_CST;
6049 c_parser_consume_token (parser);
6051 case CPP_OBJC_STRING:
6052 gcc_assert (c_dialect_objc ());
6054 = objc_build_string_object (c_parser_peek_token (parser)->value);
6055 c_parser_consume_token (parser);
6058 switch (c_parser_peek_token (parser)->id_kind)
6062 tree id = c_parser_peek_token (parser)->value;
6063 c_parser_consume_token (parser);
6064 expr.value = build_external_ref (loc, id,
6065 (c_parser_peek_token (parser)->type
6067 &expr.original_type);
6070 case C_ID_CLASSNAME:
6072 /* Here we parse the Objective-C 2.0 Class.name dot
6074 tree class_name = c_parser_peek_token (parser)->value;
6076 c_parser_consume_token (parser);
6077 gcc_assert (c_dialect_objc ());
6078 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6080 expr.value = error_mark_node;
6083 if (c_parser_next_token_is_not (parser, CPP_NAME))
6085 c_parser_error (parser, "expected identifier");
6086 expr.value = error_mark_node;
6089 component = c_parser_peek_token (parser)->value;
6090 c_parser_consume_token (parser);
6091 expr.value = objc_build_class_component_ref (class_name,
6096 c_parser_error (parser, "expected expression");
6097 expr.value = error_mark_node;
6101 case CPP_OPEN_PAREN:
6102 /* A parenthesized expression, statement expression or compound
6104 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6106 /* A statement expression. */
6108 location_t brace_loc;
6109 c_parser_consume_token (parser);
6110 brace_loc = c_parser_peek_token (parser)->location;
6111 c_parser_consume_token (parser);
6112 if (cur_stmt_list == NULL)
6114 error_at (loc, "braced-group within expression allowed "
6115 "only inside a function");
6116 parser->error = true;
6117 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6118 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6119 expr.value = error_mark_node;
6122 stmt = c_begin_stmt_expr ();
6123 c_parser_compound_statement_nostart (parser);
6124 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6126 pedwarn (loc, OPT_pedantic,
6127 "ISO C forbids braced-groups within expressions");
6128 expr.value = c_finish_stmt_expr (brace_loc, stmt);
6129 mark_exp_read (expr.value);
6131 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6133 /* A compound literal. ??? Can we actually get here rather
6134 than going directly to
6135 c_parser_postfix_expression_after_paren_type from
6138 struct c_type_name *type_name;
6139 c_parser_consume_token (parser);
6140 loc = c_parser_peek_token (parser)->location;
6141 type_name = c_parser_type_name (parser);
6142 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6144 if (type_name == NULL)
6146 expr.value = error_mark_node;
6149 expr = c_parser_postfix_expression_after_paren_type (parser,
6155 /* A parenthesized expression. */
6156 c_parser_consume_token (parser);
6157 expr = c_parser_expression (parser);
6158 if (TREE_CODE (expr.value) == MODIFY_EXPR)
6159 TREE_NO_WARNING (expr.value) = 1;
6160 if (expr.original_code != C_MAYBE_CONST_EXPR)
6161 expr.original_code = ERROR_MARK;
6162 /* Don't change EXPR.ORIGINAL_TYPE. */
6163 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6168 switch (c_parser_peek_token (parser)->keyword)
6170 case RID_FUNCTION_NAME:
6171 case RID_PRETTY_FUNCTION_NAME:
6172 case RID_C99_FUNCTION_NAME:
6173 expr.value = fname_decl (loc,
6174 c_parser_peek_token (parser)->keyword,
6175 c_parser_peek_token (parser)->value);
6176 c_parser_consume_token (parser);
6179 c_parser_consume_token (parser);
6180 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6182 expr.value = error_mark_node;
6185 e1 = c_parser_expr_no_commas (parser, NULL);
6186 mark_exp_read (e1.value);
6187 e1.value = c_fully_fold (e1.value, false, NULL);
6188 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6190 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6191 expr.value = error_mark_node;
6194 loc = c_parser_peek_token (parser)->location;
6195 t1 = c_parser_type_name (parser);
6196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6200 expr.value = error_mark_node;
6204 tree type_expr = NULL_TREE;
6205 expr.value = c_build_va_arg (loc, e1.value,
6206 groktypename (t1, &type_expr, NULL));
6209 expr.value = build2 (C_MAYBE_CONST_EXPR,
6210 TREE_TYPE (expr.value), type_expr,
6212 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6217 c_parser_consume_token (parser);
6218 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6220 expr.value = error_mark_node;
6223 t1 = c_parser_type_name (parser);
6225 parser->error = true;
6226 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6227 gcc_assert (parser->error);
6230 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6231 expr.value = error_mark_node;
6236 tree type = groktypename (t1, NULL, NULL);
6238 if (type == error_mark_node)
6239 offsetof_ref = error_mark_node;
6242 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6243 SET_EXPR_LOCATION (offsetof_ref, loc);
6245 /* Parse the second argument to __builtin_offsetof. We
6246 must have one identifier, and beyond that we want to
6247 accept sub structure and sub array references. */
6248 if (c_parser_next_token_is (parser, CPP_NAME))
6250 offsetof_ref = build_component_ref
6251 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6252 c_parser_consume_token (parser);
6253 while (c_parser_next_token_is (parser, CPP_DOT)
6254 || c_parser_next_token_is (parser,
6256 || c_parser_next_token_is (parser,
6259 if (c_parser_next_token_is (parser, CPP_DEREF))
6261 loc = c_parser_peek_token (parser)->location;
6262 offsetof_ref = build_array_ref (loc,
6267 else if (c_parser_next_token_is (parser, CPP_DOT))
6270 c_parser_consume_token (parser);
6271 if (c_parser_next_token_is_not (parser,
6274 c_parser_error (parser, "expected identifier");
6277 offsetof_ref = build_component_ref
6279 c_parser_peek_token (parser)->value);
6280 c_parser_consume_token (parser);
6285 loc = c_parser_peek_token (parser)->location;
6286 c_parser_consume_token (parser);
6287 idx = c_parser_expression (parser).value;
6288 idx = c_fully_fold (idx, false, NULL);
6289 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6291 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6296 c_parser_error (parser, "expected identifier");
6297 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6299 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6302 case RID_CHOOSE_EXPR:
6303 c_parser_consume_token (parser);
6304 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6306 expr.value = error_mark_node;
6309 loc = c_parser_peek_token (parser)->location;
6310 e1 = c_parser_expr_no_commas (parser, NULL);
6311 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6313 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6314 expr.value = error_mark_node;
6317 e2 = c_parser_expr_no_commas (parser, NULL);
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 e3 = c_parser_expr_no_commas (parser, NULL);
6325 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6331 mark_exp_read (e2.value);
6332 mark_exp_read (e3.value);
6333 if (TREE_CODE (c) != INTEGER_CST
6334 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6336 "first argument to %<__builtin_choose_expr%> not"
6338 constant_expression_warning (c);
6339 expr = integer_zerop (c) ? e3 : e2;
6342 case RID_TYPES_COMPATIBLE_P:
6343 c_parser_consume_token (parser);
6344 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6346 expr.value = error_mark_node;
6349 t1 = c_parser_type_name (parser);
6352 expr.value = error_mark_node;
6355 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6357 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6358 expr.value = error_mark_node;
6361 t2 = c_parser_type_name (parser);
6364 expr.value = error_mark_node;
6367 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6372 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6373 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6376 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6379 case RID_AT_SELECTOR:
6380 gcc_assert (c_dialect_objc ());
6381 c_parser_consume_token (parser);
6382 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6384 expr.value = error_mark_node;
6388 tree sel = c_parser_objc_selector_arg (parser);
6389 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6391 expr.value = objc_build_selector_expr (loc, sel);
6394 case RID_AT_PROTOCOL:
6395 gcc_assert (c_dialect_objc ());
6396 c_parser_consume_token (parser);
6397 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6399 expr.value = error_mark_node;
6402 if (c_parser_next_token_is_not (parser, CPP_NAME))
6404 c_parser_error (parser, "expected identifier");
6405 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6406 expr.value = error_mark_node;
6410 tree id = c_parser_peek_token (parser)->value;
6411 c_parser_consume_token (parser);
6412 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6414 expr.value = objc_build_protocol_expr (id);
6418 /* Extension to support C-structures in the archiver. */
6419 gcc_assert (c_dialect_objc ());
6420 c_parser_consume_token (parser);
6421 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6423 expr.value = error_mark_node;
6426 t1 = c_parser_type_name (parser);
6429 expr.value = error_mark_node;
6430 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6433 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6436 tree type = groktypename (t1, NULL, NULL);
6437 expr.value = objc_build_encode_expr (type);
6441 c_parser_error (parser, "expected expression");
6442 expr.value = error_mark_node;
6446 case CPP_OPEN_SQUARE:
6447 if (c_dialect_objc ())
6449 tree receiver, args;
6450 c_parser_consume_token (parser);
6451 receiver = c_parser_objc_receiver (parser);
6452 args = c_parser_objc_message_args (parser);
6453 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6455 expr.value = objc_build_message_expr (build_tree_list (receiver,
6459 /* Else fall through to report error. */
6461 c_parser_error (parser, "expected expression");
6462 expr.value = error_mark_node;
6465 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6468 /* Parse a postfix expression after a parenthesized type name: the
6469 brace-enclosed initializer of a compound literal, possibly followed
6470 by some postfix operators. This is separate because it is not
6471 possible to tell until after the type name whether a cast
6472 expression has a cast or a compound literal, or whether the operand
6473 of sizeof is a parenthesized type name or starts with a compound
6474 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6475 location of the first token after the parentheses around the type
6478 static struct c_expr
6479 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6480 struct c_type_name *type_name,
6481 location_t type_loc)
6487 location_t start_loc;
6488 tree type_expr = NULL_TREE;
6489 bool type_expr_const = true;
6490 check_compound_literal_type (type_loc, type_name);
6491 start_init (NULL_TREE, NULL, 0);
6492 type = groktypename (type_name, &type_expr, &type_expr_const);
6493 start_loc = c_parser_peek_token (parser)->location;
6494 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6496 error_at (type_loc, "compound literal has variable size");
6497 type = error_mark_node;
6499 init = c_parser_braced_init (parser, type, false);
6501 maybe_warn_string_init (type, init);
6503 if (type != error_mark_node
6504 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6505 && current_function_decl)
6507 error ("compound literal qualified by address-space qualifier");
6508 type = error_mark_node;
6512 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6513 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6514 ? CONSTRUCTOR_NON_CONST (init.value)
6515 : init.original_code == C_MAYBE_CONST_EXPR);
6516 non_const |= !type_expr_const;
6517 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6518 expr.original_code = ERROR_MARK;
6519 expr.original_type = NULL;
6522 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6524 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6525 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6529 gcc_assert (!non_const);
6530 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6531 type_expr, expr.value);
6534 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6537 /* Parse a postfix expression after the initial primary or compound
6538 literal; that is, parse a series of postfix operators.
6540 EXPR_LOC is the location of the primary expression. */
6542 static struct c_expr
6543 c_parser_postfix_expression_after_primary (c_parser *parser,
6544 location_t expr_loc,
6547 struct c_expr orig_expr;
6549 VEC(tree,gc) *exprlist;
6550 VEC(tree,gc) *origtypes;
6553 location_t op_loc = c_parser_peek_token (parser)->location;
6554 switch (c_parser_peek_token (parser)->type)
6556 case CPP_OPEN_SQUARE:
6557 /* Array reference. */
6558 c_parser_consume_token (parser);
6559 idx = c_parser_expression (parser).value;
6560 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6562 expr.value = build_array_ref (op_loc, expr.value, idx);
6563 expr.original_code = ERROR_MARK;
6564 expr.original_type = NULL;
6566 case CPP_OPEN_PAREN:
6567 /* Function call. */
6568 c_parser_consume_token (parser);
6569 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6572 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6573 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6576 mark_exp_read (expr.value);
6577 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6578 "(" after the FUNCNAME, which is what we have now. */
6579 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6581 expr.original_code = ERROR_MARK;
6582 if (TREE_CODE (expr.value) == INTEGER_CST
6583 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6584 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6585 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6586 expr.original_code = C_MAYBE_CONST_EXPR;
6587 expr.original_type = NULL;
6588 if (exprlist != NULL)
6590 release_tree_vector (exprlist);
6591 release_tree_vector (origtypes);
6595 /* Structure element reference. */
6596 c_parser_consume_token (parser);
6597 expr = default_function_array_conversion (expr_loc, expr);
6598 if (c_parser_next_token_is (parser, CPP_NAME))
6599 ident = c_parser_peek_token (parser)->value;
6602 c_parser_error (parser, "expected identifier");
6603 expr.value = error_mark_node;
6604 expr.original_code = ERROR_MARK;
6605 expr.original_type = NULL;
6608 c_parser_consume_token (parser);
6609 expr.value = build_component_ref (op_loc, expr.value, ident);
6610 expr.original_code = ERROR_MARK;
6611 if (TREE_CODE (expr.value) != COMPONENT_REF)
6612 expr.original_type = NULL;
6615 /* Remember the original type of a bitfield. */
6616 tree field = TREE_OPERAND (expr.value, 1);
6617 if (TREE_CODE (field) != FIELD_DECL)
6618 expr.original_type = NULL;
6620 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6624 /* Structure element reference. */
6625 c_parser_consume_token (parser);
6626 expr = default_function_array_conversion (expr_loc, expr);
6627 if (c_parser_next_token_is (parser, CPP_NAME))
6628 ident = c_parser_peek_token (parser)->value;
6631 c_parser_error (parser, "expected identifier");
6632 expr.value = error_mark_node;
6633 expr.original_code = ERROR_MARK;
6634 expr.original_type = NULL;
6637 c_parser_consume_token (parser);
6638 expr.value = build_component_ref (op_loc,
6639 build_indirect_ref (op_loc,
6643 expr.original_code = ERROR_MARK;
6644 if (TREE_CODE (expr.value) != COMPONENT_REF)
6645 expr.original_type = NULL;
6648 /* Remember the original type of a bitfield. */
6649 tree field = TREE_OPERAND (expr.value, 1);
6650 if (TREE_CODE (field) != FIELD_DECL)
6651 expr.original_type = NULL;
6653 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6657 /* Postincrement. */
6658 c_parser_consume_token (parser);
6659 expr = default_function_array_read_conversion (expr_loc, expr);
6660 expr.value = build_unary_op (op_loc,
6661 POSTINCREMENT_EXPR, expr.value, 0);
6662 expr.original_code = ERROR_MARK;
6663 expr.original_type = NULL;
6665 case CPP_MINUS_MINUS:
6666 /* Postdecrement. */
6667 c_parser_consume_token (parser);
6668 expr = default_function_array_read_conversion (expr_loc, expr);
6669 expr.value = build_unary_op (op_loc,
6670 POSTDECREMENT_EXPR, expr.value, 0);
6671 expr.original_code = ERROR_MARK;
6672 expr.original_type = NULL;
6680 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6683 assignment-expression
6684 expression , assignment-expression
6687 static struct c_expr
6688 c_parser_expression (c_parser *parser)
6691 expr = c_parser_expr_no_commas (parser, NULL);
6692 while (c_parser_next_token_is (parser, CPP_COMMA))
6696 location_t loc = c_parser_peek_token (parser)->location;
6697 location_t expr_loc;
6698 c_parser_consume_token (parser);
6699 expr_loc = c_parser_peek_token (parser)->location;
6700 lhsval = expr.value;
6701 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6702 lhsval = TREE_OPERAND (lhsval, 1);
6703 if (DECL_P (lhsval) || handled_component_p (lhsval))
6704 mark_exp_read (lhsval);
6705 next = c_parser_expr_no_commas (parser, NULL);
6706 next = default_function_array_conversion (expr_loc, next);
6707 expr.value = build_compound_expr (loc, expr.value, next.value);
6708 expr.original_code = COMPOUND_EXPR;
6709 expr.original_type = next.original_type;
6714 /* Parse an expression and convert functions or arrays to
6717 static struct c_expr
6718 c_parser_expression_conv (c_parser *parser)
6721 location_t loc = c_parser_peek_token (parser)->location;
6722 expr = c_parser_expression (parser);
6723 expr = default_function_array_conversion (loc, expr);
6727 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6728 functions and arrays to pointers. If FOLD_P, fold the expressions.
6731 assignment-expression
6732 nonempty-expr-list , assignment-expression
6735 static VEC(tree,gc) *
6736 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6737 VEC(tree,gc) **p_orig_types)
6740 VEC(tree,gc) *orig_types;
6742 location_t loc = c_parser_peek_token (parser)->location;
6744 ret = make_tree_vector ();
6745 if (p_orig_types == NULL)
6748 orig_types = make_tree_vector ();
6750 expr = c_parser_expr_no_commas (parser, NULL);
6752 expr = default_function_array_read_conversion (loc, expr);
6754 expr.value = c_fully_fold (expr.value, false, NULL);
6755 VEC_quick_push (tree, ret, expr.value);
6756 if (orig_types != NULL)
6757 VEC_quick_push (tree, orig_types, expr.original_type);
6758 while (c_parser_next_token_is (parser, CPP_COMMA))
6760 c_parser_consume_token (parser);
6761 loc = c_parser_peek_token (parser)->location;
6762 expr = c_parser_expr_no_commas (parser, NULL);
6764 expr = default_function_array_read_conversion (loc, expr);
6766 expr.value = c_fully_fold (expr.value, false, NULL);
6767 VEC_safe_push (tree, gc, ret, expr.value);
6768 if (orig_types != NULL)
6769 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6771 if (orig_types != NULL)
6772 *p_orig_types = orig_types;
6776 /* Parse Objective-C-specific constructs. */
6778 /* Parse an objc-class-definition.
6780 objc-class-definition:
6781 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6782 objc-class-instance-variables[opt] objc-methodprotolist @end
6783 @implementation identifier objc-superclass[opt]
6784 objc-class-instance-variables[opt]
6785 @interface identifier ( identifier ) objc-protocol-refs[opt]
6786 objc-methodprotolist @end
6787 @interface identifier ( ) objc-protocol-refs[opt]
6788 objc-methodprotolist @end
6789 @implementation identifier ( identifier )
6794 "@interface identifier (" must start "@interface identifier (
6795 identifier ) ...": objc-methodprotolist in the first production may
6796 not start with a parenthesized identifier as a declarator of a data
6797 definition with no declaration specifiers if the objc-superclass,
6798 objc-protocol-refs and objc-class-instance-variables are omitted. */
6801 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6806 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6808 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6813 c_parser_consume_token (parser);
6814 if (c_parser_next_token_is_not (parser, CPP_NAME))
6816 c_parser_error (parser, "expected identifier");
6819 id1 = c_parser_peek_token (parser)->value;
6820 c_parser_consume_token (parser);
6821 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6823 /* We have a category or class extension. */
6825 tree proto = NULL_TREE;
6826 c_parser_consume_token (parser);
6827 if (c_parser_next_token_is_not (parser, CPP_NAME))
6829 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6831 /* We have a class extension. */
6836 c_parser_error (parser, "expected identifier or %<)%>");
6837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6843 id2 = c_parser_peek_token (parser)->value;
6844 c_parser_consume_token (parser);
6846 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6849 objc_start_category_implementation (id1, id2);
6852 if (c_parser_next_token_is (parser, CPP_LESS))
6853 proto = c_parser_objc_protocol_refs (parser);
6854 objc_start_category_interface (id1, id2, proto, attributes);
6855 c_parser_objc_methodprotolist (parser);
6856 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6857 objc_finish_interface ();
6860 if (c_parser_next_token_is (parser, CPP_COLON))
6862 c_parser_consume_token (parser);
6863 if (c_parser_next_token_is_not (parser, CPP_NAME))
6865 c_parser_error (parser, "expected identifier");
6868 superclass = c_parser_peek_token (parser)->value;
6869 c_parser_consume_token (parser);
6872 superclass = NULL_TREE;
6875 tree proto = NULL_TREE;
6876 if (c_parser_next_token_is (parser, CPP_LESS))
6877 proto = c_parser_objc_protocol_refs (parser);
6878 objc_start_class_interface (id1, superclass, proto, attributes);
6881 objc_start_class_implementation (id1, superclass);
6882 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6883 c_parser_objc_class_instance_variables (parser);
6886 objc_continue_interface ();
6887 c_parser_objc_methodprotolist (parser);
6888 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6889 objc_finish_interface ();
6893 objc_continue_implementation ();
6898 /* Parse objc-class-instance-variables.
6900 objc-class-instance-variables:
6901 { objc-instance-variable-decl-list[opt] }
6903 objc-instance-variable-decl-list:
6904 objc-visibility-spec
6905 objc-instance-variable-decl ;
6907 objc-instance-variable-decl-list objc-visibility-spec
6908 objc-instance-variable-decl-list objc-instance-variable-decl ;
6909 objc-instance-variable-decl-list ;
6911 objc-visibility-spec:
6916 objc-instance-variable-decl:
6921 c_parser_objc_class_instance_variables (c_parser *parser)
6923 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6924 c_parser_consume_token (parser);
6925 while (c_parser_next_token_is_not (parser, CPP_EOF))
6928 /* Parse any stray semicolon. */
6929 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6931 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6932 "extra semicolon in struct or union specified");
6933 c_parser_consume_token (parser);
6936 /* Stop if at the end of the instance variables. */
6937 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6939 c_parser_consume_token (parser);
6942 /* Parse any objc-visibility-spec. */
6943 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6945 c_parser_consume_token (parser);
6946 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6949 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6951 c_parser_consume_token (parser);
6952 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6955 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6957 c_parser_consume_token (parser);
6958 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6961 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6963 c_parser_consume_token (parser);
6964 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6967 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6969 c_parser_pragma (parser, pragma_external);
6973 /* Parse some comma-separated declarations. */
6974 decls = c_parser_struct_declaration (parser);
6976 /* Comma-separated instance variables are chained together in
6977 reverse order; add them one by one. */
6978 tree ivar = nreverse (decls);
6979 for (; ivar; ivar = DECL_CHAIN (ivar))
6980 objc_add_instance_variable (copy_node (ivar));
6982 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6986 /* Parse an objc-class-declaration.
6988 objc-class-declaration:
6989 @class identifier-list ;
6993 c_parser_objc_class_declaration (c_parser *parser)
6995 tree list = NULL_TREE;
6996 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6997 c_parser_consume_token (parser);
6998 /* Any identifiers, including those declared as type names, are OK
7003 if (c_parser_next_token_is_not (parser, CPP_NAME))
7005 c_parser_error (parser, "expected identifier");
7006 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7007 parser->error = false;
7010 id = c_parser_peek_token (parser)->value;
7011 list = chainon (list, build_tree_list (NULL_TREE, id));
7012 c_parser_consume_token (parser);
7013 if (c_parser_next_token_is (parser, CPP_COMMA))
7014 c_parser_consume_token (parser);
7018 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7019 objc_declare_class (list);
7022 /* Parse an objc-alias-declaration.
7024 objc-alias-declaration:
7025 @compatibility_alias identifier identifier ;
7029 c_parser_objc_alias_declaration (c_parser *parser)
7032 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7033 c_parser_consume_token (parser);
7034 if (c_parser_next_token_is_not (parser, CPP_NAME))
7036 c_parser_error (parser, "expected identifier");
7037 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7040 id1 = c_parser_peek_token (parser)->value;
7041 c_parser_consume_token (parser);
7042 if (c_parser_next_token_is_not (parser, CPP_NAME))
7044 c_parser_error (parser, "expected identifier");
7045 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7048 id2 = c_parser_peek_token (parser)->value;
7049 c_parser_consume_token (parser);
7050 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7051 objc_declare_alias (id1, id2);
7054 /* Parse an objc-protocol-definition.
7056 objc-protocol-definition:
7057 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7058 @protocol identifier-list ;
7060 "@protocol identifier ;" should be resolved as "@protocol
7061 identifier-list ;": objc-methodprotolist may not start with a
7062 semicolon in the first alternative if objc-protocol-refs are
7066 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7068 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7070 c_parser_consume_token (parser);
7071 if (c_parser_next_token_is_not (parser, CPP_NAME))
7073 c_parser_error (parser, "expected identifier");
7076 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7077 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7079 tree list = NULL_TREE;
7080 /* Any identifiers, including those declared as type names, are
7085 if (c_parser_next_token_is_not (parser, CPP_NAME))
7087 c_parser_error (parser, "expected identifier");
7090 id = c_parser_peek_token (parser)->value;
7091 list = chainon (list, build_tree_list (NULL_TREE, id));
7092 c_parser_consume_token (parser);
7093 if (c_parser_next_token_is (parser, CPP_COMMA))
7094 c_parser_consume_token (parser);
7098 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7099 objc_declare_protocols (list, attributes);
7103 tree id = c_parser_peek_token (parser)->value;
7104 tree proto = NULL_TREE;
7105 c_parser_consume_token (parser);
7106 if (c_parser_next_token_is (parser, CPP_LESS))
7107 proto = c_parser_objc_protocol_refs (parser);
7108 parser->objc_pq_context = true;
7109 objc_start_protocol (id, proto, attributes);
7110 c_parser_objc_methodprotolist (parser);
7111 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7112 parser->objc_pq_context = false;
7113 objc_finish_interface ();
7117 /* Parse an objc-method-type.
7123 Return true if it is a class method (+) and false if it is
7124 an instance method (-).
7127 c_parser_objc_method_type (c_parser *parser)
7129 switch (c_parser_peek_token (parser)->type)
7132 c_parser_consume_token (parser);
7135 c_parser_consume_token (parser);
7142 /* Parse an objc-method-definition.
7144 objc-method-definition:
7145 objc-method-type objc-method-decl ;[opt] compound-statement
7149 c_parser_objc_method_definition (c_parser *parser)
7151 bool is_class_method = c_parser_objc_method_type (parser);
7152 tree decl, attributes = NULL_TREE;
7153 parser->objc_pq_context = true;
7154 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7155 if (decl == error_mark_node)
7156 return; /* Bail here. */
7158 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7160 c_parser_consume_token (parser);
7161 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7162 "extra semicolon in method definition specified");
7165 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7167 c_parser_error (parser, "expected %<{%>");
7171 parser->objc_pq_context = false;
7172 if (objc_start_method_definition (is_class_method, decl, attributes))
7174 add_stmt (c_parser_compound_statement (parser));
7175 objc_finish_method_definition (current_function_decl);
7179 /* This code is executed when we find a method definition
7180 outside of an @implementation context (or invalid for other
7181 reasons). Parse the method (to keep going) but do not emit
7184 c_parser_compound_statement (parser);
7188 /* Parse an objc-methodprotolist.
7190 objc-methodprotolist:
7192 objc-methodprotolist objc-methodproto
7193 objc-methodprotolist declaration
7194 objc-methodprotolist ;
7198 The declaration is a data definition, which may be missing
7199 declaration specifiers under the same rules and diagnostics as
7200 other data definitions outside functions, and the stray semicolon
7201 is diagnosed the same way as a stray semicolon outside a
7205 c_parser_objc_methodprotolist (c_parser *parser)
7209 /* The list is terminated by @end. */
7210 switch (c_parser_peek_token (parser)->type)
7213 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7214 "ISO C does not allow extra %<;%> outside of a function");
7215 c_parser_consume_token (parser);
7219 c_parser_objc_methodproto (parser);
7222 c_parser_pragma (parser, pragma_external);
7227 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7229 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7230 c_parser_objc_at_property_declaration (parser);
7231 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7233 objc_set_method_opt (true);
7234 c_parser_consume_token (parser);
7236 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7238 objc_set_method_opt (false);
7239 c_parser_consume_token (parser);
7242 c_parser_declaration_or_fndef (parser, false, false, true,
7249 /* Parse an objc-methodproto.
7252 objc-method-type objc-method-decl ;
7256 c_parser_objc_methodproto (c_parser *parser)
7258 bool is_class_method = c_parser_objc_method_type (parser);
7259 tree decl, attributes = NULL_TREE;
7261 /* Remember protocol qualifiers in prototypes. */
7262 parser->objc_pq_context = true;
7263 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes);
7264 /* Forget protocol qualifiers now. */
7265 parser->objc_pq_context = false;
7267 /* Do not allow the presence of attributes to hide an erroneous
7268 method implementation in the interface section. */
7269 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7271 c_parser_error (parser, "expected %<;%>");
7275 if (decl != error_mark_node)
7276 objc_add_method_declaration (is_class_method, decl, attributes);
7278 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7281 /* If we are at a position that method attributes may be present, check that
7282 there are not any parsed already (a syntax error) and then collect any
7283 specified at the current location. Finally, if new attributes were present,
7284 check that the next token is legal ( ';' for decls and '{' for defs). */
7287 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7292 c_parser_error (parser,
7293 "method attributes must be specified at the end only");
7294 *attributes = NULL_TREE;
7298 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7299 *attributes = c_parser_attributes (parser);
7301 /* If there were no attributes here, just report any earlier error. */
7302 if (*attributes == NULL_TREE || bad)
7305 /* If the attributes are followed by a ; or {, then just report any earlier
7307 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7308 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7311 /* We've got attributes, but not at the end. */
7312 c_parser_error (parser,
7313 "expected %<;%> or %<{%> after method attribute definition");
7317 /* Parse an objc-method-decl.
7320 ( objc-type-name ) objc-selector
7322 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7323 objc-keyword-selector objc-optparmlist
7326 objc-keyword-selector:
7328 objc-keyword-selector objc-keyword-decl
7331 objc-selector : ( objc-type-name ) identifier
7332 objc-selector : identifier
7333 : ( objc-type-name ) identifier
7337 objc-optparms objc-optellipsis
7341 objc-opt-parms , parameter-declaration
7349 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, tree *attributes)
7351 tree type = NULL_TREE;
7353 tree parms = NULL_TREE;
7354 bool ellipsis = false;
7355 bool attr_err = false;
7357 *attributes = NULL_TREE;
7358 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7360 c_parser_consume_token (parser);
7361 type = c_parser_objc_type_name (parser);
7362 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7364 sel = c_parser_objc_selector (parser);
7365 /* If there is no selector, or a colon follows, we have an
7366 objc-keyword-selector. If there is a selector, and a colon does
7367 not follow, that selector ends the objc-method-decl. */
7368 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7371 tree list = NULL_TREE;
7374 tree atype = NULL_TREE, id, keyworddecl;
7375 tree param_attr = NULL_TREE;
7376 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7378 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7380 c_parser_consume_token (parser);
7381 atype = c_parser_objc_type_name (parser);
7382 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7385 /* New ObjC allows attributes on method parameters. */
7386 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7387 param_attr = c_parser_attributes (parser);
7388 if (c_parser_next_token_is_not (parser, CPP_NAME))
7390 c_parser_error (parser, "expected identifier");
7391 return error_mark_node;
7393 id = c_parser_peek_token (parser)->value;
7394 c_parser_consume_token (parser);
7395 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7396 list = chainon (list, keyworddecl);
7397 tsel = c_parser_objc_selector (parser);
7398 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7402 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7404 /* Parse the optional parameter list. Optional Objective-C
7405 method parameters follow the C syntax, and may include '...'
7406 to denote a variable number of arguments. */
7407 parms = make_node (TREE_LIST);
7408 while (c_parser_next_token_is (parser, CPP_COMMA))
7410 struct c_parm *parm;
7411 c_parser_consume_token (parser);
7412 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7415 c_parser_consume_token (parser);
7416 attr_err |= c_parser_objc_maybe_method_attributes
7417 (parser, attributes) ;
7420 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7423 parms = chainon (parms,
7424 build_tree_list (NULL_TREE, grokparm (parm)));
7429 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7433 c_parser_error (parser, "objective-c method declaration is expected");
7434 return error_mark_node;
7438 return error_mark_node;
7440 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7443 /* Parse an objc-type-name.
7446 objc-type-qualifiers[opt] type-name
7447 objc-type-qualifiers[opt]
7449 objc-type-qualifiers:
7451 objc-type-qualifiers objc-type-qualifier
7453 objc-type-qualifier: one of
7454 in out inout bycopy byref oneway
7458 c_parser_objc_type_name (c_parser *parser)
7460 tree quals = NULL_TREE;
7461 struct c_type_name *type_name = NULL;
7462 tree type = NULL_TREE;
7465 c_token *token = c_parser_peek_token (parser);
7466 if (token->type == CPP_KEYWORD
7467 && (token->keyword == RID_IN
7468 || token->keyword == RID_OUT
7469 || token->keyword == RID_INOUT
7470 || token->keyword == RID_BYCOPY
7471 || token->keyword == RID_BYREF
7472 || token->keyword == RID_ONEWAY))
7474 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7475 c_parser_consume_token (parser);
7480 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7481 type_name = c_parser_type_name (parser);
7483 type = groktypename (type_name, NULL, NULL);
7485 /* If the type is unknown, and error has already been produced and
7486 we need to recover from the error. In that case, use NULL_TREE
7487 for the type, as if no type had been specified; this will use the
7488 default type ('id') which is good for error recovery. */
7489 if (type == error_mark_node)
7492 return build_tree_list (quals, type);
7495 /* Parse objc-protocol-refs.
7502 c_parser_objc_protocol_refs (c_parser *parser)
7504 tree list = NULL_TREE;
7505 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7506 c_parser_consume_token (parser);
7507 /* Any identifiers, including those declared as type names, are OK
7512 if (c_parser_next_token_is_not (parser, CPP_NAME))
7514 c_parser_error (parser, "expected identifier");
7517 id = c_parser_peek_token (parser)->value;
7518 list = chainon (list, build_tree_list (NULL_TREE, id));
7519 c_parser_consume_token (parser);
7520 if (c_parser_next_token_is (parser, CPP_COMMA))
7521 c_parser_consume_token (parser);
7525 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7529 /* Parse an objc-try-catch-finally-statement.
7531 objc-try-catch-finally-statement:
7532 @try compound-statement objc-catch-list[opt]
7533 @try compound-statement objc-catch-list[opt] @finally compound-statement
7536 @catch ( objc-catch-parameter-declaration ) compound-statement
7537 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7539 objc-catch-parameter-declaration:
7540 parameter-declaration
7543 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7545 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7546 for C++. Keep them in sync. */
7549 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7551 location_t location;
7554 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7555 c_parser_consume_token (parser);
7556 location = c_parser_peek_token (parser)->location;
7557 objc_maybe_warn_exceptions (location);
7558 stmt = c_parser_compound_statement (parser);
7559 objc_begin_try_stmt (location, stmt);
7561 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7563 struct c_parm *parm;
7564 tree parameter_declaration = error_mark_node;
7565 bool seen_open_paren = false;
7567 c_parser_consume_token (parser);
7568 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7569 seen_open_paren = true;
7570 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7572 /* We have "@catch (...)" (where the '...' are literally
7573 what is in the code). Skip the '...'.
7574 parameter_declaration is set to NULL_TREE, and
7575 objc_being_catch_clauses() knows that that means
7577 c_parser_consume_token (parser);
7578 parameter_declaration = NULL_TREE;
7582 /* We have "@catch (NSException *exception)" or something
7583 like that. Parse the parameter declaration. */
7584 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7586 parameter_declaration = error_mark_node;
7588 parameter_declaration = grokparm (parm);
7590 if (seen_open_paren)
7591 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7594 /* If there was no open parenthesis, we are recovering from
7595 an error, and we are trying to figure out what mistake
7596 the user has made. */
7598 /* If there is an immediate closing parenthesis, the user
7599 probably forgot the opening one (ie, they typed "@catch
7600 NSException *e)". Parse the closing parenthesis and keep
7602 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7603 c_parser_consume_token (parser);
7605 /* If these is no immediate closing parenthesis, the user
7606 probably doesn't know that parenthesis are required at
7607 all (ie, they typed "@catch NSException *e"). So, just
7608 forget about the closing parenthesis and keep going. */
7610 objc_begin_catch_clause (parameter_declaration);
7611 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7612 c_parser_compound_statement_nostart (parser);
7613 objc_finish_catch_clause ();
7615 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7617 c_parser_consume_token (parser);
7618 location = c_parser_peek_token (parser)->location;
7619 stmt = c_parser_compound_statement (parser);
7620 objc_build_finally_clause (location, stmt);
7622 objc_finish_try_stmt ();
7625 /* Parse an objc-synchronized-statement.
7627 objc-synchronized-statement:
7628 @synchronized ( expression ) compound-statement
7632 c_parser_objc_synchronized_statement (c_parser *parser)
7636 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7637 c_parser_consume_token (parser);
7638 loc = c_parser_peek_token (parser)->location;
7639 objc_maybe_warn_exceptions (loc);
7640 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7642 expr = c_parser_expression (parser).value;
7643 expr = c_fully_fold (expr, false, NULL);
7644 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7647 expr = error_mark_node;
7648 stmt = c_parser_compound_statement (parser);
7649 objc_build_synchronized (loc, expr, stmt);
7652 /* Parse an objc-selector; return NULL_TREE without an error if the
7653 next token is not an objc-selector.
7658 enum struct union if else while do for switch case default
7659 break continue return goto asm sizeof typeof __alignof
7660 unsigned long const short volatile signed restrict _Complex
7661 in out inout bycopy byref oneway int char float double void _Bool
7663 ??? Why this selection of keywords but not, for example, storage
7664 class specifiers? */
7667 c_parser_objc_selector (c_parser *parser)
7669 c_token *token = c_parser_peek_token (parser);
7670 tree value = token->value;
7671 if (token->type == CPP_NAME)
7673 c_parser_consume_token (parser);
7676 if (token->type != CPP_KEYWORD)
7678 switch (token->keyword)
7720 c_parser_consume_token (parser);
7727 /* Parse an objc-selector-arg.
7731 objc-keywordname-list
7733 objc-keywordname-list:
7735 objc-keywordname-list objc-keywordname
7743 c_parser_objc_selector_arg (c_parser *parser)
7745 tree sel = c_parser_objc_selector (parser);
7746 tree list = NULL_TREE;
7747 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7751 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7753 list = chainon (list, build_tree_list (sel, NULL_TREE));
7754 sel = c_parser_objc_selector (parser);
7755 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7761 /* Parse an objc-receiver.
7770 c_parser_objc_receiver (c_parser *parser)
7772 if (c_parser_peek_token (parser)->type == CPP_NAME
7773 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7774 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7776 tree id = c_parser_peek_token (parser)->value;
7777 c_parser_consume_token (parser);
7778 return objc_get_class_reference (id);
7780 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7783 /* Parse objc-message-args.
7787 objc-keywordarg-list
7789 objc-keywordarg-list:
7791 objc-keywordarg-list objc-keywordarg
7794 objc-selector : objc-keywordexpr
7799 c_parser_objc_message_args (c_parser *parser)
7801 tree sel = c_parser_objc_selector (parser);
7802 tree list = NULL_TREE;
7803 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7808 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7809 return error_mark_node;
7810 keywordexpr = c_parser_objc_keywordexpr (parser);
7811 list = chainon (list, build_tree_list (sel, keywordexpr));
7812 sel = c_parser_objc_selector (parser);
7813 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7819 /* Parse an objc-keywordexpr.
7826 c_parser_objc_keywordexpr (c_parser *parser)
7829 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7830 if (VEC_length (tree, expr_list) == 1)
7832 /* Just return the expression, remove a level of
7834 ret = VEC_index (tree, expr_list, 0);
7838 /* We have a comma expression, we will collapse later. */
7839 ret = build_tree_list_vec (expr_list);
7841 release_tree_vector (expr_list);
7845 /* A check, needed in several places, that ObjC interface, implementation or
7846 method definitions are not prefixed by incorrect items. */
7848 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7849 struct c_declspecs *specs)
7851 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7852 || specs->typespec_kind != ctsk_none)
7854 c_parser_error (parser,
7855 "no type or storage class may be specified here,");
7856 c_parser_skip_to_end_of_block_or_statement (parser);
7862 /* Parse an Objective-C @property declaration. The syntax is:
7864 objc-property-declaration:
7865 '@property' objc-property-attributes[opt] struct-declaration ;
7867 objc-property-attributes:
7868 '(' objc-property-attribute-list ')'
7870 objc-property-attribute-list:
7871 objc-property-attribute
7872 objc-property-attribute-list, objc-property-attribute
7874 objc-property-attribute
7875 'getter' = identifier
7876 'setter' = identifier
7885 @property NSString *name;
7886 @property (readonly) id object;
7887 @property (retain, nonatomic, getter=getTheName) id name;
7888 @property int a, b, c;
7890 PS: This function is identical to cp_parser_objc_at_propery_declaration
7891 for C++. Keep them in sync. */
7893 c_parser_objc_at_property_declaration (c_parser *parser)
7895 /* The following variables hold the attributes of the properties as
7896 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7897 seen. When we see an attribute, we set them to 'true' (if they
7898 are boolean properties) or to the identifier (if they have an
7899 argument, ie, for getter and setter). Note that here we only
7900 parse the list of attributes, check the syntax and accumulate the
7901 attributes that we find. objc_add_property_declaration() will
7902 then process the information. */
7903 bool property_assign = false;
7904 bool property_copy = false;
7905 tree property_getter_ident = NULL_TREE;
7906 bool property_nonatomic = false;
7907 bool property_readonly = false;
7908 bool property_readwrite = false;
7909 bool property_retain = false;
7910 tree property_setter_ident = NULL_TREE;
7912 /* 'properties' is the list of properties that we read. Usually a
7913 single one, but maybe more (eg, in "@property int a, b, c;" there
7918 loc = c_parser_peek_token (parser)->location;
7919 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7921 c_parser_consume_token (parser); /* Eat '@property'. */
7923 /* Parse the optional attribute list... */
7924 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7927 c_parser_consume_token (parser);
7929 /* Property attribute keywords are valid now. */
7930 parser->objc_property_attr_context = true;
7934 bool syntax_error = false;
7935 c_token *token = c_parser_peek_token (parser);
7938 if (token->type != CPP_KEYWORD)
7940 if (token->type == CPP_CLOSE_PAREN)
7941 c_parser_error (parser, "expected identifier");
7944 c_parser_consume_token (parser);
7945 c_parser_error (parser, "unknown property attribute");
7949 keyword = token->keyword;
7950 c_parser_consume_token (parser);
7953 case RID_ASSIGN: property_assign = true; break;
7954 case RID_COPY: property_copy = true; break;
7955 case RID_NONATOMIC: property_nonatomic = true; break;
7956 case RID_READONLY: property_readonly = true; break;
7957 case RID_READWRITE: property_readwrite = true; break;
7958 case RID_RETAIN: property_retain = true; break;
7962 if (c_parser_next_token_is_not (parser, CPP_EQ))
7964 c_parser_error (parser,
7965 "getter/setter attribute must be followed by %<=%>");
7966 syntax_error = true;
7969 c_parser_consume_token (parser); /* eat the = */
7970 if (c_parser_next_token_is_not (parser, CPP_NAME))
7972 c_parser_error (parser, "expected identifier");
7973 syntax_error = true;
7976 if (keyword == RID_SETTER)
7978 if (property_setter_ident != NULL_TREE)
7979 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
7981 property_setter_ident = c_parser_peek_token (parser)->value;
7982 c_parser_consume_token (parser);
7983 if (c_parser_next_token_is_not (parser, CPP_COLON))
7984 c_parser_error (parser, "setter name must terminate with %<:%>");
7986 c_parser_consume_token (parser);
7990 if (property_getter_ident != NULL_TREE)
7991 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
7993 property_getter_ident = c_parser_peek_token (parser)->value;
7994 c_parser_consume_token (parser);
7998 c_parser_error (parser, "unknown property attribute");
7999 syntax_error = true;
8006 if (c_parser_next_token_is (parser, CPP_COMMA))
8007 c_parser_consume_token (parser);
8011 parser->objc_property_attr_context = false;
8012 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8014 /* ... and the property declaration(s). */
8015 properties = c_parser_struct_declaration (parser);
8017 if (properties == error_mark_node)
8019 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8020 parser->error = false;
8024 if (properties == NULL_TREE)
8025 c_parser_error (parser, "expected identifier");
8028 /* Comma-separated properties are chained together in
8029 reverse order; add them one by one. */
8030 properties = nreverse (properties);
8032 for (; properties; properties = TREE_CHAIN (properties))
8033 objc_add_property_declaration (loc, copy_node (properties),
8034 property_readonly, property_readwrite,
8035 property_assign, property_retain,
8036 property_copy, property_nonatomic,
8037 property_getter_ident, property_setter_ident);
8040 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8041 parser->error = false;
8044 /* Parse an Objective-C @synthesize declaration. The syntax is:
8046 objc-synthesize-declaration:
8047 @synthesize objc-synthesize-identifier-list ;
8049 objc-synthesize-identifier-list:
8050 objc-synthesize-identifier
8051 objc-synthesize-identifier-list, objc-synthesize-identifier
8053 objc-synthesize-identifier
8055 identifier = identifier
8058 @synthesize MyProperty;
8059 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8061 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8062 for C++. Keep them in sync.
8065 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8067 tree list = NULL_TREE;
8069 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8070 loc = c_parser_peek_token (parser)->location;
8072 c_parser_consume_token (parser);
8075 tree property, ivar;
8076 if (c_parser_next_token_is_not (parser, CPP_NAME))
8078 c_parser_error (parser, "expected identifier");
8079 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8080 /* Once we find the semicolon, we can resume normal parsing.
8081 We have to reset parser->error manually because
8082 c_parser_skip_until_found() won't reset it for us if the
8083 next token is precisely a semicolon. */
8084 parser->error = false;
8087 property = c_parser_peek_token (parser)->value;
8088 c_parser_consume_token (parser);
8089 if (c_parser_next_token_is (parser, CPP_EQ))
8091 c_parser_consume_token (parser);
8092 if (c_parser_next_token_is_not (parser, CPP_NAME))
8094 c_parser_error (parser, "expected identifier");
8095 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8096 parser->error = false;
8099 ivar = c_parser_peek_token (parser)->value;
8100 c_parser_consume_token (parser);
8104 list = chainon (list, build_tree_list (ivar, property));
8105 if (c_parser_next_token_is (parser, CPP_COMMA))
8106 c_parser_consume_token (parser);
8110 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8111 objc_add_synthesize_declaration (loc, list);
8114 /* Parse an Objective-C @dynamic declaration. The syntax is:
8116 objc-dynamic-declaration:
8117 @dynamic identifier-list ;
8120 @dynamic MyProperty;
8121 @dynamic MyProperty, AnotherProperty;
8123 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8124 for C++. Keep them in sync.
8127 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8129 tree list = NULL_TREE;
8131 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8132 loc = c_parser_peek_token (parser)->location;
8134 c_parser_consume_token (parser);
8138 if (c_parser_next_token_is_not (parser, CPP_NAME))
8140 c_parser_error (parser, "expected identifier");
8141 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8142 parser->error = false;
8145 property = c_parser_peek_token (parser)->value;
8146 list = chainon (list, build_tree_list (NULL_TREE, property));
8147 c_parser_consume_token (parser);
8148 if (c_parser_next_token_is (parser, CPP_COMMA))
8149 c_parser_consume_token (parser);
8153 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8154 objc_add_dynamic_declaration (loc, list);
8158 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8159 should be considered, statements. ALLOW_STMT is true if we're within
8160 the context of a function and such pragmas are to be allowed. Returns
8161 true if we actually parsed such a pragma. */
8164 c_parser_pragma (c_parser *parser, enum pragma_context context)
8168 id = c_parser_peek_token (parser)->pragma_kind;
8169 gcc_assert (id != PRAGMA_NONE);
8173 case PRAGMA_OMP_BARRIER:
8174 if (context != pragma_compound)
8176 if (context == pragma_stmt)
8177 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8178 "used in compound statements");
8181 c_parser_omp_barrier (parser);
8184 case PRAGMA_OMP_FLUSH:
8185 if (context != pragma_compound)
8187 if (context == pragma_stmt)
8188 c_parser_error (parser, "%<#pragma omp flush%> may only be "
8189 "used in compound statements");
8192 c_parser_omp_flush (parser);
8195 case PRAGMA_OMP_TASKWAIT:
8196 if (context != pragma_compound)
8198 if (context == pragma_stmt)
8199 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8200 "used in compound statements");
8203 c_parser_omp_taskwait (parser);
8206 case PRAGMA_OMP_THREADPRIVATE:
8207 c_parser_omp_threadprivate (parser);
8210 case PRAGMA_OMP_SECTION:
8211 error_at (c_parser_peek_token (parser)->location,
8212 "%<#pragma omp section%> may only be used in "
8213 "%<#pragma omp sections%> construct");
8214 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8217 case PRAGMA_GCC_PCH_PREPROCESS:
8218 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8219 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8223 if (id < PRAGMA_FIRST_EXTERNAL)
8225 if (context == pragma_external)
8228 c_parser_error (parser, "expected declaration specifiers");
8229 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8232 c_parser_omp_construct (parser);
8238 c_parser_consume_pragma (parser);
8239 c_invoke_pragma_handler (id);
8241 /* Skip to EOL, but suppress any error message. Those will have been
8242 generated by the handler routine through calling error, as opposed
8243 to calling c_parser_error. */
8244 parser->error = true;
8245 c_parser_skip_to_pragma_eol (parser);
8250 /* The interface the pragma parsers have to the lexer. */
8253 pragma_lex (tree *value)
8255 c_token *tok = c_parser_peek_token (the_parser);
8256 enum cpp_ttype ret = tok->type;
8258 *value = tok->value;
8259 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8263 if (ret == CPP_KEYWORD)
8265 c_parser_consume_token (the_parser);
8272 c_parser_pragma_pch_preprocess (c_parser *parser)
8276 c_parser_consume_pragma (parser);
8277 if (c_parser_next_token_is (parser, CPP_STRING))
8279 name = c_parser_peek_token (parser)->value;
8280 c_parser_consume_token (parser);
8283 c_parser_error (parser, "expected string literal");
8284 c_parser_skip_to_pragma_eol (parser);
8287 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8290 /* OpenMP 2.5 parsing routines. */
8292 /* Returns name of the next clause.
8293 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8294 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8295 returned and the token is consumed. */
8297 static pragma_omp_clause
8298 c_parser_omp_clause_name (c_parser *parser)
8300 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8302 if (c_parser_next_token_is_keyword (parser, RID_IF))
8303 result = PRAGMA_OMP_CLAUSE_IF;
8304 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8305 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8306 else if (c_parser_next_token_is (parser, CPP_NAME))
8308 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8313 if (!strcmp ("collapse", p))
8314 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8315 else if (!strcmp ("copyin", p))
8316 result = PRAGMA_OMP_CLAUSE_COPYIN;
8317 else if (!strcmp ("copyprivate", p))
8318 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8321 if (!strcmp ("firstprivate", p))
8322 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8325 if (!strcmp ("lastprivate", p))
8326 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8329 if (!strcmp ("nowait", p))
8330 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8331 else if (!strcmp ("num_threads", p))
8332 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8335 if (!strcmp ("ordered", p))
8336 result = PRAGMA_OMP_CLAUSE_ORDERED;
8339 if (!strcmp ("private", p))
8340 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8343 if (!strcmp ("reduction", p))
8344 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8347 if (!strcmp ("schedule", p))
8348 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8349 else if (!strcmp ("shared", p))
8350 result = PRAGMA_OMP_CLAUSE_SHARED;
8353 if (!strcmp ("untied", p))
8354 result = PRAGMA_OMP_CLAUSE_UNTIED;
8359 if (result != PRAGMA_OMP_CLAUSE_NONE)
8360 c_parser_consume_token (parser);
8365 /* Validate that a clause of the given type does not already exist. */
8368 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8373 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8374 if (OMP_CLAUSE_CODE (c) == code)
8376 location_t loc = OMP_CLAUSE_LOCATION (c);
8377 error_at (loc, "too many %qs clauses", name);
8385 variable-list , identifier
8387 If KIND is nonzero, create the appropriate node and install the
8388 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8389 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8391 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8392 return the list created. */
8395 c_parser_omp_variable_list (c_parser *parser,
8396 location_t clause_loc,
8397 enum omp_clause_code kind,
8400 if (c_parser_next_token_is_not (parser, CPP_NAME)
8401 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8402 c_parser_error (parser, "expected identifier");
8404 while (c_parser_next_token_is (parser, CPP_NAME)
8405 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8407 tree t = lookup_name (c_parser_peek_token (parser)->value);
8410 undeclared_variable (c_parser_peek_token (parser)->location,
8411 c_parser_peek_token (parser)->value);
8412 else if (t == error_mark_node)
8416 tree u = build_omp_clause (clause_loc, kind);
8417 OMP_CLAUSE_DECL (u) = t;
8418 OMP_CLAUSE_CHAIN (u) = list;
8422 list = tree_cons (t, NULL_TREE, list);
8424 c_parser_consume_token (parser);
8426 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8429 c_parser_consume_token (parser);
8435 /* Similarly, but expect leading and trailing parenthesis. This is a very
8436 common case for omp clauses. */
8439 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8442 /* The clauses location. */
8443 location_t loc = c_parser_peek_token (parser)->location;
8445 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8447 list = c_parser_omp_variable_list (parser, loc, kind, list);
8448 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8454 collapse ( constant-expression ) */
8457 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8459 tree c, num = error_mark_node;
8463 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8465 loc = c_parser_peek_token (parser)->location;
8466 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8468 num = c_parser_expr_no_commas (parser, NULL).value;
8469 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8471 if (num == error_mark_node)
8473 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8474 || !host_integerp (num, 0)
8475 || (n = tree_low_cst (num, 0)) <= 0
8479 "collapse argument needs positive constant integer expression");
8482 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8483 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8484 OMP_CLAUSE_CHAIN (c) = list;
8489 copyin ( variable-list ) */
8492 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8494 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8498 copyprivate ( variable-list ) */
8501 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8503 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8507 default ( shared | none ) */
8510 c_parser_omp_clause_default (c_parser *parser, tree list)
8512 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8513 location_t loc = c_parser_peek_token (parser)->location;
8516 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8518 if (c_parser_next_token_is (parser, CPP_NAME))
8520 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8525 if (strcmp ("none", p) != 0)
8527 kind = OMP_CLAUSE_DEFAULT_NONE;
8531 if (strcmp ("shared", p) != 0)
8533 kind = OMP_CLAUSE_DEFAULT_SHARED;
8540 c_parser_consume_token (parser);
8545 c_parser_error (parser, "expected %<none%> or %<shared%>");
8547 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8549 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8552 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8553 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8554 OMP_CLAUSE_CHAIN (c) = list;
8555 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8561 firstprivate ( variable-list ) */
8564 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8566 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8570 if ( expression ) */
8573 c_parser_omp_clause_if (c_parser *parser, tree list)
8575 location_t loc = c_parser_peek_token (parser)->location;
8576 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8578 tree t = c_parser_paren_condition (parser);
8581 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8583 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8584 OMP_CLAUSE_IF_EXPR (c) = t;
8585 OMP_CLAUSE_CHAIN (c) = list;
8589 c_parser_error (parser, "expected %<(%>");
8595 lastprivate ( variable-list ) */
8598 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8600 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8607 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8610 location_t loc = c_parser_peek_token (parser)->location;
8612 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8614 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8615 OMP_CLAUSE_CHAIN (c) = list;
8620 num_threads ( expression ) */
8623 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8625 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8626 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8628 location_t expr_loc = c_parser_peek_token (parser)->location;
8629 tree c, t = c_parser_expression (parser).value;
8630 t = c_fully_fold (t, false, NULL);
8632 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8634 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8636 c_parser_error (parser, "expected integer expression");
8640 /* Attempt to statically determine when the number isn't positive. */
8641 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8642 build_int_cst (TREE_TYPE (t), 0));
8643 if (CAN_HAVE_LOCATION_P (c))
8644 SET_EXPR_LOCATION (c, expr_loc);
8645 if (c == boolean_true_node)
8647 warning_at (expr_loc, 0,
8648 "%<num_threads%> value must be positive");
8649 t = integer_one_node;
8652 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8654 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8655 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8656 OMP_CLAUSE_CHAIN (c) = list;
8667 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8671 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8673 c = build_omp_clause (c_parser_peek_token (parser)->location,
8674 OMP_CLAUSE_ORDERED);
8675 OMP_CLAUSE_CHAIN (c) = list;
8681 private ( variable-list ) */
8684 c_parser_omp_clause_private (c_parser *parser, tree list)
8686 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8690 reduction ( reduction-operator : variable-list )
8693 One of: + * - & ^ | && || */
8696 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8698 location_t clause_loc = c_parser_peek_token (parser)->location;
8699 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8701 enum tree_code code;
8703 switch (c_parser_peek_token (parser)->type)
8715 code = BIT_AND_EXPR;
8718 code = BIT_XOR_EXPR;
8721 code = BIT_IOR_EXPR;
8724 code = TRUTH_ANDIF_EXPR;
8727 code = TRUTH_ORIF_EXPR;
8730 c_parser_error (parser,
8731 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8732 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8733 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8736 c_parser_consume_token (parser);
8737 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8741 nl = c_parser_omp_variable_list (parser, clause_loc,
8742 OMP_CLAUSE_REDUCTION, list);
8743 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8744 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8748 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8754 schedule ( schedule-kind )
8755 schedule ( schedule-kind , expression )
8758 static | dynamic | guided | runtime | auto
8762 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8765 location_t loc = c_parser_peek_token (parser)->location;
8767 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8770 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8772 if (c_parser_next_token_is (parser, CPP_NAME))
8774 tree kind = c_parser_peek_token (parser)->value;
8775 const char *p = IDENTIFIER_POINTER (kind);
8780 if (strcmp ("dynamic", p) != 0)
8782 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8786 if (strcmp ("guided", p) != 0)
8788 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8792 if (strcmp ("runtime", p) != 0)
8794 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8801 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8802 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8803 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8804 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8808 c_parser_consume_token (parser);
8809 if (c_parser_next_token_is (parser, CPP_COMMA))
8812 c_parser_consume_token (parser);
8814 here = c_parser_peek_token (parser)->location;
8815 t = c_parser_expr_no_commas (parser, NULL).value;
8816 t = c_fully_fold (t, false, NULL);
8818 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8819 error_at (here, "schedule %<runtime%> does not take "
8820 "a %<chunk_size%> parameter");
8821 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8823 "schedule %<auto%> does not take "
8824 "a %<chunk_size%> parameter");
8825 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8826 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8828 c_parser_error (parser, "expected integer expression");
8830 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8833 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8834 "expected %<,%> or %<)%>");
8836 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8837 OMP_CLAUSE_CHAIN (c) = list;
8841 c_parser_error (parser, "invalid schedule kind");
8842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8847 shared ( variable-list ) */
8850 c_parser_omp_clause_shared (c_parser *parser, tree list)
8852 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8859 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8863 /* FIXME: Should we allow duplicates? */
8864 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8866 c = build_omp_clause (c_parser_peek_token (parser)->location,
8868 OMP_CLAUSE_CHAIN (c) = list;
8873 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8874 is a bitmask in MASK. Return the list of clauses found; the result
8875 of clause default goes in *pdefault. */
8878 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8881 tree clauses = NULL;
8884 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8887 pragma_omp_clause c_kind;
8889 tree prev = clauses;
8891 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8892 c_parser_consume_token (parser);
8895 here = c_parser_peek_token (parser)->location;
8896 c_kind = c_parser_omp_clause_name (parser);
8900 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8901 clauses = c_parser_omp_clause_collapse (parser, clauses);
8902 c_name = "collapse";
8904 case PRAGMA_OMP_CLAUSE_COPYIN:
8905 clauses = c_parser_omp_clause_copyin (parser, clauses);
8908 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8909 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8910 c_name = "copyprivate";
8912 case PRAGMA_OMP_CLAUSE_DEFAULT:
8913 clauses = c_parser_omp_clause_default (parser, clauses);
8916 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8917 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8918 c_name = "firstprivate";
8920 case PRAGMA_OMP_CLAUSE_IF:
8921 clauses = c_parser_omp_clause_if (parser, clauses);
8924 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8925 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8926 c_name = "lastprivate";
8928 case PRAGMA_OMP_CLAUSE_NOWAIT:
8929 clauses = c_parser_omp_clause_nowait (parser, clauses);
8932 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8933 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8934 c_name = "num_threads";
8936 case PRAGMA_OMP_CLAUSE_ORDERED:
8937 clauses = c_parser_omp_clause_ordered (parser, clauses);
8940 case PRAGMA_OMP_CLAUSE_PRIVATE:
8941 clauses = c_parser_omp_clause_private (parser, clauses);
8944 case PRAGMA_OMP_CLAUSE_REDUCTION:
8945 clauses = c_parser_omp_clause_reduction (parser, clauses);
8946 c_name = "reduction";
8948 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8949 clauses = c_parser_omp_clause_schedule (parser, clauses);
8950 c_name = "schedule";
8952 case PRAGMA_OMP_CLAUSE_SHARED:
8953 clauses = c_parser_omp_clause_shared (parser, clauses);
8956 case PRAGMA_OMP_CLAUSE_UNTIED:
8957 clauses = c_parser_omp_clause_untied (parser, clauses);
8961 c_parser_error (parser, "expected %<#pragma omp%> clause");
8965 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8967 /* Remove the invalid clause(s) from the list to avoid
8968 confusing the rest of the compiler. */
8970 error_at (here, "%qs is not valid for %qs", c_name, where);
8975 c_parser_skip_to_pragma_eol (parser);
8977 return c_finish_omp_clauses (clauses);
8984 In practice, we're also interested in adding the statement to an
8985 outer node. So it is convenient if we work around the fact that
8986 c_parser_statement calls add_stmt. */
8989 c_parser_omp_structured_block (c_parser *parser)
8991 tree stmt = push_stmt_list ();
8992 c_parser_statement (parser);
8993 return pop_stmt_list (stmt);
8997 # pragma omp atomic new-line
9001 x binop= expr | x++ | ++x | x-- | --x
9003 +, *, -, /, &, ^, |, <<, >>
9005 where x is an lvalue expression with scalar type.
9007 LOC is the location of the #pragma token. */
9010 c_parser_omp_atomic (location_t loc, c_parser *parser)
9014 enum tree_code code;
9015 struct c_expr rhs_expr;
9017 c_parser_skip_to_pragma_eol (parser);
9019 lhs = c_parser_unary_expression (parser).value;
9020 lhs = c_fully_fold (lhs, false, NULL);
9021 switch (TREE_CODE (lhs))
9025 c_parser_skip_to_end_of_block_or_statement (parser);
9028 case PREINCREMENT_EXPR:
9029 case POSTINCREMENT_EXPR:
9030 lhs = TREE_OPERAND (lhs, 0);
9032 rhs = integer_one_node;
9035 case PREDECREMENT_EXPR:
9036 case POSTDECREMENT_EXPR:
9037 lhs = TREE_OPERAND (lhs, 0);
9039 rhs = integer_one_node;
9043 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9044 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9045 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9046 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9047 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9048 (TREE_OPERAND (lhs, 1), 0), 0)))
9050 /* Undo effects of boolean_increment for post {in,de}crement. */
9051 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9054 if (TREE_CODE (lhs) == MODIFY_EXPR
9055 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9057 /* Undo effects of boolean_increment. */
9058 if (integer_onep (TREE_OPERAND (lhs, 1)))
9060 /* This is pre or post increment. */
9061 rhs = TREE_OPERAND (lhs, 1);
9062 lhs = TREE_OPERAND (lhs, 0);
9066 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9067 && TREE_OPERAND (lhs, 0)
9068 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9070 /* This is pre or post decrement. */
9071 rhs = TREE_OPERAND (lhs, 1);
9072 lhs = TREE_OPERAND (lhs, 0);
9079 switch (c_parser_peek_token (parser)->type)
9085 code = TRUNC_DIV_EXPR;
9100 code = BIT_AND_EXPR;
9103 code = BIT_IOR_EXPR;
9106 code = BIT_XOR_EXPR;
9109 c_parser_error (parser,
9110 "invalid operator for %<#pragma omp atomic%>");
9114 /* Arrange to pass the location of the assignment operator to
9115 c_finish_omp_atomic. */
9116 loc = c_parser_peek_token (parser)->location;
9117 c_parser_consume_token (parser);
9119 location_t rhs_loc = c_parser_peek_token (parser)->location;
9120 rhs_expr = c_parser_expression (parser);
9121 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9123 rhs = rhs_expr.value;
9124 rhs = c_fully_fold (rhs, false, NULL);
9127 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
9128 if (stmt != error_mark_node)
9130 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9135 # pragma omp barrier new-line
9139 c_parser_omp_barrier (c_parser *parser)
9141 location_t loc = c_parser_peek_token (parser)->location;
9142 c_parser_consume_pragma (parser);
9143 c_parser_skip_to_pragma_eol (parser);
9145 c_finish_omp_barrier (loc);
9149 # pragma omp critical [(name)] new-line
9152 LOC is the location of the #pragma itself. */
9155 c_parser_omp_critical (location_t loc, c_parser *parser)
9157 tree stmt, name = NULL;
9159 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9161 c_parser_consume_token (parser);
9162 if (c_parser_next_token_is (parser, CPP_NAME))
9164 name = c_parser_peek_token (parser)->value;
9165 c_parser_consume_token (parser);
9166 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9169 c_parser_error (parser, "expected identifier");
9171 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9172 c_parser_error (parser, "expected %<(%> or end of line");
9173 c_parser_skip_to_pragma_eol (parser);
9175 stmt = c_parser_omp_structured_block (parser);
9176 return c_finish_omp_critical (loc, stmt, name);
9180 # pragma omp flush flush-vars[opt] new-line
9183 ( variable-list ) */
9186 c_parser_omp_flush (c_parser *parser)
9188 location_t loc = c_parser_peek_token (parser)->location;
9189 c_parser_consume_pragma (parser);
9190 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9191 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9192 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9193 c_parser_error (parser, "expected %<(%> or end of line");
9194 c_parser_skip_to_pragma_eol (parser);
9196 c_finish_omp_flush (loc);
9199 /* Parse the restricted form of the for statement allowed by OpenMP.
9200 The real trick here is to determine the loop control variable early
9201 so that we can push a new decl if necessary to make it private.
9202 LOC is the location of the OMP in "#pragma omp". */
9205 c_parser_omp_for_loop (location_t loc,
9206 c_parser *parser, tree clauses, tree *par_clauses)
9208 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9209 tree declv, condv, incrv, initv, ret = NULL;
9210 bool fail = false, open_brace_parsed = false;
9211 int i, collapse = 1, nbraces = 0;
9213 VEC(tree,gc) *for_block = make_tree_vector ();
9215 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9216 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9217 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9219 gcc_assert (collapse >= 1);
9221 declv = make_tree_vec (collapse);
9222 initv = make_tree_vec (collapse);
9223 condv = make_tree_vec (collapse);
9224 incrv = make_tree_vec (collapse);
9226 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9228 c_parser_error (parser, "for statement expected");
9231 for_loc = c_parser_peek_token (parser)->location;
9232 c_parser_consume_token (parser);
9234 for (i = 0; i < collapse; i++)
9238 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9241 /* Parse the initialization declaration or expression. */
9242 if (c_parser_next_tokens_start_declaration (parser))
9245 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9246 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9247 decl = check_for_loop_decls (for_loc, flag_isoc99);
9250 if (DECL_INITIAL (decl) == error_mark_node)
9251 decl = error_mark_node;
9254 else if (c_parser_next_token_is (parser, CPP_NAME)
9255 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9257 struct c_expr decl_exp;
9258 struct c_expr init_exp;
9259 location_t init_loc;
9261 decl_exp = c_parser_postfix_expression (parser);
9262 decl = decl_exp.value;
9264 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9266 init_loc = c_parser_peek_token (parser)->location;
9267 init_exp = c_parser_expr_no_commas (parser, NULL);
9268 init_exp = default_function_array_read_conversion (init_loc,
9270 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9271 NOP_EXPR, init_loc, init_exp.value,
9272 init_exp.original_type);
9273 init = c_process_expr_stmt (init_loc, init);
9275 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9280 c_parser_error (parser,
9281 "expected iteration declaration or initialization");
9282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9288 /* Parse the loop condition. */
9290 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9292 location_t cond_loc = c_parser_peek_token (parser)->location;
9293 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
9295 cond = cond_expr.value;
9296 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9297 cond = c_fully_fold (cond, false, NULL);
9298 switch (cond_expr.original_code)
9306 /* Can't be cond = error_mark_node, because we want to preserve
9307 the location until c_finish_omp_for. */
9308 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9311 protected_set_expr_location (cond, cond_loc);
9313 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9315 /* Parse the increment expression. */
9317 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9319 location_t incr_loc = c_parser_peek_token (parser)->location;
9321 incr = c_process_expr_stmt (incr_loc,
9322 c_parser_expression (parser).value);
9324 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9326 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9330 TREE_VEC_ELT (declv, i) = decl;
9331 TREE_VEC_ELT (initv, i) = init;
9332 TREE_VEC_ELT (condv, i) = cond;
9333 TREE_VEC_ELT (incrv, i) = incr;
9337 if (i == collapse - 1)
9340 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9341 in between the collapsed for loops to be still considered perfectly
9342 nested. Hopefully the final version clarifies this.
9343 For now handle (multiple) {'s and empty statements. */
9346 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9348 c_parser_consume_token (parser);
9351 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9353 c_parser_consume_token (parser);
9357 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9358 c_parser_consume_token (parser);
9361 c_parser_error (parser, "not enough perfectly nested loops");
9364 open_brace_parsed = true;
9374 nbraces += bracecount;
9377 save_break = c_break_label;
9378 c_break_label = size_one_node;
9379 save_cont = c_cont_label;
9380 c_cont_label = NULL_TREE;
9381 body = push_stmt_list ();
9383 if (open_brace_parsed)
9385 location_t here = c_parser_peek_token (parser)->location;
9386 stmt = c_begin_compound_stmt (true);
9387 c_parser_compound_statement_nostart (parser);
9388 add_stmt (c_end_compound_stmt (here, stmt, true));
9391 add_stmt (c_parser_c99_block_statement (parser));
9394 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9395 SET_EXPR_LOCATION (t, loc);
9399 body = pop_stmt_list (body);
9400 c_break_label = save_break;
9401 c_cont_label = save_cont;
9405 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9407 c_parser_consume_token (parser);
9410 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9411 c_parser_consume_token (parser);
9414 c_parser_error (parser, "collapsed loops not perfectly nested");
9417 location_t here = c_parser_peek_token (parser)->location;
9418 stmt = c_begin_compound_stmt (true);
9420 c_parser_compound_statement_nostart (parser);
9421 body = c_end_compound_stmt (here, stmt, true);
9428 /* Only bother calling c_finish_omp_for if we haven't already generated
9429 an error from the initialization parsing. */
9432 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9435 if (par_clauses != NULL)
9438 for (c = par_clauses; *c ; )
9439 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9440 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9441 c = &OMP_CLAUSE_CHAIN (*c);
9444 for (i = 0; i < collapse; i++)
9445 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9448 c = &OMP_CLAUSE_CHAIN (*c);
9449 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9452 "iteration variable %qD should not be firstprivate",
9453 OMP_CLAUSE_DECL (*c));
9454 *c = OMP_CLAUSE_CHAIN (*c);
9458 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9459 change it to shared (decl) in
9460 OMP_PARALLEL_CLAUSES. */
9461 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9462 OMP_CLAUSE_LASTPRIVATE);
9463 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9464 OMP_CLAUSE_CHAIN (l) = clauses;
9466 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9470 OMP_FOR_CLAUSES (stmt) = clauses;
9475 while (!VEC_empty (tree, for_block))
9477 /* FIXME diagnostics: LOC below should be the actual location of
9478 this particular for block. We need to build a list of
9479 locations to go along with FOR_BLOCK. */
9480 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9483 release_tree_vector (for_block);
9488 #pragma omp for for-clause[optseq] new-line
9491 LOC is the location of the #pragma token.
9494 #define OMP_FOR_CLAUSE_MASK \
9495 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9496 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9497 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9498 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9499 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9500 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9501 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9502 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9505 c_parser_omp_for (location_t loc, c_parser *parser)
9507 tree block, clauses, ret;
9509 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9512 block = c_begin_compound_stmt (true);
9513 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9514 block = c_end_compound_stmt (loc, block, true);
9521 # pragma omp master new-line
9524 LOC is the location of the #pragma token.
9528 c_parser_omp_master (location_t loc, c_parser *parser)
9530 c_parser_skip_to_pragma_eol (parser);
9531 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9535 # pragma omp ordered new-line
9538 LOC is the location of the #pragma itself.
9542 c_parser_omp_ordered (location_t loc, c_parser *parser)
9544 c_parser_skip_to_pragma_eol (parser);
9545 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9551 { section-sequence }
9554 section-directive[opt] structured-block
9555 section-sequence section-directive structured-block
9557 SECTIONS_LOC is the location of the #pragma omp sections. */
9560 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9563 bool error_suppress = false;
9566 loc = c_parser_peek_token (parser)->location;
9567 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9569 /* Avoid skipping until the end of the block. */
9570 parser->error = false;
9574 stmt = push_stmt_list ();
9576 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9578 substmt = push_stmt_list ();
9582 c_parser_statement (parser);
9584 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9586 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9588 if (c_parser_next_token_is (parser, CPP_EOF))
9592 substmt = pop_stmt_list (substmt);
9593 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9594 SET_EXPR_LOCATION (substmt, loc);
9600 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9602 if (c_parser_next_token_is (parser, CPP_EOF))
9605 loc = c_parser_peek_token (parser)->location;
9606 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9608 c_parser_consume_pragma (parser);
9609 c_parser_skip_to_pragma_eol (parser);
9610 error_suppress = false;
9612 else if (!error_suppress)
9614 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9615 error_suppress = true;
9618 substmt = c_parser_omp_structured_block (parser);
9619 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9620 SET_EXPR_LOCATION (substmt, loc);
9623 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9624 "expected %<#pragma omp section%> or %<}%>");
9626 substmt = pop_stmt_list (stmt);
9628 stmt = make_node (OMP_SECTIONS);
9629 SET_EXPR_LOCATION (stmt, sections_loc);
9630 TREE_TYPE (stmt) = void_type_node;
9631 OMP_SECTIONS_BODY (stmt) = substmt;
9633 return add_stmt (stmt);
9637 # pragma omp sections sections-clause[optseq] newline
9640 LOC is the location of the #pragma token.
9643 #define OMP_SECTIONS_CLAUSE_MASK \
9644 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9645 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9646 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9647 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9648 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9651 c_parser_omp_sections (location_t loc, c_parser *parser)
9653 tree block, clauses, ret;
9655 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9656 "#pragma omp sections");
9658 block = c_begin_compound_stmt (true);
9659 ret = c_parser_omp_sections_scope (loc, parser);
9661 OMP_SECTIONS_CLAUSES (ret) = clauses;
9662 block = c_end_compound_stmt (loc, block, true);
9669 # pragma parallel parallel-clause new-line
9670 # pragma parallel for parallel-for-clause new-line
9671 # pragma parallel sections parallel-sections-clause new-line
9673 LOC is the location of the #pragma token.
9676 #define OMP_PARALLEL_CLAUSE_MASK \
9677 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9678 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9679 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9680 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9681 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9682 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9683 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9684 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9687 c_parser_omp_parallel (location_t loc, c_parser *parser)
9689 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9690 const char *p_name = "#pragma omp parallel";
9691 tree stmt, clauses, par_clause, ws_clause, block;
9692 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9694 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9696 c_parser_consume_token (parser);
9697 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9698 p_name = "#pragma omp parallel for";
9699 mask |= OMP_FOR_CLAUSE_MASK;
9700 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9702 else if (c_parser_next_token_is (parser, CPP_NAME))
9704 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9705 if (strcmp (p, "sections") == 0)
9707 c_parser_consume_token (parser);
9708 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9709 p_name = "#pragma omp parallel sections";
9710 mask |= OMP_SECTIONS_CLAUSE_MASK;
9711 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9715 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9719 case PRAGMA_OMP_PARALLEL:
9720 block = c_begin_omp_parallel ();
9721 c_parser_statement (parser);
9722 stmt = c_finish_omp_parallel (loc, clauses, block);
9725 case PRAGMA_OMP_PARALLEL_FOR:
9726 block = c_begin_omp_parallel ();
9727 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9728 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9729 stmt = c_finish_omp_parallel (loc, par_clause, block);
9730 OMP_PARALLEL_COMBINED (stmt) = 1;
9733 case PRAGMA_OMP_PARALLEL_SECTIONS:
9734 block = c_begin_omp_parallel ();
9735 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9736 stmt = c_parser_omp_sections_scope (loc, parser);
9738 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9739 stmt = c_finish_omp_parallel (loc, par_clause, block);
9740 OMP_PARALLEL_COMBINED (stmt) = 1;
9751 # pragma omp single single-clause[optseq] new-line
9754 LOC is the location of the #pragma.
9757 #define OMP_SINGLE_CLAUSE_MASK \
9758 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9759 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9760 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9761 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9764 c_parser_omp_single (location_t loc, c_parser *parser)
9766 tree stmt = make_node (OMP_SINGLE);
9767 SET_EXPR_LOCATION (stmt, loc);
9768 TREE_TYPE (stmt) = void_type_node;
9770 OMP_SINGLE_CLAUSES (stmt)
9771 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9772 "#pragma omp single");
9773 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9775 return add_stmt (stmt);
9779 # pragma omp task task-clause[optseq] new-line
9781 LOC is the location of the #pragma.
9784 #define OMP_TASK_CLAUSE_MASK \
9785 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9786 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9787 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9788 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9789 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9790 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9793 c_parser_omp_task (location_t loc, c_parser *parser)
9795 tree clauses, block;
9797 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9798 "#pragma omp task");
9800 block = c_begin_omp_task ();
9801 c_parser_statement (parser);
9802 return c_finish_omp_task (loc, clauses, block);
9806 # pragma omp taskwait new-line
9810 c_parser_omp_taskwait (c_parser *parser)
9812 location_t loc = c_parser_peek_token (parser)->location;
9813 c_parser_consume_pragma (parser);
9814 c_parser_skip_to_pragma_eol (parser);
9816 c_finish_omp_taskwait (loc);
9819 /* Main entry point to parsing most OpenMP pragmas. */
9822 c_parser_omp_construct (c_parser *parser)
9824 enum pragma_kind p_kind;
9828 loc = c_parser_peek_token (parser)->location;
9829 p_kind = c_parser_peek_token (parser)->pragma_kind;
9830 c_parser_consume_pragma (parser);
9834 case PRAGMA_OMP_ATOMIC:
9835 c_parser_omp_atomic (loc, parser);
9837 case PRAGMA_OMP_CRITICAL:
9838 stmt = c_parser_omp_critical (loc, parser);
9840 case PRAGMA_OMP_FOR:
9841 stmt = c_parser_omp_for (loc, parser);
9843 case PRAGMA_OMP_MASTER:
9844 stmt = c_parser_omp_master (loc, parser);
9846 case PRAGMA_OMP_ORDERED:
9847 stmt = c_parser_omp_ordered (loc, parser);
9849 case PRAGMA_OMP_PARALLEL:
9850 stmt = c_parser_omp_parallel (loc, parser);
9852 case PRAGMA_OMP_SECTIONS:
9853 stmt = c_parser_omp_sections (loc, parser);
9855 case PRAGMA_OMP_SINGLE:
9856 stmt = c_parser_omp_single (loc, parser);
9858 case PRAGMA_OMP_TASK:
9859 stmt = c_parser_omp_task (loc, parser);
9866 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9871 # pragma omp threadprivate (variable-list) */
9874 c_parser_omp_threadprivate (c_parser *parser)
9879 c_parser_consume_pragma (parser);
9880 loc = c_parser_peek_token (parser)->location;
9881 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9883 /* Mark every variable in VARS to be assigned thread local storage. */
9884 for (t = vars; t; t = TREE_CHAIN (t))
9886 tree v = TREE_PURPOSE (t);
9888 /* FIXME diagnostics: Ideally we should keep individual
9889 locations for all the variables in the var list to make the
9890 following errors more precise. Perhaps
9891 c_parser_omp_var_list_parens() should construct a list of
9892 locations to go along with the var list. */
9894 /* If V had already been marked threadprivate, it doesn't matter
9895 whether it had been used prior to this point. */
9896 if (TREE_CODE (v) != VAR_DECL)
9897 error_at (loc, "%qD is not a variable", v);
9898 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9899 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9900 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9901 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9902 else if (TREE_TYPE (v) == error_mark_node)
9904 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9905 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9908 if (! DECL_THREAD_LOCAL_P (v))
9910 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9911 /* If rtl has been already set for this var, call
9912 make_decl_rtl once again, so that encode_section_info
9913 has a chance to look at the new decl flags. */
9914 if (DECL_RTL_SET_P (v))
9917 C_DECL_THREADPRIVATE_P (v) = 1;
9921 c_parser_skip_to_pragma_eol (parser);
9925 /* Parse a single source file. */
9930 /* Use local storage to begin. If the first token is a pragma, parse it.
9931 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9932 which will cause garbage collection. */
9935 memset (&tparser, 0, sizeof tparser);
9936 the_parser = &tparser;
9938 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9939 c_parser_pragma_pch_preprocess (&tparser);
9941 the_parser = ggc_alloc_c_parser ();
9942 *the_parser = tparser;
9944 /* Initialize EH, if we've been told to do so. */
9945 if (flag_exceptions)
9946 using_eh_for_cleanups ();
9948 c_parser_translation_unit (the_parser);
9952 #include "gt-c-parser.h"