1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
55 #include "c-family/c-common.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX <= 255);
82 mask |= D_ASM | D_EXT;
86 if (!c_dialect_objc ())
87 mask |= D_OBJC | D_CXX_OBJC;
89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
90 for (i = 0; i < num_c_common_reswords; i++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords[i].disable & mask)
97 && (c_common_reswords[i].disable & D_CXXWARN))
99 id = get_identifier (c_common_reswords[i].word);
100 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
101 C_IS_RESERVED_WORD (id) = 1;
106 id = get_identifier (c_common_reswords[i].word);
107 C_SET_RID_CODE (id, c_common_reswords[i].rid);
108 C_IS_RESERVED_WORD (id) = 1;
109 ridpointers [(int) c_common_reswords[i].rid] = id;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind {
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token {
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype) type : 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind) id_kind : 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid) keyword : 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser {
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error : 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma : 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block : 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string : 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context : 1;
188 /* True if we are parsing a (potential) Objective-C foreach
189 statement. This is set to true after we parsed 'for (' and while
190 we wait for 'in' or ';' to decide if it's a standard C for loop or an
191 Objective-C foreach loop. */
192 BOOL_BITFIELD objc_could_be_foreach_context : 1;
193 /* The following flag is needed to contextualize Objective-C lexical
194 analysis. In some cases (e.g., 'int NSObject;'), it is
195 undesirable to bind an identifier to an Objective-C class, even
196 if a class with that name exists. */
197 BOOL_BITFIELD objc_need_raw_identifier : 1;
198 /* True if we are in a context where the Objective-C "Property attribute"
199 keywords are valid. */
200 BOOL_BITFIELD objc_property_attr_context : 1;
204 /* The actual parser and external interface. ??? Does this need to be
205 garbage-collected? */
207 static GTY (()) c_parser *the_parser;
209 /* Read in and lex a single token, storing it in *TOKEN. */
212 c_lex_one_token (c_parser *parser, c_token *token)
214 timevar_push (TV_LEX);
216 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
217 (parser->lex_untranslated_string
218 ? C_LEX_STRING_NO_TRANSLATE : 0));
219 token->id_kind = C_ID_NONE;
220 token->keyword = RID_MAX;
221 token->pragma_kind = PRAGMA_NONE;
229 bool objc_force_identifier = parser->objc_need_raw_identifier;
230 if (c_dialect_objc ())
231 parser->objc_need_raw_identifier = false;
233 if (C_IS_RESERVED_WORD (token->value))
235 enum rid rid_code = C_RID_CODE (token->value);
237 if (rid_code == RID_CXX_COMPAT_WARN)
239 warning_at (token->location,
241 "identifier %qE conflicts with C++ keyword",
244 else if (rid_code >= RID_FIRST_ADDR_SPACE
245 && rid_code <= RID_LAST_ADDR_SPACE)
247 token->id_kind = C_ID_ADDRSPACE;
248 token->keyword = rid_code;
251 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
253 /* We found an Objective-C "pq" keyword (in, out,
254 inout, bycopy, byref, oneway). They need special
255 care because the interpretation depends on the
258 if (parser->objc_pq_context)
260 token->type = CPP_KEYWORD;
261 token->keyword = rid_code;
264 else if (parser->objc_could_be_foreach_context
265 && rid_code == RID_IN)
267 /* We are in Objective-C, inside a (potential)
268 foreach context (which means after having
269 parsed 'for (', but before having parsed ';'),
270 and we found 'in'. We consider it the keyword
271 which terminates the declaration at the
272 beginning of a foreach-statement. Note that
273 this means you can't use 'in' for anything else
274 in that context; in particular, in Objective-C
275 you can't use 'in' as the name of the running
276 variable in a C for loop. We could potentially
277 try to add code here to disambiguate, but it
278 seems a reasonable limitation.
280 token->type = CPP_KEYWORD;
281 token->keyword = rid_code;
284 /* Else, "pq" keywords outside of the "pq" context are
285 not keywords, and we fall through to the code for
289 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code))
291 /* We found an Objective-C "property attribute" keyword
292 (readonly, copies, getter, setter, ivar). These are
293 only valid in the property context. */
294 if (parser->objc_property_attr_context)
296 token->type = CPP_KEYWORD;
297 token->keyword = rid_code;
300 /* Else they are not special keywords.
303 else if (c_dialect_objc ()
304 && (OBJC_IS_AT_KEYWORD (rid_code)
305 || OBJC_IS_CXX_KEYWORD (rid_code)))
307 /* We found one of the Objective-C "@" keywords (defs,
308 selector, synchronized, etc) or one of the
309 Objective-C "cxx" keywords (class, private,
310 protected, public, try, catch, throw) without a
311 preceding '@' sign. Do nothing and fall through to
312 the code for normal tokens (in C++ we would still
313 consider the CXX ones keywords, but not in C).
319 token->type = CPP_KEYWORD;
320 token->keyword = rid_code;
325 decl = lookup_name (token->value);
328 if (TREE_CODE (decl) == TYPE_DECL)
330 token->id_kind = C_ID_TYPENAME;
334 else if (c_dialect_objc ())
336 tree objc_interface_decl = objc_is_class_name (token->value);
337 /* Objective-C class names are in the same namespace as
338 variables and typedefs, and hence are shadowed by local
340 if (objc_interface_decl
341 && (global_bindings_p ()
342 || (!objc_force_identifier && !decl)))
344 token->value = objc_interface_decl;
345 token->id_kind = C_ID_CLASSNAME;
349 token->id_kind = C_ID_ID;
353 /* This only happens in Objective-C; it must be a keyword. */
354 token->type = CPP_KEYWORD;
355 switch (C_RID_CODE (token->value))
357 /* Replace 'class' with '@class', 'private' with '@private',
358 etc. This prevents confusion with the C++ keyword
359 'class', and makes the tokens consistent with other
360 Objective-C 'AT' keywords. For example '@class' is
361 reported as RID_AT_CLASS which is consistent with
362 '@synchronized', which is reported as
365 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
366 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
367 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
368 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
369 case RID_THROW: token->keyword = RID_AT_THROW; break;
370 case RID_TRY: token->keyword = RID_AT_TRY; break;
371 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
372 default: token->keyword = C_RID_CODE (token->value);
377 case CPP_CLOSE_PAREN:
379 /* These tokens may affect the interpretation of any identifiers
380 following, if doing Objective-C. */
381 if (c_dialect_objc ())
382 parser->objc_need_raw_identifier = false;
385 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
386 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
392 timevar_pop (TV_LEX);
395 /* Return a pointer to the next token from PARSER, reading it in if
398 static inline c_token *
399 c_parser_peek_token (c_parser *parser)
401 if (parser->tokens_avail == 0)
403 c_lex_one_token (parser, &parser->tokens[0]);
404 parser->tokens_avail = 1;
406 return &parser->tokens[0];
409 /* Return true if the next token from PARSER has the indicated
413 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
415 return c_parser_peek_token (parser)->type == type;
418 /* Return true if the next token from PARSER does not have the
422 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
424 return !c_parser_next_token_is (parser, type);
427 /* Return true if the next token from PARSER is the indicated
431 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
433 return c_parser_peek_token (parser)->keyword == keyword;
436 /* Return true if TOKEN can start a type name,
439 c_token_starts_typename (c_token *token)
444 switch (token->id_kind)
453 gcc_assert (c_dialect_objc ());
459 switch (token->keyword)
492 if (c_dialect_objc ())
500 /* Return true if the next token from PARSER can start a type name,
503 c_parser_next_token_starts_typename (c_parser *parser)
505 c_token *token = c_parser_peek_token (parser);
506 return c_token_starts_typename (token);
509 /* Return true if TOKEN can start declaration specifiers, false
512 c_token_starts_declspecs (c_token *token)
517 switch (token->id_kind)
526 gcc_assert (c_dialect_objc ());
532 switch (token->keyword)
572 if (c_dialect_objc ())
581 /* Return true if TOKEN can start declaration specifiers or a static
582 assertion, false otherwise. */
584 c_token_starts_declaration (c_token *token)
586 if (c_token_starts_declspecs (token)
587 || token->keyword == RID_STATIC_ASSERT)
593 static c_token *c_parser_peek_2nd_token (c_parser *parser);
595 /* Return true if the next token from PARSER can start declaration
596 specifiers, false otherwise. */
598 c_parser_next_token_starts_declspecs (c_parser *parser)
600 c_token *token = c_parser_peek_token (parser);
601 return c_token_starts_declspecs (token);
604 /* Return true if the next token from PARSER can start declaration
605 specifiers or a static assertion, false otherwise. */
607 c_parser_next_token_starts_declaration (c_parser *parser)
609 c_token *token = c_parser_peek_token (parser);
610 return c_token_starts_declaration (token);
613 /* Return a pointer to the next-but-one token from PARSER, reading it
614 in if necessary. The next token is already read in. */
617 c_parser_peek_2nd_token (c_parser *parser)
619 if (parser->tokens_avail >= 2)
620 return &parser->tokens[1];
621 gcc_assert (parser->tokens_avail == 1);
622 gcc_assert (parser->tokens[0].type != CPP_EOF);
623 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
624 c_lex_one_token (parser, &parser->tokens[1]);
625 parser->tokens_avail = 2;
626 return &parser->tokens[1];
629 /* Consume the next token from PARSER. */
632 c_parser_consume_token (c_parser *parser)
634 gcc_assert (parser->tokens_avail >= 1);
635 gcc_assert (parser->tokens[0].type != CPP_EOF);
636 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
637 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
638 if (parser->tokens_avail == 2)
639 parser->tokens[0] = parser->tokens[1];
640 parser->tokens_avail--;
643 /* Expect the current token to be a #pragma. Consume it and remember
644 that we've begun parsing a pragma. */
647 c_parser_consume_pragma (c_parser *parser)
649 gcc_assert (!parser->in_pragma);
650 gcc_assert (parser->tokens_avail >= 1);
651 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
652 if (parser->tokens_avail == 2)
653 parser->tokens[0] = parser->tokens[1];
654 parser->tokens_avail--;
655 parser->in_pragma = true;
658 /* Update the globals input_location and in_system_header from
661 c_parser_set_source_position_from_token (c_token *token)
663 if (token->type != CPP_EOF)
665 input_location = token->location;
669 /* Issue a diagnostic of the form
670 FILE:LINE: MESSAGE before TOKEN
671 where TOKEN is the next token in the input stream of PARSER.
672 MESSAGE (specified by the caller) is usually of the form "expected
675 Do not issue a diagnostic if still recovering from an error.
677 ??? This is taken from the C++ parser, but building up messages in
678 this way is not i18n-friendly and some other approach should be
682 c_parser_error (c_parser *parser, const char *gmsgid)
684 c_token *token = c_parser_peek_token (parser);
687 parser->error = true;
690 /* This diagnostic makes more sense if it is tagged to the line of
691 the token we just peeked at. */
692 c_parser_set_source_position_from_token (token);
693 c_parse_error (gmsgid,
694 /* Because c_parse_error does not understand
695 CPP_KEYWORD, keywords are treated like
697 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
698 /* ??? The C parser does not save the cpp flags of a
699 token, we need to pass 0 here and we will not get
700 the source spelling of some tokens but rather the
701 canonical spelling. */
702 token->value, /*flags=*/0);
705 /* If the next token is of the indicated TYPE, consume it. Otherwise,
706 issue the error MSGID. If MSGID is NULL then a message has already
707 been produced and no message will be produced this time. Returns
708 true if found, false otherwise. */
711 c_parser_require (c_parser *parser,
715 if (c_parser_next_token_is (parser, type))
717 c_parser_consume_token (parser);
722 c_parser_error (parser, msgid);
727 /* If the next token is the indicated keyword, consume it. Otherwise,
728 issue the error MSGID. Returns true if found, false otherwise. */
731 c_parser_require_keyword (c_parser *parser,
735 if (c_parser_next_token_is_keyword (parser, keyword))
737 c_parser_consume_token (parser);
742 c_parser_error (parser, msgid);
747 /* Like c_parser_require, except that tokens will be skipped until the
748 desired token is found. An error message is still produced if the
749 next token is not as expected. If MSGID is NULL then a message has
750 already been produced and no message will be produced this
754 c_parser_skip_until_found (c_parser *parser,
758 unsigned nesting_depth = 0;
760 if (c_parser_require (parser, type, msgid))
763 /* Skip tokens until the desired token is found. */
766 /* Peek at the next token. */
767 c_token *token = c_parser_peek_token (parser);
768 /* If we've reached the token we want, consume it and stop. */
769 if (token->type == type && !nesting_depth)
771 c_parser_consume_token (parser);
775 /* If we've run out of tokens, stop. */
776 if (token->type == CPP_EOF)
778 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
780 if (token->type == CPP_OPEN_BRACE
781 || token->type == CPP_OPEN_PAREN
782 || token->type == CPP_OPEN_SQUARE)
784 else if (token->type == CPP_CLOSE_BRACE
785 || token->type == CPP_CLOSE_PAREN
786 || token->type == CPP_CLOSE_SQUARE)
788 if (nesting_depth-- == 0)
791 /* Consume this token. */
792 c_parser_consume_token (parser);
794 parser->error = false;
797 /* Skip tokens until the end of a parameter is found, but do not
798 consume the comma, semicolon or closing delimiter. */
801 c_parser_skip_to_end_of_parameter (c_parser *parser)
803 unsigned nesting_depth = 0;
807 c_token *token = c_parser_peek_token (parser);
808 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
811 /* If we've run out of tokens, stop. */
812 if (token->type == CPP_EOF)
814 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
816 if (token->type == CPP_OPEN_BRACE
817 || token->type == CPP_OPEN_PAREN
818 || token->type == CPP_OPEN_SQUARE)
820 else if (token->type == CPP_CLOSE_BRACE
821 || token->type == CPP_CLOSE_PAREN
822 || token->type == CPP_CLOSE_SQUARE)
824 if (nesting_depth-- == 0)
827 /* Consume this token. */
828 c_parser_consume_token (parser);
830 parser->error = false;
833 /* Expect to be at the end of the pragma directive and consume an
834 end of line marker. */
837 c_parser_skip_to_pragma_eol (c_parser *parser)
839 gcc_assert (parser->in_pragma);
840 parser->in_pragma = false;
842 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
845 c_token *token = c_parser_peek_token (parser);
846 if (token->type == CPP_EOF)
848 if (token->type == CPP_PRAGMA_EOL)
850 c_parser_consume_token (parser);
853 c_parser_consume_token (parser);
856 parser->error = false;
859 /* Skip tokens until we have consumed an entire block, or until we
860 have consumed a non-nested ';'. */
863 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
865 unsigned nesting_depth = 0;
866 bool save_error = parser->error;
872 /* Peek at the next token. */
873 token = c_parser_peek_token (parser);
881 if (parser->in_pragma)
886 /* If the next token is a ';', we have reached the
887 end of the statement. */
890 /* Consume the ';'. */
891 c_parser_consume_token (parser);
896 case CPP_CLOSE_BRACE:
897 /* If the next token is a non-nested '}', then we have
898 reached the end of the current block. */
899 if (nesting_depth == 0 || --nesting_depth == 0)
901 c_parser_consume_token (parser);
907 /* If it the next token is a '{', then we are entering a new
908 block. Consume the entire block. */
913 /* If we see a pragma, consume the whole thing at once. We
914 have some safeguards against consuming pragmas willy-nilly.
915 Normally, we'd expect to be here with parser->error set,
916 which disables these safeguards. But it's possible to get
917 here for secondary error recovery, after parser->error has
919 c_parser_consume_pragma (parser);
920 c_parser_skip_to_pragma_eol (parser);
921 parser->error = save_error;
928 c_parser_consume_token (parser);
932 parser->error = false;
935 /* CPP's options (initialized by c-opts.c). */
936 extern cpp_options *cpp_opts;
938 /* Save the warning flags which are controlled by __extension__. */
941 disable_extension_diagnostics (void)
944 | (warn_pointer_arith << 1)
945 | (warn_traditional << 2)
947 | (warn_long_long << 4)
948 | (warn_cxx_compat << 5));
949 cpp_opts->cpp_pedantic = pedantic = 0;
950 warn_pointer_arith = 0;
951 cpp_opts->cpp_warn_traditional = warn_traditional = 0;
953 cpp_opts->cpp_warn_long_long = warn_long_long = 0;
958 /* Restore the warning flags which are controlled by __extension__.
959 FLAGS is the return value from disable_extension_diagnostics. */
962 restore_extension_diagnostics (int flags)
964 cpp_opts->cpp_pedantic = pedantic = flags & 1;
965 warn_pointer_arith = (flags >> 1) & 1;
966 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1;
967 flag_iso = (flags >> 3) & 1;
968 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
969 warn_cxx_compat = (flags >> 5) & 1;
972 /* Possibly kinds of declarator to parse. */
973 typedef enum c_dtr_syn {
974 /* A normal declarator with an identifier. */
976 /* An abstract declarator (maybe empty). */
978 /* A parameter declarator: may be either, but after a type name does
979 not redeclare a typedef name as an identifier if it can
980 alternatively be interpreted as a typedef name; see DR#009,
981 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
982 following DR#249. For example, given a typedef T, "int T" and
983 "int *T" are valid parameter declarations redeclaring T, while
984 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
985 abstract declarators rather than involving redundant parentheses;
986 the same applies with attributes inside the parentheses before
991 static void c_parser_external_declaration (c_parser *);
992 static void c_parser_asm_definition (c_parser *);
993 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
995 static void c_parser_static_assert_declaration_no_semi (c_parser *);
996 static void c_parser_static_assert_declaration (c_parser *);
997 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
999 static struct c_typespec c_parser_enum_specifier (c_parser *);
1000 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
1001 static tree c_parser_struct_declaration (c_parser *);
1002 static struct c_typespec c_parser_typeof_specifier (c_parser *);
1003 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
1005 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
1007 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
1009 struct c_declarator *);
1010 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
1011 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
1012 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
1013 static tree c_parser_simple_asm_expr (c_parser *);
1014 static tree c_parser_attributes (c_parser *);
1015 static struct c_type_name *c_parser_type_name (c_parser *);
1016 static struct c_expr c_parser_initializer (c_parser *);
1017 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
1018 static void c_parser_initelt (c_parser *, struct obstack *);
1019 static void c_parser_initval (c_parser *, struct c_expr *,
1021 static tree c_parser_compound_statement (c_parser *);
1022 static void c_parser_compound_statement_nostart (c_parser *);
1023 static void c_parser_label (c_parser *);
1024 static void c_parser_statement (c_parser *);
1025 static void c_parser_statement_after_labels (c_parser *);
1026 static void c_parser_if_statement (c_parser *);
1027 static void c_parser_switch_statement (c_parser *);
1028 static void c_parser_while_statement (c_parser *);
1029 static void c_parser_do_statement (c_parser *);
1030 static void c_parser_for_statement (c_parser *);
1031 static tree c_parser_asm_statement (c_parser *);
1032 static tree c_parser_asm_operands (c_parser *, bool);
1033 static tree c_parser_asm_goto_operands (c_parser *);
1034 static tree c_parser_asm_clobbers (c_parser *);
1035 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
1036 static struct c_expr c_parser_conditional_expression (c_parser *,
1038 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
1039 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
1040 static struct c_expr c_parser_unary_expression (c_parser *);
1041 static struct c_expr c_parser_sizeof_expression (c_parser *);
1042 static struct c_expr c_parser_alignof_expression (c_parser *);
1043 static struct c_expr c_parser_postfix_expression (c_parser *);
1044 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
1045 struct c_type_name *,
1047 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
1050 static struct c_expr c_parser_expression (c_parser *);
1051 static struct c_expr c_parser_expression_conv (c_parser *);
1052 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
1054 static void c_parser_omp_construct (c_parser *);
1055 static void c_parser_omp_threadprivate (c_parser *);
1056 static void c_parser_omp_barrier (c_parser *);
1057 static void c_parser_omp_flush (c_parser *);
1058 static void c_parser_omp_taskwait (c_parser *);
1060 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
1061 static bool c_parser_pragma (c_parser *, enum pragma_context);
1063 /* These Objective-C parser functions are only ever called when
1064 compiling Objective-C. */
1065 static void c_parser_objc_class_definition (c_parser *, tree);
1066 static void c_parser_objc_class_instance_variables (c_parser *);
1067 static void c_parser_objc_class_declaration (c_parser *);
1068 static void c_parser_objc_alias_declaration (c_parser *);
1069 static void c_parser_objc_protocol_definition (c_parser *, tree);
1070 static enum tree_code c_parser_objc_method_type (c_parser *);
1071 static void c_parser_objc_method_definition (c_parser *);
1072 static void c_parser_objc_methodprotolist (c_parser *);
1073 static void c_parser_objc_methodproto (c_parser *);
1074 static tree c_parser_objc_method_decl (c_parser *, tree *);
1075 static tree c_parser_objc_type_name (c_parser *);
1076 static tree c_parser_objc_protocol_refs (c_parser *);
1077 static void c_parser_objc_try_catch_statement (c_parser *);
1078 static void c_parser_objc_synchronized_statement (c_parser *);
1079 static tree c_parser_objc_selector (c_parser *);
1080 static tree c_parser_objc_selector_arg (c_parser *);
1081 static tree c_parser_objc_receiver (c_parser *);
1082 static tree c_parser_objc_message_args (c_parser *);
1083 static tree c_parser_objc_keywordexpr (c_parser *);
1084 static void c_parser_objc_at_property (c_parser *) ;
1085 static bool c_parser_objc_diagnose_bad_element_prefix
1086 (c_parser *, struct c_declspecs *);
1088 /* Parse a translation unit (C90 6.7, C99 6.9).
1091 external-declarations
1093 external-declarations:
1094 external-declaration
1095 external-declarations external-declaration
1104 c_parser_translation_unit (c_parser *parser)
1106 if (c_parser_next_token_is (parser, CPP_EOF))
1108 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1109 "ISO C forbids an empty translation unit");
1113 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1114 mark_valid_location_for_stdc_pragma (false);
1118 c_parser_external_declaration (parser);
1119 obstack_free (&parser_obstack, obstack_position);
1121 while (c_parser_next_token_is_not (parser, CPP_EOF));
1125 /* Parse an external declaration (C90 6.7, C99 6.9).
1127 external-declaration:
1133 external-declaration:
1136 __extension__ external-declaration
1140 external-declaration:
1141 objc-class-definition
1142 objc-class-declaration
1143 objc-alias-declaration
1144 objc-protocol-definition
1145 objc-method-definition
1150 c_parser_external_declaration (c_parser *parser)
1153 switch (c_parser_peek_token (parser)->type)
1156 switch (c_parser_peek_token (parser)->keyword)
1159 ext = disable_extension_diagnostics ();
1160 c_parser_consume_token (parser);
1161 c_parser_external_declaration (parser);
1162 restore_extension_diagnostics (ext);
1165 c_parser_asm_definition (parser);
1167 case RID_AT_INTERFACE:
1168 case RID_AT_IMPLEMENTATION:
1169 gcc_assert (c_dialect_objc ());
1170 c_parser_objc_class_definition (parser, NULL_TREE);
1173 gcc_assert (c_dialect_objc ());
1174 c_parser_objc_class_declaration (parser);
1177 gcc_assert (c_dialect_objc ());
1178 c_parser_objc_alias_declaration (parser);
1180 case RID_AT_PROTOCOL:
1181 gcc_assert (c_dialect_objc ());
1182 c_parser_objc_protocol_definition (parser, NULL_TREE);
1184 case RID_AT_PROPERTY:
1185 gcc_assert (c_dialect_objc ());
1186 c_parser_objc_at_property (parser);
1189 gcc_assert (c_dialect_objc ());
1190 c_parser_consume_token (parser);
1191 objc_finish_implementation ();
1198 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1199 "ISO C does not allow extra %<;%> outside of a function");
1200 c_parser_consume_token (parser);
1203 mark_valid_location_for_stdc_pragma (true);
1204 c_parser_pragma (parser, pragma_external);
1205 mark_valid_location_for_stdc_pragma (false);
1209 if (c_dialect_objc ())
1211 c_parser_objc_method_definition (parser);
1214 /* Else fall through, and yield a syntax error trying to parse
1215 as a declaration or function definition. */
1218 /* A declaration or a function definition (or, in Objective-C,
1219 an @interface or @protocol with prefix attributes). We can
1220 only tell which after parsing the declaration specifiers, if
1221 any, and the first declarator. */
1222 c_parser_declaration_or_fndef (parser, true, true, true, false, true, NULL);
1227 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1228 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1229 accepted; otherwise (old-style parameter declarations) only other
1230 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1231 assertion is accepted; otherwise (old-style parameter declarations)
1232 it is not. If NESTED is true, we are inside a function or parsing
1233 old-style parameter declarations; any functions encountered are
1234 nested functions and declaration specifiers are required; otherwise
1235 we are at top level and functions are normal functions and
1236 declaration specifiers may be optional. If EMPTY_OK is true, empty
1237 declarations are OK (subject to all other constraints); otherwise
1238 (old-style parameter declarations) they are diagnosed. If
1239 START_ATTR_OK is true, the declaration specifiers may start with
1240 attributes; otherwise they may not.
1241 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1242 declaration when parsing an Objective-C foreach statement.
1245 declaration-specifiers init-declarator-list[opt] ;
1246 static_assert-declaration
1248 function-definition:
1249 declaration-specifiers[opt] declarator declaration-list[opt]
1254 declaration-list declaration
1256 init-declarator-list:
1258 init-declarator-list , init-declarator
1261 declarator simple-asm-expr[opt] attributes[opt]
1262 declarator simple-asm-expr[opt] attributes[opt] = initializer
1266 nested-function-definition:
1267 declaration-specifiers declarator declaration-list[opt]
1271 attributes objc-class-definition
1272 attributes objc-category-definition
1273 attributes objc-protocol-definition
1275 The simple-asm-expr and attributes are GNU extensions.
1277 This function does not handle __extension__; that is handled in its
1278 callers. ??? Following the old parser, __extension__ may start
1279 external declarations, declarations in functions and declarations
1280 at the start of "for" loops, but not old-style parameter
1283 C99 requires declaration specifiers in a function definition; the
1284 absence is diagnosed through the diagnosis of implicit int. In GNU
1285 C we also allow but diagnose declarations without declaration
1286 specifiers, but only at top level (elsewhere they conflict with
1289 In Objective-C, declarations of the looping variable in a foreach
1290 statement are exceptionally terminated by 'in' (for example, 'for
1291 (NSObject *object in array) { ... }').
1296 threadprivate-directive */
1299 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1300 bool static_assert_ok, bool empty_ok,
1301 bool nested, bool start_attr_ok,
1302 tree *objc_foreach_object_declaration)
1304 struct c_declspecs *specs;
1306 tree all_prefix_attrs;
1307 bool diagnosed_no_specs = false;
1308 location_t here = c_parser_peek_token (parser)->location;
1310 if (static_assert_ok
1311 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1313 c_parser_static_assert_declaration (parser);
1316 specs = build_null_declspecs ();
1317 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1320 c_parser_skip_to_end_of_block_or_statement (parser);
1323 if (nested && !specs->declspecs_seen_p)
1325 c_parser_error (parser, "expected declaration specifiers");
1326 c_parser_skip_to_end_of_block_or_statement (parser);
1329 finish_declspecs (specs);
1330 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1336 shadow_tag_warned (specs, 1);
1337 pedwarn (here, 0, "empty declaration");
1339 c_parser_consume_token (parser);
1342 else if (c_dialect_objc ())
1344 /* Prefix attributes are an error on method decls. */
1345 switch (c_parser_peek_token (parser)->type)
1349 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1353 warning_at (c_parser_peek_token (parser)->location,
1355 "prefix attributes are ignored for methods");
1356 specs->attrs = NULL_TREE;
1359 c_parser_objc_method_definition (parser);
1361 c_parser_objc_methodproto (parser);
1367 /* This is where we parse 'attributes @interface ...',
1368 'attributes @implementation ...', 'attributes @protocol ...'
1369 (where attributes could be, for example, __attribute__
1372 switch (c_parser_peek_token (parser)->keyword)
1374 case RID_AT_INTERFACE:
1376 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1378 c_parser_objc_class_definition (parser, specs->attrs);
1382 case RID_AT_IMPLEMENTATION:
1384 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1388 warning_at (c_parser_peek_token (parser)->location,
1390 "prefix attributes are ignored for implementations");
1391 specs->attrs = NULL_TREE;
1393 c_parser_objc_class_definition (parser, NULL_TREE);
1397 case RID_AT_PROTOCOL:
1399 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1401 c_parser_objc_protocol_definition (parser, specs->attrs);
1408 case RID_AT_PROPERTY:
1411 c_parser_error (parser,
1412 "attributes may not be specified before" );
1413 specs->attrs = NULL;
1421 pending_xref_error ();
1422 prefix_attrs = specs->attrs;
1423 all_prefix_attrs = prefix_attrs;
1424 specs->attrs = NULL_TREE;
1427 struct c_declarator *declarator;
1430 /* Declaring either one or more declarators (in which case we
1431 should diagnose if there were no declaration specifiers) or a
1432 function definition (in which case the diagnostic for
1433 implicit int suffices). */
1434 declarator = c_parser_declarator (parser, specs->type_seen_p,
1435 C_DTR_NORMAL, &dummy);
1436 if (declarator == NULL)
1438 c_parser_skip_to_end_of_block_or_statement (parser);
1441 if (c_parser_next_token_is (parser, CPP_EQ)
1442 || c_parser_next_token_is (parser, CPP_COMMA)
1443 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1444 || c_parser_next_token_is_keyword (parser, RID_ASM)
1445 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)
1446 || c_parser_next_token_is_keyword (parser, RID_IN))
1448 tree asm_name = NULL_TREE;
1449 tree postfix_attrs = NULL_TREE;
1450 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1452 diagnosed_no_specs = true;
1453 pedwarn (here, 0, "data definition has no type or storage class");
1455 /* Having seen a data definition, there cannot now be a
1456 function definition. */
1458 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1459 asm_name = c_parser_simple_asm_expr (parser);
1460 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1461 postfix_attrs = c_parser_attributes (parser);
1462 if (c_parser_next_token_is (parser, CPP_EQ))
1466 location_t init_loc;
1467 c_parser_consume_token (parser);
1468 /* The declaration of the variable is in effect while
1469 its initializer is parsed. */
1470 d = start_decl (declarator, specs, true,
1471 chainon (postfix_attrs, all_prefix_attrs));
1473 d = error_mark_node;
1474 start_init (d, asm_name, global_bindings_p ());
1475 init_loc = c_parser_peek_token (parser)->location;
1476 init = c_parser_initializer (parser);
1478 if (d != error_mark_node)
1480 maybe_warn_string_init (TREE_TYPE (d), init);
1481 finish_decl (d, init_loc, init.value,
1482 init.original_type, asm_name);
1487 tree d = start_decl (declarator, specs, false,
1488 chainon (postfix_attrs,
1491 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1492 NULL_TREE, asm_name);
1494 if (c_parser_next_token_is_keyword (parser, RID_IN))
1497 *objc_foreach_object_declaration = d;
1499 *objc_foreach_object_declaration = error_mark_node;
1502 if (c_parser_next_token_is (parser, CPP_COMMA))
1504 c_parser_consume_token (parser);
1505 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1506 all_prefix_attrs = chainon (c_parser_attributes (parser),
1509 all_prefix_attrs = prefix_attrs;
1512 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1514 c_parser_consume_token (parser);
1517 else if (c_parser_next_token_is_keyword (parser, RID_IN))
1519 /* This can only happen in Objective-C: we found the
1520 'in' that terminates the declaration inside an
1521 Objective-C foreach statement. Do not consume the
1522 token, so that the caller can use it to determine
1523 that this indeed is a foreach context. */
1528 c_parser_error (parser, "expected %<,%> or %<;%>");
1529 c_parser_skip_to_end_of_block_or_statement (parser);
1535 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1536 "%<asm%> or %<__attribute__%>");
1537 c_parser_skip_to_end_of_block_or_statement (parser);
1540 /* Function definition (nested or otherwise). */
1543 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1544 c_push_function_context ();
1546 if (!start_function (specs, declarator, all_prefix_attrs))
1548 /* This can appear in many cases looking nothing like a
1549 function definition, so we don't give a more specific
1550 error suggesting there was one. */
1551 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1552 "or %<__attribute__%>");
1554 c_pop_function_context ();
1557 /* Parse old-style parameter declarations. ??? Attributes are
1558 not allowed to start declaration specifiers here because of a
1559 syntax conflict between a function declaration with attribute
1560 suffix and a function definition with an attribute prefix on
1561 first old-style parameter declaration. Following the old
1562 parser, they are not accepted on subsequent old-style
1563 parameter declarations either. However, there is no
1564 ambiguity after the first declaration, nor indeed on the
1565 first as long as we don't allow postfix attributes after a
1566 declarator with a nonempty identifier list in a definition;
1567 and postfix attributes have never been accepted here in
1568 function definitions either. */
1569 while (c_parser_next_token_is_not (parser, CPP_EOF)
1570 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1571 c_parser_declaration_or_fndef (parser, false, false, false,
1573 store_parm_decls ();
1574 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1575 = c_parser_peek_token (parser)->location;
1576 fnbody = c_parser_compound_statement (parser);
1579 tree decl = current_function_decl;
1580 /* Mark nested functions as needing static-chain initially.
1581 lower_nested_functions will recompute it but the
1582 DECL_STATIC_CHAIN flag is also used before that happens,
1583 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1584 DECL_STATIC_CHAIN (decl) = 1;
1587 c_pop_function_context ();
1588 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1599 /* Parse an asm-definition (asm() outside a function body). This is a
1607 c_parser_asm_definition (c_parser *parser)
1609 tree asm_str = c_parser_simple_asm_expr (parser);
1611 cgraph_add_asm_node (asm_str);
1612 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1615 /* Parse a static assertion (C1X N1425 6.7.10).
1617 static_assert-declaration:
1618 static_assert-declaration-no-semi ;
1622 c_parser_static_assert_declaration (c_parser *parser)
1624 c_parser_static_assert_declaration_no_semi (parser);
1626 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1627 c_parser_skip_to_end_of_block_or_statement (parser);
1630 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1633 static_assert-declaration-no-semi:
1634 _Static_assert ( constant-expression , string-literal )
1638 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1640 location_t assert_loc, value_loc;
1644 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1645 assert_loc = c_parser_peek_token (parser)->location;
1649 pedwarn (assert_loc, OPT_pedantic,
1650 "ISO C99 does not support %<_Static_assert%>");
1652 pedwarn (assert_loc, OPT_pedantic,
1653 "ISO C90 does not support %<_Static_assert%>");
1655 c_parser_consume_token (parser);
1656 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1658 value_loc = c_parser_peek_token (parser)->location;
1659 value = c_parser_expr_no_commas (parser, NULL).value;
1660 parser->lex_untranslated_string = true;
1661 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1663 parser->lex_untranslated_string = false;
1666 switch (c_parser_peek_token (parser)->type)
1672 case CPP_UTF8STRING:
1673 string = c_parser_peek_token (parser)->value;
1674 c_parser_consume_token (parser);
1675 parser->lex_untranslated_string = false;
1678 c_parser_error (parser, "expected string literal");
1679 parser->lex_untranslated_string = false;
1682 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1684 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1686 error_at (value_loc, "expression in static assertion is not an integer");
1689 if (TREE_CODE (value) != INTEGER_CST)
1691 value = c_fully_fold (value, false, NULL);
1692 if (TREE_CODE (value) == INTEGER_CST)
1693 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1694 "is not an integer constant expression");
1696 if (TREE_CODE (value) != INTEGER_CST)
1698 error_at (value_loc, "expression in static assertion is not constant");
1701 constant_expression_warning (value);
1702 if (integer_zerop (value))
1703 error_at (assert_loc, "static assertion failed: %E", string);
1706 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1707 6.7), adding them to SPECS (which may already include some).
1708 Storage class specifiers are accepted iff SCSPEC_OK; type
1709 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1710 the start iff START_ATTR_OK.
1712 declaration-specifiers:
1713 storage-class-specifier declaration-specifiers[opt]
1714 type-specifier declaration-specifiers[opt]
1715 type-qualifier declaration-specifiers[opt]
1716 function-specifier declaration-specifiers[opt]
1718 Function specifiers (inline) are from C99, and are currently
1719 handled as storage class specifiers, as is __thread.
1721 C90 6.5.1, C99 6.7.1:
1722 storage-class-specifier:
1733 C90 6.5.2, C99 6.7.2:
1746 [_Imaginary removed in C99 TC2]
1747 struct-or-union-specifier
1751 (_Bool and _Complex are new in C99.)
1753 C90 6.5.3, C99 6.7.3:
1759 address-space-qualifier
1761 (restrict is new in C99.)
1765 declaration-specifiers:
1766 attributes declaration-specifiers[opt]
1772 identifier recognized by the target
1774 storage-class-specifier:
1787 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1788 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1793 class-name objc-protocol-refs[opt]
1794 typedef-name objc-protocol-refs
1799 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1800 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1802 bool attrs_ok = start_attr_ok;
1803 bool seen_type = specs->type_seen_p;
1804 while (c_parser_next_token_is (parser, CPP_NAME)
1805 || c_parser_next_token_is (parser, CPP_KEYWORD)
1806 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1808 struct c_typespec t;
1810 location_t loc = c_parser_peek_token (parser)->location;
1811 if (c_parser_next_token_is (parser, CPP_NAME))
1813 tree value = c_parser_peek_token (parser)->value;
1814 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1816 if (kind == C_ID_ADDRSPACE)
1819 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1820 declspecs_add_addrspace (specs, as);
1821 c_parser_consume_token (parser);
1826 /* This finishes the specifiers unless a type name is OK, it
1827 is declared as a type name and a type name hasn't yet
1829 if (!typespec_ok || seen_type
1830 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1832 c_parser_consume_token (parser);
1835 if (kind == C_ID_TYPENAME
1836 && (!c_dialect_objc ()
1837 || c_parser_next_token_is_not (parser, CPP_LESS)))
1839 t.kind = ctsk_typedef;
1840 /* For a typedef name, record the meaning, not the name.
1841 In case of 'foo foo, bar;'. */
1842 t.spec = lookup_name (value);
1844 t.expr_const_operands = true;
1848 tree proto = NULL_TREE;
1849 gcc_assert (c_dialect_objc ());
1851 if (c_parser_next_token_is (parser, CPP_LESS))
1852 proto = c_parser_objc_protocol_refs (parser);
1853 t.spec = objc_get_protocol_qualified_type (value, proto);
1855 t.expr_const_operands = true;
1857 declspecs_add_type (loc, specs, t);
1860 if (c_parser_next_token_is (parser, CPP_LESS))
1862 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1863 nisse@lysator.liu.se. */
1865 gcc_assert (c_dialect_objc ());
1866 if (!typespec_ok || seen_type)
1868 proto = c_parser_objc_protocol_refs (parser);
1870 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1872 t.expr_const_operands = true;
1873 declspecs_add_type (loc, specs, t);
1876 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1877 switch (c_parser_peek_token (parser)->keyword)
1889 /* TODO: Distinguish between function specifiers (inline)
1890 and storage class specifiers, either here or in
1891 declspecs_add_scspec. */
1892 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1893 c_parser_consume_token (parser);
1917 if (c_dialect_objc ())
1918 parser->objc_need_raw_identifier = true;
1919 t.kind = ctsk_resword;
1920 t.spec = c_parser_peek_token (parser)->value;
1922 t.expr_const_operands = true;
1923 declspecs_add_type (loc, specs, t);
1924 c_parser_consume_token (parser);
1931 t = c_parser_enum_specifier (parser);
1932 declspecs_add_type (loc, specs, t);
1940 t = c_parser_struct_or_union_specifier (parser);
1941 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1942 declspecs_add_type (loc, specs, t);
1945 /* ??? The old parser rejected typeof after other type
1946 specifiers, but is a syntax error the best way of
1948 if (!typespec_ok || seen_type)
1952 t = c_parser_typeof_specifier (parser);
1953 declspecs_add_type (loc, specs, t);
1959 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1960 c_parser_consume_token (parser);
1965 attrs = c_parser_attributes (parser);
1966 declspecs_add_attrs (specs, attrs);
1975 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1978 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1979 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1980 enum attributes[opt] identifier
1982 The form with trailing comma is new in C99. The forms with
1983 attributes are GNU extensions. In GNU C, we accept any expression
1984 without commas in the syntax (assignment expressions, not just
1985 conditional expressions); assignment expressions will be diagnosed
1990 enumerator-list , enumerator
1993 enumeration-constant
1994 enumeration-constant = constant-expression
1997 static struct c_typespec
1998 c_parser_enum_specifier (c_parser *parser)
2000 struct c_typespec ret;
2002 tree ident = NULL_TREE;
2003 location_t enum_loc;
2004 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2005 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
2006 enum_loc = c_parser_peek_token (parser)->location;
2007 c_parser_consume_token (parser);
2008 attrs = c_parser_attributes (parser);
2009 enum_loc = c_parser_peek_token (parser)->location;
2010 /* Set the location in case we create a decl now. */
2011 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2012 if (c_parser_next_token_is (parser, CPP_NAME))
2014 ident = c_parser_peek_token (parser)->value;
2015 ident_loc = c_parser_peek_token (parser)->location;
2016 enum_loc = ident_loc;
2017 c_parser_consume_token (parser);
2019 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2021 /* Parse an enum definition. */
2022 struct c_enum_contents the_enum;
2023 tree type = start_enum (enum_loc, &the_enum, ident);
2025 /* We chain the enumerators in reverse order, then put them in
2026 forward order at the end. */
2027 tree values = NULL_TREE;
2028 c_parser_consume_token (parser);
2036 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
2037 location_t decl_loc, value_loc;
2038 if (c_parser_next_token_is_not (parser, CPP_NAME))
2040 c_parser_error (parser, "expected identifier");
2041 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2042 values = error_mark_node;
2045 token = c_parser_peek_token (parser);
2046 enum_id = token->value;
2047 /* Set the location in case we create a decl now. */
2048 c_parser_set_source_position_from_token (token);
2049 decl_loc = value_loc = token->location;
2050 c_parser_consume_token (parser);
2051 if (c_parser_next_token_is (parser, CPP_EQ))
2053 c_parser_consume_token (parser);
2054 value_loc = c_parser_peek_token (parser)->location;
2055 enum_value = c_parser_expr_no_commas (parser, NULL).value;
2058 enum_value = NULL_TREE;
2059 enum_decl = build_enumerator (decl_loc, value_loc,
2060 &the_enum, enum_id, enum_value);
2061 TREE_CHAIN (enum_decl) = values;
2064 if (c_parser_next_token_is (parser, CPP_COMMA))
2066 comma_loc = c_parser_peek_token (parser)->location;
2068 c_parser_consume_token (parser);
2070 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2072 if (seen_comma && !flag_isoc99)
2073 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
2074 c_parser_consume_token (parser);
2079 c_parser_error (parser, "expected %<,%> or %<}%>");
2080 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2081 values = error_mark_node;
2085 postfix_attrs = c_parser_attributes (parser);
2086 ret.spec = finish_enum (type, nreverse (values),
2087 chainon (attrs, postfix_attrs));
2088 ret.kind = ctsk_tagdef;
2089 ret.expr = NULL_TREE;
2090 ret.expr_const_operands = true;
2095 c_parser_error (parser, "expected %<{%>");
2096 ret.spec = error_mark_node;
2097 ret.kind = ctsk_tagref;
2098 ret.expr = NULL_TREE;
2099 ret.expr_const_operands = true;
2102 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2103 /* In ISO C, enumerated types can be referred to only if already
2105 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2108 pedwarn (enum_loc, OPT_pedantic,
2109 "ISO C forbids forward references to %<enum%> types");
2114 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2116 struct-or-union-specifier:
2117 struct-or-union attributes[opt] identifier[opt]
2118 { struct-contents } attributes[opt]
2119 struct-or-union attributes[opt] identifier
2122 struct-declaration-list
2124 struct-declaration-list:
2125 struct-declaration ;
2126 struct-declaration-list struct-declaration ;
2133 struct-declaration-list struct-declaration
2135 struct-declaration-list:
2136 struct-declaration-list ;
2139 (Note that in the syntax here, unlike that in ISO C, the semicolons
2140 are included here rather than in struct-declaration, in order to
2141 describe the syntax with extra semicolons and missing semicolon at
2146 struct-declaration-list:
2147 @defs ( class-name )
2149 (Note this does not include a trailing semicolon, but can be
2150 followed by further declarations, and gets a pedwarn-if-pedantic
2151 when followed by a semicolon.) */
2153 static struct c_typespec
2154 c_parser_struct_or_union_specifier (c_parser *parser)
2156 struct c_typespec ret;
2158 tree ident = NULL_TREE;
2159 location_t struct_loc;
2160 location_t ident_loc = UNKNOWN_LOCATION;
2161 enum tree_code code;
2162 switch (c_parser_peek_token (parser)->keyword)
2173 struct_loc = c_parser_peek_token (parser)->location;
2174 c_parser_consume_token (parser);
2175 attrs = c_parser_attributes (parser);
2177 /* Set the location in case we create a decl now. */
2178 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2180 if (c_parser_next_token_is (parser, CPP_NAME))
2182 ident = c_parser_peek_token (parser)->value;
2183 ident_loc = c_parser_peek_token (parser)->location;
2184 struct_loc = ident_loc;
2185 c_parser_consume_token (parser);
2187 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2189 /* Parse a struct or union definition. Start the scope of the
2190 tag before parsing components. */
2191 struct c_struct_parse_info *struct_info;
2192 tree type = start_struct (struct_loc, code, ident, &struct_info);
2194 /* We chain the components in reverse order, then put them in
2195 forward order at the end. Each struct-declaration may
2196 declare multiple components (comma-separated), so we must use
2197 chainon to join them, although when parsing each
2198 struct-declaration we can use TREE_CHAIN directly.
2200 The theory behind all this is that there will be more
2201 semicolon separated fields than comma separated fields, and
2202 so we'll be minimizing the number of node traversals required
2204 tree contents = NULL_TREE;
2205 c_parser_consume_token (parser);
2206 /* Handle the Objective-C @defs construct,
2207 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2208 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2211 gcc_assert (c_dialect_objc ());
2212 c_parser_consume_token (parser);
2213 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2215 if (c_parser_next_token_is (parser, CPP_NAME)
2216 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2218 name = c_parser_peek_token (parser)->value;
2219 c_parser_consume_token (parser);
2223 c_parser_error (parser, "expected class name");
2224 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2227 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2229 contents = nreverse (objc_get_class_ivars (name));
2232 /* Parse the struct-declarations and semicolons. Problems with
2233 semicolons are diagnosed here; empty structures are diagnosed
2238 /* Parse any stray semicolon. */
2239 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2241 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2242 "extra semicolon in struct or union specified");
2243 c_parser_consume_token (parser);
2246 /* Stop if at the end of the struct or union contents. */
2247 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2249 c_parser_consume_token (parser);
2252 /* Accept #pragmas at struct scope. */
2253 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2255 c_parser_pragma (parser, pragma_external);
2258 /* Parse some comma-separated declarations, but not the
2259 trailing semicolon if any. */
2260 decls = c_parser_struct_declaration (parser);
2261 contents = chainon (decls, contents);
2262 /* If no semicolon follows, either we have a parse error or
2263 are at the end of the struct or union and should
2265 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2266 c_parser_consume_token (parser);
2269 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2270 pedwarn (c_parser_peek_token (parser)->location, 0,
2271 "no semicolon at end of struct or union");
2274 c_parser_error (parser, "expected %<;%>");
2275 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2280 postfix_attrs = c_parser_attributes (parser);
2281 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2282 chainon (attrs, postfix_attrs), struct_info);
2283 ret.kind = ctsk_tagdef;
2284 ret.expr = NULL_TREE;
2285 ret.expr_const_operands = true;
2290 c_parser_error (parser, "expected %<{%>");
2291 ret.spec = error_mark_node;
2292 ret.kind = ctsk_tagref;
2293 ret.expr = NULL_TREE;
2294 ret.expr_const_operands = true;
2297 ret = parser_xref_tag (ident_loc, code, ident);
2301 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2302 the trailing semicolon.
2305 specifier-qualifier-list struct-declarator-list
2306 static_assert-declaration-no-semi
2308 specifier-qualifier-list:
2309 type-specifier specifier-qualifier-list[opt]
2310 type-qualifier specifier-qualifier-list[opt]
2311 attributes specifier-qualifier-list[opt]
2313 struct-declarator-list:
2315 struct-declarator-list , attributes[opt] struct-declarator
2318 declarator attributes[opt]
2319 declarator[opt] : constant-expression attributes[opt]
2324 __extension__ struct-declaration
2325 specifier-qualifier-list
2327 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2328 of attributes where shown is a GNU extension. In GNU C, we accept
2329 any expression without commas in the syntax (assignment
2330 expressions, not just conditional expressions); assignment
2331 expressions will be diagnosed as non-constant. */
2334 c_parser_struct_declaration (c_parser *parser)
2336 struct c_declspecs *specs;
2338 tree all_prefix_attrs;
2340 location_t decl_loc;
2341 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2345 ext = disable_extension_diagnostics ();
2346 c_parser_consume_token (parser);
2347 decl = c_parser_struct_declaration (parser);
2348 restore_extension_diagnostics (ext);
2351 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2353 c_parser_static_assert_declaration_no_semi (parser);
2356 specs = build_null_declspecs ();
2357 decl_loc = c_parser_peek_token (parser)->location;
2358 c_parser_declspecs (parser, specs, false, true, true);
2361 if (!specs->declspecs_seen_p)
2363 c_parser_error (parser, "expected specifier-qualifier-list");
2366 finish_declspecs (specs);
2367 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2370 if (!specs->type_seen_p)
2372 pedwarn (decl_loc, OPT_pedantic,
2373 "ISO C forbids member declarations with no members");
2374 shadow_tag_warned (specs, pedantic);
2379 /* Support for unnamed structs or unions as members of
2380 structs or unions (which is [a] useful and [b] supports
2384 ret = grokfield (c_parser_peek_token (parser)->location,
2385 build_id_declarator (NULL_TREE), specs,
2388 decl_attributes (&ret, attrs, 0);
2392 pending_xref_error ();
2393 prefix_attrs = specs->attrs;
2394 all_prefix_attrs = prefix_attrs;
2395 specs->attrs = NULL_TREE;
2399 /* Declaring one or more declarators or un-named bit-fields. */
2400 struct c_declarator *declarator;
2402 if (c_parser_next_token_is (parser, CPP_COLON))
2403 declarator = build_id_declarator (NULL_TREE);
2405 declarator = c_parser_declarator (parser, specs->type_seen_p,
2406 C_DTR_NORMAL, &dummy);
2407 if (declarator == NULL)
2409 c_parser_skip_to_end_of_block_or_statement (parser);
2412 if (c_parser_next_token_is (parser, CPP_COLON)
2413 || c_parser_next_token_is (parser, CPP_COMMA)
2414 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2415 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2416 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2418 tree postfix_attrs = NULL_TREE;
2419 tree width = NULL_TREE;
2421 if (c_parser_next_token_is (parser, CPP_COLON))
2423 c_parser_consume_token (parser);
2424 width = c_parser_expr_no_commas (parser, NULL).value;
2426 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2427 postfix_attrs = c_parser_attributes (parser);
2428 d = grokfield (c_parser_peek_token (parser)->location,
2429 declarator, specs, width, &all_prefix_attrs);
2430 decl_attributes (&d, chainon (postfix_attrs,
2431 all_prefix_attrs), 0);
2432 DECL_CHAIN (d) = decls;
2434 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2435 all_prefix_attrs = chainon (c_parser_attributes (parser),
2438 all_prefix_attrs = prefix_attrs;
2439 if (c_parser_next_token_is (parser, CPP_COMMA))
2440 c_parser_consume_token (parser);
2441 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2442 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2444 /* Semicolon consumed in caller. */
2449 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2455 c_parser_error (parser,
2456 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2457 "%<__attribute__%>");
2464 /* Parse a typeof specifier (a GNU extension).
2467 typeof ( expression )
2468 typeof ( type-name )
2471 static struct c_typespec
2472 c_parser_typeof_specifier (c_parser *parser)
2474 struct c_typespec ret;
2475 ret.kind = ctsk_typeof;
2476 ret.spec = error_mark_node;
2477 ret.expr = NULL_TREE;
2478 ret.expr_const_operands = true;
2479 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2480 c_parser_consume_token (parser);
2481 c_inhibit_evaluation_warnings++;
2483 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2485 c_inhibit_evaluation_warnings--;
2489 if (c_parser_next_token_starts_typename (parser))
2491 struct c_type_name *type = c_parser_type_name (parser);
2492 c_inhibit_evaluation_warnings--;
2496 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2497 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2503 location_t here = c_parser_peek_token (parser)->location;
2504 struct c_expr expr = c_parser_expression (parser);
2505 c_inhibit_evaluation_warnings--;
2507 if (TREE_CODE (expr.value) == COMPONENT_REF
2508 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2509 error_at (here, "%<typeof%> applied to a bit-field");
2510 mark_exp_read (expr.value);
2511 ret.spec = TREE_TYPE (expr.value);
2512 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2513 /* This is returned with the type so that when the type is
2514 evaluated, this can be evaluated. */
2516 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2517 pop_maybe_used (was_vm);
2519 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2523 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2524 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2525 be redeclared; otherwise it may not. KIND indicates which kind of
2526 declarator is wanted. Returns a valid declarator except in the
2527 case of a syntax error in which case NULL is returned. *SEEN_ID is
2528 set to true if an identifier being declared is seen; this is used
2529 to diagnose bad forms of abstract array declarators and to
2530 determine whether an identifier list is syntactically permitted.
2533 pointer[opt] direct-declarator
2537 ( attributes[opt] declarator )
2538 direct-declarator array-declarator
2539 direct-declarator ( parameter-type-list )
2540 direct-declarator ( identifier-list[opt] )
2543 * type-qualifier-list[opt]
2544 * type-qualifier-list[opt] pointer
2546 type-qualifier-list:
2549 type-qualifier-list type-qualifier
2550 type-qualifier-list attributes
2552 parameter-type-list:
2554 parameter-list , ...
2557 parameter-declaration
2558 parameter-list , parameter-declaration
2560 parameter-declaration:
2561 declaration-specifiers declarator attributes[opt]
2562 declaration-specifiers abstract-declarator[opt] attributes[opt]
2566 identifier-list , identifier
2568 abstract-declarator:
2570 pointer[opt] direct-abstract-declarator
2572 direct-abstract-declarator:
2573 ( attributes[opt] abstract-declarator )
2574 direct-abstract-declarator[opt] array-declarator
2575 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2580 direct-declarator ( parameter-forward-declarations
2581 parameter-type-list[opt] )
2583 direct-abstract-declarator:
2584 direct-abstract-declarator[opt] ( parameter-forward-declarations
2585 parameter-type-list[opt] )
2587 parameter-forward-declarations:
2589 parameter-forward-declarations parameter-list ;
2591 The uses of attributes shown above are GNU extensions.
2593 Some forms of array declarator are not included in C99 in the
2594 syntax for abstract declarators; these are disallowed elsewhere.
2595 This may be a defect (DR#289).
2597 This function also accepts an omitted abstract declarator as being
2598 an abstract declarator, although not part of the formal syntax. */
2600 static struct c_declarator *
2601 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2604 /* Parse any initial pointer part. */
2605 if (c_parser_next_token_is (parser, CPP_MULT))
2607 struct c_declspecs *quals_attrs = build_null_declspecs ();
2608 struct c_declarator *inner;
2609 c_parser_consume_token (parser);
2610 c_parser_declspecs (parser, quals_attrs, false, false, true);
2611 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2615 return make_pointer_declarator (quals_attrs, inner);
2617 /* Now we have a direct declarator, direct abstract declarator or
2618 nothing (which counts as a direct abstract declarator here). */
2619 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2622 /* Parse a direct declarator or direct abstract declarator; arguments
2623 as c_parser_declarator. */
2625 static struct c_declarator *
2626 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2629 /* The direct declarator must start with an identifier (possibly
2630 omitted) or a parenthesized declarator (possibly abstract). In
2631 an ordinary declarator, initial parentheses must start a
2632 parenthesized declarator. In an abstract declarator or parameter
2633 declarator, they could start a parenthesized declarator or a
2634 parameter list. To tell which, the open parenthesis and any
2635 following attributes must be read. If a declaration specifier
2636 follows, then it is a parameter list; if the specifier is a
2637 typedef name, there might be an ambiguity about redeclaring it,
2638 which is resolved in the direction of treating it as a typedef
2639 name. If a close parenthesis follows, it is also an empty
2640 parameter list, as the syntax does not permit empty abstract
2641 declarators. Otherwise, it is a parenthesized declarator (in
2642 which case the analysis may be repeated inside it, recursively).
2644 ??? There is an ambiguity in a parameter declaration "int
2645 (__attribute__((foo)) x)", where x is not a typedef name: it
2646 could be an abstract declarator for a function, or declare x with
2647 parentheses. The proper resolution of this ambiguity needs
2648 documenting. At present we follow an accident of the old
2649 parser's implementation, whereby the first parameter must have
2650 some declaration specifiers other than just attributes. Thus as
2651 a parameter declaration it is treated as a parenthesized
2652 parameter named x, and as an abstract declarator it is
2655 ??? Also following the old parser, attributes inside an empty
2656 parameter list are ignored, making it a list not yielding a
2657 prototype, rather than giving an error or making it have one
2658 parameter with implicit type int.
2660 ??? Also following the old parser, typedef names may be
2661 redeclared in declarators, but not Objective-C class names. */
2663 if (kind != C_DTR_ABSTRACT
2664 && c_parser_next_token_is (parser, CPP_NAME)
2666 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
2667 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
2668 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2670 struct c_declarator *inner
2671 = build_id_declarator (c_parser_peek_token (parser)->value);
2673 inner->id_loc = c_parser_peek_token (parser)->location;
2674 c_parser_consume_token (parser);
2675 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2678 if (kind != C_DTR_NORMAL
2679 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2681 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2682 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2685 /* Either we are at the end of an abstract declarator, or we have
2688 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2691 struct c_declarator *inner;
2692 c_parser_consume_token (parser);
2693 attrs = c_parser_attributes (parser);
2694 if (kind != C_DTR_NORMAL
2695 && (c_parser_next_token_starts_declspecs (parser)
2696 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2698 struct c_arg_info *args
2699 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2706 = build_function_declarator (args,
2707 build_id_declarator (NULL_TREE));
2708 return c_parser_direct_declarator_inner (parser, *seen_id,
2712 /* A parenthesized declarator. */
2713 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2714 if (inner != NULL && attrs != NULL)
2715 inner = build_attrs_declarator (attrs, inner);
2716 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2718 c_parser_consume_token (parser);
2722 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2726 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2733 if (kind == C_DTR_NORMAL)
2735 c_parser_error (parser, "expected identifier or %<(%>");
2739 return build_id_declarator (NULL_TREE);
2743 /* Parse part of a direct declarator or direct abstract declarator,
2744 given that some (in INNER) has already been parsed; ID_PRESENT is
2745 true if an identifier is present, false for an abstract
2748 static struct c_declarator *
2749 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2750 struct c_declarator *inner)
2752 /* Parse a sequence of array declarators and parameter lists. */
2753 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2755 location_t brace_loc = c_parser_peek_token (parser)->location;
2756 struct c_declarator *declarator;
2757 struct c_declspecs *quals_attrs = build_null_declspecs ();
2761 c_parser_consume_token (parser);
2762 c_parser_declspecs (parser, quals_attrs, false, false, true);
2763 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2765 c_parser_consume_token (parser);
2766 if (static_seen && !quals_attrs->declspecs_seen_p)
2767 c_parser_declspecs (parser, quals_attrs, false, false, true);
2768 if (!quals_attrs->declspecs_seen_p)
2770 /* If "static" is present, there must be an array dimension.
2771 Otherwise, there may be a dimension, "*", or no
2776 dimen = c_parser_expr_no_commas (parser, NULL).value;
2780 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2785 else if (c_parser_next_token_is (parser, CPP_MULT))
2787 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2791 c_parser_consume_token (parser);
2796 dimen = c_parser_expr_no_commas (parser, NULL).value;
2802 dimen = c_parser_expr_no_commas (parser, NULL).value;
2805 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2806 c_parser_consume_token (parser);
2809 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2814 mark_exp_read (dimen);
2815 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2816 static_seen, star_seen);
2817 if (declarator == NULL)
2819 inner = set_array_declarator_inner (declarator, inner);
2820 return c_parser_direct_declarator_inner (parser, id_present, inner);
2822 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2825 struct c_arg_info *args;
2826 c_parser_consume_token (parser);
2827 attrs = c_parser_attributes (parser);
2828 args = c_parser_parms_declarator (parser, id_present, attrs);
2833 inner = build_function_declarator (args, inner);
2834 return c_parser_direct_declarator_inner (parser, id_present, inner);
2840 /* Parse a parameter list or identifier list, including the closing
2841 parenthesis but not the opening one. ATTRS are the attributes at
2842 the start of the list. ID_LIST_OK is true if an identifier list is
2843 acceptable; such a list must not have attributes at the start. */
2845 static struct c_arg_info *
2846 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2849 declare_parm_level ();
2850 /* If the list starts with an identifier, it is an identifier list.
2851 Otherwise, it is either a prototype list or an empty list. */
2854 && c_parser_next_token_is (parser, CPP_NAME)
2855 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2857 tree list = NULL_TREE, *nextp = &list;
2858 while (c_parser_next_token_is (parser, CPP_NAME)
2859 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2861 *nextp = build_tree_list (NULL_TREE,
2862 c_parser_peek_token (parser)->value);
2863 nextp = & TREE_CHAIN (*nextp);
2864 c_parser_consume_token (parser);
2865 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2867 c_parser_consume_token (parser);
2868 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2870 c_parser_error (parser, "expected identifier");
2874 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2876 struct c_arg_info *ret = build_arg_info ();
2878 c_parser_consume_token (parser);
2884 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2892 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2898 /* Parse a parameter list (possibly empty), including the closing
2899 parenthesis but not the opening one. ATTRS are the attributes at
2900 the start of the list. */
2902 static struct c_arg_info *
2903 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2905 bool bad_parm = false;
2906 /* ??? Following the old parser, forward parameter declarations may
2907 use abstract declarators, and if no real parameter declarations
2908 follow the forward declarations then this is not diagnosed. Also
2909 note as above that attributes are ignored as the only contents of
2910 the parentheses, or as the only contents after forward
2912 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2914 struct c_arg_info *ret = build_arg_info ();
2915 c_parser_consume_token (parser);
2918 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2920 struct c_arg_info *ret = build_arg_info ();
2921 /* Suppress -Wold-style-definition for this case. */
2922 ret->types = error_mark_node;
2923 error_at (c_parser_peek_token (parser)->location,
2924 "ISO C requires a named argument before %<...%>");
2925 c_parser_consume_token (parser);
2926 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2928 c_parser_consume_token (parser);
2933 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2938 /* Nonempty list of parameters, either terminated with semicolon
2939 (forward declarations; recurse) or with close parenthesis (normal
2940 function) or with ", ... )" (variadic function). */
2943 /* Parse a parameter. */
2944 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2949 push_parm_decl (parm);
2950 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2953 c_parser_consume_token (parser);
2954 mark_forward_parm_decls ();
2955 new_attrs = c_parser_attributes (parser);
2956 return c_parser_parms_list_declarator (parser, new_attrs);
2958 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2960 c_parser_consume_token (parser);
2963 get_pending_sizes ();
2967 return get_parm_info (false);
2969 if (!c_parser_require (parser, CPP_COMMA,
2970 "expected %<;%>, %<,%> or %<)%>"))
2972 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2973 get_pending_sizes ();
2976 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2978 c_parser_consume_token (parser);
2979 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2981 c_parser_consume_token (parser);
2984 get_pending_sizes ();
2988 return get_parm_info (true);
2992 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2994 get_pending_sizes ();
3001 /* Parse a parameter declaration. ATTRS are the attributes at the
3002 start of the declaration if it is the first parameter. */
3004 static struct c_parm *
3005 c_parser_parameter_declaration (c_parser *parser, tree attrs)
3007 struct c_declspecs *specs;
3008 struct c_declarator *declarator;
3010 tree postfix_attrs = NULL_TREE;
3012 if (!c_parser_next_token_starts_declspecs (parser))
3014 c_token *token = c_parser_peek_token (parser);
3017 c_parser_set_source_position_from_token (token);
3018 if (token->type == CPP_NAME
3019 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
3020 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
3022 error ("unknown type name %qE", token->value);
3023 parser->error = true;
3025 /* ??? In some Objective-C cases '...' isn't applicable so there
3026 should be a different message. */
3028 c_parser_error (parser,
3029 "expected declaration specifiers or %<...%>");
3030 c_parser_skip_to_end_of_parameter (parser);
3033 specs = build_null_declspecs ();
3036 declspecs_add_attrs (specs, attrs);
3039 c_parser_declspecs (parser, specs, true, true, true);
3040 finish_declspecs (specs);
3041 pending_xref_error ();
3042 prefix_attrs = specs->attrs;
3043 specs->attrs = NULL_TREE;
3044 declarator = c_parser_declarator (parser, specs->type_seen_p,
3045 C_DTR_PARM, &dummy);
3046 if (declarator == NULL)
3048 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3051 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3052 postfix_attrs = c_parser_attributes (parser);
3053 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
3057 /* Parse a string literal in an asm expression. It should not be
3058 translated, and wide string literals are an error although
3059 permitted by the syntax. This is a GNU extension.
3064 ??? At present, following the old parser, the caller needs to have
3065 set lex_untranslated_string to 1. It would be better to follow the
3066 C++ parser rather than using this kludge. */
3069 c_parser_asm_string_literal (c_parser *parser)
3072 if (c_parser_next_token_is (parser, CPP_STRING))
3074 str = c_parser_peek_token (parser)->value;
3075 c_parser_consume_token (parser);
3077 else if (c_parser_next_token_is (parser, CPP_WSTRING))
3079 error_at (c_parser_peek_token (parser)->location,
3080 "wide string literal in %<asm%>");
3081 str = build_string (1, "");
3082 c_parser_consume_token (parser);
3086 c_parser_error (parser, "expected string literal");
3092 /* Parse a simple asm expression. This is used in restricted
3093 contexts, where a full expression with inputs and outputs does not
3094 make sense. This is a GNU extension.
3097 asm ( asm-string-literal )
3101 c_parser_simple_asm_expr (c_parser *parser)
3104 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3105 /* ??? Follow the C++ parser rather than using the
3106 lex_untranslated_string kludge. */
3107 parser->lex_untranslated_string = true;
3108 c_parser_consume_token (parser);
3109 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3111 parser->lex_untranslated_string = false;
3114 str = c_parser_asm_string_literal (parser);
3115 parser->lex_untranslated_string = false;
3116 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3118 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3124 /* Parse (possibly empty) attributes. This is a GNU extension.
3128 attributes attribute
3131 __attribute__ ( ( attribute-list ) )
3135 attribute_list , attrib
3140 any-word ( identifier )
3141 any-word ( identifier , nonempty-expr-list )
3142 any-word ( expr-list )
3144 where the "identifier" must not be declared as a type, and
3145 "any-word" may be any identifier (including one declared as a
3146 type), a reserved word storage class specifier, type specifier or
3147 type qualifier. ??? This still leaves out most reserved keywords
3148 (following the old parser), shouldn't we include them, and why not
3149 allow identifiers declared as types to start the arguments? */
3152 c_parser_attributes (c_parser *parser)
3154 tree attrs = NULL_TREE;
3155 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3157 /* ??? Follow the C++ parser rather than using the
3158 lex_untranslated_string kludge. */
3159 parser->lex_untranslated_string = true;
3160 c_parser_consume_token (parser);
3161 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3163 parser->lex_untranslated_string = false;
3166 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3168 parser->lex_untranslated_string = false;
3169 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3172 /* Parse the attribute list. */
3173 while (c_parser_next_token_is (parser, CPP_COMMA)
3174 || c_parser_next_token_is (parser, CPP_NAME)
3175 || c_parser_next_token_is (parser, CPP_KEYWORD))
3177 tree attr, attr_name, attr_args;
3178 VEC(tree,gc) *expr_list;
3179 if (c_parser_next_token_is (parser, CPP_COMMA))
3181 c_parser_consume_token (parser);
3184 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3186 /* ??? See comment above about what keywords are
3189 switch (c_parser_peek_token (parser)->keyword)
3227 /* Accept __attribute__((__const)) as __attribute__((const))
3230 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3233 attr_name = c_parser_peek_token (parser)->value;
3234 c_parser_consume_token (parser);
3235 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3237 attr = build_tree_list (attr_name, NULL_TREE);
3238 attrs = chainon (attrs, attr);
3241 c_parser_consume_token (parser);
3242 /* Parse the attribute contents. If they start with an
3243 identifier which is followed by a comma or close
3244 parenthesis, then the arguments start with that
3245 identifier; otherwise they are an expression list. */
3246 if (c_parser_next_token_is (parser, CPP_NAME)
3247 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3248 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3249 || (c_parser_peek_2nd_token (parser)->type
3250 == CPP_CLOSE_PAREN)))
3252 tree arg1 = c_parser_peek_token (parser)->value;
3253 c_parser_consume_token (parser);
3254 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3255 attr_args = build_tree_list (NULL_TREE, arg1);
3259 c_parser_consume_token (parser);
3260 expr_list = c_parser_expr_list (parser, false, true, NULL);
3261 tree_list = build_tree_list_vec (expr_list);
3262 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3263 release_tree_vector (expr_list);
3268 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3269 attr_args = NULL_TREE;
3272 expr_list = c_parser_expr_list (parser, false, true, NULL);
3273 attr_args = build_tree_list_vec (expr_list);
3274 release_tree_vector (expr_list);
3277 attr = build_tree_list (attr_name, attr_args);
3278 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3279 c_parser_consume_token (parser);
3282 parser->lex_untranslated_string = false;
3283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3287 attrs = chainon (attrs, attr);
3289 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3290 c_parser_consume_token (parser);
3293 parser->lex_untranslated_string = false;
3294 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3298 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3299 c_parser_consume_token (parser);
3302 parser->lex_untranslated_string = false;
3303 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3307 parser->lex_untranslated_string = false;
3312 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3315 specifier-qualifier-list abstract-declarator[opt]
3318 static struct c_type_name *
3319 c_parser_type_name (c_parser *parser)
3321 struct c_declspecs *specs = build_null_declspecs ();
3322 struct c_declarator *declarator;
3323 struct c_type_name *ret;
3325 c_parser_declspecs (parser, specs, false, true, true);
3326 if (!specs->declspecs_seen_p)
3328 c_parser_error (parser, "expected specifier-qualifier-list");
3331 pending_xref_error ();
3332 finish_declspecs (specs);
3333 declarator = c_parser_declarator (parser, specs->type_seen_p,
3334 C_DTR_ABSTRACT, &dummy);
3335 if (declarator == NULL)
3337 ret = XOBNEW (&parser_obstack, struct c_type_name);
3339 ret->declarator = declarator;
3343 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3346 assignment-expression
3347 { initializer-list }
3348 { initializer-list , }
3351 designation[opt] initializer
3352 initializer-list , designation[opt] initializer
3359 designator-list designator
3366 [ constant-expression ]
3378 [ constant-expression ... constant-expression ]
3380 Any expression without commas is accepted in the syntax for the
3381 constant-expressions, with non-constant expressions rejected later.
3383 This function is only used for top-level initializers; for nested
3384 ones, see c_parser_initval. */
3386 static struct c_expr
3387 c_parser_initializer (c_parser *parser)
3389 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3390 return c_parser_braced_init (parser, NULL_TREE, false);
3394 location_t loc = c_parser_peek_token (parser)->location;
3395 ret = c_parser_expr_no_commas (parser, NULL);
3396 if (TREE_CODE (ret.value) != STRING_CST
3397 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3398 ret = default_function_array_read_conversion (loc, ret);
3403 /* Parse a braced initializer list. TYPE is the type specified for a
3404 compound literal, and NULL_TREE for other initializers and for
3405 nested braced lists. NESTED_P is true for nested braced lists,
3406 false for the list of a compound literal or the list that is the
3407 top-level initializer in a declaration. */
3409 static struct c_expr
3410 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3413 struct obstack braced_init_obstack;
3414 location_t brace_loc = c_parser_peek_token (parser)->location;
3415 gcc_obstack_init (&braced_init_obstack);
3416 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3417 c_parser_consume_token (parser);
3419 push_init_level (0, &braced_init_obstack);
3421 really_start_incremental_init (type);
3422 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3424 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3428 /* Parse a non-empty initializer list, possibly with a trailing
3432 c_parser_initelt (parser, &braced_init_obstack);
3435 if (c_parser_next_token_is (parser, CPP_COMMA))
3436 c_parser_consume_token (parser);
3439 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3443 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3445 ret.value = error_mark_node;
3446 ret.original_code = ERROR_MARK;
3447 ret.original_type = NULL;
3448 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3449 pop_init_level (0, &braced_init_obstack);
3450 obstack_free (&braced_init_obstack, NULL);
3453 c_parser_consume_token (parser);
3454 ret = pop_init_level (0, &braced_init_obstack);
3455 obstack_free (&braced_init_obstack, NULL);
3459 /* Parse a nested initializer, including designators. */
3462 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3464 /* Parse any designator or designator list. A single array
3465 designator may have the subsequent "=" omitted in GNU C, but a
3466 longer list or a structure member designator may not. */
3467 if (c_parser_next_token_is (parser, CPP_NAME)
3468 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3470 /* Old-style structure member designator. */
3471 set_init_label (c_parser_peek_token (parser)->value,
3472 braced_init_obstack);
3473 /* Use the colon as the error location. */
3474 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3475 "obsolete use of designated initializer with %<:%>");
3476 c_parser_consume_token (parser);
3477 c_parser_consume_token (parser);
3481 /* des_seen is 0 if there have been no designators, 1 if there
3482 has been a single array designator and 2 otherwise. */
3484 /* Location of a designator. */
3485 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3486 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3487 || c_parser_next_token_is (parser, CPP_DOT))
3489 int des_prev = des_seen;
3491 des_loc = c_parser_peek_token (parser)->location;
3494 if (c_parser_next_token_is (parser, CPP_DOT))
3497 c_parser_consume_token (parser);
3498 if (c_parser_next_token_is (parser, CPP_NAME))
3500 set_init_label (c_parser_peek_token (parser)->value,
3501 braced_init_obstack);
3502 c_parser_consume_token (parser);
3507 init.value = error_mark_node;
3508 init.original_code = ERROR_MARK;
3509 init.original_type = NULL;
3510 c_parser_error (parser, "expected identifier");
3511 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3512 process_init_element (init, false, braced_init_obstack);
3519 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3520 /* ??? Following the old parser, [ objc-receiver
3521 objc-message-args ] is accepted as an initializer,
3522 being distinguished from a designator by what follows
3523 the first assignment expression inside the square
3524 brackets, but after a first array designator a
3525 subsequent square bracket is for Objective-C taken to
3526 start an expression, using the obsolete form of
3527 designated initializer without '=', rather than
3528 possibly being a second level of designation: in LALR
3529 terms, the '[' is shifted rather than reducing
3530 designator to designator-list. */
3531 if (des_prev == 1 && c_dialect_objc ())
3533 des_seen = des_prev;
3536 if (des_prev == 0 && c_dialect_objc ())
3538 /* This might be an array designator or an
3539 Objective-C message expression. If the former,
3540 continue parsing here; if the latter, parse the
3541 remainder of the initializer given the starting
3542 primary-expression. ??? It might make sense to
3543 distinguish when des_prev == 1 as well; see
3544 previous comment. */
3546 struct c_expr mexpr;
3547 c_parser_consume_token (parser);
3548 if (c_parser_peek_token (parser)->type == CPP_NAME
3549 && ((c_parser_peek_token (parser)->id_kind
3551 || (c_parser_peek_token (parser)->id_kind
3552 == C_ID_CLASSNAME)))
3554 /* Type name receiver. */
3555 tree id = c_parser_peek_token (parser)->value;
3556 c_parser_consume_token (parser);
3557 rec = objc_get_class_reference (id);
3558 goto parse_message_args;
3560 first = c_parser_expr_no_commas (parser, NULL).value;
3561 mark_exp_read (first);
3562 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3563 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3564 goto array_desig_after_first;
3565 /* Expression receiver. So far only one part
3566 without commas has been parsed; there might be
3567 more of the expression. */
3569 while (c_parser_next_token_is (parser, CPP_COMMA))
3572 location_t comma_loc, exp_loc;
3573 comma_loc = c_parser_peek_token (parser)->location;
3574 c_parser_consume_token (parser);
3575 exp_loc = c_parser_peek_token (parser)->location;
3576 next = c_parser_expr_no_commas (parser, NULL);
3577 next = default_function_array_read_conversion (exp_loc,
3579 rec = build_compound_expr (comma_loc, rec, next.value);
3582 /* Now parse the objc-message-args. */
3583 args = c_parser_objc_message_args (parser);
3584 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3587 = objc_build_message_expr (build_tree_list (rec, args));
3588 mexpr.original_code = ERROR_MARK;
3589 mexpr.original_type = NULL;
3590 /* Now parse and process the remainder of the
3591 initializer, starting with this message
3592 expression as a primary-expression. */
3593 c_parser_initval (parser, &mexpr, braced_init_obstack);
3596 c_parser_consume_token (parser);
3597 first = c_parser_expr_no_commas (parser, NULL).value;
3598 mark_exp_read (first);
3599 array_desig_after_first:
3600 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3602 ellipsis_loc = c_parser_peek_token (parser)->location;
3603 c_parser_consume_token (parser);
3604 second = c_parser_expr_no_commas (parser, NULL).value;
3605 mark_exp_read (second);
3609 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3611 c_parser_consume_token (parser);
3612 set_init_index (first, second, braced_init_obstack);
3614 pedwarn (ellipsis_loc, OPT_pedantic,
3615 "ISO C forbids specifying range of elements to initialize");
3618 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3624 if (c_parser_next_token_is (parser, CPP_EQ))
3627 pedwarn (des_loc, OPT_pedantic,
3628 "ISO C90 forbids specifying subobject to initialize");
3629 c_parser_consume_token (parser);
3634 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3635 "obsolete use of designated initializer without %<=%>");
3639 init.value = error_mark_node;
3640 init.original_code = ERROR_MARK;
3641 init.original_type = NULL;
3642 c_parser_error (parser, "expected %<=%>");
3643 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3644 process_init_element (init, false, braced_init_obstack);
3650 c_parser_initval (parser, NULL, braced_init_obstack);
3653 /* Parse a nested initializer; as c_parser_initializer but parses
3654 initializers within braced lists, after any designators have been
3655 applied. If AFTER is not NULL then it is an Objective-C message
3656 expression which is the primary-expression starting the
3660 c_parser_initval (c_parser *parser, struct c_expr *after,
3661 struct obstack * braced_init_obstack)
3664 gcc_assert (!after || c_dialect_objc ());
3665 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3666 init = c_parser_braced_init (parser, NULL_TREE, true);
3669 location_t loc = c_parser_peek_token (parser)->location;
3670 init = c_parser_expr_no_commas (parser, after);
3671 if (init.value != NULL_TREE
3672 && TREE_CODE (init.value) != STRING_CST
3673 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3674 init = default_function_array_read_conversion (loc, init);
3676 process_init_element (init, false, braced_init_obstack);
3679 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3683 { block-item-list[opt] }
3684 { label-declarations block-item-list }
3688 block-item-list block-item
3700 { label-declarations block-item-list }
3703 __extension__ nested-declaration
3704 nested-function-definition
3708 label-declarations label-declaration
3711 __label__ identifier-list ;
3713 Allowing the mixing of declarations and code is new in C99. The
3714 GNU syntax also permits (not shown above) labels at the end of
3715 compound statements, which yield an error. We don't allow labels
3716 on declarations; this might seem like a natural extension, but
3717 there would be a conflict between attributes on the label and
3718 prefix attributes on the declaration. ??? The syntax follows the
3719 old parser in requiring something after label declarations.
3720 Although they are erroneous if the labels declared aren't defined,
3721 is it useful for the syntax to be this way?
3733 c_parser_compound_statement (c_parser *parser)
3736 location_t brace_loc;
3737 brace_loc = c_parser_peek_token (parser)->location;
3738 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3740 /* Ensure a scope is entered and left anyway to avoid confusion
3741 if we have just prepared to enter a function body. */
3742 stmt = c_begin_compound_stmt (true);
3743 c_end_compound_stmt (brace_loc, stmt, true);
3744 return error_mark_node;
3746 stmt = c_begin_compound_stmt (true);
3747 c_parser_compound_statement_nostart (parser);
3748 return c_end_compound_stmt (brace_loc, stmt, true);
3751 /* Parse a compound statement except for the opening brace. This is
3752 used for parsing both compound statements and statement expressions
3753 (which follow different paths to handling the opening). */
3756 c_parser_compound_statement_nostart (c_parser *parser)
3758 bool last_stmt = false;
3759 bool last_label = false;
3760 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3761 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3762 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3764 c_parser_consume_token (parser);
3767 mark_valid_location_for_stdc_pragma (true);
3768 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3770 /* Read zero or more forward-declarations for labels that nested
3771 functions can jump to. */
3772 mark_valid_location_for_stdc_pragma (false);
3773 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3775 label_loc = c_parser_peek_token (parser)->location;
3776 c_parser_consume_token (parser);
3777 /* Any identifiers, including those declared as type names,
3782 if (c_parser_next_token_is_not (parser, CPP_NAME))
3784 c_parser_error (parser, "expected identifier");
3788 = declare_label (c_parser_peek_token (parser)->value);
3789 C_DECLARED_LABEL_FLAG (label) = 1;
3790 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3791 c_parser_consume_token (parser);
3792 if (c_parser_next_token_is (parser, CPP_COMMA))
3793 c_parser_consume_token (parser);
3797 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3799 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3801 /* We must now have at least one statement, label or declaration. */
3802 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3804 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3805 c_parser_error (parser, "expected declaration or statement");
3806 c_parser_consume_token (parser);
3809 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3811 location_t loc = c_parser_peek_token (parser)->location;
3812 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3813 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3814 || (c_parser_next_token_is (parser, CPP_NAME)
3815 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3817 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3818 label_loc = c_parser_peek_2nd_token (parser)->location;
3820 label_loc = c_parser_peek_token (parser)->location;
3823 mark_valid_location_for_stdc_pragma (false);
3824 c_parser_label (parser);
3826 else if (!last_label
3827 && c_parser_next_token_starts_declaration (parser))
3830 mark_valid_location_for_stdc_pragma (false);
3831 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
3834 (pedantic && !flag_isoc99)
3836 : OPT_Wdeclaration_after_statement,
3837 "ISO C90 forbids mixed declarations and code");
3840 else if (!last_label
3841 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3843 /* __extension__ can start a declaration, but is also an
3844 unary operator that can start an expression. Consume all
3845 but the last of a possible series of __extension__ to
3847 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3848 && (c_parser_peek_2nd_token (parser)->keyword
3850 c_parser_consume_token (parser);
3851 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3854 ext = disable_extension_diagnostics ();
3855 c_parser_consume_token (parser);
3857 mark_valid_location_for_stdc_pragma (false);
3858 c_parser_declaration_or_fndef (parser, true, true, true, true,
3860 /* Following the old parser, __extension__ does not
3861 disable this diagnostic. */
3862 restore_extension_diagnostics (ext);
3864 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3866 : OPT_Wdeclaration_after_statement,
3867 "ISO C90 forbids mixed declarations and code");
3873 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3875 /* External pragmas, and some omp pragmas, are not associated
3876 with regular c code, and so are not to be considered statements
3877 syntactically. This ensures that the user doesn't put them
3878 places that would turn into syntax errors if the directive
3880 if (c_parser_pragma (parser, pragma_compound))
3881 last_label = false, last_stmt = true;
3883 else if (c_parser_next_token_is (parser, CPP_EOF))
3885 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3886 c_parser_error (parser, "expected declaration or statement");
3889 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3891 if (parser->in_if_block)
3893 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3894 error_at (loc, """expected %<}%> before %<else%>");
3899 error_at (loc, "%<else%> without a previous %<if%>");
3900 c_parser_consume_token (parser);
3909 mark_valid_location_for_stdc_pragma (false);
3910 c_parser_statement_after_labels (parser);
3913 parser->error = false;
3916 error_at (label_loc, "label at end of compound statement");
3917 c_parser_consume_token (parser);
3918 /* Restore the value we started with. */
3919 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3922 /* Parse a label (C90 6.6.1, C99 6.8.1).
3925 identifier : attributes[opt]
3926 case constant-expression :
3932 case constant-expression ... constant-expression :
3934 The use of attributes on labels is a GNU extension. The syntax in
3935 GNU C accepts any expressions without commas, non-constant
3936 expressions being rejected later. */
3939 c_parser_label (c_parser *parser)
3941 location_t loc1 = c_parser_peek_token (parser)->location;
3942 tree label = NULL_TREE;
3943 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3946 c_parser_consume_token (parser);
3947 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3948 if (c_parser_next_token_is (parser, CPP_COLON))
3950 c_parser_consume_token (parser);
3951 label = do_case (loc1, exp1, NULL_TREE);
3953 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3955 c_parser_consume_token (parser);
3956 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3957 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3958 label = do_case (loc1, exp1, exp2);
3961 c_parser_error (parser, "expected %<:%> or %<...%>");
3963 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3965 c_parser_consume_token (parser);
3966 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3967 label = do_case (loc1, NULL_TREE, NULL_TREE);
3971 tree name = c_parser_peek_token (parser)->value;
3974 location_t loc2 = c_parser_peek_token (parser)->location;
3975 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3976 c_parser_consume_token (parser);
3977 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3978 c_parser_consume_token (parser);
3979 attrs = c_parser_attributes (parser);
3980 tlab = define_label (loc2, name);
3983 decl_attributes (&tlab, attrs, 0);
3984 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3989 if (c_parser_next_token_starts_declaration (parser)
3990 && !(c_parser_next_token_is (parser, CPP_NAME)
3991 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3993 error_at (c_parser_peek_token (parser)->location,
3994 "a label can only be part of a statement and "
3995 "a declaration is not a statement");
3996 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3997 /*static_assert_ok*/ true,
3998 /*nested*/ true, /*empty_ok*/ false,
3999 /*start_attr_ok*/ true, NULL);
4004 /* Parse a statement (C90 6.6, C99 6.8).
4009 expression-statement
4017 expression-statement:
4020 selection-statement:
4024 iteration-statement:
4033 return expression[opt] ;
4046 objc-throw-statement
4047 objc-try-catch-statement
4048 objc-synchronized-statement
4050 objc-throw-statement:
4064 parallel-for-construct
4065 parallel-sections-construct
4072 parallel-directive structured-block
4075 for-directive iteration-statement
4078 sections-directive section-scope
4081 single-directive structured-block
4083 parallel-for-construct:
4084 parallel-for-directive iteration-statement
4086 parallel-sections-construct:
4087 parallel-sections-directive section-scope
4090 master-directive structured-block
4093 critical-directive structured-block
4096 atomic-directive expression-statement
4099 ordered-directive structured-block */
4102 c_parser_statement (c_parser *parser)
4104 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4105 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4106 || (c_parser_next_token_is (parser, CPP_NAME)
4107 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4108 c_parser_label (parser);
4109 c_parser_statement_after_labels (parser);
4112 /* Parse a statement, other than a labeled statement. */
4115 c_parser_statement_after_labels (c_parser *parser)
4117 location_t loc = c_parser_peek_token (parser)->location;
4118 tree stmt = NULL_TREE;
4119 bool in_if_block = parser->in_if_block;
4120 parser->in_if_block = false;
4121 switch (c_parser_peek_token (parser)->type)
4123 case CPP_OPEN_BRACE:
4124 add_stmt (c_parser_compound_statement (parser));
4127 switch (c_parser_peek_token (parser)->keyword)
4130 c_parser_if_statement (parser);
4133 c_parser_switch_statement (parser);
4136 c_parser_while_statement (parser);
4139 c_parser_do_statement (parser);
4142 c_parser_for_statement (parser);
4145 c_parser_consume_token (parser);
4146 if (c_parser_next_token_is (parser, CPP_NAME))
4148 stmt = c_finish_goto_label (loc,
4149 c_parser_peek_token (parser)->value);
4150 c_parser_consume_token (parser);
4152 else if (c_parser_next_token_is (parser, CPP_MULT))
4154 c_parser_consume_token (parser);
4155 stmt = c_finish_goto_ptr (loc,
4156 c_parser_expression (parser).value);
4159 c_parser_error (parser, "expected identifier or %<*%>");
4160 goto expect_semicolon;
4162 c_parser_consume_token (parser);
4163 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4164 goto expect_semicolon;
4166 c_parser_consume_token (parser);
4167 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4168 goto expect_semicolon;
4170 c_parser_consume_token (parser);
4171 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4173 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4174 c_parser_consume_token (parser);
4178 struct c_expr expr = c_parser_expression_conv (parser);
4179 mark_exp_read (expr.value);
4180 stmt = c_finish_return (loc, expr.value, expr.original_type);
4181 goto expect_semicolon;
4185 stmt = c_parser_asm_statement (parser);
4188 gcc_assert (c_dialect_objc ());
4189 c_parser_consume_token (parser);
4190 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4192 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4193 c_parser_consume_token (parser);
4197 tree expr = c_parser_expression (parser).value;
4198 expr = c_fully_fold (expr, false, NULL);
4199 stmt = objc_build_throw_stmt (loc, expr);
4200 goto expect_semicolon;
4204 gcc_assert (c_dialect_objc ());
4205 c_parser_objc_try_catch_statement (parser);
4207 case RID_AT_SYNCHRONIZED:
4208 gcc_assert (c_dialect_objc ());
4209 c_parser_objc_synchronized_statement (parser);
4216 c_parser_consume_token (parser);
4218 case CPP_CLOSE_PAREN:
4219 case CPP_CLOSE_SQUARE:
4220 /* Avoid infinite loop in error recovery:
4221 c_parser_skip_until_found stops at a closing nesting
4222 delimiter without consuming it, but here we need to consume
4223 it to proceed further. */
4224 c_parser_error (parser, "expected statement");
4225 c_parser_consume_token (parser);
4228 c_parser_pragma (parser, pragma_stmt);
4232 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4234 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4237 /* Two cases cannot and do not have line numbers associated: If stmt
4238 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4239 cannot hold line numbers. But that's OK because the statement
4240 will either be changed to a MODIFY_EXPR during gimplification of
4241 the statement expr, or discarded. If stmt was compound, but
4242 without new variables, we will have skipped the creation of a
4243 BIND and will have a bare STATEMENT_LIST. But that's OK because
4244 (recursively) all of the component statements should already have
4245 line numbers assigned. ??? Can we discard no-op statements
4247 if (CAN_HAVE_LOCATION_P (stmt)
4248 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4249 SET_EXPR_LOCATION (stmt, loc);
4251 parser->in_if_block = in_if_block;
4254 /* Parse the condition from an if, do, while or for statements. */
4257 c_parser_condition (c_parser *parser)
4259 location_t loc = c_parser_peek_token (parser)->location;
4261 cond = c_parser_expression_conv (parser).value;
4262 cond = c_objc_common_truthvalue_conversion (loc, cond);
4263 cond = c_fully_fold (cond, false, NULL);
4264 if (warn_sequence_point)
4265 verify_sequence_points (cond);
4269 /* Parse a parenthesized condition from an if, do or while statement.
4275 c_parser_paren_condition (c_parser *parser)
4278 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4279 return error_mark_node;
4280 cond = c_parser_condition (parser);
4281 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4285 /* Parse a statement which is a block in C99. */
4288 c_parser_c99_block_statement (c_parser *parser)
4290 tree block = c_begin_compound_stmt (flag_isoc99);
4291 location_t loc = c_parser_peek_token (parser)->location;
4292 c_parser_statement (parser);
4293 return c_end_compound_stmt (loc, block, flag_isoc99);
4296 /* Parse the body of an if statement. This is just parsing a
4297 statement but (a) it is a block in C99, (b) we track whether the
4298 body is an if statement for the sake of -Wparentheses warnings, (c)
4299 we handle an empty body specially for the sake of -Wempty-body
4300 warnings, and (d) we call parser_compound_statement directly
4301 because c_parser_statement_after_labels resets
4302 parser->in_if_block. */
4305 c_parser_if_body (c_parser *parser, bool *if_p)
4307 tree block = c_begin_compound_stmt (flag_isoc99);
4308 location_t body_loc = c_parser_peek_token (parser)->location;
4309 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4310 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4311 || (c_parser_next_token_is (parser, CPP_NAME)
4312 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4313 c_parser_label (parser);
4314 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4315 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4317 location_t loc = c_parser_peek_token (parser)->location;
4318 add_stmt (build_empty_stmt (loc));
4319 c_parser_consume_token (parser);
4320 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4321 warning_at (loc, OPT_Wempty_body,
4322 "suggest braces around empty body in an %<if%> statement");
4324 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4325 add_stmt (c_parser_compound_statement (parser));
4327 c_parser_statement_after_labels (parser);
4328 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4331 /* Parse the else body of an if statement. This is just parsing a
4332 statement but (a) it is a block in C99, (b) we handle an empty body
4333 specially for the sake of -Wempty-body warnings. */
4336 c_parser_else_body (c_parser *parser)
4338 location_t else_loc = c_parser_peek_token (parser)->location;
4339 tree block = c_begin_compound_stmt (flag_isoc99);
4340 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4341 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4342 || (c_parser_next_token_is (parser, CPP_NAME)
4343 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4344 c_parser_label (parser);
4345 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4347 location_t loc = c_parser_peek_token (parser)->location;
4350 "suggest braces around empty body in an %<else%> statement");
4351 add_stmt (build_empty_stmt (loc));
4352 c_parser_consume_token (parser);
4355 c_parser_statement_after_labels (parser);
4356 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4359 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4362 if ( expression ) statement
4363 if ( expression ) statement else statement
4367 c_parser_if_statement (c_parser *parser)
4372 bool first_if = false;
4373 tree first_body, second_body;
4376 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4377 c_parser_consume_token (parser);
4378 block = c_begin_compound_stmt (flag_isoc99);
4379 loc = c_parser_peek_token (parser)->location;
4380 cond = c_parser_paren_condition (parser);
4381 in_if_block = parser->in_if_block;
4382 parser->in_if_block = true;
4383 first_body = c_parser_if_body (parser, &first_if);
4384 parser->in_if_block = in_if_block;
4385 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4387 c_parser_consume_token (parser);
4388 second_body = c_parser_else_body (parser);
4391 second_body = NULL_TREE;
4392 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4393 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4396 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4399 switch (expression) statement
4403 c_parser_switch_statement (c_parser *parser)
4405 tree block, expr, body, save_break;
4406 location_t switch_loc = c_parser_peek_token (parser)->location;
4407 location_t switch_cond_loc;
4408 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4409 c_parser_consume_token (parser);
4410 block = c_begin_compound_stmt (flag_isoc99);
4411 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4413 switch_cond_loc = c_parser_peek_token (parser)->location;
4414 expr = c_parser_expression (parser).value;
4415 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4419 switch_cond_loc = UNKNOWN_LOCATION;
4420 expr = error_mark_node;
4422 c_start_case (switch_loc, switch_cond_loc, expr);
4423 save_break = c_break_label;
4424 c_break_label = NULL_TREE;
4425 body = c_parser_c99_block_statement (parser);
4426 c_finish_case (body);
4429 location_t here = c_parser_peek_token (parser)->location;
4430 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4431 SET_EXPR_LOCATION (t, here);
4434 c_break_label = save_break;
4435 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4438 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4441 while (expression) statement
4445 c_parser_while_statement (c_parser *parser)
4447 tree block, cond, body, save_break, save_cont;
4449 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4450 c_parser_consume_token (parser);
4451 block = c_begin_compound_stmt (flag_isoc99);
4452 loc = c_parser_peek_token (parser)->location;
4453 cond = c_parser_paren_condition (parser);
4454 save_break = c_break_label;
4455 c_break_label = NULL_TREE;
4456 save_cont = c_cont_label;
4457 c_cont_label = NULL_TREE;
4458 body = c_parser_c99_block_statement (parser);
4459 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4460 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4461 c_break_label = save_break;
4462 c_cont_label = save_cont;
4465 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4468 do statement while ( expression ) ;
4472 c_parser_do_statement (c_parser *parser)
4474 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4476 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4477 c_parser_consume_token (parser);
4478 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4479 warning_at (c_parser_peek_token (parser)->location,
4481 "suggest braces around empty body in %<do%> statement");
4482 block = c_begin_compound_stmt (flag_isoc99);
4483 loc = c_parser_peek_token (parser)->location;
4484 save_break = c_break_label;
4485 c_break_label = NULL_TREE;
4486 save_cont = c_cont_label;
4487 c_cont_label = NULL_TREE;
4488 body = c_parser_c99_block_statement (parser);
4489 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4490 new_break = c_break_label;
4491 c_break_label = save_break;
4492 new_cont = c_cont_label;
4493 c_cont_label = save_cont;
4494 cond = c_parser_paren_condition (parser);
4495 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4496 c_parser_skip_to_end_of_block_or_statement (parser);
4497 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4498 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4501 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4504 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4505 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4507 The form with a declaration is new in C99.
4509 ??? In accordance with the old parser, the declaration may be a
4510 nested function, which is then rejected in check_for_loop_decls,
4511 but does it make any sense for this to be included in the grammar?
4512 Note in particular that the nested function does not include a
4513 trailing ';', whereas the "declaration" production includes one.
4514 Also, can we reject bad declarations earlier and cheaper than
4515 check_for_loop_decls?
4517 In Objective-C, there are two additional variants:
4520 for ( expression in expresssion ) statement
4521 for ( declaration in expression ) statement
4523 This is inconsistent with C, because the second variant is allowed
4524 even if c99 is not enabled.
4526 The rest of the comment documents these Objective-C foreach-statement.
4528 Here is the canonical example of the first variant:
4529 for (object in array) { do something with object }
4530 we call the first expression ("object") the "object_expression" and
4531 the second expression ("array") the "collection_expression".
4532 object_expression must be an lvalue of type "id" (a generic Objective-C
4533 object) because the loop works by assigning to object_expression the
4534 various objects from the collection_expression. collection_expression
4535 must evaluate to something of type "id" which responds to the method
4536 countByEnumeratingWithState:objects:count:.
4538 The canonical example of the second variant is:
4539 for (id object in array) { do something with object }
4540 which is completely equivalent to
4543 for (object in array) { do something with object }
4545 Note that initizializing 'object' in some way (eg, "for ((object =
4546 xxx) in array) { do something with object }") is possibly
4547 technically valid, but completely pointless as 'object' will be
4548 assigned to something else as soon as the loop starts. We should
4549 most likely reject it (TODO).
4551 The beginning of the Objective-C foreach-statement looks exactly
4552 like the beginning of the for-statement, and we can tell it is a
4553 foreach-statement only because the initial declaration or
4554 expression is terminated by 'in' instead of ';'.
4558 c_parser_for_statement (c_parser *parser)
4560 tree block, cond, incr, save_break, save_cont, body;
4561 /* The following are only used when parsing an ObjC foreach statement. */
4562 tree object_expression, collection_expression;
4563 location_t loc = c_parser_peek_token (parser)->location;
4564 location_t for_loc = c_parser_peek_token (parser)->location;
4565 bool is_foreach_statement = false;
4566 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4567 c_parser_consume_token (parser);
4568 /* Open a compound statement in Objective-C as well, just in case this is
4569 as foreach expression. */
4570 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
4571 cond = error_mark_node;
4572 incr = error_mark_node;
4573 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4575 /* Parse the initialization declaration or expression. */
4576 object_expression = error_mark_node;
4577 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4579 c_parser_consume_token (parser);
4580 c_finish_expr_stmt (loc, NULL_TREE);
4582 else if (c_parser_next_token_starts_declaration (parser))
4584 parser->objc_could_be_foreach_context = true;
4585 c_parser_declaration_or_fndef (parser, true, true, true, true, true,
4586 &object_expression);
4587 parser->objc_could_be_foreach_context = false;
4589 if (c_parser_next_token_is_keyword (parser, RID_IN))
4591 c_parser_consume_token (parser);
4592 is_foreach_statement = true;
4593 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4594 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4597 check_for_loop_decls (for_loc, flag_isoc99);
4599 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4601 /* __extension__ can start a declaration, but is also an
4602 unary operator that can start an expression. Consume all
4603 but the last of a possible series of __extension__ to
4605 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4606 && (c_parser_peek_2nd_token (parser)->keyword
4608 c_parser_consume_token (parser);
4609 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4612 ext = disable_extension_diagnostics ();
4613 c_parser_consume_token (parser);
4614 parser->objc_could_be_foreach_context = true;
4615 c_parser_declaration_or_fndef (parser, true, true, true, true,
4616 true, &object_expression);
4617 parser->objc_could_be_foreach_context = false;
4619 restore_extension_diagnostics (ext);
4620 if (c_parser_next_token_is_keyword (parser, RID_IN))
4622 c_parser_consume_token (parser);
4623 is_foreach_statement = true;
4624 if (check_for_loop_decls (for_loc, true) == NULL_TREE)
4625 c_parser_error (parser, "multiple iterating variables in fast enumeration");
4628 check_for_loop_decls (for_loc, flag_isoc99);
4637 tree init_expression;
4638 parser->objc_could_be_foreach_context = true;
4639 init_expression = c_parser_expression (parser).value;
4640 parser->objc_could_be_foreach_context = false;
4641 if (c_parser_next_token_is_keyword (parser, RID_IN))
4643 c_parser_consume_token (parser);
4644 is_foreach_statement = true;
4645 if (! lvalue_p (init_expression))
4646 c_parser_error (parser, "invalid iterating variable in fast enumeration");
4647 object_expression = c_process_expr_stmt (loc, init_expression);
4652 c_finish_expr_stmt (loc, init_expression);
4653 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4657 /* Parse the loop condition. In the case of a foreach
4658 statement, there is no loop condition. */
4659 if (!is_foreach_statement)
4661 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4663 c_parser_consume_token (parser);
4668 cond = c_parser_condition (parser);
4669 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4672 /* Parse the increment expression (the third expression in a
4673 for-statement). In the case of a foreach-statement, this is
4674 the expression that follows the 'in'. */
4675 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4677 if (is_foreach_statement)
4679 c_parser_error (parser, "missing collection in fast enumeration");
4680 collection_expression = error_mark_node;
4683 incr = c_process_expr_stmt (loc, NULL_TREE);
4687 if (is_foreach_statement)
4688 collection_expression = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4690 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4692 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4694 save_break = c_break_label;
4695 c_break_label = NULL_TREE;
4696 save_cont = c_cont_label;
4697 c_cont_label = NULL_TREE;
4698 body = c_parser_c99_block_statement (parser);
4699 if (is_foreach_statement)
4700 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label);
4702 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4703 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
4704 c_break_label = save_break;
4705 c_cont_label = save_cont;
4708 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4709 statement with inputs, outputs, clobbers, and volatile tag
4713 asm type-qualifier[opt] ( asm-argument ) ;
4714 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4718 asm-string-literal : asm-operands[opt]
4719 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4720 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4723 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4726 Qualifiers other than volatile are accepted in the syntax but
4730 c_parser_asm_statement (c_parser *parser)
4732 tree quals, str, outputs, inputs, clobbers, labels, ret;
4733 bool simple, is_goto;
4734 location_t asm_loc = c_parser_peek_token (parser)->location;
4735 int section, nsections;
4737 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4738 c_parser_consume_token (parser);
4739 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4741 quals = c_parser_peek_token (parser)->value;
4742 c_parser_consume_token (parser);
4744 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4745 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4747 warning_at (c_parser_peek_token (parser)->location,
4749 "%E qualifier ignored on asm",
4750 c_parser_peek_token (parser)->value);
4752 c_parser_consume_token (parser);
4758 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4760 c_parser_consume_token (parser);
4764 /* ??? Follow the C++ parser rather than using the
4765 lex_untranslated_string kludge. */
4766 parser->lex_untranslated_string = true;
4769 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4772 str = c_parser_asm_string_literal (parser);
4773 if (str == NULL_TREE)
4774 goto error_close_paren;
4777 outputs = NULL_TREE;
4779 clobbers = NULL_TREE;
4782 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4785 /* Parse each colon-delimited section of operands. */
4786 nsections = 3 + is_goto;
4787 for (section = 0; section < nsections; ++section)
4789 if (!c_parser_require (parser, CPP_COLON,
4792 : "expected %<:%> or %<)%>"))
4793 goto error_close_paren;
4795 /* Once past any colon, we're no longer a simple asm. */
4798 if ((!c_parser_next_token_is (parser, CPP_COLON)
4799 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4804 /* For asm goto, we don't allow output operands, but reserve
4805 the slot for a future extension that does allow them. */
4807 outputs = c_parser_asm_operands (parser, false);
4810 inputs = c_parser_asm_operands (parser, true);
4813 clobbers = c_parser_asm_clobbers (parser);
4816 labels = c_parser_asm_goto_operands (parser);
4822 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4827 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4829 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4833 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4834 c_parser_skip_to_end_of_block_or_statement (parser);
4836 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4837 clobbers, labels, simple));
4840 parser->lex_untranslated_string = false;
4844 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4848 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4849 not outputs), apply the default conversion of functions and arrays
4854 asm-operands , asm-operand
4857 asm-string-literal ( expression )
4858 [ identifier ] asm-string-literal ( expression )
4862 c_parser_asm_operands (c_parser *parser, bool convert_p)
4864 tree list = NULL_TREE;
4870 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4872 c_parser_consume_token (parser);
4873 if (c_parser_next_token_is (parser, CPP_NAME))
4875 tree id = c_parser_peek_token (parser)->value;
4876 c_parser_consume_token (parser);
4877 name = build_string (IDENTIFIER_LENGTH (id),
4878 IDENTIFIER_POINTER (id));
4882 c_parser_error (parser, "expected identifier");
4883 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4886 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4891 str = c_parser_asm_string_literal (parser);
4892 if (str == NULL_TREE)
4894 parser->lex_untranslated_string = false;
4895 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4897 parser->lex_untranslated_string = true;
4900 loc = c_parser_peek_token (parser)->location;
4901 expr = c_parser_expression (parser);
4902 mark_exp_read (expr.value);
4904 expr = default_function_array_conversion (loc, expr);
4905 expr.value = c_fully_fold (expr.value, false, NULL);
4906 parser->lex_untranslated_string = true;
4907 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4909 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4912 list = chainon (list, build_tree_list (build_tree_list (name, str),
4914 if (c_parser_next_token_is (parser, CPP_COMMA))
4915 c_parser_consume_token (parser);
4922 /* Parse asm clobbers, a GNU extension.
4926 asm-clobbers , asm-string-literal
4930 c_parser_asm_clobbers (c_parser *parser)
4932 tree list = NULL_TREE;
4935 tree str = c_parser_asm_string_literal (parser);
4937 list = tree_cons (NULL_TREE, str, list);
4940 if (c_parser_next_token_is (parser, CPP_COMMA))
4941 c_parser_consume_token (parser);
4948 /* Parse asm goto labels, a GNU extension.
4952 asm-goto-operands , identifier
4956 c_parser_asm_goto_operands (c_parser *parser)
4958 tree list = NULL_TREE;
4963 if (c_parser_next_token_is (parser, CPP_NAME))
4965 c_token *tok = c_parser_peek_token (parser);
4967 label = lookup_label_for_goto (tok->location, name);
4968 c_parser_consume_token (parser);
4969 TREE_USED (label) = 1;
4973 c_parser_error (parser, "expected identifier");
4977 name = build_string (IDENTIFIER_LENGTH (name),
4978 IDENTIFIER_POINTER (name));
4979 list = tree_cons (name, label, list);
4980 if (c_parser_next_token_is (parser, CPP_COMMA))
4981 c_parser_consume_token (parser);
4983 return nreverse (list);
4987 /* Parse an expression other than a compound expression; that is, an
4988 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4989 NULL then it is an Objective-C message expression which is the
4990 primary-expression starting the expression as an initializer.
4992 assignment-expression:
4993 conditional-expression
4994 unary-expression assignment-operator assignment-expression
4996 assignment-operator: one of
4997 = *= /= %= += -= <<= >>= &= ^= |=
4999 In GNU C we accept any conditional expression on the LHS and
5000 diagnose the invalid lvalue rather than producing a syntax
5003 static struct c_expr
5004 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
5006 struct c_expr lhs, rhs, ret;
5007 enum tree_code code;
5008 location_t op_location, exp_location;
5009 gcc_assert (!after || c_dialect_objc ());
5010 lhs = c_parser_conditional_expression (parser, after);
5011 op_location = c_parser_peek_token (parser)->location;
5012 switch (c_parser_peek_token (parser)->type)
5021 code = TRUNC_DIV_EXPR;
5024 code = TRUNC_MOD_EXPR;
5039 code = BIT_AND_EXPR;
5042 code = BIT_XOR_EXPR;
5045 code = BIT_IOR_EXPR;
5050 c_parser_consume_token (parser);
5051 exp_location = c_parser_peek_token (parser)->location;
5052 rhs = c_parser_expr_no_commas (parser, NULL);
5053 rhs = default_function_array_read_conversion (exp_location, rhs);
5054 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
5055 code, exp_location, rhs.value,
5057 if (code == NOP_EXPR)
5058 ret.original_code = MODIFY_EXPR;
5061 TREE_NO_WARNING (ret.value) = 1;
5062 ret.original_code = ERROR_MARK;
5064 ret.original_type = NULL;
5068 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5069 is not NULL then it is an Objective-C message expression which is
5070 the primary-expression starting the expression as an initializer.
5072 conditional-expression:
5073 logical-OR-expression
5074 logical-OR-expression ? expression : conditional-expression
5078 conditional-expression:
5079 logical-OR-expression ? : conditional-expression
5082 static struct c_expr
5083 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
5085 struct c_expr cond, exp1, exp2, ret;
5086 location_t cond_loc, colon_loc, middle_loc;
5088 gcc_assert (!after || c_dialect_objc ());
5090 cond = c_parser_binary_expression (parser, after);
5092 if (c_parser_next_token_is_not (parser, CPP_QUERY))
5094 cond_loc = c_parser_peek_token (parser)->location;
5095 cond = default_function_array_read_conversion (cond_loc, cond);
5096 c_parser_consume_token (parser);
5097 if (c_parser_next_token_is (parser, CPP_COLON))
5099 tree eptype = NULL_TREE;
5101 middle_loc = c_parser_peek_token (parser)->location;
5102 pedwarn (middle_loc, OPT_pedantic,
5103 "ISO C forbids omitting the middle term of a ?: expression");
5104 warn_for_omitted_condop (middle_loc, cond.value);
5105 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
5107 eptype = TREE_TYPE (cond.value);
5108 cond.value = TREE_OPERAND (cond.value, 0);
5110 /* Make sure first operand is calculated only once. */
5111 exp1.value = c_save_expr (default_conversion (cond.value));
5113 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
5114 exp1.original_type = NULL;
5115 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
5116 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
5121 = c_objc_common_truthvalue_conversion
5122 (cond_loc, default_conversion (cond.value));
5123 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
5124 exp1 = c_parser_expression_conv (parser);
5125 mark_exp_read (exp1.value);
5126 c_inhibit_evaluation_warnings +=
5127 ((cond.value == truthvalue_true_node)
5128 - (cond.value == truthvalue_false_node));
5131 colon_loc = c_parser_peek_token (parser)->location;
5132 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
5134 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5135 ret.value = error_mark_node;
5136 ret.original_code = ERROR_MARK;
5137 ret.original_type = NULL;
5141 location_t exp2_loc = c_parser_peek_token (parser)->location;
5142 exp2 = c_parser_conditional_expression (parser, NULL);
5143 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
5145 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
5146 ret.value = build_conditional_expr (colon_loc, cond.value,
5147 cond.original_code == C_MAYBE_CONST_EXPR,
5148 exp1.value, exp1.original_type,
5149 exp2.value, exp2.original_type);
5150 ret.original_code = ERROR_MARK;
5151 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
5152 ret.original_type = NULL;
5157 /* If both sides are enum type, the default conversion will have
5158 made the type of the result be an integer type. We want to
5159 remember the enum types we started with. */
5160 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
5161 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
5162 ret.original_type = ((t1 != error_mark_node
5163 && t2 != error_mark_node
5164 && (TYPE_MAIN_VARIANT (t1)
5165 == TYPE_MAIN_VARIANT (t2)))
5172 /* Parse a binary expression; that is, a logical-OR-expression (C90
5173 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5174 an Objective-C message expression which is the primary-expression
5175 starting the expression as an initializer.
5177 multiplicative-expression:
5179 multiplicative-expression * cast-expression
5180 multiplicative-expression / cast-expression
5181 multiplicative-expression % cast-expression
5183 additive-expression:
5184 multiplicative-expression
5185 additive-expression + multiplicative-expression
5186 additive-expression - multiplicative-expression
5190 shift-expression << additive-expression
5191 shift-expression >> additive-expression
5193 relational-expression:
5195 relational-expression < shift-expression
5196 relational-expression > shift-expression
5197 relational-expression <= shift-expression
5198 relational-expression >= shift-expression
5200 equality-expression:
5201 relational-expression
5202 equality-expression == relational-expression
5203 equality-expression != relational-expression
5207 AND-expression & equality-expression
5209 exclusive-OR-expression:
5211 exclusive-OR-expression ^ AND-expression
5213 inclusive-OR-expression:
5214 exclusive-OR-expression
5215 inclusive-OR-expression | exclusive-OR-expression
5217 logical-AND-expression:
5218 inclusive-OR-expression
5219 logical-AND-expression && inclusive-OR-expression
5221 logical-OR-expression:
5222 logical-AND-expression
5223 logical-OR-expression || logical-AND-expression
5226 static struct c_expr
5227 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5229 /* A binary expression is parsed using operator-precedence parsing,
5230 with the operands being cast expressions. All the binary
5231 operators are left-associative. Thus a binary expression is of
5234 E0 op1 E1 op2 E2 ...
5236 which we represent on a stack. On the stack, the precedence
5237 levels are strictly increasing. When a new operator is
5238 encountered of higher precedence than that at the top of the
5239 stack, it is pushed; its LHS is the top expression, and its RHS
5240 is everything parsed until it is popped. When a new operator is
5241 encountered with precedence less than or equal to that at the top
5242 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5243 by the result of the operation until the operator at the top of
5244 the stack has lower precedence than the new operator or there is
5245 only one element on the stack; then the top expression is the LHS
5246 of the new operator. In the case of logical AND and OR
5247 expressions, we also need to adjust c_inhibit_evaluation_warnings
5248 as appropriate when the operators are pushed and popped. */
5250 /* The precedence levels, where 0 is a dummy lowest level used for
5251 the bottom of the stack. */
5267 /* The expression at this stack level. */
5269 /* The precedence of the operator on its left, PREC_NONE at the
5270 bottom of the stack. */
5272 /* The operation on its left. */
5274 /* The source location of this operation. */
5278 /* Location of the binary operator. */
5279 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5282 switch (stack[sp].op) \
5284 case TRUTH_ANDIF_EXPR: \
5285 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5286 == truthvalue_false_node); \
5288 case TRUTH_ORIF_EXPR: \
5289 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5290 == truthvalue_true_node); \
5295 stack[sp - 1].expr \
5296 = default_function_array_read_conversion (stack[sp - 1].loc, \
5297 stack[sp - 1].expr); \
5299 = default_function_array_read_conversion (stack[sp].loc, \
5301 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5303 stack[sp - 1].expr, \
5307 gcc_assert (!after || c_dialect_objc ());
5308 stack[0].loc = c_parser_peek_token (parser)->location;
5309 stack[0].expr = c_parser_cast_expression (parser, after);
5310 stack[0].prec = PREC_NONE;
5315 enum tree_code ocode;
5318 switch (c_parser_peek_token (parser)->type)
5326 ocode = TRUNC_DIV_EXPR;
5330 ocode = TRUNC_MOD_EXPR;
5342 ocode = LSHIFT_EXPR;
5346 ocode = RSHIFT_EXPR;
5360 case CPP_GREATER_EQ:
5373 oprec = PREC_BITAND;
5374 ocode = BIT_AND_EXPR;
5377 oprec = PREC_BITXOR;
5378 ocode = BIT_XOR_EXPR;
5382 ocode = BIT_IOR_EXPR;
5385 oprec = PREC_LOGAND;
5386 ocode = TRUTH_ANDIF_EXPR;
5390 ocode = TRUTH_ORIF_EXPR;
5393 /* Not a binary operator, so end of the binary
5397 binary_loc = c_parser_peek_token (parser)->location;
5398 c_parser_consume_token (parser);
5399 while (oprec <= stack[sp].prec)
5403 case TRUTH_ANDIF_EXPR:
5405 = default_function_array_read_conversion (stack[sp].loc,
5407 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5408 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5409 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5410 == truthvalue_false_node);
5412 case TRUTH_ORIF_EXPR:
5414 = default_function_array_read_conversion (stack[sp].loc,
5416 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5417 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5418 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5419 == truthvalue_true_node);
5425 stack[sp].loc = binary_loc;
5426 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5427 stack[sp].prec = oprec;
5428 stack[sp].op = ocode;
5429 stack[sp].loc = binary_loc;
5434 return stack[0].expr;
5438 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5439 NULL then it is an Objective-C message expression which is the
5440 primary-expression starting the expression as an initializer.
5444 ( type-name ) unary-expression
5447 static struct c_expr
5448 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5450 location_t cast_loc = c_parser_peek_token (parser)->location;
5451 gcc_assert (!after || c_dialect_objc ());
5453 return c_parser_postfix_expression_after_primary (parser,
5455 /* If the expression begins with a parenthesized type name, it may
5456 be either a cast or a compound literal; we need to see whether
5457 the next character is '{' to tell the difference. If not, it is
5458 an unary expression. */
5459 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5460 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5462 struct c_type_name *type_name;
5465 c_parser_consume_token (parser);
5466 type_name = c_parser_type_name (parser);
5467 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5468 if (type_name == NULL)
5470 ret.value = error_mark_node;
5471 ret.original_code = ERROR_MARK;
5472 ret.original_type = NULL;
5476 /* Save casted types in the function's used types hash table. */
5477 used_types_insert (type_name->specs->type);
5479 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5480 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5483 location_t expr_loc = c_parser_peek_token (parser)->location;
5484 expr = c_parser_cast_expression (parser, NULL);
5485 expr = default_function_array_read_conversion (expr_loc, expr);
5487 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5488 ret.original_code = ERROR_MARK;
5489 ret.original_type = NULL;
5493 return c_parser_unary_expression (parser);
5496 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5502 unary-operator cast-expression
5503 sizeof unary-expression
5504 sizeof ( type-name )
5506 unary-operator: one of
5512 __alignof__ unary-expression
5513 __alignof__ ( type-name )
5516 unary-operator: one of
5517 __extension__ __real__ __imag__
5519 In addition, the GNU syntax treats ++ and -- as unary operators, so
5520 they may be applied to cast expressions with errors for non-lvalues
5523 static struct c_expr
5524 c_parser_unary_expression (c_parser *parser)
5527 struct c_expr ret, op;
5528 location_t op_loc = c_parser_peek_token (parser)->location;
5530 ret.original_code = ERROR_MARK;
5531 ret.original_type = NULL;
5532 switch (c_parser_peek_token (parser)->type)
5535 c_parser_consume_token (parser);
5536 exp_loc = c_parser_peek_token (parser)->location;
5537 op = c_parser_cast_expression (parser, NULL);
5538 op = default_function_array_read_conversion (exp_loc, op);
5539 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5540 case CPP_MINUS_MINUS:
5541 c_parser_consume_token (parser);
5542 exp_loc = c_parser_peek_token (parser)->location;
5543 op = c_parser_cast_expression (parser, NULL);
5544 op = default_function_array_read_conversion (exp_loc, op);
5545 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5547 c_parser_consume_token (parser);
5548 op = c_parser_cast_expression (parser, NULL);
5549 mark_exp_read (op.value);
5550 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5552 c_parser_consume_token (parser);
5553 exp_loc = c_parser_peek_token (parser)->location;
5554 op = c_parser_cast_expression (parser, NULL);
5555 op = default_function_array_read_conversion (exp_loc, op);
5556 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5559 if (!c_dialect_objc () && !in_system_header)
5562 "traditional C rejects the unary plus operator");
5563 c_parser_consume_token (parser);
5564 exp_loc = c_parser_peek_token (parser)->location;
5565 op = c_parser_cast_expression (parser, NULL);
5566 op = default_function_array_read_conversion (exp_loc, op);
5567 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5569 c_parser_consume_token (parser);
5570 exp_loc = c_parser_peek_token (parser)->location;
5571 op = c_parser_cast_expression (parser, NULL);
5572 op = default_function_array_read_conversion (exp_loc, op);
5573 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5575 c_parser_consume_token (parser);
5576 exp_loc = c_parser_peek_token (parser)->location;
5577 op = c_parser_cast_expression (parser, NULL);
5578 op = default_function_array_read_conversion (exp_loc, op);
5579 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5581 c_parser_consume_token (parser);
5582 exp_loc = c_parser_peek_token (parser)->location;
5583 op = c_parser_cast_expression (parser, NULL);
5584 op = default_function_array_read_conversion (exp_loc, op);
5585 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5587 /* Refer to the address of a label as a pointer. */
5588 c_parser_consume_token (parser);
5589 if (c_parser_next_token_is (parser, CPP_NAME))
5591 ret.value = finish_label_address_expr
5592 (c_parser_peek_token (parser)->value, op_loc);
5593 c_parser_consume_token (parser);
5597 c_parser_error (parser, "expected identifier");
5598 ret.value = error_mark_node;
5602 switch (c_parser_peek_token (parser)->keyword)
5605 return c_parser_sizeof_expression (parser);
5607 return c_parser_alignof_expression (parser);
5609 c_parser_consume_token (parser);
5610 ext = disable_extension_diagnostics ();
5611 ret = c_parser_cast_expression (parser, NULL);
5612 restore_extension_diagnostics (ext);
5615 c_parser_consume_token (parser);
5616 exp_loc = c_parser_peek_token (parser)->location;
5617 op = c_parser_cast_expression (parser, NULL);
5618 op = default_function_array_conversion (exp_loc, op);
5619 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5621 c_parser_consume_token (parser);
5622 exp_loc = c_parser_peek_token (parser)->location;
5623 op = c_parser_cast_expression (parser, NULL);
5624 op = default_function_array_conversion (exp_loc, op);
5625 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5627 return c_parser_postfix_expression (parser);
5630 return c_parser_postfix_expression (parser);
5634 /* Parse a sizeof expression. */
5636 static struct c_expr
5637 c_parser_sizeof_expression (c_parser *parser)
5640 location_t expr_loc;
5641 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5642 c_parser_consume_token (parser);
5643 c_inhibit_evaluation_warnings++;
5645 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5646 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5648 /* Either sizeof ( type-name ) or sizeof unary-expression
5649 starting with a compound literal. */
5650 struct c_type_name *type_name;
5651 c_parser_consume_token (parser);
5652 expr_loc = c_parser_peek_token (parser)->location;
5653 type_name = c_parser_type_name (parser);
5654 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5655 if (type_name == NULL)
5658 c_inhibit_evaluation_warnings--;
5660 ret.value = error_mark_node;
5661 ret.original_code = ERROR_MARK;
5662 ret.original_type = NULL;
5665 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5667 expr = c_parser_postfix_expression_after_paren_type (parser,
5672 /* sizeof ( type-name ). */
5673 c_inhibit_evaluation_warnings--;
5675 return c_expr_sizeof_type (expr_loc, type_name);
5679 expr_loc = c_parser_peek_token (parser)->location;
5680 expr = c_parser_unary_expression (parser);
5682 c_inhibit_evaluation_warnings--;
5684 mark_exp_read (expr.value);
5685 if (TREE_CODE (expr.value) == COMPONENT_REF
5686 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5687 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5688 return c_expr_sizeof_expr (expr_loc, expr);
5692 /* Parse an alignof expression. */
5694 static struct c_expr
5695 c_parser_alignof_expression (c_parser *parser)
5698 location_t loc = c_parser_peek_token (parser)->location;
5699 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5700 c_parser_consume_token (parser);
5701 c_inhibit_evaluation_warnings++;
5703 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5704 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5706 /* Either __alignof__ ( type-name ) or __alignof__
5707 unary-expression starting with a compound literal. */
5709 struct c_type_name *type_name;
5711 c_parser_consume_token (parser);
5712 loc = c_parser_peek_token (parser)->location;
5713 type_name = c_parser_type_name (parser);
5714 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5715 if (type_name == NULL)
5718 c_inhibit_evaluation_warnings--;
5720 ret.value = error_mark_node;
5721 ret.original_code = ERROR_MARK;
5722 ret.original_type = NULL;
5725 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5727 expr = c_parser_postfix_expression_after_paren_type (parser,
5732 /* alignof ( type-name ). */
5733 c_inhibit_evaluation_warnings--;
5735 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5736 ret.original_code = ERROR_MARK;
5737 ret.original_type = NULL;
5743 expr = c_parser_unary_expression (parser);
5745 mark_exp_read (expr.value);
5746 c_inhibit_evaluation_warnings--;
5748 ret.value = c_alignof_expr (loc, expr.value);
5749 ret.original_code = ERROR_MARK;
5750 ret.original_type = NULL;
5755 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5759 postfix-expression [ expression ]
5760 postfix-expression ( argument-expression-list[opt] )
5761 postfix-expression . identifier
5762 postfix-expression -> identifier
5763 postfix-expression ++
5764 postfix-expression --
5765 ( type-name ) { initializer-list }
5766 ( type-name ) { initializer-list , }
5768 argument-expression-list:
5770 argument-expression-list , argument-expression
5782 (treated as a keyword in GNU C)
5785 ( compound-statement )
5786 __builtin_va_arg ( assignment-expression , type-name )
5787 __builtin_offsetof ( type-name , offsetof-member-designator )
5788 __builtin_choose_expr ( assignment-expression ,
5789 assignment-expression ,
5790 assignment-expression )
5791 __builtin_types_compatible_p ( type-name , type-name )
5793 offsetof-member-designator:
5795 offsetof-member-designator . identifier
5796 offsetof-member-designator [ expression ]
5801 [ objc-receiver objc-message-args ]
5802 @selector ( objc-selector-arg )
5803 @protocol ( identifier )
5804 @encode ( type-name )
5808 static struct c_expr
5809 c_parser_postfix_expression (c_parser *parser)
5811 struct c_expr expr, e1, e2, e3;
5812 struct c_type_name *t1, *t2;
5813 location_t loc = c_parser_peek_token (parser)->location;;
5814 expr.original_code = ERROR_MARK;
5815 expr.original_type = NULL;
5816 switch (c_parser_peek_token (parser)->type)
5819 expr.value = c_parser_peek_token (parser)->value;
5820 loc = c_parser_peek_token (parser)->location;
5821 c_parser_consume_token (parser);
5822 if (TREE_CODE (expr.value) == FIXED_CST
5823 && !targetm.fixed_point_supported_p ())
5825 error_at (loc, "fixed-point types not supported for this target");
5826 expr.value = error_mark_node;
5833 expr.value = c_parser_peek_token (parser)->value;
5834 c_parser_consume_token (parser);
5840 case CPP_UTF8STRING:
5841 expr.value = c_parser_peek_token (parser)->value;
5842 expr.original_code = STRING_CST;
5843 c_parser_consume_token (parser);
5845 case CPP_OBJC_STRING:
5846 gcc_assert (c_dialect_objc ());
5848 = objc_build_string_object (c_parser_peek_token (parser)->value);
5849 c_parser_consume_token (parser);
5852 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5854 c_parser_error (parser, "expected expression");
5855 expr.value = error_mark_node;
5859 tree id = c_parser_peek_token (parser)->value;
5860 c_parser_consume_token (parser);
5861 expr.value = build_external_ref (loc, id,
5862 (c_parser_peek_token (parser)->type
5864 &expr.original_type);
5867 case CPP_OPEN_PAREN:
5868 /* A parenthesized expression, statement expression or compound
5870 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5872 /* A statement expression. */
5874 location_t brace_loc;
5875 c_parser_consume_token (parser);
5876 brace_loc = c_parser_peek_token (parser)->location;
5877 c_parser_consume_token (parser);
5878 if (cur_stmt_list == NULL)
5880 error_at (loc, "braced-group within expression allowed "
5881 "only inside a function");
5882 parser->error = true;
5883 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5884 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5885 expr.value = error_mark_node;
5888 stmt = c_begin_stmt_expr ();
5889 c_parser_compound_statement_nostart (parser);
5890 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5892 pedwarn (loc, OPT_pedantic,
5893 "ISO C forbids braced-groups within expressions");
5894 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5895 mark_exp_read (expr.value);
5897 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5899 /* A compound literal. ??? Can we actually get here rather
5900 than going directly to
5901 c_parser_postfix_expression_after_paren_type from
5904 struct c_type_name *type_name;
5905 c_parser_consume_token (parser);
5906 loc = c_parser_peek_token (parser)->location;
5907 type_name = c_parser_type_name (parser);
5908 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5910 if (type_name == NULL)
5912 expr.value = error_mark_node;
5915 expr = c_parser_postfix_expression_after_paren_type (parser,
5921 /* A parenthesized expression. */
5922 c_parser_consume_token (parser);
5923 expr = c_parser_expression (parser);
5924 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5925 TREE_NO_WARNING (expr.value) = 1;
5926 if (expr.original_code != C_MAYBE_CONST_EXPR)
5927 expr.original_code = ERROR_MARK;
5928 /* Don't change EXPR.ORIGINAL_TYPE. */
5929 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5934 switch (c_parser_peek_token (parser)->keyword)
5936 case RID_FUNCTION_NAME:
5937 case RID_PRETTY_FUNCTION_NAME:
5938 case RID_C99_FUNCTION_NAME:
5939 expr.value = fname_decl (loc,
5940 c_parser_peek_token (parser)->keyword,
5941 c_parser_peek_token (parser)->value);
5942 c_parser_consume_token (parser);
5945 c_parser_consume_token (parser);
5946 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5948 expr.value = error_mark_node;
5951 e1 = c_parser_expr_no_commas (parser, NULL);
5952 mark_exp_read (e1.value);
5953 e1.value = c_fully_fold (e1.value, false, NULL);
5954 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5956 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5957 expr.value = error_mark_node;
5960 loc = c_parser_peek_token (parser)->location;
5961 t1 = c_parser_type_name (parser);
5962 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5966 expr.value = error_mark_node;
5970 tree type_expr = NULL_TREE;
5971 expr.value = c_build_va_arg (loc, e1.value,
5972 groktypename (t1, &type_expr, NULL));
5975 expr.value = build2 (C_MAYBE_CONST_EXPR,
5976 TREE_TYPE (expr.value), type_expr,
5978 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5983 c_parser_consume_token (parser);
5984 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5986 expr.value = error_mark_node;
5989 t1 = c_parser_type_name (parser);
5992 expr.value = error_mark_node;
5995 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5997 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5998 expr.value = error_mark_node;
6002 tree type = groktypename (t1, NULL, NULL);
6004 if (type == error_mark_node)
6005 offsetof_ref = error_mark_node;
6008 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
6009 SET_EXPR_LOCATION (offsetof_ref, loc);
6011 /* Parse the second argument to __builtin_offsetof. We
6012 must have one identifier, and beyond that we want to
6013 accept sub structure and sub array references. */
6014 if (c_parser_next_token_is (parser, CPP_NAME))
6016 offsetof_ref = build_component_ref
6017 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
6018 c_parser_consume_token (parser);
6019 while (c_parser_next_token_is (parser, CPP_DOT)
6020 || c_parser_next_token_is (parser,
6022 || c_parser_next_token_is (parser,
6025 if (c_parser_next_token_is (parser, CPP_DEREF))
6027 loc = c_parser_peek_token (parser)->location;
6028 offsetof_ref = build_array_ref (loc,
6033 else if (c_parser_next_token_is (parser, CPP_DOT))
6036 c_parser_consume_token (parser);
6037 if (c_parser_next_token_is_not (parser,
6040 c_parser_error (parser, "expected identifier");
6043 offsetof_ref = build_component_ref
6045 c_parser_peek_token (parser)->value);
6046 c_parser_consume_token (parser);
6051 loc = c_parser_peek_token (parser)->location;
6052 c_parser_consume_token (parser);
6053 idx = c_parser_expression (parser).value;
6054 idx = c_fully_fold (idx, false, NULL);
6055 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6057 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
6062 c_parser_error (parser, "expected identifier");
6063 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6065 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
6068 case RID_CHOOSE_EXPR:
6069 c_parser_consume_token (parser);
6070 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6072 expr.value = error_mark_node;
6075 loc = c_parser_peek_token (parser)->location;
6076 e1 = c_parser_expr_no_commas (parser, NULL);
6077 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6079 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6080 expr.value = error_mark_node;
6083 e2 = c_parser_expr_no_commas (parser, NULL);
6084 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6086 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6087 expr.value = error_mark_node;
6090 e3 = c_parser_expr_no_commas (parser, NULL);
6091 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6097 mark_exp_read (e2.value);
6098 mark_exp_read (e3.value);
6099 if (TREE_CODE (c) != INTEGER_CST
6100 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
6102 "first argument to %<__builtin_choose_expr%> not"
6104 constant_expression_warning (c);
6105 expr = integer_zerop (c) ? e3 : e2;
6108 case RID_TYPES_COMPATIBLE_P:
6109 c_parser_consume_token (parser);
6110 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6112 expr.value = error_mark_node;
6115 t1 = c_parser_type_name (parser);
6118 expr.value = error_mark_node;
6121 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
6123 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6124 expr.value = error_mark_node;
6127 t2 = c_parser_type_name (parser);
6130 expr.value = error_mark_node;
6133 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6138 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
6139 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
6142 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
6145 case RID_AT_SELECTOR:
6146 gcc_assert (c_dialect_objc ());
6147 c_parser_consume_token (parser);
6148 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6150 expr.value = error_mark_node;
6154 tree sel = c_parser_objc_selector_arg (parser);
6155 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6157 expr.value = objc_build_selector_expr (loc, sel);
6160 case RID_AT_PROTOCOL:
6161 gcc_assert (c_dialect_objc ());
6162 c_parser_consume_token (parser);
6163 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6165 expr.value = error_mark_node;
6168 if (c_parser_next_token_is_not (parser, CPP_NAME))
6170 c_parser_error (parser, "expected identifier");
6171 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6172 expr.value = error_mark_node;
6176 tree id = c_parser_peek_token (parser)->value;
6177 c_parser_consume_token (parser);
6178 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6180 expr.value = objc_build_protocol_expr (id);
6184 /* Extension to support C-structures in the archiver. */
6185 gcc_assert (c_dialect_objc ());
6186 c_parser_consume_token (parser);
6187 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6189 expr.value = error_mark_node;
6192 t1 = c_parser_type_name (parser);
6195 expr.value = error_mark_node;
6196 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6199 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6202 tree type = groktypename (t1, NULL, NULL);
6203 expr.value = objc_build_encode_expr (type);
6207 c_parser_error (parser, "expected expression");
6208 expr.value = error_mark_node;
6212 case CPP_OPEN_SQUARE:
6213 if (c_dialect_objc ())
6215 tree receiver, args;
6216 c_parser_consume_token (parser);
6217 receiver = c_parser_objc_receiver (parser);
6218 args = c_parser_objc_message_args (parser);
6219 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6221 expr.value = objc_build_message_expr (build_tree_list (receiver,
6225 /* Else fall through to report error. */
6227 c_parser_error (parser, "expected expression");
6228 expr.value = error_mark_node;
6231 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6234 /* Parse a postfix expression after a parenthesized type name: the
6235 brace-enclosed initializer of a compound literal, possibly followed
6236 by some postfix operators. This is separate because it is not
6237 possible to tell until after the type name whether a cast
6238 expression has a cast or a compound literal, or whether the operand
6239 of sizeof is a parenthesized type name or starts with a compound
6240 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6241 location of the first token after the parentheses around the type
6244 static struct c_expr
6245 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6246 struct c_type_name *type_name,
6247 location_t type_loc)
6253 location_t start_loc;
6254 tree type_expr = NULL_TREE;
6255 bool type_expr_const = true;
6256 check_compound_literal_type (type_loc, type_name);
6257 start_init (NULL_TREE, NULL, 0);
6258 type = groktypename (type_name, &type_expr, &type_expr_const);
6259 start_loc = c_parser_peek_token (parser)->location;
6260 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6262 error_at (type_loc, "compound literal has variable size");
6263 type = error_mark_node;
6265 init = c_parser_braced_init (parser, type, false);
6267 maybe_warn_string_init (type, init);
6269 if (type != error_mark_node
6270 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6271 && current_function_decl)
6273 error ("compound literal qualified by address-space qualifier");
6274 type = error_mark_node;
6278 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6279 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6280 ? CONSTRUCTOR_NON_CONST (init.value)
6281 : init.original_code == C_MAYBE_CONST_EXPR);
6282 non_const |= !type_expr_const;
6283 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6284 expr.original_code = ERROR_MARK;
6285 expr.original_type = NULL;
6288 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6290 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6291 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6295 gcc_assert (!non_const);
6296 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6297 type_expr, expr.value);
6300 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6303 /* Parse a postfix expression after the initial primary or compound
6304 literal; that is, parse a series of postfix operators.
6306 EXPR_LOC is the location of the primary expression. */
6308 static struct c_expr
6309 c_parser_postfix_expression_after_primary (c_parser *parser,
6310 location_t expr_loc,
6313 struct c_expr orig_expr;
6315 VEC(tree,gc) *exprlist;
6316 VEC(tree,gc) *origtypes;
6319 location_t op_loc = c_parser_peek_token (parser)->location;
6320 switch (c_parser_peek_token (parser)->type)
6322 case CPP_OPEN_SQUARE:
6323 /* Array reference. */
6324 c_parser_consume_token (parser);
6325 idx = c_parser_expression (parser).value;
6326 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6328 expr.value = build_array_ref (op_loc, expr.value, idx);
6329 expr.original_code = ERROR_MARK;
6330 expr.original_type = NULL;
6332 case CPP_OPEN_PAREN:
6333 /* Function call. */
6334 c_parser_consume_token (parser);
6335 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6338 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6339 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6342 mark_exp_read (expr.value);
6343 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6344 "(" after the FUNCNAME, which is what we have now. */
6345 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6347 expr.original_code = ERROR_MARK;
6348 if (TREE_CODE (expr.value) == INTEGER_CST
6349 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6350 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6351 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6352 expr.original_code = C_MAYBE_CONST_EXPR;
6353 expr.original_type = NULL;
6354 if (exprlist != NULL)
6356 release_tree_vector (exprlist);
6357 release_tree_vector (origtypes);
6361 /* Structure element reference. */
6362 c_parser_consume_token (parser);
6363 expr = default_function_array_conversion (expr_loc, expr);
6364 if (c_parser_next_token_is (parser, CPP_NAME))
6365 ident = c_parser_peek_token (parser)->value;
6368 c_parser_error (parser, "expected identifier");
6369 expr.value = error_mark_node;
6370 expr.original_code = ERROR_MARK;
6371 expr.original_type = NULL;
6374 c_parser_consume_token (parser);
6375 expr.value = build_component_ref (op_loc, expr.value, ident);
6376 expr.original_code = ERROR_MARK;
6377 if (TREE_CODE (expr.value) != COMPONENT_REF)
6378 expr.original_type = NULL;
6381 /* Remember the original type of a bitfield. */
6382 tree field = TREE_OPERAND (expr.value, 1);
6383 if (TREE_CODE (field) != FIELD_DECL)
6384 expr.original_type = NULL;
6386 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6390 /* Structure element reference. */
6391 c_parser_consume_token (parser);
6392 expr = default_function_array_conversion (expr_loc, expr);
6393 if (c_parser_next_token_is (parser, CPP_NAME))
6394 ident = c_parser_peek_token (parser)->value;
6397 c_parser_error (parser, "expected identifier");
6398 expr.value = error_mark_node;
6399 expr.original_code = ERROR_MARK;
6400 expr.original_type = NULL;
6403 c_parser_consume_token (parser);
6404 expr.value = build_component_ref (op_loc,
6405 build_indirect_ref (op_loc,
6409 expr.original_code = ERROR_MARK;
6410 if (TREE_CODE (expr.value) != COMPONENT_REF)
6411 expr.original_type = NULL;
6414 /* Remember the original type of a bitfield. */
6415 tree field = TREE_OPERAND (expr.value, 1);
6416 if (TREE_CODE (field) != FIELD_DECL)
6417 expr.original_type = NULL;
6419 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6423 /* Postincrement. */
6424 c_parser_consume_token (parser);
6425 expr = default_function_array_read_conversion (expr_loc, expr);
6426 expr.value = build_unary_op (op_loc,
6427 POSTINCREMENT_EXPR, expr.value, 0);
6428 expr.original_code = ERROR_MARK;
6429 expr.original_type = NULL;
6431 case CPP_MINUS_MINUS:
6432 /* Postdecrement. */
6433 c_parser_consume_token (parser);
6434 expr = default_function_array_read_conversion (expr_loc, expr);
6435 expr.value = build_unary_op (op_loc,
6436 POSTDECREMENT_EXPR, expr.value, 0);
6437 expr.original_code = ERROR_MARK;
6438 expr.original_type = NULL;
6446 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6449 assignment-expression
6450 expression , assignment-expression
6453 static struct c_expr
6454 c_parser_expression (c_parser *parser)
6457 expr = c_parser_expr_no_commas (parser, NULL);
6458 while (c_parser_next_token_is (parser, CPP_COMMA))
6462 location_t loc = c_parser_peek_token (parser)->location;
6463 location_t expr_loc;
6464 c_parser_consume_token (parser);
6465 expr_loc = c_parser_peek_token (parser)->location;
6466 lhsval = expr.value;
6467 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6468 lhsval = TREE_OPERAND (lhsval, 1);
6469 if (DECL_P (lhsval) || handled_component_p (lhsval))
6470 mark_exp_read (lhsval);
6471 next = c_parser_expr_no_commas (parser, NULL);
6472 next = default_function_array_conversion (expr_loc, next);
6473 expr.value = build_compound_expr (loc, expr.value, next.value);
6474 expr.original_code = COMPOUND_EXPR;
6475 expr.original_type = next.original_type;
6480 /* Parse an expression and convert functions or arrays to
6483 static struct c_expr
6484 c_parser_expression_conv (c_parser *parser)
6487 location_t loc = c_parser_peek_token (parser)->location;
6488 expr = c_parser_expression (parser);
6489 expr = default_function_array_conversion (loc, expr);
6493 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6494 functions and arrays to pointers. If FOLD_P, fold the expressions.
6497 assignment-expression
6498 nonempty-expr-list , assignment-expression
6501 static VEC(tree,gc) *
6502 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6503 VEC(tree,gc) **p_orig_types)
6506 VEC(tree,gc) *orig_types;
6508 location_t loc = c_parser_peek_token (parser)->location;
6510 ret = make_tree_vector ();
6511 if (p_orig_types == NULL)
6514 orig_types = make_tree_vector ();
6516 expr = c_parser_expr_no_commas (parser, NULL);
6518 expr = default_function_array_read_conversion (loc, expr);
6520 expr.value = c_fully_fold (expr.value, false, NULL);
6521 VEC_quick_push (tree, ret, expr.value);
6522 if (orig_types != NULL)
6523 VEC_quick_push (tree, orig_types, expr.original_type);
6524 while (c_parser_next_token_is (parser, CPP_COMMA))
6526 c_parser_consume_token (parser);
6527 loc = c_parser_peek_token (parser)->location;
6528 expr = c_parser_expr_no_commas (parser, NULL);
6530 expr = default_function_array_read_conversion (loc, expr);
6532 expr.value = c_fully_fold (expr.value, false, NULL);
6533 VEC_safe_push (tree, gc, ret, expr.value);
6534 if (orig_types != NULL)
6535 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6537 if (orig_types != NULL)
6538 *p_orig_types = orig_types;
6542 /* Parse Objective-C-specific constructs. */
6544 /* Parse an objc-class-definition.
6546 objc-class-definition:
6547 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6548 objc-class-instance-variables[opt] objc-methodprotolist @end
6549 @implementation identifier objc-superclass[opt]
6550 objc-class-instance-variables[opt]
6551 @interface identifier ( identifier ) objc-protocol-refs[opt]
6552 objc-methodprotolist @end
6553 @implementation identifier ( identifier )
6558 "@interface identifier (" must start "@interface identifier (
6559 identifier ) ...": objc-methodprotolist in the first production may
6560 not start with a parenthesized identifier as a declarator of a data
6561 definition with no declaration specifiers if the objc-superclass,
6562 objc-protocol-refs and objc-class-instance-variables are omitted. */
6565 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6570 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6572 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6577 c_parser_consume_token (parser);
6578 if (c_parser_next_token_is_not (parser, CPP_NAME))
6580 c_parser_error (parser, "expected identifier");
6583 id1 = c_parser_peek_token (parser)->value;
6584 c_parser_consume_token (parser);
6585 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6588 tree proto = NULL_TREE;
6589 c_parser_consume_token (parser);
6590 if (c_parser_next_token_is_not (parser, CPP_NAME))
6592 c_parser_error (parser, "expected identifier");
6593 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6596 id2 = c_parser_peek_token (parser)->value;
6597 c_parser_consume_token (parser);
6598 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6601 objc_start_category_implementation (id1, id2);
6604 if (c_parser_next_token_is (parser, CPP_LESS))
6605 proto = c_parser_objc_protocol_refs (parser);
6606 objc_start_category_interface (id1, id2, proto, attributes);
6607 c_parser_objc_methodprotolist (parser);
6608 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6609 objc_finish_interface ();
6612 if (c_parser_next_token_is (parser, CPP_COLON))
6614 c_parser_consume_token (parser);
6615 if (c_parser_next_token_is_not (parser, CPP_NAME))
6617 c_parser_error (parser, "expected identifier");
6620 superclass = c_parser_peek_token (parser)->value;
6621 c_parser_consume_token (parser);
6624 superclass = NULL_TREE;
6627 tree proto = NULL_TREE;
6628 if (c_parser_next_token_is (parser, CPP_LESS))
6629 proto = c_parser_objc_protocol_refs (parser);
6630 objc_start_class_interface (id1, superclass, proto, attributes);
6633 objc_start_class_implementation (id1, superclass);
6634 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6635 c_parser_objc_class_instance_variables (parser);
6638 objc_continue_interface ();
6639 c_parser_objc_methodprotolist (parser);
6640 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6641 objc_finish_interface ();
6645 objc_continue_implementation ();
6650 /* Parse objc-class-instance-variables.
6652 objc-class-instance-variables:
6653 { objc-instance-variable-decl-list[opt] }
6655 objc-instance-variable-decl-list:
6656 objc-visibility-spec
6657 objc-instance-variable-decl ;
6659 objc-instance-variable-decl-list objc-visibility-spec
6660 objc-instance-variable-decl-list objc-instance-variable-decl ;
6661 objc-instance-variable-decl-list ;
6663 objc-visibility-spec:
6668 objc-instance-variable-decl:
6673 c_parser_objc_class_instance_variables (c_parser *parser)
6675 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6676 c_parser_consume_token (parser);
6677 while (c_parser_next_token_is_not (parser, CPP_EOF))
6680 /* Parse any stray semicolon. */
6681 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6683 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6684 "extra semicolon in struct or union specified");
6685 c_parser_consume_token (parser);
6688 /* Stop if at the end of the instance variables. */
6689 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6691 c_parser_consume_token (parser);
6694 /* Parse any objc-visibility-spec. */
6695 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE))
6697 c_parser_consume_token (parser);
6698 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE);
6701 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED))
6703 c_parser_consume_token (parser);
6704 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED);
6707 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC))
6709 c_parser_consume_token (parser);
6710 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC);
6713 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE))
6715 c_parser_consume_token (parser);
6716 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE);
6719 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6721 c_parser_pragma (parser, pragma_external);
6725 /* Parse some comma-separated declarations. */
6726 decls = c_parser_struct_declaration (parser);
6728 /* Comma-separated instance variables are chained together in
6729 reverse order; add them one by one. */
6730 tree ivar = nreverse (decls);
6731 for (; ivar; ivar = DECL_CHAIN (ivar))
6732 objc_add_instance_variable (copy_node (ivar));
6734 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6738 /* Parse an objc-class-declaration.
6740 objc-class-declaration:
6741 @class identifier-list ;
6745 c_parser_objc_class_declaration (c_parser *parser)
6747 tree list = NULL_TREE;
6748 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS));
6749 c_parser_consume_token (parser);
6750 /* Any identifiers, including those declared as type names, are OK
6755 if (c_parser_next_token_is_not (parser, CPP_NAME))
6757 c_parser_error (parser, "expected identifier");
6760 id = c_parser_peek_token (parser)->value;
6761 list = chainon (list, build_tree_list (NULL_TREE, id));
6762 c_parser_consume_token (parser);
6763 if (c_parser_next_token_is (parser, CPP_COMMA))
6764 c_parser_consume_token (parser);
6768 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6769 objc_declare_class (list);
6772 /* Parse an objc-alias-declaration.
6774 objc-alias-declaration:
6775 @compatibility_alias identifier identifier ;
6779 c_parser_objc_alias_declaration (c_parser *parser)
6782 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6783 c_parser_consume_token (parser);
6784 if (c_parser_next_token_is_not (parser, CPP_NAME))
6786 c_parser_error (parser, "expected identifier");
6787 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6790 id1 = c_parser_peek_token (parser)->value;
6791 c_parser_consume_token (parser);
6792 if (c_parser_next_token_is_not (parser, CPP_NAME))
6794 c_parser_error (parser, "expected identifier");
6795 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6798 id2 = c_parser_peek_token (parser)->value;
6799 c_parser_consume_token (parser);
6800 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6801 objc_declare_alias (id1, id2);
6804 /* Parse an objc-protocol-definition.
6806 objc-protocol-definition:
6807 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6808 @protocol identifier-list ;
6810 "@protocol identifier ;" should be resolved as "@protocol
6811 identifier-list ;": objc-methodprotolist may not start with a
6812 semicolon in the first alternative if objc-protocol-refs are
6816 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6818 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6820 c_parser_consume_token (parser);
6821 if (c_parser_next_token_is_not (parser, CPP_NAME))
6823 c_parser_error (parser, "expected identifier");
6826 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6827 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6829 tree list = NULL_TREE;
6830 /* Any identifiers, including those declared as type names, are
6835 if (c_parser_next_token_is_not (parser, CPP_NAME))
6837 c_parser_error (parser, "expected identifier");
6840 id = c_parser_peek_token (parser)->value;
6841 list = chainon (list, build_tree_list (NULL_TREE, id));
6842 c_parser_consume_token (parser);
6843 if (c_parser_next_token_is (parser, CPP_COMMA))
6844 c_parser_consume_token (parser);
6848 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6849 objc_declare_protocols (list);
6853 tree id = c_parser_peek_token (parser)->value;
6854 tree proto = NULL_TREE;
6855 c_parser_consume_token (parser);
6856 if (c_parser_next_token_is (parser, CPP_LESS))
6857 proto = c_parser_objc_protocol_refs (parser);
6858 parser->objc_pq_context = true;
6859 objc_start_protocol (id, proto, attributes);
6860 c_parser_objc_methodprotolist (parser);
6861 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6862 parser->objc_pq_context = false;
6863 objc_finish_interface ();
6867 /* Parse an objc-method-type.
6874 static enum tree_code
6875 c_parser_objc_method_type (c_parser *parser)
6877 switch (c_parser_peek_token (parser)->type)
6880 c_parser_consume_token (parser);
6883 c_parser_consume_token (parser);
6890 /* Parse an objc-method-definition.
6892 objc-method-definition:
6893 objc-method-type objc-method-decl ;[opt] compound-statement
6897 c_parser_objc_method_definition (c_parser *parser)
6899 enum tree_code type = c_parser_objc_method_type (parser);
6900 tree decl, attributes = NULL_TREE;
6901 objc_set_method_type (type);
6902 parser->objc_pq_context = true;
6903 decl = c_parser_objc_method_decl (parser, &attributes);
6904 if (decl == error_mark_node)
6905 return; /* Bail here. */
6907 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6909 c_parser_consume_token (parser);
6910 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6911 "extra semicolon in method definition specified");
6914 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6916 c_parser_error (parser, "expected %<{%>");
6920 parser->objc_pq_context = false;
6921 if (objc_start_method_definition (decl, attributes))
6923 add_stmt (c_parser_compound_statement (parser));
6924 objc_finish_method_definition (current_function_decl);
6928 /* This code is executed when we find a method definition
6929 outside of an @implementation context (or invalid for other
6930 reasons). Parse the method (to keep going) but do not emit
6933 c_parser_compound_statement (parser);
6937 /* Parse an objc-methodprotolist.
6939 objc-methodprotolist:
6941 objc-methodprotolist objc-methodproto
6942 objc-methodprotolist declaration
6943 objc-methodprotolist ;
6947 The declaration is a data definition, which may be missing
6948 declaration specifiers under the same rules and diagnostics as
6949 other data definitions outside functions, and the stray semicolon
6950 is diagnosed the same way as a stray semicolon outside a
6954 c_parser_objc_methodprotolist (c_parser *parser)
6958 /* The list is terminated by @end. */
6959 switch (c_parser_peek_token (parser)->type)
6962 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6963 "ISO C does not allow extra %<;%> outside of a function");
6964 c_parser_consume_token (parser);
6968 c_parser_objc_methodproto (parser);
6971 c_parser_pragma (parser, pragma_external);
6976 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6978 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY))
6979 c_parser_objc_at_property (parser);
6980 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL))
6982 objc_set_method_opt (true);
6983 c_parser_consume_token (parser);
6985 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED))
6987 objc_set_method_opt (false);
6988 c_parser_consume_token (parser);
6991 c_parser_declaration_or_fndef (parser, false, false, true,
6998 /* Parse an objc-methodproto.
7001 objc-method-type objc-method-decl ;
7005 c_parser_objc_methodproto (c_parser *parser)
7007 enum tree_code type = c_parser_objc_method_type (parser);
7008 tree decl, attributes = NULL_TREE;
7009 objc_set_method_type (type);
7010 /* Remember protocol qualifiers in prototypes. */
7011 parser->objc_pq_context = true;
7012 decl = c_parser_objc_method_decl (parser, &attributes);
7013 /* Forget protocol qualifiers now. */
7014 parser->objc_pq_context = false;
7016 /* Do not allow the presence of attributes to hide an erroneous
7017 method implementation in the interface section. */
7018 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
7020 c_parser_error (parser, "expected %<;%>");
7024 if (decl != error_mark_node)
7025 objc_add_method_declaration (decl, attributes);
7027 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7030 /* If we are at a position that method attributes may be present, check that
7031 there are not any parsed already (a syntax error) and then collect any
7032 specified at the current location. Finally, if new attributes were present,
7033 check that the next token is legal ( ';' for decls and '{' for defs). */
7036 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
7041 c_parser_error (parser,
7042 "method attributes must be specified at the end only");
7043 *attributes = NULL_TREE;
7047 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7048 *attributes = c_parser_attributes (parser);
7050 /* If there were no attributes here, just report any earlier error. */
7051 if (*attributes == NULL_TREE || bad)
7054 /* If the attributes are followed by a ; or {, then just report any earlier
7056 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
7057 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
7060 /* We've got attributes, but not at the end. */
7061 c_parser_error (parser,
7062 "expected %<;%> or %<{%> after method attribute definition");
7066 /* Parse an objc-method-decl.
7069 ( objc-type-name ) objc-selector
7071 ( objc-type-name ) objc-keyword-selector objc-optparmlist
7072 objc-keyword-selector objc-optparmlist
7075 objc-keyword-selector:
7077 objc-keyword-selector objc-keyword-decl
7080 objc-selector : ( objc-type-name ) identifier
7081 objc-selector : identifier
7082 : ( objc-type-name ) identifier
7086 objc-optparms objc-optellipsis
7090 objc-opt-parms , parameter-declaration
7098 c_parser_objc_method_decl (c_parser *parser, tree *attributes)
7100 tree type = NULL_TREE;
7102 tree parms = NULL_TREE;
7103 bool ellipsis = false;
7104 bool attr_err = false;
7106 *attributes = NULL_TREE;
7107 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7109 c_parser_consume_token (parser);
7110 type = c_parser_objc_type_name (parser);
7111 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7113 sel = c_parser_objc_selector (parser);
7114 /* If there is no selector, or a colon follows, we have an
7115 objc-keyword-selector. If there is a selector, and a colon does
7116 not follow, that selector ends the objc-method-decl. */
7117 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
7120 tree list = NULL_TREE;
7123 tree atype = NULL_TREE, id, keyworddecl;
7124 tree param_attr = NULL_TREE;
7125 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7127 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7129 c_parser_consume_token (parser);
7130 atype = c_parser_objc_type_name (parser);
7131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7134 /* New ObjC allows attributes on method parameters. */
7135 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
7136 param_attr = c_parser_attributes (parser);
7137 if (c_parser_next_token_is_not (parser, CPP_NAME))
7139 c_parser_error (parser, "expected identifier");
7140 return error_mark_node;
7142 id = c_parser_peek_token (parser)->value;
7143 c_parser_consume_token (parser);
7144 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
7145 list = chainon (list, keyworddecl);
7146 tsel = c_parser_objc_selector (parser);
7147 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
7151 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7153 /* Parse the optional parameter list. Optional Objective-C
7154 method parameters follow the C syntax, and may include '...'
7155 to denote a variable number of arguments. */
7156 parms = make_node (TREE_LIST);
7157 while (c_parser_next_token_is (parser, CPP_COMMA))
7159 struct c_parm *parm;
7160 c_parser_consume_token (parser);
7161 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
7164 c_parser_consume_token (parser);
7165 attr_err |= c_parser_objc_maybe_method_attributes
7166 (parser, attributes) ;
7169 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7172 parms = chainon (parms,
7173 build_tree_list (NULL_TREE, grokparm (parm)));
7178 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
7182 c_parser_error (parser, "objective-c method declaration is expected");
7183 return error_mark_node;
7187 return error_mark_node;
7189 return objc_build_method_signature (type, sel, parms, ellipsis);
7192 /* Parse an objc-type-name.
7195 objc-type-qualifiers[opt] type-name
7196 objc-type-qualifiers[opt]
7198 objc-type-qualifiers:
7200 objc-type-qualifiers objc-type-qualifier
7202 objc-type-qualifier: one of
7203 in out inout bycopy byref oneway
7207 c_parser_objc_type_name (c_parser *parser)
7209 tree quals = NULL_TREE;
7210 struct c_type_name *type_name = NULL;
7211 tree type = NULL_TREE;
7214 c_token *token = c_parser_peek_token (parser);
7215 if (token->type == CPP_KEYWORD
7216 && (token->keyword == RID_IN
7217 || token->keyword == RID_OUT
7218 || token->keyword == RID_INOUT
7219 || token->keyword == RID_BYCOPY
7220 || token->keyword == RID_BYREF
7221 || token->keyword == RID_ONEWAY))
7223 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
7224 c_parser_consume_token (parser);
7229 if (c_parser_next_token_starts_typename (parser))
7230 type_name = c_parser_type_name (parser);
7232 type = groktypename (type_name, NULL, NULL);
7233 return build_tree_list (quals, type);
7236 /* Parse objc-protocol-refs.
7243 c_parser_objc_protocol_refs (c_parser *parser)
7245 tree list = NULL_TREE;
7246 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7247 c_parser_consume_token (parser);
7248 /* Any identifiers, including those declared as type names, are OK
7253 if (c_parser_next_token_is_not (parser, CPP_NAME))
7255 c_parser_error (parser, "expected identifier");
7258 id = c_parser_peek_token (parser)->value;
7259 list = chainon (list, build_tree_list (NULL_TREE, id));
7260 c_parser_consume_token (parser);
7261 if (c_parser_next_token_is (parser, CPP_COMMA))
7262 c_parser_consume_token (parser);
7266 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7270 /* Parse an objc-try-catch-statement.
7272 objc-try-catch-statement:
7273 @try compound-statement objc-catch-list[opt]
7274 @try compound-statement objc-catch-list[opt] @finally compound-statement
7277 @catch ( parameter-declaration ) compound-statement
7278 objc-catch-list @catch ( parameter-declaration ) compound-statement
7282 c_parser_objc_try_catch_statement (c_parser *parser)
7286 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
7287 c_parser_consume_token (parser);
7288 loc = c_parser_peek_token (parser)->location;
7289 stmt = c_parser_compound_statement (parser);
7290 objc_begin_try_stmt (loc, stmt);
7291 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH))
7293 struct c_parm *parm;
7294 c_parser_consume_token (parser);
7295 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7297 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7300 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7303 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7304 objc_begin_catch_clause (grokparm (parm));
7305 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7306 c_parser_compound_statement_nostart (parser);
7307 objc_finish_catch_clause ();
7309 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7313 c_parser_consume_token (parser);
7314 finloc = c_parser_peek_token (parser)->location;
7315 finstmt = c_parser_compound_statement (parser);
7316 objc_build_finally_clause (finloc, finstmt);
7318 objc_finish_try_stmt ();
7321 /* Parse an objc-synchronized-statement.
7323 objc-synchronized-statement:
7324 @synchronized ( expression ) compound-statement
7328 c_parser_objc_synchronized_statement (c_parser *parser)
7332 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7333 c_parser_consume_token (parser);
7334 loc = c_parser_peek_token (parser)->location;
7335 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7337 expr = c_parser_expression (parser).value;
7338 expr = c_fully_fold (expr, false, NULL);
7339 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7342 expr = error_mark_node;
7343 stmt = c_parser_compound_statement (parser);
7344 objc_build_synchronized (loc, expr, stmt);
7347 /* Parse an objc-selector; return NULL_TREE without an error if the
7348 next token is not an objc-selector.
7353 enum struct union if else while do for switch case default
7354 break continue return goto asm sizeof typeof __alignof
7355 unsigned long const short volatile signed restrict _Complex
7356 in out inout bycopy byref oneway int char float double void _Bool
7358 ??? Why this selection of keywords but not, for example, storage
7359 class specifiers? */
7362 c_parser_objc_selector (c_parser *parser)
7364 c_token *token = c_parser_peek_token (parser);
7365 tree value = token->value;
7366 if (token->type == CPP_NAME)
7368 c_parser_consume_token (parser);
7371 if (token->type != CPP_KEYWORD)
7373 switch (token->keyword)
7415 c_parser_consume_token (parser);
7422 /* Parse an objc-selector-arg.
7426 objc-keywordname-list
7428 objc-keywordname-list:
7430 objc-keywordname-list objc-keywordname
7438 c_parser_objc_selector_arg (c_parser *parser)
7440 tree sel = c_parser_objc_selector (parser);
7441 tree list = NULL_TREE;
7442 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7446 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7448 list = chainon (list, build_tree_list (sel, NULL_TREE));
7449 sel = c_parser_objc_selector (parser);
7450 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7456 /* Parse an objc-receiver.
7465 c_parser_objc_receiver (c_parser *parser)
7467 if (c_parser_peek_token (parser)->type == CPP_NAME
7468 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7469 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7471 tree id = c_parser_peek_token (parser)->value;
7472 c_parser_consume_token (parser);
7473 return objc_get_class_reference (id);
7475 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7478 /* Parse objc-message-args.
7482 objc-keywordarg-list
7484 objc-keywordarg-list:
7486 objc-keywordarg-list objc-keywordarg
7489 objc-selector : objc-keywordexpr
7494 c_parser_objc_message_args (c_parser *parser)
7496 tree sel = c_parser_objc_selector (parser);
7497 tree list = NULL_TREE;
7498 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7503 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7504 return error_mark_node;
7505 keywordexpr = c_parser_objc_keywordexpr (parser);
7506 list = chainon (list, build_tree_list (sel, keywordexpr));
7507 sel = c_parser_objc_selector (parser);
7508 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7514 /* Parse an objc-keywordexpr.
7521 c_parser_objc_keywordexpr (c_parser *parser)
7524 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7525 if (VEC_length (tree, expr_list) == 1)
7527 /* Just return the expression, remove a level of
7529 ret = VEC_index (tree, expr_list, 0);
7533 /* We have a comma expression, we will collapse later. */
7534 ret = build_tree_list_vec (expr_list);
7536 release_tree_vector (expr_list);
7540 /* A check, needed in several places, that ObjC interface, implementation or
7541 method definitions are not prefixed by incorrect items. */
7543 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7544 struct c_declspecs *specs)
7546 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7548 c_parser_error (parser,
7549 "no type or storage class may be specified here,");
7550 c_parser_skip_to_end_of_block_or_statement (parser);
7556 /* ObjC @property. */
7558 /* Parse a comma-separated list of property attributes. */
7561 c_parser_objc_property_attrlist (c_parser *parser)
7564 /* Initialize to an empty list. */
7565 objc_set_property_attr (c_parser_peek_token (parser)->location,
7566 OBJC_PATTR_INIT, NULL_TREE);
7568 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
7572 c_parser_consume_token (parser);
7574 /* Property attribute keywords are valid now. */
7575 parser->objc_property_attr_context = true;
7576 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)
7577 && c_parser_next_token_is_not (parser, CPP_EOF)
7582 if (c_parser_peek_token (parser)->type != CPP_KEYWORD)
7584 c_parser_error (parser, "expected a property attribute");
7585 c_parser_consume_token (parser);
7589 keywd = c_parser_peek_token (parser)->keyword;
7590 /* Initially, make diagnostics point to the attribute. */
7591 loc = c_parser_peek_token (parser)->location;
7595 objc_property_attribute_kind pkind;
7597 objc_set_property_attr (loc, OBJC_PATTR_READONLY, NULL_TREE);
7602 c_parser_consume_token (parser);
7603 if (c_parser_next_token_is_not (parser, CPP_EQ))
7605 c_parser_error (parser,
7606 "getter/setter/ivar attribute must be followed by %<=%>");
7610 c_parser_consume_token (parser); /* eat the = */
7611 if (c_parser_next_token_is_not (parser, CPP_NAME))
7613 c_parser_error (parser, "expected an identifier");
7617 ident = c_parser_peek_token (parser)->value;
7618 if (keywd == RID_SETTER)
7620 pkind = OBJC_PATTR_SETTER;
7621 /* Eat the identifier, and look for the following : */
7622 c_parser_consume_token (parser);
7623 if (c_parser_next_token_is_not (parser, CPP_COLON))
7625 c_parser_error (parser,
7626 "setter name must be followed by %<:%>");
7630 else if (keywd == RID_GETTER)
7631 pkind = OBJC_PATTR_GETTER;
7633 pkind = OBJC_PATTR_IVAR;
7635 objc_set_property_attr (loc, pkind, ident);
7638 objc_set_property_attr (loc, OBJC_PATTR_COPIES, NULL_TREE);
7641 c_parser_error (parser, "unknown property attribute");
7645 /* Eat the attribute,identifier or colon that's been used. */
7646 c_parser_consume_token (parser);
7650 if (c_parser_next_token_is (parser, CPP_COMMA))
7651 c_parser_consume_token (parser);
7652 else if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
7653 warning_at (c_parser_peek_token (parser)->location, 0,
7654 "property attributes should be separated by a %<,%>");
7656 parser->objc_property_attr_context = false;
7657 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7660 /* Parse property attributes and then the definition. */
7663 c_parser_objc_at_property (c_parser *parser)
7666 /* We should only arrive here with the property keyword. */
7667 c_parser_require_keyword (parser, RID_AT_PROPERTY, "expected %<@property%>");
7669 /* Process the optional attribute list... */
7670 c_parser_objc_property_attrlist (parser) ;
7671 /* ... and the property var decls. */
7672 props = c_parser_struct_declaration (parser);
7674 /* Comma-separated properties are chained together in
7675 reverse order; add them one by one. */
7676 props = nreverse (props);
7678 for (; props; props = TREE_CHAIN (props))
7679 objc_add_property_variable (copy_node (props));
7681 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7685 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7686 should be considered, statements. ALLOW_STMT is true if we're within
7687 the context of a function and such pragmas are to be allowed. Returns
7688 true if we actually parsed such a pragma. */
7691 c_parser_pragma (c_parser *parser, enum pragma_context context)
7695 id = c_parser_peek_token (parser)->pragma_kind;
7696 gcc_assert (id != PRAGMA_NONE);
7700 case PRAGMA_OMP_BARRIER:
7701 if (context != pragma_compound)
7703 if (context == pragma_stmt)
7704 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7705 "used in compound statements");
7708 c_parser_omp_barrier (parser);
7711 case PRAGMA_OMP_FLUSH:
7712 if (context != pragma_compound)
7714 if (context == pragma_stmt)
7715 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7716 "used in compound statements");
7719 c_parser_omp_flush (parser);
7722 case PRAGMA_OMP_TASKWAIT:
7723 if (context != pragma_compound)
7725 if (context == pragma_stmt)
7726 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7727 "used in compound statements");
7730 c_parser_omp_taskwait (parser);
7733 case PRAGMA_OMP_THREADPRIVATE:
7734 c_parser_omp_threadprivate (parser);
7737 case PRAGMA_OMP_SECTION:
7738 error_at (c_parser_peek_token (parser)->location,
7739 "%<#pragma omp section%> may only be used in "
7740 "%<#pragma omp sections%> construct");
7741 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7744 case PRAGMA_GCC_PCH_PREPROCESS:
7745 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7746 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7750 if (id < PRAGMA_FIRST_EXTERNAL)
7752 if (context == pragma_external)
7755 c_parser_error (parser, "expected declaration specifiers");
7756 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7759 c_parser_omp_construct (parser);
7765 c_parser_consume_pragma (parser);
7766 c_invoke_pragma_handler (id);
7768 /* Skip to EOL, but suppress any error message. Those will have been
7769 generated by the handler routine through calling error, as opposed
7770 to calling c_parser_error. */
7771 parser->error = true;
7772 c_parser_skip_to_pragma_eol (parser);
7777 /* The interface the pragma parsers have to the lexer. */
7780 pragma_lex (tree *value)
7782 c_token *tok = c_parser_peek_token (the_parser);
7783 enum cpp_ttype ret = tok->type;
7785 *value = tok->value;
7786 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7790 if (ret == CPP_KEYWORD)
7792 c_parser_consume_token (the_parser);
7799 c_parser_pragma_pch_preprocess (c_parser *parser)
7803 c_parser_consume_pragma (parser);
7804 if (c_parser_next_token_is (parser, CPP_STRING))
7806 name = c_parser_peek_token (parser)->value;
7807 c_parser_consume_token (parser);
7810 c_parser_error (parser, "expected string literal");
7811 c_parser_skip_to_pragma_eol (parser);
7814 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7817 /* OpenMP 2.5 parsing routines. */
7819 /* Returns name of the next clause.
7820 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7821 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7822 returned and the token is consumed. */
7824 static pragma_omp_clause
7825 c_parser_omp_clause_name (c_parser *parser)
7827 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7829 if (c_parser_next_token_is_keyword (parser, RID_IF))
7830 result = PRAGMA_OMP_CLAUSE_IF;
7831 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7832 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7833 else if (c_parser_next_token_is (parser, CPP_NAME))
7835 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7840 if (!strcmp ("collapse", p))
7841 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7842 else if (!strcmp ("copyin", p))
7843 result = PRAGMA_OMP_CLAUSE_COPYIN;
7844 else if (!strcmp ("copyprivate", p))
7845 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7848 if (!strcmp ("firstprivate", p))
7849 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7852 if (!strcmp ("lastprivate", p))
7853 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7856 if (!strcmp ("nowait", p))
7857 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7858 else if (!strcmp ("num_threads", p))
7859 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7862 if (!strcmp ("ordered", p))
7863 result = PRAGMA_OMP_CLAUSE_ORDERED;
7866 if (!strcmp ("private", p))
7867 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7870 if (!strcmp ("reduction", p))
7871 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7874 if (!strcmp ("schedule", p))
7875 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7876 else if (!strcmp ("shared", p))
7877 result = PRAGMA_OMP_CLAUSE_SHARED;
7880 if (!strcmp ("untied", p))
7881 result = PRAGMA_OMP_CLAUSE_UNTIED;
7886 if (result != PRAGMA_OMP_CLAUSE_NONE)
7887 c_parser_consume_token (parser);
7892 /* Validate that a clause of the given type does not already exist. */
7895 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7900 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7901 if (OMP_CLAUSE_CODE (c) == code)
7903 location_t loc = OMP_CLAUSE_LOCATION (c);
7904 error_at (loc, "too many %qs clauses", name);
7912 variable-list , identifier
7914 If KIND is nonzero, create the appropriate node and install the
7915 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7916 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7918 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7919 return the list created. */
7922 c_parser_omp_variable_list (c_parser *parser,
7923 location_t clause_loc,
7924 enum omp_clause_code kind,
7927 if (c_parser_next_token_is_not (parser, CPP_NAME)
7928 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7929 c_parser_error (parser, "expected identifier");
7931 while (c_parser_next_token_is (parser, CPP_NAME)
7932 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7934 tree t = lookup_name (c_parser_peek_token (parser)->value);
7937 undeclared_variable (c_parser_peek_token (parser)->location,
7938 c_parser_peek_token (parser)->value);
7939 else if (t == error_mark_node)
7943 tree u = build_omp_clause (clause_loc, kind);
7944 OMP_CLAUSE_DECL (u) = t;
7945 OMP_CLAUSE_CHAIN (u) = list;
7949 list = tree_cons (t, NULL_TREE, list);
7951 c_parser_consume_token (parser);
7953 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7956 c_parser_consume_token (parser);
7962 /* Similarly, but expect leading and trailing parenthesis. This is a very
7963 common case for omp clauses. */
7966 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7969 /* The clauses location. */
7970 location_t loc = c_parser_peek_token (parser)->location;
7972 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7974 list = c_parser_omp_variable_list (parser, loc, kind, list);
7975 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7981 collapse ( constant-expression ) */
7984 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7986 tree c, num = error_mark_node;
7990 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7992 loc = c_parser_peek_token (parser)->location;
7993 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7995 num = c_parser_expr_no_commas (parser, NULL).value;
7996 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7998 if (num == error_mark_node)
8000 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
8001 || !host_integerp (num, 0)
8002 || (n = tree_low_cst (num, 0)) <= 0
8006 "collapse argument needs positive constant integer expression");
8009 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
8010 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
8011 OMP_CLAUSE_CHAIN (c) = list;
8016 copyin ( variable-list ) */
8019 c_parser_omp_clause_copyin (c_parser *parser, tree list)
8021 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
8025 copyprivate ( variable-list ) */
8028 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
8030 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
8034 default ( shared | none ) */
8037 c_parser_omp_clause_default (c_parser *parser, tree list)
8039 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
8040 location_t loc = c_parser_peek_token (parser)->location;
8043 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8045 if (c_parser_next_token_is (parser, CPP_NAME))
8047 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8052 if (strcmp ("none", p) != 0)
8054 kind = OMP_CLAUSE_DEFAULT_NONE;
8058 if (strcmp ("shared", p) != 0)
8060 kind = OMP_CLAUSE_DEFAULT_SHARED;
8067 c_parser_consume_token (parser);
8072 c_parser_error (parser, "expected %<none%> or %<shared%>");
8074 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8076 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
8079 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
8080 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
8081 OMP_CLAUSE_CHAIN (c) = list;
8082 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
8088 firstprivate ( variable-list ) */
8091 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
8093 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
8097 if ( expression ) */
8100 c_parser_omp_clause_if (c_parser *parser, tree list)
8102 location_t loc = c_parser_peek_token (parser)->location;
8103 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8105 tree t = c_parser_paren_condition (parser);
8108 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
8110 c = build_omp_clause (loc, OMP_CLAUSE_IF);
8111 OMP_CLAUSE_IF_EXPR (c) = t;
8112 OMP_CLAUSE_CHAIN (c) = list;
8116 c_parser_error (parser, "expected %<(%>");
8122 lastprivate ( variable-list ) */
8125 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
8127 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
8134 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8137 location_t loc = c_parser_peek_token (parser)->location;
8139 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
8141 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
8142 OMP_CLAUSE_CHAIN (c) = list;
8147 num_threads ( expression ) */
8150 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
8152 location_t num_threads_loc = c_parser_peek_token (parser)->location;
8153 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8155 location_t expr_loc = c_parser_peek_token (parser)->location;
8156 tree c, t = c_parser_expression (parser).value;
8157 t = c_fully_fold (t, false, NULL);
8159 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8161 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
8163 c_parser_error (parser, "expected integer expression");
8167 /* Attempt to statically determine when the number isn't positive. */
8168 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
8169 build_int_cst (TREE_TYPE (t), 0));
8170 if (CAN_HAVE_LOCATION_P (c))
8171 SET_EXPR_LOCATION (c, expr_loc);
8172 if (c == boolean_true_node)
8174 warning_at (expr_loc, 0,
8175 "%<num_threads%> value must be positive");
8176 t = integer_one_node;
8179 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
8181 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
8182 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
8183 OMP_CLAUSE_CHAIN (c) = list;
8194 c_parser_omp_clause_ordered (c_parser *parser, tree list)
8198 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
8200 c = build_omp_clause (c_parser_peek_token (parser)->location,
8201 OMP_CLAUSE_ORDERED);
8202 OMP_CLAUSE_CHAIN (c) = list;
8208 private ( variable-list ) */
8211 c_parser_omp_clause_private (c_parser *parser, tree list)
8213 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
8217 reduction ( reduction-operator : variable-list )
8220 One of: + * - & ^ | && || */
8223 c_parser_omp_clause_reduction (c_parser *parser, tree list)
8225 location_t clause_loc = c_parser_peek_token (parser)->location;
8226 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8228 enum tree_code code;
8230 switch (c_parser_peek_token (parser)->type)
8242 code = BIT_AND_EXPR;
8245 code = BIT_XOR_EXPR;
8248 code = BIT_IOR_EXPR;
8251 code = TRUTH_ANDIF_EXPR;
8254 code = TRUTH_ORIF_EXPR;
8257 c_parser_error (parser,
8258 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
8259 "%<^%>, %<|%>, %<&&%>, or %<||%>");
8260 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8263 c_parser_consume_token (parser);
8264 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
8268 nl = c_parser_omp_variable_list (parser, clause_loc,
8269 OMP_CLAUSE_REDUCTION, list);
8270 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
8271 OMP_CLAUSE_REDUCTION_CODE (c) = code;
8275 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8281 schedule ( schedule-kind )
8282 schedule ( schedule-kind , expression )
8285 static | dynamic | guided | runtime | auto
8289 c_parser_omp_clause_schedule (c_parser *parser, tree list)
8292 location_t loc = c_parser_peek_token (parser)->location;
8294 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8297 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
8299 if (c_parser_next_token_is (parser, CPP_NAME))
8301 tree kind = c_parser_peek_token (parser)->value;
8302 const char *p = IDENTIFIER_POINTER (kind);
8307 if (strcmp ("dynamic", p) != 0)
8309 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
8313 if (strcmp ("guided", p) != 0)
8315 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
8319 if (strcmp ("runtime", p) != 0)
8321 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
8328 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
8329 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
8330 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
8331 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
8335 c_parser_consume_token (parser);
8336 if (c_parser_next_token_is (parser, CPP_COMMA))
8339 c_parser_consume_token (parser);
8341 here = c_parser_peek_token (parser)->location;
8342 t = c_parser_expr_no_commas (parser, NULL).value;
8343 t = c_fully_fold (t, false, NULL);
8345 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
8346 error_at (here, "schedule %<runtime%> does not take "
8347 "a %<chunk_size%> parameter");
8348 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
8350 "schedule %<auto%> does not take "
8351 "a %<chunk_size%> parameter");
8352 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
8353 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8355 c_parser_error (parser, "expected integer expression");
8357 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8361 "expected %<,%> or %<)%>");
8363 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8364 OMP_CLAUSE_CHAIN (c) = list;
8368 c_parser_error (parser, "invalid schedule kind");
8369 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8374 shared ( variable-list ) */
8377 c_parser_omp_clause_shared (c_parser *parser, tree list)
8379 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8386 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8390 /* FIXME: Should we allow duplicates? */
8391 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8393 c = build_omp_clause (c_parser_peek_token (parser)->location,
8395 OMP_CLAUSE_CHAIN (c) = list;
8400 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8401 is a bitmask in MASK. Return the list of clauses found; the result
8402 of clause default goes in *pdefault. */
8405 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8408 tree clauses = NULL;
8411 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8414 pragma_omp_clause c_kind;
8416 tree prev = clauses;
8418 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8419 c_parser_consume_token (parser);
8422 here = c_parser_peek_token (parser)->location;
8423 c_kind = c_parser_omp_clause_name (parser);
8427 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8428 clauses = c_parser_omp_clause_collapse (parser, clauses);
8429 c_name = "collapse";
8431 case PRAGMA_OMP_CLAUSE_COPYIN:
8432 clauses = c_parser_omp_clause_copyin (parser, clauses);
8435 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8436 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8437 c_name = "copyprivate";
8439 case PRAGMA_OMP_CLAUSE_DEFAULT:
8440 clauses = c_parser_omp_clause_default (parser, clauses);
8443 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8444 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8445 c_name = "firstprivate";
8447 case PRAGMA_OMP_CLAUSE_IF:
8448 clauses = c_parser_omp_clause_if (parser, clauses);
8451 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8452 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8453 c_name = "lastprivate";
8455 case PRAGMA_OMP_CLAUSE_NOWAIT:
8456 clauses = c_parser_omp_clause_nowait (parser, clauses);
8459 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8460 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8461 c_name = "num_threads";
8463 case PRAGMA_OMP_CLAUSE_ORDERED:
8464 clauses = c_parser_omp_clause_ordered (parser, clauses);
8467 case PRAGMA_OMP_CLAUSE_PRIVATE:
8468 clauses = c_parser_omp_clause_private (parser, clauses);
8471 case PRAGMA_OMP_CLAUSE_REDUCTION:
8472 clauses = c_parser_omp_clause_reduction (parser, clauses);
8473 c_name = "reduction";
8475 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8476 clauses = c_parser_omp_clause_schedule (parser, clauses);
8477 c_name = "schedule";
8479 case PRAGMA_OMP_CLAUSE_SHARED:
8480 clauses = c_parser_omp_clause_shared (parser, clauses);
8483 case PRAGMA_OMP_CLAUSE_UNTIED:
8484 clauses = c_parser_omp_clause_untied (parser, clauses);
8488 c_parser_error (parser, "expected %<#pragma omp%> clause");
8492 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8494 /* Remove the invalid clause(s) from the list to avoid
8495 confusing the rest of the compiler. */
8497 error_at (here, "%qs is not valid for %qs", c_name, where);
8502 c_parser_skip_to_pragma_eol (parser);
8504 return c_finish_omp_clauses (clauses);
8511 In practice, we're also interested in adding the statement to an
8512 outer node. So it is convenient if we work around the fact that
8513 c_parser_statement calls add_stmt. */
8516 c_parser_omp_structured_block (c_parser *parser)
8518 tree stmt = push_stmt_list ();
8519 c_parser_statement (parser);
8520 return pop_stmt_list (stmt);
8524 # pragma omp atomic new-line
8528 x binop= expr | x++ | ++x | x-- | --x
8530 +, *, -, /, &, ^, |, <<, >>
8532 where x is an lvalue expression with scalar type.
8534 LOC is the location of the #pragma token. */
8537 c_parser_omp_atomic (location_t loc, c_parser *parser)
8541 enum tree_code code;
8542 struct c_expr rhs_expr;
8544 c_parser_skip_to_pragma_eol (parser);
8546 lhs = c_parser_unary_expression (parser).value;
8547 lhs = c_fully_fold (lhs, false, NULL);
8548 switch (TREE_CODE (lhs))
8552 c_parser_skip_to_end_of_block_or_statement (parser);
8555 case PREINCREMENT_EXPR:
8556 case POSTINCREMENT_EXPR:
8557 lhs = TREE_OPERAND (lhs, 0);
8559 rhs = integer_one_node;
8562 case PREDECREMENT_EXPR:
8563 case POSTDECREMENT_EXPR:
8564 lhs = TREE_OPERAND (lhs, 0);
8566 rhs = integer_one_node;
8570 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8571 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8572 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8573 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8574 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8575 (TREE_OPERAND (lhs, 1), 0), 0)))
8577 /* Undo effects of boolean_increment for post {in,de}crement. */
8578 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8581 if (TREE_CODE (lhs) == MODIFY_EXPR
8582 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8584 /* Undo effects of boolean_increment. */
8585 if (integer_onep (TREE_OPERAND (lhs, 1)))
8587 /* This is pre or post increment. */
8588 rhs = TREE_OPERAND (lhs, 1);
8589 lhs = TREE_OPERAND (lhs, 0);
8593 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8594 && TREE_OPERAND (lhs, 0)
8595 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8597 /* This is pre or post decrement. */
8598 rhs = TREE_OPERAND (lhs, 1);
8599 lhs = TREE_OPERAND (lhs, 0);
8606 switch (c_parser_peek_token (parser)->type)
8612 code = TRUNC_DIV_EXPR;
8627 code = BIT_AND_EXPR;
8630 code = BIT_IOR_EXPR;
8633 code = BIT_XOR_EXPR;
8636 c_parser_error (parser,
8637 "invalid operator for %<#pragma omp atomic%>");
8641 c_parser_consume_token (parser);
8643 location_t rhs_loc = c_parser_peek_token (parser)->location;
8644 rhs_expr = c_parser_expression (parser);
8645 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8647 rhs = rhs_expr.value;
8648 rhs = c_fully_fold (rhs, false, NULL);
8651 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8652 if (stmt != error_mark_node)
8654 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8659 # pragma omp barrier new-line
8663 c_parser_omp_barrier (c_parser *parser)
8665 location_t loc = c_parser_peek_token (parser)->location;
8666 c_parser_consume_pragma (parser);
8667 c_parser_skip_to_pragma_eol (parser);
8669 c_finish_omp_barrier (loc);
8673 # pragma omp critical [(name)] new-line
8676 LOC is the location of the #pragma itself. */
8679 c_parser_omp_critical (location_t loc, c_parser *parser)
8681 tree stmt, name = NULL;
8683 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8685 c_parser_consume_token (parser);
8686 if (c_parser_next_token_is (parser, CPP_NAME))
8688 name = c_parser_peek_token (parser)->value;
8689 c_parser_consume_token (parser);
8690 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8693 c_parser_error (parser, "expected identifier");
8695 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8696 c_parser_error (parser, "expected %<(%> or end of line");
8697 c_parser_skip_to_pragma_eol (parser);
8699 stmt = c_parser_omp_structured_block (parser);
8700 return c_finish_omp_critical (loc, stmt, name);
8704 # pragma omp flush flush-vars[opt] new-line
8707 ( variable-list ) */
8710 c_parser_omp_flush (c_parser *parser)
8712 location_t loc = c_parser_peek_token (parser)->location;
8713 c_parser_consume_pragma (parser);
8714 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8715 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8716 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8717 c_parser_error (parser, "expected %<(%> or end of line");
8718 c_parser_skip_to_pragma_eol (parser);
8720 c_finish_omp_flush (loc);
8723 /* Parse the restricted form of the for statement allowed by OpenMP.
8724 The real trick here is to determine the loop control variable early
8725 so that we can push a new decl if necessary to make it private.
8726 LOC is the location of the OMP in "#pragma omp". */
8729 c_parser_omp_for_loop (location_t loc,
8730 c_parser *parser, tree clauses, tree *par_clauses)
8732 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8733 tree declv, condv, incrv, initv, ret = NULL;
8734 bool fail = false, open_brace_parsed = false;
8735 int i, collapse = 1, nbraces = 0;
8737 VEC(tree,gc) *for_block = make_tree_vector ();
8739 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8740 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8741 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8743 gcc_assert (collapse >= 1);
8745 declv = make_tree_vec (collapse);
8746 initv = make_tree_vec (collapse);
8747 condv = make_tree_vec (collapse);
8748 incrv = make_tree_vec (collapse);
8750 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8752 c_parser_error (parser, "for statement expected");
8755 for_loc = c_parser_peek_token (parser)->location;
8756 c_parser_consume_token (parser);
8758 for (i = 0; i < collapse; i++)
8762 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8765 /* Parse the initialization declaration or expression. */
8766 if (c_parser_next_token_starts_declaration (parser))
8769 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
8770 c_parser_declaration_or_fndef (parser, true, true, true, true, true, NULL);
8771 decl = check_for_loop_decls (for_loc, flag_isoc99);
8774 if (DECL_INITIAL (decl) == error_mark_node)
8775 decl = error_mark_node;
8778 else if (c_parser_next_token_is (parser, CPP_NAME)
8779 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8781 struct c_expr decl_exp;
8782 struct c_expr init_exp;
8783 location_t init_loc;
8785 decl_exp = c_parser_postfix_expression (parser);
8786 decl = decl_exp.value;
8788 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8790 init_loc = c_parser_peek_token (parser)->location;
8791 init_exp = c_parser_expr_no_commas (parser, NULL);
8792 init_exp = default_function_array_read_conversion (init_loc,
8794 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8795 NOP_EXPR, init_loc, init_exp.value,
8796 init_exp.original_type);
8797 init = c_process_expr_stmt (init_loc, init);
8799 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8804 c_parser_error (parser,
8805 "expected iteration declaration or initialization");
8806 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8812 /* Parse the loop condition. */
8814 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8816 location_t cond_loc = c_parser_peek_token (parser)->location;
8817 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8819 cond = cond_expr.value;
8820 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8821 cond = c_fully_fold (cond, false, NULL);
8822 switch (cond_expr.original_code)
8830 /* Can't be cond = error_mark_node, because we want to preserve
8831 the location until c_finish_omp_for. */
8832 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8835 protected_set_expr_location (cond, cond_loc);
8837 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8839 /* Parse the increment expression. */
8841 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8843 location_t incr_loc = c_parser_peek_token (parser)->location;
8845 incr = c_process_expr_stmt (incr_loc,
8846 c_parser_expression (parser).value);
8848 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8850 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8854 TREE_VEC_ELT (declv, i) = decl;
8855 TREE_VEC_ELT (initv, i) = init;
8856 TREE_VEC_ELT (condv, i) = cond;
8857 TREE_VEC_ELT (incrv, i) = incr;
8861 if (i == collapse - 1)
8864 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8865 in between the collapsed for loops to be still considered perfectly
8866 nested. Hopefully the final version clarifies this.
8867 For now handle (multiple) {'s and empty statements. */
8870 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8872 c_parser_consume_token (parser);
8875 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8877 c_parser_consume_token (parser);
8881 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8882 c_parser_consume_token (parser);
8885 c_parser_error (parser, "not enough perfectly nested loops");
8888 open_brace_parsed = true;
8898 nbraces += bracecount;
8901 save_break = c_break_label;
8902 c_break_label = size_one_node;
8903 save_cont = c_cont_label;
8904 c_cont_label = NULL_TREE;
8905 body = push_stmt_list ();
8907 if (open_brace_parsed)
8909 location_t here = c_parser_peek_token (parser)->location;
8910 stmt = c_begin_compound_stmt (true);
8911 c_parser_compound_statement_nostart (parser);
8912 add_stmt (c_end_compound_stmt (here, stmt, true));
8915 add_stmt (c_parser_c99_block_statement (parser));
8918 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8919 SET_EXPR_LOCATION (t, loc);
8923 body = pop_stmt_list (body);
8924 c_break_label = save_break;
8925 c_cont_label = save_cont;
8929 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8931 c_parser_consume_token (parser);
8934 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8935 c_parser_consume_token (parser);
8938 c_parser_error (parser, "collapsed loops not perfectly nested");
8941 location_t here = c_parser_peek_token (parser)->location;
8942 stmt = c_begin_compound_stmt (true);
8944 c_parser_compound_statement_nostart (parser);
8945 body = c_end_compound_stmt (here, stmt, true);
8952 /* Only bother calling c_finish_omp_for if we haven't already generated
8953 an error from the initialization parsing. */
8956 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8959 if (par_clauses != NULL)
8962 for (c = par_clauses; *c ; )
8963 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8964 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8965 c = &OMP_CLAUSE_CHAIN (*c);
8968 for (i = 0; i < collapse; i++)
8969 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8972 c = &OMP_CLAUSE_CHAIN (*c);
8973 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8976 "iteration variable %qD should not be firstprivate",
8977 OMP_CLAUSE_DECL (*c));
8978 *c = OMP_CLAUSE_CHAIN (*c);
8982 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8983 change it to shared (decl) in
8984 OMP_PARALLEL_CLAUSES. */
8985 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8986 OMP_CLAUSE_LASTPRIVATE);
8987 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8988 OMP_CLAUSE_CHAIN (l) = clauses;
8990 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8994 OMP_FOR_CLAUSES (stmt) = clauses;
8999 while (!VEC_empty (tree, for_block))
9001 /* FIXME diagnostics: LOC below should be the actual location of
9002 this particular for block. We need to build a list of
9003 locations to go along with FOR_BLOCK. */
9004 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
9007 release_tree_vector (for_block);
9012 #pragma omp for for-clause[optseq] new-line
9015 LOC is the location of the #pragma token.
9018 #define OMP_FOR_CLAUSE_MASK \
9019 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9020 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9021 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9022 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9023 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
9024 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
9025 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
9026 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9029 c_parser_omp_for (location_t loc, c_parser *parser)
9031 tree block, clauses, ret;
9033 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
9036 block = c_begin_compound_stmt (true);
9037 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
9038 block = c_end_compound_stmt (loc, block, true);
9045 # pragma omp master new-line
9048 LOC is the location of the #pragma token.
9052 c_parser_omp_master (location_t loc, c_parser *parser)
9054 c_parser_skip_to_pragma_eol (parser);
9055 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
9059 # pragma omp ordered new-line
9062 LOC is the location of the #pragma itself.
9066 c_parser_omp_ordered (location_t loc, c_parser *parser)
9068 c_parser_skip_to_pragma_eol (parser);
9069 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
9075 { section-sequence }
9078 section-directive[opt] structured-block
9079 section-sequence section-directive structured-block
9081 SECTIONS_LOC is the location of the #pragma omp sections. */
9084 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
9087 bool error_suppress = false;
9090 loc = c_parser_peek_token (parser)->location;
9091 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
9093 /* Avoid skipping until the end of the block. */
9094 parser->error = false;
9098 stmt = push_stmt_list ();
9100 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
9102 substmt = push_stmt_list ();
9106 c_parser_statement (parser);
9108 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9110 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9112 if (c_parser_next_token_is (parser, CPP_EOF))
9116 substmt = pop_stmt_list (substmt);
9117 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9118 SET_EXPR_LOCATION (substmt, loc);
9124 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
9126 if (c_parser_next_token_is (parser, CPP_EOF))
9129 loc = c_parser_peek_token (parser)->location;
9130 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
9132 c_parser_consume_pragma (parser);
9133 c_parser_skip_to_pragma_eol (parser);
9134 error_suppress = false;
9136 else if (!error_suppress)
9138 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
9139 error_suppress = true;
9142 substmt = c_parser_omp_structured_block (parser);
9143 substmt = build1 (OMP_SECTION, void_type_node, substmt);
9144 SET_EXPR_LOCATION (substmt, loc);
9147 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
9148 "expected %<#pragma omp section%> or %<}%>");
9150 substmt = pop_stmt_list (stmt);
9152 stmt = make_node (OMP_SECTIONS);
9153 SET_EXPR_LOCATION (stmt, sections_loc);
9154 TREE_TYPE (stmt) = void_type_node;
9155 OMP_SECTIONS_BODY (stmt) = substmt;
9157 return add_stmt (stmt);
9161 # pragma omp sections sections-clause[optseq] newline
9164 LOC is the location of the #pragma token.
9167 #define OMP_SECTIONS_CLAUSE_MASK \
9168 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9169 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9170 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
9171 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9172 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9175 c_parser_omp_sections (location_t loc, c_parser *parser)
9177 tree block, clauses, ret;
9179 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
9180 "#pragma omp sections");
9182 block = c_begin_compound_stmt (true);
9183 ret = c_parser_omp_sections_scope (loc, parser);
9185 OMP_SECTIONS_CLAUSES (ret) = clauses;
9186 block = c_end_compound_stmt (loc, block, true);
9193 # pragma parallel parallel-clause new-line
9194 # pragma parallel for parallel-for-clause new-line
9195 # pragma parallel sections parallel-sections-clause new-line
9197 LOC is the location of the #pragma token.
9200 #define OMP_PARALLEL_CLAUSE_MASK \
9201 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9202 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9203 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9204 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9205 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
9206 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
9207 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
9208 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
9211 c_parser_omp_parallel (location_t loc, c_parser *parser)
9213 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
9214 const char *p_name = "#pragma omp parallel";
9215 tree stmt, clauses, par_clause, ws_clause, block;
9216 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
9218 if (c_parser_next_token_is_keyword (parser, RID_FOR))
9220 c_parser_consume_token (parser);
9221 p_kind = PRAGMA_OMP_PARALLEL_FOR;
9222 p_name = "#pragma omp parallel for";
9223 mask |= OMP_FOR_CLAUSE_MASK;
9224 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9226 else if (c_parser_next_token_is (parser, CPP_NAME))
9228 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
9229 if (strcmp (p, "sections") == 0)
9231 c_parser_consume_token (parser);
9232 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
9233 p_name = "#pragma omp parallel sections";
9234 mask |= OMP_SECTIONS_CLAUSE_MASK;
9235 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
9239 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
9243 case PRAGMA_OMP_PARALLEL:
9244 block = c_begin_omp_parallel ();
9245 c_parser_statement (parser);
9246 stmt = c_finish_omp_parallel (loc, clauses, block);
9249 case PRAGMA_OMP_PARALLEL_FOR:
9250 block = c_begin_omp_parallel ();
9251 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9252 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
9253 stmt = c_finish_omp_parallel (loc, par_clause, block);
9254 OMP_PARALLEL_COMBINED (stmt) = 1;
9257 case PRAGMA_OMP_PARALLEL_SECTIONS:
9258 block = c_begin_omp_parallel ();
9259 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
9260 stmt = c_parser_omp_sections_scope (loc, parser);
9262 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
9263 stmt = c_finish_omp_parallel (loc, par_clause, block);
9264 OMP_PARALLEL_COMBINED (stmt) = 1;
9275 # pragma omp single single-clause[optseq] new-line
9278 LOC is the location of the #pragma.
9281 #define OMP_SINGLE_CLAUSE_MASK \
9282 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9283 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9284 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
9285 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
9288 c_parser_omp_single (location_t loc, c_parser *parser)
9290 tree stmt = make_node (OMP_SINGLE);
9291 SET_EXPR_LOCATION (stmt, loc);
9292 TREE_TYPE (stmt) = void_type_node;
9294 OMP_SINGLE_CLAUSES (stmt)
9295 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
9296 "#pragma omp single");
9297 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
9299 return add_stmt (stmt);
9303 # pragma omp task task-clause[optseq] new-line
9305 LOC is the location of the #pragma.
9308 #define OMP_TASK_CLAUSE_MASK \
9309 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
9310 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
9311 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
9312 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
9313 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
9314 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
9317 c_parser_omp_task (location_t loc, c_parser *parser)
9319 tree clauses, block;
9321 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
9322 "#pragma omp task");
9324 block = c_begin_omp_task ();
9325 c_parser_statement (parser);
9326 return c_finish_omp_task (loc, clauses, block);
9330 # pragma omp taskwait new-line
9334 c_parser_omp_taskwait (c_parser *parser)
9336 location_t loc = c_parser_peek_token (parser)->location;
9337 c_parser_consume_pragma (parser);
9338 c_parser_skip_to_pragma_eol (parser);
9340 c_finish_omp_taskwait (loc);
9343 /* Main entry point to parsing most OpenMP pragmas. */
9346 c_parser_omp_construct (c_parser *parser)
9348 enum pragma_kind p_kind;
9352 loc = c_parser_peek_token (parser)->location;
9353 p_kind = c_parser_peek_token (parser)->pragma_kind;
9354 c_parser_consume_pragma (parser);
9358 case PRAGMA_OMP_ATOMIC:
9359 c_parser_omp_atomic (loc, parser);
9361 case PRAGMA_OMP_CRITICAL:
9362 stmt = c_parser_omp_critical (loc, parser);
9364 case PRAGMA_OMP_FOR:
9365 stmt = c_parser_omp_for (loc, parser);
9367 case PRAGMA_OMP_MASTER:
9368 stmt = c_parser_omp_master (loc, parser);
9370 case PRAGMA_OMP_ORDERED:
9371 stmt = c_parser_omp_ordered (loc, parser);
9373 case PRAGMA_OMP_PARALLEL:
9374 stmt = c_parser_omp_parallel (loc, parser);
9376 case PRAGMA_OMP_SECTIONS:
9377 stmt = c_parser_omp_sections (loc, parser);
9379 case PRAGMA_OMP_SINGLE:
9380 stmt = c_parser_omp_single (loc, parser);
9382 case PRAGMA_OMP_TASK:
9383 stmt = c_parser_omp_task (loc, parser);
9390 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9395 # pragma omp threadprivate (variable-list) */
9398 c_parser_omp_threadprivate (c_parser *parser)
9403 c_parser_consume_pragma (parser);
9404 loc = c_parser_peek_token (parser)->location;
9405 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9407 /* Mark every variable in VARS to be assigned thread local storage. */
9408 for (t = vars; t; t = TREE_CHAIN (t))
9410 tree v = TREE_PURPOSE (t);
9412 /* FIXME diagnostics: Ideally we should keep individual
9413 locations for all the variables in the var list to make the
9414 following errors more precise. Perhaps
9415 c_parser_omp_var_list_parens() should construct a list of
9416 locations to go along with the var list. */
9418 /* If V had already been marked threadprivate, it doesn't matter
9419 whether it had been used prior to this point. */
9420 if (TREE_CODE (v) != VAR_DECL)
9421 error_at (loc, "%qD is not a variable", v);
9422 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9423 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9424 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9425 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9426 else if (TREE_TYPE (v) == error_mark_node)
9428 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9429 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9432 if (! DECL_THREAD_LOCAL_P (v))
9434 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9435 /* If rtl has been already set for this var, call
9436 make_decl_rtl once again, so that encode_section_info
9437 has a chance to look at the new decl flags. */
9438 if (DECL_RTL_SET_P (v))
9441 C_DECL_THREADPRIVATE_P (v) = 1;
9445 c_parser_skip_to_pragma_eol (parser);
9449 /* Parse a single source file. */
9454 /* Use local storage to begin. If the first token is a pragma, parse it.
9455 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9456 which will cause garbage collection. */
9459 memset (&tparser, 0, sizeof tparser);
9460 the_parser = &tparser;
9462 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9463 c_parser_pragma_pch_preprocess (&tparser);
9465 the_parser = ggc_alloc_c_parser ();
9466 *the_parser = tparser;
9468 /* Initialize EH, if we've been told to do so. */
9469 if (flag_exceptions)
9470 using_eh_for_cleanups ();
9472 c_parser_translation_unit (the_parser);
9476 #include "gt-c-parser.h"