1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
55 #include "c-family/c-common.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX <= 255);
82 mask |= D_ASM | D_EXT;
86 if (!c_dialect_objc ())
87 mask |= D_OBJC | D_CXX_OBJC;
89 ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
90 for (i = 0; i < num_c_common_reswords; i++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords[i].disable & mask)
97 && (c_common_reswords[i].disable & D_CXXWARN))
99 id = get_identifier (c_common_reswords[i].word);
100 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
101 C_IS_RESERVED_WORD (id) = 1;
106 id = get_identifier (c_common_reswords[i].word);
107 C_SET_RID_CODE (id, c_common_reswords[i].rid);
108 C_IS_RESERVED_WORD (id) = 1;
109 ridpointers [(int) c_common_reswords[i].rid] = id;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind {
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token {
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype) type : 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind) id_kind : 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid) keyword : 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser {
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error : 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma : 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block : 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string : 1;
182 /* Objective-C specific parser/lexer information. */
183 BOOL_BITFIELD objc_pq_context : 1;
184 /* The following flag is needed to contextualize Objective-C lexical
185 analysis. In some cases (e.g., 'int NSObject;'), it is
186 undesirable to bind an identifier to an Objective-C class, even
187 if a class with that name exists. */
188 BOOL_BITFIELD objc_need_raw_identifier : 1;
192 /* The actual parser and external interface. ??? Does this need to be
193 garbage-collected? */
195 static GTY (()) c_parser *the_parser;
197 /* Read in and lex a single token, storing it in *TOKEN. */
200 c_lex_one_token (c_parser *parser, c_token *token)
202 timevar_push (TV_LEX);
204 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
205 (parser->lex_untranslated_string
206 ? C_LEX_STRING_NO_TRANSLATE : 0));
207 token->id_kind = C_ID_NONE;
208 token->keyword = RID_MAX;
209 token->pragma_kind = PRAGMA_NONE;
217 bool objc_force_identifier = parser->objc_need_raw_identifier;
218 if (c_dialect_objc ())
219 parser->objc_need_raw_identifier = false;
221 if (C_IS_RESERVED_WORD (token->value))
223 enum rid rid_code = C_RID_CODE (token->value);
225 if (rid_code == RID_CXX_COMPAT_WARN)
227 warning_at (token->location,
229 "identifier %qE conflicts with C++ keyword",
232 else if (rid_code >= RID_FIRST_ADDR_SPACE
233 && rid_code <= RID_LAST_ADDR_SPACE)
235 token->id_kind = C_ID_ADDRSPACE;
236 token->keyword = rid_code;
239 else if (c_dialect_objc ())
241 if (!objc_is_reserved_word (token->value)
242 && (!OBJC_IS_PQ_KEYWORD (rid_code)
243 || parser->objc_pq_context))
245 /* Return the canonical spelling for this keyword. */
246 token->value = ridpointers[(int) rid_code];
247 token->type = CPP_KEYWORD;
248 token->keyword = rid_code;
254 token->type = CPP_KEYWORD;
255 token->keyword = rid_code;
260 decl = lookup_name (token->value);
263 if (TREE_CODE (decl) == TYPE_DECL)
265 token->id_kind = C_ID_TYPENAME;
269 else if (c_dialect_objc ())
271 tree objc_interface_decl = objc_is_class_name (token->value);
272 /* Objective-C class names are in the same namespace as
273 variables and typedefs, and hence are shadowed by local
275 if (objc_interface_decl
276 && (global_bindings_p ()
277 || (!objc_force_identifier && !decl)))
279 token->value = objc_interface_decl;
280 token->id_kind = C_ID_CLASSNAME;
284 token->id_kind = C_ID_ID;
288 /* This only happens in Objective-C; it must be a keyword. */
289 token->type = CPP_KEYWORD;
290 token->keyword = C_RID_CODE (token->value);
294 case CPP_CLOSE_PAREN:
296 /* These tokens may affect the interpretation of any identifiers
297 following, if doing Objective-C. */
298 if (c_dialect_objc ())
299 parser->objc_need_raw_identifier = false;
302 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
303 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
309 timevar_pop (TV_LEX);
312 /* Return a pointer to the next token from PARSER, reading it in if
315 static inline c_token *
316 c_parser_peek_token (c_parser *parser)
318 if (parser->tokens_avail == 0)
320 c_lex_one_token (parser, &parser->tokens[0]);
321 parser->tokens_avail = 1;
323 return &parser->tokens[0];
326 /* Return true if the next token from PARSER has the indicated
330 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
332 return c_parser_peek_token (parser)->type == type;
335 /* Return true if the next token from PARSER does not have the
339 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
341 return !c_parser_next_token_is (parser, type);
344 /* Return true if the next token from PARSER is the indicated
348 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
350 return c_parser_peek_token (parser)->keyword == keyword;
353 /* Return true if TOKEN can start a type name,
356 c_token_starts_typename (c_token *token)
361 switch (token->id_kind)
370 gcc_assert (c_dialect_objc ());
376 switch (token->keyword)
409 if (c_dialect_objc ())
417 /* Return true if the next token from PARSER can start a type name,
420 c_parser_next_token_starts_typename (c_parser *parser)
422 c_token *token = c_parser_peek_token (parser);
423 return c_token_starts_typename (token);
426 /* Return true if TOKEN can start declaration specifiers, false
429 c_token_starts_declspecs (c_token *token)
434 switch (token->id_kind)
443 gcc_assert (c_dialect_objc ());
449 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 *, tree);
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 *, tree);
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 *);
999 static bool c_parser_objc_diagnose_bad_element_prefix
1000 (c_parser *, struct c_declspecs *);
1002 /* Parse a translation unit (C90 6.7, C99 6.9).
1005 external-declarations
1007 external-declarations:
1008 external-declaration
1009 external-declarations external-declaration
1018 c_parser_translation_unit (c_parser *parser)
1020 if (c_parser_next_token_is (parser, CPP_EOF))
1022 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1023 "ISO C forbids an empty translation unit");
1027 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1028 mark_valid_location_for_stdc_pragma (false);
1032 c_parser_external_declaration (parser);
1033 obstack_free (&parser_obstack, obstack_position);
1035 while (c_parser_next_token_is_not (parser, CPP_EOF));
1039 /* Parse an external declaration (C90 6.7, C99 6.9).
1041 external-declaration:
1047 external-declaration:
1050 __extension__ external-declaration
1054 external-declaration:
1055 objc-class-definition
1056 objc-class-declaration
1057 objc-alias-declaration
1058 objc-protocol-definition
1059 objc-method-definition
1064 c_parser_external_declaration (c_parser *parser)
1067 switch (c_parser_peek_token (parser)->type)
1070 switch (c_parser_peek_token (parser)->keyword)
1073 ext = disable_extension_diagnostics ();
1074 c_parser_consume_token (parser);
1075 c_parser_external_declaration (parser);
1076 restore_extension_diagnostics (ext);
1079 c_parser_asm_definition (parser);
1081 case RID_AT_INTERFACE:
1082 case RID_AT_IMPLEMENTATION:
1083 gcc_assert (c_dialect_objc ());
1084 c_parser_objc_class_definition (parser, NULL_TREE);
1087 gcc_assert (c_dialect_objc ());
1088 c_parser_objc_class_declaration (parser);
1091 gcc_assert (c_dialect_objc ());
1092 c_parser_objc_alias_declaration (parser);
1094 case RID_AT_PROTOCOL:
1095 gcc_assert (c_dialect_objc ());
1096 c_parser_objc_protocol_definition (parser, NULL_TREE);
1099 gcc_assert (c_dialect_objc ());
1100 c_parser_consume_token (parser);
1101 objc_finish_implementation ();
1108 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1109 "ISO C does not allow extra %<;%> outside of a function");
1110 c_parser_consume_token (parser);
1113 mark_valid_location_for_stdc_pragma (true);
1114 c_parser_pragma (parser, pragma_external);
1115 mark_valid_location_for_stdc_pragma (false);
1119 if (c_dialect_objc ())
1121 c_parser_objc_method_definition (parser);
1124 /* Else fall through, and yield a syntax error trying to parse
1125 as a declaration or function definition. */
1128 /* A declaration or a function definition (or, in Objective-C,
1129 an @interface or @protocol with prefix attributes). We can
1130 only tell which after parsing the declaration specifiers, if
1131 any, and the first declarator. */
1132 c_parser_declaration_or_fndef (parser, true, true, true, false, true);
1137 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1138 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1139 accepted; otherwise (old-style parameter declarations) only other
1140 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1141 assertion is accepted; otherwise (old-style parameter declarations)
1142 it is not. If NESTED is true, we are inside a function or parsing
1143 old-style parameter declarations; any functions encountered are
1144 nested functions and declaration specifiers are required; otherwise
1145 we are at top level and functions are normal functions and
1146 declaration specifiers may be optional. If EMPTY_OK is true, empty
1147 declarations are OK (subject to all other constraints); otherwise
1148 (old-style parameter declarations) they are diagnosed. If
1149 START_ATTR_OK is true, the declaration specifiers may start with
1150 attributes; otherwise they may not.
1153 declaration-specifiers init-declarator-list[opt] ;
1154 static_assert-declaration
1156 function-definition:
1157 declaration-specifiers[opt] declarator declaration-list[opt]
1162 declaration-list declaration
1164 init-declarator-list:
1166 init-declarator-list , init-declarator
1169 declarator simple-asm-expr[opt] attributes[opt]
1170 declarator simple-asm-expr[opt] attributes[opt] = initializer
1174 nested-function-definition:
1175 declaration-specifiers declarator declaration-list[opt]
1179 attributes objc-class-definition
1180 attributes objc-category-definition
1181 attributes objc-protocol-definition
1183 The simple-asm-expr and attributes are GNU extensions.
1185 This function does not handle __extension__; that is handled in its
1186 callers. ??? Following the old parser, __extension__ may start
1187 external declarations, declarations in functions and declarations
1188 at the start of "for" loops, but not old-style parameter
1191 C99 requires declaration specifiers in a function definition; the
1192 absence is diagnosed through the diagnosis of implicit int. In GNU
1193 C we also allow but diagnose declarations without declaration
1194 specifiers, but only at top level (elsewhere they conflict with
1200 threadprivate-directive */
1203 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
1204 bool static_assert_ok, bool empty_ok,
1205 bool nested, bool start_attr_ok)
1207 struct c_declspecs *specs;
1209 tree all_prefix_attrs;
1210 bool diagnosed_no_specs = false;
1211 location_t here = c_parser_peek_token (parser)->location;
1213 if (static_assert_ok
1214 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
1216 c_parser_static_assert_declaration (parser);
1219 specs = build_null_declspecs ();
1220 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1223 c_parser_skip_to_end_of_block_or_statement (parser);
1226 if (nested && !specs->declspecs_seen_p)
1228 c_parser_error (parser, "expected declaration specifiers");
1229 c_parser_skip_to_end_of_block_or_statement (parser);
1232 finish_declspecs (specs);
1233 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1239 shadow_tag_warned (specs, 1);
1240 pedwarn (here, 0, "empty declaration");
1242 c_parser_consume_token (parser);
1245 else if (c_dialect_objc ())
1247 /* This is where we parse 'attributes @interface ...',
1248 'attributes @implementation ...', 'attributes @protocol ...'
1249 (where attributes could be, for example, __attribute__
1252 switch (c_parser_peek_token (parser)->keyword)
1254 case RID_AT_INTERFACE:
1256 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1258 c_parser_objc_class_definition (parser, specs->attrs);
1262 case RID_AT_IMPLEMENTATION:
1264 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1268 warning_at (c_parser_peek_token (parser)->location,
1270 "prefix attributes are ignored for implementations");
1271 specs->attrs = NULL_TREE;
1273 c_parser_objc_class_definition (parser, NULL_TREE);
1277 case RID_AT_PROTOCOL:
1279 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs))
1281 c_parser_objc_protocol_definition (parser, specs->attrs);
1290 pending_xref_error ();
1291 prefix_attrs = specs->attrs;
1292 all_prefix_attrs = prefix_attrs;
1293 specs->attrs = NULL_TREE;
1296 struct c_declarator *declarator;
1299 /* Declaring either one or more declarators (in which case we
1300 should diagnose if there were no declaration specifiers) or a
1301 function definition (in which case the diagnostic for
1302 implicit int suffices). */
1303 declarator = c_parser_declarator (parser, specs->type_seen_p,
1304 C_DTR_NORMAL, &dummy);
1305 if (declarator == NULL)
1307 c_parser_skip_to_end_of_block_or_statement (parser);
1310 if (c_parser_next_token_is (parser, CPP_EQ)
1311 || c_parser_next_token_is (parser, CPP_COMMA)
1312 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1313 || c_parser_next_token_is_keyword (parser, RID_ASM)
1314 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1316 tree asm_name = NULL_TREE;
1317 tree postfix_attrs = NULL_TREE;
1318 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1320 diagnosed_no_specs = true;
1321 pedwarn (here, 0, "data definition has no type or storage class");
1323 /* Having seen a data definition, there cannot now be a
1324 function definition. */
1326 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1327 asm_name = c_parser_simple_asm_expr (parser);
1328 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1329 postfix_attrs = c_parser_attributes (parser);
1330 if (c_parser_next_token_is (parser, CPP_EQ))
1334 location_t init_loc;
1335 c_parser_consume_token (parser);
1336 /* The declaration of the variable is in effect while
1337 its initializer is parsed. */
1338 d = start_decl (declarator, specs, true,
1339 chainon (postfix_attrs, all_prefix_attrs));
1341 d = error_mark_node;
1342 start_init (d, asm_name, global_bindings_p ());
1343 init_loc = c_parser_peek_token (parser)->location;
1344 init = c_parser_initializer (parser);
1346 if (d != error_mark_node)
1348 maybe_warn_string_init (TREE_TYPE (d), init);
1349 finish_decl (d, init_loc, init.value,
1350 init.original_type, asm_name);
1355 tree d = start_decl (declarator, specs, false,
1356 chainon (postfix_attrs,
1359 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1360 NULL_TREE, asm_name);
1362 if (c_parser_next_token_is (parser, CPP_COMMA))
1364 c_parser_consume_token (parser);
1365 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1366 all_prefix_attrs = chainon (c_parser_attributes (parser),
1369 all_prefix_attrs = prefix_attrs;
1372 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1374 c_parser_consume_token (parser);
1379 c_parser_error (parser, "expected %<,%> or %<;%>");
1380 c_parser_skip_to_end_of_block_or_statement (parser);
1386 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1387 "%<asm%> or %<__attribute__%>");
1388 c_parser_skip_to_end_of_block_or_statement (parser);
1391 /* Function definition (nested or otherwise). */
1394 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1395 c_push_function_context ();
1397 if (!start_function (specs, declarator, all_prefix_attrs))
1399 /* This can appear in many cases looking nothing like a
1400 function definition, so we don't give a more specific
1401 error suggesting there was one. */
1402 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1403 "or %<__attribute__%>");
1405 c_pop_function_context ();
1408 /* Parse old-style parameter declarations. ??? Attributes are
1409 not allowed to start declaration specifiers here because of a
1410 syntax conflict between a function declaration with attribute
1411 suffix and a function definition with an attribute prefix on
1412 first old-style parameter declaration. Following the old
1413 parser, they are not accepted on subsequent old-style
1414 parameter declarations either. However, there is no
1415 ambiguity after the first declaration, nor indeed on the
1416 first as long as we don't allow postfix attributes after a
1417 declarator with a nonempty identifier list in a definition;
1418 and postfix attributes have never been accepted here in
1419 function definitions either. */
1420 while (c_parser_next_token_is_not (parser, CPP_EOF)
1421 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1422 c_parser_declaration_or_fndef (parser, false, false, false,
1424 store_parm_decls ();
1425 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1426 = c_parser_peek_token (parser)->location;
1427 fnbody = c_parser_compound_statement (parser);
1430 tree decl = current_function_decl;
1431 /* Mark nested functions as needing static-chain initially.
1432 lower_nested_functions will recompute it but the
1433 DECL_STATIC_CHAIN flag is also used before that happens,
1434 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1435 DECL_STATIC_CHAIN (decl) = 1;
1438 c_pop_function_context ();
1439 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1450 /* Parse an asm-definition (asm() outside a function body). This is a
1458 c_parser_asm_definition (c_parser *parser)
1460 tree asm_str = c_parser_simple_asm_expr (parser);
1462 cgraph_add_asm_node (asm_str);
1463 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1466 /* Parse a static assertion (C1X N1425 6.7.10).
1468 static_assert-declaration:
1469 static_assert-declaration-no-semi ;
1473 c_parser_static_assert_declaration (c_parser *parser)
1475 c_parser_static_assert_declaration_no_semi (parser);
1477 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
1478 c_parser_skip_to_end_of_block_or_statement (parser);
1481 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1484 static_assert-declaration-no-semi:
1485 _Static_assert ( constant-expression , string-literal )
1489 c_parser_static_assert_declaration_no_semi (c_parser *parser)
1491 location_t assert_loc, value_loc;
1495 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT));
1496 assert_loc = c_parser_peek_token (parser)->location;
1500 pedwarn (assert_loc, OPT_pedantic,
1501 "ISO C99 does not support %<_Static_assert%>");
1503 pedwarn (assert_loc, OPT_pedantic,
1504 "ISO C90 does not support %<_Static_assert%>");
1506 c_parser_consume_token (parser);
1507 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1509 value_loc = c_parser_peek_token (parser)->location;
1510 value = c_parser_expr_no_commas (parser, NULL).value;
1511 parser->lex_untranslated_string = true;
1512 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
1514 parser->lex_untranslated_string = false;
1517 switch (c_parser_peek_token (parser)->type)
1523 case CPP_UTF8STRING:
1524 string = c_parser_peek_token (parser)->value;
1525 c_parser_consume_token (parser);
1526 parser->lex_untranslated_string = false;
1529 c_parser_error (parser, "expected string literal");
1530 parser->lex_untranslated_string = false;
1533 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
1535 if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
1537 error_at (value_loc, "expression in static assertion is not an integer");
1540 if (TREE_CODE (value) != INTEGER_CST)
1542 value = c_fully_fold (value, false, NULL);
1543 if (TREE_CODE (value) == INTEGER_CST)
1544 pedwarn (value_loc, OPT_pedantic, "expression in static assertion "
1545 "is not an integer constant expression");
1547 if (TREE_CODE (value) != INTEGER_CST)
1549 error_at (value_loc, "expression in static assertion is not constant");
1552 constant_expression_warning (value);
1553 if (integer_zerop (value))
1554 error_at (assert_loc, "static assertion failed: %E", string);
1557 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1558 6.7), adding them to SPECS (which may already include some).
1559 Storage class specifiers are accepted iff SCSPEC_OK; type
1560 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1561 the start iff START_ATTR_OK.
1563 declaration-specifiers:
1564 storage-class-specifier declaration-specifiers[opt]
1565 type-specifier declaration-specifiers[opt]
1566 type-qualifier declaration-specifiers[opt]
1567 function-specifier declaration-specifiers[opt]
1569 Function specifiers (inline) are from C99, and are currently
1570 handled as storage class specifiers, as is __thread.
1572 C90 6.5.1, C99 6.7.1:
1573 storage-class-specifier:
1584 C90 6.5.2, C99 6.7.2:
1597 [_Imaginary removed in C99 TC2]
1598 struct-or-union-specifier
1602 (_Bool and _Complex are new in C99.)
1604 C90 6.5.3, C99 6.7.3:
1610 address-space-qualifier
1612 (restrict is new in C99.)
1616 declaration-specifiers:
1617 attributes declaration-specifiers[opt]
1623 identifier recognized by the target
1625 storage-class-specifier:
1638 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1639 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1644 class-name objc-protocol-refs[opt]
1645 typedef-name objc-protocol-refs
1650 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1651 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1653 bool attrs_ok = start_attr_ok;
1654 bool seen_type = specs->type_seen_p;
1655 while (c_parser_next_token_is (parser, CPP_NAME)
1656 || c_parser_next_token_is (parser, CPP_KEYWORD)
1657 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1659 struct c_typespec t;
1661 location_t loc = c_parser_peek_token (parser)->location;
1662 if (c_parser_next_token_is (parser, CPP_NAME))
1664 tree value = c_parser_peek_token (parser)->value;
1665 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1667 if (kind == C_ID_ADDRSPACE)
1670 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1671 declspecs_add_addrspace (specs, as);
1672 c_parser_consume_token (parser);
1677 /* This finishes the specifiers unless a type name is OK, it
1678 is declared as a type name and a type name hasn't yet
1680 if (!typespec_ok || seen_type
1681 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1683 c_parser_consume_token (parser);
1686 if (kind == C_ID_TYPENAME
1687 && (!c_dialect_objc ()
1688 || c_parser_next_token_is_not (parser, CPP_LESS)))
1690 t.kind = ctsk_typedef;
1691 /* For a typedef name, record the meaning, not the name.
1692 In case of 'foo foo, bar;'. */
1693 t.spec = lookup_name (value);
1695 t.expr_const_operands = true;
1699 tree proto = NULL_TREE;
1700 gcc_assert (c_dialect_objc ());
1702 if (c_parser_next_token_is (parser, CPP_LESS))
1703 proto = c_parser_objc_protocol_refs (parser);
1704 t.spec = objc_get_protocol_qualified_type (value, proto);
1706 t.expr_const_operands = true;
1708 declspecs_add_type (loc, specs, t);
1711 if (c_parser_next_token_is (parser, CPP_LESS))
1713 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1714 nisse@lysator.liu.se. */
1716 gcc_assert (c_dialect_objc ());
1717 if (!typespec_ok || seen_type)
1719 proto = c_parser_objc_protocol_refs (parser);
1721 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1723 t.expr_const_operands = true;
1724 declspecs_add_type (loc, specs, t);
1727 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1728 switch (c_parser_peek_token (parser)->keyword)
1740 /* TODO: Distinguish between function specifiers (inline)
1741 and storage class specifiers, either here or in
1742 declspecs_add_scspec. */
1743 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1744 c_parser_consume_token (parser);
1768 if (c_dialect_objc ())
1769 parser->objc_need_raw_identifier = true;
1770 t.kind = ctsk_resword;
1771 t.spec = c_parser_peek_token (parser)->value;
1773 t.expr_const_operands = true;
1774 declspecs_add_type (loc, specs, t);
1775 c_parser_consume_token (parser);
1782 t = c_parser_enum_specifier (parser);
1783 declspecs_add_type (loc, specs, t);
1791 t = c_parser_struct_or_union_specifier (parser);
1792 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1793 declspecs_add_type (loc, specs, t);
1796 /* ??? The old parser rejected typeof after other type
1797 specifiers, but is a syntax error the best way of
1799 if (!typespec_ok || seen_type)
1803 t = c_parser_typeof_specifier (parser);
1804 declspecs_add_type (loc, specs, t);
1810 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1811 c_parser_consume_token (parser);
1816 attrs = c_parser_attributes (parser);
1817 declspecs_add_attrs (specs, attrs);
1826 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1829 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1830 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1831 enum attributes[opt] identifier
1833 The form with trailing comma is new in C99. The forms with
1834 attributes are GNU extensions. In GNU C, we accept any expression
1835 without commas in the syntax (assignment expressions, not just
1836 conditional expressions); assignment expressions will be diagnosed
1841 enumerator-list , enumerator
1844 enumeration-constant
1845 enumeration-constant = constant-expression
1848 static struct c_typespec
1849 c_parser_enum_specifier (c_parser *parser)
1851 struct c_typespec ret;
1853 tree ident = NULL_TREE;
1854 location_t enum_loc;
1855 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1856 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1857 enum_loc = c_parser_peek_token (parser)->location;
1858 c_parser_consume_token (parser);
1859 attrs = c_parser_attributes (parser);
1860 enum_loc = c_parser_peek_token (parser)->location;
1861 /* Set the location in case we create a decl now. */
1862 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1863 if (c_parser_next_token_is (parser, CPP_NAME))
1865 ident = c_parser_peek_token (parser)->value;
1866 ident_loc = c_parser_peek_token (parser)->location;
1867 enum_loc = ident_loc;
1868 c_parser_consume_token (parser);
1870 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1872 /* Parse an enum definition. */
1873 struct c_enum_contents the_enum;
1874 tree type = start_enum (enum_loc, &the_enum, ident);
1876 /* We chain the enumerators in reverse order, then put them in
1877 forward order at the end. */
1878 tree values = NULL_TREE;
1879 c_parser_consume_token (parser);
1887 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1888 location_t decl_loc, value_loc;
1889 if (c_parser_next_token_is_not (parser, CPP_NAME))
1891 c_parser_error (parser, "expected identifier");
1892 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1893 values = error_mark_node;
1896 token = c_parser_peek_token (parser);
1897 enum_id = token->value;
1898 /* Set the location in case we create a decl now. */
1899 c_parser_set_source_position_from_token (token);
1900 decl_loc = value_loc = token->location;
1901 c_parser_consume_token (parser);
1902 if (c_parser_next_token_is (parser, CPP_EQ))
1904 c_parser_consume_token (parser);
1905 value_loc = c_parser_peek_token (parser)->location;
1906 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1909 enum_value = NULL_TREE;
1910 enum_decl = build_enumerator (decl_loc, value_loc,
1911 &the_enum, enum_id, enum_value);
1912 TREE_CHAIN (enum_decl) = values;
1915 if (c_parser_next_token_is (parser, CPP_COMMA))
1917 comma_loc = c_parser_peek_token (parser)->location;
1919 c_parser_consume_token (parser);
1921 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1923 if (seen_comma && !flag_isoc99)
1924 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1925 c_parser_consume_token (parser);
1930 c_parser_error (parser, "expected %<,%> or %<}%>");
1931 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1932 values = error_mark_node;
1936 postfix_attrs = c_parser_attributes (parser);
1937 ret.spec = finish_enum (type, nreverse (values),
1938 chainon (attrs, postfix_attrs));
1939 ret.kind = ctsk_tagdef;
1940 ret.expr = NULL_TREE;
1941 ret.expr_const_operands = true;
1946 c_parser_error (parser, "expected %<{%>");
1947 ret.spec = error_mark_node;
1948 ret.kind = ctsk_tagref;
1949 ret.expr = NULL_TREE;
1950 ret.expr_const_operands = true;
1953 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1954 /* In ISO C, enumerated types can be referred to only if already
1956 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1959 pedwarn (enum_loc, OPT_pedantic,
1960 "ISO C forbids forward references to %<enum%> types");
1965 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1967 struct-or-union-specifier:
1968 struct-or-union attributes[opt] identifier[opt]
1969 { struct-contents } attributes[opt]
1970 struct-or-union attributes[opt] identifier
1973 struct-declaration-list
1975 struct-declaration-list:
1976 struct-declaration ;
1977 struct-declaration-list struct-declaration ;
1984 struct-declaration-list struct-declaration
1986 struct-declaration-list:
1987 struct-declaration-list ;
1990 (Note that in the syntax here, unlike that in ISO C, the semicolons
1991 are included here rather than in struct-declaration, in order to
1992 describe the syntax with extra semicolons and missing semicolon at
1997 struct-declaration-list:
1998 @defs ( class-name )
2000 (Note this does not include a trailing semicolon, but can be
2001 followed by further declarations, and gets a pedwarn-if-pedantic
2002 when followed by a semicolon.) */
2004 static struct c_typespec
2005 c_parser_struct_or_union_specifier (c_parser *parser)
2007 struct c_typespec ret;
2009 tree ident = NULL_TREE;
2010 location_t struct_loc;
2011 location_t ident_loc = UNKNOWN_LOCATION;
2012 enum tree_code code;
2013 switch (c_parser_peek_token (parser)->keyword)
2024 struct_loc = c_parser_peek_token (parser)->location;
2025 c_parser_consume_token (parser);
2026 attrs = c_parser_attributes (parser);
2028 /* Set the location in case we create a decl now. */
2029 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
2031 if (c_parser_next_token_is (parser, CPP_NAME))
2033 ident = c_parser_peek_token (parser)->value;
2034 ident_loc = c_parser_peek_token (parser)->location;
2035 struct_loc = ident_loc;
2036 c_parser_consume_token (parser);
2038 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
2040 /* Parse a struct or union definition. Start the scope of the
2041 tag before parsing components. */
2042 struct c_struct_parse_info *struct_info;
2043 tree type = start_struct (struct_loc, code, ident, &struct_info);
2045 /* We chain the components in reverse order, then put them in
2046 forward order at the end. Each struct-declaration may
2047 declare multiple components (comma-separated), so we must use
2048 chainon to join them, although when parsing each
2049 struct-declaration we can use TREE_CHAIN directly.
2051 The theory behind all this is that there will be more
2052 semicolon separated fields than comma separated fields, and
2053 so we'll be minimizing the number of node traversals required
2055 tree contents = NULL_TREE;
2056 c_parser_consume_token (parser);
2057 /* Handle the Objective-C @defs construct,
2058 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2059 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
2062 gcc_assert (c_dialect_objc ());
2063 c_parser_consume_token (parser);
2064 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2066 if (c_parser_next_token_is (parser, CPP_NAME)
2067 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
2069 name = c_parser_peek_token (parser)->value;
2070 c_parser_consume_token (parser);
2074 c_parser_error (parser, "expected class name");
2075 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2078 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2080 contents = nreverse (objc_get_class_ivars (name));
2083 /* Parse the struct-declarations and semicolons. Problems with
2084 semicolons are diagnosed here; empty structures are diagnosed
2089 /* Parse any stray semicolon. */
2090 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2092 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
2093 "extra semicolon in struct or union specified");
2094 c_parser_consume_token (parser);
2097 /* Stop if at the end of the struct or union contents. */
2098 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2100 c_parser_consume_token (parser);
2103 /* Accept #pragmas at struct scope. */
2104 if (c_parser_next_token_is (parser, CPP_PRAGMA))
2106 c_parser_pragma (parser, pragma_external);
2109 /* Parse some comma-separated declarations, but not the
2110 trailing semicolon if any. */
2111 decls = c_parser_struct_declaration (parser);
2112 contents = chainon (decls, contents);
2113 /* If no semicolon follows, either we have a parse error or
2114 are at the end of the struct or union and should
2116 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2117 c_parser_consume_token (parser);
2120 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2121 pedwarn (c_parser_peek_token (parser)->location, 0,
2122 "no semicolon at end of struct or union");
2125 c_parser_error (parser, "expected %<;%>");
2126 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
2131 postfix_attrs = c_parser_attributes (parser);
2132 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
2133 chainon (attrs, postfix_attrs), struct_info);
2134 ret.kind = ctsk_tagdef;
2135 ret.expr = NULL_TREE;
2136 ret.expr_const_operands = true;
2141 c_parser_error (parser, "expected %<{%>");
2142 ret.spec = error_mark_node;
2143 ret.kind = ctsk_tagref;
2144 ret.expr = NULL_TREE;
2145 ret.expr_const_operands = true;
2148 ret = parser_xref_tag (ident_loc, code, ident);
2152 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2153 the trailing semicolon.
2156 specifier-qualifier-list struct-declarator-list
2157 static_assert-declaration-no-semi
2159 specifier-qualifier-list:
2160 type-specifier specifier-qualifier-list[opt]
2161 type-qualifier specifier-qualifier-list[opt]
2162 attributes specifier-qualifier-list[opt]
2164 struct-declarator-list:
2166 struct-declarator-list , attributes[opt] struct-declarator
2169 declarator attributes[opt]
2170 declarator[opt] : constant-expression attributes[opt]
2175 __extension__ struct-declaration
2176 specifier-qualifier-list
2178 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2179 of attributes where shown is a GNU extension. In GNU C, we accept
2180 any expression without commas in the syntax (assignment
2181 expressions, not just conditional expressions); assignment
2182 expressions will be diagnosed as non-constant. */
2185 c_parser_struct_declaration (c_parser *parser)
2187 struct c_declspecs *specs;
2189 tree all_prefix_attrs;
2191 location_t decl_loc;
2192 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2196 ext = disable_extension_diagnostics ();
2197 c_parser_consume_token (parser);
2198 decl = c_parser_struct_declaration (parser);
2199 restore_extension_diagnostics (ext);
2202 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT))
2204 c_parser_static_assert_declaration_no_semi (parser);
2207 specs = build_null_declspecs ();
2208 decl_loc = c_parser_peek_token (parser)->location;
2209 c_parser_declspecs (parser, specs, false, true, true);
2212 if (!specs->declspecs_seen_p)
2214 c_parser_error (parser, "expected specifier-qualifier-list");
2217 finish_declspecs (specs);
2218 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2221 if (!specs->type_seen_p)
2223 pedwarn (decl_loc, OPT_pedantic,
2224 "ISO C forbids member declarations with no members");
2225 shadow_tag_warned (specs, pedantic);
2230 /* Support for unnamed structs or unions as members of
2231 structs or unions (which is [a] useful and [b] supports
2235 ret = grokfield (c_parser_peek_token (parser)->location,
2236 build_id_declarator (NULL_TREE), specs,
2239 decl_attributes (&ret, attrs, 0);
2243 pending_xref_error ();
2244 prefix_attrs = specs->attrs;
2245 all_prefix_attrs = prefix_attrs;
2246 specs->attrs = NULL_TREE;
2250 /* Declaring one or more declarators or un-named bit-fields. */
2251 struct c_declarator *declarator;
2253 if (c_parser_next_token_is (parser, CPP_COLON))
2254 declarator = build_id_declarator (NULL_TREE);
2256 declarator = c_parser_declarator (parser, specs->type_seen_p,
2257 C_DTR_NORMAL, &dummy);
2258 if (declarator == NULL)
2260 c_parser_skip_to_end_of_block_or_statement (parser);
2263 if (c_parser_next_token_is (parser, CPP_COLON)
2264 || c_parser_next_token_is (parser, CPP_COMMA)
2265 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2266 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2267 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2269 tree postfix_attrs = NULL_TREE;
2270 tree width = NULL_TREE;
2272 if (c_parser_next_token_is (parser, CPP_COLON))
2274 c_parser_consume_token (parser);
2275 width = c_parser_expr_no_commas (parser, NULL).value;
2277 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2278 postfix_attrs = c_parser_attributes (parser);
2279 d = grokfield (c_parser_peek_token (parser)->location,
2280 declarator, specs, width, &all_prefix_attrs);
2281 decl_attributes (&d, chainon (postfix_attrs,
2282 all_prefix_attrs), 0);
2283 DECL_CHAIN (d) = decls;
2285 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2286 all_prefix_attrs = chainon (c_parser_attributes (parser),
2289 all_prefix_attrs = prefix_attrs;
2290 if (c_parser_next_token_is (parser, CPP_COMMA))
2291 c_parser_consume_token (parser);
2292 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2293 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2295 /* Semicolon consumed in caller. */
2300 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2306 c_parser_error (parser,
2307 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2308 "%<__attribute__%>");
2315 /* Parse a typeof specifier (a GNU extension).
2318 typeof ( expression )
2319 typeof ( type-name )
2322 static struct c_typespec
2323 c_parser_typeof_specifier (c_parser *parser)
2325 struct c_typespec ret;
2326 ret.kind = ctsk_typeof;
2327 ret.spec = error_mark_node;
2328 ret.expr = NULL_TREE;
2329 ret.expr_const_operands = true;
2330 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2331 c_parser_consume_token (parser);
2332 c_inhibit_evaluation_warnings++;
2334 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2336 c_inhibit_evaluation_warnings--;
2340 if (c_parser_next_token_starts_typename (parser))
2342 struct c_type_name *type = c_parser_type_name (parser);
2343 c_inhibit_evaluation_warnings--;
2347 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2348 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2354 location_t here = c_parser_peek_token (parser)->location;
2355 struct c_expr expr = c_parser_expression (parser);
2356 c_inhibit_evaluation_warnings--;
2358 if (TREE_CODE (expr.value) == COMPONENT_REF
2359 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2360 error_at (here, "%<typeof%> applied to a bit-field");
2361 mark_exp_read (expr.value);
2362 ret.spec = TREE_TYPE (expr.value);
2363 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2364 /* This is returned with the type so that when the type is
2365 evaluated, this can be evaluated. */
2367 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2368 pop_maybe_used (was_vm);
2370 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2374 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2375 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2376 be redeclared; otherwise it may not. KIND indicates which kind of
2377 declarator is wanted. Returns a valid declarator except in the
2378 case of a syntax error in which case NULL is returned. *SEEN_ID is
2379 set to true if an identifier being declared is seen; this is used
2380 to diagnose bad forms of abstract array declarators and to
2381 determine whether an identifier list is syntactically permitted.
2384 pointer[opt] direct-declarator
2388 ( attributes[opt] declarator )
2389 direct-declarator array-declarator
2390 direct-declarator ( parameter-type-list )
2391 direct-declarator ( identifier-list[opt] )
2394 * type-qualifier-list[opt]
2395 * type-qualifier-list[opt] pointer
2397 type-qualifier-list:
2400 type-qualifier-list type-qualifier
2401 type-qualifier-list attributes
2403 parameter-type-list:
2405 parameter-list , ...
2408 parameter-declaration
2409 parameter-list , parameter-declaration
2411 parameter-declaration:
2412 declaration-specifiers declarator attributes[opt]
2413 declaration-specifiers abstract-declarator[opt] attributes[opt]
2417 identifier-list , identifier
2419 abstract-declarator:
2421 pointer[opt] direct-abstract-declarator
2423 direct-abstract-declarator:
2424 ( attributes[opt] abstract-declarator )
2425 direct-abstract-declarator[opt] array-declarator
2426 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2431 direct-declarator ( parameter-forward-declarations
2432 parameter-type-list[opt] )
2434 direct-abstract-declarator:
2435 direct-abstract-declarator[opt] ( parameter-forward-declarations
2436 parameter-type-list[opt] )
2438 parameter-forward-declarations:
2440 parameter-forward-declarations parameter-list ;
2442 The uses of attributes shown above are GNU extensions.
2444 Some forms of array declarator are not included in C99 in the
2445 syntax for abstract declarators; these are disallowed elsewhere.
2446 This may be a defect (DR#289).
2448 This function also accepts an omitted abstract declarator as being
2449 an abstract declarator, although not part of the formal syntax. */
2451 static struct c_declarator *
2452 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2455 /* Parse any initial pointer part. */
2456 if (c_parser_next_token_is (parser, CPP_MULT))
2458 struct c_declspecs *quals_attrs = build_null_declspecs ();
2459 struct c_declarator *inner;
2460 c_parser_consume_token (parser);
2461 c_parser_declspecs (parser, quals_attrs, false, false, true);
2462 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2466 return make_pointer_declarator (quals_attrs, inner);
2468 /* Now we have a direct declarator, direct abstract declarator or
2469 nothing (which counts as a direct abstract declarator here). */
2470 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2473 /* Parse a direct declarator or direct abstract declarator; arguments
2474 as c_parser_declarator. */
2476 static struct c_declarator *
2477 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2480 /* The direct declarator must start with an identifier (possibly
2481 omitted) or a parenthesized declarator (possibly abstract). In
2482 an ordinary declarator, initial parentheses must start a
2483 parenthesized declarator. In an abstract declarator or parameter
2484 declarator, they could start a parenthesized declarator or a
2485 parameter list. To tell which, the open parenthesis and any
2486 following attributes must be read. If a declaration specifier
2487 follows, then it is a parameter list; if the specifier is a
2488 typedef name, there might be an ambiguity about redeclaring it,
2489 which is resolved in the direction of treating it as a typedef
2490 name. If a close parenthesis follows, it is also an empty
2491 parameter list, as the syntax does not permit empty abstract
2492 declarators. Otherwise, it is a parenthesized declarator (in
2493 which case the analysis may be repeated inside it, recursively).
2495 ??? There is an ambiguity in a parameter declaration "int
2496 (__attribute__((foo)) x)", where x is not a typedef name: it
2497 could be an abstract declarator for a function, or declare x with
2498 parentheses. The proper resolution of this ambiguity needs
2499 documenting. At present we follow an accident of the old
2500 parser's implementation, whereby the first parameter must have
2501 some declaration specifiers other than just attributes. Thus as
2502 a parameter declaration it is treated as a parenthesized
2503 parameter named x, and as an abstract declarator it is
2506 ??? Also following the old parser, attributes inside an empty
2507 parameter list are ignored, making it a list not yielding a
2508 prototype, rather than giving an error or making it have one
2509 parameter with implicit type int.
2511 ??? Also following the old parser, typedef names may be
2512 redeclared in declarators, but not Objective-C class names. */
2514 if (kind != C_DTR_ABSTRACT
2515 && c_parser_next_token_is (parser, CPP_NAME)
2517 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2518 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2520 struct c_declarator *inner
2521 = build_id_declarator (c_parser_peek_token (parser)->value);
2523 inner->id_loc = c_parser_peek_token (parser)->location;
2524 c_parser_consume_token (parser);
2525 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2528 if (kind != C_DTR_NORMAL
2529 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2531 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2532 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2535 /* Either we are at the end of an abstract declarator, or we have
2538 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2541 struct c_declarator *inner;
2542 c_parser_consume_token (parser);
2543 attrs = c_parser_attributes (parser);
2544 if (kind != C_DTR_NORMAL
2545 && (c_parser_next_token_starts_declspecs (parser)
2546 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2548 struct c_arg_info *args
2549 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2556 = build_function_declarator (args,
2557 build_id_declarator (NULL_TREE));
2558 return c_parser_direct_declarator_inner (parser, *seen_id,
2562 /* A parenthesized declarator. */
2563 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2564 if (inner != NULL && attrs != NULL)
2565 inner = build_attrs_declarator (attrs, inner);
2566 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2568 c_parser_consume_token (parser);
2572 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2576 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2583 if (kind == C_DTR_NORMAL)
2585 c_parser_error (parser, "expected identifier or %<(%>");
2589 return build_id_declarator (NULL_TREE);
2593 /* Parse part of a direct declarator or direct abstract declarator,
2594 given that some (in INNER) has already been parsed; ID_PRESENT is
2595 true if an identifier is present, false for an abstract
2598 static struct c_declarator *
2599 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2600 struct c_declarator *inner)
2602 /* Parse a sequence of array declarators and parameter lists. */
2603 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2605 location_t brace_loc = c_parser_peek_token (parser)->location;
2606 struct c_declarator *declarator;
2607 struct c_declspecs *quals_attrs = build_null_declspecs ();
2611 c_parser_consume_token (parser);
2612 c_parser_declspecs (parser, quals_attrs, false, false, true);
2613 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2615 c_parser_consume_token (parser);
2616 if (static_seen && !quals_attrs->declspecs_seen_p)
2617 c_parser_declspecs (parser, quals_attrs, false, false, true);
2618 if (!quals_attrs->declspecs_seen_p)
2620 /* If "static" is present, there must be an array dimension.
2621 Otherwise, there may be a dimension, "*", or no
2626 dimen = c_parser_expr_no_commas (parser, NULL).value;
2630 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2635 else if (c_parser_next_token_is (parser, CPP_MULT))
2637 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2641 c_parser_consume_token (parser);
2646 dimen = c_parser_expr_no_commas (parser, NULL).value;
2652 dimen = c_parser_expr_no_commas (parser, NULL).value;
2655 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2656 c_parser_consume_token (parser);
2659 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2664 mark_exp_read (dimen);
2665 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2666 static_seen, star_seen);
2667 if (declarator == NULL)
2669 inner = set_array_declarator_inner (declarator, inner);
2670 return c_parser_direct_declarator_inner (parser, id_present, inner);
2672 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2675 struct c_arg_info *args;
2676 c_parser_consume_token (parser);
2677 attrs = c_parser_attributes (parser);
2678 args = c_parser_parms_declarator (parser, id_present, attrs);
2683 inner = build_function_declarator (args, inner);
2684 return c_parser_direct_declarator_inner (parser, id_present, inner);
2690 /* Parse a parameter list or identifier list, including the closing
2691 parenthesis but not the opening one. ATTRS are the attributes at
2692 the start of the list. ID_LIST_OK is true if an identifier list is
2693 acceptable; such a list must not have attributes at the start. */
2695 static struct c_arg_info *
2696 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2699 declare_parm_level ();
2700 /* If the list starts with an identifier, it is an identifier list.
2701 Otherwise, it is either a prototype list or an empty list. */
2704 && c_parser_next_token_is (parser, CPP_NAME)
2705 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2707 tree list = NULL_TREE, *nextp = &list;
2708 while (c_parser_next_token_is (parser, CPP_NAME)
2709 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2711 *nextp = build_tree_list (NULL_TREE,
2712 c_parser_peek_token (parser)->value);
2713 nextp = & TREE_CHAIN (*nextp);
2714 c_parser_consume_token (parser);
2715 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2717 c_parser_consume_token (parser);
2718 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2720 c_parser_error (parser, "expected identifier");
2724 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2726 struct c_arg_info *ret = build_arg_info ();
2728 c_parser_consume_token (parser);
2734 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2742 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2748 /* Parse a parameter list (possibly empty), including the closing
2749 parenthesis but not the opening one. ATTRS are the attributes at
2750 the start of the list. */
2752 static struct c_arg_info *
2753 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2755 bool bad_parm = false;
2756 /* ??? Following the old parser, forward parameter declarations may
2757 use abstract declarators, and if no real parameter declarations
2758 follow the forward declarations then this is not diagnosed. Also
2759 note as above that attributes are ignored as the only contents of
2760 the parentheses, or as the only contents after forward
2762 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2764 struct c_arg_info *ret = build_arg_info ();
2765 c_parser_consume_token (parser);
2768 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2770 struct c_arg_info *ret = build_arg_info ();
2771 /* Suppress -Wold-style-definition for this case. */
2772 ret->types = error_mark_node;
2773 error_at (c_parser_peek_token (parser)->location,
2774 "ISO C requires a named argument before %<...%>");
2775 c_parser_consume_token (parser);
2776 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2778 c_parser_consume_token (parser);
2783 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2788 /* Nonempty list of parameters, either terminated with semicolon
2789 (forward declarations; recurse) or with close parenthesis (normal
2790 function) or with ", ... )" (variadic function). */
2793 /* Parse a parameter. */
2794 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2799 push_parm_decl (parm);
2800 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2803 c_parser_consume_token (parser);
2804 mark_forward_parm_decls ();
2805 new_attrs = c_parser_attributes (parser);
2806 return c_parser_parms_list_declarator (parser, new_attrs);
2808 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2810 c_parser_consume_token (parser);
2813 get_pending_sizes ();
2817 return get_parm_info (false);
2819 if (!c_parser_require (parser, CPP_COMMA,
2820 "expected %<;%>, %<,%> or %<)%>"))
2822 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2823 get_pending_sizes ();
2826 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2828 c_parser_consume_token (parser);
2829 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2831 c_parser_consume_token (parser);
2834 get_pending_sizes ();
2838 return get_parm_info (true);
2842 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2844 get_pending_sizes ();
2851 /* Parse a parameter declaration. ATTRS are the attributes at the
2852 start of the declaration if it is the first parameter. */
2854 static struct c_parm *
2855 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2857 struct c_declspecs *specs;
2858 struct c_declarator *declarator;
2860 tree postfix_attrs = NULL_TREE;
2862 if (!c_parser_next_token_starts_declspecs (parser))
2864 c_token *token = c_parser_peek_token (parser);
2867 c_parser_set_source_position_from_token (token);
2868 if (token->type == CPP_NAME
2869 && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
2870 && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
2872 error ("unknown type name %qE", token->value);
2873 parser->error = true;
2875 /* ??? In some Objective-C cases '...' isn't applicable so there
2876 should be a different message. */
2878 c_parser_error (parser,
2879 "expected declaration specifiers or %<...%>");
2880 c_parser_skip_to_end_of_parameter (parser);
2883 specs = build_null_declspecs ();
2886 declspecs_add_attrs (specs, attrs);
2889 c_parser_declspecs (parser, specs, true, true, true);
2890 finish_declspecs (specs);
2891 pending_xref_error ();
2892 prefix_attrs = specs->attrs;
2893 specs->attrs = NULL_TREE;
2894 declarator = c_parser_declarator (parser, specs->type_seen_p,
2895 C_DTR_PARM, &dummy);
2896 if (declarator == NULL)
2898 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2901 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2902 postfix_attrs = c_parser_attributes (parser);
2903 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2907 /* Parse a string literal in an asm expression. It should not be
2908 translated, and wide string literals are an error although
2909 permitted by the syntax. This is a GNU extension.
2914 ??? At present, following the old parser, the caller needs to have
2915 set lex_untranslated_string to 1. It would be better to follow the
2916 C++ parser rather than using this kludge. */
2919 c_parser_asm_string_literal (c_parser *parser)
2922 if (c_parser_next_token_is (parser, CPP_STRING))
2924 str = c_parser_peek_token (parser)->value;
2925 c_parser_consume_token (parser);
2927 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2929 error_at (c_parser_peek_token (parser)->location,
2930 "wide string literal in %<asm%>");
2931 str = build_string (1, "");
2932 c_parser_consume_token (parser);
2936 c_parser_error (parser, "expected string literal");
2942 /* Parse a simple asm expression. This is used in restricted
2943 contexts, where a full expression with inputs and outputs does not
2944 make sense. This is a GNU extension.
2947 asm ( asm-string-literal )
2951 c_parser_simple_asm_expr (c_parser *parser)
2954 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2955 /* ??? Follow the C++ parser rather than using the
2956 lex_untranslated_string kludge. */
2957 parser->lex_untranslated_string = true;
2958 c_parser_consume_token (parser);
2959 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2961 parser->lex_untranslated_string = false;
2964 str = c_parser_asm_string_literal (parser);
2965 parser->lex_untranslated_string = false;
2966 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2968 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2974 /* Parse (possibly empty) attributes. This is a GNU extension.
2978 attributes attribute
2981 __attribute__ ( ( attribute-list ) )
2985 attribute_list , attrib
2990 any-word ( identifier )
2991 any-word ( identifier , nonempty-expr-list )
2992 any-word ( expr-list )
2994 where the "identifier" must not be declared as a type, and
2995 "any-word" may be any identifier (including one declared as a
2996 type), a reserved word storage class specifier, type specifier or
2997 type qualifier. ??? This still leaves out most reserved keywords
2998 (following the old parser), shouldn't we include them, and why not
2999 allow identifiers declared as types to start the arguments? */
3002 c_parser_attributes (c_parser *parser)
3004 tree attrs = NULL_TREE;
3005 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
3007 /* ??? Follow the C++ parser rather than using the
3008 lex_untranslated_string kludge. */
3009 parser->lex_untranslated_string = true;
3010 c_parser_consume_token (parser);
3011 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3013 parser->lex_untranslated_string = false;
3016 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3018 parser->lex_untranslated_string = false;
3019 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
3022 /* Parse the attribute list. */
3023 while (c_parser_next_token_is (parser, CPP_COMMA)
3024 || c_parser_next_token_is (parser, CPP_NAME)
3025 || c_parser_next_token_is (parser, CPP_KEYWORD))
3027 tree attr, attr_name, attr_args;
3028 VEC(tree,gc) *expr_list;
3029 if (c_parser_next_token_is (parser, CPP_COMMA))
3031 c_parser_consume_token (parser);
3034 if (c_parser_next_token_is (parser, CPP_KEYWORD))
3036 /* ??? See comment above about what keywords are
3039 switch (c_parser_peek_token (parser)->keyword)
3077 /* Accept __attribute__((__const)) as __attribute__((const))
3080 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
3083 attr_name = c_parser_peek_token (parser)->value;
3084 c_parser_consume_token (parser);
3085 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
3087 attr = build_tree_list (attr_name, NULL_TREE);
3088 attrs = chainon (attrs, attr);
3091 c_parser_consume_token (parser);
3092 /* Parse the attribute contents. If they start with an
3093 identifier which is followed by a comma or close
3094 parenthesis, then the arguments start with that
3095 identifier; otherwise they are an expression list. */
3096 if (c_parser_next_token_is (parser, CPP_NAME)
3097 && c_parser_peek_token (parser)->id_kind == C_ID_ID
3098 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
3099 || (c_parser_peek_2nd_token (parser)->type
3100 == CPP_CLOSE_PAREN)))
3102 tree arg1 = c_parser_peek_token (parser)->value;
3103 c_parser_consume_token (parser);
3104 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3105 attr_args = build_tree_list (NULL_TREE, arg1);
3109 c_parser_consume_token (parser);
3110 expr_list = c_parser_expr_list (parser, false, true, NULL);
3111 tree_list = build_tree_list_vec (expr_list);
3112 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
3113 release_tree_vector (expr_list);
3118 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3119 attr_args = NULL_TREE;
3122 expr_list = c_parser_expr_list (parser, false, true, NULL);
3123 attr_args = build_tree_list_vec (expr_list);
3124 release_tree_vector (expr_list);
3127 attr = build_tree_list (attr_name, attr_args);
3128 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3129 c_parser_consume_token (parser);
3132 parser->lex_untranslated_string = false;
3133 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3137 attrs = chainon (attrs, attr);
3139 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3140 c_parser_consume_token (parser);
3143 parser->lex_untranslated_string = false;
3144 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3148 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3149 c_parser_consume_token (parser);
3152 parser->lex_untranslated_string = false;
3153 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3157 parser->lex_untranslated_string = false;
3162 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3165 specifier-qualifier-list abstract-declarator[opt]
3168 static struct c_type_name *
3169 c_parser_type_name (c_parser *parser)
3171 struct c_declspecs *specs = build_null_declspecs ();
3172 struct c_declarator *declarator;
3173 struct c_type_name *ret;
3175 c_parser_declspecs (parser, specs, false, true, true);
3176 if (!specs->declspecs_seen_p)
3178 c_parser_error (parser, "expected specifier-qualifier-list");
3181 pending_xref_error ();
3182 finish_declspecs (specs);
3183 declarator = c_parser_declarator (parser, specs->type_seen_p,
3184 C_DTR_ABSTRACT, &dummy);
3185 if (declarator == NULL)
3187 ret = XOBNEW (&parser_obstack, struct c_type_name);
3189 ret->declarator = declarator;
3193 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3196 assignment-expression
3197 { initializer-list }
3198 { initializer-list , }
3201 designation[opt] initializer
3202 initializer-list , designation[opt] initializer
3209 designator-list designator
3216 [ constant-expression ]
3228 [ constant-expression ... constant-expression ]
3230 Any expression without commas is accepted in the syntax for the
3231 constant-expressions, with non-constant expressions rejected later.
3233 This function is only used for top-level initializers; for nested
3234 ones, see c_parser_initval. */
3236 static struct c_expr
3237 c_parser_initializer (c_parser *parser)
3239 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3240 return c_parser_braced_init (parser, NULL_TREE, false);
3244 location_t loc = c_parser_peek_token (parser)->location;
3245 ret = c_parser_expr_no_commas (parser, NULL);
3246 if (TREE_CODE (ret.value) != STRING_CST
3247 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3248 ret = default_function_array_read_conversion (loc, ret);
3253 /* Parse a braced initializer list. TYPE is the type specified for a
3254 compound literal, and NULL_TREE for other initializers and for
3255 nested braced lists. NESTED_P is true for nested braced lists,
3256 false for the list of a compound literal or the list that is the
3257 top-level initializer in a declaration. */
3259 static struct c_expr
3260 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3263 struct obstack braced_init_obstack;
3264 location_t brace_loc = c_parser_peek_token (parser)->location;
3265 gcc_obstack_init (&braced_init_obstack);
3266 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3267 c_parser_consume_token (parser);
3269 push_init_level (0, &braced_init_obstack);
3271 really_start_incremental_init (type);
3272 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3274 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3278 /* Parse a non-empty initializer list, possibly with a trailing
3282 c_parser_initelt (parser, &braced_init_obstack);
3285 if (c_parser_next_token_is (parser, CPP_COMMA))
3286 c_parser_consume_token (parser);
3289 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3293 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3295 ret.value = error_mark_node;
3296 ret.original_code = ERROR_MARK;
3297 ret.original_type = NULL;
3298 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3299 pop_init_level (0, &braced_init_obstack);
3300 obstack_free (&braced_init_obstack, NULL);
3303 c_parser_consume_token (parser);
3304 ret = pop_init_level (0, &braced_init_obstack);
3305 obstack_free (&braced_init_obstack, NULL);
3309 /* Parse a nested initializer, including designators. */
3312 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3314 /* Parse any designator or designator list. A single array
3315 designator may have the subsequent "=" omitted in GNU C, but a
3316 longer list or a structure member designator may not. */
3317 if (c_parser_next_token_is (parser, CPP_NAME)
3318 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3320 /* Old-style structure member designator. */
3321 set_init_label (c_parser_peek_token (parser)->value,
3322 braced_init_obstack);
3323 /* Use the colon as the error location. */
3324 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3325 "obsolete use of designated initializer with %<:%>");
3326 c_parser_consume_token (parser);
3327 c_parser_consume_token (parser);
3331 /* des_seen is 0 if there have been no designators, 1 if there
3332 has been a single array designator and 2 otherwise. */
3334 /* Location of a designator. */
3335 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3336 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3337 || c_parser_next_token_is (parser, CPP_DOT))
3339 int des_prev = des_seen;
3341 des_loc = c_parser_peek_token (parser)->location;
3344 if (c_parser_next_token_is (parser, CPP_DOT))
3347 c_parser_consume_token (parser);
3348 if (c_parser_next_token_is (parser, CPP_NAME))
3350 set_init_label (c_parser_peek_token (parser)->value,
3351 braced_init_obstack);
3352 c_parser_consume_token (parser);
3357 init.value = error_mark_node;
3358 init.original_code = ERROR_MARK;
3359 init.original_type = NULL;
3360 c_parser_error (parser, "expected identifier");
3361 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3362 process_init_element (init, false, braced_init_obstack);
3369 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3370 /* ??? Following the old parser, [ objc-receiver
3371 objc-message-args ] is accepted as an initializer,
3372 being distinguished from a designator by what follows
3373 the first assignment expression inside the square
3374 brackets, but after a first array designator a
3375 subsequent square bracket is for Objective-C taken to
3376 start an expression, using the obsolete form of
3377 designated initializer without '=', rather than
3378 possibly being a second level of designation: in LALR
3379 terms, the '[' is shifted rather than reducing
3380 designator to designator-list. */
3381 if (des_prev == 1 && c_dialect_objc ())
3383 des_seen = des_prev;
3386 if (des_prev == 0 && c_dialect_objc ())
3388 /* This might be an array designator or an
3389 Objective-C message expression. If the former,
3390 continue parsing here; if the latter, parse the
3391 remainder of the initializer given the starting
3392 primary-expression. ??? It might make sense to
3393 distinguish when des_prev == 1 as well; see
3394 previous comment. */
3396 struct c_expr mexpr;
3397 c_parser_consume_token (parser);
3398 if (c_parser_peek_token (parser)->type == CPP_NAME
3399 && ((c_parser_peek_token (parser)->id_kind
3401 || (c_parser_peek_token (parser)->id_kind
3402 == C_ID_CLASSNAME)))
3404 /* Type name receiver. */
3405 tree id = c_parser_peek_token (parser)->value;
3406 c_parser_consume_token (parser);
3407 rec = objc_get_class_reference (id);
3408 goto parse_message_args;
3410 first = c_parser_expr_no_commas (parser, NULL).value;
3411 mark_exp_read (first);
3412 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3413 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3414 goto array_desig_after_first;
3415 /* Expression receiver. So far only one part
3416 without commas has been parsed; there might be
3417 more of the expression. */
3419 while (c_parser_next_token_is (parser, CPP_COMMA))
3422 location_t comma_loc, exp_loc;
3423 comma_loc = c_parser_peek_token (parser)->location;
3424 c_parser_consume_token (parser);
3425 exp_loc = c_parser_peek_token (parser)->location;
3426 next = c_parser_expr_no_commas (parser, NULL);
3427 next = default_function_array_read_conversion (exp_loc,
3429 rec = build_compound_expr (comma_loc, rec, next.value);
3432 /* Now parse the objc-message-args. */
3433 args = c_parser_objc_message_args (parser);
3434 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3437 = objc_build_message_expr (build_tree_list (rec, args));
3438 mexpr.original_code = ERROR_MARK;
3439 mexpr.original_type = NULL;
3440 /* Now parse and process the remainder of the
3441 initializer, starting with this message
3442 expression as a primary-expression. */
3443 c_parser_initval (parser, &mexpr, braced_init_obstack);
3446 c_parser_consume_token (parser);
3447 first = c_parser_expr_no_commas (parser, NULL).value;
3448 mark_exp_read (first);
3449 array_desig_after_first:
3450 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3452 ellipsis_loc = c_parser_peek_token (parser)->location;
3453 c_parser_consume_token (parser);
3454 second = c_parser_expr_no_commas (parser, NULL).value;
3455 mark_exp_read (second);
3459 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3461 c_parser_consume_token (parser);
3462 set_init_index (first, second, braced_init_obstack);
3464 pedwarn (ellipsis_loc, OPT_pedantic,
3465 "ISO C forbids specifying range of elements to initialize");
3468 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3474 if (c_parser_next_token_is (parser, CPP_EQ))
3477 pedwarn (des_loc, OPT_pedantic,
3478 "ISO C90 forbids specifying subobject to initialize");
3479 c_parser_consume_token (parser);
3484 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3485 "obsolete use of designated initializer without %<=%>");
3489 init.value = error_mark_node;
3490 init.original_code = ERROR_MARK;
3491 init.original_type = NULL;
3492 c_parser_error (parser, "expected %<=%>");
3493 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3494 process_init_element (init, false, braced_init_obstack);
3500 c_parser_initval (parser, NULL, braced_init_obstack);
3503 /* Parse a nested initializer; as c_parser_initializer but parses
3504 initializers within braced lists, after any designators have been
3505 applied. If AFTER is not NULL then it is an Objective-C message
3506 expression which is the primary-expression starting the
3510 c_parser_initval (c_parser *parser, struct c_expr *after,
3511 struct obstack * braced_init_obstack)
3514 gcc_assert (!after || c_dialect_objc ());
3515 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3516 init = c_parser_braced_init (parser, NULL_TREE, true);
3519 location_t loc = c_parser_peek_token (parser)->location;
3520 init = c_parser_expr_no_commas (parser, after);
3521 if (init.value != NULL_TREE
3522 && TREE_CODE (init.value) != STRING_CST
3523 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3524 init = default_function_array_read_conversion (loc, init);
3526 process_init_element (init, false, braced_init_obstack);
3529 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3533 { block-item-list[opt] }
3534 { label-declarations block-item-list }
3538 block-item-list block-item
3550 { label-declarations block-item-list }
3553 __extension__ nested-declaration
3554 nested-function-definition
3558 label-declarations label-declaration
3561 __label__ identifier-list ;
3563 Allowing the mixing of declarations and code is new in C99. The
3564 GNU syntax also permits (not shown above) labels at the end of
3565 compound statements, which yield an error. We don't allow labels
3566 on declarations; this might seem like a natural extension, but
3567 there would be a conflict between attributes on the label and
3568 prefix attributes on the declaration. ??? The syntax follows the
3569 old parser in requiring something after label declarations.
3570 Although they are erroneous if the labels declared aren't defined,
3571 is it useful for the syntax to be this way?
3583 c_parser_compound_statement (c_parser *parser)
3586 location_t brace_loc;
3587 brace_loc = c_parser_peek_token (parser)->location;
3588 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3590 /* Ensure a scope is entered and left anyway to avoid confusion
3591 if we have just prepared to enter a function body. */
3592 stmt = c_begin_compound_stmt (true);
3593 c_end_compound_stmt (brace_loc, stmt, true);
3594 return error_mark_node;
3596 stmt = c_begin_compound_stmt (true);
3597 c_parser_compound_statement_nostart (parser);
3598 return c_end_compound_stmt (brace_loc, stmt, true);
3601 /* Parse a compound statement except for the opening brace. This is
3602 used for parsing both compound statements and statement expressions
3603 (which follow different paths to handling the opening). */
3606 c_parser_compound_statement_nostart (c_parser *parser)
3608 bool last_stmt = false;
3609 bool last_label = false;
3610 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3611 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3612 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3614 c_parser_consume_token (parser);
3617 mark_valid_location_for_stdc_pragma (true);
3618 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3620 /* Read zero or more forward-declarations for labels that nested
3621 functions can jump to. */
3622 mark_valid_location_for_stdc_pragma (false);
3623 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3625 label_loc = c_parser_peek_token (parser)->location;
3626 c_parser_consume_token (parser);
3627 /* Any identifiers, including those declared as type names,
3632 if (c_parser_next_token_is_not (parser, CPP_NAME))
3634 c_parser_error (parser, "expected identifier");
3638 = declare_label (c_parser_peek_token (parser)->value);
3639 C_DECLARED_LABEL_FLAG (label) = 1;
3640 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3641 c_parser_consume_token (parser);
3642 if (c_parser_next_token_is (parser, CPP_COMMA))
3643 c_parser_consume_token (parser);
3647 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3649 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3651 /* We must now have at least one statement, label or declaration. */
3652 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3654 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3655 c_parser_error (parser, "expected declaration or statement");
3656 c_parser_consume_token (parser);
3659 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3661 location_t loc = c_parser_peek_token (parser)->location;
3662 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3663 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3664 || (c_parser_next_token_is (parser, CPP_NAME)
3665 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3667 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3668 label_loc = c_parser_peek_2nd_token (parser)->location;
3670 label_loc = c_parser_peek_token (parser)->location;
3673 mark_valid_location_for_stdc_pragma (false);
3674 c_parser_label (parser);
3676 else if (!last_label
3677 && c_parser_next_token_starts_declaration (parser))
3680 mark_valid_location_for_stdc_pragma (false);
3681 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
3684 (pedantic && !flag_isoc99)
3686 : OPT_Wdeclaration_after_statement,
3687 "ISO C90 forbids mixed declarations and code");
3690 else if (!last_label
3691 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3693 /* __extension__ can start a declaration, but is also an
3694 unary operator that can start an expression. Consume all
3695 but the last of a possible series of __extension__ to
3697 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3698 && (c_parser_peek_2nd_token (parser)->keyword
3700 c_parser_consume_token (parser);
3701 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
3704 ext = disable_extension_diagnostics ();
3705 c_parser_consume_token (parser);
3707 mark_valid_location_for_stdc_pragma (false);
3708 c_parser_declaration_or_fndef (parser, true, true, true, true,
3710 /* Following the old parser, __extension__ does not
3711 disable this diagnostic. */
3712 restore_extension_diagnostics (ext);
3714 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3716 : OPT_Wdeclaration_after_statement,
3717 "ISO C90 forbids mixed declarations and code");
3723 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3725 /* External pragmas, and some omp pragmas, are not associated
3726 with regular c code, and so are not to be considered statements
3727 syntactically. This ensures that the user doesn't put them
3728 places that would turn into syntax errors if the directive
3730 if (c_parser_pragma (parser, pragma_compound))
3731 last_label = false, last_stmt = true;
3733 else if (c_parser_next_token_is (parser, CPP_EOF))
3735 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3736 c_parser_error (parser, "expected declaration or statement");
3739 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3741 if (parser->in_if_block)
3743 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3744 error_at (loc, """expected %<}%> before %<else%>");
3749 error_at (loc, "%<else%> without a previous %<if%>");
3750 c_parser_consume_token (parser);
3759 mark_valid_location_for_stdc_pragma (false);
3760 c_parser_statement_after_labels (parser);
3763 parser->error = false;
3766 error_at (label_loc, "label at end of compound statement");
3767 c_parser_consume_token (parser);
3768 /* Restore the value we started with. */
3769 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3772 /* Parse a label (C90 6.6.1, C99 6.8.1).
3775 identifier : attributes[opt]
3776 case constant-expression :
3782 case constant-expression ... constant-expression :
3784 The use of attributes on labels is a GNU extension. The syntax in
3785 GNU C accepts any expressions without commas, non-constant
3786 expressions being rejected later. */
3789 c_parser_label (c_parser *parser)
3791 location_t loc1 = c_parser_peek_token (parser)->location;
3792 tree label = NULL_TREE;
3793 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3796 c_parser_consume_token (parser);
3797 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3798 if (c_parser_next_token_is (parser, CPP_COLON))
3800 c_parser_consume_token (parser);
3801 label = do_case (loc1, exp1, NULL_TREE);
3803 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3805 c_parser_consume_token (parser);
3806 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3807 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3808 label = do_case (loc1, exp1, exp2);
3811 c_parser_error (parser, "expected %<:%> or %<...%>");
3813 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3815 c_parser_consume_token (parser);
3816 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3817 label = do_case (loc1, NULL_TREE, NULL_TREE);
3821 tree name = c_parser_peek_token (parser)->value;
3824 location_t loc2 = c_parser_peek_token (parser)->location;
3825 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3826 c_parser_consume_token (parser);
3827 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3828 c_parser_consume_token (parser);
3829 attrs = c_parser_attributes (parser);
3830 tlab = define_label (loc2, name);
3833 decl_attributes (&tlab, attrs, 0);
3834 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3839 if (c_parser_next_token_starts_declaration (parser)
3840 && !(c_parser_next_token_is (parser, CPP_NAME)
3841 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3843 error_at (c_parser_peek_token (parser)->location,
3844 "a label can only be part of a statement and "
3845 "a declaration is not a statement");
3846 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3847 /*static_assert_ok*/ true,
3848 /*nested*/ true, /*empty_ok*/ false,
3849 /*start_attr_ok*/ true);
3854 /* Parse a statement (C90 6.6, C99 6.8).
3859 expression-statement
3867 expression-statement:
3870 selection-statement:
3874 iteration-statement:
3883 return expression[opt] ;
3896 objc-throw-statement
3897 objc-try-catch-statement
3898 objc-synchronized-statement
3900 objc-throw-statement:
3914 parallel-for-construct
3915 parallel-sections-construct
3922 parallel-directive structured-block
3925 for-directive iteration-statement
3928 sections-directive section-scope
3931 single-directive structured-block
3933 parallel-for-construct:
3934 parallel-for-directive iteration-statement
3936 parallel-sections-construct:
3937 parallel-sections-directive section-scope
3940 master-directive structured-block
3943 critical-directive structured-block
3946 atomic-directive expression-statement
3949 ordered-directive structured-block */
3952 c_parser_statement (c_parser *parser)
3954 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3955 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3956 || (c_parser_next_token_is (parser, CPP_NAME)
3957 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3958 c_parser_label (parser);
3959 c_parser_statement_after_labels (parser);
3962 /* Parse a statement, other than a labeled statement. */
3965 c_parser_statement_after_labels (c_parser *parser)
3967 location_t loc = c_parser_peek_token (parser)->location;
3968 tree stmt = NULL_TREE;
3969 bool in_if_block = parser->in_if_block;
3970 parser->in_if_block = false;
3971 switch (c_parser_peek_token (parser)->type)
3973 case CPP_OPEN_BRACE:
3974 add_stmt (c_parser_compound_statement (parser));
3977 switch (c_parser_peek_token (parser)->keyword)
3980 c_parser_if_statement (parser);
3983 c_parser_switch_statement (parser);
3986 c_parser_while_statement (parser);
3989 c_parser_do_statement (parser);
3992 c_parser_for_statement (parser);
3995 c_parser_consume_token (parser);
3996 if (c_parser_next_token_is (parser, CPP_NAME))
3998 stmt = c_finish_goto_label (loc,
3999 c_parser_peek_token (parser)->value);
4000 c_parser_consume_token (parser);
4002 else if (c_parser_next_token_is (parser, CPP_MULT))
4004 c_parser_consume_token (parser);
4005 stmt = c_finish_goto_ptr (loc,
4006 c_parser_expression (parser).value);
4009 c_parser_error (parser, "expected identifier or %<*%>");
4010 goto expect_semicolon;
4012 c_parser_consume_token (parser);
4013 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
4014 goto expect_semicolon;
4016 c_parser_consume_token (parser);
4017 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
4018 goto expect_semicolon;
4020 c_parser_consume_token (parser);
4021 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4023 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
4024 c_parser_consume_token (parser);
4028 struct c_expr expr = c_parser_expression_conv (parser);
4029 mark_exp_read (expr.value);
4030 stmt = c_finish_return (loc, expr.value, expr.original_type);
4031 goto expect_semicolon;
4035 stmt = c_parser_asm_statement (parser);
4038 gcc_assert (c_dialect_objc ());
4039 c_parser_consume_token (parser);
4040 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4042 stmt = objc_build_throw_stmt (loc, NULL_TREE);
4043 c_parser_consume_token (parser);
4047 tree expr = c_parser_expression (parser).value;
4048 expr = c_fully_fold (expr, false, NULL);
4049 stmt = objc_build_throw_stmt (loc, expr);
4050 goto expect_semicolon;
4054 gcc_assert (c_dialect_objc ());
4055 c_parser_objc_try_catch_statement (parser);
4057 case RID_AT_SYNCHRONIZED:
4058 gcc_assert (c_dialect_objc ());
4059 c_parser_objc_synchronized_statement (parser);
4066 c_parser_consume_token (parser);
4068 case CPP_CLOSE_PAREN:
4069 case CPP_CLOSE_SQUARE:
4070 /* Avoid infinite loop in error recovery:
4071 c_parser_skip_until_found stops at a closing nesting
4072 delimiter without consuming it, but here we need to consume
4073 it to proceed further. */
4074 c_parser_error (parser, "expected statement");
4075 c_parser_consume_token (parser);
4078 c_parser_pragma (parser, pragma_stmt);
4082 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
4084 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4087 /* Two cases cannot and do not have line numbers associated: If stmt
4088 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4089 cannot hold line numbers. But that's OK because the statement
4090 will either be changed to a MODIFY_EXPR during gimplification of
4091 the statement expr, or discarded. If stmt was compound, but
4092 without new variables, we will have skipped the creation of a
4093 BIND and will have a bare STATEMENT_LIST. But that's OK because
4094 (recursively) all of the component statements should already have
4095 line numbers assigned. ??? Can we discard no-op statements
4097 if (CAN_HAVE_LOCATION_P (stmt)
4098 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
4099 SET_EXPR_LOCATION (stmt, loc);
4101 parser->in_if_block = in_if_block;
4104 /* Parse the condition from an if, do, while or for statements. */
4107 c_parser_condition (c_parser *parser)
4109 location_t loc = c_parser_peek_token (parser)->location;
4111 cond = c_parser_expression_conv (parser).value;
4112 cond = c_objc_common_truthvalue_conversion (loc, cond);
4113 cond = c_fully_fold (cond, false, NULL);
4114 if (warn_sequence_point)
4115 verify_sequence_points (cond);
4119 /* Parse a parenthesized condition from an if, do or while statement.
4125 c_parser_paren_condition (c_parser *parser)
4128 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4129 return error_mark_node;
4130 cond = c_parser_condition (parser);
4131 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4135 /* Parse a statement which is a block in C99. */
4138 c_parser_c99_block_statement (c_parser *parser)
4140 tree block = c_begin_compound_stmt (flag_isoc99);
4141 location_t loc = c_parser_peek_token (parser)->location;
4142 c_parser_statement (parser);
4143 return c_end_compound_stmt (loc, block, flag_isoc99);
4146 /* Parse the body of an if statement. This is just parsing a
4147 statement but (a) it is a block in C99, (b) we track whether the
4148 body is an if statement for the sake of -Wparentheses warnings, (c)
4149 we handle an empty body specially for the sake of -Wempty-body
4150 warnings, and (d) we call parser_compound_statement directly
4151 because c_parser_statement_after_labels resets
4152 parser->in_if_block. */
4155 c_parser_if_body (c_parser *parser, bool *if_p)
4157 tree block = c_begin_compound_stmt (flag_isoc99);
4158 location_t body_loc = c_parser_peek_token (parser)->location;
4159 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4160 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4161 || (c_parser_next_token_is (parser, CPP_NAME)
4162 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4163 c_parser_label (parser);
4164 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
4165 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4167 location_t loc = c_parser_peek_token (parser)->location;
4168 add_stmt (build_empty_stmt (loc));
4169 c_parser_consume_token (parser);
4170 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4171 warning_at (loc, OPT_Wempty_body,
4172 "suggest braces around empty body in an %<if%> statement");
4174 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4175 add_stmt (c_parser_compound_statement (parser));
4177 c_parser_statement_after_labels (parser);
4178 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4181 /* Parse the else body of an if statement. This is just parsing a
4182 statement but (a) it is a block in C99, (b) we handle an empty body
4183 specially for the sake of -Wempty-body warnings. */
4186 c_parser_else_body (c_parser *parser)
4188 location_t else_loc = c_parser_peek_token (parser)->location;
4189 tree block = c_begin_compound_stmt (flag_isoc99);
4190 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4191 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4192 || (c_parser_next_token_is (parser, CPP_NAME)
4193 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4194 c_parser_label (parser);
4195 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4197 location_t loc = c_parser_peek_token (parser)->location;
4200 "suggest braces around empty body in an %<else%> statement");
4201 add_stmt (build_empty_stmt (loc));
4202 c_parser_consume_token (parser);
4205 c_parser_statement_after_labels (parser);
4206 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4209 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4212 if ( expression ) statement
4213 if ( expression ) statement else statement
4217 c_parser_if_statement (c_parser *parser)
4222 bool first_if = false;
4223 tree first_body, second_body;
4226 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4227 c_parser_consume_token (parser);
4228 block = c_begin_compound_stmt (flag_isoc99);
4229 loc = c_parser_peek_token (parser)->location;
4230 cond = c_parser_paren_condition (parser);
4231 in_if_block = parser->in_if_block;
4232 parser->in_if_block = true;
4233 first_body = c_parser_if_body (parser, &first_if);
4234 parser->in_if_block = in_if_block;
4235 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4237 c_parser_consume_token (parser);
4238 second_body = c_parser_else_body (parser);
4241 second_body = NULL_TREE;
4242 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4243 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4246 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4249 switch (expression) statement
4253 c_parser_switch_statement (c_parser *parser)
4255 tree block, expr, body, save_break;
4256 location_t switch_loc = c_parser_peek_token (parser)->location;
4257 location_t switch_cond_loc;
4258 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4259 c_parser_consume_token (parser);
4260 block = c_begin_compound_stmt (flag_isoc99);
4261 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4263 switch_cond_loc = c_parser_peek_token (parser)->location;
4264 expr = c_parser_expression (parser).value;
4265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4269 switch_cond_loc = UNKNOWN_LOCATION;
4270 expr = error_mark_node;
4272 c_start_case (switch_loc, switch_cond_loc, expr);
4273 save_break = c_break_label;
4274 c_break_label = NULL_TREE;
4275 body = c_parser_c99_block_statement (parser);
4276 c_finish_case (body);
4279 location_t here = c_parser_peek_token (parser)->location;
4280 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4281 SET_EXPR_LOCATION (t, here);
4284 c_break_label = save_break;
4285 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4288 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4291 while (expression) statement
4295 c_parser_while_statement (c_parser *parser)
4297 tree block, cond, body, save_break, save_cont;
4299 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4300 c_parser_consume_token (parser);
4301 block = c_begin_compound_stmt (flag_isoc99);
4302 loc = c_parser_peek_token (parser)->location;
4303 cond = c_parser_paren_condition (parser);
4304 save_break = c_break_label;
4305 c_break_label = NULL_TREE;
4306 save_cont = c_cont_label;
4307 c_cont_label = NULL_TREE;
4308 body = c_parser_c99_block_statement (parser);
4309 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4310 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4311 c_break_label = save_break;
4312 c_cont_label = save_cont;
4315 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4318 do statement while ( expression ) ;
4322 c_parser_do_statement (c_parser *parser)
4324 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4326 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4327 c_parser_consume_token (parser);
4328 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4329 warning_at (c_parser_peek_token (parser)->location,
4331 "suggest braces around empty body in %<do%> statement");
4332 block = c_begin_compound_stmt (flag_isoc99);
4333 loc = c_parser_peek_token (parser)->location;
4334 save_break = c_break_label;
4335 c_break_label = NULL_TREE;
4336 save_cont = c_cont_label;
4337 c_cont_label = NULL_TREE;
4338 body = c_parser_c99_block_statement (parser);
4339 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4340 new_break = c_break_label;
4341 c_break_label = save_break;
4342 new_cont = c_cont_label;
4343 c_cont_label = save_cont;
4344 cond = c_parser_paren_condition (parser);
4345 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4346 c_parser_skip_to_end_of_block_or_statement (parser);
4347 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4348 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4351 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4354 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4355 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4357 The form with a declaration is new in C99.
4359 ??? In accordance with the old parser, the declaration may be a
4360 nested function, which is then rejected in check_for_loop_decls,
4361 but does it make any sense for this to be included in the grammar?
4362 Note in particular that the nested function does not include a
4363 trailing ';', whereas the "declaration" production includes one.
4364 Also, can we reject bad declarations earlier and cheaper than
4365 check_for_loop_decls? */
4368 c_parser_for_statement (c_parser *parser)
4370 tree block, cond, incr, save_break, save_cont, body;
4371 location_t loc = c_parser_peek_token (parser)->location;
4372 location_t for_loc = c_parser_peek_token (parser)->location;
4373 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4374 c_parser_consume_token (parser);
4375 block = c_begin_compound_stmt (flag_isoc99);
4376 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4378 /* Parse the initialization declaration or expression. */
4379 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4381 c_parser_consume_token (parser);
4382 c_finish_expr_stmt (loc, NULL_TREE);
4384 else if (c_parser_next_token_starts_declaration (parser))
4386 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
4387 check_for_loop_decls (for_loc);
4389 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4391 /* __extension__ can start a declaration, but is also an
4392 unary operator that can start an expression. Consume all
4393 but the last of a possible series of __extension__ to
4395 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4396 && (c_parser_peek_2nd_token (parser)->keyword
4398 c_parser_consume_token (parser);
4399 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser)))
4402 ext = disable_extension_diagnostics ();
4403 c_parser_consume_token (parser);
4404 c_parser_declaration_or_fndef (parser, true, true, true, true,
4406 restore_extension_diagnostics (ext);
4407 check_for_loop_decls (for_loc);
4415 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4416 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4418 /* Parse the loop condition. */
4419 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4421 c_parser_consume_token (parser);
4426 cond = c_parser_condition (parser);
4427 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4429 /* Parse the increment expression. */
4430 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4431 incr = c_process_expr_stmt (loc, NULL_TREE);
4433 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4438 cond = error_mark_node;
4439 incr = error_mark_node;
4441 save_break = c_break_label;
4442 c_break_label = NULL_TREE;
4443 save_cont = c_cont_label;
4444 c_cont_label = NULL_TREE;
4445 body = c_parser_c99_block_statement (parser);
4446 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4447 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4448 c_break_label = save_break;
4449 c_cont_label = save_cont;
4452 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4453 statement with inputs, outputs, clobbers, and volatile tag
4457 asm type-qualifier[opt] ( asm-argument ) ;
4458 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4462 asm-string-literal : asm-operands[opt]
4463 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4464 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4467 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4470 Qualifiers other than volatile are accepted in the syntax but
4474 c_parser_asm_statement (c_parser *parser)
4476 tree quals, str, outputs, inputs, clobbers, labels, ret;
4477 bool simple, is_goto;
4478 location_t asm_loc = c_parser_peek_token (parser)->location;
4479 int section, nsections;
4481 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4482 c_parser_consume_token (parser);
4483 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4485 quals = c_parser_peek_token (parser)->value;
4486 c_parser_consume_token (parser);
4488 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4489 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4491 warning_at (c_parser_peek_token (parser)->location,
4493 "%E qualifier ignored on asm",
4494 c_parser_peek_token (parser)->value);
4496 c_parser_consume_token (parser);
4502 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4504 c_parser_consume_token (parser);
4508 /* ??? Follow the C++ parser rather than using the
4509 lex_untranslated_string kludge. */
4510 parser->lex_untranslated_string = true;
4513 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4516 str = c_parser_asm_string_literal (parser);
4517 if (str == NULL_TREE)
4518 goto error_close_paren;
4521 outputs = NULL_TREE;
4523 clobbers = NULL_TREE;
4526 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4529 /* Parse each colon-delimited section of operands. */
4530 nsections = 3 + is_goto;
4531 for (section = 0; section < nsections; ++section)
4533 if (!c_parser_require (parser, CPP_COLON,
4536 : "expected %<:%> or %<)%>"))
4537 goto error_close_paren;
4539 /* Once past any colon, we're no longer a simple asm. */
4542 if ((!c_parser_next_token_is (parser, CPP_COLON)
4543 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4548 /* For asm goto, we don't allow output operands, but reserve
4549 the slot for a future extension that does allow them. */
4551 outputs = c_parser_asm_operands (parser, false);
4554 inputs = c_parser_asm_operands (parser, true);
4557 clobbers = c_parser_asm_clobbers (parser);
4560 labels = c_parser_asm_goto_operands (parser);
4566 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4571 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4573 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4577 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4578 c_parser_skip_to_end_of_block_or_statement (parser);
4580 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4581 clobbers, labels, simple));
4584 parser->lex_untranslated_string = false;
4588 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4592 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4593 not outputs), apply the default conversion of functions and arrays
4598 asm-operands , asm-operand
4601 asm-string-literal ( expression )
4602 [ identifier ] asm-string-literal ( expression )
4606 c_parser_asm_operands (c_parser *parser, bool convert_p)
4608 tree list = NULL_TREE;
4614 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4616 c_parser_consume_token (parser);
4617 if (c_parser_next_token_is (parser, CPP_NAME))
4619 tree id = c_parser_peek_token (parser)->value;
4620 c_parser_consume_token (parser);
4621 name = build_string (IDENTIFIER_LENGTH (id),
4622 IDENTIFIER_POINTER (id));
4626 c_parser_error (parser, "expected identifier");
4627 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4630 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4635 str = c_parser_asm_string_literal (parser);
4636 if (str == NULL_TREE)
4638 parser->lex_untranslated_string = false;
4639 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4641 parser->lex_untranslated_string = true;
4644 loc = c_parser_peek_token (parser)->location;
4645 expr = c_parser_expression (parser);
4646 mark_exp_read (expr.value);
4648 expr = default_function_array_conversion (loc, expr);
4649 expr.value = c_fully_fold (expr.value, false, NULL);
4650 parser->lex_untranslated_string = true;
4651 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4653 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4656 list = chainon (list, build_tree_list (build_tree_list (name, str),
4658 if (c_parser_next_token_is (parser, CPP_COMMA))
4659 c_parser_consume_token (parser);
4666 /* Parse asm clobbers, a GNU extension.
4670 asm-clobbers , asm-string-literal
4674 c_parser_asm_clobbers (c_parser *parser)
4676 tree list = NULL_TREE;
4679 tree str = c_parser_asm_string_literal (parser);
4681 list = tree_cons (NULL_TREE, str, list);
4684 if (c_parser_next_token_is (parser, CPP_COMMA))
4685 c_parser_consume_token (parser);
4692 /* Parse asm goto labels, a GNU extension.
4696 asm-goto-operands , identifier
4700 c_parser_asm_goto_operands (c_parser *parser)
4702 tree list = NULL_TREE;
4707 if (c_parser_next_token_is (parser, CPP_NAME))
4709 c_token *tok = c_parser_peek_token (parser);
4711 label = lookup_label_for_goto (tok->location, name);
4712 c_parser_consume_token (parser);
4713 TREE_USED (label) = 1;
4717 c_parser_error (parser, "expected identifier");
4721 name = build_string (IDENTIFIER_LENGTH (name),
4722 IDENTIFIER_POINTER (name));
4723 list = tree_cons (name, label, list);
4724 if (c_parser_next_token_is (parser, CPP_COMMA))
4725 c_parser_consume_token (parser);
4727 return nreverse (list);
4731 /* Parse an expression other than a compound expression; that is, an
4732 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4733 NULL then it is an Objective-C message expression which is the
4734 primary-expression starting the expression as an initializer.
4736 assignment-expression:
4737 conditional-expression
4738 unary-expression assignment-operator assignment-expression
4740 assignment-operator: one of
4741 = *= /= %= += -= <<= >>= &= ^= |=
4743 In GNU C we accept any conditional expression on the LHS and
4744 diagnose the invalid lvalue rather than producing a syntax
4747 static struct c_expr
4748 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4750 struct c_expr lhs, rhs, ret;
4751 enum tree_code code;
4752 location_t op_location, exp_location;
4753 gcc_assert (!after || c_dialect_objc ());
4754 lhs = c_parser_conditional_expression (parser, after);
4755 op_location = c_parser_peek_token (parser)->location;
4756 switch (c_parser_peek_token (parser)->type)
4765 code = TRUNC_DIV_EXPR;
4768 code = TRUNC_MOD_EXPR;
4783 code = BIT_AND_EXPR;
4786 code = BIT_XOR_EXPR;
4789 code = BIT_IOR_EXPR;
4794 c_parser_consume_token (parser);
4795 exp_location = c_parser_peek_token (parser)->location;
4796 rhs = c_parser_expr_no_commas (parser, NULL);
4797 rhs = default_function_array_read_conversion (exp_location, rhs);
4798 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4799 code, exp_location, rhs.value,
4801 if (code == NOP_EXPR)
4802 ret.original_code = MODIFY_EXPR;
4805 TREE_NO_WARNING (ret.value) = 1;
4806 ret.original_code = ERROR_MARK;
4808 ret.original_type = NULL;
4812 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4813 is not NULL then it is an Objective-C message expression which is
4814 the primary-expression starting the expression as an initializer.
4816 conditional-expression:
4817 logical-OR-expression
4818 logical-OR-expression ? expression : conditional-expression
4822 conditional-expression:
4823 logical-OR-expression ? : conditional-expression
4826 static struct c_expr
4827 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4829 struct c_expr cond, exp1, exp2, ret;
4830 location_t cond_loc, colon_loc, middle_loc;
4832 gcc_assert (!after || c_dialect_objc ());
4834 cond = c_parser_binary_expression (parser, after);
4836 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4838 cond_loc = c_parser_peek_token (parser)->location;
4839 cond = default_function_array_read_conversion (cond_loc, cond);
4840 c_parser_consume_token (parser);
4841 if (c_parser_next_token_is (parser, CPP_COLON))
4843 tree eptype = NULL_TREE;
4845 middle_loc = c_parser_peek_token (parser)->location;
4846 pedwarn (middle_loc, OPT_pedantic,
4847 "ISO C forbids omitting the middle term of a ?: expression");
4848 warn_for_omitted_condop (middle_loc, cond.value);
4849 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4851 eptype = TREE_TYPE (cond.value);
4852 cond.value = TREE_OPERAND (cond.value, 0);
4854 /* Make sure first operand is calculated only once. */
4855 exp1.value = c_save_expr (default_conversion (cond.value));
4857 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4858 exp1.original_type = NULL;
4859 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4860 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4865 = c_objc_common_truthvalue_conversion
4866 (cond_loc, default_conversion (cond.value));
4867 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4868 exp1 = c_parser_expression_conv (parser);
4869 mark_exp_read (exp1.value);
4870 c_inhibit_evaluation_warnings +=
4871 ((cond.value == truthvalue_true_node)
4872 - (cond.value == truthvalue_false_node));
4875 colon_loc = c_parser_peek_token (parser)->location;
4876 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4878 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4879 ret.value = error_mark_node;
4880 ret.original_code = ERROR_MARK;
4881 ret.original_type = NULL;
4885 location_t exp2_loc = c_parser_peek_token (parser)->location;
4886 exp2 = c_parser_conditional_expression (parser, NULL);
4887 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
4889 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4890 ret.value = build_conditional_expr (colon_loc, cond.value,
4891 cond.original_code == C_MAYBE_CONST_EXPR,
4892 exp1.value, exp1.original_type,
4893 exp2.value, exp2.original_type);
4894 ret.original_code = ERROR_MARK;
4895 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4896 ret.original_type = NULL;
4901 /* If both sides are enum type, the default conversion will have
4902 made the type of the result be an integer type. We want to
4903 remember the enum types we started with. */
4904 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4905 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4906 ret.original_type = ((t1 != error_mark_node
4907 && t2 != error_mark_node
4908 && (TYPE_MAIN_VARIANT (t1)
4909 == TYPE_MAIN_VARIANT (t2)))
4916 /* Parse a binary expression; that is, a logical-OR-expression (C90
4917 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4918 an Objective-C message expression which is the primary-expression
4919 starting the expression as an initializer.
4921 multiplicative-expression:
4923 multiplicative-expression * cast-expression
4924 multiplicative-expression / cast-expression
4925 multiplicative-expression % cast-expression
4927 additive-expression:
4928 multiplicative-expression
4929 additive-expression + multiplicative-expression
4930 additive-expression - multiplicative-expression
4934 shift-expression << additive-expression
4935 shift-expression >> additive-expression
4937 relational-expression:
4939 relational-expression < shift-expression
4940 relational-expression > shift-expression
4941 relational-expression <= shift-expression
4942 relational-expression >= shift-expression
4944 equality-expression:
4945 relational-expression
4946 equality-expression == relational-expression
4947 equality-expression != relational-expression
4951 AND-expression & equality-expression
4953 exclusive-OR-expression:
4955 exclusive-OR-expression ^ AND-expression
4957 inclusive-OR-expression:
4958 exclusive-OR-expression
4959 inclusive-OR-expression | exclusive-OR-expression
4961 logical-AND-expression:
4962 inclusive-OR-expression
4963 logical-AND-expression && inclusive-OR-expression
4965 logical-OR-expression:
4966 logical-AND-expression
4967 logical-OR-expression || logical-AND-expression
4970 static struct c_expr
4971 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4973 /* A binary expression is parsed using operator-precedence parsing,
4974 with the operands being cast expressions. All the binary
4975 operators are left-associative. Thus a binary expression is of
4978 E0 op1 E1 op2 E2 ...
4980 which we represent on a stack. On the stack, the precedence
4981 levels are strictly increasing. When a new operator is
4982 encountered of higher precedence than that at the top of the
4983 stack, it is pushed; its LHS is the top expression, and its RHS
4984 is everything parsed until it is popped. When a new operator is
4985 encountered with precedence less than or equal to that at the top
4986 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4987 by the result of the operation until the operator at the top of
4988 the stack has lower precedence than the new operator or there is
4989 only one element on the stack; then the top expression is the LHS
4990 of the new operator. In the case of logical AND and OR
4991 expressions, we also need to adjust c_inhibit_evaluation_warnings
4992 as appropriate when the operators are pushed and popped. */
4994 /* The precedence levels, where 0 is a dummy lowest level used for
4995 the bottom of the stack. */
5011 /* The expression at this stack level. */
5013 /* The precedence of the operator on its left, PREC_NONE at the
5014 bottom of the stack. */
5016 /* The operation on its left. */
5018 /* The source location of this operation. */
5022 /* Location of the binary operator. */
5023 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
5026 switch (stack[sp].op) \
5028 case TRUTH_ANDIF_EXPR: \
5029 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5030 == truthvalue_false_node); \
5032 case TRUTH_ORIF_EXPR: \
5033 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5034 == truthvalue_true_node); \
5039 stack[sp - 1].expr \
5040 = default_function_array_read_conversion (stack[sp - 1].loc, \
5041 stack[sp - 1].expr); \
5043 = default_function_array_read_conversion (stack[sp].loc, \
5045 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5047 stack[sp - 1].expr, \
5051 gcc_assert (!after || c_dialect_objc ());
5052 stack[0].loc = c_parser_peek_token (parser)->location;
5053 stack[0].expr = c_parser_cast_expression (parser, after);
5054 stack[0].prec = PREC_NONE;
5059 enum tree_code ocode;
5062 switch (c_parser_peek_token (parser)->type)
5070 ocode = TRUNC_DIV_EXPR;
5074 ocode = TRUNC_MOD_EXPR;
5086 ocode = LSHIFT_EXPR;
5090 ocode = RSHIFT_EXPR;
5104 case CPP_GREATER_EQ:
5117 oprec = PREC_BITAND;
5118 ocode = BIT_AND_EXPR;
5121 oprec = PREC_BITXOR;
5122 ocode = BIT_XOR_EXPR;
5126 ocode = BIT_IOR_EXPR;
5129 oprec = PREC_LOGAND;
5130 ocode = TRUTH_ANDIF_EXPR;
5134 ocode = TRUTH_ORIF_EXPR;
5137 /* Not a binary operator, so end of the binary
5141 binary_loc = c_parser_peek_token (parser)->location;
5142 c_parser_consume_token (parser);
5143 while (oprec <= stack[sp].prec)
5147 case TRUTH_ANDIF_EXPR:
5149 = default_function_array_read_conversion (stack[sp].loc,
5151 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5152 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5153 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5154 == truthvalue_false_node);
5156 case TRUTH_ORIF_EXPR:
5158 = default_function_array_read_conversion (stack[sp].loc,
5160 stack[sp].expr.value = c_objc_common_truthvalue_conversion
5161 (stack[sp].loc, default_conversion (stack[sp].expr.value));
5162 c_inhibit_evaluation_warnings += (stack[sp].expr.value
5163 == truthvalue_true_node);
5169 stack[sp].loc = binary_loc;
5170 stack[sp].expr = c_parser_cast_expression (parser, NULL);
5171 stack[sp].prec = oprec;
5172 stack[sp].op = ocode;
5173 stack[sp].loc = binary_loc;
5178 return stack[0].expr;
5182 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5183 NULL then it is an Objective-C message expression which is the
5184 primary-expression starting the expression as an initializer.
5188 ( type-name ) unary-expression
5191 static struct c_expr
5192 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5194 location_t cast_loc = c_parser_peek_token (parser)->location;
5195 gcc_assert (!after || c_dialect_objc ());
5197 return c_parser_postfix_expression_after_primary (parser,
5199 /* If the expression begins with a parenthesized type name, it may
5200 be either a cast or a compound literal; we need to see whether
5201 the next character is '{' to tell the difference. If not, it is
5202 an unary expression. */
5203 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5204 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5206 struct c_type_name *type_name;
5209 c_parser_consume_token (parser);
5210 type_name = c_parser_type_name (parser);
5211 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5212 if (type_name == NULL)
5214 ret.value = error_mark_node;
5215 ret.original_code = ERROR_MARK;
5216 ret.original_type = NULL;
5220 /* Save casted types in the function's used types hash table. */
5221 used_types_insert (type_name->specs->type);
5223 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5224 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5227 location_t expr_loc = c_parser_peek_token (parser)->location;
5228 expr = c_parser_cast_expression (parser, NULL);
5229 expr = default_function_array_read_conversion (expr_loc, expr);
5231 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5232 ret.original_code = ERROR_MARK;
5233 ret.original_type = NULL;
5237 return c_parser_unary_expression (parser);
5240 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5246 unary-operator cast-expression
5247 sizeof unary-expression
5248 sizeof ( type-name )
5250 unary-operator: one of
5256 __alignof__ unary-expression
5257 __alignof__ ( type-name )
5260 unary-operator: one of
5261 __extension__ __real__ __imag__
5263 In addition, the GNU syntax treats ++ and -- as unary operators, so
5264 they may be applied to cast expressions with errors for non-lvalues
5267 static struct c_expr
5268 c_parser_unary_expression (c_parser *parser)
5271 struct c_expr ret, op;
5272 location_t op_loc = c_parser_peek_token (parser)->location;
5274 ret.original_code = ERROR_MARK;
5275 ret.original_type = NULL;
5276 switch (c_parser_peek_token (parser)->type)
5279 c_parser_consume_token (parser);
5280 exp_loc = c_parser_peek_token (parser)->location;
5281 op = c_parser_cast_expression (parser, NULL);
5282 op = default_function_array_read_conversion (exp_loc, op);
5283 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5284 case CPP_MINUS_MINUS:
5285 c_parser_consume_token (parser);
5286 exp_loc = c_parser_peek_token (parser)->location;
5287 op = c_parser_cast_expression (parser, NULL);
5288 op = default_function_array_read_conversion (exp_loc, op);
5289 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5291 c_parser_consume_token (parser);
5292 op = c_parser_cast_expression (parser, NULL);
5293 mark_exp_read (op.value);
5294 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5296 c_parser_consume_token (parser);
5297 exp_loc = c_parser_peek_token (parser)->location;
5298 op = c_parser_cast_expression (parser, NULL);
5299 op = default_function_array_read_conversion (exp_loc, op);
5300 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5303 if (!c_dialect_objc () && !in_system_header)
5306 "traditional C rejects the unary plus operator");
5307 c_parser_consume_token (parser);
5308 exp_loc = c_parser_peek_token (parser)->location;
5309 op = c_parser_cast_expression (parser, NULL);
5310 op = default_function_array_read_conversion (exp_loc, op);
5311 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5313 c_parser_consume_token (parser);
5314 exp_loc = c_parser_peek_token (parser)->location;
5315 op = c_parser_cast_expression (parser, NULL);
5316 op = default_function_array_read_conversion (exp_loc, op);
5317 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5319 c_parser_consume_token (parser);
5320 exp_loc = c_parser_peek_token (parser)->location;
5321 op = c_parser_cast_expression (parser, NULL);
5322 op = default_function_array_read_conversion (exp_loc, op);
5323 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5325 c_parser_consume_token (parser);
5326 exp_loc = c_parser_peek_token (parser)->location;
5327 op = c_parser_cast_expression (parser, NULL);
5328 op = default_function_array_read_conversion (exp_loc, op);
5329 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5331 /* Refer to the address of a label as a pointer. */
5332 c_parser_consume_token (parser);
5333 if (c_parser_next_token_is (parser, CPP_NAME))
5335 ret.value = finish_label_address_expr
5336 (c_parser_peek_token (parser)->value, op_loc);
5337 c_parser_consume_token (parser);
5341 c_parser_error (parser, "expected identifier");
5342 ret.value = error_mark_node;
5346 switch (c_parser_peek_token (parser)->keyword)
5349 return c_parser_sizeof_expression (parser);
5351 return c_parser_alignof_expression (parser);
5353 c_parser_consume_token (parser);
5354 ext = disable_extension_diagnostics ();
5355 ret = c_parser_cast_expression (parser, NULL);
5356 restore_extension_diagnostics (ext);
5359 c_parser_consume_token (parser);
5360 exp_loc = c_parser_peek_token (parser)->location;
5361 op = c_parser_cast_expression (parser, NULL);
5362 op = default_function_array_conversion (exp_loc, op);
5363 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5365 c_parser_consume_token (parser);
5366 exp_loc = c_parser_peek_token (parser)->location;
5367 op = c_parser_cast_expression (parser, NULL);
5368 op = default_function_array_conversion (exp_loc, op);
5369 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5371 return c_parser_postfix_expression (parser);
5374 return c_parser_postfix_expression (parser);
5378 /* Parse a sizeof expression. */
5380 static struct c_expr
5381 c_parser_sizeof_expression (c_parser *parser)
5384 location_t expr_loc;
5385 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5386 c_parser_consume_token (parser);
5387 c_inhibit_evaluation_warnings++;
5389 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5390 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5392 /* Either sizeof ( type-name ) or sizeof unary-expression
5393 starting with a compound literal. */
5394 struct c_type_name *type_name;
5395 c_parser_consume_token (parser);
5396 expr_loc = c_parser_peek_token (parser)->location;
5397 type_name = c_parser_type_name (parser);
5398 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5399 if (type_name == NULL)
5402 c_inhibit_evaluation_warnings--;
5404 ret.value = error_mark_node;
5405 ret.original_code = ERROR_MARK;
5406 ret.original_type = NULL;
5409 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5411 expr = c_parser_postfix_expression_after_paren_type (parser,
5416 /* sizeof ( type-name ). */
5417 c_inhibit_evaluation_warnings--;
5419 return c_expr_sizeof_type (expr_loc, type_name);
5423 expr_loc = c_parser_peek_token (parser)->location;
5424 expr = c_parser_unary_expression (parser);
5426 c_inhibit_evaluation_warnings--;
5428 mark_exp_read (expr.value);
5429 if (TREE_CODE (expr.value) == COMPONENT_REF
5430 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5431 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5432 return c_expr_sizeof_expr (expr_loc, expr);
5436 /* Parse an alignof expression. */
5438 static struct c_expr
5439 c_parser_alignof_expression (c_parser *parser)
5442 location_t loc = c_parser_peek_token (parser)->location;
5443 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5444 c_parser_consume_token (parser);
5445 c_inhibit_evaluation_warnings++;
5447 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5448 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5450 /* Either __alignof__ ( type-name ) or __alignof__
5451 unary-expression starting with a compound literal. */
5453 struct c_type_name *type_name;
5455 c_parser_consume_token (parser);
5456 loc = c_parser_peek_token (parser)->location;
5457 type_name = c_parser_type_name (parser);
5458 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5459 if (type_name == NULL)
5462 c_inhibit_evaluation_warnings--;
5464 ret.value = error_mark_node;
5465 ret.original_code = ERROR_MARK;
5466 ret.original_type = NULL;
5469 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5471 expr = c_parser_postfix_expression_after_paren_type (parser,
5476 /* alignof ( type-name ). */
5477 c_inhibit_evaluation_warnings--;
5479 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5480 ret.original_code = ERROR_MARK;
5481 ret.original_type = NULL;
5487 expr = c_parser_unary_expression (parser);
5489 mark_exp_read (expr.value);
5490 c_inhibit_evaluation_warnings--;
5492 ret.value = c_alignof_expr (loc, expr.value);
5493 ret.original_code = ERROR_MARK;
5494 ret.original_type = NULL;
5499 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5503 postfix-expression [ expression ]
5504 postfix-expression ( argument-expression-list[opt] )
5505 postfix-expression . identifier
5506 postfix-expression -> identifier
5507 postfix-expression ++
5508 postfix-expression --
5509 ( type-name ) { initializer-list }
5510 ( type-name ) { initializer-list , }
5512 argument-expression-list:
5514 argument-expression-list , argument-expression
5526 (treated as a keyword in GNU C)
5529 ( compound-statement )
5530 __builtin_va_arg ( assignment-expression , type-name )
5531 __builtin_offsetof ( type-name , offsetof-member-designator )
5532 __builtin_choose_expr ( assignment-expression ,
5533 assignment-expression ,
5534 assignment-expression )
5535 __builtin_types_compatible_p ( type-name , type-name )
5537 offsetof-member-designator:
5539 offsetof-member-designator . identifier
5540 offsetof-member-designator [ expression ]
5545 [ objc-receiver objc-message-args ]
5546 @selector ( objc-selector-arg )
5547 @protocol ( identifier )
5548 @encode ( type-name )
5552 static struct c_expr
5553 c_parser_postfix_expression (c_parser *parser)
5555 struct c_expr expr, e1, e2, e3;
5556 struct c_type_name *t1, *t2;
5557 location_t loc = c_parser_peek_token (parser)->location;;
5558 expr.original_code = ERROR_MARK;
5559 expr.original_type = NULL;
5560 switch (c_parser_peek_token (parser)->type)
5563 expr.value = c_parser_peek_token (parser)->value;
5564 loc = c_parser_peek_token (parser)->location;
5565 c_parser_consume_token (parser);
5566 if (TREE_CODE (expr.value) == FIXED_CST
5567 && !targetm.fixed_point_supported_p ())
5569 error_at (loc, "fixed-point types not supported for this target");
5570 expr.value = error_mark_node;
5577 expr.value = c_parser_peek_token (parser)->value;
5578 c_parser_consume_token (parser);
5584 case CPP_UTF8STRING:
5585 expr.value = c_parser_peek_token (parser)->value;
5586 expr.original_code = STRING_CST;
5587 c_parser_consume_token (parser);
5589 case CPP_OBJC_STRING:
5590 gcc_assert (c_dialect_objc ());
5592 = objc_build_string_object (c_parser_peek_token (parser)->value);
5593 c_parser_consume_token (parser);
5596 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5598 c_parser_error (parser, "expected expression");
5599 expr.value = error_mark_node;
5603 tree id = c_parser_peek_token (parser)->value;
5604 c_parser_consume_token (parser);
5605 expr.value = build_external_ref (loc, id,
5606 (c_parser_peek_token (parser)->type
5608 &expr.original_type);
5611 case CPP_OPEN_PAREN:
5612 /* A parenthesized expression, statement expression or compound
5614 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5616 /* A statement expression. */
5618 location_t brace_loc;
5619 c_parser_consume_token (parser);
5620 brace_loc = c_parser_peek_token (parser)->location;
5621 c_parser_consume_token (parser);
5622 if (cur_stmt_list == NULL)
5624 error_at (loc, "braced-group within expression allowed "
5625 "only inside a function");
5626 parser->error = true;
5627 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5628 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5629 expr.value = error_mark_node;
5632 stmt = c_begin_stmt_expr ();
5633 c_parser_compound_statement_nostart (parser);
5634 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5636 pedwarn (loc, OPT_pedantic,
5637 "ISO C forbids braced-groups within expressions");
5638 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5639 mark_exp_read (expr.value);
5641 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5643 /* A compound literal. ??? Can we actually get here rather
5644 than going directly to
5645 c_parser_postfix_expression_after_paren_type from
5648 struct c_type_name *type_name;
5649 c_parser_consume_token (parser);
5650 loc = c_parser_peek_token (parser)->location;
5651 type_name = c_parser_type_name (parser);
5652 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5654 if (type_name == NULL)
5656 expr.value = error_mark_node;
5659 expr = c_parser_postfix_expression_after_paren_type (parser,
5665 /* A parenthesized expression. */
5666 c_parser_consume_token (parser);
5667 expr = c_parser_expression (parser);
5668 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5669 TREE_NO_WARNING (expr.value) = 1;
5670 if (expr.original_code != C_MAYBE_CONST_EXPR)
5671 expr.original_code = ERROR_MARK;
5672 /* Don't change EXPR.ORIGINAL_TYPE. */
5673 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5678 switch (c_parser_peek_token (parser)->keyword)
5680 case RID_FUNCTION_NAME:
5681 case RID_PRETTY_FUNCTION_NAME:
5682 case RID_C99_FUNCTION_NAME:
5683 expr.value = fname_decl (loc,
5684 c_parser_peek_token (parser)->keyword,
5685 c_parser_peek_token (parser)->value);
5686 c_parser_consume_token (parser);
5689 c_parser_consume_token (parser);
5690 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5692 expr.value = error_mark_node;
5695 e1 = c_parser_expr_no_commas (parser, NULL);
5696 mark_exp_read (e1.value);
5697 e1.value = c_fully_fold (e1.value, false, NULL);
5698 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5700 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5701 expr.value = error_mark_node;
5704 loc = c_parser_peek_token (parser)->location;
5705 t1 = c_parser_type_name (parser);
5706 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5710 expr.value = error_mark_node;
5714 tree type_expr = NULL_TREE;
5715 expr.value = c_build_va_arg (loc, e1.value,
5716 groktypename (t1, &type_expr, NULL));
5719 expr.value = build2 (C_MAYBE_CONST_EXPR,
5720 TREE_TYPE (expr.value), type_expr,
5722 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5727 c_parser_consume_token (parser);
5728 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5730 expr.value = error_mark_node;
5733 t1 = c_parser_type_name (parser);
5736 expr.value = error_mark_node;
5739 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5741 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5742 expr.value = error_mark_node;
5746 tree type = groktypename (t1, NULL, NULL);
5748 if (type == error_mark_node)
5749 offsetof_ref = error_mark_node;
5752 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5753 SET_EXPR_LOCATION (offsetof_ref, loc);
5755 /* Parse the second argument to __builtin_offsetof. We
5756 must have one identifier, and beyond that we want to
5757 accept sub structure and sub array references. */
5758 if (c_parser_next_token_is (parser, CPP_NAME))
5760 offsetof_ref = build_component_ref
5761 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5762 c_parser_consume_token (parser);
5763 while (c_parser_next_token_is (parser, CPP_DOT)
5764 || c_parser_next_token_is (parser,
5766 || c_parser_next_token_is (parser,
5769 if (c_parser_next_token_is (parser, CPP_DEREF))
5771 loc = c_parser_peek_token (parser)->location;
5772 offsetof_ref = build_array_ref (loc,
5777 else if (c_parser_next_token_is (parser, CPP_DOT))
5780 c_parser_consume_token (parser);
5781 if (c_parser_next_token_is_not (parser,
5784 c_parser_error (parser, "expected identifier");
5787 offsetof_ref = build_component_ref
5789 c_parser_peek_token (parser)->value);
5790 c_parser_consume_token (parser);
5795 loc = c_parser_peek_token (parser)->location;
5796 c_parser_consume_token (parser);
5797 idx = c_parser_expression (parser).value;
5798 idx = c_fully_fold (idx, false, NULL);
5799 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5801 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5806 c_parser_error (parser, "expected identifier");
5807 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5809 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5812 case RID_CHOOSE_EXPR:
5813 c_parser_consume_token (parser);
5814 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5816 expr.value = error_mark_node;
5819 loc = c_parser_peek_token (parser)->location;
5820 e1 = c_parser_expr_no_commas (parser, NULL);
5821 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5823 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5824 expr.value = error_mark_node;
5827 e2 = c_parser_expr_no_commas (parser, NULL);
5828 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5830 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5831 expr.value = error_mark_node;
5834 e3 = c_parser_expr_no_commas (parser, NULL);
5835 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5841 mark_exp_read (e2.value);
5842 mark_exp_read (e3.value);
5843 if (TREE_CODE (c) != INTEGER_CST
5844 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5846 "first argument to %<__builtin_choose_expr%> not"
5848 constant_expression_warning (c);
5849 expr = integer_zerop (c) ? e3 : e2;
5852 case RID_TYPES_COMPATIBLE_P:
5853 c_parser_consume_token (parser);
5854 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5856 expr.value = error_mark_node;
5859 t1 = c_parser_type_name (parser);
5862 expr.value = error_mark_node;
5865 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5867 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5868 expr.value = error_mark_node;
5871 t2 = c_parser_type_name (parser);
5874 expr.value = error_mark_node;
5877 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5882 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5883 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5886 = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
5889 case RID_AT_SELECTOR:
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;
5898 tree sel = c_parser_objc_selector_arg (parser);
5899 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5901 expr.value = objc_build_selector_expr (loc, sel);
5904 case RID_AT_PROTOCOL:
5905 gcc_assert (c_dialect_objc ());
5906 c_parser_consume_token (parser);
5907 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5909 expr.value = error_mark_node;
5912 if (c_parser_next_token_is_not (parser, CPP_NAME))
5914 c_parser_error (parser, "expected identifier");
5915 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5916 expr.value = error_mark_node;
5920 tree id = c_parser_peek_token (parser)->value;
5921 c_parser_consume_token (parser);
5922 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5924 expr.value = objc_build_protocol_expr (id);
5928 /* Extension to support C-structures in the archiver. */
5929 gcc_assert (c_dialect_objc ());
5930 c_parser_consume_token (parser);
5931 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5933 expr.value = error_mark_node;
5936 t1 = c_parser_type_name (parser);
5939 expr.value = error_mark_node;
5940 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5943 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5946 tree type = groktypename (t1, NULL, NULL);
5947 expr.value = objc_build_encode_expr (type);
5951 c_parser_error (parser, "expected expression");
5952 expr.value = error_mark_node;
5956 case CPP_OPEN_SQUARE:
5957 if (c_dialect_objc ())
5959 tree receiver, args;
5960 c_parser_consume_token (parser);
5961 receiver = c_parser_objc_receiver (parser);
5962 args = c_parser_objc_message_args (parser);
5963 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5965 expr.value = objc_build_message_expr (build_tree_list (receiver,
5969 /* Else fall through to report error. */
5971 c_parser_error (parser, "expected expression");
5972 expr.value = error_mark_node;
5975 return c_parser_postfix_expression_after_primary (parser, loc, expr);
5978 /* Parse a postfix expression after a parenthesized type name: the
5979 brace-enclosed initializer of a compound literal, possibly followed
5980 by some postfix operators. This is separate because it is not
5981 possible to tell until after the type name whether a cast
5982 expression has a cast or a compound literal, or whether the operand
5983 of sizeof is a parenthesized type name or starts with a compound
5984 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5985 location of the first token after the parentheses around the type
5988 static struct c_expr
5989 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5990 struct c_type_name *type_name,
5991 location_t type_loc)
5997 location_t start_loc;
5998 tree type_expr = NULL_TREE;
5999 bool type_expr_const = true;
6000 check_compound_literal_type (type_loc, type_name);
6001 start_init (NULL_TREE, NULL, 0);
6002 type = groktypename (type_name, &type_expr, &type_expr_const);
6003 start_loc = c_parser_peek_token (parser)->location;
6004 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
6006 error_at (type_loc, "compound literal has variable size");
6007 type = error_mark_node;
6009 init = c_parser_braced_init (parser, type, false);
6011 maybe_warn_string_init (type, init);
6013 if (type != error_mark_node
6014 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
6015 && current_function_decl)
6017 error ("compound literal qualified by address-space qualifier");
6018 type = error_mark_node;
6022 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
6023 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
6024 ? CONSTRUCTOR_NON_CONST (init.value)
6025 : init.original_code == C_MAYBE_CONST_EXPR);
6026 non_const |= !type_expr_const;
6027 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
6028 expr.original_code = ERROR_MARK;
6029 expr.original_type = NULL;
6032 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
6034 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
6035 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
6039 gcc_assert (!non_const);
6040 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
6041 type_expr, expr.value);
6044 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
6047 /* Parse a postfix expression after the initial primary or compound
6048 literal; that is, parse a series of postfix operators.
6050 EXPR_LOC is the location of the primary expression. */
6052 static struct c_expr
6053 c_parser_postfix_expression_after_primary (c_parser *parser,
6054 location_t expr_loc,
6057 struct c_expr orig_expr;
6059 VEC(tree,gc) *exprlist;
6060 VEC(tree,gc) *origtypes;
6063 location_t op_loc = c_parser_peek_token (parser)->location;
6064 switch (c_parser_peek_token (parser)->type)
6066 case CPP_OPEN_SQUARE:
6067 /* Array reference. */
6068 c_parser_consume_token (parser);
6069 idx = c_parser_expression (parser).value;
6070 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
6072 expr.value = build_array_ref (op_loc, expr.value, idx);
6073 expr.original_code = ERROR_MARK;
6074 expr.original_type = NULL;
6076 case CPP_OPEN_PAREN:
6077 /* Function call. */
6078 c_parser_consume_token (parser);
6079 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
6082 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
6083 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6086 mark_exp_read (expr.value);
6087 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6088 "(" after the FUNCNAME, which is what we have now. */
6089 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
6091 expr.original_code = ERROR_MARK;
6092 if (TREE_CODE (expr.value) == INTEGER_CST
6093 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
6094 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
6095 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
6096 expr.original_code = C_MAYBE_CONST_EXPR;
6097 expr.original_type = NULL;
6098 if (exprlist != NULL)
6100 release_tree_vector (exprlist);
6101 release_tree_vector (origtypes);
6105 /* Structure element reference. */
6106 c_parser_consume_token (parser);
6107 expr = default_function_array_conversion (expr_loc, expr);
6108 if (c_parser_next_token_is (parser, CPP_NAME))
6109 ident = c_parser_peek_token (parser)->value;
6112 c_parser_error (parser, "expected identifier");
6113 expr.value = error_mark_node;
6114 expr.original_code = ERROR_MARK;
6115 expr.original_type = NULL;
6118 c_parser_consume_token (parser);
6119 expr.value = build_component_ref (op_loc, expr.value, ident);
6120 expr.original_code = ERROR_MARK;
6121 if (TREE_CODE (expr.value) != COMPONENT_REF)
6122 expr.original_type = NULL;
6125 /* Remember the original type of a bitfield. */
6126 tree field = TREE_OPERAND (expr.value, 1);
6127 if (TREE_CODE (field) != FIELD_DECL)
6128 expr.original_type = NULL;
6130 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6134 /* Structure element reference. */
6135 c_parser_consume_token (parser);
6136 expr = default_function_array_conversion (expr_loc, expr);
6137 if (c_parser_next_token_is (parser, CPP_NAME))
6138 ident = c_parser_peek_token (parser)->value;
6141 c_parser_error (parser, "expected identifier");
6142 expr.value = error_mark_node;
6143 expr.original_code = ERROR_MARK;
6144 expr.original_type = NULL;
6147 c_parser_consume_token (parser);
6148 expr.value = build_component_ref (op_loc,
6149 build_indirect_ref (op_loc,
6153 expr.original_code = ERROR_MARK;
6154 if (TREE_CODE (expr.value) != COMPONENT_REF)
6155 expr.original_type = NULL;
6158 /* Remember the original type of a bitfield. */
6159 tree field = TREE_OPERAND (expr.value, 1);
6160 if (TREE_CODE (field) != FIELD_DECL)
6161 expr.original_type = NULL;
6163 expr.original_type = DECL_BIT_FIELD_TYPE (field);
6167 /* Postincrement. */
6168 c_parser_consume_token (parser);
6169 expr = default_function_array_read_conversion (expr_loc, expr);
6170 expr.value = build_unary_op (op_loc,
6171 POSTINCREMENT_EXPR, expr.value, 0);
6172 expr.original_code = ERROR_MARK;
6173 expr.original_type = NULL;
6175 case CPP_MINUS_MINUS:
6176 /* Postdecrement. */
6177 c_parser_consume_token (parser);
6178 expr = default_function_array_read_conversion (expr_loc, expr);
6179 expr.value = build_unary_op (op_loc,
6180 POSTDECREMENT_EXPR, expr.value, 0);
6181 expr.original_code = ERROR_MARK;
6182 expr.original_type = NULL;
6190 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6193 assignment-expression
6194 expression , assignment-expression
6197 static struct c_expr
6198 c_parser_expression (c_parser *parser)
6201 expr = c_parser_expr_no_commas (parser, NULL);
6202 while (c_parser_next_token_is (parser, CPP_COMMA))
6206 location_t loc = c_parser_peek_token (parser)->location;
6207 location_t expr_loc;
6208 c_parser_consume_token (parser);
6209 expr_loc = c_parser_peek_token (parser)->location;
6210 lhsval = expr.value;
6211 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6212 lhsval = TREE_OPERAND (lhsval, 1);
6213 if (DECL_P (lhsval) || handled_component_p (lhsval))
6214 mark_exp_read (lhsval);
6215 next = c_parser_expr_no_commas (parser, NULL);
6216 next = default_function_array_conversion (expr_loc, next);
6217 expr.value = build_compound_expr (loc, expr.value, next.value);
6218 expr.original_code = COMPOUND_EXPR;
6219 expr.original_type = next.original_type;
6224 /* Parse an expression and convert functions or arrays to
6227 static struct c_expr
6228 c_parser_expression_conv (c_parser *parser)
6231 location_t loc = c_parser_peek_token (parser)->location;
6232 expr = c_parser_expression (parser);
6233 expr = default_function_array_conversion (loc, expr);
6237 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6238 functions and arrays to pointers. If FOLD_P, fold the expressions.
6241 assignment-expression
6242 nonempty-expr-list , assignment-expression
6245 static VEC(tree,gc) *
6246 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6247 VEC(tree,gc) **p_orig_types)
6250 VEC(tree,gc) *orig_types;
6252 location_t loc = c_parser_peek_token (parser)->location;
6254 ret = make_tree_vector ();
6255 if (p_orig_types == NULL)
6258 orig_types = make_tree_vector ();
6260 expr = c_parser_expr_no_commas (parser, NULL);
6262 expr = default_function_array_read_conversion (loc, expr);
6264 expr.value = c_fully_fold (expr.value, false, NULL);
6265 VEC_quick_push (tree, ret, expr.value);
6266 if (orig_types != NULL)
6267 VEC_quick_push (tree, orig_types, expr.original_type);
6268 while (c_parser_next_token_is (parser, CPP_COMMA))
6270 c_parser_consume_token (parser);
6271 loc = c_parser_peek_token (parser)->location;
6272 expr = c_parser_expr_no_commas (parser, NULL);
6274 expr = default_function_array_read_conversion (loc, expr);
6276 expr.value = c_fully_fold (expr.value, false, NULL);
6277 VEC_safe_push (tree, gc, ret, expr.value);
6278 if (orig_types != NULL)
6279 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6281 if (orig_types != NULL)
6282 *p_orig_types = orig_types;
6286 /* Parse Objective-C-specific constructs. */
6288 /* Parse an objc-class-definition.
6290 objc-class-definition:
6291 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6292 objc-class-instance-variables[opt] objc-methodprotolist @end
6293 @implementation identifier objc-superclass[opt]
6294 objc-class-instance-variables[opt]
6295 @interface identifier ( identifier ) objc-protocol-refs[opt]
6296 objc-methodprotolist @end
6297 @implementation identifier ( identifier )
6302 "@interface identifier (" must start "@interface identifier (
6303 identifier ) ...": objc-methodprotolist in the first production may
6304 not start with a parenthesized identifier as a declarator of a data
6305 definition with no declaration specifiers if the objc-superclass,
6306 objc-protocol-refs and objc-class-instance-variables are omitted. */
6309 c_parser_objc_class_definition (c_parser *parser, tree attributes)
6314 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6316 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6321 c_parser_consume_token (parser);
6322 if (c_parser_next_token_is_not (parser, CPP_NAME))
6324 c_parser_error (parser, "expected identifier");
6327 id1 = c_parser_peek_token (parser)->value;
6328 c_parser_consume_token (parser);
6329 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6332 tree proto = NULL_TREE;
6333 c_parser_consume_token (parser);
6334 if (c_parser_next_token_is_not (parser, CPP_NAME))
6336 c_parser_error (parser, "expected identifier");
6337 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6340 id2 = c_parser_peek_token (parser)->value;
6341 c_parser_consume_token (parser);
6342 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6345 objc_start_category_implementation (id1, id2);
6348 if (c_parser_next_token_is (parser, CPP_LESS))
6349 proto = c_parser_objc_protocol_refs (parser);
6350 objc_start_category_interface (id1, id2, proto, attributes);
6351 c_parser_objc_methodprotolist (parser);
6352 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6353 objc_finish_interface ();
6356 if (c_parser_next_token_is (parser, CPP_COLON))
6358 c_parser_consume_token (parser);
6359 if (c_parser_next_token_is_not (parser, CPP_NAME))
6361 c_parser_error (parser, "expected identifier");
6364 superclass = c_parser_peek_token (parser)->value;
6365 c_parser_consume_token (parser);
6368 superclass = NULL_TREE;
6371 tree proto = NULL_TREE;
6372 if (c_parser_next_token_is (parser, CPP_LESS))
6373 proto = c_parser_objc_protocol_refs (parser);
6374 objc_start_class_interface (id1, superclass, proto, attributes);
6377 objc_start_class_implementation (id1, superclass);
6378 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6379 c_parser_objc_class_instance_variables (parser);
6382 objc_continue_interface ();
6383 c_parser_objc_methodprotolist (parser);
6384 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6385 objc_finish_interface ();
6389 objc_continue_implementation ();
6394 /* Parse objc-class-instance-variables.
6396 objc-class-instance-variables:
6397 { objc-instance-variable-decl-list[opt] }
6399 objc-instance-variable-decl-list:
6400 objc-visibility-spec
6401 objc-instance-variable-decl ;
6403 objc-instance-variable-decl-list objc-visibility-spec
6404 objc-instance-variable-decl-list objc-instance-variable-decl ;
6405 objc-instance-variable-decl-list ;
6407 objc-visibility-spec:
6412 objc-instance-variable-decl:
6417 c_parser_objc_class_instance_variables (c_parser *parser)
6419 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6420 c_parser_consume_token (parser);
6421 while (c_parser_next_token_is_not (parser, CPP_EOF))
6424 /* Parse any stray semicolon. */
6425 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6427 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6428 "extra semicolon in struct or union specified");
6429 c_parser_consume_token (parser);
6432 /* Stop if at the end of the instance variables. */
6433 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6435 c_parser_consume_token (parser);
6438 /* Parse any objc-visibility-spec. */
6439 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6441 c_parser_consume_token (parser);
6442 objc_set_visibility (2);
6445 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6447 c_parser_consume_token (parser);
6448 objc_set_visibility (0);
6451 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6453 c_parser_consume_token (parser);
6454 objc_set_visibility (1);
6457 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6459 c_parser_pragma (parser, pragma_external);
6463 /* Parse some comma-separated declarations. */
6464 decls = c_parser_struct_declaration (parser);
6466 /* Comma-separated instance variables are chained together in
6467 reverse order; add them one by one. */
6468 tree ivar = nreverse (decls);
6469 for (; ivar; ivar = DECL_CHAIN (ivar))
6470 objc_add_instance_variable (copy_node (ivar));
6472 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6476 /* Parse an objc-class-declaration.
6478 objc-class-declaration:
6479 @class identifier-list ;
6483 c_parser_objc_class_declaration (c_parser *parser)
6485 tree list = NULL_TREE;
6486 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6487 c_parser_consume_token (parser);
6488 /* Any identifiers, including those declared as type names, are OK
6493 if (c_parser_next_token_is_not (parser, CPP_NAME))
6495 c_parser_error (parser, "expected identifier");
6498 id = c_parser_peek_token (parser)->value;
6499 list = chainon (list, build_tree_list (NULL_TREE, id));
6500 c_parser_consume_token (parser);
6501 if (c_parser_next_token_is (parser, CPP_COMMA))
6502 c_parser_consume_token (parser);
6506 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6507 objc_declare_class (list);
6510 /* Parse an objc-alias-declaration.
6512 objc-alias-declaration:
6513 @compatibility_alias identifier identifier ;
6517 c_parser_objc_alias_declaration (c_parser *parser)
6520 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6521 c_parser_consume_token (parser);
6522 if (c_parser_next_token_is_not (parser, CPP_NAME))
6524 c_parser_error (parser, "expected identifier");
6525 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6528 id1 = c_parser_peek_token (parser)->value;
6529 c_parser_consume_token (parser);
6530 if (c_parser_next_token_is_not (parser, CPP_NAME))
6532 c_parser_error (parser, "expected identifier");
6533 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6536 id2 = c_parser_peek_token (parser)->value;
6537 c_parser_consume_token (parser);
6538 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6539 objc_declare_alias (id1, id2);
6542 /* Parse an objc-protocol-definition.
6544 objc-protocol-definition:
6545 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6546 @protocol identifier-list ;
6548 "@protocol identifier ;" should be resolved as "@protocol
6549 identifier-list ;": objc-methodprotolist may not start with a
6550 semicolon in the first alternative if objc-protocol-refs are
6554 c_parser_objc_protocol_definition (c_parser *parser, tree attributes)
6556 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6558 c_parser_consume_token (parser);
6559 if (c_parser_next_token_is_not (parser, CPP_NAME))
6561 c_parser_error (parser, "expected identifier");
6564 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6565 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6567 tree list = NULL_TREE;
6568 /* Any identifiers, including those declared as type names, are
6573 if (c_parser_next_token_is_not (parser, CPP_NAME))
6575 c_parser_error (parser, "expected identifier");
6578 id = c_parser_peek_token (parser)->value;
6579 list = chainon (list, build_tree_list (NULL_TREE, id));
6580 c_parser_consume_token (parser);
6581 if (c_parser_next_token_is (parser, CPP_COMMA))
6582 c_parser_consume_token (parser);
6586 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6587 objc_declare_protocols (list);
6591 tree id = c_parser_peek_token (parser)->value;
6592 tree proto = NULL_TREE;
6593 c_parser_consume_token (parser);
6594 if (c_parser_next_token_is (parser, CPP_LESS))
6595 proto = c_parser_objc_protocol_refs (parser);
6596 parser->objc_pq_context = true;
6597 objc_start_protocol (id, proto, attributes);
6598 c_parser_objc_methodprotolist (parser);
6599 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6600 parser->objc_pq_context = false;
6601 objc_finish_interface ();
6605 /* Parse an objc-method-type.
6612 static enum tree_code
6613 c_parser_objc_method_type (c_parser *parser)
6615 switch (c_parser_peek_token (parser)->type)
6618 c_parser_consume_token (parser);
6621 c_parser_consume_token (parser);
6628 /* Parse an objc-method-definition.
6630 objc-method-definition:
6631 objc-method-type objc-method-decl ;[opt] compound-statement
6635 c_parser_objc_method_definition (c_parser *parser)
6637 enum tree_code type = c_parser_objc_method_type (parser);
6639 objc_set_method_type (type);
6640 parser->objc_pq_context = true;
6641 decl = c_parser_objc_method_decl (parser);
6642 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6644 c_parser_consume_token (parser);
6645 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6646 "extra semicolon in method definition specified");
6648 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6650 c_parser_error (parser, "expected %<{%>");
6653 parser->objc_pq_context = false;
6654 if (objc_start_method_definition (decl))
6656 add_stmt (c_parser_compound_statement (parser));
6657 objc_finish_method_definition (current_function_decl);
6661 /* This code is executed when we find a method definition
6662 outside of an @implementation context. Parse the method (to
6663 keep going) but do not emit any code.
6665 c_parser_compound_statement (parser);
6669 /* Parse an objc-methodprotolist.
6671 objc-methodprotolist:
6673 objc-methodprotolist objc-methodproto
6674 objc-methodprotolist declaration
6675 objc-methodprotolist ;
6677 The declaration is a data definition, which may be missing
6678 declaration specifiers under the same rules and diagnostics as
6679 other data definitions outside functions, and the stray semicolon
6680 is diagnosed the same way as a stray semicolon outside a
6684 c_parser_objc_methodprotolist (c_parser *parser)
6688 /* The list is terminated by @end. */
6689 switch (c_parser_peek_token (parser)->type)
6692 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6693 "ISO C does not allow extra %<;%> outside of a function");
6694 c_parser_consume_token (parser);
6698 c_parser_objc_methodproto (parser);
6701 c_parser_pragma (parser, pragma_external);
6706 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6708 c_parser_declaration_or_fndef (parser, false, false, true,
6715 /* Parse an objc-methodproto.
6718 objc-method-type objc-method-decl ;
6722 c_parser_objc_methodproto (c_parser *parser)
6724 enum tree_code type = c_parser_objc_method_type (parser);
6726 objc_set_method_type (type);
6727 /* Remember protocol qualifiers in prototypes. */
6728 parser->objc_pq_context = true;
6729 decl = c_parser_objc_method_decl (parser);
6730 /* Forget protocol qualifiers here. */
6731 parser->objc_pq_context = false;
6732 objc_add_method_declaration (decl);
6733 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6736 /* Parse an objc-method-decl.
6739 ( objc-type-name ) objc-selector
6741 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6742 objc-keyword-selector objc-optparmlist
6744 objc-keyword-selector:
6746 objc-keyword-selector objc-keyword-decl
6749 objc-selector : ( objc-type-name ) identifier
6750 objc-selector : identifier
6751 : ( objc-type-name ) identifier
6755 objc-optparms objc-optellipsis
6759 objc-opt-parms , parameter-declaration
6767 c_parser_objc_method_decl (c_parser *parser)
6769 tree type = NULL_TREE;
6771 tree parms = NULL_TREE;
6772 bool ellipsis = false;
6774 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6776 c_parser_consume_token (parser);
6777 type = c_parser_objc_type_name (parser);
6778 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6780 sel = c_parser_objc_selector (parser);
6781 /* If there is no selector, or a colon follows, we have an
6782 objc-keyword-selector. If there is a selector, and a colon does
6783 not follow, that selector ends the objc-method-decl. */
6784 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6787 tree list = NULL_TREE;
6790 tree atype = NULL_TREE, id, keyworddecl;
6791 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6793 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6795 c_parser_consume_token (parser);
6796 atype = c_parser_objc_type_name (parser);
6797 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6800 if (c_parser_next_token_is_not (parser, CPP_NAME))
6802 c_parser_error (parser, "expected identifier");
6803 return error_mark_node;
6805 id = c_parser_peek_token (parser)->value;
6806 c_parser_consume_token (parser);
6807 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6808 list = chainon (list, keyworddecl);
6809 tsel = c_parser_objc_selector (parser);
6810 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6813 /* Parse the optional parameter list. Optional Objective-C
6814 method parameters follow the C syntax, and may include '...'
6815 to denote a variable number of arguments. */
6816 parms = make_node (TREE_LIST);
6817 while (c_parser_next_token_is (parser, CPP_COMMA))
6819 struct c_parm *parm;
6820 c_parser_consume_token (parser);
6821 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6824 c_parser_consume_token (parser);
6827 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6830 parms = chainon (parms,
6831 build_tree_list (NULL_TREE, grokparm (parm)));
6835 return objc_build_method_signature (type, sel, parms, ellipsis);
6838 /* Parse an objc-type-name.
6841 objc-type-qualifiers[opt] type-name
6842 objc-type-qualifiers[opt]
6844 objc-type-qualifiers:
6846 objc-type-qualifiers objc-type-qualifier
6848 objc-type-qualifier: one of
6849 in out inout bycopy byref oneway
6853 c_parser_objc_type_name (c_parser *parser)
6855 tree quals = NULL_TREE;
6856 struct c_type_name *type_name = NULL;
6857 tree type = NULL_TREE;
6860 c_token *token = c_parser_peek_token (parser);
6861 if (token->type == CPP_KEYWORD
6862 && (token->keyword == RID_IN
6863 || token->keyword == RID_OUT
6864 || token->keyword == RID_INOUT
6865 || token->keyword == RID_BYCOPY
6866 || token->keyword == RID_BYREF
6867 || token->keyword == RID_ONEWAY))
6869 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6870 c_parser_consume_token (parser);
6875 if (c_parser_next_token_starts_typename (parser))
6876 type_name = c_parser_type_name (parser);
6878 type = groktypename (type_name, NULL, NULL);
6879 return build_tree_list (quals, type);
6882 /* Parse objc-protocol-refs.
6889 c_parser_objc_protocol_refs (c_parser *parser)
6891 tree list = NULL_TREE;
6892 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6893 c_parser_consume_token (parser);
6894 /* Any identifiers, including those declared as type names, are OK
6899 if (c_parser_next_token_is_not (parser, CPP_NAME))
6901 c_parser_error (parser, "expected identifier");
6904 id = c_parser_peek_token (parser)->value;
6905 list = chainon (list, build_tree_list (NULL_TREE, id));
6906 c_parser_consume_token (parser);
6907 if (c_parser_next_token_is (parser, CPP_COMMA))
6908 c_parser_consume_token (parser);
6912 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6916 /* Parse an objc-try-catch-statement.
6918 objc-try-catch-statement:
6919 @try compound-statement objc-catch-list[opt]
6920 @try compound-statement objc-catch-list[opt] @finally compound-statement
6923 @catch ( parameter-declaration ) compound-statement
6924 objc-catch-list @catch ( parameter-declaration ) compound-statement
6928 c_parser_objc_try_catch_statement (c_parser *parser)
6932 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6933 c_parser_consume_token (parser);
6934 loc = c_parser_peek_token (parser)->location;
6935 stmt = c_parser_compound_statement (parser);
6936 objc_begin_try_stmt (loc, stmt);
6937 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6939 struct c_parm *parm;
6940 c_parser_consume_token (parser);
6941 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6943 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6946 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6949 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6950 objc_begin_catch_clause (grokparm (parm));
6951 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6952 c_parser_compound_statement_nostart (parser);
6953 objc_finish_catch_clause ();
6955 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6959 c_parser_consume_token (parser);
6960 finloc = c_parser_peek_token (parser)->location;
6961 finstmt = c_parser_compound_statement (parser);
6962 objc_build_finally_clause (finloc, finstmt);
6964 objc_finish_try_stmt ();
6967 /* Parse an objc-synchronized-statement.
6969 objc-synchronized-statement:
6970 @synchronized ( expression ) compound-statement
6974 c_parser_objc_synchronized_statement (c_parser *parser)
6978 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6979 c_parser_consume_token (parser);
6980 loc = c_parser_peek_token (parser)->location;
6981 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6983 expr = c_parser_expression (parser).value;
6984 expr = c_fully_fold (expr, false, NULL);
6985 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6988 expr = error_mark_node;
6989 stmt = c_parser_compound_statement (parser);
6990 objc_build_synchronized (loc, expr, stmt);
6993 /* Parse an objc-selector; return NULL_TREE without an error if the
6994 next token is not an objc-selector.
6999 enum struct union if else while do for switch case default
7000 break continue return goto asm sizeof typeof __alignof
7001 unsigned long const short volatile signed restrict _Complex
7002 in out inout bycopy byref oneway int char float double void _Bool
7004 ??? Why this selection of keywords but not, for example, storage
7005 class specifiers? */
7008 c_parser_objc_selector (c_parser *parser)
7010 c_token *token = c_parser_peek_token (parser);
7011 tree value = token->value;
7012 if (token->type == CPP_NAME)
7014 c_parser_consume_token (parser);
7017 if (token->type != CPP_KEYWORD)
7019 switch (token->keyword)
7061 c_parser_consume_token (parser);
7068 /* Parse an objc-selector-arg.
7072 objc-keywordname-list
7074 objc-keywordname-list:
7076 objc-keywordname-list objc-keywordname
7084 c_parser_objc_selector_arg (c_parser *parser)
7086 tree sel = c_parser_objc_selector (parser);
7087 tree list = NULL_TREE;
7088 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7092 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7094 list = chainon (list, build_tree_list (sel, NULL_TREE));
7095 sel = c_parser_objc_selector (parser);
7096 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7102 /* Parse an objc-receiver.
7111 c_parser_objc_receiver (c_parser *parser)
7113 if (c_parser_peek_token (parser)->type == CPP_NAME
7114 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
7115 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
7117 tree id = c_parser_peek_token (parser)->value;
7118 c_parser_consume_token (parser);
7119 return objc_get_class_reference (id);
7121 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
7124 /* Parse objc-message-args.
7128 objc-keywordarg-list
7130 objc-keywordarg-list:
7132 objc-keywordarg-list objc-keywordarg
7135 objc-selector : objc-keywordexpr
7140 c_parser_objc_message_args (c_parser *parser)
7142 tree sel = c_parser_objc_selector (parser);
7143 tree list = NULL_TREE;
7144 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
7149 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7150 return error_mark_node;
7151 keywordexpr = c_parser_objc_keywordexpr (parser);
7152 list = chainon (list, build_tree_list (sel, keywordexpr));
7153 sel = c_parser_objc_selector (parser);
7154 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
7160 /* Parse an objc-keywordexpr.
7167 c_parser_objc_keywordexpr (c_parser *parser)
7170 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
7171 if (VEC_length (tree, expr_list) == 1)
7173 /* Just return the expression, remove a level of
7175 ret = VEC_index (tree, expr_list, 0);
7179 /* We have a comma expression, we will collapse later. */
7180 ret = build_tree_list_vec (expr_list);
7182 release_tree_vector (expr_list);
7186 /* A check, needed in several places, that ObjC interface, implementation or
7187 method definitions are not prefixed by incorrect items. */
7189 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser,
7190 struct c_declspecs *specs)
7192 if (!specs->declspecs_seen_p || specs->type_seen_p || specs->non_sc_seen_p)
7194 c_parser_error (parser,
7195 "no type or storage class may be specified here,");
7196 c_parser_skip_to_end_of_block_or_statement (parser);
7202 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7203 should be considered, statements. ALLOW_STMT is true if we're within
7204 the context of a function and such pragmas are to be allowed. Returns
7205 true if we actually parsed such a pragma. */
7208 c_parser_pragma (c_parser *parser, enum pragma_context context)
7212 id = c_parser_peek_token (parser)->pragma_kind;
7213 gcc_assert (id != PRAGMA_NONE);
7217 case PRAGMA_OMP_BARRIER:
7218 if (context != pragma_compound)
7220 if (context == pragma_stmt)
7221 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7222 "used in compound statements");
7225 c_parser_omp_barrier (parser);
7228 case PRAGMA_OMP_FLUSH:
7229 if (context != pragma_compound)
7231 if (context == pragma_stmt)
7232 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7233 "used in compound statements");
7236 c_parser_omp_flush (parser);
7239 case PRAGMA_OMP_TASKWAIT:
7240 if (context != pragma_compound)
7242 if (context == pragma_stmt)
7243 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7244 "used in compound statements");
7247 c_parser_omp_taskwait (parser);
7250 case PRAGMA_OMP_THREADPRIVATE:
7251 c_parser_omp_threadprivate (parser);
7254 case PRAGMA_OMP_SECTION:
7255 error_at (c_parser_peek_token (parser)->location,
7256 "%<#pragma omp section%> may only be used in "
7257 "%<#pragma omp sections%> construct");
7258 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7261 case PRAGMA_GCC_PCH_PREPROCESS:
7262 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7263 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7267 if (id < PRAGMA_FIRST_EXTERNAL)
7269 if (context == pragma_external)
7272 c_parser_error (parser, "expected declaration specifiers");
7273 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7276 c_parser_omp_construct (parser);
7282 c_parser_consume_pragma (parser);
7283 c_invoke_pragma_handler (id);
7285 /* Skip to EOL, but suppress any error message. Those will have been
7286 generated by the handler routine through calling error, as opposed
7287 to calling c_parser_error. */
7288 parser->error = true;
7289 c_parser_skip_to_pragma_eol (parser);
7294 /* The interface the pragma parsers have to the lexer. */
7297 pragma_lex (tree *value)
7299 c_token *tok = c_parser_peek_token (the_parser);
7300 enum cpp_ttype ret = tok->type;
7302 *value = tok->value;
7303 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7307 if (ret == CPP_KEYWORD)
7309 c_parser_consume_token (the_parser);
7316 c_parser_pragma_pch_preprocess (c_parser *parser)
7320 c_parser_consume_pragma (parser);
7321 if (c_parser_next_token_is (parser, CPP_STRING))
7323 name = c_parser_peek_token (parser)->value;
7324 c_parser_consume_token (parser);
7327 c_parser_error (parser, "expected string literal");
7328 c_parser_skip_to_pragma_eol (parser);
7331 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7334 /* OpenMP 2.5 parsing routines. */
7336 /* Returns name of the next clause.
7337 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7338 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7339 returned and the token is consumed. */
7341 static pragma_omp_clause
7342 c_parser_omp_clause_name (c_parser *parser)
7344 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7346 if (c_parser_next_token_is_keyword (parser, RID_IF))
7347 result = PRAGMA_OMP_CLAUSE_IF;
7348 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7349 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7350 else if (c_parser_next_token_is (parser, CPP_NAME))
7352 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7357 if (!strcmp ("collapse", p))
7358 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7359 else if (!strcmp ("copyin", p))
7360 result = PRAGMA_OMP_CLAUSE_COPYIN;
7361 else if (!strcmp ("copyprivate", p))
7362 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7365 if (!strcmp ("firstprivate", p))
7366 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7369 if (!strcmp ("lastprivate", p))
7370 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7373 if (!strcmp ("nowait", p))
7374 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7375 else if (!strcmp ("num_threads", p))
7376 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7379 if (!strcmp ("ordered", p))
7380 result = PRAGMA_OMP_CLAUSE_ORDERED;
7383 if (!strcmp ("private", p))
7384 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7387 if (!strcmp ("reduction", p))
7388 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7391 if (!strcmp ("schedule", p))
7392 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7393 else if (!strcmp ("shared", p))
7394 result = PRAGMA_OMP_CLAUSE_SHARED;
7397 if (!strcmp ("untied", p))
7398 result = PRAGMA_OMP_CLAUSE_UNTIED;
7403 if (result != PRAGMA_OMP_CLAUSE_NONE)
7404 c_parser_consume_token (parser);
7409 /* Validate that a clause of the given type does not already exist. */
7412 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7417 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7418 if (OMP_CLAUSE_CODE (c) == code)
7420 location_t loc = OMP_CLAUSE_LOCATION (c);
7421 error_at (loc, "too many %qs clauses", name);
7429 variable-list , identifier
7431 If KIND is nonzero, create the appropriate node and install the
7432 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7433 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7435 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7436 return the list created. */
7439 c_parser_omp_variable_list (c_parser *parser,
7440 location_t clause_loc,
7441 enum omp_clause_code kind,
7444 if (c_parser_next_token_is_not (parser, CPP_NAME)
7445 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7446 c_parser_error (parser, "expected identifier");
7448 while (c_parser_next_token_is (parser, CPP_NAME)
7449 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7451 tree t = lookup_name (c_parser_peek_token (parser)->value);
7454 undeclared_variable (c_parser_peek_token (parser)->location,
7455 c_parser_peek_token (parser)->value);
7456 else if (t == error_mark_node)
7460 tree u = build_omp_clause (clause_loc, kind);
7461 OMP_CLAUSE_DECL (u) = t;
7462 OMP_CLAUSE_CHAIN (u) = list;
7466 list = tree_cons (t, NULL_TREE, list);
7468 c_parser_consume_token (parser);
7470 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7473 c_parser_consume_token (parser);
7479 /* Similarly, but expect leading and trailing parenthesis. This is a very
7480 common case for omp clauses. */
7483 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7486 /* The clauses location. */
7487 location_t loc = c_parser_peek_token (parser)->location;
7489 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7491 list = c_parser_omp_variable_list (parser, loc, kind, list);
7492 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7498 collapse ( constant-expression ) */
7501 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7503 tree c, num = error_mark_node;
7507 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7509 loc = c_parser_peek_token (parser)->location;
7510 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7512 num = c_parser_expr_no_commas (parser, NULL).value;
7513 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7515 if (num == error_mark_node)
7517 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7518 || !host_integerp (num, 0)
7519 || (n = tree_low_cst (num, 0)) <= 0
7523 "collapse argument needs positive constant integer expression");
7526 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7527 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7528 OMP_CLAUSE_CHAIN (c) = list;
7533 copyin ( variable-list ) */
7536 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7538 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7542 copyprivate ( variable-list ) */
7545 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7547 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7551 default ( shared | none ) */
7554 c_parser_omp_clause_default (c_parser *parser, tree list)
7556 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7557 location_t loc = c_parser_peek_token (parser)->location;
7560 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7562 if (c_parser_next_token_is (parser, CPP_NAME))
7564 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7569 if (strcmp ("none", p) != 0)
7571 kind = OMP_CLAUSE_DEFAULT_NONE;
7575 if (strcmp ("shared", p) != 0)
7577 kind = OMP_CLAUSE_DEFAULT_SHARED;
7584 c_parser_consume_token (parser);
7589 c_parser_error (parser, "expected %<none%> or %<shared%>");
7591 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7593 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7596 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7597 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7598 OMP_CLAUSE_CHAIN (c) = list;
7599 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7605 firstprivate ( variable-list ) */
7608 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7610 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7614 if ( expression ) */
7617 c_parser_omp_clause_if (c_parser *parser, tree list)
7619 location_t loc = c_parser_peek_token (parser)->location;
7620 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7622 tree t = c_parser_paren_condition (parser);
7625 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7627 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7628 OMP_CLAUSE_IF_EXPR (c) = t;
7629 OMP_CLAUSE_CHAIN (c) = list;
7633 c_parser_error (parser, "expected %<(%>");
7639 lastprivate ( variable-list ) */
7642 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7644 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7651 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7654 location_t loc = c_parser_peek_token (parser)->location;
7656 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7658 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7659 OMP_CLAUSE_CHAIN (c) = list;
7664 num_threads ( expression ) */
7667 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7669 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7670 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7672 location_t expr_loc = c_parser_peek_token (parser)->location;
7673 tree c, t = c_parser_expression (parser).value;
7674 t = c_fully_fold (t, false, NULL);
7676 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7678 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7680 c_parser_error (parser, "expected integer expression");
7684 /* Attempt to statically determine when the number isn't positive. */
7685 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7686 build_int_cst (TREE_TYPE (t), 0));
7687 if (CAN_HAVE_LOCATION_P (c))
7688 SET_EXPR_LOCATION (c, expr_loc);
7689 if (c == boolean_true_node)
7691 warning_at (expr_loc, 0,
7692 "%<num_threads%> value must be positive");
7693 t = integer_one_node;
7696 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7698 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7699 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7700 OMP_CLAUSE_CHAIN (c) = list;
7711 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7715 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7717 c = build_omp_clause (c_parser_peek_token (parser)->location,
7718 OMP_CLAUSE_ORDERED);
7719 OMP_CLAUSE_CHAIN (c) = list;
7725 private ( variable-list ) */
7728 c_parser_omp_clause_private (c_parser *parser, tree list)
7730 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7734 reduction ( reduction-operator : variable-list )
7737 One of: + * - & ^ | && || */
7740 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7742 location_t clause_loc = c_parser_peek_token (parser)->location;
7743 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7745 enum tree_code code;
7747 switch (c_parser_peek_token (parser)->type)
7759 code = BIT_AND_EXPR;
7762 code = BIT_XOR_EXPR;
7765 code = BIT_IOR_EXPR;
7768 code = TRUTH_ANDIF_EXPR;
7771 code = TRUTH_ORIF_EXPR;
7774 c_parser_error (parser,
7775 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7776 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7777 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7780 c_parser_consume_token (parser);
7781 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7785 nl = c_parser_omp_variable_list (parser, clause_loc,
7786 OMP_CLAUSE_REDUCTION, list);
7787 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7788 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7792 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7798 schedule ( schedule-kind )
7799 schedule ( schedule-kind , expression )
7802 static | dynamic | guided | runtime | auto
7806 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7809 location_t loc = c_parser_peek_token (parser)->location;
7811 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7814 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7816 if (c_parser_next_token_is (parser, CPP_NAME))
7818 tree kind = c_parser_peek_token (parser)->value;
7819 const char *p = IDENTIFIER_POINTER (kind);
7824 if (strcmp ("dynamic", p) != 0)
7826 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7830 if (strcmp ("guided", p) != 0)
7832 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7836 if (strcmp ("runtime", p) != 0)
7838 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7845 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7846 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7847 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7848 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7852 c_parser_consume_token (parser);
7853 if (c_parser_next_token_is (parser, CPP_COMMA))
7856 c_parser_consume_token (parser);
7858 here = c_parser_peek_token (parser)->location;
7859 t = c_parser_expr_no_commas (parser, NULL).value;
7860 t = c_fully_fold (t, false, NULL);
7862 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7863 error_at (here, "schedule %<runtime%> does not take "
7864 "a %<chunk_size%> parameter");
7865 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7867 "schedule %<auto%> does not take "
7868 "a %<chunk_size%> parameter");
7869 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7870 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7872 c_parser_error (parser, "expected integer expression");
7874 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7877 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7878 "expected %<,%> or %<)%>");
7880 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7881 OMP_CLAUSE_CHAIN (c) = list;
7885 c_parser_error (parser, "invalid schedule kind");
7886 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7891 shared ( variable-list ) */
7894 c_parser_omp_clause_shared (c_parser *parser, tree list)
7896 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7903 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7907 /* FIXME: Should we allow duplicates? */
7908 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7910 c = build_omp_clause (c_parser_peek_token (parser)->location,
7912 OMP_CLAUSE_CHAIN (c) = list;
7917 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7918 is a bitmask in MASK. Return the list of clauses found; the result
7919 of clause default goes in *pdefault. */
7922 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7925 tree clauses = NULL;
7928 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7931 pragma_omp_clause c_kind;
7933 tree prev = clauses;
7935 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7936 c_parser_consume_token (parser);
7939 here = c_parser_peek_token (parser)->location;
7940 c_kind = c_parser_omp_clause_name (parser);
7944 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7945 clauses = c_parser_omp_clause_collapse (parser, clauses);
7946 c_name = "collapse";
7948 case PRAGMA_OMP_CLAUSE_COPYIN:
7949 clauses = c_parser_omp_clause_copyin (parser, clauses);
7952 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7953 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7954 c_name = "copyprivate";
7956 case PRAGMA_OMP_CLAUSE_DEFAULT:
7957 clauses = c_parser_omp_clause_default (parser, clauses);
7960 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7961 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7962 c_name = "firstprivate";
7964 case PRAGMA_OMP_CLAUSE_IF:
7965 clauses = c_parser_omp_clause_if (parser, clauses);
7968 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7969 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7970 c_name = "lastprivate";
7972 case PRAGMA_OMP_CLAUSE_NOWAIT:
7973 clauses = c_parser_omp_clause_nowait (parser, clauses);
7976 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7977 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7978 c_name = "num_threads";
7980 case PRAGMA_OMP_CLAUSE_ORDERED:
7981 clauses = c_parser_omp_clause_ordered (parser, clauses);
7984 case PRAGMA_OMP_CLAUSE_PRIVATE:
7985 clauses = c_parser_omp_clause_private (parser, clauses);
7988 case PRAGMA_OMP_CLAUSE_REDUCTION:
7989 clauses = c_parser_omp_clause_reduction (parser, clauses);
7990 c_name = "reduction";
7992 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7993 clauses = c_parser_omp_clause_schedule (parser, clauses);
7994 c_name = "schedule";
7996 case PRAGMA_OMP_CLAUSE_SHARED:
7997 clauses = c_parser_omp_clause_shared (parser, clauses);
8000 case PRAGMA_OMP_CLAUSE_UNTIED:
8001 clauses = c_parser_omp_clause_untied (parser, clauses);
8005 c_parser_error (parser, "expected %<#pragma omp%> clause");
8009 if (((mask >> c_kind) & 1) == 0 && !parser->error)
8011 /* Remove the invalid clause(s) from the list to avoid
8012 confusing the rest of the compiler. */
8014 error_at (here, "%qs is not valid for %qs", c_name, where);
8019 c_parser_skip_to_pragma_eol (parser);
8021 return c_finish_omp_clauses (clauses);
8028 In practice, we're also interested in adding the statement to an
8029 outer node. So it is convenient if we work around the fact that
8030 c_parser_statement calls add_stmt. */
8033 c_parser_omp_structured_block (c_parser *parser)
8035 tree stmt = push_stmt_list ();
8036 c_parser_statement (parser);
8037 return pop_stmt_list (stmt);
8041 # pragma omp atomic new-line
8045 x binop= expr | x++ | ++x | x-- | --x
8047 +, *, -, /, &, ^, |, <<, >>
8049 where x is an lvalue expression with scalar type.
8051 LOC is the location of the #pragma token. */
8054 c_parser_omp_atomic (location_t loc, c_parser *parser)
8058 enum tree_code code;
8059 struct c_expr rhs_expr;
8061 c_parser_skip_to_pragma_eol (parser);
8063 lhs = c_parser_unary_expression (parser).value;
8064 lhs = c_fully_fold (lhs, false, NULL);
8065 switch (TREE_CODE (lhs))
8069 c_parser_skip_to_end_of_block_or_statement (parser);
8072 case PREINCREMENT_EXPR:
8073 case POSTINCREMENT_EXPR:
8074 lhs = TREE_OPERAND (lhs, 0);
8076 rhs = integer_one_node;
8079 case PREDECREMENT_EXPR:
8080 case POSTDECREMENT_EXPR:
8081 lhs = TREE_OPERAND (lhs, 0);
8083 rhs = integer_one_node;
8087 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
8088 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
8089 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
8090 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
8091 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8092 (TREE_OPERAND (lhs, 1), 0), 0)))
8094 /* Undo effects of boolean_increment for post {in,de}crement. */
8095 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
8098 if (TREE_CODE (lhs) == MODIFY_EXPR
8099 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
8101 /* Undo effects of boolean_increment. */
8102 if (integer_onep (TREE_OPERAND (lhs, 1)))
8104 /* This is pre or post increment. */
8105 rhs = TREE_OPERAND (lhs, 1);
8106 lhs = TREE_OPERAND (lhs, 0);
8110 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
8111 && TREE_OPERAND (lhs, 0)
8112 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
8114 /* This is pre or post decrement. */
8115 rhs = TREE_OPERAND (lhs, 1);
8116 lhs = TREE_OPERAND (lhs, 0);
8123 switch (c_parser_peek_token (parser)->type)
8129 code = TRUNC_DIV_EXPR;
8144 code = BIT_AND_EXPR;
8147 code = BIT_IOR_EXPR;
8150 code = BIT_XOR_EXPR;
8153 c_parser_error (parser,
8154 "invalid operator for %<#pragma omp atomic%>");
8158 c_parser_consume_token (parser);
8160 location_t rhs_loc = c_parser_peek_token (parser)->location;
8161 rhs_expr = c_parser_expression (parser);
8162 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
8164 rhs = rhs_expr.value;
8165 rhs = c_fully_fold (rhs, false, NULL);
8168 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
8169 if (stmt != error_mark_node)
8171 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8176 # pragma omp barrier new-line
8180 c_parser_omp_barrier (c_parser *parser)
8182 location_t loc = c_parser_peek_token (parser)->location;
8183 c_parser_consume_pragma (parser);
8184 c_parser_skip_to_pragma_eol (parser);
8186 c_finish_omp_barrier (loc);
8190 # pragma omp critical [(name)] new-line
8193 LOC is the location of the #pragma itself. */
8196 c_parser_omp_critical (location_t loc, c_parser *parser)
8198 tree stmt, name = NULL;
8200 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8202 c_parser_consume_token (parser);
8203 if (c_parser_next_token_is (parser, CPP_NAME))
8205 name = c_parser_peek_token (parser)->value;
8206 c_parser_consume_token (parser);
8207 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8210 c_parser_error (parser, "expected identifier");
8212 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8213 c_parser_error (parser, "expected %<(%> or end of line");
8214 c_parser_skip_to_pragma_eol (parser);
8216 stmt = c_parser_omp_structured_block (parser);
8217 return c_finish_omp_critical (loc, stmt, name);
8221 # pragma omp flush flush-vars[opt] new-line
8224 ( variable-list ) */
8227 c_parser_omp_flush (c_parser *parser)
8229 location_t loc = c_parser_peek_token (parser)->location;
8230 c_parser_consume_pragma (parser);
8231 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
8232 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8233 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
8234 c_parser_error (parser, "expected %<(%> or end of line");
8235 c_parser_skip_to_pragma_eol (parser);
8237 c_finish_omp_flush (loc);
8240 /* Parse the restricted form of the for statement allowed by OpenMP.
8241 The real trick here is to determine the loop control variable early
8242 so that we can push a new decl if necessary to make it private.
8243 LOC is the location of the OMP in "#pragma omp". */
8246 c_parser_omp_for_loop (location_t loc,
8247 c_parser *parser, tree clauses, tree *par_clauses)
8249 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8250 tree declv, condv, incrv, initv, ret = NULL;
8251 bool fail = false, open_brace_parsed = false;
8252 int i, collapse = 1, nbraces = 0;
8254 VEC(tree,gc) *for_block = make_tree_vector ();
8256 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8257 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8258 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8260 gcc_assert (collapse >= 1);
8262 declv = make_tree_vec (collapse);
8263 initv = make_tree_vec (collapse);
8264 condv = make_tree_vec (collapse);
8265 incrv = make_tree_vec (collapse);
8267 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8269 c_parser_error (parser, "for statement expected");
8272 for_loc = c_parser_peek_token (parser)->location;
8273 c_parser_consume_token (parser);
8275 for (i = 0; i < collapse; i++)
8279 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8282 /* Parse the initialization declaration or expression. */
8283 if (c_parser_next_token_starts_declaration (parser))
8286 VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
8287 c_parser_declaration_or_fndef (parser, true, true, true, true, true);
8288 decl = check_for_loop_decls (for_loc);
8291 if (DECL_INITIAL (decl) == error_mark_node)
8292 decl = error_mark_node;
8295 else if (c_parser_next_token_is (parser, CPP_NAME)
8296 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8298 struct c_expr decl_exp;
8299 struct c_expr init_exp;
8300 location_t init_loc;
8302 decl_exp = c_parser_postfix_expression (parser);
8303 decl = decl_exp.value;
8305 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8307 init_loc = c_parser_peek_token (parser)->location;
8308 init_exp = c_parser_expr_no_commas (parser, NULL);
8309 init_exp = default_function_array_read_conversion (init_loc,
8311 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8312 NOP_EXPR, init_loc, init_exp.value,
8313 init_exp.original_type);
8314 init = c_process_expr_stmt (init_loc, init);
8316 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8321 c_parser_error (parser,
8322 "expected iteration declaration or initialization");
8323 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8329 /* Parse the loop condition. */
8331 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8333 location_t cond_loc = c_parser_peek_token (parser)->location;
8334 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8336 cond = cond_expr.value;
8337 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8338 cond = c_fully_fold (cond, false, NULL);
8339 switch (cond_expr.original_code)
8347 /* Can't be cond = error_mark_node, because we want to preserve
8348 the location until c_finish_omp_for. */
8349 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8352 protected_set_expr_location (cond, cond_loc);
8354 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8356 /* Parse the increment expression. */
8358 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8360 location_t incr_loc = c_parser_peek_token (parser)->location;
8362 incr = c_process_expr_stmt (incr_loc,
8363 c_parser_expression (parser).value);
8365 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8367 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8371 TREE_VEC_ELT (declv, i) = decl;
8372 TREE_VEC_ELT (initv, i) = init;
8373 TREE_VEC_ELT (condv, i) = cond;
8374 TREE_VEC_ELT (incrv, i) = incr;
8378 if (i == collapse - 1)
8381 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8382 in between the collapsed for loops to be still considered perfectly
8383 nested. Hopefully the final version clarifies this.
8384 For now handle (multiple) {'s and empty statements. */
8387 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8389 c_parser_consume_token (parser);
8392 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8394 c_parser_consume_token (parser);
8398 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8399 c_parser_consume_token (parser);
8402 c_parser_error (parser, "not enough perfectly nested loops");
8405 open_brace_parsed = true;
8415 nbraces += bracecount;
8418 save_break = c_break_label;
8419 c_break_label = size_one_node;
8420 save_cont = c_cont_label;
8421 c_cont_label = NULL_TREE;
8422 body = push_stmt_list ();
8424 if (open_brace_parsed)
8426 location_t here = c_parser_peek_token (parser)->location;
8427 stmt = c_begin_compound_stmt (true);
8428 c_parser_compound_statement_nostart (parser);
8429 add_stmt (c_end_compound_stmt (here, stmt, true));
8432 add_stmt (c_parser_c99_block_statement (parser));
8435 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8436 SET_EXPR_LOCATION (t, loc);
8440 body = pop_stmt_list (body);
8441 c_break_label = save_break;
8442 c_cont_label = save_cont;
8446 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8448 c_parser_consume_token (parser);
8451 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8452 c_parser_consume_token (parser);
8455 c_parser_error (parser, "collapsed loops not perfectly nested");
8458 location_t here = c_parser_peek_token (parser)->location;
8459 stmt = c_begin_compound_stmt (true);
8461 c_parser_compound_statement_nostart (parser);
8462 body = c_end_compound_stmt (here, stmt, true);
8469 /* Only bother calling c_finish_omp_for if we haven't already generated
8470 an error from the initialization parsing. */
8473 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8476 if (par_clauses != NULL)
8479 for (c = par_clauses; *c ; )
8480 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8481 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8482 c = &OMP_CLAUSE_CHAIN (*c);
8485 for (i = 0; i < collapse; i++)
8486 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8489 c = &OMP_CLAUSE_CHAIN (*c);
8490 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8493 "iteration variable %qD should not be firstprivate",
8494 OMP_CLAUSE_DECL (*c));
8495 *c = OMP_CLAUSE_CHAIN (*c);
8499 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8500 change it to shared (decl) in
8501 OMP_PARALLEL_CLAUSES. */
8502 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8503 OMP_CLAUSE_LASTPRIVATE);
8504 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8505 OMP_CLAUSE_CHAIN (l) = clauses;
8507 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8511 OMP_FOR_CLAUSES (stmt) = clauses;
8516 while (!VEC_empty (tree, for_block))
8518 /* FIXME diagnostics: LOC below should be the actual location of
8519 this particular for block. We need to build a list of
8520 locations to go along with FOR_BLOCK. */
8521 stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
8524 release_tree_vector (for_block);
8529 #pragma omp for for-clause[optseq] new-line
8532 LOC is the location of the #pragma token.
8535 #define OMP_FOR_CLAUSE_MASK \
8536 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8537 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8538 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8539 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8540 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8541 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8542 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8543 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8546 c_parser_omp_for (location_t loc, c_parser *parser)
8548 tree block, clauses, ret;
8550 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8553 block = c_begin_compound_stmt (true);
8554 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8555 block = c_end_compound_stmt (loc, block, true);
8562 # pragma omp master new-line
8565 LOC is the location of the #pragma token.
8569 c_parser_omp_master (location_t loc, c_parser *parser)
8571 c_parser_skip_to_pragma_eol (parser);
8572 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8576 # pragma omp ordered new-line
8579 LOC is the location of the #pragma itself.
8583 c_parser_omp_ordered (location_t loc, c_parser *parser)
8585 c_parser_skip_to_pragma_eol (parser);
8586 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8592 { section-sequence }
8595 section-directive[opt] structured-block
8596 section-sequence section-directive structured-block
8598 SECTIONS_LOC is the location of the #pragma omp sections. */
8601 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8604 bool error_suppress = false;
8607 loc = c_parser_peek_token (parser)->location;
8608 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8610 /* Avoid skipping until the end of the block. */
8611 parser->error = false;
8615 stmt = push_stmt_list ();
8617 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8619 substmt = push_stmt_list ();
8623 c_parser_statement (parser);
8625 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8627 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8629 if (c_parser_next_token_is (parser, CPP_EOF))
8633 substmt = pop_stmt_list (substmt);
8634 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8635 SET_EXPR_LOCATION (substmt, loc);
8641 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8643 if (c_parser_next_token_is (parser, CPP_EOF))
8646 loc = c_parser_peek_token (parser)->location;
8647 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8649 c_parser_consume_pragma (parser);
8650 c_parser_skip_to_pragma_eol (parser);
8651 error_suppress = false;
8653 else if (!error_suppress)
8655 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8656 error_suppress = true;
8659 substmt = c_parser_omp_structured_block (parser);
8660 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8661 SET_EXPR_LOCATION (substmt, loc);
8664 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8665 "expected %<#pragma omp section%> or %<}%>");
8667 substmt = pop_stmt_list (stmt);
8669 stmt = make_node (OMP_SECTIONS);
8670 SET_EXPR_LOCATION (stmt, sections_loc);
8671 TREE_TYPE (stmt) = void_type_node;
8672 OMP_SECTIONS_BODY (stmt) = substmt;
8674 return add_stmt (stmt);
8678 # pragma omp sections sections-clause[optseq] newline
8681 LOC is the location of the #pragma token.
8684 #define OMP_SECTIONS_CLAUSE_MASK \
8685 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8686 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8687 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8688 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8689 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8692 c_parser_omp_sections (location_t loc, c_parser *parser)
8694 tree block, clauses, ret;
8696 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8697 "#pragma omp sections");
8699 block = c_begin_compound_stmt (true);
8700 ret = c_parser_omp_sections_scope (loc, parser);
8702 OMP_SECTIONS_CLAUSES (ret) = clauses;
8703 block = c_end_compound_stmt (loc, block, true);
8710 # pragma parallel parallel-clause new-line
8711 # pragma parallel for parallel-for-clause new-line
8712 # pragma parallel sections parallel-sections-clause new-line
8714 LOC is the location of the #pragma token.
8717 #define OMP_PARALLEL_CLAUSE_MASK \
8718 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8719 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8720 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8721 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8722 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8723 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8724 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8725 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8728 c_parser_omp_parallel (location_t loc, c_parser *parser)
8730 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8731 const char *p_name = "#pragma omp parallel";
8732 tree stmt, clauses, par_clause, ws_clause, block;
8733 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8735 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8737 c_parser_consume_token (parser);
8738 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8739 p_name = "#pragma omp parallel for";
8740 mask |= OMP_FOR_CLAUSE_MASK;
8741 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8743 else if (c_parser_next_token_is (parser, CPP_NAME))
8745 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8746 if (strcmp (p, "sections") == 0)
8748 c_parser_consume_token (parser);
8749 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8750 p_name = "#pragma omp parallel sections";
8751 mask |= OMP_SECTIONS_CLAUSE_MASK;
8752 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8756 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8760 case PRAGMA_OMP_PARALLEL:
8761 block = c_begin_omp_parallel ();
8762 c_parser_statement (parser);
8763 stmt = c_finish_omp_parallel (loc, clauses, block);
8766 case PRAGMA_OMP_PARALLEL_FOR:
8767 block = c_begin_omp_parallel ();
8768 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8769 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8770 stmt = c_finish_omp_parallel (loc, par_clause, block);
8771 OMP_PARALLEL_COMBINED (stmt) = 1;
8774 case PRAGMA_OMP_PARALLEL_SECTIONS:
8775 block = c_begin_omp_parallel ();
8776 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8777 stmt = c_parser_omp_sections_scope (loc, parser);
8779 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8780 stmt = c_finish_omp_parallel (loc, par_clause, block);
8781 OMP_PARALLEL_COMBINED (stmt) = 1;
8792 # pragma omp single single-clause[optseq] new-line
8795 LOC is the location of the #pragma.
8798 #define OMP_SINGLE_CLAUSE_MASK \
8799 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8800 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8801 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8802 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8805 c_parser_omp_single (location_t loc, c_parser *parser)
8807 tree stmt = make_node (OMP_SINGLE);
8808 SET_EXPR_LOCATION (stmt, loc);
8809 TREE_TYPE (stmt) = void_type_node;
8811 OMP_SINGLE_CLAUSES (stmt)
8812 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8813 "#pragma omp single");
8814 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8816 return add_stmt (stmt);
8820 # pragma omp task task-clause[optseq] new-line
8822 LOC is the location of the #pragma.
8825 #define OMP_TASK_CLAUSE_MASK \
8826 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8827 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8828 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8829 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8830 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8831 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8834 c_parser_omp_task (location_t loc, c_parser *parser)
8836 tree clauses, block;
8838 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8839 "#pragma omp task");
8841 block = c_begin_omp_task ();
8842 c_parser_statement (parser);
8843 return c_finish_omp_task (loc, clauses, block);
8847 # pragma omp taskwait new-line
8851 c_parser_omp_taskwait (c_parser *parser)
8853 location_t loc = c_parser_peek_token (parser)->location;
8854 c_parser_consume_pragma (parser);
8855 c_parser_skip_to_pragma_eol (parser);
8857 c_finish_omp_taskwait (loc);
8860 /* Main entry point to parsing most OpenMP pragmas. */
8863 c_parser_omp_construct (c_parser *parser)
8865 enum pragma_kind p_kind;
8869 loc = c_parser_peek_token (parser)->location;
8870 p_kind = c_parser_peek_token (parser)->pragma_kind;
8871 c_parser_consume_pragma (parser);
8875 case PRAGMA_OMP_ATOMIC:
8876 c_parser_omp_atomic (loc, parser);
8878 case PRAGMA_OMP_CRITICAL:
8879 stmt = c_parser_omp_critical (loc, parser);
8881 case PRAGMA_OMP_FOR:
8882 stmt = c_parser_omp_for (loc, parser);
8884 case PRAGMA_OMP_MASTER:
8885 stmt = c_parser_omp_master (loc, parser);
8887 case PRAGMA_OMP_ORDERED:
8888 stmt = c_parser_omp_ordered (loc, parser);
8890 case PRAGMA_OMP_PARALLEL:
8891 stmt = c_parser_omp_parallel (loc, parser);
8893 case PRAGMA_OMP_SECTIONS:
8894 stmt = c_parser_omp_sections (loc, parser);
8896 case PRAGMA_OMP_SINGLE:
8897 stmt = c_parser_omp_single (loc, parser);
8899 case PRAGMA_OMP_TASK:
8900 stmt = c_parser_omp_task (loc, parser);
8907 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
8912 # pragma omp threadprivate (variable-list) */
8915 c_parser_omp_threadprivate (c_parser *parser)
8920 c_parser_consume_pragma (parser);
8921 loc = c_parser_peek_token (parser)->location;
8922 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8924 /* Mark every variable in VARS to be assigned thread local storage. */
8925 for (t = vars; t; t = TREE_CHAIN (t))
8927 tree v = TREE_PURPOSE (t);
8929 /* FIXME diagnostics: Ideally we should keep individual
8930 locations for all the variables in the var list to make the
8931 following errors more precise. Perhaps
8932 c_parser_omp_var_list_parens() should construct a list of
8933 locations to go along with the var list. */
8935 /* If V had already been marked threadprivate, it doesn't matter
8936 whether it had been used prior to this point. */
8937 if (TREE_CODE (v) != VAR_DECL)
8938 error_at (loc, "%qD is not a variable", v);
8939 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8940 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
8941 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8942 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
8943 else if (TREE_TYPE (v) == error_mark_node)
8945 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8946 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
8949 if (! DECL_THREAD_LOCAL_P (v))
8951 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8952 /* If rtl has been already set for this var, call
8953 make_decl_rtl once again, so that encode_section_info
8954 has a chance to look at the new decl flags. */
8955 if (DECL_RTL_SET_P (v))
8958 C_DECL_THREADPRIVATE_P (v) = 1;
8962 c_parser_skip_to_pragma_eol (parser);
8966 /* Parse a single source file. */
8971 /* Use local storage to begin. If the first token is a pragma, parse it.
8972 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8973 which will cause garbage collection. */
8976 memset (&tparser, 0, sizeof tparser);
8977 the_parser = &tparser;
8979 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8980 c_parser_pragma_pch_preprocess (&tparser);
8982 the_parser = ggc_alloc_c_parser ();
8983 *the_parser = tparser;
8985 /* Initialize EH, if we've been told to do so. */
8986 if (flag_exceptions)
8987 using_eh_for_cleanups ();
8989 c_parser_translation_unit (the_parser);
8993 #include "gt-c-parser.h"