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 "rtl.h" /* For decl_default_tls_model. */
46 #include "langhooks.h"
63 /* Initialization routine for this file. */
68 /* The only initialization required is of the reserved word
74 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
75 the c_token structure. */
76 gcc_assert (RID_MAX <= 255);
83 mask |= D_ASM | D_EXT;
87 if (!c_dialect_objc ())
88 mask |= D_OBJC | D_CXX_OBJC;
90 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
91 for (i = 0; i < num_c_common_reswords; i++)
93 /* If a keyword is disabled, do not enter it into the table
94 and so create a canonical spelling that isn't a keyword. */
95 if (c_common_reswords[i].disable & mask)
98 && (c_common_reswords[i].disable & D_CXXWARN))
100 id = get_identifier (c_common_reswords[i].word);
101 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
102 C_IS_RESERVED_WORD (id) = 1;
107 id = get_identifier (c_common_reswords[i].word);
108 C_SET_RID_CODE (id, c_common_reswords[i].rid);
109 C_IS_RESERVED_WORD (id) = 1;
110 ridpointers [(int) c_common_reswords[i].rid] = id;
114 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
115 and the C parser. Unlike the C++ lexer, the parser structure
116 stores the lexer information instead of using a separate structure.
117 Identifiers are separated into ordinary identifiers, type names,
118 keywords and some other Objective-C types of identifiers, and some
119 look-ahead is maintained.
121 ??? It might be a good idea to lex the whole file up front (as for
122 C++). It would then be possible to share more of the C and C++
123 lexer code, if desired. */
125 /* The following local token type is used. */
128 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
130 /* More information about the type of a CPP_NAME token. */
131 typedef enum c_id_kind {
132 /* An ordinary identifier. */
134 /* An identifier declared as a typedef name. */
136 /* An identifier declared as an Objective-C class name. */
138 /* An address space identifier. */
140 /* Not an identifier. */
144 /* A single C token after string literal concatenation and conversion
145 of preprocessing tokens to tokens. */
146 typedef struct GTY (()) c_token {
147 /* The kind of token. */
148 ENUM_BITFIELD (cpp_ttype) type : 8;
149 /* If this token is a CPP_NAME, this value indicates whether also
150 declared as some kind of type. Otherwise, it is C_ID_NONE. */
151 ENUM_BITFIELD (c_id_kind) id_kind : 8;
152 /* If this token is a keyword, this value indicates which keyword.
153 Otherwise, this value is RID_MAX. */
154 ENUM_BITFIELD (rid) keyword : 8;
155 /* If this token is a CPP_PRAGMA, this indicates the pragma that
156 was seen. Otherwise it is PRAGMA_NONE. */
157 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
158 /* The location at which this token was found. */
160 /* The value associated with this token, if any. */
164 /* A parser structure recording information about the state and
165 context of parsing. Includes lexer information with up to two
166 tokens of look-ahead; more are not needed for C. */
167 typedef struct GTY(()) c_parser {
168 /* The look-ahead tokens. */
170 /* How many look-ahead tokens are available (0, 1 or 2). */
172 /* True if a syntax error is being recovered from; false otherwise.
173 c_parser_error sets this flag. It should clear this flag when
174 enough tokens have been consumed to recover from the error. */
175 BOOL_BITFIELD error : 1;
176 /* True if we're processing a pragma, and shouldn't automatically
177 consume CPP_PRAGMA_EOL. */
178 BOOL_BITFIELD in_pragma : 1;
179 /* True if we're parsing the outermost block of an if statement. */
180 BOOL_BITFIELD in_if_block : 1;
181 /* True if we want to lex an untranslated string. */
182 BOOL_BITFIELD lex_untranslated_string : 1;
183 /* Objective-C specific parser/lexer information. */
184 BOOL_BITFIELD objc_pq_context : 1;
185 /* The following flag is needed to contextualize Objective-C lexical
186 analysis. In some cases (e.g., 'int NSObject;'), it is
187 undesirable to bind an identifier to an Objective-C class, even
188 if a class with that name exists. */
189 BOOL_BITFIELD objc_need_raw_identifier : 1;
193 /* The actual parser and external interface. ??? Does this need to be
194 garbage-collected? */
196 static GTY (()) c_parser *the_parser;
199 /* Read in and lex a single token, storing it in *TOKEN. */
202 c_lex_one_token (c_parser *parser, c_token *token)
204 timevar_push (TV_LEX);
206 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
207 (parser->lex_untranslated_string
208 ? C_LEX_STRING_NO_TRANSLATE : 0));
209 token->id_kind = C_ID_NONE;
210 token->keyword = RID_MAX;
211 token->pragma_kind = PRAGMA_NONE;
219 bool objc_force_identifier = parser->objc_need_raw_identifier;
220 if (c_dialect_objc ())
221 parser->objc_need_raw_identifier = false;
223 if (C_IS_RESERVED_WORD (token->value))
225 enum rid rid_code = C_RID_CODE (token->value);
227 if (rid_code == RID_CXX_COMPAT_WARN)
229 warning_at (token->location,
231 "identifier %qE conflicts with C++ keyword",
234 else if (rid_code >= RID_FIRST_ADDR_SPACE
235 && rid_code <= RID_LAST_ADDR_SPACE)
237 token->id_kind = C_ID_ADDRSPACE;
238 token->keyword = rid_code;
241 else if (c_dialect_objc ())
243 if (!objc_is_reserved_word (token->value)
244 && (!OBJC_IS_PQ_KEYWORD (rid_code)
245 || parser->objc_pq_context))
247 /* Return the canonical spelling for this keyword. */
248 token->value = ridpointers[(int) rid_code];
249 token->type = CPP_KEYWORD;
250 token->keyword = rid_code;
256 token->type = CPP_KEYWORD;
257 token->keyword = rid_code;
262 decl = lookup_name (token->value);
265 if (TREE_CODE (decl) == TYPE_DECL)
267 token->id_kind = C_ID_TYPENAME;
271 else if (c_dialect_objc ())
273 tree objc_interface_decl = objc_is_class_name (token->value);
274 /* Objective-C class names are in the same namespace as
275 variables and typedefs, and hence are shadowed by local
277 if (objc_interface_decl
278 && (global_bindings_p ()
279 || (!objc_force_identifier && !decl)))
281 token->value = objc_interface_decl;
282 token->id_kind = C_ID_CLASSNAME;
286 token->id_kind = C_ID_ID;
290 /* This only happens in Objective-C; it must be a keyword. */
291 token->type = CPP_KEYWORD;
292 token->keyword = C_RID_CODE (token->value);
296 case CPP_CLOSE_PAREN:
298 /* These tokens may affect the interpretation of any identifiers
299 following, if doing Objective-C. */
300 if (c_dialect_objc ())
301 parser->objc_need_raw_identifier = false;
304 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
305 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
311 timevar_pop (TV_LEX);
314 /* Return a pointer to the next token from PARSER, reading it in if
317 static inline c_token *
318 c_parser_peek_token (c_parser *parser)
320 if (parser->tokens_avail == 0)
322 c_lex_one_token (parser, &parser->tokens[0]);
323 parser->tokens_avail = 1;
325 return &parser->tokens[0];
328 /* Return true if the next token from PARSER has the indicated
332 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
334 return c_parser_peek_token (parser)->type == type;
337 /* Return true if the next token from PARSER does not have the
341 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
343 return !c_parser_next_token_is (parser, type);
346 /* Return true if the next token from PARSER is the indicated
350 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
352 return c_parser_peek_token (parser)->keyword == keyword;
355 /* Return true if TOKEN can start a type name,
358 c_token_starts_typename (c_token *token)
363 switch (token->id_kind)
372 gcc_assert (c_dialect_objc ());
378 switch (token->keyword)
410 if (c_dialect_objc ())
418 /* Return true if the next token from PARSER can start a type name,
421 c_parser_next_token_starts_typename (c_parser *parser)
423 c_token *token = c_parser_peek_token (parser);
424 return c_token_starts_typename (token);
427 /* Return true if TOKEN can start declaration specifiers, false
430 c_token_starts_declspecs (c_token *token)
435 switch (token->id_kind)
444 gcc_assert (c_dialect_objc ());
450 switch (token->keyword)
489 if (c_dialect_objc ())
498 /* Return true if TOKEN can start declaration specifiers or a static
499 assertion, false otherwise. */
501 c_token_starts_declaration (c_token *token)
503 if (c_token_starts_declspecs (token)
504 || token->keyword == RID_STATIC_ASSERT)
510 /* Return true if the next token from PARSER can start declaration
511 specifiers, false otherwise. */
513 c_parser_next_token_starts_declspecs (c_parser *parser)
515 c_token *token = c_parser_peek_token (parser);
516 return c_token_starts_declspecs (token);
519 /* Return true if the next token from PARSER can start declaration
520 specifiers or a static assertion, false otherwise. */
522 c_parser_next_token_starts_declaration (c_parser *parser)
524 c_token *token = c_parser_peek_token (parser);
525 return c_token_starts_declaration (token);
528 /* Return a pointer to the next-but-one token from PARSER, reading it
529 in if necessary. The next token is already read in. */
532 c_parser_peek_2nd_token (c_parser *parser)
534 if (parser->tokens_avail >= 2)
535 return &parser->tokens[1];
536 gcc_assert (parser->tokens_avail == 1);
537 gcc_assert (parser->tokens[0].type != CPP_EOF);
538 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
539 c_lex_one_token (parser, &parser->tokens[1]);
540 parser->tokens_avail = 2;
541 return &parser->tokens[1];
544 /* Consume the next token from PARSER. */
547 c_parser_consume_token (c_parser *parser)
549 gcc_assert (parser->tokens_avail >= 1);
550 gcc_assert (parser->tokens[0].type != CPP_EOF);
551 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
552 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
553 if (parser->tokens_avail == 2)
554 parser->tokens[0] = parser->tokens[1];
555 parser->tokens_avail--;
558 /* Expect the current token to be a #pragma. Consume it and remember
559 that we've begun parsing a pragma. */
562 c_parser_consume_pragma (c_parser *parser)
564 gcc_assert (!parser->in_pragma);
565 gcc_assert (parser->tokens_avail >= 1);
566 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
567 if (parser->tokens_avail == 2)
568 parser->tokens[0] = parser->tokens[1];
569 parser->tokens_avail--;
570 parser->in_pragma = true;
573 /* Update the globals input_location and in_system_header from
576 c_parser_set_source_position_from_token (c_token *token)
578 if (token->type != CPP_EOF)
580 input_location = token->location;
584 /* Issue a diagnostic of the form
585 FILE:LINE: MESSAGE before TOKEN
586 where TOKEN is the next token in the input stream of PARSER.
587 MESSAGE (specified by the caller) is usually of the form "expected
590 Do not issue a diagnostic if still recovering from an error.
592 ??? This is taken from the C++ parser, but building up messages in
593 this way is not i18n-friendly and some other approach should be
597 c_parser_error (c_parser *parser, const char *gmsgid)
599 c_token *token = c_parser_peek_token (parser);
602 parser->error = true;
605 /* This diagnostic makes more sense if it is tagged to the line of
606 the token we just peeked at. */
607 c_parser_set_source_position_from_token (token);
608 c_parse_error (gmsgid,
609 /* Because c_parse_error does not understand
610 CPP_KEYWORD, keywords are treated like
612 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
613 /* ??? The C parser does not save the cpp flags of a
614 token, we need to pass 0 here and we will not get
615 the source spelling of some tokens but rather the
616 canonical spelling. */
617 token->value, /*flags=*/0);
620 /* If the next token is of the indicated TYPE, consume it. Otherwise,
621 issue the error MSGID. If MSGID is NULL then a message has already
622 been produced and no message will be produced this time. Returns
623 true if found, false otherwise. */
626 c_parser_require (c_parser *parser,
630 if (c_parser_next_token_is (parser, type))
632 c_parser_consume_token (parser);
637 c_parser_error (parser, msgid);
642 /* If the next token is the indicated keyword, consume it. Otherwise,
643 issue the error MSGID. Returns true if found, false otherwise. */
646 c_parser_require_keyword (c_parser *parser,
650 if (c_parser_next_token_is_keyword (parser, keyword))
652 c_parser_consume_token (parser);
657 c_parser_error (parser, msgid);
662 /* Like c_parser_require, except that tokens will be skipped until the
663 desired token is found. An error message is still produced if the
664 next token is not as expected. If MSGID is NULL then a message has
665 already been produced and no message will be produced this
669 c_parser_skip_until_found (c_parser *parser,
673 unsigned nesting_depth = 0;
675 if (c_parser_require (parser, type, msgid))
678 /* Skip tokens until the desired token is found. */
681 /* Peek at the next token. */
682 c_token *token = c_parser_peek_token (parser);
683 /* If we've reached the token we want, consume it and stop. */
684 if (token->type == type && !nesting_depth)
686 c_parser_consume_token (parser);
690 /* If we've run out of tokens, stop. */
691 if (token->type == CPP_EOF)
693 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
695 if (token->type == CPP_OPEN_BRACE
696 || token->type == CPP_OPEN_PAREN
697 || token->type == CPP_OPEN_SQUARE)
699 else if (token->type == CPP_CLOSE_BRACE
700 || token->type == CPP_CLOSE_PAREN
701 || token->type == CPP_CLOSE_SQUARE)
703 if (nesting_depth-- == 0)
706 /* Consume this token. */
707 c_parser_consume_token (parser);
709 parser->error = false;
712 /* Skip tokens until the end of a parameter is found, but do not
713 consume the comma, semicolon or closing delimiter. */
716 c_parser_skip_to_end_of_parameter (c_parser *parser)
718 unsigned nesting_depth = 0;
722 c_token *token = c_parser_peek_token (parser);
723 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
726 /* If we've run out of tokens, stop. */
727 if (token->type == CPP_EOF)
729 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
731 if (token->type == CPP_OPEN_BRACE
732 || token->type == CPP_OPEN_PAREN
733 || token->type == CPP_OPEN_SQUARE)
735 else if (token->type == CPP_CLOSE_BRACE
736 || token->type == CPP_CLOSE_PAREN
737 || token->type == CPP_CLOSE_SQUARE)
739 if (nesting_depth-- == 0)
742 /* Consume this token. */
743 c_parser_consume_token (parser);
745 parser->error = false;
748 /* Expect to be at the end of the pragma directive and consume an
749 end of line marker. */
752 c_parser_skip_to_pragma_eol (c_parser *parser)
754 gcc_assert (parser->in_pragma);
755 parser->in_pragma = false;
757 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
760 c_token *token = c_parser_peek_token (parser);
761 if (token->type == CPP_EOF)
763 if (token->type == CPP_PRAGMA_EOL)
765 c_parser_consume_token (parser);
768 c_parser_consume_token (parser);
771 parser->error = false;
774 /* Skip tokens until we have consumed an entire block, or until we
775 have consumed a non-nested ';'. */
778 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
780 unsigned nesting_depth = 0;
781 bool save_error = parser->error;
787 /* Peek at the next token. */
788 token = c_parser_peek_token (parser);
796 if (parser->in_pragma)
801 /* If the next token is a ';', we have reached the
802 end of the statement. */
805 /* Consume the ';'. */
806 c_parser_consume_token (parser);
811 case CPP_CLOSE_BRACE:
812 /* If the next token is a non-nested '}', then we have
813 reached the end of the current block. */
814 if (nesting_depth == 0 || --nesting_depth == 0)
816 c_parser_consume_token (parser);
822 /* If it the next token is a '{', then we are entering a new
823 block. Consume the entire block. */
828 /* If we see a pragma, consume the whole thing at once. We
829 have some safeguards against consuming pragmas willy-nilly.
830 Normally, we'd expect to be here with parser->error set,
831 which disables these safeguards. But it's possible to get
832 here for secondary error recovery, after parser->error has
834 c_parser_consume_pragma (parser);
835 c_parser_skip_to_pragma_eol (parser);
836 parser->error = save_error;
843 c_parser_consume_token (parser);
847 parser->error = false;
850 /* CPP's options (initialized by c-opts.c). */
851 extern cpp_options *cpp_opts;
853 /* Save the warning flags which are controlled by __extension__. */
856 disable_extension_diagnostics (void)
859 | (warn_pointer_arith << 1)
860 | (warn_traditional << 2)
862 | (warn_long_long << 4)
863 | (warn_cxx_compat << 5));
864 cpp_opts->pedantic = pedantic = 0;
865 warn_pointer_arith = 0;
866 cpp_opts->warn_traditional = warn_traditional = 0;
868 cpp_opts->warn_long_long = warn_long_long = 0;
873 /* Restore the warning flags which are controlled by __extension__.
874 FLAGS is the return value from disable_extension_diagnostics. */
877 restore_extension_diagnostics (int flags)
879 cpp_opts->pedantic = pedantic = flags & 1;
880 warn_pointer_arith = (flags >> 1) & 1;
881 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
882 flag_iso = (flags >> 3) & 1;
883 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
884 warn_cxx_compat = (flags >> 5) & 1;
887 /* Possibly kinds of declarator to parse. */
888 typedef enum c_dtr_syn {
889 /* A normal declarator with an identifier. */
891 /* An abstract declarator (maybe empty). */
893 /* A parameter declarator: may be either, but after a type name does
894 not redeclare a typedef name as an identifier if it can
895 alternatively be interpreted as a typedef name; see DR#009,
896 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
897 following DR#249. For example, given a typedef T, "int T" and
898 "int *T" are valid parameter declarations redeclaring T, while
899 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
900 abstract declarators rather than involving redundant parentheses;
901 the same applies with attributes inside the parentheses before
906 static void c_parser_external_declaration (c_parser *);
907 static void c_parser_asm_definition (c_parser *);
908 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
910 static void c_parser_static_assert_declaration_no_semi (c_parser *);
911 static void c_parser_static_assert_declaration (c_parser *);
912 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
914 static struct c_typespec c_parser_enum_specifier (c_parser *);
915 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
916 static tree c_parser_struct_declaration (c_parser *);
917 static struct c_typespec c_parser_typeof_specifier (c_parser *);
918 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
920 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
922 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
924 struct c_declarator *);
925 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
926 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
927 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
928 static tree c_parser_simple_asm_expr (c_parser *);
929 static tree c_parser_attributes (c_parser *);
930 static struct c_type_name *c_parser_type_name (c_parser *);
931 static struct c_expr c_parser_initializer (c_parser *);
932 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
933 static void c_parser_initelt (c_parser *, struct obstack *);
934 static void c_parser_initval (c_parser *, struct c_expr *,
936 static tree c_parser_compound_statement (c_parser *);
937 static void c_parser_compound_statement_nostart (c_parser *);
938 static void c_parser_label (c_parser *);
939 static void c_parser_statement (c_parser *);
940 static void c_parser_statement_after_labels (c_parser *);
941 static void c_parser_if_statement (c_parser *);
942 static void c_parser_switch_statement (c_parser *);
943 static void c_parser_while_statement (c_parser *);
944 static void c_parser_do_statement (c_parser *);
945 static void c_parser_for_statement (c_parser *);
946 static tree c_parser_asm_statement (c_parser *);
947 static tree c_parser_asm_operands (c_parser *, bool);
948 static tree c_parser_asm_goto_operands (c_parser *);
949 static tree c_parser_asm_clobbers (c_parser *);
950 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
951 static struct c_expr c_parser_conditional_expression (c_parser *,
953 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
954 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
955 static struct c_expr c_parser_unary_expression (c_parser *);
956 static struct c_expr c_parser_sizeof_expression (c_parser *);
957 static struct c_expr c_parser_alignof_expression (c_parser *);
958 static struct c_expr c_parser_postfix_expression (c_parser *);
959 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
960 struct c_type_name *,
962 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
965 static struct c_expr c_parser_expression (c_parser *);
966 static struct c_expr c_parser_expression_conv (c_parser *);
967 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
969 static void c_parser_omp_construct (c_parser *);
970 static void c_parser_omp_threadprivate (c_parser *);
971 static void c_parser_omp_barrier (c_parser *);
972 static void c_parser_omp_flush (c_parser *);
973 static void c_parser_omp_taskwait (c_parser *);
975 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
976 static bool c_parser_pragma (c_parser *, enum pragma_context);
978 /* These Objective-C parser functions are only ever called when
979 compiling Objective-C. */
980 static void c_parser_objc_class_definition (c_parser *);
981 static void c_parser_objc_class_instance_variables (c_parser *);
982 static void c_parser_objc_class_declaration (c_parser *);
983 static void c_parser_objc_alias_declaration (c_parser *);
984 static void c_parser_objc_protocol_definition (c_parser *);
985 static enum tree_code c_parser_objc_method_type (c_parser *);
986 static void c_parser_objc_method_definition (c_parser *);
987 static void c_parser_objc_methodprotolist (c_parser *);
988 static void c_parser_objc_methodproto (c_parser *);
989 static tree c_parser_objc_method_decl (c_parser *);
990 static tree c_parser_objc_type_name (c_parser *);
991 static tree c_parser_objc_protocol_refs (c_parser *);
992 static void c_parser_objc_try_catch_statement (c_parser *);
993 static void c_parser_objc_synchronized_statement (c_parser *);
994 static tree c_parser_objc_selector (c_parser *);
995 static tree c_parser_objc_selector_arg (c_parser *);
996 static tree c_parser_objc_receiver (c_parser *);
997 static tree c_parser_objc_message_args (c_parser *);
998 static tree c_parser_objc_keywordexpr (c_parser *);
1000 /* Parse a translation unit (C90 6.7, C99 6.9).
1003 external-declarations
1005 external-declarations:
1006 external-declaration
1007 external-declarations external-declaration
1016 c_parser_translation_unit (c_parser *parser)
1018 if (c_parser_next_token_is (parser, CPP_EOF))
1020 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1021 "ISO C forbids an empty translation unit");
1025 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1026 mark_valid_location_for_stdc_pragma (false);
1030 c_parser_external_declaration (parser);
1031 obstack_free (&parser_obstack, obstack_position);
1033 while (c_parser_next_token_is_not (parser, CPP_EOF));
1037 /* Parse an external declaration (C90 6.7, C99 6.9).
1039 external-declaration:
1045 external-declaration:
1048 __extension__ external-declaration
1052 external-declaration:
1053 objc-class-definition
1054 objc-class-declaration
1055 objc-alias-declaration
1056 objc-protocol-definition
1057 objc-method-definition
1062 c_parser_external_declaration (c_parser *parser)
1065 switch (c_parser_peek_token (parser)->type)
1068 switch (c_parser_peek_token (parser)->keyword)
1071 ext = disable_extension_diagnostics ();
1072 c_parser_consume_token (parser);
1073 c_parser_external_declaration (parser);
1074 restore_extension_diagnostics (ext);
1077 c_parser_asm_definition (parser);
1079 case RID_AT_INTERFACE:
1080 case RID_AT_IMPLEMENTATION:
1081 gcc_assert (c_dialect_objc ());
1082 c_parser_objc_class_definition (parser);
1085 gcc_assert (c_dialect_objc ());
1086 c_parser_objc_class_declaration (parser);
1089 gcc_assert (c_dialect_objc ());
1090 c_parser_objc_alias_declaration (parser);
1092 case RID_AT_PROTOCOL:
1093 gcc_assert (c_dialect_objc ());
1094 c_parser_objc_protocol_definition (parser);
1097 gcc_assert (c_dialect_objc ());
1098 c_parser_consume_token (parser);
1099 objc_finish_implementation ();
1106 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1107 "ISO C does not allow extra %<;%> outside of a function");
1108 c_parser_consume_token (parser);
1111 mark_valid_location_for_stdc_pragma (true);
1112 c_parser_pragma (parser, pragma_external);
1113 mark_valid_location_for_stdc_pragma (false);
1117 if (c_dialect_objc ())
1119 c_parser_objc_method_definition (parser);
1122 /* Else fall through, and yield a syntax error trying to parse
1123 as a declaration or function definition. */
1126 /* A declaration or a function definition. We can only tell
1127 which after parsing the declaration specifiers, if any, and
1128 the first declarator. */
1129 c_parser_declaration_or_fndef (parser, true, true, true, false, true);
1135 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1136 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1137 accepted; otherwise (old-style parameter declarations) only other
1138 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1139 assertion is accepted; otherwise (old-style parameter declarations)
1140 it is not. If NESTED is true, we are inside a function or parsing
1141 old-style parameter declarations; any functions encountered are
1142 nested functions and declaration specifiers are required; otherwise
1143 we are at top level and functions are normal functions and
1144 declaration specifiers may be optional. If EMPTY_OK is true, empty
1145 declarations are OK (subject to all other constraints); otherwise
1146 (old-style parameter declarations) they are diagnosed. If
1147 START_ATTR_OK is true, the declaration specifiers may start with
1148 attributes; otherwise they may not.
1151 declaration-specifiers init-declarator-list[opt] ;
1152 static_assert-declaration
1154 function-definition:
1155 declaration-specifiers[opt] declarator declaration-list[opt]
1160 declaration-list declaration
1162 init-declarator-list:
1164 init-declarator-list , init-declarator
1167 declarator simple-asm-expr[opt] attributes[opt]
1168 declarator simple-asm-expr[opt] attributes[opt] = initializer
1172 nested-function-definition:
1173 declaration-specifiers declarator declaration-list[opt]
1176 The simple-asm-expr and attributes are GNU extensions.
1178 This function does not handle __extension__; that is handled in its
1179 callers. ??? Following the old parser, __extension__ may start
1180 external declarations, declarations in functions and declarations
1181 at the start of "for" loops, but not old-style parameter
1184 C99 requires declaration specifiers in a function definition; the
1185 absence is diagnosed through the diagnosis of implicit int. In GNU
1186 C we also allow but diagnose declarations without declaration
1187 specifiers, but only at top level (elsewhere they conflict with
1193 threadprivate-directive */
1196 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1197 bool static_assert_ok, bool empty_ok,
1198 bool nested, bool start_attr_ok)
1200 struct c_declspecs *specs;
1202 tree all_prefix_attrs;
1203 bool diagnosed_no_specs = false;
1204 location_t here = c_parser_peek_token (parser)->location;
1206 if (static_assert_ok
1207 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1209 c_parser_static_assert_declaration (parser);
1212 specs = build_null_declspecs ();
1213 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1216 c_parser_skip_to_end_of_block_or_statement (parser);
1219 if (nested && !specs->declspecs_seen_p)
1221 c_parser_error (parser, "expected declaration specifiers");
1222 c_parser_skip_to_end_of_block_or_statement (parser);
1225 finish_declspecs (specs);
1226 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1232 shadow_tag_warned (specs, 1);
1233 pedwarn (here, 0, "empty declaration");
1235 c_parser_consume_token (parser);
1238 pending_xref_error ();
1239 prefix_attrs = specs->attrs;
1240 all_prefix_attrs = prefix_attrs;
1241 specs->attrs = NULL_TREE;
1244 struct c_declarator *declarator;
1247 /* Declaring either one or more declarators (in which case we
1248 should diagnose if there were no declaration specifiers) or a
1249 function definition (in which case the diagnostic for
1250 implicit int suffices). */
1251 declarator = c_parser_declarator (parser, specs->type_seen_p,
1252 C_DTR_NORMAL, &dummy);
1253 if (declarator == NULL)
1255 c_parser_skip_to_end_of_block_or_statement (parser);
1258 if (c_parser_next_token_is (parser, CPP_EQ)
1259 || c_parser_next_token_is (parser, CPP_COMMA)
1260 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1261 || c_parser_next_token_is_keyword (parser, RID_ASM)
1262 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1264 tree asm_name = NULL_TREE;
1265 tree postfix_attrs = NULL_TREE;
1266 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1268 diagnosed_no_specs = true;
1269 pedwarn (here, 0, "data definition has no type or storage class");
1271 /* Having seen a data definition, there cannot now be a
1272 function definition. */
1274 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1275 asm_name = c_parser_simple_asm_expr (parser);
1276 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1277 postfix_attrs = c_parser_attributes (parser);
1278 if (c_parser_next_token_is (parser, CPP_EQ))
1282 location_t init_loc;
1283 c_parser_consume_token (parser);
1284 /* The declaration of the variable is in effect while
1285 its initializer is parsed. */
1286 d = start_decl (declarator, specs, true,
1287 chainon (postfix_attrs, all_prefix_attrs));
1289 d = error_mark_node;
1290 start_init (d, asm_name, global_bindings_p ());
1291 init_loc = c_parser_peek_token (parser)->location;
1292 init = c_parser_initializer (parser);
1294 if (d != error_mark_node)
1296 maybe_warn_string_init (TREE_TYPE (d), init);
1297 finish_decl (d, init_loc, init.value,
1298 init.original_type, asm_name);
1303 tree d = start_decl (declarator, specs, false,
1304 chainon (postfix_attrs,
1307 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1308 NULL_TREE, asm_name);
1310 if (c_parser_next_token_is (parser, CPP_COMMA))
1312 c_parser_consume_token (parser);
1313 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1314 all_prefix_attrs = chainon (c_parser_attributes (parser),
1317 all_prefix_attrs = prefix_attrs;
1320 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1322 c_parser_consume_token (parser);
1327 c_parser_error (parser, "expected %<,%> or %<;%>");
1328 c_parser_skip_to_end_of_block_or_statement (parser);
1334 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1335 "%<asm%> or %<__attribute__%>");
1336 c_parser_skip_to_end_of_block_or_statement (parser);
1339 /* Function definition (nested or otherwise). */
1342 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1343 c_push_function_context ();
1345 if (!start_function (specs, declarator, all_prefix_attrs))
1347 /* This can appear in many cases looking nothing like a
1348 function definition, so we don't give a more specific
1349 error suggesting there was one. */
1350 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1351 "or %<__attribute__%>");
1353 c_pop_function_context ();
1356 /* Parse old-style parameter declarations. ??? Attributes are
1357 not allowed to start declaration specifiers here because of a
1358 syntax conflict between a function declaration with attribute
1359 suffix and a function definition with an attribute prefix on
1360 first old-style parameter declaration. Following the old
1361 parser, they are not accepted on subsequent old-style
1362 parameter declarations either. However, there is no
1363 ambiguity after the first declaration, nor indeed on the
1364 first as long as we don't allow postfix attributes after a
1365 declarator with a nonempty identifier list in a definition;
1366 and postfix attributes have never been accepted here in
1367 function definitions either. */
1368 while (c_parser_next_token_is_not (parser, CPP_EOF)
1369 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1370 c_parser_declaration_or_fndef (parser, false, false, false,
1372 store_parm_decls ();
1373 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1374 = c_parser_peek_token (parser)->location;
1375 fnbody = c_parser_compound_statement (parser);
1378 tree decl = current_function_decl;
1379 /* Mark nested functions as needing static-chain initially.
1380 lower_nested_functions will recompute it but the
1381 DECL_STATIC_CHAIN flag is also used before that happens,
1382 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1383 DECL_STATIC_CHAIN (decl) = 1;
1386 c_pop_function_context ();
1387 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1398 /* Parse an asm-definition (asm() outside a function body). This is a
1406 c_parser_asm_definition (c_parser *parser)
1408 tree asm_str = c_parser_simple_asm_expr (parser);
1410 cgraph_add_asm_node (asm_str);
1411 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1414 /* Parse a static assertion (C1X N1425 6.7.10).
1416 static_assert-declaration:
1417 static_assert-declaration-no-semi ;
1421 c_parser_static_assert_declaration (c_parser *parser)
1423 c_parser_static_assert_declaration_no_semi (parser);
1425 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1426 c_parser_skip_to_end_of_block_or_statement (parser);
1429 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1432 static_assert-declaration-no-semi:
1433 _Static_assert ( constant-expression , string-literal )
1437 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1439 location_t assert_loc, value_loc;
1443 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1444 assert_loc = c_parser_peek_token (parser)->location;
1448 pedwarn (assert_loc, OPT_pedantic,
1449 "ISO C99 does not support %<_Static_assert%>");
1451 pedwarn (assert_loc, OPT_pedantic,
1452 "ISO C90 does not support %<_Static_assert%>");
1454 c_parser_consume_token (parser);
1455 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1457 value_loc = c_parser_peek_token (parser)->location;
1458 value = c_parser_expr_no_commas (parser, NULL).value;
1459 parser->lex_untranslated_string = true;
1460 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1462 parser->lex_untranslated_string = false;
1465 switch (c_parser_peek_token (parser)->type)
1471 case CPP_UTF8STRING:
1472 string = c_parser_peek_token (parser)->value;
1473 c_parser_consume_token (parser);
1474 parser->lex_untranslated_string = false;
1477 c_parser_error (parser, "expected string literal");
1478 parser->lex_untranslated_string = false;
1481 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1483 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1485 error_at (value_loc, "expression in static assertion is not an integer");
1488 if (TREE_CODE (value) != INTEGER_CST)
1490 value = c_fully_fold (value, false, NULL);
1491 if (TREE_CODE (value) == INTEGER_CST)
1492 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1493 "is not an integer constant expression");
1495 if (TREE_CODE (value) != INTEGER_CST)
1497 error_at (value_loc, "expression in static assertion is not constant");
1500 constant_expression_warning (value);
1501 if (integer_zerop (value))
1502 error_at (assert_loc, "static assertion failed: %E", string);
1505 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1506 6.7), adding them to SPECS (which may already include some).
1507 Storage class specifiers are accepted iff SCSPEC_OK; type
1508 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1509 the start iff START_ATTR_OK.
1511 declaration-specifiers:
1512 storage-class-specifier declaration-specifiers[opt]
1513 type-specifier declaration-specifiers[opt]
1514 type-qualifier declaration-specifiers[opt]
1515 function-specifier declaration-specifiers[opt]
1517 Function specifiers (inline) are from C99, and are currently
1518 handled as storage class specifiers, as is __thread.
1520 C90 6.5.1, C99 6.7.1:
1521 storage-class-specifier:
1532 C90 6.5.2, C99 6.7.2:
1545 [_Imaginary removed in C99 TC2]
1546 struct-or-union-specifier
1550 (_Bool and _Complex are new in C99.)
1552 C90 6.5.3, C99 6.7.3:
1558 address-space-qualifier
1560 (restrict is new in C99.)
1564 declaration-specifiers:
1565 attributes declaration-specifiers[opt]
1571 identifier recognized by the target
1573 storage-class-specifier:
1585 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1586 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1591 class-name objc-protocol-refs[opt]
1592 typedef-name objc-protocol-refs
1597 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1598 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1600 bool attrs_ok = start_attr_ok;
1601 bool seen_type = specs->type_seen_p;
1602 while (c_parser_next_token_is (parser, CPP_NAME)
1603 || c_parser_next_token_is (parser, CPP_KEYWORD)
1604 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1606 struct c_typespec t;
1608 location_t loc = c_parser_peek_token (parser)->location;
1609 if (c_parser_next_token_is (parser, CPP_NAME))
1611 tree value = c_parser_peek_token (parser)->value;
1612 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1614 if (kind == C_ID_ADDRSPACE)
1617 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1618 declspecs_add_addrspace (specs, as);
1619 c_parser_consume_token (parser);
1624 /* This finishes the specifiers unless a type name is OK, it
1625 is declared as a type name and a type name hasn't yet
1627 if (!typespec_ok || seen_type
1628 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1630 c_parser_consume_token (parser);
1633 if (kind == C_ID_TYPENAME
1634 && (!c_dialect_objc ()
1635 || c_parser_next_token_is_not (parser, CPP_LESS)))
1637 t.kind = ctsk_typedef;
1638 /* For a typedef name, record the meaning, not the name.
1639 In case of 'foo foo, bar;'. */
1640 t.spec = lookup_name (value);
1642 t.expr_const_operands = true;
1646 tree proto = NULL_TREE;
1647 gcc_assert (c_dialect_objc ());
1649 if (c_parser_next_token_is (parser, CPP_LESS))
1650 proto = c_parser_objc_protocol_refs (parser);
1651 t.spec = objc_get_protocol_qualified_type (value, proto);
1653 t.expr_const_operands = true;
1655 declspecs_add_type (loc, specs, t);
1658 if (c_parser_next_token_is (parser, CPP_LESS))
1660 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1661 nisse@lysator.liu.se. */
1663 gcc_assert (c_dialect_objc ());
1664 if (!typespec_ok || seen_type)
1666 proto = c_parser_objc_protocol_refs (parser);
1668 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1670 t.expr_const_operands = true;
1671 declspecs_add_type (loc, specs, t);
1674 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1675 switch (c_parser_peek_token (parser)->keyword)
1687 /* TODO: Distinguish between function specifiers (inline)
1688 and storage class specifiers, either here or in
1689 declspecs_add_scspec. */
1690 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1691 c_parser_consume_token (parser);
1714 if (c_dialect_objc ())
1715 parser->objc_need_raw_identifier = true;
1716 t.kind = ctsk_resword;
1717 t.spec = c_parser_peek_token (parser)->value;
1719 t.expr_const_operands = true;
1720 declspecs_add_type (loc, specs, t);
1721 c_parser_consume_token (parser);
1728 t = c_parser_enum_specifier (parser);
1729 declspecs_add_type (loc, specs, t);
1737 t = c_parser_struct_or_union_specifier (parser);
1738 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1739 declspecs_add_type (loc, specs, t);
1742 /* ??? The old parser rejected typeof after other type
1743 specifiers, but is a syntax error the best way of
1745 if (!typespec_ok || seen_type)
1749 t = c_parser_typeof_specifier (parser);
1750 declspecs_add_type (loc, specs, t);
1756 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1757 c_parser_consume_token (parser);
1762 attrs = c_parser_attributes (parser);
1763 declspecs_add_attrs (specs, attrs);
1772 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1775 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1776 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1777 enum attributes[opt] identifier
1779 The form with trailing comma is new in C99. The forms with
1780 attributes are GNU extensions. In GNU C, we accept any expression
1781 without commas in the syntax (assignment expressions, not just
1782 conditional expressions); assignment expressions will be diagnosed
1787 enumerator-list , enumerator
1790 enumeration-constant
1791 enumeration-constant = constant-expression
1794 static struct c_typespec
1795 c_parser_enum_specifier (c_parser *parser)
1797 struct c_typespec ret;
1799 tree ident = NULL_TREE;
1800 location_t enum_loc;
1801 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1802 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1803 enum_loc = c_parser_peek_token (parser)->location;
1804 c_parser_consume_token (parser);
1805 attrs = c_parser_attributes (parser);
1806 enum_loc = c_parser_peek_token (parser)->location;
1807 /* Set the location in case we create a decl now. */
1808 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1809 if (c_parser_next_token_is (parser, CPP_NAME))
1811 ident = c_parser_peek_token (parser)->value;
1812 ident_loc = c_parser_peek_token (parser)->location;
1813 enum_loc = ident_loc;
1814 c_parser_consume_token (parser);
1816 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1818 /* Parse an enum definition. */
1819 struct c_enum_contents the_enum;
1820 tree type = start_enum (enum_loc, &the_enum, ident);
1822 /* We chain the enumerators in reverse order, then put them in
1823 forward order at the end. */
1824 tree values = NULL_TREE;
1825 c_parser_consume_token (parser);
1833 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1834 location_t value_loc;
1835 if (c_parser_next_token_is_not (parser, CPP_NAME))
1837 c_parser_error (parser, "expected identifier");
1838 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1839 values = error_mark_node;
1842 token = c_parser_peek_token (parser);
1843 enum_id = token->value;
1844 /* Set the location in case we create a decl now. */
1845 c_parser_set_source_position_from_token (token);
1846 value_loc = token->location;
1847 c_parser_consume_token (parser);
1848 if (c_parser_next_token_is (parser, CPP_EQ))
1850 c_parser_consume_token (parser);
1851 value_loc = c_parser_peek_token (parser)->location;
1852 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1855 enum_value = NULL_TREE;
1856 enum_decl = build_enumerator (value_loc,
1857 &the_enum, enum_id, enum_value);
1858 TREE_CHAIN (enum_decl) = values;
1861 if (c_parser_next_token_is (parser, CPP_COMMA))
1863 comma_loc = c_parser_peek_token (parser)->location;
1865 c_parser_consume_token (parser);
1867 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1869 if (seen_comma && !flag_isoc99)
1870 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1871 c_parser_consume_token (parser);
1876 c_parser_error (parser, "expected %<,%> or %<}%>");
1877 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1878 values = error_mark_node;
1882 postfix_attrs = c_parser_attributes (parser);
1883 ret.spec = finish_enum (type, nreverse (values),
1884 chainon (attrs, postfix_attrs));
1885 ret.kind = ctsk_tagdef;
1886 ret.expr = NULL_TREE;
1887 ret.expr_const_operands = true;
1892 c_parser_error (parser, "expected %<{%>");
1893 ret.spec = error_mark_node;
1894 ret.kind = ctsk_tagref;
1895 ret.expr = NULL_TREE;
1896 ret.expr_const_operands = true;
1899 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1900 /* In ISO C, enumerated types can be referred to only if already
1902 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1905 pedwarn (enum_loc, OPT_pedantic,
1906 "ISO C forbids forward references to %<enum%> types");
1911 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1913 struct-or-union-specifier:
1914 struct-or-union attributes[opt] identifier[opt]
1915 { struct-contents } attributes[opt]
1916 struct-or-union attributes[opt] identifier
1919 struct-declaration-list
1921 struct-declaration-list:
1922 struct-declaration ;
1923 struct-declaration-list struct-declaration ;
1930 struct-declaration-list struct-declaration
1932 struct-declaration-list:
1933 struct-declaration-list ;
1936 (Note that in the syntax here, unlike that in ISO C, the semicolons
1937 are included here rather than in struct-declaration, in order to
1938 describe the syntax with extra semicolons and missing semicolon at
1943 struct-declaration-list:
1944 @defs ( class-name )
1946 (Note this does not include a trailing semicolon, but can be
1947 followed by further declarations, and gets a pedwarn-if-pedantic
1948 when followed by a semicolon.) */
1950 static struct c_typespec
1951 c_parser_struct_or_union_specifier (c_parser *parser)
1953 struct c_typespec ret;
1955 tree ident = NULL_TREE;
1956 location_t struct_loc;
1957 location_t ident_loc = UNKNOWN_LOCATION;
1958 enum tree_code code;
1959 switch (c_parser_peek_token (parser)->keyword)
1970 struct_loc = c_parser_peek_token (parser)->location;
1971 c_parser_consume_token (parser);
1972 attrs = c_parser_attributes (parser);
1974 /* Set the location in case we create a decl now. */
1975 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1977 if (c_parser_next_token_is (parser, CPP_NAME))
1979 ident = c_parser_peek_token (parser)->value;
1980 ident_loc = c_parser_peek_token (parser)->location;
1981 struct_loc = ident_loc;
1982 c_parser_consume_token (parser);
1984 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1986 /* Parse a struct or union definition. Start the scope of the
1987 tag before parsing components. */
1988 struct c_struct_parse_info *struct_info;
1989 tree type = start_struct (struct_loc, code, ident, &struct_info);
1991 /* We chain the components in reverse order, then put them in
1992 forward order at the end. Each struct-declaration may
1993 declare multiple components (comma-separated), so we must use
1994 chainon to join them, although when parsing each
1995 struct-declaration we can use TREE_CHAIN directly.
1997 The theory behind all this is that there will be more
1998 semicolon separated fields than comma separated fields, and
1999 so we'll be minimizing the number of node traversals required
2001 tree contents = NULL_TREE;
2002 c_parser_consume_token (parser);
2003 /* Handle the Objective-C @defs construct,
2004 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2005 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2008 gcc_assert (c_dialect_objc ());
2009 c_parser_consume_token (parser);
2010 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2012 if (c_parser_next_token_is (parser, CPP_NAME)
2013 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2015 name = c_parser_peek_token (parser)->value;
2016 c_parser_consume_token (parser);
2020 c_parser_error (parser, "expected class name");
2021 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2024 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2026 contents = nreverse (objc_get_class_ivars (name));
2029 /* Parse the struct-declarations and semicolons. Problems with
2030 semicolons are diagnosed here; empty structures are diagnosed
2035 /* Parse any stray semicolon. */
2036 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2038 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2039 "extra semicolon in struct or union specified");
2040 c_parser_consume_token (parser);
2043 /* Stop if at the end of the struct or union contents. */
2044 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2046 c_parser_consume_token (parser);
2049 /* Accept #pragmas at struct scope. */
2050 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2052 c_parser_pragma (parser, pragma_external);
2055 /* Parse some comma-separated declarations, but not the
2056 trailing semicolon if any. */
2057 decls = c_parser_struct_declaration (parser);
2058 contents = chainon (decls, contents);
2059 /* If no semicolon follows, either we have a parse error or
2060 are at the end of the struct or union and should
2062 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2063 c_parser_consume_token (parser);
2066 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2067 pedwarn (c_parser_peek_token (parser)->location, 0,
2068 "no semicolon at end of struct or union");
2071 c_parser_error (parser, "expected %<;%>");
2072 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2077 postfix_attrs = c_parser_attributes (parser);
2078 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2079 chainon (attrs, postfix_attrs), struct_info);
2080 ret.kind = ctsk_tagdef;
2081 ret.expr = NULL_TREE;
2082 ret.expr_const_operands = true;
2087 c_parser_error (parser, "expected %<{%>");
2088 ret.spec = error_mark_node;
2089 ret.kind = ctsk_tagref;
2090 ret.expr = NULL_TREE;
2091 ret.expr_const_operands = true;
2094 ret = parser_xref_tag (ident_loc, code, ident);
2098 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2099 the trailing semicolon.
2102 specifier-qualifier-list struct-declarator-list
2103 static_assert-declaration-no-semi
2105 specifier-qualifier-list:
2106 type-specifier specifier-qualifier-list[opt]
2107 type-qualifier specifier-qualifier-list[opt]
2108 attributes specifier-qualifier-list[opt]
2110 struct-declarator-list:
2112 struct-declarator-list , attributes[opt] struct-declarator
2115 declarator attributes[opt]
2116 declarator[opt] : constant-expression attributes[opt]
2121 __extension__ struct-declaration
2122 specifier-qualifier-list
2124 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2125 of attributes where shown is a GNU extension. In GNU C, we accept
2126 any expression without commas in the syntax (assignment
2127 expressions, not just conditional expressions); assignment
2128 expressions will be diagnosed as non-constant. */
2131 c_parser_struct_declaration (c_parser *parser)
2133 struct c_declspecs *specs;
2135 tree all_prefix_attrs;
2137 location_t decl_loc;
2138 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2142 ext = disable_extension_diagnostics ();
2143 c_parser_consume_token (parser);
2144 decl = c_parser_struct_declaration (parser);
2145 restore_extension_diagnostics (ext);
2148 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2150 c_parser_static_assert_declaration_no_semi (parser);
2153 specs = build_null_declspecs ();
2154 decl_loc = c_parser_peek_token (parser)->location;
2155 c_parser_declspecs (parser, specs, false, true, true);
2158 if (!specs->declspecs_seen_p)
2160 c_parser_error (parser, "expected specifier-qualifier-list");
2163 finish_declspecs (specs);
2164 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2167 if (!specs->type_seen_p)
2169 pedwarn (decl_loc, OPT_pedantic,
2170 "ISO C forbids member declarations with no members");
2171 shadow_tag_warned (specs, pedantic);
2176 /* Support for unnamed structs or unions as members of
2177 structs or unions (which is [a] useful and [b] supports
2181 ret = grokfield (c_parser_peek_token (parser)->location,
2182 build_id_declarator (NULL_TREE), specs,
2185 decl_attributes (&ret, attrs, 0);
2189 pending_xref_error ();
2190 prefix_attrs = specs->attrs;
2191 all_prefix_attrs = prefix_attrs;
2192 specs->attrs = NULL_TREE;
2196 /* Declaring one or more declarators or un-named bit-fields. */
2197 struct c_declarator *declarator;
2199 if (c_parser_next_token_is (parser, CPP_COLON))
2200 declarator = build_id_declarator (NULL_TREE);
2202 declarator = c_parser_declarator (parser, specs->type_seen_p,
2203 C_DTR_NORMAL, &dummy);
2204 if (declarator == NULL)
2206 c_parser_skip_to_end_of_block_or_statement (parser);
2209 if (c_parser_next_token_is (parser, CPP_COLON)
2210 || c_parser_next_token_is (parser, CPP_COMMA)
2211 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2212 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2213 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2215 tree postfix_attrs = NULL_TREE;
2216 tree width = NULL_TREE;
2218 if (c_parser_next_token_is (parser, CPP_COLON))
2220 c_parser_consume_token (parser);
2221 width = c_parser_expr_no_commas (parser, NULL).value;
2223 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2224 postfix_attrs = c_parser_attributes (parser);
2225 d = grokfield (c_parser_peek_token (parser)->location,
2226 declarator, specs, width, &all_prefix_attrs);
2227 decl_attributes (&d, chainon (postfix_attrs,
2228 all_prefix_attrs), 0);
2229 TREE_CHAIN (d) = decls;
2231 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2232 all_prefix_attrs = chainon (c_parser_attributes (parser),
2235 all_prefix_attrs = prefix_attrs;
2236 if (c_parser_next_token_is (parser, CPP_COMMA))
2237 c_parser_consume_token (parser);
2238 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2239 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2241 /* Semicolon consumed in caller. */
2246 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2252 c_parser_error (parser,
2253 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2254 "%<__attribute__%>");
2261 /* Parse a typeof specifier (a GNU extension).
2264 typeof ( expression )
2265 typeof ( type-name )
2268 static struct c_typespec
2269 c_parser_typeof_specifier (c_parser *parser)
2271 struct c_typespec ret;
2272 ret.kind = ctsk_typeof;
2273 ret.spec = error_mark_node;
2274 ret.expr = NULL_TREE;
2275 ret.expr_const_operands = true;
2276 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2277 c_parser_consume_token (parser);
2278 c_inhibit_evaluation_warnings++;
2280 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2282 c_inhibit_evaluation_warnings--;
2286 if (c_parser_next_token_starts_typename (parser))
2288 struct c_type_name *type = c_parser_type_name (parser);
2289 c_inhibit_evaluation_warnings--;
2293 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2294 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2300 location_t here = c_parser_peek_token (parser)->location;
2301 struct c_expr expr = c_parser_expression (parser);
2302 c_inhibit_evaluation_warnings--;
2304 if (TREE_CODE (expr.value) == COMPONENT_REF
2305 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2306 error_at (here, "%<typeof%> applied to a bit-field");
2307 mark_exp_read (expr.value);
2308 ret.spec = TREE_TYPE (expr.value);
2309 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2310 /* This is returned with the type so that when the type is
2311 evaluated, this can be evaluated. */
2313 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2314 pop_maybe_used (was_vm);
2316 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2320 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2321 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2322 be redeclared; otherwise it may not. KIND indicates which kind of
2323 declarator is wanted. Returns a valid declarator except in the
2324 case of a syntax error in which case NULL is returned. *SEEN_ID is
2325 set to true if an identifier being declared is seen; this is used
2326 to diagnose bad forms of abstract array declarators and to
2327 determine whether an identifier list is syntactically permitted.
2330 pointer[opt] direct-declarator
2334 ( attributes[opt] declarator )
2335 direct-declarator array-declarator
2336 direct-declarator ( parameter-type-list )
2337 direct-declarator ( identifier-list[opt] )
2340 * type-qualifier-list[opt]
2341 * type-qualifier-list[opt] pointer
2343 type-qualifier-list:
2346 type-qualifier-list type-qualifier
2347 type-qualifier-list attributes
2349 parameter-type-list:
2351 parameter-list , ...
2354 parameter-declaration
2355 parameter-list , parameter-declaration
2357 parameter-declaration:
2358 declaration-specifiers declarator attributes[opt]
2359 declaration-specifiers abstract-declarator[opt] attributes[opt]
2363 identifier-list , identifier
2365 abstract-declarator:
2367 pointer[opt] direct-abstract-declarator
2369 direct-abstract-declarator:
2370 ( attributes[opt] abstract-declarator )
2371 direct-abstract-declarator[opt] array-declarator
2372 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2377 direct-declarator ( parameter-forward-declarations
2378 parameter-type-list[opt] )
2380 direct-abstract-declarator:
2381 direct-abstract-declarator[opt] ( parameter-forward-declarations
2382 parameter-type-list[opt] )
2384 parameter-forward-declarations:
2386 parameter-forward-declarations parameter-list ;
2388 The uses of attributes shown above are GNU extensions.
2390 Some forms of array declarator are not included in C99 in the
2391 syntax for abstract declarators; these are disallowed elsewhere.
2392 This may be a defect (DR#289).
2394 This function also accepts an omitted abstract declarator as being
2395 an abstract declarator, although not part of the formal syntax. */
2397 static struct c_declarator *
2398 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2401 /* Parse any initial pointer part. */
2402 if (c_parser_next_token_is (parser, CPP_MULT))
2404 struct c_declspecs *quals_attrs = build_null_declspecs ();
2405 struct c_declarator *inner;
2406 c_parser_consume_token (parser);
2407 c_parser_declspecs (parser, quals_attrs, false, false, true);
2408 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2412 return make_pointer_declarator (quals_attrs, inner);
2414 /* Now we have a direct declarator, direct abstract declarator or
2415 nothing (which counts as a direct abstract declarator here). */
2416 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2419 /* Parse a direct declarator or direct abstract declarator; arguments
2420 as c_parser_declarator. */
2422 static struct c_declarator *
2423 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2426 /* The direct declarator must start with an identifier (possibly
2427 omitted) or a parenthesized declarator (possibly abstract). In
2428 an ordinary declarator, initial parentheses must start a
2429 parenthesized declarator. In an abstract declarator or parameter
2430 declarator, they could start a parenthesized declarator or a
2431 parameter list. To tell which, the open parenthesis and any
2432 following attributes must be read. If a declaration specifier
2433 follows, then it is a parameter list; if the specifier is a
2434 typedef name, there might be an ambiguity about redeclaring it,
2435 which is resolved in the direction of treating it as a typedef
2436 name. If a close parenthesis follows, it is also an empty
2437 parameter list, as the syntax does not permit empty abstract
2438 declarators. Otherwise, it is a parenthesized declarator (in
2439 which case the analysis may be repeated inside it, recursively).
2441 ??? There is an ambiguity in a parameter declaration "int
2442 (__attribute__((foo)) x)", where x is not a typedef name: it
2443 could be an abstract declarator for a function, or declare x with
2444 parentheses. The proper resolution of this ambiguity needs
2445 documenting. At present we follow an accident of the old
2446 parser's implementation, whereby the first parameter must have
2447 some declaration specifiers other than just attributes. Thus as
2448 a parameter declaration it is treated as a parenthesized
2449 parameter named x, and as an abstract declarator it is
2452 ??? Also following the old parser, attributes inside an empty
2453 parameter list are ignored, making it a list not yielding a
2454 prototype, rather than giving an error or making it have one
2455 parameter with implicit type int.
2457 ??? Also following the old parser, typedef names may be
2458 redeclared in declarators, but not Objective-C class names. */
2460 if (kind != C_DTR_ABSTRACT
2461 && c_parser_next_token_is (parser, CPP_NAME)
2463 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2464 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2466 struct c_declarator *inner
2467 = build_id_declarator (c_parser_peek_token (parser)->value);
2469 inner->id_loc = c_parser_peek_token (parser)->location;
2470 c_parser_consume_token (parser);
2471 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2474 if (kind != C_DTR_NORMAL
2475 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2477 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2478 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2481 /* Either we are at the end of an abstract declarator, or we have
2484 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2487 struct c_declarator *inner;
2488 c_parser_consume_token (parser);
2489 attrs = c_parser_attributes (parser);
2490 if (kind != C_DTR_NORMAL
2491 && (c_parser_next_token_starts_declspecs (parser)
2492 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2494 struct c_arg_info *args
2495 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2502 = build_function_declarator (args,
2503 build_id_declarator (NULL_TREE));
2504 return c_parser_direct_declarator_inner (parser, *seen_id,
2508 /* A parenthesized declarator. */
2509 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2510 if (inner != NULL && attrs != NULL)
2511 inner = build_attrs_declarator (attrs, inner);
2512 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2514 c_parser_consume_token (parser);
2518 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2522 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2529 if (kind == C_DTR_NORMAL)
2531 c_parser_error (parser, "expected identifier or %<(%>");
2535 return build_id_declarator (NULL_TREE);
2539 /* Parse part of a direct declarator or direct abstract declarator,
2540 given that some (in INNER) has already been parsed; ID_PRESENT is
2541 true if an identifier is present, false for an abstract
2544 static struct c_declarator *
2545 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2546 struct c_declarator *inner)
2548 /* Parse a sequence of array declarators and parameter lists. */
2549 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2551 location_t brace_loc = c_parser_peek_token (parser)->location;
2552 struct c_declarator *declarator;
2553 struct c_declspecs *quals_attrs = build_null_declspecs ();
2557 c_parser_consume_token (parser);
2558 c_parser_declspecs (parser, quals_attrs, false, false, true);
2559 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2561 c_parser_consume_token (parser);
2562 if (static_seen && !quals_attrs->declspecs_seen_p)
2563 c_parser_declspecs (parser, quals_attrs, false, false, true);
2564 if (!quals_attrs->declspecs_seen_p)
2566 /* If "static" is present, there must be an array dimension.
2567 Otherwise, there may be a dimension, "*", or no
2572 dimen = c_parser_expr_no_commas (parser, NULL).value;
2576 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2581 else if (c_parser_next_token_is (parser, CPP_MULT))
2583 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2587 c_parser_consume_token (parser);
2592 dimen = c_parser_expr_no_commas (parser, NULL).value;
2598 dimen = c_parser_expr_no_commas (parser, NULL).value;
2601 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2602 c_parser_consume_token (parser);
2605 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2610 mark_exp_read (dimen);
2611 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2612 static_seen, star_seen);
2613 if (declarator == NULL)
2615 inner = set_array_declarator_inner (declarator, inner);
2616 return c_parser_direct_declarator_inner (parser, id_present, inner);
2618 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2621 struct c_arg_info *args;
2622 c_parser_consume_token (parser);
2623 attrs = c_parser_attributes (parser);
2624 args = c_parser_parms_declarator (parser, id_present, attrs);
2629 inner = build_function_declarator (args, inner);
2630 return c_parser_direct_declarator_inner (parser, id_present, inner);
2636 /* Parse a parameter list or identifier list, including the closing
2637 parenthesis but not the opening one. ATTRS are the attributes at
2638 the start of the list. ID_LIST_OK is true if an identifier list is
2639 acceptable; such a list must not have attributes at the start. */
2641 static struct c_arg_info *
2642 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2645 declare_parm_level ();
2646 /* If the list starts with an identifier, it is an identifier list.
2647 Otherwise, it is either a prototype list or an empty list. */
2650 && c_parser_next_token_is (parser, CPP_NAME)
2651 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2653 tree list = NULL_TREE, *nextp = &list;
2654 while (c_parser_next_token_is (parser, CPP_NAME)
2655 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2657 *nextp = build_tree_list (NULL_TREE,
2658 c_parser_peek_token (parser)->value);
2659 nextp = & TREE_CHAIN (*nextp);
2660 c_parser_consume_token (parser);
2661 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2663 c_parser_consume_token (parser);
2664 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2666 c_parser_error (parser, "expected identifier");
2670 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2672 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2677 ret->pending_sizes = 0;
2678 ret->had_vla_unspec = 0;
2679 c_parser_consume_token (parser);
2685 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2693 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2699 /* Parse a parameter list (possibly empty), including the closing
2700 parenthesis but not the opening one. ATTRS are the attributes at
2701 the start of the list. */
2703 static struct c_arg_info *
2704 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2706 bool good_parm = false;
2707 /* ??? Following the old parser, forward parameter declarations may
2708 use abstract declarators, and if no real parameter declarations
2709 follow the forward declarations then this is not diagnosed. Also
2710 note as above that attributes are ignored as the only contents of
2711 the parentheses, or as the only contents after forward
2713 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2715 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2720 ret->pending_sizes = 0;
2721 ret->had_vla_unspec = 0;
2722 c_parser_consume_token (parser);
2725 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2727 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2731 ret->pending_sizes = 0;
2732 ret->had_vla_unspec = 0;
2733 /* Suppress -Wold-style-definition for this case. */
2734 ret->types = error_mark_node;
2735 error_at (c_parser_peek_token (parser)->location,
2736 "ISO C requires a named argument before %<...%>");
2737 c_parser_consume_token (parser);
2738 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2740 c_parser_consume_token (parser);
2745 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2750 /* Nonempty list of parameters, either terminated with semicolon
2751 (forward declarations; recurse) or with close parenthesis (normal
2752 function) or with ", ... )" (variadic function). */
2755 /* Parse a parameter. */
2756 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2761 push_parm_decl (parm);
2763 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2766 c_parser_consume_token (parser);
2767 mark_forward_parm_decls ();
2768 new_attrs = c_parser_attributes (parser);
2769 return c_parser_parms_list_declarator (parser, new_attrs);
2771 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2773 c_parser_consume_token (parser);
2775 return get_parm_info (false);
2778 struct c_arg_info *ret
2779 = XOBNEW (&parser_obstack, struct c_arg_info);
2784 ret->pending_sizes = 0;
2785 ret->had_vla_unspec = 0;
2789 if (!c_parser_require (parser, CPP_COMMA,
2790 "expected %<;%>, %<,%> or %<)%>"))
2792 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2793 get_pending_sizes ();
2796 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2798 c_parser_consume_token (parser);
2799 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2801 c_parser_consume_token (parser);
2803 return get_parm_info (true);
2806 struct c_arg_info *ret
2807 = XOBNEW (&parser_obstack, struct c_arg_info);
2812 ret->pending_sizes = 0;
2813 ret->had_vla_unspec = 0;
2819 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2821 get_pending_sizes ();
2828 /* Parse a parameter declaration. ATTRS are the attributes at the
2829 start of the declaration if it is the first parameter. */
2831 static struct c_parm *
2832 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2834 struct c_declspecs *specs;
2835 struct c_declarator *declarator;
2837 tree postfix_attrs = NULL_TREE;
2839 if (!c_parser_next_token_starts_declspecs (parser))
2841 /* ??? In some Objective-C cases '...' isn't applicable so there
2842 should be a different message. */
2843 c_parser_error (parser,
2844 "expected declaration specifiers or %<...%>");
2845 c_parser_skip_to_end_of_parameter (parser);
2848 specs = build_null_declspecs ();
2851 declspecs_add_attrs (specs, attrs);
2854 c_parser_declspecs (parser, specs, true, true, true);
2855 finish_declspecs (specs);
2856 pending_xref_error ();
2857 prefix_attrs = specs->attrs;
2858 specs->attrs = NULL_TREE;
2859 declarator = c_parser_declarator (parser, specs->type_seen_p,
2860 C_DTR_PARM, &dummy);
2861 if (declarator == NULL)
2863 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2866 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2867 postfix_attrs = c_parser_attributes (parser);
2868 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2872 /* Parse a string literal in an asm expression. It should not be
2873 translated, and wide string literals are an error although
2874 permitted by the syntax. This is a GNU extension.
2879 ??? At present, following the old parser, the caller needs to have
2880 set lex_untranslated_string to 1. It would be better to follow the
2881 C++ parser rather than using this kludge. */
2884 c_parser_asm_string_literal (c_parser *parser)
2887 if (c_parser_next_token_is (parser, CPP_STRING))
2889 str = c_parser_peek_token (parser)->value;
2890 c_parser_consume_token (parser);
2892 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2894 error_at (c_parser_peek_token (parser)->location,
2895 "wide string literal in %<asm%>");
2896 str = build_string (1, "");
2897 c_parser_consume_token (parser);
2901 c_parser_error (parser, "expected string literal");
2907 /* Parse a simple asm expression. This is used in restricted
2908 contexts, where a full expression with inputs and outputs does not
2909 make sense. This is a GNU extension.
2912 asm ( asm-string-literal )
2916 c_parser_simple_asm_expr (c_parser *parser)
2919 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2920 /* ??? Follow the C++ parser rather than using the
2921 lex_untranslated_string kludge. */
2922 parser->lex_untranslated_string = true;
2923 c_parser_consume_token (parser);
2924 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2926 parser->lex_untranslated_string = false;
2929 str = c_parser_asm_string_literal (parser);
2930 parser->lex_untranslated_string = false;
2931 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2933 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2939 /* Parse (possibly empty) attributes. This is a GNU extension.
2943 attributes attribute
2946 __attribute__ ( ( attribute-list ) )
2950 attribute_list , attrib
2955 any-word ( identifier )
2956 any-word ( identifier , nonempty-expr-list )
2957 any-word ( expr-list )
2959 where the "identifier" must not be declared as a type, and
2960 "any-word" may be any identifier (including one declared as a
2961 type), a reserved word storage class specifier, type specifier or
2962 type qualifier. ??? This still leaves out most reserved keywords
2963 (following the old parser), shouldn't we include them, and why not
2964 allow identifiers declared as types to start the arguments? */
2967 c_parser_attributes (c_parser *parser)
2969 tree attrs = NULL_TREE;
2970 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2972 /* ??? Follow the C++ parser rather than using the
2973 lex_untranslated_string kludge. */
2974 parser->lex_untranslated_string = true;
2975 c_parser_consume_token (parser);
2976 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2978 parser->lex_untranslated_string = false;
2981 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2983 parser->lex_untranslated_string = false;
2984 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2987 /* Parse the attribute list. */
2988 while (c_parser_next_token_is (parser, CPP_COMMA)
2989 || c_parser_next_token_is (parser, CPP_NAME)
2990 || c_parser_next_token_is (parser, CPP_KEYWORD))
2992 tree attr, attr_name, attr_args;
2993 VEC(tree,gc) *expr_list;
2994 if (c_parser_next_token_is (parser, CPP_COMMA))
2996 c_parser_consume_token (parser);
2999 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3001 /* ??? See comment above about what keywords are
3004 switch (c_parser_peek_token (parser)->keyword)
3041 /* Accept __attribute__((__const)) as __attribute__((const))
3044 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3047 attr_name = c_parser_peek_token (parser)->value;
3048 c_parser_consume_token (parser);
3049 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3051 attr = build_tree_list (attr_name, NULL_TREE);
3052 attrs = chainon (attrs, attr);
3055 c_parser_consume_token (parser);
3056 /* Parse the attribute contents. If they start with an
3057 identifier which is followed by a comma or close
3058 parenthesis, then the arguments start with that
3059 identifier; otherwise they are an expression list. */
3060 if (c_parser_next_token_is (parser, CPP_NAME)
3061 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3062 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3063 || (c_parser_peek_2nd_token (parser)->type
3064 == CPP_CLOSE_PAREN)))
3066 tree arg1 = c_parser_peek_token (parser)->value;
3067 c_parser_consume_token (parser);
3068 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3069 attr_args = build_tree_list (NULL_TREE, arg1);
3073 c_parser_consume_token (parser);
3074 expr_list = c_parser_expr_list (parser, false, true, NULL);
3075 tree_list = build_tree_list_vec (expr_list);
3076 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3077 release_tree_vector (expr_list);
3082 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3083 attr_args = NULL_TREE;
3086 expr_list = c_parser_expr_list (parser, false, true, NULL);
3087 attr_args = build_tree_list_vec (expr_list);
3088 release_tree_vector (expr_list);
3091 attr = build_tree_list (attr_name, attr_args);
3092 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3093 c_parser_consume_token (parser);
3096 parser->lex_untranslated_string = false;
3097 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3101 attrs = chainon (attrs, attr);
3103 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3104 c_parser_consume_token (parser);
3107 parser->lex_untranslated_string = false;
3108 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3112 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3113 c_parser_consume_token (parser);
3116 parser->lex_untranslated_string = false;
3117 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3121 parser->lex_untranslated_string = false;
3126 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3129 specifier-qualifier-list abstract-declarator[opt]
3132 static struct c_type_name *
3133 c_parser_type_name (c_parser *parser)
3135 struct c_declspecs *specs = build_null_declspecs ();
3136 struct c_declarator *declarator;
3137 struct c_type_name *ret;
3139 c_parser_declspecs (parser, specs, false, true, true);
3140 if (!specs->declspecs_seen_p)
3142 c_parser_error (parser, "expected specifier-qualifier-list");
3145 pending_xref_error ();
3146 finish_declspecs (specs);
3147 declarator = c_parser_declarator (parser, specs->type_seen_p,
3148 C_DTR_ABSTRACT, &dummy);
3149 if (declarator == NULL)
3151 ret = XOBNEW (&parser_obstack, struct c_type_name);
3153 ret->declarator = declarator;
3157 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3160 assignment-expression
3161 { initializer-list }
3162 { initializer-list , }
3165 designation[opt] initializer
3166 initializer-list , designation[opt] initializer
3173 designator-list designator
3180 [ constant-expression ]
3192 [ constant-expression ... constant-expression ]
3194 Any expression without commas is accepted in the syntax for the
3195 constant-expressions, with non-constant expressions rejected later.
3197 This function is only used for top-level initializers; for nested
3198 ones, see c_parser_initval. */
3200 static struct c_expr
3201 c_parser_initializer (c_parser *parser)
3203 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3204 return c_parser_braced_init (parser, NULL_TREE, false);
3208 location_t loc = c_parser_peek_token (parser)->location;
3209 ret = c_parser_expr_no_commas (parser, NULL);
3210 if (TREE_CODE (ret.value) != STRING_CST
3211 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3212 ret = default_function_array_read_conversion (loc, ret);
3217 /* Parse a braced initializer list. TYPE is the type specified for a
3218 compound literal, and NULL_TREE for other initializers and for
3219 nested braced lists. NESTED_P is true for nested braced lists,
3220 false for the list of a compound literal or the list that is the
3221 top-level initializer in a declaration. */
3223 static struct c_expr
3224 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3227 struct obstack braced_init_obstack;
3228 location_t brace_loc = c_parser_peek_token (parser)->location;
3229 gcc_obstack_init (&braced_init_obstack);
3230 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3231 c_parser_consume_token (parser);
3233 push_init_level (0, &braced_init_obstack);
3235 really_start_incremental_init (type);
3236 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3238 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3242 /* Parse a non-empty initializer list, possibly with a trailing
3246 c_parser_initelt (parser, &braced_init_obstack);
3249 if (c_parser_next_token_is (parser, CPP_COMMA))
3250 c_parser_consume_token (parser);
3253 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3257 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3259 ret.value = error_mark_node;
3260 ret.original_code = ERROR_MARK;
3261 ret.original_type = NULL;
3262 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3263 pop_init_level (0, &braced_init_obstack);
3264 obstack_free (&braced_init_obstack, NULL);
3267 c_parser_consume_token (parser);
3268 ret = pop_init_level (0, &braced_init_obstack);
3269 obstack_free (&braced_init_obstack, NULL);
3273 /* Parse a nested initializer, including designators. */
3276 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3278 /* Parse any designator or designator list. A single array
3279 designator may have the subsequent "=" omitted in GNU C, but a
3280 longer list or a structure member designator may not. */
3281 if (c_parser_next_token_is (parser, CPP_NAME)
3282 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3284 /* Old-style structure member designator. */
3285 set_init_label (c_parser_peek_token (parser)->value,
3286 braced_init_obstack);
3287 /* Use the colon as the error location. */
3288 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3289 "obsolete use of designated initializer with %<:%>");
3290 c_parser_consume_token (parser);
3291 c_parser_consume_token (parser);
3295 /* des_seen is 0 if there have been no designators, 1 if there
3296 has been a single array designator and 2 otherwise. */
3298 /* Location of a designator. */
3299 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3300 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3301 || c_parser_next_token_is (parser, CPP_DOT))
3303 int des_prev = des_seen;
3305 des_loc = c_parser_peek_token (parser)->location;
3308 if (c_parser_next_token_is (parser, CPP_DOT))
3311 c_parser_consume_token (parser);
3312 if (c_parser_next_token_is (parser, CPP_NAME))
3314 set_init_label (c_parser_peek_token (parser)->value,
3315 braced_init_obstack);
3316 c_parser_consume_token (parser);
3321 init.value = error_mark_node;
3322 init.original_code = ERROR_MARK;
3323 init.original_type = NULL;
3324 c_parser_error (parser, "expected identifier");
3325 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3326 process_init_element (init, false, braced_init_obstack);
3333 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3334 /* ??? Following the old parser, [ objc-receiver
3335 objc-message-args ] is accepted as an initializer,
3336 being distinguished from a designator by what follows
3337 the first assignment expression inside the square
3338 brackets, but after a first array designator a
3339 subsequent square bracket is for Objective-C taken to
3340 start an expression, using the obsolete form of
3341 designated initializer without '=', rather than
3342 possibly being a second level of designation: in LALR
3343 terms, the '[' is shifted rather than reducing
3344 designator to designator-list. */
3345 if (des_prev == 1 && c_dialect_objc ())
3347 des_seen = des_prev;
3350 if (des_prev == 0 && c_dialect_objc ())
3352 /* This might be an array designator or an
3353 Objective-C message expression. If the former,
3354 continue parsing here; if the latter, parse the
3355 remainder of the initializer given the starting
3356 primary-expression. ??? It might make sense to
3357 distinguish when des_prev == 1 as well; see
3358 previous comment. */
3360 struct c_expr mexpr;
3361 c_parser_consume_token (parser);
3362 if (c_parser_peek_token (parser)->type == CPP_NAME
3363 && ((c_parser_peek_token (parser)->id_kind
3365 || (c_parser_peek_token (parser)->id_kind
3366 == C_ID_CLASSNAME)))
3368 /* Type name receiver. */
3369 tree id = c_parser_peek_token (parser)->value;
3370 c_parser_consume_token (parser);
3371 rec = objc_get_class_reference (id);
3372 goto parse_message_args;
3374 first = c_parser_expr_no_commas (parser, NULL).value;
3375 mark_exp_read (first);
3376 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3377 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3378 goto array_desig_after_first;
3379 /* Expression receiver. So far only one part
3380 without commas has been parsed; there might be
3381 more of the expression. */
3383 while (c_parser_next_token_is (parser, CPP_COMMA))
3386 location_t comma_loc, exp_loc;
3387 comma_loc = c_parser_peek_token (parser)->location;
3388 c_parser_consume_token (parser);
3389 exp_loc = c_parser_peek_token (parser)->location;
3390 next = c_parser_expr_no_commas (parser, NULL);
3391 next = default_function_array_read_conversion (exp_loc,
3393 rec = build_compound_expr (comma_loc, rec, next.value);
3396 /* Now parse the objc-message-args. */
3397 args = c_parser_objc_message_args (parser);
3398 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3401 = objc_build_message_expr (build_tree_list (rec, args));
3402 mexpr.original_code = ERROR_MARK;
3403 mexpr.original_type = NULL;
3404 /* Now parse and process the remainder of the
3405 initializer, starting with this message
3406 expression as a primary-expression. */
3407 c_parser_initval (parser, &mexpr, braced_init_obstack);
3410 c_parser_consume_token (parser);
3411 first = c_parser_expr_no_commas (parser, NULL).value;
3412 mark_exp_read (first);
3413 array_desig_after_first:
3414 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3416 ellipsis_loc = c_parser_peek_token (parser)->location;
3417 c_parser_consume_token (parser);
3418 second = c_parser_expr_no_commas (parser, NULL).value;
3419 mark_exp_read (second);
3423 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3425 c_parser_consume_token (parser);
3426 set_init_index (first, second, braced_init_obstack);
3428 pedwarn (ellipsis_loc, OPT_pedantic,
3429 "ISO C forbids specifying range of elements to initialize");
3432 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3438 if (c_parser_next_token_is (parser, CPP_EQ))
3441 pedwarn (des_loc, OPT_pedantic,
3442 "ISO C90 forbids specifying subobject to initialize");
3443 c_parser_consume_token (parser);
3448 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3449 "obsolete use of designated initializer without %<=%>");
3453 init.value = error_mark_node;
3454 init.original_code = ERROR_MARK;
3455 init.original_type = NULL;
3456 c_parser_error (parser, "expected %<=%>");
3457 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3458 process_init_element (init, false, braced_init_obstack);
3464 c_parser_initval (parser, NULL, braced_init_obstack);
3467 /* Parse a nested initializer; as c_parser_initializer but parses
3468 initializers within braced lists, after any designators have been
3469 applied. If AFTER is not NULL then it is an Objective-C message
3470 expression which is the primary-expression starting the
3474 c_parser_initval (c_parser *parser, struct c_expr *after,
3475 struct obstack * braced_init_obstack)
3478 gcc_assert (!after || c_dialect_objc ());
3479 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3480 init = c_parser_braced_init (parser, NULL_TREE, true);
3483 location_t loc = c_parser_peek_token (parser)->location;
3484 init = c_parser_expr_no_commas (parser, after);
3485 if (init.value != NULL_TREE
3486 && TREE_CODE (init.value) != STRING_CST
3487 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3488 init = default_function_array_read_conversion (loc, init);
3490 process_init_element (init, false, braced_init_obstack);
3493 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3497 { block-item-list[opt] }
3498 { label-declarations block-item-list }
3502 block-item-list block-item
3514 { label-declarations block-item-list }
3517 __extension__ nested-declaration
3518 nested-function-definition
3522 label-declarations label-declaration
3525 __label__ identifier-list ;
3527 Allowing the mixing of declarations and code is new in C99. The
3528 GNU syntax also permits (not shown above) labels at the end of
3529 compound statements, which yield an error. We don't allow labels
3530 on declarations; this might seem like a natural extension, but
3531 there would be a conflict between attributes on the label and
3532 prefix attributes on the declaration. ??? The syntax follows the
3533 old parser in requiring something after label declarations.
3534 Although they are erroneous if the labels declared aren't defined,
3535 is it useful for the syntax to be this way?
3547 c_parser_compound_statement (c_parser *parser)
3550 location_t brace_loc;
3551 brace_loc = c_parser_peek_token (parser)->location;
3552 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3554 /* Ensure a scope is entered and left anyway to avoid confusion
3555 if we have just prepared to enter a function body. */
3556 stmt = c_begin_compound_stmt (true);
3557 c_end_compound_stmt (brace_loc, stmt, true);
3558 return error_mark_node;
3560 stmt = c_begin_compound_stmt (true);
3561 c_parser_compound_statement_nostart (parser);
3562 return c_end_compound_stmt (brace_loc, stmt, true);
3565 /* Parse a compound statement except for the opening brace. This is
3566 used for parsing both compound statements and statement expressions
3567 (which follow different paths to handling the opening). */
3570 c_parser_compound_statement_nostart (c_parser *parser)
3572 bool last_stmt = false;
3573 bool last_label = false;
3574 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3575 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3576 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3578 c_parser_consume_token (parser);
3581 mark_valid_location_for_stdc_pragma (true);
3582 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3584 /* Read zero or more forward-declarations for labels that nested
3585 functions can jump to. */
3586 mark_valid_location_for_stdc_pragma (false);
3587 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3589 label_loc = c_parser_peek_token (parser)->location;
3590 c_parser_consume_token (parser);
3591 /* Any identifiers, including those declared as type names,
3596 if (c_parser_next_token_is_not (parser, CPP_NAME))
3598 c_parser_error (parser, "expected identifier");
3602 = declare_label (c_parser_peek_token (parser)->value);
3603 C_DECLARED_LABEL_FLAG (label) = 1;
3604 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3605 c_parser_consume_token (parser);
3606 if (c_parser_next_token_is (parser, CPP_COMMA))
3607 c_parser_consume_token (parser);
3611 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3613 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3615 /* We must now have at least one statement, label or declaration. */
3616 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3618 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3619 c_parser_error (parser, "expected declaration or statement");
3620 c_parser_consume_token (parser);
3623 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3625 location_t loc = c_parser_peek_token (parser)->location;
3626 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3627 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3628 || (c_parser_next_token_is (parser, CPP_NAME)
3629 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3631 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3632 label_loc = c_parser_peek_2nd_token (parser)->location;
3634 label_loc = c_parser_peek_token (parser)->location;
3637 mark_valid_location_for_stdc_pragma (false);
3638 c_parser_label (parser);
3640 else if (!last_label
3641 && c_parser_next_token_starts_declaration (parser))
3644 mark_valid_location_for_stdc_pragma (false);
3645 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
3648 (pedantic && !flag_isoc99)
3650 : OPT_Wdeclaration_after_statement,
3651 "ISO C90 forbids mixed declarations and code");
3654 else if (!last_label
3655 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3657 /* __extension__ can start a declaration, but is also an
3658 unary operator that can start an expression. Consume all
3659 but the last of a possible series of __extension__ to
3661 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3662 && (c_parser_peek_2nd_token (parser)->keyword
3664 c_parser_consume_token (parser);
3665 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3668 ext = disable_extension_diagnostics ();
3669 c_parser_consume_token (parser);
3671 mark_valid_location_for_stdc_pragma (false);
3672 c_parser_declaration_or_fndef (parser, true, true, true, true,
3674 /* Following the old parser, __extension__ does not
3675 disable this diagnostic. */
3676 restore_extension_diagnostics (ext);
3678 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3680 : OPT_Wdeclaration_after_statement,
3681 "ISO C90 forbids mixed declarations and code");
3687 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3689 /* External pragmas, and some omp pragmas, are not associated
3690 with regular c code, and so are not to be considered statements
3691 syntactically. This ensures that the user doesn't put them
3692 places that would turn into syntax errors if the directive
3694 if (c_parser_pragma (parser, pragma_compound))
3695 last_label = false, last_stmt = true;
3697 else if (c_parser_next_token_is (parser, CPP_EOF))
3699 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3700 c_parser_error (parser, "expected declaration or statement");
3703 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3705 if (parser->in_if_block)
3707 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3708 error_at (loc, """expected %<}%> before %<else%>");
3713 error_at (loc, "%<else%> without a previous %<if%>");
3714 c_parser_consume_token (parser);
3723 mark_valid_location_for_stdc_pragma (false);
3724 c_parser_statement_after_labels (parser);
3727 parser->error = false;
3730 error_at (label_loc, "label at end of compound statement");
3731 c_parser_consume_token (parser);
3732 /* Restore the value we started with. */
3733 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3736 /* Parse a label (C90 6.6.1, C99 6.8.1).
3739 identifier : attributes[opt]
3740 case constant-expression :
3746 case constant-expression ... constant-expression :
3748 The use of attributes on labels is a GNU extension. The syntax in
3749 GNU C accepts any expressions without commas, non-constant
3750 expressions being rejected later. */
3753 c_parser_label (c_parser *parser)
3755 location_t loc1 = c_parser_peek_token (parser)->location;
3756 tree label = NULL_TREE;
3757 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3760 c_parser_consume_token (parser);
3761 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3762 if (c_parser_next_token_is (parser, CPP_COLON))
3764 c_parser_consume_token (parser);
3765 label = do_case (loc1, exp1, NULL_TREE);
3767 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3769 c_parser_consume_token (parser);
3770 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3771 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3772 label = do_case (loc1, exp1, exp2);
3775 c_parser_error (parser, "expected %<:%> or %<...%>");
3777 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3779 c_parser_consume_token (parser);
3780 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3781 label = do_case (loc1, NULL_TREE, NULL_TREE);
3785 tree name = c_parser_peek_token (parser)->value;
3788 location_t loc2 = c_parser_peek_token (parser)->location;
3789 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3790 c_parser_consume_token (parser);
3791 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3792 c_parser_consume_token (parser);
3793 attrs = c_parser_attributes (parser);
3794 tlab = define_label (loc2, name);
3797 decl_attributes (&tlab, attrs, 0);
3798 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3803 if (c_parser_next_token_starts_declaration (parser)
3804 && !(c_parser_next_token_is (parser, CPP_NAME)
3805 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3807 error_at (c_parser_peek_token (parser)->location,
3808 "a label can only be part of a statement and "
3809 "a declaration is not a statement");
3810 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3811 /*static_assert_ok*/ true,
3812 /*nested*/ true, /*empty_ok*/ false,
3813 /*start_attr_ok*/ true);
3818 /* Parse a statement (C90 6.6, C99 6.8).
3823 expression-statement
3831 expression-statement:
3834 selection-statement:
3838 iteration-statement:
3847 return expression[opt] ;
3860 objc-throw-statement
3861 objc-try-catch-statement
3862 objc-synchronized-statement
3864 objc-throw-statement:
3878 parallel-for-construct
3879 parallel-sections-construct
3886 parallel-directive structured-block
3889 for-directive iteration-statement
3892 sections-directive section-scope
3895 single-directive structured-block
3897 parallel-for-construct:
3898 parallel-for-directive iteration-statement
3900 parallel-sections-construct:
3901 parallel-sections-directive section-scope
3904 master-directive structured-block
3907 critical-directive structured-block
3910 atomic-directive expression-statement
3913 ordered-directive structured-block */
3916 c_parser_statement (c_parser *parser)
3918 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3919 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3920 || (c_parser_next_token_is (parser, CPP_NAME)
3921 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3922 c_parser_label (parser);
3923 c_parser_statement_after_labels (parser);
3926 /* Parse a statement, other than a labeled statement. */
3929 c_parser_statement_after_labels (c_parser *parser)
3931 location_t loc = c_parser_peek_token (parser)->location;
3932 tree stmt = NULL_TREE;
3933 bool in_if_block = parser->in_if_block;
3934 parser->in_if_block = false;
3935 switch (c_parser_peek_token (parser)->type)
3937 case CPP_OPEN_BRACE:
3938 add_stmt (c_parser_compound_statement (parser));
3941 switch (c_parser_peek_token (parser)->keyword)
3944 c_parser_if_statement (parser);
3947 c_parser_switch_statement (parser);
3950 c_parser_while_statement (parser);
3953 c_parser_do_statement (parser);
3956 c_parser_for_statement (parser);
3959 c_parser_consume_token (parser);
3960 if (c_parser_next_token_is (parser, CPP_NAME))
3962 stmt = c_finish_goto_label (loc,
3963 c_parser_peek_token (parser)->value);
3964 c_parser_consume_token (parser);
3966 else if (c_parser_next_token_is (parser, CPP_MULT))
3968 c_parser_consume_token (parser);
3969 stmt = c_finish_goto_ptr (loc,
3970 c_parser_expression (parser).value);
3973 c_parser_error (parser, "expected identifier or %<*%>");
3974 goto expect_semicolon;
3976 c_parser_consume_token (parser);
3977 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
3978 goto expect_semicolon;
3980 c_parser_consume_token (parser);
3981 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
3982 goto expect_semicolon;
3984 c_parser_consume_token (parser);
3985 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3987 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
3988 c_parser_consume_token (parser);
3992 struct c_expr expr = c_parser_expression_conv (parser);
3993 mark_exp_read (expr.value);
3994 stmt = c_finish_return (loc, expr.value, expr.original_type);
3995 goto expect_semicolon;
3999 stmt = c_parser_asm_statement (parser);
4002 gcc_assert (c_dialect_objc ());
4003 c_parser_consume_token (parser);
4004 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4006 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4007 c_parser_consume_token (parser);
4011 tree expr = c_parser_expression (parser).value;
4012 expr = c_fully_fold (expr, false, NULL);
4013 stmt = objc_build_throw_stmt (loc, expr);
4014 goto expect_semicolon;
4018 gcc_assert (c_dialect_objc ());
4019 c_parser_objc_try_catch_statement (parser);
4021 case RID_AT_SYNCHRONIZED:
4022 gcc_assert (c_dialect_objc ());
4023 c_parser_objc_synchronized_statement (parser);
4030 c_parser_consume_token (parser);
4032 case CPP_CLOSE_PAREN:
4033 case CPP_CLOSE_SQUARE:
4034 /* Avoid infinite loop in error recovery:
4035 c_parser_skip_until_found stops at a closing nesting
4036 delimiter without consuming it, but here we need to consume
4037 it to proceed further. */
4038 c_parser_error (parser, "expected statement");
4039 c_parser_consume_token (parser);
4042 c_parser_pragma (parser, pragma_stmt);
4046 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4048 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4051 /* Two cases cannot and do not have line numbers associated: If stmt
4052 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4053 cannot hold line numbers. But that's OK because the statement
4054 will either be changed to a MODIFY_EXPR during gimplification of
4055 the statement expr, or discarded. If stmt was compound, but
4056 without new variables, we will have skipped the creation of a
4057 BIND and will have a bare STATEMENT_LIST. But that's OK because
4058 (recursively) all of the component statements should already have
4059 line numbers assigned. ??? Can we discard no-op statements
4061 if (CAN_HAVE_LOCATION_P (stmt)
4062 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4063 SET_EXPR_LOCATION (stmt, loc);
4065 parser->in_if_block = in_if_block;
4068 /* Parse the condition from an if, do, while or for statements. */
4071 c_parser_condition (c_parser *parser)
4073 location_t loc = c_parser_peek_token (parser)->location;
4075 cond = c_parser_expression_conv (parser).value;
4076 cond = c_objc_common_truthvalue_conversion (loc, cond);
4077 cond = c_fully_fold (cond, false, NULL);
4078 if (warn_sequence_point)
4079 verify_sequence_points (cond);
4083 /* Parse a parenthesized condition from an if, do or while statement.
4089 c_parser_paren_condition (c_parser *parser)
4092 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4093 return error_mark_node;
4094 cond = c_parser_condition (parser);
4095 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4099 /* Parse a statement which is a block in C99. */
4102 c_parser_c99_block_statement (c_parser *parser)
4104 tree block = c_begin_compound_stmt (flag_isoc99);
4105 location_t loc = c_parser_peek_token (parser)->location;
4106 c_parser_statement (parser);
4107 return c_end_compound_stmt (loc, block, flag_isoc99);
4110 /* Parse the body of an if statement. This is just parsing a
4111 statement but (a) it is a block in C99, (b) we track whether the
4112 body is an if statement for the sake of -Wparentheses warnings, (c)
4113 we handle an empty body specially for the sake of -Wempty-body
4114 warnings, and (d) we call parser_compound_statement directly
4115 because c_parser_statement_after_labels resets
4116 parser->in_if_block. */
4119 c_parser_if_body (c_parser *parser, bool *if_p)
4121 tree block = c_begin_compound_stmt (flag_isoc99);
4122 location_t body_loc = c_parser_peek_token (parser)->location;
4123 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4124 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4125 || (c_parser_next_token_is (parser, CPP_NAME)
4126 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4127 c_parser_label (parser);
4128 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4129 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4131 location_t loc = c_parser_peek_token (parser)->location;
4132 add_stmt (build_empty_stmt (loc));
4133 c_parser_consume_token (parser);
4134 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4135 warning_at (loc, OPT_Wempty_body,
4136 "suggest braces around empty body in an %<if%> statement");
4138 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4139 add_stmt (c_parser_compound_statement (parser));
4141 c_parser_statement_after_labels (parser);
4142 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4145 /* Parse the else body of an if statement. This is just parsing a
4146 statement but (a) it is a block in C99, (b) we handle an empty body
4147 specially for the sake of -Wempty-body warnings. */
4150 c_parser_else_body (c_parser *parser)
4152 location_t else_loc = c_parser_peek_token (parser)->location;
4153 tree block = c_begin_compound_stmt (flag_isoc99);
4154 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4155 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4156 || (c_parser_next_token_is (parser, CPP_NAME)
4157 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4158 c_parser_label (parser);
4159 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4161 location_t loc = c_parser_peek_token (parser)->location;
4164 "suggest braces around empty body in an %<else%> statement");
4165 add_stmt (build_empty_stmt (loc));
4166 c_parser_consume_token (parser);
4169 c_parser_statement_after_labels (parser);
4170 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4173 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4176 if ( expression ) statement
4177 if ( expression ) statement else statement
4181 c_parser_if_statement (c_parser *parser)
4186 bool first_if = false;
4187 tree first_body, second_body;
4190 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4191 c_parser_consume_token (parser);
4192 block = c_begin_compound_stmt (flag_isoc99);
4193 loc = c_parser_peek_token (parser)->location;
4194 cond = c_parser_paren_condition (parser);
4195 in_if_block = parser->in_if_block;
4196 parser->in_if_block = true;
4197 first_body = c_parser_if_body (parser, &first_if);
4198 parser->in_if_block = in_if_block;
4199 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4201 c_parser_consume_token (parser);
4202 second_body = c_parser_else_body (parser);
4205 second_body = NULL_TREE;
4206 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4207 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4210 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4213 switch (expression) statement
4217 c_parser_switch_statement (c_parser *parser)
4219 tree block, expr, body, save_break;
4220 location_t switch_loc = c_parser_peek_token (parser)->location;
4221 location_t switch_cond_loc;
4222 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4223 c_parser_consume_token (parser);
4224 block = c_begin_compound_stmt (flag_isoc99);
4225 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4227 switch_cond_loc = c_parser_peek_token (parser)->location;
4228 expr = c_parser_expression (parser).value;
4229 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4233 switch_cond_loc = UNKNOWN_LOCATION;
4234 expr = error_mark_node;
4236 c_start_case (switch_loc, switch_cond_loc, expr);
4237 save_break = c_break_label;
4238 c_break_label = NULL_TREE;
4239 body = c_parser_c99_block_statement (parser);
4240 c_finish_case (body);
4243 location_t here = c_parser_peek_token (parser)->location;
4244 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4245 SET_EXPR_LOCATION (t, here);
4248 c_break_label = save_break;
4249 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4252 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4255 while (expression) statement
4259 c_parser_while_statement (c_parser *parser)
4261 tree block, cond, body, save_break, save_cont;
4263 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4264 c_parser_consume_token (parser);
4265 block = c_begin_compound_stmt (flag_isoc99);
4266 loc = c_parser_peek_token (parser)->location;
4267 cond = c_parser_paren_condition (parser);
4268 save_break = c_break_label;
4269 c_break_label = NULL_TREE;
4270 save_cont = c_cont_label;
4271 c_cont_label = NULL_TREE;
4272 body = c_parser_c99_block_statement (parser);
4273 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4274 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4275 c_break_label = save_break;
4276 c_cont_label = save_cont;
4279 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4282 do statement while ( expression ) ;
4286 c_parser_do_statement (c_parser *parser)
4288 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4290 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4291 c_parser_consume_token (parser);
4292 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4293 warning_at (c_parser_peek_token (parser)->location,
4295 "suggest braces around empty body in %<do%> statement");
4296 block = c_begin_compound_stmt (flag_isoc99);
4297 loc = c_parser_peek_token (parser)->location;
4298 save_break = c_break_label;
4299 c_break_label = NULL_TREE;
4300 save_cont = c_cont_label;
4301 c_cont_label = NULL_TREE;
4302 body = c_parser_c99_block_statement (parser);
4303 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4304 new_break = c_break_label;
4305 c_break_label = save_break;
4306 new_cont = c_cont_label;
4307 c_cont_label = save_cont;
4308 cond = c_parser_paren_condition (parser);
4309 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4310 c_parser_skip_to_end_of_block_or_statement (parser);
4311 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4312 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4315 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4318 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4319 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4321 The form with a declaration is new in C99.
4323 ??? In accordance with the old parser, the declaration may be a
4324 nested function, which is then rejected in check_for_loop_decls,
4325 but does it make any sense for this to be included in the grammar?
4326 Note in particular that the nested function does not include a
4327 trailing ';', whereas the "declaration" production includes one.
4328 Also, can we reject bad declarations earlier and cheaper than
4329 check_for_loop_decls? */
4332 c_parser_for_statement (c_parser *parser)
4334 tree block, cond, incr, save_break, save_cont, body;
4335 location_t loc = c_parser_peek_token (parser)->location;
4336 location_t for_loc = c_parser_peek_token (parser)->location;
4337 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4338 c_parser_consume_token (parser);
4339 block = c_begin_compound_stmt (flag_isoc99);
4340 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4342 /* Parse the initialization declaration or expression. */
4343 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4345 c_parser_consume_token (parser);
4346 c_finish_expr_stmt (loc, NULL_TREE);
4348 else if (c_parser_next_token_starts_declaration (parser))
4350 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
4351 check_for_loop_decls (for_loc);
4353 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4355 /* __extension__ can start a declaration, but is also an
4356 unary operator that can start an expression. Consume all
4357 but the last of a possible series of __extension__ to
4359 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4360 && (c_parser_peek_2nd_token (parser)->keyword
4362 c_parser_consume_token (parser);
4363 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4366 ext = disable_extension_diagnostics ();
4367 c_parser_consume_token (parser);
4368 c_parser_declaration_or_fndef (parser, true, true, true, true,
4370 restore_extension_diagnostics (ext);
4371 check_for_loop_decls (for_loc);
4379 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4380 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4382 /* Parse the loop condition. */
4383 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4385 c_parser_consume_token (parser);
4390 cond = c_parser_condition (parser);
4391 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4393 /* Parse the increment expression. */
4394 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4395 incr = c_process_expr_stmt (loc, NULL_TREE);
4397 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4402 cond = error_mark_node;
4403 incr = error_mark_node;
4405 save_break = c_break_label;
4406 c_break_label = NULL_TREE;
4407 save_cont = c_cont_label;
4408 c_cont_label = NULL_TREE;
4409 body = c_parser_c99_block_statement (parser);
4410 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4411 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4412 c_break_label = save_break;
4413 c_cont_label = save_cont;
4416 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4417 statement with inputs, outputs, clobbers, and volatile tag
4421 asm type-qualifier[opt] ( asm-argument ) ;
4422 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4426 asm-string-literal : asm-operands[opt]
4427 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4428 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4431 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4434 Qualifiers other than volatile are accepted in the syntax but
4438 c_parser_asm_statement (c_parser *parser)
4440 tree quals, str, outputs, inputs, clobbers, labels, ret;
4441 bool simple, is_goto;
4442 location_t asm_loc = c_parser_peek_token (parser)->location;
4443 int section, nsections;
4445 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4446 c_parser_consume_token (parser);
4447 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4449 quals = c_parser_peek_token (parser)->value;
4450 c_parser_consume_token (parser);
4452 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4453 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4455 warning_at (c_parser_peek_token (parser)->location,
4457 "%E qualifier ignored on asm",
4458 c_parser_peek_token (parser)->value);
4460 c_parser_consume_token (parser);
4466 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4468 c_parser_consume_token (parser);
4472 /* ??? Follow the C++ parser rather than using the
4473 lex_untranslated_string kludge. */
4474 parser->lex_untranslated_string = true;
4477 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4480 str = c_parser_asm_string_literal (parser);
4481 if (str == NULL_TREE)
4482 goto error_close_paren;
4485 outputs = NULL_TREE;
4487 clobbers = NULL_TREE;
4490 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4493 /* Parse each colon-delimited section of operands. */
4494 nsections = 3 + is_goto;
4495 for (section = 0; section < nsections; ++section)
4497 if (!c_parser_require (parser, CPP_COLON,
4500 : "expected %<:%> or %<)%>"))
4501 goto error_close_paren;
4503 /* Once past any colon, we're no longer a simple asm. */
4506 if ((!c_parser_next_token_is (parser, CPP_COLON)
4507 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4512 /* For asm goto, we don't allow output operands, but reserve
4513 the slot for a future extension that does allow them. */
4515 outputs = c_parser_asm_operands (parser, false);
4518 inputs = c_parser_asm_operands (parser, true);
4521 clobbers = c_parser_asm_clobbers (parser);
4524 labels = c_parser_asm_goto_operands (parser);
4530 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4535 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4537 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4541 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4542 c_parser_skip_to_end_of_block_or_statement (parser);
4544 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4545 clobbers, labels, simple));
4548 parser->lex_untranslated_string = false;
4552 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4556 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4557 not outputs), apply the default conversion of functions and arrays
4562 asm-operands , asm-operand
4565 asm-string-literal ( expression )
4566 [ identifier ] asm-string-literal ( expression )
4570 c_parser_asm_operands (c_parser *parser, bool convert_p)
4572 tree list = NULL_TREE;
4578 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4580 c_parser_consume_token (parser);
4581 if (c_parser_next_token_is (parser, CPP_NAME))
4583 tree id = c_parser_peek_token (parser)->value;
4584 c_parser_consume_token (parser);
4585 name = build_string (IDENTIFIER_LENGTH (id),
4586 IDENTIFIER_POINTER (id));
4590 c_parser_error (parser, "expected identifier");
4591 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4594 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4599 str = c_parser_asm_string_literal (parser);
4600 if (str == NULL_TREE)
4602 parser->lex_untranslated_string = false;
4603 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4605 parser->lex_untranslated_string = true;
4608 loc = c_parser_peek_token (parser)->location;
4609 expr = c_parser_expression (parser);
4610 mark_exp_read (expr.value);
4612 expr = default_function_array_conversion (loc, expr);
4613 expr.value = c_fully_fold (expr.value, false, NULL);
4614 parser->lex_untranslated_string = true;
4615 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4617 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4620 list = chainon (list, build_tree_list (build_tree_list (name, str),
4622 if (c_parser_next_token_is (parser, CPP_COMMA))
4623 c_parser_consume_token (parser);
4630 /* Parse asm clobbers, a GNU extension.
4634 asm-clobbers , asm-string-literal
4638 c_parser_asm_clobbers (c_parser *parser)
4640 tree list = NULL_TREE;
4643 tree str = c_parser_asm_string_literal (parser);
4645 list = tree_cons (NULL_TREE, str, list);
4648 if (c_parser_next_token_is (parser, CPP_COMMA))
4649 c_parser_consume_token (parser);
4656 /* Parse asm goto labels, a GNU extension.
4660 asm-goto-operands , identifier
4664 c_parser_asm_goto_operands (c_parser *parser)
4666 tree list = NULL_TREE;
4671 if (c_parser_next_token_is (parser, CPP_NAME))
4673 c_token *tok = c_parser_peek_token (parser);
4675 label = lookup_label_for_goto (tok->location, name);
4676 c_parser_consume_token (parser);
4677 TREE_USED (label) = 1;
4681 c_parser_error (parser, "expected identifier");
4685 name = build_string (IDENTIFIER_LENGTH (name),
4686 IDENTIFIER_POINTER (name));
4687 list = tree_cons (name, label, list);
4688 if (c_parser_next_token_is (parser, CPP_COMMA))
4689 c_parser_consume_token (parser);
4691 return nreverse (list);
4695 /* Parse an expression other than a compound expression; that is, an
4696 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4697 NULL then it is an Objective-C message expression which is the
4698 primary-expression starting the expression as an initializer.
4700 assignment-expression:
4701 conditional-expression
4702 unary-expression assignment-operator assignment-expression
4704 assignment-operator: one of
4705 = *= /= %= += -= <<= >>= &= ^= |=
4707 In GNU C we accept any conditional expression on the LHS and
4708 diagnose the invalid lvalue rather than producing a syntax
4711 static struct c_expr
4712 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4714 struct c_expr lhs, rhs, ret;
4715 enum tree_code code;
4716 location_t op_location, exp_location;
4717 gcc_assert (!after || c_dialect_objc ());
4718 lhs = c_parser_conditional_expression (parser, after);
4719 op_location = c_parser_peek_token (parser)->location;
4720 switch (c_parser_peek_token (parser)->type)
4729 code = TRUNC_DIV_EXPR;
4732 code = TRUNC_MOD_EXPR;
4747 code = BIT_AND_EXPR;
4750 code = BIT_XOR_EXPR;
4753 code = BIT_IOR_EXPR;
4758 c_parser_consume_token (parser);
4759 exp_location = c_parser_peek_token (parser)->location;
4760 rhs = c_parser_expr_no_commas (parser, NULL);
4761 rhs = default_function_array_read_conversion (exp_location, rhs);
4762 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4763 code, exp_location, rhs.value,
4765 if (code == NOP_EXPR)
4766 ret.original_code = MODIFY_EXPR;
4769 TREE_NO_WARNING (ret.value) = 1;
4770 ret.original_code = ERROR_MARK;
4772 ret.original_type = NULL;
4776 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4777 is not NULL then it is an Objective-C message expression which is
4778 the primary-expression starting the expression as an initializer.
4780 conditional-expression:
4781 logical-OR-expression
4782 logical-OR-expression ? expression : conditional-expression
4786 conditional-expression:
4787 logical-OR-expression ? : conditional-expression
4790 static struct c_expr
4791 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4793 struct c_expr cond, exp1, exp2, ret;
4794 location_t cond_loc, colon_loc;
4796 gcc_assert (!after || c_dialect_objc ());
4798 cond = c_parser_binary_expression (parser, after);
4800 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4802 cond_loc = c_parser_peek_token (parser)->location;
4803 cond = default_function_array_read_conversion (cond_loc, cond);
4804 c_parser_consume_token (parser);
4805 if (c_parser_next_token_is (parser, CPP_COLON))
4807 tree eptype = NULL_TREE;
4808 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4809 "ISO C forbids omitting the middle term of a ?: expression");
4810 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4812 eptype = TREE_TYPE (cond.value);
4813 cond.value = TREE_OPERAND (cond.value, 0);
4815 /* Make sure first operand is calculated only once. */
4816 exp1.value = c_save_expr (default_conversion (cond.value));
4818 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4819 exp1.original_type = NULL;
4820 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4821 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4826 = c_objc_common_truthvalue_conversion
4827 (cond_loc, default_conversion (cond.value));
4828 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4829 exp1 = c_parser_expression_conv (parser);
4830 mark_exp_read (exp1.value);
4831 c_inhibit_evaluation_warnings +=
4832 ((cond.value == truthvalue_true_node)
4833 - (cond.value == truthvalue_false_node));
4836 colon_loc = c_parser_peek_token (parser)->location;
4837 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4839 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4840 ret.value = error_mark_node;
4841 ret.original_code = ERROR_MARK;
4842 ret.original_type = NULL;
4846 location_t exp2_loc = c_parser_peek_token (parser)->location;
4847 exp2 = c_parser_conditional_expression (parser, NULL);
4848 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
4850 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4851 ret.value = build_conditional_expr (colon_loc, cond.value,
4852 cond.original_code == C_MAYBE_CONST_EXPR,
4853 exp1.value, exp1.original_type,
4854 exp2.value, exp2.original_type);
4855 ret.original_code = ERROR_MARK;
4856 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4857 ret.original_type = NULL;
4862 /* If both sides are enum type, the default conversion will have
4863 made the type of the result be an integer type. We want to
4864 remember the enum types we started with. */
4865 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4866 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4867 ret.original_type = ((t1 != error_mark_node
4868 && t2 != error_mark_node
4869 && (TYPE_MAIN_VARIANT (t1)
4870 == TYPE_MAIN_VARIANT (t2)))
4877 /* Parse a binary expression; that is, a logical-OR-expression (C90
4878 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4879 an Objective-C message expression which is the primary-expression
4880 starting the expression as an initializer.
4882 multiplicative-expression:
4884 multiplicative-expression * cast-expression
4885 multiplicative-expression / cast-expression
4886 multiplicative-expression % cast-expression
4888 additive-expression:
4889 multiplicative-expression
4890 additive-expression + multiplicative-expression
4891 additive-expression - multiplicative-expression
4895 shift-expression << additive-expression
4896 shift-expression >> additive-expression
4898 relational-expression:
4900 relational-expression < shift-expression
4901 relational-expression > shift-expression
4902 relational-expression <= shift-expression
4903 relational-expression >= shift-expression
4905 equality-expression:
4906 relational-expression
4907 equality-expression == relational-expression
4908 equality-expression != relational-expression
4912 AND-expression & equality-expression
4914 exclusive-OR-expression:
4916 exclusive-OR-expression ^ AND-expression
4918 inclusive-OR-expression:
4919 exclusive-OR-expression
4920 inclusive-OR-expression | exclusive-OR-expression
4922 logical-AND-expression:
4923 inclusive-OR-expression
4924 logical-AND-expression && inclusive-OR-expression
4926 logical-OR-expression:
4927 logical-AND-expression
4928 logical-OR-expression || logical-AND-expression
4931 static struct c_expr
4932 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4934 /* A binary expression is parsed using operator-precedence parsing,
4935 with the operands being cast expressions. All the binary
4936 operators are left-associative. Thus a binary expression is of
4939 E0 op1 E1 op2 E2 ...
4941 which we represent on a stack. On the stack, the precedence
4942 levels are strictly increasing. When a new operator is
4943 encountered of higher precedence than that at the top of the
4944 stack, it is pushed; its LHS is the top expression, and its RHS
4945 is everything parsed until it is popped. When a new operator is
4946 encountered with precedence less than or equal to that at the top
4947 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4948 by the result of the operation until the operator at the top of
4949 the stack has lower precedence than the new operator or there is
4950 only one element on the stack; then the top expression is the LHS
4951 of the new operator. In the case of logical AND and OR
4952 expressions, we also need to adjust c_inhibit_evaluation_warnings
4953 as appropriate when the operators are pushed and popped. */
4955 /* The precedence levels, where 0 is a dummy lowest level used for
4956 the bottom of the stack. */
4972 /* The expression at this stack level. */
4974 /* The precedence of the operator on its left, PREC_NONE at the
4975 bottom of the stack. */
4977 /* The operation on its left. */
4979 /* The source location of this operation. */
4983 /* Location of the binary operator. */
4984 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4987 switch (stack[sp].op) \
4989 case TRUTH_ANDIF_EXPR: \
4990 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4991 == truthvalue_false_node); \
4993 case TRUTH_ORIF_EXPR: \
4994 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4995 == truthvalue_true_node); \
5000 stack[sp - 1].expr \
5001 = default_function_array_read_conversion (stack[sp - 1].loc, \
5002 stack[sp - 1].expr); \
5004 = default_function_array_read_conversion (stack[sp].loc, \
5006 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5008 stack[sp - 1].expr, \
5012 gcc_assert (!after || c_dialect_objc ());
5013 stack[0].loc = c_parser_peek_token (parser)->location;
5014 stack[0].expr = c_parser_cast_expression (parser, after);
5015 stack[0].prec = PREC_NONE;
5020 enum tree_code ocode;
5023 switch (c_parser_peek_token (parser)->type)
5031 ocode = TRUNC_DIV_EXPR;
5035 ocode = TRUNC_MOD_EXPR;
5047 ocode = LSHIFT_EXPR;
5051 ocode = RSHIFT_EXPR;
5065 case CPP_GREATER_EQ:
5078 oprec = PREC_BITAND;
5079 ocode = BIT_AND_EXPR;
5082 oprec = PREC_BITXOR;
5083 ocode = BIT_XOR_EXPR;
5087 ocode = BIT_IOR_EXPR;
5090 oprec = PREC_LOGAND;
5091 ocode = TRUTH_ANDIF_EXPR;
5095 ocode = TRUTH_ORIF_EXPR;
5098 /* Not a binary operator, so end of the binary
5102 binary_loc = c_parser_peek_token (parser)->location;
5103 c_parser_consume_token (parser);
5104 while (oprec <= stack[sp].prec)
5108 case TRUTH_ANDIF_EXPR:
5110 = default_function_array_read_conversion (stack[sp].loc,
5112 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5113 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5114 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5115 == truthvalue_false_node);
5117 case TRUTH_ORIF_EXPR:
5119 = default_function_array_read_conversion (stack[sp].loc,
5121 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5122 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5123 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5124 == truthvalue_true_node);
5130 stack[sp].loc = binary_loc;
5131 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5132 stack[sp].prec = oprec;
5133 stack[sp].op = ocode;
5134 stack[sp].loc = binary_loc;
5139 return stack[0].expr;
5143 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5144 NULL then it is an Objective-C message expression which is the
5145 primary-expression starting the expression as an initializer.
5149 ( type-name ) unary-expression
5152 static struct c_expr
5153 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5155 location_t cast_loc = c_parser_peek_token (parser)->location;
5156 gcc_assert (!after || c_dialect_objc ());
5158 return c_parser_postfix_expression_after_primary (parser,
5160 /* If the expression begins with a parenthesized type name, it may
5161 be either a cast or a compound literal; we need to see whether
5162 the next character is '{' to tell the difference. If not, it is
5163 an unary expression. */
5164 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5165 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5167 struct c_type_name *type_name;
5170 c_parser_consume_token (parser);
5171 type_name = c_parser_type_name (parser);
5172 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5173 if (type_name == NULL)
5175 ret.value = error_mark_node;
5176 ret.original_code = ERROR_MARK;
5177 ret.original_type = NULL;
5181 /* Save casted types in the function's used types hash table. */
5182 used_types_insert (type_name->specs->type);
5184 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5185 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5188 location_t expr_loc = c_parser_peek_token (parser)->location;
5189 expr = c_parser_cast_expression (parser, NULL);
5190 expr = default_function_array_read_conversion (expr_loc, expr);
5192 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5193 ret.original_code = ERROR_MARK;
5194 ret.original_type = NULL;
5198 return c_parser_unary_expression (parser);
5201 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5207 unary-operator cast-expression
5208 sizeof unary-expression
5209 sizeof ( type-name )
5211 unary-operator: one of
5217 __alignof__ unary-expression
5218 __alignof__ ( type-name )
5221 unary-operator: one of
5222 __extension__ __real__ __imag__
5224 In addition, the GNU syntax treats ++ and -- as unary operators, so
5225 they may be applied to cast expressions with errors for non-lvalues
5228 static struct c_expr
5229 c_parser_unary_expression (c_parser *parser)
5232 struct c_expr ret, op;
5233 location_t op_loc = c_parser_peek_token (parser)->location;
5235 ret.original_code = ERROR_MARK;
5236 ret.original_type = NULL;
5237 switch (c_parser_peek_token (parser)->type)
5240 c_parser_consume_token (parser);
5241 exp_loc = c_parser_peek_token (parser)->location;
5242 op = c_parser_cast_expression (parser, NULL);
5243 op = default_function_array_read_conversion (exp_loc, op);
5244 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5245 case CPP_MINUS_MINUS:
5246 c_parser_consume_token (parser);
5247 exp_loc = c_parser_peek_token (parser)->location;
5248 op = c_parser_cast_expression (parser, NULL);
5249 op = default_function_array_read_conversion (exp_loc, op);
5250 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5252 c_parser_consume_token (parser);
5253 op = c_parser_cast_expression (parser, NULL);
5254 mark_exp_read (op.value);
5255 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5257 c_parser_consume_token (parser);
5258 exp_loc = c_parser_peek_token (parser)->location;
5259 op = c_parser_cast_expression (parser, NULL);
5260 op = default_function_array_read_conversion (exp_loc, op);
5261 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5264 if (!c_dialect_objc () && !in_system_header)
5267 "traditional C rejects the unary plus operator");
5268 c_parser_consume_token (parser);
5269 exp_loc = c_parser_peek_token (parser)->location;
5270 op = c_parser_cast_expression (parser, NULL);
5271 op = default_function_array_read_conversion (exp_loc, op);
5272 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5274 c_parser_consume_token (parser);
5275 exp_loc = c_parser_peek_token (parser)->location;
5276 op = c_parser_cast_expression (parser, NULL);
5277 op = default_function_array_read_conversion (exp_loc, op);
5278 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5280 c_parser_consume_token (parser);
5281 exp_loc = c_parser_peek_token (parser)->location;
5282 op = c_parser_cast_expression (parser, NULL);
5283 op = default_function_array_read_conversion (exp_loc, op);
5284 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5286 c_parser_consume_token (parser);
5287 exp_loc = c_parser_peek_token (parser)->location;
5288 op = c_parser_cast_expression (parser, NULL);
5289 op = default_function_array_read_conversion (exp_loc, op);
5290 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5292 /* Refer to the address of a label as a pointer. */
5293 c_parser_consume_token (parser);
5294 if (c_parser_next_token_is (parser, CPP_NAME))
5296 ret.value = finish_label_address_expr
5297 (c_parser_peek_token (parser)->value, op_loc);
5298 c_parser_consume_token (parser);
5302 c_parser_error (parser, "expected identifier");
5303 ret.value = error_mark_node;
5307 switch (c_parser_peek_token (parser)->keyword)
5310 return c_parser_sizeof_expression (parser);
5312 return c_parser_alignof_expression (parser);
5314 c_parser_consume_token (parser);
5315 ext = disable_extension_diagnostics ();
5316 ret = c_parser_cast_expression (parser, NULL);
5317 restore_extension_diagnostics (ext);
5320 c_parser_consume_token (parser);
5321 exp_loc = c_parser_peek_token (parser)->location;
5322 op = c_parser_cast_expression (parser, NULL);
5323 op = default_function_array_conversion (exp_loc, op);
5324 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5326 c_parser_consume_token (parser);
5327 exp_loc = c_parser_peek_token (parser)->location;
5328 op = c_parser_cast_expression (parser, NULL);
5329 op = default_function_array_conversion (exp_loc, op);
5330 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5332 return c_parser_postfix_expression (parser);
5335 return c_parser_postfix_expression (parser);
5339 /* Parse a sizeof expression. */
5341 static struct c_expr
5342 c_parser_sizeof_expression (c_parser *parser)
5345 location_t expr_loc;
5346 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5347 c_parser_consume_token (parser);
5348 c_inhibit_evaluation_warnings++;
5350 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5351 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5353 /* Either sizeof ( type-name ) or sizeof unary-expression
5354 starting with a compound literal. */
5355 struct c_type_name *type_name;
5356 c_parser_consume_token (parser);
5357 expr_loc = c_parser_peek_token (parser)->location;
5358 type_name = c_parser_type_name (parser);
5359 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5360 if (type_name == NULL)
5363 c_inhibit_evaluation_warnings--;
5365 ret.value = error_mark_node;
5366 ret.original_code = ERROR_MARK;
5367 ret.original_type = NULL;
5370 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5372 expr = c_parser_postfix_expression_after_paren_type (parser,
5377 /* sizeof ( type-name ). */
5378 c_inhibit_evaluation_warnings--;
5380 return c_expr_sizeof_type (expr_loc, type_name);
5384 expr_loc = c_parser_peek_token (parser)->location;
5385 expr = c_parser_unary_expression (parser);
5387 c_inhibit_evaluation_warnings--;
5389 mark_exp_read (expr.value);
5390 if (TREE_CODE (expr.value) == COMPONENT_REF
5391 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5392 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5393 return c_expr_sizeof_expr (expr_loc, expr);
5397 /* Parse an alignof expression. */
5399 static struct c_expr
5400 c_parser_alignof_expression (c_parser *parser)
5403 location_t loc = c_parser_peek_token (parser)->location;
5404 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5405 c_parser_consume_token (parser);
5406 c_inhibit_evaluation_warnings++;
5408 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5409 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5411 /* Either __alignof__ ( type-name ) or __alignof__
5412 unary-expression starting with a compound literal. */
5414 struct c_type_name *type_name;
5416 c_parser_consume_token (parser);
5417 loc = c_parser_peek_token (parser)->location;
5418 type_name = c_parser_type_name (parser);
5419 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5420 if (type_name == NULL)
5423 c_inhibit_evaluation_warnings--;
5425 ret.value = error_mark_node;
5426 ret.original_code = ERROR_MARK;
5427 ret.original_type = NULL;
5430 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5432 expr = c_parser_postfix_expression_after_paren_type (parser,
5437 /* alignof ( type-name ). */
5438 c_inhibit_evaluation_warnings--;
5440 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5441 ret.original_code = ERROR_MARK;
5442 ret.original_type = NULL;
5448 expr = c_parser_unary_expression (parser);
5450 mark_exp_read (expr.value);
5451 c_inhibit_evaluation_warnings--;
5453 ret.value = c_alignof_expr (loc, expr.value);
5454 ret.original_code = ERROR_MARK;
5455 ret.original_type = NULL;
5460 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5464 postfix-expression [ expression ]
5465 postfix-expression ( argument-expression-list[opt] )
5466 postfix-expression . identifier
5467 postfix-expression -> identifier
5468 postfix-expression ++
5469 postfix-expression --
5470 ( type-name ) { initializer-list }
5471 ( type-name ) { initializer-list , }
5473 argument-expression-list:
5475 argument-expression-list , argument-expression
5487 (treated as a keyword in GNU C)
5490 ( compound-statement )
5491 __builtin_va_arg ( assignment-expression , type-name )
5492 __builtin_offsetof ( type-name , offsetof-member-designator )
5493 __builtin_choose_expr ( assignment-expression ,
5494 assignment-expression ,
5495 assignment-expression )
5496 __builtin_types_compatible_p ( type-name , type-name )
5498 offsetof-member-designator:
5500 offsetof-member-designator . identifier
5501 offsetof-member-designator [ expression ]
5506 [ objc-receiver objc-message-args ]
5507 @selector ( objc-selector-arg )
5508 @protocol ( identifier )
5509 @encode ( type-name )
5513 static struct c_expr
5514 c_parser_postfix_expression (c_parser *parser)
5516 struct c_expr expr, e1, e2, e3;
5517 struct c_type_name *t1, *t2;
5518 location_t loc = c_parser_peek_token (parser)->location;;
5519 expr.original_code = ERROR_MARK;
5520 expr.original_type = NULL;
5521 switch (c_parser_peek_token (parser)->type)
5524 expr.value = c_parser_peek_token (parser)->value;
5525 loc = c_parser_peek_token (parser)->location;
5526 c_parser_consume_token (parser);
5527 if (TREE_CODE (expr.value) == FIXED_CST
5528 && !targetm.fixed_point_supported_p ())
5530 error_at (loc, "fixed-point types not supported for this target");
5531 expr.value = error_mark_node;
5538 expr.value = c_parser_peek_token (parser)->value;
5539 c_parser_consume_token (parser);
5545 case CPP_UTF8STRING:
5546 expr.value = c_parser_peek_token (parser)->value;
5547 expr.original_code = STRING_CST;
5548 c_parser_consume_token (parser);
5550 case CPP_OBJC_STRING:
5551 gcc_assert (c_dialect_objc ());
5553 = objc_build_string_object (c_parser_peek_token (parser)->value);
5554 c_parser_consume_token (parser);
5557 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5559 c_parser_error (parser, "expected expression");
5560 expr.value = error_mark_node;
5564 tree id = c_parser_peek_token (parser)->value;
5565 c_parser_consume_token (parser);
5566 expr.value = build_external_ref (loc, id,
5567 (c_parser_peek_token (parser)->type
5569 &expr.original_type);
5572 case CPP_OPEN_PAREN:
5573 /* A parenthesized expression, statement expression or compound
5575 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5577 /* A statement expression. */
5579 location_t brace_loc;
5580 c_parser_consume_token (parser);
5581 brace_loc = c_parser_peek_token (parser)->location;
5582 c_parser_consume_token (parser);
5583 if (cur_stmt_list == NULL)
5585 error_at (loc, "braced-group within expression allowed "
5586 "only inside a function");
5587 parser->error = true;
5588 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5589 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5590 expr.value = error_mark_node;
5593 stmt = c_begin_stmt_expr ();
5594 c_parser_compound_statement_nostart (parser);
5595 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5597 pedwarn (loc, OPT_pedantic,
5598 "ISO C forbids braced-groups within expressions");
5599 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5601 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5603 /* A compound literal. ??? Can we actually get here rather
5604 than going directly to
5605 c_parser_postfix_expression_after_paren_type from
5608 struct c_type_name *type_name;
5609 c_parser_consume_token (parser);
5610 loc = c_parser_peek_token (parser)->location;
5611 type_name = c_parser_type_name (parser);
5612 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5614 if (type_name == NULL)
5616 expr.value = error_mark_node;
5619 expr = c_parser_postfix_expression_after_paren_type (parser,
5625 /* A parenthesized expression. */
5626 c_parser_consume_token (parser);
5627 expr = c_parser_expression (parser);
5628 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5629 TREE_NO_WARNING (expr.value) = 1;
5630 if (expr.original_code != C_MAYBE_CONST_EXPR)
5631 expr.original_code = ERROR_MARK;
5632 /* Don't change EXPR.ORIGINAL_TYPE. */
5633 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5638 switch (c_parser_peek_token (parser)->keyword)
5640 case RID_FUNCTION_NAME:
5641 case RID_PRETTY_FUNCTION_NAME:
5642 case RID_C99_FUNCTION_NAME:
5643 expr.value = fname_decl (loc,
5644 c_parser_peek_token (parser)->keyword,
5645 c_parser_peek_token (parser)->value);
5646 c_parser_consume_token (parser);
5649 c_parser_consume_token (parser);
5650 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5652 expr.value = error_mark_node;
5655 e1 = c_parser_expr_no_commas (parser, NULL);
5656 mark_exp_read (e1.value);
5657 e1.value = c_fully_fold (e1.value, false, NULL);
5658 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5660 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5661 expr.value = error_mark_node;
5664 loc = c_parser_peek_token (parser)->location;
5665 t1 = c_parser_type_name (parser);
5666 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5670 expr.value = error_mark_node;
5674 tree type_expr = NULL_TREE;
5675 expr.value = c_build_va_arg (loc, e1.value,
5676 groktypename (t1, &type_expr, NULL));
5679 expr.value = build2 (C_MAYBE_CONST_EXPR,
5680 TREE_TYPE (expr.value), type_expr,
5682 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5687 c_parser_consume_token (parser);
5688 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5690 expr.value = error_mark_node;
5693 t1 = c_parser_type_name (parser);
5696 expr.value = error_mark_node;
5699 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5701 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5702 expr.value = error_mark_node;
5706 tree type = groktypename (t1, NULL, NULL);
5708 if (type == error_mark_node)
5709 offsetof_ref = error_mark_node;
5712 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5713 SET_EXPR_LOCATION (offsetof_ref, loc);
5715 /* Parse the second argument to __builtin_offsetof. We
5716 must have one identifier, and beyond that we want to
5717 accept sub structure and sub array references. */
5718 if (c_parser_next_token_is (parser, CPP_NAME))
5720 offsetof_ref = build_component_ref
5721 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5722 c_parser_consume_token (parser);
5723 while (c_parser_next_token_is (parser, CPP_DOT)
5724 || c_parser_next_token_is (parser,
5726 || c_parser_next_token_is (parser,
5729 if (c_parser_next_token_is (parser, CPP_DEREF))
5731 loc = c_parser_peek_token (parser)->location;
5732 offsetof_ref = build_array_ref (loc,
5737 else if (c_parser_next_token_is (parser, CPP_DOT))
5740 c_parser_consume_token (parser);
5741 if (c_parser_next_token_is_not (parser,
5744 c_parser_error (parser, "expected identifier");
5747 offsetof_ref = build_component_ref
5749 c_parser_peek_token (parser)->value);
5750 c_parser_consume_token (parser);
5755 loc = c_parser_peek_token (parser)->location;
5756 c_parser_consume_token (parser);
5757 idx = c_parser_expression (parser).value;
5758 idx = c_fully_fold (idx, false, NULL);
5759 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5761 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5766 c_parser_error (parser, "expected identifier");
5767 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5769 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5772 case RID_CHOOSE_EXPR:
5773 c_parser_consume_token (parser);
5774 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5776 expr.value = error_mark_node;
5779 loc = c_parser_peek_token (parser)->location;
5780 e1 = c_parser_expr_no_commas (parser, NULL);
5781 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5783 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5784 expr.value = error_mark_node;
5787 e2 = c_parser_expr_no_commas (parser, NULL);
5788 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5790 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5791 expr.value = error_mark_node;
5794 e3 = c_parser_expr_no_commas (parser, NULL);
5795 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5801 mark_exp_read (e2.value);
5802 mark_exp_read (e3.value);
5803 if (TREE_CODE (c) != INTEGER_CST
5804 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5806 "first argument to %<__builtin_choose_expr%> not"
5808 constant_expression_warning (c);
5809 expr = integer_zerop (c) ? e3 : e2;
5812 case RID_TYPES_COMPATIBLE_P:
5813 c_parser_consume_token (parser);
5814 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5816 expr.value = error_mark_node;
5819 t1 = c_parser_type_name (parser);
5822 expr.value = error_mark_node;
5825 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5827 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5828 expr.value = error_mark_node;
5831 t2 = c_parser_type_name (parser);
5834 expr.value = error_mark_node;
5837 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5842 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5843 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5845 expr.value = comptypes (e1, e2)
5846 ? build_int_cst (NULL_TREE, 1)
5847 : build_int_cst (NULL_TREE, 0);
5850 case RID_AT_SELECTOR:
5851 gcc_assert (c_dialect_objc ());
5852 c_parser_consume_token (parser);
5853 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5855 expr.value = error_mark_node;
5859 tree sel = c_parser_objc_selector_arg (parser);
5860 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5862 expr.value = objc_build_selector_expr (loc, sel);
5865 case RID_AT_PROTOCOL:
5866 gcc_assert (c_dialect_objc ());
5867 c_parser_consume_token (parser);
5868 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5870 expr.value = error_mark_node;
5873 if (c_parser_next_token_is_not (parser, CPP_NAME))
5875 c_parser_error (parser, "expected identifier");
5876 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5877 expr.value = error_mark_node;
5881 tree id = c_parser_peek_token (parser)->value;
5882 c_parser_consume_token (parser);
5883 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5885 expr.value = objc_build_protocol_expr (id);
5889 /* Extension to support C-structures in the archiver. */
5890 gcc_assert (c_dialect_objc ());
5891 c_parser_consume_token (parser);
5892 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5894 expr.value = error_mark_node;
5897 t1 = c_parser_type_name (parser);
5900 expr.value = error_mark_node;
5901 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5907 tree type = groktypename (t1, NULL, NULL);
5908 expr.value = objc_build_encode_expr (type);
5912 c_parser_error (parser, "expected expression");
5913 expr.value = error_mark_node;
5917 case CPP_OPEN_SQUARE:
5918 if (c_dialect_objc ())
5920 tree receiver, args;
5921 c_parser_consume_token (parser);
5922 receiver = c_parser_objc_receiver (parser);
5923 args = c_parser_objc_message_args (parser);
5924 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5926 expr.value = objc_build_message_expr (build_tree_list (receiver,
5930 /* Else fall through to report error. */
5932 c_parser_error (parser, "expected expression");
5933 expr.value = error_mark_node;
5936 return c_parser_postfix_expression_after_primary (parser, loc, expr);
5939 /* Parse a postfix expression after a parenthesized type name: the
5940 brace-enclosed initializer of a compound literal, possibly followed
5941 by some postfix operators. This is separate because it is not
5942 possible to tell until after the type name whether a cast
5943 expression has a cast or a compound literal, or whether the operand
5944 of sizeof is a parenthesized type name or starts with a compound
5945 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5946 location of the first token after the parentheses around the type
5949 static struct c_expr
5950 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5951 struct c_type_name *type_name,
5952 location_t type_loc)
5958 location_t start_loc;
5959 tree type_expr = NULL_TREE;
5960 bool type_expr_const = true;
5961 check_compound_literal_type (type_loc, type_name);
5962 start_init (NULL_TREE, NULL, 0);
5963 type = groktypename (type_name, &type_expr, &type_expr_const);
5964 start_loc = c_parser_peek_token (parser)->location;
5965 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5967 error_at (type_loc, "compound literal has variable size");
5968 type = error_mark_node;
5970 init = c_parser_braced_init (parser, type, false);
5972 maybe_warn_string_init (type, init);
5974 if (type != error_mark_node
5975 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
5976 && current_function_decl)
5978 error ("compound literal qualified by address-space qualifier");
5979 type = error_mark_node;
5983 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5984 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5985 ? CONSTRUCTOR_NON_CONST (init.value)
5986 : init.original_code == C_MAYBE_CONST_EXPR);
5987 non_const |= !type_expr_const;
5988 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
5989 expr.original_code = ERROR_MARK;
5990 expr.original_type = NULL;
5993 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5995 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5996 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6000 gcc_assert (!non_const);
6001 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6002 type_expr, expr.value);
6005 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6008 /* Parse a postfix expression after the initial primary or compound
6009 literal; that is, parse a series of postfix operators.
6011 EXPR_LOC is the location of the primary expression. */
6013 static struct c_expr
6014 c_parser_postfix_expression_after_primary (c_parser *parser,
6015 location_t expr_loc,
6018 struct c_expr orig_expr;
6020 VEC(tree,gc) *exprlist;
6021 VEC(tree,gc) *origtypes;
6024 location_t op_loc = c_parser_peek_token (parser)->location;
6025 switch (c_parser_peek_token (parser)->type)
6027 case CPP_OPEN_SQUARE:
6028 /* Array reference. */
6029 c_parser_consume_token (parser);
6030 idx = c_parser_expression (parser).value;
6031 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6033 expr.value = build_array_ref (op_loc, expr.value, idx);
6034 expr.original_code = ERROR_MARK;
6035 expr.original_type = NULL;
6037 case CPP_OPEN_PAREN:
6038 /* Function call. */
6039 c_parser_consume_token (parser);
6040 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6043 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6044 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6047 mark_exp_read (expr.value);
6048 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6049 "(" after the FUNCNAME, which is what we have now. */
6050 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6052 expr.original_code = ERROR_MARK;
6053 if (TREE_CODE (expr.value) == INTEGER_CST
6054 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6055 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6056 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6057 expr.original_code = C_MAYBE_CONST_EXPR;
6058 expr.original_type = NULL;
6059 if (exprlist != NULL)
6061 release_tree_vector (exprlist);
6062 release_tree_vector (origtypes);
6066 /* Structure element reference. */
6067 c_parser_consume_token (parser);
6068 expr = default_function_array_conversion (expr_loc, expr);
6069 if (c_parser_next_token_is (parser, CPP_NAME))
6070 ident = c_parser_peek_token (parser)->value;
6073 c_parser_error (parser, "expected identifier");
6074 expr.value = error_mark_node;
6075 expr.original_code = ERROR_MARK;
6076 expr.original_type = NULL;
6079 c_parser_consume_token (parser);
6080 expr.value = build_component_ref (op_loc, expr.value, ident);
6081 expr.original_code = ERROR_MARK;
6082 if (TREE_CODE (expr.value) != COMPONENT_REF)
6083 expr.original_type = NULL;
6086 /* Remember the original type of a bitfield. */
6087 tree field = TREE_OPERAND (expr.value, 1);
6088 if (TREE_CODE (field) != FIELD_DECL)
6089 expr.original_type = NULL;
6091 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6095 /* Structure element reference. */
6096 c_parser_consume_token (parser);
6097 expr = default_function_array_conversion (expr_loc, expr);
6098 if (c_parser_next_token_is (parser, CPP_NAME))
6099 ident = c_parser_peek_token (parser)->value;
6102 c_parser_error (parser, "expected identifier");
6103 expr.value = error_mark_node;
6104 expr.original_code = ERROR_MARK;
6105 expr.original_type = NULL;
6108 c_parser_consume_token (parser);
6109 expr.value = build_component_ref (op_loc,
6110 build_indirect_ref (op_loc,
6114 expr.original_code = ERROR_MARK;
6115 if (TREE_CODE (expr.value) != COMPONENT_REF)
6116 expr.original_type = NULL;
6119 /* Remember the original type of a bitfield. */
6120 tree field = TREE_OPERAND (expr.value, 1);
6121 if (TREE_CODE (field) != FIELD_DECL)
6122 expr.original_type = NULL;
6124 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6128 /* Postincrement. */
6129 c_parser_consume_token (parser);
6130 expr = default_function_array_read_conversion (expr_loc, expr);
6131 expr.value = build_unary_op (op_loc,
6132 POSTINCREMENT_EXPR, expr.value, 0);
6133 expr.original_code = ERROR_MARK;
6134 expr.original_type = NULL;
6136 case CPP_MINUS_MINUS:
6137 /* Postdecrement. */
6138 c_parser_consume_token (parser);
6139 expr = default_function_array_read_conversion (expr_loc, expr);
6140 expr.value = build_unary_op (op_loc,
6141 POSTDECREMENT_EXPR, expr.value, 0);
6142 expr.original_code = ERROR_MARK;
6143 expr.original_type = NULL;
6151 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6154 assignment-expression
6155 expression , assignment-expression
6158 static struct c_expr
6159 c_parser_expression (c_parser *parser)
6162 expr = c_parser_expr_no_commas (parser, NULL);
6163 while (c_parser_next_token_is (parser, CPP_COMMA))
6167 location_t loc = c_parser_peek_token (parser)->location;
6168 location_t expr_loc;
6169 c_parser_consume_token (parser);
6170 expr_loc = c_parser_peek_token (parser)->location;
6171 lhsval = expr.value;
6172 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6173 lhsval = TREE_OPERAND (lhsval, 1);
6174 if (DECL_P (lhsval) || handled_component_p (lhsval))
6175 mark_exp_read (lhsval);
6176 next = c_parser_expr_no_commas (parser, NULL);
6177 next = default_function_array_conversion (expr_loc, next);
6178 expr.value = build_compound_expr (loc, expr.value, next.value);
6179 expr.original_code = COMPOUND_EXPR;
6180 expr.original_type = next.original_type;
6185 /* Parse an expression and convert functions or arrays to
6188 static struct c_expr
6189 c_parser_expression_conv (c_parser *parser)
6192 location_t loc = c_parser_peek_token (parser)->location;
6193 expr = c_parser_expression (parser);
6194 expr = default_function_array_conversion (loc, expr);
6198 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6199 functions and arrays to pointers. If FOLD_P, fold the expressions.
6202 assignment-expression
6203 nonempty-expr-list , assignment-expression
6206 static VEC(tree,gc) *
6207 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6208 VEC(tree,gc) **p_orig_types)
6211 VEC(tree,gc) *orig_types;
6213 location_t loc = c_parser_peek_token (parser)->location;
6215 ret = make_tree_vector ();
6216 if (p_orig_types == NULL)
6219 orig_types = make_tree_vector ();
6221 expr = c_parser_expr_no_commas (parser, NULL);
6223 expr = default_function_array_read_conversion (loc, expr);
6225 expr.value = c_fully_fold (expr.value, false, NULL);
6226 VEC_quick_push (tree, ret, expr.value);
6227 if (orig_types != NULL)
6228 VEC_quick_push (tree, orig_types, expr.original_type);
6229 while (c_parser_next_token_is (parser, CPP_COMMA))
6231 c_parser_consume_token (parser);
6232 loc = c_parser_peek_token (parser)->location;
6233 expr = c_parser_expr_no_commas (parser, NULL);
6235 expr = default_function_array_read_conversion (loc, expr);
6237 expr.value = c_fully_fold (expr.value, false, NULL);
6238 VEC_safe_push (tree, gc, ret, expr.value);
6239 if (orig_types != NULL)
6240 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6242 if (orig_types != NULL)
6243 *p_orig_types = orig_types;
6247 /* Parse Objective-C-specific constructs. */
6249 /* Parse an objc-class-definition.
6251 objc-class-definition:
6252 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6253 objc-class-instance-variables[opt] objc-methodprotolist @end
6254 @implementation identifier objc-superclass[opt]
6255 objc-class-instance-variables[opt]
6256 @interface identifier ( identifier ) objc-protocol-refs[opt]
6257 objc-methodprotolist @end
6258 @implementation identifier ( identifier )
6263 "@interface identifier (" must start "@interface identifier (
6264 identifier ) ...": objc-methodprotolist in the first production may
6265 not start with a parenthesized identifier as a declarator of a data
6266 definition with no declaration specifiers if the objc-superclass,
6267 objc-protocol-refs and objc-class-instance-variables are omitted. */
6270 c_parser_objc_class_definition (c_parser *parser)
6275 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6277 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6281 c_parser_consume_token (parser);
6282 if (c_parser_next_token_is_not (parser, CPP_NAME))
6284 c_parser_error (parser, "expected identifier");
6287 id1 = c_parser_peek_token (parser)->value;
6288 c_parser_consume_token (parser);
6289 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6292 tree proto = NULL_TREE;
6293 c_parser_consume_token (parser);
6294 if (c_parser_next_token_is_not (parser, CPP_NAME))
6296 c_parser_error (parser, "expected identifier");
6297 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6300 id2 = c_parser_peek_token (parser)->value;
6301 c_parser_consume_token (parser);
6302 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6305 objc_start_category_implementation (id1, id2);
6308 if (c_parser_next_token_is (parser, CPP_LESS))
6309 proto = c_parser_objc_protocol_refs (parser);
6310 objc_start_category_interface (id1, id2, proto);
6311 c_parser_objc_methodprotolist (parser);
6312 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6313 objc_finish_interface ();
6316 if (c_parser_next_token_is (parser, CPP_COLON))
6318 c_parser_consume_token (parser);
6319 if (c_parser_next_token_is_not (parser, CPP_NAME))
6321 c_parser_error (parser, "expected identifier");
6324 superclass = c_parser_peek_token (parser)->value;
6325 c_parser_consume_token (parser);
6328 superclass = NULL_TREE;
6331 tree proto = NULL_TREE;
6332 if (c_parser_next_token_is (parser, CPP_LESS))
6333 proto = c_parser_objc_protocol_refs (parser);
6334 objc_start_class_interface (id1, superclass, proto);
6337 objc_start_class_implementation (id1, superclass);
6338 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6339 c_parser_objc_class_instance_variables (parser);
6342 objc_continue_interface ();
6343 c_parser_objc_methodprotolist (parser);
6344 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6345 objc_finish_interface ();
6349 objc_continue_implementation ();
6354 /* Parse objc-class-instance-variables.
6356 objc-class-instance-variables:
6357 { objc-instance-variable-decl-list[opt] }
6359 objc-instance-variable-decl-list:
6360 objc-visibility-spec
6361 objc-instance-variable-decl ;
6363 objc-instance-variable-decl-list objc-visibility-spec
6364 objc-instance-variable-decl-list objc-instance-variable-decl ;
6365 objc-instance-variable-decl-list ;
6367 objc-visibility-spec:
6372 objc-instance-variable-decl:
6377 c_parser_objc_class_instance_variables (c_parser *parser)
6379 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6380 c_parser_consume_token (parser);
6381 while (c_parser_next_token_is_not (parser, CPP_EOF))
6384 /* Parse any stray semicolon. */
6385 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6387 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6388 "extra semicolon in struct or union specified");
6389 c_parser_consume_token (parser);
6392 /* Stop if at the end of the instance variables. */
6393 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6395 c_parser_consume_token (parser);
6398 /* Parse any objc-visibility-spec. */
6399 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6401 c_parser_consume_token (parser);
6402 objc_set_visibility (2);
6405 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6407 c_parser_consume_token (parser);
6408 objc_set_visibility (0);
6411 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6413 c_parser_consume_token (parser);
6414 objc_set_visibility (1);
6417 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6419 c_parser_pragma (parser, pragma_external);
6423 /* Parse some comma-separated declarations. */
6424 decls = c_parser_struct_declaration (parser);
6426 /* Comma-separated instance variables are chained together in
6427 reverse order; add them one by one. */
6428 tree ivar = nreverse (decls);
6429 for (; ivar; ivar = TREE_CHAIN (ivar))
6430 objc_add_instance_variable (copy_node (ivar));
6432 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6436 /* Parse an objc-class-declaration.
6438 objc-class-declaration:
6439 @class identifier-list ;
6443 c_parser_objc_class_declaration (c_parser *parser)
6445 tree list = NULL_TREE;
6446 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6447 c_parser_consume_token (parser);
6448 /* Any identifiers, including those declared as type names, are OK
6453 if (c_parser_next_token_is_not (parser, CPP_NAME))
6455 c_parser_error (parser, "expected identifier");
6458 id = c_parser_peek_token (parser)->value;
6459 list = chainon (list, build_tree_list (NULL_TREE, id));
6460 c_parser_consume_token (parser);
6461 if (c_parser_next_token_is (parser, CPP_COMMA))
6462 c_parser_consume_token (parser);
6466 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6467 objc_declare_class (list);
6470 /* Parse an objc-alias-declaration.
6472 objc-alias-declaration:
6473 @compatibility_alias identifier identifier ;
6477 c_parser_objc_alias_declaration (c_parser *parser)
6480 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6481 c_parser_consume_token (parser);
6482 if (c_parser_next_token_is_not (parser, CPP_NAME))
6484 c_parser_error (parser, "expected identifier");
6485 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6488 id1 = c_parser_peek_token (parser)->value;
6489 c_parser_consume_token (parser);
6490 if (c_parser_next_token_is_not (parser, CPP_NAME))
6492 c_parser_error (parser, "expected identifier");
6493 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6496 id2 = c_parser_peek_token (parser)->value;
6497 c_parser_consume_token (parser);
6498 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6499 objc_declare_alias (id1, id2);
6502 /* Parse an objc-protocol-definition.
6504 objc-protocol-definition:
6505 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6506 @protocol identifier-list ;
6508 "@protocol identifier ;" should be resolved as "@protocol
6509 identifier-list ;": objc-methodprotolist may not start with a
6510 semicolon in the first alternative if objc-protocol-refs are
6514 c_parser_objc_protocol_definition (c_parser *parser)
6516 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6517 c_parser_consume_token (parser);
6518 if (c_parser_next_token_is_not (parser, CPP_NAME))
6520 c_parser_error (parser, "expected identifier");
6523 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6524 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6526 tree list = NULL_TREE;
6527 /* Any identifiers, including those declared as type names, are
6532 if (c_parser_next_token_is_not (parser, CPP_NAME))
6534 c_parser_error (parser, "expected identifier");
6537 id = c_parser_peek_token (parser)->value;
6538 list = chainon (list, build_tree_list (NULL_TREE, id));
6539 c_parser_consume_token (parser);
6540 if (c_parser_next_token_is (parser, CPP_COMMA))
6541 c_parser_consume_token (parser);
6545 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6546 objc_declare_protocols (list);
6550 tree id = c_parser_peek_token (parser)->value;
6551 tree proto = NULL_TREE;
6552 c_parser_consume_token (parser);
6553 if (c_parser_next_token_is (parser, CPP_LESS))
6554 proto = c_parser_objc_protocol_refs (parser);
6555 parser->objc_pq_context = true;
6556 objc_start_protocol (id, proto);
6557 c_parser_objc_methodprotolist (parser);
6558 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6559 parser->objc_pq_context = false;
6560 objc_finish_interface ();
6564 /* Parse an objc-method-type.
6571 static enum tree_code
6572 c_parser_objc_method_type (c_parser *parser)
6574 switch (c_parser_peek_token (parser)->type)
6577 c_parser_consume_token (parser);
6580 c_parser_consume_token (parser);
6587 /* Parse an objc-method-definition.
6589 objc-method-definition:
6590 objc-method-type objc-method-decl ;[opt] compound-statement
6594 c_parser_objc_method_definition (c_parser *parser)
6596 enum tree_code type = c_parser_objc_method_type (parser);
6598 objc_set_method_type (type);
6599 parser->objc_pq_context = true;
6600 decl = c_parser_objc_method_decl (parser);
6601 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6603 c_parser_consume_token (parser);
6604 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6605 "extra semicolon in method definition specified");
6607 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6609 c_parser_error (parser, "expected %<{%>");
6612 parser->objc_pq_context = false;
6613 objc_start_method_definition (decl);
6614 add_stmt (c_parser_compound_statement (parser));
6615 objc_finish_method_definition (current_function_decl);
6618 /* Parse an objc-methodprotolist.
6620 objc-methodprotolist:
6622 objc-methodprotolist objc-methodproto
6623 objc-methodprotolist declaration
6624 objc-methodprotolist ;
6626 The declaration is a data definition, which may be missing
6627 declaration specifiers under the same rules and diagnostics as
6628 other data definitions outside functions, and the stray semicolon
6629 is diagnosed the same way as a stray semicolon outside a
6633 c_parser_objc_methodprotolist (c_parser *parser)
6637 /* The list is terminated by @end. */
6638 switch (c_parser_peek_token (parser)->type)
6641 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6642 "ISO C does not allow extra %<;%> outside of a function");
6643 c_parser_consume_token (parser);
6647 c_parser_objc_methodproto (parser);
6650 c_parser_pragma (parser, pragma_external);
6655 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6657 c_parser_declaration_or_fndef (parser, false, false, true,
6664 /* Parse an objc-methodproto.
6667 objc-method-type objc-method-decl ;
6671 c_parser_objc_methodproto (c_parser *parser)
6673 enum tree_code type = c_parser_objc_method_type (parser);
6675 objc_set_method_type (type);
6676 /* Remember protocol qualifiers in prototypes. */
6677 parser->objc_pq_context = true;
6678 decl = c_parser_objc_method_decl (parser);
6679 /* Forget protocol qualifiers here. */
6680 parser->objc_pq_context = false;
6681 objc_add_method_declaration (decl);
6682 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6685 /* Parse an objc-method-decl.
6688 ( objc-type-name ) objc-selector
6690 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6691 objc-keyword-selector objc-optparmlist
6693 objc-keyword-selector:
6695 objc-keyword-selector objc-keyword-decl
6698 objc-selector : ( objc-type-name ) identifier
6699 objc-selector : identifier
6700 : ( objc-type-name ) identifier
6704 objc-optparms objc-optellipsis
6708 objc-opt-parms , parameter-declaration
6716 c_parser_objc_method_decl (c_parser *parser)
6718 tree type = NULL_TREE;
6720 tree parms = NULL_TREE;
6721 bool ellipsis = false;
6723 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6725 c_parser_consume_token (parser);
6726 type = c_parser_objc_type_name (parser);
6727 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6729 sel = c_parser_objc_selector (parser);
6730 /* If there is no selector, or a colon follows, we have an
6731 objc-keyword-selector. If there is a selector, and a colon does
6732 not follow, that selector ends the objc-method-decl. */
6733 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6736 tree list = NULL_TREE;
6739 tree atype = NULL_TREE, id, keyworddecl;
6740 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6742 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6744 c_parser_consume_token (parser);
6745 atype = c_parser_objc_type_name (parser);
6746 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6749 if (c_parser_next_token_is_not (parser, CPP_NAME))
6751 c_parser_error (parser, "expected identifier");
6752 return error_mark_node;
6754 id = c_parser_peek_token (parser)->value;
6755 c_parser_consume_token (parser);
6756 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6757 list = chainon (list, keyworddecl);
6758 tsel = c_parser_objc_selector (parser);
6759 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6762 /* Parse the optional parameter list. Optional Objective-C
6763 method parameters follow the C syntax, and may include '...'
6764 to denote a variable number of arguments. */
6765 parms = make_node (TREE_LIST);
6766 while (c_parser_next_token_is (parser, CPP_COMMA))
6768 struct c_parm *parm;
6769 c_parser_consume_token (parser);
6770 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6773 c_parser_consume_token (parser);
6776 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6779 parms = chainon (parms,
6780 build_tree_list (NULL_TREE, grokparm (parm)));
6784 return objc_build_method_signature (type, sel, parms, ellipsis);
6787 /* Parse an objc-type-name.
6790 objc-type-qualifiers[opt] type-name
6791 objc-type-qualifiers[opt]
6793 objc-type-qualifiers:
6795 objc-type-qualifiers objc-type-qualifier
6797 objc-type-qualifier: one of
6798 in out inout bycopy byref oneway
6802 c_parser_objc_type_name (c_parser *parser)
6804 tree quals = NULL_TREE;
6805 struct c_type_name *type_name = NULL;
6806 tree type = NULL_TREE;
6809 c_token *token = c_parser_peek_token (parser);
6810 if (token->type == CPP_KEYWORD
6811 && (token->keyword == RID_IN
6812 || token->keyword == RID_OUT
6813 || token->keyword == RID_INOUT
6814 || token->keyword == RID_BYCOPY
6815 || token->keyword == RID_BYREF
6816 || token->keyword == RID_ONEWAY))
6818 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6819 c_parser_consume_token (parser);
6824 if (c_parser_next_token_starts_typename (parser))
6825 type_name = c_parser_type_name (parser);
6827 type = groktypename (type_name, NULL, NULL);
6828 return build_tree_list (quals, type);
6831 /* Parse objc-protocol-refs.
6838 c_parser_objc_protocol_refs (c_parser *parser)
6840 tree list = NULL_TREE;
6841 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6842 c_parser_consume_token (parser);
6843 /* Any identifiers, including those declared as type names, are OK
6848 if (c_parser_next_token_is_not (parser, CPP_NAME))
6850 c_parser_error (parser, "expected identifier");
6853 id = c_parser_peek_token (parser)->value;
6854 list = chainon (list, build_tree_list (NULL_TREE, id));
6855 c_parser_consume_token (parser);
6856 if (c_parser_next_token_is (parser, CPP_COMMA))
6857 c_parser_consume_token (parser);
6861 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6865 /* Parse an objc-try-catch-statement.
6867 objc-try-catch-statement:
6868 @try compound-statement objc-catch-list[opt]
6869 @try compound-statement objc-catch-list[opt] @finally compound-statement
6872 @catch ( parameter-declaration ) compound-statement
6873 objc-catch-list @catch ( parameter-declaration ) compound-statement
6877 c_parser_objc_try_catch_statement (c_parser *parser)
6881 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6882 c_parser_consume_token (parser);
6883 loc = c_parser_peek_token (parser)->location;
6884 stmt = c_parser_compound_statement (parser);
6885 objc_begin_try_stmt (loc, stmt);
6886 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6888 struct c_parm *parm;
6889 c_parser_consume_token (parser);
6890 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6892 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6899 objc_begin_catch_clause (grokparm (parm));
6900 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6901 c_parser_compound_statement_nostart (parser);
6902 objc_finish_catch_clause ();
6904 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6908 c_parser_consume_token (parser);
6909 finloc = c_parser_peek_token (parser)->location;
6910 finstmt = c_parser_compound_statement (parser);
6911 objc_build_finally_clause (finloc, finstmt);
6913 objc_finish_try_stmt ();
6916 /* Parse an objc-synchronized-statement.
6918 objc-synchronized-statement:
6919 @synchronized ( expression ) compound-statement
6923 c_parser_objc_synchronized_statement (c_parser *parser)
6927 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6928 c_parser_consume_token (parser);
6929 loc = c_parser_peek_token (parser)->location;
6930 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6932 expr = c_parser_expression (parser).value;
6933 expr = c_fully_fold (expr, false, NULL);
6934 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6937 expr = error_mark_node;
6938 stmt = c_parser_compound_statement (parser);
6939 objc_build_synchronized (loc, expr, stmt);
6942 /* Parse an objc-selector; return NULL_TREE without an error if the
6943 next token is not an objc-selector.
6948 enum struct union if else while do for switch case default
6949 break continue return goto asm sizeof typeof __alignof
6950 unsigned long const short volatile signed restrict _Complex
6951 in out inout bycopy byref oneway int char float double void _Bool
6953 ??? Why this selection of keywords but not, for example, storage
6954 class specifiers? */
6957 c_parser_objc_selector (c_parser *parser)
6959 c_token *token = c_parser_peek_token (parser);
6960 tree value = token->value;
6961 if (token->type == CPP_NAME)
6963 c_parser_consume_token (parser);
6966 if (token->type != CPP_KEYWORD)
6968 switch (token->keyword)
7009 c_parser_consume_token (parser);
7016 /* Parse an objc-selector-arg.
7020 objc-keywordname-list
7022 objc-keywordname-list:
7024 objc-keywordname-list objc-keywordname
7032 c_parser_objc_selector_arg (c_parser *parser)
7034 tree sel = c_parser_objc_selector (parser);
7035 tree list = NULL_TREE;
7036 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7040 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7042 list = chainon (list, build_tree_list (sel, NULL_TREE));
7043 sel = c_parser_objc_selector (parser);
7044 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7050 /* Parse an objc-receiver.
7059 c_parser_objc_receiver (c_parser *parser)
7061 if (c_parser_peek_token (parser)->type == CPP_NAME
7062 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7063 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7065 tree id = c_parser_peek_token (parser)->value;
7066 c_parser_consume_token (parser);
7067 return objc_get_class_reference (id);
7069 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7072 /* Parse objc-message-args.
7076 objc-keywordarg-list
7078 objc-keywordarg-list:
7080 objc-keywordarg-list objc-keywordarg
7083 objc-selector : objc-keywordexpr
7088 c_parser_objc_message_args (c_parser *parser)
7090 tree sel = c_parser_objc_selector (parser);
7091 tree list = NULL_TREE;
7092 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7097 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7098 return error_mark_node;
7099 keywordexpr = c_parser_objc_keywordexpr (parser);
7100 list = chainon (list, build_tree_list (sel, keywordexpr));
7101 sel = c_parser_objc_selector (parser);
7102 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7108 /* Parse an objc-keywordexpr.
7115 c_parser_objc_keywordexpr (c_parser *parser)
7118 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7119 if (VEC_length (tree, expr_list) == 1)
7121 /* Just return the expression, remove a level of
7123 ret = VEC_index (tree, expr_list, 0);
7127 /* We have a comma expression, we will collapse later. */
7128 ret = build_tree_list_vec (expr_list);
7130 release_tree_vector (expr_list);
7135 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7136 should be considered, statements. ALLOW_STMT is true if we're within
7137 the context of a function and such pragmas are to be allowed. Returns
7138 true if we actually parsed such a pragma. */
7141 c_parser_pragma (c_parser *parser, enum pragma_context context)
7145 id = c_parser_peek_token (parser)->pragma_kind;
7146 gcc_assert (id != PRAGMA_NONE);
7150 case PRAGMA_OMP_BARRIER:
7151 if (context != pragma_compound)
7153 if (context == pragma_stmt)
7154 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7155 "used in compound statements");
7158 c_parser_omp_barrier (parser);
7161 case PRAGMA_OMP_FLUSH:
7162 if (context != pragma_compound)
7164 if (context == pragma_stmt)
7165 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7166 "used in compound statements");
7169 c_parser_omp_flush (parser);
7172 case PRAGMA_OMP_TASKWAIT:
7173 if (context != pragma_compound)
7175 if (context == pragma_stmt)
7176 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7177 "used in compound statements");
7180 c_parser_omp_taskwait (parser);
7183 case PRAGMA_OMP_THREADPRIVATE:
7184 c_parser_omp_threadprivate (parser);
7187 case PRAGMA_OMP_SECTION:
7188 error_at (c_parser_peek_token (parser)->location,
7189 "%<#pragma omp section%> may only be used in "
7190 "%<#pragma omp sections%> construct");
7191 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7194 case PRAGMA_GCC_PCH_PREPROCESS:
7195 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7196 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7200 if (id < PRAGMA_FIRST_EXTERNAL)
7202 if (context == pragma_external)
7205 c_parser_error (parser, "expected declaration specifiers");
7206 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7209 c_parser_omp_construct (parser);
7215 c_parser_consume_pragma (parser);
7216 c_invoke_pragma_handler (id);
7218 /* Skip to EOL, but suppress any error message. Those will have been
7219 generated by the handler routine through calling error, as opposed
7220 to calling c_parser_error. */
7221 parser->error = true;
7222 c_parser_skip_to_pragma_eol (parser);
7227 /* The interface the pragma parsers have to the lexer. */
7230 pragma_lex (tree *value)
7232 c_token *tok = c_parser_peek_token (the_parser);
7233 enum cpp_ttype ret = tok->type;
7235 *value = tok->value;
7236 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7240 if (ret == CPP_KEYWORD)
7242 c_parser_consume_token (the_parser);
7249 c_parser_pragma_pch_preprocess (c_parser *parser)
7253 c_parser_consume_pragma (parser);
7254 if (c_parser_next_token_is (parser, CPP_STRING))
7256 name = c_parser_peek_token (parser)->value;
7257 c_parser_consume_token (parser);
7260 c_parser_error (parser, "expected string literal");
7261 c_parser_skip_to_pragma_eol (parser);
7264 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7267 /* OpenMP 2.5 parsing routines. */
7269 /* Returns name of the next clause.
7270 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7271 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7272 returned and the token is consumed. */
7274 static pragma_omp_clause
7275 c_parser_omp_clause_name (c_parser *parser)
7277 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7279 if (c_parser_next_token_is_keyword (parser, RID_IF))
7280 result = PRAGMA_OMP_CLAUSE_IF;
7281 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7282 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7283 else if (c_parser_next_token_is (parser, CPP_NAME))
7285 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7290 if (!strcmp ("collapse", p))
7291 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7292 else if (!strcmp ("copyin", p))
7293 result = PRAGMA_OMP_CLAUSE_COPYIN;
7294 else if (!strcmp ("copyprivate", p))
7295 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7298 if (!strcmp ("firstprivate", p))
7299 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7302 if (!strcmp ("lastprivate", p))
7303 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7306 if (!strcmp ("nowait", p))
7307 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7308 else if (!strcmp ("num_threads", p))
7309 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7312 if (!strcmp ("ordered", p))
7313 result = PRAGMA_OMP_CLAUSE_ORDERED;
7316 if (!strcmp ("private", p))
7317 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7320 if (!strcmp ("reduction", p))
7321 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7324 if (!strcmp ("schedule", p))
7325 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7326 else if (!strcmp ("shared", p))
7327 result = PRAGMA_OMP_CLAUSE_SHARED;
7330 if (!strcmp ("untied", p))
7331 result = PRAGMA_OMP_CLAUSE_UNTIED;
7336 if (result != PRAGMA_OMP_CLAUSE_NONE)
7337 c_parser_consume_token (parser);
7342 /* Validate that a clause of the given type does not already exist. */
7345 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7350 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7351 if (OMP_CLAUSE_CODE (c) == code)
7353 location_t loc = OMP_CLAUSE_LOCATION (c);
7354 error_at (loc, "too many %qs clauses", name);
7362 variable-list , identifier
7364 If KIND is nonzero, create the appropriate node and install the
7365 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7366 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7368 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7369 return the list created. */
7372 c_parser_omp_variable_list (c_parser *parser,
7373 location_t clause_loc,
7374 enum omp_clause_code kind,
7377 if (c_parser_next_token_is_not (parser, CPP_NAME)
7378 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7379 c_parser_error (parser, "expected identifier");
7381 while (c_parser_next_token_is (parser, CPP_NAME)
7382 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7384 tree t = lookup_name (c_parser_peek_token (parser)->value);
7387 undeclared_variable (c_parser_peek_token (parser)->location,
7388 c_parser_peek_token (parser)->value);
7389 else if (t == error_mark_node)
7393 tree u = build_omp_clause (clause_loc, kind);
7394 OMP_CLAUSE_DECL (u) = t;
7395 OMP_CLAUSE_CHAIN (u) = list;
7399 list = tree_cons (t, NULL_TREE, list);
7401 c_parser_consume_token (parser);
7403 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7406 c_parser_consume_token (parser);
7412 /* Similarly, but expect leading and trailing parenthesis. This is a very
7413 common case for omp clauses. */
7416 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7419 /* The clauses location. */
7420 location_t loc = c_parser_peek_token (parser)->location;
7422 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7424 list = c_parser_omp_variable_list (parser, loc, kind, list);
7425 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7431 collapse ( constant-expression ) */
7434 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7436 tree c, num = error_mark_node;
7440 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7442 loc = c_parser_peek_token (parser)->location;
7443 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7445 num = c_parser_expr_no_commas (parser, NULL).value;
7446 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7448 if (num == error_mark_node)
7450 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7451 || !host_integerp (num, 0)
7452 || (n = tree_low_cst (num, 0)) <= 0
7456 "collapse argument needs positive constant integer expression");
7459 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7460 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7461 OMP_CLAUSE_CHAIN (c) = list;
7466 copyin ( variable-list ) */
7469 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7471 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7475 copyprivate ( variable-list ) */
7478 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7480 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7484 default ( shared | none ) */
7487 c_parser_omp_clause_default (c_parser *parser, tree list)
7489 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7490 location_t loc = c_parser_peek_token (parser)->location;
7493 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7495 if (c_parser_next_token_is (parser, CPP_NAME))
7497 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7502 if (strcmp ("none", p) != 0)
7504 kind = OMP_CLAUSE_DEFAULT_NONE;
7508 if (strcmp ("shared", p) != 0)
7510 kind = OMP_CLAUSE_DEFAULT_SHARED;
7517 c_parser_consume_token (parser);
7522 c_parser_error (parser, "expected %<none%> or %<shared%>");
7524 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7526 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7529 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7530 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7531 OMP_CLAUSE_CHAIN (c) = list;
7532 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7538 firstprivate ( variable-list ) */
7541 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7543 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7547 if ( expression ) */
7550 c_parser_omp_clause_if (c_parser *parser, tree list)
7552 location_t loc = c_parser_peek_token (parser)->location;
7553 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7555 tree t = c_parser_paren_condition (parser);
7558 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7560 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7561 OMP_CLAUSE_IF_EXPR (c) = t;
7562 OMP_CLAUSE_CHAIN (c) = list;
7566 c_parser_error (parser, "expected %<(%>");
7572 lastprivate ( variable-list ) */
7575 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7577 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7584 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7587 location_t loc = c_parser_peek_token (parser)->location;
7589 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7591 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7592 OMP_CLAUSE_CHAIN (c) = list;
7597 num_threads ( expression ) */
7600 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7602 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7603 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7605 location_t expr_loc = c_parser_peek_token (parser)->location;
7606 tree c, t = c_parser_expression (parser).value;
7607 t = c_fully_fold (t, false, NULL);
7609 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7611 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7613 c_parser_error (parser, "expected integer expression");
7617 /* Attempt to statically determine when the number isn't positive. */
7618 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7619 build_int_cst (TREE_TYPE (t), 0));
7620 if (CAN_HAVE_LOCATION_P (c))
7621 SET_EXPR_LOCATION (c, expr_loc);
7622 if (c == boolean_true_node)
7624 warning_at (expr_loc, 0,
7625 "%<num_threads%> value must be positive");
7626 t = integer_one_node;
7629 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7631 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7632 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7633 OMP_CLAUSE_CHAIN (c) = list;
7644 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7648 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7650 c = build_omp_clause (c_parser_peek_token (parser)->location,
7651 OMP_CLAUSE_ORDERED);
7652 OMP_CLAUSE_CHAIN (c) = list;
7658 private ( variable-list ) */
7661 c_parser_omp_clause_private (c_parser *parser, tree list)
7663 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7667 reduction ( reduction-operator : variable-list )
7670 One of: + * - & ^ | && || */
7673 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7675 location_t clause_loc = c_parser_peek_token (parser)->location;
7676 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7678 enum tree_code code;
7680 switch (c_parser_peek_token (parser)->type)
7692 code = BIT_AND_EXPR;
7695 code = BIT_XOR_EXPR;
7698 code = BIT_IOR_EXPR;
7701 code = TRUTH_ANDIF_EXPR;
7704 code = TRUTH_ORIF_EXPR;
7707 c_parser_error (parser,
7708 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7709 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7710 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7713 c_parser_consume_token (parser);
7714 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7718 nl = c_parser_omp_variable_list (parser, clause_loc,
7719 OMP_CLAUSE_REDUCTION, list);
7720 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7721 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7725 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7731 schedule ( schedule-kind )
7732 schedule ( schedule-kind , expression )
7735 static | dynamic | guided | runtime | auto
7739 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7742 location_t loc = c_parser_peek_token (parser)->location;
7744 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7747 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7749 if (c_parser_next_token_is (parser, CPP_NAME))
7751 tree kind = c_parser_peek_token (parser)->value;
7752 const char *p = IDENTIFIER_POINTER (kind);
7757 if (strcmp ("dynamic", p) != 0)
7759 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7763 if (strcmp ("guided", p) != 0)
7765 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7769 if (strcmp ("runtime", p) != 0)
7771 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7778 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7779 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7780 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7781 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7785 c_parser_consume_token (parser);
7786 if (c_parser_next_token_is (parser, CPP_COMMA))
7789 c_parser_consume_token (parser);
7791 here = c_parser_peek_token (parser)->location;
7792 t = c_parser_expr_no_commas (parser, NULL).value;
7793 t = c_fully_fold (t, false, NULL);
7795 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7796 error_at (here, "schedule %<runtime%> does not take "
7797 "a %<chunk_size%> parameter");
7798 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7800 "schedule %<auto%> does not take "
7801 "a %<chunk_size%> parameter");
7802 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7803 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7805 c_parser_error (parser, "expected integer expression");
7807 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7810 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7811 "expected %<,%> or %<)%>");
7813 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7814 OMP_CLAUSE_CHAIN (c) = list;
7818 c_parser_error (parser, "invalid schedule kind");
7819 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7824 shared ( variable-list ) */
7827 c_parser_omp_clause_shared (c_parser *parser, tree list)
7829 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7836 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7840 /* FIXME: Should we allow duplicates? */
7841 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7843 c = build_omp_clause (c_parser_peek_token (parser)->location,
7845 OMP_CLAUSE_CHAIN (c) = list;
7850 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7851 is a bitmask in MASK. Return the list of clauses found; the result
7852 of clause default goes in *pdefault. */
7855 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7858 tree clauses = NULL;
7861 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7864 pragma_omp_clause c_kind;
7866 tree prev = clauses;
7868 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7869 c_parser_consume_token (parser);
7872 here = c_parser_peek_token (parser)->location;
7873 c_kind = c_parser_omp_clause_name (parser);
7877 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7878 clauses = c_parser_omp_clause_collapse (parser, clauses);
7879 c_name = "collapse";
7881 case PRAGMA_OMP_CLAUSE_COPYIN:
7882 clauses = c_parser_omp_clause_copyin (parser, clauses);
7885 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7886 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7887 c_name = "copyprivate";
7889 case PRAGMA_OMP_CLAUSE_DEFAULT:
7890 clauses = c_parser_omp_clause_default (parser, clauses);
7893 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7894 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7895 c_name = "firstprivate";
7897 case PRAGMA_OMP_CLAUSE_IF:
7898 clauses = c_parser_omp_clause_if (parser, clauses);
7901 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7902 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7903 c_name = "lastprivate";
7905 case PRAGMA_OMP_CLAUSE_NOWAIT:
7906 clauses = c_parser_omp_clause_nowait (parser, clauses);
7909 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7910 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7911 c_name = "num_threads";
7913 case PRAGMA_OMP_CLAUSE_ORDERED:
7914 clauses = c_parser_omp_clause_ordered (parser, clauses);
7917 case PRAGMA_OMP_CLAUSE_PRIVATE:
7918 clauses = c_parser_omp_clause_private (parser, clauses);
7921 case PRAGMA_OMP_CLAUSE_REDUCTION:
7922 clauses = c_parser_omp_clause_reduction (parser, clauses);
7923 c_name = "reduction";
7925 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7926 clauses = c_parser_omp_clause_schedule (parser, clauses);
7927 c_name = "schedule";
7929 case PRAGMA_OMP_CLAUSE_SHARED:
7930 clauses = c_parser_omp_clause_shared (parser, clauses);
7933 case PRAGMA_OMP_CLAUSE_UNTIED:
7934 clauses = c_parser_omp_clause_untied (parser, clauses);
7938 c_parser_error (parser, "expected %<#pragma omp%> clause");
7942 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7944 /* Remove the invalid clause(s) from the list to avoid
7945 confusing the rest of the compiler. */
7947 error_at (here, "%qs is not valid for %qs", c_name, where);
7952 c_parser_skip_to_pragma_eol (parser);
7954 return c_finish_omp_clauses (clauses);
7961 In practice, we're also interested in adding the statement to an
7962 outer node. So it is convenient if we work around the fact that
7963 c_parser_statement calls add_stmt. */
7966 c_parser_omp_structured_block (c_parser *parser)
7968 tree stmt = push_stmt_list ();
7969 c_parser_statement (parser);
7970 return pop_stmt_list (stmt);
7974 # pragma omp atomic new-line
7978 x binop= expr | x++ | ++x | x-- | --x
7980 +, *, -, /, &, ^, |, <<, >>
7982 where x is an lvalue expression with scalar type.
7984 LOC is the location of the #pragma token. */
7987 c_parser_omp_atomic (location_t loc, c_parser *parser)
7991 enum tree_code code;
7992 struct c_expr rhs_expr;
7994 c_parser_skip_to_pragma_eol (parser);
7996 lhs = c_parser_unary_expression (parser).value;
7997 lhs = c_fully_fold (lhs, false, NULL);
7998 switch (TREE_CODE (lhs))
8002 c_parser_skip_to_end_of_block_or_statement (parser);
8005 case PREINCREMENT_EXPR:
8006 case POSTINCREMENT_EXPR:
8007 lhs = TREE_OPERAND (lhs, 0);
8009 rhs = integer_one_node;
8012 case PREDECREMENT_EXPR:
8013 case POSTDECREMENT_EXPR:
8014 lhs = TREE_OPERAND (lhs, 0);
8016 rhs = integer_one_node;
8020 switch (c_parser_peek_token (parser)->type)
8026 code = TRUNC_DIV_EXPR;
8041 code = BIT_AND_EXPR;
8044 code = BIT_IOR_EXPR;
8047 code = BIT_XOR_EXPR;
8050 c_parser_error (parser,
8051 "invalid operator for %<#pragma omp atomic%>");
8055 c_parser_consume_token (parser);
8057 location_t rhs_loc = c_parser_peek_token (parser)->location;
8058 rhs_expr = c_parser_expression (parser);
8059 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8061 rhs = rhs_expr.value;
8062 rhs = c_fully_fold (rhs, false, NULL);
8065 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8066 if (stmt != error_mark_node)
8068 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8073 # pragma omp barrier new-line
8077 c_parser_omp_barrier (c_parser *parser)
8079 location_t loc = c_parser_peek_token (parser)->location;
8080 c_parser_consume_pragma (parser);
8081 c_parser_skip_to_pragma_eol (parser);
8083 c_finish_omp_barrier (loc);
8087 # pragma omp critical [(name)] new-line
8090 LOC is the location of the #pragma itself. */
8093 c_parser_omp_critical (location_t loc, c_parser *parser)
8095 tree stmt, name = NULL;
8097 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8099 c_parser_consume_token (parser);
8100 if (c_parser_next_token_is (parser, CPP_NAME))
8102 name = c_parser_peek_token (parser)->value;
8103 c_parser_consume_token (parser);
8104 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8107 c_parser_error (parser, "expected identifier");
8109 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8110 c_parser_error (parser, "expected %<(%> or end of line");
8111 c_parser_skip_to_pragma_eol (parser);
8113 stmt = c_parser_omp_structured_block (parser);
8114 return c_finish_omp_critical (loc, stmt, name);
8118 # pragma omp flush flush-vars[opt] new-line
8121 ( variable-list ) */
8124 c_parser_omp_flush (c_parser *parser)
8126 location_t loc = c_parser_peek_token (parser)->location;
8127 c_parser_consume_pragma (parser);
8128 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8129 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8130 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8131 c_parser_error (parser, "expected %<(%> or end of line");
8132 c_parser_skip_to_pragma_eol (parser);
8134 c_finish_omp_flush (loc);
8137 /* Parse the restricted form of the for statement allowed by OpenMP.
8138 The real trick here is to determine the loop control variable early
8139 so that we can push a new decl if necessary to make it private.
8140 LOC is the location of the OMP in "#pragma omp". */
8143 c_parser_omp_for_loop (location_t loc,
8144 c_parser *parser, tree clauses, tree *par_clauses)
8146 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8147 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
8148 bool fail = false, open_brace_parsed = false;
8149 int i, collapse = 1, nbraces = 0;
8152 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8153 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8154 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8156 gcc_assert (collapse >= 1);
8158 declv = make_tree_vec (collapse);
8159 initv = make_tree_vec (collapse);
8160 condv = make_tree_vec (collapse);
8161 incrv = make_tree_vec (collapse);
8163 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8165 c_parser_error (parser, "for statement expected");
8168 for_loc = c_parser_peek_token (parser)->location;
8169 c_parser_consume_token (parser);
8171 for (i = 0; i < collapse; i++)
8175 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8178 /* Parse the initialization declaration or expression. */
8179 if (c_parser_next_token_starts_declaration (parser))
8183 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
8184 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
8185 decl = check_for_loop_decls (for_loc);
8188 if (DECL_INITIAL (decl) == error_mark_node)
8189 decl = error_mark_node;
8192 else if (c_parser_next_token_is (parser, CPP_NAME)
8193 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8195 struct c_expr decl_exp;
8196 struct c_expr init_exp;
8197 location_t init_loc;
8199 decl_exp = c_parser_postfix_expression (parser);
8200 decl = decl_exp.value;
8202 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8204 init_loc = c_parser_peek_token (parser)->location;
8205 init_exp = c_parser_expr_no_commas (parser, NULL);
8206 init_exp = default_function_array_read_conversion (init_loc,
8208 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8209 NOP_EXPR, init_loc, init_exp.value,
8210 init_exp.original_type);
8211 init = c_process_expr_stmt (init_loc, init);
8213 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8218 c_parser_error (parser,
8219 "expected iteration declaration or initialization");
8220 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8226 /* Parse the loop condition. */
8228 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8230 location_t cond_loc = c_parser_peek_token (parser)->location;
8231 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8233 cond = cond_expr.value;
8234 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8235 cond = c_fully_fold (cond, false, NULL);
8236 switch (cond_expr.original_code)
8244 /* Can't be cond = error_mark_node, because we want to preserve
8245 the location until c_finish_omp_for. */
8246 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8249 protected_set_expr_location (cond, cond_loc);
8251 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8253 /* Parse the increment expression. */
8255 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8257 location_t incr_loc = c_parser_peek_token (parser)->location;
8259 incr = c_process_expr_stmt (incr_loc,
8260 c_parser_expression (parser).value);
8262 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8264 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8268 TREE_VEC_ELT (declv, i) = decl;
8269 TREE_VEC_ELT (initv, i) = init;
8270 TREE_VEC_ELT (condv, i) = cond;
8271 TREE_VEC_ELT (incrv, i) = incr;
8275 if (i == collapse - 1)
8278 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8279 in between the collapsed for loops to be still considered perfectly
8280 nested. Hopefully the final version clarifies this.
8281 For now handle (multiple) {'s and empty statements. */
8284 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8286 c_parser_consume_token (parser);
8289 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8291 c_parser_consume_token (parser);
8295 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8296 c_parser_consume_token (parser);
8299 c_parser_error (parser, "not enough perfectly nested loops");
8302 open_brace_parsed = true;
8312 nbraces += bracecount;
8315 save_break = c_break_label;
8316 c_break_label = size_one_node;
8317 save_cont = c_cont_label;
8318 c_cont_label = NULL_TREE;
8319 body = push_stmt_list ();
8321 if (open_brace_parsed)
8323 location_t here = c_parser_peek_token (parser)->location;
8324 stmt = c_begin_compound_stmt (true);
8325 c_parser_compound_statement_nostart (parser);
8326 add_stmt (c_end_compound_stmt (here, stmt, true));
8329 add_stmt (c_parser_c99_block_statement (parser));
8332 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8333 SET_EXPR_LOCATION (t, loc);
8337 body = pop_stmt_list (body);
8338 c_break_label = save_break;
8339 c_cont_label = save_cont;
8343 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8345 c_parser_consume_token (parser);
8348 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8349 c_parser_consume_token (parser);
8352 c_parser_error (parser, "collapsed loops not perfectly nested");
8355 location_t here = c_parser_peek_token (parser)->location;
8356 stmt = c_begin_compound_stmt (true);
8358 c_parser_compound_statement_nostart (parser);
8359 body = c_end_compound_stmt (here, stmt, true);
8366 /* Only bother calling c_finish_omp_for if we haven't already generated
8367 an error from the initialization parsing. */
8370 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8373 if (par_clauses != NULL)
8376 for (c = par_clauses; *c ; )
8377 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8378 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8379 c = &OMP_CLAUSE_CHAIN (*c);
8382 for (i = 0; i < collapse; i++)
8383 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8386 c = &OMP_CLAUSE_CHAIN (*c);
8387 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8390 "iteration variable %qD should not be firstprivate",
8391 OMP_CLAUSE_DECL (*c));
8392 *c = OMP_CLAUSE_CHAIN (*c);
8396 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8397 change it to shared (decl) in
8398 OMP_PARALLEL_CLAUSES. */
8399 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8400 OMP_CLAUSE_LASTPRIVATE);
8401 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8402 OMP_CLAUSE_CHAIN (l) = clauses;
8404 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8408 OMP_FOR_CLAUSES (stmt) = clauses;
8415 /* FIXME diagnostics: LOC below should be the actual location of
8416 this particular for block. We need to build a list of
8417 locations to go along with FOR_BLOCK. */
8418 stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
8420 for_block = TREE_CHAIN (for_block);
8426 #pragma omp for for-clause[optseq] new-line
8429 LOC is the location of the #pragma token.
8432 #define OMP_FOR_CLAUSE_MASK \
8433 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8434 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8435 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8436 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8437 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8438 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8439 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8440 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8443 c_parser_omp_for (location_t loc, c_parser *parser)
8445 tree block, clauses, ret;
8447 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8450 block = c_begin_compound_stmt (true);
8451 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8452 block = c_end_compound_stmt (loc, block, true);
8459 # pragma omp master new-line
8462 LOC is the location of the #pragma token.
8466 c_parser_omp_master (location_t loc, c_parser *parser)
8468 c_parser_skip_to_pragma_eol (parser);
8469 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8473 # pragma omp ordered new-line
8476 LOC is the location of the #pragma itself.
8480 c_parser_omp_ordered (location_t loc, c_parser *parser)
8482 c_parser_skip_to_pragma_eol (parser);
8483 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8489 { section-sequence }
8492 section-directive[opt] structured-block
8493 section-sequence section-directive structured-block
8495 SECTIONS_LOC is the location of the #pragma omp sections. */
8498 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8501 bool error_suppress = false;
8504 loc = c_parser_peek_token (parser)->location;
8505 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8507 /* Avoid skipping until the end of the block. */
8508 parser->error = false;
8512 stmt = push_stmt_list ();
8514 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8516 substmt = push_stmt_list ();
8520 c_parser_statement (parser);
8522 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8524 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8526 if (c_parser_next_token_is (parser, CPP_EOF))
8530 substmt = pop_stmt_list (substmt);
8531 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8532 SET_EXPR_LOCATION (substmt, loc);
8538 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8540 if (c_parser_next_token_is (parser, CPP_EOF))
8543 loc = c_parser_peek_token (parser)->location;
8544 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8546 c_parser_consume_pragma (parser);
8547 c_parser_skip_to_pragma_eol (parser);
8548 error_suppress = false;
8550 else if (!error_suppress)
8552 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8553 error_suppress = true;
8556 substmt = c_parser_omp_structured_block (parser);
8557 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8558 SET_EXPR_LOCATION (substmt, loc);
8561 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8562 "expected %<#pragma omp section%> or %<}%>");
8564 substmt = pop_stmt_list (stmt);
8566 stmt = make_node (OMP_SECTIONS);
8567 SET_EXPR_LOCATION (stmt, sections_loc);
8568 TREE_TYPE (stmt) = void_type_node;
8569 OMP_SECTIONS_BODY (stmt) = substmt;
8571 return add_stmt (stmt);
8575 # pragma omp sections sections-clause[optseq] newline
8578 LOC is the location of the #pragma token.
8581 #define OMP_SECTIONS_CLAUSE_MASK \
8582 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8583 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8584 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8585 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8586 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8589 c_parser_omp_sections (location_t loc, c_parser *parser)
8591 tree block, clauses, ret;
8593 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8594 "#pragma omp sections");
8596 block = c_begin_compound_stmt (true);
8597 ret = c_parser_omp_sections_scope (loc, parser);
8599 OMP_SECTIONS_CLAUSES (ret) = clauses;
8600 block = c_end_compound_stmt (loc, block, true);
8607 # pragma parallel parallel-clause new-line
8608 # pragma parallel for parallel-for-clause new-line
8609 # pragma parallel sections parallel-sections-clause new-line
8611 LOC is the location of the #pragma token.
8614 #define OMP_PARALLEL_CLAUSE_MASK \
8615 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8616 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8617 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8618 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8619 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8620 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8621 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8622 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8625 c_parser_omp_parallel (location_t loc, c_parser *parser)
8627 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8628 const char *p_name = "#pragma omp parallel";
8629 tree stmt, clauses, par_clause, ws_clause, block;
8630 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8632 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8634 c_parser_consume_token (parser);
8635 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8636 p_name = "#pragma omp parallel for";
8637 mask |= OMP_FOR_CLAUSE_MASK;
8638 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8640 else if (c_parser_next_token_is (parser, CPP_NAME))
8642 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8643 if (strcmp (p, "sections") == 0)
8645 c_parser_consume_token (parser);
8646 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8647 p_name = "#pragma omp parallel sections";
8648 mask |= OMP_SECTIONS_CLAUSE_MASK;
8649 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8653 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8657 case PRAGMA_OMP_PARALLEL:
8658 block = c_begin_omp_parallel ();
8659 c_parser_statement (parser);
8660 stmt = c_finish_omp_parallel (loc, clauses, block);
8663 case PRAGMA_OMP_PARALLEL_FOR:
8664 block = c_begin_omp_parallel ();
8665 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8666 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8667 stmt = c_finish_omp_parallel (loc, par_clause, block);
8668 OMP_PARALLEL_COMBINED (stmt) = 1;
8671 case PRAGMA_OMP_PARALLEL_SECTIONS:
8672 block = c_begin_omp_parallel ();
8673 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8674 stmt = c_parser_omp_sections_scope (loc, parser);
8676 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8677 stmt = c_finish_omp_parallel (loc, par_clause, block);
8678 OMP_PARALLEL_COMBINED (stmt) = 1;
8689 # pragma omp single single-clause[optseq] new-line
8692 LOC is the location of the #pragma.
8695 #define OMP_SINGLE_CLAUSE_MASK \
8696 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8697 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8698 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8699 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8702 c_parser_omp_single (location_t loc, c_parser *parser)
8704 tree stmt = make_node (OMP_SINGLE);
8705 SET_EXPR_LOCATION (stmt, loc);
8706 TREE_TYPE (stmt) = void_type_node;
8708 OMP_SINGLE_CLAUSES (stmt)
8709 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8710 "#pragma omp single");
8711 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8713 return add_stmt (stmt);
8717 # pragma omp task task-clause[optseq] new-line
8719 LOC is the location of the #pragma.
8722 #define OMP_TASK_CLAUSE_MASK \
8723 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8724 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8725 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8726 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8727 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8728 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8731 c_parser_omp_task (location_t loc, c_parser *parser)
8733 tree clauses, block;
8735 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8736 "#pragma omp task");
8738 block = c_begin_omp_task ();
8739 c_parser_statement (parser);
8740 return c_finish_omp_task (loc, clauses, block);
8744 # pragma omp taskwait new-line
8748 c_parser_omp_taskwait (c_parser *parser)
8750 location_t loc = c_parser_peek_token (parser)->location;
8751 c_parser_consume_pragma (parser);
8752 c_parser_skip_to_pragma_eol (parser);
8754 c_finish_omp_taskwait (loc);
8757 /* Main entry point to parsing most OpenMP pragmas. */
8760 c_parser_omp_construct (c_parser *parser)
8762 enum pragma_kind p_kind;
8766 loc = c_parser_peek_token (parser)->location;
8767 p_kind = c_parser_peek_token (parser)->pragma_kind;
8768 c_parser_consume_pragma (parser);
8772 case PRAGMA_OMP_ATOMIC:
8773 c_parser_omp_atomic (loc, parser);
8775 case PRAGMA_OMP_CRITICAL:
8776 stmt = c_parser_omp_critical (loc, parser);
8778 case PRAGMA_OMP_FOR:
8779 stmt = c_parser_omp_for (loc, parser);
8781 case PRAGMA_OMP_MASTER:
8782 stmt = c_parser_omp_master (loc, parser);
8784 case PRAGMA_OMP_ORDERED:
8785 stmt = c_parser_omp_ordered (loc, parser);
8787 case PRAGMA_OMP_PARALLEL:
8788 stmt = c_parser_omp_parallel (loc, parser);
8790 case PRAGMA_OMP_SECTIONS:
8791 stmt = c_parser_omp_sections (loc, parser);
8793 case PRAGMA_OMP_SINGLE:
8794 stmt = c_parser_omp_single (loc, parser);
8796 case PRAGMA_OMP_TASK:
8797 stmt = c_parser_omp_task (loc, parser);
8804 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
8809 # pragma omp threadprivate (variable-list) */
8812 c_parser_omp_threadprivate (c_parser *parser)
8817 c_parser_consume_pragma (parser);
8818 loc = c_parser_peek_token (parser)->location;
8819 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8821 /* Mark every variable in VARS to be assigned thread local storage. */
8822 for (t = vars; t; t = TREE_CHAIN (t))
8824 tree v = TREE_PURPOSE (t);
8826 /* FIXME diagnostics: Ideally we should keep individual
8827 locations for all the variables in the var list to make the
8828 following errors more precise. Perhaps
8829 c_parser_omp_var_list_parens() should construct a list of
8830 locations to go along with the var list. */
8832 /* If V had already been marked threadprivate, it doesn't matter
8833 whether it had been used prior to this point. */
8834 if (TREE_CODE (v) != VAR_DECL)
8835 error_at (loc, "%qD is not a variable", v);
8836 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8837 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
8838 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8839 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
8840 else if (TREE_TYPE (v) == error_mark_node)
8842 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8843 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
8846 if (! DECL_THREAD_LOCAL_P (v))
8848 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8849 /* If rtl has been already set for this var, call
8850 make_decl_rtl once again, so that encode_section_info
8851 has a chance to look at the new decl flags. */
8852 if (DECL_RTL_SET_P (v))
8855 C_DECL_THREADPRIVATE_P (v) = 1;
8859 c_parser_skip_to_pragma_eol (parser);
8863 /* Parse a single source file. */
8868 /* Use local storage to begin. If the first token is a pragma, parse it.
8869 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8870 which will cause garbage collection. */
8873 memset (&tparser, 0, sizeof tparser);
8874 the_parser = &tparser;
8876 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8877 c_parser_pragma_pch_preprocess (&tparser);
8879 the_parser = GGC_NEW (c_parser);
8880 *the_parser = tparser;
8882 /* Initialize EH, if we've been told to do so. */
8883 if (flag_exceptions)
8884 using_eh_for_cleanups ();
8886 c_parser_translation_unit (the_parser);
8890 #include "gt-c-parser.h"