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
257 if (parser->objc_pq_context)
259 token->type = CPP_KEYWORD;
260 token->keyword = rid_code;
263 else if (parser->objc_could_be_foreach_context
264 && rid_code == RID_IN)
266 /* We are in Objective-C, inside a (potential)
267 foreach context (which means after having
268 parsed 'for (', but before having parsed ';'),
269 and we found 'in'. We consider it the keyword
270 which terminates the declaration at the
271 beginning of a foreach-statement. Note that
272 this means you can't use 'in' for anything else
273 in that context; in particular, in Objective-C
274 you can't use 'in' as the name of the running
275 variable in a C for loop. We could potentially
276 try to add code here to disambiguate, but it
277 seems a reasonable limitation. */
278 token->type = CPP_KEYWORD;
279 token->keyword = rid_code;
282 /* Else, "pq" keywords outside of the "pq" context are
283 not keywords, and we fall through to the code for
286 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
288 /* We found an Objective-C "property attribute"
289 keyword (getter, setter, readonly, etc). These are
290 only valid in the property context. */
291 if (parser->objc_property_attr_context)
293 token->type = CPP_KEYWORD;
294 token->keyword = rid_code;
297 /* Else they are not special keywords.
300 else if (c_dialect_objc ()
301 && (OBJC_IS_AT_KEYWORD (rid_code)
302 || OBJC_IS_CXX_KEYWORD (rid_code)))
304 /* We found one of the Objective-C "@" keywords (defs,
305 selector, synchronized, etc) or one of the
306 Objective-C "cxx" keywords (class, private,
307 protected, public, try, catch, throw) without a
308 preceding '@' sign. Do nothing and fall through to
309 the code for normal tokens (in C++ we would still
310 consider the CXX ones keywords, but not in C). */
315 token->type = CPP_KEYWORD;
316 token->keyword = rid_code;
321 decl = lookup_name (token->value);
324 if (TREE_CODE (decl) == TYPE_DECL)
326 token->id_kind = C_ID_TYPENAME;
330 else if (c_dialect_objc ())
332 tree objc_interface_decl = objc_is_class_name (token->value);
333 /* Objective-C class names are in the same namespace as
334 variables and typedefs, and hence are shadowed by local
336 if (objc_interface_decl
337 && (!objc_force_identifier || global_bindings_p ()))
339 token->value = objc_interface_decl;
340 token->id_kind = C_ID_CLASSNAME;
344 token->id_kind = C_ID_ID;
348 /* This only happens in Objective-C; it must be a keyword. */
349 token->type = CPP_KEYWORD;
350 switch (C_RID_CODE (token->value))
352 /* Replace 'class' with '@class', 'private' with '@private',
353 etc. This prevents confusion with the C++ keyword
354 'class', and makes the tokens consistent with other
355 Objective-C 'AT' keywords. For example '@class' is
356 reported as RID_AT_CLASS which is consistent with
357 '@synchronized', which is reported as
360 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
361 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
362 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
363 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
364 case RID_THROW: token->keyword = RID_AT_THROW; break;
365 case RID_TRY: token->keyword = RID_AT_TRY; break;
366 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
367 default: token->keyword = C_RID_CODE (token->value);
372 case CPP_CLOSE_PAREN:
374 /* These tokens may affect the interpretation of any identifiers
375 following, if doing Objective-C. */
376 if (c_dialect_objc ())
377 parser->objc_need_raw_identifier = false;
380 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
381 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
387 timevar_pop (TV_LEX);
390 /* Return a pointer to the next token from PARSER, reading it in if
393 static inline c_token *
394 c_parser_peek_token (c_parser *parser)
396 if (parser->tokens_avail == 0)
398 c_lex_one_token (parser, &parser->tokens[0]);
399 parser->tokens_avail = 1;
401 return &parser->tokens[0];
404 /* Return true if the next token from PARSER has the indicated
408 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
410 return c_parser_peek_token (parser)->type == type;
413 /* Return true if the next token from PARSER does not have the
417 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
419 return !c_parser_next_token_is (parser, type);
422 /* Return true if the next token from PARSER is the indicated
426 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
428 return c_parser_peek_token (parser)->keyword == keyword;
431 /* Return a pointer to the next-but-one token from PARSER, reading it
432 in if necessary. The next token is already read in. */
435 c_parser_peek_2nd_token (c_parser *parser)
437 if (parser->tokens_avail >= 2)
438 return &parser->tokens[1];
439 gcc_assert (parser->tokens_avail == 1);
440 gcc_assert (parser->tokens[0].type != CPP_EOF);
441 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
442 c_lex_one_token (parser, &parser->tokens[1]);
443 parser->tokens_avail = 2;
444 return &parser->tokens[1];
447 /* Return true if TOKEN can start a type name,
450 c_token_starts_typename (c_token *token)
455 switch (token->id_kind)
464 gcc_assert (c_dialect_objc ());
470 switch (token->keyword)
503 if (c_dialect_objc ())
511 enum c_lookahead_kind {
512 /* Always treat unknown identifiers as typenames. */
515 /* Could be parsing a nonabstract declarator. Only treat an identifier
516 as a typename if followed by another identifier or a star. */
517 cla_nonabstract_decl,
519 /* Never treat identifiers as typenames. */
523 /* Return true if the next token from PARSER can start a type name,
524 false otherwise. LA specifies how to do lookahead in order to
525 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
528 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la)
530 c_token *token = c_parser_peek_token (parser);
531 if (c_token_starts_typename (token))
534 /* Try a bit harder to detect an unknown typename. */
535 if (la != cla_prefer_id
536 && token->type == CPP_NAME
537 && token->id_kind == C_ID_ID
539 /* Do not try too hard when we could have "object in array". */
540 && !parser->objc_could_be_foreach_context
542 && (la == cla_prefer_type
543 || c_parser_peek_2nd_token (parser)->type == CPP_NAME
544 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
546 /* Only unknown identifiers. */
547 && !lookup_name (token->value))
553 /* Return true if TOKEN is a type qualifier, false otherwise. */
555 c_token_is_qualifier (c_token *token)
560 switch (token->id_kind)
568 switch (token->keyword)
585 /* Return true if the next token from PARSER is a type qualifier,
588 c_parser_next_token_is_qualifier (c_parser *parser)
590 c_token *token = c_parser_peek_token (parser);
591 return c_token_is_qualifier (token);
594 /* Return true if TOKEN can start declaration specifiers, false
597 c_token_starts_declspecs (c_token *token)
602 switch (token->id_kind)
611 gcc_assert (c_dialect_objc ());
617 switch (token->keyword)
658 if (c_dialect_objc ())
667 /* Return true if TOKEN can start declaration specifiers or a static
668 assertion, false otherwise. */
670 c_token_starts_declaration (c_token *token)
672 if (c_token_starts_declspecs (token)
673 || token->keyword == RID_STATIC_ASSERT)
679 /* Return true if the next token from PARSER can start declaration
680 specifiers, false otherwise. */
682 c_parser_next_token_starts_declspecs (c_parser *parser)
684 c_token *token = c_parser_peek_token (parser);
686 /* In Objective-C, a classname normally starts a declspecs unless it
687 is immediately followed by a dot. In that case, it is the
688 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
689 setter/getter on the class. c_token_starts_declspecs() can't
690 differentiate between the two cases because it only checks the
691 current token, so we have a special check here. */
692 if (c_dialect_objc ()
693 && token->type == CPP_NAME
694 && token->id_kind == C_ID_CLASSNAME
695 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
698 return c_token_starts_declspecs (token);
701 /* Return true if the next tokens from PARSER can start declaration
702 specifiers or a static assertion, false otherwise. */
704 c_parser_next_tokens_start_declaration (c_parser *parser)
706 c_token *token = c_parser_peek_token (parser);
709 if (c_dialect_objc ()
710 && token->type == CPP_NAME
711 && token->id_kind == C_ID_CLASSNAME
712 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
715 /* Labels do not start declarations. */
716 if (token->type == CPP_NAME
717 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
720 if (c_token_starts_declaration (token))
723 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
729 /* Consume the next token from PARSER. */
732 c_parser_consume_token (c_parser *parser)
734 gcc_assert (parser->tokens_avail >= 1);
735 gcc_assert (parser->tokens[0].type != CPP_EOF);
736 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
737 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
738 if (parser->tokens_avail == 2)
739 parser->tokens[0] = parser->tokens[1];
740 parser->tokens_avail--;
743 /* Expect the current token to be a #pragma. Consume it and remember
744 that we've begun parsing a pragma. */
747 c_parser_consume_pragma (c_parser *parser)
749 gcc_assert (!parser->in_pragma);
750 gcc_assert (parser->tokens_avail >= 1);
751 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
752 if (parser->tokens_avail == 2)
753 parser->tokens[0] = parser->tokens[1];
754 parser->tokens_avail--;
755 parser->in_pragma = true;
758 /* Update the globals input_location and in_system_header from
761 c_parser_set_source_position_from_token (c_token *token)
763 if (token->type != CPP_EOF)
765 input_location = token->location;
769 /* Issue a diagnostic of the form
770 FILE:LINE: MESSAGE before TOKEN
771 where TOKEN is the next token in the input stream of PARSER.
772 MESSAGE (specified by the caller) is usually of the form "expected
775 Do not issue a diagnostic if still recovering from an error.
777 ??? This is taken from the C++ parser, but building up messages in
778 this way is not i18n-friendly and some other approach should be
782 c_parser_error (c_parser *parser, const char *gmsgid)
784 c_token *token = c_parser_peek_token (parser);
787 parser->error = true;
790 /* This diagnostic makes more sense if it is tagged to the line of
791 the token we just peeked at. */
792 c_parser_set_source_position_from_token (token);
793 c_parse_error (gmsgid,
794 /* Because c_parse_error does not understand
795 CPP_KEYWORD, keywords are treated like
797 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
798 /* ??? The C parser does not save the cpp flags of a
799 token, we need to pass 0 here and we will not get
800 the source spelling of some tokens but rather the
801 canonical spelling. */
802 token->value, /*flags=*/0);
805 /* If the next token is of the indicated TYPE, consume it. Otherwise,
806 issue the error MSGID. If MSGID is NULL then a message has already
807 been produced and no message will be produced this time. Returns
808 true if found, false otherwise. */
811 c_parser_require (c_parser *parser,
815 if (c_parser_next_token_is (parser, type))
817 c_parser_consume_token (parser);
822 c_parser_error (parser, msgid);
827 /* If the next token is the indicated keyword, consume it. Otherwise,
828 issue the error MSGID. Returns true if found, false otherwise. */
831 c_parser_require_keyword (c_parser *parser,
835 if (c_parser_next_token_is_keyword (parser, keyword))
837 c_parser_consume_token (parser);
842 c_parser_error (parser, msgid);
847 /* Like c_parser_require, except that tokens will be skipped until the
848 desired token is found. An error message is still produced if the
849 next token is not as expected. If MSGID is NULL then a message has
850 already been produced and no message will be produced this
854 c_parser_skip_until_found (c_parser *parser,
858 unsigned nesting_depth = 0;
860 if (c_parser_require (parser, type, msgid))
863 /* Skip tokens until the desired token is found. */
866 /* Peek at the next token. */
867 c_token *token = c_parser_peek_token (parser);
868 /* If we've reached the token we want, consume it and stop. */
869 if (token->type == type && !nesting_depth)
871 c_parser_consume_token (parser);
875 /* If we've run out of tokens, stop. */
876 if (token->type == CPP_EOF)
878 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
880 if (token->type == CPP_OPEN_BRACE
881 || token->type == CPP_OPEN_PAREN
882 || token->type == CPP_OPEN_SQUARE)
884 else if (token->type == CPP_CLOSE_BRACE
885 || token->type == CPP_CLOSE_PAREN
886 || token->type == CPP_CLOSE_SQUARE)
888 if (nesting_depth-- == 0)
891 /* Consume this token. */
892 c_parser_consume_token (parser);
894 parser->error = false;
897 /* Skip tokens until the end of a parameter is found, but do not
898 consume the comma, semicolon or closing delimiter. */
901 c_parser_skip_to_end_of_parameter (c_parser *parser)
903 unsigned nesting_depth = 0;
907 c_token *token = c_parser_peek_token (parser);
908 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
911 /* If we've run out of tokens, stop. */
912 if (token->type == CPP_EOF)
914 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
916 if (token->type == CPP_OPEN_BRACE
917 || token->type == CPP_OPEN_PAREN
918 || token->type == CPP_OPEN_SQUARE)
920 else if (token->type == CPP_CLOSE_BRACE
921 || token->type == CPP_CLOSE_PAREN
922 || token->type == CPP_CLOSE_SQUARE)
924 if (nesting_depth-- == 0)
927 /* Consume this token. */
928 c_parser_consume_token (parser);
930 parser->error = false;
933 /* Expect to be at the end of the pragma directive and consume an
934 end of line marker. */
937 c_parser_skip_to_pragma_eol (c_parser *parser)
939 gcc_assert (parser->in_pragma);
940 parser->in_pragma = false;
942 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
945 c_token *token = c_parser_peek_token (parser);
946 if (token->type == CPP_EOF)
948 if (token->type == CPP_PRAGMA_EOL)
950 c_parser_consume_token (parser);
953 c_parser_consume_token (parser);
956 parser->error = false;
959 /* Skip tokens until we have consumed an entire block, or until we
960 have consumed a non-nested ';'. */
963 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
965 unsigned nesting_depth = 0;
966 bool save_error = parser->error;
972 /* Peek at the next token. */
973 token = c_parser_peek_token (parser);
981 if (parser->in_pragma)
986 /* If the next token is a ';', we have reached the
987 end of the statement. */
990 /* Consume the ';'. */
991 c_parser_consume_token (parser);
996 case CPP_CLOSE_BRACE:
997 /* If the next token is a non-nested '}', then we have
998 reached the end of the current block. */
999 if (nesting_depth == 0 || --nesting_depth == 0)
1001 c_parser_consume_token (parser);
1006 case CPP_OPEN_BRACE:
1007 /* If it the next token is a '{', then we are entering a new
1008 block. Consume the entire block. */
1013 /* If we see a pragma, consume the whole thing at once. We
1014 have some safeguards against consuming pragmas willy-nilly.
1015 Normally, we'd expect to be here with parser->error set,
1016 which disables these safeguards. But it's possible to get
1017 here for secondary error recovery, after parser->error has
1019 c_parser_consume_pragma (parser);
1020 c_parser_skip_to_pragma_eol (parser);
1021 parser->error = save_error;
1028 c_parser_consume_token (parser);
1032 parser->error = false;
1035 /* CPP's options (initialized by c-opts.c). */
1036 extern cpp_options *cpp_opts;
1038 /* Save the warning flags which are controlled by __extension__. */
1041 disable_extension_diagnostics (void)
1044 | (warn_pointer_arith << 1)
1045 | (warn_traditional << 2)
1047 | (warn_long_long << 4)
1048 | (warn_cxx_compat << 5)
1049 | (warn_overlength_strings << 6));
1050 cpp_opts->cpp_pedantic = pedantic = 0;
1051 warn_pointer_arith = 0;
1052 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1054 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1055 warn_cxx_compat = 0;
1056 warn_overlength_strings = 0;
1060 /* Restore the warning flags which are controlled by __extension__.
1061 FLAGS is the return value from disable_extension_diagnostics. */
1064 restore_extension_diagnostics (int flags)
1066 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1067 warn_pointer_arith = (flags >> 1) & 1;
1068 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1069 flag_iso = (flags >> 3) & 1;
1070 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1071 warn_cxx_compat = (flags >> 5) & 1;
1072 warn_overlength_strings = (flags >> 6) & 1;
1075 /* Possibly kinds of declarator to parse. */
1076 typedef enum c_dtr_syn {
1077 /* A normal declarator with an identifier. */
1079 /* An abstract declarator (maybe empty). */
1081 /* A parameter declarator: may be either, but after a type name does
1082 not redeclare a typedef name as an identifier if it can
1083 alternatively be interpreted as a typedef name; see DR#009,
1084 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1085 following DR#249. For example, given a typedef T, "int T" and
1086 "int *T" are valid parameter declarations redeclaring T, while
1087 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1088 abstract declarators rather than involving redundant parentheses;
1089 the same applies with attributes inside the parentheses before
1094 /* The binary operation precedence levels, where 0 is a dummy lowest level
1095 used for the bottom of the stack. */
1096 enum c_parser_prec {
1111 static void c_parser_external_declaration (c_parser *);
1112 static void c_parser_asm_definition (c_parser *);
1113 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1114 bool, bool, tree *);
1115 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1116 static void c_parser_static_assert_declaration (c_parser *);
1117 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1118 bool, enum c_lookahead_kind);
1119 static struct c_typespec c_parser_enum_specifier (c_parser *);
1120 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1121 static tree c_parser_struct_declaration (c_parser *);
1122 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1123 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1125 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1127 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1129 struct c_declarator *);
1130 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1131 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1133 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1134 static tree c_parser_simple_asm_expr (c_parser *);
1135 static tree c_parser_attributes (c_parser *);
1136 static struct c_type_name *c_parser_type_name (c_parser *);
1137 static struct c_expr c_parser_initializer (c_parser *);
1138 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1139 static void c_parser_initelt (c_parser *, struct obstack *);
1140 static void c_parser_initval (c_parser *, struct c_expr *,
1142 static tree c_parser_compound_statement (c_parser *);
1143 static void c_parser_compound_statement_nostart (c_parser *);
1144 static void c_parser_label (c_parser *);
1145 static void c_parser_statement (c_parser *);
1146 static void c_parser_statement_after_labels (c_parser *);
1147 static void c_parser_if_statement (c_parser *);
1148 static void c_parser_switch_statement (c_parser *);
1149 static void c_parser_while_statement (c_parser *);
1150 static void c_parser_do_statement (c_parser *);
1151 static void c_parser_for_statement (c_parser *);
1152 static tree c_parser_asm_statement (c_parser *);
1153 static tree c_parser_asm_operands (c_parser *, bool);
1154 static tree c_parser_asm_goto_operands (c_parser *);
1155 static tree c_parser_asm_clobbers (c_parser *);
1156 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1157 static struct c_expr c_parser_conditional_expression (c_parser *,
1159 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1160 enum c_parser_prec);
1161 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1162 static struct c_expr c_parser_unary_expression (c_parser *);
1163 static struct c_expr c_parser_sizeof_expression (c_parser *);
1164 static struct c_expr c_parser_alignof_expression (c_parser *);
1165 static struct c_expr c_parser_postfix_expression (c_parser *);
1166 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1167 struct c_type_name *,
1169 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1172 static struct c_expr c_parser_expression (c_parser *);
1173 static struct c_expr c_parser_expression_conv (c_parser *);
1174 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1176 static void c_parser_omp_construct (c_parser *);
1177 static void c_parser_omp_threadprivate (c_parser *);
1178 static void c_parser_omp_barrier (c_parser *);
1179 static void c_parser_omp_flush (c_parser *);
1180 static void c_parser_omp_taskwait (c_parser *);
1181 static void c_parser_omp_taskyield (c_parser *);
1183 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1184 static bool c_parser_pragma (c_parser *, enum pragma_context);
1186 /* These Objective-C parser functions are only ever called when
1187 compiling Objective-C. */
1188 static void c_parser_objc_class_definition (c_parser *, tree);
1189 static void c_parser_objc_class_instance_variables (c_parser *);
1190 static void c_parser_objc_class_declaration (c_parser *);
1191 static void c_parser_objc_alias_declaration (c_parser *);
1192 static void c_parser_objc_protocol_definition (c_parser *, tree);
1193 static bool c_parser_objc_method_type (c_parser *);
1194 static void c_parser_objc_method_definition (c_parser *);
1195 static void c_parser_objc_methodprotolist (c_parser *);
1196 static void c_parser_objc_methodproto (c_parser *);
1197 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1198 static tree c_parser_objc_type_name (c_parser *);
1199 static tree c_parser_objc_protocol_refs (c_parser *);
1200 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1201 static void c_parser_objc_synchronized_statement (c_parser *);
1202 static tree c_parser_objc_selector (c_parser *);
1203 static tree c_parser_objc_selector_arg (c_parser *);
1204 static tree c_parser_objc_receiver (c_parser *);
1205 static tree c_parser_objc_message_args (c_parser *);
1206 static tree c_parser_objc_keywordexpr (c_parser *);
1207 static void c_parser_objc_at_property_declaration (c_parser *);
1208 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1209 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1210 static bool c_parser_objc_diagnose_bad_element_prefix
1211 (c_parser *, struct c_declspecs *);
1213 /* Parse a translation unit (C90 6.7, C99 6.9).
1216 external-declarations
1218 external-declarations:
1219 external-declaration
1220 external-declarations external-declaration
1229 c_parser_translation_unit (c_parser *parser)
1231 if (c_parser_next_token_is (parser, CPP_EOF))
1233 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1234 "ISO C forbids an empty translation unit");
1238 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1239 mark_valid_location_for_stdc_pragma (false);
1243 c_parser_external_declaration (parser);
1244 obstack_free (&parser_obstack, obstack_position);
1246 while (c_parser_next_token_is_not (parser, CPP_EOF));
1250 /* Parse an external declaration (C90 6.7, C99 6.9).
1252 external-declaration:
1258 external-declaration:
1261 __extension__ external-declaration
1265 external-declaration:
1266 objc-class-definition
1267 objc-class-declaration
1268 objc-alias-declaration
1269 objc-protocol-definition
1270 objc-method-definition
1275 c_parser_external_declaration (c_parser *parser)
1278 switch (c_parser_peek_token (parser)->type)
1281 switch (c_parser_peek_token (parser)->keyword)
1284 ext = disable_extension_diagnostics ();
1285 c_parser_consume_token (parser);
1286 c_parser_external_declaration (parser);
1287 restore_extension_diagnostics (ext);
1290 c_parser_asm_definition (parser);
1292 case RID_AT_INTERFACE:
1293 case RID_AT_IMPLEMENTATION:
1294 gcc_assert (c_dialect_objc ());
1295 c_parser_objc_class_definition (parser, NULL_TREE);
1298 gcc_assert (c_dialect_objc ());
1299 c_parser_objc_class_declaration (parser);
1302 gcc_assert (c_dialect_objc ());
1303 c_parser_objc_alias_declaration (parser);
1305 case RID_AT_PROTOCOL:
1306 gcc_assert (c_dialect_objc ());
1307 c_parser_objc_protocol_definition (parser, NULL_TREE);
1309 case RID_AT_PROPERTY:
1310 gcc_assert (c_dialect_objc ());
1311 c_parser_objc_at_property_declaration (parser);
1313 case RID_AT_SYNTHESIZE:
1314 gcc_assert (c_dialect_objc ());
1315 c_parser_objc_at_synthesize_declaration (parser);
1317 case RID_AT_DYNAMIC:
1318 gcc_assert (c_dialect_objc ());
1319 c_parser_objc_at_dynamic_declaration (parser);
1322 gcc_assert (c_dialect_objc ());
1323 c_parser_consume_token (parser);
1324 objc_finish_implementation ();
1331 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1332 "ISO C does not allow extra %<;%> outside of a function");
1333 c_parser_consume_token (parser);
1336 mark_valid_location_for_stdc_pragma (true);
1337 c_parser_pragma (parser, pragma_external);
1338 mark_valid_location_for_stdc_pragma (false);
1342 if (c_dialect_objc ())
1344 c_parser_objc_method_definition (parser);
1347 /* Else fall through, and yield a syntax error trying to parse
1348 as a declaration or function definition. */
1351 /* A declaration or a function definition (or, in Objective-C,
1352 an @interface or @protocol with prefix attributes). We can
1353 only tell which after parsing the declaration specifiers, if
1354 any, and the first declarator. */
1355 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1360 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1361 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1362 accepted; otherwise (old-style parameter declarations) only other
1363 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1364 assertion is accepted; otherwise (old-style parameter declarations)
1365 it is not. If NESTED is true, we are inside a function or parsing
1366 old-style parameter declarations; any functions encountered are
1367 nested functions and declaration specifiers are required; otherwise
1368 we are at top level and functions are normal functions and
1369 declaration specifiers may be optional. If EMPTY_OK is true, empty
1370 declarations are OK (subject to all other constraints); otherwise
1371 (old-style parameter declarations) they are diagnosed. If
1372 START_ATTR_OK is true, the declaration specifiers may start with
1373 attributes; otherwise they may not.
1374 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1375 declaration when parsing an Objective-C foreach statement.
1378 declaration-specifiers init-declarator-list[opt] ;
1379 static_assert-declaration
1381 function-definition:
1382 declaration-specifiers[opt] declarator declaration-list[opt]
1387 declaration-list declaration
1389 init-declarator-list:
1391 init-declarator-list , init-declarator
1394 declarator simple-asm-expr[opt] attributes[opt]
1395 declarator simple-asm-expr[opt] attributes[opt] = initializer
1399 nested-function-definition:
1400 declaration-specifiers declarator declaration-list[opt]
1404 attributes objc-class-definition
1405 attributes objc-category-definition
1406 attributes objc-protocol-definition
1408 The simple-asm-expr and attributes are GNU extensions.
1410 This function does not handle __extension__; that is handled in its
1411 callers. ??? Following the old parser, __extension__ may start
1412 external declarations, declarations in functions and declarations
1413 at the start of "for" loops, but not old-style parameter
1416 C99 requires declaration specifiers in a function definition; the
1417 absence is diagnosed through the diagnosis of implicit int. In GNU
1418 C we also allow but diagnose declarations without declaration
1419 specifiers, but only at top level (elsewhere they conflict with
1422 In Objective-C, declarations of the looping variable in a foreach
1423 statement are exceptionally terminated by 'in' (for example, 'for
1424 (NSObject *object in array) { ... }').
1429 threadprivate-directive */
1432 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1433 bool static_assert_ok, bool empty_ok,
1434 bool nested, bool start_attr_ok,
1435 tree *objc_foreach_object_declaration)
1437 struct c_declspecs *specs;
1439 tree all_prefix_attrs;
1440 bool diagnosed_no_specs = false;
1441 location_t here = c_parser_peek_token (parser)->location;
1443 if (static_assert_ok
1444 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1446 c_parser_static_assert_declaration (parser);
1449 specs = build_null_declspecs ();
1451 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1452 if (c_parser_peek_token (parser)->type == CPP_NAME
1453 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1454 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1455 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1456 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1458 error_at (here, "unknown type name %qE",
1459 c_parser_peek_token (parser)->value);
1461 /* Parse declspecs normally to get a correct pointer type, but avoid
1462 a further "fails to be a type name" error. Refuse nested functions
1463 since it is not how the user likely wants us to recover. */
1464 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1465 c_parser_peek_token (parser)->keyword = RID_VOID;
1466 c_parser_peek_token (parser)->value = error_mark_node;
1470 c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1473 c_parser_skip_to_end_of_block_or_statement (parser);
1476 if (nested && !specs->declspecs_seen_p)
1478 c_parser_error (parser, "expected declaration specifiers");
1479 c_parser_skip_to_end_of_block_or_statement (parser);
1482 finish_declspecs (specs);
1483 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1489 shadow_tag_warned (specs, 1);
1490 pedwarn (here, 0, "empty declaration");
1492 c_parser_consume_token (parser);
1496 /* Provide better error recovery. Note that a type name here is usually
1497 better diagnosed as a redeclaration. */
1499 && specs->typespec_kind == ctsk_tagdef
1500 && c_parser_next_token_starts_declspecs (parser)
1501 && !c_parser_next_token_is (parser, CPP_NAME))
1503 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1504 parser->error = false;
1505 shadow_tag_warned (specs, 1);
1508 else if (c_dialect_objc ())
1510 /* Prefix attributes are an error on method decls. */
1511 switch (c_parser_peek_token (parser)->type)
1515 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1519 warning_at (c_parser_peek_token (parser)->location,
1521 "prefix attributes are ignored for methods");
1522 specs->attrs = NULL_TREE;
1525 c_parser_objc_method_definition (parser);
1527 c_parser_objc_methodproto (parser);
1533 /* This is where we parse 'attributes @interface ...',
1534 'attributes @implementation ...', 'attributes @protocol ...'
1535 (where attributes could be, for example, __attribute__
1538 switch (c_parser_peek_token (parser)->keyword)
1540 case RID_AT_INTERFACE:
1542 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1544 c_parser_objc_class_definition (parser, specs->attrs);
1548 case RID_AT_IMPLEMENTATION:
1550 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1554 warning_at (c_parser_peek_token (parser)->location,
1556 "prefix attributes are ignored for implementations");
1557 specs->attrs = NULL_TREE;
1559 c_parser_objc_class_definition (parser, NULL_TREE);
1563 case RID_AT_PROTOCOL:
1565 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1567 c_parser_objc_protocol_definition (parser, specs->attrs);
1574 case RID_AT_PROPERTY:
1577 c_parser_error (parser, "unexpected attribute");
1578 specs->attrs = NULL;
1586 pending_xref_error ();
1587 prefix_attrs = specs->attrs;
1588 all_prefix_attrs = prefix_attrs;
1589 specs->attrs = NULL_TREE;
1592 struct c_declarator *declarator;
1596 /* Declaring either one or more declarators (in which case we
1597 should diagnose if there were no declaration specifiers) or a
1598 function definition (in which case the diagnostic for
1599 implicit int suffices). */
1600 declarator = c_parser_declarator (parser,
1601 specs->typespec_kind != ctsk_none,
1602 C_DTR_NORMAL, &dummy);
1603 if (declarator == NULL)
1605 c_parser_skip_to_end_of_block_or_statement (parser);
1608 if (c_parser_next_token_is (parser, CPP_EQ)
1609 || c_parser_next_token_is (parser, CPP_COMMA)
1610 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1611 || c_parser_next_token_is_keyword (parser, RID_ASM)
1612 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1613 || c_parser_next_token_is_keyword (parser, RID_IN))
1615 tree asm_name = NULL_TREE;
1616 tree postfix_attrs = NULL_TREE;
1617 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1619 diagnosed_no_specs = true;
1620 pedwarn (here, 0, "data definition has no type or storage class");
1622 /* Having seen a data definition, there cannot now be a
1623 function definition. */
1625 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1626 asm_name = c_parser_simple_asm_expr (parser);
1627 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1628 postfix_attrs = c_parser_attributes (parser);
1629 if (c_parser_next_token_is (parser, CPP_EQ))
1633 location_t init_loc;
1634 c_parser_consume_token (parser);
1635 /* The declaration of the variable is in effect while
1636 its initializer is parsed. */
1637 d = start_decl (declarator, specs, true,
1638 chainon (postfix_attrs, all_prefix_attrs));
1640 d = error_mark_node;
1641 start_init (d, asm_name, global_bindings_p ());
1642 init_loc = c_parser_peek_token (parser)->location;
1643 init = c_parser_initializer (parser);
1645 if (d != error_mark_node)
1647 maybe_warn_string_init (TREE_TYPE (d), init);
1648 finish_decl (d, init_loc, init.value,
1649 init.original_type, asm_name);
1654 tree d = start_decl (declarator, specs, false,
1655 chainon (postfix_attrs,
1658 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1659 NULL_TREE, asm_name);
1661 if (c_parser_next_token_is_keyword (parser, RID_IN))
1664 *objc_foreach_object_declaration = d;
1666 *objc_foreach_object_declaration = error_mark_node;
1669 if (c_parser_next_token_is (parser, CPP_COMMA))
1671 c_parser_consume_token (parser);
1672 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1673 all_prefix_attrs = chainon (c_parser_attributes (parser),
1676 all_prefix_attrs = prefix_attrs;
1679 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1681 c_parser_consume_token (parser);
1684 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1686 /* This can only happen in Objective-C: we found the
1687 'in' that terminates the declaration inside an
1688 Objective-C foreach statement. Do not consume the
1689 token, so that the caller can use it to determine
1690 that this indeed is a foreach context. */
1695 c_parser_error (parser, "expected %<,%> or %<;%>");
1696 c_parser_skip_to_end_of_block_or_statement (parser);
1702 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1703 "%<asm%> or %<__attribute__%>");
1704 c_parser_skip_to_end_of_block_or_statement (parser);
1707 /* Function definition (nested or otherwise). */
1710 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1711 c_push_function_context ();
1713 if (!start_function (specs, declarator, all_prefix_attrs))
1715 /* This can appear in many cases looking nothing like a
1716 function definition, so we don't give a more specific
1717 error suggesting there was one. */
1718 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1719 "or %<__attribute__%>");
1721 c_pop_function_context ();
1725 if (DECL_DECLARED_INLINE_P (current_function_decl))
1726 tv = TV_PARSE_INLINE;
1731 /* Parse old-style parameter declarations. ??? Attributes are
1732 not allowed to start declaration specifiers here because of a
1733 syntax conflict between a function declaration with attribute
1734 suffix and a function definition with an attribute prefix on
1735 first old-style parameter declaration. Following the old
1736 parser, they are not accepted on subsequent old-style
1737 parameter declarations either. However, there is no
1738 ambiguity after the first declaration, nor indeed on the
1739 first as long as we don't allow postfix attributes after a
1740 declarator with a nonempty identifier list in a definition;
1741 and postfix attributes have never been accepted here in
1742 function definitions either. */
1743 while (c_parser_next_token_is_not (parser, CPP_EOF)
1744 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1745 c_parser_declaration_or_fndef (parser, false, false, false,
1747 store_parm_decls ();
1748 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1749 = c_parser_peek_token (parser)->location;
1750 fnbody = c_parser_compound_statement (parser);
1753 tree decl = current_function_decl;
1754 /* Mark nested functions as needing static-chain initially.
1755 lower_nested_functions will recompute it but the
1756 DECL_STATIC_CHAIN flag is also used before that happens,
1757 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1758 DECL_STATIC_CHAIN (decl) = 1;
1761 c_pop_function_context ();
1762 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1775 /* Parse an asm-definition (asm() outside a function body). This is a
1783 c_parser_asm_definition (c_parser *parser)
1785 tree asm_str = c_parser_simple_asm_expr (parser);
1787 cgraph_add_asm_node (asm_str);
1788 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1791 /* Parse a static assertion (C1X N1425 6.7.10).
1793 static_assert-declaration:
1794 static_assert-declaration-no-semi ;
1798 c_parser_static_assert_declaration (c_parser *parser)
1800 c_parser_static_assert_declaration_no_semi (parser);
1802 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1803 c_parser_skip_to_end_of_block_or_statement (parser);
1806 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1809 static_assert-declaration-no-semi:
1810 _Static_assert ( constant-expression , string-literal )
1814 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1816 location_t assert_loc, value_loc;
1820 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1821 assert_loc = c_parser_peek_token (parser)->location;
1825 pedwarn (assert_loc, OPT_pedantic,
1826 "ISO C99 does not support %<_Static_assert%>");
1828 pedwarn (assert_loc, OPT_pedantic,
1829 "ISO C90 does not support %<_Static_assert%>");
1831 c_parser_consume_token (parser);
1832 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1834 value_loc = c_parser_peek_token (parser)->location;
1835 value = c_parser_expr_no_commas (parser, NULL).value;
1836 parser->lex_untranslated_string = true;
1837 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1839 parser->lex_untranslated_string = false;
1842 switch (c_parser_peek_token (parser)->type)
1848 case CPP_UTF8STRING:
1849 string = c_parser_peek_token (parser)->value;
1850 c_parser_consume_token (parser);
1851 parser->lex_untranslated_string = false;
1854 c_parser_error (parser, "expected string literal");
1855 parser->lex_untranslated_string = false;
1858 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1860 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1862 error_at (value_loc, "expression in static assertion is not an integer");
1865 if (TREE_CODE (value) != INTEGER_CST)
1867 value = c_fully_fold (value, false, NULL);
1868 if (TREE_CODE (value) == INTEGER_CST)
1869 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1870 "is not an integer constant expression");
1872 if (TREE_CODE (value) != INTEGER_CST)
1874 error_at (value_loc, "expression in static assertion is not constant");
1877 constant_expression_warning (value);
1878 if (integer_zerop (value))
1879 error_at (assert_loc, "static assertion failed: %E", string);
1882 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1883 6.7), adding them to SPECS (which may already include some).
1884 Storage class specifiers are accepted iff SCSPEC_OK; type
1885 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1886 the start iff START_ATTR_OK.
1888 declaration-specifiers:
1889 storage-class-specifier declaration-specifiers[opt]
1890 type-specifier declaration-specifiers[opt]
1891 type-qualifier declaration-specifiers[opt]
1892 function-specifier declaration-specifiers[opt]
1894 Function specifiers (inline) are from C99, and are currently
1895 handled as storage class specifiers, as is __thread.
1897 C90 6.5.1, C99 6.7.1:
1898 storage-class-specifier:
1909 C90 6.5.2, C99 6.7.2:
1922 [_Imaginary removed in C99 TC2]
1923 struct-or-union-specifier
1927 (_Bool and _Complex are new in C99.)
1929 C90 6.5.3, C99 6.7.3:
1935 address-space-qualifier
1937 (restrict is new in C99.)
1941 declaration-specifiers:
1942 attributes declaration-specifiers[opt]
1948 identifier recognized by the target
1950 storage-class-specifier:
1963 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1964 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1969 class-name objc-protocol-refs[opt]
1970 typedef-name objc-protocol-refs
1975 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1976 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1977 enum c_lookahead_kind la)
1979 bool attrs_ok = start_attr_ok;
1980 bool seen_type = specs->typespec_kind != ctsk_none;
1983 gcc_assert (la == cla_prefer_id);
1985 while (c_parser_next_token_is (parser, CPP_NAME)
1986 || c_parser_next_token_is (parser, CPP_KEYWORD)
1987 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1989 struct c_typespec t;
1991 location_t loc = c_parser_peek_token (parser)->location;
1993 /* If we cannot accept a type, exit if the next token must start
1994 one. Also, if we already have seen a tagged definition,
1995 a typename would be an error anyway and likely the user
1996 has simply forgotten a semicolon, so we exit. */
1997 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
1998 && c_parser_next_tokens_start_typename (parser, la)
1999 && !c_parser_next_token_is_qualifier (parser))
2002 if (c_parser_next_token_is (parser, CPP_NAME))
2004 tree value = c_parser_peek_token (parser)->value;
2005 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
2007 if (kind == C_ID_ADDRSPACE)
2010 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
2011 declspecs_add_addrspace (specs, as);
2012 c_parser_consume_token (parser);
2017 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2019 /* If we cannot accept a type, and the next token must start one,
2020 exit. Do the same if we already have seen a tagged definition,
2021 since it would be an error anyway and likely the user has simply
2022 forgotten a semicolon. */
2023 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2026 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2027 a C_ID_CLASSNAME. */
2028 c_parser_consume_token (parser);
2031 if (kind == C_ID_ID)
2033 error ("unknown type name %qE", value);
2034 t.kind = ctsk_typedef;
2035 t.spec = error_mark_node;
2037 else if (kind == C_ID_TYPENAME
2038 && (!c_dialect_objc ()
2039 || c_parser_next_token_is_not (parser, CPP_LESS)))
2041 t.kind = ctsk_typedef;
2042 /* For a typedef name, record the meaning, not the name.
2043 In case of 'foo foo, bar;'. */
2044 t.spec = lookup_name (value);
2048 tree proto = NULL_TREE;
2049 gcc_assert (c_dialect_objc ());
2051 if (c_parser_next_token_is (parser, CPP_LESS))
2052 proto = c_parser_objc_protocol_refs (parser);
2053 t.spec = objc_get_protocol_qualified_type (value, proto);
2056 t.expr_const_operands = true;
2057 declspecs_add_type (loc, specs, t);
2060 if (c_parser_next_token_is (parser, CPP_LESS))
2062 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2063 nisse@lysator.liu.se. */
2065 gcc_assert (c_dialect_objc ());
2066 if (!typespec_ok || seen_type)
2068 proto = c_parser_objc_protocol_refs (parser);
2070 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2072 t.expr_const_operands = true;
2073 declspecs_add_type (loc, specs, t);
2076 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2077 switch (c_parser_peek_token (parser)->keyword)
2090 /* TODO: Distinguish between function specifiers (inline, noreturn)
2091 and storage class specifiers, either here or in
2092 declspecs_add_scspec. */
2093 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2094 c_parser_consume_token (parser);
2118 if (c_dialect_objc ())
2119 parser->objc_need_raw_identifier = true;
2120 t.kind = ctsk_resword;
2121 t.spec = c_parser_peek_token (parser)->value;
2123 t.expr_const_operands = true;
2124 declspecs_add_type (loc, specs, t);
2125 c_parser_consume_token (parser);
2132 t = c_parser_enum_specifier (parser);
2133 declspecs_add_type (loc, specs, t);
2141 t = c_parser_struct_or_union_specifier (parser);
2142 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2143 declspecs_add_type (loc, specs, t);
2146 /* ??? The old parser rejected typeof after other type
2147 specifiers, but is a syntax error the best way of
2149 if (!typespec_ok || seen_type)
2153 t = c_parser_typeof_specifier (parser);
2154 declspecs_add_type (loc, specs, t);
2160 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2161 c_parser_consume_token (parser);
2166 attrs = c_parser_attributes (parser);
2167 declspecs_add_attrs (specs, attrs);
2176 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2179 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2180 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2181 enum attributes[opt] identifier
2183 The form with trailing comma is new in C99. The forms with
2184 attributes are GNU extensions. In GNU C, we accept any expression
2185 without commas in the syntax (assignment expressions, not just
2186 conditional expressions); assignment expressions will be diagnosed
2191 enumerator-list , enumerator
2194 enumeration-constant
2195 enumeration-constant = constant-expression
2198 static struct c_typespec
2199 c_parser_enum_specifier (c_parser *parser)
2201 struct c_typespec ret;
2203 tree ident = NULL_TREE;
2204 location_t enum_loc;
2205 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2206 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2207 enum_loc = c_parser_peek_token (parser)->location;
2208 c_parser_consume_token (parser);
2209 attrs = c_parser_attributes (parser);
2210 enum_loc = c_parser_peek_token (parser)->location;
2211 /* Set the location in case we create a decl now. */
2212 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2213 if (c_parser_next_token_is (parser, CPP_NAME))
2215 ident = c_parser_peek_token (parser)->value;
2216 ident_loc = c_parser_peek_token (parser)->location;
2217 enum_loc = ident_loc;
2218 c_parser_consume_token (parser);
2220 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2222 /* Parse an enum definition. */
2223 struct c_enum_contents the_enum;
2226 /* We chain the enumerators in reverse order, then put them in
2227 forward order at the end. */
2229 timevar_push (TV_PARSE_ENUM);
2230 type = start_enum (enum_loc, &the_enum, ident);
2232 c_parser_consume_token (parser);
2240 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2241 location_t decl_loc, value_loc;
2242 if (c_parser_next_token_is_not (parser, CPP_NAME))
2244 c_parser_error (parser, "expected identifier");
2245 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2246 values = error_mark_node;
2249 token = c_parser_peek_token (parser);
2250 enum_id = token->value;
2251 /* Set the location in case we create a decl now. */
2252 c_parser_set_source_position_from_token (token);
2253 decl_loc = value_loc = token->location;
2254 c_parser_consume_token (parser);
2255 if (c_parser_next_token_is (parser, CPP_EQ))
2257 c_parser_consume_token (parser);
2258 value_loc = c_parser_peek_token (parser)->location;
2259 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2262 enum_value = NULL_TREE;
2263 enum_decl = build_enumerator (decl_loc, value_loc,
2264 &the_enum, enum_id, enum_value);
2265 TREE_CHAIN (enum_decl) = values;
2268 if (c_parser_next_token_is (parser, CPP_COMMA))
2270 comma_loc = c_parser_peek_token (parser)->location;
2272 c_parser_consume_token (parser);
2274 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2276 if (seen_comma && !flag_isoc99)
2277 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2278 c_parser_consume_token (parser);
2283 c_parser_error (parser, "expected %<,%> or %<}%>");
2284 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2285 values = error_mark_node;
2289 postfix_attrs = c_parser_attributes (parser);
2290 ret.spec = finish_enum (type, nreverse (values),
2291 chainon (attrs, postfix_attrs));
2292 ret.kind = ctsk_tagdef;
2293 ret.expr = NULL_TREE;
2294 ret.expr_const_operands = true;
2295 timevar_pop (TV_PARSE_ENUM);
2300 c_parser_error (parser, "expected %<{%>");
2301 ret.spec = error_mark_node;
2302 ret.kind = ctsk_tagref;
2303 ret.expr = NULL_TREE;
2304 ret.expr_const_operands = true;
2307 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2308 /* In ISO C, enumerated types can be referred to only if already
2310 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2313 pedwarn (enum_loc, OPT_pedantic,
2314 "ISO C forbids forward references to %<enum%> types");
2319 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2321 struct-or-union-specifier:
2322 struct-or-union attributes[opt] identifier[opt]
2323 { struct-contents } attributes[opt]
2324 struct-or-union attributes[opt] identifier
2327 struct-declaration-list
2329 struct-declaration-list:
2330 struct-declaration ;
2331 struct-declaration-list struct-declaration ;
2338 struct-declaration-list struct-declaration
2340 struct-declaration-list:
2341 struct-declaration-list ;
2344 (Note that in the syntax here, unlike that in ISO C, the semicolons
2345 are included here rather than in struct-declaration, in order to
2346 describe the syntax with extra semicolons and missing semicolon at
2351 struct-declaration-list:
2352 @defs ( class-name )
2354 (Note this does not include a trailing semicolon, but can be
2355 followed by further declarations, and gets a pedwarn-if-pedantic
2356 when followed by a semicolon.) */
2358 static struct c_typespec
2359 c_parser_struct_or_union_specifier (c_parser *parser)
2361 struct c_typespec ret;
2363 tree ident = NULL_TREE;
2364 location_t struct_loc;
2365 location_t ident_loc = UNKNOWN_LOCATION;
2366 enum tree_code code;
2367 switch (c_parser_peek_token (parser)->keyword)
2378 struct_loc = c_parser_peek_token (parser)->location;
2379 c_parser_consume_token (parser);
2380 attrs = c_parser_attributes (parser);
2382 /* Set the location in case we create a decl now. */
2383 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2385 if (c_parser_next_token_is (parser, CPP_NAME))
2387 ident = c_parser_peek_token (parser)->value;
2388 ident_loc = c_parser_peek_token (parser)->location;
2389 struct_loc = ident_loc;
2390 c_parser_consume_token (parser);
2392 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2394 /* Parse a struct or union definition. Start the scope of the
2395 tag before parsing components. */
2396 struct c_struct_parse_info *struct_info;
2397 tree type = start_struct (struct_loc, code, ident, &struct_info);
2399 /* We chain the components in reverse order, then put them in
2400 forward order at the end. Each struct-declaration may
2401 declare multiple components (comma-separated), so we must use
2402 chainon to join them, although when parsing each
2403 struct-declaration we can use TREE_CHAIN directly.
2405 The theory behind all this is that there will be more
2406 semicolon separated fields than comma separated fields, and
2407 so we'll be minimizing the number of node traversals required
2410 timevar_push (TV_PARSE_STRUCT);
2411 contents = NULL_TREE;
2412 c_parser_consume_token (parser);
2413 /* Handle the Objective-C @defs construct,
2414 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2415 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2418 gcc_assert (c_dialect_objc ());
2419 c_parser_consume_token (parser);
2420 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2422 if (c_parser_next_token_is (parser, CPP_NAME)
2423 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2425 name = c_parser_peek_token (parser)->value;
2426 c_parser_consume_token (parser);
2430 c_parser_error (parser, "expected class name");
2431 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2436 contents = nreverse (objc_get_class_ivars (name));
2439 /* Parse the struct-declarations and semicolons. Problems with
2440 semicolons are diagnosed here; empty structures are diagnosed
2445 /* Parse any stray semicolon. */
2446 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2448 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2449 "extra semicolon in struct or union specified");
2450 c_parser_consume_token (parser);
2453 /* Stop if at the end of the struct or union contents. */
2454 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2456 c_parser_consume_token (parser);
2459 /* Accept #pragmas at struct scope. */
2460 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2462 c_parser_pragma (parser, pragma_external);
2465 /* Parse some comma-separated declarations, but not the
2466 trailing semicolon if any. */
2467 decls = c_parser_struct_declaration (parser);
2468 contents = chainon (decls, contents);
2469 /* If no semicolon follows, either we have a parse error or
2470 are at the end of the struct or union and should
2472 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2473 c_parser_consume_token (parser);
2476 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2477 pedwarn (c_parser_peek_token (parser)->location, 0,
2478 "no semicolon at end of struct or union");
2479 else if (parser->error
2480 || !c_parser_next_token_starts_declspecs (parser))
2482 c_parser_error (parser, "expected %<;%>");
2483 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2487 /* If we come here, we have already emitted an error
2488 for an expected `;', identifier or `(', and we also
2489 recovered already. Go on with the next field. */
2492 postfix_attrs = c_parser_attributes (parser);
2493 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2494 chainon (attrs, postfix_attrs), struct_info);
2495 ret.kind = ctsk_tagdef;
2496 ret.expr = NULL_TREE;
2497 ret.expr_const_operands = true;
2498 timevar_pop (TV_PARSE_STRUCT);
2503 c_parser_error (parser, "expected %<{%>");
2504 ret.spec = error_mark_node;
2505 ret.kind = ctsk_tagref;
2506 ret.expr = NULL_TREE;
2507 ret.expr_const_operands = true;
2510 ret = parser_xref_tag (ident_loc, code, ident);
2514 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2515 the trailing semicolon.
2518 specifier-qualifier-list struct-declarator-list
2519 static_assert-declaration-no-semi
2521 specifier-qualifier-list:
2522 type-specifier specifier-qualifier-list[opt]
2523 type-qualifier specifier-qualifier-list[opt]
2524 attributes specifier-qualifier-list[opt]
2526 struct-declarator-list:
2528 struct-declarator-list , attributes[opt] struct-declarator
2531 declarator attributes[opt]
2532 declarator[opt] : constant-expression attributes[opt]
2537 __extension__ struct-declaration
2538 specifier-qualifier-list
2540 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2541 of attributes where shown is a GNU extension. In GNU C, we accept
2542 any expression without commas in the syntax (assignment
2543 expressions, not just conditional expressions); assignment
2544 expressions will be diagnosed as non-constant. */
2547 c_parser_struct_declaration (c_parser *parser)
2549 struct c_declspecs *specs;
2551 tree all_prefix_attrs;
2553 location_t decl_loc;
2554 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2558 ext = disable_extension_diagnostics ();
2559 c_parser_consume_token (parser);
2560 decl = c_parser_struct_declaration (parser);
2561 restore_extension_diagnostics (ext);
2564 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2566 c_parser_static_assert_declaration_no_semi (parser);
2569 specs = build_null_declspecs ();
2570 decl_loc = c_parser_peek_token (parser)->location;
2571 c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2574 if (!specs->declspecs_seen_p)
2576 c_parser_error (parser, "expected specifier-qualifier-list");
2579 finish_declspecs (specs);
2580 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2581 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2584 if (specs->typespec_kind == ctsk_none)
2586 pedwarn (decl_loc, OPT_pedantic,
2587 "ISO C forbids member declarations with no members");
2588 shadow_tag_warned (specs, pedantic);
2593 /* Support for unnamed structs or unions as members of
2594 structs or unions (which is [a] useful and [b] supports
2598 ret = grokfield (c_parser_peek_token (parser)->location,
2599 build_id_declarator (NULL_TREE), specs,
2602 decl_attributes (&ret, attrs, 0);
2607 /* Provide better error recovery. Note that a type name here is valid,
2608 and will be treated as a field name. */
2609 if (specs->typespec_kind == ctsk_tagdef
2610 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2611 && c_parser_next_token_starts_declspecs (parser)
2612 && !c_parser_next_token_is (parser, CPP_NAME))
2614 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2615 parser->error = false;
2619 pending_xref_error ();
2620 prefix_attrs = specs->attrs;
2621 all_prefix_attrs = prefix_attrs;
2622 specs->attrs = NULL_TREE;
2626 /* Declaring one or more declarators or un-named bit-fields. */
2627 struct c_declarator *declarator;
2629 if (c_parser_next_token_is (parser, CPP_COLON))
2630 declarator = build_id_declarator (NULL_TREE);
2632 declarator = c_parser_declarator (parser,
2633 specs->typespec_kind != ctsk_none,
2634 C_DTR_NORMAL, &dummy);
2635 if (declarator == NULL)
2637 c_parser_skip_to_end_of_block_or_statement (parser);
2640 if (c_parser_next_token_is (parser, CPP_COLON)
2641 || c_parser_next_token_is (parser, CPP_COMMA)
2642 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2643 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2644 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2646 tree postfix_attrs = NULL_TREE;
2647 tree width = NULL_TREE;
2649 if (c_parser_next_token_is (parser, CPP_COLON))
2651 c_parser_consume_token (parser);
2652 width = c_parser_expr_no_commas (parser, NULL).value;
2654 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2655 postfix_attrs = c_parser_attributes (parser);
2656 d = grokfield (c_parser_peek_token (parser)->location,
2657 declarator, specs, width, &all_prefix_attrs);
2658 decl_attributes (&d, chainon (postfix_attrs,
2659 all_prefix_attrs), 0);
2660 DECL_CHAIN (d) = decls;
2662 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2663 all_prefix_attrs = chainon (c_parser_attributes (parser),
2666 all_prefix_attrs = prefix_attrs;
2667 if (c_parser_next_token_is (parser, CPP_COMMA))
2668 c_parser_consume_token (parser);
2669 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2670 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2672 /* Semicolon consumed in caller. */
2677 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2683 c_parser_error (parser,
2684 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2685 "%<__attribute__%>");
2692 /* Parse a typeof specifier (a GNU extension).
2695 typeof ( expression )
2696 typeof ( type-name )
2699 static struct c_typespec
2700 c_parser_typeof_specifier (c_parser *parser)
2702 struct c_typespec ret;
2703 ret.kind = ctsk_typeof;
2704 ret.spec = error_mark_node;
2705 ret.expr = NULL_TREE;
2706 ret.expr_const_operands = true;
2707 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2708 c_parser_consume_token (parser);
2709 c_inhibit_evaluation_warnings++;
2711 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2713 c_inhibit_evaluation_warnings--;
2717 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2719 struct c_type_name *type = c_parser_type_name (parser);
2720 c_inhibit_evaluation_warnings--;
2724 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2725 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2731 location_t here = c_parser_peek_token (parser)->location;
2732 struct c_expr expr = c_parser_expression (parser);
2733 c_inhibit_evaluation_warnings--;
2735 if (TREE_CODE (expr.value) == COMPONENT_REF
2736 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2737 error_at (here, "%<typeof%> applied to a bit-field");
2738 mark_exp_read (expr.value);
2739 ret.spec = TREE_TYPE (expr.value);
2740 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2741 /* This is returned with the type so that when the type is
2742 evaluated, this can be evaluated. */
2744 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2745 pop_maybe_used (was_vm);
2747 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2751 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2752 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2753 be redeclared; otherwise it may not. KIND indicates which kind of
2754 declarator is wanted. Returns a valid declarator except in the
2755 case of a syntax error in which case NULL is returned. *SEEN_ID is
2756 set to true if an identifier being declared is seen; this is used
2757 to diagnose bad forms of abstract array declarators and to
2758 determine whether an identifier list is syntactically permitted.
2761 pointer[opt] direct-declarator
2765 ( attributes[opt] declarator )
2766 direct-declarator array-declarator
2767 direct-declarator ( parameter-type-list )
2768 direct-declarator ( identifier-list[opt] )
2771 * type-qualifier-list[opt]
2772 * type-qualifier-list[opt] pointer
2774 type-qualifier-list:
2777 type-qualifier-list type-qualifier
2778 type-qualifier-list attributes
2780 parameter-type-list:
2782 parameter-list , ...
2785 parameter-declaration
2786 parameter-list , parameter-declaration
2788 parameter-declaration:
2789 declaration-specifiers declarator attributes[opt]
2790 declaration-specifiers abstract-declarator[opt] attributes[opt]
2794 identifier-list , identifier
2796 abstract-declarator:
2798 pointer[opt] direct-abstract-declarator
2800 direct-abstract-declarator:
2801 ( attributes[opt] abstract-declarator )
2802 direct-abstract-declarator[opt] array-declarator
2803 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2808 direct-declarator ( parameter-forward-declarations
2809 parameter-type-list[opt] )
2811 direct-abstract-declarator:
2812 direct-abstract-declarator[opt] ( parameter-forward-declarations
2813 parameter-type-list[opt] )
2815 parameter-forward-declarations:
2817 parameter-forward-declarations parameter-list ;
2819 The uses of attributes shown above are GNU extensions.
2821 Some forms of array declarator are not included in C99 in the
2822 syntax for abstract declarators; these are disallowed elsewhere.
2823 This may be a defect (DR#289).
2825 This function also accepts an omitted abstract declarator as being
2826 an abstract declarator, although not part of the formal syntax. */
2828 static struct c_declarator *
2829 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2832 /* Parse any initial pointer part. */
2833 if (c_parser_next_token_is (parser, CPP_MULT))
2835 struct c_declspecs *quals_attrs = build_null_declspecs ();
2836 struct c_declarator *inner;
2837 c_parser_consume_token (parser);
2838 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2839 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2843 return make_pointer_declarator (quals_attrs, inner);
2845 /* Now we have a direct declarator, direct abstract declarator or
2846 nothing (which counts as a direct abstract declarator here). */
2847 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2850 /* Parse a direct declarator or direct abstract declarator; arguments
2851 as c_parser_declarator. */
2853 static struct c_declarator *
2854 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2857 /* The direct declarator must start with an identifier (possibly
2858 omitted) or a parenthesized declarator (possibly abstract). In
2859 an ordinary declarator, initial parentheses must start a
2860 parenthesized declarator. In an abstract declarator or parameter
2861 declarator, they could start a parenthesized declarator or a
2862 parameter list. To tell which, the open parenthesis and any
2863 following attributes must be read. If a declaration specifier
2864 follows, then it is a parameter list; if the specifier is a
2865 typedef name, there might be an ambiguity about redeclaring it,
2866 which is resolved in the direction of treating it as a typedef
2867 name. If a close parenthesis follows, it is also an empty
2868 parameter list, as the syntax does not permit empty abstract
2869 declarators. Otherwise, it is a parenthesized declarator (in
2870 which case the analysis may be repeated inside it, recursively).
2872 ??? There is an ambiguity in a parameter declaration "int
2873 (__attribute__((foo)) x)", where x is not a typedef name: it
2874 could be an abstract declarator for a function, or declare x with
2875 parentheses. The proper resolution of this ambiguity needs
2876 documenting. At present we follow an accident of the old
2877 parser's implementation, whereby the first parameter must have
2878 some declaration specifiers other than just attributes. Thus as
2879 a parameter declaration it is treated as a parenthesized
2880 parameter named x, and as an abstract declarator it is
2883 ??? Also following the old parser, attributes inside an empty
2884 parameter list are ignored, making it a list not yielding a
2885 prototype, rather than giving an error or making it have one
2886 parameter with implicit type int.
2888 ??? Also following the old parser, typedef names may be
2889 redeclared in declarators, but not Objective-C class names. */
2891 if (kind != C_DTR_ABSTRACT
2892 && c_parser_next_token_is (parser, CPP_NAME)
2894 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2895 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2896 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2898 struct c_declarator *inner
2899 = build_id_declarator (c_parser_peek_token (parser)->value);
2901 inner->id_loc = c_parser_peek_token (parser)->location;
2902 c_parser_consume_token (parser);
2903 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2906 if (kind != C_DTR_NORMAL
2907 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2909 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2910 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2913 /* Either we are at the end of an abstract declarator, or we have
2916 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2919 struct c_declarator *inner;
2920 c_parser_consume_token (parser);
2921 attrs = c_parser_attributes (parser);
2922 if (kind != C_DTR_NORMAL
2923 && (c_parser_next_token_starts_declspecs (parser)
2924 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2926 struct c_arg_info *args
2927 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2934 = build_function_declarator (args,
2935 build_id_declarator (NULL_TREE));
2936 return c_parser_direct_declarator_inner (parser, *seen_id,
2940 /* A parenthesized declarator. */
2941 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2942 if (inner != NULL && attrs != NULL)
2943 inner = build_attrs_declarator (attrs, inner);
2944 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2946 c_parser_consume_token (parser);
2950 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2954 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2961 if (kind == C_DTR_NORMAL)
2963 c_parser_error (parser, "expected identifier or %<(%>");
2967 return build_id_declarator (NULL_TREE);
2971 /* Parse part of a direct declarator or direct abstract declarator,
2972 given that some (in INNER) has already been parsed; ID_PRESENT is
2973 true if an identifier is present, false for an abstract
2976 static struct c_declarator *
2977 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2978 struct c_declarator *inner)
2980 /* Parse a sequence of array declarators and parameter lists. */
2981 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2983 location_t brace_loc = c_parser_peek_token (parser)->location;
2984 struct c_declarator *declarator;
2985 struct c_declspecs *quals_attrs = build_null_declspecs ();
2989 c_parser_consume_token (parser);
2990 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2991 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2993 c_parser_consume_token (parser);
2994 if (static_seen && !quals_attrs->declspecs_seen_p)
2995 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2996 if (!quals_attrs->declspecs_seen_p)
2998 /* If "static" is present, there must be an array dimension.
2999 Otherwise, there may be a dimension, "*", or no
3004 dimen = c_parser_expr_no_commas (parser, NULL).value;
3008 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3013 else if (c_parser_next_token_is (parser, CPP_MULT))
3015 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3019 c_parser_consume_token (parser);
3024 dimen = c_parser_expr_no_commas (parser, NULL).value;
3030 dimen = c_parser_expr_no_commas (parser, NULL).value;
3033 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3034 c_parser_consume_token (parser);
3037 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3042 mark_exp_read (dimen);
3043 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3044 static_seen, star_seen);
3045 if (declarator == NULL)
3047 inner = set_array_declarator_inner (declarator, inner);
3048 return c_parser_direct_declarator_inner (parser, id_present, inner);
3050 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3053 struct c_arg_info *args;
3054 c_parser_consume_token (parser);
3055 attrs = c_parser_attributes (parser);
3056 args = c_parser_parms_declarator (parser, id_present, attrs);
3061 inner = build_function_declarator (args, inner);
3062 return c_parser_direct_declarator_inner (parser, id_present, inner);
3068 /* Parse a parameter list or identifier list, including the closing
3069 parenthesis but not the opening one. ATTRS are the attributes at
3070 the start of the list. ID_LIST_OK is true if an identifier list is
3071 acceptable; such a list must not have attributes at the start. */
3073 static struct c_arg_info *
3074 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3077 declare_parm_level ();
3078 /* If the list starts with an identifier, it is an identifier list.
3079 Otherwise, it is either a prototype list or an empty list. */
3082 && c_parser_next_token_is (parser, CPP_NAME)
3083 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3085 /* Look ahead to detect typos in type names. */
3086 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3087 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3088 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3089 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3091 tree list = NULL_TREE, *nextp = &list;
3092 while (c_parser_next_token_is (parser, CPP_NAME)
3093 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3095 *nextp = build_tree_list (NULL_TREE,
3096 c_parser_peek_token (parser)->value);
3097 nextp = & TREE_CHAIN (*nextp);
3098 c_parser_consume_token (parser);
3099 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3101 c_parser_consume_token (parser);
3102 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3104 c_parser_error (parser, "expected identifier");
3108 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3110 struct c_arg_info *ret = build_arg_info ();
3112 c_parser_consume_token (parser);
3118 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3126 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3133 /* Parse a parameter list (possibly empty), including the closing
3134 parenthesis but not the opening one. ATTRS are the attributes at
3135 the start of the list. EXPR is NULL or an expression that needs to
3136 be evaluated for the side effects of array size expressions in the
3139 static struct c_arg_info *
3140 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3142 bool bad_parm = false;
3144 /* ??? Following the old parser, forward parameter declarations may
3145 use abstract declarators, and if no real parameter declarations
3146 follow the forward declarations then this is not diagnosed. Also
3147 note as above that attributes are ignored as the only contents of
3148 the parentheses, or as the only contents after forward
3150 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3152 struct c_arg_info *ret = build_arg_info ();
3153 c_parser_consume_token (parser);
3156 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3158 struct c_arg_info *ret = build_arg_info ();
3159 /* Suppress -Wold-style-definition for this case. */
3160 ret->types = error_mark_node;
3161 error_at (c_parser_peek_token (parser)->location,
3162 "ISO C requires a named argument before %<...%>");
3163 c_parser_consume_token (parser);
3164 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3166 c_parser_consume_token (parser);
3171 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3176 /* Nonempty list of parameters, either terminated with semicolon
3177 (forward declarations; recurse) or with close parenthesis (normal
3178 function) or with ", ... )" (variadic function). */
3181 /* Parse a parameter. */
3182 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3187 push_parm_decl (parm, &expr);
3188 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3191 c_parser_consume_token (parser);
3192 mark_forward_parm_decls ();
3193 new_attrs = c_parser_attributes (parser);
3194 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3196 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3198 c_parser_consume_token (parser);
3202 return get_parm_info (false, expr);
3204 if (!c_parser_require (parser, CPP_COMMA,
3205 "expected %<;%>, %<,%> or %<)%>"))
3207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3210 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3212 c_parser_consume_token (parser);
3213 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3215 c_parser_consume_token (parser);
3219 return get_parm_info (true, expr);
3223 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3231 /* Parse a parameter declaration. ATTRS are the attributes at the
3232 start of the declaration if it is the first parameter. */
3234 static struct c_parm *
3235 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3237 struct c_declspecs *specs;
3238 struct c_declarator *declarator;
3240 tree postfix_attrs = NULL_TREE;
3242 if (!c_parser_next_token_starts_declspecs (parser))
3244 c_token *token = c_parser_peek_token (parser);
3247 c_parser_set_source_position_from_token (token);
3248 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3250 error ("unknown type name %qE", token->value);
3251 parser->error = true;
3253 /* ??? In some Objective-C cases '...' isn't applicable so there
3254 should be a different message. */
3256 c_parser_error (parser,
3257 "expected declaration specifiers or %<...%>");
3258 c_parser_skip_to_end_of_parameter (parser);
3261 specs = build_null_declspecs ();
3264 declspecs_add_attrs (specs, attrs);
3267 c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3268 finish_declspecs (specs);
3269 pending_xref_error ();
3270 prefix_attrs = specs->attrs;
3271 specs->attrs = NULL_TREE;
3272 declarator = c_parser_declarator (parser,
3273 specs->typespec_kind != ctsk_none,
3274 C_DTR_PARM, &dummy);
3275 if (declarator == NULL)
3277 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3280 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3281 postfix_attrs = c_parser_attributes (parser);
3282 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3286 /* Parse a string literal in an asm expression. It should not be
3287 translated, and wide string literals are an error although
3288 permitted by the syntax. This is a GNU extension.
3293 ??? At present, following the old parser, the caller needs to have
3294 set lex_untranslated_string to 1. It would be better to follow the
3295 C++ parser rather than using this kludge. */
3298 c_parser_asm_string_literal (c_parser *parser)
3301 int save_flag = warn_overlength_strings;
3302 warn_overlength_strings = 0;
3303 if (c_parser_next_token_is (parser, CPP_STRING))
3305 str = c_parser_peek_token (parser)->value;
3306 c_parser_consume_token (parser);
3308 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3310 error_at (c_parser_peek_token (parser)->location,
3311 "wide string literal in %<asm%>");
3312 str = build_string (1, "");
3313 c_parser_consume_token (parser);
3317 c_parser_error (parser, "expected string literal");
3320 warn_overlength_strings = save_flag;
3324 /* Parse a simple asm expression. This is used in restricted
3325 contexts, where a full expression with inputs and outputs does not
3326 make sense. This is a GNU extension.
3329 asm ( asm-string-literal )
3333 c_parser_simple_asm_expr (c_parser *parser)
3336 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3337 /* ??? Follow the C++ parser rather than using the
3338 lex_untranslated_string kludge. */
3339 parser->lex_untranslated_string = true;
3340 c_parser_consume_token (parser);
3341 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3343 parser->lex_untranslated_string = false;
3346 str = c_parser_asm_string_literal (parser);
3347 parser->lex_untranslated_string = false;
3348 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3350 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3356 /* Parse (possibly empty) attributes. This is a GNU extension.
3360 attributes attribute
3363 __attribute__ ( ( attribute-list ) )
3367 attribute_list , attrib
3372 any-word ( identifier )
3373 any-word ( identifier , nonempty-expr-list )
3374 any-word ( expr-list )
3376 where the "identifier" must not be declared as a type, and
3377 "any-word" may be any identifier (including one declared as a
3378 type), a reserved word storage class specifier, type specifier or
3379 type qualifier. ??? This still leaves out most reserved keywords
3380 (following the old parser), shouldn't we include them, and why not
3381 allow identifiers declared as types to start the arguments? */
3384 c_parser_attributes (c_parser *parser)
3386 tree attrs = NULL_TREE;
3387 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3389 /* ??? Follow the C++ parser rather than using the
3390 lex_untranslated_string kludge. */
3391 parser->lex_untranslated_string = true;
3392 c_parser_consume_token (parser);
3393 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3395 parser->lex_untranslated_string = false;
3398 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3400 parser->lex_untranslated_string = false;
3401 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3404 /* Parse the attribute list. */
3405 while (c_parser_next_token_is (parser, CPP_COMMA)
3406 || c_parser_next_token_is (parser, CPP_NAME)
3407 || c_parser_next_token_is (parser, CPP_KEYWORD))
3409 tree attr, attr_name, attr_args;
3410 VEC(tree,gc) *expr_list;
3411 if (c_parser_next_token_is (parser, CPP_COMMA))
3413 c_parser_consume_token (parser);
3416 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3418 /* ??? See comment above about what keywords are
3421 switch (c_parser_peek_token (parser)->keyword)
3460 /* Accept __attribute__((__const)) as __attribute__((const))
3463 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3466 attr_name = c_parser_peek_token (parser)->value;
3467 c_parser_consume_token (parser);
3468 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3470 attr = build_tree_list (attr_name, NULL_TREE);
3471 attrs = chainon (attrs, attr);
3474 c_parser_consume_token (parser);
3475 /* Parse the attribute contents. If they start with an
3476 identifier which is followed by a comma or close
3477 parenthesis, then the arguments start with that
3478 identifier; otherwise they are an expression list.
3479 In objective-c the identifier may be a classname. */
3480 if (c_parser_next_token_is (parser, CPP_NAME)
3481 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3482 || (c_dialect_objc ()
3483 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3484 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3485 || (c_parser_peek_2nd_token (parser)->type
3486 == CPP_CLOSE_PAREN)))
3488 tree arg1 = c_parser_peek_token (parser)->value;
3489 c_parser_consume_token (parser);
3490 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3491 attr_args = build_tree_list (NULL_TREE, arg1);
3495 c_parser_consume_token (parser);
3496 expr_list = c_parser_expr_list (parser, false, true, NULL);
3497 tree_list = build_tree_list_vec (expr_list);
3498 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3499 release_tree_vector (expr_list);
3504 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3505 attr_args = NULL_TREE;
3508 expr_list = c_parser_expr_list (parser, false, true, NULL);
3509 attr_args = build_tree_list_vec (expr_list);
3510 release_tree_vector (expr_list);
3513 attr = build_tree_list (attr_name, attr_args);
3514 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3515 c_parser_consume_token (parser);
3518 parser->lex_untranslated_string = false;
3519 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3523 attrs = chainon (attrs, attr);
3525 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3526 c_parser_consume_token (parser);
3529 parser->lex_untranslated_string = false;
3530 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3534 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3535 c_parser_consume_token (parser);
3538 parser->lex_untranslated_string = false;
3539 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3543 parser->lex_untranslated_string = false;
3548 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3551 specifier-qualifier-list abstract-declarator[opt]
3554 static struct c_type_name *
3555 c_parser_type_name (c_parser *parser)
3557 struct c_declspecs *specs = build_null_declspecs ();
3558 struct c_declarator *declarator;
3559 struct c_type_name *ret;
3561 c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3562 if (!specs->declspecs_seen_p)
3564 c_parser_error (parser, "expected specifier-qualifier-list");
3567 if (specs->type != error_mark_node)
3569 pending_xref_error ();
3570 finish_declspecs (specs);
3572 declarator = c_parser_declarator (parser,
3573 specs->typespec_kind != ctsk_none,
3574 C_DTR_ABSTRACT, &dummy);
3575 if (declarator == NULL)
3577 ret = XOBNEW (&parser_obstack, struct c_type_name);
3579 ret->declarator = declarator;
3583 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3586 assignment-expression
3587 { initializer-list }
3588 { initializer-list , }
3591 designation[opt] initializer
3592 initializer-list , designation[opt] initializer
3599 designator-list designator
3606 [ constant-expression ]
3618 [ constant-expression ... constant-expression ]
3620 Any expression without commas is accepted in the syntax for the
3621 constant-expressions, with non-constant expressions rejected later.
3623 This function is only used for top-level initializers; for nested
3624 ones, see c_parser_initval. */
3626 static struct c_expr
3627 c_parser_initializer (c_parser *parser)
3629 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3630 return c_parser_braced_init (parser, NULL_TREE, false);
3634 location_t loc = c_parser_peek_token (parser)->location;
3635 ret = c_parser_expr_no_commas (parser, NULL);
3636 if (TREE_CODE (ret.value) != STRING_CST
3637 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3638 ret = default_function_array_read_conversion (loc, ret);
3643 /* Parse a braced initializer list. TYPE is the type specified for a
3644 compound literal, and NULL_TREE for other initializers and for
3645 nested braced lists. NESTED_P is true for nested braced lists,
3646 false for the list of a compound literal or the list that is the
3647 top-level initializer in a declaration. */
3649 static struct c_expr
3650 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3653 struct obstack braced_init_obstack;
3654 location_t brace_loc = c_parser_peek_token (parser)->location;
3655 gcc_obstack_init (&braced_init_obstack);
3656 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3657 c_parser_consume_token (parser);
3659 push_init_level (0, &braced_init_obstack);
3661 really_start_incremental_init (type);
3662 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3664 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3668 /* Parse a non-empty initializer list, possibly with a trailing
3672 c_parser_initelt (parser, &braced_init_obstack);
3675 if (c_parser_next_token_is (parser, CPP_COMMA))
3676 c_parser_consume_token (parser);
3679 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3683 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3685 ret.value = error_mark_node;
3686 ret.original_code = ERROR_MARK;
3687 ret.original_type = NULL;
3688 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3689 pop_init_level (0, &braced_init_obstack);
3690 obstack_free (&braced_init_obstack, NULL);
3693 c_parser_consume_token (parser);
3694 ret = pop_init_level (0, &braced_init_obstack);
3695 obstack_free (&braced_init_obstack, NULL);
3699 /* Parse a nested initializer, including designators. */
3702 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3704 /* Parse any designator or designator list. A single array
3705 designator may have the subsequent "=" omitted in GNU C, but a
3706 longer list or a structure member designator may not. */
3707 if (c_parser_next_token_is (parser, CPP_NAME)
3708 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3710 /* Old-style structure member designator. */
3711 set_init_label (c_parser_peek_token (parser)->value,
3712 braced_init_obstack);
3713 /* Use the colon as the error location. */
3714 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3715 "obsolete use of designated initializer with %<:%>");
3716 c_parser_consume_token (parser);
3717 c_parser_consume_token (parser);
3721 /* des_seen is 0 if there have been no designators, 1 if there
3722 has been a single array designator and 2 otherwise. */
3724 /* Location of a designator. */
3725 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3726 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3727 || c_parser_next_token_is (parser, CPP_DOT))
3729 int des_prev = des_seen;
3731 des_loc = c_parser_peek_token (parser)->location;
3734 if (c_parser_next_token_is (parser, CPP_DOT))
3737 c_parser_consume_token (parser);
3738 if (c_parser_next_token_is (parser, CPP_NAME))
3740 set_init_label (c_parser_peek_token (parser)->value,
3741 braced_init_obstack);
3742 c_parser_consume_token (parser);
3747 init.value = error_mark_node;
3748 init.original_code = ERROR_MARK;
3749 init.original_type = NULL;
3750 c_parser_error (parser, "expected identifier");
3751 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3752 process_init_element (init, false, braced_init_obstack);
3759 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3760 /* ??? Following the old parser, [ objc-receiver
3761 objc-message-args ] is accepted as an initializer,
3762 being distinguished from a designator by what follows
3763 the first assignment expression inside the square
3764 brackets, but after a first array designator a
3765 subsequent square bracket is for Objective-C taken to
3766 start an expression, using the obsolete form of
3767 designated initializer without '=', rather than
3768 possibly being a second level of designation: in LALR
3769 terms, the '[' is shifted rather than reducing
3770 designator to designator-list. */
3771 if (des_prev == 1 && c_dialect_objc ())
3773 des_seen = des_prev;
3776 if (des_prev == 0 && c_dialect_objc ())
3778 /* This might be an array designator or an
3779 Objective-C message expression. If the former,
3780 continue parsing here; if the latter, parse the
3781 remainder of the initializer given the starting
3782 primary-expression. ??? It might make sense to
3783 distinguish when des_prev == 1 as well; see
3784 previous comment. */
3786 struct c_expr mexpr;
3787 c_parser_consume_token (parser);
3788 if (c_parser_peek_token (parser)->type == CPP_NAME
3789 && ((c_parser_peek_token (parser)->id_kind
3791 || (c_parser_peek_token (parser)->id_kind
3792 == C_ID_CLASSNAME)))
3794 /* Type name receiver. */
3795 tree id = c_parser_peek_token (parser)->value;
3796 c_parser_consume_token (parser);
3797 rec = objc_get_class_reference (id);
3798 goto parse_message_args;
3800 first = c_parser_expr_no_commas (parser, NULL).value;
3801 mark_exp_read (first);
3802 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3803 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3804 goto array_desig_after_first;
3805 /* Expression receiver. So far only one part
3806 without commas has been parsed; there might be
3807 more of the expression. */
3809 while (c_parser_next_token_is (parser, CPP_COMMA))
3812 location_t comma_loc, exp_loc;
3813 comma_loc = c_parser_peek_token (parser)->location;
3814 c_parser_consume_token (parser);
3815 exp_loc = c_parser_peek_token (parser)->location;
3816 next = c_parser_expr_no_commas (parser, NULL);
3817 next = default_function_array_read_conversion (exp_loc,
3819 rec = build_compound_expr (comma_loc, rec, next.value);
3822 /* Now parse the objc-message-args. */
3823 args = c_parser_objc_message_args (parser);
3824 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3827 = objc_build_message_expr (rec, args);
3828 mexpr.original_code = ERROR_MARK;
3829 mexpr.original_type = NULL;
3830 /* Now parse and process the remainder of the
3831 initializer, starting with this message
3832 expression as a primary-expression. */
3833 c_parser_initval (parser, &mexpr, braced_init_obstack);
3836 c_parser_consume_token (parser);
3837 first = c_parser_expr_no_commas (parser, NULL).value;
3838 mark_exp_read (first);
3839 array_desig_after_first:
3840 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3842 ellipsis_loc = c_parser_peek_token (parser)->location;
3843 c_parser_consume_token (parser);
3844 second = c_parser_expr_no_commas (parser, NULL).value;
3845 mark_exp_read (second);
3849 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3851 c_parser_consume_token (parser);
3852 set_init_index (first, second, braced_init_obstack);
3854 pedwarn (ellipsis_loc, OPT_pedantic,
3855 "ISO C forbids specifying range of elements to initialize");
3858 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3864 if (c_parser_next_token_is (parser, CPP_EQ))
3867 pedwarn (des_loc, OPT_pedantic,
3868 "ISO C90 forbids specifying subobject to initialize");
3869 c_parser_consume_token (parser);
3874 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3875 "obsolete use of designated initializer without %<=%>");
3879 init.value = error_mark_node;
3880 init.original_code = ERROR_MARK;
3881 init.original_type = NULL;
3882 c_parser_error (parser, "expected %<=%>");
3883 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3884 process_init_element (init, false, braced_init_obstack);
3890 c_parser_initval (parser, NULL, braced_init_obstack);
3893 /* Parse a nested initializer; as c_parser_initializer but parses
3894 initializers within braced lists, after any designators have been
3895 applied. If AFTER is not NULL then it is an Objective-C message
3896 expression which is the primary-expression starting the
3900 c_parser_initval (c_parser *parser, struct c_expr *after,
3901 struct obstack * braced_init_obstack)
3904 gcc_assert (!after || c_dialect_objc ());
3905 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3906 init = c_parser_braced_init (parser, NULL_TREE, true);
3909 location_t loc = c_parser_peek_token (parser)->location;
3910 init = c_parser_expr_no_commas (parser, after);
3911 if (init.value != NULL_TREE
3912 && TREE_CODE (init.value) != STRING_CST
3913 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3914 init = default_function_array_read_conversion (loc, init);
3916 process_init_element (init, false, braced_init_obstack);
3919 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3923 { block-item-list[opt] }
3924 { label-declarations block-item-list }
3928 block-item-list block-item
3940 { label-declarations block-item-list }
3943 __extension__ nested-declaration
3944 nested-function-definition
3948 label-declarations label-declaration
3951 __label__ identifier-list ;
3953 Allowing the mixing of declarations and code is new in C99. The
3954 GNU syntax also permits (not shown above) labels at the end of
3955 compound statements, which yield an error. We don't allow labels
3956 on declarations; this might seem like a natural extension, but
3957 there would be a conflict between attributes on the label and
3958 prefix attributes on the declaration. ??? The syntax follows the
3959 old parser in requiring something after label declarations.
3960 Although they are erroneous if the labels declared aren't defined,
3961 is it useful for the syntax to be this way?
3973 c_parser_compound_statement (c_parser *parser)
3976 location_t brace_loc;
3977 brace_loc = c_parser_peek_token (parser)->location;
3978 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3980 /* Ensure a scope is entered and left anyway to avoid confusion
3981 if we have just prepared to enter a function body. */
3982 stmt = c_begin_compound_stmt (true);
3983 c_end_compound_stmt (brace_loc, stmt, true);
3984 return error_mark_node;
3986 stmt = c_begin_compound_stmt (true);
3987 c_parser_compound_statement_nostart (parser);
3988 return c_end_compound_stmt (brace_loc, stmt, true);
3991 /* Parse a compound statement except for the opening brace. This is
3992 used for parsing both compound statements and statement expressions
3993 (which follow different paths to handling the opening). */
3996 c_parser_compound_statement_nostart (c_parser *parser)
3998 bool last_stmt = false;
3999 bool last_label = false;
4000 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4001 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4002 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4004 c_parser_consume_token (parser);
4007 mark_valid_location_for_stdc_pragma (true);
4008 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4010 /* Read zero or more forward-declarations for labels that nested
4011 functions can jump to. */
4012 mark_valid_location_for_stdc_pragma (false);
4013 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4015 label_loc = c_parser_peek_token (parser)->location;
4016 c_parser_consume_token (parser);
4017 /* Any identifiers, including those declared as type names,
4022 if (c_parser_next_token_is_not (parser, CPP_NAME))
4024 c_parser_error (parser, "expected identifier");
4028 = declare_label (c_parser_peek_token (parser)->value);
4029 C_DECLARED_LABEL_FLAG (label) = 1;
4030 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4031 c_parser_consume_token (parser);
4032 if (c_parser_next_token_is (parser, CPP_COMMA))
4033 c_parser_consume_token (parser);
4037 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4039 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
4041 /* We must now have at least one statement, label or declaration. */
4042 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4044 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4045 c_parser_error (parser, "expected declaration or statement");
4046 c_parser_consume_token (parser);
4049 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4051 location_t loc = c_parser_peek_token (parser)->location;
4052 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4053 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4054 || (c_parser_next_token_is (parser, CPP_NAME)
4055 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4057 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4058 label_loc = c_parser_peek_2nd_token (parser)->location;
4060 label_loc = c_parser_peek_token (parser)->location;
4063 mark_valid_location_for_stdc_pragma (false);
4064 c_parser_label (parser);
4066 else if (!last_label
4067 && c_parser_next_tokens_start_declaration (parser))
4070 mark_valid_location_for_stdc_pragma (false);
4071 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4074 (pedantic && !flag_isoc99)
4076 : OPT_Wdeclaration_after_statement,
4077 "ISO C90 forbids mixed declarations and code");
4080 else if (!last_label
4081 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4083 /* __extension__ can start a declaration, but is also an
4084 unary operator that can start an expression. Consume all
4085 but the last of a possible series of __extension__ to
4087 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4088 && (c_parser_peek_2nd_token (parser)->keyword
4090 c_parser_consume_token (parser);
4091 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4094 ext = disable_extension_diagnostics ();
4095 c_parser_consume_token (parser);
4097 mark_valid_location_for_stdc_pragma (false);
4098 c_parser_declaration_or_fndef (parser, true, true, true, true,
4100 /* Following the old parser, __extension__ does not
4101 disable this diagnostic. */
4102 restore_extension_diagnostics (ext);
4104 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4106 : OPT_Wdeclaration_after_statement,
4107 "ISO C90 forbids mixed declarations and code");
4113 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4115 /* External pragmas, and some omp pragmas, are not associated
4116 with regular c code, and so are not to be considered statements
4117 syntactically. This ensures that the user doesn't put them
4118 places that would turn into syntax errors if the directive
4120 if (c_parser_pragma (parser, pragma_compound))
4121 last_label = false, last_stmt = true;
4123 else if (c_parser_next_token_is (parser, CPP_EOF))
4125 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4126 c_parser_error (parser, "expected declaration or statement");
4129 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4131 if (parser->in_if_block)
4133 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4134 error_at (loc, """expected %<}%> before %<else%>");
4139 error_at (loc, "%<else%> without a previous %<if%>");
4140 c_parser_consume_token (parser);
4149 mark_valid_location_for_stdc_pragma (false);
4150 c_parser_statement_after_labels (parser);
4153 parser->error = false;
4156 error_at (label_loc, "label at end of compound statement");
4157 c_parser_consume_token (parser);
4158 /* Restore the value we started with. */
4159 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4162 /* Parse a label (C90 6.6.1, C99 6.8.1).
4165 identifier : attributes[opt]
4166 case constant-expression :
4172 case constant-expression ... constant-expression :
4174 The use of attributes on labels is a GNU extension. The syntax in
4175 GNU C accepts any expressions without commas, non-constant
4176 expressions being rejected later. */
4179 c_parser_label (c_parser *parser)
4181 location_t loc1 = c_parser_peek_token (parser)->location;
4182 tree label = NULL_TREE;
4183 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4186 c_parser_consume_token (parser);
4187 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4188 if (c_parser_next_token_is (parser, CPP_COLON))
4190 c_parser_consume_token (parser);
4191 label = do_case (loc1, exp1, NULL_TREE);
4193 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4195 c_parser_consume_token (parser);
4196 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4197 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4198 label = do_case (loc1, exp1, exp2);
4201 c_parser_error (parser, "expected %<:%> or %<...%>");
4203 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4205 c_parser_consume_token (parser);
4206 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4207 label = do_case (loc1, NULL_TREE, NULL_TREE);
4211 tree name = c_parser_peek_token (parser)->value;
4214 location_t loc2 = c_parser_peek_token (parser)->location;
4215 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4216 c_parser_consume_token (parser);
4217 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4218 c_parser_consume_token (parser);
4219 attrs = c_parser_attributes (parser);
4220 tlab = define_label (loc2, name);
4223 decl_attributes (&tlab, attrs, 0);
4224 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4229 if (c_parser_next_tokens_start_declaration (parser))
4231 error_at (c_parser_peek_token (parser)->location,
4232 "a label can only be part of a statement and "
4233 "a declaration is not a statement");
4234 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4235 /*static_assert_ok*/ true,
4236 /*nested*/ true, /*empty_ok*/ false,
4237 /*start_attr_ok*/ true, NULL);
4242 /* Parse a statement (C90 6.6, C99 6.8).
4247 expression-statement
4255 expression-statement:
4258 selection-statement:
4262 iteration-statement:
4271 return expression[opt] ;
4284 objc-throw-statement
4285 objc-try-catch-statement
4286 objc-synchronized-statement
4288 objc-throw-statement:
4302 parallel-for-construct
4303 parallel-sections-construct
4310 parallel-directive structured-block
4313 for-directive iteration-statement
4316 sections-directive section-scope
4319 single-directive structured-block
4321 parallel-for-construct:
4322 parallel-for-directive iteration-statement
4324 parallel-sections-construct:
4325 parallel-sections-directive section-scope
4328 master-directive structured-block
4331 critical-directive structured-block
4334 atomic-directive expression-statement
4337 ordered-directive structured-block */
4340 c_parser_statement (c_parser *parser)
4342 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4343 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4344 || (c_parser_next_token_is (parser, CPP_NAME)
4345 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4346 c_parser_label (parser);
4347 c_parser_statement_after_labels (parser);
4350 /* Parse a statement, other than a labeled statement. */
4353 c_parser_statement_after_labels (c_parser *parser)
4355 location_t loc = c_parser_peek_token (parser)->location;
4356 tree stmt = NULL_TREE;
4357 bool in_if_block = parser->in_if_block;
4358 parser->in_if_block = false;
4359 switch (c_parser_peek_token (parser)->type)
4361 case CPP_OPEN_BRACE:
4362 add_stmt (c_parser_compound_statement (parser));
4365 switch (c_parser_peek_token (parser)->keyword)
4368 c_parser_if_statement (parser);
4371 c_parser_switch_statement (parser);
4374 c_parser_while_statement (parser);
4377 c_parser_do_statement (parser);
4380 c_parser_for_statement (parser);
4383 c_parser_consume_token (parser);
4384 if (c_parser_next_token_is (parser, CPP_NAME))
4386 stmt = c_finish_goto_label (loc,
4387 c_parser_peek_token (parser)->value);
4388 c_parser_consume_token (parser);
4390 else if (c_parser_next_token_is (parser, CPP_MULT))
4394 c_parser_consume_token (parser);
4395 val = c_parser_expression (parser).value;
4396 mark_exp_read (val);
4397 stmt = c_finish_goto_ptr (loc, val);
4400 c_parser_error (parser, "expected identifier or %<*%>");
4401 goto expect_semicolon;
4403 c_parser_consume_token (parser);
4404 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4405 goto expect_semicolon;
4407 c_parser_consume_token (parser);
4408 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4409 goto expect_semicolon;
4411 c_parser_consume_token (parser);
4412 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4414 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4415 c_parser_consume_token (parser);
4419 struct c_expr expr = c_parser_expression_conv (parser);
4420 mark_exp_read (expr.value);
4421 stmt = c_finish_return (loc, expr.value, expr.original_type);
4422 goto expect_semicolon;
4426 stmt = c_parser_asm_statement (parser);
4429 gcc_assert (c_dialect_objc ());
4430 c_parser_consume_token (parser);
4431 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4433 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4434 c_parser_consume_token (parser);
4438 tree expr = c_parser_expression (parser).value;
4439 expr = c_fully_fold (expr, false, NULL);
4440 stmt = objc_build_throw_stmt (loc, expr);
4441 goto expect_semicolon;
4445 gcc_assert (c_dialect_objc ());
4446 c_parser_objc_try_catch_finally_statement (parser);
4448 case RID_AT_SYNCHRONIZED:
4449 gcc_assert (c_dialect_objc ());
4450 c_parser_objc_synchronized_statement (parser);
4457 c_parser_consume_token (parser);
4459 case CPP_CLOSE_PAREN:
4460 case CPP_CLOSE_SQUARE:
4461 /* Avoid infinite loop in error recovery:
4462 c_parser_skip_until_found stops at a closing nesting
4463 delimiter without consuming it, but here we need to consume
4464 it to proceed further. */
4465 c_parser_error (parser, "expected statement");
4466 c_parser_consume_token (parser);
4469 c_parser_pragma (parser, pragma_stmt);
4473 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4475 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4478 /* Two cases cannot and do not have line numbers associated: If stmt
4479 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4480 cannot hold line numbers. But that's OK because the statement
4481 will either be changed to a MODIFY_EXPR during gimplification of
4482 the statement expr, or discarded. If stmt was compound, but
4483 without new variables, we will have skipped the creation of a
4484 BIND and will have a bare STATEMENT_LIST. But that's OK because
4485 (recursively) all of the component statements should already have
4486 line numbers assigned. ??? Can we discard no-op statements
4488 if (CAN_HAVE_LOCATION_P (stmt)
4489 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4490 SET_EXPR_LOCATION (stmt, loc);
4492 parser->in_if_block = in_if_block;
4495 /* Parse the condition from an if, do, while or for statements. */
4498 c_parser_condition (c_parser *parser)
4500 location_t loc = c_parser_peek_token (parser)->location;
4502 cond = c_parser_expression_conv (parser).value;
4503 cond = c_objc_common_truthvalue_conversion (loc, cond);
4504 cond = c_fully_fold (cond, false, NULL);
4505 if (warn_sequence_point)
4506 verify_sequence_points (cond);
4510 /* Parse a parenthesized condition from an if, do or while statement.
4516 c_parser_paren_condition (c_parser *parser)
4519 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4520 return error_mark_node;
4521 cond = c_parser_condition (parser);
4522 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4526 /* Parse a statement which is a block in C99. */
4529 c_parser_c99_block_statement (c_parser *parser)
4531 tree block = c_begin_compound_stmt (flag_isoc99);
4532 location_t loc = c_parser_peek_token (parser)->location;
4533 c_parser_statement (parser);
4534 return c_end_compound_stmt (loc, block, flag_isoc99);
4537 /* Parse the body of an if statement. This is just parsing a
4538 statement but (a) it is a block in C99, (b) we track whether the
4539 body is an if statement for the sake of -Wparentheses warnings, (c)
4540 we handle an empty body specially for the sake of -Wempty-body
4541 warnings, and (d) we call parser_compound_statement directly
4542 because c_parser_statement_after_labels resets
4543 parser->in_if_block. */
4546 c_parser_if_body (c_parser *parser, bool *if_p)
4548 tree block = c_begin_compound_stmt (flag_isoc99);
4549 location_t body_loc = c_parser_peek_token (parser)->location;
4550 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4551 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4552 || (c_parser_next_token_is (parser, CPP_NAME)
4553 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4554 c_parser_label (parser);
4555 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4556 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4558 location_t loc = c_parser_peek_token (parser)->location;
4559 add_stmt (build_empty_stmt (loc));
4560 c_parser_consume_token (parser);
4561 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4562 warning_at (loc, OPT_Wempty_body,
4563 "suggest braces around empty body in an %<if%> statement");
4565 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4566 add_stmt (c_parser_compound_statement (parser));
4568 c_parser_statement_after_labels (parser);
4569 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4572 /* Parse the else body of an if statement. This is just parsing a
4573 statement but (a) it is a block in C99, (b) we handle an empty body
4574 specially for the sake of -Wempty-body warnings. */
4577 c_parser_else_body (c_parser *parser)
4579 location_t else_loc = c_parser_peek_token (parser)->location;
4580 tree block = c_begin_compound_stmt (flag_isoc99);
4581 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4582 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4583 || (c_parser_next_token_is (parser, CPP_NAME)
4584 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4585 c_parser_label (parser);
4586 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4588 location_t loc = c_parser_peek_token (parser)->location;
4591 "suggest braces around empty body in an %<else%> statement");
4592 add_stmt (build_empty_stmt (loc));
4593 c_parser_consume_token (parser);
4596 c_parser_statement_after_labels (parser);
4597 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4600 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4603 if ( expression ) statement
4604 if ( expression ) statement else statement
4608 c_parser_if_statement (c_parser *parser)
4613 bool first_if = false;
4614 tree first_body, second_body;
4617 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4618 c_parser_consume_token (parser);
4619 block = c_begin_compound_stmt (flag_isoc99);
4620 loc = c_parser_peek_token (parser)->location;
4621 cond = c_parser_paren_condition (parser);
4622 in_if_block = parser->in_if_block;
4623 parser->in_if_block = true;
4624 first_body = c_parser_if_body (parser, &first_if);
4625 parser->in_if_block = in_if_block;
4626 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4628 c_parser_consume_token (parser);
4629 second_body = c_parser_else_body (parser);
4632 second_body = NULL_TREE;
4633 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4634 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4637 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4640 switch (expression) statement
4644 c_parser_switch_statement (c_parser *parser)
4646 tree block, expr, body, save_break;
4647 location_t switch_loc = c_parser_peek_token (parser)->location;
4648 location_t switch_cond_loc;
4649 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4650 c_parser_consume_token (parser);
4651 block = c_begin_compound_stmt (flag_isoc99);
4652 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4654 switch_cond_loc = c_parser_peek_token (parser)->location;
4655 expr = c_parser_expression (parser).value;
4656 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4660 switch_cond_loc = UNKNOWN_LOCATION;
4661 expr = error_mark_node;
4663 c_start_case (switch_loc, switch_cond_loc, expr);
4664 save_break = c_break_label;
4665 c_break_label = NULL_TREE;
4666 body = c_parser_c99_block_statement (parser);
4667 c_finish_case (body);
4670 location_t here = c_parser_peek_token (parser)->location;
4671 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4672 SET_EXPR_LOCATION (t, here);
4675 c_break_label = save_break;
4676 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4679 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4682 while (expression) statement
4686 c_parser_while_statement (c_parser *parser)
4688 tree block, cond, body, save_break, save_cont;
4690 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4691 c_parser_consume_token (parser);
4692 block = c_begin_compound_stmt (flag_isoc99);
4693 loc = c_parser_peek_token (parser)->location;
4694 cond = c_parser_paren_condition (parser);
4695 save_break = c_break_label;
4696 c_break_label = NULL_TREE;
4697 save_cont = c_cont_label;
4698 c_cont_label = NULL_TREE;
4699 body = c_parser_c99_block_statement (parser);
4700 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4701 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4702 c_break_label = save_break;
4703 c_cont_label = save_cont;
4706 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4709 do statement while ( expression ) ;
4713 c_parser_do_statement (c_parser *parser)
4715 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4717 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4718 c_parser_consume_token (parser);
4719 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4720 warning_at (c_parser_peek_token (parser)->location,
4722 "suggest braces around empty body in %<do%> statement");
4723 block = c_begin_compound_stmt (flag_isoc99);
4724 loc = c_parser_peek_token (parser)->location;
4725 save_break = c_break_label;
4726 c_break_label = NULL_TREE;
4727 save_cont = c_cont_label;
4728 c_cont_label = NULL_TREE;
4729 body = c_parser_c99_block_statement (parser);
4730 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4731 new_break = c_break_label;
4732 c_break_label = save_break;
4733 new_cont = c_cont_label;
4734 c_cont_label = save_cont;
4735 cond = c_parser_paren_condition (parser);
4736 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4737 c_parser_skip_to_end_of_block_or_statement (parser);
4738 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4739 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4742 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4745 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4746 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4748 The form with a declaration is new in C99.
4750 ??? In accordance with the old parser, the declaration may be a
4751 nested function, which is then rejected in check_for_loop_decls,
4752 but does it make any sense for this to be included in the grammar?
4753 Note in particular that the nested function does not include a
4754 trailing ';', whereas the "declaration" production includes one.
4755 Also, can we reject bad declarations earlier and cheaper than
4756 check_for_loop_decls?
4758 In Objective-C, there are two additional variants:
4761 for ( expression in expresssion ) statement
4762 for ( declaration in expression ) statement
4764 This is inconsistent with C, because the second variant is allowed
4765 even if c99 is not enabled.
4767 The rest of the comment documents these Objective-C foreach-statement.
4769 Here is the canonical example of the first variant:
4770 for (object in array) { do something with object }
4771 we call the first expression ("object") the "object_expression" and
4772 the second expression ("array") the "collection_expression".
4773 object_expression must be an lvalue of type "id" (a generic Objective-C
4774 object) because the loop works by assigning to object_expression the
4775 various objects from the collection_expression. collection_expression
4776 must evaluate to something of type "id" which responds to the method
4777 countByEnumeratingWithState:objects:count:.
4779 The canonical example of the second variant is:
4780 for (id object in array) { do something with object }
4781 which is completely equivalent to
4784 for (object in array) { do something with object }
4786 Note that initizializing 'object' in some way (eg, "for ((object =
4787 xxx) in array) { do something with object }") is possibly
4788 technically valid, but completely pointless as 'object' will be
4789 assigned to something else as soon as the loop starts. We should
4790 most likely reject it (TODO).
4792 The beginning of the Objective-C foreach-statement looks exactly
4793 like the beginning of the for-statement, and we can tell it is a
4794 foreach-statement only because the initial declaration or
4795 expression is terminated by 'in' instead of ';'.
4799 c_parser_for_statement (c_parser *parser)
4801 tree block, cond, incr, save_break, save_cont, body;
4802 /* The following are only used when parsing an ObjC foreach statement. */
4803 tree object_expression;
4804 /* Silence the bogus uninitialized warning. */
4805 tree collection_expression = NULL;
4806 location_t loc = c_parser_peek_token (parser)->location;
4807 location_t for_loc = c_parser_peek_token (parser)->location;
4808 bool is_foreach_statement = false;
4809 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4810 c_parser_consume_token (parser);
4811 /* Open a compound statement in Objective-C as well, just in case this is
4812 as foreach expression. */
4813 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4814 cond = error_mark_node;
4815 incr = error_mark_node;
4816 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4818 /* Parse the initialization declaration or expression. */
4819 object_expression = error_mark_node;
4820 parser->objc_could_be_foreach_context = c_dialect_objc ();
4821 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4823 parser->objc_could_be_foreach_context = false;
4824 c_parser_consume_token (parser);
4825 c_finish_expr_stmt (loc, NULL_TREE);
4827 else if (c_parser_next_tokens_start_declaration (parser))
4829 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4830 &object_expression);
4831 parser->objc_could_be_foreach_context = false;
4833 if (c_parser_next_token_is_keyword (parser, RID_IN))
4835 c_parser_consume_token (parser);
4836 is_foreach_statement = true;
4837 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4838 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4841 check_for_loop_decls (for_loc, flag_isoc99);
4843 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4845 /* __extension__ can start a declaration, but is also an
4846 unary operator that can start an expression. Consume all
4847 but the last of a possible series of __extension__ to
4849 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4850 && (c_parser_peek_2nd_token (parser)->keyword
4852 c_parser_consume_token (parser);
4853 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4856 ext = disable_extension_diagnostics ();
4857 c_parser_consume_token (parser);
4858 c_parser_declaration_or_fndef (parser, true, true, true, true,
4859 true, &object_expression);
4860 parser->objc_could_be_foreach_context = false;
4862 restore_extension_diagnostics (ext);
4863 if (c_parser_next_token_is_keyword (parser, RID_IN))
4865 c_parser_consume_token (parser);
4866 is_foreach_statement = true;
4867 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4868 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4871 check_for_loop_decls (for_loc, flag_isoc99);
4880 tree init_expression;
4881 init_expression = c_parser_expression (parser).value;
4882 parser->objc_could_be_foreach_context = false;
4883 if (c_parser_next_token_is_keyword (parser, RID_IN))
4885 c_parser_consume_token (parser);
4886 is_foreach_statement = true;
4887 if (! lvalue_p (init_expression))
4888 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4889 object_expression = c_fully_fold (init_expression, false, NULL);
4893 c_finish_expr_stmt (loc, init_expression);
4894 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4898 /* Parse the loop condition. In the case of a foreach
4899 statement, there is no loop condition. */
4900 gcc_assert (!parser->objc_could_be_foreach_context);
4901 if (!is_foreach_statement)
4903 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4905 c_parser_consume_token (parser);
4910 cond = c_parser_condition (parser);
4911 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4914 /* Parse the increment expression (the third expression in a
4915 for-statement). In the case of a foreach-statement, this is
4916 the expression that follows the 'in'. */
4917 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4919 if (is_foreach_statement)
4921 c_parser_error (parser, "missing collection in fast enumeration");
4922 collection_expression = error_mark_node;
4925 incr = c_process_expr_stmt (loc, NULL_TREE);
4929 if (is_foreach_statement)
4930 collection_expression = c_fully_fold (c_parser_expression (parser).value,
4933 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4935 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4937 save_break = c_break_label;
4938 c_break_label = NULL_TREE;
4939 save_cont = c_cont_label;
4940 c_cont_label = NULL_TREE;
4941 body = c_parser_c99_block_statement (parser);
4942 if (is_foreach_statement)
4943 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4945 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4946 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4947 c_break_label = save_break;
4948 c_cont_label = save_cont;
4951 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4952 statement with inputs, outputs, clobbers, and volatile tag
4956 asm type-qualifier[opt] ( asm-argument ) ;
4957 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4961 asm-string-literal : asm-operands[opt]
4962 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4963 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4966 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4969 Qualifiers other than volatile are accepted in the syntax but
4973 c_parser_asm_statement (c_parser *parser)
4975 tree quals, str, outputs, inputs, clobbers, labels, ret;
4976 bool simple, is_goto;
4977 location_t asm_loc = c_parser_peek_token (parser)->location;
4978 int section, nsections;
4980 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4981 c_parser_consume_token (parser);
4982 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4984 quals = c_parser_peek_token (parser)->value;
4985 c_parser_consume_token (parser);
4987 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4988 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4990 warning_at (c_parser_peek_token (parser)->location,
4992 "%E qualifier ignored on asm",
4993 c_parser_peek_token (parser)->value);
4995 c_parser_consume_token (parser);
5001 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5003 c_parser_consume_token (parser);
5007 /* ??? Follow the C++ parser rather than using the
5008 lex_untranslated_string kludge. */
5009 parser->lex_untranslated_string = true;
5012 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5015 str = c_parser_asm_string_literal (parser);
5016 if (str == NULL_TREE)
5017 goto error_close_paren;
5020 outputs = NULL_TREE;
5022 clobbers = NULL_TREE;
5025 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5028 /* Parse each colon-delimited section of operands. */
5029 nsections = 3 + is_goto;
5030 for (section = 0; section < nsections; ++section)
5032 if (!c_parser_require (parser, CPP_COLON,
5035 : "expected %<:%> or %<)%>"))
5036 goto error_close_paren;
5038 /* Once past any colon, we're no longer a simple asm. */
5041 if ((!c_parser_next_token_is (parser, CPP_COLON)
5042 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5047 /* For asm goto, we don't allow output operands, but reserve
5048 the slot for a future extension that does allow them. */
5050 outputs = c_parser_asm_operands (parser, false);
5053 inputs = c_parser_asm_operands (parser, true);
5056 clobbers = c_parser_asm_clobbers (parser);
5059 labels = c_parser_asm_goto_operands (parser);
5065 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5070 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5072 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5076 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5077 c_parser_skip_to_end_of_block_or_statement (parser);
5079 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5080 clobbers, labels, simple));
5083 parser->lex_untranslated_string = false;
5087 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5091 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5092 not outputs), apply the default conversion of functions and arrays
5097 asm-operands , asm-operand
5100 asm-string-literal ( expression )
5101 [ identifier ] asm-string-literal ( expression )
5105 c_parser_asm_operands (c_parser *parser, bool convert_p)
5107 tree list = NULL_TREE;
5113 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5115 c_parser_consume_token (parser);
5116 if (c_parser_next_token_is (parser, CPP_NAME))
5118 tree id = c_parser_peek_token (parser)->value;
5119 c_parser_consume_token (parser);
5120 name = build_string (IDENTIFIER_LENGTH (id),
5121 IDENTIFIER_POINTER (id));
5125 c_parser_error (parser, "expected identifier");
5126 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5129 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5134 str = c_parser_asm_string_literal (parser);
5135 if (str == NULL_TREE)
5137 parser->lex_untranslated_string = false;
5138 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5140 parser->lex_untranslated_string = true;
5143 loc = c_parser_peek_token (parser)->location;
5144 expr = c_parser_expression (parser);
5145 mark_exp_read (expr.value);
5147 expr = default_function_array_conversion (loc, expr);
5148 expr.value = c_fully_fold (expr.value, false, NULL);
5149 parser->lex_untranslated_string = true;
5150 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5152 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5155 list = chainon (list, build_tree_list (build_tree_list (name, str),
5157 if (c_parser_next_token_is (parser, CPP_COMMA))
5158 c_parser_consume_token (parser);
5165 /* Parse asm clobbers, a GNU extension.
5169 asm-clobbers , asm-string-literal
5173 c_parser_asm_clobbers (c_parser *parser)
5175 tree list = NULL_TREE;
5178 tree str = c_parser_asm_string_literal (parser);
5180 list = tree_cons (NULL_TREE, str, list);
5183 if (c_parser_next_token_is (parser, CPP_COMMA))
5184 c_parser_consume_token (parser);
5191 /* Parse asm goto labels, a GNU extension.
5195 asm-goto-operands , identifier
5199 c_parser_asm_goto_operands (c_parser *parser)
5201 tree list = NULL_TREE;
5206 if (c_parser_next_token_is (parser, CPP_NAME))
5208 c_token *tok = c_parser_peek_token (parser);
5210 label = lookup_label_for_goto (tok->location, name);
5211 c_parser_consume_token (parser);
5212 TREE_USED (label) = 1;
5216 c_parser_error (parser, "expected identifier");
5220 name = build_string (IDENTIFIER_LENGTH (name),
5221 IDENTIFIER_POINTER (name));
5222 list = tree_cons (name, label, list);
5223 if (c_parser_next_token_is (parser, CPP_COMMA))
5224 c_parser_consume_token (parser);
5226 return nreverse (list);
5230 /* Parse an expression other than a compound expression; that is, an
5231 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5232 NULL then it is an Objective-C message expression which is the
5233 primary-expression starting the expression as an initializer.
5235 assignment-expression:
5236 conditional-expression
5237 unary-expression assignment-operator assignment-expression
5239 assignment-operator: one of
5240 = *= /= %= += -= <<= >>= &= ^= |=
5242 In GNU C we accept any conditional expression on the LHS and
5243 diagnose the invalid lvalue rather than producing a syntax
5246 static struct c_expr
5247 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5249 struct c_expr lhs, rhs, ret;
5250 enum tree_code code;
5251 location_t op_location, exp_location;
5252 gcc_assert (!after || c_dialect_objc ());
5253 lhs = c_parser_conditional_expression (parser, after);
5254 op_location = c_parser_peek_token (parser)->location;
5255 switch (c_parser_peek_token (parser)->type)
5264 code = TRUNC_DIV_EXPR;
5267 code = TRUNC_MOD_EXPR;
5282 code = BIT_AND_EXPR;
5285 code = BIT_XOR_EXPR;
5288 code = BIT_IOR_EXPR;
5293 c_parser_consume_token (parser);
5294 exp_location = c_parser_peek_token (parser)->location;
5295 rhs = c_parser_expr_no_commas (parser, NULL);
5296 rhs = default_function_array_read_conversion (exp_location, rhs);
5297 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5298 code, exp_location, rhs.value,
5300 if (code == NOP_EXPR)
5301 ret.original_code = MODIFY_EXPR;
5304 TREE_NO_WARNING (ret.value) = 1;
5305 ret.original_code = ERROR_MARK;
5307 ret.original_type = NULL;
5311 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5312 is not NULL then it is an Objective-C message expression which is
5313 the primary-expression starting the expression as an initializer.
5315 conditional-expression:
5316 logical-OR-expression
5317 logical-OR-expression ? expression : conditional-expression
5321 conditional-expression:
5322 logical-OR-expression ? : conditional-expression
5325 static struct c_expr
5326 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5328 struct c_expr cond, exp1, exp2, ret;
5329 location_t cond_loc, colon_loc, middle_loc;
5331 gcc_assert (!after || c_dialect_objc ());
5333 cond = c_parser_binary_expression (parser, after, PREC_NONE);
5335 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5337 cond_loc = c_parser_peek_token (parser)->location;
5338 cond = default_function_array_read_conversion (cond_loc, cond);
5339 c_parser_consume_token (parser);
5340 if (c_parser_next_token_is (parser, CPP_COLON))
5342 tree eptype = NULL_TREE;
5344 middle_loc = c_parser_peek_token (parser)->location;
5345 pedwarn (middle_loc, OPT_pedantic,
5346 "ISO C forbids omitting the middle term of a ?: expression");
5347 warn_for_omitted_condop (middle_loc, cond.value);
5348 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5350 eptype = TREE_TYPE (cond.value);
5351 cond.value = TREE_OPERAND (cond.value, 0);
5353 /* Make sure first operand is calculated only once. */
5354 exp1.value = c_save_expr (default_conversion (cond.value));
5356 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5357 exp1.original_type = NULL;
5358 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5359 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5364 = c_objc_common_truthvalue_conversion
5365 (cond_loc, default_conversion (cond.value));
5366 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5367 exp1 = c_parser_expression_conv (parser);
5368 mark_exp_read (exp1.value);
5369 c_inhibit_evaluation_warnings +=
5370 ((cond.value == truthvalue_true_node)
5371 - (cond.value == truthvalue_false_node));
5374 colon_loc = c_parser_peek_token (parser)->location;
5375 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5377 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5378 ret.value = error_mark_node;
5379 ret.original_code = ERROR_MARK;
5380 ret.original_type = NULL;
5384 location_t exp2_loc = c_parser_peek_token (parser)->location;
5385 exp2 = c_parser_conditional_expression (parser, NULL);
5386 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5388 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5389 ret.value = build_conditional_expr (colon_loc, cond.value,
5390 cond.original_code == C_MAYBE_CONST_EXPR,
5391 exp1.value, exp1.original_type,
5392 exp2.value, exp2.original_type);
5393 ret.original_code = ERROR_MARK;
5394 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5395 ret.original_type = NULL;
5400 /* If both sides are enum type, the default conversion will have
5401 made the type of the result be an integer type. We want to
5402 remember the enum types we started with. */
5403 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5404 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5405 ret.original_type = ((t1 != error_mark_node
5406 && t2 != error_mark_node
5407 && (TYPE_MAIN_VARIANT (t1)
5408 == TYPE_MAIN_VARIANT (t2)))
5415 /* Parse a binary expression; that is, a logical-OR-expression (C90
5416 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5417 an Objective-C message expression which is the primary-expression
5418 starting the expression as an initializer. PREC is the starting
5419 precedence, usually PREC_NONE.
5421 multiplicative-expression:
5423 multiplicative-expression * cast-expression
5424 multiplicative-expression / cast-expression
5425 multiplicative-expression % cast-expression
5427 additive-expression:
5428 multiplicative-expression
5429 additive-expression + multiplicative-expression
5430 additive-expression - multiplicative-expression
5434 shift-expression << additive-expression
5435 shift-expression >> additive-expression
5437 relational-expression:
5439 relational-expression < shift-expression
5440 relational-expression > shift-expression
5441 relational-expression <= shift-expression
5442 relational-expression >= shift-expression
5444 equality-expression:
5445 relational-expression
5446 equality-expression == relational-expression
5447 equality-expression != relational-expression
5451 AND-expression & equality-expression
5453 exclusive-OR-expression:
5455 exclusive-OR-expression ^ AND-expression
5457 inclusive-OR-expression:
5458 exclusive-OR-expression
5459 inclusive-OR-expression | exclusive-OR-expression
5461 logical-AND-expression:
5462 inclusive-OR-expression
5463 logical-AND-expression && inclusive-OR-expression
5465 logical-OR-expression:
5466 logical-AND-expression
5467 logical-OR-expression || logical-AND-expression
5470 static struct c_expr
5471 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
5472 enum c_parser_prec prec)
5474 /* A binary expression is parsed using operator-precedence parsing,
5475 with the operands being cast expressions. All the binary
5476 operators are left-associative. Thus a binary expression is of
5479 E0 op1 E1 op2 E2 ...
5481 which we represent on a stack. On the stack, the precedence
5482 levels are strictly increasing. When a new operator is
5483 encountered of higher precedence than that at the top of the
5484 stack, it is pushed; its LHS is the top expression, and its RHS
5485 is everything parsed until it is popped. When a new operator is
5486 encountered with precedence less than or equal to that at the top
5487 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5488 by the result of the operation until the operator at the top of
5489 the stack has lower precedence than the new operator or there is
5490 only one element on the stack; then the top expression is the LHS
5491 of the new operator. In the case of logical AND and OR
5492 expressions, we also need to adjust c_inhibit_evaluation_warnings
5493 as appropriate when the operators are pushed and popped. */
5496 /* The expression at this stack level. */
5498 /* The precedence of the operator on its left, PREC_NONE at the
5499 bottom of the stack. */
5500 enum c_parser_prec prec;
5501 /* The operation on its left. */
5503 /* The source location of this operation. */
5507 /* Location of the binary operator. */
5508 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5511 switch (stack[sp].op) \
5513 case TRUTH_ANDIF_EXPR: \
5514 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5515 == truthvalue_false_node); \
5517 case TRUTH_ORIF_EXPR: \
5518 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5519 == truthvalue_true_node); \
5524 stack[sp - 1].expr \
5525 = default_function_array_read_conversion (stack[sp - 1].loc, \
5526 stack[sp - 1].expr); \
5528 = default_function_array_read_conversion (stack[sp].loc, \
5530 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5532 stack[sp - 1].expr, \
5536 gcc_assert (!after || c_dialect_objc ());
5537 stack[0].loc = c_parser_peek_token (parser)->location;
5538 stack[0].expr = c_parser_cast_expression (parser, after);
5539 stack[0].prec = prec;
5543 enum c_parser_prec oprec;
5544 enum tree_code ocode;
5547 switch (c_parser_peek_token (parser)->type)
5555 ocode = TRUNC_DIV_EXPR;
5559 ocode = TRUNC_MOD_EXPR;
5571 ocode = LSHIFT_EXPR;
5575 ocode = RSHIFT_EXPR;
5589 case CPP_GREATER_EQ:
5602 oprec = PREC_BITAND;
5603 ocode = BIT_AND_EXPR;
5606 oprec = PREC_BITXOR;
5607 ocode = BIT_XOR_EXPR;
5611 ocode = BIT_IOR_EXPR;
5614 oprec = PREC_LOGAND;
5615 ocode = TRUTH_ANDIF_EXPR;
5619 ocode = TRUTH_ORIF_EXPR;
5622 /* Not a binary operator, so end of the binary
5626 binary_loc = c_parser_peek_token (parser)->location;
5627 while (oprec <= stack[sp].prec)
5633 c_parser_consume_token (parser);
5636 case TRUTH_ANDIF_EXPR:
5638 = default_function_array_read_conversion (stack[sp].loc,
5640 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5641 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5642 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5643 == truthvalue_false_node);
5645 case TRUTH_ORIF_EXPR:
5647 = default_function_array_read_conversion (stack[sp].loc,
5649 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5650 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5651 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5652 == truthvalue_true_node);
5658 stack[sp].loc = binary_loc;
5659 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5660 stack[sp].prec = oprec;
5661 stack[sp].op = ocode;
5662 stack[sp].loc = binary_loc;
5667 return stack[0].expr;
5671 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5672 NULL then it is an Objective-C message expression which is the
5673 primary-expression starting the expression as an initializer.
5677 ( type-name ) unary-expression
5680 static struct c_expr
5681 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5683 location_t cast_loc = c_parser_peek_token (parser)->location;
5684 gcc_assert (!after || c_dialect_objc ());
5686 return c_parser_postfix_expression_after_primary (parser,
5688 /* If the expression begins with a parenthesized type name, it may
5689 be either a cast or a compound literal; we need to see whether
5690 the next character is '{' to tell the difference. If not, it is
5691 an unary expression. Full detection of unknown typenames here
5692 would require a 3-token lookahead. */
5693 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5694 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5696 struct c_type_name *type_name;
5699 c_parser_consume_token (parser);
5700 type_name = c_parser_type_name (parser);
5701 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5702 if (type_name == NULL)
5704 ret.value = error_mark_node;
5705 ret.original_code = ERROR_MARK;
5706 ret.original_type = NULL;
5710 /* Save casted types in the function's used types hash table. */
5711 used_types_insert (type_name->specs->type);
5713 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5714 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5717 location_t expr_loc = c_parser_peek_token (parser)->location;
5718 expr = c_parser_cast_expression (parser, NULL);
5719 expr = default_function_array_read_conversion (expr_loc, expr);
5721 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5722 ret.original_code = ERROR_MARK;
5723 ret.original_type = NULL;
5727 return c_parser_unary_expression (parser);
5730 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5736 unary-operator cast-expression
5737 sizeof unary-expression
5738 sizeof ( type-name )
5740 unary-operator: one of
5746 __alignof__ unary-expression
5747 __alignof__ ( type-name )
5750 unary-operator: one of
5751 __extension__ __real__ __imag__
5753 In addition, the GNU syntax treats ++ and -- as unary operators, so
5754 they may be applied to cast expressions with errors for non-lvalues
5757 static struct c_expr
5758 c_parser_unary_expression (c_parser *parser)
5761 struct c_expr ret, op;
5762 location_t op_loc = c_parser_peek_token (parser)->location;
5764 ret.original_code = ERROR_MARK;
5765 ret.original_type = NULL;
5766 switch (c_parser_peek_token (parser)->type)
5769 c_parser_consume_token (parser);
5770 exp_loc = c_parser_peek_token (parser)->location;
5771 op = c_parser_cast_expression (parser, NULL);
5772 op = default_function_array_read_conversion (exp_loc, op);
5773 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5774 case CPP_MINUS_MINUS:
5775 c_parser_consume_token (parser);
5776 exp_loc = c_parser_peek_token (parser)->location;
5777 op = c_parser_cast_expression (parser, NULL);
5778 op = default_function_array_read_conversion (exp_loc, op);
5779 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5781 c_parser_consume_token (parser);
5782 op = c_parser_cast_expression (parser, NULL);
5783 mark_exp_read (op.value);
5784 return parser_build_unary_op (op_loc, ADDR_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 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5793 if (!c_dialect_objc () && !in_system_header)
5796 "traditional C rejects the unary plus operator");
5797 c_parser_consume_token (parser);
5798 exp_loc = c_parser_peek_token (parser)->location;
5799 op = c_parser_cast_expression (parser, NULL);
5800 op = default_function_array_read_conversion (exp_loc, op);
5801 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5803 c_parser_consume_token (parser);
5804 exp_loc = c_parser_peek_token (parser)->location;
5805 op = c_parser_cast_expression (parser, NULL);
5806 op = default_function_array_read_conversion (exp_loc, op);
5807 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5809 c_parser_consume_token (parser);
5810 exp_loc = c_parser_peek_token (parser)->location;
5811 op = c_parser_cast_expression (parser, NULL);
5812 op = default_function_array_read_conversion (exp_loc, op);
5813 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5815 c_parser_consume_token (parser);
5816 exp_loc = c_parser_peek_token (parser)->location;
5817 op = c_parser_cast_expression (parser, NULL);
5818 op = default_function_array_read_conversion (exp_loc, op);
5819 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5821 /* Refer to the address of a label as a pointer. */
5822 c_parser_consume_token (parser);
5823 if (c_parser_next_token_is (parser, CPP_NAME))
5825 ret.value = finish_label_address_expr
5826 (c_parser_peek_token (parser)->value, op_loc);
5827 c_parser_consume_token (parser);
5831 c_parser_error (parser, "expected identifier");
5832 ret.value = error_mark_node;
5836 switch (c_parser_peek_token (parser)->keyword)
5839 return c_parser_sizeof_expression (parser);
5841 return c_parser_alignof_expression (parser);
5843 c_parser_consume_token (parser);
5844 ext = disable_extension_diagnostics ();
5845 ret = c_parser_cast_expression (parser, NULL);
5846 restore_extension_diagnostics (ext);
5849 c_parser_consume_token (parser);
5850 exp_loc = c_parser_peek_token (parser)->location;
5851 op = c_parser_cast_expression (parser, NULL);
5852 op = default_function_array_conversion (exp_loc, op);
5853 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5855 c_parser_consume_token (parser);
5856 exp_loc = c_parser_peek_token (parser)->location;
5857 op = c_parser_cast_expression (parser, NULL);
5858 op = default_function_array_conversion (exp_loc, op);
5859 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5861 return c_parser_postfix_expression (parser);
5864 return c_parser_postfix_expression (parser);
5868 /* Parse a sizeof expression. */
5870 static struct c_expr
5871 c_parser_sizeof_expression (c_parser *parser)
5874 location_t expr_loc;
5875 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5876 c_parser_consume_token (parser);
5877 c_inhibit_evaluation_warnings++;
5879 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5880 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5882 /* Either sizeof ( type-name ) or sizeof unary-expression
5883 starting with a compound literal. */
5884 struct c_type_name *type_name;
5885 c_parser_consume_token (parser);
5886 expr_loc = c_parser_peek_token (parser)->location;
5887 type_name = c_parser_type_name (parser);
5888 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5889 if (type_name == NULL)
5892 c_inhibit_evaluation_warnings--;
5894 ret.value = error_mark_node;
5895 ret.original_code = ERROR_MARK;
5896 ret.original_type = NULL;
5899 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5901 expr = c_parser_postfix_expression_after_paren_type (parser,
5906 /* sizeof ( type-name ). */
5907 c_inhibit_evaluation_warnings--;
5909 return c_expr_sizeof_type (expr_loc, type_name);
5913 expr_loc = c_parser_peek_token (parser)->location;
5914 expr = c_parser_unary_expression (parser);
5916 c_inhibit_evaluation_warnings--;
5918 mark_exp_read (expr.value);
5919 if (TREE_CODE (expr.value) == COMPONENT_REF
5920 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5921 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5922 return c_expr_sizeof_expr (expr_loc, expr);
5926 /* Parse an alignof expression. */
5928 static struct c_expr
5929 c_parser_alignof_expression (c_parser *parser)
5932 location_t loc = c_parser_peek_token (parser)->location;
5933 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5934 c_parser_consume_token (parser);
5935 c_inhibit_evaluation_warnings++;
5937 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5938 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5940 /* Either __alignof__ ( type-name ) or __alignof__
5941 unary-expression starting with a compound literal. */
5943 struct c_type_name *type_name;
5945 c_parser_consume_token (parser);
5946 loc = c_parser_peek_token (parser)->location;
5947 type_name = c_parser_type_name (parser);
5948 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5949 if (type_name == NULL)
5952 c_inhibit_evaluation_warnings--;
5954 ret.value = error_mark_node;
5955 ret.original_code = ERROR_MARK;
5956 ret.original_type = NULL;
5959 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5961 expr = c_parser_postfix_expression_after_paren_type (parser,
5966 /* alignof ( type-name ). */
5967 c_inhibit_evaluation_warnings--;
5969 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5970 ret.original_code = ERROR_MARK;
5971 ret.original_type = NULL;
5977 expr = c_parser_unary_expression (parser);
5979 mark_exp_read (expr.value);
5980 c_inhibit_evaluation_warnings--;
5982 ret.value = c_alignof_expr (loc, expr.value);
5983 ret.original_code = ERROR_MARK;
5984 ret.original_type = NULL;
5989 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5993 postfix-expression [ expression ]
5994 postfix-expression ( argument-expression-list[opt] )
5995 postfix-expression . identifier
5996 postfix-expression -> identifier
5997 postfix-expression ++
5998 postfix-expression --
5999 ( type-name ) { initializer-list }
6000 ( type-name ) { initializer-list , }
6002 argument-expression-list:
6004 argument-expression-list , argument-expression
6016 (treated as a keyword in GNU C)
6019 ( compound-statement )
6020 __builtin_va_arg ( assignment-expression , type-name )
6021 __builtin_offsetof ( type-name , offsetof-member-designator )
6022 __builtin_choose_expr ( assignment-expression ,
6023 assignment-expression ,
6024 assignment-expression )
6025 __builtin_types_compatible_p ( type-name , type-name )
6027 offsetof-member-designator:
6029 offsetof-member-designator . identifier
6030 offsetof-member-designator [ expression ]
6035 [ objc-receiver objc-message-args ]
6036 @selector ( objc-selector-arg )
6037 @protocol ( identifier )
6038 @encode ( type-name )
6040 Classname . identifier
6043 static struct c_expr
6044 c_parser_postfix_expression (c_parser *parser)
6046 struct c_expr expr, e1, e2, e3;
6047 struct c_type_name *t1, *t2;
6048 location_t loc = c_parser_peek_token (parser)->location;;
6049 expr.original_code = ERROR_MARK;
6050 expr.original_type = NULL;
6051 switch (c_parser_peek_token (parser)->type)
6054 expr.value = c_parser_peek_token (parser)->value;
6055 loc = c_parser_peek_token (parser)->location;
6056 c_parser_consume_token (parser);
6057 if (TREE_CODE (expr.value) == FIXED_CST
6058 && !targetm.fixed_point_supported_p ())
6060 error_at (loc, "fixed-point types not supported for this target");
6061 expr.value = error_mark_node;
6068 expr.value = c_parser_peek_token (parser)->value;
6069 c_parser_consume_token (parser);
6075 case CPP_UTF8STRING:
6076 expr.value = c_parser_peek_token (parser)->value;
6077 expr.original_code = STRING_CST;
6078 c_parser_consume_token (parser);
6080 case CPP_OBJC_STRING:
6081 gcc_assert (c_dialect_objc ());
6083 = objc_build_string_object (c_parser_peek_token (parser)->value);
6084 c_parser_consume_token (parser);
6087 switch (c_parser_peek_token (parser)->id_kind)
6091 tree id = c_parser_peek_token (parser)->value;
6092 c_parser_consume_token (parser);
6093 expr.value = build_external_ref (loc, id,
6094 (c_parser_peek_token (parser)->type
6096 &expr.original_type);
6099 case C_ID_CLASSNAME:
6101 /* Here we parse the Objective-C 2.0 Class.name dot
6103 tree class_name = c_parser_peek_token (parser)->value;
6105 c_parser_consume_token (parser);
6106 gcc_assert (c_dialect_objc ());
6107 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6109 expr.value = error_mark_node;
6112 if (c_parser_next_token_is_not (parser, CPP_NAME))
6114 c_parser_error (parser, "expected identifier");
6115 expr.value = error_mark_node;
6118 component = c_parser_peek_token (parser)->value;
6119 c_parser_consume_token (parser);
6120 expr.value = objc_build_class_component_ref (class_name,
6125 c_parser_error (parser, "expected expression");
6126 expr.value = error_mark_node;
6130 case CPP_OPEN_PAREN:
6131 /* A parenthesized expression, statement expression or compound
6133 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6135 /* A statement expression. */
6137 location_t brace_loc;
6138 c_parser_consume_token (parser);
6139 brace_loc = c_parser_peek_token (parser)->location;
6140 c_parser_consume_token (parser);
6141 if (!building_stmt_list_p ())
6143 error_at (loc, "braced-group within expression allowed "
6144 "only inside a function");
6145 parser->error = true;
6146 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6147 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6148 expr.value = error_mark_node;
6151 stmt = c_begin_stmt_expr ();
6152 c_parser_compound_statement_nostart (parser);
6153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6155 pedwarn (loc, OPT_pedantic,
6156 "ISO C forbids braced-groups within expressions");
6157 expr.value = c_finish_stmt_expr (brace_loc, stmt);
6158 mark_exp_read (expr.value);
6160 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6162 /* A compound literal. ??? Can we actually get here rather
6163 than going directly to
6164 c_parser_postfix_expression_after_paren_type from
6167 struct c_type_name *type_name;
6168 c_parser_consume_token (parser);
6169 loc = c_parser_peek_token (parser)->location;
6170 type_name = c_parser_type_name (parser);
6171 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6173 if (type_name == NULL)
6175 expr.value = error_mark_node;
6178 expr = c_parser_postfix_expression_after_paren_type (parser,
6184 /* A parenthesized expression. */
6185 c_parser_consume_token (parser);
6186 expr = c_parser_expression (parser);
6187 if (TREE_CODE (expr.value) == MODIFY_EXPR)
6188 TREE_NO_WARNING (expr.value) = 1;
6189 if (expr.original_code != C_MAYBE_CONST_EXPR)
6190 expr.original_code = ERROR_MARK;
6191 /* Don't change EXPR.ORIGINAL_TYPE. */
6192 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6197 switch (c_parser_peek_token (parser)->keyword)
6199 case RID_FUNCTION_NAME:
6200 case RID_PRETTY_FUNCTION_NAME:
6201 case RID_C99_FUNCTION_NAME:
6202 expr.value = fname_decl (loc,
6203 c_parser_peek_token (parser)->keyword,
6204 c_parser_peek_token (parser)->value);
6205 c_parser_consume_token (parser);
6208 c_parser_consume_token (parser);
6209 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6211 expr.value = error_mark_node;
6214 e1 = c_parser_expr_no_commas (parser, NULL);
6215 mark_exp_read (e1.value);
6216 e1.value = c_fully_fold (e1.value, false, NULL);
6217 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6219 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6220 expr.value = error_mark_node;
6223 loc = c_parser_peek_token (parser)->location;
6224 t1 = c_parser_type_name (parser);
6225 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6229 expr.value = error_mark_node;
6233 tree type_expr = NULL_TREE;
6234 expr.value = c_build_va_arg (loc, e1.value,
6235 groktypename (t1, &type_expr, NULL));
6238 expr.value = build2 (C_MAYBE_CONST_EXPR,
6239 TREE_TYPE (expr.value), type_expr,
6241 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6246 c_parser_consume_token (parser);
6247 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6249 expr.value = error_mark_node;
6252 t1 = c_parser_type_name (parser);
6254 parser->error = true;
6255 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6256 gcc_assert (parser->error);
6259 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6260 expr.value = error_mark_node;
6265 tree type = groktypename (t1, NULL, NULL);
6267 if (type == error_mark_node)
6268 offsetof_ref = error_mark_node;
6271 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6272 SET_EXPR_LOCATION (offsetof_ref, loc);
6274 /* Parse the second argument to __builtin_offsetof. We
6275 must have one identifier, and beyond that we want to
6276 accept sub structure and sub array references. */
6277 if (c_parser_next_token_is (parser, CPP_NAME))
6279 offsetof_ref = build_component_ref
6280 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6281 c_parser_consume_token (parser);
6282 while (c_parser_next_token_is (parser, CPP_DOT)
6283 || c_parser_next_token_is (parser,
6285 || c_parser_next_token_is (parser,
6288 if (c_parser_next_token_is (parser, CPP_DEREF))
6290 loc = c_parser_peek_token (parser)->location;
6291 offsetof_ref = build_array_ref (loc,
6296 else if (c_parser_next_token_is (parser, CPP_DOT))
6299 c_parser_consume_token (parser);
6300 if (c_parser_next_token_is_not (parser,
6303 c_parser_error (parser, "expected identifier");
6306 offsetof_ref = build_component_ref
6308 c_parser_peek_token (parser)->value);
6309 c_parser_consume_token (parser);
6314 loc = c_parser_peek_token (parser)->location;
6315 c_parser_consume_token (parser);
6316 idx = c_parser_expression (parser).value;
6317 idx = c_fully_fold (idx, false, NULL);
6318 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6320 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6325 c_parser_error (parser, "expected identifier");
6326 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6328 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6331 case RID_CHOOSE_EXPR:
6332 c_parser_consume_token (parser);
6333 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6335 expr.value = error_mark_node;
6338 loc = c_parser_peek_token (parser)->location;
6339 e1 = c_parser_expr_no_commas (parser, NULL);
6340 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6342 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6343 expr.value = error_mark_node;
6346 e2 = c_parser_expr_no_commas (parser, NULL);
6347 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6349 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6350 expr.value = error_mark_node;
6353 e3 = c_parser_expr_no_commas (parser, NULL);
6354 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6360 mark_exp_read (e2.value);
6361 mark_exp_read (e3.value);
6362 if (TREE_CODE (c) != INTEGER_CST
6363 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6365 "first argument to %<__builtin_choose_expr%> not"
6367 constant_expression_warning (c);
6368 expr = integer_zerop (c) ? e3 : e2;
6371 case RID_TYPES_COMPATIBLE_P:
6372 c_parser_consume_token (parser);
6373 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6375 expr.value = error_mark_node;
6378 t1 = c_parser_type_name (parser);
6381 expr.value = error_mark_node;
6384 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6386 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6387 expr.value = error_mark_node;
6390 t2 = c_parser_type_name (parser);
6393 expr.value = error_mark_node;
6396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6401 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6402 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6405 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6408 case RID_AT_SELECTOR:
6409 gcc_assert (c_dialect_objc ());
6410 c_parser_consume_token (parser);
6411 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6413 expr.value = error_mark_node;
6417 tree sel = c_parser_objc_selector_arg (parser);
6418 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6420 expr.value = objc_build_selector_expr (loc, sel);
6423 case RID_AT_PROTOCOL:
6424 gcc_assert (c_dialect_objc ());
6425 c_parser_consume_token (parser);
6426 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6428 expr.value = error_mark_node;
6431 if (c_parser_next_token_is_not (parser, CPP_NAME))
6433 c_parser_error (parser, "expected identifier");
6434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6435 expr.value = error_mark_node;
6439 tree id = c_parser_peek_token (parser)->value;
6440 c_parser_consume_token (parser);
6441 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6443 expr.value = objc_build_protocol_expr (id);
6447 /* Extension to support C-structures in the archiver. */
6448 gcc_assert (c_dialect_objc ());
6449 c_parser_consume_token (parser);
6450 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6452 expr.value = error_mark_node;
6455 t1 = c_parser_type_name (parser);
6458 expr.value = error_mark_node;
6459 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6462 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6465 tree type = groktypename (t1, NULL, NULL);
6466 expr.value = objc_build_encode_expr (type);
6470 c_parser_error (parser, "expected expression");
6471 expr.value = error_mark_node;
6475 case CPP_OPEN_SQUARE:
6476 if (c_dialect_objc ())
6478 tree receiver, args;
6479 c_parser_consume_token (parser);
6480 receiver = c_parser_objc_receiver (parser);
6481 args = c_parser_objc_message_args (parser);
6482 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6484 expr.value = objc_build_message_expr (receiver, args);
6487 /* Else fall through to report error. */
6489 c_parser_error (parser, "expected expression");
6490 expr.value = error_mark_node;
6493 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6496 /* Parse a postfix expression after a parenthesized type name: the
6497 brace-enclosed initializer of a compound literal, possibly followed
6498 by some postfix operators. This is separate because it is not
6499 possible to tell until after the type name whether a cast
6500 expression has a cast or a compound literal, or whether the operand
6501 of sizeof is a parenthesized type name or starts with a compound
6502 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6503 location of the first token after the parentheses around the type
6506 static struct c_expr
6507 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6508 struct c_type_name *type_name,
6509 location_t type_loc)
6515 location_t start_loc;
6516 tree type_expr = NULL_TREE;
6517 bool type_expr_const = true;
6518 check_compound_literal_type (type_loc, type_name);
6519 start_init (NULL_TREE, NULL, 0);
6520 type = groktypename (type_name, &type_expr, &type_expr_const);
6521 start_loc = c_parser_peek_token (parser)->location;
6522 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6524 error_at (type_loc, "compound literal has variable size");
6525 type = error_mark_node;
6527 init = c_parser_braced_init (parser, type, false);
6529 maybe_warn_string_init (type, init);
6531 if (type != error_mark_node
6532 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6533 && current_function_decl)
6535 error ("compound literal qualified by address-space qualifier");
6536 type = error_mark_node;
6540 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6541 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6542 ? CONSTRUCTOR_NON_CONST (init.value)
6543 : init.original_code == C_MAYBE_CONST_EXPR);
6544 non_const |= !type_expr_const;
6545 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6546 expr.original_code = ERROR_MARK;
6547 expr.original_type = NULL;
6550 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6552 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6553 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6557 gcc_assert (!non_const);
6558 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6559 type_expr, expr.value);
6562 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6565 /* Parse a postfix expression after the initial primary or compound
6566 literal; that is, parse a series of postfix operators.
6568 EXPR_LOC is the location of the primary expression. */
6570 static struct c_expr
6571 c_parser_postfix_expression_after_primary (c_parser *parser,
6572 location_t expr_loc,
6575 struct c_expr orig_expr;
6577 VEC(tree,gc) *exprlist;
6578 VEC(tree,gc) *origtypes;
6581 location_t op_loc = c_parser_peek_token (parser)->location;
6582 switch (c_parser_peek_token (parser)->type)
6584 case CPP_OPEN_SQUARE:
6585 /* Array reference. */
6586 c_parser_consume_token (parser);
6587 idx = c_parser_expression (parser).value;
6588 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6590 expr.value = build_array_ref (op_loc, expr.value, idx);
6591 expr.original_code = ERROR_MARK;
6592 expr.original_type = NULL;
6594 case CPP_OPEN_PAREN:
6595 /* Function call. */
6596 c_parser_consume_token (parser);
6597 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6600 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6601 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6604 mark_exp_read (expr.value);
6605 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6606 "(" after the FUNCNAME, which is what we have now. */
6607 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6609 expr.original_code = ERROR_MARK;
6610 if (TREE_CODE (expr.value) == INTEGER_CST
6611 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6612 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6613 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6614 expr.original_code = C_MAYBE_CONST_EXPR;
6615 expr.original_type = NULL;
6616 if (exprlist != NULL)
6618 release_tree_vector (exprlist);
6619 release_tree_vector (origtypes);
6623 /* Structure element reference. */
6624 c_parser_consume_token (parser);
6625 expr = default_function_array_conversion (expr_loc, expr);
6626 if (c_parser_next_token_is (parser, CPP_NAME))
6627 ident = c_parser_peek_token (parser)->value;
6630 c_parser_error (parser, "expected identifier");
6631 expr.value = error_mark_node;
6632 expr.original_code = ERROR_MARK;
6633 expr.original_type = NULL;
6636 c_parser_consume_token (parser);
6637 expr.value = build_component_ref (op_loc, expr.value, ident);
6638 expr.original_code = ERROR_MARK;
6639 if (TREE_CODE (expr.value) != COMPONENT_REF)
6640 expr.original_type = NULL;
6643 /* Remember the original type of a bitfield. */
6644 tree field = TREE_OPERAND (expr.value, 1);
6645 if (TREE_CODE (field) != FIELD_DECL)
6646 expr.original_type = NULL;
6648 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6652 /* Structure element reference. */
6653 c_parser_consume_token (parser);
6654 expr = default_function_array_conversion (expr_loc, expr);
6655 if (c_parser_next_token_is (parser, CPP_NAME))
6656 ident = c_parser_peek_token (parser)->value;
6659 c_parser_error (parser, "expected identifier");
6660 expr.value = error_mark_node;
6661 expr.original_code = ERROR_MARK;
6662 expr.original_type = NULL;
6665 c_parser_consume_token (parser);
6666 expr.value = build_component_ref (op_loc,
6667 build_indirect_ref (op_loc,
6671 expr.original_code = ERROR_MARK;
6672 if (TREE_CODE (expr.value) != COMPONENT_REF)
6673 expr.original_type = NULL;
6676 /* Remember the original type of a bitfield. */
6677 tree field = TREE_OPERAND (expr.value, 1);
6678 if (TREE_CODE (field) != FIELD_DECL)
6679 expr.original_type = NULL;
6681 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6685 /* Postincrement. */
6686 c_parser_consume_token (parser);
6687 expr = default_function_array_read_conversion (expr_loc, expr);
6688 expr.value = build_unary_op (op_loc,
6689 POSTINCREMENT_EXPR, expr.value, 0);
6690 expr.original_code = ERROR_MARK;
6691 expr.original_type = NULL;
6693 case CPP_MINUS_MINUS:
6694 /* Postdecrement. */
6695 c_parser_consume_token (parser);
6696 expr = default_function_array_read_conversion (expr_loc, expr);
6697 expr.value = build_unary_op (op_loc,
6698 POSTDECREMENT_EXPR, expr.value, 0);
6699 expr.original_code = ERROR_MARK;
6700 expr.original_type = NULL;
6708 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6711 assignment-expression
6712 expression , assignment-expression
6715 static struct c_expr
6716 c_parser_expression (c_parser *parser)
6719 expr = c_parser_expr_no_commas (parser, NULL);
6720 while (c_parser_next_token_is (parser, CPP_COMMA))
6724 location_t loc = c_parser_peek_token (parser)->location;
6725 location_t expr_loc;
6726 c_parser_consume_token (parser);
6727 expr_loc = c_parser_peek_token (parser)->location;
6728 lhsval = expr.value;
6729 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6730 lhsval = TREE_OPERAND (lhsval, 1);
6731 if (DECL_P (lhsval) || handled_component_p (lhsval))
6732 mark_exp_read (lhsval);
6733 next = c_parser_expr_no_commas (parser, NULL);
6734 next = default_function_array_conversion (expr_loc, next);
6735 expr.value = build_compound_expr (loc, expr.value, next.value);
6736 expr.original_code = COMPOUND_EXPR;
6737 expr.original_type = next.original_type;
6742 /* Parse an expression and convert functions or arrays to
6745 static struct c_expr
6746 c_parser_expression_conv (c_parser *parser)
6749 location_t loc = c_parser_peek_token (parser)->location;
6750 expr = c_parser_expression (parser);
6751 expr = default_function_array_conversion (loc, expr);
6755 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6756 functions and arrays to pointers. If FOLD_P, fold the expressions.
6759 assignment-expression
6760 nonempty-expr-list , assignment-expression
6763 static VEC(tree,gc) *
6764 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6765 VEC(tree,gc) **p_orig_types)
6768 VEC(tree,gc) *orig_types;
6770 location_t loc = c_parser_peek_token (parser)->location;
6772 ret = make_tree_vector ();
6773 if (p_orig_types == NULL)
6776 orig_types = make_tree_vector ();
6778 expr = c_parser_expr_no_commas (parser, NULL);
6780 expr = default_function_array_read_conversion (loc, expr);
6782 expr.value = c_fully_fold (expr.value, false, NULL);
6783 VEC_quick_push (tree, ret, expr.value);
6784 if (orig_types != NULL)
6785 VEC_quick_push (tree, orig_types, expr.original_type);
6786 while (c_parser_next_token_is (parser, CPP_COMMA))
6788 c_parser_consume_token (parser);
6789 loc = c_parser_peek_token (parser)->location;
6790 expr = c_parser_expr_no_commas (parser, NULL);
6792 expr = default_function_array_read_conversion (loc, expr);
6794 expr.value = c_fully_fold (expr.value, false, NULL);
6795 VEC_safe_push (tree, gc, ret, expr.value);
6796 if (orig_types != NULL)
6797 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6799 if (orig_types != NULL)
6800 *p_orig_types = orig_types;
6804 /* Parse Objective-C-specific constructs. */
6806 /* Parse an objc-class-definition.
6808 objc-class-definition:
6809 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6810 objc-class-instance-variables[opt] objc-methodprotolist @end
6811 @implementation identifier objc-superclass[opt]
6812 objc-class-instance-variables[opt]
6813 @interface identifier ( identifier ) objc-protocol-refs[opt]
6814 objc-methodprotolist @end
6815 @interface identifier ( ) objc-protocol-refs[opt]
6816 objc-methodprotolist @end
6817 @implementation identifier ( identifier )
6822 "@interface identifier (" must start "@interface identifier (
6823 identifier ) ...": objc-methodprotolist in the first production may
6824 not start with a parenthesized identifier as a declarator of a data
6825 definition with no declaration specifiers if the objc-superclass,
6826 objc-protocol-refs and objc-class-instance-variables are omitted. */
6829 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6834 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6836 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6841 c_parser_consume_token (parser);
6842 if (c_parser_next_token_is_not (parser, CPP_NAME))
6844 c_parser_error (parser, "expected identifier");
6847 id1 = c_parser_peek_token (parser)->value;
6848 c_parser_consume_token (parser);
6849 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6851 /* We have a category or class extension. */
6853 tree proto = NULL_TREE;
6854 c_parser_consume_token (parser);
6855 if (c_parser_next_token_is_not (parser, CPP_NAME))
6857 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6859 /* We have a class extension. */
6864 c_parser_error (parser, "expected identifier or %<)%>");
6865 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6871 id2 = c_parser_peek_token (parser)->value;
6872 c_parser_consume_token (parser);
6874 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6877 objc_start_category_implementation (id1, id2);
6880 if (c_parser_next_token_is (parser, CPP_LESS))
6881 proto = c_parser_objc_protocol_refs (parser);
6882 objc_start_category_interface (id1, id2, proto, attributes);
6883 c_parser_objc_methodprotolist (parser);
6884 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6885 objc_finish_interface ();
6888 if (c_parser_next_token_is (parser, CPP_COLON))
6890 c_parser_consume_token (parser);
6891 if (c_parser_next_token_is_not (parser, CPP_NAME))
6893 c_parser_error (parser, "expected identifier");
6896 superclass = c_parser_peek_token (parser)->value;
6897 c_parser_consume_token (parser);
6900 superclass = NULL_TREE;
6903 tree proto = NULL_TREE;
6904 if (c_parser_next_token_is (parser, CPP_LESS))
6905 proto = c_parser_objc_protocol_refs (parser);
6906 objc_start_class_interface (id1, superclass, proto, attributes);
6909 objc_start_class_implementation (id1, superclass);
6910 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6911 c_parser_objc_class_instance_variables (parser);
6914 objc_continue_interface ();
6915 c_parser_objc_methodprotolist (parser);
6916 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6917 objc_finish_interface ();
6921 objc_continue_implementation ();
6926 /* Parse objc-class-instance-variables.
6928 objc-class-instance-variables:
6929 { objc-instance-variable-decl-list[opt] }
6931 objc-instance-variable-decl-list:
6932 objc-visibility-spec
6933 objc-instance-variable-decl ;
6935 objc-instance-variable-decl-list objc-visibility-spec
6936 objc-instance-variable-decl-list objc-instance-variable-decl ;
6937 objc-instance-variable-decl-list ;
6939 objc-visibility-spec:
6944 objc-instance-variable-decl:
6949 c_parser_objc_class_instance_variables (c_parser *parser)
6951 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6952 c_parser_consume_token (parser);
6953 while (c_parser_next_token_is_not (parser, CPP_EOF))
6956 /* Parse any stray semicolon. */
6957 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6959 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6961 c_parser_consume_token (parser);
6964 /* Stop if at the end of the instance variables. */
6965 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6967 c_parser_consume_token (parser);
6970 /* Parse any objc-visibility-spec. */
6971 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6973 c_parser_consume_token (parser);
6974 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6977 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6979 c_parser_consume_token (parser);
6980 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6983 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6985 c_parser_consume_token (parser);
6986 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6989 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6991 c_parser_consume_token (parser);
6992 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6995 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6997 c_parser_pragma (parser, pragma_external);
7001 /* Parse some comma-separated declarations. */
7002 decls = c_parser_struct_declaration (parser);
7005 /* There is a syntax error. We want to skip the offending
7006 tokens up to the next ';' (included) or '}'
7009 /* First, skip manually a ')' or ']'. This is because they
7010 reduce the nesting level, so c_parser_skip_until_found()
7011 wouldn't be able to skip past them. */
7012 c_token *token = c_parser_peek_token (parser);
7013 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
7014 c_parser_consume_token (parser);
7016 /* Then, do the standard skipping. */
7017 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7019 /* We hopefully recovered. Start normal parsing again. */
7020 parser->error = false;
7025 /* Comma-separated instance variables are chained together
7026 in reverse order; add them one by one. */
7027 tree ivar = nreverse (decls);
7028 for (; ivar; ivar = DECL_CHAIN (ivar))
7029 objc_add_instance_variable (copy_node (ivar));
7031 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7035 /* Parse an objc-class-declaration.
7037 objc-class-declaration:
7038 @class identifier-list ;
7042 c_parser_objc_class_declaration (c_parser *parser)
7044 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
7045 c_parser_consume_token (parser);
7046 /* Any identifiers, including those declared as type names, are OK
7051 if (c_parser_next_token_is_not (parser, CPP_NAME))
7053 c_parser_error (parser, "expected identifier");
7054 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7055 parser->error = false;
7058 id = c_parser_peek_token (parser)->value;
7059 objc_declare_class (id);
7060 c_parser_consume_token (parser);
7061 if (c_parser_next_token_is (parser, CPP_COMMA))
7062 c_parser_consume_token (parser);
7066 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7069 /* Parse an objc-alias-declaration.
7071 objc-alias-declaration:
7072 @compatibility_alias identifier identifier ;
7076 c_parser_objc_alias_declaration (c_parser *parser)
7079 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7080 c_parser_consume_token (parser);
7081 if (c_parser_next_token_is_not (parser, CPP_NAME))
7083 c_parser_error (parser, "expected identifier");
7084 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7087 id1 = c_parser_peek_token (parser)->value;
7088 c_parser_consume_token (parser);
7089 if (c_parser_next_token_is_not (parser, CPP_NAME))
7091 c_parser_error (parser, "expected identifier");
7092 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7095 id2 = c_parser_peek_token (parser)->value;
7096 c_parser_consume_token (parser);
7097 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7098 objc_declare_alias (id1, id2);
7101 /* Parse an objc-protocol-definition.
7103 objc-protocol-definition:
7104 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7105 @protocol identifier-list ;
7107 "@protocol identifier ;" should be resolved as "@protocol
7108 identifier-list ;": objc-methodprotolist may not start with a
7109 semicolon in the first alternative if objc-protocol-refs are
7113 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7115 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7117 c_parser_consume_token (parser);
7118 if (c_parser_next_token_is_not (parser, CPP_NAME))
7120 c_parser_error (parser, "expected identifier");
7123 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7124 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7126 /* Any identifiers, including those declared as type names, are
7131 if (c_parser_next_token_is_not (parser, CPP_NAME))
7133 c_parser_error (parser, "expected identifier");
7136 id = c_parser_peek_token (parser)->value;
7137 objc_declare_protocol (id, attributes);
7138 c_parser_consume_token (parser);
7139 if (c_parser_next_token_is (parser, CPP_COMMA))
7140 c_parser_consume_token (parser);
7144 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7148 tree id = c_parser_peek_token (parser)->value;
7149 tree proto = NULL_TREE;
7150 c_parser_consume_token (parser);
7151 if (c_parser_next_token_is (parser, CPP_LESS))
7152 proto = c_parser_objc_protocol_refs (parser);
7153 parser->objc_pq_context = true;
7154 objc_start_protocol (id, proto, attributes);
7155 c_parser_objc_methodprotolist (parser);
7156 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7157 parser->objc_pq_context = false;
7158 objc_finish_interface ();
7162 /* Parse an objc-method-type.
7168 Return true if it is a class method (+) and false if it is
7169 an instance method (-).
7172 c_parser_objc_method_type (c_parser *parser)
7174 switch (c_parser_peek_token (parser)->type)
7177 c_parser_consume_token (parser);
7180 c_parser_consume_token (parser);
7187 /* Parse an objc-method-definition.
7189 objc-method-definition:
7190 objc-method-type objc-method-decl ;[opt] compound-statement
7194 c_parser_objc_method_definition (c_parser *parser)
7196 bool is_class_method = c_parser_objc_method_type (parser);
7197 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
7198 parser->objc_pq_context = true;
7199 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7201 if (decl == error_mark_node)
7202 return; /* Bail here. */
7204 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7206 c_parser_consume_token (parser);
7207 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7208 "extra semicolon in method definition specified");
7211 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7213 c_parser_error (parser, "expected %<{%>");
7217 parser->objc_pq_context = false;
7218 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
7220 add_stmt (c_parser_compound_statement (parser));
7221 objc_finish_method_definition (current_function_decl);
7225 /* This code is executed when we find a method definition
7226 outside of an @implementation context (or invalid for other
7227 reasons). Parse the method (to keep going) but do not emit
7230 c_parser_compound_statement (parser);
7234 /* Parse an objc-methodprotolist.
7236 objc-methodprotolist:
7238 objc-methodprotolist objc-methodproto
7239 objc-methodprotolist declaration
7240 objc-methodprotolist ;
7244 The declaration is a data definition, which may be missing
7245 declaration specifiers under the same rules and diagnostics as
7246 other data definitions outside functions, and the stray semicolon
7247 is diagnosed the same way as a stray semicolon outside a
7251 c_parser_objc_methodprotolist (c_parser *parser)
7255 /* The list is terminated by @end. */
7256 switch (c_parser_peek_token (parser)->type)
7259 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7260 "ISO C does not allow extra %<;%> outside of a function");
7261 c_parser_consume_token (parser);
7265 c_parser_objc_methodproto (parser);
7268 c_parser_pragma (parser, pragma_external);
7273 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7275 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7276 c_parser_objc_at_property_declaration (parser);
7277 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7279 objc_set_method_opt (true);
7280 c_parser_consume_token (parser);
7282 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7284 objc_set_method_opt (false);
7285 c_parser_consume_token (parser);
7288 c_parser_declaration_or_fndef (parser, false, false, true,
7295 /* Parse an objc-methodproto.
7298 objc-method-type objc-method-decl ;
7302 c_parser_objc_methodproto (c_parser *parser)
7304 bool is_class_method = c_parser_objc_method_type (parser);
7305 tree decl, attributes = NULL_TREE;
7307 /* Remember protocol qualifiers in prototypes. */
7308 parser->objc_pq_context = true;
7309 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7311 /* Forget protocol qualifiers now. */
7312 parser->objc_pq_context = false;
7314 /* Do not allow the presence of attributes to hide an erroneous
7315 method implementation in the interface section. */
7316 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7318 c_parser_error (parser, "expected %<;%>");
7322 if (decl != error_mark_node)
7323 objc_add_method_declaration (is_class_method, decl, attributes);
7325 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7328 /* If we are at a position that method attributes may be present, check that
7329 there are not any parsed already (a syntax error) and then collect any
7330 specified at the current location. Finally, if new attributes were present,
7331 check that the next token is legal ( ';' for decls and '{' for defs). */
7334 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7339 c_parser_error (parser,
7340 "method attributes must be specified at the end only");
7341 *attributes = NULL_TREE;
7345 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7346 *attributes = c_parser_attributes (parser);
7348 /* If there were no attributes here, just report any earlier error. */
7349 if (*attributes == NULL_TREE || bad)
7352 /* If the attributes are followed by a ; or {, then just report any earlier
7354 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7355 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7358 /* We've got attributes, but not at the end. */
7359 c_parser_error (parser,
7360 "expected %<;%> or %<{%> after method attribute definition");
7364 /* Parse an objc-method-decl.
7367 ( objc-type-name ) objc-selector
7369 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7370 objc-keyword-selector objc-optparmlist
7373 objc-keyword-selector:
7375 objc-keyword-selector objc-keyword-decl
7378 objc-selector : ( objc-type-name ) identifier
7379 objc-selector : identifier
7380 : ( objc-type-name ) identifier
7384 objc-optparms objc-optellipsis
7388 objc-opt-parms , parameter-declaration
7396 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
7397 tree *attributes, tree *expr)
7399 tree type = NULL_TREE;
7401 tree parms = NULL_TREE;
7402 bool ellipsis = false;
7403 bool attr_err = false;
7405 *attributes = NULL_TREE;
7406 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7408 c_parser_consume_token (parser);
7409 type = c_parser_objc_type_name (parser);
7410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7412 sel = c_parser_objc_selector (parser);
7413 /* If there is no selector, or a colon follows, we have an
7414 objc-keyword-selector. If there is a selector, and a colon does
7415 not follow, that selector ends the objc-method-decl. */
7416 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7419 tree list = NULL_TREE;
7422 tree atype = NULL_TREE, id, keyworddecl;
7423 tree param_attr = NULL_TREE;
7424 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7426 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7428 c_parser_consume_token (parser);
7429 atype = c_parser_objc_type_name (parser);
7430 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7433 /* New ObjC allows attributes on method parameters. */
7434 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7435 param_attr = c_parser_attributes (parser);
7436 if (c_parser_next_token_is_not (parser, CPP_NAME))
7438 c_parser_error (parser, "expected identifier");
7439 return error_mark_node;
7441 id = c_parser_peek_token (parser)->value;
7442 c_parser_consume_token (parser);
7443 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7444 list = chainon (list, keyworddecl);
7445 tsel = c_parser_objc_selector (parser);
7446 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7450 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7452 /* Parse the optional parameter list. Optional Objective-C
7453 method parameters follow the C syntax, and may include '...'
7454 to denote a variable number of arguments. */
7455 parms = make_node (TREE_LIST);
7456 while (c_parser_next_token_is (parser, CPP_COMMA))
7458 struct c_parm *parm;
7459 c_parser_consume_token (parser);
7460 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7463 c_parser_consume_token (parser);
7464 attr_err |= c_parser_objc_maybe_method_attributes
7465 (parser, attributes) ;
7468 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7471 parms = chainon (parms,
7472 build_tree_list (NULL_TREE, grokparm (parm, expr)));
7477 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7481 c_parser_error (parser, "objective-c method declaration is expected");
7482 return error_mark_node;
7486 return error_mark_node;
7488 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7491 /* Parse an objc-type-name.
7494 objc-type-qualifiers[opt] type-name
7495 objc-type-qualifiers[opt]
7497 objc-type-qualifiers:
7499 objc-type-qualifiers objc-type-qualifier
7501 objc-type-qualifier: one of
7502 in out inout bycopy byref oneway
7506 c_parser_objc_type_name (c_parser *parser)
7508 tree quals = NULL_TREE;
7509 struct c_type_name *type_name = NULL;
7510 tree type = NULL_TREE;
7513 c_token *token = c_parser_peek_token (parser);
7514 if (token->type == CPP_KEYWORD
7515 && (token->keyword == RID_IN
7516 || token->keyword == RID_OUT
7517 || token->keyword == RID_INOUT
7518 || token->keyword == RID_BYCOPY
7519 || token->keyword == RID_BYREF
7520 || token->keyword == RID_ONEWAY))
7522 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7523 c_parser_consume_token (parser);
7528 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7529 type_name = c_parser_type_name (parser);
7531 type = groktypename (type_name, NULL, NULL);
7533 /* If the type is unknown, and error has already been produced and
7534 we need to recover from the error. In that case, use NULL_TREE
7535 for the type, as if no type had been specified; this will use the
7536 default type ('id') which is good for error recovery. */
7537 if (type == error_mark_node)
7540 return build_tree_list (quals, type);
7543 /* Parse objc-protocol-refs.
7550 c_parser_objc_protocol_refs (c_parser *parser)
7552 tree list = NULL_TREE;
7553 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7554 c_parser_consume_token (parser);
7555 /* Any identifiers, including those declared as type names, are OK
7560 if (c_parser_next_token_is_not (parser, CPP_NAME))
7562 c_parser_error (parser, "expected identifier");
7565 id = c_parser_peek_token (parser)->value;
7566 list = chainon (list, build_tree_list (NULL_TREE, id));
7567 c_parser_consume_token (parser);
7568 if (c_parser_next_token_is (parser, CPP_COMMA))
7569 c_parser_consume_token (parser);
7573 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7577 /* Parse an objc-try-catch-finally-statement.
7579 objc-try-catch-finally-statement:
7580 @try compound-statement objc-catch-list[opt]
7581 @try compound-statement objc-catch-list[opt] @finally compound-statement
7584 @catch ( objc-catch-parameter-declaration ) compound-statement
7585 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7587 objc-catch-parameter-declaration:
7588 parameter-declaration
7591 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7593 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7594 for C++. Keep them in sync. */
7597 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7599 location_t location;
7602 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7603 c_parser_consume_token (parser);
7604 location = c_parser_peek_token (parser)->location;
7605 objc_maybe_warn_exceptions (location);
7606 stmt = c_parser_compound_statement (parser);
7607 objc_begin_try_stmt (location, stmt);
7609 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7611 struct c_parm *parm;
7612 tree parameter_declaration = error_mark_node;
7613 bool seen_open_paren = false;
7615 c_parser_consume_token (parser);
7616 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7617 seen_open_paren = true;
7618 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7620 /* We have "@catch (...)" (where the '...' are literally
7621 what is in the code). Skip the '...'.
7622 parameter_declaration is set to NULL_TREE, and
7623 objc_being_catch_clauses() knows that that means
7625 c_parser_consume_token (parser);
7626 parameter_declaration = NULL_TREE;
7630 /* We have "@catch (NSException *exception)" or something
7631 like that. Parse the parameter declaration. */
7632 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7634 parameter_declaration = error_mark_node;
7636 parameter_declaration = grokparm (parm, NULL);
7638 if (seen_open_paren)
7639 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7642 /* If there was no open parenthesis, we are recovering from
7643 an error, and we are trying to figure out what mistake
7644 the user has made. */
7646 /* If there is an immediate closing parenthesis, the user
7647 probably forgot the opening one (ie, they typed "@catch
7648 NSException *e)". Parse the closing parenthesis and keep
7650 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7651 c_parser_consume_token (parser);
7653 /* If these is no immediate closing parenthesis, the user
7654 probably doesn't know that parenthesis are required at
7655 all (ie, they typed "@catch NSException *e"). So, just
7656 forget about the closing parenthesis and keep going. */
7658 objc_begin_catch_clause (parameter_declaration);
7659 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7660 c_parser_compound_statement_nostart (parser);
7661 objc_finish_catch_clause ();
7663 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7665 c_parser_consume_token (parser);
7666 location = c_parser_peek_token (parser)->location;
7667 stmt = c_parser_compound_statement (parser);
7668 objc_build_finally_clause (location, stmt);
7670 objc_finish_try_stmt ();
7673 /* Parse an objc-synchronized-statement.
7675 objc-synchronized-statement:
7676 @synchronized ( expression ) compound-statement
7680 c_parser_objc_synchronized_statement (c_parser *parser)
7684 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7685 c_parser_consume_token (parser);
7686 loc = c_parser_peek_token (parser)->location;
7687 objc_maybe_warn_exceptions (loc);
7688 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7690 expr = c_parser_expression (parser).value;
7691 expr = c_fully_fold (expr, false, NULL);
7692 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7695 expr = error_mark_node;
7696 stmt = c_parser_compound_statement (parser);
7697 objc_build_synchronized (loc, expr, stmt);
7700 /* Parse an objc-selector; return NULL_TREE without an error if the
7701 next token is not an objc-selector.
7706 enum struct union if else while do for switch case default
7707 break continue return goto asm sizeof typeof __alignof
7708 unsigned long const short volatile signed restrict _Complex
7709 in out inout bycopy byref oneway int char float double void _Bool
7711 ??? Why this selection of keywords but not, for example, storage
7712 class specifiers? */
7715 c_parser_objc_selector (c_parser *parser)
7717 c_token *token = c_parser_peek_token (parser);
7718 tree value = token->value;
7719 if (token->type == CPP_NAME)
7721 c_parser_consume_token (parser);
7724 if (token->type != CPP_KEYWORD)
7726 switch (token->keyword)
7768 c_parser_consume_token (parser);
7775 /* Parse an objc-selector-arg.
7779 objc-keywordname-list
7781 objc-keywordname-list:
7783 objc-keywordname-list objc-keywordname
7791 c_parser_objc_selector_arg (c_parser *parser)
7793 tree sel = c_parser_objc_selector (parser);
7794 tree list = NULL_TREE;
7795 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7799 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7801 list = chainon (list, build_tree_list (sel, NULL_TREE));
7802 sel = c_parser_objc_selector (parser);
7803 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7809 /* Parse an objc-receiver.
7818 c_parser_objc_receiver (c_parser *parser)
7820 if (c_parser_peek_token (parser)->type == CPP_NAME
7821 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7822 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7824 tree id = c_parser_peek_token (parser)->value;
7825 c_parser_consume_token (parser);
7826 return objc_get_class_reference (id);
7828 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7831 /* Parse objc-message-args.
7835 objc-keywordarg-list
7837 objc-keywordarg-list:
7839 objc-keywordarg-list objc-keywordarg
7842 objc-selector : objc-keywordexpr
7847 c_parser_objc_message_args (c_parser *parser)
7849 tree sel = c_parser_objc_selector (parser);
7850 tree list = NULL_TREE;
7851 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7856 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7857 return error_mark_node;
7858 keywordexpr = c_parser_objc_keywordexpr (parser);
7859 list = chainon (list, build_tree_list (sel, keywordexpr));
7860 sel = c_parser_objc_selector (parser);
7861 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7867 /* Parse an objc-keywordexpr.
7874 c_parser_objc_keywordexpr (c_parser *parser)
7877 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7878 if (VEC_length (tree, expr_list) == 1)
7880 /* Just return the expression, remove a level of
7882 ret = VEC_index (tree, expr_list, 0);
7886 /* We have a comma expression, we will collapse later. */
7887 ret = build_tree_list_vec (expr_list);
7889 release_tree_vector (expr_list);
7893 /* A check, needed in several places, that ObjC interface, implementation or
7894 method definitions are not prefixed by incorrect items. */
7896 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7897 struct c_declspecs *specs)
7899 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
7900 || specs->typespec_kind != ctsk_none)
7902 c_parser_error (parser,
7903 "no type or storage class may be specified here,");
7904 c_parser_skip_to_end_of_block_or_statement (parser);
7910 /* Parse an Objective-C @property declaration. The syntax is:
7912 objc-property-declaration:
7913 '@property' objc-property-attributes[opt] struct-declaration ;
7915 objc-property-attributes:
7916 '(' objc-property-attribute-list ')'
7918 objc-property-attribute-list:
7919 objc-property-attribute
7920 objc-property-attribute-list, objc-property-attribute
7922 objc-property-attribute
7923 'getter' = identifier
7924 'setter' = identifier
7933 @property NSString *name;
7934 @property (readonly) id object;
7935 @property (retain, nonatomic, getter=getTheName) id name;
7936 @property int a, b, c;
7938 PS: This function is identical to cp_parser_objc_at_propery_declaration
7939 for C++. Keep them in sync. */
7941 c_parser_objc_at_property_declaration (c_parser *parser)
7943 /* The following variables hold the attributes of the properties as
7944 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
7945 seen. When we see an attribute, we set them to 'true' (if they
7946 are boolean properties) or to the identifier (if they have an
7947 argument, ie, for getter and setter). Note that here we only
7948 parse the list of attributes, check the syntax and accumulate the
7949 attributes that we find. objc_add_property_declaration() will
7950 then process the information. */
7951 bool property_assign = false;
7952 bool property_copy = false;
7953 tree property_getter_ident = NULL_TREE;
7954 bool property_nonatomic = false;
7955 bool property_readonly = false;
7956 bool property_readwrite = false;
7957 bool property_retain = false;
7958 tree property_setter_ident = NULL_TREE;
7960 /* 'properties' is the list of properties that we read. Usually a
7961 single one, but maybe more (eg, in "@property int a, b, c;" there
7966 loc = c_parser_peek_token (parser)->location;
7967 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
7969 c_parser_consume_token (parser); /* Eat '@property'. */
7971 /* Parse the optional attribute list... */
7972 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7975 c_parser_consume_token (parser);
7977 /* Property attribute keywords are valid now. */
7978 parser->objc_property_attr_context = true;
7982 bool syntax_error = false;
7983 c_token *token = c_parser_peek_token (parser);
7986 if (token->type != CPP_KEYWORD)
7988 if (token->type == CPP_CLOSE_PAREN)
7989 c_parser_error (parser, "expected identifier");
7992 c_parser_consume_token (parser);
7993 c_parser_error (parser, "unknown property attribute");
7997 keyword = token->keyword;
7998 c_parser_consume_token (parser);
8001 case RID_ASSIGN: property_assign = true; break;
8002 case RID_COPY: property_copy = true; break;
8003 case RID_NONATOMIC: property_nonatomic = true; break;
8004 case RID_READONLY: property_readonly = true; break;
8005 case RID_READWRITE: property_readwrite = true; break;
8006 case RID_RETAIN: property_retain = true; break;
8010 if (c_parser_next_token_is_not (parser, CPP_EQ))
8012 if (keyword == RID_GETTER)
8013 c_parser_error (parser,
8014 "missing %<=%> (after %<getter%> attribute)");
8016 c_parser_error (parser,
8017 "missing %<=%> (after %<setter%> attribute)");
8018 syntax_error = true;
8021 c_parser_consume_token (parser); /* eat the = */
8022 if (c_parser_next_token_is_not (parser, CPP_NAME))
8024 c_parser_error (parser, "expected identifier");
8025 syntax_error = true;
8028 if (keyword == RID_SETTER)
8030 if (property_setter_ident != NULL_TREE)
8031 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
8033 property_setter_ident = c_parser_peek_token (parser)->value;
8034 c_parser_consume_token (parser);
8035 if (c_parser_next_token_is_not (parser, CPP_COLON))
8036 c_parser_error (parser, "setter name must terminate with %<:%>");
8038 c_parser_consume_token (parser);
8042 if (property_getter_ident != NULL_TREE)
8043 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
8045 property_getter_ident = c_parser_peek_token (parser)->value;
8046 c_parser_consume_token (parser);
8050 c_parser_error (parser, "unknown property attribute");
8051 syntax_error = true;
8058 if (c_parser_next_token_is (parser, CPP_COMMA))
8059 c_parser_consume_token (parser);
8063 parser->objc_property_attr_context = false;
8064 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8066 /* ... and the property declaration(s). */
8067 properties = c_parser_struct_declaration (parser);
8069 if (properties == error_mark_node)
8071 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8072 parser->error = false;
8076 if (properties == NULL_TREE)
8077 c_parser_error (parser, "expected identifier");
8080 /* Comma-separated properties are chained together in
8081 reverse order; add them one by one. */
8082 properties = nreverse (properties);
8084 for (; properties; properties = TREE_CHAIN (properties))
8085 objc_add_property_declaration (loc, copy_node (properties),
8086 property_readonly, property_readwrite,
8087 property_assign, property_retain,
8088 property_copy, property_nonatomic,
8089 property_getter_ident, property_setter_ident);
8092 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8093 parser->error = false;
8096 /* Parse an Objective-C @synthesize declaration. The syntax is:
8098 objc-synthesize-declaration:
8099 @synthesize objc-synthesize-identifier-list ;
8101 objc-synthesize-identifier-list:
8102 objc-synthesize-identifier
8103 objc-synthesize-identifier-list, objc-synthesize-identifier
8105 objc-synthesize-identifier
8107 identifier = identifier
8110 @synthesize MyProperty;
8111 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8113 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8114 for C++. Keep them in sync.
8117 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8119 tree list = NULL_TREE;
8121 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8122 loc = c_parser_peek_token (parser)->location;
8124 c_parser_consume_token (parser);
8127 tree property, ivar;
8128 if (c_parser_next_token_is_not (parser, CPP_NAME))
8130 c_parser_error (parser, "expected identifier");
8131 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8132 /* Once we find the semicolon, we can resume normal parsing.
8133 We have to reset parser->error manually because
8134 c_parser_skip_until_found() won't reset it for us if the
8135 next token is precisely a semicolon. */
8136 parser->error = false;
8139 property = c_parser_peek_token (parser)->value;
8140 c_parser_consume_token (parser);
8141 if (c_parser_next_token_is (parser, CPP_EQ))
8143 c_parser_consume_token (parser);
8144 if (c_parser_next_token_is_not (parser, CPP_NAME))
8146 c_parser_error (parser, "expected identifier");
8147 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8148 parser->error = false;
8151 ivar = c_parser_peek_token (parser)->value;
8152 c_parser_consume_token (parser);
8156 list = chainon (list, build_tree_list (ivar, property));
8157 if (c_parser_next_token_is (parser, CPP_COMMA))
8158 c_parser_consume_token (parser);
8162 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8163 objc_add_synthesize_declaration (loc, list);
8166 /* Parse an Objective-C @dynamic declaration. The syntax is:
8168 objc-dynamic-declaration:
8169 @dynamic identifier-list ;
8172 @dynamic MyProperty;
8173 @dynamic MyProperty, AnotherProperty;
8175 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8176 for C++. Keep them in sync.
8179 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8181 tree list = NULL_TREE;
8183 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8184 loc = c_parser_peek_token (parser)->location;
8186 c_parser_consume_token (parser);
8190 if (c_parser_next_token_is_not (parser, CPP_NAME))
8192 c_parser_error (parser, "expected identifier");
8193 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8194 parser->error = false;
8197 property = c_parser_peek_token (parser)->value;
8198 list = chainon (list, build_tree_list (NULL_TREE, property));
8199 c_parser_consume_token (parser);
8200 if (c_parser_next_token_is (parser, CPP_COMMA))
8201 c_parser_consume_token (parser);
8205 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8206 objc_add_dynamic_declaration (loc, list);
8210 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8211 should be considered, statements. ALLOW_STMT is true if we're within
8212 the context of a function and such pragmas are to be allowed. Returns
8213 true if we actually parsed such a pragma. */
8216 c_parser_pragma (c_parser *parser, enum pragma_context context)
8220 id = c_parser_peek_token (parser)->pragma_kind;
8221 gcc_assert (id != PRAGMA_NONE);
8225 case PRAGMA_OMP_BARRIER:
8226 if (context != pragma_compound)
8228 if (context == pragma_stmt)
8229 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8230 "used in compound statements");
8233 c_parser_omp_barrier (parser);
8236 case PRAGMA_OMP_FLUSH:
8237 if (context != pragma_compound)
8239 if (context == pragma_stmt)
8240 c_parser_error (parser, "%<#pragma omp flush%> may only be "
8241 "used in compound statements");
8244 c_parser_omp_flush (parser);
8247 case PRAGMA_OMP_TASKWAIT:
8248 if (context != pragma_compound)
8250 if (context == pragma_stmt)
8251 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8252 "used in compound statements");
8255 c_parser_omp_taskwait (parser);
8258 case PRAGMA_OMP_TASKYIELD:
8259 if (context != pragma_compound)
8261 if (context == pragma_stmt)
8262 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
8263 "used in compound statements");
8266 c_parser_omp_taskyield (parser);
8269 case PRAGMA_OMP_THREADPRIVATE:
8270 c_parser_omp_threadprivate (parser);
8273 case PRAGMA_OMP_SECTION:
8274 error_at (c_parser_peek_token (parser)->location,
8275 "%<#pragma omp section%> may only be used in "
8276 "%<#pragma omp sections%> construct");
8277 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8280 case PRAGMA_GCC_PCH_PREPROCESS:
8281 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8282 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8286 if (id < PRAGMA_FIRST_EXTERNAL)
8288 if (context == pragma_external)
8291 c_parser_error (parser, "expected declaration specifiers");
8292 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8295 c_parser_omp_construct (parser);
8301 c_parser_consume_pragma (parser);
8302 c_invoke_pragma_handler (id);
8304 /* Skip to EOL, but suppress any error message. Those will have been
8305 generated by the handler routine through calling error, as opposed
8306 to calling c_parser_error. */
8307 parser->error = true;
8308 c_parser_skip_to_pragma_eol (parser);
8313 /* The interface the pragma parsers have to the lexer. */
8316 pragma_lex (tree *value)
8318 c_token *tok = c_parser_peek_token (the_parser);
8319 enum cpp_ttype ret = tok->type;
8321 *value = tok->value;
8322 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8326 if (ret == CPP_KEYWORD)
8328 c_parser_consume_token (the_parser);
8335 c_parser_pragma_pch_preprocess (c_parser *parser)
8339 c_parser_consume_pragma (parser);
8340 if (c_parser_next_token_is (parser, CPP_STRING))
8342 name = c_parser_peek_token (parser)->value;
8343 c_parser_consume_token (parser);
8346 c_parser_error (parser, "expected string literal");
8347 c_parser_skip_to_pragma_eol (parser);
8350 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8353 /* OpenMP 2.5 parsing routines. */
8355 /* Returns name of the next clause.
8356 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8357 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8358 returned and the token is consumed. */
8360 static pragma_omp_clause
8361 c_parser_omp_clause_name (c_parser *parser)
8363 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8365 if (c_parser_next_token_is_keyword (parser, RID_IF))
8366 result = PRAGMA_OMP_CLAUSE_IF;
8367 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8368 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8369 else if (c_parser_next_token_is (parser, CPP_NAME))
8371 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8376 if (!strcmp ("collapse", p))
8377 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8378 else if (!strcmp ("copyin", p))
8379 result = PRAGMA_OMP_CLAUSE_COPYIN;
8380 else if (!strcmp ("copyprivate", p))
8381 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8384 if (!strcmp ("final", p))
8385 result = PRAGMA_OMP_CLAUSE_FINAL;
8386 else if (!strcmp ("firstprivate", p))
8387 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8390 if (!strcmp ("lastprivate", p))
8391 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8394 if (!strcmp ("mergeable", p))
8395 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
8398 if (!strcmp ("nowait", p))
8399 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8400 else if (!strcmp ("num_threads", p))
8401 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8404 if (!strcmp ("ordered", p))
8405 result = PRAGMA_OMP_CLAUSE_ORDERED;
8408 if (!strcmp ("private", p))
8409 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8412 if (!strcmp ("reduction", p))
8413 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8416 if (!strcmp ("schedule", p))
8417 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8418 else if (!strcmp ("shared", p))
8419 result = PRAGMA_OMP_CLAUSE_SHARED;
8422 if (!strcmp ("untied", p))
8423 result = PRAGMA_OMP_CLAUSE_UNTIED;
8428 if (result != PRAGMA_OMP_CLAUSE_NONE)
8429 c_parser_consume_token (parser);
8434 /* Validate that a clause of the given type does not already exist. */
8437 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8442 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8443 if (OMP_CLAUSE_CODE (c) == code)
8445 location_t loc = OMP_CLAUSE_LOCATION (c);
8446 error_at (loc, "too many %qs clauses", name);
8454 variable-list , identifier
8456 If KIND is nonzero, create the appropriate node and install the
8457 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8458 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8460 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8461 return the list created. */
8464 c_parser_omp_variable_list (c_parser *parser,
8465 location_t clause_loc,
8466 enum omp_clause_code kind,
8469 if (c_parser_next_token_is_not (parser, CPP_NAME)
8470 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8471 c_parser_error (parser, "expected identifier");
8473 while (c_parser_next_token_is (parser, CPP_NAME)
8474 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8476 tree t = lookup_name (c_parser_peek_token (parser)->value);
8479 undeclared_variable (c_parser_peek_token (parser)->location,
8480 c_parser_peek_token (parser)->value);
8481 else if (t == error_mark_node)
8485 tree u = build_omp_clause (clause_loc, kind);
8486 OMP_CLAUSE_DECL (u) = t;
8487 OMP_CLAUSE_CHAIN (u) = list;
8491 list = tree_cons (t, NULL_TREE, list);
8493 c_parser_consume_token (parser);
8495 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8498 c_parser_consume_token (parser);
8504 /* Similarly, but expect leading and trailing parenthesis. This is a very
8505 common case for omp clauses. */
8508 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8511 /* The clauses location. */
8512 location_t loc = c_parser_peek_token (parser)->location;
8514 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8516 list = c_parser_omp_variable_list (parser, loc, kind, list);
8517 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8523 collapse ( constant-expression ) */
8526 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8528 tree c, num = error_mark_node;
8532 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8534 loc = c_parser_peek_token (parser)->location;
8535 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8537 num = c_parser_expr_no_commas (parser, NULL).value;
8538 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8540 if (num == error_mark_node)
8542 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8543 || !host_integerp (num, 0)
8544 || (n = tree_low_cst (num, 0)) <= 0
8548 "collapse argument needs positive constant integer expression");
8551 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8552 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8553 OMP_CLAUSE_CHAIN (c) = list;
8558 copyin ( variable-list ) */
8561 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8563 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8567 copyprivate ( variable-list ) */
8570 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8572 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8576 default ( shared | none ) */
8579 c_parser_omp_clause_default (c_parser *parser, tree list)
8581 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8582 location_t loc = c_parser_peek_token (parser)->location;
8585 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8587 if (c_parser_next_token_is (parser, CPP_NAME))
8589 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8594 if (strcmp ("none", p) != 0)
8596 kind = OMP_CLAUSE_DEFAULT_NONE;
8600 if (strcmp ("shared", p) != 0)
8602 kind = OMP_CLAUSE_DEFAULT_SHARED;
8609 c_parser_consume_token (parser);
8614 c_parser_error (parser, "expected %<none%> or %<shared%>");
8616 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8618 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8621 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8622 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8623 OMP_CLAUSE_CHAIN (c) = list;
8624 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8630 firstprivate ( variable-list ) */
8633 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8635 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8639 final ( expression ) */
8642 c_parser_omp_clause_final (c_parser *parser, tree list)
8644 location_t loc = c_parser_peek_token (parser)->location;
8645 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8647 tree t = c_parser_paren_condition (parser);
8650 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
8652 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
8653 OMP_CLAUSE_FINAL_EXPR (c) = t;
8654 OMP_CLAUSE_CHAIN (c) = list;
8658 c_parser_error (parser, "expected %<(%>");
8664 if ( expression ) */
8667 c_parser_omp_clause_if (c_parser *parser, tree list)
8669 location_t loc = c_parser_peek_token (parser)->location;
8670 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8672 tree t = c_parser_paren_condition (parser);
8675 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8677 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8678 OMP_CLAUSE_IF_EXPR (c) = t;
8679 OMP_CLAUSE_CHAIN (c) = list;
8683 c_parser_error (parser, "expected %<(%>");
8689 lastprivate ( variable-list ) */
8692 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8694 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8701 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8705 /* FIXME: Should we allow duplicates? */
8706 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
8708 c = build_omp_clause (c_parser_peek_token (parser)->location,
8709 OMP_CLAUSE_MERGEABLE);
8710 OMP_CLAUSE_CHAIN (c) = list;
8719 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8722 location_t loc = c_parser_peek_token (parser)->location;
8724 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8726 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8727 OMP_CLAUSE_CHAIN (c) = list;
8732 num_threads ( expression ) */
8735 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8737 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8738 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8740 location_t expr_loc = c_parser_peek_token (parser)->location;
8741 tree c, t = c_parser_expression (parser).value;
8742 t = c_fully_fold (t, false, NULL);
8744 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8746 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8748 c_parser_error (parser, "expected integer expression");
8752 /* Attempt to statically determine when the number isn't positive. */
8753 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8754 build_int_cst (TREE_TYPE (t), 0));
8755 if (CAN_HAVE_LOCATION_P (c))
8756 SET_EXPR_LOCATION (c, expr_loc);
8757 if (c == boolean_true_node)
8759 warning_at (expr_loc, 0,
8760 "%<num_threads%> value must be positive");
8761 t = integer_one_node;
8764 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8766 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8767 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8768 OMP_CLAUSE_CHAIN (c) = list;
8779 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8783 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8785 c = build_omp_clause (c_parser_peek_token (parser)->location,
8786 OMP_CLAUSE_ORDERED);
8787 OMP_CLAUSE_CHAIN (c) = list;
8793 private ( variable-list ) */
8796 c_parser_omp_clause_private (c_parser *parser, tree list)
8798 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8802 reduction ( reduction-operator : variable-list )
8805 One of: + * - & ^ | && ||
8810 One of: + * - & ^ | && || max min */
8813 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8815 location_t clause_loc = c_parser_peek_token (parser)->location;
8816 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8818 enum tree_code code;
8820 switch (c_parser_peek_token (parser)->type)
8832 code = BIT_AND_EXPR;
8835 code = BIT_XOR_EXPR;
8838 code = BIT_IOR_EXPR;
8841 code = TRUTH_ANDIF_EXPR;
8844 code = TRUTH_ORIF_EXPR;
8849 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8850 if (strcmp (p, "min") == 0)
8855 if (strcmp (p, "max") == 0)
8863 c_parser_error (parser,
8864 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8865 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
8866 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8869 c_parser_consume_token (parser);
8870 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8874 nl = c_parser_omp_variable_list (parser, clause_loc,
8875 OMP_CLAUSE_REDUCTION, list);
8876 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8877 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8881 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8887 schedule ( schedule-kind )
8888 schedule ( schedule-kind , expression )
8891 static | dynamic | guided | runtime | auto
8895 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8898 location_t loc = c_parser_peek_token (parser)->location;
8900 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8903 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8905 if (c_parser_next_token_is (parser, CPP_NAME))
8907 tree kind = c_parser_peek_token (parser)->value;
8908 const char *p = IDENTIFIER_POINTER (kind);
8913 if (strcmp ("dynamic", p) != 0)
8915 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8919 if (strcmp ("guided", p) != 0)
8921 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8925 if (strcmp ("runtime", p) != 0)
8927 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8934 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8935 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8936 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8937 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8941 c_parser_consume_token (parser);
8942 if (c_parser_next_token_is (parser, CPP_COMMA))
8945 c_parser_consume_token (parser);
8947 here = c_parser_peek_token (parser)->location;
8948 t = c_parser_expr_no_commas (parser, NULL).value;
8949 t = c_fully_fold (t, false, NULL);
8951 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8952 error_at (here, "schedule %<runtime%> does not take "
8953 "a %<chunk_size%> parameter");
8954 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8956 "schedule %<auto%> does not take "
8957 "a %<chunk_size%> parameter");
8958 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8959 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8961 c_parser_error (parser, "expected integer expression");
8963 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8966 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8967 "expected %<,%> or %<)%>");
8969 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8970 OMP_CLAUSE_CHAIN (c) = list;
8974 c_parser_error (parser, "invalid schedule kind");
8975 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8980 shared ( variable-list ) */
8983 c_parser_omp_clause_shared (c_parser *parser, tree list)
8985 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8992 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8996 /* FIXME: Should we allow duplicates? */
8997 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8999 c = build_omp_clause (c_parser_peek_token (parser)->location,
9001 OMP_CLAUSE_CHAIN (c) = list;
9006 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9007 is a bitmask in MASK. Return the list of clauses found; the result
9008 of clause default goes in *pdefault. */
9011 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
9014 tree clauses = NULL;
9017 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9020 pragma_omp_clause c_kind;
9022 tree prev = clauses;
9024 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
9025 c_parser_consume_token (parser);
9028 here = c_parser_peek_token (parser)->location;
9029 c_kind = c_parser_omp_clause_name (parser);
9033 case PRAGMA_OMP_CLAUSE_COLLAPSE:
9034 clauses = c_parser_omp_clause_collapse (parser, clauses);
9035 c_name = "collapse";
9037 case PRAGMA_OMP_CLAUSE_COPYIN:
9038 clauses = c_parser_omp_clause_copyin (parser, clauses);
9041 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
9042 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
9043 c_name = "copyprivate";
9045 case PRAGMA_OMP_CLAUSE_DEFAULT:
9046 clauses = c_parser_omp_clause_default (parser, clauses);
9049 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
9050 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
9051 c_name = "firstprivate";
9053 case PRAGMA_OMP_CLAUSE_FINAL:
9054 clauses = c_parser_omp_clause_final (parser, clauses);
9057 case PRAGMA_OMP_CLAUSE_IF:
9058 clauses = c_parser_omp_clause_if (parser, clauses);
9061 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
9062 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
9063 c_name = "lastprivate";
9065 case PRAGMA_OMP_CLAUSE_MERGEABLE:
9066 clauses = c_parser_omp_clause_mergeable (parser, clauses);
9067 c_name = "mergeable";
9069 case PRAGMA_OMP_CLAUSE_NOWAIT:
9070 clauses = c_parser_omp_clause_nowait (parser, clauses);
9073 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
9074 clauses = c_parser_omp_clause_num_threads (parser, clauses);
9075 c_name = "num_threads";
9077 case PRAGMA_OMP_CLAUSE_ORDERED:
9078 clauses = c_parser_omp_clause_ordered (parser, clauses);
9081 case PRAGMA_OMP_CLAUSE_PRIVATE:
9082 clauses = c_parser_omp_clause_private (parser, clauses);
9085 case PRAGMA_OMP_CLAUSE_REDUCTION:
9086 clauses = c_parser_omp_clause_reduction (parser, clauses);
9087 c_name = "reduction";
9089 case PRAGMA_OMP_CLAUSE_SCHEDULE:
9090 clauses = c_parser_omp_clause_schedule (parser, clauses);
9091 c_name = "schedule";
9093 case PRAGMA_OMP_CLAUSE_SHARED:
9094 clauses = c_parser_omp_clause_shared (parser, clauses);
9097 case PRAGMA_OMP_CLAUSE_UNTIED:
9098 clauses = c_parser_omp_clause_untied (parser, clauses);
9102 c_parser_error (parser, "expected %<#pragma omp%> clause");
9106 if (((mask >> c_kind) & 1) == 0 && !parser->error)
9108 /* Remove the invalid clause(s) from the list to avoid
9109 confusing the rest of the compiler. */
9111 error_at (here, "%qs is not valid for %qs", c_name, where);
9116 c_parser_skip_to_pragma_eol (parser);
9118 return c_finish_omp_clauses (clauses);
9125 In practice, we're also interested in adding the statement to an
9126 outer node. So it is convenient if we work around the fact that
9127 c_parser_statement calls add_stmt. */
9130 c_parser_omp_structured_block (c_parser *parser)
9132 tree stmt = push_stmt_list ();
9133 c_parser_statement (parser);
9134 return pop_stmt_list (stmt);
9138 # pragma omp atomic new-line
9142 x binop= expr | x++ | ++x | x-- | --x
9144 +, *, -, /, &, ^, |, <<, >>
9146 where x is an lvalue expression with scalar type.
9149 # pragma omp atomic new-line
9152 # pragma omp atomic read new-line
9155 # pragma omp atomic write new-line
9158 # pragma omp atomic update new-line
9161 # pragma omp atomic capture new-line
9164 # pragma omp atomic capture new-line
9172 expression-stmt | x = x binop expr
9174 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9176 { v = x; update-stmt; } | { update-stmt; v = x; }
9178 where x and v are lvalue expressions with scalar type.
9180 LOC is the location of the #pragma token. */
9183 c_parser_omp_atomic (location_t loc, c_parser *parser)
9185 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
9186 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
9187 tree stmt, orig_lhs;
9188 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
9189 struct c_expr rhs_expr;
9190 bool structured_block = false;
9192 if (c_parser_next_token_is (parser, CPP_NAME))
9194 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9196 if (!strcmp (p, "read"))
9197 code = OMP_ATOMIC_READ;
9198 else if (!strcmp (p, "write"))
9200 else if (!strcmp (p, "update"))
9202 else if (!strcmp (p, "capture"))
9203 code = OMP_ATOMIC_CAPTURE_NEW;
9207 c_parser_consume_token (parser);
9209 c_parser_skip_to_pragma_eol (parser);
9213 case OMP_ATOMIC_READ:
9214 case NOP_EXPR: /* atomic write */
9215 v = c_parser_unary_expression (parser).value;
9216 v = c_fully_fold (v, false, NULL);
9217 if (v == error_mark_node)
9219 loc = c_parser_peek_token (parser)->location;
9220 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9222 if (code == NOP_EXPR)
9223 lhs = c_parser_expression (parser).value;
9225 lhs = c_parser_unary_expression (parser).value;
9226 lhs = c_fully_fold (lhs, false, NULL);
9227 if (lhs == error_mark_node)
9229 if (code == NOP_EXPR)
9231 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9239 case OMP_ATOMIC_CAPTURE_NEW:
9240 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9242 c_parser_consume_token (parser);
9243 structured_block = true;
9247 v = c_parser_unary_expression (parser).value;
9248 v = c_fully_fold (v, false, NULL);
9249 if (v == error_mark_node)
9251 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9259 /* For structured_block case we don't know yet whether
9260 old or new x should be captured. */
9262 lhs = c_parser_unary_expression (parser).value;
9263 lhs = c_fully_fold (lhs, false, NULL);
9265 switch (TREE_CODE (lhs))
9269 c_parser_skip_to_end_of_block_or_statement (parser);
9270 if (structured_block)
9272 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9273 c_parser_consume_token (parser);
9274 else if (code == OMP_ATOMIC_CAPTURE_NEW)
9276 c_parser_skip_to_end_of_block_or_statement (parser);
9277 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9278 c_parser_consume_token (parser);
9283 case POSTINCREMENT_EXPR:
9284 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9285 code = OMP_ATOMIC_CAPTURE_OLD;
9287 case PREINCREMENT_EXPR:
9288 lhs = TREE_OPERAND (lhs, 0);
9290 rhs = integer_one_node;
9293 case POSTDECREMENT_EXPR:
9294 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9295 code = OMP_ATOMIC_CAPTURE_OLD;
9297 case PREDECREMENT_EXPR:
9298 lhs = TREE_OPERAND (lhs, 0);
9299 opcode = MINUS_EXPR;
9300 rhs = integer_one_node;
9304 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9305 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9306 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9307 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9308 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9309 (TREE_OPERAND (lhs, 1), 0), 0)))
9311 /* Undo effects of boolean_increment for post {in,de}crement. */
9312 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9315 if (TREE_CODE (lhs) == MODIFY_EXPR
9316 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9318 /* Undo effects of boolean_increment. */
9319 if (integer_onep (TREE_OPERAND (lhs, 1)))
9321 /* This is pre or post increment. */
9322 rhs = TREE_OPERAND (lhs, 1);
9323 lhs = TREE_OPERAND (lhs, 0);
9325 if (code == OMP_ATOMIC_CAPTURE_NEW
9326 && !structured_block
9327 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9328 code = OMP_ATOMIC_CAPTURE_OLD;
9331 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9332 && TREE_OPERAND (lhs, 0)
9333 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9335 /* This is pre or post decrement. */
9336 rhs = TREE_OPERAND (lhs, 1);
9337 lhs = TREE_OPERAND (lhs, 0);
9339 if (code == OMP_ATOMIC_CAPTURE_NEW
9340 && !structured_block
9341 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9342 code = OMP_ATOMIC_CAPTURE_OLD;
9348 switch (c_parser_peek_token (parser)->type)
9354 opcode = TRUNC_DIV_EXPR;
9360 opcode = MINUS_EXPR;
9363 opcode = LSHIFT_EXPR;
9366 opcode = RSHIFT_EXPR;
9369 opcode = BIT_AND_EXPR;
9372 opcode = BIT_IOR_EXPR;
9375 opcode = BIT_XOR_EXPR;
9378 if (structured_block || code == OMP_ATOMIC)
9380 location_t aloc = c_parser_peek_token (parser)->location;
9382 enum c_parser_prec oprec = PREC_NONE;
9384 c_parser_consume_token (parser);
9385 rhs1 = c_parser_unary_expression (parser).value;
9386 rhs1 = c_fully_fold (rhs1, false, NULL);
9387 if (rhs1 == error_mark_node)
9389 switch (c_parser_peek_token (parser)->type)
9392 if (code == OMP_ATOMIC_CAPTURE_NEW)
9394 code = OMP_ATOMIC_CAPTURE_OLD;
9399 c_parser_consume_token (parser);
9402 c_parser_error (parser,
9403 "invalid form of %<#pragma omp atomic%>");
9410 opcode = TRUNC_DIV_EXPR;
9418 opcode = MINUS_EXPR;
9422 opcode = LSHIFT_EXPR;
9426 opcode = RSHIFT_EXPR;
9430 opcode = BIT_AND_EXPR;
9431 oprec = PREC_BITAND;
9434 opcode = BIT_IOR_EXPR;
9438 opcode = BIT_XOR_EXPR;
9439 oprec = PREC_BITXOR;
9442 c_parser_error (parser,
9443 "invalid operator for %<#pragma omp atomic%>");
9447 c_parser_consume_token (parser);
9448 rhs_loc = c_parser_peek_token (parser)->location;
9449 if (commutative_tree_code (opcode))
9450 oprec = (enum c_parser_prec) (oprec - 1);
9451 rhs_expr = c_parser_binary_expression (parser, NULL, oprec);
9452 rhs_expr = default_function_array_read_conversion (rhs_loc,
9454 rhs = rhs_expr.value;
9455 rhs = c_fully_fold (rhs, false, NULL);
9460 c_parser_error (parser,
9461 "invalid operator for %<#pragma omp atomic%>");
9465 /* Arrange to pass the location of the assignment operator to
9466 c_finish_omp_atomic. */
9467 loc = c_parser_peek_token (parser)->location;
9468 c_parser_consume_token (parser);
9470 location_t rhs_loc = c_parser_peek_token (parser)->location;
9471 rhs_expr = c_parser_expression (parser);
9472 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9474 rhs = rhs_expr.value;
9475 rhs = c_fully_fold (rhs, false, NULL);
9479 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
9481 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
9483 v = c_parser_unary_expression (parser).value;
9484 v = c_fully_fold (v, false, NULL);
9485 if (v == error_mark_node)
9487 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9489 lhs1 = c_parser_unary_expression (parser).value;
9490 lhs1 = c_fully_fold (lhs1, false, NULL);
9491 if (lhs1 == error_mark_node)
9494 if (structured_block)
9496 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9497 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
9500 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1);
9501 if (stmt != error_mark_node)
9504 if (!structured_block)
9505 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9510 # pragma omp barrier new-line
9514 c_parser_omp_barrier (c_parser *parser)
9516 location_t loc = c_parser_peek_token (parser)->location;
9517 c_parser_consume_pragma (parser);
9518 c_parser_skip_to_pragma_eol (parser);
9520 c_finish_omp_barrier (loc);
9524 # pragma omp critical [(name)] new-line
9527 LOC is the location of the #pragma itself. */
9530 c_parser_omp_critical (location_t loc, c_parser *parser)
9532 tree stmt, name = NULL;
9534 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9536 c_parser_consume_token (parser);
9537 if (c_parser_next_token_is (parser, CPP_NAME))
9539 name = c_parser_peek_token (parser)->value;
9540 c_parser_consume_token (parser);
9541 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9544 c_parser_error (parser, "expected identifier");
9546 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9547 c_parser_error (parser, "expected %<(%> or end of line");
9548 c_parser_skip_to_pragma_eol (parser);
9550 stmt = c_parser_omp_structured_block (parser);
9551 return c_finish_omp_critical (loc, stmt, name);
9555 # pragma omp flush flush-vars[opt] new-line
9558 ( variable-list ) */
9561 c_parser_omp_flush (c_parser *parser)
9563 location_t loc = c_parser_peek_token (parser)->location;
9564 c_parser_consume_pragma (parser);
9565 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9566 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9567 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9568 c_parser_error (parser, "expected %<(%> or end of line");
9569 c_parser_skip_to_pragma_eol (parser);
9571 c_finish_omp_flush (loc);
9574 /* Parse the restricted form of the for statement allowed by OpenMP.
9575 The real trick here is to determine the loop control variable early
9576 so that we can push a new decl if necessary to make it private.
9577 LOC is the location of the OMP in "#pragma omp". */
9580 c_parser_omp_for_loop (location_t loc,
9581 c_parser *parser, tree clauses, tree *par_clauses)
9583 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9584 tree declv, condv, incrv, initv, ret = NULL;
9585 bool fail = false, open_brace_parsed = false;
9586 int i, collapse = 1, nbraces = 0;
9588 VEC(tree,gc) *for_block = make_tree_vector ();
9590 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9591 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9592 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9594 gcc_assert (collapse >= 1);
9596 declv = make_tree_vec (collapse);
9597 initv = make_tree_vec (collapse);
9598 condv = make_tree_vec (collapse);
9599 incrv = make_tree_vec (collapse);
9601 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9603 c_parser_error (parser, "for statement expected");
9606 for_loc = c_parser_peek_token (parser)->location;
9607 c_parser_consume_token (parser);
9609 for (i = 0; i < collapse; i++)
9613 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9616 /* Parse the initialization declaration or expression. */
9617 if (c_parser_next_tokens_start_declaration (parser))
9620 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9621 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9622 decl = check_for_loop_decls (for_loc, flag_isoc99);
9625 if (DECL_INITIAL (decl) == error_mark_node)
9626 decl = error_mark_node;
9629 else if (c_parser_next_token_is (parser, CPP_NAME)
9630 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9632 struct c_expr decl_exp;
9633 struct c_expr init_exp;
9634 location_t init_loc;
9636 decl_exp = c_parser_postfix_expression (parser);
9637 decl = decl_exp.value;
9639 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9641 init_loc = c_parser_peek_token (parser)->location;
9642 init_exp = c_parser_expr_no_commas (parser, NULL);
9643 init_exp = default_function_array_read_conversion (init_loc,
9645 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9646 NOP_EXPR, init_loc, init_exp.value,
9647 init_exp.original_type);
9648 init = c_process_expr_stmt (init_loc, init);
9650 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9655 c_parser_error (parser,
9656 "expected iteration declaration or initialization");
9657 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9663 /* Parse the loop condition. */
9665 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9667 location_t cond_loc = c_parser_peek_token (parser)->location;
9668 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL,
9671 cond = cond_expr.value;
9672 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9673 cond = c_fully_fold (cond, false, NULL);
9674 switch (cond_expr.original_code)
9682 /* Can't be cond = error_mark_node, because we want to preserve
9683 the location until c_finish_omp_for. */
9684 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9687 protected_set_expr_location (cond, cond_loc);
9689 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9691 /* Parse the increment expression. */
9693 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9695 location_t incr_loc = c_parser_peek_token (parser)->location;
9697 incr = c_process_expr_stmt (incr_loc,
9698 c_parser_expression (parser).value);
9700 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9702 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9706 TREE_VEC_ELT (declv, i) = decl;
9707 TREE_VEC_ELT (initv, i) = init;
9708 TREE_VEC_ELT (condv, i) = cond;
9709 TREE_VEC_ELT (incrv, i) = incr;
9713 if (i == collapse - 1)
9716 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9717 in between the collapsed for loops to be still considered perfectly
9718 nested. Hopefully the final version clarifies this.
9719 For now handle (multiple) {'s and empty statements. */
9722 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9724 c_parser_consume_token (parser);
9727 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9729 c_parser_consume_token (parser);
9733 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9734 c_parser_consume_token (parser);
9737 c_parser_error (parser, "not enough perfectly nested loops");
9740 open_brace_parsed = true;
9750 nbraces += bracecount;
9753 save_break = c_break_label;
9754 c_break_label = size_one_node;
9755 save_cont = c_cont_label;
9756 c_cont_label = NULL_TREE;
9757 body = push_stmt_list ();
9759 if (open_brace_parsed)
9761 location_t here = c_parser_peek_token (parser)->location;
9762 stmt = c_begin_compound_stmt (true);
9763 c_parser_compound_statement_nostart (parser);
9764 add_stmt (c_end_compound_stmt (here, stmt, true));
9767 add_stmt (c_parser_c99_block_statement (parser));
9770 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9771 SET_EXPR_LOCATION (t, loc);
9775 body = pop_stmt_list (body);
9776 c_break_label = save_break;
9777 c_cont_label = save_cont;
9781 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9783 c_parser_consume_token (parser);
9786 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
9787 c_parser_consume_token (parser);
9790 c_parser_error (parser, "collapsed loops not perfectly nested");
9793 location_t here = c_parser_peek_token (parser)->location;
9794 stmt = c_begin_compound_stmt (true);
9796 c_parser_compound_statement_nostart (parser);
9797 body = c_end_compound_stmt (here, stmt, true);
9804 /* Only bother calling c_finish_omp_for if we haven't already generated
9805 an error from the initialization parsing. */
9808 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
9811 if (par_clauses != NULL)
9814 for (c = par_clauses; *c ; )
9815 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
9816 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
9817 c = &OMP_CLAUSE_CHAIN (*c);
9820 for (i = 0; i < collapse; i++)
9821 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
9824 c = &OMP_CLAUSE_CHAIN (*c);
9825 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
9828 "iteration variable %qD should not be firstprivate",
9829 OMP_CLAUSE_DECL (*c));
9830 *c = OMP_CLAUSE_CHAIN (*c);
9834 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
9835 change it to shared (decl) in
9836 OMP_PARALLEL_CLAUSES. */
9837 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
9838 OMP_CLAUSE_LASTPRIVATE);
9839 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
9840 OMP_CLAUSE_CHAIN (l) = clauses;
9842 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
9846 OMP_FOR_CLAUSES (stmt) = clauses;
9851 while (!VEC_empty (tree, for_block))
9853 /* FIXME diagnostics: LOC below should be the actual location of
9854 this particular for block. We need to build a list of
9855 locations to go along with FOR_BLOCK. */
9856 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9859 release_tree_vector (for_block);
9864 #pragma omp for for-clause[optseq] new-line
9867 LOC is the location of the #pragma token.
9870 #define OMP_FOR_CLAUSE_MASK \
9871 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9872 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9873 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9874 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9875 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9876 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9877 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9878 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9881 c_parser_omp_for (location_t loc, c_parser *parser)
9883 tree block, clauses, ret;
9885 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9888 block = c_begin_compound_stmt (true);
9889 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9890 block = c_end_compound_stmt (loc, block, true);
9897 # pragma omp master new-line
9900 LOC is the location of the #pragma token.
9904 c_parser_omp_master (location_t loc, c_parser *parser)
9906 c_parser_skip_to_pragma_eol (parser);
9907 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9911 # pragma omp ordered new-line
9914 LOC is the location of the #pragma itself.
9918 c_parser_omp_ordered (location_t loc, c_parser *parser)
9920 c_parser_skip_to_pragma_eol (parser);
9921 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9927 { section-sequence }
9930 section-directive[opt] structured-block
9931 section-sequence section-directive structured-block
9933 SECTIONS_LOC is the location of the #pragma omp sections. */
9936 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9939 bool error_suppress = false;
9942 loc = c_parser_peek_token (parser)->location;
9943 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9945 /* Avoid skipping until the end of the block. */
9946 parser->error = false;
9950 stmt = push_stmt_list ();
9952 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9954 substmt = push_stmt_list ();
9958 c_parser_statement (parser);
9960 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9962 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9964 if (c_parser_next_token_is (parser, CPP_EOF))
9968 substmt = pop_stmt_list (substmt);
9969 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9970 SET_EXPR_LOCATION (substmt, loc);
9976 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9978 if (c_parser_next_token_is (parser, CPP_EOF))
9981 loc = c_parser_peek_token (parser)->location;
9982 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9984 c_parser_consume_pragma (parser);
9985 c_parser_skip_to_pragma_eol (parser);
9986 error_suppress = false;
9988 else if (!error_suppress)
9990 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9991 error_suppress = true;
9994 substmt = c_parser_omp_structured_block (parser);
9995 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9996 SET_EXPR_LOCATION (substmt, loc);
9999 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
10000 "expected %<#pragma omp section%> or %<}%>");
10002 substmt = pop_stmt_list (stmt);
10004 stmt = make_node (OMP_SECTIONS);
10005 SET_EXPR_LOCATION (stmt, sections_loc);
10006 TREE_TYPE (stmt) = void_type_node;
10007 OMP_SECTIONS_BODY (stmt) = substmt;
10009 return add_stmt (stmt);
10013 # pragma omp sections sections-clause[optseq] newline
10016 LOC is the location of the #pragma token.
10019 #define OMP_SECTIONS_CLAUSE_MASK \
10020 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10021 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10022 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10023 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10024 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10027 c_parser_omp_sections (location_t loc, c_parser *parser)
10029 tree block, clauses, ret;
10031 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
10032 "#pragma omp sections");
10034 block = c_begin_compound_stmt (true);
10035 ret = c_parser_omp_sections_scope (loc, parser);
10037 OMP_SECTIONS_CLAUSES (ret) = clauses;
10038 block = c_end_compound_stmt (loc, block, true);
10045 # pragma parallel parallel-clause new-line
10046 # pragma parallel for parallel-for-clause new-line
10047 # pragma parallel sections parallel-sections-clause new-line
10049 LOC is the location of the #pragma token.
10052 #define OMP_PARALLEL_CLAUSE_MASK \
10053 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10054 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10055 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10056 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10057 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10058 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10059 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10060 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10063 c_parser_omp_parallel (location_t loc, c_parser *parser)
10065 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
10066 const char *p_name = "#pragma omp parallel";
10067 tree stmt, clauses, par_clause, ws_clause, block;
10068 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
10070 if (c_parser_next_token_is_keyword (parser, RID_FOR))
10072 c_parser_consume_token (parser);
10073 p_kind = PRAGMA_OMP_PARALLEL_FOR;
10074 p_name = "#pragma omp parallel for";
10075 mask |= OMP_FOR_CLAUSE_MASK;
10076 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10078 else if (c_parser_next_token_is (parser, CPP_NAME))
10080 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10081 if (strcmp (p, "sections") == 0)
10083 c_parser_consume_token (parser);
10084 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
10085 p_name = "#pragma omp parallel sections";
10086 mask |= OMP_SECTIONS_CLAUSE_MASK;
10087 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10091 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
10095 case PRAGMA_OMP_PARALLEL:
10096 block = c_begin_omp_parallel ();
10097 c_parser_statement (parser);
10098 stmt = c_finish_omp_parallel (loc, clauses, block);
10101 case PRAGMA_OMP_PARALLEL_FOR:
10102 block = c_begin_omp_parallel ();
10103 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10104 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
10105 stmt = c_finish_omp_parallel (loc, par_clause, block);
10106 OMP_PARALLEL_COMBINED (stmt) = 1;
10109 case PRAGMA_OMP_PARALLEL_SECTIONS:
10110 block = c_begin_omp_parallel ();
10111 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10112 stmt = c_parser_omp_sections_scope (loc, parser);
10114 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
10115 stmt = c_finish_omp_parallel (loc, par_clause, block);
10116 OMP_PARALLEL_COMBINED (stmt) = 1;
10120 gcc_unreachable ();
10127 # pragma omp single single-clause[optseq] new-line
10130 LOC is the location of the #pragma.
10133 #define OMP_SINGLE_CLAUSE_MASK \
10134 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10135 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10136 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10137 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10140 c_parser_omp_single (location_t loc, c_parser *parser)
10142 tree stmt = make_node (OMP_SINGLE);
10143 SET_EXPR_LOCATION (stmt, loc);
10144 TREE_TYPE (stmt) = void_type_node;
10146 OMP_SINGLE_CLAUSES (stmt)
10147 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
10148 "#pragma omp single");
10149 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
10151 return add_stmt (stmt);
10155 # pragma omp task task-clause[optseq] new-line
10157 LOC is the location of the #pragma.
10160 #define OMP_TASK_CLAUSE_MASK \
10161 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10162 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10163 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10164 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10165 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10166 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10167 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10168 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10171 c_parser_omp_task (location_t loc, c_parser *parser)
10173 tree clauses, block;
10175 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
10176 "#pragma omp task");
10178 block = c_begin_omp_task ();
10179 c_parser_statement (parser);
10180 return c_finish_omp_task (loc, clauses, block);
10184 # pragma omp taskwait new-line
10188 c_parser_omp_taskwait (c_parser *parser)
10190 location_t loc = c_parser_peek_token (parser)->location;
10191 c_parser_consume_pragma (parser);
10192 c_parser_skip_to_pragma_eol (parser);
10194 c_finish_omp_taskwait (loc);
10198 # pragma omp taskyield new-line
10202 c_parser_omp_taskyield (c_parser *parser)
10204 location_t loc = c_parser_peek_token (parser)->location;
10205 c_parser_consume_pragma (parser);
10206 c_parser_skip_to_pragma_eol (parser);
10208 c_finish_omp_taskyield (loc);
10211 /* Main entry point to parsing most OpenMP pragmas. */
10214 c_parser_omp_construct (c_parser *parser)
10216 enum pragma_kind p_kind;
10220 loc = c_parser_peek_token (parser)->location;
10221 p_kind = c_parser_peek_token (parser)->pragma_kind;
10222 c_parser_consume_pragma (parser);
10226 case PRAGMA_OMP_ATOMIC:
10227 c_parser_omp_atomic (loc, parser);
10229 case PRAGMA_OMP_CRITICAL:
10230 stmt = c_parser_omp_critical (loc, parser);
10232 case PRAGMA_OMP_FOR:
10233 stmt = c_parser_omp_for (loc, parser);
10235 case PRAGMA_OMP_MASTER:
10236 stmt = c_parser_omp_master (loc, parser);
10238 case PRAGMA_OMP_ORDERED:
10239 stmt = c_parser_omp_ordered (loc, parser);
10241 case PRAGMA_OMP_PARALLEL:
10242 stmt = c_parser_omp_parallel (loc, parser);
10244 case PRAGMA_OMP_SECTIONS:
10245 stmt = c_parser_omp_sections (loc, parser);
10247 case PRAGMA_OMP_SINGLE:
10248 stmt = c_parser_omp_single (loc, parser);
10250 case PRAGMA_OMP_TASK:
10251 stmt = c_parser_omp_task (loc, parser);
10254 gcc_unreachable ();
10258 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
10263 # pragma omp threadprivate (variable-list) */
10266 c_parser_omp_threadprivate (c_parser *parser)
10271 c_parser_consume_pragma (parser);
10272 loc = c_parser_peek_token (parser)->location;
10273 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10275 /* Mark every variable in VARS to be assigned thread local storage. */
10276 for (t = vars; t; t = TREE_CHAIN (t))
10278 tree v = TREE_PURPOSE (t);
10280 /* FIXME diagnostics: Ideally we should keep individual
10281 locations for all the variables in the var list to make the
10282 following errors more precise. Perhaps
10283 c_parser_omp_var_list_parens() should construct a list of
10284 locations to go along with the var list. */
10286 /* If V had already been marked threadprivate, it doesn't matter
10287 whether it had been used prior to this point. */
10288 if (TREE_CODE (v) != VAR_DECL)
10289 error_at (loc, "%qD is not a variable", v);
10290 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
10291 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10292 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10293 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10294 else if (TREE_TYPE (v) == error_mark_node)
10296 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
10297 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10300 if (! DECL_THREAD_LOCAL_P (v))
10302 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
10303 /* If rtl has been already set for this var, call
10304 make_decl_rtl once again, so that encode_section_info
10305 has a chance to look at the new decl flags. */
10306 if (DECL_RTL_SET_P (v))
10309 C_DECL_THREADPRIVATE_P (v) = 1;
10313 c_parser_skip_to_pragma_eol (parser);
10317 /* Parse a single source file. */
10320 c_parse_file (void)
10322 /* Use local storage to begin. If the first token is a pragma, parse it.
10323 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10324 which will cause garbage collection. */
10327 memset (&tparser, 0, sizeof tparser);
10328 the_parser = &tparser;
10330 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
10331 c_parser_pragma_pch_preprocess (&tparser);
10333 the_parser = ggc_alloc_c_parser ();
10334 *the_parser = tparser;
10336 /* Initialize EH, if we've been told to do so. */
10337 if (flag_exceptions)
10338 using_eh_for_cleanups ();
10340 c_parser_translation_unit (the_parser);
10344 #include "gt-c-parser.h"