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)
659 if (c_dialect_objc ())
668 /* Return true if TOKEN can start declaration specifiers or a static
669 assertion, false otherwise. */
671 c_token_starts_declaration (c_token *token)
673 if (c_token_starts_declspecs (token)
674 || token->keyword == RID_STATIC_ASSERT)
680 /* Return true if the next token from PARSER can start declaration
681 specifiers, false otherwise. */
683 c_parser_next_token_starts_declspecs (c_parser *parser)
685 c_token *token = c_parser_peek_token (parser);
687 /* In Objective-C, a classname normally starts a declspecs unless it
688 is immediately followed by a dot. In that case, it is the
689 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
690 setter/getter on the class. c_token_starts_declspecs() can't
691 differentiate between the two cases because it only checks the
692 current token, so we have a special check here. */
693 if (c_dialect_objc ()
694 && token->type == CPP_NAME
695 && token->id_kind == C_ID_CLASSNAME
696 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
699 return c_token_starts_declspecs (token);
702 /* Return true if the next tokens from PARSER can start declaration
703 specifiers or a static assertion, false otherwise. */
705 c_parser_next_tokens_start_declaration (c_parser *parser)
707 c_token *token = c_parser_peek_token (parser);
710 if (c_dialect_objc ()
711 && token->type == CPP_NAME
712 && token->id_kind == C_ID_CLASSNAME
713 && c_parser_peek_2nd_token (parser)->type == CPP_DOT)
716 /* Labels do not start declarations. */
717 if (token->type == CPP_NAME
718 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
721 if (c_token_starts_declaration (token))
724 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl))
730 /* Consume the next token from PARSER. */
733 c_parser_consume_token (c_parser *parser)
735 gcc_assert (parser->tokens_avail >= 1);
736 gcc_assert (parser->tokens[0].type != CPP_EOF);
737 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
738 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
739 if (parser->tokens_avail == 2)
740 parser->tokens[0] = parser->tokens[1];
741 parser->tokens_avail--;
744 /* Expect the current token to be a #pragma. Consume it and remember
745 that we've begun parsing a pragma. */
748 c_parser_consume_pragma (c_parser *parser)
750 gcc_assert (!parser->in_pragma);
751 gcc_assert (parser->tokens_avail >= 1);
752 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
753 if (parser->tokens_avail == 2)
754 parser->tokens[0] = parser->tokens[1];
755 parser->tokens_avail--;
756 parser->in_pragma = true;
759 /* Update the globals input_location and in_system_header from
762 c_parser_set_source_position_from_token (c_token *token)
764 if (token->type != CPP_EOF)
766 input_location = token->location;
770 /* Issue a diagnostic of the form
771 FILE:LINE: MESSAGE before TOKEN
772 where TOKEN is the next token in the input stream of PARSER.
773 MESSAGE (specified by the caller) is usually of the form "expected
776 Do not issue a diagnostic if still recovering from an error.
778 ??? This is taken from the C++ parser, but building up messages in
779 this way is not i18n-friendly and some other approach should be
783 c_parser_error (c_parser *parser, const char *gmsgid)
785 c_token *token = c_parser_peek_token (parser);
788 parser->error = true;
791 /* This diagnostic makes more sense if it is tagged to the line of
792 the token we just peeked at. */
793 c_parser_set_source_position_from_token (token);
794 c_parse_error (gmsgid,
795 /* Because c_parse_error does not understand
796 CPP_KEYWORD, keywords are treated like
798 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
799 /* ??? The C parser does not save the cpp flags of a
800 token, we need to pass 0 here and we will not get
801 the source spelling of some tokens but rather the
802 canonical spelling. */
803 token->value, /*flags=*/0);
806 /* If the next token is of the indicated TYPE, consume it. Otherwise,
807 issue the error MSGID. If MSGID is NULL then a message has already
808 been produced and no message will be produced this time. Returns
809 true if found, false otherwise. */
812 c_parser_require (c_parser *parser,
816 if (c_parser_next_token_is (parser, type))
818 c_parser_consume_token (parser);
823 c_parser_error (parser, msgid);
828 /* If the next token is the indicated keyword, consume it. Otherwise,
829 issue the error MSGID. Returns true if found, false otherwise. */
832 c_parser_require_keyword (c_parser *parser,
836 if (c_parser_next_token_is_keyword (parser, keyword))
838 c_parser_consume_token (parser);
843 c_parser_error (parser, msgid);
848 /* Like c_parser_require, except that tokens will be skipped until the
849 desired token is found. An error message is still produced if the
850 next token is not as expected. If MSGID is NULL then a message has
851 already been produced and no message will be produced this
855 c_parser_skip_until_found (c_parser *parser,
859 unsigned nesting_depth = 0;
861 if (c_parser_require (parser, type, msgid))
864 /* Skip tokens until the desired token is found. */
867 /* Peek at the next token. */
868 c_token *token = c_parser_peek_token (parser);
869 /* If we've reached the token we want, consume it and stop. */
870 if (token->type == type && !nesting_depth)
872 c_parser_consume_token (parser);
876 /* If we've run out of tokens, stop. */
877 if (token->type == CPP_EOF)
879 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
881 if (token->type == CPP_OPEN_BRACE
882 || token->type == CPP_OPEN_PAREN
883 || token->type == CPP_OPEN_SQUARE)
885 else if (token->type == CPP_CLOSE_BRACE
886 || token->type == CPP_CLOSE_PAREN
887 || token->type == CPP_CLOSE_SQUARE)
889 if (nesting_depth-- == 0)
892 /* Consume this token. */
893 c_parser_consume_token (parser);
895 parser->error = false;
898 /* Skip tokens until the end of a parameter is found, but do not
899 consume the comma, semicolon or closing delimiter. */
902 c_parser_skip_to_end_of_parameter (c_parser *parser)
904 unsigned nesting_depth = 0;
908 c_token *token = c_parser_peek_token (parser);
909 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
912 /* If we've run out of tokens, stop. */
913 if (token->type == CPP_EOF)
915 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
917 if (token->type == CPP_OPEN_BRACE
918 || token->type == CPP_OPEN_PAREN
919 || token->type == CPP_OPEN_SQUARE)
921 else if (token->type == CPP_CLOSE_BRACE
922 || token->type == CPP_CLOSE_PAREN
923 || token->type == CPP_CLOSE_SQUARE)
925 if (nesting_depth-- == 0)
928 /* Consume this token. */
929 c_parser_consume_token (parser);
931 parser->error = false;
934 /* Expect to be at the end of the pragma directive and consume an
935 end of line marker. */
938 c_parser_skip_to_pragma_eol (c_parser *parser)
940 gcc_assert (parser->in_pragma);
941 parser->in_pragma = false;
943 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
946 c_token *token = c_parser_peek_token (parser);
947 if (token->type == CPP_EOF)
949 if (token->type == CPP_PRAGMA_EOL)
951 c_parser_consume_token (parser);
954 c_parser_consume_token (parser);
957 parser->error = false;
960 /* Skip tokens until we have consumed an entire block, or until we
961 have consumed a non-nested ';'. */
964 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
966 unsigned nesting_depth = 0;
967 bool save_error = parser->error;
973 /* Peek at the next token. */
974 token = c_parser_peek_token (parser);
982 if (parser->in_pragma)
987 /* If the next token is a ';', we have reached the
988 end of the statement. */
991 /* Consume the ';'. */
992 c_parser_consume_token (parser);
997 case CPP_CLOSE_BRACE:
998 /* If the next token is a non-nested '}', then we have
999 reached the end of the current block. */
1000 if (nesting_depth == 0 || --nesting_depth == 0)
1002 c_parser_consume_token (parser);
1007 case CPP_OPEN_BRACE:
1008 /* If it the next token is a '{', then we are entering a new
1009 block. Consume the entire block. */
1014 /* If we see a pragma, consume the whole thing at once. We
1015 have some safeguards against consuming pragmas willy-nilly.
1016 Normally, we'd expect to be here with parser->error set,
1017 which disables these safeguards. But it's possible to get
1018 here for secondary error recovery, after parser->error has
1020 c_parser_consume_pragma (parser);
1021 c_parser_skip_to_pragma_eol (parser);
1022 parser->error = save_error;
1029 c_parser_consume_token (parser);
1033 parser->error = false;
1036 /* CPP's options (initialized by c-opts.c). */
1037 extern cpp_options *cpp_opts;
1039 /* Save the warning flags which are controlled by __extension__. */
1042 disable_extension_diagnostics (void)
1045 | (warn_pointer_arith << 1)
1046 | (warn_traditional << 2)
1048 | (warn_long_long << 4)
1049 | (warn_cxx_compat << 5)
1050 | (warn_overlength_strings << 6));
1051 cpp_opts->cpp_pedantic = pedantic = 0;
1052 warn_pointer_arith = 0;
1053 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
1055 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
1056 warn_cxx_compat = 0;
1057 warn_overlength_strings = 0;
1061 /* Restore the warning flags which are controlled by __extension__.
1062 FLAGS is the return value from disable_extension_diagnostics. */
1065 restore_extension_diagnostics (int flags)
1067 cpp_opts->cpp_pedantic = pedantic = flags & 1;
1068 warn_pointer_arith = (flags >> 1) & 1;
1069 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
1070 flag_iso = (flags >> 3) & 1;
1071 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
1072 warn_cxx_compat = (flags >> 5) & 1;
1073 warn_overlength_strings = (flags >> 6) & 1;
1076 /* Possibly kinds of declarator to parse. */
1077 typedef enum c_dtr_syn {
1078 /* A normal declarator with an identifier. */
1080 /* An abstract declarator (maybe empty). */
1082 /* A parameter declarator: may be either, but after a type name does
1083 not redeclare a typedef name as an identifier if it can
1084 alternatively be interpreted as a typedef name; see DR#009,
1085 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1086 following DR#249. For example, given a typedef T, "int T" and
1087 "int *T" are valid parameter declarations redeclaring T, while
1088 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1089 abstract declarators rather than involving redundant parentheses;
1090 the same applies with attributes inside the parentheses before
1095 /* The binary operation precedence levels, where 0 is a dummy lowest level
1096 used for the bottom of the stack. */
1097 enum c_parser_prec {
1112 static void c_parser_external_declaration (c_parser *);
1113 static void c_parser_asm_definition (c_parser *);
1114 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
1115 bool, bool, tree *);
1116 static void c_parser_static_assert_declaration_no_semi (c_parser *);
1117 static void c_parser_static_assert_declaration (c_parser *);
1118 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
1119 bool, enum c_lookahead_kind);
1120 static struct c_typespec c_parser_enum_specifier (c_parser *);
1121 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1122 static tree c_parser_struct_declaration (c_parser *);
1123 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1124 static tree c_parser_alignas_specifier (c_parser *);
1125 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1127 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1129 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1131 struct c_declarator *);
1132 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1133 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree,
1135 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1136 static tree c_parser_simple_asm_expr (c_parser *);
1137 static tree c_parser_attributes (c_parser *);
1138 static struct c_type_name *c_parser_type_name (c_parser *);
1139 static struct c_expr c_parser_initializer (c_parser *);
1140 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1141 static void c_parser_initelt (c_parser *, struct obstack *);
1142 static void c_parser_initval (c_parser *, struct c_expr *,
1144 static tree c_parser_compound_statement (c_parser *);
1145 static void c_parser_compound_statement_nostart (c_parser *);
1146 static void c_parser_label (c_parser *);
1147 static void c_parser_statement (c_parser *);
1148 static void c_parser_statement_after_labels (c_parser *);
1149 static void c_parser_if_statement (c_parser *);
1150 static void c_parser_switch_statement (c_parser *);
1151 static void c_parser_while_statement (c_parser *);
1152 static void c_parser_do_statement (c_parser *);
1153 static void c_parser_for_statement (c_parser *);
1154 static tree c_parser_asm_statement (c_parser *);
1155 static tree c_parser_asm_operands (c_parser *, bool);
1156 static tree c_parser_asm_goto_operands (c_parser *);
1157 static tree c_parser_asm_clobbers (c_parser *);
1158 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1159 static struct c_expr c_parser_conditional_expression (c_parser *,
1161 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
1162 enum c_parser_prec);
1163 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1164 static struct c_expr c_parser_unary_expression (c_parser *);
1165 static struct c_expr c_parser_sizeof_expression (c_parser *);
1166 static struct c_expr c_parser_alignof_expression (c_parser *);
1167 static struct c_expr c_parser_postfix_expression (c_parser *);
1168 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1169 struct c_type_name *,
1171 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1174 static struct c_expr c_parser_expression (c_parser *);
1175 static struct c_expr c_parser_expression_conv (c_parser *);
1176 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1178 static void c_parser_omp_construct (c_parser *);
1179 static void c_parser_omp_threadprivate (c_parser *);
1180 static void c_parser_omp_barrier (c_parser *);
1181 static void c_parser_omp_flush (c_parser *);
1182 static void c_parser_omp_taskwait (c_parser *);
1183 static void c_parser_omp_taskyield (c_parser *);
1185 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1186 static bool c_parser_pragma (c_parser *, enum pragma_context);
1188 /* These Objective-C parser functions are only ever called when
1189 compiling Objective-C. */
1190 static void c_parser_objc_class_definition (c_parser *, tree);
1191 static void c_parser_objc_class_instance_variables (c_parser *);
1192 static void c_parser_objc_class_declaration (c_parser *);
1193 static void c_parser_objc_alias_declaration (c_parser *);
1194 static void c_parser_objc_protocol_definition (c_parser *, tree);
1195 static bool c_parser_objc_method_type (c_parser *);
1196 static void c_parser_objc_method_definition (c_parser *);
1197 static void c_parser_objc_methodprotolist (c_parser *);
1198 static void c_parser_objc_methodproto (c_parser *);
1199 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *);
1200 static tree c_parser_objc_type_name (c_parser *);
1201 static tree c_parser_objc_protocol_refs (c_parser *);
1202 static void c_parser_objc_try_catch_finally_statement (c_parser *);
1203 static void c_parser_objc_synchronized_statement (c_parser *);
1204 static tree c_parser_objc_selector (c_parser *);
1205 static tree c_parser_objc_selector_arg (c_parser *);
1206 static tree c_parser_objc_receiver (c_parser *);
1207 static tree c_parser_objc_message_args (c_parser *);
1208 static tree c_parser_objc_keywordexpr (c_parser *);
1209 static void c_parser_objc_at_property_declaration (c_parser *);
1210 static void c_parser_objc_at_synthesize_declaration (c_parser *);
1211 static void c_parser_objc_at_dynamic_declaration (c_parser *);
1212 static bool c_parser_objc_diagnose_bad_element_prefix
1213 (c_parser *, struct c_declspecs *);
1215 /* Parse a translation unit (C90 6.7, C99 6.9).
1218 external-declarations
1220 external-declarations:
1221 external-declaration
1222 external-declarations external-declaration
1231 c_parser_translation_unit (c_parser *parser)
1233 if (c_parser_next_token_is (parser, CPP_EOF))
1235 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1236 "ISO C forbids an empty translation unit");
1240 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1241 mark_valid_location_for_stdc_pragma (false);
1245 c_parser_external_declaration (parser);
1246 obstack_free (&parser_obstack, obstack_position);
1248 while (c_parser_next_token_is_not (parser, CPP_EOF));
1252 /* Parse an external declaration (C90 6.7, C99 6.9).
1254 external-declaration:
1260 external-declaration:
1263 __extension__ external-declaration
1267 external-declaration:
1268 objc-class-definition
1269 objc-class-declaration
1270 objc-alias-declaration
1271 objc-protocol-definition
1272 objc-method-definition
1277 c_parser_external_declaration (c_parser *parser)
1280 switch (c_parser_peek_token (parser)->type)
1283 switch (c_parser_peek_token (parser)->keyword)
1286 ext = disable_extension_diagnostics ();
1287 c_parser_consume_token (parser);
1288 c_parser_external_declaration (parser);
1289 restore_extension_diagnostics (ext);
1292 c_parser_asm_definition (parser);
1294 case RID_AT_INTERFACE:
1295 case RID_AT_IMPLEMENTATION:
1296 gcc_assert (c_dialect_objc ());
1297 c_parser_objc_class_definition (parser, NULL_TREE);
1300 gcc_assert (c_dialect_objc ());
1301 c_parser_objc_class_declaration (parser);
1304 gcc_assert (c_dialect_objc ());
1305 c_parser_objc_alias_declaration (parser);
1307 case RID_AT_PROTOCOL:
1308 gcc_assert (c_dialect_objc ());
1309 c_parser_objc_protocol_definition (parser, NULL_TREE);
1311 case RID_AT_PROPERTY:
1312 gcc_assert (c_dialect_objc ());
1313 c_parser_objc_at_property_declaration (parser);
1315 case RID_AT_SYNTHESIZE:
1316 gcc_assert (c_dialect_objc ());
1317 c_parser_objc_at_synthesize_declaration (parser);
1319 case RID_AT_DYNAMIC:
1320 gcc_assert (c_dialect_objc ());
1321 c_parser_objc_at_dynamic_declaration (parser);
1324 gcc_assert (c_dialect_objc ());
1325 c_parser_consume_token (parser);
1326 objc_finish_implementation ();
1333 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1334 "ISO C does not allow extra %<;%> outside of a function");
1335 c_parser_consume_token (parser);
1338 mark_valid_location_for_stdc_pragma (true);
1339 c_parser_pragma (parser, pragma_external);
1340 mark_valid_location_for_stdc_pragma (false);
1344 if (c_dialect_objc ())
1346 c_parser_objc_method_definition (parser);
1349 /* Else fall through, and yield a syntax error trying to parse
1350 as a declaration or function definition. */
1353 /* A declaration or a function definition (or, in Objective-C,
1354 an @interface or @protocol with prefix attributes). We can
1355 only tell which after parsing the declaration specifiers, if
1356 any, and the first declarator. */
1357 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1362 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1363 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1364 accepted; otherwise (old-style parameter declarations) only other
1365 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1366 assertion is accepted; otherwise (old-style parameter declarations)
1367 it is not. If NESTED is true, we are inside a function or parsing
1368 old-style parameter declarations; any functions encountered are
1369 nested functions and declaration specifiers are required; otherwise
1370 we are at top level and functions are normal functions and
1371 declaration specifiers may be optional. If EMPTY_OK is true, empty
1372 declarations are OK (subject to all other constraints); otherwise
1373 (old-style parameter declarations) they are diagnosed. If
1374 START_ATTR_OK is true, the declaration specifiers may start with
1375 attributes; otherwise they may not.
1376 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1377 declaration when parsing an Objective-C foreach statement.
1380 declaration-specifiers init-declarator-list[opt] ;
1381 static_assert-declaration
1383 function-definition:
1384 declaration-specifiers[opt] declarator declaration-list[opt]
1389 declaration-list declaration
1391 init-declarator-list:
1393 init-declarator-list , init-declarator
1396 declarator simple-asm-expr[opt] attributes[opt]
1397 declarator simple-asm-expr[opt] attributes[opt] = initializer
1401 nested-function-definition:
1402 declaration-specifiers declarator declaration-list[opt]
1406 attributes objc-class-definition
1407 attributes objc-category-definition
1408 attributes objc-protocol-definition
1410 The simple-asm-expr and attributes are GNU extensions.
1412 This function does not handle __extension__; that is handled in its
1413 callers. ??? Following the old parser, __extension__ may start
1414 external declarations, declarations in functions and declarations
1415 at the start of "for" loops, but not old-style parameter
1418 C99 requires declaration specifiers in a function definition; the
1419 absence is diagnosed through the diagnosis of implicit int. In GNU
1420 C we also allow but diagnose declarations without declaration
1421 specifiers, but only at top level (elsewhere they conflict with
1424 In Objective-C, declarations of the looping variable in a foreach
1425 statement are exceptionally terminated by 'in' (for example, 'for
1426 (NSObject *object in array) { ... }').
1431 threadprivate-directive */
1434 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1435 bool static_assert_ok, bool empty_ok,
1436 bool nested, bool start_attr_ok,
1437 tree *objc_foreach_object_declaration)
1439 struct c_declspecs *specs;
1441 tree all_prefix_attrs;
1442 bool diagnosed_no_specs = false;
1443 location_t here = c_parser_peek_token (parser)->location;
1445 if (static_assert_ok
1446 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1448 c_parser_static_assert_declaration (parser);
1451 specs = build_null_declspecs ();
1453 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1454 if (c_parser_peek_token (parser)->type == CPP_NAME
1455 && c_parser_peek_token (parser)->id_kind == C_ID_ID
1456 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME
1457 || c_parser_peek_2nd_token (parser)->type == CPP_MULT)
1458 && (!nested || !lookup_name (c_parser_peek_token (parser)->value)))
1460 error_at (here, "unknown type name %qE",
1461 c_parser_peek_token (parser)->value);
1463 /* Parse declspecs normally to get a correct pointer type, but avoid
1464 a further "fails to be a type name" error. Refuse nested functions
1465 since it is not how the user likely wants us to recover. */
1466 c_parser_peek_token (parser)->type = CPP_KEYWORD;
1467 c_parser_peek_token (parser)->keyword = RID_VOID;
1468 c_parser_peek_token (parser)->value = error_mark_node;
1472 c_parser_declspecs (parser, specs, true, true, start_attr_ok, cla_nonabstract_decl);
1475 c_parser_skip_to_end_of_block_or_statement (parser);
1478 if (nested && !specs->declspecs_seen_p)
1480 c_parser_error (parser, "expected declaration specifiers");
1481 c_parser_skip_to_end_of_block_or_statement (parser);
1484 finish_declspecs (specs);
1485 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1491 shadow_tag_warned (specs, 1);
1492 pedwarn (here, 0, "empty declaration");
1494 c_parser_consume_token (parser);
1498 /* Provide better error recovery. Note that a type name here is usually
1499 better diagnosed as a redeclaration. */
1501 && specs->typespec_kind == ctsk_tagdef
1502 && c_parser_next_token_starts_declspecs (parser)
1503 && !c_parser_next_token_is (parser, CPP_NAME))
1505 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
1506 parser->error = false;
1507 shadow_tag_warned (specs, 1);
1510 else if (c_dialect_objc ())
1512 /* Prefix attributes are an error on method decls. */
1513 switch (c_parser_peek_token (parser)->type)
1517 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1521 warning_at (c_parser_peek_token (parser)->location,
1523 "prefix attributes are ignored for methods");
1524 specs->attrs = NULL_TREE;
1527 c_parser_objc_method_definition (parser);
1529 c_parser_objc_methodproto (parser);
1535 /* This is where we parse 'attributes @interface ...',
1536 'attributes @implementation ...', 'attributes @protocol ...'
1537 (where attributes could be, for example, __attribute__
1540 switch (c_parser_peek_token (parser)->keyword)
1542 case RID_AT_INTERFACE:
1544 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1546 c_parser_objc_class_definition (parser, specs->attrs);
1550 case RID_AT_IMPLEMENTATION:
1552 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1556 warning_at (c_parser_peek_token (parser)->location,
1558 "prefix attributes are ignored for implementations");
1559 specs->attrs = NULL_TREE;
1561 c_parser_objc_class_definition (parser, NULL_TREE);
1565 case RID_AT_PROTOCOL:
1567 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1569 c_parser_objc_protocol_definition (parser, specs->attrs);
1576 case RID_AT_PROPERTY:
1579 c_parser_error (parser, "unexpected attribute");
1580 specs->attrs = NULL;
1588 pending_xref_error ();
1589 prefix_attrs = specs->attrs;
1590 all_prefix_attrs = prefix_attrs;
1591 specs->attrs = NULL_TREE;
1594 struct c_declarator *declarator;
1598 /* Declaring either one or more declarators (in which case we
1599 should diagnose if there were no declaration specifiers) or a
1600 function definition (in which case the diagnostic for
1601 implicit int suffices). */
1602 declarator = c_parser_declarator (parser,
1603 specs->typespec_kind != ctsk_none,
1604 C_DTR_NORMAL, &dummy);
1605 if (declarator == NULL)
1607 c_parser_skip_to_end_of_block_or_statement (parser);
1610 if (c_parser_next_token_is (parser, CPP_EQ)
1611 || c_parser_next_token_is (parser, CPP_COMMA)
1612 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1613 || c_parser_next_token_is_keyword (parser, RID_ASM)
1614 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1615 || c_parser_next_token_is_keyword (parser, RID_IN))
1617 tree asm_name = NULL_TREE;
1618 tree postfix_attrs = NULL_TREE;
1619 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1621 diagnosed_no_specs = true;
1622 pedwarn (here, 0, "data definition has no type or storage class");
1624 /* Having seen a data definition, there cannot now be a
1625 function definition. */
1627 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1628 asm_name = c_parser_simple_asm_expr (parser);
1629 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1630 postfix_attrs = c_parser_attributes (parser);
1631 if (c_parser_next_token_is (parser, CPP_EQ))
1635 location_t init_loc;
1636 c_parser_consume_token (parser);
1637 /* The declaration of the variable is in effect while
1638 its initializer is parsed. */
1639 d = start_decl (declarator, specs, true,
1640 chainon (postfix_attrs, all_prefix_attrs));
1642 d = error_mark_node;
1643 start_init (d, asm_name, global_bindings_p ());
1644 init_loc = c_parser_peek_token (parser)->location;
1645 init = c_parser_initializer (parser);
1647 if (d != error_mark_node)
1649 maybe_warn_string_init (TREE_TYPE (d), init);
1650 finish_decl (d, init_loc, init.value,
1651 init.original_type, asm_name);
1656 tree d = start_decl (declarator, specs, false,
1657 chainon (postfix_attrs,
1660 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1661 NULL_TREE, asm_name);
1663 if (c_parser_next_token_is_keyword (parser, RID_IN))
1666 *objc_foreach_object_declaration = d;
1668 *objc_foreach_object_declaration = error_mark_node;
1671 if (c_parser_next_token_is (parser, CPP_COMMA))
1673 c_parser_consume_token (parser);
1674 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1675 all_prefix_attrs = chainon (c_parser_attributes (parser),
1678 all_prefix_attrs = prefix_attrs;
1681 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1683 c_parser_consume_token (parser);
1686 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1688 /* This can only happen in Objective-C: we found the
1689 'in' that terminates the declaration inside an
1690 Objective-C foreach statement. Do not consume the
1691 token, so that the caller can use it to determine
1692 that this indeed is a foreach context. */
1697 c_parser_error (parser, "expected %<,%> or %<;%>");
1698 c_parser_skip_to_end_of_block_or_statement (parser);
1704 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1705 "%<asm%> or %<__attribute__%>");
1706 c_parser_skip_to_end_of_block_or_statement (parser);
1709 /* Function definition (nested or otherwise). */
1712 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1713 c_push_function_context ();
1715 if (!start_function (specs, declarator, all_prefix_attrs))
1717 /* This can appear in many cases looking nothing like a
1718 function definition, so we don't give a more specific
1719 error suggesting there was one. */
1720 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1721 "or %<__attribute__%>");
1723 c_pop_function_context ();
1727 if (DECL_DECLARED_INLINE_P (current_function_decl))
1728 tv = TV_PARSE_INLINE;
1733 /* Parse old-style parameter declarations. ??? Attributes are
1734 not allowed to start declaration specifiers here because of a
1735 syntax conflict between a function declaration with attribute
1736 suffix and a function definition with an attribute prefix on
1737 first old-style parameter declaration. Following the old
1738 parser, they are not accepted on subsequent old-style
1739 parameter declarations either. However, there is no
1740 ambiguity after the first declaration, nor indeed on the
1741 first as long as we don't allow postfix attributes after a
1742 declarator with a nonempty identifier list in a definition;
1743 and postfix attributes have never been accepted here in
1744 function definitions either. */
1745 while (c_parser_next_token_is_not (parser, CPP_EOF)
1746 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1747 c_parser_declaration_or_fndef (parser, false, false, false,
1749 store_parm_decls ();
1750 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1751 = c_parser_peek_token (parser)->location;
1752 fnbody = c_parser_compound_statement (parser);
1755 tree decl = current_function_decl;
1756 /* Mark nested functions as needing static-chain initially.
1757 lower_nested_functions will recompute it but the
1758 DECL_STATIC_CHAIN flag is also used before that happens,
1759 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1760 DECL_STATIC_CHAIN (decl) = 1;
1763 c_pop_function_context ();
1764 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1777 /* Parse an asm-definition (asm() outside a function body). This is a
1785 c_parser_asm_definition (c_parser *parser)
1787 tree asm_str = c_parser_simple_asm_expr (parser);
1789 cgraph_add_asm_node (asm_str);
1790 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1793 /* Parse a static assertion (C1X N1425 6.7.10).
1795 static_assert-declaration:
1796 static_assert-declaration-no-semi ;
1800 c_parser_static_assert_declaration (c_parser *parser)
1802 c_parser_static_assert_declaration_no_semi (parser);
1804 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1805 c_parser_skip_to_end_of_block_or_statement (parser);
1808 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1811 static_assert-declaration-no-semi:
1812 _Static_assert ( constant-expression , string-literal )
1816 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1818 location_t assert_loc, value_loc;
1822 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1823 assert_loc = c_parser_peek_token (parser)->location;
1827 pedwarn (assert_loc, OPT_pedantic,
1828 "ISO C99 does not support %<_Static_assert%>");
1830 pedwarn (assert_loc, OPT_pedantic,
1831 "ISO C90 does not support %<_Static_assert%>");
1833 c_parser_consume_token (parser);
1834 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1836 value_loc = c_parser_peek_token (parser)->location;
1837 value = c_parser_expr_no_commas (parser, NULL).value;
1838 parser->lex_untranslated_string = true;
1839 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1841 parser->lex_untranslated_string = false;
1844 switch (c_parser_peek_token (parser)->type)
1850 case CPP_UTF8STRING:
1851 string = c_parser_peek_token (parser)->value;
1852 c_parser_consume_token (parser);
1853 parser->lex_untranslated_string = false;
1856 c_parser_error (parser, "expected string literal");
1857 parser->lex_untranslated_string = false;
1860 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1862 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1864 error_at (value_loc, "expression in static assertion is not an integer");
1867 if (TREE_CODE (value) != INTEGER_CST)
1869 value = c_fully_fold (value, false, NULL);
1870 if (TREE_CODE (value) == INTEGER_CST)
1871 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1872 "is not an integer constant expression");
1874 if (TREE_CODE (value) != INTEGER_CST)
1876 error_at (value_loc, "expression in static assertion is not constant");
1879 constant_expression_warning (value);
1880 if (integer_zerop (value))
1881 error_at (assert_loc, "static assertion failed: %E", string);
1884 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1885 6.7), adding them to SPECS (which may already include some).
1886 Storage class specifiers are accepted iff SCSPEC_OK; type
1887 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1888 the start iff START_ATTR_OK.
1890 declaration-specifiers:
1891 storage-class-specifier declaration-specifiers[opt]
1892 type-specifier declaration-specifiers[opt]
1893 type-qualifier declaration-specifiers[opt]
1894 function-specifier declaration-specifiers[opt]
1895 alignment-specifier declaration-specifiers[opt]
1897 Function specifiers (inline) are from C99, and are currently
1898 handled as storage class specifiers, as is __thread. Alignment
1899 specifiers are from C1X.
1901 C90 6.5.1, C99 6.7.1:
1902 storage-class-specifier:
1914 (_Noreturn is new in C1X.)
1916 C90 6.5.2, C99 6.7.2:
1929 [_Imaginary removed in C99 TC2]
1930 struct-or-union-specifier
1934 (_Bool and _Complex are new in C99.)
1936 C90 6.5.3, C99 6.7.3:
1942 address-space-qualifier
1944 (restrict is new in C99.)
1948 declaration-specifiers:
1949 attributes declaration-specifiers[opt]
1955 identifier recognized by the target
1957 storage-class-specifier:
1970 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1971 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1976 class-name objc-protocol-refs[opt]
1977 typedef-name objc-protocol-refs
1982 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1983 bool scspec_ok, bool typespec_ok, bool start_attr_ok,
1984 enum c_lookahead_kind la)
1986 bool attrs_ok = start_attr_ok;
1987 bool seen_type = specs->typespec_kind != ctsk_none;
1990 gcc_assert (la == cla_prefer_id);
1992 while (c_parser_next_token_is (parser, CPP_NAME)
1993 || c_parser_next_token_is (parser, CPP_KEYWORD)
1994 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1996 struct c_typespec t;
1999 location_t loc = c_parser_peek_token (parser)->location;
2001 /* If we cannot accept a type, exit if the next token must start
2002 one. Also, if we already have seen a tagged definition,
2003 a typename would be an error anyway and likely the user
2004 has simply forgotten a semicolon, so we exit. */
2005 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef)
2006 && c_parser_next_tokens_start_typename (parser, la)
2007 && !c_parser_next_token_is_qualifier (parser))
2010 if (c_parser_next_token_is (parser, CPP_NAME))
2012 tree value = c_parser_peek_token (parser)->value;
2013 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
2015 if (kind == C_ID_ADDRSPACE)
2018 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
2019 declspecs_add_addrspace (specs, as);
2020 c_parser_consume_token (parser);
2025 gcc_assert (!c_parser_next_token_is_qualifier (parser));
2027 /* If we cannot accept a type, and the next token must start one,
2028 exit. Do the same if we already have seen a tagged definition,
2029 since it would be an error anyway and likely the user has simply
2030 forgotten a semicolon. */
2031 if (seen_type || !c_parser_next_tokens_start_typename (parser, la))
2034 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2035 a C_ID_CLASSNAME. */
2036 c_parser_consume_token (parser);
2039 if (kind == C_ID_ID)
2041 error ("unknown type name %qE", value);
2042 t.kind = ctsk_typedef;
2043 t.spec = error_mark_node;
2045 else if (kind == C_ID_TYPENAME
2046 && (!c_dialect_objc ()
2047 || c_parser_next_token_is_not (parser, CPP_LESS)))
2049 t.kind = ctsk_typedef;
2050 /* For a typedef name, record the meaning, not the name.
2051 In case of 'foo foo, bar;'. */
2052 t.spec = lookup_name (value);
2056 tree proto = NULL_TREE;
2057 gcc_assert (c_dialect_objc ());
2059 if (c_parser_next_token_is (parser, CPP_LESS))
2060 proto = c_parser_objc_protocol_refs (parser);
2061 t.spec = objc_get_protocol_qualified_type (value, proto);
2064 t.expr_const_operands = true;
2065 declspecs_add_type (loc, specs, t);
2068 if (c_parser_next_token_is (parser, CPP_LESS))
2070 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2071 nisse@lysator.liu.se. */
2073 gcc_assert (c_dialect_objc ());
2074 if (!typespec_ok || seen_type)
2076 proto = c_parser_objc_protocol_refs (parser);
2078 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
2080 t.expr_const_operands = true;
2081 declspecs_add_type (loc, specs, t);
2084 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
2085 switch (c_parser_peek_token (parser)->keyword)
2098 /* TODO: Distinguish between function specifiers (inline, noreturn)
2099 and storage class specifiers, either here or in
2100 declspecs_add_scspec. */
2101 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
2102 c_parser_consume_token (parser);
2126 if (c_dialect_objc ())
2127 parser->objc_need_raw_identifier = true;
2128 t.kind = ctsk_resword;
2129 t.spec = c_parser_peek_token (parser)->value;
2131 t.expr_const_operands = true;
2132 declspecs_add_type (loc, specs, t);
2133 c_parser_consume_token (parser);
2140 t = c_parser_enum_specifier (parser);
2141 declspecs_add_type (loc, specs, t);
2149 t = c_parser_struct_or_union_specifier (parser);
2150 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
2151 declspecs_add_type (loc, specs, t);
2154 /* ??? The old parser rejected typeof after other type
2155 specifiers, but is a syntax error the best way of
2157 if (!typespec_ok || seen_type)
2161 t = c_parser_typeof_specifier (parser);
2162 declspecs_add_type (loc, specs, t);
2168 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
2169 c_parser_consume_token (parser);
2174 attrs = c_parser_attributes (parser);
2175 declspecs_add_attrs (specs, attrs);
2178 align = c_parser_alignas_specifier (parser);
2179 declspecs_add_alignas (specs, align);
2188 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2191 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2192 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2193 enum attributes[opt] identifier
2195 The form with trailing comma is new in C99. The forms with
2196 attributes are GNU extensions. In GNU C, we accept any expression
2197 without commas in the syntax (assignment expressions, not just
2198 conditional expressions); assignment expressions will be diagnosed
2203 enumerator-list , enumerator
2206 enumeration-constant
2207 enumeration-constant = constant-expression
2210 static struct c_typespec
2211 c_parser_enum_specifier (c_parser *parser)
2213 struct c_typespec ret;
2215 tree ident = NULL_TREE;
2216 location_t enum_loc;
2217 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2218 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2219 enum_loc = c_parser_peek_token (parser)->location;
2220 c_parser_consume_token (parser);
2221 attrs = c_parser_attributes (parser);
2222 enum_loc = c_parser_peek_token (parser)->location;
2223 /* Set the location in case we create a decl now. */
2224 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2225 if (c_parser_next_token_is (parser, CPP_NAME))
2227 ident = c_parser_peek_token (parser)->value;
2228 ident_loc = c_parser_peek_token (parser)->location;
2229 enum_loc = ident_loc;
2230 c_parser_consume_token (parser);
2232 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2234 /* Parse an enum definition. */
2235 struct c_enum_contents the_enum;
2238 /* We chain the enumerators in reverse order, then put them in
2239 forward order at the end. */
2241 timevar_push (TV_PARSE_ENUM);
2242 type = start_enum (enum_loc, &the_enum, ident);
2244 c_parser_consume_token (parser);
2252 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2253 location_t decl_loc, value_loc;
2254 if (c_parser_next_token_is_not (parser, CPP_NAME))
2256 c_parser_error (parser, "expected identifier");
2257 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2258 values = error_mark_node;
2261 token = c_parser_peek_token (parser);
2262 enum_id = token->value;
2263 /* Set the location in case we create a decl now. */
2264 c_parser_set_source_position_from_token (token);
2265 decl_loc = value_loc = token->location;
2266 c_parser_consume_token (parser);
2267 if (c_parser_next_token_is (parser, CPP_EQ))
2269 c_parser_consume_token (parser);
2270 value_loc = c_parser_peek_token (parser)->location;
2271 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2274 enum_value = NULL_TREE;
2275 enum_decl = build_enumerator (decl_loc, value_loc,
2276 &the_enum, enum_id, enum_value);
2277 TREE_CHAIN (enum_decl) = values;
2280 if (c_parser_next_token_is (parser, CPP_COMMA))
2282 comma_loc = c_parser_peek_token (parser)->location;
2284 c_parser_consume_token (parser);
2286 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2288 if (seen_comma && !flag_isoc99)
2289 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2290 c_parser_consume_token (parser);
2295 c_parser_error (parser, "expected %<,%> or %<}%>");
2296 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2297 values = error_mark_node;
2301 postfix_attrs = c_parser_attributes (parser);
2302 ret.spec = finish_enum (type, nreverse (values),
2303 chainon (attrs, postfix_attrs));
2304 ret.kind = ctsk_tagdef;
2305 ret.expr = NULL_TREE;
2306 ret.expr_const_operands = true;
2307 timevar_pop (TV_PARSE_ENUM);
2312 c_parser_error (parser, "expected %<{%>");
2313 ret.spec = error_mark_node;
2314 ret.kind = ctsk_tagref;
2315 ret.expr = NULL_TREE;
2316 ret.expr_const_operands = true;
2319 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2320 /* In ISO C, enumerated types can be referred to only if already
2322 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2325 pedwarn (enum_loc, OPT_pedantic,
2326 "ISO C forbids forward references to %<enum%> types");
2331 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2333 struct-or-union-specifier:
2334 struct-or-union attributes[opt] identifier[opt]
2335 { struct-contents } attributes[opt]
2336 struct-or-union attributes[opt] identifier
2339 struct-declaration-list
2341 struct-declaration-list:
2342 struct-declaration ;
2343 struct-declaration-list struct-declaration ;
2350 struct-declaration-list struct-declaration
2352 struct-declaration-list:
2353 struct-declaration-list ;
2356 (Note that in the syntax here, unlike that in ISO C, the semicolons
2357 are included here rather than in struct-declaration, in order to
2358 describe the syntax with extra semicolons and missing semicolon at
2363 struct-declaration-list:
2364 @defs ( class-name )
2366 (Note this does not include a trailing semicolon, but can be
2367 followed by further declarations, and gets a pedwarn-if-pedantic
2368 when followed by a semicolon.) */
2370 static struct c_typespec
2371 c_parser_struct_or_union_specifier (c_parser *parser)
2373 struct c_typespec ret;
2375 tree ident = NULL_TREE;
2376 location_t struct_loc;
2377 location_t ident_loc = UNKNOWN_LOCATION;
2378 enum tree_code code;
2379 switch (c_parser_peek_token (parser)->keyword)
2390 struct_loc = c_parser_peek_token (parser)->location;
2391 c_parser_consume_token (parser);
2392 attrs = c_parser_attributes (parser);
2394 /* Set the location in case we create a decl now. */
2395 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2397 if (c_parser_next_token_is (parser, CPP_NAME))
2399 ident = c_parser_peek_token (parser)->value;
2400 ident_loc = c_parser_peek_token (parser)->location;
2401 struct_loc = ident_loc;
2402 c_parser_consume_token (parser);
2404 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2406 /* Parse a struct or union definition. Start the scope of the
2407 tag before parsing components. */
2408 struct c_struct_parse_info *struct_info;
2409 tree type = start_struct (struct_loc, code, ident, &struct_info);
2411 /* We chain the components in reverse order, then put them in
2412 forward order at the end. Each struct-declaration may
2413 declare multiple components (comma-separated), so we must use
2414 chainon to join them, although when parsing each
2415 struct-declaration we can use TREE_CHAIN directly.
2417 The theory behind all this is that there will be more
2418 semicolon separated fields than comma separated fields, and
2419 so we'll be minimizing the number of node traversals required
2422 timevar_push (TV_PARSE_STRUCT);
2423 contents = NULL_TREE;
2424 c_parser_consume_token (parser);
2425 /* Handle the Objective-C @defs construct,
2426 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2427 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2430 gcc_assert (c_dialect_objc ());
2431 c_parser_consume_token (parser);
2432 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2434 if (c_parser_next_token_is (parser, CPP_NAME)
2435 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2437 name = c_parser_peek_token (parser)->value;
2438 c_parser_consume_token (parser);
2442 c_parser_error (parser, "expected class name");
2443 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2446 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2448 contents = nreverse (objc_get_class_ivars (name));
2451 /* Parse the struct-declarations and semicolons. Problems with
2452 semicolons are diagnosed here; empty structures are diagnosed
2457 /* Parse any stray semicolon. */
2458 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2460 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2461 "extra semicolon in struct or union specified");
2462 c_parser_consume_token (parser);
2465 /* Stop if at the end of the struct or union contents. */
2466 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2468 c_parser_consume_token (parser);
2471 /* Accept #pragmas at struct scope. */
2472 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2474 c_parser_pragma (parser, pragma_external);
2477 /* Parse some comma-separated declarations, but not the
2478 trailing semicolon if any. */
2479 decls = c_parser_struct_declaration (parser);
2480 contents = chainon (decls, contents);
2481 /* If no semicolon follows, either we have a parse error or
2482 are at the end of the struct or union and should
2484 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2485 c_parser_consume_token (parser);
2488 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2489 pedwarn (c_parser_peek_token (parser)->location, 0,
2490 "no semicolon at end of struct or union");
2491 else if (parser->error
2492 || !c_parser_next_token_starts_declspecs (parser))
2494 c_parser_error (parser, "expected %<;%>");
2495 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2499 /* If we come here, we have already emitted an error
2500 for an expected `;', identifier or `(', and we also
2501 recovered already. Go on with the next field. */
2504 postfix_attrs = c_parser_attributes (parser);
2505 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2506 chainon (attrs, postfix_attrs), struct_info);
2507 ret.kind = ctsk_tagdef;
2508 ret.expr = NULL_TREE;
2509 ret.expr_const_operands = true;
2510 timevar_pop (TV_PARSE_STRUCT);
2515 c_parser_error (parser, "expected %<{%>");
2516 ret.spec = error_mark_node;
2517 ret.kind = ctsk_tagref;
2518 ret.expr = NULL_TREE;
2519 ret.expr_const_operands = true;
2522 ret = parser_xref_tag (ident_loc, code, ident);
2526 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2527 the trailing semicolon.
2530 specifier-qualifier-list struct-declarator-list
2531 static_assert-declaration-no-semi
2533 specifier-qualifier-list:
2534 type-specifier specifier-qualifier-list[opt]
2535 type-qualifier specifier-qualifier-list[opt]
2536 attributes specifier-qualifier-list[opt]
2538 struct-declarator-list:
2540 struct-declarator-list , attributes[opt] struct-declarator
2543 declarator attributes[opt]
2544 declarator[opt] : constant-expression attributes[opt]
2549 __extension__ struct-declaration
2550 specifier-qualifier-list
2552 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2553 of attributes where shown is a GNU extension. In GNU C, we accept
2554 any expression without commas in the syntax (assignment
2555 expressions, not just conditional expressions); assignment
2556 expressions will be diagnosed as non-constant. */
2559 c_parser_struct_declaration (c_parser *parser)
2561 struct c_declspecs *specs;
2563 tree all_prefix_attrs;
2565 location_t decl_loc;
2566 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2570 ext = disable_extension_diagnostics ();
2571 c_parser_consume_token (parser);
2572 decl = c_parser_struct_declaration (parser);
2573 restore_extension_diagnostics (ext);
2576 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2578 c_parser_static_assert_declaration_no_semi (parser);
2581 specs = build_null_declspecs ();
2582 decl_loc = c_parser_peek_token (parser)->location;
2583 c_parser_declspecs (parser, specs, false, true, true, cla_nonabstract_decl);
2586 if (!specs->declspecs_seen_p)
2588 c_parser_error (parser, "expected specifier-qualifier-list");
2591 finish_declspecs (specs);
2592 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2593 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2596 if (specs->typespec_kind == ctsk_none)
2598 pedwarn (decl_loc, OPT_pedantic,
2599 "ISO C forbids member declarations with no members");
2600 shadow_tag_warned (specs, pedantic);
2605 /* Support for unnamed structs or unions as members of
2606 structs or unions (which is [a] useful and [b] supports
2610 ret = grokfield (c_parser_peek_token (parser)->location,
2611 build_id_declarator (NULL_TREE), specs,
2614 decl_attributes (&ret, attrs, 0);
2619 /* Provide better error recovery. Note that a type name here is valid,
2620 and will be treated as a field name. */
2621 if (specs->typespec_kind == ctsk_tagdef
2622 && TREE_CODE (specs->type) != ENUMERAL_TYPE
2623 && c_parser_next_token_starts_declspecs (parser)
2624 && !c_parser_next_token_is (parser, CPP_NAME))
2626 c_parser_error (parser, "expected %<;%>, identifier or %<(%>");
2627 parser->error = false;
2631 pending_xref_error ();
2632 prefix_attrs = specs->attrs;
2633 all_prefix_attrs = prefix_attrs;
2634 specs->attrs = NULL_TREE;
2638 /* Declaring one or more declarators or un-named bit-fields. */
2639 struct c_declarator *declarator;
2641 if (c_parser_next_token_is (parser, CPP_COLON))
2642 declarator = build_id_declarator (NULL_TREE);
2644 declarator = c_parser_declarator (parser,
2645 specs->typespec_kind != ctsk_none,
2646 C_DTR_NORMAL, &dummy);
2647 if (declarator == NULL)
2649 c_parser_skip_to_end_of_block_or_statement (parser);
2652 if (c_parser_next_token_is (parser, CPP_COLON)
2653 || c_parser_next_token_is (parser, CPP_COMMA)
2654 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2655 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2656 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2658 tree postfix_attrs = NULL_TREE;
2659 tree width = NULL_TREE;
2661 if (c_parser_next_token_is (parser, CPP_COLON))
2663 c_parser_consume_token (parser);
2664 width = c_parser_expr_no_commas (parser, NULL).value;
2666 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2667 postfix_attrs = c_parser_attributes (parser);
2668 d = grokfield (c_parser_peek_token (parser)->location,
2669 declarator, specs, width, &all_prefix_attrs);
2670 decl_attributes (&d, chainon (postfix_attrs,
2671 all_prefix_attrs), 0);
2672 DECL_CHAIN (d) = decls;
2674 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2675 all_prefix_attrs = chainon (c_parser_attributes (parser),
2678 all_prefix_attrs = prefix_attrs;
2679 if (c_parser_next_token_is (parser, CPP_COMMA))
2680 c_parser_consume_token (parser);
2681 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2682 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2684 /* Semicolon consumed in caller. */
2689 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2695 c_parser_error (parser,
2696 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2697 "%<__attribute__%>");
2704 /* Parse a typeof specifier (a GNU extension).
2707 typeof ( expression )
2708 typeof ( type-name )
2711 static struct c_typespec
2712 c_parser_typeof_specifier (c_parser *parser)
2714 struct c_typespec ret;
2715 ret.kind = ctsk_typeof;
2716 ret.spec = error_mark_node;
2717 ret.expr = NULL_TREE;
2718 ret.expr_const_operands = true;
2719 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2720 c_parser_consume_token (parser);
2721 c_inhibit_evaluation_warnings++;
2723 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2725 c_inhibit_evaluation_warnings--;
2729 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2731 struct c_type_name *type = c_parser_type_name (parser);
2732 c_inhibit_evaluation_warnings--;
2736 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2737 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2743 location_t here = c_parser_peek_token (parser)->location;
2744 struct c_expr expr = c_parser_expression (parser);
2745 c_inhibit_evaluation_warnings--;
2747 if (TREE_CODE (expr.value) == COMPONENT_REF
2748 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2749 error_at (here, "%<typeof%> applied to a bit-field");
2750 mark_exp_read (expr.value);
2751 ret.spec = TREE_TYPE (expr.value);
2752 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2753 /* This is returned with the type so that when the type is
2754 evaluated, this can be evaluated. */
2756 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2757 pop_maybe_used (was_vm);
2759 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2763 /* Parse an alignment-specifier.
2767 alignment-specifier:
2768 _Alignas ( type-name )
2769 _Alignas ( constant-expression )
2773 c_parser_alignas_specifier (c_parser * parser)
2775 tree ret = error_mark_node;
2776 location_t loc = c_parser_peek_token (parser)->location;
2777 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS));
2778 c_parser_consume_token (parser);
2782 pedwarn (loc, OPT_pedantic,
2783 "ISO C99 does not support %<_Alignas%>");
2785 pedwarn (loc, OPT_pedantic,
2786 "ISO C90 does not support %<_Alignas%>");
2788 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2790 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
2792 struct c_type_name *type = c_parser_type_name (parser);
2794 ret = c_alignof (loc, groktypename (type, NULL, NULL));
2797 ret = c_parser_expr_no_commas (parser, NULL).value;
2798 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2802 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2803 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2804 be redeclared; otherwise it may not. KIND indicates which kind of
2805 declarator is wanted. Returns a valid declarator except in the
2806 case of a syntax error in which case NULL is returned. *SEEN_ID is
2807 set to true if an identifier being declared is seen; this is used
2808 to diagnose bad forms of abstract array declarators and to
2809 determine whether an identifier list is syntactically permitted.
2812 pointer[opt] direct-declarator
2816 ( attributes[opt] declarator )
2817 direct-declarator array-declarator
2818 direct-declarator ( parameter-type-list )
2819 direct-declarator ( identifier-list[opt] )
2822 * type-qualifier-list[opt]
2823 * type-qualifier-list[opt] pointer
2825 type-qualifier-list:
2828 type-qualifier-list type-qualifier
2829 type-qualifier-list attributes
2831 parameter-type-list:
2833 parameter-list , ...
2836 parameter-declaration
2837 parameter-list , parameter-declaration
2839 parameter-declaration:
2840 declaration-specifiers declarator attributes[opt]
2841 declaration-specifiers abstract-declarator[opt] attributes[opt]
2845 identifier-list , identifier
2847 abstract-declarator:
2849 pointer[opt] direct-abstract-declarator
2851 direct-abstract-declarator:
2852 ( attributes[opt] abstract-declarator )
2853 direct-abstract-declarator[opt] array-declarator
2854 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2859 direct-declarator ( parameter-forward-declarations
2860 parameter-type-list[opt] )
2862 direct-abstract-declarator:
2863 direct-abstract-declarator[opt] ( parameter-forward-declarations
2864 parameter-type-list[opt] )
2866 parameter-forward-declarations:
2868 parameter-forward-declarations parameter-list ;
2870 The uses of attributes shown above are GNU extensions.
2872 Some forms of array declarator are not included in C99 in the
2873 syntax for abstract declarators; these are disallowed elsewhere.
2874 This may be a defect (DR#289).
2876 This function also accepts an omitted abstract declarator as being
2877 an abstract declarator, although not part of the formal syntax. */
2879 static struct c_declarator *
2880 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2883 /* Parse any initial pointer part. */
2884 if (c_parser_next_token_is (parser, CPP_MULT))
2886 struct c_declspecs *quals_attrs = build_null_declspecs ();
2887 struct c_declarator *inner;
2888 c_parser_consume_token (parser);
2889 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
2890 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2894 return make_pointer_declarator (quals_attrs, inner);
2896 /* Now we have a direct declarator, direct abstract declarator or
2897 nothing (which counts as a direct abstract declarator here). */
2898 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2901 /* Parse a direct declarator or direct abstract declarator; arguments
2902 as c_parser_declarator. */
2904 static struct c_declarator *
2905 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2908 /* The direct declarator must start with an identifier (possibly
2909 omitted) or a parenthesized declarator (possibly abstract). In
2910 an ordinary declarator, initial parentheses must start a
2911 parenthesized declarator. In an abstract declarator or parameter
2912 declarator, they could start a parenthesized declarator or a
2913 parameter list. To tell which, the open parenthesis and any
2914 following attributes must be read. If a declaration specifier
2915 follows, then it is a parameter list; if the specifier is a
2916 typedef name, there might be an ambiguity about redeclaring it,
2917 which is resolved in the direction of treating it as a typedef
2918 name. If a close parenthesis follows, it is also an empty
2919 parameter list, as the syntax does not permit empty abstract
2920 declarators. Otherwise, it is a parenthesized declarator (in
2921 which case the analysis may be repeated inside it, recursively).
2923 ??? There is an ambiguity in a parameter declaration "int
2924 (__attribute__((foo)) x)", where x is not a typedef name: it
2925 could be an abstract declarator for a function, or declare x with
2926 parentheses. The proper resolution of this ambiguity needs
2927 documenting. At present we follow an accident of the old
2928 parser's implementation, whereby the first parameter must have
2929 some declaration specifiers other than just attributes. Thus as
2930 a parameter declaration it is treated as a parenthesized
2931 parameter named x, and as an abstract declarator it is
2934 ??? Also following the old parser, attributes inside an empty
2935 parameter list are ignored, making it a list not yielding a
2936 prototype, rather than giving an error or making it have one
2937 parameter with implicit type int.
2939 ??? Also following the old parser, typedef names may be
2940 redeclared in declarators, but not Objective-C class names. */
2942 if (kind != C_DTR_ABSTRACT
2943 && c_parser_next_token_is (parser, CPP_NAME)
2945 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2946 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2947 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2949 struct c_declarator *inner
2950 = build_id_declarator (c_parser_peek_token (parser)->value);
2952 inner->id_loc = c_parser_peek_token (parser)->location;
2953 c_parser_consume_token (parser);
2954 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2957 if (kind != C_DTR_NORMAL
2958 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2960 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2961 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2964 /* Either we are at the end of an abstract declarator, or we have
2967 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2970 struct c_declarator *inner;
2971 c_parser_consume_token (parser);
2972 attrs = c_parser_attributes (parser);
2973 if (kind != C_DTR_NORMAL
2974 && (c_parser_next_token_starts_declspecs (parser)
2975 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2977 struct c_arg_info *args
2978 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2985 = build_function_declarator (args,
2986 build_id_declarator (NULL_TREE));
2987 return c_parser_direct_declarator_inner (parser, *seen_id,
2991 /* A parenthesized declarator. */
2992 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2993 if (inner != NULL && attrs != NULL)
2994 inner = build_attrs_declarator (attrs, inner);
2995 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2997 c_parser_consume_token (parser);
3001 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
3005 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3012 if (kind == C_DTR_NORMAL)
3014 c_parser_error (parser, "expected identifier or %<(%>");
3018 return build_id_declarator (NULL_TREE);
3022 /* Parse part of a direct declarator or direct abstract declarator,
3023 given that some (in INNER) has already been parsed; ID_PRESENT is
3024 true if an identifier is present, false for an abstract
3027 static struct c_declarator *
3028 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
3029 struct c_declarator *inner)
3031 /* Parse a sequence of array declarators and parameter lists. */
3032 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
3034 location_t brace_loc = c_parser_peek_token (parser)->location;
3035 struct c_declarator *declarator;
3036 struct c_declspecs *quals_attrs = build_null_declspecs ();
3040 c_parser_consume_token (parser);
3041 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
3042 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
3044 c_parser_consume_token (parser);
3045 if (static_seen && !quals_attrs->declspecs_seen_p)
3046 c_parser_declspecs (parser, quals_attrs, false, false, true, cla_prefer_id);
3047 if (!quals_attrs->declspecs_seen_p)
3049 /* If "static" is present, there must be an array dimension.
3050 Otherwise, there may be a dimension, "*", or no
3055 dimen = c_parser_expr_no_commas (parser, NULL).value;
3059 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3064 else if (c_parser_next_token_is (parser, CPP_MULT))
3066 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
3070 c_parser_consume_token (parser);
3075 dimen = c_parser_expr_no_commas (parser, NULL).value;
3081 dimen = c_parser_expr_no_commas (parser, NULL).value;
3084 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3085 c_parser_consume_token (parser);
3088 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3093 mark_exp_read (dimen);
3094 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
3095 static_seen, star_seen);
3096 if (declarator == NULL)
3098 inner = set_array_declarator_inner (declarator, inner);
3099 return c_parser_direct_declarator_inner (parser, id_present, inner);
3101 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
3104 struct c_arg_info *args;
3105 c_parser_consume_token (parser);
3106 attrs = c_parser_attributes (parser);
3107 args = c_parser_parms_declarator (parser, id_present, attrs);
3112 inner = build_function_declarator (args, inner);
3113 return c_parser_direct_declarator_inner (parser, id_present, inner);
3119 /* Parse a parameter list or identifier list, including the closing
3120 parenthesis but not the opening one. ATTRS are the attributes at
3121 the start of the list. ID_LIST_OK is true if an identifier list is
3122 acceptable; such a list must not have attributes at the start. */
3124 static struct c_arg_info *
3125 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
3128 declare_parm_level ();
3129 /* If the list starts with an identifier, it is an identifier list.
3130 Otherwise, it is either a prototype list or an empty list. */
3133 && c_parser_next_token_is (parser, CPP_NAME)
3134 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3136 /* Look ahead to detect typos in type names. */
3137 && c_parser_peek_2nd_token (parser)->type != CPP_NAME
3138 && c_parser_peek_2nd_token (parser)->type != CPP_MULT
3139 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN
3140 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE)
3142 tree list = NULL_TREE, *nextp = &list;
3143 while (c_parser_next_token_is (parser, CPP_NAME)
3144 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
3146 *nextp = build_tree_list (NULL_TREE,
3147 c_parser_peek_token (parser)->value);
3148 nextp = & TREE_CHAIN (*nextp);
3149 c_parser_consume_token (parser);
3150 if (c_parser_next_token_is_not (parser, CPP_COMMA))
3152 c_parser_consume_token (parser);
3153 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3155 c_parser_error (parser, "expected identifier");
3159 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3161 struct c_arg_info *ret = build_arg_info ();
3163 c_parser_consume_token (parser);
3169 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3177 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs,
3184 /* Parse a parameter list (possibly empty), including the closing
3185 parenthesis but not the opening one. ATTRS are the attributes at
3186 the start of the list. EXPR is NULL or an expression that needs to
3187 be evaluated for the side effects of array size expressions in the
3190 static struct c_arg_info *
3191 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
3193 bool bad_parm = false;
3195 /* ??? Following the old parser, forward parameter declarations may
3196 use abstract declarators, and if no real parameter declarations
3197 follow the forward declarations then this is not diagnosed. Also
3198 note as above that attributes are ignored as the only contents of
3199 the parentheses, or as the only contents after forward
3201 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3203 struct c_arg_info *ret = build_arg_info ();
3204 c_parser_consume_token (parser);
3207 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3209 struct c_arg_info *ret = build_arg_info ();
3211 if (flag_allow_parameterless_variadic_functions)
3213 /* F (...) is allowed. */
3214 ret->types = NULL_TREE;
3218 /* Suppress -Wold-style-definition for this case. */
3219 ret->types = error_mark_node;
3220 error_at (c_parser_peek_token (parser)->location,
3221 "ISO C requires a named argument before %<...%>");
3223 c_parser_consume_token (parser);
3224 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3226 c_parser_consume_token (parser);
3231 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3236 /* Nonempty list of parameters, either terminated with semicolon
3237 (forward declarations; recurse) or with close parenthesis (normal
3238 function) or with ", ... )" (variadic function). */
3241 /* Parse a parameter. */
3242 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
3247 push_parm_decl (parm, &expr);
3248 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3251 c_parser_consume_token (parser);
3252 mark_forward_parm_decls ();
3253 new_attrs = c_parser_attributes (parser);
3254 return c_parser_parms_list_declarator (parser, new_attrs, expr);
3256 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3258 c_parser_consume_token (parser);
3262 return get_parm_info (false, expr);
3264 if (!c_parser_require (parser, CPP_COMMA,
3265 "expected %<;%>, %<,%> or %<)%>"))
3267 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3270 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3272 c_parser_consume_token (parser);
3273 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3275 c_parser_consume_token (parser);
3279 return get_parm_info (true, expr);
3283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3291 /* Parse a parameter declaration. ATTRS are the attributes at the
3292 start of the declaration if it is the first parameter. */
3294 static struct c_parm *
3295 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3297 struct c_declspecs *specs;
3298 struct c_declarator *declarator;
3300 tree postfix_attrs = NULL_TREE;
3302 if (!c_parser_next_token_starts_declspecs (parser))
3304 c_token *token = c_parser_peek_token (parser);
3307 c_parser_set_source_position_from_token (token);
3308 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
3310 error ("unknown type name %qE", token->value);
3311 parser->error = true;
3313 /* ??? In some Objective-C cases '...' isn't applicable so there
3314 should be a different message. */
3316 c_parser_error (parser,
3317 "expected declaration specifiers or %<...%>");
3318 c_parser_skip_to_end_of_parameter (parser);
3321 specs = build_null_declspecs ();
3324 declspecs_add_attrs (specs, attrs);
3327 c_parser_declspecs (parser, specs, true, true, true, cla_nonabstract_decl);
3328 finish_declspecs (specs);
3329 pending_xref_error ();
3330 prefix_attrs = specs->attrs;
3331 specs->attrs = NULL_TREE;
3332 declarator = c_parser_declarator (parser,
3333 specs->typespec_kind != ctsk_none,
3334 C_DTR_PARM, &dummy);
3335 if (declarator == NULL)
3337 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3340 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3341 postfix_attrs = c_parser_attributes (parser);
3342 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3346 /* Parse a string literal in an asm expression. It should not be
3347 translated, and wide string literals are an error although
3348 permitted by the syntax. This is a GNU extension.
3353 ??? At present, following the old parser, the caller needs to have
3354 set lex_untranslated_string to 1. It would be better to follow the
3355 C++ parser rather than using this kludge. */
3358 c_parser_asm_string_literal (c_parser *parser)
3361 int save_flag = warn_overlength_strings;
3362 warn_overlength_strings = 0;
3363 if (c_parser_next_token_is (parser, CPP_STRING))
3365 str = c_parser_peek_token (parser)->value;
3366 c_parser_consume_token (parser);
3368 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3370 error_at (c_parser_peek_token (parser)->location,
3371 "wide string literal in %<asm%>");
3372 str = build_string (1, "");
3373 c_parser_consume_token (parser);
3377 c_parser_error (parser, "expected string literal");
3380 warn_overlength_strings = save_flag;
3384 /* Parse a simple asm expression. This is used in restricted
3385 contexts, where a full expression with inputs and outputs does not
3386 make sense. This is a GNU extension.
3389 asm ( asm-string-literal )
3393 c_parser_simple_asm_expr (c_parser *parser)
3396 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3397 /* ??? Follow the C++ parser rather than using the
3398 lex_untranslated_string kludge. */
3399 parser->lex_untranslated_string = true;
3400 c_parser_consume_token (parser);
3401 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3403 parser->lex_untranslated_string = false;
3406 str = c_parser_asm_string_literal (parser);
3407 parser->lex_untranslated_string = false;
3408 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3410 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3416 /* Parse (possibly empty) attributes. This is a GNU extension.
3420 attributes attribute
3423 __attribute__ ( ( attribute-list ) )
3427 attribute_list , attrib
3432 any-word ( identifier )
3433 any-word ( identifier , nonempty-expr-list )
3434 any-word ( expr-list )
3436 where the "identifier" must not be declared as a type, and
3437 "any-word" may be any identifier (including one declared as a
3438 type), a reserved word storage class specifier, type specifier or
3439 type qualifier. ??? This still leaves out most reserved keywords
3440 (following the old parser), shouldn't we include them, and why not
3441 allow identifiers declared as types to start the arguments? */
3444 c_parser_attributes (c_parser *parser)
3446 tree attrs = NULL_TREE;
3447 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3449 /* ??? Follow the C++ parser rather than using the
3450 lex_untranslated_string kludge. */
3451 parser->lex_untranslated_string = true;
3452 c_parser_consume_token (parser);
3453 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3455 parser->lex_untranslated_string = false;
3458 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3460 parser->lex_untranslated_string = false;
3461 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3464 /* Parse the attribute list. */
3465 while (c_parser_next_token_is (parser, CPP_COMMA)
3466 || c_parser_next_token_is (parser, CPP_NAME)
3467 || c_parser_next_token_is (parser, CPP_KEYWORD))
3469 tree attr, attr_name, attr_args;
3470 VEC(tree,gc) *expr_list;
3471 if (c_parser_next_token_is (parser, CPP_COMMA))
3473 c_parser_consume_token (parser);
3476 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3478 /* ??? See comment above about what keywords are
3481 switch (c_parser_peek_token (parser)->keyword)
3520 /* Accept __attribute__((__const)) as __attribute__((const))
3523 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3526 attr_name = c_parser_peek_token (parser)->value;
3527 c_parser_consume_token (parser);
3528 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3530 attr = build_tree_list (attr_name, NULL_TREE);
3531 attrs = chainon (attrs, attr);
3534 c_parser_consume_token (parser);
3535 /* Parse the attribute contents. If they start with an
3536 identifier which is followed by a comma or close
3537 parenthesis, then the arguments start with that
3538 identifier; otherwise they are an expression list.
3539 In objective-c the identifier may be a classname. */
3540 if (c_parser_next_token_is (parser, CPP_NAME)
3541 && (c_parser_peek_token (parser)->id_kind == C_ID_ID
3542 || (c_dialect_objc ()
3543 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
3544 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3545 || (c_parser_peek_2nd_token (parser)->type
3546 == CPP_CLOSE_PAREN)))
3548 tree arg1 = c_parser_peek_token (parser)->value;
3549 c_parser_consume_token (parser);
3550 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3551 attr_args = build_tree_list (NULL_TREE, arg1);
3555 c_parser_consume_token (parser);
3556 expr_list = c_parser_expr_list (parser, false, true, NULL);
3557 tree_list = build_tree_list_vec (expr_list);
3558 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3559 release_tree_vector (expr_list);
3564 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3565 attr_args = NULL_TREE;
3568 expr_list = c_parser_expr_list (parser, false, true, NULL);
3569 attr_args = build_tree_list_vec (expr_list);
3570 release_tree_vector (expr_list);
3573 attr = build_tree_list (attr_name, attr_args);
3574 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3575 c_parser_consume_token (parser);
3578 parser->lex_untranslated_string = false;
3579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3583 attrs = chainon (attrs, attr);
3585 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3586 c_parser_consume_token (parser);
3589 parser->lex_untranslated_string = false;
3590 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3594 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3595 c_parser_consume_token (parser);
3598 parser->lex_untranslated_string = false;
3599 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3603 parser->lex_untranslated_string = false;
3608 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3611 specifier-qualifier-list abstract-declarator[opt]
3614 static struct c_type_name *
3615 c_parser_type_name (c_parser *parser)
3617 struct c_declspecs *specs = build_null_declspecs ();
3618 struct c_declarator *declarator;
3619 struct c_type_name *ret;
3621 c_parser_declspecs (parser, specs, false, true, true, cla_prefer_type);
3622 if (!specs->declspecs_seen_p)
3624 c_parser_error (parser, "expected specifier-qualifier-list");
3627 if (specs->type != error_mark_node)
3629 pending_xref_error ();
3630 finish_declspecs (specs);
3632 declarator = c_parser_declarator (parser,
3633 specs->typespec_kind != ctsk_none,
3634 C_DTR_ABSTRACT, &dummy);
3635 if (declarator == NULL)
3637 ret = XOBNEW (&parser_obstack, struct c_type_name);
3639 ret->declarator = declarator;
3643 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3646 assignment-expression
3647 { initializer-list }
3648 { initializer-list , }
3651 designation[opt] initializer
3652 initializer-list , designation[opt] initializer
3659 designator-list designator
3666 [ constant-expression ]
3678 [ constant-expression ... constant-expression ]
3680 Any expression without commas is accepted in the syntax for the
3681 constant-expressions, with non-constant expressions rejected later.
3683 This function is only used for top-level initializers; for nested
3684 ones, see c_parser_initval. */
3686 static struct c_expr
3687 c_parser_initializer (c_parser *parser)
3689 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3690 return c_parser_braced_init (parser, NULL_TREE, false);
3694 location_t loc = c_parser_peek_token (parser)->location;
3695 ret = c_parser_expr_no_commas (parser, NULL);
3696 if (TREE_CODE (ret.value) != STRING_CST
3697 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3698 ret = default_function_array_read_conversion (loc, ret);
3703 /* Parse a braced initializer list. TYPE is the type specified for a
3704 compound literal, and NULL_TREE for other initializers and for
3705 nested braced lists. NESTED_P is true for nested braced lists,
3706 false for the list of a compound literal or the list that is the
3707 top-level initializer in a declaration. */
3709 static struct c_expr
3710 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3713 struct obstack braced_init_obstack;
3714 location_t brace_loc = c_parser_peek_token (parser)->location;
3715 gcc_obstack_init (&braced_init_obstack);
3716 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3717 c_parser_consume_token (parser);
3719 push_init_level (0, &braced_init_obstack);
3721 really_start_incremental_init (type);
3722 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3724 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3728 /* Parse a non-empty initializer list, possibly with a trailing
3732 c_parser_initelt (parser, &braced_init_obstack);
3735 if (c_parser_next_token_is (parser, CPP_COMMA))
3736 c_parser_consume_token (parser);
3739 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3743 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3745 ret.value = error_mark_node;
3746 ret.original_code = ERROR_MARK;
3747 ret.original_type = NULL;
3748 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3749 pop_init_level (0, &braced_init_obstack);
3750 obstack_free (&braced_init_obstack, NULL);
3753 c_parser_consume_token (parser);
3754 ret = pop_init_level (0, &braced_init_obstack);
3755 obstack_free (&braced_init_obstack, NULL);
3759 /* Parse a nested initializer, including designators. */
3762 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3764 /* Parse any designator or designator list. A single array
3765 designator may have the subsequent "=" omitted in GNU C, but a
3766 longer list or a structure member designator may not. */
3767 if (c_parser_next_token_is (parser, CPP_NAME)
3768 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3770 /* Old-style structure member designator. */
3771 set_init_label (c_parser_peek_token (parser)->value,
3772 braced_init_obstack);
3773 /* Use the colon as the error location. */
3774 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3775 "obsolete use of designated initializer with %<:%>");
3776 c_parser_consume_token (parser);
3777 c_parser_consume_token (parser);
3781 /* des_seen is 0 if there have been no designators, 1 if there
3782 has been a single array designator and 2 otherwise. */
3784 /* Location of a designator. */
3785 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3786 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3787 || c_parser_next_token_is (parser, CPP_DOT))
3789 int des_prev = des_seen;
3791 des_loc = c_parser_peek_token (parser)->location;
3794 if (c_parser_next_token_is (parser, CPP_DOT))
3797 c_parser_consume_token (parser);
3798 if (c_parser_next_token_is (parser, CPP_NAME))
3800 set_init_label (c_parser_peek_token (parser)->value,
3801 braced_init_obstack);
3802 c_parser_consume_token (parser);
3807 init.value = error_mark_node;
3808 init.original_code = ERROR_MARK;
3809 init.original_type = NULL;
3810 c_parser_error (parser, "expected identifier");
3811 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3812 process_init_element (init, false, braced_init_obstack);
3819 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3820 /* ??? Following the old parser, [ objc-receiver
3821 objc-message-args ] is accepted as an initializer,
3822 being distinguished from a designator by what follows
3823 the first assignment expression inside the square
3824 brackets, but after a first array designator a
3825 subsequent square bracket is for Objective-C taken to
3826 start an expression, using the obsolete form of
3827 designated initializer without '=', rather than
3828 possibly being a second level of designation: in LALR
3829 terms, the '[' is shifted rather than reducing
3830 designator to designator-list. */
3831 if (des_prev == 1 && c_dialect_objc ())
3833 des_seen = des_prev;
3836 if (des_prev == 0 && c_dialect_objc ())
3838 /* This might be an array designator or an
3839 Objective-C message expression. If the former,
3840 continue parsing here; if the latter, parse the
3841 remainder of the initializer given the starting
3842 primary-expression. ??? It might make sense to
3843 distinguish when des_prev == 1 as well; see
3844 previous comment. */
3846 struct c_expr mexpr;
3847 c_parser_consume_token (parser);
3848 if (c_parser_peek_token (parser)->type == CPP_NAME
3849 && ((c_parser_peek_token (parser)->id_kind
3851 || (c_parser_peek_token (parser)->id_kind
3852 == C_ID_CLASSNAME)))
3854 /* Type name receiver. */
3855 tree id = c_parser_peek_token (parser)->value;
3856 c_parser_consume_token (parser);
3857 rec = objc_get_class_reference (id);
3858 goto parse_message_args;
3860 first = c_parser_expr_no_commas (parser, NULL).value;
3861 mark_exp_read (first);
3862 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3863 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3864 goto array_desig_after_first;
3865 /* Expression receiver. So far only one part
3866 without commas has been parsed; there might be
3867 more of the expression. */
3869 while (c_parser_next_token_is (parser, CPP_COMMA))
3872 location_t comma_loc, exp_loc;
3873 comma_loc = c_parser_peek_token (parser)->location;
3874 c_parser_consume_token (parser);
3875 exp_loc = c_parser_peek_token (parser)->location;
3876 next = c_parser_expr_no_commas (parser, NULL);
3877 next = default_function_array_read_conversion (exp_loc,
3879 rec = build_compound_expr (comma_loc, rec, next.value);
3882 /* Now parse the objc-message-args. */
3883 args = c_parser_objc_message_args (parser);
3884 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3887 = objc_build_message_expr (rec, args);
3888 mexpr.original_code = ERROR_MARK;
3889 mexpr.original_type = NULL;
3890 /* Now parse and process the remainder of the
3891 initializer, starting with this message
3892 expression as a primary-expression. */
3893 c_parser_initval (parser, &mexpr, braced_init_obstack);
3896 c_parser_consume_token (parser);
3897 first = c_parser_expr_no_commas (parser, NULL).value;
3898 mark_exp_read (first);
3899 array_desig_after_first:
3900 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3902 ellipsis_loc = c_parser_peek_token (parser)->location;
3903 c_parser_consume_token (parser);
3904 second = c_parser_expr_no_commas (parser, NULL).value;
3905 mark_exp_read (second);
3909 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3911 c_parser_consume_token (parser);
3912 set_init_index (first, second, braced_init_obstack);
3914 pedwarn (ellipsis_loc, OPT_pedantic,
3915 "ISO C forbids specifying range of elements to initialize");
3918 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3924 if (c_parser_next_token_is (parser, CPP_EQ))
3927 pedwarn (des_loc, OPT_pedantic,
3928 "ISO C90 forbids specifying subobject to initialize");
3929 c_parser_consume_token (parser);
3934 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3935 "obsolete use of designated initializer without %<=%>");
3939 init.value = error_mark_node;
3940 init.original_code = ERROR_MARK;
3941 init.original_type = NULL;
3942 c_parser_error (parser, "expected %<=%>");
3943 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3944 process_init_element (init, false, braced_init_obstack);
3950 c_parser_initval (parser, NULL, braced_init_obstack);
3953 /* Parse a nested initializer; as c_parser_initializer but parses
3954 initializers within braced lists, after any designators have been
3955 applied. If AFTER is not NULL then it is an Objective-C message
3956 expression which is the primary-expression starting the
3960 c_parser_initval (c_parser *parser, struct c_expr *after,
3961 struct obstack * braced_init_obstack)
3964 gcc_assert (!after || c_dialect_objc ());
3965 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3966 init = c_parser_braced_init (parser, NULL_TREE, true);
3969 location_t loc = c_parser_peek_token (parser)->location;
3970 init = c_parser_expr_no_commas (parser, after);
3971 if (init.value != NULL_TREE
3972 && TREE_CODE (init.value) != STRING_CST
3973 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3974 init = default_function_array_read_conversion (loc, init);
3976 process_init_element (init, false, braced_init_obstack);
3979 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3983 { block-item-list[opt] }
3984 { label-declarations block-item-list }
3988 block-item-list block-item
4000 { label-declarations block-item-list }
4003 __extension__ nested-declaration
4004 nested-function-definition
4008 label-declarations label-declaration
4011 __label__ identifier-list ;
4013 Allowing the mixing of declarations and code is new in C99. The
4014 GNU syntax also permits (not shown above) labels at the end of
4015 compound statements, which yield an error. We don't allow labels
4016 on declarations; this might seem like a natural extension, but
4017 there would be a conflict between attributes on the label and
4018 prefix attributes on the declaration. ??? The syntax follows the
4019 old parser in requiring something after label declarations.
4020 Although they are erroneous if the labels declared aren't defined,
4021 is it useful for the syntax to be this way?
4033 c_parser_compound_statement (c_parser *parser)
4036 location_t brace_loc;
4037 brace_loc = c_parser_peek_token (parser)->location;
4038 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
4040 /* Ensure a scope is entered and left anyway to avoid confusion
4041 if we have just prepared to enter a function body. */
4042 stmt = c_begin_compound_stmt (true);
4043 c_end_compound_stmt (brace_loc, stmt, true);
4044 return error_mark_node;
4046 stmt = c_begin_compound_stmt (true);
4047 c_parser_compound_statement_nostart (parser);
4048 return c_end_compound_stmt (brace_loc, stmt, true);
4051 /* Parse a compound statement except for the opening brace. This is
4052 used for parsing both compound statements and statement expressions
4053 (which follow different paths to handling the opening). */
4056 c_parser_compound_statement_nostart (c_parser *parser)
4058 bool last_stmt = false;
4059 bool last_label = false;
4060 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
4061 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4062 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4064 c_parser_consume_token (parser);
4067 mark_valid_location_for_stdc_pragma (true);
4068 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
4070 /* Read zero or more forward-declarations for labels that nested
4071 functions can jump to. */
4072 mark_valid_location_for_stdc_pragma (false);
4073 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
4075 label_loc = c_parser_peek_token (parser)->location;
4076 c_parser_consume_token (parser);
4077 /* Any identifiers, including those declared as type names,
4082 if (c_parser_next_token_is_not (parser, CPP_NAME))
4084 c_parser_error (parser, "expected identifier");
4088 = declare_label (c_parser_peek_token (parser)->value);
4089 C_DECLARED_LABEL_FLAG (label) = 1;
4090 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
4091 c_parser_consume_token (parser);
4092 if (c_parser_next_token_is (parser, CPP_COMMA))
4093 c_parser_consume_token (parser);
4097 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4099 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
4101 /* We must now have at least one statement, label or declaration. */
4102 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
4104 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4105 c_parser_error (parser, "expected declaration or statement");
4106 c_parser_consume_token (parser);
4109 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
4111 location_t loc = c_parser_peek_token (parser)->location;
4112 if (c_parser_next_token_is_keyword (parser, RID_CASE)
4113 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4114 || (c_parser_next_token_is (parser, CPP_NAME)
4115 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4117 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4118 label_loc = c_parser_peek_2nd_token (parser)->location;
4120 label_loc = c_parser_peek_token (parser)->location;
4123 mark_valid_location_for_stdc_pragma (false);
4124 c_parser_label (parser);
4126 else if (!last_label
4127 && c_parser_next_tokens_start_declaration (parser))
4130 mark_valid_location_for_stdc_pragma (false);
4131 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
4134 (pedantic && !flag_isoc99)
4136 : OPT_Wdeclaration_after_statement,
4137 "ISO C90 forbids mixed declarations and code");
4140 else if (!last_label
4141 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4143 /* __extension__ can start a declaration, but is also an
4144 unary operator that can start an expression. Consume all
4145 but the last of a possible series of __extension__ to
4147 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4148 && (c_parser_peek_2nd_token (parser)->keyword
4150 c_parser_consume_token (parser);
4151 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4154 ext = disable_extension_diagnostics ();
4155 c_parser_consume_token (parser);
4157 mark_valid_location_for_stdc_pragma (false);
4158 c_parser_declaration_or_fndef (parser, true, true, true, true,
4160 /* Following the old parser, __extension__ does not
4161 disable this diagnostic. */
4162 restore_extension_diagnostics (ext);
4164 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
4166 : OPT_Wdeclaration_after_statement,
4167 "ISO C90 forbids mixed declarations and code");
4173 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
4175 /* External pragmas, and some omp pragmas, are not associated
4176 with regular c code, and so are not to be considered statements
4177 syntactically. This ensures that the user doesn't put them
4178 places that would turn into syntax errors if the directive
4180 if (c_parser_pragma (parser, pragma_compound))
4181 last_label = false, last_stmt = true;
4183 else if (c_parser_next_token_is (parser, CPP_EOF))
4185 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4186 c_parser_error (parser, "expected declaration or statement");
4189 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4191 if (parser->in_if_block)
4193 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4194 error_at (loc, """expected %<}%> before %<else%>");
4199 error_at (loc, "%<else%> without a previous %<if%>");
4200 c_parser_consume_token (parser);
4209 mark_valid_location_for_stdc_pragma (false);
4210 c_parser_statement_after_labels (parser);
4213 parser->error = false;
4216 error_at (label_loc, "label at end of compound statement");
4217 c_parser_consume_token (parser);
4218 /* Restore the value we started with. */
4219 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
4222 /* Parse a label (C90 6.6.1, C99 6.8.1).
4225 identifier : attributes[opt]
4226 case constant-expression :
4232 case constant-expression ... constant-expression :
4234 The use of attributes on labels is a GNU extension. The syntax in
4235 GNU C accepts any expressions without commas, non-constant
4236 expressions being rejected later. */
4239 c_parser_label (c_parser *parser)
4241 location_t loc1 = c_parser_peek_token (parser)->location;
4242 tree label = NULL_TREE;
4243 if (c_parser_next_token_is_keyword (parser, RID_CASE))
4246 c_parser_consume_token (parser);
4247 exp1 = c_parser_expr_no_commas (parser, NULL).value;
4248 if (c_parser_next_token_is (parser, CPP_COLON))
4250 c_parser_consume_token (parser);
4251 label = do_case (loc1, exp1, NULL_TREE);
4253 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
4255 c_parser_consume_token (parser);
4256 exp2 = c_parser_expr_no_commas (parser, NULL).value;
4257 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4258 label = do_case (loc1, exp1, exp2);
4261 c_parser_error (parser, "expected %<:%> or %<...%>");
4263 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
4265 c_parser_consume_token (parser);
4266 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4267 label = do_case (loc1, NULL_TREE, NULL_TREE);
4271 tree name = c_parser_peek_token (parser)->value;
4274 location_t loc2 = c_parser_peek_token (parser)->location;
4275 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
4276 c_parser_consume_token (parser);
4277 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
4278 c_parser_consume_token (parser);
4279 attrs = c_parser_attributes (parser);
4280 tlab = define_label (loc2, name);
4283 decl_attributes (&tlab, attrs, 0);
4284 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
4289 if (c_parser_next_tokens_start_declaration (parser))
4291 error_at (c_parser_peek_token (parser)->location,
4292 "a label can only be part of a statement and "
4293 "a declaration is not a statement");
4294 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
4295 /*static_assert_ok*/ true,
4296 /*nested*/ true, /*empty_ok*/ false,
4297 /*start_attr_ok*/ true, NULL);
4302 /* Parse a statement (C90 6.6, C99 6.8).
4307 expression-statement
4315 expression-statement:
4318 selection-statement:
4322 iteration-statement:
4331 return expression[opt] ;
4344 objc-throw-statement
4345 objc-try-catch-statement
4346 objc-synchronized-statement
4348 objc-throw-statement:
4362 parallel-for-construct
4363 parallel-sections-construct
4370 parallel-directive structured-block
4373 for-directive iteration-statement
4376 sections-directive section-scope
4379 single-directive structured-block
4381 parallel-for-construct:
4382 parallel-for-directive iteration-statement
4384 parallel-sections-construct:
4385 parallel-sections-directive section-scope
4388 master-directive structured-block
4391 critical-directive structured-block
4394 atomic-directive expression-statement
4397 ordered-directive structured-block */
4400 c_parser_statement (c_parser *parser)
4402 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4403 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4404 || (c_parser_next_token_is (parser, CPP_NAME)
4405 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4406 c_parser_label (parser);
4407 c_parser_statement_after_labels (parser);
4410 /* Parse a statement, other than a labeled statement. */
4413 c_parser_statement_after_labels (c_parser *parser)
4415 location_t loc = c_parser_peek_token (parser)->location;
4416 tree stmt = NULL_TREE;
4417 bool in_if_block = parser->in_if_block;
4418 parser->in_if_block = false;
4419 switch (c_parser_peek_token (parser)->type)
4421 case CPP_OPEN_BRACE:
4422 add_stmt (c_parser_compound_statement (parser));
4425 switch (c_parser_peek_token (parser)->keyword)
4428 c_parser_if_statement (parser);
4431 c_parser_switch_statement (parser);
4434 c_parser_while_statement (parser);
4437 c_parser_do_statement (parser);
4440 c_parser_for_statement (parser);
4443 c_parser_consume_token (parser);
4444 if (c_parser_next_token_is (parser, CPP_NAME))
4446 stmt = c_finish_goto_label (loc,
4447 c_parser_peek_token (parser)->value);
4448 c_parser_consume_token (parser);
4450 else if (c_parser_next_token_is (parser, CPP_MULT))
4454 c_parser_consume_token (parser);
4455 val = c_parser_expression (parser).value;
4456 mark_exp_read (val);
4457 stmt = c_finish_goto_ptr (loc, val);
4460 c_parser_error (parser, "expected identifier or %<*%>");
4461 goto expect_semicolon;
4463 c_parser_consume_token (parser);
4464 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4465 goto expect_semicolon;
4467 c_parser_consume_token (parser);
4468 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4469 goto expect_semicolon;
4471 c_parser_consume_token (parser);
4472 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4474 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4475 c_parser_consume_token (parser);
4479 struct c_expr expr = c_parser_expression_conv (parser);
4480 mark_exp_read (expr.value);
4481 stmt = c_finish_return (loc, expr.value, expr.original_type);
4482 goto expect_semicolon;
4486 stmt = c_parser_asm_statement (parser);
4489 gcc_assert (c_dialect_objc ());
4490 c_parser_consume_token (parser);
4491 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4493 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4494 c_parser_consume_token (parser);
4498 tree expr = c_parser_expression (parser).value;
4499 expr = c_fully_fold (expr, false, NULL);
4500 stmt = objc_build_throw_stmt (loc, expr);
4501 goto expect_semicolon;
4505 gcc_assert (c_dialect_objc ());
4506 c_parser_objc_try_catch_finally_statement (parser);
4508 case RID_AT_SYNCHRONIZED:
4509 gcc_assert (c_dialect_objc ());
4510 c_parser_objc_synchronized_statement (parser);
4517 c_parser_consume_token (parser);
4519 case CPP_CLOSE_PAREN:
4520 case CPP_CLOSE_SQUARE:
4521 /* Avoid infinite loop in error recovery:
4522 c_parser_skip_until_found stops at a closing nesting
4523 delimiter without consuming it, but here we need to consume
4524 it to proceed further. */
4525 c_parser_error (parser, "expected statement");
4526 c_parser_consume_token (parser);
4529 c_parser_pragma (parser, pragma_stmt);
4533 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4535 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4538 /* Two cases cannot and do not have line numbers associated: If stmt
4539 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4540 cannot hold line numbers. But that's OK because the statement
4541 will either be changed to a MODIFY_EXPR during gimplification of
4542 the statement expr, or discarded. If stmt was compound, but
4543 without new variables, we will have skipped the creation of a
4544 BIND and will have a bare STATEMENT_LIST. But that's OK because
4545 (recursively) all of the component statements should already have
4546 line numbers assigned. ??? Can we discard no-op statements
4548 if (CAN_HAVE_LOCATION_P (stmt)
4549 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4550 SET_EXPR_LOCATION (stmt, loc);
4552 parser->in_if_block = in_if_block;
4555 /* Parse the condition from an if, do, while or for statements. */
4558 c_parser_condition (c_parser *parser)
4560 location_t loc = c_parser_peek_token (parser)->location;
4562 cond = c_parser_expression_conv (parser).value;
4563 cond = c_objc_common_truthvalue_conversion (loc, cond);
4564 cond = c_fully_fold (cond, false, NULL);
4565 if (warn_sequence_point)
4566 verify_sequence_points (cond);
4570 /* Parse a parenthesized condition from an if, do or while statement.
4576 c_parser_paren_condition (c_parser *parser)
4579 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4580 return error_mark_node;
4581 cond = c_parser_condition (parser);
4582 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4586 /* Parse a statement which is a block in C99. */
4589 c_parser_c99_block_statement (c_parser *parser)
4591 tree block = c_begin_compound_stmt (flag_isoc99);
4592 location_t loc = c_parser_peek_token (parser)->location;
4593 c_parser_statement (parser);
4594 return c_end_compound_stmt (loc, block, flag_isoc99);
4597 /* Parse the body of an if statement. This is just parsing a
4598 statement but (a) it is a block in C99, (b) we track whether the
4599 body is an if statement for the sake of -Wparentheses warnings, (c)
4600 we handle an empty body specially for the sake of -Wempty-body
4601 warnings, and (d) we call parser_compound_statement directly
4602 because c_parser_statement_after_labels resets
4603 parser->in_if_block. */
4606 c_parser_if_body (c_parser *parser, bool *if_p)
4608 tree block = c_begin_compound_stmt (flag_isoc99);
4609 location_t body_loc = c_parser_peek_token (parser)->location;
4610 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4611 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4612 || (c_parser_next_token_is (parser, CPP_NAME)
4613 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4614 c_parser_label (parser);
4615 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4616 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4618 location_t loc = c_parser_peek_token (parser)->location;
4619 add_stmt (build_empty_stmt (loc));
4620 c_parser_consume_token (parser);
4621 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4622 warning_at (loc, OPT_Wempty_body,
4623 "suggest braces around empty body in an %<if%> statement");
4625 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4626 add_stmt (c_parser_compound_statement (parser));
4628 c_parser_statement_after_labels (parser);
4629 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4632 /* Parse the else body of an if statement. This is just parsing a
4633 statement but (a) it is a block in C99, (b) we handle an empty body
4634 specially for the sake of -Wempty-body warnings. */
4637 c_parser_else_body (c_parser *parser)
4639 location_t else_loc = c_parser_peek_token (parser)->location;
4640 tree block = c_begin_compound_stmt (flag_isoc99);
4641 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4642 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4643 || (c_parser_next_token_is (parser, CPP_NAME)
4644 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4645 c_parser_label (parser);
4646 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4648 location_t loc = c_parser_peek_token (parser)->location;
4651 "suggest braces around empty body in an %<else%> statement");
4652 add_stmt (build_empty_stmt (loc));
4653 c_parser_consume_token (parser);
4656 c_parser_statement_after_labels (parser);
4657 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4660 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4663 if ( expression ) statement
4664 if ( expression ) statement else statement
4668 c_parser_if_statement (c_parser *parser)
4673 bool first_if = false;
4674 tree first_body, second_body;
4677 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4678 c_parser_consume_token (parser);
4679 block = c_begin_compound_stmt (flag_isoc99);
4680 loc = c_parser_peek_token (parser)->location;
4681 cond = c_parser_paren_condition (parser);
4682 in_if_block = parser->in_if_block;
4683 parser->in_if_block = true;
4684 first_body = c_parser_if_body (parser, &first_if);
4685 parser->in_if_block = in_if_block;
4686 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4688 c_parser_consume_token (parser);
4689 second_body = c_parser_else_body (parser);
4692 second_body = NULL_TREE;
4693 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4694 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4697 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4700 switch (expression) statement
4704 c_parser_switch_statement (c_parser *parser)
4706 tree block, expr, body, save_break;
4707 location_t switch_loc = c_parser_peek_token (parser)->location;
4708 location_t switch_cond_loc;
4709 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4710 c_parser_consume_token (parser);
4711 block = c_begin_compound_stmt (flag_isoc99);
4712 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4714 switch_cond_loc = c_parser_peek_token (parser)->location;
4715 expr = c_parser_expression (parser).value;
4716 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4720 switch_cond_loc = UNKNOWN_LOCATION;
4721 expr = error_mark_node;
4723 c_start_case (switch_loc, switch_cond_loc, expr);
4724 save_break = c_break_label;
4725 c_break_label = NULL_TREE;
4726 body = c_parser_c99_block_statement (parser);
4727 c_finish_case (body);
4730 location_t here = c_parser_peek_token (parser)->location;
4731 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4732 SET_EXPR_LOCATION (t, here);
4735 c_break_label = save_break;
4736 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4739 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4742 while (expression) statement
4746 c_parser_while_statement (c_parser *parser)
4748 tree block, cond, body, save_break, save_cont;
4750 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4751 c_parser_consume_token (parser);
4752 block = c_begin_compound_stmt (flag_isoc99);
4753 loc = c_parser_peek_token (parser)->location;
4754 cond = c_parser_paren_condition (parser);
4755 save_break = c_break_label;
4756 c_break_label = NULL_TREE;
4757 save_cont = c_cont_label;
4758 c_cont_label = NULL_TREE;
4759 body = c_parser_c99_block_statement (parser);
4760 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4761 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4762 c_break_label = save_break;
4763 c_cont_label = save_cont;
4766 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4769 do statement while ( expression ) ;
4773 c_parser_do_statement (c_parser *parser)
4775 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4777 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4778 c_parser_consume_token (parser);
4779 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4780 warning_at (c_parser_peek_token (parser)->location,
4782 "suggest braces around empty body in %<do%> statement");
4783 block = c_begin_compound_stmt (flag_isoc99);
4784 loc = c_parser_peek_token (parser)->location;
4785 save_break = c_break_label;
4786 c_break_label = NULL_TREE;
4787 save_cont = c_cont_label;
4788 c_cont_label = NULL_TREE;
4789 body = c_parser_c99_block_statement (parser);
4790 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4791 new_break = c_break_label;
4792 c_break_label = save_break;
4793 new_cont = c_cont_label;
4794 c_cont_label = save_cont;
4795 cond = c_parser_paren_condition (parser);
4796 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4797 c_parser_skip_to_end_of_block_or_statement (parser);
4798 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4799 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4802 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4805 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4806 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4808 The form with a declaration is new in C99.
4810 ??? In accordance with the old parser, the declaration may be a
4811 nested function, which is then rejected in check_for_loop_decls,
4812 but does it make any sense for this to be included in the grammar?
4813 Note in particular that the nested function does not include a
4814 trailing ';', whereas the "declaration" production includes one.
4815 Also, can we reject bad declarations earlier and cheaper than
4816 check_for_loop_decls?
4818 In Objective-C, there are two additional variants:
4821 for ( expression in expresssion ) statement
4822 for ( declaration in expression ) statement
4824 This is inconsistent with C, because the second variant is allowed
4825 even if c99 is not enabled.
4827 The rest of the comment documents these Objective-C foreach-statement.
4829 Here is the canonical example of the first variant:
4830 for (object in array) { do something with object }
4831 we call the first expression ("object") the "object_expression" and
4832 the second expression ("array") the "collection_expression".
4833 object_expression must be an lvalue of type "id" (a generic Objective-C
4834 object) because the loop works by assigning to object_expression the
4835 various objects from the collection_expression. collection_expression
4836 must evaluate to something of type "id" which responds to the method
4837 countByEnumeratingWithState:objects:count:.
4839 The canonical example of the second variant is:
4840 for (id object in array) { do something with object }
4841 which is completely equivalent to
4844 for (object in array) { do something with object }
4846 Note that initizializing 'object' in some way (eg, "for ((object =
4847 xxx) in array) { do something with object }") is possibly
4848 technically valid, but completely pointless as 'object' will be
4849 assigned to something else as soon as the loop starts. We should
4850 most likely reject it (TODO).
4852 The beginning of the Objective-C foreach-statement looks exactly
4853 like the beginning of the for-statement, and we can tell it is a
4854 foreach-statement only because the initial declaration or
4855 expression is terminated by 'in' instead of ';'.
4859 c_parser_for_statement (c_parser *parser)
4861 tree block, cond, incr, save_break, save_cont, body;
4862 /* The following are only used when parsing an ObjC foreach statement. */
4863 tree object_expression;
4864 /* Silence the bogus uninitialized warning. */
4865 tree collection_expression = NULL;
4866 location_t loc = c_parser_peek_token (parser)->location;
4867 location_t for_loc = c_parser_peek_token (parser)->location;
4868 bool is_foreach_statement = false;
4869 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4870 c_parser_consume_token (parser);
4871 /* Open a compound statement in Objective-C as well, just in case this is
4872 as foreach expression. */
4873 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4874 cond = error_mark_node;
4875 incr = error_mark_node;
4876 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4878 /* Parse the initialization declaration or expression. */
4879 object_expression = error_mark_node;
4880 parser->objc_could_be_foreach_context = c_dialect_objc ();
4881 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4883 parser->objc_could_be_foreach_context = false;
4884 c_parser_consume_token (parser);
4885 c_finish_expr_stmt (loc, NULL_TREE);
4887 else if (c_parser_next_tokens_start_declaration (parser))
4889 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4890 &object_expression);
4891 parser->objc_could_be_foreach_context = false;
4893 if (c_parser_next_token_is_keyword (parser, RID_IN))
4895 c_parser_consume_token (parser);
4896 is_foreach_statement = true;
4897 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4898 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4901 check_for_loop_decls (for_loc, flag_isoc99);
4903 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4905 /* __extension__ can start a declaration, but is also an
4906 unary operator that can start an expression. Consume all
4907 but the last of a possible series of __extension__ to
4909 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4910 && (c_parser_peek_2nd_token (parser)->keyword
4912 c_parser_consume_token (parser);
4913 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4916 ext = disable_extension_diagnostics ();
4917 c_parser_consume_token (parser);
4918 c_parser_declaration_or_fndef (parser, true, true, true, true,
4919 true, &object_expression);
4920 parser->objc_could_be_foreach_context = false;
4922 restore_extension_diagnostics (ext);
4923 if (c_parser_next_token_is_keyword (parser, RID_IN))
4925 c_parser_consume_token (parser);
4926 is_foreach_statement = true;
4927 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4928 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4931 check_for_loop_decls (for_loc, flag_isoc99);
4940 tree init_expression;
4941 init_expression = c_parser_expression (parser).value;
4942 parser->objc_could_be_foreach_context = false;
4943 if (c_parser_next_token_is_keyword (parser, RID_IN))
4945 c_parser_consume_token (parser);
4946 is_foreach_statement = true;
4947 if (! lvalue_p (init_expression))
4948 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4949 object_expression = c_fully_fold (init_expression, false, NULL);
4953 c_finish_expr_stmt (loc, init_expression);
4954 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4958 /* Parse the loop condition. In the case of a foreach
4959 statement, there is no loop condition. */
4960 gcc_assert (!parser->objc_could_be_foreach_context);
4961 if (!is_foreach_statement)
4963 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4965 c_parser_consume_token (parser);
4970 cond = c_parser_condition (parser);
4971 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4974 /* Parse the increment expression (the third expression in a
4975 for-statement). In the case of a foreach-statement, this is
4976 the expression that follows the 'in'. */
4977 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4979 if (is_foreach_statement)
4981 c_parser_error (parser, "missing collection in fast enumeration");
4982 collection_expression = error_mark_node;
4985 incr = c_process_expr_stmt (loc, NULL_TREE);
4989 if (is_foreach_statement)
4990 collection_expression = c_fully_fold (c_parser_expression (parser).value,
4993 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4995 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4997 save_break = c_break_label;
4998 c_break_label = NULL_TREE;
4999 save_cont = c_cont_label;
5000 c_cont_label = NULL_TREE;
5001 body = c_parser_c99_block_statement (parser);
5002 if (is_foreach_statement)
5003 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
5005 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
5006 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
5007 c_break_label = save_break;
5008 c_cont_label = save_cont;
5011 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5012 statement with inputs, outputs, clobbers, and volatile tag
5016 asm type-qualifier[opt] ( asm-argument ) ;
5017 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5021 asm-string-literal : asm-operands[opt]
5022 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5023 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5026 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5029 Qualifiers other than volatile are accepted in the syntax but
5033 c_parser_asm_statement (c_parser *parser)
5035 tree quals, str, outputs, inputs, clobbers, labels, ret;
5036 bool simple, is_goto;
5037 location_t asm_loc = c_parser_peek_token (parser)->location;
5038 int section, nsections;
5040 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
5041 c_parser_consume_token (parser);
5042 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
5044 quals = c_parser_peek_token (parser)->value;
5045 c_parser_consume_token (parser);
5047 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
5048 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
5050 warning_at (c_parser_peek_token (parser)->location,
5052 "%E qualifier ignored on asm",
5053 c_parser_peek_token (parser)->value);
5055 c_parser_consume_token (parser);
5061 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
5063 c_parser_consume_token (parser);
5067 /* ??? Follow the C++ parser rather than using the
5068 lex_untranslated_string kludge. */
5069 parser->lex_untranslated_string = true;
5072 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5075 str = c_parser_asm_string_literal (parser);
5076 if (str == NULL_TREE)
5077 goto error_close_paren;
5080 outputs = NULL_TREE;
5082 clobbers = NULL_TREE;
5085 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5088 /* Parse each colon-delimited section of operands. */
5089 nsections = 3 + is_goto;
5090 for (section = 0; section < nsections; ++section)
5092 if (!c_parser_require (parser, CPP_COLON,
5095 : "expected %<:%> or %<)%>"))
5096 goto error_close_paren;
5098 /* Once past any colon, we're no longer a simple asm. */
5101 if ((!c_parser_next_token_is (parser, CPP_COLON)
5102 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5107 /* For asm goto, we don't allow output operands, but reserve
5108 the slot for a future extension that does allow them. */
5110 outputs = c_parser_asm_operands (parser, false);
5113 inputs = c_parser_asm_operands (parser, true);
5116 clobbers = c_parser_asm_clobbers (parser);
5119 labels = c_parser_asm_goto_operands (parser);
5125 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
5130 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5132 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5136 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
5137 c_parser_skip_to_end_of_block_or_statement (parser);
5139 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
5140 clobbers, labels, simple));
5143 parser->lex_untranslated_string = false;
5147 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5151 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
5152 not outputs), apply the default conversion of functions and arrays
5157 asm-operands , asm-operand
5160 asm-string-literal ( expression )
5161 [ identifier ] asm-string-literal ( expression )
5165 c_parser_asm_operands (c_parser *parser, bool convert_p)
5167 tree list = NULL_TREE;
5173 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
5175 c_parser_consume_token (parser);
5176 if (c_parser_next_token_is (parser, CPP_NAME))
5178 tree id = c_parser_peek_token (parser)->value;
5179 c_parser_consume_token (parser);
5180 name = build_string (IDENTIFIER_LENGTH (id),
5181 IDENTIFIER_POINTER (id));
5185 c_parser_error (parser, "expected identifier");
5186 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
5189 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5194 str = c_parser_asm_string_literal (parser);
5195 if (str == NULL_TREE)
5197 parser->lex_untranslated_string = false;
5198 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5200 parser->lex_untranslated_string = true;
5203 loc = c_parser_peek_token (parser)->location;
5204 expr = c_parser_expression (parser);
5205 mark_exp_read (expr.value);
5207 expr = default_function_array_conversion (loc, expr);
5208 expr.value = c_fully_fold (expr.value, false, NULL);
5209 parser->lex_untranslated_string = true;
5210 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
5212 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5215 list = chainon (list, build_tree_list (build_tree_list (name, str),
5217 if (c_parser_next_token_is (parser, CPP_COMMA))
5218 c_parser_consume_token (parser);
5225 /* Parse asm clobbers, a GNU extension.
5229 asm-clobbers , asm-string-literal
5233 c_parser_asm_clobbers (c_parser *parser)
5235 tree list = NULL_TREE;
5238 tree str = c_parser_asm_string_literal (parser);
5240 list = tree_cons (NULL_TREE, str, list);
5243 if (c_parser_next_token_is (parser, CPP_COMMA))
5244 c_parser_consume_token (parser);
5251 /* Parse asm goto labels, a GNU extension.
5255 asm-goto-operands , identifier
5259 c_parser_asm_goto_operands (c_parser *parser)
5261 tree list = NULL_TREE;
5266 if (c_parser_next_token_is (parser, CPP_NAME))
5268 c_token *tok = c_parser_peek_token (parser);
5270 label = lookup_label_for_goto (tok->location, name);
5271 c_parser_consume_token (parser);
5272 TREE_USED (label) = 1;
5276 c_parser_error (parser, "expected identifier");
5280 name = build_string (IDENTIFIER_LENGTH (name),
5281 IDENTIFIER_POINTER (name));
5282 list = tree_cons (name, label, list);
5283 if (c_parser_next_token_is (parser, CPP_COMMA))
5284 c_parser_consume_token (parser);
5286 return nreverse (list);
5290 /* Parse an expression other than a compound expression; that is, an
5291 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5292 NULL then it is an Objective-C message expression which is the
5293 primary-expression starting the expression as an initializer.
5295 assignment-expression:
5296 conditional-expression
5297 unary-expression assignment-operator assignment-expression
5299 assignment-operator: one of
5300 = *= /= %= += -= <<= >>= &= ^= |=
5302 In GNU C we accept any conditional expression on the LHS and
5303 diagnose the invalid lvalue rather than producing a syntax
5306 static struct c_expr
5307 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5309 struct c_expr lhs, rhs, ret;
5310 enum tree_code code;
5311 location_t op_location, exp_location;
5312 gcc_assert (!after || c_dialect_objc ());
5313 lhs = c_parser_conditional_expression (parser, after);
5314 op_location = c_parser_peek_token (parser)->location;
5315 switch (c_parser_peek_token (parser)->type)
5324 code = TRUNC_DIV_EXPR;
5327 code = TRUNC_MOD_EXPR;
5342 code = BIT_AND_EXPR;
5345 code = BIT_XOR_EXPR;
5348 code = BIT_IOR_EXPR;
5353 c_parser_consume_token (parser);
5354 exp_location = c_parser_peek_token (parser)->location;
5355 rhs = c_parser_expr_no_commas (parser, NULL);
5356 rhs = default_function_array_read_conversion (exp_location, rhs);
5357 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5358 code, exp_location, rhs.value,
5360 if (code == NOP_EXPR)
5361 ret.original_code = MODIFY_EXPR;
5364 TREE_NO_WARNING (ret.value) = 1;
5365 ret.original_code = ERROR_MARK;
5367 ret.original_type = NULL;
5371 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5372 is not NULL then it is an Objective-C message expression which is
5373 the primary-expression starting the expression as an initializer.
5375 conditional-expression:
5376 logical-OR-expression
5377 logical-OR-expression ? expression : conditional-expression
5381 conditional-expression:
5382 logical-OR-expression ? : conditional-expression
5385 static struct c_expr
5386 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5388 struct c_expr cond, exp1, exp2, ret;
5389 location_t cond_loc, colon_loc, middle_loc;
5391 gcc_assert (!after || c_dialect_objc ());
5393 cond = c_parser_binary_expression (parser, after, PREC_NONE);
5395 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5397 cond_loc = c_parser_peek_token (parser)->location;
5398 cond = default_function_array_read_conversion (cond_loc, cond);
5399 c_parser_consume_token (parser);
5400 if (c_parser_next_token_is (parser, CPP_COLON))
5402 tree eptype = NULL_TREE;
5404 middle_loc = c_parser_peek_token (parser)->location;
5405 pedwarn (middle_loc, OPT_pedantic,
5406 "ISO C forbids omitting the middle term of a ?: expression");
5407 warn_for_omitted_condop (middle_loc, cond.value);
5408 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5410 eptype = TREE_TYPE (cond.value);
5411 cond.value = TREE_OPERAND (cond.value, 0);
5413 /* Make sure first operand is calculated only once. */
5414 exp1.value = c_save_expr (default_conversion (cond.value));
5416 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5417 exp1.original_type = NULL;
5418 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5419 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5424 = c_objc_common_truthvalue_conversion
5425 (cond_loc, default_conversion (cond.value));
5426 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5427 exp1 = c_parser_expression_conv (parser);
5428 mark_exp_read (exp1.value);
5429 c_inhibit_evaluation_warnings +=
5430 ((cond.value == truthvalue_true_node)
5431 - (cond.value == truthvalue_false_node));
5434 colon_loc = c_parser_peek_token (parser)->location;
5435 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5437 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5438 ret.value = error_mark_node;
5439 ret.original_code = ERROR_MARK;
5440 ret.original_type = NULL;
5444 location_t exp2_loc = c_parser_peek_token (parser)->location;
5445 exp2 = c_parser_conditional_expression (parser, NULL);
5446 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5448 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5449 ret.value = build_conditional_expr (colon_loc, cond.value,
5450 cond.original_code == C_MAYBE_CONST_EXPR,
5451 exp1.value, exp1.original_type,
5452 exp2.value, exp2.original_type);
5453 ret.original_code = ERROR_MARK;
5454 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5455 ret.original_type = NULL;
5460 /* If both sides are enum type, the default conversion will have
5461 made the type of the result be an integer type. We want to
5462 remember the enum types we started with. */
5463 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5464 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5465 ret.original_type = ((t1 != error_mark_node
5466 && t2 != error_mark_node
5467 && (TYPE_MAIN_VARIANT (t1)
5468 == TYPE_MAIN_VARIANT (t2)))
5475 /* Parse a binary expression; that is, a logical-OR-expression (C90
5476 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5477 an Objective-C message expression which is the primary-expression
5478 starting the expression as an initializer. PREC is the starting
5479 precedence, usually PREC_NONE.
5481 multiplicative-expression:
5483 multiplicative-expression * cast-expression
5484 multiplicative-expression / cast-expression
5485 multiplicative-expression % cast-expression
5487 additive-expression:
5488 multiplicative-expression
5489 additive-expression + multiplicative-expression
5490 additive-expression - multiplicative-expression
5494 shift-expression << additive-expression
5495 shift-expression >> additive-expression
5497 relational-expression:
5499 relational-expression < shift-expression
5500 relational-expression > shift-expression
5501 relational-expression <= shift-expression
5502 relational-expression >= shift-expression
5504 equality-expression:
5505 relational-expression
5506 equality-expression == relational-expression
5507 equality-expression != relational-expression
5511 AND-expression & equality-expression
5513 exclusive-OR-expression:
5515 exclusive-OR-expression ^ AND-expression
5517 inclusive-OR-expression:
5518 exclusive-OR-expression
5519 inclusive-OR-expression | exclusive-OR-expression
5521 logical-AND-expression:
5522 inclusive-OR-expression
5523 logical-AND-expression && inclusive-OR-expression
5525 logical-OR-expression:
5526 logical-AND-expression
5527 logical-OR-expression || logical-AND-expression
5530 static struct c_expr
5531 c_parser_binary_expression (c_parser *parser, struct c_expr *after,
5532 enum c_parser_prec prec)
5534 /* A binary expression is parsed using operator-precedence parsing,
5535 with the operands being cast expressions. All the binary
5536 operators are left-associative. Thus a binary expression is of
5539 E0 op1 E1 op2 E2 ...
5541 which we represent on a stack. On the stack, the precedence
5542 levels are strictly increasing. When a new operator is
5543 encountered of higher precedence than that at the top of the
5544 stack, it is pushed; its LHS is the top expression, and its RHS
5545 is everything parsed until it is popped. When a new operator is
5546 encountered with precedence less than or equal to that at the top
5547 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5548 by the result of the operation until the operator at the top of
5549 the stack has lower precedence than the new operator or there is
5550 only one element on the stack; then the top expression is the LHS
5551 of the new operator. In the case of logical AND and OR
5552 expressions, we also need to adjust c_inhibit_evaluation_warnings
5553 as appropriate when the operators are pushed and popped. */
5556 /* The expression at this stack level. */
5558 /* The precedence of the operator on its left, PREC_NONE at the
5559 bottom of the stack. */
5560 enum c_parser_prec prec;
5561 /* The operation on its left. */
5563 /* The source location of this operation. */
5567 /* Location of the binary operator. */
5568 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5571 switch (stack[sp].op) \
5573 case TRUTH_ANDIF_EXPR: \
5574 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5575 == truthvalue_false_node); \
5577 case TRUTH_ORIF_EXPR: \
5578 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5579 == truthvalue_true_node); \
5584 stack[sp - 1].expr \
5585 = default_function_array_read_conversion (stack[sp - 1].loc, \
5586 stack[sp - 1].expr); \
5588 = default_function_array_read_conversion (stack[sp].loc, \
5590 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5592 stack[sp - 1].expr, \
5596 gcc_assert (!after || c_dialect_objc ());
5597 stack[0].loc = c_parser_peek_token (parser)->location;
5598 stack[0].expr = c_parser_cast_expression (parser, after);
5599 stack[0].prec = prec;
5603 enum c_parser_prec oprec;
5604 enum tree_code ocode;
5607 switch (c_parser_peek_token (parser)->type)
5615 ocode = TRUNC_DIV_EXPR;
5619 ocode = TRUNC_MOD_EXPR;
5631 ocode = LSHIFT_EXPR;
5635 ocode = RSHIFT_EXPR;
5649 case CPP_GREATER_EQ:
5662 oprec = PREC_BITAND;
5663 ocode = BIT_AND_EXPR;
5666 oprec = PREC_BITXOR;
5667 ocode = BIT_XOR_EXPR;
5671 ocode = BIT_IOR_EXPR;
5674 oprec = PREC_LOGAND;
5675 ocode = TRUTH_ANDIF_EXPR;
5679 ocode = TRUTH_ORIF_EXPR;
5682 /* Not a binary operator, so end of the binary
5686 binary_loc = c_parser_peek_token (parser)->location;
5687 while (oprec <= stack[sp].prec)
5693 c_parser_consume_token (parser);
5696 case TRUTH_ANDIF_EXPR:
5698 = default_function_array_read_conversion (stack[sp].loc,
5700 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5701 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5702 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5703 == truthvalue_false_node);
5705 case TRUTH_ORIF_EXPR:
5707 = default_function_array_read_conversion (stack[sp].loc,
5709 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5710 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5711 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5712 == truthvalue_true_node);
5718 stack[sp].loc = binary_loc;
5719 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5720 stack[sp].prec = oprec;
5721 stack[sp].op = ocode;
5722 stack[sp].loc = binary_loc;
5727 return stack[0].expr;
5731 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5732 NULL then it is an Objective-C message expression which is the
5733 primary-expression starting the expression as an initializer.
5737 ( type-name ) unary-expression
5740 static struct c_expr
5741 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5743 location_t cast_loc = c_parser_peek_token (parser)->location;
5744 gcc_assert (!after || c_dialect_objc ());
5746 return c_parser_postfix_expression_after_primary (parser,
5748 /* If the expression begins with a parenthesized type name, it may
5749 be either a cast or a compound literal; we need to see whether
5750 the next character is '{' to tell the difference. If not, it is
5751 an unary expression. Full detection of unknown typenames here
5752 would require a 3-token lookahead. */
5753 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5754 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5756 struct c_type_name *type_name;
5759 c_parser_consume_token (parser);
5760 type_name = c_parser_type_name (parser);
5761 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5762 if (type_name == NULL)
5764 ret.value = error_mark_node;
5765 ret.original_code = ERROR_MARK;
5766 ret.original_type = NULL;
5770 /* Save casted types in the function's used types hash table. */
5771 used_types_insert (type_name->specs->type);
5773 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5774 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5777 location_t expr_loc = c_parser_peek_token (parser)->location;
5778 expr = c_parser_cast_expression (parser, NULL);
5779 expr = default_function_array_read_conversion (expr_loc, expr);
5781 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5782 ret.original_code = ERROR_MARK;
5783 ret.original_type = NULL;
5787 return c_parser_unary_expression (parser);
5790 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5796 unary-operator cast-expression
5797 sizeof unary-expression
5798 sizeof ( type-name )
5800 unary-operator: one of
5806 __alignof__ unary-expression
5807 __alignof__ ( type-name )
5810 (C1X permits _Alignof with type names only.)
5812 unary-operator: one of
5813 __extension__ __real__ __imag__
5815 In addition, the GNU syntax treats ++ and -- as unary operators, so
5816 they may be applied to cast expressions with errors for non-lvalues
5819 static struct c_expr
5820 c_parser_unary_expression (c_parser *parser)
5823 struct c_expr ret, op;
5824 location_t op_loc = c_parser_peek_token (parser)->location;
5826 ret.original_code = ERROR_MARK;
5827 ret.original_type = NULL;
5828 switch (c_parser_peek_token (parser)->type)
5831 c_parser_consume_token (parser);
5832 exp_loc = c_parser_peek_token (parser)->location;
5833 op = c_parser_cast_expression (parser, NULL);
5834 op = default_function_array_read_conversion (exp_loc, op);
5835 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5836 case CPP_MINUS_MINUS:
5837 c_parser_consume_token (parser);
5838 exp_loc = c_parser_peek_token (parser)->location;
5839 op = c_parser_cast_expression (parser, NULL);
5840 op = default_function_array_read_conversion (exp_loc, op);
5841 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5843 c_parser_consume_token (parser);
5844 op = c_parser_cast_expression (parser, NULL);
5845 mark_exp_read (op.value);
5846 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5848 c_parser_consume_token (parser);
5849 exp_loc = c_parser_peek_token (parser)->location;
5850 op = c_parser_cast_expression (parser, NULL);
5851 op = default_function_array_read_conversion (exp_loc, op);
5852 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5855 if (!c_dialect_objc () && !in_system_header)
5858 "traditional C rejects the unary plus operator");
5859 c_parser_consume_token (parser);
5860 exp_loc = c_parser_peek_token (parser)->location;
5861 op = c_parser_cast_expression (parser, NULL);
5862 op = default_function_array_read_conversion (exp_loc, op);
5863 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5865 c_parser_consume_token (parser);
5866 exp_loc = c_parser_peek_token (parser)->location;
5867 op = c_parser_cast_expression (parser, NULL);
5868 op = default_function_array_read_conversion (exp_loc, op);
5869 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5871 c_parser_consume_token (parser);
5872 exp_loc = c_parser_peek_token (parser)->location;
5873 op = c_parser_cast_expression (parser, NULL);
5874 op = default_function_array_read_conversion (exp_loc, op);
5875 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5877 c_parser_consume_token (parser);
5878 exp_loc = c_parser_peek_token (parser)->location;
5879 op = c_parser_cast_expression (parser, NULL);
5880 op = default_function_array_read_conversion (exp_loc, op);
5881 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5883 /* Refer to the address of a label as a pointer. */
5884 c_parser_consume_token (parser);
5885 if (c_parser_next_token_is (parser, CPP_NAME))
5887 ret.value = finish_label_address_expr
5888 (c_parser_peek_token (parser)->value, op_loc);
5889 c_parser_consume_token (parser);
5893 c_parser_error (parser, "expected identifier");
5894 ret.value = error_mark_node;
5898 switch (c_parser_peek_token (parser)->keyword)
5901 return c_parser_sizeof_expression (parser);
5903 return c_parser_alignof_expression (parser);
5905 c_parser_consume_token (parser);
5906 ext = disable_extension_diagnostics ();
5907 ret = c_parser_cast_expression (parser, NULL);
5908 restore_extension_diagnostics (ext);
5911 c_parser_consume_token (parser);
5912 exp_loc = c_parser_peek_token (parser)->location;
5913 op = c_parser_cast_expression (parser, NULL);
5914 op = default_function_array_conversion (exp_loc, op);
5915 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5917 c_parser_consume_token (parser);
5918 exp_loc = c_parser_peek_token (parser)->location;
5919 op = c_parser_cast_expression (parser, NULL);
5920 op = default_function_array_conversion (exp_loc, op);
5921 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5923 return c_parser_postfix_expression (parser);
5926 return c_parser_postfix_expression (parser);
5930 /* Parse a sizeof expression. */
5932 static struct c_expr
5933 c_parser_sizeof_expression (c_parser *parser)
5936 location_t expr_loc;
5937 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5938 c_parser_consume_token (parser);
5939 c_inhibit_evaluation_warnings++;
5941 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5942 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5944 /* Either sizeof ( type-name ) or sizeof unary-expression
5945 starting with a compound literal. */
5946 struct c_type_name *type_name;
5947 c_parser_consume_token (parser);
5948 expr_loc = c_parser_peek_token (parser)->location;
5949 type_name = c_parser_type_name (parser);
5950 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5951 if (type_name == NULL)
5954 c_inhibit_evaluation_warnings--;
5956 ret.value = error_mark_node;
5957 ret.original_code = ERROR_MARK;
5958 ret.original_type = NULL;
5961 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5963 expr = c_parser_postfix_expression_after_paren_type (parser,
5968 /* sizeof ( type-name ). */
5969 c_inhibit_evaluation_warnings--;
5971 return c_expr_sizeof_type (expr_loc, type_name);
5975 expr_loc = c_parser_peek_token (parser)->location;
5976 expr = c_parser_unary_expression (parser);
5978 c_inhibit_evaluation_warnings--;
5980 mark_exp_read (expr.value);
5981 if (TREE_CODE (expr.value) == COMPONENT_REF
5982 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5983 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5984 return c_expr_sizeof_expr (expr_loc, expr);
5988 /* Parse an alignof expression. */
5990 static struct c_expr
5991 c_parser_alignof_expression (c_parser *parser)
5994 location_t loc = c_parser_peek_token (parser)->location;
5995 tree alignof_spelling = c_parser_peek_token (parser)->value;
5996 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5997 /* A diagnostic is not required for the use of this identifier in
5998 the implementation namespace; only diagnose it for the C1X
5999 spelling because of existing code using the other spellings. */
6001 && strcmp (IDENTIFIER_POINTER (alignof_spelling), "_Alignof") == 0)
6004 pedwarn (loc, OPT_pedantic, "ISO C99 does not support %qE",
6007 pedwarn (loc, OPT_pedantic, "ISO C90 does not support %qE",
6010 c_parser_consume_token (parser);
6011 c_inhibit_evaluation_warnings++;
6013 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
6014 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6016 /* Either __alignof__ ( type-name ) or __alignof__
6017 unary-expression starting with a compound literal. */
6019 struct c_type_name *type_name;
6021 c_parser_consume_token (parser);
6022 loc = c_parser_peek_token (parser)->location;
6023 type_name = c_parser_type_name (parser);
6024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6025 if (type_name == NULL)
6028 c_inhibit_evaluation_warnings--;
6030 ret.value = error_mark_node;
6031 ret.original_code = ERROR_MARK;
6032 ret.original_type = NULL;
6035 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6037 expr = c_parser_postfix_expression_after_paren_type (parser,
6042 /* alignof ( type-name ). */
6043 c_inhibit_evaluation_warnings--;
6045 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
6046 ret.original_code = ERROR_MARK;
6047 ret.original_type = NULL;
6053 expr = c_parser_unary_expression (parser);
6055 mark_exp_read (expr.value);
6056 c_inhibit_evaluation_warnings--;
6058 pedwarn (loc, OPT_pedantic, "ISO C does not allow %<%E (expression)%>",
6060 ret.value = c_alignof_expr (loc, expr.value);
6061 ret.original_code = ERROR_MARK;
6062 ret.original_type = NULL;
6067 /* Helper function to read arguments of builtins which are interfaces
6068 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6069 others. The name of the builtin is passed using BNAME parameter.
6070 Function returns true if there were no errors while parsing and
6071 stores the arguments in CEXPR_LIST. */
6073 c_parser_get_builtin_args (c_parser *parser, const char *bname,
6074 VEC(c_expr_t,gc) **ret_cexpr_list)
6076 location_t loc = c_parser_peek_token (parser)->location;
6077 VEC (c_expr_t,gc) *cexpr_list;
6080 *ret_cexpr_list = NULL;
6081 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
6083 error_at (loc, "cannot take address of %qs", bname);
6087 c_parser_consume_token (parser);
6089 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6091 c_parser_consume_token (parser);
6095 expr = c_parser_expr_no_commas (parser, NULL);
6096 cexpr_list = VEC_alloc (c_expr_t, gc, 1);
6097 C_EXPR_APPEND (cexpr_list, expr);
6098 while (c_parser_next_token_is (parser, CPP_COMMA))
6100 c_parser_consume_token (parser);
6101 expr = c_parser_expr_no_commas (parser, NULL);
6102 C_EXPR_APPEND (cexpr_list, expr);
6105 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
6108 *ret_cexpr_list = cexpr_list;
6113 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6117 postfix-expression [ expression ]
6118 postfix-expression ( argument-expression-list[opt] )
6119 postfix-expression . identifier
6120 postfix-expression -> identifier
6121 postfix-expression ++
6122 postfix-expression --
6123 ( type-name ) { initializer-list }
6124 ( type-name ) { initializer-list , }
6126 argument-expression-list:
6128 argument-expression-list , argument-expression
6140 (treated as a keyword in GNU C)
6143 ( compound-statement )
6144 __builtin_va_arg ( assignment-expression , type-name )
6145 __builtin_offsetof ( type-name , offsetof-member-designator )
6146 __builtin_choose_expr ( assignment-expression ,
6147 assignment-expression ,
6148 assignment-expression )
6149 __builtin_types_compatible_p ( type-name , type-name )
6150 __builtin_complex ( assignment-expression , assignment-expression )
6151 __builtin_shuffle ( assignment-expression , assignment-expression )
6152 __builtin_shuffle ( assignment-expression ,
6153 assignment-expression ,
6154 assignment-expression, )
6156 offsetof-member-designator:
6158 offsetof-member-designator . identifier
6159 offsetof-member-designator [ expression ]
6164 [ objc-receiver objc-message-args ]
6165 @selector ( objc-selector-arg )
6166 @protocol ( identifier )
6167 @encode ( type-name )
6169 Classname . identifier
6172 static struct c_expr
6173 c_parser_postfix_expression (c_parser *parser)
6175 struct c_expr expr, e1;
6176 struct c_type_name *t1, *t2;
6177 location_t loc = c_parser_peek_token (parser)->location;;
6178 expr.original_code = ERROR_MARK;
6179 expr.original_type = NULL;
6180 switch (c_parser_peek_token (parser)->type)
6183 expr.value = c_parser_peek_token (parser)->value;
6184 loc = c_parser_peek_token (parser)->location;
6185 c_parser_consume_token (parser);
6186 if (TREE_CODE (expr.value) == FIXED_CST
6187 && !targetm.fixed_point_supported_p ())
6189 error_at (loc, "fixed-point types not supported for this target");
6190 expr.value = error_mark_node;
6197 expr.value = c_parser_peek_token (parser)->value;
6198 c_parser_consume_token (parser);
6204 case CPP_UTF8STRING:
6205 expr.value = c_parser_peek_token (parser)->value;
6206 expr.original_code = STRING_CST;
6207 c_parser_consume_token (parser);
6209 case CPP_OBJC_STRING:
6210 gcc_assert (c_dialect_objc ());
6212 = objc_build_string_object (c_parser_peek_token (parser)->value);
6213 c_parser_consume_token (parser);
6216 switch (c_parser_peek_token (parser)->id_kind)
6220 tree id = c_parser_peek_token (parser)->value;
6221 c_parser_consume_token (parser);
6222 expr.value = build_external_ref (loc, id,
6223 (c_parser_peek_token (parser)->type
6225 &expr.original_type);
6228 case C_ID_CLASSNAME:
6230 /* Here we parse the Objective-C 2.0 Class.name dot
6232 tree class_name = c_parser_peek_token (parser)->value;
6234 c_parser_consume_token (parser);
6235 gcc_assert (c_dialect_objc ());
6236 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>"))
6238 expr.value = error_mark_node;
6241 if (c_parser_next_token_is_not (parser, CPP_NAME))
6243 c_parser_error (parser, "expected identifier");
6244 expr.value = error_mark_node;
6247 component = c_parser_peek_token (parser)->value;
6248 c_parser_consume_token (parser);
6249 expr.value = objc_build_class_component_ref (class_name,
6254 c_parser_error (parser, "expected expression");
6255 expr.value = error_mark_node;
6259 case CPP_OPEN_PAREN:
6260 /* A parenthesized expression, statement expression or compound
6262 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
6264 /* A statement expression. */
6266 location_t brace_loc;
6267 c_parser_consume_token (parser);
6268 brace_loc = c_parser_peek_token (parser)->location;
6269 c_parser_consume_token (parser);
6270 if (!building_stmt_list_p ())
6272 error_at (loc, "braced-group within expression allowed "
6273 "only inside a function");
6274 parser->error = true;
6275 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
6276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6277 expr.value = error_mark_node;
6280 stmt = c_begin_stmt_expr ();
6281 c_parser_compound_statement_nostart (parser);
6282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6284 pedwarn (loc, OPT_pedantic,
6285 "ISO C forbids braced-groups within expressions");
6286 expr.value = c_finish_stmt_expr (brace_loc, stmt);
6287 mark_exp_read (expr.value);
6289 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
6291 /* A compound literal. ??? Can we actually get here rather
6292 than going directly to
6293 c_parser_postfix_expression_after_paren_type from
6296 struct c_type_name *type_name;
6297 c_parser_consume_token (parser);
6298 loc = c_parser_peek_token (parser)->location;
6299 type_name = c_parser_type_name (parser);
6300 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6302 if (type_name == NULL)
6304 expr.value = error_mark_node;
6307 expr = c_parser_postfix_expression_after_paren_type (parser,
6313 /* A parenthesized expression. */
6314 c_parser_consume_token (parser);
6315 expr = c_parser_expression (parser);
6316 if (TREE_CODE (expr.value) == MODIFY_EXPR)
6317 TREE_NO_WARNING (expr.value) = 1;
6318 if (expr.original_code != C_MAYBE_CONST_EXPR)
6319 expr.original_code = ERROR_MARK;
6320 /* Don't change EXPR.ORIGINAL_TYPE. */
6321 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6326 switch (c_parser_peek_token (parser)->keyword)
6328 case RID_FUNCTION_NAME:
6329 case RID_PRETTY_FUNCTION_NAME:
6330 case RID_C99_FUNCTION_NAME:
6331 expr.value = fname_decl (loc,
6332 c_parser_peek_token (parser)->keyword,
6333 c_parser_peek_token (parser)->value);
6334 c_parser_consume_token (parser);
6337 c_parser_consume_token (parser);
6338 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6340 expr.value = error_mark_node;
6343 e1 = c_parser_expr_no_commas (parser, NULL);
6344 mark_exp_read (e1.value);
6345 e1.value = c_fully_fold (e1.value, false, NULL);
6346 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6348 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6349 expr.value = error_mark_node;
6352 loc = c_parser_peek_token (parser)->location;
6353 t1 = c_parser_type_name (parser);
6354 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6358 expr.value = error_mark_node;
6362 tree type_expr = NULL_TREE;
6363 expr.value = c_build_va_arg (loc, e1.value,
6364 groktypename (t1, &type_expr, NULL));
6367 expr.value = build2 (C_MAYBE_CONST_EXPR,
6368 TREE_TYPE (expr.value), type_expr,
6370 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
6375 c_parser_consume_token (parser);
6376 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6378 expr.value = error_mark_node;
6381 t1 = c_parser_type_name (parser);
6383 parser->error = true;
6384 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6385 gcc_assert (parser->error);
6388 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6389 expr.value = error_mark_node;
6394 tree type = groktypename (t1, NULL, NULL);
6396 if (type == error_mark_node)
6397 offsetof_ref = error_mark_node;
6400 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6401 SET_EXPR_LOCATION (offsetof_ref, loc);
6403 /* Parse the second argument to __builtin_offsetof. We
6404 must have one identifier, and beyond that we want to
6405 accept sub structure and sub array references. */
6406 if (c_parser_next_token_is (parser, CPP_NAME))
6408 offsetof_ref = build_component_ref
6409 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6410 c_parser_consume_token (parser);
6411 while (c_parser_next_token_is (parser, CPP_DOT)
6412 || c_parser_next_token_is (parser,
6414 || c_parser_next_token_is (parser,
6417 if (c_parser_next_token_is (parser, CPP_DEREF))
6419 loc = c_parser_peek_token (parser)->location;
6420 offsetof_ref = build_array_ref (loc,
6425 else if (c_parser_next_token_is (parser, CPP_DOT))
6428 c_parser_consume_token (parser);
6429 if (c_parser_next_token_is_not (parser,
6432 c_parser_error (parser, "expected identifier");
6435 offsetof_ref = build_component_ref
6437 c_parser_peek_token (parser)->value);
6438 c_parser_consume_token (parser);
6443 loc = c_parser_peek_token (parser)->location;
6444 c_parser_consume_token (parser);
6445 idx = c_parser_expression (parser).value;
6446 idx = c_fully_fold (idx, false, NULL);
6447 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6449 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6454 c_parser_error (parser, "expected identifier");
6455 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6457 expr.value = fold_offsetof (offsetof_ref);
6460 case RID_CHOOSE_EXPR:
6462 VEC (c_expr_t, gc) *cexpr_list;
6463 c_expr_t *e1_p, *e2_p, *e3_p;
6466 c_parser_consume_token (parser);
6467 if (!c_parser_get_builtin_args (parser,
6468 "__builtin_choose_expr",
6471 expr.value = error_mark_node;
6475 if (VEC_length (c_expr_t, cexpr_list) != 3)
6477 error_at (loc, "wrong number of arguments to "
6478 "%<__builtin_choose_expr%>");
6479 expr.value = error_mark_node;
6483 e1_p = VEC_index (c_expr_t, cexpr_list, 0);
6484 e2_p = VEC_index (c_expr_t, cexpr_list, 1);
6485 e3_p = VEC_index (c_expr_t, cexpr_list, 2);
6488 mark_exp_read (e2_p->value);
6489 mark_exp_read (e3_p->value);
6490 if (TREE_CODE (c) != INTEGER_CST
6491 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6493 "first argument to %<__builtin_choose_expr%> not"
6495 constant_expression_warning (c);
6496 expr = integer_zerop (c) ? *e3_p : *e2_p;
6499 case RID_TYPES_COMPATIBLE_P:
6500 c_parser_consume_token (parser);
6501 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6503 expr.value = error_mark_node;
6506 t1 = c_parser_type_name (parser);
6509 expr.value = error_mark_node;
6512 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6514 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6515 expr.value = error_mark_node;
6518 t2 = c_parser_type_name (parser);
6521 expr.value = error_mark_node;
6524 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6529 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6530 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6533 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6536 case RID_BUILTIN_COMPLEX:
6538 VEC(c_expr_t, gc) *cexpr_list;
6539 c_expr_t *e1_p, *e2_p;
6541 c_parser_consume_token (parser);
6542 if (!c_parser_get_builtin_args (parser,
6543 "__builtin_complex",
6546 expr.value = error_mark_node;
6550 if (VEC_length (c_expr_t, cexpr_list) != 2)
6552 error_at (loc, "wrong number of arguments to "
6553 "%<__builtin_complex%>");
6554 expr.value = error_mark_node;
6558 e1_p = VEC_index (c_expr_t, cexpr_list, 0);
6559 e2_p = VEC_index (c_expr_t, cexpr_list, 1);
6561 mark_exp_read (e1_p->value);
6562 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR)
6563 e1_p->value = convert (TREE_TYPE (e1_p->value),
6564 TREE_OPERAND (e1_p->value, 0));
6565 mark_exp_read (e2_p->value);
6566 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR)
6567 e2_p->value = convert (TREE_TYPE (e2_p->value),
6568 TREE_OPERAND (e2_p->value, 0));
6569 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
6570 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value))
6571 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))
6572 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)))
6574 error_at (loc, "%<__builtin_complex%> operand "
6575 "not of real binary floating-point type");
6576 expr.value = error_mark_node;
6579 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value))
6580 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value)))
6583 "%<__builtin_complex%> operands of different types");
6584 expr.value = error_mark_node;
6588 pedwarn (loc, OPT_pedantic,
6589 "ISO C90 does not support complex types");
6590 expr.value = build2 (COMPLEX_EXPR,
6593 (TREE_TYPE (e1_p->value))),
6594 e1_p->value, e2_p->value);
6597 case RID_BUILTIN_SHUFFLE:
6599 VEC(c_expr_t,gc) *cexpr_list;
6601 c_parser_consume_token (parser);
6602 if (!c_parser_get_builtin_args (parser,
6603 "__builtin_shuffle",
6606 expr.value = error_mark_node;
6610 if (VEC_length (c_expr_t, cexpr_list) == 2)
6612 c_build_vec_perm_expr
6613 (loc, VEC_index (c_expr_t, cexpr_list, 0)->value,
6614 NULL_TREE, VEC_index (c_expr_t, cexpr_list, 1)->value);
6616 else if (VEC_length (c_expr_t, cexpr_list) == 3)
6618 c_build_vec_perm_expr
6619 (loc, VEC_index (c_expr_t, cexpr_list, 0)->value,
6620 VEC_index (c_expr_t, cexpr_list, 1)->value,
6621 VEC_index (c_expr_t, cexpr_list, 2)->value);
6624 error_at (loc, "wrong number of arguments to "
6625 "%<__builtin_shuffle%>");
6626 expr.value = error_mark_node;
6630 case RID_AT_SELECTOR:
6631 gcc_assert (c_dialect_objc ());
6632 c_parser_consume_token (parser);
6633 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6635 expr.value = error_mark_node;
6639 tree sel = c_parser_objc_selector_arg (parser);
6640 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6642 expr.value = objc_build_selector_expr (loc, sel);
6645 case RID_AT_PROTOCOL:
6646 gcc_assert (c_dialect_objc ());
6647 c_parser_consume_token (parser);
6648 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6650 expr.value = error_mark_node;
6653 if (c_parser_next_token_is_not (parser, CPP_NAME))
6655 c_parser_error (parser, "expected identifier");
6656 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6657 expr.value = error_mark_node;
6661 tree id = c_parser_peek_token (parser)->value;
6662 c_parser_consume_token (parser);
6663 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6665 expr.value = objc_build_protocol_expr (id);
6669 /* Extension to support C-structures in the archiver. */
6670 gcc_assert (c_dialect_objc ());
6671 c_parser_consume_token (parser);
6672 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6674 expr.value = error_mark_node;
6677 t1 = c_parser_type_name (parser);
6680 expr.value = error_mark_node;
6681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6684 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6687 tree type = groktypename (t1, NULL, NULL);
6688 expr.value = objc_build_encode_expr (type);
6692 c_parser_error (parser, "expected expression");
6693 expr.value = error_mark_node;
6697 case CPP_OPEN_SQUARE:
6698 if (c_dialect_objc ())
6700 tree receiver, args;
6701 c_parser_consume_token (parser);
6702 receiver = c_parser_objc_receiver (parser);
6703 args = c_parser_objc_message_args (parser);
6704 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6706 expr.value = objc_build_message_expr (receiver, args);
6709 /* Else fall through to report error. */
6711 c_parser_error (parser, "expected expression");
6712 expr.value = error_mark_node;
6715 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6718 /* Parse a postfix expression after a parenthesized type name: the
6719 brace-enclosed initializer of a compound literal, possibly followed
6720 by some postfix operators. This is separate because it is not
6721 possible to tell until after the type name whether a cast
6722 expression has a cast or a compound literal, or whether the operand
6723 of sizeof is a parenthesized type name or starts with a compound
6724 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6725 location of the first token after the parentheses around the type
6728 static struct c_expr
6729 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6730 struct c_type_name *type_name,
6731 location_t type_loc)
6737 location_t start_loc;
6738 tree type_expr = NULL_TREE;
6739 bool type_expr_const = true;
6740 check_compound_literal_type (type_loc, type_name);
6741 start_init (NULL_TREE, NULL, 0);
6742 type = groktypename (type_name, &type_expr, &type_expr_const);
6743 start_loc = c_parser_peek_token (parser)->location;
6744 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6746 error_at (type_loc, "compound literal has variable size");
6747 type = error_mark_node;
6749 init = c_parser_braced_init (parser, type, false);
6751 maybe_warn_string_init (type, init);
6753 if (type != error_mark_node
6754 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6755 && current_function_decl)
6757 error ("compound literal qualified by address-space qualifier");
6758 type = error_mark_node;
6762 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6763 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6764 ? CONSTRUCTOR_NON_CONST (init.value)
6765 : init.original_code == C_MAYBE_CONST_EXPR);
6766 non_const |= !type_expr_const;
6767 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6768 expr.original_code = ERROR_MARK;
6769 expr.original_type = NULL;
6772 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6774 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6775 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6779 gcc_assert (!non_const);
6780 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6781 type_expr, expr.value);
6784 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6787 /* Parse a postfix expression after the initial primary or compound
6788 literal; that is, parse a series of postfix operators.
6790 EXPR_LOC is the location of the primary expression. */
6792 static struct c_expr
6793 c_parser_postfix_expression_after_primary (c_parser *parser,
6794 location_t expr_loc,
6797 struct c_expr orig_expr;
6799 VEC(tree,gc) *exprlist;
6800 VEC(tree,gc) *origtypes;
6803 location_t op_loc = c_parser_peek_token (parser)->location;
6804 switch (c_parser_peek_token (parser)->type)
6806 case CPP_OPEN_SQUARE:
6807 /* Array reference. */
6808 c_parser_consume_token (parser);
6809 idx = c_parser_expression (parser).value;
6810 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6812 expr.value = build_array_ref (op_loc, expr.value, idx);
6813 expr.original_code = ERROR_MARK;
6814 expr.original_type = NULL;
6816 case CPP_OPEN_PAREN:
6817 /* Function call. */
6818 c_parser_consume_token (parser);
6819 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6822 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6823 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6826 mark_exp_read (expr.value);
6827 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6828 "(" after the FUNCNAME, which is what we have now. */
6829 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6831 expr.original_code = ERROR_MARK;
6832 if (TREE_CODE (expr.value) == INTEGER_CST
6833 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6834 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6835 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6836 expr.original_code = C_MAYBE_CONST_EXPR;
6837 expr.original_type = NULL;
6838 if (exprlist != NULL)
6840 release_tree_vector (exprlist);
6841 release_tree_vector (origtypes);
6845 /* Structure element reference. */
6846 c_parser_consume_token (parser);
6847 expr = default_function_array_conversion (expr_loc, expr);
6848 if (c_parser_next_token_is (parser, CPP_NAME))
6849 ident = c_parser_peek_token (parser)->value;
6852 c_parser_error (parser, "expected identifier");
6853 expr.value = error_mark_node;
6854 expr.original_code = ERROR_MARK;
6855 expr.original_type = NULL;
6858 c_parser_consume_token (parser);
6859 expr.value = build_component_ref (op_loc, expr.value, ident);
6860 expr.original_code = ERROR_MARK;
6861 if (TREE_CODE (expr.value) != COMPONENT_REF)
6862 expr.original_type = NULL;
6865 /* Remember the original type of a bitfield. */
6866 tree field = TREE_OPERAND (expr.value, 1);
6867 if (TREE_CODE (field) != FIELD_DECL)
6868 expr.original_type = NULL;
6870 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6874 /* Structure element reference. */
6875 c_parser_consume_token (parser);
6876 expr = default_function_array_conversion (expr_loc, expr);
6877 if (c_parser_next_token_is (parser, CPP_NAME))
6878 ident = c_parser_peek_token (parser)->value;
6881 c_parser_error (parser, "expected identifier");
6882 expr.value = error_mark_node;
6883 expr.original_code = ERROR_MARK;
6884 expr.original_type = NULL;
6887 c_parser_consume_token (parser);
6888 expr.value = build_component_ref (op_loc,
6889 build_indirect_ref (op_loc,
6893 expr.original_code = ERROR_MARK;
6894 if (TREE_CODE (expr.value) != COMPONENT_REF)
6895 expr.original_type = NULL;
6898 /* Remember the original type of a bitfield. */
6899 tree field = TREE_OPERAND (expr.value, 1);
6900 if (TREE_CODE (field) != FIELD_DECL)
6901 expr.original_type = NULL;
6903 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6907 /* Postincrement. */
6908 c_parser_consume_token (parser);
6909 expr = default_function_array_read_conversion (expr_loc, expr);
6910 expr.value = build_unary_op (op_loc,
6911 POSTINCREMENT_EXPR, expr.value, 0);
6912 expr.original_code = ERROR_MARK;
6913 expr.original_type = NULL;
6915 case CPP_MINUS_MINUS:
6916 /* Postdecrement. */
6917 c_parser_consume_token (parser);
6918 expr = default_function_array_read_conversion (expr_loc, expr);
6919 expr.value = build_unary_op (op_loc,
6920 POSTDECREMENT_EXPR, expr.value, 0);
6921 expr.original_code = ERROR_MARK;
6922 expr.original_type = NULL;
6930 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6933 assignment-expression
6934 expression , assignment-expression
6937 static struct c_expr
6938 c_parser_expression (c_parser *parser)
6941 expr = c_parser_expr_no_commas (parser, NULL);
6942 while (c_parser_next_token_is (parser, CPP_COMMA))
6946 location_t loc = c_parser_peek_token (parser)->location;
6947 location_t expr_loc;
6948 c_parser_consume_token (parser);
6949 expr_loc = c_parser_peek_token (parser)->location;
6950 lhsval = expr.value;
6951 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6952 lhsval = TREE_OPERAND (lhsval, 1);
6953 if (DECL_P (lhsval) || handled_component_p (lhsval))
6954 mark_exp_read (lhsval);
6955 next = c_parser_expr_no_commas (parser, NULL);
6956 next = default_function_array_conversion (expr_loc, next);
6957 expr.value = build_compound_expr (loc, expr.value, next.value);
6958 expr.original_code = COMPOUND_EXPR;
6959 expr.original_type = next.original_type;
6964 /* Parse an expression and convert functions or arrays to
6967 static struct c_expr
6968 c_parser_expression_conv (c_parser *parser)
6971 location_t loc = c_parser_peek_token (parser)->location;
6972 expr = c_parser_expression (parser);
6973 expr = default_function_array_conversion (loc, expr);
6977 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6978 functions and arrays to pointers. If FOLD_P, fold the expressions.
6981 assignment-expression
6982 nonempty-expr-list , assignment-expression
6985 static VEC(tree,gc) *
6986 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6987 VEC(tree,gc) **p_orig_types)
6990 VEC(tree,gc) *orig_types;
6992 location_t loc = c_parser_peek_token (parser)->location;
6994 ret = make_tree_vector ();
6995 if (p_orig_types == NULL)
6998 orig_types = make_tree_vector ();
7000 expr = c_parser_expr_no_commas (parser, NULL);
7002 expr = default_function_array_read_conversion (loc, expr);
7004 expr.value = c_fully_fold (expr.value, false, NULL);
7005 VEC_quick_push (tree, ret, expr.value);
7006 if (orig_types != NULL)
7007 VEC_quick_push (tree, orig_types, expr.original_type);
7008 while (c_parser_next_token_is (parser, CPP_COMMA))
7010 c_parser_consume_token (parser);
7011 loc = c_parser_peek_token (parser)->location;
7012 expr = c_parser_expr_no_commas (parser, NULL);
7014 expr = default_function_array_read_conversion (loc, expr);
7016 expr.value = c_fully_fold (expr.value, false, NULL);
7017 VEC_safe_push (tree, gc, ret, expr.value);
7018 if (orig_types != NULL)
7019 VEC_safe_push (tree, gc, orig_types, expr.original_type);
7021 if (orig_types != NULL)
7022 *p_orig_types = orig_types;
7026 /* Parse Objective-C-specific constructs. */
7028 /* Parse an objc-class-definition.
7030 objc-class-definition:
7031 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7032 objc-class-instance-variables[opt] objc-methodprotolist @end
7033 @implementation identifier objc-superclass[opt]
7034 objc-class-instance-variables[opt]
7035 @interface identifier ( identifier ) objc-protocol-refs[opt]
7036 objc-methodprotolist @end
7037 @interface identifier ( ) objc-protocol-refs[opt]
7038 objc-methodprotolist @end
7039 @implementation identifier ( identifier )
7044 "@interface identifier (" must start "@interface identifier (
7045 identifier ) ...": objc-methodprotolist in the first production may
7046 not start with a parenthesized identifier as a declarator of a data
7047 definition with no declaration specifiers if the objc-superclass,
7048 objc-protocol-refs and objc-class-instance-variables are omitted. */
7051 c_parser_objc_class_definition (c_parser *parser, tree attributes)
7056 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
7058 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
7063 c_parser_consume_token (parser);
7064 if (c_parser_next_token_is_not (parser, CPP_NAME))
7066 c_parser_error (parser, "expected identifier");
7069 id1 = c_parser_peek_token (parser)->value;
7070 c_parser_consume_token (parser);
7071 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7073 /* We have a category or class extension. */
7075 tree proto = NULL_TREE;
7076 c_parser_consume_token (parser);
7077 if (c_parser_next_token_is_not (parser, CPP_NAME))
7079 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7081 /* We have a class extension. */
7086 c_parser_error (parser, "expected identifier or %<)%>");
7087 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7093 id2 = c_parser_peek_token (parser)->value;
7094 c_parser_consume_token (parser);
7096 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7099 objc_start_category_implementation (id1, id2);
7102 if (c_parser_next_token_is (parser, CPP_LESS))
7103 proto = c_parser_objc_protocol_refs (parser);
7104 objc_start_category_interface (id1, id2, proto, attributes);
7105 c_parser_objc_methodprotolist (parser);
7106 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7107 objc_finish_interface ();
7110 if (c_parser_next_token_is (parser, CPP_COLON))
7112 c_parser_consume_token (parser);
7113 if (c_parser_next_token_is_not (parser, CPP_NAME))
7115 c_parser_error (parser, "expected identifier");
7118 superclass = c_parser_peek_token (parser)->value;
7119 c_parser_consume_token (parser);
7122 superclass = NULL_TREE;
7125 tree proto = NULL_TREE;
7126 if (c_parser_next_token_is (parser, CPP_LESS))
7127 proto = c_parser_objc_protocol_refs (parser);
7128 objc_start_class_interface (id1, superclass, proto, attributes);
7131 objc_start_class_implementation (id1, superclass);
7132 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7133 c_parser_objc_class_instance_variables (parser);
7136 objc_continue_interface ();
7137 c_parser_objc_methodprotolist (parser);
7138 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7139 objc_finish_interface ();
7143 objc_continue_implementation ();
7148 /* Parse objc-class-instance-variables.
7150 objc-class-instance-variables:
7151 { objc-instance-variable-decl-list[opt] }
7153 objc-instance-variable-decl-list:
7154 objc-visibility-spec
7155 objc-instance-variable-decl ;
7157 objc-instance-variable-decl-list objc-visibility-spec
7158 objc-instance-variable-decl-list objc-instance-variable-decl ;
7159 objc-instance-variable-decl-list ;
7161 objc-visibility-spec:
7166 objc-instance-variable-decl:
7171 c_parser_objc_class_instance_variables (c_parser *parser)
7173 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
7174 c_parser_consume_token (parser);
7175 while (c_parser_next_token_is_not (parser, CPP_EOF))
7178 /* Parse any stray semicolon. */
7179 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7181 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7183 c_parser_consume_token (parser);
7186 /* Stop if at the end of the instance variables. */
7187 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
7189 c_parser_consume_token (parser);
7192 /* Parse any objc-visibility-spec. */
7193 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
7195 c_parser_consume_token (parser);
7196 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
7199 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
7201 c_parser_consume_token (parser);
7202 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
7205 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
7207 c_parser_consume_token (parser);
7208 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
7211 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
7213 c_parser_consume_token (parser);
7214 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
7217 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
7219 c_parser_pragma (parser, pragma_external);
7223 /* Parse some comma-separated declarations. */
7224 decls = c_parser_struct_declaration (parser);
7227 /* There is a syntax error. We want to skip the offending
7228 tokens up to the next ';' (included) or '}'
7231 /* First, skip manually a ')' or ']'. This is because they
7232 reduce the nesting level, so c_parser_skip_until_found()
7233 wouldn't be able to skip past them. */
7234 c_token *token = c_parser_peek_token (parser);
7235 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE)
7236 c_parser_consume_token (parser);
7238 /* Then, do the standard skipping. */
7239 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7241 /* We hopefully recovered. Start normal parsing again. */
7242 parser->error = false;
7247 /* Comma-separated instance variables are chained together
7248 in reverse order; add them one by one. */
7249 tree ivar = nreverse (decls);
7250 for (; ivar; ivar = DECL_CHAIN (ivar))
7251 objc_add_instance_variable (copy_node (ivar));
7253 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7257 /* Parse an objc-class-declaration.
7259 objc-class-declaration:
7260 @class identifier-list ;
7264 c_parser_objc_class_declaration (c_parser *parser)
7266 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
7267 c_parser_consume_token (parser);
7268 /* Any identifiers, including those declared as type names, are OK
7273 if (c_parser_next_token_is_not (parser, CPP_NAME))
7275 c_parser_error (parser, "expected identifier");
7276 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7277 parser->error = false;
7280 id = c_parser_peek_token (parser)->value;
7281 objc_declare_class (id);
7282 c_parser_consume_token (parser);
7283 if (c_parser_next_token_is (parser, CPP_COMMA))
7284 c_parser_consume_token (parser);
7288 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7291 /* Parse an objc-alias-declaration.
7293 objc-alias-declaration:
7294 @compatibility_alias identifier identifier ;
7298 c_parser_objc_alias_declaration (c_parser *parser)
7301 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
7302 c_parser_consume_token (parser);
7303 if (c_parser_next_token_is_not (parser, CPP_NAME))
7305 c_parser_error (parser, "expected identifier");
7306 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7309 id1 = c_parser_peek_token (parser)->value;
7310 c_parser_consume_token (parser);
7311 if (c_parser_next_token_is_not (parser, CPP_NAME))
7313 c_parser_error (parser, "expected identifier");
7314 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
7317 id2 = c_parser_peek_token (parser)->value;
7318 c_parser_consume_token (parser);
7319 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7320 objc_declare_alias (id1, id2);
7323 /* Parse an objc-protocol-definition.
7325 objc-protocol-definition:
7326 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7327 @protocol identifier-list ;
7329 "@protocol identifier ;" should be resolved as "@protocol
7330 identifier-list ;": objc-methodprotolist may not start with a
7331 semicolon in the first alternative if objc-protocol-refs are
7335 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
7337 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
7339 c_parser_consume_token (parser);
7340 if (c_parser_next_token_is_not (parser, CPP_NAME))
7342 c_parser_error (parser, "expected identifier");
7345 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
7346 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
7348 /* Any identifiers, including those declared as type names, are
7353 if (c_parser_next_token_is_not (parser, CPP_NAME))
7355 c_parser_error (parser, "expected identifier");
7358 id = c_parser_peek_token (parser)->value;
7359 objc_declare_protocol (id, attributes);
7360 c_parser_consume_token (parser);
7361 if (c_parser_next_token_is (parser, CPP_COMMA))
7362 c_parser_consume_token (parser);
7366 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7370 tree id = c_parser_peek_token (parser)->value;
7371 tree proto = NULL_TREE;
7372 c_parser_consume_token (parser);
7373 if (c_parser_next_token_is (parser, CPP_LESS))
7374 proto = c_parser_objc_protocol_refs (parser);
7375 parser->objc_pq_context = true;
7376 objc_start_protocol (id, proto, attributes);
7377 c_parser_objc_methodprotolist (parser);
7378 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
7379 parser->objc_pq_context = false;
7380 objc_finish_interface ();
7384 /* Parse an objc-method-type.
7390 Return true if it is a class method (+) and false if it is
7391 an instance method (-).
7394 c_parser_objc_method_type (c_parser *parser)
7396 switch (c_parser_peek_token (parser)->type)
7399 c_parser_consume_token (parser);
7402 c_parser_consume_token (parser);
7409 /* Parse an objc-method-definition.
7411 objc-method-definition:
7412 objc-method-type objc-method-decl ;[opt] compound-statement
7416 c_parser_objc_method_definition (c_parser *parser)
7418 bool is_class_method = c_parser_objc_method_type (parser);
7419 tree decl, attributes = NULL_TREE, expr = NULL_TREE;
7420 parser->objc_pq_context = true;
7421 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7423 if (decl == error_mark_node)
7424 return; /* Bail here. */
7426 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
7428 c_parser_consume_token (parser);
7429 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7430 "extra semicolon in method definition specified");
7433 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7435 c_parser_error (parser, "expected %<{%>");
7439 parser->objc_pq_context = false;
7440 if (objc_start_method_definition (is_class_method, decl, attributes, expr))
7442 add_stmt (c_parser_compound_statement (parser));
7443 objc_finish_method_definition (current_function_decl);
7447 /* This code is executed when we find a method definition
7448 outside of an @implementation context (or invalid for other
7449 reasons). Parse the method (to keep going) but do not emit
7452 c_parser_compound_statement (parser);
7456 /* Parse an objc-methodprotolist.
7458 objc-methodprotolist:
7460 objc-methodprotolist objc-methodproto
7461 objc-methodprotolist declaration
7462 objc-methodprotolist ;
7466 The declaration is a data definition, which may be missing
7467 declaration specifiers under the same rules and diagnostics as
7468 other data definitions outside functions, and the stray semicolon
7469 is diagnosed the same way as a stray semicolon outside a
7473 c_parser_objc_methodprotolist (c_parser *parser)
7477 /* The list is terminated by @end. */
7478 switch (c_parser_peek_token (parser)->type)
7481 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
7482 "ISO C does not allow extra %<;%> outside of a function");
7483 c_parser_consume_token (parser);
7487 c_parser_objc_methodproto (parser);
7490 c_parser_pragma (parser, pragma_external);
7495 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
7497 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
7498 c_parser_objc_at_property_declaration (parser);
7499 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
7501 objc_set_method_opt (true);
7502 c_parser_consume_token (parser);
7504 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
7506 objc_set_method_opt (false);
7507 c_parser_consume_token (parser);
7510 c_parser_declaration_or_fndef (parser, false, false, true,
7517 /* Parse an objc-methodproto.
7520 objc-method-type objc-method-decl ;
7524 c_parser_objc_methodproto (c_parser *parser)
7526 bool is_class_method = c_parser_objc_method_type (parser);
7527 tree decl, attributes = NULL_TREE;
7529 /* Remember protocol qualifiers in prototypes. */
7530 parser->objc_pq_context = true;
7531 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes,
7533 /* Forget protocol qualifiers now. */
7534 parser->objc_pq_context = false;
7536 /* Do not allow the presence of attributes to hide an erroneous
7537 method implementation in the interface section. */
7538 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7540 c_parser_error (parser, "expected %<;%>");
7544 if (decl != error_mark_node)
7545 objc_add_method_declaration (is_class_method, decl, attributes);
7547 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7550 /* If we are at a position that method attributes may be present, check that
7551 there are not any parsed already (a syntax error) and then collect any
7552 specified at the current location. Finally, if new attributes were present,
7553 check that the next token is legal ( ';' for decls and '{' for defs). */
7556 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7561 c_parser_error (parser,
7562 "method attributes must be specified at the end only");
7563 *attributes = NULL_TREE;
7567 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7568 *attributes = c_parser_attributes (parser);
7570 /* If there were no attributes here, just report any earlier error. */
7571 if (*attributes == NULL_TREE || bad)
7574 /* If the attributes are followed by a ; or {, then just report any earlier
7576 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7577 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7580 /* We've got attributes, but not at the end. */
7581 c_parser_error (parser,
7582 "expected %<;%> or %<{%> after method attribute definition");
7586 /* Parse an objc-method-decl.
7589 ( objc-type-name ) objc-selector
7591 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7592 objc-keyword-selector objc-optparmlist
7595 objc-keyword-selector:
7597 objc-keyword-selector objc-keyword-decl
7600 objc-selector : ( objc-type-name ) identifier
7601 objc-selector : identifier
7602 : ( objc-type-name ) identifier
7606 objc-optparms objc-optellipsis
7610 objc-opt-parms , parameter-declaration
7618 c_parser_objc_method_decl (c_parser *parser, bool is_class_method,
7619 tree *attributes, tree *expr)
7621 tree type = NULL_TREE;
7623 tree parms = NULL_TREE;
7624 bool ellipsis = false;
7625 bool attr_err = false;
7627 *attributes = NULL_TREE;
7628 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7630 c_parser_consume_token (parser);
7631 type = c_parser_objc_type_name (parser);
7632 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7634 sel = c_parser_objc_selector (parser);
7635 /* If there is no selector, or a colon follows, we have an
7636 objc-keyword-selector. If there is a selector, and a colon does
7637 not follow, that selector ends the objc-method-decl. */
7638 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7641 tree list = NULL_TREE;
7644 tree atype = NULL_TREE, id, keyworddecl;
7645 tree param_attr = NULL_TREE;
7646 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7648 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7650 c_parser_consume_token (parser);
7651 atype = c_parser_objc_type_name (parser);
7652 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7655 /* New ObjC allows attributes on method parameters. */
7656 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7657 param_attr = c_parser_attributes (parser);
7658 if (c_parser_next_token_is_not (parser, CPP_NAME))
7660 c_parser_error (parser, "expected identifier");
7661 return error_mark_node;
7663 id = c_parser_peek_token (parser)->value;
7664 c_parser_consume_token (parser);
7665 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7666 list = chainon (list, keyworddecl);
7667 tsel = c_parser_objc_selector (parser);
7668 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7672 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7674 /* Parse the optional parameter list. Optional Objective-C
7675 method parameters follow the C syntax, and may include '...'
7676 to denote a variable number of arguments. */
7677 parms = make_node (TREE_LIST);
7678 while (c_parser_next_token_is (parser, CPP_COMMA))
7680 struct c_parm *parm;
7681 c_parser_consume_token (parser);
7682 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7685 c_parser_consume_token (parser);
7686 attr_err |= c_parser_objc_maybe_method_attributes
7687 (parser, attributes) ;
7690 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7693 parms = chainon (parms,
7694 build_tree_list (NULL_TREE, grokparm (parm, expr)));
7699 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7703 c_parser_error (parser, "objective-c method declaration is expected");
7704 return error_mark_node;
7708 return error_mark_node;
7710 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis);
7713 /* Parse an objc-type-name.
7716 objc-type-qualifiers[opt] type-name
7717 objc-type-qualifiers[opt]
7719 objc-type-qualifiers:
7721 objc-type-qualifiers objc-type-qualifier
7723 objc-type-qualifier: one of
7724 in out inout bycopy byref oneway
7728 c_parser_objc_type_name (c_parser *parser)
7730 tree quals = NULL_TREE;
7731 struct c_type_name *type_name = NULL;
7732 tree type = NULL_TREE;
7735 c_token *token = c_parser_peek_token (parser);
7736 if (token->type == CPP_KEYWORD
7737 && (token->keyword == RID_IN
7738 || token->keyword == RID_OUT
7739 || token->keyword == RID_INOUT
7740 || token->keyword == RID_BYCOPY
7741 || token->keyword == RID_BYREF
7742 || token->keyword == RID_ONEWAY))
7744 quals = chainon (build_tree_list (NULL_TREE, token->value), quals);
7745 c_parser_consume_token (parser);
7750 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type))
7751 type_name = c_parser_type_name (parser);
7753 type = groktypename (type_name, NULL, NULL);
7755 /* If the type is unknown, and error has already been produced and
7756 we need to recover from the error. In that case, use NULL_TREE
7757 for the type, as if no type had been specified; this will use the
7758 default type ('id') which is good for error recovery. */
7759 if (type == error_mark_node)
7762 return build_tree_list (quals, type);
7765 /* Parse objc-protocol-refs.
7772 c_parser_objc_protocol_refs (c_parser *parser)
7774 tree list = NULL_TREE;
7775 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7776 c_parser_consume_token (parser);
7777 /* Any identifiers, including those declared as type names, are OK
7782 if (c_parser_next_token_is_not (parser, CPP_NAME))
7784 c_parser_error (parser, "expected identifier");
7787 id = c_parser_peek_token (parser)->value;
7788 list = chainon (list, build_tree_list (NULL_TREE, id));
7789 c_parser_consume_token (parser);
7790 if (c_parser_next_token_is (parser, CPP_COMMA))
7791 c_parser_consume_token (parser);
7795 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7799 /* Parse an objc-try-catch-finally-statement.
7801 objc-try-catch-finally-statement:
7802 @try compound-statement objc-catch-list[opt]
7803 @try compound-statement objc-catch-list[opt] @finally compound-statement
7806 @catch ( objc-catch-parameter-declaration ) compound-statement
7807 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
7809 objc-catch-parameter-declaration:
7810 parameter-declaration
7813 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
7815 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
7816 for C++. Keep them in sync. */
7819 c_parser_objc_try_catch_finally_statement (c_parser *parser)
7821 location_t location;
7824 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7825 c_parser_consume_token (parser);
7826 location = c_parser_peek_token (parser)->location;
7827 objc_maybe_warn_exceptions (location);
7828 stmt = c_parser_compound_statement (parser);
7829 objc_begin_try_stmt (location, stmt);
7831 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7833 struct c_parm *parm;
7834 tree parameter_declaration = error_mark_node;
7835 bool seen_open_paren = false;
7837 c_parser_consume_token (parser);
7838 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7839 seen_open_paren = true;
7840 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7842 /* We have "@catch (...)" (where the '...' are literally
7843 what is in the code). Skip the '...'.
7844 parameter_declaration is set to NULL_TREE, and
7845 objc_being_catch_clauses() knows that that means
7847 c_parser_consume_token (parser);
7848 parameter_declaration = NULL_TREE;
7852 /* We have "@catch (NSException *exception)" or something
7853 like that. Parse the parameter declaration. */
7854 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7856 parameter_declaration = error_mark_node;
7858 parameter_declaration = grokparm (parm, NULL);
7860 if (seen_open_paren)
7861 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7864 /* If there was no open parenthesis, we are recovering from
7865 an error, and we are trying to figure out what mistake
7866 the user has made. */
7868 /* If there is an immediate closing parenthesis, the user
7869 probably forgot the opening one (ie, they typed "@catch
7870 NSException *e)". Parse the closing parenthesis and keep
7872 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
7873 c_parser_consume_token (parser);
7875 /* If these is no immediate closing parenthesis, the user
7876 probably doesn't know that parenthesis are required at
7877 all (ie, they typed "@catch NSException *e"). So, just
7878 forget about the closing parenthesis and keep going. */
7880 objc_begin_catch_clause (parameter_declaration);
7881 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7882 c_parser_compound_statement_nostart (parser);
7883 objc_finish_catch_clause ();
7885 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7887 c_parser_consume_token (parser);
7888 location = c_parser_peek_token (parser)->location;
7889 stmt = c_parser_compound_statement (parser);
7890 objc_build_finally_clause (location, stmt);
7892 objc_finish_try_stmt ();
7895 /* Parse an objc-synchronized-statement.
7897 objc-synchronized-statement:
7898 @synchronized ( expression ) compound-statement
7902 c_parser_objc_synchronized_statement (c_parser *parser)
7906 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7907 c_parser_consume_token (parser);
7908 loc = c_parser_peek_token (parser)->location;
7909 objc_maybe_warn_exceptions (loc);
7910 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7912 expr = c_parser_expression (parser).value;
7913 expr = c_fully_fold (expr, false, NULL);
7914 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7917 expr = error_mark_node;
7918 stmt = c_parser_compound_statement (parser);
7919 objc_build_synchronized (loc, expr, stmt);
7922 /* Parse an objc-selector; return NULL_TREE without an error if the
7923 next token is not an objc-selector.
7928 enum struct union if else while do for switch case default
7929 break continue return goto asm sizeof typeof __alignof
7930 unsigned long const short volatile signed restrict _Complex
7931 in out inout bycopy byref oneway int char float double void _Bool
7933 ??? Why this selection of keywords but not, for example, storage
7934 class specifiers? */
7937 c_parser_objc_selector (c_parser *parser)
7939 c_token *token = c_parser_peek_token (parser);
7940 tree value = token->value;
7941 if (token->type == CPP_NAME)
7943 c_parser_consume_token (parser);
7946 if (token->type != CPP_KEYWORD)
7948 switch (token->keyword)
7990 c_parser_consume_token (parser);
7997 /* Parse an objc-selector-arg.
8001 objc-keywordname-list
8003 objc-keywordname-list:
8005 objc-keywordname-list objc-keywordname
8013 c_parser_objc_selector_arg (c_parser *parser)
8015 tree sel = c_parser_objc_selector (parser);
8016 tree list = NULL_TREE;
8017 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
8021 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8023 list = chainon (list, build_tree_list (sel, NULL_TREE));
8024 sel = c_parser_objc_selector (parser);
8025 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
8031 /* Parse an objc-receiver.
8040 c_parser_objc_receiver (c_parser *parser)
8042 if (c_parser_peek_token (parser)->type == CPP_NAME
8043 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
8044 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
8046 tree id = c_parser_peek_token (parser)->value;
8047 c_parser_consume_token (parser);
8048 return objc_get_class_reference (id);
8050 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
8053 /* Parse objc-message-args.
8057 objc-keywordarg-list
8059 objc-keywordarg-list:
8061 objc-keywordarg-list objc-keywordarg
8064 objc-selector : objc-keywordexpr
8069 c_parser_objc_message_args (c_parser *parser)
8071 tree sel = c_parser_objc_selector (parser);
8072 tree list = NULL_TREE;
8073 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
8078 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8079 return error_mark_node;
8080 keywordexpr = c_parser_objc_keywordexpr (parser);
8081 list = chainon (list, build_tree_list (sel, keywordexpr));
8082 sel = c_parser_objc_selector (parser);
8083 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
8089 /* Parse an objc-keywordexpr.
8096 c_parser_objc_keywordexpr (c_parser *parser)
8099 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
8100 if (VEC_length (tree, expr_list) == 1)
8102 /* Just return the expression, remove a level of
8104 ret = VEC_index (tree, expr_list, 0);
8108 /* We have a comma expression, we will collapse later. */
8109 ret = build_tree_list_vec (expr_list);
8111 release_tree_vector (expr_list);
8115 /* A check, needed in several places, that ObjC interface, implementation or
8116 method definitions are not prefixed by incorrect items. */
8118 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
8119 struct c_declspecs *specs)
8121 if (!specs->declspecs_seen_p || specs->non_sc_seen_p
8122 || specs->typespec_kind != ctsk_none)
8124 c_parser_error (parser,
8125 "no type or storage class may be specified here,");
8126 c_parser_skip_to_end_of_block_or_statement (parser);
8132 /* Parse an Objective-C @property declaration. The syntax is:
8134 objc-property-declaration:
8135 '@property' objc-property-attributes[opt] struct-declaration ;
8137 objc-property-attributes:
8138 '(' objc-property-attribute-list ')'
8140 objc-property-attribute-list:
8141 objc-property-attribute
8142 objc-property-attribute-list, objc-property-attribute
8144 objc-property-attribute
8145 'getter' = identifier
8146 'setter' = identifier
8155 @property NSString *name;
8156 @property (readonly) id object;
8157 @property (retain, nonatomic, getter=getTheName) id name;
8158 @property int a, b, c;
8160 PS: This function is identical to cp_parser_objc_at_propery_declaration
8161 for C++. Keep them in sync. */
8163 c_parser_objc_at_property_declaration (c_parser *parser)
8165 /* The following variables hold the attributes of the properties as
8166 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8167 seen. When we see an attribute, we set them to 'true' (if they
8168 are boolean properties) or to the identifier (if they have an
8169 argument, ie, for getter and setter). Note that here we only
8170 parse the list of attributes, check the syntax and accumulate the
8171 attributes that we find. objc_add_property_declaration() will
8172 then process the information. */
8173 bool property_assign = false;
8174 bool property_copy = false;
8175 tree property_getter_ident = NULL_TREE;
8176 bool property_nonatomic = false;
8177 bool property_readonly = false;
8178 bool property_readwrite = false;
8179 bool property_retain = false;
8180 tree property_setter_ident = NULL_TREE;
8182 /* 'properties' is the list of properties that we read. Usually a
8183 single one, but maybe more (eg, in "@property int a, b, c;" there
8188 loc = c_parser_peek_token (parser)->location;
8189 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY));
8191 c_parser_consume_token (parser); /* Eat '@property'. */
8193 /* Parse the optional attribute list... */
8194 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8197 c_parser_consume_token (parser);
8199 /* Property attribute keywords are valid now. */
8200 parser->objc_property_attr_context = true;
8204 bool syntax_error = false;
8205 c_token *token = c_parser_peek_token (parser);
8208 if (token->type != CPP_KEYWORD)
8210 if (token->type == CPP_CLOSE_PAREN)
8211 c_parser_error (parser, "expected identifier");
8214 c_parser_consume_token (parser);
8215 c_parser_error (parser, "unknown property attribute");
8219 keyword = token->keyword;
8220 c_parser_consume_token (parser);
8223 case RID_ASSIGN: property_assign = true; break;
8224 case RID_COPY: property_copy = true; break;
8225 case RID_NONATOMIC: property_nonatomic = true; break;
8226 case RID_READONLY: property_readonly = true; break;
8227 case RID_READWRITE: property_readwrite = true; break;
8228 case RID_RETAIN: property_retain = true; break;
8232 if (c_parser_next_token_is_not (parser, CPP_EQ))
8234 if (keyword == RID_GETTER)
8235 c_parser_error (parser,
8236 "missing %<=%> (after %<getter%> attribute)");
8238 c_parser_error (parser,
8239 "missing %<=%> (after %<setter%> attribute)");
8240 syntax_error = true;
8243 c_parser_consume_token (parser); /* eat the = */
8244 if (c_parser_next_token_is_not (parser, CPP_NAME))
8246 c_parser_error (parser, "expected identifier");
8247 syntax_error = true;
8250 if (keyword == RID_SETTER)
8252 if (property_setter_ident != NULL_TREE)
8253 c_parser_error (parser, "the %<setter%> attribute may only be specified once");
8255 property_setter_ident = c_parser_peek_token (parser)->value;
8256 c_parser_consume_token (parser);
8257 if (c_parser_next_token_is_not (parser, CPP_COLON))
8258 c_parser_error (parser, "setter name must terminate with %<:%>");
8260 c_parser_consume_token (parser);
8264 if (property_getter_ident != NULL_TREE)
8265 c_parser_error (parser, "the %<getter%> attribute may only be specified once");
8267 property_getter_ident = c_parser_peek_token (parser)->value;
8268 c_parser_consume_token (parser);
8272 c_parser_error (parser, "unknown property attribute");
8273 syntax_error = true;
8280 if (c_parser_next_token_is (parser, CPP_COMMA))
8281 c_parser_consume_token (parser);
8285 parser->objc_property_attr_context = false;
8286 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8288 /* ... and the property declaration(s). */
8289 properties = c_parser_struct_declaration (parser);
8291 if (properties == error_mark_node)
8293 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8294 parser->error = false;
8298 if (properties == NULL_TREE)
8299 c_parser_error (parser, "expected identifier");
8302 /* Comma-separated properties are chained together in
8303 reverse order; add them one by one. */
8304 properties = nreverse (properties);
8306 for (; properties; properties = TREE_CHAIN (properties))
8307 objc_add_property_declaration (loc, copy_node (properties),
8308 property_readonly, property_readwrite,
8309 property_assign, property_retain,
8310 property_copy, property_nonatomic,
8311 property_getter_ident, property_setter_ident);
8314 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8315 parser->error = false;
8318 /* Parse an Objective-C @synthesize declaration. The syntax is:
8320 objc-synthesize-declaration:
8321 @synthesize objc-synthesize-identifier-list ;
8323 objc-synthesize-identifier-list:
8324 objc-synthesize-identifier
8325 objc-synthesize-identifier-list, objc-synthesize-identifier
8327 objc-synthesize-identifier
8329 identifier = identifier
8332 @synthesize MyProperty;
8333 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8335 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8336 for C++. Keep them in sync.
8339 c_parser_objc_at_synthesize_declaration (c_parser *parser)
8341 tree list = NULL_TREE;
8343 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE));
8344 loc = c_parser_peek_token (parser)->location;
8346 c_parser_consume_token (parser);
8349 tree property, ivar;
8350 if (c_parser_next_token_is_not (parser, CPP_NAME))
8352 c_parser_error (parser, "expected identifier");
8353 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8354 /* Once we find the semicolon, we can resume normal parsing.
8355 We have to reset parser->error manually because
8356 c_parser_skip_until_found() won't reset it for us if the
8357 next token is precisely a semicolon. */
8358 parser->error = false;
8361 property = c_parser_peek_token (parser)->value;
8362 c_parser_consume_token (parser);
8363 if (c_parser_next_token_is (parser, CPP_EQ))
8365 c_parser_consume_token (parser);
8366 if (c_parser_next_token_is_not (parser, CPP_NAME))
8368 c_parser_error (parser, "expected identifier");
8369 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8370 parser->error = false;
8373 ivar = c_parser_peek_token (parser)->value;
8374 c_parser_consume_token (parser);
8378 list = chainon (list, build_tree_list (ivar, property));
8379 if (c_parser_next_token_is (parser, CPP_COMMA))
8380 c_parser_consume_token (parser);
8384 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8385 objc_add_synthesize_declaration (loc, list);
8388 /* Parse an Objective-C @dynamic declaration. The syntax is:
8390 objc-dynamic-declaration:
8391 @dynamic identifier-list ;
8394 @dynamic MyProperty;
8395 @dynamic MyProperty, AnotherProperty;
8397 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8398 for C++. Keep them in sync.
8401 c_parser_objc_at_dynamic_declaration (c_parser *parser)
8403 tree list = NULL_TREE;
8405 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC));
8406 loc = c_parser_peek_token (parser)->location;
8408 c_parser_consume_token (parser);
8412 if (c_parser_next_token_is_not (parser, CPP_NAME))
8414 c_parser_error (parser, "expected identifier");
8415 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
8416 parser->error = false;
8419 property = c_parser_peek_token (parser)->value;
8420 list = chainon (list, build_tree_list (NULL_TREE, property));
8421 c_parser_consume_token (parser);
8422 if (c_parser_next_token_is (parser, CPP_COMMA))
8423 c_parser_consume_token (parser);
8427 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8428 objc_add_dynamic_declaration (loc, list);
8432 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
8433 should be considered, statements. ALLOW_STMT is true if we're within
8434 the context of a function and such pragmas are to be allowed. Returns
8435 true if we actually parsed such a pragma. */
8438 c_parser_pragma (c_parser *parser, enum pragma_context context)
8442 id = c_parser_peek_token (parser)->pragma_kind;
8443 gcc_assert (id != PRAGMA_NONE);
8447 case PRAGMA_OMP_BARRIER:
8448 if (context != pragma_compound)
8450 if (context == pragma_stmt)
8451 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
8452 "used in compound statements");
8455 c_parser_omp_barrier (parser);
8458 case PRAGMA_OMP_FLUSH:
8459 if (context != pragma_compound)
8461 if (context == pragma_stmt)
8462 c_parser_error (parser, "%<#pragma omp flush%> may only be "
8463 "used in compound statements");
8466 c_parser_omp_flush (parser);
8469 case PRAGMA_OMP_TASKWAIT:
8470 if (context != pragma_compound)
8472 if (context == pragma_stmt)
8473 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
8474 "used in compound statements");
8477 c_parser_omp_taskwait (parser);
8480 case PRAGMA_OMP_TASKYIELD:
8481 if (context != pragma_compound)
8483 if (context == pragma_stmt)
8484 c_parser_error (parser, "%<#pragma omp taskyield%> may only be "
8485 "used in compound statements");
8488 c_parser_omp_taskyield (parser);
8491 case PRAGMA_OMP_THREADPRIVATE:
8492 c_parser_omp_threadprivate (parser);
8495 case PRAGMA_OMP_SECTION:
8496 error_at (c_parser_peek_token (parser)->location,
8497 "%<#pragma omp section%> may only be used in "
8498 "%<#pragma omp sections%> construct");
8499 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8502 case PRAGMA_GCC_PCH_PREPROCESS:
8503 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
8504 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8508 if (id < PRAGMA_FIRST_EXTERNAL)
8510 if (context == pragma_external)
8513 c_parser_error (parser, "expected declaration specifiers");
8514 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
8517 c_parser_omp_construct (parser);
8523 c_parser_consume_pragma (parser);
8524 c_invoke_pragma_handler (id);
8526 /* Skip to EOL, but suppress any error message. Those will have been
8527 generated by the handler routine through calling error, as opposed
8528 to calling c_parser_error. */
8529 parser->error = true;
8530 c_parser_skip_to_pragma_eol (parser);
8535 /* The interface the pragma parsers have to the lexer. */
8538 pragma_lex (tree *value)
8540 c_token *tok = c_parser_peek_token (the_parser);
8541 enum cpp_ttype ret = tok->type;
8543 *value = tok->value;
8544 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
8548 if (ret == CPP_KEYWORD)
8550 c_parser_consume_token (the_parser);
8557 c_parser_pragma_pch_preprocess (c_parser *parser)
8561 c_parser_consume_pragma (parser);
8562 if (c_parser_next_token_is (parser, CPP_STRING))
8564 name = c_parser_peek_token (parser)->value;
8565 c_parser_consume_token (parser);
8568 c_parser_error (parser, "expected string literal");
8569 c_parser_skip_to_pragma_eol (parser);
8572 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
8575 /* OpenMP 2.5 parsing routines. */
8577 /* Returns name of the next clause.
8578 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
8579 the token is not consumed. Otherwise appropriate pragma_omp_clause is
8580 returned and the token is consumed. */
8582 static pragma_omp_clause
8583 c_parser_omp_clause_name (c_parser *parser)
8585 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
8587 if (c_parser_next_token_is_keyword (parser, RID_IF))
8588 result = PRAGMA_OMP_CLAUSE_IF;
8589 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
8590 result = PRAGMA_OMP_CLAUSE_DEFAULT;
8591 else if (c_parser_next_token_is (parser, CPP_NAME))
8593 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8598 if (!strcmp ("collapse", p))
8599 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
8600 else if (!strcmp ("copyin", p))
8601 result = PRAGMA_OMP_CLAUSE_COPYIN;
8602 else if (!strcmp ("copyprivate", p))
8603 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
8606 if (!strcmp ("final", p))
8607 result = PRAGMA_OMP_CLAUSE_FINAL;
8608 else if (!strcmp ("firstprivate", p))
8609 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
8612 if (!strcmp ("lastprivate", p))
8613 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
8616 if (!strcmp ("mergeable", p))
8617 result = PRAGMA_OMP_CLAUSE_MERGEABLE;
8620 if (!strcmp ("nowait", p))
8621 result = PRAGMA_OMP_CLAUSE_NOWAIT;
8622 else if (!strcmp ("num_threads", p))
8623 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
8626 if (!strcmp ("ordered", p))
8627 result = PRAGMA_OMP_CLAUSE_ORDERED;
8630 if (!strcmp ("private", p))
8631 result = PRAGMA_OMP_CLAUSE_PRIVATE;
8634 if (!strcmp ("reduction", p))
8635 result = PRAGMA_OMP_CLAUSE_REDUCTION;
8638 if (!strcmp ("schedule", p))
8639 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
8640 else if (!strcmp ("shared", p))
8641 result = PRAGMA_OMP_CLAUSE_SHARED;
8644 if (!strcmp ("untied", p))
8645 result = PRAGMA_OMP_CLAUSE_UNTIED;
8650 if (result != PRAGMA_OMP_CLAUSE_NONE)
8651 c_parser_consume_token (parser);
8656 /* Validate that a clause of the given type does not already exist. */
8659 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
8664 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8665 if (OMP_CLAUSE_CODE (c) == code)
8667 location_t loc = OMP_CLAUSE_LOCATION (c);
8668 error_at (loc, "too many %qs clauses", name);
8676 variable-list , identifier
8678 If KIND is nonzero, create the appropriate node and install the
8679 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
8680 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
8682 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
8683 return the list created. */
8686 c_parser_omp_variable_list (c_parser *parser,
8687 location_t clause_loc,
8688 enum omp_clause_code kind,
8691 if (c_parser_next_token_is_not (parser, CPP_NAME)
8692 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
8693 c_parser_error (parser, "expected identifier");
8695 while (c_parser_next_token_is (parser, CPP_NAME)
8696 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
8698 tree t = lookup_name (c_parser_peek_token (parser)->value);
8701 undeclared_variable (c_parser_peek_token (parser)->location,
8702 c_parser_peek_token (parser)->value);
8703 else if (t == error_mark_node)
8707 tree u = build_omp_clause (clause_loc, kind);
8708 OMP_CLAUSE_DECL (u) = t;
8709 OMP_CLAUSE_CHAIN (u) = list;
8713 list = tree_cons (t, NULL_TREE, list);
8715 c_parser_consume_token (parser);
8717 if (c_parser_next_token_is_not (parser, CPP_COMMA))
8720 c_parser_consume_token (parser);
8726 /* Similarly, but expect leading and trailing parenthesis. This is a very
8727 common case for omp clauses. */
8730 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
8733 /* The clauses location. */
8734 location_t loc = c_parser_peek_token (parser)->location;
8736 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8738 list = c_parser_omp_variable_list (parser, loc, kind, list);
8739 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8745 collapse ( constant-expression ) */
8748 c_parser_omp_clause_collapse (c_parser *parser, tree list)
8750 tree c, num = error_mark_node;
8754 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
8756 loc = c_parser_peek_token (parser)->location;
8757 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8759 num = c_parser_expr_no_commas (parser, NULL).value;
8760 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8762 if (num == error_mark_node)
8764 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8765 || !host_integerp (num, 0)
8766 || (n = tree_low_cst (num, 0)) <= 0
8770 "collapse argument needs positive constant integer expression");
8773 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8774 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8775 OMP_CLAUSE_CHAIN (c) = list;
8780 copyin ( variable-list ) */
8783 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8785 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8789 copyprivate ( variable-list ) */
8792 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8794 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8798 default ( shared | none ) */
8801 c_parser_omp_clause_default (c_parser *parser, tree list)
8803 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8804 location_t loc = c_parser_peek_token (parser)->location;
8807 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8809 if (c_parser_next_token_is (parser, CPP_NAME))
8811 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8816 if (strcmp ("none", p) != 0)
8818 kind = OMP_CLAUSE_DEFAULT_NONE;
8822 if (strcmp ("shared", p) != 0)
8824 kind = OMP_CLAUSE_DEFAULT_SHARED;
8831 c_parser_consume_token (parser);
8836 c_parser_error (parser, "expected %<none%> or %<shared%>");
8838 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8840 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8843 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8844 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8845 OMP_CLAUSE_CHAIN (c) = list;
8846 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8852 firstprivate ( variable-list ) */
8855 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8857 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8861 final ( expression ) */
8864 c_parser_omp_clause_final (c_parser *parser, tree list)
8866 location_t loc = c_parser_peek_token (parser)->location;
8867 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8869 tree t = c_parser_paren_condition (parser);
8872 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final");
8874 c = build_omp_clause (loc, OMP_CLAUSE_FINAL);
8875 OMP_CLAUSE_FINAL_EXPR (c) = t;
8876 OMP_CLAUSE_CHAIN (c) = list;
8880 c_parser_error (parser, "expected %<(%>");
8886 if ( expression ) */
8889 c_parser_omp_clause_if (c_parser *parser, tree list)
8891 location_t loc = c_parser_peek_token (parser)->location;
8892 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8894 tree t = c_parser_paren_condition (parser);
8897 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8899 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8900 OMP_CLAUSE_IF_EXPR (c) = t;
8901 OMP_CLAUSE_CHAIN (c) = list;
8905 c_parser_error (parser, "expected %<(%>");
8911 lastprivate ( variable-list ) */
8914 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8916 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8923 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8927 /* FIXME: Should we allow duplicates? */
8928 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable");
8930 c = build_omp_clause (c_parser_peek_token (parser)->location,
8931 OMP_CLAUSE_MERGEABLE);
8932 OMP_CLAUSE_CHAIN (c) = list;
8941 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8944 location_t loc = c_parser_peek_token (parser)->location;
8946 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8948 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8949 OMP_CLAUSE_CHAIN (c) = list;
8954 num_threads ( expression ) */
8957 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8959 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8960 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8962 location_t expr_loc = c_parser_peek_token (parser)->location;
8963 tree c, t = c_parser_expression (parser).value;
8964 t = c_fully_fold (t, false, NULL);
8966 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8968 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8970 c_parser_error (parser, "expected integer expression");
8974 /* Attempt to statically determine when the number isn't positive. */
8975 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8976 build_int_cst (TREE_TYPE (t), 0));
8977 if (CAN_HAVE_LOCATION_P (c))
8978 SET_EXPR_LOCATION (c, expr_loc);
8979 if (c == boolean_true_node)
8981 warning_at (expr_loc, 0,
8982 "%<num_threads%> value must be positive");
8983 t = integer_one_node;
8986 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8988 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8989 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8990 OMP_CLAUSE_CHAIN (c) = list;
9001 c_parser_omp_clause_ordered (c_parser *parser, tree list)
9005 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
9007 c = build_omp_clause (c_parser_peek_token (parser)->location,
9008 OMP_CLAUSE_ORDERED);
9009 OMP_CLAUSE_CHAIN (c) = list;
9015 private ( variable-list ) */
9018 c_parser_omp_clause_private (c_parser *parser, tree list)
9020 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
9024 reduction ( reduction-operator : variable-list )
9027 One of: + * - & ^ | && ||
9032 One of: + * - & ^ | && || max min */
9035 c_parser_omp_clause_reduction (c_parser *parser, tree list)
9037 location_t clause_loc = c_parser_peek_token (parser)->location;
9038 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9040 enum tree_code code;
9042 switch (c_parser_peek_token (parser)->type)
9054 code = BIT_AND_EXPR;
9057 code = BIT_XOR_EXPR;
9060 code = BIT_IOR_EXPR;
9063 code = TRUTH_ANDIF_EXPR;
9066 code = TRUTH_ORIF_EXPR;
9071 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9072 if (strcmp (p, "min") == 0)
9077 if (strcmp (p, "max") == 0)
9085 c_parser_error (parser,
9086 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9087 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9088 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
9091 c_parser_consume_token (parser);
9092 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
9096 nl = c_parser_omp_variable_list (parser, clause_loc,
9097 OMP_CLAUSE_REDUCTION, list);
9098 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
9099 OMP_CLAUSE_REDUCTION_CODE (c) = code;
9103 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9109 schedule ( schedule-kind )
9110 schedule ( schedule-kind , expression )
9113 static | dynamic | guided | runtime | auto
9117 c_parser_omp_clause_schedule (c_parser *parser, tree list)
9120 location_t loc = c_parser_peek_token (parser)->location;
9122 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9125 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
9127 if (c_parser_next_token_is (parser, CPP_NAME))
9129 tree kind = c_parser_peek_token (parser)->value;
9130 const char *p = IDENTIFIER_POINTER (kind);
9135 if (strcmp ("dynamic", p) != 0)
9137 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
9141 if (strcmp ("guided", p) != 0)
9143 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
9147 if (strcmp ("runtime", p) != 0)
9149 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
9156 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
9157 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
9158 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
9159 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
9163 c_parser_consume_token (parser);
9164 if (c_parser_next_token_is (parser, CPP_COMMA))
9167 c_parser_consume_token (parser);
9169 here = c_parser_peek_token (parser)->location;
9170 t = c_parser_expr_no_commas (parser, NULL).value;
9171 t = c_fully_fold (t, false, NULL);
9173 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
9174 error_at (here, "schedule %<runtime%> does not take "
9175 "a %<chunk_size%> parameter");
9176 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
9178 "schedule %<auto%> does not take "
9179 "a %<chunk_size%> parameter");
9180 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
9181 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
9183 c_parser_error (parser, "expected integer expression");
9185 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9188 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9189 "expected %<,%> or %<)%>");
9191 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
9192 OMP_CLAUSE_CHAIN (c) = list;
9196 c_parser_error (parser, "invalid schedule kind");
9197 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
9202 shared ( variable-list ) */
9205 c_parser_omp_clause_shared (c_parser *parser, tree list)
9207 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
9214 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
9218 /* FIXME: Should we allow duplicates? */
9219 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
9221 c = build_omp_clause (c_parser_peek_token (parser)->location,
9223 OMP_CLAUSE_CHAIN (c) = list;
9228 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9229 is a bitmask in MASK. Return the list of clauses found; the result
9230 of clause default goes in *pdefault. */
9233 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
9236 tree clauses = NULL;
9239 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9242 pragma_omp_clause c_kind;
9244 tree prev = clauses;
9246 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
9247 c_parser_consume_token (parser);
9250 here = c_parser_peek_token (parser)->location;
9251 c_kind = c_parser_omp_clause_name (parser);
9255 case PRAGMA_OMP_CLAUSE_COLLAPSE:
9256 clauses = c_parser_omp_clause_collapse (parser, clauses);
9257 c_name = "collapse";
9259 case PRAGMA_OMP_CLAUSE_COPYIN:
9260 clauses = c_parser_omp_clause_copyin (parser, clauses);
9263 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
9264 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
9265 c_name = "copyprivate";
9267 case PRAGMA_OMP_CLAUSE_DEFAULT:
9268 clauses = c_parser_omp_clause_default (parser, clauses);
9271 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
9272 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
9273 c_name = "firstprivate";
9275 case PRAGMA_OMP_CLAUSE_FINAL:
9276 clauses = c_parser_omp_clause_final (parser, clauses);
9279 case PRAGMA_OMP_CLAUSE_IF:
9280 clauses = c_parser_omp_clause_if (parser, clauses);
9283 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
9284 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
9285 c_name = "lastprivate";
9287 case PRAGMA_OMP_CLAUSE_MERGEABLE:
9288 clauses = c_parser_omp_clause_mergeable (parser, clauses);
9289 c_name = "mergeable";
9291 case PRAGMA_OMP_CLAUSE_NOWAIT:
9292 clauses = c_parser_omp_clause_nowait (parser, clauses);
9295 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
9296 clauses = c_parser_omp_clause_num_threads (parser, clauses);
9297 c_name = "num_threads";
9299 case PRAGMA_OMP_CLAUSE_ORDERED:
9300 clauses = c_parser_omp_clause_ordered (parser, clauses);
9303 case PRAGMA_OMP_CLAUSE_PRIVATE:
9304 clauses = c_parser_omp_clause_private (parser, clauses);
9307 case PRAGMA_OMP_CLAUSE_REDUCTION:
9308 clauses = c_parser_omp_clause_reduction (parser, clauses);
9309 c_name = "reduction";
9311 case PRAGMA_OMP_CLAUSE_SCHEDULE:
9312 clauses = c_parser_omp_clause_schedule (parser, clauses);
9313 c_name = "schedule";
9315 case PRAGMA_OMP_CLAUSE_SHARED:
9316 clauses = c_parser_omp_clause_shared (parser, clauses);
9319 case PRAGMA_OMP_CLAUSE_UNTIED:
9320 clauses = c_parser_omp_clause_untied (parser, clauses);
9324 c_parser_error (parser, "expected %<#pragma omp%> clause");
9328 if (((mask >> c_kind) & 1) == 0 && !parser->error)
9330 /* Remove the invalid clause(s) from the list to avoid
9331 confusing the rest of the compiler. */
9333 error_at (here, "%qs is not valid for %qs", c_name, where);
9338 c_parser_skip_to_pragma_eol (parser);
9340 return c_finish_omp_clauses (clauses);
9347 In practice, we're also interested in adding the statement to an
9348 outer node. So it is convenient if we work around the fact that
9349 c_parser_statement calls add_stmt. */
9352 c_parser_omp_structured_block (c_parser *parser)
9354 tree stmt = push_stmt_list ();
9355 c_parser_statement (parser);
9356 return pop_stmt_list (stmt);
9360 # pragma omp atomic new-line
9364 x binop= expr | x++ | ++x | x-- | --x
9366 +, *, -, /, &, ^, |, <<, >>
9368 where x is an lvalue expression with scalar type.
9371 # pragma omp atomic new-line
9374 # pragma omp atomic read new-line
9377 # pragma omp atomic write new-line
9380 # pragma omp atomic update new-line
9383 # pragma omp atomic capture new-line
9386 # pragma omp atomic capture new-line
9394 expression-stmt | x = x binop expr
9396 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
9398 { v = x; update-stmt; } | { update-stmt; v = x; }
9400 where x and v are lvalue expressions with scalar type.
9402 LOC is the location of the #pragma token. */
9405 c_parser_omp_atomic (location_t loc, c_parser *parser)
9407 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE;
9408 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE;
9409 tree stmt, orig_lhs;
9410 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR;
9411 struct c_expr rhs_expr;
9412 bool structured_block = false;
9414 if (c_parser_next_token_is (parser, CPP_NAME))
9416 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9418 if (!strcmp (p, "read"))
9419 code = OMP_ATOMIC_READ;
9420 else if (!strcmp (p, "write"))
9422 else if (!strcmp (p, "update"))
9424 else if (!strcmp (p, "capture"))
9425 code = OMP_ATOMIC_CAPTURE_NEW;
9429 c_parser_consume_token (parser);
9431 c_parser_skip_to_pragma_eol (parser);
9435 case OMP_ATOMIC_READ:
9436 case NOP_EXPR: /* atomic write */
9437 v = c_parser_unary_expression (parser).value;
9438 v = c_fully_fold (v, false, NULL);
9439 if (v == error_mark_node)
9441 loc = c_parser_peek_token (parser)->location;
9442 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9444 if (code == NOP_EXPR)
9445 lhs = c_parser_expression (parser).value;
9447 lhs = c_parser_unary_expression (parser).value;
9448 lhs = c_fully_fold (lhs, false, NULL);
9449 if (lhs == error_mark_node)
9451 if (code == NOP_EXPR)
9453 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
9461 case OMP_ATOMIC_CAPTURE_NEW:
9462 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9464 c_parser_consume_token (parser);
9465 structured_block = true;
9469 v = c_parser_unary_expression (parser).value;
9470 v = c_fully_fold (v, false, NULL);
9471 if (v == error_mark_node)
9473 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9481 /* For structured_block case we don't know yet whether
9482 old or new x should be captured. */
9484 lhs = c_parser_unary_expression (parser).value;
9485 lhs = c_fully_fold (lhs, false, NULL);
9487 switch (TREE_CODE (lhs))
9491 c_parser_skip_to_end_of_block_or_statement (parser);
9492 if (structured_block)
9494 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9495 c_parser_consume_token (parser);
9496 else if (code == OMP_ATOMIC_CAPTURE_NEW)
9498 c_parser_skip_to_end_of_block_or_statement (parser);
9499 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9500 c_parser_consume_token (parser);
9505 case POSTINCREMENT_EXPR:
9506 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9507 code = OMP_ATOMIC_CAPTURE_OLD;
9509 case PREINCREMENT_EXPR:
9510 lhs = TREE_OPERAND (lhs, 0);
9512 rhs = integer_one_node;
9515 case POSTDECREMENT_EXPR:
9516 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block)
9517 code = OMP_ATOMIC_CAPTURE_OLD;
9519 case PREDECREMENT_EXPR:
9520 lhs = TREE_OPERAND (lhs, 0);
9521 opcode = MINUS_EXPR;
9522 rhs = integer_one_node;
9526 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
9527 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
9528 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
9529 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
9530 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
9531 (TREE_OPERAND (lhs, 1), 0), 0)))
9533 /* Undo effects of boolean_increment for post {in,de}crement. */
9534 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
9537 if (TREE_CODE (lhs) == MODIFY_EXPR
9538 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
9540 /* Undo effects of boolean_increment. */
9541 if (integer_onep (TREE_OPERAND (lhs, 1)))
9543 /* This is pre or post increment. */
9544 rhs = TREE_OPERAND (lhs, 1);
9545 lhs = TREE_OPERAND (lhs, 0);
9547 if (code == OMP_ATOMIC_CAPTURE_NEW
9548 && !structured_block
9549 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9550 code = OMP_ATOMIC_CAPTURE_OLD;
9553 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
9554 && TREE_OPERAND (lhs, 0)
9555 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
9557 /* This is pre or post decrement. */
9558 rhs = TREE_OPERAND (lhs, 1);
9559 lhs = TREE_OPERAND (lhs, 0);
9561 if (code == OMP_ATOMIC_CAPTURE_NEW
9562 && !structured_block
9563 && TREE_CODE (orig_lhs) == COMPOUND_EXPR)
9564 code = OMP_ATOMIC_CAPTURE_OLD;
9570 switch (c_parser_peek_token (parser)->type)
9576 opcode = TRUNC_DIV_EXPR;
9582 opcode = MINUS_EXPR;
9585 opcode = LSHIFT_EXPR;
9588 opcode = RSHIFT_EXPR;
9591 opcode = BIT_AND_EXPR;
9594 opcode = BIT_IOR_EXPR;
9597 opcode = BIT_XOR_EXPR;
9600 if (structured_block || code == OMP_ATOMIC)
9602 location_t aloc = c_parser_peek_token (parser)->location;
9604 enum c_parser_prec oprec = PREC_NONE;
9606 c_parser_consume_token (parser);
9607 rhs1 = c_parser_unary_expression (parser).value;
9608 rhs1 = c_fully_fold (rhs1, false, NULL);
9609 if (rhs1 == error_mark_node)
9611 switch (c_parser_peek_token (parser)->type)
9614 if (code == OMP_ATOMIC_CAPTURE_NEW)
9616 code = OMP_ATOMIC_CAPTURE_OLD;
9621 c_parser_consume_token (parser);
9624 c_parser_error (parser,
9625 "invalid form of %<#pragma omp atomic%>");
9632 opcode = TRUNC_DIV_EXPR;
9640 opcode = MINUS_EXPR;
9644 opcode = LSHIFT_EXPR;
9648 opcode = RSHIFT_EXPR;
9652 opcode = BIT_AND_EXPR;
9653 oprec = PREC_BITAND;
9656 opcode = BIT_IOR_EXPR;
9660 opcode = BIT_XOR_EXPR;
9661 oprec = PREC_BITXOR;
9664 c_parser_error (parser,
9665 "invalid operator for %<#pragma omp atomic%>");
9669 c_parser_consume_token (parser);
9670 rhs_loc = c_parser_peek_token (parser)->location;
9671 if (commutative_tree_code (opcode))
9672 oprec = (enum c_parser_prec) (oprec - 1);
9673 rhs_expr = c_parser_binary_expression (parser, NULL, oprec);
9674 rhs_expr = default_function_array_read_conversion (rhs_loc,
9676 rhs = rhs_expr.value;
9677 rhs = c_fully_fold (rhs, false, NULL);
9682 c_parser_error (parser,
9683 "invalid operator for %<#pragma omp atomic%>");
9687 /* Arrange to pass the location of the assignment operator to
9688 c_finish_omp_atomic. */
9689 loc = c_parser_peek_token (parser)->location;
9690 c_parser_consume_token (parser);
9692 location_t rhs_loc = c_parser_peek_token (parser)->location;
9693 rhs_expr = c_parser_expression (parser);
9694 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
9696 rhs = rhs_expr.value;
9697 rhs = c_fully_fold (rhs, false, NULL);
9701 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW)
9703 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
9705 v = c_parser_unary_expression (parser).value;
9706 v = c_fully_fold (v, false, NULL);
9707 if (v == error_mark_node)
9709 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
9711 lhs1 = c_parser_unary_expression (parser).value;
9712 lhs1 = c_fully_fold (lhs1, false, NULL);
9713 if (lhs1 == error_mark_node)
9716 if (structured_block)
9718 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9719 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>");
9722 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1);
9723 if (stmt != error_mark_node)
9726 if (!structured_block)
9727 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9732 # pragma omp barrier new-line
9736 c_parser_omp_barrier (c_parser *parser)
9738 location_t loc = c_parser_peek_token (parser)->location;
9739 c_parser_consume_pragma (parser);
9740 c_parser_skip_to_pragma_eol (parser);
9742 c_finish_omp_barrier (loc);
9746 # pragma omp critical [(name)] new-line
9749 LOC is the location of the #pragma itself. */
9752 c_parser_omp_critical (location_t loc, c_parser *parser)
9754 tree stmt, name = NULL;
9756 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9758 c_parser_consume_token (parser);
9759 if (c_parser_next_token_is (parser, CPP_NAME))
9761 name = c_parser_peek_token (parser)->value;
9762 c_parser_consume_token (parser);
9763 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9766 c_parser_error (parser, "expected identifier");
9768 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9769 c_parser_error (parser, "expected %<(%> or end of line");
9770 c_parser_skip_to_pragma_eol (parser);
9772 stmt = c_parser_omp_structured_block (parser);
9773 return c_finish_omp_critical (loc, stmt, name);
9777 # pragma omp flush flush-vars[opt] new-line
9780 ( variable-list ) */
9783 c_parser_omp_flush (c_parser *parser)
9785 location_t loc = c_parser_peek_token (parser)->location;
9786 c_parser_consume_pragma (parser);
9787 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
9788 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9789 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
9790 c_parser_error (parser, "expected %<(%> or end of line");
9791 c_parser_skip_to_pragma_eol (parser);
9793 c_finish_omp_flush (loc);
9796 /* Parse the restricted form of the for statement allowed by OpenMP.
9797 The real trick here is to determine the loop control variable early
9798 so that we can push a new decl if necessary to make it private.
9799 LOC is the location of the OMP in "#pragma omp". */
9802 c_parser_omp_for_loop (location_t loc,
9803 c_parser *parser, tree clauses, tree *par_clauses)
9805 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
9806 tree declv, condv, incrv, initv, ret = NULL;
9807 bool fail = false, open_brace_parsed = false;
9808 int i, collapse = 1, nbraces = 0;
9810 VEC(tree,gc) *for_block = make_tree_vector ();
9812 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
9813 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
9814 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
9816 gcc_assert (collapse >= 1);
9818 declv = make_tree_vec (collapse);
9819 initv = make_tree_vec (collapse);
9820 condv = make_tree_vec (collapse);
9821 incrv = make_tree_vec (collapse);
9823 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
9825 c_parser_error (parser, "for statement expected");
9828 for_loc = c_parser_peek_token (parser)->location;
9829 c_parser_consume_token (parser);
9831 for (i = 0; i < collapse; i++)
9835 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
9838 /* Parse the initialization declaration or expression. */
9839 if (c_parser_next_tokens_start_declaration (parser))
9842 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
9843 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
9844 decl = check_for_loop_decls (for_loc, flag_isoc99);
9847 if (DECL_INITIAL (decl) == error_mark_node)
9848 decl = error_mark_node;
9851 else if (c_parser_next_token_is (parser, CPP_NAME)
9852 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
9854 struct c_expr decl_exp;
9855 struct c_expr init_exp;
9856 location_t init_loc;
9858 decl_exp = c_parser_postfix_expression (parser);
9859 decl = decl_exp.value;
9861 c_parser_require (parser, CPP_EQ, "expected %<=%>");
9863 init_loc = c_parser_peek_token (parser)->location;
9864 init_exp = c_parser_expr_no_commas (parser, NULL);
9865 init_exp = default_function_array_read_conversion (init_loc,
9867 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
9868 NOP_EXPR, init_loc, init_exp.value,
9869 init_exp.original_type);
9870 init = c_process_expr_stmt (init_loc, init);
9872 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9877 c_parser_error (parser,
9878 "expected iteration declaration or initialization");
9879 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
9885 /* Parse the loop condition. */
9887 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
9889 location_t cond_loc = c_parser_peek_token (parser)->location;
9890 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL,
9893 cond = cond_expr.value;
9894 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
9895 cond = c_fully_fold (cond, false, NULL);
9896 switch (cond_expr.original_code)
9904 /* Can't be cond = error_mark_node, because we want to preserve
9905 the location until c_finish_omp_for. */
9906 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
9909 protected_set_expr_location (cond, cond_loc);
9911 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
9913 /* Parse the increment expression. */
9915 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
9917 location_t incr_loc = c_parser_peek_token (parser)->location;
9919 incr = c_process_expr_stmt (incr_loc,
9920 c_parser_expression (parser).value);
9922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
9924 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
9928 TREE_VEC_ELT (declv, i) = decl;
9929 TREE_VEC_ELT (initv, i) = init;
9930 TREE_VEC_ELT (condv, i) = cond;
9931 TREE_VEC_ELT (incrv, i) = incr;
9935 if (i == collapse - 1)
9938 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
9939 in between the collapsed for loops to be still considered perfectly
9940 nested. Hopefully the final version clarifies this.
9941 For now handle (multiple) {'s and empty statements. */
9944 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9946 c_parser_consume_token (parser);
9949 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
9951 c_parser_consume_token (parser);
9955 && c_parser_next_token_is (parser, CPP_SEMICOLON))
9956 c_parser_consume_token (parser);
9959 c_parser_error (parser, "not enough perfectly nested loops");
9962 open_brace_parsed = true;
9972 nbraces += bracecount;
9975 save_break = c_break_label;
9976 c_break_label = size_one_node;
9977 save_cont = c_cont_label;
9978 c_cont_label = NULL_TREE;
9979 body = push_stmt_list ();
9981 if (open_brace_parsed)
9983 location_t here = c_parser_peek_token (parser)->location;
9984 stmt = c_begin_compound_stmt (true);
9985 c_parser_compound_statement_nostart (parser);
9986 add_stmt (c_end_compound_stmt (here, stmt, true));
9989 add_stmt (c_parser_c99_block_statement (parser));
9992 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
9993 SET_EXPR_LOCATION (t, loc);
9997 body = pop_stmt_list (body);
9998 c_break_label = save_break;
9999 c_cont_label = save_cont;
10003 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10005 c_parser_consume_token (parser);
10008 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
10009 c_parser_consume_token (parser);
10012 c_parser_error (parser, "collapsed loops not perfectly nested");
10015 location_t here = c_parser_peek_token (parser)->location;
10016 stmt = c_begin_compound_stmt (true);
10018 c_parser_compound_statement_nostart (parser);
10019 body = c_end_compound_stmt (here, stmt, true);
10026 /* Only bother calling c_finish_omp_for if we haven't already generated
10027 an error from the initialization parsing. */
10030 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
10033 if (par_clauses != NULL)
10036 for (c = par_clauses; *c ; )
10037 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
10038 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
10039 c = &OMP_CLAUSE_CHAIN (*c);
10042 for (i = 0; i < collapse; i++)
10043 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
10046 c = &OMP_CLAUSE_CHAIN (*c);
10047 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
10050 "iteration variable %qD should not be firstprivate",
10051 OMP_CLAUSE_DECL (*c));
10052 *c = OMP_CLAUSE_CHAIN (*c);
10056 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10057 change it to shared (decl) in
10058 OMP_PARALLEL_CLAUSES. */
10059 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
10060 OMP_CLAUSE_LASTPRIVATE);
10061 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
10062 OMP_CLAUSE_CHAIN (l) = clauses;
10064 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
10068 OMP_FOR_CLAUSES (stmt) = clauses;
10073 while (!VEC_empty (tree, for_block))
10075 /* FIXME diagnostics: LOC below should be the actual location of
10076 this particular for block. We need to build a list of
10077 locations to go along with FOR_BLOCK. */
10078 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
10081 release_tree_vector (for_block);
10086 #pragma omp for for-clause[optseq] new-line
10089 LOC is the location of the #pragma token.
10092 #define OMP_FOR_CLAUSE_MASK \
10093 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10094 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10095 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10096 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10097 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10098 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10099 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10100 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10103 c_parser_omp_for (location_t loc, c_parser *parser)
10105 tree block, clauses, ret;
10107 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
10108 "#pragma omp for");
10110 block = c_begin_compound_stmt (true);
10111 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
10112 block = c_end_compound_stmt (loc, block, true);
10119 # pragma omp master new-line
10122 LOC is the location of the #pragma token.
10126 c_parser_omp_master (location_t loc, c_parser *parser)
10128 c_parser_skip_to_pragma_eol (parser);
10129 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
10133 # pragma omp ordered new-line
10136 LOC is the location of the #pragma itself.
10140 c_parser_omp_ordered (location_t loc, c_parser *parser)
10142 c_parser_skip_to_pragma_eol (parser);
10143 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
10149 { section-sequence }
10152 section-directive[opt] structured-block
10153 section-sequence section-directive structured-block
10155 SECTIONS_LOC is the location of the #pragma omp sections. */
10158 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
10160 tree stmt, substmt;
10161 bool error_suppress = false;
10164 loc = c_parser_peek_token (parser)->location;
10165 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
10167 /* Avoid skipping until the end of the block. */
10168 parser->error = false;
10172 stmt = push_stmt_list ();
10174 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
10176 substmt = push_stmt_list ();
10180 c_parser_statement (parser);
10182 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
10184 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10186 if (c_parser_next_token_is (parser, CPP_EOF))
10190 substmt = pop_stmt_list (substmt);
10191 substmt = build1 (OMP_SECTION, void_type_node, substmt);
10192 SET_EXPR_LOCATION (substmt, loc);
10193 add_stmt (substmt);
10198 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
10200 if (c_parser_next_token_is (parser, CPP_EOF))
10203 loc = c_parser_peek_token (parser)->location;
10204 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
10206 c_parser_consume_pragma (parser);
10207 c_parser_skip_to_pragma_eol (parser);
10208 error_suppress = false;
10210 else if (!error_suppress)
10212 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
10213 error_suppress = true;
10216 substmt = c_parser_omp_structured_block (parser);
10217 substmt = build1 (OMP_SECTION, void_type_node, substmt);
10218 SET_EXPR_LOCATION (substmt, loc);
10219 add_stmt (substmt);
10221 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
10222 "expected %<#pragma omp section%> or %<}%>");
10224 substmt = pop_stmt_list (stmt);
10226 stmt = make_node (OMP_SECTIONS);
10227 SET_EXPR_LOCATION (stmt, sections_loc);
10228 TREE_TYPE (stmt) = void_type_node;
10229 OMP_SECTIONS_BODY (stmt) = substmt;
10231 return add_stmt (stmt);
10235 # pragma omp sections sections-clause[optseq] newline
10238 LOC is the location of the #pragma token.
10241 #define OMP_SECTIONS_CLAUSE_MASK \
10242 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10243 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10244 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10245 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10246 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10249 c_parser_omp_sections (location_t loc, c_parser *parser)
10251 tree block, clauses, ret;
10253 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
10254 "#pragma omp sections");
10256 block = c_begin_compound_stmt (true);
10257 ret = c_parser_omp_sections_scope (loc, parser);
10259 OMP_SECTIONS_CLAUSES (ret) = clauses;
10260 block = c_end_compound_stmt (loc, block, true);
10267 # pragma parallel parallel-clause new-line
10268 # pragma parallel for parallel-for-clause new-line
10269 # pragma parallel sections parallel-sections-clause new-line
10271 LOC is the location of the #pragma token.
10274 #define OMP_PARALLEL_CLAUSE_MASK \
10275 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10276 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10277 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10278 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10279 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10280 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10281 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10282 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10285 c_parser_omp_parallel (location_t loc, c_parser *parser)
10287 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
10288 const char *p_name = "#pragma omp parallel";
10289 tree stmt, clauses, par_clause, ws_clause, block;
10290 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
10292 if (c_parser_next_token_is_keyword (parser, RID_FOR))
10294 c_parser_consume_token (parser);
10295 p_kind = PRAGMA_OMP_PARALLEL_FOR;
10296 p_name = "#pragma omp parallel for";
10297 mask |= OMP_FOR_CLAUSE_MASK;
10298 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10300 else if (c_parser_next_token_is (parser, CPP_NAME))
10302 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
10303 if (strcmp (p, "sections") == 0)
10305 c_parser_consume_token (parser);
10306 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
10307 p_name = "#pragma omp parallel sections";
10308 mask |= OMP_SECTIONS_CLAUSE_MASK;
10309 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
10313 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
10317 case PRAGMA_OMP_PARALLEL:
10318 block = c_begin_omp_parallel ();
10319 c_parser_statement (parser);
10320 stmt = c_finish_omp_parallel (loc, clauses, block);
10323 case PRAGMA_OMP_PARALLEL_FOR:
10324 block = c_begin_omp_parallel ();
10325 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10326 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
10327 stmt = c_finish_omp_parallel (loc, par_clause, block);
10328 OMP_PARALLEL_COMBINED (stmt) = 1;
10331 case PRAGMA_OMP_PARALLEL_SECTIONS:
10332 block = c_begin_omp_parallel ();
10333 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
10334 stmt = c_parser_omp_sections_scope (loc, parser);
10336 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
10337 stmt = c_finish_omp_parallel (loc, par_clause, block);
10338 OMP_PARALLEL_COMBINED (stmt) = 1;
10342 gcc_unreachable ();
10349 # pragma omp single single-clause[optseq] new-line
10352 LOC is the location of the #pragma.
10355 #define OMP_SINGLE_CLAUSE_MASK \
10356 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10357 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10358 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
10359 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10362 c_parser_omp_single (location_t loc, c_parser *parser)
10364 tree stmt = make_node (OMP_SINGLE);
10365 SET_EXPR_LOCATION (stmt, loc);
10366 TREE_TYPE (stmt) = void_type_node;
10368 OMP_SINGLE_CLAUSES (stmt)
10369 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
10370 "#pragma omp single");
10371 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
10373 return add_stmt (stmt);
10377 # pragma omp task task-clause[optseq] new-line
10379 LOC is the location of the #pragma.
10382 #define OMP_TASK_CLAUSE_MASK \
10383 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10384 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
10385 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10386 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10387 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10388 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10389 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
10390 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
10393 c_parser_omp_task (location_t loc, c_parser *parser)
10395 tree clauses, block;
10397 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
10398 "#pragma omp task");
10400 block = c_begin_omp_task ();
10401 c_parser_statement (parser);
10402 return c_finish_omp_task (loc, clauses, block);
10406 # pragma omp taskwait new-line
10410 c_parser_omp_taskwait (c_parser *parser)
10412 location_t loc = c_parser_peek_token (parser)->location;
10413 c_parser_consume_pragma (parser);
10414 c_parser_skip_to_pragma_eol (parser);
10416 c_finish_omp_taskwait (loc);
10420 # pragma omp taskyield new-line
10424 c_parser_omp_taskyield (c_parser *parser)
10426 location_t loc = c_parser_peek_token (parser)->location;
10427 c_parser_consume_pragma (parser);
10428 c_parser_skip_to_pragma_eol (parser);
10430 c_finish_omp_taskyield (loc);
10433 /* Main entry point to parsing most OpenMP pragmas. */
10436 c_parser_omp_construct (c_parser *parser)
10438 enum pragma_kind p_kind;
10442 loc = c_parser_peek_token (parser)->location;
10443 p_kind = c_parser_peek_token (parser)->pragma_kind;
10444 c_parser_consume_pragma (parser);
10448 case PRAGMA_OMP_ATOMIC:
10449 c_parser_omp_atomic (loc, parser);
10451 case PRAGMA_OMP_CRITICAL:
10452 stmt = c_parser_omp_critical (loc, parser);
10454 case PRAGMA_OMP_FOR:
10455 stmt = c_parser_omp_for (loc, parser);
10457 case PRAGMA_OMP_MASTER:
10458 stmt = c_parser_omp_master (loc, parser);
10460 case PRAGMA_OMP_ORDERED:
10461 stmt = c_parser_omp_ordered (loc, parser);
10463 case PRAGMA_OMP_PARALLEL:
10464 stmt = c_parser_omp_parallel (loc, parser);
10466 case PRAGMA_OMP_SECTIONS:
10467 stmt = c_parser_omp_sections (loc, parser);
10469 case PRAGMA_OMP_SINGLE:
10470 stmt = c_parser_omp_single (loc, parser);
10472 case PRAGMA_OMP_TASK:
10473 stmt = c_parser_omp_task (loc, parser);
10476 gcc_unreachable ();
10480 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
10485 # pragma omp threadprivate (variable-list) */
10488 c_parser_omp_threadprivate (c_parser *parser)
10493 c_parser_consume_pragma (parser);
10494 loc = c_parser_peek_token (parser)->location;
10495 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
10497 /* Mark every variable in VARS to be assigned thread local storage. */
10498 for (t = vars; t; t = TREE_CHAIN (t))
10500 tree v = TREE_PURPOSE (t);
10502 /* FIXME diagnostics: Ideally we should keep individual
10503 locations for all the variables in the var list to make the
10504 following errors more precise. Perhaps
10505 c_parser_omp_var_list_parens() should construct a list of
10506 locations to go along with the var list. */
10508 /* If V had already been marked threadprivate, it doesn't matter
10509 whether it had been used prior to this point. */
10510 if (TREE_CODE (v) != VAR_DECL)
10511 error_at (loc, "%qD is not a variable", v);
10512 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
10513 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10514 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10515 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10516 else if (TREE_TYPE (v) == error_mark_node)
10518 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
10519 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10522 if (! DECL_THREAD_LOCAL_P (v))
10524 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
10525 /* If rtl has been already set for this var, call
10526 make_decl_rtl once again, so that encode_section_info
10527 has a chance to look at the new decl flags. */
10528 if (DECL_RTL_SET_P (v))
10531 C_DECL_THREADPRIVATE_P (v) = 1;
10535 c_parser_skip_to_pragma_eol (parser);
10539 /* Parse a single source file. */
10542 c_parse_file (void)
10544 /* Use local storage to begin. If the first token is a pragma, parse it.
10545 If it is #pragma GCC pch_preprocess, then this will load a PCH file
10546 which will cause garbage collection. */
10549 memset (&tparser, 0, sizeof tparser);
10550 the_parser = &tparser;
10552 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
10553 c_parser_pragma_pch_preprocess (&tparser);
10555 the_parser = ggc_alloc_c_parser ();
10556 *the_parser = tparser;
10558 /* Initialize EH, if we've been told to do so. */
10559 if (flag_exceptions)
10560 using_eh_for_cleanups ();
10562 c_parser_translation_unit (the_parser);
10566 #include "gt-c-parser.h"