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 /* The following flag is needed to contextualize Objective-C lexical
189 analysis. In some cases (e.g., 'int NSObject;'), it is
190 undesirable to bind an identifier to an Objective-C class, even
191 if a class with that name exists. */
192 BOOL_BITFIELD objc_need_raw_identifier : 1;
196 /* The actual parser and external interface. ??? Does this need to be
197 garbage-collected? */
199 static GTY (()) c_parser *the_parser;
201 /* Read in and lex a single token, storing it in *TOKEN. */
204 c_lex_one_token (c_parser *parser, c_token *token)
206 timevar_push (TV_LEX);
208 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
209 (parser->lex_untranslated_string
210 ? C_LEX_STRING_NO_TRANSLATE : 0));
211 token->id_kind = C_ID_NONE;
212 token->keyword = RID_MAX;
213 token->pragma_kind = PRAGMA_NONE;
221 bool objc_force_identifier = parser->objc_need_raw_identifier;
222 if (c_dialect_objc ())
223 parser->objc_need_raw_identifier = false;
225 if (C_IS_RESERVED_WORD (token->value))
227 enum rid rid_code = C_RID_CODE (token->value);
229 if (rid_code == RID_CXX_COMPAT_WARN)
231 warning_at (token->location,
233 "identifier %qE conflicts with C++ keyword",
236 else if (rid_code >= RID_FIRST_ADDR_SPACE
237 && rid_code <= RID_LAST_ADDR_SPACE)
239 token->id_kind = C_ID_ADDRSPACE;
240 token->keyword = rid_code;
243 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code))
245 /* We found an Objective-C "pq" keyword (in, out,
246 inout, bycopy, byref, oneway). They need special
247 care because the interpretation depends on the
250 if (parser->objc_pq_context)
252 token->type = CPP_KEYWORD;
253 token->keyword = rid_code;
256 /* Else, "pq" keywords outside of the "pq" context are
257 not keywords, and we fall through to the code for
261 else if (c_dialect_objc ()
262 && (OBJC_IS_AT_KEYWORD (rid_code)
263 || OBJC_IS_CXX_KEYWORD (rid_code)))
265 /* We found one of the Objective-C "@" keywords (defs,
266 selector, synchronized, etc) or one of the
267 Objective-C "cxx" keywords (class, private,
268 protected, public, try, catch, throw) without a
269 preceding '@' sign. Do nothing and fall through to
270 the code for normal tokens (in C++ we would still
271 consider the CXX ones keywords, but not in C).
277 token->type = CPP_KEYWORD;
278 token->keyword = rid_code;
283 decl = lookup_name (token->value);
286 if (TREE_CODE (decl) == TYPE_DECL)
288 token->id_kind = C_ID_TYPENAME;
292 else if (c_dialect_objc ())
294 tree objc_interface_decl = objc_is_class_name (token->value);
295 /* Objective-C class names are in the same namespace as
296 variables and typedefs, and hence are shadowed by local
298 if (objc_interface_decl
299 && (global_bindings_p ()
300 || (!objc_force_identifier && !decl)))
302 token->value = objc_interface_decl;
303 token->id_kind = C_ID_CLASSNAME;
307 token->id_kind = C_ID_ID;
311 /* This only happens in Objective-C; it must be a keyword. */
312 token->type = CPP_KEYWORD;
313 token->keyword = C_RID_CODE (token->value);
317 case CPP_CLOSE_PAREN:
319 /* These tokens may affect the interpretation of any identifiers
320 following, if doing Objective-C. */
321 if (c_dialect_objc ())
322 parser->objc_need_raw_identifier = false;
325 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
326 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
332 timevar_pop (TV_LEX);
335 /* Return a pointer to the next token from PARSER, reading it in if
338 static inline c_token *
339 c_parser_peek_token (c_parser *parser)
341 if (parser->tokens_avail == 0)
343 c_lex_one_token (parser, &parser->tokens[0]);
344 parser->tokens_avail = 1;
346 return &parser->tokens[0];
349 /* Return true if the next token from PARSER has the indicated
353 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
355 return c_parser_peek_token (parser)->type == type;
358 /* Return true if the next token from PARSER does not have the
362 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
364 return !c_parser_next_token_is (parser, type);
367 /* Return true if the next token from PARSER is the indicated
371 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
373 return c_parser_peek_token (parser)->keyword == keyword;
376 /* Return true if TOKEN can start a type name,
379 c_token_starts_typename (c_token *token)
384 switch (token->id_kind)
393 gcc_assert (c_dialect_objc ());
399 switch (token->keyword)
432 if (c_dialect_objc ())
440 /* Return true if the next token from PARSER can start a type name,
443 c_parser_next_token_starts_typename (c_parser *parser)
445 c_token *token = c_parser_peek_token (parser);
446 return c_token_starts_typename (token);
449 /* Return true if TOKEN can start declaration specifiers, false
452 c_token_starts_declspecs (c_token *token)
457 switch (token->id_kind)
466 gcc_assert (c_dialect_objc ());
472 switch (token->keyword)
512 if (c_dialect_objc ())
521 /* Return true if TOKEN can start declaration specifiers or a static
522 assertion, false otherwise. */
524 c_token_starts_declaration (c_token *token)
526 if (c_token_starts_declspecs (token)
527 || token->keyword == RID_STATIC_ASSERT)
533 /* Return true if the next token from PARSER can start declaration
534 specifiers, false otherwise. */
536 c_parser_next_token_starts_declspecs (c_parser *parser)
538 c_token *token = c_parser_peek_token (parser);
539 return c_token_starts_declspecs (token);
542 /* Return true if the next token from PARSER can start declaration
543 specifiers or a static assertion, false otherwise. */
545 c_parser_next_token_starts_declaration (c_parser *parser)
547 c_token *token = c_parser_peek_token (parser);
548 return c_token_starts_declaration (token);
551 /* Return a pointer to the next-but-one token from PARSER, reading it
552 in if necessary. The next token is already read in. */
555 c_parser_peek_2nd_token (c_parser *parser)
557 if (parser->tokens_avail >= 2)
558 return &parser->tokens[1];
559 gcc_assert (parser->tokens_avail == 1);
560 gcc_assert (parser->tokens[0].type != CPP_EOF);
561 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
562 c_lex_one_token (parser, &parser->tokens[1]);
563 parser->tokens_avail = 2;
564 return &parser->tokens[1];
567 /* Consume the next token from PARSER. */
570 c_parser_consume_token (c_parser *parser)
572 gcc_assert (parser->tokens_avail >= 1);
573 gcc_assert (parser->tokens[0].type != CPP_EOF);
574 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
575 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
576 if (parser->tokens_avail == 2)
577 parser->tokens[0] = parser->tokens[1];
578 parser->tokens_avail--;
581 /* Expect the current token to be a #pragma. Consume it and remember
582 that we've begun parsing a pragma. */
585 c_parser_consume_pragma (c_parser *parser)
587 gcc_assert (!parser->in_pragma);
588 gcc_assert (parser->tokens_avail >= 1);
589 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
590 if (parser->tokens_avail == 2)
591 parser->tokens[0] = parser->tokens[1];
592 parser->tokens_avail--;
593 parser->in_pragma = true;
596 /* Update the globals input_location and in_system_header from
599 c_parser_set_source_position_from_token (c_token *token)
601 if (token->type != CPP_EOF)
603 input_location = token->location;
607 /* Issue a diagnostic of the form
608 FILE:LINE: MESSAGE before TOKEN
609 where TOKEN is the next token in the input stream of PARSER.
610 MESSAGE (specified by the caller) is usually of the form "expected
613 Do not issue a diagnostic if still recovering from an error.
615 ??? This is taken from the C++ parser, but building up messages in
616 this way is not i18n-friendly and some other approach should be
620 c_parser_error (c_parser *parser, const char *gmsgid)
622 c_token *token = c_parser_peek_token (parser);
625 parser->error = true;
628 /* This diagnostic makes more sense if it is tagged to the line of
629 the token we just peeked at. */
630 c_parser_set_source_position_from_token (token);
631 c_parse_error (gmsgid,
632 /* Because c_parse_error does not understand
633 CPP_KEYWORD, keywords are treated like
635 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
636 /* ??? The C parser does not save the cpp flags of a
637 token, we need to pass 0 here and we will not get
638 the source spelling of some tokens but rather the
639 canonical spelling. */
640 token->value, /*flags=*/0);
643 /* If the next token is of the indicated TYPE, consume it. Otherwise,
644 issue the error MSGID. If MSGID is NULL then a message has already
645 been produced and no message will be produced this time. Returns
646 true if found, false otherwise. */
649 c_parser_require (c_parser *parser,
653 if (c_parser_next_token_is (parser, type))
655 c_parser_consume_token (parser);
660 c_parser_error (parser, msgid);
665 /* If the next token is the indicated keyword, consume it. Otherwise,
666 issue the error MSGID. Returns true if found, false otherwise. */
669 c_parser_require_keyword (c_parser *parser,
673 if (c_parser_next_token_is_keyword (parser, keyword))
675 c_parser_consume_token (parser);
680 c_parser_error (parser, msgid);
685 /* Like c_parser_require, except that tokens will be skipped until the
686 desired token is found. An error message is still produced if the
687 next token is not as expected. If MSGID is NULL then a message has
688 already been produced and no message will be produced this
692 c_parser_skip_until_found (c_parser *parser,
696 unsigned nesting_depth = 0;
698 if (c_parser_require (parser, type, msgid))
701 /* Skip tokens until the desired token is found. */
704 /* Peek at the next token. */
705 c_token *token = c_parser_peek_token (parser);
706 /* If we've reached the token we want, consume it and stop. */
707 if (token->type == type && !nesting_depth)
709 c_parser_consume_token (parser);
713 /* If we've run out of tokens, stop. */
714 if (token->type == CPP_EOF)
716 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
718 if (token->type == CPP_OPEN_BRACE
719 || token->type == CPP_OPEN_PAREN
720 || token->type == CPP_OPEN_SQUARE)
722 else if (token->type == CPP_CLOSE_BRACE
723 || token->type == CPP_CLOSE_PAREN
724 || token->type == CPP_CLOSE_SQUARE)
726 if (nesting_depth-- == 0)
729 /* Consume this token. */
730 c_parser_consume_token (parser);
732 parser->error = false;
735 /* Skip tokens until the end of a parameter is found, but do not
736 consume the comma, semicolon or closing delimiter. */
739 c_parser_skip_to_end_of_parameter (c_parser *parser)
741 unsigned nesting_depth = 0;
745 c_token *token = c_parser_peek_token (parser);
746 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
749 /* If we've run out of tokens, stop. */
750 if (token->type == CPP_EOF)
752 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
754 if (token->type == CPP_OPEN_BRACE
755 || token->type == CPP_OPEN_PAREN
756 || token->type == CPP_OPEN_SQUARE)
758 else if (token->type == CPP_CLOSE_BRACE
759 || token->type == CPP_CLOSE_PAREN
760 || token->type == CPP_CLOSE_SQUARE)
762 if (nesting_depth-- == 0)
765 /* Consume this token. */
766 c_parser_consume_token (parser);
768 parser->error = false;
771 /* Expect to be at the end of the pragma directive and consume an
772 end of line marker. */
775 c_parser_skip_to_pragma_eol (c_parser *parser)
777 gcc_assert (parser->in_pragma);
778 parser->in_pragma = false;
780 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
783 c_token *token = c_parser_peek_token (parser);
784 if (token->type == CPP_EOF)
786 if (token->type == CPP_PRAGMA_EOL)
788 c_parser_consume_token (parser);
791 c_parser_consume_token (parser);
794 parser->error = false;
797 /* Skip tokens until we have consumed an entire block, or until we
798 have consumed a non-nested ';'. */
801 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
803 unsigned nesting_depth = 0;
804 bool save_error = parser->error;
810 /* Peek at the next token. */
811 token = c_parser_peek_token (parser);
819 if (parser->in_pragma)
824 /* If the next token is a ';', we have reached the
825 end of the statement. */
828 /* Consume the ';'. */
829 c_parser_consume_token (parser);
834 case CPP_CLOSE_BRACE:
835 /* If the next token is a non-nested '}', then we have
836 reached the end of the current block. */
837 if (nesting_depth == 0 || --nesting_depth == 0)
839 c_parser_consume_token (parser);
845 /* If it the next token is a '{', then we are entering a new
846 block. Consume the entire block. */
851 /* If we see a pragma, consume the whole thing at once. We
852 have some safeguards against consuming pragmas willy-nilly.
853 Normally, we'd expect to be here with parser->error set,
854 which disables these safeguards. But it's possible to get
855 here for secondary error recovery, after parser->error has
857 c_parser_consume_pragma (parser);
858 c_parser_skip_to_pragma_eol (parser);
859 parser->error = save_error;
866 c_parser_consume_token (parser);
870 parser->error = false;
873 /* CPP's options (initialized by c-opts.c). */
874 extern cpp_options *cpp_opts;
876 /* Save the warning flags which are controlled by __extension__. */
879 disable_extension_diagnostics (void)
882 | (warn_pointer_arith << 1)
883 | (warn_traditional << 2)
885 | (warn_long_long << 4)
886 | (warn_cxx_compat << 5));
887 cpp_opts->pedantic = pedantic = 0;
888 warn_pointer_arith = 0;
889 cpp_opts->warn_traditional = warn_traditional = 0;
891 cpp_opts->warn_long_long = warn_long_long = 0;
896 /* Restore the warning flags which are controlled by __extension__.
897 FLAGS is the return value from disable_extension_diagnostics. */
900 restore_extension_diagnostics (int flags)
902 cpp_opts->pedantic = pedantic = flags & 1;
903 warn_pointer_arith = (flags >> 1) & 1;
904 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
905 flag_iso = (flags >> 3) & 1;
906 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
907 warn_cxx_compat = (flags >> 5) & 1;
910 /* Possibly kinds of declarator to parse. */
911 typedef enum c_dtr_syn {
912 /* A normal declarator with an identifier. */
914 /* An abstract declarator (maybe empty). */
916 /* A parameter declarator: may be either, but after a type name does
917 not redeclare a typedef name as an identifier if it can
918 alternatively be interpreted as a typedef name; see DR#009,
919 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
920 following DR#249. For example, given a typedef T, "int T" and
921 "int *T" are valid parameter declarations redeclaring T, while
922 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
923 abstract declarators rather than involving redundant parentheses;
924 the same applies with attributes inside the parentheses before
929 static void c_parser_external_declaration (c_parser *);
930 static void c_parser_asm_definition (c_parser *);
931 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
933 static void c_parser_static_assert_declaration_no_semi (c_parser *);
934 static void c_parser_static_assert_declaration (c_parser *);
935 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
937 static struct c_typespec c_parser_enum_specifier (c_parser *);
938 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
939 static tree c_parser_struct_declaration (c_parser *);
940 static struct c_typespec c_parser_typeof_specifier (c_parser *);
941 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
943 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
945 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
947 struct c_declarator *);
948 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
949 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
950 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
951 static tree c_parser_simple_asm_expr (c_parser *);
952 static tree c_parser_attributes (c_parser *);
953 static struct c_type_name *c_parser_type_name (c_parser *);
954 static struct c_expr c_parser_initializer (c_parser *);
955 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
956 static void c_parser_initelt (c_parser *, struct obstack *);
957 static void c_parser_initval (c_parser *, struct c_expr *,
959 static tree c_parser_compound_statement (c_parser *);
960 static void c_parser_compound_statement_nostart (c_parser *);
961 static void c_parser_label (c_parser *);
962 static void c_parser_statement (c_parser *);
963 static void c_parser_statement_after_labels (c_parser *);
964 static void c_parser_if_statement (c_parser *);
965 static void c_parser_switch_statement (c_parser *);
966 static void c_parser_while_statement (c_parser *);
967 static void c_parser_do_statement (c_parser *);
968 static void c_parser_for_statement (c_parser *);
969 static tree c_parser_asm_statement (c_parser *);
970 static tree c_parser_asm_operands (c_parser *, bool);
971 static tree c_parser_asm_goto_operands (c_parser *);
972 static tree c_parser_asm_clobbers (c_parser *);
973 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
974 static struct c_expr c_parser_conditional_expression (c_parser *,
976 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
977 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
978 static struct c_expr c_parser_unary_expression (c_parser *);
979 static struct c_expr c_parser_sizeof_expression (c_parser *);
980 static struct c_expr c_parser_alignof_expression (c_parser *);
981 static struct c_expr c_parser_postfix_expression (c_parser *);
982 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
983 struct c_type_name *,
985 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
988 static struct c_expr c_parser_expression (c_parser *);
989 static struct c_expr c_parser_expression_conv (c_parser *);
990 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
992 static void c_parser_omp_construct (c_parser *);
993 static void c_parser_omp_threadprivate (c_parser *);
994 static void c_parser_omp_barrier (c_parser *);
995 static void c_parser_omp_flush (c_parser *);
996 static void c_parser_omp_taskwait (c_parser *);
998 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
999 static bool c_parser_pragma (c_parser *, enum pragma_context);
1001 /* These Objective-C parser functions are only ever called when
1002 compiling Objective-C. */
1003 static void c_parser_objc_class_definition (c_parser *, tree);
1004 static void c_parser_objc_class_instance_variables (c_parser *);
1005 static void c_parser_objc_class_declaration (c_parser *);
1006 static void c_parser_objc_alias_declaration (c_parser *);
1007 static void c_parser_objc_protocol_definition (c_parser *, tree);
1008 static enum tree_code c_parser_objc_method_type (c_parser *);
1009 static void c_parser_objc_method_definition (c_parser *);
1010 static void c_parser_objc_methodprotolist (c_parser *);
1011 static void c_parser_objc_methodproto (c_parser *);
1012 static tree c_parser_objc_method_decl (c_parser *, tree *);
1013 static tree c_parser_objc_type_name (c_parser *);
1014 static tree c_parser_objc_protocol_refs (c_parser *);
1015 static void c_parser_objc_try_catch_statement (c_parser *);
1016 static void c_parser_objc_synchronized_statement (c_parser *);
1017 static tree c_parser_objc_selector (c_parser *);
1018 static tree c_parser_objc_selector_arg (c_parser *);
1019 static tree c_parser_objc_receiver (c_parser *);
1020 static tree c_parser_objc_message_args (c_parser *);
1021 static tree c_parser_objc_keywordexpr (c_parser *);
1022 static bool c_parser_objc_diagnose_bad_element_prefix
1023 (c_parser *, struct c_declspecs *);
1025 /* Parse a translation unit (C90 6.7, C99 6.9).
1028 external-declarations
1030 external-declarations:
1031 external-declaration
1032 external-declarations external-declaration
1041 c_parser_translation_unit (c_parser *parser)
1043 if (c_parser_next_token_is (parser, CPP_EOF))
1045 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1046 "ISO C forbids an empty translation unit");
1050 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1051 mark_valid_location_for_stdc_pragma (false);
1055 c_parser_external_declaration (parser);
1056 obstack_free (&parser_obstack, obstack_position);
1058 while (c_parser_next_token_is_not (parser, CPP_EOF));
1062 /* Parse an external declaration (C90 6.7, C99 6.9).
1064 external-declaration:
1070 external-declaration:
1073 __extension__ external-declaration
1077 external-declaration:
1078 objc-class-definition
1079 objc-class-declaration
1080 objc-alias-declaration
1081 objc-protocol-definition
1082 objc-method-definition
1087 c_parser_external_declaration (c_parser *parser)
1090 switch (c_parser_peek_token (parser)->type)
1093 switch (c_parser_peek_token (parser)->keyword)
1096 ext = disable_extension_diagnostics ();
1097 c_parser_consume_token (parser);
1098 c_parser_external_declaration (parser);
1099 restore_extension_diagnostics (ext);
1102 c_parser_asm_definition (parser);
1104 case RID_AT_INTERFACE:
1105 case RID_AT_IMPLEMENTATION:
1106 gcc_assert (c_dialect_objc ());
1107 c_parser_objc_class_definition (parser, NULL_TREE);
1110 gcc_assert (c_dialect_objc ());
1111 c_parser_objc_class_declaration (parser);
1114 gcc_assert (c_dialect_objc ());
1115 c_parser_objc_alias_declaration (parser);
1117 case RID_AT_PROTOCOL:
1118 gcc_assert (c_dialect_objc ());
1119 c_parser_objc_protocol_definition (parser, NULL_TREE);
1122 gcc_assert (c_dialect_objc ());
1123 c_parser_consume_token (parser);
1124 objc_finish_implementation ();
1131 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1132 "ISO C does not allow extra %<;%> outside of a function");
1133 c_parser_consume_token (parser);
1136 mark_valid_location_for_stdc_pragma (true);
1137 c_parser_pragma (parser, pragma_external);
1138 mark_valid_location_for_stdc_pragma (false);
1142 if (c_dialect_objc ())
1144 c_parser_objc_method_definition (parser);
1147 /* Else fall through, and yield a syntax error trying to parse
1148 as a declaration or function definition. */
1151 /* A declaration or a function definition (or, in Objective-C,
1152 an @interface or @protocol with prefix attributes). We can
1153 only tell which after parsing the declaration specifiers, if
1154 any, and the first declarator. */
1155 c_parser_declaration_or_fndef (parser, true, true, true, false, true);
1160 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1161 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1162 accepted; otherwise (old-style parameter declarations) only other
1163 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1164 assertion is accepted; otherwise (old-style parameter declarations)
1165 it is not. If NESTED is true, we are inside a function or parsing
1166 old-style parameter declarations; any functions encountered are
1167 nested functions and declaration specifiers are required; otherwise
1168 we are at top level and functions are normal functions and
1169 declaration specifiers may be optional. If EMPTY_OK is true, empty
1170 declarations are OK (subject to all other constraints); otherwise
1171 (old-style parameter declarations) they are diagnosed. If
1172 START_ATTR_OK is true, the declaration specifiers may start with
1173 attributes; otherwise they may not.
1176 declaration-specifiers init-declarator-list[opt] ;
1177 static_assert-declaration
1179 function-definition:
1180 declaration-specifiers[opt] declarator declaration-list[opt]
1185 declaration-list declaration
1187 init-declarator-list:
1189 init-declarator-list , init-declarator
1192 declarator simple-asm-expr[opt] attributes[opt]
1193 declarator simple-asm-expr[opt] attributes[opt] = initializer
1197 nested-function-definition:
1198 declaration-specifiers declarator declaration-list[opt]
1202 attributes objc-class-definition
1203 attributes objc-category-definition
1204 attributes objc-protocol-definition
1206 The simple-asm-expr and attributes are GNU extensions.
1208 This function does not handle __extension__; that is handled in its
1209 callers. ??? Following the old parser, __extension__ may start
1210 external declarations, declarations in functions and declarations
1211 at the start of "for" loops, but not old-style parameter
1214 C99 requires declaration specifiers in a function definition; the
1215 absence is diagnosed through the diagnosis of implicit int. In GNU
1216 C we also allow but diagnose declarations without declaration
1217 specifiers, but only at top level (elsewhere they conflict with
1223 threadprivate-directive */
1226 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1227 bool static_assert_ok, bool empty_ok,
1228 bool nested, bool start_attr_ok)
1230 struct c_declspecs *specs;
1232 tree all_prefix_attrs;
1233 bool diagnosed_no_specs = false;
1234 location_t here = c_parser_peek_token (parser)->location;
1236 if (static_assert_ok
1237 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1239 c_parser_static_assert_declaration (parser);
1242 specs = build_null_declspecs ();
1243 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1246 c_parser_skip_to_end_of_block_or_statement (parser);
1249 if (nested && !specs->declspecs_seen_p)
1251 c_parser_error (parser, "expected declaration specifiers");
1252 c_parser_skip_to_end_of_block_or_statement (parser);
1255 finish_declspecs (specs);
1256 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1262 shadow_tag_warned (specs, 1);
1263 pedwarn (here, 0, "empty declaration");
1265 c_parser_consume_token (parser);
1268 else if (c_dialect_objc ())
1270 /* Prefix attributes are an error on method decls. */
1271 switch (c_parser_peek_token (parser)->type)
1275 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1279 warning_at (c_parser_peek_token (parser)->location,
1281 "prefix attributes are ignored for methods");
1282 specs->attrs = NULL_TREE;
1285 c_parser_objc_method_definition (parser);
1287 c_parser_objc_methodproto (parser);
1293 /* This is where we parse 'attributes @interface ...',
1294 'attributes @implementation ...', 'attributes @protocol ...'
1295 (where attributes could be, for example, __attribute__
1298 switch (c_parser_peek_token (parser)->keyword)
1300 case RID_AT_INTERFACE:
1302 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1304 c_parser_objc_class_definition (parser, specs->attrs);
1308 case RID_AT_IMPLEMENTATION:
1310 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1314 warning_at (c_parser_peek_token (parser)->location,
1316 "prefix attributes are ignored for implementations");
1317 specs->attrs = NULL_TREE;
1319 c_parser_objc_class_definition (parser, NULL_TREE);
1323 case RID_AT_PROTOCOL:
1325 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1327 c_parser_objc_protocol_definition (parser, specs->attrs);
1336 pending_xref_error ();
1337 prefix_attrs = specs->attrs;
1338 all_prefix_attrs = prefix_attrs;
1339 specs->attrs = NULL_TREE;
1342 struct c_declarator *declarator;
1345 /* Declaring either one or more declarators (in which case we
1346 should diagnose if there were no declaration specifiers) or a
1347 function definition (in which case the diagnostic for
1348 implicit int suffices). */
1349 declarator = c_parser_declarator (parser, specs->type_seen_p,
1350 C_DTR_NORMAL, &dummy);
1351 if (declarator == NULL)
1353 c_parser_skip_to_end_of_block_or_statement (parser);
1356 if (c_parser_next_token_is (parser, CPP_EQ)
1357 || c_parser_next_token_is (parser, CPP_COMMA)
1358 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1359 || c_parser_next_token_is_keyword (parser, RID_ASM)
1360 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1362 tree asm_name = NULL_TREE;
1363 tree postfix_attrs = NULL_TREE;
1364 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1366 diagnosed_no_specs = true;
1367 pedwarn (here, 0, "data definition has no type or storage class");
1369 /* Having seen a data definition, there cannot now be a
1370 function definition. */
1372 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1373 asm_name = c_parser_simple_asm_expr (parser);
1374 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1375 postfix_attrs = c_parser_attributes (parser);
1376 if (c_parser_next_token_is (parser, CPP_EQ))
1380 location_t init_loc;
1381 c_parser_consume_token (parser);
1382 /* The declaration of the variable is in effect while
1383 its initializer is parsed. */
1384 d = start_decl (declarator, specs, true,
1385 chainon (postfix_attrs, all_prefix_attrs));
1387 d = error_mark_node;
1388 start_init (d, asm_name, global_bindings_p ());
1389 init_loc = c_parser_peek_token (parser)->location;
1390 init = c_parser_initializer (parser);
1392 if (d != error_mark_node)
1394 maybe_warn_string_init (TREE_TYPE (d), init);
1395 finish_decl (d, init_loc, init.value,
1396 init.original_type, asm_name);
1401 tree d = start_decl (declarator, specs, false,
1402 chainon (postfix_attrs,
1405 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1406 NULL_TREE, asm_name);
1408 if (c_parser_next_token_is (parser, CPP_COMMA))
1410 c_parser_consume_token (parser);
1411 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1412 all_prefix_attrs = chainon (c_parser_attributes (parser),
1415 all_prefix_attrs = prefix_attrs;
1418 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1420 c_parser_consume_token (parser);
1425 c_parser_error (parser, "expected %<,%> or %<;%>");
1426 c_parser_skip_to_end_of_block_or_statement (parser);
1432 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1433 "%<asm%> or %<__attribute__%>");
1434 c_parser_skip_to_end_of_block_or_statement (parser);
1437 /* Function definition (nested or otherwise). */
1440 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1441 c_push_function_context ();
1443 if (!start_function (specs, declarator, all_prefix_attrs))
1445 /* This can appear in many cases looking nothing like a
1446 function definition, so we don't give a more specific
1447 error suggesting there was one. */
1448 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1449 "or %<__attribute__%>");
1451 c_pop_function_context ();
1454 /* Parse old-style parameter declarations. ??? Attributes are
1455 not allowed to start declaration specifiers here because of a
1456 syntax conflict between a function declaration with attribute
1457 suffix and a function definition with an attribute prefix on
1458 first old-style parameter declaration. Following the old
1459 parser, they are not accepted on subsequent old-style
1460 parameter declarations either. However, there is no
1461 ambiguity after the first declaration, nor indeed on the
1462 first as long as we don't allow postfix attributes after a
1463 declarator with a nonempty identifier list in a definition;
1464 and postfix attributes have never been accepted here in
1465 function definitions either. */
1466 while (c_parser_next_token_is_not (parser, CPP_EOF)
1467 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1468 c_parser_declaration_or_fndef (parser, false, false, false,
1470 store_parm_decls ();
1471 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1472 = c_parser_peek_token (parser)->location;
1473 fnbody = c_parser_compound_statement (parser);
1476 tree decl = current_function_decl;
1477 /* Mark nested functions as needing static-chain initially.
1478 lower_nested_functions will recompute it but the
1479 DECL_STATIC_CHAIN flag is also used before that happens,
1480 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1481 DECL_STATIC_CHAIN (decl) = 1;
1484 c_pop_function_context ();
1485 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1496 /* Parse an asm-definition (asm() outside a function body). This is a
1504 c_parser_asm_definition (c_parser *parser)
1506 tree asm_str = c_parser_simple_asm_expr (parser);
1508 cgraph_add_asm_node (asm_str);
1509 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1512 /* Parse a static assertion (C1X N1425 6.7.10).
1514 static_assert-declaration:
1515 static_assert-declaration-no-semi ;
1519 c_parser_static_assert_declaration (c_parser *parser)
1521 c_parser_static_assert_declaration_no_semi (parser);
1523 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1524 c_parser_skip_to_end_of_block_or_statement (parser);
1527 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1530 static_assert-declaration-no-semi:
1531 _Static_assert ( constant-expression , string-literal )
1535 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1537 location_t assert_loc, value_loc;
1541 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1542 assert_loc = c_parser_peek_token (parser)->location;
1546 pedwarn (assert_loc, OPT_pedantic,
1547 "ISO C99 does not support %<_Static_assert%>");
1549 pedwarn (assert_loc, OPT_pedantic,
1550 "ISO C90 does not support %<_Static_assert%>");
1552 c_parser_consume_token (parser);
1553 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1555 value_loc = c_parser_peek_token (parser)->location;
1556 value = c_parser_expr_no_commas (parser, NULL).value;
1557 parser->lex_untranslated_string = true;
1558 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1560 parser->lex_untranslated_string = false;
1563 switch (c_parser_peek_token (parser)->type)
1569 case CPP_UTF8STRING:
1570 string = c_parser_peek_token (parser)->value;
1571 c_parser_consume_token (parser);
1572 parser->lex_untranslated_string = false;
1575 c_parser_error (parser, "expected string literal");
1576 parser->lex_untranslated_string = false;
1579 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1581 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1583 error_at (value_loc, "expression in static assertion is not an integer");
1586 if (TREE_CODE (value) != INTEGER_CST)
1588 value = c_fully_fold (value, false, NULL);
1589 if (TREE_CODE (value) == INTEGER_CST)
1590 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1591 "is not an integer constant expression");
1593 if (TREE_CODE (value) != INTEGER_CST)
1595 error_at (value_loc, "expression in static assertion is not constant");
1598 constant_expression_warning (value);
1599 if (integer_zerop (value))
1600 error_at (assert_loc, "static assertion failed: %E", string);
1603 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1604 6.7), adding them to SPECS (which may already include some).
1605 Storage class specifiers are accepted iff SCSPEC_OK; type
1606 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1607 the start iff START_ATTR_OK.
1609 declaration-specifiers:
1610 storage-class-specifier declaration-specifiers[opt]
1611 type-specifier declaration-specifiers[opt]
1612 type-qualifier declaration-specifiers[opt]
1613 function-specifier declaration-specifiers[opt]
1615 Function specifiers (inline) are from C99, and are currently
1616 handled as storage class specifiers, as is __thread.
1618 C90 6.5.1, C99 6.7.1:
1619 storage-class-specifier:
1630 C90 6.5.2, C99 6.7.2:
1643 [_Imaginary removed in C99 TC2]
1644 struct-or-union-specifier
1648 (_Bool and _Complex are new in C99.)
1650 C90 6.5.3, C99 6.7.3:
1656 address-space-qualifier
1658 (restrict is new in C99.)
1662 declaration-specifiers:
1663 attributes declaration-specifiers[opt]
1669 identifier recognized by the target
1671 storage-class-specifier:
1684 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1685 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1690 class-name objc-protocol-refs[opt]
1691 typedef-name objc-protocol-refs
1696 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1697 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1699 bool attrs_ok = start_attr_ok;
1700 bool seen_type = specs->type_seen_p;
1701 while (c_parser_next_token_is (parser, CPP_NAME)
1702 || c_parser_next_token_is (parser, CPP_KEYWORD)
1703 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1705 struct c_typespec t;
1707 location_t loc = c_parser_peek_token (parser)->location;
1708 if (c_parser_next_token_is (parser, CPP_NAME))
1710 tree value = c_parser_peek_token (parser)->value;
1711 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1713 if (kind == C_ID_ADDRSPACE)
1716 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1717 declspecs_add_addrspace (specs, as);
1718 c_parser_consume_token (parser);
1723 /* This finishes the specifiers unless a type name is OK, it
1724 is declared as a type name and a type name hasn't yet
1726 if (!typespec_ok || seen_type
1727 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1729 c_parser_consume_token (parser);
1732 if (kind == C_ID_TYPENAME
1733 && (!c_dialect_objc ()
1734 || c_parser_next_token_is_not (parser, CPP_LESS)))
1736 t.kind = ctsk_typedef;
1737 /* For a typedef name, record the meaning, not the name.
1738 In case of 'foo foo, bar;'. */
1739 t.spec = lookup_name (value);
1741 t.expr_const_operands = true;
1745 tree proto = NULL_TREE;
1746 gcc_assert (c_dialect_objc ());
1748 if (c_parser_next_token_is (parser, CPP_LESS))
1749 proto = c_parser_objc_protocol_refs (parser);
1750 t.spec = objc_get_protocol_qualified_type (value, proto);
1752 t.expr_const_operands = true;
1754 declspecs_add_type (loc, specs, t);
1757 if (c_parser_next_token_is (parser, CPP_LESS))
1759 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1760 nisse@lysator.liu.se. */
1762 gcc_assert (c_dialect_objc ());
1763 if (!typespec_ok || seen_type)
1765 proto = c_parser_objc_protocol_refs (parser);
1767 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1769 t.expr_const_operands = true;
1770 declspecs_add_type (loc, specs, t);
1773 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1774 switch (c_parser_peek_token (parser)->keyword)
1786 /* TODO: Distinguish between function specifiers (inline)
1787 and storage class specifiers, either here or in
1788 declspecs_add_scspec. */
1789 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1790 c_parser_consume_token (parser);
1814 if (c_dialect_objc ())
1815 parser->objc_need_raw_identifier = true;
1816 t.kind = ctsk_resword;
1817 t.spec = c_parser_peek_token (parser)->value;
1819 t.expr_const_operands = true;
1820 declspecs_add_type (loc, specs, t);
1821 c_parser_consume_token (parser);
1828 t = c_parser_enum_specifier (parser);
1829 declspecs_add_type (loc, specs, t);
1837 t = c_parser_struct_or_union_specifier (parser);
1838 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1839 declspecs_add_type (loc, specs, t);
1842 /* ??? The old parser rejected typeof after other type
1843 specifiers, but is a syntax error the best way of
1845 if (!typespec_ok || seen_type)
1849 t = c_parser_typeof_specifier (parser);
1850 declspecs_add_type (loc, specs, t);
1856 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1857 c_parser_consume_token (parser);
1862 attrs = c_parser_attributes (parser);
1863 declspecs_add_attrs (specs, attrs);
1872 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1875 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1876 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1877 enum attributes[opt] identifier
1879 The form with trailing comma is new in C99. The forms with
1880 attributes are GNU extensions. In GNU C, we accept any expression
1881 without commas in the syntax (assignment expressions, not just
1882 conditional expressions); assignment expressions will be diagnosed
1887 enumerator-list , enumerator
1890 enumeration-constant
1891 enumeration-constant = constant-expression
1894 static struct c_typespec
1895 c_parser_enum_specifier (c_parser *parser)
1897 struct c_typespec ret;
1899 tree ident = NULL_TREE;
1900 location_t enum_loc;
1901 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1902 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1903 enum_loc = c_parser_peek_token (parser)->location;
1904 c_parser_consume_token (parser);
1905 attrs = c_parser_attributes (parser);
1906 enum_loc = c_parser_peek_token (parser)->location;
1907 /* Set the location in case we create a decl now. */
1908 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1909 if (c_parser_next_token_is (parser, CPP_NAME))
1911 ident = c_parser_peek_token (parser)->value;
1912 ident_loc = c_parser_peek_token (parser)->location;
1913 enum_loc = ident_loc;
1914 c_parser_consume_token (parser);
1916 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1918 /* Parse an enum definition. */
1919 struct c_enum_contents the_enum;
1920 tree type = start_enum (enum_loc, &the_enum, ident);
1922 /* We chain the enumerators in reverse order, then put them in
1923 forward order at the end. */
1924 tree values = NULL_TREE;
1925 c_parser_consume_token (parser);
1933 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1934 location_t decl_loc, value_loc;
1935 if (c_parser_next_token_is_not (parser, CPP_NAME))
1937 c_parser_error (parser, "expected identifier");
1938 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1939 values = error_mark_node;
1942 token = c_parser_peek_token (parser);
1943 enum_id = token->value;
1944 /* Set the location in case we create a decl now. */
1945 c_parser_set_source_position_from_token (token);
1946 decl_loc = value_loc = token->location;
1947 c_parser_consume_token (parser);
1948 if (c_parser_next_token_is (parser, CPP_EQ))
1950 c_parser_consume_token (parser);
1951 value_loc = c_parser_peek_token (parser)->location;
1952 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1955 enum_value = NULL_TREE;
1956 enum_decl = build_enumerator (decl_loc, value_loc,
1957 &the_enum, enum_id, enum_value);
1958 TREE_CHAIN (enum_decl) = values;
1961 if (c_parser_next_token_is (parser, CPP_COMMA))
1963 comma_loc = c_parser_peek_token (parser)->location;
1965 c_parser_consume_token (parser);
1967 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1969 if (seen_comma && !flag_isoc99)
1970 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1971 c_parser_consume_token (parser);
1976 c_parser_error (parser, "expected %<,%> or %<}%>");
1977 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1978 values = error_mark_node;
1982 postfix_attrs = c_parser_attributes (parser);
1983 ret.spec = finish_enum (type, nreverse (values),
1984 chainon (attrs, postfix_attrs));
1985 ret.kind = ctsk_tagdef;
1986 ret.expr = NULL_TREE;
1987 ret.expr_const_operands = true;
1992 c_parser_error (parser, "expected %<{%>");
1993 ret.spec = error_mark_node;
1994 ret.kind = ctsk_tagref;
1995 ret.expr = NULL_TREE;
1996 ret.expr_const_operands = true;
1999 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
2000 /* In ISO C, enumerated types can be referred to only if already
2002 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
2005 pedwarn (enum_loc, OPT_pedantic,
2006 "ISO C forbids forward references to %<enum%> types");
2011 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2013 struct-or-union-specifier:
2014 struct-or-union attributes[opt] identifier[opt]
2015 { struct-contents } attributes[opt]
2016 struct-or-union attributes[opt] identifier
2019 struct-declaration-list
2021 struct-declaration-list:
2022 struct-declaration ;
2023 struct-declaration-list struct-declaration ;
2030 struct-declaration-list struct-declaration
2032 struct-declaration-list:
2033 struct-declaration-list ;
2036 (Note that in the syntax here, unlike that in ISO C, the semicolons
2037 are included here rather than in struct-declaration, in order to
2038 describe the syntax with extra semicolons and missing semicolon at
2043 struct-declaration-list:
2044 @defs ( class-name )
2046 (Note this does not include a trailing semicolon, but can be
2047 followed by further declarations, and gets a pedwarn-if-pedantic
2048 when followed by a semicolon.) */
2050 static struct c_typespec
2051 c_parser_struct_or_union_specifier (c_parser *parser)
2053 struct c_typespec ret;
2055 tree ident = NULL_TREE;
2056 location_t struct_loc;
2057 location_t ident_loc = UNKNOWN_LOCATION;
2058 enum tree_code code;
2059 switch (c_parser_peek_token (parser)->keyword)
2070 struct_loc = c_parser_peek_token (parser)->location;
2071 c_parser_consume_token (parser);
2072 attrs = c_parser_attributes (parser);
2074 /* Set the location in case we create a decl now. */
2075 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2077 if (c_parser_next_token_is (parser, CPP_NAME))
2079 ident = c_parser_peek_token (parser)->value;
2080 ident_loc = c_parser_peek_token (parser)->location;
2081 struct_loc = ident_loc;
2082 c_parser_consume_token (parser);
2084 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2086 /* Parse a struct or union definition. Start the scope of the
2087 tag before parsing components. */
2088 struct c_struct_parse_info *struct_info;
2089 tree type = start_struct (struct_loc, code, ident, &struct_info);
2091 /* We chain the components in reverse order, then put them in
2092 forward order at the end. Each struct-declaration may
2093 declare multiple components (comma-separated), so we must use
2094 chainon to join them, although when parsing each
2095 struct-declaration we can use TREE_CHAIN directly.
2097 The theory behind all this is that there will be more
2098 semicolon separated fields than comma separated fields, and
2099 so we'll be minimizing the number of node traversals required
2101 tree contents = NULL_TREE;
2102 c_parser_consume_token (parser);
2103 /* Handle the Objective-C @defs construct,
2104 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2105 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2108 gcc_assert (c_dialect_objc ());
2109 c_parser_consume_token (parser);
2110 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2112 if (c_parser_next_token_is (parser, CPP_NAME)
2113 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2115 name = c_parser_peek_token (parser)->value;
2116 c_parser_consume_token (parser);
2120 c_parser_error (parser, "expected class name");
2121 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2124 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2126 contents = nreverse (objc_get_class_ivars (name));
2129 /* Parse the struct-declarations and semicolons. Problems with
2130 semicolons are diagnosed here; empty structures are diagnosed
2135 /* Parse any stray semicolon. */
2136 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2138 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2139 "extra semicolon in struct or union specified");
2140 c_parser_consume_token (parser);
2143 /* Stop if at the end of the struct or union contents. */
2144 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2146 c_parser_consume_token (parser);
2149 /* Accept #pragmas at struct scope. */
2150 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2152 c_parser_pragma (parser, pragma_external);
2155 /* Parse some comma-separated declarations, but not the
2156 trailing semicolon if any. */
2157 decls = c_parser_struct_declaration (parser);
2158 contents = chainon (decls, contents);
2159 /* If no semicolon follows, either we have a parse error or
2160 are at the end of the struct or union and should
2162 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2163 c_parser_consume_token (parser);
2166 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2167 pedwarn (c_parser_peek_token (parser)->location, 0,
2168 "no semicolon at end of struct or union");
2171 c_parser_error (parser, "expected %<;%>");
2172 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2177 postfix_attrs = c_parser_attributes (parser);
2178 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2179 chainon (attrs, postfix_attrs), struct_info);
2180 ret.kind = ctsk_tagdef;
2181 ret.expr = NULL_TREE;
2182 ret.expr_const_operands = true;
2187 c_parser_error (parser, "expected %<{%>");
2188 ret.spec = error_mark_node;
2189 ret.kind = ctsk_tagref;
2190 ret.expr = NULL_TREE;
2191 ret.expr_const_operands = true;
2194 ret = parser_xref_tag (ident_loc, code, ident);
2198 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2199 the trailing semicolon.
2202 specifier-qualifier-list struct-declarator-list
2203 static_assert-declaration-no-semi
2205 specifier-qualifier-list:
2206 type-specifier specifier-qualifier-list[opt]
2207 type-qualifier specifier-qualifier-list[opt]
2208 attributes specifier-qualifier-list[opt]
2210 struct-declarator-list:
2212 struct-declarator-list , attributes[opt] struct-declarator
2215 declarator attributes[opt]
2216 declarator[opt] : constant-expression attributes[opt]
2221 __extension__ struct-declaration
2222 specifier-qualifier-list
2224 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2225 of attributes where shown is a GNU extension. In GNU C, we accept
2226 any expression without commas in the syntax (assignment
2227 expressions, not just conditional expressions); assignment
2228 expressions will be diagnosed as non-constant. */
2231 c_parser_struct_declaration (c_parser *parser)
2233 struct c_declspecs *specs;
2235 tree all_prefix_attrs;
2237 location_t decl_loc;
2238 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2242 ext = disable_extension_diagnostics ();
2243 c_parser_consume_token (parser);
2244 decl = c_parser_struct_declaration (parser);
2245 restore_extension_diagnostics (ext);
2248 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2250 c_parser_static_assert_declaration_no_semi (parser);
2253 specs = build_null_declspecs ();
2254 decl_loc = c_parser_peek_token (parser)->location;
2255 c_parser_declspecs (parser, specs, false, true, true);
2258 if (!specs->declspecs_seen_p)
2260 c_parser_error (parser, "expected specifier-qualifier-list");
2263 finish_declspecs (specs);
2264 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2267 if (!specs->type_seen_p)
2269 pedwarn (decl_loc, OPT_pedantic,
2270 "ISO C forbids member declarations with no members");
2271 shadow_tag_warned (specs, pedantic);
2276 /* Support for unnamed structs or unions as members of
2277 structs or unions (which is [a] useful and [b] supports
2281 ret = grokfield (c_parser_peek_token (parser)->location,
2282 build_id_declarator (NULL_TREE), specs,
2285 decl_attributes (&ret, attrs, 0);
2289 pending_xref_error ();
2290 prefix_attrs = specs->attrs;
2291 all_prefix_attrs = prefix_attrs;
2292 specs->attrs = NULL_TREE;
2296 /* Declaring one or more declarators or un-named bit-fields. */
2297 struct c_declarator *declarator;
2299 if (c_parser_next_token_is (parser, CPP_COLON))
2300 declarator = build_id_declarator (NULL_TREE);
2302 declarator = c_parser_declarator (parser, specs->type_seen_p,
2303 C_DTR_NORMAL, &dummy);
2304 if (declarator == NULL)
2306 c_parser_skip_to_end_of_block_or_statement (parser);
2309 if (c_parser_next_token_is (parser, CPP_COLON)
2310 || c_parser_next_token_is (parser, CPP_COMMA)
2311 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2312 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2313 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2315 tree postfix_attrs = NULL_TREE;
2316 tree width = NULL_TREE;
2318 if (c_parser_next_token_is (parser, CPP_COLON))
2320 c_parser_consume_token (parser);
2321 width = c_parser_expr_no_commas (parser, NULL).value;
2323 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2324 postfix_attrs = c_parser_attributes (parser);
2325 d = grokfield (c_parser_peek_token (parser)->location,
2326 declarator, specs, width, &all_prefix_attrs);
2327 decl_attributes (&d, chainon (postfix_attrs,
2328 all_prefix_attrs), 0);
2329 DECL_CHAIN (d) = decls;
2331 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2332 all_prefix_attrs = chainon (c_parser_attributes (parser),
2335 all_prefix_attrs = prefix_attrs;
2336 if (c_parser_next_token_is (parser, CPP_COMMA))
2337 c_parser_consume_token (parser);
2338 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2339 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2341 /* Semicolon consumed in caller. */
2346 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2352 c_parser_error (parser,
2353 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2354 "%<__attribute__%>");
2361 /* Parse a typeof specifier (a GNU extension).
2364 typeof ( expression )
2365 typeof ( type-name )
2368 static struct c_typespec
2369 c_parser_typeof_specifier (c_parser *parser)
2371 struct c_typespec ret;
2372 ret.kind = ctsk_typeof;
2373 ret.spec = error_mark_node;
2374 ret.expr = NULL_TREE;
2375 ret.expr_const_operands = true;
2376 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2377 c_parser_consume_token (parser);
2378 c_inhibit_evaluation_warnings++;
2380 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2382 c_inhibit_evaluation_warnings--;
2386 if (c_parser_next_token_starts_typename (parser))
2388 struct c_type_name *type = c_parser_type_name (parser);
2389 c_inhibit_evaluation_warnings--;
2393 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2394 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2400 location_t here = c_parser_peek_token (parser)->location;
2401 struct c_expr expr = c_parser_expression (parser);
2402 c_inhibit_evaluation_warnings--;
2404 if (TREE_CODE (expr.value) == COMPONENT_REF
2405 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2406 error_at (here, "%<typeof%> applied to a bit-field");
2407 mark_exp_read (expr.value);
2408 ret.spec = TREE_TYPE (expr.value);
2409 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2410 /* This is returned with the type so that when the type is
2411 evaluated, this can be evaluated. */
2413 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2414 pop_maybe_used (was_vm);
2416 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2420 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2421 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2422 be redeclared; otherwise it may not. KIND indicates which kind of
2423 declarator is wanted. Returns a valid declarator except in the
2424 case of a syntax error in which case NULL is returned. *SEEN_ID is
2425 set to true if an identifier being declared is seen; this is used
2426 to diagnose bad forms of abstract array declarators and to
2427 determine whether an identifier list is syntactically permitted.
2430 pointer[opt] direct-declarator
2434 ( attributes[opt] declarator )
2435 direct-declarator array-declarator
2436 direct-declarator ( parameter-type-list )
2437 direct-declarator ( identifier-list[opt] )
2440 * type-qualifier-list[opt]
2441 * type-qualifier-list[opt] pointer
2443 type-qualifier-list:
2446 type-qualifier-list type-qualifier
2447 type-qualifier-list attributes
2449 parameter-type-list:
2451 parameter-list , ...
2454 parameter-declaration
2455 parameter-list , parameter-declaration
2457 parameter-declaration:
2458 declaration-specifiers declarator attributes[opt]
2459 declaration-specifiers abstract-declarator[opt] attributes[opt]
2463 identifier-list , identifier
2465 abstract-declarator:
2467 pointer[opt] direct-abstract-declarator
2469 direct-abstract-declarator:
2470 ( attributes[opt] abstract-declarator )
2471 direct-abstract-declarator[opt] array-declarator
2472 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2477 direct-declarator ( parameter-forward-declarations
2478 parameter-type-list[opt] )
2480 direct-abstract-declarator:
2481 direct-abstract-declarator[opt] ( parameter-forward-declarations
2482 parameter-type-list[opt] )
2484 parameter-forward-declarations:
2486 parameter-forward-declarations parameter-list ;
2488 The uses of attributes shown above are GNU extensions.
2490 Some forms of array declarator are not included in C99 in the
2491 syntax for abstract declarators; these are disallowed elsewhere.
2492 This may be a defect (DR#289).
2494 This function also accepts an omitted abstract declarator as being
2495 an abstract declarator, although not part of the formal syntax. */
2497 static struct c_declarator *
2498 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2501 /* Parse any initial pointer part. */
2502 if (c_parser_next_token_is (parser, CPP_MULT))
2504 struct c_declspecs *quals_attrs = build_null_declspecs ();
2505 struct c_declarator *inner;
2506 c_parser_consume_token (parser);
2507 c_parser_declspecs (parser, quals_attrs, false, false, true);
2508 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2512 return make_pointer_declarator (quals_attrs, inner);
2514 /* Now we have a direct declarator, direct abstract declarator or
2515 nothing (which counts as a direct abstract declarator here). */
2516 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2519 /* Parse a direct declarator or direct abstract declarator; arguments
2520 as c_parser_declarator. */
2522 static struct c_declarator *
2523 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2526 /* The direct declarator must start with an identifier (possibly
2527 omitted) or a parenthesized declarator (possibly abstract). In
2528 an ordinary declarator, initial parentheses must start a
2529 parenthesized declarator. In an abstract declarator or parameter
2530 declarator, they could start a parenthesized declarator or a
2531 parameter list. To tell which, the open parenthesis and any
2532 following attributes must be read. If a declaration specifier
2533 follows, then it is a parameter list; if the specifier is a
2534 typedef name, there might be an ambiguity about redeclaring it,
2535 which is resolved in the direction of treating it as a typedef
2536 name. If a close parenthesis follows, it is also an empty
2537 parameter list, as the syntax does not permit empty abstract
2538 declarators. Otherwise, it is a parenthesized declarator (in
2539 which case the analysis may be repeated inside it, recursively).
2541 ??? There is an ambiguity in a parameter declaration "int
2542 (__attribute__((foo)) x)", where x is not a typedef name: it
2543 could be an abstract declarator for a function, or declare x with
2544 parentheses. The proper resolution of this ambiguity needs
2545 documenting. At present we follow an accident of the old
2546 parser's implementation, whereby the first parameter must have
2547 some declaration specifiers other than just attributes. Thus as
2548 a parameter declaration it is treated as a parenthesized
2549 parameter named x, and as an abstract declarator it is
2552 ??? Also following the old parser, attributes inside an empty
2553 parameter list are ignored, making it a list not yielding a
2554 prototype, rather than giving an error or making it have one
2555 parameter with implicit type int.
2557 ??? Also following the old parser, typedef names may be
2558 redeclared in declarators, but not Objective-C class names. */
2560 if (kind != C_DTR_ABSTRACT
2561 && c_parser_next_token_is (parser, CPP_NAME)
2563 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2564 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2566 struct c_declarator *inner
2567 = build_id_declarator (c_parser_peek_token (parser)->value);
2569 inner->id_loc = c_parser_peek_token (parser)->location;
2570 c_parser_consume_token (parser);
2571 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2574 if (kind != C_DTR_NORMAL
2575 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2577 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2578 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2581 /* Either we are at the end of an abstract declarator, or we have
2584 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2587 struct c_declarator *inner;
2588 c_parser_consume_token (parser);
2589 attrs = c_parser_attributes (parser);
2590 if (kind != C_DTR_NORMAL
2591 && (c_parser_next_token_starts_declspecs (parser)
2592 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2594 struct c_arg_info *args
2595 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2602 = build_function_declarator (args,
2603 build_id_declarator (NULL_TREE));
2604 return c_parser_direct_declarator_inner (parser, *seen_id,
2608 /* A parenthesized declarator. */
2609 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2610 if (inner != NULL && attrs != NULL)
2611 inner = build_attrs_declarator (attrs, inner);
2612 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2614 c_parser_consume_token (parser);
2618 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2622 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2629 if (kind == C_DTR_NORMAL)
2631 c_parser_error (parser, "expected identifier or %<(%>");
2635 return build_id_declarator (NULL_TREE);
2639 /* Parse part of a direct declarator or direct abstract declarator,
2640 given that some (in INNER) has already been parsed; ID_PRESENT is
2641 true if an identifier is present, false for an abstract
2644 static struct c_declarator *
2645 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2646 struct c_declarator *inner)
2648 /* Parse a sequence of array declarators and parameter lists. */
2649 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2651 location_t brace_loc = c_parser_peek_token (parser)->location;
2652 struct c_declarator *declarator;
2653 struct c_declspecs *quals_attrs = build_null_declspecs ();
2657 c_parser_consume_token (parser);
2658 c_parser_declspecs (parser, quals_attrs, false, false, true);
2659 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2661 c_parser_consume_token (parser);
2662 if (static_seen && !quals_attrs->declspecs_seen_p)
2663 c_parser_declspecs (parser, quals_attrs, false, false, true);
2664 if (!quals_attrs->declspecs_seen_p)
2666 /* If "static" is present, there must be an array dimension.
2667 Otherwise, there may be a dimension, "*", or no
2672 dimen = c_parser_expr_no_commas (parser, NULL).value;
2676 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2681 else if (c_parser_next_token_is (parser, CPP_MULT))
2683 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2687 c_parser_consume_token (parser);
2692 dimen = c_parser_expr_no_commas (parser, NULL).value;
2698 dimen = c_parser_expr_no_commas (parser, NULL).value;
2701 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2702 c_parser_consume_token (parser);
2705 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2710 mark_exp_read (dimen);
2711 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2712 static_seen, star_seen);
2713 if (declarator == NULL)
2715 inner = set_array_declarator_inner (declarator, inner);
2716 return c_parser_direct_declarator_inner (parser, id_present, inner);
2718 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2721 struct c_arg_info *args;
2722 c_parser_consume_token (parser);
2723 attrs = c_parser_attributes (parser);
2724 args = c_parser_parms_declarator (parser, id_present, attrs);
2729 inner = build_function_declarator (args, inner);
2730 return c_parser_direct_declarator_inner (parser, id_present, inner);
2736 /* Parse a parameter list or identifier list, including the closing
2737 parenthesis but not the opening one. ATTRS are the attributes at
2738 the start of the list. ID_LIST_OK is true if an identifier list is
2739 acceptable; such a list must not have attributes at the start. */
2741 static struct c_arg_info *
2742 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2745 declare_parm_level ();
2746 /* If the list starts with an identifier, it is an identifier list.
2747 Otherwise, it is either a prototype list or an empty list. */
2750 && c_parser_next_token_is (parser, CPP_NAME)
2751 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2753 tree list = NULL_TREE, *nextp = &list;
2754 while (c_parser_next_token_is (parser, CPP_NAME)
2755 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2757 *nextp = build_tree_list (NULL_TREE,
2758 c_parser_peek_token (parser)->value);
2759 nextp = & TREE_CHAIN (*nextp);
2760 c_parser_consume_token (parser);
2761 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2763 c_parser_consume_token (parser);
2764 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2766 c_parser_error (parser, "expected identifier");
2770 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2772 struct c_arg_info *ret = build_arg_info ();
2774 c_parser_consume_token (parser);
2780 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2788 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2794 /* Parse a parameter list (possibly empty), including the closing
2795 parenthesis but not the opening one. ATTRS are the attributes at
2796 the start of the list. */
2798 static struct c_arg_info *
2799 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2801 bool bad_parm = false;
2802 /* ??? Following the old parser, forward parameter declarations may
2803 use abstract declarators, and if no real parameter declarations
2804 follow the forward declarations then this is not diagnosed. Also
2805 note as above that attributes are ignored as the only contents of
2806 the parentheses, or as the only contents after forward
2808 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2810 struct c_arg_info *ret = build_arg_info ();
2811 c_parser_consume_token (parser);
2814 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2816 struct c_arg_info *ret = build_arg_info ();
2817 /* Suppress -Wold-style-definition for this case. */
2818 ret->types = error_mark_node;
2819 error_at (c_parser_peek_token (parser)->location,
2820 "ISO C requires a named argument before %<...%>");
2821 c_parser_consume_token (parser);
2822 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2824 c_parser_consume_token (parser);
2829 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2834 /* Nonempty list of parameters, either terminated with semicolon
2835 (forward declarations; recurse) or with close parenthesis (normal
2836 function) or with ", ... )" (variadic function). */
2839 /* Parse a parameter. */
2840 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2845 push_parm_decl (parm);
2846 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2849 c_parser_consume_token (parser);
2850 mark_forward_parm_decls ();
2851 new_attrs = c_parser_attributes (parser);
2852 return c_parser_parms_list_declarator (parser, new_attrs);
2854 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2856 c_parser_consume_token (parser);
2859 get_pending_sizes ();
2863 return get_parm_info (false);
2865 if (!c_parser_require (parser, CPP_COMMA,
2866 "expected %<;%>, %<,%> or %<)%>"))
2868 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2869 get_pending_sizes ();
2872 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2874 c_parser_consume_token (parser);
2875 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2877 c_parser_consume_token (parser);
2880 get_pending_sizes ();
2884 return get_parm_info (true);
2888 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2890 get_pending_sizes ();
2897 /* Parse a parameter declaration. ATTRS are the attributes at the
2898 start of the declaration if it is the first parameter. */
2900 static struct c_parm *
2901 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2903 struct c_declspecs *specs;
2904 struct c_declarator *declarator;
2906 tree postfix_attrs = NULL_TREE;
2908 if (!c_parser_next_token_starts_declspecs (parser))
2910 c_token *token = c_parser_peek_token (parser);
2913 c_parser_set_source_position_from_token (token);
2914 if (token->type == CPP_NAME
2915 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
2916 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
2918 error ("unknown type name %qE", token->value);
2919 parser->error = true;
2921 /* ??? In some Objective-C cases '...' isn't applicable so there
2922 should be a different message. */
2924 c_parser_error (parser,
2925 "expected declaration specifiers or %<...%>");
2926 c_parser_skip_to_end_of_parameter (parser);
2929 specs = build_null_declspecs ();
2932 declspecs_add_attrs (specs, attrs);
2935 c_parser_declspecs (parser, specs, true, true, true);
2936 finish_declspecs (specs);
2937 pending_xref_error ();
2938 prefix_attrs = specs->attrs;
2939 specs->attrs = NULL_TREE;
2940 declarator = c_parser_declarator (parser, specs->type_seen_p,
2941 C_DTR_PARM, &dummy);
2942 if (declarator == NULL)
2944 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2947 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2948 postfix_attrs = c_parser_attributes (parser);
2949 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2953 /* Parse a string literal in an asm expression. It should not be
2954 translated, and wide string literals are an error although
2955 permitted by the syntax. This is a GNU extension.
2960 ??? At present, following the old parser, the caller needs to have
2961 set lex_untranslated_string to 1. It would be better to follow the
2962 C++ parser rather than using this kludge. */
2965 c_parser_asm_string_literal (c_parser *parser)
2968 if (c_parser_next_token_is (parser, CPP_STRING))
2970 str = c_parser_peek_token (parser)->value;
2971 c_parser_consume_token (parser);
2973 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2975 error_at (c_parser_peek_token (parser)->location,
2976 "wide string literal in %<asm%>");
2977 str = build_string (1, "");
2978 c_parser_consume_token (parser);
2982 c_parser_error (parser, "expected string literal");
2988 /* Parse a simple asm expression. This is used in restricted
2989 contexts, where a full expression with inputs and outputs does not
2990 make sense. This is a GNU extension.
2993 asm ( asm-string-literal )
2997 c_parser_simple_asm_expr (c_parser *parser)
3000 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
3001 /* ??? Follow the C++ parser rather than using the
3002 lex_untranslated_string kludge. */
3003 parser->lex_untranslated_string = true;
3004 c_parser_consume_token (parser);
3005 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3007 parser->lex_untranslated_string = false;
3010 str = c_parser_asm_string_literal (parser);
3011 parser->lex_untranslated_string = false;
3012 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
3014 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3020 /* Parse (possibly empty) attributes. This is a GNU extension.
3024 attributes attribute
3027 __attribute__ ( ( attribute-list ) )
3031 attribute_list , attrib
3036 any-word ( identifier )
3037 any-word ( identifier , nonempty-expr-list )
3038 any-word ( expr-list )
3040 where the "identifier" must not be declared as a type, and
3041 "any-word" may be any identifier (including one declared as a
3042 type), a reserved word storage class specifier, type specifier or
3043 type qualifier. ??? This still leaves out most reserved keywords
3044 (following the old parser), shouldn't we include them, and why not
3045 allow identifiers declared as types to start the arguments? */
3048 c_parser_attributes (c_parser *parser)
3050 tree attrs = NULL_TREE;
3051 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3053 /* ??? Follow the C++ parser rather than using the
3054 lex_untranslated_string kludge. */
3055 parser->lex_untranslated_string = true;
3056 c_parser_consume_token (parser);
3057 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3059 parser->lex_untranslated_string = false;
3062 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3064 parser->lex_untranslated_string = false;
3065 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3068 /* Parse the attribute list. */
3069 while (c_parser_next_token_is (parser, CPP_COMMA)
3070 || c_parser_next_token_is (parser, CPP_NAME)
3071 || c_parser_next_token_is (parser, CPP_KEYWORD))
3073 tree attr, attr_name, attr_args;
3074 VEC(tree,gc) *expr_list;
3075 if (c_parser_next_token_is (parser, CPP_COMMA))
3077 c_parser_consume_token (parser);
3080 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3082 /* ??? See comment above about what keywords are
3085 switch (c_parser_peek_token (parser)->keyword)
3123 /* Accept __attribute__((__const)) as __attribute__((const))
3126 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3129 attr_name = c_parser_peek_token (parser)->value;
3130 c_parser_consume_token (parser);
3131 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3133 attr = build_tree_list (attr_name, NULL_TREE);
3134 attrs = chainon (attrs, attr);
3137 c_parser_consume_token (parser);
3138 /* Parse the attribute contents. If they start with an
3139 identifier which is followed by a comma or close
3140 parenthesis, then the arguments start with that
3141 identifier; otherwise they are an expression list. */
3142 if (c_parser_next_token_is (parser, CPP_NAME)
3143 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3144 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3145 || (c_parser_peek_2nd_token (parser)->type
3146 == CPP_CLOSE_PAREN)))
3148 tree arg1 = c_parser_peek_token (parser)->value;
3149 c_parser_consume_token (parser);
3150 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3151 attr_args = build_tree_list (NULL_TREE, arg1);
3155 c_parser_consume_token (parser);
3156 expr_list = c_parser_expr_list (parser, false, true, NULL);
3157 tree_list = build_tree_list_vec (expr_list);
3158 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3159 release_tree_vector (expr_list);
3164 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3165 attr_args = NULL_TREE;
3168 expr_list = c_parser_expr_list (parser, false, true, NULL);
3169 attr_args = build_tree_list_vec (expr_list);
3170 release_tree_vector (expr_list);
3173 attr = build_tree_list (attr_name, attr_args);
3174 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3175 c_parser_consume_token (parser);
3178 parser->lex_untranslated_string = false;
3179 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3183 attrs = chainon (attrs, attr);
3185 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3186 c_parser_consume_token (parser);
3189 parser->lex_untranslated_string = false;
3190 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3194 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3195 c_parser_consume_token (parser);
3198 parser->lex_untranslated_string = false;
3199 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3203 parser->lex_untranslated_string = false;
3208 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3211 specifier-qualifier-list abstract-declarator[opt]
3214 static struct c_type_name *
3215 c_parser_type_name (c_parser *parser)
3217 struct c_declspecs *specs = build_null_declspecs ();
3218 struct c_declarator *declarator;
3219 struct c_type_name *ret;
3221 c_parser_declspecs (parser, specs, false, true, true);
3222 if (!specs->declspecs_seen_p)
3224 c_parser_error (parser, "expected specifier-qualifier-list");
3227 pending_xref_error ();
3228 finish_declspecs (specs);
3229 declarator = c_parser_declarator (parser, specs->type_seen_p,
3230 C_DTR_ABSTRACT, &dummy);
3231 if (declarator == NULL)
3233 ret = XOBNEW (&parser_obstack, struct c_type_name);
3235 ret->declarator = declarator;
3239 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3242 assignment-expression
3243 { initializer-list }
3244 { initializer-list , }
3247 designation[opt] initializer
3248 initializer-list , designation[opt] initializer
3255 designator-list designator
3262 [ constant-expression ]
3274 [ constant-expression ... constant-expression ]
3276 Any expression without commas is accepted in the syntax for the
3277 constant-expressions, with non-constant expressions rejected later.
3279 This function is only used for top-level initializers; for nested
3280 ones, see c_parser_initval. */
3282 static struct c_expr
3283 c_parser_initializer (c_parser *parser)
3285 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3286 return c_parser_braced_init (parser, NULL_TREE, false);
3290 location_t loc = c_parser_peek_token (parser)->location;
3291 ret = c_parser_expr_no_commas (parser, NULL);
3292 if (TREE_CODE (ret.value) != STRING_CST
3293 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3294 ret = default_function_array_read_conversion (loc, ret);
3299 /* Parse a braced initializer list. TYPE is the type specified for a
3300 compound literal, and NULL_TREE for other initializers and for
3301 nested braced lists. NESTED_P is true for nested braced lists,
3302 false for the list of a compound literal or the list that is the
3303 top-level initializer in a declaration. */
3305 static struct c_expr
3306 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3309 struct obstack braced_init_obstack;
3310 location_t brace_loc = c_parser_peek_token (parser)->location;
3311 gcc_obstack_init (&braced_init_obstack);
3312 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3313 c_parser_consume_token (parser);
3315 push_init_level (0, &braced_init_obstack);
3317 really_start_incremental_init (type);
3318 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3320 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3324 /* Parse a non-empty initializer list, possibly with a trailing
3328 c_parser_initelt (parser, &braced_init_obstack);
3331 if (c_parser_next_token_is (parser, CPP_COMMA))
3332 c_parser_consume_token (parser);
3335 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3339 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3341 ret.value = error_mark_node;
3342 ret.original_code = ERROR_MARK;
3343 ret.original_type = NULL;
3344 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3345 pop_init_level (0, &braced_init_obstack);
3346 obstack_free (&braced_init_obstack, NULL);
3349 c_parser_consume_token (parser);
3350 ret = pop_init_level (0, &braced_init_obstack);
3351 obstack_free (&braced_init_obstack, NULL);
3355 /* Parse a nested initializer, including designators. */
3358 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3360 /* Parse any designator or designator list. A single array
3361 designator may have the subsequent "=" omitted in GNU C, but a
3362 longer list or a structure member designator may not. */
3363 if (c_parser_next_token_is (parser, CPP_NAME)
3364 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3366 /* Old-style structure member designator. */
3367 set_init_label (c_parser_peek_token (parser)->value,
3368 braced_init_obstack);
3369 /* Use the colon as the error location. */
3370 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3371 "obsolete use of designated initializer with %<:%>");
3372 c_parser_consume_token (parser);
3373 c_parser_consume_token (parser);
3377 /* des_seen is 0 if there have been no designators, 1 if there
3378 has been a single array designator and 2 otherwise. */
3380 /* Location of a designator. */
3381 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3382 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3383 || c_parser_next_token_is (parser, CPP_DOT))
3385 int des_prev = des_seen;
3387 des_loc = c_parser_peek_token (parser)->location;
3390 if (c_parser_next_token_is (parser, CPP_DOT))
3393 c_parser_consume_token (parser);
3394 if (c_parser_next_token_is (parser, CPP_NAME))
3396 set_init_label (c_parser_peek_token (parser)->value,
3397 braced_init_obstack);
3398 c_parser_consume_token (parser);
3403 init.value = error_mark_node;
3404 init.original_code = ERROR_MARK;
3405 init.original_type = NULL;
3406 c_parser_error (parser, "expected identifier");
3407 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3408 process_init_element (init, false, braced_init_obstack);
3415 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3416 /* ??? Following the old parser, [ objc-receiver
3417 objc-message-args ] is accepted as an initializer,
3418 being distinguished from a designator by what follows
3419 the first assignment expression inside the square
3420 brackets, but after a first array designator a
3421 subsequent square bracket is for Objective-C taken to
3422 start an expression, using the obsolete form of
3423 designated initializer without '=', rather than
3424 possibly being a second level of designation: in LALR
3425 terms, the '[' is shifted rather than reducing
3426 designator to designator-list. */
3427 if (des_prev == 1 && c_dialect_objc ())
3429 des_seen = des_prev;
3432 if (des_prev == 0 && c_dialect_objc ())
3434 /* This might be an array designator or an
3435 Objective-C message expression. If the former,
3436 continue parsing here; if the latter, parse the
3437 remainder of the initializer given the starting
3438 primary-expression. ??? It might make sense to
3439 distinguish when des_prev == 1 as well; see
3440 previous comment. */
3442 struct c_expr mexpr;
3443 c_parser_consume_token (parser);
3444 if (c_parser_peek_token (parser)->type == CPP_NAME
3445 && ((c_parser_peek_token (parser)->id_kind
3447 || (c_parser_peek_token (parser)->id_kind
3448 == C_ID_CLASSNAME)))
3450 /* Type name receiver. */
3451 tree id = c_parser_peek_token (parser)->value;
3452 c_parser_consume_token (parser);
3453 rec = objc_get_class_reference (id);
3454 goto parse_message_args;
3456 first = c_parser_expr_no_commas (parser, NULL).value;
3457 mark_exp_read (first);
3458 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3459 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3460 goto array_desig_after_first;
3461 /* Expression receiver. So far only one part
3462 without commas has been parsed; there might be
3463 more of the expression. */
3465 while (c_parser_next_token_is (parser, CPP_COMMA))
3468 location_t comma_loc, exp_loc;
3469 comma_loc = c_parser_peek_token (parser)->location;
3470 c_parser_consume_token (parser);
3471 exp_loc = c_parser_peek_token (parser)->location;
3472 next = c_parser_expr_no_commas (parser, NULL);
3473 next = default_function_array_read_conversion (exp_loc,
3475 rec = build_compound_expr (comma_loc, rec, next.value);
3478 /* Now parse the objc-message-args. */
3479 args = c_parser_objc_message_args (parser);
3480 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3483 = objc_build_message_expr (build_tree_list (rec, args));
3484 mexpr.original_code = ERROR_MARK;
3485 mexpr.original_type = NULL;
3486 /* Now parse and process the remainder of the
3487 initializer, starting with this message
3488 expression as a primary-expression. */
3489 c_parser_initval (parser, &mexpr, braced_init_obstack);
3492 c_parser_consume_token (parser);
3493 first = c_parser_expr_no_commas (parser, NULL).value;
3494 mark_exp_read (first);
3495 array_desig_after_first:
3496 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3498 ellipsis_loc = c_parser_peek_token (parser)->location;
3499 c_parser_consume_token (parser);
3500 second = c_parser_expr_no_commas (parser, NULL).value;
3501 mark_exp_read (second);
3505 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3507 c_parser_consume_token (parser);
3508 set_init_index (first, second, braced_init_obstack);
3510 pedwarn (ellipsis_loc, OPT_pedantic,
3511 "ISO C forbids specifying range of elements to initialize");
3514 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3520 if (c_parser_next_token_is (parser, CPP_EQ))
3523 pedwarn (des_loc, OPT_pedantic,
3524 "ISO C90 forbids specifying subobject to initialize");
3525 c_parser_consume_token (parser);
3530 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3531 "obsolete use of designated initializer without %<=%>");
3535 init.value = error_mark_node;
3536 init.original_code = ERROR_MARK;
3537 init.original_type = NULL;
3538 c_parser_error (parser, "expected %<=%>");
3539 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3540 process_init_element (init, false, braced_init_obstack);
3546 c_parser_initval (parser, NULL, braced_init_obstack);
3549 /* Parse a nested initializer; as c_parser_initializer but parses
3550 initializers within braced lists, after any designators have been
3551 applied. If AFTER is not NULL then it is an Objective-C message
3552 expression which is the primary-expression starting the
3556 c_parser_initval (c_parser *parser, struct c_expr *after,
3557 struct obstack * braced_init_obstack)
3560 gcc_assert (!after || c_dialect_objc ());
3561 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3562 init = c_parser_braced_init (parser, NULL_TREE, true);
3565 location_t loc = c_parser_peek_token (parser)->location;
3566 init = c_parser_expr_no_commas (parser, after);
3567 if (init.value != NULL_TREE
3568 && TREE_CODE (init.value) != STRING_CST
3569 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3570 init = default_function_array_read_conversion (loc, init);
3572 process_init_element (init, false, braced_init_obstack);
3575 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3579 { block-item-list[opt] }
3580 { label-declarations block-item-list }
3584 block-item-list block-item
3596 { label-declarations block-item-list }
3599 __extension__ nested-declaration
3600 nested-function-definition
3604 label-declarations label-declaration
3607 __label__ identifier-list ;
3609 Allowing the mixing of declarations and code is new in C99. The
3610 GNU syntax also permits (not shown above) labels at the end of
3611 compound statements, which yield an error. We don't allow labels
3612 on declarations; this might seem like a natural extension, but
3613 there would be a conflict between attributes on the label and
3614 prefix attributes on the declaration. ??? The syntax follows the
3615 old parser in requiring something after label declarations.
3616 Although they are erroneous if the labels declared aren't defined,
3617 is it useful for the syntax to be this way?
3629 c_parser_compound_statement (c_parser *parser)
3632 location_t brace_loc;
3633 brace_loc = c_parser_peek_token (parser)->location;
3634 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3636 /* Ensure a scope is entered and left anyway to avoid confusion
3637 if we have just prepared to enter a function body. */
3638 stmt = c_begin_compound_stmt (true);
3639 c_end_compound_stmt (brace_loc, stmt, true);
3640 return error_mark_node;
3642 stmt = c_begin_compound_stmt (true);
3643 c_parser_compound_statement_nostart (parser);
3644 return c_end_compound_stmt (brace_loc, stmt, true);
3647 /* Parse a compound statement except for the opening brace. This is
3648 used for parsing both compound statements and statement expressions
3649 (which follow different paths to handling the opening). */
3652 c_parser_compound_statement_nostart (c_parser *parser)
3654 bool last_stmt = false;
3655 bool last_label = false;
3656 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3657 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3658 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3660 c_parser_consume_token (parser);
3663 mark_valid_location_for_stdc_pragma (true);
3664 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3666 /* Read zero or more forward-declarations for labels that nested
3667 functions can jump to. */
3668 mark_valid_location_for_stdc_pragma (false);
3669 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3671 label_loc = c_parser_peek_token (parser)->location;
3672 c_parser_consume_token (parser);
3673 /* Any identifiers, including those declared as type names,
3678 if (c_parser_next_token_is_not (parser, CPP_NAME))
3680 c_parser_error (parser, "expected identifier");
3684 = declare_label (c_parser_peek_token (parser)->value);
3685 C_DECLARED_LABEL_FLAG (label) = 1;
3686 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3687 c_parser_consume_token (parser);
3688 if (c_parser_next_token_is (parser, CPP_COMMA))
3689 c_parser_consume_token (parser);
3693 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3695 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3697 /* We must now have at least one statement, label or declaration. */
3698 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3700 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3701 c_parser_error (parser, "expected declaration or statement");
3702 c_parser_consume_token (parser);
3705 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3707 location_t loc = c_parser_peek_token (parser)->location;
3708 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3709 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3710 || (c_parser_next_token_is (parser, CPP_NAME)
3711 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3713 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3714 label_loc = c_parser_peek_2nd_token (parser)->location;
3716 label_loc = c_parser_peek_token (parser)->location;
3719 mark_valid_location_for_stdc_pragma (false);
3720 c_parser_label (parser);
3722 else if (!last_label
3723 && c_parser_next_token_starts_declaration (parser))
3726 mark_valid_location_for_stdc_pragma (false);
3727 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
3730 (pedantic && !flag_isoc99)
3732 : OPT_Wdeclaration_after_statement,
3733 "ISO C90 forbids mixed declarations and code");
3736 else if (!last_label
3737 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3739 /* __extension__ can start a declaration, but is also an
3740 unary operator that can start an expression. Consume all
3741 but the last of a possible series of __extension__ to
3743 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3744 && (c_parser_peek_2nd_token (parser)->keyword
3746 c_parser_consume_token (parser);
3747 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3750 ext = disable_extension_diagnostics ();
3751 c_parser_consume_token (parser);
3753 mark_valid_location_for_stdc_pragma (false);
3754 c_parser_declaration_or_fndef (parser, true, true, true, true,
3756 /* Following the old parser, __extension__ does not
3757 disable this diagnostic. */
3758 restore_extension_diagnostics (ext);
3760 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3762 : OPT_Wdeclaration_after_statement,
3763 "ISO C90 forbids mixed declarations and code");
3769 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3771 /* External pragmas, and some omp pragmas, are not associated
3772 with regular c code, and so are not to be considered statements
3773 syntactically. This ensures that the user doesn't put them
3774 places that would turn into syntax errors if the directive
3776 if (c_parser_pragma (parser, pragma_compound))
3777 last_label = false, last_stmt = true;
3779 else if (c_parser_next_token_is (parser, CPP_EOF))
3781 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3782 c_parser_error (parser, "expected declaration or statement");
3785 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3787 if (parser->in_if_block)
3789 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3790 error_at (loc, """expected %<}%> before %<else%>");
3795 error_at (loc, "%<else%> without a previous %<if%>");
3796 c_parser_consume_token (parser);
3805 mark_valid_location_for_stdc_pragma (false);
3806 c_parser_statement_after_labels (parser);
3809 parser->error = false;
3812 error_at (label_loc, "label at end of compound statement");
3813 c_parser_consume_token (parser);
3814 /* Restore the value we started with. */
3815 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3818 /* Parse a label (C90 6.6.1, C99 6.8.1).
3821 identifier : attributes[opt]
3822 case constant-expression :
3828 case constant-expression ... constant-expression :
3830 The use of attributes on labels is a GNU extension. The syntax in
3831 GNU C accepts any expressions without commas, non-constant
3832 expressions being rejected later. */
3835 c_parser_label (c_parser *parser)
3837 location_t loc1 = c_parser_peek_token (parser)->location;
3838 tree label = NULL_TREE;
3839 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3842 c_parser_consume_token (parser);
3843 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3844 if (c_parser_next_token_is (parser, CPP_COLON))
3846 c_parser_consume_token (parser);
3847 label = do_case (loc1, exp1, NULL_TREE);
3849 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3851 c_parser_consume_token (parser);
3852 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3853 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3854 label = do_case (loc1, exp1, exp2);
3857 c_parser_error (parser, "expected %<:%> or %<...%>");
3859 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3861 c_parser_consume_token (parser);
3862 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3863 label = do_case (loc1, NULL_TREE, NULL_TREE);
3867 tree name = c_parser_peek_token (parser)->value;
3870 location_t loc2 = c_parser_peek_token (parser)->location;
3871 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3872 c_parser_consume_token (parser);
3873 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3874 c_parser_consume_token (parser);
3875 attrs = c_parser_attributes (parser);
3876 tlab = define_label (loc2, name);
3879 decl_attributes (&tlab, attrs, 0);
3880 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3885 if (c_parser_next_token_starts_declaration (parser)
3886 && !(c_parser_next_token_is (parser, CPP_NAME)
3887 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3889 error_at (c_parser_peek_token (parser)->location,
3890 "a label can only be part of a statement and "
3891 "a declaration is not a statement");
3892 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3893 /*static_assert_ok*/ true,
3894 /*nested*/ true, /*empty_ok*/ false,
3895 /*start_attr_ok*/ true);
3900 /* Parse a statement (C90 6.6, C99 6.8).
3905 expression-statement
3913 expression-statement:
3916 selection-statement:
3920 iteration-statement:
3929 return expression[opt] ;
3942 objc-throw-statement
3943 objc-try-catch-statement
3944 objc-synchronized-statement
3946 objc-throw-statement:
3960 parallel-for-construct
3961 parallel-sections-construct
3968 parallel-directive structured-block
3971 for-directive iteration-statement
3974 sections-directive section-scope
3977 single-directive structured-block
3979 parallel-for-construct:
3980 parallel-for-directive iteration-statement
3982 parallel-sections-construct:
3983 parallel-sections-directive section-scope
3986 master-directive structured-block
3989 critical-directive structured-block
3992 atomic-directive expression-statement
3995 ordered-directive structured-block */
3998 c_parser_statement (c_parser *parser)
4000 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4001 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4002 || (c_parser_next_token_is (parser, CPP_NAME)
4003 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4004 c_parser_label (parser);
4005 c_parser_statement_after_labels (parser);
4008 /* Parse a statement, other than a labeled statement. */
4011 c_parser_statement_after_labels (c_parser *parser)
4013 location_t loc = c_parser_peek_token (parser)->location;
4014 tree stmt = NULL_TREE;
4015 bool in_if_block = parser->in_if_block;
4016 parser->in_if_block = false;
4017 switch (c_parser_peek_token (parser)->type)
4019 case CPP_OPEN_BRACE:
4020 add_stmt (c_parser_compound_statement (parser));
4023 switch (c_parser_peek_token (parser)->keyword)
4026 c_parser_if_statement (parser);
4029 c_parser_switch_statement (parser);
4032 c_parser_while_statement (parser);
4035 c_parser_do_statement (parser);
4038 c_parser_for_statement (parser);
4041 c_parser_consume_token (parser);
4042 if (c_parser_next_token_is (parser, CPP_NAME))
4044 stmt = c_finish_goto_label (loc,
4045 c_parser_peek_token (parser)->value);
4046 c_parser_consume_token (parser);
4048 else if (c_parser_next_token_is (parser, CPP_MULT))
4050 c_parser_consume_token (parser);
4051 stmt = c_finish_goto_ptr (loc,
4052 c_parser_expression (parser).value);
4055 c_parser_error (parser, "expected identifier or %<*%>");
4056 goto expect_semicolon;
4058 c_parser_consume_token (parser);
4059 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4060 goto expect_semicolon;
4062 c_parser_consume_token (parser);
4063 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4064 goto expect_semicolon;
4066 c_parser_consume_token (parser);
4067 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4069 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4070 c_parser_consume_token (parser);
4074 struct c_expr expr = c_parser_expression_conv (parser);
4075 mark_exp_read (expr.value);
4076 stmt = c_finish_return (loc, expr.value, expr.original_type);
4077 goto expect_semicolon;
4081 stmt = c_parser_asm_statement (parser);
4084 gcc_assert (c_dialect_objc ());
4085 c_parser_consume_token (parser);
4086 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4088 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4089 c_parser_consume_token (parser);
4093 tree expr = c_parser_expression (parser).value;
4094 expr = c_fully_fold (expr, false, NULL);
4095 stmt = objc_build_throw_stmt (loc, expr);
4096 goto expect_semicolon;
4100 gcc_assert (c_dialect_objc ());
4101 c_parser_objc_try_catch_statement (parser);
4103 case RID_AT_SYNCHRONIZED:
4104 gcc_assert (c_dialect_objc ());
4105 c_parser_objc_synchronized_statement (parser);
4112 c_parser_consume_token (parser);
4114 case CPP_CLOSE_PAREN:
4115 case CPP_CLOSE_SQUARE:
4116 /* Avoid infinite loop in error recovery:
4117 c_parser_skip_until_found stops at a closing nesting
4118 delimiter without consuming it, but here we need to consume
4119 it to proceed further. */
4120 c_parser_error (parser, "expected statement");
4121 c_parser_consume_token (parser);
4124 c_parser_pragma (parser, pragma_stmt);
4128 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4130 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4133 /* Two cases cannot and do not have line numbers associated: If stmt
4134 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4135 cannot hold line numbers. But that's OK because the statement
4136 will either be changed to a MODIFY_EXPR during gimplification of
4137 the statement expr, or discarded. If stmt was compound, but
4138 without new variables, we will have skipped the creation of a
4139 BIND and will have a bare STATEMENT_LIST. But that's OK because
4140 (recursively) all of the component statements should already have
4141 line numbers assigned. ??? Can we discard no-op statements
4143 if (CAN_HAVE_LOCATION_P (stmt)
4144 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4145 SET_EXPR_LOCATION (stmt, loc);
4147 parser->in_if_block = in_if_block;
4150 /* Parse the condition from an if, do, while or for statements. */
4153 c_parser_condition (c_parser *parser)
4155 location_t loc = c_parser_peek_token (parser)->location;
4157 cond = c_parser_expression_conv (parser).value;
4158 cond = c_objc_common_truthvalue_conversion (loc, cond);
4159 cond = c_fully_fold (cond, false, NULL);
4160 if (warn_sequence_point)
4161 verify_sequence_points (cond);
4165 /* Parse a parenthesized condition from an if, do or while statement.
4171 c_parser_paren_condition (c_parser *parser)
4174 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4175 return error_mark_node;
4176 cond = c_parser_condition (parser);
4177 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4181 /* Parse a statement which is a block in C99. */
4184 c_parser_c99_block_statement (c_parser *parser)
4186 tree block = c_begin_compound_stmt (flag_isoc99);
4187 location_t loc = c_parser_peek_token (parser)->location;
4188 c_parser_statement (parser);
4189 return c_end_compound_stmt (loc, block, flag_isoc99);
4192 /* Parse the body of an if statement. This is just parsing a
4193 statement but (a) it is a block in C99, (b) we track whether the
4194 body is an if statement for the sake of -Wparentheses warnings, (c)
4195 we handle an empty body specially for the sake of -Wempty-body
4196 warnings, and (d) we call parser_compound_statement directly
4197 because c_parser_statement_after_labels resets
4198 parser->in_if_block. */
4201 c_parser_if_body (c_parser *parser, bool *if_p)
4203 tree block = c_begin_compound_stmt (flag_isoc99);
4204 location_t body_loc = c_parser_peek_token (parser)->location;
4205 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4206 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4207 || (c_parser_next_token_is (parser, CPP_NAME)
4208 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4209 c_parser_label (parser);
4210 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4211 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4213 location_t loc = c_parser_peek_token (parser)->location;
4214 add_stmt (build_empty_stmt (loc));
4215 c_parser_consume_token (parser);
4216 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4217 warning_at (loc, OPT_Wempty_body,
4218 "suggest braces around empty body in an %<if%> statement");
4220 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4221 add_stmt (c_parser_compound_statement (parser));
4223 c_parser_statement_after_labels (parser);
4224 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4227 /* Parse the else body of an if statement. This is just parsing a
4228 statement but (a) it is a block in C99, (b) we handle an empty body
4229 specially for the sake of -Wempty-body warnings. */
4232 c_parser_else_body (c_parser *parser)
4234 location_t else_loc = c_parser_peek_token (parser)->location;
4235 tree block = c_begin_compound_stmt (flag_isoc99);
4236 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4237 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4238 || (c_parser_next_token_is (parser, CPP_NAME)
4239 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4240 c_parser_label (parser);
4241 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4243 location_t loc = c_parser_peek_token (parser)->location;
4246 "suggest braces around empty body in an %<else%> statement");
4247 add_stmt (build_empty_stmt (loc));
4248 c_parser_consume_token (parser);
4251 c_parser_statement_after_labels (parser);
4252 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4255 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4258 if ( expression ) statement
4259 if ( expression ) statement else statement
4263 c_parser_if_statement (c_parser *parser)
4268 bool first_if = false;
4269 tree first_body, second_body;
4272 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4273 c_parser_consume_token (parser);
4274 block = c_begin_compound_stmt (flag_isoc99);
4275 loc = c_parser_peek_token (parser)->location;
4276 cond = c_parser_paren_condition (parser);
4277 in_if_block = parser->in_if_block;
4278 parser->in_if_block = true;
4279 first_body = c_parser_if_body (parser, &first_if);
4280 parser->in_if_block = in_if_block;
4281 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4283 c_parser_consume_token (parser);
4284 second_body = c_parser_else_body (parser);
4287 second_body = NULL_TREE;
4288 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4289 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4292 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4295 switch (expression) statement
4299 c_parser_switch_statement (c_parser *parser)
4301 tree block, expr, body, save_break;
4302 location_t switch_loc = c_parser_peek_token (parser)->location;
4303 location_t switch_cond_loc;
4304 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4305 c_parser_consume_token (parser);
4306 block = c_begin_compound_stmt (flag_isoc99);
4307 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4309 switch_cond_loc = c_parser_peek_token (parser)->location;
4310 expr = c_parser_expression (parser).value;
4311 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4315 switch_cond_loc = UNKNOWN_LOCATION;
4316 expr = error_mark_node;
4318 c_start_case (switch_loc, switch_cond_loc, expr);
4319 save_break = c_break_label;
4320 c_break_label = NULL_TREE;
4321 body = c_parser_c99_block_statement (parser);
4322 c_finish_case (body);
4325 location_t here = c_parser_peek_token (parser)->location;
4326 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4327 SET_EXPR_LOCATION (t, here);
4330 c_break_label = save_break;
4331 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4334 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4337 while (expression) statement
4341 c_parser_while_statement (c_parser *parser)
4343 tree block, cond, body, save_break, save_cont;
4345 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4346 c_parser_consume_token (parser);
4347 block = c_begin_compound_stmt (flag_isoc99);
4348 loc = c_parser_peek_token (parser)->location;
4349 cond = c_parser_paren_condition (parser);
4350 save_break = c_break_label;
4351 c_break_label = NULL_TREE;
4352 save_cont = c_cont_label;
4353 c_cont_label = NULL_TREE;
4354 body = c_parser_c99_block_statement (parser);
4355 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4356 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4357 c_break_label = save_break;
4358 c_cont_label = save_cont;
4361 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4364 do statement while ( expression ) ;
4368 c_parser_do_statement (c_parser *parser)
4370 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4372 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4373 c_parser_consume_token (parser);
4374 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4375 warning_at (c_parser_peek_token (parser)->location,
4377 "suggest braces around empty body in %<do%> statement");
4378 block = c_begin_compound_stmt (flag_isoc99);
4379 loc = c_parser_peek_token (parser)->location;
4380 save_break = c_break_label;
4381 c_break_label = NULL_TREE;
4382 save_cont = c_cont_label;
4383 c_cont_label = NULL_TREE;
4384 body = c_parser_c99_block_statement (parser);
4385 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4386 new_break = c_break_label;
4387 c_break_label = save_break;
4388 new_cont = c_cont_label;
4389 c_cont_label = save_cont;
4390 cond = c_parser_paren_condition (parser);
4391 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4392 c_parser_skip_to_end_of_block_or_statement (parser);
4393 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4394 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4397 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4400 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4401 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4403 The form with a declaration is new in C99.
4405 ??? In accordance with the old parser, the declaration may be a
4406 nested function, which is then rejected in check_for_loop_decls,
4407 but does it make any sense for this to be included in the grammar?
4408 Note in particular that the nested function does not include a
4409 trailing ';', whereas the "declaration" production includes one.
4410 Also, can we reject bad declarations earlier and cheaper than
4411 check_for_loop_decls? */
4414 c_parser_for_statement (c_parser *parser)
4416 tree block, cond, incr, save_break, save_cont, body;
4417 location_t loc = c_parser_peek_token (parser)->location;
4418 location_t for_loc = c_parser_peek_token (parser)->location;
4419 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4420 c_parser_consume_token (parser);
4421 block = c_begin_compound_stmt (flag_isoc99);
4422 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4424 /* Parse the initialization declaration or expression. */
4425 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4427 c_parser_consume_token (parser);
4428 c_finish_expr_stmt (loc, NULL_TREE);
4430 else if (c_parser_next_token_starts_declaration (parser))
4432 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
4433 check_for_loop_decls (for_loc);
4435 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4437 /* __extension__ can start a declaration, but is also an
4438 unary operator that can start an expression. Consume all
4439 but the last of a possible series of __extension__ to
4441 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4442 && (c_parser_peek_2nd_token (parser)->keyword
4444 c_parser_consume_token (parser);
4445 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4448 ext = disable_extension_diagnostics ();
4449 c_parser_consume_token (parser);
4450 c_parser_declaration_or_fndef (parser, true, true, true, true,
4452 restore_extension_diagnostics (ext);
4453 check_for_loop_decls (for_loc);
4461 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4462 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4464 /* Parse the loop condition. */
4465 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4467 c_parser_consume_token (parser);
4472 cond = c_parser_condition (parser);
4473 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4475 /* Parse the increment expression. */
4476 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4477 incr = c_process_expr_stmt (loc, NULL_TREE);
4479 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4480 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4484 cond = error_mark_node;
4485 incr = error_mark_node;
4487 save_break = c_break_label;
4488 c_break_label = NULL_TREE;
4489 save_cont = c_cont_label;
4490 c_cont_label = NULL_TREE;
4491 body = c_parser_c99_block_statement (parser);
4492 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4493 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4494 c_break_label = save_break;
4495 c_cont_label = save_cont;
4498 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4499 statement with inputs, outputs, clobbers, and volatile tag
4503 asm type-qualifier[opt] ( asm-argument ) ;
4504 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4508 asm-string-literal : asm-operands[opt]
4509 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4510 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4513 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4516 Qualifiers other than volatile are accepted in the syntax but
4520 c_parser_asm_statement (c_parser *parser)
4522 tree quals, str, outputs, inputs, clobbers, labels, ret;
4523 bool simple, is_goto;
4524 location_t asm_loc = c_parser_peek_token (parser)->location;
4525 int section, nsections;
4527 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4528 c_parser_consume_token (parser);
4529 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4531 quals = c_parser_peek_token (parser)->value;
4532 c_parser_consume_token (parser);
4534 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4535 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4537 warning_at (c_parser_peek_token (parser)->location,
4539 "%E qualifier ignored on asm",
4540 c_parser_peek_token (parser)->value);
4542 c_parser_consume_token (parser);
4548 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4550 c_parser_consume_token (parser);
4554 /* ??? Follow the C++ parser rather than using the
4555 lex_untranslated_string kludge. */
4556 parser->lex_untranslated_string = true;
4559 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4562 str = c_parser_asm_string_literal (parser);
4563 if (str == NULL_TREE)
4564 goto error_close_paren;
4567 outputs = NULL_TREE;
4569 clobbers = NULL_TREE;
4572 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4575 /* Parse each colon-delimited section of operands. */
4576 nsections = 3 + is_goto;
4577 for (section = 0; section < nsections; ++section)
4579 if (!c_parser_require (parser, CPP_COLON,
4582 : "expected %<:%> or %<)%>"))
4583 goto error_close_paren;
4585 /* Once past any colon, we're no longer a simple asm. */
4588 if ((!c_parser_next_token_is (parser, CPP_COLON)
4589 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4594 /* For asm goto, we don't allow output operands, but reserve
4595 the slot for a future extension that does allow them. */
4597 outputs = c_parser_asm_operands (parser, false);
4600 inputs = c_parser_asm_operands (parser, true);
4603 clobbers = c_parser_asm_clobbers (parser);
4606 labels = c_parser_asm_goto_operands (parser);
4612 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4617 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4619 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4623 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4624 c_parser_skip_to_end_of_block_or_statement (parser);
4626 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4627 clobbers, labels, simple));
4630 parser->lex_untranslated_string = false;
4634 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4638 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4639 not outputs), apply the default conversion of functions and arrays
4644 asm-operands , asm-operand
4647 asm-string-literal ( expression )
4648 [ identifier ] asm-string-literal ( expression )
4652 c_parser_asm_operands (c_parser *parser, bool convert_p)
4654 tree list = NULL_TREE;
4660 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4662 c_parser_consume_token (parser);
4663 if (c_parser_next_token_is (parser, CPP_NAME))
4665 tree id = c_parser_peek_token (parser)->value;
4666 c_parser_consume_token (parser);
4667 name = build_string (IDENTIFIER_LENGTH (id),
4668 IDENTIFIER_POINTER (id));
4672 c_parser_error (parser, "expected identifier");
4673 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4676 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4681 str = c_parser_asm_string_literal (parser);
4682 if (str == NULL_TREE)
4684 parser->lex_untranslated_string = false;
4685 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4687 parser->lex_untranslated_string = true;
4690 loc = c_parser_peek_token (parser)->location;
4691 expr = c_parser_expression (parser);
4692 mark_exp_read (expr.value);
4694 expr = default_function_array_conversion (loc, expr);
4695 expr.value = c_fully_fold (expr.value, false, NULL);
4696 parser->lex_untranslated_string = true;
4697 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4699 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4702 list = chainon (list, build_tree_list (build_tree_list (name, str),
4704 if (c_parser_next_token_is (parser, CPP_COMMA))
4705 c_parser_consume_token (parser);
4712 /* Parse asm clobbers, a GNU extension.
4716 asm-clobbers , asm-string-literal
4720 c_parser_asm_clobbers (c_parser *parser)
4722 tree list = NULL_TREE;
4725 tree str = c_parser_asm_string_literal (parser);
4727 list = tree_cons (NULL_TREE, str, list);
4730 if (c_parser_next_token_is (parser, CPP_COMMA))
4731 c_parser_consume_token (parser);
4738 /* Parse asm goto labels, a GNU extension.
4742 asm-goto-operands , identifier
4746 c_parser_asm_goto_operands (c_parser *parser)
4748 tree list = NULL_TREE;
4753 if (c_parser_next_token_is (parser, CPP_NAME))
4755 c_token *tok = c_parser_peek_token (parser);
4757 label = lookup_label_for_goto (tok->location, name);
4758 c_parser_consume_token (parser);
4759 TREE_USED (label) = 1;
4763 c_parser_error (parser, "expected identifier");
4767 name = build_string (IDENTIFIER_LENGTH (name),
4768 IDENTIFIER_POINTER (name));
4769 list = tree_cons (name, label, list);
4770 if (c_parser_next_token_is (parser, CPP_COMMA))
4771 c_parser_consume_token (parser);
4773 return nreverse (list);
4777 /* Parse an expression other than a compound expression; that is, an
4778 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4779 NULL then it is an Objective-C message expression which is the
4780 primary-expression starting the expression as an initializer.
4782 assignment-expression:
4783 conditional-expression
4784 unary-expression assignment-operator assignment-expression
4786 assignment-operator: one of
4787 = *= /= %= += -= <<= >>= &= ^= |=
4789 In GNU C we accept any conditional expression on the LHS and
4790 diagnose the invalid lvalue rather than producing a syntax
4793 static struct c_expr
4794 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4796 struct c_expr lhs, rhs, ret;
4797 enum tree_code code;
4798 location_t op_location, exp_location;
4799 gcc_assert (!after || c_dialect_objc ());
4800 lhs = c_parser_conditional_expression (parser, after);
4801 op_location = c_parser_peek_token (parser)->location;
4802 switch (c_parser_peek_token (parser)->type)
4811 code = TRUNC_DIV_EXPR;
4814 code = TRUNC_MOD_EXPR;
4829 code = BIT_AND_EXPR;
4832 code = BIT_XOR_EXPR;
4835 code = BIT_IOR_EXPR;
4840 c_parser_consume_token (parser);
4841 exp_location = c_parser_peek_token (parser)->location;
4842 rhs = c_parser_expr_no_commas (parser, NULL);
4843 rhs = default_function_array_read_conversion (exp_location, rhs);
4844 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4845 code, exp_location, rhs.value,
4847 if (code == NOP_EXPR)
4848 ret.original_code = MODIFY_EXPR;
4851 TREE_NO_WARNING (ret.value) = 1;
4852 ret.original_code = ERROR_MARK;
4854 ret.original_type = NULL;
4858 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4859 is not NULL then it is an Objective-C message expression which is
4860 the primary-expression starting the expression as an initializer.
4862 conditional-expression:
4863 logical-OR-expression
4864 logical-OR-expression ? expression : conditional-expression
4868 conditional-expression:
4869 logical-OR-expression ? : conditional-expression
4872 static struct c_expr
4873 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4875 struct c_expr cond, exp1, exp2, ret;
4876 location_t cond_loc, colon_loc, middle_loc;
4878 gcc_assert (!after || c_dialect_objc ());
4880 cond = c_parser_binary_expression (parser, after);
4882 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4884 cond_loc = c_parser_peek_token (parser)->location;
4885 cond = default_function_array_read_conversion (cond_loc, cond);
4886 c_parser_consume_token (parser);
4887 if (c_parser_next_token_is (parser, CPP_COLON))
4889 tree eptype = NULL_TREE;
4891 middle_loc = c_parser_peek_token (parser)->location;
4892 pedwarn (middle_loc, OPT_pedantic,
4893 "ISO C forbids omitting the middle term of a ?: expression");
4894 warn_for_omitted_condop (middle_loc, cond.value);
4895 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4897 eptype = TREE_TYPE (cond.value);
4898 cond.value = TREE_OPERAND (cond.value, 0);
4900 /* Make sure first operand is calculated only once. */
4901 exp1.value = c_save_expr (default_conversion (cond.value));
4903 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4904 exp1.original_type = NULL;
4905 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4906 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4911 = c_objc_common_truthvalue_conversion
4912 (cond_loc, default_conversion (cond.value));
4913 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4914 exp1 = c_parser_expression_conv (parser);
4915 mark_exp_read (exp1.value);
4916 c_inhibit_evaluation_warnings +=
4917 ((cond.value == truthvalue_true_node)
4918 - (cond.value == truthvalue_false_node));
4921 colon_loc = c_parser_peek_token (parser)->location;
4922 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4924 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4925 ret.value = error_mark_node;
4926 ret.original_code = ERROR_MARK;
4927 ret.original_type = NULL;
4931 location_t exp2_loc = c_parser_peek_token (parser)->location;
4932 exp2 = c_parser_conditional_expression (parser, NULL);
4933 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
4935 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4936 ret.value = build_conditional_expr (colon_loc, cond.value,
4937 cond.original_code == C_MAYBE_CONST_EXPR,
4938 exp1.value, exp1.original_type,
4939 exp2.value, exp2.original_type);
4940 ret.original_code = ERROR_MARK;
4941 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4942 ret.original_type = NULL;
4947 /* If both sides are enum type, the default conversion will have
4948 made the type of the result be an integer type. We want to
4949 remember the enum types we started with. */
4950 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4951 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4952 ret.original_type = ((t1 != error_mark_node
4953 && t2 != error_mark_node
4954 && (TYPE_MAIN_VARIANT (t1)
4955 == TYPE_MAIN_VARIANT (t2)))
4962 /* Parse a binary expression; that is, a logical-OR-expression (C90
4963 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4964 an Objective-C message expression which is the primary-expression
4965 starting the expression as an initializer.
4967 multiplicative-expression:
4969 multiplicative-expression * cast-expression
4970 multiplicative-expression / cast-expression
4971 multiplicative-expression % cast-expression
4973 additive-expression:
4974 multiplicative-expression
4975 additive-expression + multiplicative-expression
4976 additive-expression - multiplicative-expression
4980 shift-expression << additive-expression
4981 shift-expression >> additive-expression
4983 relational-expression:
4985 relational-expression < shift-expression
4986 relational-expression > shift-expression
4987 relational-expression <= shift-expression
4988 relational-expression >= shift-expression
4990 equality-expression:
4991 relational-expression
4992 equality-expression == relational-expression
4993 equality-expression != relational-expression
4997 AND-expression & equality-expression
4999 exclusive-OR-expression:
5001 exclusive-OR-expression ^ AND-expression
5003 inclusive-OR-expression:
5004 exclusive-OR-expression
5005 inclusive-OR-expression | exclusive-OR-expression
5007 logical-AND-expression:
5008 inclusive-OR-expression
5009 logical-AND-expression && inclusive-OR-expression
5011 logical-OR-expression:
5012 logical-AND-expression
5013 logical-OR-expression || logical-AND-expression
5016 static struct c_expr
5017 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
5019 /* A binary expression is parsed using operator-precedence parsing,
5020 with the operands being cast expressions. All the binary
5021 operators are left-associative. Thus a binary expression is of
5024 E0 op1 E1 op2 E2 ...
5026 which we represent on a stack. On the stack, the precedence
5027 levels are strictly increasing. When a new operator is
5028 encountered of higher precedence than that at the top of the
5029 stack, it is pushed; its LHS is the top expression, and its RHS
5030 is everything parsed until it is popped. When a new operator is
5031 encountered with precedence less than or equal to that at the top
5032 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5033 by the result of the operation until the operator at the top of
5034 the stack has lower precedence than the new operator or there is
5035 only one element on the stack; then the top expression is the LHS
5036 of the new operator. In the case of logical AND and OR
5037 expressions, we also need to adjust c_inhibit_evaluation_warnings
5038 as appropriate when the operators are pushed and popped. */
5040 /* The precedence levels, where 0 is a dummy lowest level used for
5041 the bottom of the stack. */
5057 /* The expression at this stack level. */
5059 /* The precedence of the operator on its left, PREC_NONE at the
5060 bottom of the stack. */
5062 /* The operation on its left. */
5064 /* The source location of this operation. */
5068 /* Location of the binary operator. */
5069 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5072 switch (stack[sp].op) \
5074 case TRUTH_ANDIF_EXPR: \
5075 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5076 == truthvalue_false_node); \
5078 case TRUTH_ORIF_EXPR: \
5079 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5080 == truthvalue_true_node); \
5085 stack[sp - 1].expr \
5086 = default_function_array_read_conversion (stack[sp - 1].loc, \
5087 stack[sp - 1].expr); \
5089 = default_function_array_read_conversion (stack[sp].loc, \
5091 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5093 stack[sp - 1].expr, \
5097 gcc_assert (!after || c_dialect_objc ());
5098 stack[0].loc = c_parser_peek_token (parser)->location;
5099 stack[0].expr = c_parser_cast_expression (parser, after);
5100 stack[0].prec = PREC_NONE;
5105 enum tree_code ocode;
5108 switch (c_parser_peek_token (parser)->type)
5116 ocode = TRUNC_DIV_EXPR;
5120 ocode = TRUNC_MOD_EXPR;
5132 ocode = LSHIFT_EXPR;
5136 ocode = RSHIFT_EXPR;
5150 case CPP_GREATER_EQ:
5163 oprec = PREC_BITAND;
5164 ocode = BIT_AND_EXPR;
5167 oprec = PREC_BITXOR;
5168 ocode = BIT_XOR_EXPR;
5172 ocode = BIT_IOR_EXPR;
5175 oprec = PREC_LOGAND;
5176 ocode = TRUTH_ANDIF_EXPR;
5180 ocode = TRUTH_ORIF_EXPR;
5183 /* Not a binary operator, so end of the binary
5187 binary_loc = c_parser_peek_token (parser)->location;
5188 c_parser_consume_token (parser);
5189 while (oprec <= stack[sp].prec)
5193 case TRUTH_ANDIF_EXPR:
5195 = default_function_array_read_conversion (stack[sp].loc,
5197 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5198 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5199 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5200 == truthvalue_false_node);
5202 case TRUTH_ORIF_EXPR:
5204 = default_function_array_read_conversion (stack[sp].loc,
5206 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5207 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5208 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5209 == truthvalue_true_node);
5215 stack[sp].loc = binary_loc;
5216 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5217 stack[sp].prec = oprec;
5218 stack[sp].op = ocode;
5219 stack[sp].loc = binary_loc;
5224 return stack[0].expr;
5228 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5229 NULL then it is an Objective-C message expression which is the
5230 primary-expression starting the expression as an initializer.
5234 ( type-name ) unary-expression
5237 static struct c_expr
5238 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5240 location_t cast_loc = c_parser_peek_token (parser)->location;
5241 gcc_assert (!after || c_dialect_objc ());
5243 return c_parser_postfix_expression_after_primary (parser,
5245 /* If the expression begins with a parenthesized type name, it may
5246 be either a cast or a compound literal; we need to see whether
5247 the next character is '{' to tell the difference. If not, it is
5248 an unary expression. */
5249 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5250 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5252 struct c_type_name *type_name;
5255 c_parser_consume_token (parser);
5256 type_name = c_parser_type_name (parser);
5257 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5258 if (type_name == NULL)
5260 ret.value = error_mark_node;
5261 ret.original_code = ERROR_MARK;
5262 ret.original_type = NULL;
5266 /* Save casted types in the function's used types hash table. */
5267 used_types_insert (type_name->specs->type);
5269 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5270 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5273 location_t expr_loc = c_parser_peek_token (parser)->location;
5274 expr = c_parser_cast_expression (parser, NULL);
5275 expr = default_function_array_read_conversion (expr_loc, expr);
5277 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5278 ret.original_code = ERROR_MARK;
5279 ret.original_type = NULL;
5283 return c_parser_unary_expression (parser);
5286 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5292 unary-operator cast-expression
5293 sizeof unary-expression
5294 sizeof ( type-name )
5296 unary-operator: one of
5302 __alignof__ unary-expression
5303 __alignof__ ( type-name )
5306 unary-operator: one of
5307 __extension__ __real__ __imag__
5309 In addition, the GNU syntax treats ++ and -- as unary operators, so
5310 they may be applied to cast expressions with errors for non-lvalues
5313 static struct c_expr
5314 c_parser_unary_expression (c_parser *parser)
5317 struct c_expr ret, op;
5318 location_t op_loc = c_parser_peek_token (parser)->location;
5320 ret.original_code = ERROR_MARK;
5321 ret.original_type = NULL;
5322 switch (c_parser_peek_token (parser)->type)
5325 c_parser_consume_token (parser);
5326 exp_loc = c_parser_peek_token (parser)->location;
5327 op = c_parser_cast_expression (parser, NULL);
5328 op = default_function_array_read_conversion (exp_loc, op);
5329 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5330 case CPP_MINUS_MINUS:
5331 c_parser_consume_token (parser);
5332 exp_loc = c_parser_peek_token (parser)->location;
5333 op = c_parser_cast_expression (parser, NULL);
5334 op = default_function_array_read_conversion (exp_loc, op);
5335 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5337 c_parser_consume_token (parser);
5338 op = c_parser_cast_expression (parser, NULL);
5339 mark_exp_read (op.value);
5340 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5342 c_parser_consume_token (parser);
5343 exp_loc = c_parser_peek_token (parser)->location;
5344 op = c_parser_cast_expression (parser, NULL);
5345 op = default_function_array_read_conversion (exp_loc, op);
5346 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5349 if (!c_dialect_objc () && !in_system_header)
5352 "traditional C rejects the unary plus operator");
5353 c_parser_consume_token (parser);
5354 exp_loc = c_parser_peek_token (parser)->location;
5355 op = c_parser_cast_expression (parser, NULL);
5356 op = default_function_array_read_conversion (exp_loc, op);
5357 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5359 c_parser_consume_token (parser);
5360 exp_loc = c_parser_peek_token (parser)->location;
5361 op = c_parser_cast_expression (parser, NULL);
5362 op = default_function_array_read_conversion (exp_loc, op);
5363 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5365 c_parser_consume_token (parser);
5366 exp_loc = c_parser_peek_token (parser)->location;
5367 op = c_parser_cast_expression (parser, NULL);
5368 op = default_function_array_read_conversion (exp_loc, op);
5369 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5371 c_parser_consume_token (parser);
5372 exp_loc = c_parser_peek_token (parser)->location;
5373 op = c_parser_cast_expression (parser, NULL);
5374 op = default_function_array_read_conversion (exp_loc, op);
5375 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5377 /* Refer to the address of a label as a pointer. */
5378 c_parser_consume_token (parser);
5379 if (c_parser_next_token_is (parser, CPP_NAME))
5381 ret.value = finish_label_address_expr
5382 (c_parser_peek_token (parser)->value, op_loc);
5383 c_parser_consume_token (parser);
5387 c_parser_error (parser, "expected identifier");
5388 ret.value = error_mark_node;
5392 switch (c_parser_peek_token (parser)->keyword)
5395 return c_parser_sizeof_expression (parser);
5397 return c_parser_alignof_expression (parser);
5399 c_parser_consume_token (parser);
5400 ext = disable_extension_diagnostics ();
5401 ret = c_parser_cast_expression (parser, NULL);
5402 restore_extension_diagnostics (ext);
5405 c_parser_consume_token (parser);
5406 exp_loc = c_parser_peek_token (parser)->location;
5407 op = c_parser_cast_expression (parser, NULL);
5408 op = default_function_array_conversion (exp_loc, op);
5409 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5411 c_parser_consume_token (parser);
5412 exp_loc = c_parser_peek_token (parser)->location;
5413 op = c_parser_cast_expression (parser, NULL);
5414 op = default_function_array_conversion (exp_loc, op);
5415 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5417 return c_parser_postfix_expression (parser);
5420 return c_parser_postfix_expression (parser);
5424 /* Parse a sizeof expression. */
5426 static struct c_expr
5427 c_parser_sizeof_expression (c_parser *parser)
5430 location_t expr_loc;
5431 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5432 c_parser_consume_token (parser);
5433 c_inhibit_evaluation_warnings++;
5435 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5436 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5438 /* Either sizeof ( type-name ) or sizeof unary-expression
5439 starting with a compound literal. */
5440 struct c_type_name *type_name;
5441 c_parser_consume_token (parser);
5442 expr_loc = c_parser_peek_token (parser)->location;
5443 type_name = c_parser_type_name (parser);
5444 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5445 if (type_name == NULL)
5448 c_inhibit_evaluation_warnings--;
5450 ret.value = error_mark_node;
5451 ret.original_code = ERROR_MARK;
5452 ret.original_type = NULL;
5455 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5457 expr = c_parser_postfix_expression_after_paren_type (parser,
5462 /* sizeof ( type-name ). */
5463 c_inhibit_evaluation_warnings--;
5465 return c_expr_sizeof_type (expr_loc, type_name);
5469 expr_loc = c_parser_peek_token (parser)->location;
5470 expr = c_parser_unary_expression (parser);
5472 c_inhibit_evaluation_warnings--;
5474 mark_exp_read (expr.value);
5475 if (TREE_CODE (expr.value) == COMPONENT_REF
5476 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5477 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5478 return c_expr_sizeof_expr (expr_loc, expr);
5482 /* Parse an alignof expression. */
5484 static struct c_expr
5485 c_parser_alignof_expression (c_parser *parser)
5488 location_t loc = c_parser_peek_token (parser)->location;
5489 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5490 c_parser_consume_token (parser);
5491 c_inhibit_evaluation_warnings++;
5493 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5494 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5496 /* Either __alignof__ ( type-name ) or __alignof__
5497 unary-expression starting with a compound literal. */
5499 struct c_type_name *type_name;
5501 c_parser_consume_token (parser);
5502 loc = c_parser_peek_token (parser)->location;
5503 type_name = c_parser_type_name (parser);
5504 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5505 if (type_name == NULL)
5508 c_inhibit_evaluation_warnings--;
5510 ret.value = error_mark_node;
5511 ret.original_code = ERROR_MARK;
5512 ret.original_type = NULL;
5515 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5517 expr = c_parser_postfix_expression_after_paren_type (parser,
5522 /* alignof ( type-name ). */
5523 c_inhibit_evaluation_warnings--;
5525 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5526 ret.original_code = ERROR_MARK;
5527 ret.original_type = NULL;
5533 expr = c_parser_unary_expression (parser);
5535 mark_exp_read (expr.value);
5536 c_inhibit_evaluation_warnings--;
5538 ret.value = c_alignof_expr (loc, expr.value);
5539 ret.original_code = ERROR_MARK;
5540 ret.original_type = NULL;
5545 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5549 postfix-expression [ expression ]
5550 postfix-expression ( argument-expression-list[opt] )
5551 postfix-expression . identifier
5552 postfix-expression -> identifier
5553 postfix-expression ++
5554 postfix-expression --
5555 ( type-name ) { initializer-list }
5556 ( type-name ) { initializer-list , }
5558 argument-expression-list:
5560 argument-expression-list , argument-expression
5572 (treated as a keyword in GNU C)
5575 ( compound-statement )
5576 __builtin_va_arg ( assignment-expression , type-name )
5577 __builtin_offsetof ( type-name , offsetof-member-designator )
5578 __builtin_choose_expr ( assignment-expression ,
5579 assignment-expression ,
5580 assignment-expression )
5581 __builtin_types_compatible_p ( type-name , type-name )
5583 offsetof-member-designator:
5585 offsetof-member-designator . identifier
5586 offsetof-member-designator [ expression ]
5591 [ objc-receiver objc-message-args ]
5592 @selector ( objc-selector-arg )
5593 @protocol ( identifier )
5594 @encode ( type-name )
5598 static struct c_expr
5599 c_parser_postfix_expression (c_parser *parser)
5601 struct c_expr expr, e1, e2, e3;
5602 struct c_type_name *t1, *t2;
5603 location_t loc = c_parser_peek_token (parser)->location;;
5604 expr.original_code = ERROR_MARK;
5605 expr.original_type = NULL;
5606 switch (c_parser_peek_token (parser)->type)
5609 expr.value = c_parser_peek_token (parser)->value;
5610 loc = c_parser_peek_token (parser)->location;
5611 c_parser_consume_token (parser);
5612 if (TREE_CODE (expr.value) == FIXED_CST
5613 && !targetm.fixed_point_supported_p ())
5615 error_at (loc, "fixed-point types not supported for this target");
5616 expr.value = error_mark_node;
5623 expr.value = c_parser_peek_token (parser)->value;
5624 c_parser_consume_token (parser);
5630 case CPP_UTF8STRING:
5631 expr.value = c_parser_peek_token (parser)->value;
5632 expr.original_code = STRING_CST;
5633 c_parser_consume_token (parser);
5635 case CPP_OBJC_STRING:
5636 gcc_assert (c_dialect_objc ());
5638 = objc_build_string_object (c_parser_peek_token (parser)->value);
5639 c_parser_consume_token (parser);
5642 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5644 c_parser_error (parser, "expected expression");
5645 expr.value = error_mark_node;
5649 tree id = c_parser_peek_token (parser)->value;
5650 c_parser_consume_token (parser);
5651 expr.value = build_external_ref (loc, id,
5652 (c_parser_peek_token (parser)->type
5654 &expr.original_type);
5657 case CPP_OPEN_PAREN:
5658 /* A parenthesized expression, statement expression or compound
5660 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5662 /* A statement expression. */
5664 location_t brace_loc;
5665 c_parser_consume_token (parser);
5666 brace_loc = c_parser_peek_token (parser)->location;
5667 c_parser_consume_token (parser);
5668 if (cur_stmt_list == NULL)
5670 error_at (loc, "braced-group within expression allowed "
5671 "only inside a function");
5672 parser->error = true;
5673 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5674 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5675 expr.value = error_mark_node;
5678 stmt = c_begin_stmt_expr ();
5679 c_parser_compound_statement_nostart (parser);
5680 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5682 pedwarn (loc, OPT_pedantic,
5683 "ISO C forbids braced-groups within expressions");
5684 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5685 mark_exp_read (expr.value);
5687 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5689 /* A compound literal. ??? Can we actually get here rather
5690 than going directly to
5691 c_parser_postfix_expression_after_paren_type from
5694 struct c_type_name *type_name;
5695 c_parser_consume_token (parser);
5696 loc = c_parser_peek_token (parser)->location;
5697 type_name = c_parser_type_name (parser);
5698 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5700 if (type_name == NULL)
5702 expr.value = error_mark_node;
5705 expr = c_parser_postfix_expression_after_paren_type (parser,
5711 /* A parenthesized expression. */
5712 c_parser_consume_token (parser);
5713 expr = c_parser_expression (parser);
5714 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5715 TREE_NO_WARNING (expr.value) = 1;
5716 if (expr.original_code != C_MAYBE_CONST_EXPR)
5717 expr.original_code = ERROR_MARK;
5718 /* Don't change EXPR.ORIGINAL_TYPE. */
5719 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5724 switch (c_parser_peek_token (parser)->keyword)
5726 case RID_FUNCTION_NAME:
5727 case RID_PRETTY_FUNCTION_NAME:
5728 case RID_C99_FUNCTION_NAME:
5729 expr.value = fname_decl (loc,
5730 c_parser_peek_token (parser)->keyword,
5731 c_parser_peek_token (parser)->value);
5732 c_parser_consume_token (parser);
5735 c_parser_consume_token (parser);
5736 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5738 expr.value = error_mark_node;
5741 e1 = c_parser_expr_no_commas (parser, NULL);
5742 mark_exp_read (e1.value);
5743 e1.value = c_fully_fold (e1.value, false, NULL);
5744 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5746 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5747 expr.value = error_mark_node;
5750 loc = c_parser_peek_token (parser)->location;
5751 t1 = c_parser_type_name (parser);
5752 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5756 expr.value = error_mark_node;
5760 tree type_expr = NULL_TREE;
5761 expr.value = c_build_va_arg (loc, e1.value,
5762 groktypename (t1, &type_expr, NULL));
5765 expr.value = build2 (C_MAYBE_CONST_EXPR,
5766 TREE_TYPE (expr.value), type_expr,
5768 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5773 c_parser_consume_token (parser);
5774 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5776 expr.value = error_mark_node;
5779 t1 = c_parser_type_name (parser);
5782 expr.value = error_mark_node;
5785 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5787 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5788 expr.value = error_mark_node;
5792 tree type = groktypename (t1, NULL, NULL);
5794 if (type == error_mark_node)
5795 offsetof_ref = error_mark_node;
5798 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5799 SET_EXPR_LOCATION (offsetof_ref, loc);
5801 /* Parse the second argument to __builtin_offsetof. We
5802 must have one identifier, and beyond that we want to
5803 accept sub structure and sub array references. */
5804 if (c_parser_next_token_is (parser, CPP_NAME))
5806 offsetof_ref = build_component_ref
5807 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5808 c_parser_consume_token (parser);
5809 while (c_parser_next_token_is (parser, CPP_DOT)
5810 || c_parser_next_token_is (parser,
5812 || c_parser_next_token_is (parser,
5815 if (c_parser_next_token_is (parser, CPP_DEREF))
5817 loc = c_parser_peek_token (parser)->location;
5818 offsetof_ref = build_array_ref (loc,
5823 else if (c_parser_next_token_is (parser, CPP_DOT))
5826 c_parser_consume_token (parser);
5827 if (c_parser_next_token_is_not (parser,
5830 c_parser_error (parser, "expected identifier");
5833 offsetof_ref = build_component_ref
5835 c_parser_peek_token (parser)->value);
5836 c_parser_consume_token (parser);
5841 loc = c_parser_peek_token (parser)->location;
5842 c_parser_consume_token (parser);
5843 idx = c_parser_expression (parser).value;
5844 idx = c_fully_fold (idx, false, NULL);
5845 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5847 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5852 c_parser_error (parser, "expected identifier");
5853 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5855 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5858 case RID_CHOOSE_EXPR:
5859 c_parser_consume_token (parser);
5860 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5862 expr.value = error_mark_node;
5865 loc = c_parser_peek_token (parser)->location;
5866 e1 = c_parser_expr_no_commas (parser, NULL);
5867 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5869 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5870 expr.value = error_mark_node;
5873 e2 = c_parser_expr_no_commas (parser, NULL);
5874 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5876 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5877 expr.value = error_mark_node;
5880 e3 = c_parser_expr_no_commas (parser, NULL);
5881 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5887 mark_exp_read (e2.value);
5888 mark_exp_read (e3.value);
5889 if (TREE_CODE (c) != INTEGER_CST
5890 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5892 "first argument to %<__builtin_choose_expr%> not"
5894 constant_expression_warning (c);
5895 expr = integer_zerop (c) ? e3 : e2;
5898 case RID_TYPES_COMPATIBLE_P:
5899 c_parser_consume_token (parser);
5900 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5902 expr.value = error_mark_node;
5905 t1 = c_parser_type_name (parser);
5908 expr.value = error_mark_node;
5911 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5913 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5914 expr.value = error_mark_node;
5917 t2 = c_parser_type_name (parser);
5920 expr.value = error_mark_node;
5923 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5928 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5929 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5932 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
5935 case RID_AT_SELECTOR:
5936 gcc_assert (c_dialect_objc ());
5937 c_parser_consume_token (parser);
5938 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5940 expr.value = error_mark_node;
5944 tree sel = c_parser_objc_selector_arg (parser);
5945 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5947 expr.value = objc_build_selector_expr (loc, sel);
5950 case RID_AT_PROTOCOL:
5951 gcc_assert (c_dialect_objc ());
5952 c_parser_consume_token (parser);
5953 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5955 expr.value = error_mark_node;
5958 if (c_parser_next_token_is_not (parser, CPP_NAME))
5960 c_parser_error (parser, "expected identifier");
5961 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5962 expr.value = error_mark_node;
5966 tree id = c_parser_peek_token (parser)->value;
5967 c_parser_consume_token (parser);
5968 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5970 expr.value = objc_build_protocol_expr (id);
5974 /* Extension to support C-structures in the archiver. */
5975 gcc_assert (c_dialect_objc ());
5976 c_parser_consume_token (parser);
5977 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5979 expr.value = error_mark_node;
5982 t1 = c_parser_type_name (parser);
5985 expr.value = error_mark_node;
5986 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5989 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5992 tree type = groktypename (t1, NULL, NULL);
5993 expr.value = objc_build_encode_expr (type);
5997 c_parser_error (parser, "expected expression");
5998 expr.value = error_mark_node;
6002 case CPP_OPEN_SQUARE:
6003 if (c_dialect_objc ())
6005 tree receiver, args;
6006 c_parser_consume_token (parser);
6007 receiver = c_parser_objc_receiver (parser);
6008 args = c_parser_objc_message_args (parser);
6009 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6011 expr.value = objc_build_message_expr (build_tree_list (receiver,
6015 /* Else fall through to report error. */
6017 c_parser_error (parser, "expected expression");
6018 expr.value = error_mark_node;
6021 return c_parser_postfix_expression_after_primary (parser, loc, expr);
6024 /* Parse a postfix expression after a parenthesized type name: the
6025 brace-enclosed initializer of a compound literal, possibly followed
6026 by some postfix operators. This is separate because it is not
6027 possible to tell until after the type name whether a cast
6028 expression has a cast or a compound literal, or whether the operand
6029 of sizeof is a parenthesized type name or starts with a compound
6030 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6031 location of the first token after the parentheses around the type
6034 static struct c_expr
6035 c_parser_postfix_expression_after_paren_type (c_parser *parser,
6036 struct c_type_name *type_name,
6037 location_t type_loc)
6043 location_t start_loc;
6044 tree type_expr = NULL_TREE;
6045 bool type_expr_const = true;
6046 check_compound_literal_type (type_loc, type_name);
6047 start_init (NULL_TREE, NULL, 0);
6048 type = groktypename (type_name, &type_expr, &type_expr_const);
6049 start_loc = c_parser_peek_token (parser)->location;
6050 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6052 error_at (type_loc, "compound literal has variable size");
6053 type = error_mark_node;
6055 init = c_parser_braced_init (parser, type, false);
6057 maybe_warn_string_init (type, init);
6059 if (type != error_mark_node
6060 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6061 && current_function_decl)
6063 error ("compound literal qualified by address-space qualifier");
6064 type = error_mark_node;
6068 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6069 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6070 ? CONSTRUCTOR_NON_CONST (init.value)
6071 : init.original_code == C_MAYBE_CONST_EXPR);
6072 non_const |= !type_expr_const;
6073 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6074 expr.original_code = ERROR_MARK;
6075 expr.original_type = NULL;
6078 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6080 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6081 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6085 gcc_assert (!non_const);
6086 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6087 type_expr, expr.value);
6090 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6093 /* Parse a postfix expression after the initial primary or compound
6094 literal; that is, parse a series of postfix operators.
6096 EXPR_LOC is the location of the primary expression. */
6098 static struct c_expr
6099 c_parser_postfix_expression_after_primary (c_parser *parser,
6100 location_t expr_loc,
6103 struct c_expr orig_expr;
6105 VEC(tree,gc) *exprlist;
6106 VEC(tree,gc) *origtypes;
6109 location_t op_loc = c_parser_peek_token (parser)->location;
6110 switch (c_parser_peek_token (parser)->type)
6112 case CPP_OPEN_SQUARE:
6113 /* Array reference. */
6114 c_parser_consume_token (parser);
6115 idx = c_parser_expression (parser).value;
6116 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6118 expr.value = build_array_ref (op_loc, expr.value, idx);
6119 expr.original_code = ERROR_MARK;
6120 expr.original_type = NULL;
6122 case CPP_OPEN_PAREN:
6123 /* Function call. */
6124 c_parser_consume_token (parser);
6125 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6128 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6129 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6132 mark_exp_read (expr.value);
6133 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6134 "(" after the FUNCNAME, which is what we have now. */
6135 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6137 expr.original_code = ERROR_MARK;
6138 if (TREE_CODE (expr.value) == INTEGER_CST
6139 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6140 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6141 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6142 expr.original_code = C_MAYBE_CONST_EXPR;
6143 expr.original_type = NULL;
6144 if (exprlist != NULL)
6146 release_tree_vector (exprlist);
6147 release_tree_vector (origtypes);
6151 /* Structure element reference. */
6152 c_parser_consume_token (parser);
6153 expr = default_function_array_conversion (expr_loc, expr);
6154 if (c_parser_next_token_is (parser, CPP_NAME))
6155 ident = c_parser_peek_token (parser)->value;
6158 c_parser_error (parser, "expected identifier");
6159 expr.value = error_mark_node;
6160 expr.original_code = ERROR_MARK;
6161 expr.original_type = NULL;
6164 c_parser_consume_token (parser);
6165 expr.value = build_component_ref (op_loc, expr.value, ident);
6166 expr.original_code = ERROR_MARK;
6167 if (TREE_CODE (expr.value) != COMPONENT_REF)
6168 expr.original_type = NULL;
6171 /* Remember the original type of a bitfield. */
6172 tree field = TREE_OPERAND (expr.value, 1);
6173 if (TREE_CODE (field) != FIELD_DECL)
6174 expr.original_type = NULL;
6176 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6180 /* Structure element reference. */
6181 c_parser_consume_token (parser);
6182 expr = default_function_array_conversion (expr_loc, expr);
6183 if (c_parser_next_token_is (parser, CPP_NAME))
6184 ident = c_parser_peek_token (parser)->value;
6187 c_parser_error (parser, "expected identifier");
6188 expr.value = error_mark_node;
6189 expr.original_code = ERROR_MARK;
6190 expr.original_type = NULL;
6193 c_parser_consume_token (parser);
6194 expr.value = build_component_ref (op_loc,
6195 build_indirect_ref (op_loc,
6199 expr.original_code = ERROR_MARK;
6200 if (TREE_CODE (expr.value) != COMPONENT_REF)
6201 expr.original_type = NULL;
6204 /* Remember the original type of a bitfield. */
6205 tree field = TREE_OPERAND (expr.value, 1);
6206 if (TREE_CODE (field) != FIELD_DECL)
6207 expr.original_type = NULL;
6209 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6213 /* Postincrement. */
6214 c_parser_consume_token (parser);
6215 expr = default_function_array_read_conversion (expr_loc, expr);
6216 expr.value = build_unary_op (op_loc,
6217 POSTINCREMENT_EXPR, expr.value, 0);
6218 expr.original_code = ERROR_MARK;
6219 expr.original_type = NULL;
6221 case CPP_MINUS_MINUS:
6222 /* Postdecrement. */
6223 c_parser_consume_token (parser);
6224 expr = default_function_array_read_conversion (expr_loc, expr);
6225 expr.value = build_unary_op (op_loc,
6226 POSTDECREMENT_EXPR, expr.value, 0);
6227 expr.original_code = ERROR_MARK;
6228 expr.original_type = NULL;
6236 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6239 assignment-expression
6240 expression , assignment-expression
6243 static struct c_expr
6244 c_parser_expression (c_parser *parser)
6247 expr = c_parser_expr_no_commas (parser, NULL);
6248 while (c_parser_next_token_is (parser, CPP_COMMA))
6252 location_t loc = c_parser_peek_token (parser)->location;
6253 location_t expr_loc;
6254 c_parser_consume_token (parser);
6255 expr_loc = c_parser_peek_token (parser)->location;
6256 lhsval = expr.value;
6257 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6258 lhsval = TREE_OPERAND (lhsval, 1);
6259 if (DECL_P (lhsval) || handled_component_p (lhsval))
6260 mark_exp_read (lhsval);
6261 next = c_parser_expr_no_commas (parser, NULL);
6262 next = default_function_array_conversion (expr_loc, next);
6263 expr.value = build_compound_expr (loc, expr.value, next.value);
6264 expr.original_code = COMPOUND_EXPR;
6265 expr.original_type = next.original_type;
6270 /* Parse an expression and convert functions or arrays to
6273 static struct c_expr
6274 c_parser_expression_conv (c_parser *parser)
6277 location_t loc = c_parser_peek_token (parser)->location;
6278 expr = c_parser_expression (parser);
6279 expr = default_function_array_conversion (loc, expr);
6283 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6284 functions and arrays to pointers. If FOLD_P, fold the expressions.
6287 assignment-expression
6288 nonempty-expr-list , assignment-expression
6291 static VEC(tree,gc) *
6292 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6293 VEC(tree,gc) **p_orig_types)
6296 VEC(tree,gc) *orig_types;
6298 location_t loc = c_parser_peek_token (parser)->location;
6300 ret = make_tree_vector ();
6301 if (p_orig_types == NULL)
6304 orig_types = make_tree_vector ();
6306 expr = c_parser_expr_no_commas (parser, NULL);
6308 expr = default_function_array_read_conversion (loc, expr);
6310 expr.value = c_fully_fold (expr.value, false, NULL);
6311 VEC_quick_push (tree, ret, expr.value);
6312 if (orig_types != NULL)
6313 VEC_quick_push (tree, orig_types, expr.original_type);
6314 while (c_parser_next_token_is (parser, CPP_COMMA))
6316 c_parser_consume_token (parser);
6317 loc = c_parser_peek_token (parser)->location;
6318 expr = c_parser_expr_no_commas (parser, NULL);
6320 expr = default_function_array_read_conversion (loc, expr);
6322 expr.value = c_fully_fold (expr.value, false, NULL);
6323 VEC_safe_push (tree, gc, ret, expr.value);
6324 if (orig_types != NULL)
6325 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6327 if (orig_types != NULL)
6328 *p_orig_types = orig_types;
6332 /* Parse Objective-C-specific constructs. */
6334 /* Parse an objc-class-definition.
6336 objc-class-definition:
6337 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6338 objc-class-instance-variables[opt] objc-methodprotolist @end
6339 @implementation identifier objc-superclass[opt]
6340 objc-class-instance-variables[opt]
6341 @interface identifier ( identifier ) objc-protocol-refs[opt]
6342 objc-methodprotolist @end
6343 @implementation identifier ( identifier )
6348 "@interface identifier (" must start "@interface identifier (
6349 identifier ) ...": objc-methodprotolist in the first production may
6350 not start with a parenthesized identifier as a declarator of a data
6351 definition with no declaration specifiers if the objc-superclass,
6352 objc-protocol-refs and objc-class-instance-variables are omitted. */
6355 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6360 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6362 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6367 c_parser_consume_token (parser);
6368 if (c_parser_next_token_is_not (parser, CPP_NAME))
6370 c_parser_error (parser, "expected identifier");
6373 id1 = c_parser_peek_token (parser)->value;
6374 c_parser_consume_token (parser);
6375 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6378 tree proto = NULL_TREE;
6379 c_parser_consume_token (parser);
6380 if (c_parser_next_token_is_not (parser, CPP_NAME))
6382 c_parser_error (parser, "expected identifier");
6383 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6386 id2 = c_parser_peek_token (parser)->value;
6387 c_parser_consume_token (parser);
6388 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6391 objc_start_category_implementation (id1, id2);
6394 if (c_parser_next_token_is (parser, CPP_LESS))
6395 proto = c_parser_objc_protocol_refs (parser);
6396 objc_start_category_interface (id1, id2, proto, attributes);
6397 c_parser_objc_methodprotolist (parser);
6398 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6399 objc_finish_interface ();
6402 if (c_parser_next_token_is (parser, CPP_COLON))
6404 c_parser_consume_token (parser);
6405 if (c_parser_next_token_is_not (parser, CPP_NAME))
6407 c_parser_error (parser, "expected identifier");
6410 superclass = c_parser_peek_token (parser)->value;
6411 c_parser_consume_token (parser);
6414 superclass = NULL_TREE;
6417 tree proto = NULL_TREE;
6418 if (c_parser_next_token_is (parser, CPP_LESS))
6419 proto = c_parser_objc_protocol_refs (parser);
6420 objc_start_class_interface (id1, superclass, proto, attributes);
6423 objc_start_class_implementation (id1, superclass);
6424 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6425 c_parser_objc_class_instance_variables (parser);
6428 objc_continue_interface ();
6429 c_parser_objc_methodprotolist (parser);
6430 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6431 objc_finish_interface ();
6435 objc_continue_implementation ();
6440 /* Parse objc-class-instance-variables.
6442 objc-class-instance-variables:
6443 { objc-instance-variable-decl-list[opt] }
6445 objc-instance-variable-decl-list:
6446 objc-visibility-spec
6447 objc-instance-variable-decl ;
6449 objc-instance-variable-decl-list objc-visibility-spec
6450 objc-instance-variable-decl-list objc-instance-variable-decl ;
6451 objc-instance-variable-decl-list ;
6453 objc-visibility-spec:
6458 objc-instance-variable-decl:
6463 c_parser_objc_class_instance_variables (c_parser *parser)
6465 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6466 c_parser_consume_token (parser);
6467 while (c_parser_next_token_is_not (parser, CPP_EOF))
6470 /* Parse any stray semicolon. */
6471 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6473 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6474 "extra semicolon in struct or union specified");
6475 c_parser_consume_token (parser);
6478 /* Stop if at the end of the instance variables. */
6479 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6481 c_parser_consume_token (parser);
6484 /* Parse any objc-visibility-spec. */
6485 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6487 c_parser_consume_token (parser);
6488 objc_set_visibility (2);
6491 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6493 c_parser_consume_token (parser);
6494 objc_set_visibility (0);
6497 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6499 c_parser_consume_token (parser);
6500 objc_set_visibility (1);
6503 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6505 c_parser_pragma (parser, pragma_external);
6509 /* Parse some comma-separated declarations. */
6510 decls = c_parser_struct_declaration (parser);
6512 /* Comma-separated instance variables are chained together in
6513 reverse order; add them one by one. */
6514 tree ivar = nreverse (decls);
6515 for (; ivar; ivar = DECL_CHAIN (ivar))
6516 objc_add_instance_variable (copy_node (ivar));
6518 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6522 /* Parse an objc-class-declaration.
6524 objc-class-declaration:
6525 @class identifier-list ;
6529 c_parser_objc_class_declaration (c_parser *parser)
6531 tree list = NULL_TREE;
6532 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6533 c_parser_consume_token (parser);
6534 /* Any identifiers, including those declared as type names, are OK
6539 if (c_parser_next_token_is_not (parser, CPP_NAME))
6541 c_parser_error (parser, "expected identifier");
6544 id = c_parser_peek_token (parser)->value;
6545 list = chainon (list, build_tree_list (NULL_TREE, id));
6546 c_parser_consume_token (parser);
6547 if (c_parser_next_token_is (parser, CPP_COMMA))
6548 c_parser_consume_token (parser);
6552 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6553 objc_declare_class (list);
6556 /* Parse an objc-alias-declaration.
6558 objc-alias-declaration:
6559 @compatibility_alias identifier identifier ;
6563 c_parser_objc_alias_declaration (c_parser *parser)
6566 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6567 c_parser_consume_token (parser);
6568 if (c_parser_next_token_is_not (parser, CPP_NAME))
6570 c_parser_error (parser, "expected identifier");
6571 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6574 id1 = c_parser_peek_token (parser)->value;
6575 c_parser_consume_token (parser);
6576 if (c_parser_next_token_is_not (parser, CPP_NAME))
6578 c_parser_error (parser, "expected identifier");
6579 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6582 id2 = c_parser_peek_token (parser)->value;
6583 c_parser_consume_token (parser);
6584 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6585 objc_declare_alias (id1, id2);
6588 /* Parse an objc-protocol-definition.
6590 objc-protocol-definition:
6591 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6592 @protocol identifier-list ;
6594 "@protocol identifier ;" should be resolved as "@protocol
6595 identifier-list ;": objc-methodprotolist may not start with a
6596 semicolon in the first alternative if objc-protocol-refs are
6600 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6602 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6604 c_parser_consume_token (parser);
6605 if (c_parser_next_token_is_not (parser, CPP_NAME))
6607 c_parser_error (parser, "expected identifier");
6610 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6611 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6613 tree list = NULL_TREE;
6614 /* Any identifiers, including those declared as type names, are
6619 if (c_parser_next_token_is_not (parser, CPP_NAME))
6621 c_parser_error (parser, "expected identifier");
6624 id = c_parser_peek_token (parser)->value;
6625 list = chainon (list, build_tree_list (NULL_TREE, id));
6626 c_parser_consume_token (parser);
6627 if (c_parser_next_token_is (parser, CPP_COMMA))
6628 c_parser_consume_token (parser);
6632 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6633 objc_declare_protocols (list);
6637 tree id = c_parser_peek_token (parser)->value;
6638 tree proto = NULL_TREE;
6639 c_parser_consume_token (parser);
6640 if (c_parser_next_token_is (parser, CPP_LESS))
6641 proto = c_parser_objc_protocol_refs (parser);
6642 parser->objc_pq_context = true;
6643 objc_start_protocol (id, proto, attributes);
6644 c_parser_objc_methodprotolist (parser);
6645 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6646 parser->objc_pq_context = false;
6647 objc_finish_interface ();
6651 /* Parse an objc-method-type.
6658 static enum tree_code
6659 c_parser_objc_method_type (c_parser *parser)
6661 switch (c_parser_peek_token (parser)->type)
6664 c_parser_consume_token (parser);
6667 c_parser_consume_token (parser);
6674 /* Parse an objc-method-definition.
6676 objc-method-definition:
6677 objc-method-type objc-method-decl ;[opt] compound-statement
6681 c_parser_objc_method_definition (c_parser *parser)
6683 enum tree_code type = c_parser_objc_method_type (parser);
6684 tree decl, attributes = NULL_TREE;
6685 objc_set_method_type (type);
6686 parser->objc_pq_context = true;
6687 decl = c_parser_objc_method_decl (parser, &attributes);
6688 if (decl == error_mark_node)
6689 return; /* Bail here. */
6691 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6693 c_parser_consume_token (parser);
6694 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6695 "extra semicolon in method definition specified");
6698 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6700 c_parser_error (parser, "expected %<{%>");
6704 parser->objc_pq_context = false;
6705 if (objc_start_method_definition (decl, attributes))
6707 add_stmt (c_parser_compound_statement (parser));
6708 objc_finish_method_definition (current_function_decl);
6712 /* This code is executed when we find a method definition
6713 outside of an @implementation context. Parse the method (to
6714 keep going) but do not emit any code.
6716 c_parser_compound_statement (parser);
6720 /* Parse an objc-methodprotolist.
6722 objc-methodprotolist:
6724 objc-methodprotolist objc-methodproto
6725 objc-methodprotolist declaration
6726 objc-methodprotolist ;
6728 The declaration is a data definition, which may be missing
6729 declaration specifiers under the same rules and diagnostics as
6730 other data definitions outside functions, and the stray semicolon
6731 is diagnosed the same way as a stray semicolon outside a
6735 c_parser_objc_methodprotolist (c_parser *parser)
6739 /* The list is terminated by @end. */
6740 switch (c_parser_peek_token (parser)->type)
6743 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6744 "ISO C does not allow extra %<;%> outside of a function");
6745 c_parser_consume_token (parser);
6749 c_parser_objc_methodproto (parser);
6752 c_parser_pragma (parser, pragma_external);
6757 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6759 c_parser_declaration_or_fndef (parser, false, false, true,
6766 /* Parse an objc-methodproto.
6769 objc-method-type objc-method-decl ;
6773 c_parser_objc_methodproto (c_parser *parser)
6775 enum tree_code type = c_parser_objc_method_type (parser);
6776 tree decl, attributes = NULL_TREE;
6777 objc_set_method_type (type);
6778 /* Remember protocol qualifiers in prototypes. */
6779 parser->objc_pq_context = true;
6780 decl = c_parser_objc_method_decl (parser, &attributes);
6781 /* Forget protocol qualifiers now. */
6782 parser->objc_pq_context = false;
6784 /* Do not allow the presence of attributes to hide an erroneous
6785 method implementation in the interface section. */
6786 if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
6788 c_parser_error (parser, "expected %<;%>");
6792 if (decl != error_mark_node)
6793 objc_add_method_declaration (decl, attributes);
6795 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6798 /* If we are at a position that method attributes may be present, check that
6799 there are not any parsed already (a syntax error) and then collect any
6800 specified at the current location. Finally, if new attributes were present,
6801 check that the next token is legal ( ';' for decls and '{' for defs). */
6804 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes)
6809 c_parser_error (parser,
6810 "method attributes must be specified at the end only");
6811 *attributes = NULL_TREE;
6815 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6816 *attributes = c_parser_attributes (parser);
6818 /* If there were no attributes here, just report any earlier error. */
6819 if (*attributes == NULL_TREE || bad)
6822 /* If the attributes are followed by a ; or {, then just report any earlier
6824 if (c_parser_next_token_is (parser, CPP_SEMICOLON)
6825 || c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6828 /* We've got attributes, but not at the end. */
6829 c_parser_error (parser,
6830 "expected %<;%> or %<{%> after method attribute definition");
6834 /* Parse an objc-method-decl.
6837 ( objc-type-name ) objc-selector
6839 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6840 objc-keyword-selector objc-optparmlist
6843 objc-keyword-selector:
6845 objc-keyword-selector objc-keyword-decl
6848 objc-selector : ( objc-type-name ) identifier
6849 objc-selector : identifier
6850 : ( objc-type-name ) identifier
6854 objc-optparms objc-optellipsis
6858 objc-opt-parms , parameter-declaration
6866 c_parser_objc_method_decl (c_parser *parser, tree *attributes)
6868 tree type = NULL_TREE;
6870 tree parms = NULL_TREE;
6871 bool ellipsis = false;
6872 bool attr_err = false;
6874 *attributes = NULL_TREE;
6875 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6877 c_parser_consume_token (parser);
6878 type = c_parser_objc_type_name (parser);
6879 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6881 sel = c_parser_objc_selector (parser);
6882 /* If there is no selector, or a colon follows, we have an
6883 objc-keyword-selector. If there is a selector, and a colon does
6884 not follow, that selector ends the objc-method-decl. */
6885 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6888 tree list = NULL_TREE;
6891 tree atype = NULL_TREE, id, keyworddecl;
6892 tree param_attr = NULL_TREE;
6893 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6895 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6897 c_parser_consume_token (parser);
6898 atype = c_parser_objc_type_name (parser);
6899 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6902 /* New ObjC allows attributes on method parameters. */
6903 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
6904 param_attr = c_parser_attributes (parser);
6905 if (c_parser_next_token_is_not (parser, CPP_NAME))
6907 c_parser_error (parser, "expected identifier");
6908 return error_mark_node;
6910 id = c_parser_peek_token (parser)->value;
6911 c_parser_consume_token (parser);
6912 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr);
6913 list = chainon (list, keyworddecl);
6914 tsel = c_parser_objc_selector (parser);
6915 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6919 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
6921 /* Parse the optional parameter list. Optional Objective-C
6922 method parameters follow the C syntax, and may include '...'
6923 to denote a variable number of arguments. */
6924 parms = make_node (TREE_LIST);
6925 while (c_parser_next_token_is (parser, CPP_COMMA))
6927 struct c_parm *parm;
6928 c_parser_consume_token (parser);
6929 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6932 c_parser_consume_token (parser);
6933 attr_err |= c_parser_objc_maybe_method_attributes
6934 (parser, attributes) ;
6937 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6940 parms = chainon (parms,
6941 build_tree_list (NULL_TREE, grokparm (parm)));
6946 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ;
6950 c_parser_error (parser, "objective-c method declaration is expected");
6951 return error_mark_node;
6955 return error_mark_node;
6957 return objc_build_method_signature (type, sel, parms, ellipsis);
6960 /* Parse an objc-type-name.
6963 objc-type-qualifiers[opt] type-name
6964 objc-type-qualifiers[opt]
6966 objc-type-qualifiers:
6968 objc-type-qualifiers objc-type-qualifier
6970 objc-type-qualifier: one of
6971 in out inout bycopy byref oneway
6975 c_parser_objc_type_name (c_parser *parser)
6977 tree quals = NULL_TREE;
6978 struct c_type_name *type_name = NULL;
6979 tree type = NULL_TREE;
6982 c_token *token = c_parser_peek_token (parser);
6983 if (token->type == CPP_KEYWORD
6984 && (token->keyword == RID_IN
6985 || token->keyword == RID_OUT
6986 || token->keyword == RID_INOUT
6987 || token->keyword == RID_BYCOPY
6988 || token->keyword == RID_BYREF
6989 || token->keyword == RID_ONEWAY))
6991 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6992 c_parser_consume_token (parser);
6997 if (c_parser_next_token_starts_typename (parser))
6998 type_name = c_parser_type_name (parser);
7000 type = groktypename (type_name, NULL, NULL);
7001 return build_tree_list (quals, type);
7004 /* Parse objc-protocol-refs.
7011 c_parser_objc_protocol_refs (c_parser *parser)
7013 tree list = NULL_TREE;
7014 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
7015 c_parser_consume_token (parser);
7016 /* Any identifiers, including those declared as type names, are OK
7021 if (c_parser_next_token_is_not (parser, CPP_NAME))
7023 c_parser_error (parser, "expected identifier");
7026 id = c_parser_peek_token (parser)->value;
7027 list = chainon (list, build_tree_list (NULL_TREE, id));
7028 c_parser_consume_token (parser);
7029 if (c_parser_next_token_is (parser, CPP_COMMA))
7030 c_parser_consume_token (parser);
7034 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
7038 /* Parse an objc-try-catch-statement.
7040 objc-try-catch-statement:
7041 @try compound-statement objc-catch-list[opt]
7042 @try compound-statement objc-catch-list[opt] @finally compound-statement
7045 @catch ( parameter-declaration ) compound-statement
7046 objc-catch-list @catch ( parameter-declaration ) compound-statement
7050 c_parser_objc_try_catch_statement (c_parser *parser)
7054 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
7055 c_parser_consume_token (parser);
7056 loc = c_parser_peek_token (parser)->location;
7057 stmt = c_parser_compound_statement (parser);
7058 objc_begin_try_stmt (loc, stmt);
7059 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
7061 struct c_parm *parm;
7062 c_parser_consume_token (parser);
7063 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7065 parm = c_parser_parameter_declaration (parser, NULL_TREE);
7068 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
7071 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7072 objc_begin_catch_clause (grokparm (parm));
7073 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
7074 c_parser_compound_statement_nostart (parser);
7075 objc_finish_catch_clause ();
7077 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
7081 c_parser_consume_token (parser);
7082 finloc = c_parser_peek_token (parser)->location;
7083 finstmt = c_parser_compound_statement (parser);
7084 objc_build_finally_clause (finloc, finstmt);
7086 objc_finish_try_stmt ();
7089 /* Parse an objc-synchronized-statement.
7091 objc-synchronized-statement:
7092 @synchronized ( expression ) compound-statement
7096 c_parser_objc_synchronized_statement (c_parser *parser)
7100 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
7101 c_parser_consume_token (parser);
7102 loc = c_parser_peek_token (parser)->location;
7103 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7105 expr = c_parser_expression (parser).value;
7106 expr = c_fully_fold (expr, false, NULL);
7107 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7110 expr = error_mark_node;
7111 stmt = c_parser_compound_statement (parser);
7112 objc_build_synchronized (loc, expr, stmt);
7115 /* Parse an objc-selector; return NULL_TREE without an error if the
7116 next token is not an objc-selector.
7121 enum struct union if else while do for switch case default
7122 break continue return goto asm sizeof typeof __alignof
7123 unsigned long const short volatile signed restrict _Complex
7124 in out inout bycopy byref oneway int char float double void _Bool
7126 ??? Why this selection of keywords but not, for example, storage
7127 class specifiers? */
7130 c_parser_objc_selector (c_parser *parser)
7132 c_token *token = c_parser_peek_token (parser);
7133 tree value = token->value;
7134 if (token->type == CPP_NAME)
7136 c_parser_consume_token (parser);
7139 if (token->type != CPP_KEYWORD)
7141 switch (token->keyword)
7183 c_parser_consume_token (parser);
7190 /* Parse an objc-selector-arg.
7194 objc-keywordname-list
7196 objc-keywordname-list:
7198 objc-keywordname-list objc-keywordname
7206 c_parser_objc_selector_arg (c_parser *parser)
7208 tree sel = c_parser_objc_selector (parser);
7209 tree list = NULL_TREE;
7210 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7214 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7216 list = chainon (list, build_tree_list (sel, NULL_TREE));
7217 sel = c_parser_objc_selector (parser);
7218 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7224 /* Parse an objc-receiver.
7233 c_parser_objc_receiver (c_parser *parser)
7235 if (c_parser_peek_token (parser)->type == CPP_NAME
7236 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7237 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7239 tree id = c_parser_peek_token (parser)->value;
7240 c_parser_consume_token (parser);
7241 return objc_get_class_reference (id);
7243 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7246 /* Parse objc-message-args.
7250 objc-keywordarg-list
7252 objc-keywordarg-list:
7254 objc-keywordarg-list objc-keywordarg
7257 objc-selector : objc-keywordexpr
7262 c_parser_objc_message_args (c_parser *parser)
7264 tree sel = c_parser_objc_selector (parser);
7265 tree list = NULL_TREE;
7266 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7271 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7272 return error_mark_node;
7273 keywordexpr = c_parser_objc_keywordexpr (parser);
7274 list = chainon (list, build_tree_list (sel, keywordexpr));
7275 sel = c_parser_objc_selector (parser);
7276 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7282 /* Parse an objc-keywordexpr.
7289 c_parser_objc_keywordexpr (c_parser *parser)
7292 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7293 if (VEC_length (tree, expr_list) == 1)
7295 /* Just return the expression, remove a level of
7297 ret = VEC_index (tree, expr_list, 0);
7301 /* We have a comma expression, we will collapse later. */
7302 ret = build_tree_list_vec (expr_list);
7304 release_tree_vector (expr_list);
7308 /* A check, needed in several places, that ObjC interface, implementation or
7309 method definitions are not prefixed by incorrect items. */
7311 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7312 struct c_declspecs *specs)
7314 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7316 c_parser_error (parser,
7317 "no type or storage class may be specified here,");
7318 c_parser_skip_to_end_of_block_or_statement (parser);
7324 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7325 should be considered, statements. ALLOW_STMT is true if we're within
7326 the context of a function and such pragmas are to be allowed. Returns
7327 true if we actually parsed such a pragma. */
7330 c_parser_pragma (c_parser *parser, enum pragma_context context)
7334 id = c_parser_peek_token (parser)->pragma_kind;
7335 gcc_assert (id != PRAGMA_NONE);
7339 case PRAGMA_OMP_BARRIER:
7340 if (context != pragma_compound)
7342 if (context == pragma_stmt)
7343 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7344 "used in compound statements");
7347 c_parser_omp_barrier (parser);
7350 case PRAGMA_OMP_FLUSH:
7351 if (context != pragma_compound)
7353 if (context == pragma_stmt)
7354 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7355 "used in compound statements");
7358 c_parser_omp_flush (parser);
7361 case PRAGMA_OMP_TASKWAIT:
7362 if (context != pragma_compound)
7364 if (context == pragma_stmt)
7365 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7366 "used in compound statements");
7369 c_parser_omp_taskwait (parser);
7372 case PRAGMA_OMP_THREADPRIVATE:
7373 c_parser_omp_threadprivate (parser);
7376 case PRAGMA_OMP_SECTION:
7377 error_at (c_parser_peek_token (parser)->location,
7378 "%<#pragma omp section%> may only be used in "
7379 "%<#pragma omp sections%> construct");
7380 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7383 case PRAGMA_GCC_PCH_PREPROCESS:
7384 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7385 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7389 if (id < PRAGMA_FIRST_EXTERNAL)
7391 if (context == pragma_external)
7394 c_parser_error (parser, "expected declaration specifiers");
7395 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7398 c_parser_omp_construct (parser);
7404 c_parser_consume_pragma (parser);
7405 c_invoke_pragma_handler (id);
7407 /* Skip to EOL, but suppress any error message. Those will have been
7408 generated by the handler routine through calling error, as opposed
7409 to calling c_parser_error. */
7410 parser->error = true;
7411 c_parser_skip_to_pragma_eol (parser);
7416 /* The interface the pragma parsers have to the lexer. */
7419 pragma_lex (tree *value)
7421 c_token *tok = c_parser_peek_token (the_parser);
7422 enum cpp_ttype ret = tok->type;
7424 *value = tok->value;
7425 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7429 if (ret == CPP_KEYWORD)
7431 c_parser_consume_token (the_parser);
7438 c_parser_pragma_pch_preprocess (c_parser *parser)
7442 c_parser_consume_pragma (parser);
7443 if (c_parser_next_token_is (parser, CPP_STRING))
7445 name = c_parser_peek_token (parser)->value;
7446 c_parser_consume_token (parser);
7449 c_parser_error (parser, "expected string literal");
7450 c_parser_skip_to_pragma_eol (parser);
7453 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7456 /* OpenMP 2.5 parsing routines. */
7458 /* Returns name of the next clause.
7459 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7460 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7461 returned and the token is consumed. */
7463 static pragma_omp_clause
7464 c_parser_omp_clause_name (c_parser *parser)
7466 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7468 if (c_parser_next_token_is_keyword (parser, RID_IF))
7469 result = PRAGMA_OMP_CLAUSE_IF;
7470 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7471 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7472 else if (c_parser_next_token_is (parser, CPP_NAME))
7474 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7479 if (!strcmp ("collapse", p))
7480 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7481 else if (!strcmp ("copyin", p))
7482 result = PRAGMA_OMP_CLAUSE_COPYIN;
7483 else if (!strcmp ("copyprivate", p))
7484 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7487 if (!strcmp ("firstprivate", p))
7488 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7491 if (!strcmp ("lastprivate", p))
7492 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7495 if (!strcmp ("nowait", p))
7496 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7497 else if (!strcmp ("num_threads", p))
7498 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7501 if (!strcmp ("ordered", p))
7502 result = PRAGMA_OMP_CLAUSE_ORDERED;
7505 if (!strcmp ("private", p))
7506 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7509 if (!strcmp ("reduction", p))
7510 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7513 if (!strcmp ("schedule", p))
7514 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7515 else if (!strcmp ("shared", p))
7516 result = PRAGMA_OMP_CLAUSE_SHARED;
7519 if (!strcmp ("untied", p))
7520 result = PRAGMA_OMP_CLAUSE_UNTIED;
7525 if (result != PRAGMA_OMP_CLAUSE_NONE)
7526 c_parser_consume_token (parser);
7531 /* Validate that a clause of the given type does not already exist. */
7534 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7539 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7540 if (OMP_CLAUSE_CODE (c) == code)
7542 location_t loc = OMP_CLAUSE_LOCATION (c);
7543 error_at (loc, "too many %qs clauses", name);
7551 variable-list , identifier
7553 If KIND is nonzero, create the appropriate node and install the
7554 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7555 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7557 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7558 return the list created. */
7561 c_parser_omp_variable_list (c_parser *parser,
7562 location_t clause_loc,
7563 enum omp_clause_code kind,
7566 if (c_parser_next_token_is_not (parser, CPP_NAME)
7567 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7568 c_parser_error (parser, "expected identifier");
7570 while (c_parser_next_token_is (parser, CPP_NAME)
7571 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7573 tree t = lookup_name (c_parser_peek_token (parser)->value);
7576 undeclared_variable (c_parser_peek_token (parser)->location,
7577 c_parser_peek_token (parser)->value);
7578 else if (t == error_mark_node)
7582 tree u = build_omp_clause (clause_loc, kind);
7583 OMP_CLAUSE_DECL (u) = t;
7584 OMP_CLAUSE_CHAIN (u) = list;
7588 list = tree_cons (t, NULL_TREE, list);
7590 c_parser_consume_token (parser);
7592 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7595 c_parser_consume_token (parser);
7601 /* Similarly, but expect leading and trailing parenthesis. This is a very
7602 common case for omp clauses. */
7605 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7608 /* The clauses location. */
7609 location_t loc = c_parser_peek_token (parser)->location;
7611 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7613 list = c_parser_omp_variable_list (parser, loc, kind, list);
7614 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7620 collapse ( constant-expression ) */
7623 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7625 tree c, num = error_mark_node;
7629 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7631 loc = c_parser_peek_token (parser)->location;
7632 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7634 num = c_parser_expr_no_commas (parser, NULL).value;
7635 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7637 if (num == error_mark_node)
7639 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7640 || !host_integerp (num, 0)
7641 || (n = tree_low_cst (num, 0)) <= 0
7645 "collapse argument needs positive constant integer expression");
7648 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7649 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7650 OMP_CLAUSE_CHAIN (c) = list;
7655 copyin ( variable-list ) */
7658 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7660 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7664 copyprivate ( variable-list ) */
7667 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7669 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7673 default ( shared | none ) */
7676 c_parser_omp_clause_default (c_parser *parser, tree list)
7678 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7679 location_t loc = c_parser_peek_token (parser)->location;
7682 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7684 if (c_parser_next_token_is (parser, CPP_NAME))
7686 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7691 if (strcmp ("none", p) != 0)
7693 kind = OMP_CLAUSE_DEFAULT_NONE;
7697 if (strcmp ("shared", p) != 0)
7699 kind = OMP_CLAUSE_DEFAULT_SHARED;
7706 c_parser_consume_token (parser);
7711 c_parser_error (parser, "expected %<none%> or %<shared%>");
7713 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7715 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7718 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7719 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7720 OMP_CLAUSE_CHAIN (c) = list;
7721 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7727 firstprivate ( variable-list ) */
7730 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7732 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7736 if ( expression ) */
7739 c_parser_omp_clause_if (c_parser *parser, tree list)
7741 location_t loc = c_parser_peek_token (parser)->location;
7742 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7744 tree t = c_parser_paren_condition (parser);
7747 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7749 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7750 OMP_CLAUSE_IF_EXPR (c) = t;
7751 OMP_CLAUSE_CHAIN (c) = list;
7755 c_parser_error (parser, "expected %<(%>");
7761 lastprivate ( variable-list ) */
7764 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7766 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7773 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7776 location_t loc = c_parser_peek_token (parser)->location;
7778 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7780 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7781 OMP_CLAUSE_CHAIN (c) = list;
7786 num_threads ( expression ) */
7789 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7791 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7792 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7794 location_t expr_loc = c_parser_peek_token (parser)->location;
7795 tree c, t = c_parser_expression (parser).value;
7796 t = c_fully_fold (t, false, NULL);
7798 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7800 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7802 c_parser_error (parser, "expected integer expression");
7806 /* Attempt to statically determine when the number isn't positive. */
7807 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7808 build_int_cst (TREE_TYPE (t), 0));
7809 if (CAN_HAVE_LOCATION_P (c))
7810 SET_EXPR_LOCATION (c, expr_loc);
7811 if (c == boolean_true_node)
7813 warning_at (expr_loc, 0,
7814 "%<num_threads%> value must be positive");
7815 t = integer_one_node;
7818 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7820 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7821 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7822 OMP_CLAUSE_CHAIN (c) = list;
7833 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7837 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7839 c = build_omp_clause (c_parser_peek_token (parser)->location,
7840 OMP_CLAUSE_ORDERED);
7841 OMP_CLAUSE_CHAIN (c) = list;
7847 private ( variable-list ) */
7850 c_parser_omp_clause_private (c_parser *parser, tree list)
7852 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7856 reduction ( reduction-operator : variable-list )
7859 One of: + * - & ^ | && || */
7862 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7864 location_t clause_loc = c_parser_peek_token (parser)->location;
7865 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7867 enum tree_code code;
7869 switch (c_parser_peek_token (parser)->type)
7881 code = BIT_AND_EXPR;
7884 code = BIT_XOR_EXPR;
7887 code = BIT_IOR_EXPR;
7890 code = TRUTH_ANDIF_EXPR;
7893 code = TRUTH_ORIF_EXPR;
7896 c_parser_error (parser,
7897 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7898 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7899 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7902 c_parser_consume_token (parser);
7903 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7907 nl = c_parser_omp_variable_list (parser, clause_loc,
7908 OMP_CLAUSE_REDUCTION, list);
7909 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7910 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7914 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7920 schedule ( schedule-kind )
7921 schedule ( schedule-kind , expression )
7924 static | dynamic | guided | runtime | auto
7928 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7931 location_t loc = c_parser_peek_token (parser)->location;
7933 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7936 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7938 if (c_parser_next_token_is (parser, CPP_NAME))
7940 tree kind = c_parser_peek_token (parser)->value;
7941 const char *p = IDENTIFIER_POINTER (kind);
7946 if (strcmp ("dynamic", p) != 0)
7948 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7952 if (strcmp ("guided", p) != 0)
7954 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7958 if (strcmp ("runtime", p) != 0)
7960 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7967 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7968 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7969 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7970 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7974 c_parser_consume_token (parser);
7975 if (c_parser_next_token_is (parser, CPP_COMMA))
7978 c_parser_consume_token (parser);
7980 here = c_parser_peek_token (parser)->location;
7981 t = c_parser_expr_no_commas (parser, NULL).value;
7982 t = c_fully_fold (t, false, NULL);
7984 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7985 error_at (here, "schedule %<runtime%> does not take "
7986 "a %<chunk_size%> parameter");
7987 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7989 "schedule %<auto%> does not take "
7990 "a %<chunk_size%> parameter");
7991 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7992 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7994 c_parser_error (parser, "expected integer expression");
7996 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7999 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8000 "expected %<,%> or %<)%>");
8002 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
8003 OMP_CLAUSE_CHAIN (c) = list;
8007 c_parser_error (parser, "invalid schedule kind");
8008 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
8013 shared ( variable-list ) */
8016 c_parser_omp_clause_shared (c_parser *parser, tree list)
8018 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
8025 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
8029 /* FIXME: Should we allow duplicates? */
8030 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
8032 c = build_omp_clause (c_parser_peek_token (parser)->location,
8034 OMP_CLAUSE_CHAIN (c) = list;
8039 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8040 is a bitmask in MASK. Return the list of clauses found; the result
8041 of clause default goes in *pdefault. */
8044 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
8047 tree clauses = NULL;
8050 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8053 pragma_omp_clause c_kind;
8055 tree prev = clauses;
8057 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
8058 c_parser_consume_token (parser);
8061 here = c_parser_peek_token (parser)->location;
8062 c_kind = c_parser_omp_clause_name (parser);
8066 case PRAGMA_OMP_CLAUSE_COLLAPSE:
8067 clauses = c_parser_omp_clause_collapse (parser, clauses);
8068 c_name = "collapse";
8070 case PRAGMA_OMP_CLAUSE_COPYIN:
8071 clauses = c_parser_omp_clause_copyin (parser, clauses);
8074 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
8075 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
8076 c_name = "copyprivate";
8078 case PRAGMA_OMP_CLAUSE_DEFAULT:
8079 clauses = c_parser_omp_clause_default (parser, clauses);
8082 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
8083 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
8084 c_name = "firstprivate";
8086 case PRAGMA_OMP_CLAUSE_IF:
8087 clauses = c_parser_omp_clause_if (parser, clauses);
8090 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
8091 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
8092 c_name = "lastprivate";
8094 case PRAGMA_OMP_CLAUSE_NOWAIT:
8095 clauses = c_parser_omp_clause_nowait (parser, clauses);
8098 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
8099 clauses = c_parser_omp_clause_num_threads (parser, clauses);
8100 c_name = "num_threads";
8102 case PRAGMA_OMP_CLAUSE_ORDERED:
8103 clauses = c_parser_omp_clause_ordered (parser, clauses);
8106 case PRAGMA_OMP_CLAUSE_PRIVATE:
8107 clauses = c_parser_omp_clause_private (parser, clauses);
8110 case PRAGMA_OMP_CLAUSE_REDUCTION:
8111 clauses = c_parser_omp_clause_reduction (parser, clauses);
8112 c_name = "reduction";
8114 case PRAGMA_OMP_CLAUSE_SCHEDULE:
8115 clauses = c_parser_omp_clause_schedule (parser, clauses);
8116 c_name = "schedule";
8118 case PRAGMA_OMP_CLAUSE_SHARED:
8119 clauses = c_parser_omp_clause_shared (parser, clauses);
8122 case PRAGMA_OMP_CLAUSE_UNTIED:
8123 clauses = c_parser_omp_clause_untied (parser, clauses);
8127 c_parser_error (parser, "expected %<#pragma omp%> clause");
8131 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8133 /* Remove the invalid clause(s) from the list to avoid
8134 confusing the rest of the compiler. */
8136 error_at (here, "%qs is not valid for %qs", c_name, where);
8141 c_parser_skip_to_pragma_eol (parser);
8143 return c_finish_omp_clauses (clauses);
8150 In practice, we're also interested in adding the statement to an
8151 outer node. So it is convenient if we work around the fact that
8152 c_parser_statement calls add_stmt. */
8155 c_parser_omp_structured_block (c_parser *parser)
8157 tree stmt = push_stmt_list ();
8158 c_parser_statement (parser);
8159 return pop_stmt_list (stmt);
8163 # pragma omp atomic new-line
8167 x binop= expr | x++ | ++x | x-- | --x
8169 +, *, -, /, &, ^, |, <<, >>
8171 where x is an lvalue expression with scalar type.
8173 LOC is the location of the #pragma token. */
8176 c_parser_omp_atomic (location_t loc, c_parser *parser)
8180 enum tree_code code;
8181 struct c_expr rhs_expr;
8183 c_parser_skip_to_pragma_eol (parser);
8185 lhs = c_parser_unary_expression (parser).value;
8186 lhs = c_fully_fold (lhs, false, NULL);
8187 switch (TREE_CODE (lhs))
8191 c_parser_skip_to_end_of_block_or_statement (parser);
8194 case PREINCREMENT_EXPR:
8195 case POSTINCREMENT_EXPR:
8196 lhs = TREE_OPERAND (lhs, 0);
8198 rhs = integer_one_node;
8201 case PREDECREMENT_EXPR:
8202 case POSTDECREMENT_EXPR:
8203 lhs = TREE_OPERAND (lhs, 0);
8205 rhs = integer_one_node;
8209 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8210 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8211 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8212 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8213 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8214 (TREE_OPERAND (lhs, 1), 0), 0)))
8216 /* Undo effects of boolean_increment for post {in,de}crement. */
8217 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8220 if (TREE_CODE (lhs) == MODIFY_EXPR
8221 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8223 /* Undo effects of boolean_increment. */
8224 if (integer_onep (TREE_OPERAND (lhs, 1)))
8226 /* This is pre or post increment. */
8227 rhs = TREE_OPERAND (lhs, 1);
8228 lhs = TREE_OPERAND (lhs, 0);
8232 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8233 && TREE_OPERAND (lhs, 0)
8234 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8236 /* This is pre or post decrement. */
8237 rhs = TREE_OPERAND (lhs, 1);
8238 lhs = TREE_OPERAND (lhs, 0);
8245 switch (c_parser_peek_token (parser)->type)
8251 code = TRUNC_DIV_EXPR;
8266 code = BIT_AND_EXPR;
8269 code = BIT_IOR_EXPR;
8272 code = BIT_XOR_EXPR;
8275 c_parser_error (parser,
8276 "invalid operator for %<#pragma omp atomic%>");
8280 c_parser_consume_token (parser);
8282 location_t rhs_loc = c_parser_peek_token (parser)->location;
8283 rhs_expr = c_parser_expression (parser);
8284 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8286 rhs = rhs_expr.value;
8287 rhs = c_fully_fold (rhs, false, NULL);
8290 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8291 if (stmt != error_mark_node)
8293 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8298 # pragma omp barrier new-line
8302 c_parser_omp_barrier (c_parser *parser)
8304 location_t loc = c_parser_peek_token (parser)->location;
8305 c_parser_consume_pragma (parser);
8306 c_parser_skip_to_pragma_eol (parser);
8308 c_finish_omp_barrier (loc);
8312 # pragma omp critical [(name)] new-line
8315 LOC is the location of the #pragma itself. */
8318 c_parser_omp_critical (location_t loc, c_parser *parser)
8320 tree stmt, name = NULL;
8322 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8324 c_parser_consume_token (parser);
8325 if (c_parser_next_token_is (parser, CPP_NAME))
8327 name = c_parser_peek_token (parser)->value;
8328 c_parser_consume_token (parser);
8329 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8332 c_parser_error (parser, "expected identifier");
8334 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8335 c_parser_error (parser, "expected %<(%> or end of line");
8336 c_parser_skip_to_pragma_eol (parser);
8338 stmt = c_parser_omp_structured_block (parser);
8339 return c_finish_omp_critical (loc, stmt, name);
8343 # pragma omp flush flush-vars[opt] new-line
8346 ( variable-list ) */
8349 c_parser_omp_flush (c_parser *parser)
8351 location_t loc = c_parser_peek_token (parser)->location;
8352 c_parser_consume_pragma (parser);
8353 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8354 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8355 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8356 c_parser_error (parser, "expected %<(%> or end of line");
8357 c_parser_skip_to_pragma_eol (parser);
8359 c_finish_omp_flush (loc);
8362 /* Parse the restricted form of the for statement allowed by OpenMP.
8363 The real trick here is to determine the loop control variable early
8364 so that we can push a new decl if necessary to make it private.
8365 LOC is the location of the OMP in "#pragma omp". */
8368 c_parser_omp_for_loop (location_t loc,
8369 c_parser *parser, tree clauses, tree *par_clauses)
8371 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8372 tree declv, condv, incrv, initv, ret = NULL;
8373 bool fail = false, open_brace_parsed = false;
8374 int i, collapse = 1, nbraces = 0;
8376 VEC(tree,gc) *for_block = make_tree_vector ();
8378 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8379 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8380 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8382 gcc_assert (collapse >= 1);
8384 declv = make_tree_vec (collapse);
8385 initv = make_tree_vec (collapse);
8386 condv = make_tree_vec (collapse);
8387 incrv = make_tree_vec (collapse);
8389 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8391 c_parser_error (parser, "for statement expected");
8394 for_loc = c_parser_peek_token (parser)->location;
8395 c_parser_consume_token (parser);
8397 for (i = 0; i < collapse; i++)
8401 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8404 /* Parse the initialization declaration or expression. */
8405 if (c_parser_next_token_starts_declaration (parser))
8408 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
8409 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
8410 decl = check_for_loop_decls (for_loc);
8413 if (DECL_INITIAL (decl) == error_mark_node)
8414 decl = error_mark_node;
8417 else if (c_parser_next_token_is (parser, CPP_NAME)
8418 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8420 struct c_expr decl_exp;
8421 struct c_expr init_exp;
8422 location_t init_loc;
8424 decl_exp = c_parser_postfix_expression (parser);
8425 decl = decl_exp.value;
8427 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8429 init_loc = c_parser_peek_token (parser)->location;
8430 init_exp = c_parser_expr_no_commas (parser, NULL);
8431 init_exp = default_function_array_read_conversion (init_loc,
8433 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8434 NOP_EXPR, init_loc, init_exp.value,
8435 init_exp.original_type);
8436 init = c_process_expr_stmt (init_loc, init);
8438 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8443 c_parser_error (parser,
8444 "expected iteration declaration or initialization");
8445 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8451 /* Parse the loop condition. */
8453 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8455 location_t cond_loc = c_parser_peek_token (parser)->location;
8456 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8458 cond = cond_expr.value;
8459 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8460 cond = c_fully_fold (cond, false, NULL);
8461 switch (cond_expr.original_code)
8469 /* Can't be cond = error_mark_node, because we want to preserve
8470 the location until c_finish_omp_for. */
8471 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8474 protected_set_expr_location (cond, cond_loc);
8476 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8478 /* Parse the increment expression. */
8480 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8482 location_t incr_loc = c_parser_peek_token (parser)->location;
8484 incr = c_process_expr_stmt (incr_loc,
8485 c_parser_expression (parser).value);
8487 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8489 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8493 TREE_VEC_ELT (declv, i) = decl;
8494 TREE_VEC_ELT (initv, i) = init;
8495 TREE_VEC_ELT (condv, i) = cond;
8496 TREE_VEC_ELT (incrv, i) = incr;
8500 if (i == collapse - 1)
8503 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8504 in between the collapsed for loops to be still considered perfectly
8505 nested. Hopefully the final version clarifies this.
8506 For now handle (multiple) {'s and empty statements. */
8509 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8511 c_parser_consume_token (parser);
8514 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8516 c_parser_consume_token (parser);
8520 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8521 c_parser_consume_token (parser);
8524 c_parser_error (parser, "not enough perfectly nested loops");
8527 open_brace_parsed = true;
8537 nbraces += bracecount;
8540 save_break = c_break_label;
8541 c_break_label = size_one_node;
8542 save_cont = c_cont_label;
8543 c_cont_label = NULL_TREE;
8544 body = push_stmt_list ();
8546 if (open_brace_parsed)
8548 location_t here = c_parser_peek_token (parser)->location;
8549 stmt = c_begin_compound_stmt (true);
8550 c_parser_compound_statement_nostart (parser);
8551 add_stmt (c_end_compound_stmt (here, stmt, true));
8554 add_stmt (c_parser_c99_block_statement (parser));
8557 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8558 SET_EXPR_LOCATION (t, loc);
8562 body = pop_stmt_list (body);
8563 c_break_label = save_break;
8564 c_cont_label = save_cont;
8568 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8570 c_parser_consume_token (parser);
8573 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8574 c_parser_consume_token (parser);
8577 c_parser_error (parser, "collapsed loops not perfectly nested");
8580 location_t here = c_parser_peek_token (parser)->location;
8581 stmt = c_begin_compound_stmt (true);
8583 c_parser_compound_statement_nostart (parser);
8584 body = c_end_compound_stmt (here, stmt, true);
8591 /* Only bother calling c_finish_omp_for if we haven't already generated
8592 an error from the initialization parsing. */
8595 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8598 if (par_clauses != NULL)
8601 for (c = par_clauses; *c ; )
8602 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8603 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8604 c = &OMP_CLAUSE_CHAIN (*c);
8607 for (i = 0; i < collapse; i++)
8608 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8611 c = &OMP_CLAUSE_CHAIN (*c);
8612 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8615 "iteration variable %qD should not be firstprivate",
8616 OMP_CLAUSE_DECL (*c));
8617 *c = OMP_CLAUSE_CHAIN (*c);
8621 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8622 change it to shared (decl) in
8623 OMP_PARALLEL_CLAUSES. */
8624 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8625 OMP_CLAUSE_LASTPRIVATE);
8626 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8627 OMP_CLAUSE_CHAIN (l) = clauses;
8629 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8633 OMP_FOR_CLAUSES (stmt) = clauses;
8638 while (!VEC_empty (tree, for_block))
8640 /* FIXME diagnostics: LOC below should be the actual location of
8641 this particular for block. We need to build a list of
8642 locations to go along with FOR_BLOCK. */
8643 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
8646 release_tree_vector (for_block);
8651 #pragma omp for for-clause[optseq] new-line
8654 LOC is the location of the #pragma token.
8657 #define OMP_FOR_CLAUSE_MASK \
8658 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8659 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8660 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8661 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8662 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8663 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8664 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8665 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8668 c_parser_omp_for (location_t loc, c_parser *parser)
8670 tree block, clauses, ret;
8672 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8675 block = c_begin_compound_stmt (true);
8676 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8677 block = c_end_compound_stmt (loc, block, true);
8684 # pragma omp master new-line
8687 LOC is the location of the #pragma token.
8691 c_parser_omp_master (location_t loc, c_parser *parser)
8693 c_parser_skip_to_pragma_eol (parser);
8694 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8698 # pragma omp ordered new-line
8701 LOC is the location of the #pragma itself.
8705 c_parser_omp_ordered (location_t loc, c_parser *parser)
8707 c_parser_skip_to_pragma_eol (parser);
8708 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8714 { section-sequence }
8717 section-directive[opt] structured-block
8718 section-sequence section-directive structured-block
8720 SECTIONS_LOC is the location of the #pragma omp sections. */
8723 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8726 bool error_suppress = false;
8729 loc = c_parser_peek_token (parser)->location;
8730 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8732 /* Avoid skipping until the end of the block. */
8733 parser->error = false;
8737 stmt = push_stmt_list ();
8739 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8741 substmt = push_stmt_list ();
8745 c_parser_statement (parser);
8747 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8749 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8751 if (c_parser_next_token_is (parser, CPP_EOF))
8755 substmt = pop_stmt_list (substmt);
8756 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8757 SET_EXPR_LOCATION (substmt, loc);
8763 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8765 if (c_parser_next_token_is (parser, CPP_EOF))
8768 loc = c_parser_peek_token (parser)->location;
8769 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8771 c_parser_consume_pragma (parser);
8772 c_parser_skip_to_pragma_eol (parser);
8773 error_suppress = false;
8775 else if (!error_suppress)
8777 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8778 error_suppress = true;
8781 substmt = c_parser_omp_structured_block (parser);
8782 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8783 SET_EXPR_LOCATION (substmt, loc);
8786 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8787 "expected %<#pragma omp section%> or %<}%>");
8789 substmt = pop_stmt_list (stmt);
8791 stmt = make_node (OMP_SECTIONS);
8792 SET_EXPR_LOCATION (stmt, sections_loc);
8793 TREE_TYPE (stmt) = void_type_node;
8794 OMP_SECTIONS_BODY (stmt) = substmt;
8796 return add_stmt (stmt);
8800 # pragma omp sections sections-clause[optseq] newline
8803 LOC is the location of the #pragma token.
8806 #define OMP_SECTIONS_CLAUSE_MASK \
8807 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8808 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8809 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8810 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8811 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8814 c_parser_omp_sections (location_t loc, c_parser *parser)
8816 tree block, clauses, ret;
8818 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8819 "#pragma omp sections");
8821 block = c_begin_compound_stmt (true);
8822 ret = c_parser_omp_sections_scope (loc, parser);
8824 OMP_SECTIONS_CLAUSES (ret) = clauses;
8825 block = c_end_compound_stmt (loc, block, true);
8832 # pragma parallel parallel-clause new-line
8833 # pragma parallel for parallel-for-clause new-line
8834 # pragma parallel sections parallel-sections-clause new-line
8836 LOC is the location of the #pragma token.
8839 #define OMP_PARALLEL_CLAUSE_MASK \
8840 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8841 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8842 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8843 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8844 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8845 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8846 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8847 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8850 c_parser_omp_parallel (location_t loc, c_parser *parser)
8852 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8853 const char *p_name = "#pragma omp parallel";
8854 tree stmt, clauses, par_clause, ws_clause, block;
8855 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8857 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8859 c_parser_consume_token (parser);
8860 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8861 p_name = "#pragma omp parallel for";
8862 mask |= OMP_FOR_CLAUSE_MASK;
8863 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8865 else if (c_parser_next_token_is (parser, CPP_NAME))
8867 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8868 if (strcmp (p, "sections") == 0)
8870 c_parser_consume_token (parser);
8871 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8872 p_name = "#pragma omp parallel sections";
8873 mask |= OMP_SECTIONS_CLAUSE_MASK;
8874 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8878 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8882 case PRAGMA_OMP_PARALLEL:
8883 block = c_begin_omp_parallel ();
8884 c_parser_statement (parser);
8885 stmt = c_finish_omp_parallel (loc, clauses, block);
8888 case PRAGMA_OMP_PARALLEL_FOR:
8889 block = c_begin_omp_parallel ();
8890 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8891 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8892 stmt = c_finish_omp_parallel (loc, par_clause, block);
8893 OMP_PARALLEL_COMBINED (stmt) = 1;
8896 case PRAGMA_OMP_PARALLEL_SECTIONS:
8897 block = c_begin_omp_parallel ();
8898 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8899 stmt = c_parser_omp_sections_scope (loc, parser);
8901 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8902 stmt = c_finish_omp_parallel (loc, par_clause, block);
8903 OMP_PARALLEL_COMBINED (stmt) = 1;
8914 # pragma omp single single-clause[optseq] new-line
8917 LOC is the location of the #pragma.
8920 #define OMP_SINGLE_CLAUSE_MASK \
8921 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8922 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8923 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8924 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8927 c_parser_omp_single (location_t loc, c_parser *parser)
8929 tree stmt = make_node (OMP_SINGLE);
8930 SET_EXPR_LOCATION (stmt, loc);
8931 TREE_TYPE (stmt) = void_type_node;
8933 OMP_SINGLE_CLAUSES (stmt)
8934 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8935 "#pragma omp single");
8936 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8938 return add_stmt (stmt);
8942 # pragma omp task task-clause[optseq] new-line
8944 LOC is the location of the #pragma.
8947 #define OMP_TASK_CLAUSE_MASK \
8948 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8949 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8950 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8951 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8952 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8953 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8956 c_parser_omp_task (location_t loc, c_parser *parser)
8958 tree clauses, block;
8960 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8961 "#pragma omp task");
8963 block = c_begin_omp_task ();
8964 c_parser_statement (parser);
8965 return c_finish_omp_task (loc, clauses, block);
8969 # pragma omp taskwait new-line
8973 c_parser_omp_taskwait (c_parser *parser)
8975 location_t loc = c_parser_peek_token (parser)->location;
8976 c_parser_consume_pragma (parser);
8977 c_parser_skip_to_pragma_eol (parser);
8979 c_finish_omp_taskwait (loc);
8982 /* Main entry point to parsing most OpenMP pragmas. */
8985 c_parser_omp_construct (c_parser *parser)
8987 enum pragma_kind p_kind;
8991 loc = c_parser_peek_token (parser)->location;
8992 p_kind = c_parser_peek_token (parser)->pragma_kind;
8993 c_parser_consume_pragma (parser);
8997 case PRAGMA_OMP_ATOMIC:
8998 c_parser_omp_atomic (loc, parser);
9000 case PRAGMA_OMP_CRITICAL:
9001 stmt = c_parser_omp_critical (loc, parser);
9003 case PRAGMA_OMP_FOR:
9004 stmt = c_parser_omp_for (loc, parser);
9006 case PRAGMA_OMP_MASTER:
9007 stmt = c_parser_omp_master (loc, parser);
9009 case PRAGMA_OMP_ORDERED:
9010 stmt = c_parser_omp_ordered (loc, parser);
9012 case PRAGMA_OMP_PARALLEL:
9013 stmt = c_parser_omp_parallel (loc, parser);
9015 case PRAGMA_OMP_SECTIONS:
9016 stmt = c_parser_omp_sections (loc, parser);
9018 case PRAGMA_OMP_SINGLE:
9019 stmt = c_parser_omp_single (loc, parser);
9021 case PRAGMA_OMP_TASK:
9022 stmt = c_parser_omp_task (loc, parser);
9029 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
9034 # pragma omp threadprivate (variable-list) */
9037 c_parser_omp_threadprivate (c_parser *parser)
9042 c_parser_consume_pragma (parser);
9043 loc = c_parser_peek_token (parser)->location;
9044 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
9046 /* Mark every variable in VARS to be assigned thread local storage. */
9047 for (t = vars; t; t = TREE_CHAIN (t))
9049 tree v = TREE_PURPOSE (t);
9051 /* FIXME diagnostics: Ideally we should keep individual
9052 locations for all the variables in the var list to make the
9053 following errors more precise. Perhaps
9054 c_parser_omp_var_list_parens() should construct a list of
9055 locations to go along with the var list. */
9057 /* If V had already been marked threadprivate, it doesn't matter
9058 whether it had been used prior to this point. */
9059 if (TREE_CODE (v) != VAR_DECL)
9060 error_at (loc, "%qD is not a variable", v);
9061 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
9062 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
9063 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9064 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
9065 else if (TREE_TYPE (v) == error_mark_node)
9067 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
9068 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
9071 if (! DECL_THREAD_LOCAL_P (v))
9073 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
9074 /* If rtl has been already set for this var, call
9075 make_decl_rtl once again, so that encode_section_info
9076 has a chance to look at the new decl flags. */
9077 if (DECL_RTL_SET_P (v))
9080 C_DECL_THREADPRIVATE_P (v) = 1;
9084 c_parser_skip_to_pragma_eol (parser);
9088 /* Parse a single source file. */
9093 /* Use local storage to begin. If the first token is a pragma, parse it.
9094 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9095 which will cause garbage collection. */
9098 memset (&tparser, 0, sizeof tparser);
9099 the_parser = &tparser;
9101 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
9102 c_parser_pragma_pch_preprocess (&tparser);
9104 the_parser = ggc_alloc_c_parser ();
9105 *the_parser = tparser;
9107 /* Initialize EH, if we've been told to do so. */
9108 if (flag_exceptions)
9109 using_eh_for_cleanups ();
9111 c_parser_translation_unit (the_parser);
9115 #include "gt-c-parser.h"