1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "rtl.h" /* For decl_default_tls_model. */
46 #include "langhooks.h"
63 /* Initialization routine for this file. */
68 /* The only initialization required is of the reserved word
74 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
75 the c_token structure. */
76 gcc_assert (RID_MAX <= 255);
83 mask |= D_ASM | D_EXT;
87 if (!c_dialect_objc ())
88 mask |= D_OBJC | D_CXX_OBJC;
90 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
91 for (i = 0; i < num_c_common_reswords; i++)
93 /* If a keyword is disabled, do not enter it into the table
94 and so create a canonical spelling that isn't a keyword. */
95 if (c_common_reswords[i].disable & mask)
98 && (c_common_reswords[i].disable & D_CXXWARN))
100 id = get_identifier (c_common_reswords[i].word);
101 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
102 C_IS_RESERVED_WORD (id) = 1;
107 id = get_identifier (c_common_reswords[i].word);
108 C_SET_RID_CODE (id, c_common_reswords[i].rid);
109 C_IS_RESERVED_WORD (id) = 1;
110 ridpointers [(int) c_common_reswords[i].rid] = id;
114 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
115 and the C parser. Unlike the C++ lexer, the parser structure
116 stores the lexer information instead of using a separate structure.
117 Identifiers are separated into ordinary identifiers, type names,
118 keywords and some other Objective-C types of identifiers, and some
119 look-ahead is maintained.
121 ??? It might be a good idea to lex the whole file up front (as for
122 C++). It would then be possible to share more of the C and C++
123 lexer code, if desired. */
125 /* The following local token type is used. */
128 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
130 /* More information about the type of a CPP_NAME token. */
131 typedef enum c_id_kind {
132 /* An ordinary identifier. */
134 /* An identifier declared as a typedef name. */
136 /* An identifier declared as an Objective-C class name. */
138 /* An address space identifier. */
140 /* Not an identifier. */
144 /* A single C token after string literal concatenation and conversion
145 of preprocessing tokens to tokens. */
146 typedef struct GTY (()) c_token {
147 /* The kind of token. */
148 ENUM_BITFIELD (cpp_ttype) type : 8;
149 /* If this token is a CPP_NAME, this value indicates whether also
150 declared as some kind of type. Otherwise, it is C_ID_NONE. */
151 ENUM_BITFIELD (c_id_kind) id_kind : 8;
152 /* If this token is a keyword, this value indicates which keyword.
153 Otherwise, this value is RID_MAX. */
154 ENUM_BITFIELD (rid) keyword : 8;
155 /* If this token is a CPP_PRAGMA, this indicates the pragma that
156 was seen. Otherwise it is PRAGMA_NONE. */
157 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
158 /* The location at which this token was found. */
160 /* The value associated with this token, if any. */
164 /* A parser structure recording information about the state and
165 context of parsing. Includes lexer information with up to two
166 tokens of look-ahead; more are not needed for C. */
167 typedef struct GTY(()) c_parser {
168 /* The look-ahead tokens. */
170 /* How many look-ahead tokens are available (0, 1 or 2). */
172 /* True if a syntax error is being recovered from; false otherwise.
173 c_parser_error sets this flag. It should clear this flag when
174 enough tokens have been consumed to recover from the error. */
175 BOOL_BITFIELD error : 1;
176 /* True if we're processing a pragma, and shouldn't automatically
177 consume CPP_PRAGMA_EOL. */
178 BOOL_BITFIELD in_pragma : 1;
179 /* True if we're parsing the outermost block of an if statement. */
180 BOOL_BITFIELD in_if_block : 1;
181 /* True if we want to lex an untranslated string. */
182 BOOL_BITFIELD lex_untranslated_string : 1;
183 /* Objective-C specific parser/lexer information. */
184 BOOL_BITFIELD objc_pq_context : 1;
185 /* The following flag is needed to contextualize Objective-C lexical
186 analysis. In some cases (e.g., 'int NSObject;'), it is
187 undesirable to bind an identifier to an Objective-C class, even
188 if a class with that name exists. */
189 BOOL_BITFIELD objc_need_raw_identifier : 1;
193 /* The actual parser and external interface. ??? Does this need to be
194 garbage-collected? */
196 static GTY (()) c_parser *the_parser;
199 /* Read in and lex a single token, storing it in *TOKEN. */
202 c_lex_one_token (c_parser *parser, c_token *token)
204 timevar_push (TV_LEX);
206 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
207 (parser->lex_untranslated_string
208 ? C_LEX_STRING_NO_TRANSLATE : 0));
209 token->id_kind = C_ID_NONE;
210 token->keyword = RID_MAX;
211 token->pragma_kind = PRAGMA_NONE;
219 bool objc_force_identifier = parser->objc_need_raw_identifier;
220 if (c_dialect_objc ())
221 parser->objc_need_raw_identifier = false;
223 if (C_IS_RESERVED_WORD (token->value))
225 enum rid rid_code = C_RID_CODE (token->value);
227 if (rid_code == RID_CXX_COMPAT_WARN)
229 warning_at (token->location,
231 "identifier %qE conflicts with C++ keyword",
234 else if (rid_code >= RID_FIRST_ADDR_SPACE
235 && rid_code <= RID_LAST_ADDR_SPACE)
237 token->id_kind = C_ID_ADDRSPACE;
238 token->keyword = rid_code;
241 else if (c_dialect_objc ())
243 if (!objc_is_reserved_word (token->value)
244 && (!OBJC_IS_PQ_KEYWORD (rid_code)
245 || parser->objc_pq_context))
247 /* Return the canonical spelling for this keyword. */
248 token->value = ridpointers[(int) rid_code];
249 token->type = CPP_KEYWORD;
250 token->keyword = rid_code;
256 token->type = CPP_KEYWORD;
257 token->keyword = rid_code;
262 decl = lookup_name (token->value);
265 if (TREE_CODE (decl) == TYPE_DECL)
267 token->id_kind = C_ID_TYPENAME;
271 else if (c_dialect_objc ())
273 tree objc_interface_decl = objc_is_class_name (token->value);
274 /* Objective-C class names are in the same namespace as
275 variables and typedefs, and hence are shadowed by local
277 if (objc_interface_decl
278 && (global_bindings_p ()
279 || (!objc_force_identifier && !decl)))
281 token->value = objc_interface_decl;
282 token->id_kind = C_ID_CLASSNAME;
286 token->id_kind = C_ID_ID;
290 /* This only happens in Objective-C; it must be a keyword. */
291 token->type = CPP_KEYWORD;
292 token->keyword = C_RID_CODE (token->value);
296 case CPP_CLOSE_PAREN:
298 /* These tokens may affect the interpretation of any identifiers
299 following, if doing Objective-C. */
300 if (c_dialect_objc ())
301 parser->objc_need_raw_identifier = false;
304 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
305 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
311 timevar_pop (TV_LEX);
314 /* Return a pointer to the next token from PARSER, reading it in if
317 static inline c_token *
318 c_parser_peek_token (c_parser *parser)
320 if (parser->tokens_avail == 0)
322 c_lex_one_token (parser, &parser->tokens[0]);
323 parser->tokens_avail = 1;
325 return &parser->tokens[0];
328 /* Return true if the next token from PARSER has the indicated
332 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
334 return c_parser_peek_token (parser)->type == type;
337 /* Return true if the next token from PARSER does not have the
341 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
343 return !c_parser_next_token_is (parser, type);
346 /* Return true if the next token from PARSER is the indicated
350 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
352 return c_parser_peek_token (parser)->keyword == keyword;
355 /* Return true if TOKEN can start a type name,
358 c_token_starts_typename (c_token *token)
363 switch (token->id_kind)
372 gcc_assert (c_dialect_objc ());
378 switch (token->keyword)
410 if (c_dialect_objc ())
418 /* Return true if the next token from PARSER can start a type name,
421 c_parser_next_token_starts_typename (c_parser *parser)
423 c_token *token = c_parser_peek_token (parser);
424 return c_token_starts_typename (token);
427 /* Return true if TOKEN can start declaration specifiers, false
430 c_token_starts_declspecs (c_token *token)
435 switch (token->id_kind)
444 gcc_assert (c_dialect_objc ());
450 switch (token->keyword)
489 if (c_dialect_objc ())
497 /* Return true if the next token from PARSER can start declaration
498 specifiers, false otherwise. */
500 c_parser_next_token_starts_declspecs (c_parser *parser)
502 c_token *token = c_parser_peek_token (parser);
503 return c_token_starts_declspecs (token);
506 /* Return a pointer to the next-but-one token from PARSER, reading it
507 in if necessary. The next token is already read in. */
510 c_parser_peek_2nd_token (c_parser *parser)
512 if (parser->tokens_avail >= 2)
513 return &parser->tokens[1];
514 gcc_assert (parser->tokens_avail == 1);
515 gcc_assert (parser->tokens[0].type != CPP_EOF);
516 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
517 c_lex_one_token (parser, &parser->tokens[1]);
518 parser->tokens_avail = 2;
519 return &parser->tokens[1];
522 /* Consume the next token from PARSER. */
525 c_parser_consume_token (c_parser *parser)
527 gcc_assert (parser->tokens_avail >= 1);
528 gcc_assert (parser->tokens[0].type != CPP_EOF);
529 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
530 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
531 if (parser->tokens_avail == 2)
532 parser->tokens[0] = parser->tokens[1];
533 parser->tokens_avail--;
536 /* Expect the current token to be a #pragma. Consume it and remember
537 that we've begun parsing a pragma. */
540 c_parser_consume_pragma (c_parser *parser)
542 gcc_assert (!parser->in_pragma);
543 gcc_assert (parser->tokens_avail >= 1);
544 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
545 if (parser->tokens_avail == 2)
546 parser->tokens[0] = parser->tokens[1];
547 parser->tokens_avail--;
548 parser->in_pragma = true;
551 /* Update the globals input_location and in_system_header from
554 c_parser_set_source_position_from_token (c_token *token)
556 if (token->type != CPP_EOF)
558 input_location = token->location;
562 /* Issue a diagnostic of the form
563 FILE:LINE: MESSAGE before TOKEN
564 where TOKEN is the next token in the input stream of PARSER.
565 MESSAGE (specified by the caller) is usually of the form "expected
568 Do not issue a diagnostic if still recovering from an error.
570 ??? This is taken from the C++ parser, but building up messages in
571 this way is not i18n-friendly and some other approach should be
575 c_parser_error (c_parser *parser, const char *gmsgid)
577 c_token *token = c_parser_peek_token (parser);
580 parser->error = true;
583 /* This diagnostic makes more sense if it is tagged to the line of
584 the token we just peeked at. */
585 c_parser_set_source_position_from_token (token);
586 c_parse_error (gmsgid,
587 /* Because c_parse_error does not understand
588 CPP_KEYWORD, keywords are treated like
590 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
591 /* ??? The C parser does not save the cpp flags of a
592 token, we need to pass 0 here and we will not get
593 the source spelling of some tokens but rather the
594 canonical spelling. */
595 token->value, /*flags=*/0);
598 /* If the next token is of the indicated TYPE, consume it. Otherwise,
599 issue the error MSGID. If MSGID is NULL then a message has already
600 been produced and no message will be produced this time. Returns
601 true if found, false otherwise. */
604 c_parser_require (c_parser *parser,
608 if (c_parser_next_token_is (parser, type))
610 c_parser_consume_token (parser);
615 c_parser_error (parser, msgid);
620 /* If the next token is the indicated keyword, consume it. Otherwise,
621 issue the error MSGID. Returns true if found, false otherwise. */
624 c_parser_require_keyword (c_parser *parser,
628 if (c_parser_next_token_is_keyword (parser, keyword))
630 c_parser_consume_token (parser);
635 c_parser_error (parser, msgid);
640 /* Like c_parser_require, except that tokens will be skipped until the
641 desired token is found. An error message is still produced if the
642 next token is not as expected. If MSGID is NULL then a message has
643 already been produced and no message will be produced this
647 c_parser_skip_until_found (c_parser *parser,
651 unsigned nesting_depth = 0;
653 if (c_parser_require (parser, type, msgid))
656 /* Skip tokens until the desired token is found. */
659 /* Peek at the next token. */
660 c_token *token = c_parser_peek_token (parser);
661 /* If we've reached the token we want, consume it and stop. */
662 if (token->type == type && !nesting_depth)
664 c_parser_consume_token (parser);
668 /* If we've run out of tokens, stop. */
669 if (token->type == CPP_EOF)
671 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
673 if (token->type == CPP_OPEN_BRACE
674 || token->type == CPP_OPEN_PAREN
675 || token->type == CPP_OPEN_SQUARE)
677 else if (token->type == CPP_CLOSE_BRACE
678 || token->type == CPP_CLOSE_PAREN
679 || token->type == CPP_CLOSE_SQUARE)
681 if (nesting_depth-- == 0)
684 /* Consume this token. */
685 c_parser_consume_token (parser);
687 parser->error = false;
690 /* Skip tokens until the end of a parameter is found, but do not
691 consume the comma, semicolon or closing delimiter. */
694 c_parser_skip_to_end_of_parameter (c_parser *parser)
696 unsigned nesting_depth = 0;
700 c_token *token = c_parser_peek_token (parser);
701 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
704 /* If we've run out of tokens, stop. */
705 if (token->type == CPP_EOF)
707 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
709 if (token->type == CPP_OPEN_BRACE
710 || token->type == CPP_OPEN_PAREN
711 || token->type == CPP_OPEN_SQUARE)
713 else if (token->type == CPP_CLOSE_BRACE
714 || token->type == CPP_CLOSE_PAREN
715 || token->type == CPP_CLOSE_SQUARE)
717 if (nesting_depth-- == 0)
720 /* Consume this token. */
721 c_parser_consume_token (parser);
723 parser->error = false;
726 /* Expect to be at the end of the pragma directive and consume an
727 end of line marker. */
730 c_parser_skip_to_pragma_eol (c_parser *parser)
732 gcc_assert (parser->in_pragma);
733 parser->in_pragma = false;
735 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
738 c_token *token = c_parser_peek_token (parser);
739 if (token->type == CPP_EOF)
741 if (token->type == CPP_PRAGMA_EOL)
743 c_parser_consume_token (parser);
746 c_parser_consume_token (parser);
749 parser->error = false;
752 /* Skip tokens until we have consumed an entire block, or until we
753 have consumed a non-nested ';'. */
756 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
758 unsigned nesting_depth = 0;
759 bool save_error = parser->error;
765 /* Peek at the next token. */
766 token = c_parser_peek_token (parser);
774 if (parser->in_pragma)
779 /* If the next token is a ';', we have reached the
780 end of the statement. */
783 /* Consume the ';'. */
784 c_parser_consume_token (parser);
789 case CPP_CLOSE_BRACE:
790 /* If the next token is a non-nested '}', then we have
791 reached the end of the current block. */
792 if (nesting_depth == 0 || --nesting_depth == 0)
794 c_parser_consume_token (parser);
800 /* If it the next token is a '{', then we are entering a new
801 block. Consume the entire block. */
806 /* If we see a pragma, consume the whole thing at once. We
807 have some safeguards against consuming pragmas willy-nilly.
808 Normally, we'd expect to be here with parser->error set,
809 which disables these safeguards. But it's possible to get
810 here for secondary error recovery, after parser->error has
812 c_parser_consume_pragma (parser);
813 c_parser_skip_to_pragma_eol (parser);
814 parser->error = save_error;
821 c_parser_consume_token (parser);
825 parser->error = false;
828 /* CPP's options (initialized by c-opts.c). */
829 extern cpp_options *cpp_opts;
831 /* Save the warning flags which are controlled by __extension__. */
834 disable_extension_diagnostics (void)
837 | (warn_pointer_arith << 1)
838 | (warn_traditional << 2)
840 | (warn_long_long << 4)
841 | (warn_cxx_compat << 5));
842 cpp_opts->pedantic = pedantic = 0;
843 warn_pointer_arith = 0;
844 cpp_opts->warn_traditional = warn_traditional = 0;
846 cpp_opts->warn_long_long = warn_long_long = 0;
851 /* Restore the warning flags which are controlled by __extension__.
852 FLAGS is the return value from disable_extension_diagnostics. */
855 restore_extension_diagnostics (int flags)
857 cpp_opts->pedantic = pedantic = flags & 1;
858 warn_pointer_arith = (flags >> 1) & 1;
859 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
860 flag_iso = (flags >> 3) & 1;
861 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
862 warn_cxx_compat = (flags >> 5) & 1;
865 /* Possibly kinds of declarator to parse. */
866 typedef enum c_dtr_syn {
867 /* A normal declarator with an identifier. */
869 /* An abstract declarator (maybe empty). */
871 /* A parameter declarator: may be either, but after a type name does
872 not redeclare a typedef name as an identifier if it can
873 alternatively be interpreted as a typedef name; see DR#009,
874 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
875 following DR#249. For example, given a typedef T, "int T" and
876 "int *T" are valid parameter declarations redeclaring T, while
877 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
878 abstract declarators rather than involving redundant parentheses;
879 the same applies with attributes inside the parentheses before
884 static void c_parser_external_declaration (c_parser *);
885 static void c_parser_asm_definition (c_parser *);
886 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
887 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
889 static struct c_typespec c_parser_enum_specifier (c_parser *);
890 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
891 static tree c_parser_struct_declaration (c_parser *);
892 static struct c_typespec c_parser_typeof_specifier (c_parser *);
893 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
895 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
897 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
899 struct c_declarator *);
900 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
901 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
902 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
903 static tree c_parser_simple_asm_expr (c_parser *);
904 static tree c_parser_attributes (c_parser *);
905 static struct c_type_name *c_parser_type_name (c_parser *);
906 static struct c_expr c_parser_initializer (c_parser *);
907 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
908 static void c_parser_initelt (c_parser *, struct obstack *);
909 static void c_parser_initval (c_parser *, struct c_expr *,
911 static tree c_parser_compound_statement (c_parser *);
912 static void c_parser_compound_statement_nostart (c_parser *);
913 static void c_parser_label (c_parser *);
914 static void c_parser_statement (c_parser *);
915 static void c_parser_statement_after_labels (c_parser *);
916 static void c_parser_if_statement (c_parser *);
917 static void c_parser_switch_statement (c_parser *);
918 static void c_parser_while_statement (c_parser *);
919 static void c_parser_do_statement (c_parser *);
920 static void c_parser_for_statement (c_parser *);
921 static tree c_parser_asm_statement (c_parser *);
922 static tree c_parser_asm_operands (c_parser *, bool);
923 static tree c_parser_asm_goto_operands (c_parser *);
924 static tree c_parser_asm_clobbers (c_parser *);
925 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
926 static struct c_expr c_parser_conditional_expression (c_parser *,
928 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
929 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
930 static struct c_expr c_parser_unary_expression (c_parser *);
931 static struct c_expr c_parser_sizeof_expression (c_parser *);
932 static struct c_expr c_parser_alignof_expression (c_parser *);
933 static struct c_expr c_parser_postfix_expression (c_parser *);
934 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
935 struct c_type_name *,
937 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
940 static struct c_expr c_parser_expression (c_parser *);
941 static struct c_expr c_parser_expression_conv (c_parser *);
942 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
944 static void c_parser_omp_construct (c_parser *);
945 static void c_parser_omp_threadprivate (c_parser *);
946 static void c_parser_omp_barrier (c_parser *);
947 static void c_parser_omp_flush (c_parser *);
948 static void c_parser_omp_taskwait (c_parser *);
950 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
951 static bool c_parser_pragma (c_parser *, enum pragma_context);
953 /* These Objective-C parser functions are only ever called when
954 compiling Objective-C. */
955 static void c_parser_objc_class_definition (c_parser *);
956 static void c_parser_objc_class_instance_variables (c_parser *);
957 static void c_parser_objc_class_declaration (c_parser *);
958 static void c_parser_objc_alias_declaration (c_parser *);
959 static void c_parser_objc_protocol_definition (c_parser *);
960 static enum tree_code c_parser_objc_method_type (c_parser *);
961 static void c_parser_objc_method_definition (c_parser *);
962 static void c_parser_objc_methodprotolist (c_parser *);
963 static void c_parser_objc_methodproto (c_parser *);
964 static tree c_parser_objc_method_decl (c_parser *);
965 static tree c_parser_objc_type_name (c_parser *);
966 static tree c_parser_objc_protocol_refs (c_parser *);
967 static void c_parser_objc_try_catch_statement (c_parser *);
968 static void c_parser_objc_synchronized_statement (c_parser *);
969 static tree c_parser_objc_selector (c_parser *);
970 static tree c_parser_objc_selector_arg (c_parser *);
971 static tree c_parser_objc_receiver (c_parser *);
972 static tree c_parser_objc_message_args (c_parser *);
973 static tree c_parser_objc_keywordexpr (c_parser *);
975 /* Parse a translation unit (C90 6.7, C99 6.9).
978 external-declarations
980 external-declarations:
982 external-declarations external-declaration
991 c_parser_translation_unit (c_parser *parser)
993 if (c_parser_next_token_is (parser, CPP_EOF))
995 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
996 "ISO C forbids an empty translation unit");
1000 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1001 mark_valid_location_for_stdc_pragma (false);
1005 c_parser_external_declaration (parser);
1006 obstack_free (&parser_obstack, obstack_position);
1008 while (c_parser_next_token_is_not (parser, CPP_EOF));
1012 /* Parse an external declaration (C90 6.7, C99 6.9).
1014 external-declaration:
1020 external-declaration:
1023 __extension__ external-declaration
1027 external-declaration:
1028 objc-class-definition
1029 objc-class-declaration
1030 objc-alias-declaration
1031 objc-protocol-definition
1032 objc-method-definition
1037 c_parser_external_declaration (c_parser *parser)
1040 switch (c_parser_peek_token (parser)->type)
1043 switch (c_parser_peek_token (parser)->keyword)
1046 ext = disable_extension_diagnostics ();
1047 c_parser_consume_token (parser);
1048 c_parser_external_declaration (parser);
1049 restore_extension_diagnostics (ext);
1052 c_parser_asm_definition (parser);
1054 case RID_AT_INTERFACE:
1055 case RID_AT_IMPLEMENTATION:
1056 gcc_assert (c_dialect_objc ());
1057 c_parser_objc_class_definition (parser);
1060 gcc_assert (c_dialect_objc ());
1061 c_parser_objc_class_declaration (parser);
1064 gcc_assert (c_dialect_objc ());
1065 c_parser_objc_alias_declaration (parser);
1067 case RID_AT_PROTOCOL:
1068 gcc_assert (c_dialect_objc ());
1069 c_parser_objc_protocol_definition (parser);
1072 gcc_assert (c_dialect_objc ());
1073 c_parser_consume_token (parser);
1074 objc_finish_implementation ();
1081 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1082 "ISO C does not allow extra %<;%> outside of a function");
1083 c_parser_consume_token (parser);
1086 mark_valid_location_for_stdc_pragma (true);
1087 c_parser_pragma (parser, pragma_external);
1088 mark_valid_location_for_stdc_pragma (false);
1092 if (c_dialect_objc ())
1094 c_parser_objc_method_definition (parser);
1097 /* Else fall through, and yield a syntax error trying to parse
1098 as a declaration or function definition. */
1101 /* A declaration or a function definition. We can only tell
1102 which after parsing the declaration specifiers, if any, and
1103 the first declarator. */
1104 c_parser_declaration_or_fndef (parser, true, true, false, true);
1110 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1111 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1112 accepted; otherwise (old-style parameter declarations) only other
1113 declarations are accepted. If NESTED is true, we are inside a
1114 function or parsing old-style parameter declarations; any functions
1115 encountered are nested functions and declaration specifiers are
1116 required; otherwise we are at top level and functions are normal
1117 functions and declaration specifiers may be optional. If EMPTY_OK
1118 is true, empty declarations are OK (subject to all other
1119 constraints); otherwise (old-style parameter declarations) they are
1120 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1121 may start with attributes; otherwise they may not.
1124 declaration-specifiers init-declarator-list[opt] ;
1126 function-definition:
1127 declaration-specifiers[opt] declarator declaration-list[opt]
1132 declaration-list declaration
1134 init-declarator-list:
1136 init-declarator-list , init-declarator
1139 declarator simple-asm-expr[opt] attributes[opt]
1140 declarator simple-asm-expr[opt] attributes[opt] = initializer
1144 nested-function-definition:
1145 declaration-specifiers declarator declaration-list[opt]
1148 The simple-asm-expr and attributes are GNU extensions.
1150 This function does not handle __extension__; that is handled in its
1151 callers. ??? Following the old parser, __extension__ may start
1152 external declarations, declarations in functions and declarations
1153 at the start of "for" loops, but not old-style parameter
1156 C99 requires declaration specifiers in a function definition; the
1157 absence is diagnosed through the diagnosis of implicit int. In GNU
1158 C we also allow but diagnose declarations without declaration
1159 specifiers, but only at top level (elsewhere they conflict with
1165 threadprivate-directive */
1168 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1169 bool nested, bool start_attr_ok)
1171 struct c_declspecs *specs;
1173 tree all_prefix_attrs;
1174 bool diagnosed_no_specs = false;
1175 location_t here = c_parser_peek_token (parser)->location;
1177 specs = build_null_declspecs ();
1178 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1181 c_parser_skip_to_end_of_block_or_statement (parser);
1184 if (nested && !specs->declspecs_seen_p)
1186 c_parser_error (parser, "expected declaration specifiers");
1187 c_parser_skip_to_end_of_block_or_statement (parser);
1190 finish_declspecs (specs);
1191 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1197 shadow_tag_warned (specs, 1);
1198 pedwarn (here, 0, "empty declaration");
1200 c_parser_consume_token (parser);
1203 pending_xref_error ();
1204 prefix_attrs = specs->attrs;
1205 all_prefix_attrs = prefix_attrs;
1206 specs->attrs = NULL_TREE;
1209 struct c_declarator *declarator;
1212 /* Declaring either one or more declarators (in which case we
1213 should diagnose if there were no declaration specifiers) or a
1214 function definition (in which case the diagnostic for
1215 implicit int suffices). */
1216 declarator = c_parser_declarator (parser, specs->type_seen_p,
1217 C_DTR_NORMAL, &dummy);
1218 if (declarator == NULL)
1220 c_parser_skip_to_end_of_block_or_statement (parser);
1223 if (c_parser_next_token_is (parser, CPP_EQ)
1224 || c_parser_next_token_is (parser, CPP_COMMA)
1225 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1226 || c_parser_next_token_is_keyword (parser, RID_ASM)
1227 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1229 tree asm_name = NULL_TREE;
1230 tree postfix_attrs = NULL_TREE;
1231 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1233 diagnosed_no_specs = true;
1234 pedwarn (here, 0, "data definition has no type or storage class");
1236 /* Having seen a data definition, there cannot now be a
1237 function definition. */
1239 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1240 asm_name = c_parser_simple_asm_expr (parser);
1241 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1242 postfix_attrs = c_parser_attributes (parser);
1243 if (c_parser_next_token_is (parser, CPP_EQ))
1247 location_t init_loc;
1248 c_parser_consume_token (parser);
1249 /* The declaration of the variable is in effect while
1250 its initializer is parsed. */
1251 d = start_decl (declarator, specs, true,
1252 chainon (postfix_attrs, all_prefix_attrs));
1254 d = error_mark_node;
1255 start_init (d, asm_name, global_bindings_p ());
1256 init_loc = c_parser_peek_token (parser)->location;
1257 init = c_parser_initializer (parser);
1259 if (d != error_mark_node)
1261 maybe_warn_string_init (TREE_TYPE (d), init);
1262 finish_decl (d, init_loc, init.value,
1263 init.original_type, asm_name);
1268 tree d = start_decl (declarator, specs, false,
1269 chainon (postfix_attrs,
1272 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1273 NULL_TREE, asm_name);
1275 if (c_parser_next_token_is (parser, CPP_COMMA))
1277 c_parser_consume_token (parser);
1278 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1279 all_prefix_attrs = chainon (c_parser_attributes (parser),
1282 all_prefix_attrs = prefix_attrs;
1285 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1287 c_parser_consume_token (parser);
1292 c_parser_error (parser, "expected %<,%> or %<;%>");
1293 c_parser_skip_to_end_of_block_or_statement (parser);
1299 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1300 "%<asm%> or %<__attribute__%>");
1301 c_parser_skip_to_end_of_block_or_statement (parser);
1304 /* Function definition (nested or otherwise). */
1307 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1308 c_push_function_context ();
1310 if (!start_function (specs, declarator, all_prefix_attrs))
1312 /* This can appear in many cases looking nothing like a
1313 function definition, so we don't give a more specific
1314 error suggesting there was one. */
1315 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1316 "or %<__attribute__%>");
1318 c_pop_function_context ();
1321 /* Parse old-style parameter declarations. ??? Attributes are
1322 not allowed to start declaration specifiers here because of a
1323 syntax conflict between a function declaration with attribute
1324 suffix and a function definition with an attribute prefix on
1325 first old-style parameter declaration. Following the old
1326 parser, they are not accepted on subsequent old-style
1327 parameter declarations either. However, there is no
1328 ambiguity after the first declaration, nor indeed on the
1329 first as long as we don't allow postfix attributes after a
1330 declarator with a nonempty identifier list in a definition;
1331 and postfix attributes have never been accepted here in
1332 function definitions either. */
1333 while (c_parser_next_token_is_not (parser, CPP_EOF)
1334 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1335 c_parser_declaration_or_fndef (parser, false, false, true, false);
1336 store_parm_decls ();
1337 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1338 = c_parser_peek_token (parser)->location;
1339 fnbody = c_parser_compound_statement (parser);
1342 tree decl = current_function_decl;
1343 /* Mark nested functions as needing static-chain initially.
1344 lower_nested_functions will recompute it but the
1345 DECL_STATIC_CHAIN flag is also used before that happens,
1346 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1347 DECL_STATIC_CHAIN (decl) = 1;
1350 c_pop_function_context ();
1351 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1362 /* Parse an asm-definition (asm() outside a function body). This is a
1370 c_parser_asm_definition (c_parser *parser)
1372 tree asm_str = c_parser_simple_asm_expr (parser);
1374 cgraph_add_asm_node (asm_str);
1375 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1378 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1379 6.7), adding them to SPECS (which may already include some).
1380 Storage class specifiers are accepted iff SCSPEC_OK; type
1381 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1382 the start iff START_ATTR_OK.
1384 declaration-specifiers:
1385 storage-class-specifier declaration-specifiers[opt]
1386 type-specifier declaration-specifiers[opt]
1387 type-qualifier declaration-specifiers[opt]
1388 function-specifier declaration-specifiers[opt]
1390 Function specifiers (inline) are from C99, and are currently
1391 handled as storage class specifiers, as is __thread.
1393 C90 6.5.1, C99 6.7.1:
1394 storage-class-specifier:
1405 C90 6.5.2, C99 6.7.2:
1418 [_Imaginary removed in C99 TC2]
1419 struct-or-union-specifier
1423 (_Bool and _Complex are new in C99.)
1425 C90 6.5.3, C99 6.7.3:
1431 address-space-qualifier
1433 (restrict is new in C99.)
1437 declaration-specifiers:
1438 attributes declaration-specifiers[opt]
1444 identifier recognized by the target
1446 storage-class-specifier:
1458 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1459 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1464 class-name objc-protocol-refs[opt]
1465 typedef-name objc-protocol-refs
1470 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1471 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1473 bool attrs_ok = start_attr_ok;
1474 bool seen_type = specs->type_seen_p;
1475 while (c_parser_next_token_is (parser, CPP_NAME)
1476 || c_parser_next_token_is (parser, CPP_KEYWORD)
1477 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1479 struct c_typespec t;
1481 location_t loc = c_parser_peek_token (parser)->location;
1482 if (c_parser_next_token_is (parser, CPP_NAME))
1484 tree value = c_parser_peek_token (parser)->value;
1485 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1487 if (kind == C_ID_ADDRSPACE)
1490 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1491 declspecs_add_addrspace (specs, as);
1492 c_parser_consume_token (parser);
1497 /* This finishes the specifiers unless a type name is OK, it
1498 is declared as a type name and a type name hasn't yet
1500 if (!typespec_ok || seen_type
1501 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1503 c_parser_consume_token (parser);
1506 if (kind == C_ID_TYPENAME
1507 && (!c_dialect_objc ()
1508 || c_parser_next_token_is_not (parser, CPP_LESS)))
1510 t.kind = ctsk_typedef;
1511 /* For a typedef name, record the meaning, not the name.
1512 In case of 'foo foo, bar;'. */
1513 t.spec = lookup_name (value);
1515 t.expr_const_operands = true;
1519 tree proto = NULL_TREE;
1520 gcc_assert (c_dialect_objc ());
1522 if (c_parser_next_token_is (parser, CPP_LESS))
1523 proto = c_parser_objc_protocol_refs (parser);
1524 t.spec = objc_get_protocol_qualified_type (value, proto);
1526 t.expr_const_operands = true;
1528 declspecs_add_type (loc, specs, t);
1531 if (c_parser_next_token_is (parser, CPP_LESS))
1533 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1534 nisse@lysator.liu.se. */
1536 gcc_assert (c_dialect_objc ());
1537 if (!typespec_ok || seen_type)
1539 proto = c_parser_objc_protocol_refs (parser);
1541 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1543 t.expr_const_operands = true;
1544 declspecs_add_type (loc, specs, t);
1547 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1548 switch (c_parser_peek_token (parser)->keyword)
1560 /* TODO: Distinguish between function specifiers (inline)
1561 and storage class specifiers, either here or in
1562 declspecs_add_scspec. */
1563 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1564 c_parser_consume_token (parser);
1587 if (c_dialect_objc ())
1588 parser->objc_need_raw_identifier = true;
1589 t.kind = ctsk_resword;
1590 t.spec = c_parser_peek_token (parser)->value;
1592 t.expr_const_operands = true;
1593 declspecs_add_type (loc, specs, t);
1594 c_parser_consume_token (parser);
1601 t = c_parser_enum_specifier (parser);
1602 declspecs_add_type (loc, specs, t);
1610 t = c_parser_struct_or_union_specifier (parser);
1611 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1612 declspecs_add_type (loc, specs, t);
1615 /* ??? The old parser rejected typeof after other type
1616 specifiers, but is a syntax error the best way of
1618 if (!typespec_ok || seen_type)
1622 t = c_parser_typeof_specifier (parser);
1623 declspecs_add_type (loc, specs, t);
1629 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1630 c_parser_consume_token (parser);
1635 attrs = c_parser_attributes (parser);
1636 declspecs_add_attrs (specs, attrs);
1645 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1648 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1649 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1650 enum attributes[opt] identifier
1652 The form with trailing comma is new in C99. The forms with
1653 attributes are GNU extensions. In GNU C, we accept any expression
1654 without commas in the syntax (assignment expressions, not just
1655 conditional expressions); assignment expressions will be diagnosed
1660 enumerator-list , enumerator
1663 enumeration-constant
1664 enumeration-constant = constant-expression
1667 static struct c_typespec
1668 c_parser_enum_specifier (c_parser *parser)
1670 struct c_typespec ret;
1672 tree ident = NULL_TREE;
1673 location_t enum_loc;
1674 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1675 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1676 enum_loc = c_parser_peek_token (parser)->location;
1677 c_parser_consume_token (parser);
1678 attrs = c_parser_attributes (parser);
1679 enum_loc = c_parser_peek_token (parser)->location;
1680 /* Set the location in case we create a decl now. */
1681 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1682 if (c_parser_next_token_is (parser, CPP_NAME))
1684 ident = c_parser_peek_token (parser)->value;
1685 ident_loc = c_parser_peek_token (parser)->location;
1686 enum_loc = ident_loc;
1687 c_parser_consume_token (parser);
1689 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1691 /* Parse an enum definition. */
1692 struct c_enum_contents the_enum;
1693 tree type = start_enum (enum_loc, &the_enum, ident);
1695 /* We chain the enumerators in reverse order, then put them in
1696 forward order at the end. */
1697 tree values = NULL_TREE;
1698 c_parser_consume_token (parser);
1706 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1707 location_t value_loc;
1708 if (c_parser_next_token_is_not (parser, CPP_NAME))
1710 c_parser_error (parser, "expected identifier");
1711 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1712 values = error_mark_node;
1715 token = c_parser_peek_token (parser);
1716 enum_id = token->value;
1717 /* Set the location in case we create a decl now. */
1718 c_parser_set_source_position_from_token (token);
1719 value_loc = token->location;
1720 c_parser_consume_token (parser);
1721 if (c_parser_next_token_is (parser, CPP_EQ))
1723 c_parser_consume_token (parser);
1724 value_loc = c_parser_peek_token (parser)->location;
1725 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1728 enum_value = NULL_TREE;
1729 enum_decl = build_enumerator (value_loc,
1730 &the_enum, enum_id, enum_value);
1731 TREE_CHAIN (enum_decl) = values;
1734 if (c_parser_next_token_is (parser, CPP_COMMA))
1736 comma_loc = c_parser_peek_token (parser)->location;
1738 c_parser_consume_token (parser);
1740 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1742 if (seen_comma && !flag_isoc99)
1743 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1744 c_parser_consume_token (parser);
1749 c_parser_error (parser, "expected %<,%> or %<}%>");
1750 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1751 values = error_mark_node;
1755 postfix_attrs = c_parser_attributes (parser);
1756 ret.spec = finish_enum (type, nreverse (values),
1757 chainon (attrs, postfix_attrs));
1758 ret.kind = ctsk_tagdef;
1759 ret.expr = NULL_TREE;
1760 ret.expr_const_operands = true;
1765 c_parser_error (parser, "expected %<{%>");
1766 ret.spec = error_mark_node;
1767 ret.kind = ctsk_tagref;
1768 ret.expr = NULL_TREE;
1769 ret.expr_const_operands = true;
1772 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1773 /* In ISO C, enumerated types can be referred to only if already
1775 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1778 pedwarn (enum_loc, OPT_pedantic,
1779 "ISO C forbids forward references to %<enum%> types");
1784 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1786 struct-or-union-specifier:
1787 struct-or-union attributes[opt] identifier[opt]
1788 { struct-contents } attributes[opt]
1789 struct-or-union attributes[opt] identifier
1792 struct-declaration-list
1794 struct-declaration-list:
1795 struct-declaration ;
1796 struct-declaration-list struct-declaration ;
1803 struct-declaration-list struct-declaration
1805 struct-declaration-list:
1806 struct-declaration-list ;
1809 (Note that in the syntax here, unlike that in ISO C, the semicolons
1810 are included here rather than in struct-declaration, in order to
1811 describe the syntax with extra semicolons and missing semicolon at
1816 struct-declaration-list:
1817 @defs ( class-name )
1819 (Note this does not include a trailing semicolon, but can be
1820 followed by further declarations, and gets a pedwarn-if-pedantic
1821 when followed by a semicolon.) */
1823 static struct c_typespec
1824 c_parser_struct_or_union_specifier (c_parser *parser)
1826 struct c_typespec ret;
1828 tree ident = NULL_TREE;
1829 location_t struct_loc;
1830 location_t ident_loc = UNKNOWN_LOCATION;
1831 enum tree_code code;
1832 switch (c_parser_peek_token (parser)->keyword)
1843 struct_loc = c_parser_peek_token (parser)->location;
1844 c_parser_consume_token (parser);
1845 attrs = c_parser_attributes (parser);
1847 /* Set the location in case we create a decl now. */
1848 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1850 if (c_parser_next_token_is (parser, CPP_NAME))
1852 ident = c_parser_peek_token (parser)->value;
1853 ident_loc = c_parser_peek_token (parser)->location;
1854 struct_loc = ident_loc;
1855 c_parser_consume_token (parser);
1857 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1859 /* Parse a struct or union definition. Start the scope of the
1860 tag before parsing components. */
1861 struct c_struct_parse_info *struct_info;
1862 tree type = start_struct (struct_loc, code, ident, &struct_info);
1864 /* We chain the components in reverse order, then put them in
1865 forward order at the end. Each struct-declaration may
1866 declare multiple components (comma-separated), so we must use
1867 chainon to join them, although when parsing each
1868 struct-declaration we can use TREE_CHAIN directly.
1870 The theory behind all this is that there will be more
1871 semicolon separated fields than comma separated fields, and
1872 so we'll be minimizing the number of node traversals required
1874 tree contents = NULL_TREE;
1875 c_parser_consume_token (parser);
1876 /* Handle the Objective-C @defs construct,
1877 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1878 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1881 gcc_assert (c_dialect_objc ());
1882 c_parser_consume_token (parser);
1883 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1885 if (c_parser_next_token_is (parser, CPP_NAME)
1886 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1888 name = c_parser_peek_token (parser)->value;
1889 c_parser_consume_token (parser);
1893 c_parser_error (parser, "expected class name");
1894 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1897 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1899 contents = nreverse (objc_get_class_ivars (name));
1902 /* Parse the struct-declarations and semicolons. Problems with
1903 semicolons are diagnosed here; empty structures are diagnosed
1908 /* Parse any stray semicolon. */
1909 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1911 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1912 "extra semicolon in struct or union specified");
1913 c_parser_consume_token (parser);
1916 /* Stop if at the end of the struct or union contents. */
1917 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1919 c_parser_consume_token (parser);
1922 /* Accept #pragmas at struct scope. */
1923 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1925 c_parser_pragma (parser, pragma_external);
1928 /* Parse some comma-separated declarations, but not the
1929 trailing semicolon if any. */
1930 decls = c_parser_struct_declaration (parser);
1931 contents = chainon (decls, contents);
1932 /* If no semicolon follows, either we have a parse error or
1933 are at the end of the struct or union and should
1935 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1936 c_parser_consume_token (parser);
1939 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1940 pedwarn (c_parser_peek_token (parser)->location, 0,
1941 "no semicolon at end of struct or union");
1944 c_parser_error (parser, "expected %<;%>");
1945 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1950 postfix_attrs = c_parser_attributes (parser);
1951 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
1952 chainon (attrs, postfix_attrs), struct_info);
1953 ret.kind = ctsk_tagdef;
1954 ret.expr = NULL_TREE;
1955 ret.expr_const_operands = true;
1960 c_parser_error (parser, "expected %<{%>");
1961 ret.spec = error_mark_node;
1962 ret.kind = ctsk_tagref;
1963 ret.expr = NULL_TREE;
1964 ret.expr_const_operands = true;
1967 ret = parser_xref_tag (ident_loc, code, ident);
1971 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1972 the trailing semicolon.
1975 specifier-qualifier-list struct-declarator-list
1977 specifier-qualifier-list:
1978 type-specifier specifier-qualifier-list[opt]
1979 type-qualifier specifier-qualifier-list[opt]
1980 attributes specifier-qualifier-list[opt]
1982 struct-declarator-list:
1984 struct-declarator-list , attributes[opt] struct-declarator
1987 declarator attributes[opt]
1988 declarator[opt] : constant-expression attributes[opt]
1993 __extension__ struct-declaration
1994 specifier-qualifier-list
1996 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1997 of attributes where shown is a GNU extension. In GNU C, we accept
1998 any expression without commas in the syntax (assignment
1999 expressions, not just conditional expressions); assignment
2000 expressions will be diagnosed as non-constant. */
2003 c_parser_struct_declaration (c_parser *parser)
2005 struct c_declspecs *specs;
2007 tree all_prefix_attrs;
2009 location_t decl_loc;
2010 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2014 ext = disable_extension_diagnostics ();
2015 c_parser_consume_token (parser);
2016 decl = c_parser_struct_declaration (parser);
2017 restore_extension_diagnostics (ext);
2020 specs = build_null_declspecs ();
2021 decl_loc = c_parser_peek_token (parser)->location;
2022 c_parser_declspecs (parser, specs, false, true, true);
2025 if (!specs->declspecs_seen_p)
2027 c_parser_error (parser, "expected specifier-qualifier-list");
2030 finish_declspecs (specs);
2031 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2034 if (!specs->type_seen_p)
2036 pedwarn (decl_loc, OPT_pedantic,
2037 "ISO C forbids member declarations with no members");
2038 shadow_tag_warned (specs, pedantic);
2043 /* Support for unnamed structs or unions as members of
2044 structs or unions (which is [a] useful and [b] supports
2048 ret = grokfield (c_parser_peek_token (parser)->location,
2049 build_id_declarator (NULL_TREE), specs,
2052 decl_attributes (&ret, attrs, 0);
2056 pending_xref_error ();
2057 prefix_attrs = specs->attrs;
2058 all_prefix_attrs = prefix_attrs;
2059 specs->attrs = NULL_TREE;
2063 /* Declaring one or more declarators or un-named bit-fields. */
2064 struct c_declarator *declarator;
2066 if (c_parser_next_token_is (parser, CPP_COLON))
2067 declarator = build_id_declarator (NULL_TREE);
2069 declarator = c_parser_declarator (parser, specs->type_seen_p,
2070 C_DTR_NORMAL, &dummy);
2071 if (declarator == NULL)
2073 c_parser_skip_to_end_of_block_or_statement (parser);
2076 if (c_parser_next_token_is (parser, CPP_COLON)
2077 || c_parser_next_token_is (parser, CPP_COMMA)
2078 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2079 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2080 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2082 tree postfix_attrs = NULL_TREE;
2083 tree width = NULL_TREE;
2085 if (c_parser_next_token_is (parser, CPP_COLON))
2087 c_parser_consume_token (parser);
2088 width = c_parser_expr_no_commas (parser, NULL).value;
2090 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2091 postfix_attrs = c_parser_attributes (parser);
2092 d = grokfield (c_parser_peek_token (parser)->location,
2093 declarator, specs, width, &all_prefix_attrs);
2094 decl_attributes (&d, chainon (postfix_attrs,
2095 all_prefix_attrs), 0);
2096 TREE_CHAIN (d) = decls;
2098 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2099 all_prefix_attrs = chainon (c_parser_attributes (parser),
2102 all_prefix_attrs = prefix_attrs;
2103 if (c_parser_next_token_is (parser, CPP_COMMA))
2104 c_parser_consume_token (parser);
2105 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2106 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2108 /* Semicolon consumed in caller. */
2113 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2119 c_parser_error (parser,
2120 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2121 "%<__attribute__%>");
2128 /* Parse a typeof specifier (a GNU extension).
2131 typeof ( expression )
2132 typeof ( type-name )
2135 static struct c_typespec
2136 c_parser_typeof_specifier (c_parser *parser)
2138 struct c_typespec ret;
2139 ret.kind = ctsk_typeof;
2140 ret.spec = error_mark_node;
2141 ret.expr = NULL_TREE;
2142 ret.expr_const_operands = true;
2143 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2144 c_parser_consume_token (parser);
2145 c_inhibit_evaluation_warnings++;
2147 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2149 c_inhibit_evaluation_warnings--;
2153 if (c_parser_next_token_starts_typename (parser))
2155 struct c_type_name *type = c_parser_type_name (parser);
2156 c_inhibit_evaluation_warnings--;
2160 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2161 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2167 location_t here = c_parser_peek_token (parser)->location;
2168 struct c_expr expr = c_parser_expression (parser);
2169 c_inhibit_evaluation_warnings--;
2171 if (TREE_CODE (expr.value) == COMPONENT_REF
2172 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2173 error_at (here, "%<typeof%> applied to a bit-field");
2174 mark_exp_read (expr.value);
2175 ret.spec = TREE_TYPE (expr.value);
2176 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2177 /* This is returned with the type so that when the type is
2178 evaluated, this can be evaluated. */
2180 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2181 pop_maybe_used (was_vm);
2183 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2187 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2188 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2189 be redeclared; otherwise it may not. KIND indicates which kind of
2190 declarator is wanted. Returns a valid declarator except in the
2191 case of a syntax error in which case NULL is returned. *SEEN_ID is
2192 set to true if an identifier being declared is seen; this is used
2193 to diagnose bad forms of abstract array declarators and to
2194 determine whether an identifier list is syntactically permitted.
2197 pointer[opt] direct-declarator
2201 ( attributes[opt] declarator )
2202 direct-declarator array-declarator
2203 direct-declarator ( parameter-type-list )
2204 direct-declarator ( identifier-list[opt] )
2207 * type-qualifier-list[opt]
2208 * type-qualifier-list[opt] pointer
2210 type-qualifier-list:
2213 type-qualifier-list type-qualifier
2214 type-qualifier-list attributes
2216 parameter-type-list:
2218 parameter-list , ...
2221 parameter-declaration
2222 parameter-list , parameter-declaration
2224 parameter-declaration:
2225 declaration-specifiers declarator attributes[opt]
2226 declaration-specifiers abstract-declarator[opt] attributes[opt]
2230 identifier-list , identifier
2232 abstract-declarator:
2234 pointer[opt] direct-abstract-declarator
2236 direct-abstract-declarator:
2237 ( attributes[opt] abstract-declarator )
2238 direct-abstract-declarator[opt] array-declarator
2239 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2244 direct-declarator ( parameter-forward-declarations
2245 parameter-type-list[opt] )
2247 direct-abstract-declarator:
2248 direct-abstract-declarator[opt] ( parameter-forward-declarations
2249 parameter-type-list[opt] )
2251 parameter-forward-declarations:
2253 parameter-forward-declarations parameter-list ;
2255 The uses of attributes shown above are GNU extensions.
2257 Some forms of array declarator are not included in C99 in the
2258 syntax for abstract declarators; these are disallowed elsewhere.
2259 This may be a defect (DR#289).
2261 This function also accepts an omitted abstract declarator as being
2262 an abstract declarator, although not part of the formal syntax. */
2264 static struct c_declarator *
2265 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2268 /* Parse any initial pointer part. */
2269 if (c_parser_next_token_is (parser, CPP_MULT))
2271 struct c_declspecs *quals_attrs = build_null_declspecs ();
2272 struct c_declarator *inner;
2273 c_parser_consume_token (parser);
2274 c_parser_declspecs (parser, quals_attrs, false, false, true);
2275 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2279 return make_pointer_declarator (quals_attrs, inner);
2281 /* Now we have a direct declarator, direct abstract declarator or
2282 nothing (which counts as a direct abstract declarator here). */
2283 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2286 /* Parse a direct declarator or direct abstract declarator; arguments
2287 as c_parser_declarator. */
2289 static struct c_declarator *
2290 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2293 /* The direct declarator must start with an identifier (possibly
2294 omitted) or a parenthesized declarator (possibly abstract). In
2295 an ordinary declarator, initial parentheses must start a
2296 parenthesized declarator. In an abstract declarator or parameter
2297 declarator, they could start a parenthesized declarator or a
2298 parameter list. To tell which, the open parenthesis and any
2299 following attributes must be read. If a declaration specifier
2300 follows, then it is a parameter list; if the specifier is a
2301 typedef name, there might be an ambiguity about redeclaring it,
2302 which is resolved in the direction of treating it as a typedef
2303 name. If a close parenthesis follows, it is also an empty
2304 parameter list, as the syntax does not permit empty abstract
2305 declarators. Otherwise, it is a parenthesized declarator (in
2306 which case the analysis may be repeated inside it, recursively).
2308 ??? There is an ambiguity in a parameter declaration "int
2309 (__attribute__((foo)) x)", where x is not a typedef name: it
2310 could be an abstract declarator for a function, or declare x with
2311 parentheses. The proper resolution of this ambiguity needs
2312 documenting. At present we follow an accident of the old
2313 parser's implementation, whereby the first parameter must have
2314 some declaration specifiers other than just attributes. Thus as
2315 a parameter declaration it is treated as a parenthesized
2316 parameter named x, and as an abstract declarator it is
2319 ??? Also following the old parser, attributes inside an empty
2320 parameter list are ignored, making it a list not yielding a
2321 prototype, rather than giving an error or making it have one
2322 parameter with implicit type int.
2324 ??? Also following the old parser, typedef names may be
2325 redeclared in declarators, but not Objective-C class names. */
2327 if (kind != C_DTR_ABSTRACT
2328 && c_parser_next_token_is (parser, CPP_NAME)
2330 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2331 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2333 struct c_declarator *inner
2334 = build_id_declarator (c_parser_peek_token (parser)->value);
2336 inner->id_loc = c_parser_peek_token (parser)->location;
2337 c_parser_consume_token (parser);
2338 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2341 if (kind != C_DTR_NORMAL
2342 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2344 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2345 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2348 /* Either we are at the end of an abstract declarator, or we have
2351 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2354 struct c_declarator *inner;
2355 c_parser_consume_token (parser);
2356 attrs = c_parser_attributes (parser);
2357 if (kind != C_DTR_NORMAL
2358 && (c_parser_next_token_starts_declspecs (parser)
2359 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2361 struct c_arg_info *args
2362 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2369 = build_function_declarator (args,
2370 build_id_declarator (NULL_TREE));
2371 return c_parser_direct_declarator_inner (parser, *seen_id,
2375 /* A parenthesized declarator. */
2376 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2377 if (inner != NULL && attrs != NULL)
2378 inner = build_attrs_declarator (attrs, inner);
2379 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2381 c_parser_consume_token (parser);
2385 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2389 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2396 if (kind == C_DTR_NORMAL)
2398 c_parser_error (parser, "expected identifier or %<(%>");
2402 return build_id_declarator (NULL_TREE);
2406 /* Parse part of a direct declarator or direct abstract declarator,
2407 given that some (in INNER) has already been parsed; ID_PRESENT is
2408 true if an identifier is present, false for an abstract
2411 static struct c_declarator *
2412 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2413 struct c_declarator *inner)
2415 /* Parse a sequence of array declarators and parameter lists. */
2416 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2418 location_t brace_loc = c_parser_peek_token (parser)->location;
2419 struct c_declarator *declarator;
2420 struct c_declspecs *quals_attrs = build_null_declspecs ();
2424 c_parser_consume_token (parser);
2425 c_parser_declspecs (parser, quals_attrs, false, false, true);
2426 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2428 c_parser_consume_token (parser);
2429 if (static_seen && !quals_attrs->declspecs_seen_p)
2430 c_parser_declspecs (parser, quals_attrs, false, false, true);
2431 if (!quals_attrs->declspecs_seen_p)
2433 /* If "static" is present, there must be an array dimension.
2434 Otherwise, there may be a dimension, "*", or no
2439 dimen = c_parser_expr_no_commas (parser, NULL).value;
2443 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2448 else if (c_parser_next_token_is (parser, CPP_MULT))
2450 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2454 c_parser_consume_token (parser);
2459 dimen = c_parser_expr_no_commas (parser, NULL).value;
2465 dimen = c_parser_expr_no_commas (parser, NULL).value;
2468 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2469 c_parser_consume_token (parser);
2472 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2477 mark_exp_read (dimen);
2478 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2479 static_seen, star_seen);
2480 if (declarator == NULL)
2482 inner = set_array_declarator_inner (declarator, inner);
2483 return c_parser_direct_declarator_inner (parser, id_present, inner);
2485 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2488 struct c_arg_info *args;
2489 c_parser_consume_token (parser);
2490 attrs = c_parser_attributes (parser);
2491 args = c_parser_parms_declarator (parser, id_present, attrs);
2496 inner = build_function_declarator (args, inner);
2497 return c_parser_direct_declarator_inner (parser, id_present, inner);
2503 /* Parse a parameter list or identifier list, including the closing
2504 parenthesis but not the opening one. ATTRS are the attributes at
2505 the start of the list. ID_LIST_OK is true if an identifier list is
2506 acceptable; such a list must not have attributes at the start. */
2508 static struct c_arg_info *
2509 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2512 declare_parm_level ();
2513 /* If the list starts with an identifier, it is an identifier list.
2514 Otherwise, it is either a prototype list or an empty list. */
2517 && c_parser_next_token_is (parser, CPP_NAME)
2518 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2520 tree list = NULL_TREE, *nextp = &list;
2521 while (c_parser_next_token_is (parser, CPP_NAME)
2522 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2524 *nextp = build_tree_list (NULL_TREE,
2525 c_parser_peek_token (parser)->value);
2526 nextp = & TREE_CHAIN (*nextp);
2527 c_parser_consume_token (parser);
2528 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2530 c_parser_consume_token (parser);
2531 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2533 c_parser_error (parser, "expected identifier");
2537 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2539 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2544 ret->pending_sizes = 0;
2545 ret->had_vla_unspec = 0;
2546 c_parser_consume_token (parser);
2552 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2560 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2566 /* Parse a parameter list (possibly empty), including the closing
2567 parenthesis but not the opening one. ATTRS are the attributes at
2568 the start of the list. */
2570 static struct c_arg_info *
2571 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2573 bool good_parm = false;
2574 /* ??? Following the old parser, forward parameter declarations may
2575 use abstract declarators, and if no real parameter declarations
2576 follow the forward declarations then this is not diagnosed. Also
2577 note as above that attributes are ignored as the only contents of
2578 the parentheses, or as the only contents after forward
2580 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2582 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2587 ret->pending_sizes = 0;
2588 ret->had_vla_unspec = 0;
2589 c_parser_consume_token (parser);
2592 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2594 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2598 ret->pending_sizes = 0;
2599 ret->had_vla_unspec = 0;
2600 /* Suppress -Wold-style-definition for this case. */
2601 ret->types = error_mark_node;
2602 error_at (c_parser_peek_token (parser)->location,
2603 "ISO C requires a named argument before %<...%>");
2604 c_parser_consume_token (parser);
2605 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2607 c_parser_consume_token (parser);
2612 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2617 /* Nonempty list of parameters, either terminated with semicolon
2618 (forward declarations; recurse) or with close parenthesis (normal
2619 function) or with ", ... )" (variadic function). */
2622 /* Parse a parameter. */
2623 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2628 push_parm_decl (parm);
2630 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2633 c_parser_consume_token (parser);
2634 mark_forward_parm_decls ();
2635 new_attrs = c_parser_attributes (parser);
2636 return c_parser_parms_list_declarator (parser, new_attrs);
2638 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2640 c_parser_consume_token (parser);
2642 return get_parm_info (false);
2645 struct c_arg_info *ret
2646 = XOBNEW (&parser_obstack, struct c_arg_info);
2651 ret->pending_sizes = 0;
2652 ret->had_vla_unspec = 0;
2656 if (!c_parser_require (parser, CPP_COMMA,
2657 "expected %<;%>, %<,%> or %<)%>"))
2659 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2660 get_pending_sizes ();
2663 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2665 c_parser_consume_token (parser);
2666 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2668 c_parser_consume_token (parser);
2670 return get_parm_info (true);
2673 struct c_arg_info *ret
2674 = XOBNEW (&parser_obstack, struct c_arg_info);
2679 ret->pending_sizes = 0;
2680 ret->had_vla_unspec = 0;
2686 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2688 get_pending_sizes ();
2695 /* Parse a parameter declaration. ATTRS are the attributes at the
2696 start of the declaration if it is the first parameter. */
2698 static struct c_parm *
2699 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2701 struct c_declspecs *specs;
2702 struct c_declarator *declarator;
2704 tree postfix_attrs = NULL_TREE;
2706 if (!c_parser_next_token_starts_declspecs (parser))
2708 /* ??? In some Objective-C cases '...' isn't applicable so there
2709 should be a different message. */
2710 c_parser_error (parser,
2711 "expected declaration specifiers or %<...%>");
2712 c_parser_skip_to_end_of_parameter (parser);
2715 specs = build_null_declspecs ();
2718 declspecs_add_attrs (specs, attrs);
2721 c_parser_declspecs (parser, specs, true, true, true);
2722 finish_declspecs (specs);
2723 pending_xref_error ();
2724 prefix_attrs = specs->attrs;
2725 specs->attrs = NULL_TREE;
2726 declarator = c_parser_declarator (parser, specs->type_seen_p,
2727 C_DTR_PARM, &dummy);
2728 if (declarator == NULL)
2730 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2733 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2734 postfix_attrs = c_parser_attributes (parser);
2735 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2739 /* Parse a string literal in an asm expression. It should not be
2740 translated, and wide string literals are an error although
2741 permitted by the syntax. This is a GNU extension.
2746 ??? At present, following the old parser, the caller needs to have
2747 set lex_untranslated_string to 1. It would be better to follow the
2748 C++ parser rather than using this kludge. */
2751 c_parser_asm_string_literal (c_parser *parser)
2754 if (c_parser_next_token_is (parser, CPP_STRING))
2756 str = c_parser_peek_token (parser)->value;
2757 c_parser_consume_token (parser);
2759 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2761 error_at (c_parser_peek_token (parser)->location,
2762 "wide string literal in %<asm%>");
2763 str = build_string (1, "");
2764 c_parser_consume_token (parser);
2768 c_parser_error (parser, "expected string literal");
2774 /* Parse a simple asm expression. This is used in restricted
2775 contexts, where a full expression with inputs and outputs does not
2776 make sense. This is a GNU extension.
2779 asm ( asm-string-literal )
2783 c_parser_simple_asm_expr (c_parser *parser)
2786 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2787 /* ??? Follow the C++ parser rather than using the
2788 lex_untranslated_string kludge. */
2789 parser->lex_untranslated_string = true;
2790 c_parser_consume_token (parser);
2791 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2793 parser->lex_untranslated_string = false;
2796 str = c_parser_asm_string_literal (parser);
2797 parser->lex_untranslated_string = false;
2798 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2800 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2806 /* Parse (possibly empty) attributes. This is a GNU extension.
2810 attributes attribute
2813 __attribute__ ( ( attribute-list ) )
2817 attribute_list , attrib
2822 any-word ( identifier )
2823 any-word ( identifier , nonempty-expr-list )
2824 any-word ( expr-list )
2826 where the "identifier" must not be declared as a type, and
2827 "any-word" may be any identifier (including one declared as a
2828 type), a reserved word storage class specifier, type specifier or
2829 type qualifier. ??? This still leaves out most reserved keywords
2830 (following the old parser), shouldn't we include them, and why not
2831 allow identifiers declared as types to start the arguments? */
2834 c_parser_attributes (c_parser *parser)
2836 tree attrs = NULL_TREE;
2837 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2839 /* ??? Follow the C++ parser rather than using the
2840 lex_untranslated_string kludge. */
2841 parser->lex_untranslated_string = true;
2842 c_parser_consume_token (parser);
2843 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2845 parser->lex_untranslated_string = false;
2848 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2850 parser->lex_untranslated_string = false;
2851 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2854 /* Parse the attribute list. */
2855 while (c_parser_next_token_is (parser, CPP_COMMA)
2856 || c_parser_next_token_is (parser, CPP_NAME)
2857 || c_parser_next_token_is (parser, CPP_KEYWORD))
2859 tree attr, attr_name, attr_args;
2860 VEC(tree,gc) *expr_list;
2861 if (c_parser_next_token_is (parser, CPP_COMMA))
2863 c_parser_consume_token (parser);
2866 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2868 /* ??? See comment above about what keywords are
2871 switch (c_parser_peek_token (parser)->keyword)
2908 /* Accept __attribute__((__const)) as __attribute__((const))
2911 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2914 attr_name = c_parser_peek_token (parser)->value;
2915 c_parser_consume_token (parser);
2916 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2918 attr = build_tree_list (attr_name, NULL_TREE);
2919 attrs = chainon (attrs, attr);
2922 c_parser_consume_token (parser);
2923 /* Parse the attribute contents. If they start with an
2924 identifier which is followed by a comma or close
2925 parenthesis, then the arguments start with that
2926 identifier; otherwise they are an expression list. */
2927 if (c_parser_next_token_is (parser, CPP_NAME)
2928 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2929 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2930 || (c_parser_peek_2nd_token (parser)->type
2931 == CPP_CLOSE_PAREN)))
2933 tree arg1 = c_parser_peek_token (parser)->value;
2934 c_parser_consume_token (parser);
2935 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2936 attr_args = build_tree_list (NULL_TREE, arg1);
2940 c_parser_consume_token (parser);
2941 expr_list = c_parser_expr_list (parser, false, true, NULL);
2942 tree_list = build_tree_list_vec (expr_list);
2943 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
2944 release_tree_vector (expr_list);
2949 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2950 attr_args = NULL_TREE;
2953 expr_list = c_parser_expr_list (parser, false, true, NULL);
2954 attr_args = build_tree_list_vec (expr_list);
2955 release_tree_vector (expr_list);
2958 attr = build_tree_list (attr_name, attr_args);
2959 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2960 c_parser_consume_token (parser);
2963 parser->lex_untranslated_string = false;
2964 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2968 attrs = chainon (attrs, attr);
2970 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2971 c_parser_consume_token (parser);
2974 parser->lex_untranslated_string = false;
2975 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2979 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2980 c_parser_consume_token (parser);
2983 parser->lex_untranslated_string = false;
2984 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2988 parser->lex_untranslated_string = false;
2993 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2996 specifier-qualifier-list abstract-declarator[opt]
2999 static struct c_type_name *
3000 c_parser_type_name (c_parser *parser)
3002 struct c_declspecs *specs = build_null_declspecs ();
3003 struct c_declarator *declarator;
3004 struct c_type_name *ret;
3006 c_parser_declspecs (parser, specs, false, true, true);
3007 if (!specs->declspecs_seen_p)
3009 c_parser_error (parser, "expected specifier-qualifier-list");
3012 pending_xref_error ();
3013 finish_declspecs (specs);
3014 declarator = c_parser_declarator (parser, specs->type_seen_p,
3015 C_DTR_ABSTRACT, &dummy);
3016 if (declarator == NULL)
3018 ret = XOBNEW (&parser_obstack, struct c_type_name);
3020 ret->declarator = declarator;
3024 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3027 assignment-expression
3028 { initializer-list }
3029 { initializer-list , }
3032 designation[opt] initializer
3033 initializer-list , designation[opt] initializer
3040 designator-list designator
3047 [ constant-expression ]
3059 [ constant-expression ... constant-expression ]
3061 Any expression without commas is accepted in the syntax for the
3062 constant-expressions, with non-constant expressions rejected later.
3064 This function is only used for top-level initializers; for nested
3065 ones, see c_parser_initval. */
3067 static struct c_expr
3068 c_parser_initializer (c_parser *parser)
3070 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3071 return c_parser_braced_init (parser, NULL_TREE, false);
3075 location_t loc = c_parser_peek_token (parser)->location;
3076 ret = c_parser_expr_no_commas (parser, NULL);
3077 if (TREE_CODE (ret.value) != STRING_CST
3078 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3079 ret = default_function_array_read_conversion (loc, ret);
3084 /* Parse a braced initializer list. TYPE is the type specified for a
3085 compound literal, and NULL_TREE for other initializers and for
3086 nested braced lists. NESTED_P is true for nested braced lists,
3087 false for the list of a compound literal or the list that is the
3088 top-level initializer in a declaration. */
3090 static struct c_expr
3091 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3094 struct obstack braced_init_obstack;
3095 location_t brace_loc = c_parser_peek_token (parser)->location;
3096 gcc_obstack_init (&braced_init_obstack);
3097 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3098 c_parser_consume_token (parser);
3100 push_init_level (0, &braced_init_obstack);
3102 really_start_incremental_init (type);
3103 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3105 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3109 /* Parse a non-empty initializer list, possibly with a trailing
3113 c_parser_initelt (parser, &braced_init_obstack);
3116 if (c_parser_next_token_is (parser, CPP_COMMA))
3117 c_parser_consume_token (parser);
3120 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3124 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3126 ret.value = error_mark_node;
3127 ret.original_code = ERROR_MARK;
3128 ret.original_type = NULL;
3129 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3130 pop_init_level (0, &braced_init_obstack);
3131 obstack_free (&braced_init_obstack, NULL);
3134 c_parser_consume_token (parser);
3135 ret = pop_init_level (0, &braced_init_obstack);
3136 obstack_free (&braced_init_obstack, NULL);
3140 /* Parse a nested initializer, including designators. */
3143 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3145 /* Parse any designator or designator list. A single array
3146 designator may have the subsequent "=" omitted in GNU C, but a
3147 longer list or a structure member designator may not. */
3148 if (c_parser_next_token_is (parser, CPP_NAME)
3149 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3151 /* Old-style structure member designator. */
3152 set_init_label (c_parser_peek_token (parser)->value,
3153 braced_init_obstack);
3154 /* Use the colon as the error location. */
3155 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3156 "obsolete use of designated initializer with %<:%>");
3157 c_parser_consume_token (parser);
3158 c_parser_consume_token (parser);
3162 /* des_seen is 0 if there have been no designators, 1 if there
3163 has been a single array designator and 2 otherwise. */
3165 /* Location of a designator. */
3166 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3167 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3168 || c_parser_next_token_is (parser, CPP_DOT))
3170 int des_prev = des_seen;
3172 des_loc = c_parser_peek_token (parser)->location;
3175 if (c_parser_next_token_is (parser, CPP_DOT))
3178 c_parser_consume_token (parser);
3179 if (c_parser_next_token_is (parser, CPP_NAME))
3181 set_init_label (c_parser_peek_token (parser)->value,
3182 braced_init_obstack);
3183 c_parser_consume_token (parser);
3188 init.value = error_mark_node;
3189 init.original_code = ERROR_MARK;
3190 init.original_type = NULL;
3191 c_parser_error (parser, "expected identifier");
3192 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3193 process_init_element (init, false, braced_init_obstack);
3200 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3201 /* ??? Following the old parser, [ objc-receiver
3202 objc-message-args ] is accepted as an initializer,
3203 being distinguished from a designator by what follows
3204 the first assignment expression inside the square
3205 brackets, but after a first array designator a
3206 subsequent square bracket is for Objective-C taken to
3207 start an expression, using the obsolete form of
3208 designated initializer without '=', rather than
3209 possibly being a second level of designation: in LALR
3210 terms, the '[' is shifted rather than reducing
3211 designator to designator-list. */
3212 if (des_prev == 1 && c_dialect_objc ())
3214 des_seen = des_prev;
3217 if (des_prev == 0 && c_dialect_objc ())
3219 /* This might be an array designator or an
3220 Objective-C message expression. If the former,
3221 continue parsing here; if the latter, parse the
3222 remainder of the initializer given the starting
3223 primary-expression. ??? It might make sense to
3224 distinguish when des_prev == 1 as well; see
3225 previous comment. */
3227 struct c_expr mexpr;
3228 c_parser_consume_token (parser);
3229 if (c_parser_peek_token (parser)->type == CPP_NAME
3230 && ((c_parser_peek_token (parser)->id_kind
3232 || (c_parser_peek_token (parser)->id_kind
3233 == C_ID_CLASSNAME)))
3235 /* Type name receiver. */
3236 tree id = c_parser_peek_token (parser)->value;
3237 c_parser_consume_token (parser);
3238 rec = objc_get_class_reference (id);
3239 goto parse_message_args;
3241 first = c_parser_expr_no_commas (parser, NULL).value;
3242 mark_exp_read (first);
3243 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3244 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3245 goto array_desig_after_first;
3246 /* Expression receiver. So far only one part
3247 without commas has been parsed; there might be
3248 more of the expression. */
3250 while (c_parser_next_token_is (parser, CPP_COMMA))
3253 location_t comma_loc, exp_loc;
3254 comma_loc = c_parser_peek_token (parser)->location;
3255 c_parser_consume_token (parser);
3256 exp_loc = c_parser_peek_token (parser)->location;
3257 next = c_parser_expr_no_commas (parser, NULL);
3258 next = default_function_array_read_conversion (exp_loc,
3260 rec = build_compound_expr (comma_loc, rec, next.value);
3263 /* Now parse the objc-message-args. */
3264 args = c_parser_objc_message_args (parser);
3265 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3268 = objc_build_message_expr (build_tree_list (rec, args));
3269 mexpr.original_code = ERROR_MARK;
3270 mexpr.original_type = NULL;
3271 /* Now parse and process the remainder of the
3272 initializer, starting with this message
3273 expression as a primary-expression. */
3274 c_parser_initval (parser, &mexpr, braced_init_obstack);
3277 c_parser_consume_token (parser);
3278 first = c_parser_expr_no_commas (parser, NULL).value;
3279 mark_exp_read (first);
3280 array_desig_after_first:
3281 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3283 ellipsis_loc = c_parser_peek_token (parser)->location;
3284 c_parser_consume_token (parser);
3285 second = c_parser_expr_no_commas (parser, NULL).value;
3286 mark_exp_read (second);
3290 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3292 c_parser_consume_token (parser);
3293 set_init_index (first, second, braced_init_obstack);
3295 pedwarn (ellipsis_loc, OPT_pedantic,
3296 "ISO C forbids specifying range of elements to initialize");
3299 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3305 if (c_parser_next_token_is (parser, CPP_EQ))
3308 pedwarn (des_loc, OPT_pedantic,
3309 "ISO C90 forbids specifying subobject to initialize");
3310 c_parser_consume_token (parser);
3315 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3316 "obsolete use of designated initializer without %<=%>");
3320 init.value = error_mark_node;
3321 init.original_code = ERROR_MARK;
3322 init.original_type = NULL;
3323 c_parser_error (parser, "expected %<=%>");
3324 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3325 process_init_element (init, false, braced_init_obstack);
3331 c_parser_initval (parser, NULL, braced_init_obstack);
3334 /* Parse a nested initializer; as c_parser_initializer but parses
3335 initializers within braced lists, after any designators have been
3336 applied. If AFTER is not NULL then it is an Objective-C message
3337 expression which is the primary-expression starting the
3341 c_parser_initval (c_parser *parser, struct c_expr *after,
3342 struct obstack * braced_init_obstack)
3345 gcc_assert (!after || c_dialect_objc ());
3346 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3347 init = c_parser_braced_init (parser, NULL_TREE, true);
3350 location_t loc = c_parser_peek_token (parser)->location;
3351 init = c_parser_expr_no_commas (parser, after);
3352 if (init.value != NULL_TREE
3353 && TREE_CODE (init.value) != STRING_CST
3354 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3355 init = default_function_array_read_conversion (loc, init);
3357 process_init_element (init, false, braced_init_obstack);
3360 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3364 { block-item-list[opt] }
3365 { label-declarations block-item-list }
3369 block-item-list block-item
3381 { label-declarations block-item-list }
3384 __extension__ nested-declaration
3385 nested-function-definition
3389 label-declarations label-declaration
3392 __label__ identifier-list ;
3394 Allowing the mixing of declarations and code is new in C99. The
3395 GNU syntax also permits (not shown above) labels at the end of
3396 compound statements, which yield an error. We don't allow labels
3397 on declarations; this might seem like a natural extension, but
3398 there would be a conflict between attributes on the label and
3399 prefix attributes on the declaration. ??? The syntax follows the
3400 old parser in requiring something after label declarations.
3401 Although they are erroneous if the labels declared aren't defined,
3402 is it useful for the syntax to be this way?
3414 c_parser_compound_statement (c_parser *parser)
3417 location_t brace_loc;
3418 brace_loc = c_parser_peek_token (parser)->location;
3419 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3421 /* Ensure a scope is entered and left anyway to avoid confusion
3422 if we have just prepared to enter a function body. */
3423 stmt = c_begin_compound_stmt (true);
3424 c_end_compound_stmt (brace_loc, stmt, true);
3425 return error_mark_node;
3427 stmt = c_begin_compound_stmt (true);
3428 c_parser_compound_statement_nostart (parser);
3429 return c_end_compound_stmt (brace_loc, stmt, true);
3432 /* Parse a compound statement except for the opening brace. This is
3433 used for parsing both compound statements and statement expressions
3434 (which follow different paths to handling the opening). */
3437 c_parser_compound_statement_nostart (c_parser *parser)
3439 bool last_stmt = false;
3440 bool last_label = false;
3441 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3442 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3443 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3445 c_parser_consume_token (parser);
3448 mark_valid_location_for_stdc_pragma (true);
3449 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3451 /* Read zero or more forward-declarations for labels that nested
3452 functions can jump to. */
3453 mark_valid_location_for_stdc_pragma (false);
3454 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3456 label_loc = c_parser_peek_token (parser)->location;
3457 c_parser_consume_token (parser);
3458 /* Any identifiers, including those declared as type names,
3463 if (c_parser_next_token_is_not (parser, CPP_NAME))
3465 c_parser_error (parser, "expected identifier");
3469 = declare_label (c_parser_peek_token (parser)->value);
3470 C_DECLARED_LABEL_FLAG (label) = 1;
3471 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3472 c_parser_consume_token (parser);
3473 if (c_parser_next_token_is (parser, CPP_COMMA))
3474 c_parser_consume_token (parser);
3478 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3480 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3482 /* We must now have at least one statement, label or declaration. */
3483 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3485 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3486 c_parser_error (parser, "expected declaration or statement");
3487 c_parser_consume_token (parser);
3490 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3492 location_t loc = c_parser_peek_token (parser)->location;
3493 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3494 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3495 || (c_parser_next_token_is (parser, CPP_NAME)
3496 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3498 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3499 label_loc = c_parser_peek_2nd_token (parser)->location;
3501 label_loc = c_parser_peek_token (parser)->location;
3504 mark_valid_location_for_stdc_pragma (false);
3505 c_parser_label (parser);
3507 else if (!last_label
3508 && c_parser_next_token_starts_declspecs (parser))
3511 mark_valid_location_for_stdc_pragma (false);
3512 c_parser_declaration_or_fndef (parser, true, true, true, true);
3515 (pedantic && !flag_isoc99)
3517 : OPT_Wdeclaration_after_statement,
3518 "ISO C90 forbids mixed declarations and code");
3521 else if (!last_label
3522 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3524 /* __extension__ can start a declaration, but is also an
3525 unary operator that can start an expression. Consume all
3526 but the last of a possible series of __extension__ to
3528 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3529 && (c_parser_peek_2nd_token (parser)->keyword
3531 c_parser_consume_token (parser);
3532 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3535 ext = disable_extension_diagnostics ();
3536 c_parser_consume_token (parser);
3538 mark_valid_location_for_stdc_pragma (false);
3539 c_parser_declaration_or_fndef (parser, true, true, true, true);
3540 /* Following the old parser, __extension__ does not
3541 disable this diagnostic. */
3542 restore_extension_diagnostics (ext);
3544 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3546 : OPT_Wdeclaration_after_statement,
3547 "ISO C90 forbids mixed declarations and code");
3553 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3555 /* External pragmas, and some omp pragmas, are not associated
3556 with regular c code, and so are not to be considered statements
3557 syntactically. This ensures that the user doesn't put them
3558 places that would turn into syntax errors if the directive
3560 if (c_parser_pragma (parser, pragma_compound))
3561 last_label = false, last_stmt = true;
3563 else if (c_parser_next_token_is (parser, CPP_EOF))
3565 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3566 c_parser_error (parser, "expected declaration or statement");
3569 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3571 if (parser->in_if_block)
3573 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3574 error_at (loc, """expected %<}%> before %<else%>");
3579 error_at (loc, "%<else%> without a previous %<if%>");
3580 c_parser_consume_token (parser);
3589 mark_valid_location_for_stdc_pragma (false);
3590 c_parser_statement_after_labels (parser);
3593 parser->error = false;
3596 error_at (label_loc, "label at end of compound statement");
3597 c_parser_consume_token (parser);
3598 /* Restore the value we started with. */
3599 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3602 /* Parse a label (C90 6.6.1, C99 6.8.1).
3605 identifier : attributes[opt]
3606 case constant-expression :
3612 case constant-expression ... constant-expression :
3614 The use of attributes on labels is a GNU extension. The syntax in
3615 GNU C accepts any expressions without commas, non-constant
3616 expressions being rejected later. */
3619 c_parser_label (c_parser *parser)
3621 location_t loc1 = c_parser_peek_token (parser)->location;
3622 tree label = NULL_TREE;
3623 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3626 c_parser_consume_token (parser);
3627 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3628 if (c_parser_next_token_is (parser, CPP_COLON))
3630 c_parser_consume_token (parser);
3631 label = do_case (loc1, exp1, NULL_TREE);
3633 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3635 c_parser_consume_token (parser);
3636 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3637 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3638 label = do_case (loc1, exp1, exp2);
3641 c_parser_error (parser, "expected %<:%> or %<...%>");
3643 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3645 c_parser_consume_token (parser);
3646 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3647 label = do_case (loc1, NULL_TREE, NULL_TREE);
3651 tree name = c_parser_peek_token (parser)->value;
3654 location_t loc2 = c_parser_peek_token (parser)->location;
3655 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3656 c_parser_consume_token (parser);
3657 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3658 c_parser_consume_token (parser);
3659 attrs = c_parser_attributes (parser);
3660 tlab = define_label (loc2, name);
3663 decl_attributes (&tlab, attrs, 0);
3664 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3669 if (c_parser_next_token_starts_declspecs (parser)
3670 && !(c_parser_next_token_is (parser, CPP_NAME)
3671 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3673 error_at (c_parser_peek_token (parser)->location,
3674 "a label can only be part of a statement and "
3675 "a declaration is not a statement");
3676 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3677 /*nested*/ true, /*empty_ok*/ false,
3678 /*start_attr_ok*/ true);
3683 /* Parse a statement (C90 6.6, C99 6.8).
3688 expression-statement
3696 expression-statement:
3699 selection-statement:
3703 iteration-statement:
3712 return expression[opt] ;
3725 objc-throw-statement
3726 objc-try-catch-statement
3727 objc-synchronized-statement
3729 objc-throw-statement:
3743 parallel-for-construct
3744 parallel-sections-construct
3751 parallel-directive structured-block
3754 for-directive iteration-statement
3757 sections-directive section-scope
3760 single-directive structured-block
3762 parallel-for-construct:
3763 parallel-for-directive iteration-statement
3765 parallel-sections-construct:
3766 parallel-sections-directive section-scope
3769 master-directive structured-block
3772 critical-directive structured-block
3775 atomic-directive expression-statement
3778 ordered-directive structured-block */
3781 c_parser_statement (c_parser *parser)
3783 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3784 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3785 || (c_parser_next_token_is (parser, CPP_NAME)
3786 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3787 c_parser_label (parser);
3788 c_parser_statement_after_labels (parser);
3791 /* Parse a statement, other than a labeled statement. */
3794 c_parser_statement_after_labels (c_parser *parser)
3796 location_t loc = c_parser_peek_token (parser)->location;
3797 tree stmt = NULL_TREE;
3798 bool in_if_block = parser->in_if_block;
3799 parser->in_if_block = false;
3800 switch (c_parser_peek_token (parser)->type)
3802 case CPP_OPEN_BRACE:
3803 add_stmt (c_parser_compound_statement (parser));
3806 switch (c_parser_peek_token (parser)->keyword)
3809 c_parser_if_statement (parser);
3812 c_parser_switch_statement (parser);
3815 c_parser_while_statement (parser);
3818 c_parser_do_statement (parser);
3821 c_parser_for_statement (parser);
3824 c_parser_consume_token (parser);
3825 if (c_parser_next_token_is (parser, CPP_NAME))
3827 stmt = c_finish_goto_label (loc,
3828 c_parser_peek_token (parser)->value);
3829 c_parser_consume_token (parser);
3831 else if (c_parser_next_token_is (parser, CPP_MULT))
3833 c_parser_consume_token (parser);
3834 stmt = c_finish_goto_ptr (loc,
3835 c_parser_expression (parser).value);
3838 c_parser_error (parser, "expected identifier or %<*%>");
3839 goto expect_semicolon;
3841 c_parser_consume_token (parser);
3842 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
3843 goto expect_semicolon;
3845 c_parser_consume_token (parser);
3846 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
3847 goto expect_semicolon;
3849 c_parser_consume_token (parser);
3850 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3852 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
3853 c_parser_consume_token (parser);
3857 struct c_expr expr = c_parser_expression_conv (parser);
3858 mark_exp_read (expr.value);
3859 stmt = c_finish_return (loc, expr.value, expr.original_type);
3860 goto expect_semicolon;
3864 stmt = c_parser_asm_statement (parser);
3867 gcc_assert (c_dialect_objc ());
3868 c_parser_consume_token (parser);
3869 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3871 stmt = objc_build_throw_stmt (loc, NULL_TREE);
3872 c_parser_consume_token (parser);
3876 tree expr = c_parser_expression (parser).value;
3877 expr = c_fully_fold (expr, false, NULL);
3878 stmt = objc_build_throw_stmt (loc, expr);
3879 goto expect_semicolon;
3883 gcc_assert (c_dialect_objc ());
3884 c_parser_objc_try_catch_statement (parser);
3886 case RID_AT_SYNCHRONIZED:
3887 gcc_assert (c_dialect_objc ());
3888 c_parser_objc_synchronized_statement (parser);
3895 c_parser_consume_token (parser);
3897 case CPP_CLOSE_PAREN:
3898 case CPP_CLOSE_SQUARE:
3899 /* Avoid infinite loop in error recovery:
3900 c_parser_skip_until_found stops at a closing nesting
3901 delimiter without consuming it, but here we need to consume
3902 it to proceed further. */
3903 c_parser_error (parser, "expected statement");
3904 c_parser_consume_token (parser);
3907 c_parser_pragma (parser, pragma_stmt);
3911 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
3913 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3916 /* Two cases cannot and do not have line numbers associated: If stmt
3917 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3918 cannot hold line numbers. But that's OK because the statement
3919 will either be changed to a MODIFY_EXPR during gimplification of
3920 the statement expr, or discarded. If stmt was compound, but
3921 without new variables, we will have skipped the creation of a
3922 BIND and will have a bare STATEMENT_LIST. But that's OK because
3923 (recursively) all of the component statements should already have
3924 line numbers assigned. ??? Can we discard no-op statements
3926 if (CAN_HAVE_LOCATION_P (stmt)
3927 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
3928 SET_EXPR_LOCATION (stmt, loc);
3930 parser->in_if_block = in_if_block;
3933 /* Parse the condition from an if, do, while or for statements. */
3936 c_parser_condition (c_parser *parser)
3938 location_t loc = c_parser_peek_token (parser)->location;
3940 cond = c_parser_expression_conv (parser).value;
3941 cond = c_objc_common_truthvalue_conversion (loc, cond);
3942 cond = c_fully_fold (cond, false, NULL);
3943 if (warn_sequence_point)
3944 verify_sequence_points (cond);
3948 /* Parse a parenthesized condition from an if, do or while statement.
3954 c_parser_paren_condition (c_parser *parser)
3957 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3958 return error_mark_node;
3959 cond = c_parser_condition (parser);
3960 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3964 /* Parse a statement which is a block in C99. */
3967 c_parser_c99_block_statement (c_parser *parser)
3969 tree block = c_begin_compound_stmt (flag_isoc99);
3970 location_t loc = c_parser_peek_token (parser)->location;
3971 c_parser_statement (parser);
3972 return c_end_compound_stmt (loc, block, flag_isoc99);
3975 /* Parse the body of an if statement. This is just parsing a
3976 statement but (a) it is a block in C99, (b) we track whether the
3977 body is an if statement for the sake of -Wparentheses warnings, (c)
3978 we handle an empty body specially for the sake of -Wempty-body
3979 warnings, and (d) we call parser_compound_statement directly
3980 because c_parser_statement_after_labels resets
3981 parser->in_if_block. */
3984 c_parser_if_body (c_parser *parser, bool *if_p)
3986 tree block = c_begin_compound_stmt (flag_isoc99);
3987 location_t body_loc = c_parser_peek_token (parser)->location;
3988 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3989 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3990 || (c_parser_next_token_is (parser, CPP_NAME)
3991 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3992 c_parser_label (parser);
3993 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3994 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3996 location_t loc = c_parser_peek_token (parser)->location;
3997 add_stmt (build_empty_stmt (loc));
3998 c_parser_consume_token (parser);
3999 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
4000 warning_at (loc, OPT_Wempty_body,
4001 "suggest braces around empty body in an %<if%> statement");
4003 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4004 add_stmt (c_parser_compound_statement (parser));
4006 c_parser_statement_after_labels (parser);
4007 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4010 /* Parse the else body of an if statement. This is just parsing a
4011 statement but (a) it is a block in C99, (b) we handle an empty body
4012 specially for the sake of -Wempty-body warnings. */
4015 c_parser_else_body (c_parser *parser)
4017 location_t else_loc = c_parser_peek_token (parser)->location;
4018 tree block = c_begin_compound_stmt (flag_isoc99);
4019 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4020 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4021 || (c_parser_next_token_is (parser, CPP_NAME)
4022 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4023 c_parser_label (parser);
4024 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4026 location_t loc = c_parser_peek_token (parser)->location;
4029 "suggest braces around empty body in an %<else%> statement");
4030 add_stmt (build_empty_stmt (loc));
4031 c_parser_consume_token (parser);
4034 c_parser_statement_after_labels (parser);
4035 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4038 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4041 if ( expression ) statement
4042 if ( expression ) statement else statement
4046 c_parser_if_statement (c_parser *parser)
4051 bool first_if = false;
4052 tree first_body, second_body;
4055 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4056 c_parser_consume_token (parser);
4057 block = c_begin_compound_stmt (flag_isoc99);
4058 loc = c_parser_peek_token (parser)->location;
4059 cond = c_parser_paren_condition (parser);
4060 in_if_block = parser->in_if_block;
4061 parser->in_if_block = true;
4062 first_body = c_parser_if_body (parser, &first_if);
4063 parser->in_if_block = in_if_block;
4064 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4066 c_parser_consume_token (parser);
4067 second_body = c_parser_else_body (parser);
4070 second_body = NULL_TREE;
4071 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4072 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4075 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4078 switch (expression) statement
4082 c_parser_switch_statement (c_parser *parser)
4084 tree block, expr, body, save_break;
4085 location_t switch_loc = c_parser_peek_token (parser)->location;
4086 location_t switch_cond_loc;
4087 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4088 c_parser_consume_token (parser);
4089 block = c_begin_compound_stmt (flag_isoc99);
4090 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4092 switch_cond_loc = c_parser_peek_token (parser)->location;
4093 expr = c_parser_expression (parser).value;
4094 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4098 switch_cond_loc = UNKNOWN_LOCATION;
4099 expr = error_mark_node;
4101 c_start_case (switch_loc, switch_cond_loc, expr);
4102 save_break = c_break_label;
4103 c_break_label = NULL_TREE;
4104 body = c_parser_c99_block_statement (parser);
4105 c_finish_case (body);
4108 location_t here = c_parser_peek_token (parser)->location;
4109 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4110 SET_EXPR_LOCATION (t, here);
4113 c_break_label = save_break;
4114 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4117 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4120 while (expression) statement
4124 c_parser_while_statement (c_parser *parser)
4126 tree block, cond, body, save_break, save_cont;
4128 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4129 c_parser_consume_token (parser);
4130 block = c_begin_compound_stmt (flag_isoc99);
4131 loc = c_parser_peek_token (parser)->location;
4132 cond = c_parser_paren_condition (parser);
4133 save_break = c_break_label;
4134 c_break_label = NULL_TREE;
4135 save_cont = c_cont_label;
4136 c_cont_label = NULL_TREE;
4137 body = c_parser_c99_block_statement (parser);
4138 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4139 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4140 c_break_label = save_break;
4141 c_cont_label = save_cont;
4144 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4147 do statement while ( expression ) ;
4151 c_parser_do_statement (c_parser *parser)
4153 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4155 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4156 c_parser_consume_token (parser);
4157 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4158 warning_at (c_parser_peek_token (parser)->location,
4160 "suggest braces around empty body in %<do%> statement");
4161 block = c_begin_compound_stmt (flag_isoc99);
4162 loc = c_parser_peek_token (parser)->location;
4163 save_break = c_break_label;
4164 c_break_label = NULL_TREE;
4165 save_cont = c_cont_label;
4166 c_cont_label = NULL_TREE;
4167 body = c_parser_c99_block_statement (parser);
4168 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4169 new_break = c_break_label;
4170 c_break_label = save_break;
4171 new_cont = c_cont_label;
4172 c_cont_label = save_cont;
4173 cond = c_parser_paren_condition (parser);
4174 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4175 c_parser_skip_to_end_of_block_or_statement (parser);
4176 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4177 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4180 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4183 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4184 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4186 The form with a declaration is new in C99.
4188 ??? In accordance with the old parser, the declaration may be a
4189 nested function, which is then rejected in check_for_loop_decls,
4190 but does it make any sense for this to be included in the grammar?
4191 Note in particular that the nested function does not include a
4192 trailing ';', whereas the "declaration" production includes one.
4193 Also, can we reject bad declarations earlier and cheaper than
4194 check_for_loop_decls? */
4197 c_parser_for_statement (c_parser *parser)
4199 tree block, cond, incr, save_break, save_cont, body;
4200 location_t loc = c_parser_peek_token (parser)->location;
4201 location_t for_loc = c_parser_peek_token (parser)->location;
4202 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4203 c_parser_consume_token (parser);
4204 block = c_begin_compound_stmt (flag_isoc99);
4205 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4207 /* Parse the initialization declaration or expression. */
4208 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4210 c_parser_consume_token (parser);
4211 c_finish_expr_stmt (loc, NULL_TREE);
4213 else if (c_parser_next_token_starts_declspecs (parser))
4215 c_parser_declaration_or_fndef (parser, true, true, true, true);
4216 check_for_loop_decls (for_loc);
4218 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4220 /* __extension__ can start a declaration, but is also an
4221 unary operator that can start an expression. Consume all
4222 but the last of a possible series of __extension__ to
4224 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4225 && (c_parser_peek_2nd_token (parser)->keyword
4227 c_parser_consume_token (parser);
4228 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4231 ext = disable_extension_diagnostics ();
4232 c_parser_consume_token (parser);
4233 c_parser_declaration_or_fndef (parser, true, true, true, true);
4234 restore_extension_diagnostics (ext);
4235 check_for_loop_decls (for_loc);
4243 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4244 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4246 /* Parse the loop condition. */
4247 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4249 c_parser_consume_token (parser);
4254 cond = c_parser_condition (parser);
4255 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4257 /* Parse the increment expression. */
4258 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4259 incr = c_process_expr_stmt (loc, NULL_TREE);
4261 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4262 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4266 cond = error_mark_node;
4267 incr = error_mark_node;
4269 save_break = c_break_label;
4270 c_break_label = NULL_TREE;
4271 save_cont = c_cont_label;
4272 c_cont_label = NULL_TREE;
4273 body = c_parser_c99_block_statement (parser);
4274 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4275 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4276 c_break_label = save_break;
4277 c_cont_label = save_cont;
4280 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4281 statement with inputs, outputs, clobbers, and volatile tag
4285 asm type-qualifier[opt] ( asm-argument ) ;
4286 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4290 asm-string-literal : asm-operands[opt]
4291 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4292 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4295 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4298 Qualifiers other than volatile are accepted in the syntax but
4302 c_parser_asm_statement (c_parser *parser)
4304 tree quals, str, outputs, inputs, clobbers, labels, ret;
4305 bool simple, is_goto;
4306 location_t asm_loc = c_parser_peek_token (parser)->location;
4307 int section, nsections;
4309 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4310 c_parser_consume_token (parser);
4311 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4313 quals = c_parser_peek_token (parser)->value;
4314 c_parser_consume_token (parser);
4316 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4317 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4319 warning_at (c_parser_peek_token (parser)->location,
4321 "%E qualifier ignored on asm",
4322 c_parser_peek_token (parser)->value);
4324 c_parser_consume_token (parser);
4330 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4332 c_parser_consume_token (parser);
4336 /* ??? Follow the C++ parser rather than using the
4337 lex_untranslated_string kludge. */
4338 parser->lex_untranslated_string = true;
4341 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4344 str = c_parser_asm_string_literal (parser);
4345 if (str == NULL_TREE)
4346 goto error_close_paren;
4349 outputs = NULL_TREE;
4351 clobbers = NULL_TREE;
4354 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4357 /* Parse each colon-delimited section of operands. */
4358 nsections = 3 + is_goto;
4359 for (section = 0; section < nsections; ++section)
4361 if (!c_parser_require (parser, CPP_COLON,
4364 : "expected %<:%> or %<)%>"))
4365 goto error_close_paren;
4367 /* Once past any colon, we're no longer a simple asm. */
4370 if ((!c_parser_next_token_is (parser, CPP_COLON)
4371 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4376 /* For asm goto, we don't allow output operands, but reserve
4377 the slot for a future extension that does allow them. */
4379 outputs = c_parser_asm_operands (parser, false);
4382 inputs = c_parser_asm_operands (parser, true);
4385 clobbers = c_parser_asm_clobbers (parser);
4388 labels = c_parser_asm_goto_operands (parser);
4394 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4399 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4401 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4405 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4406 c_parser_skip_to_end_of_block_or_statement (parser);
4408 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4409 clobbers, labels, simple));
4412 parser->lex_untranslated_string = false;
4416 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4420 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4421 not outputs), apply the default conversion of functions and arrays
4426 asm-operands , asm-operand
4429 asm-string-literal ( expression )
4430 [ identifier ] asm-string-literal ( expression )
4434 c_parser_asm_operands (c_parser *parser, bool convert_p)
4436 tree list = NULL_TREE;
4442 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4444 c_parser_consume_token (parser);
4445 if (c_parser_next_token_is (parser, CPP_NAME))
4447 tree id = c_parser_peek_token (parser)->value;
4448 c_parser_consume_token (parser);
4449 name = build_string (IDENTIFIER_LENGTH (id),
4450 IDENTIFIER_POINTER (id));
4454 c_parser_error (parser, "expected identifier");
4455 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4458 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4463 str = c_parser_asm_string_literal (parser);
4464 if (str == NULL_TREE)
4466 parser->lex_untranslated_string = false;
4467 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4469 parser->lex_untranslated_string = true;
4472 loc = c_parser_peek_token (parser)->location;
4473 expr = c_parser_expression (parser);
4474 mark_exp_read (expr.value);
4476 expr = default_function_array_conversion (loc, expr);
4477 expr.value = c_fully_fold (expr.value, false, NULL);
4478 parser->lex_untranslated_string = true;
4479 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4481 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4484 list = chainon (list, build_tree_list (build_tree_list (name, str),
4486 if (c_parser_next_token_is (parser, CPP_COMMA))
4487 c_parser_consume_token (parser);
4494 /* Parse asm clobbers, a GNU extension.
4498 asm-clobbers , asm-string-literal
4502 c_parser_asm_clobbers (c_parser *parser)
4504 tree list = NULL_TREE;
4507 tree str = c_parser_asm_string_literal (parser);
4509 list = tree_cons (NULL_TREE, str, list);
4512 if (c_parser_next_token_is (parser, CPP_COMMA))
4513 c_parser_consume_token (parser);
4520 /* Parse asm goto labels, a GNU extension.
4524 asm-goto-operands , identifier
4528 c_parser_asm_goto_operands (c_parser *parser)
4530 tree list = NULL_TREE;
4535 if (c_parser_next_token_is (parser, CPP_NAME))
4537 c_token *tok = c_parser_peek_token (parser);
4539 label = lookup_label_for_goto (tok->location, name);
4540 c_parser_consume_token (parser);
4541 TREE_USED (label) = 1;
4545 c_parser_error (parser, "expected identifier");
4549 name = build_string (IDENTIFIER_LENGTH (name),
4550 IDENTIFIER_POINTER (name));
4551 list = tree_cons (name, label, list);
4552 if (c_parser_next_token_is (parser, CPP_COMMA))
4553 c_parser_consume_token (parser);
4555 return nreverse (list);
4559 /* Parse an expression other than a compound expression; that is, an
4560 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4561 NULL then it is an Objective-C message expression which is the
4562 primary-expression starting the expression as an initializer.
4564 assignment-expression:
4565 conditional-expression
4566 unary-expression assignment-operator assignment-expression
4568 assignment-operator: one of
4569 = *= /= %= += -= <<= >>= &= ^= |=
4571 In GNU C we accept any conditional expression on the LHS and
4572 diagnose the invalid lvalue rather than producing a syntax
4575 static struct c_expr
4576 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4578 struct c_expr lhs, rhs, ret;
4579 enum tree_code code;
4580 location_t op_location, exp_location;
4581 gcc_assert (!after || c_dialect_objc ());
4582 lhs = c_parser_conditional_expression (parser, after);
4583 op_location = c_parser_peek_token (parser)->location;
4584 switch (c_parser_peek_token (parser)->type)
4593 code = TRUNC_DIV_EXPR;
4596 code = TRUNC_MOD_EXPR;
4611 code = BIT_AND_EXPR;
4614 code = BIT_XOR_EXPR;
4617 code = BIT_IOR_EXPR;
4622 c_parser_consume_token (parser);
4623 exp_location = c_parser_peek_token (parser)->location;
4624 rhs = c_parser_expr_no_commas (parser, NULL);
4625 rhs = default_function_array_read_conversion (exp_location, rhs);
4626 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4627 code, exp_location, rhs.value,
4629 if (code == NOP_EXPR)
4630 ret.original_code = MODIFY_EXPR;
4633 TREE_NO_WARNING (ret.value) = 1;
4634 ret.original_code = ERROR_MARK;
4636 ret.original_type = NULL;
4640 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4641 is not NULL then it is an Objective-C message expression which is
4642 the primary-expression starting the expression as an initializer.
4644 conditional-expression:
4645 logical-OR-expression
4646 logical-OR-expression ? expression : conditional-expression
4650 conditional-expression:
4651 logical-OR-expression ? : conditional-expression
4654 static struct c_expr
4655 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4657 struct c_expr cond, exp1, exp2, ret;
4658 location_t cond_loc, colon_loc;
4660 gcc_assert (!after || c_dialect_objc ());
4662 cond = c_parser_binary_expression (parser, after);
4664 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4666 cond_loc = c_parser_peek_token (parser)->location;
4667 cond = default_function_array_read_conversion (cond_loc, cond);
4668 c_parser_consume_token (parser);
4669 if (c_parser_next_token_is (parser, CPP_COLON))
4671 tree eptype = NULL_TREE;
4672 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4673 "ISO C forbids omitting the middle term of a ?: expression");
4674 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4676 eptype = TREE_TYPE (cond.value);
4677 cond.value = TREE_OPERAND (cond.value, 0);
4679 /* Make sure first operand is calculated only once. */
4680 exp1.value = c_save_expr (default_conversion (cond.value));
4682 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4683 exp1.original_type = NULL;
4684 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4685 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4690 = c_objc_common_truthvalue_conversion
4691 (cond_loc, default_conversion (cond.value));
4692 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4693 exp1 = c_parser_expression_conv (parser);
4694 mark_exp_read (exp1.value);
4695 c_inhibit_evaluation_warnings +=
4696 ((cond.value == truthvalue_true_node)
4697 - (cond.value == truthvalue_false_node));
4700 colon_loc = c_parser_peek_token (parser)->location;
4701 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4703 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4704 ret.value = error_mark_node;
4705 ret.original_code = ERROR_MARK;
4706 ret.original_type = NULL;
4710 location_t exp2_loc = c_parser_peek_token (parser)->location;
4711 exp2 = c_parser_conditional_expression (parser, NULL);
4712 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
4714 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4715 ret.value = build_conditional_expr (colon_loc, cond.value,
4716 cond.original_code == C_MAYBE_CONST_EXPR,
4717 exp1.value, exp1.original_type,
4718 exp2.value, exp2.original_type);
4719 ret.original_code = ERROR_MARK;
4720 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4721 ret.original_type = NULL;
4726 /* If both sides are enum type, the default conversion will have
4727 made the type of the result be an integer type. We want to
4728 remember the enum types we started with. */
4729 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4730 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4731 ret.original_type = ((t1 != error_mark_node
4732 && t2 != error_mark_node
4733 && (TYPE_MAIN_VARIANT (t1)
4734 == TYPE_MAIN_VARIANT (t2)))
4741 /* Parse a binary expression; that is, a logical-OR-expression (C90
4742 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4743 an Objective-C message expression which is the primary-expression
4744 starting the expression as an initializer.
4746 multiplicative-expression:
4748 multiplicative-expression * cast-expression
4749 multiplicative-expression / cast-expression
4750 multiplicative-expression % cast-expression
4752 additive-expression:
4753 multiplicative-expression
4754 additive-expression + multiplicative-expression
4755 additive-expression - multiplicative-expression
4759 shift-expression << additive-expression
4760 shift-expression >> additive-expression
4762 relational-expression:
4764 relational-expression < shift-expression
4765 relational-expression > shift-expression
4766 relational-expression <= shift-expression
4767 relational-expression >= shift-expression
4769 equality-expression:
4770 relational-expression
4771 equality-expression == relational-expression
4772 equality-expression != relational-expression
4776 AND-expression & equality-expression
4778 exclusive-OR-expression:
4780 exclusive-OR-expression ^ AND-expression
4782 inclusive-OR-expression:
4783 exclusive-OR-expression
4784 inclusive-OR-expression | exclusive-OR-expression
4786 logical-AND-expression:
4787 inclusive-OR-expression
4788 logical-AND-expression && inclusive-OR-expression
4790 logical-OR-expression:
4791 logical-AND-expression
4792 logical-OR-expression || logical-AND-expression
4795 static struct c_expr
4796 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4798 /* A binary expression is parsed using operator-precedence parsing,
4799 with the operands being cast expressions. All the binary
4800 operators are left-associative. Thus a binary expression is of
4803 E0 op1 E1 op2 E2 ...
4805 which we represent on a stack. On the stack, the precedence
4806 levels are strictly increasing. When a new operator is
4807 encountered of higher precedence than that at the top of the
4808 stack, it is pushed; its LHS is the top expression, and its RHS
4809 is everything parsed until it is popped. When a new operator is
4810 encountered with precedence less than or equal to that at the top
4811 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4812 by the result of the operation until the operator at the top of
4813 the stack has lower precedence than the new operator or there is
4814 only one element on the stack; then the top expression is the LHS
4815 of the new operator. In the case of logical AND and OR
4816 expressions, we also need to adjust c_inhibit_evaluation_warnings
4817 as appropriate when the operators are pushed and popped. */
4819 /* The precedence levels, where 0 is a dummy lowest level used for
4820 the bottom of the stack. */
4836 /* The expression at this stack level. */
4838 /* The precedence of the operator on its left, PREC_NONE at the
4839 bottom of the stack. */
4841 /* The operation on its left. */
4843 /* The source location of this operation. */
4847 /* Location of the binary operator. */
4848 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4851 switch (stack[sp].op) \
4853 case TRUTH_ANDIF_EXPR: \
4854 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4855 == truthvalue_false_node); \
4857 case TRUTH_ORIF_EXPR: \
4858 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4859 == truthvalue_true_node); \
4864 stack[sp - 1].expr \
4865 = default_function_array_read_conversion (stack[sp - 1].loc, \
4866 stack[sp - 1].expr); \
4868 = default_function_array_read_conversion (stack[sp].loc, \
4870 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4872 stack[sp - 1].expr, \
4876 gcc_assert (!after || c_dialect_objc ());
4877 stack[0].loc = c_parser_peek_token (parser)->location;
4878 stack[0].expr = c_parser_cast_expression (parser, after);
4879 stack[0].prec = PREC_NONE;
4884 enum tree_code ocode;
4887 switch (c_parser_peek_token (parser)->type)
4895 ocode = TRUNC_DIV_EXPR;
4899 ocode = TRUNC_MOD_EXPR;
4911 ocode = LSHIFT_EXPR;
4915 ocode = RSHIFT_EXPR;
4929 case CPP_GREATER_EQ:
4942 oprec = PREC_BITAND;
4943 ocode = BIT_AND_EXPR;
4946 oprec = PREC_BITXOR;
4947 ocode = BIT_XOR_EXPR;
4951 ocode = BIT_IOR_EXPR;
4954 oprec = PREC_LOGAND;
4955 ocode = TRUTH_ANDIF_EXPR;
4959 ocode = TRUTH_ORIF_EXPR;
4962 /* Not a binary operator, so end of the binary
4966 binary_loc = c_parser_peek_token (parser)->location;
4967 c_parser_consume_token (parser);
4968 while (oprec <= stack[sp].prec)
4972 case TRUTH_ANDIF_EXPR:
4974 = default_function_array_read_conversion (stack[sp].loc,
4976 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4977 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4978 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4979 == truthvalue_false_node);
4981 case TRUTH_ORIF_EXPR:
4983 = default_function_array_read_conversion (stack[sp].loc,
4985 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4986 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4987 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4988 == truthvalue_true_node);
4994 stack[sp].loc = binary_loc;
4995 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4996 stack[sp].prec = oprec;
4997 stack[sp].op = ocode;
4998 stack[sp].loc = binary_loc;
5003 return stack[0].expr;
5007 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5008 NULL then it is an Objective-C message expression which is the
5009 primary-expression starting the expression as an initializer.
5013 ( type-name ) unary-expression
5016 static struct c_expr
5017 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5019 location_t cast_loc = c_parser_peek_token (parser)->location;
5020 gcc_assert (!after || c_dialect_objc ());
5022 return c_parser_postfix_expression_after_primary (parser,
5024 /* If the expression begins with a parenthesized type name, it may
5025 be either a cast or a compound literal; we need to see whether
5026 the next character is '{' to tell the difference. If not, it is
5027 an unary expression. */
5028 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5029 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5031 struct c_type_name *type_name;
5034 c_parser_consume_token (parser);
5035 type_name = c_parser_type_name (parser);
5036 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5037 if (type_name == NULL)
5039 ret.value = error_mark_node;
5040 ret.original_code = ERROR_MARK;
5041 ret.original_type = NULL;
5045 /* Save casted types in the function's used types hash table. */
5046 used_types_insert (type_name->specs->type);
5048 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5049 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5052 location_t expr_loc = c_parser_peek_token (parser)->location;
5053 expr = c_parser_cast_expression (parser, NULL);
5054 expr = default_function_array_read_conversion (expr_loc, expr);
5056 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5057 ret.original_code = ERROR_MARK;
5058 ret.original_type = NULL;
5062 return c_parser_unary_expression (parser);
5065 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5071 unary-operator cast-expression
5072 sizeof unary-expression
5073 sizeof ( type-name )
5075 unary-operator: one of
5081 __alignof__ unary-expression
5082 __alignof__ ( type-name )
5085 unary-operator: one of
5086 __extension__ __real__ __imag__
5088 In addition, the GNU syntax treats ++ and -- as unary operators, so
5089 they may be applied to cast expressions with errors for non-lvalues
5092 static struct c_expr
5093 c_parser_unary_expression (c_parser *parser)
5096 struct c_expr ret, op;
5097 location_t op_loc = c_parser_peek_token (parser)->location;
5099 ret.original_code = ERROR_MARK;
5100 ret.original_type = NULL;
5101 switch (c_parser_peek_token (parser)->type)
5104 c_parser_consume_token (parser);
5105 exp_loc = c_parser_peek_token (parser)->location;
5106 op = c_parser_cast_expression (parser, NULL);
5107 op = default_function_array_read_conversion (exp_loc, op);
5108 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5109 case CPP_MINUS_MINUS:
5110 c_parser_consume_token (parser);
5111 exp_loc = c_parser_peek_token (parser)->location;
5112 op = c_parser_cast_expression (parser, NULL);
5113 op = default_function_array_read_conversion (exp_loc, op);
5114 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5116 c_parser_consume_token (parser);
5117 op = c_parser_cast_expression (parser, NULL);
5118 mark_exp_read (op.value);
5119 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5121 c_parser_consume_token (parser);
5122 exp_loc = c_parser_peek_token (parser)->location;
5123 op = c_parser_cast_expression (parser, NULL);
5124 op = default_function_array_read_conversion (exp_loc, op);
5125 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5128 if (!c_dialect_objc () && !in_system_header)
5131 "traditional C rejects the unary plus operator");
5132 c_parser_consume_token (parser);
5133 exp_loc = c_parser_peek_token (parser)->location;
5134 op = c_parser_cast_expression (parser, NULL);
5135 op = default_function_array_read_conversion (exp_loc, op);
5136 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5138 c_parser_consume_token (parser);
5139 exp_loc = c_parser_peek_token (parser)->location;
5140 op = c_parser_cast_expression (parser, NULL);
5141 op = default_function_array_read_conversion (exp_loc, op);
5142 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5144 c_parser_consume_token (parser);
5145 exp_loc = c_parser_peek_token (parser)->location;
5146 op = c_parser_cast_expression (parser, NULL);
5147 op = default_function_array_read_conversion (exp_loc, op);
5148 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5150 c_parser_consume_token (parser);
5151 exp_loc = c_parser_peek_token (parser)->location;
5152 op = c_parser_cast_expression (parser, NULL);
5153 op = default_function_array_read_conversion (exp_loc, op);
5154 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5156 /* Refer to the address of a label as a pointer. */
5157 c_parser_consume_token (parser);
5158 if (c_parser_next_token_is (parser, CPP_NAME))
5160 ret.value = finish_label_address_expr
5161 (c_parser_peek_token (parser)->value, op_loc);
5162 c_parser_consume_token (parser);
5166 c_parser_error (parser, "expected identifier");
5167 ret.value = error_mark_node;
5171 switch (c_parser_peek_token (parser)->keyword)
5174 return c_parser_sizeof_expression (parser);
5176 return c_parser_alignof_expression (parser);
5178 c_parser_consume_token (parser);
5179 ext = disable_extension_diagnostics ();
5180 ret = c_parser_cast_expression (parser, NULL);
5181 restore_extension_diagnostics (ext);
5184 c_parser_consume_token (parser);
5185 exp_loc = c_parser_peek_token (parser)->location;
5186 op = c_parser_cast_expression (parser, NULL);
5187 op = default_function_array_conversion (exp_loc, op);
5188 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5190 c_parser_consume_token (parser);
5191 exp_loc = c_parser_peek_token (parser)->location;
5192 op = c_parser_cast_expression (parser, NULL);
5193 op = default_function_array_conversion (exp_loc, op);
5194 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5196 return c_parser_postfix_expression (parser);
5199 return c_parser_postfix_expression (parser);
5203 /* Parse a sizeof expression. */
5205 static struct c_expr
5206 c_parser_sizeof_expression (c_parser *parser)
5209 location_t expr_loc;
5210 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5211 c_parser_consume_token (parser);
5212 c_inhibit_evaluation_warnings++;
5214 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5215 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5217 /* Either sizeof ( type-name ) or sizeof unary-expression
5218 starting with a compound literal. */
5219 struct c_type_name *type_name;
5220 c_parser_consume_token (parser);
5221 expr_loc = c_parser_peek_token (parser)->location;
5222 type_name = c_parser_type_name (parser);
5223 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5224 if (type_name == NULL)
5227 c_inhibit_evaluation_warnings--;
5229 ret.value = error_mark_node;
5230 ret.original_code = ERROR_MARK;
5231 ret.original_type = NULL;
5234 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5236 expr = c_parser_postfix_expression_after_paren_type (parser,
5241 /* sizeof ( type-name ). */
5242 c_inhibit_evaluation_warnings--;
5244 return c_expr_sizeof_type (expr_loc, type_name);
5248 expr_loc = c_parser_peek_token (parser)->location;
5249 expr = c_parser_unary_expression (parser);
5251 c_inhibit_evaluation_warnings--;
5253 mark_exp_read (expr.value);
5254 if (TREE_CODE (expr.value) == COMPONENT_REF
5255 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5256 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5257 return c_expr_sizeof_expr (expr_loc, expr);
5261 /* Parse an alignof expression. */
5263 static struct c_expr
5264 c_parser_alignof_expression (c_parser *parser)
5267 location_t loc = c_parser_peek_token (parser)->location;
5268 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5269 c_parser_consume_token (parser);
5270 c_inhibit_evaluation_warnings++;
5272 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5273 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5275 /* Either __alignof__ ( type-name ) or __alignof__
5276 unary-expression starting with a compound literal. */
5278 struct c_type_name *type_name;
5280 c_parser_consume_token (parser);
5281 loc = c_parser_peek_token (parser)->location;
5282 type_name = c_parser_type_name (parser);
5283 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5284 if (type_name == NULL)
5287 c_inhibit_evaluation_warnings--;
5289 ret.value = error_mark_node;
5290 ret.original_code = ERROR_MARK;
5291 ret.original_type = NULL;
5294 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5296 expr = c_parser_postfix_expression_after_paren_type (parser,
5301 /* alignof ( type-name ). */
5302 c_inhibit_evaluation_warnings--;
5304 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5305 ret.original_code = ERROR_MARK;
5306 ret.original_type = NULL;
5312 expr = c_parser_unary_expression (parser);
5314 mark_exp_read (expr.value);
5315 c_inhibit_evaluation_warnings--;
5317 ret.value = c_alignof_expr (loc, expr.value);
5318 ret.original_code = ERROR_MARK;
5319 ret.original_type = NULL;
5324 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5328 postfix-expression [ expression ]
5329 postfix-expression ( argument-expression-list[opt] )
5330 postfix-expression . identifier
5331 postfix-expression -> identifier
5332 postfix-expression ++
5333 postfix-expression --
5334 ( type-name ) { initializer-list }
5335 ( type-name ) { initializer-list , }
5337 argument-expression-list:
5339 argument-expression-list , argument-expression
5351 (treated as a keyword in GNU C)
5354 ( compound-statement )
5355 __builtin_va_arg ( assignment-expression , type-name )
5356 __builtin_offsetof ( type-name , offsetof-member-designator )
5357 __builtin_choose_expr ( assignment-expression ,
5358 assignment-expression ,
5359 assignment-expression )
5360 __builtin_types_compatible_p ( type-name , type-name )
5362 offsetof-member-designator:
5364 offsetof-member-designator . identifier
5365 offsetof-member-designator [ expression ]
5370 [ objc-receiver objc-message-args ]
5371 @selector ( objc-selector-arg )
5372 @protocol ( identifier )
5373 @encode ( type-name )
5377 static struct c_expr
5378 c_parser_postfix_expression (c_parser *parser)
5380 struct c_expr expr, e1, e2, e3;
5381 struct c_type_name *t1, *t2;
5382 location_t loc = c_parser_peek_token (parser)->location;;
5383 expr.original_code = ERROR_MARK;
5384 expr.original_type = NULL;
5385 switch (c_parser_peek_token (parser)->type)
5388 expr.value = c_parser_peek_token (parser)->value;
5389 loc = c_parser_peek_token (parser)->location;
5390 c_parser_consume_token (parser);
5391 if (TREE_CODE (expr.value) == FIXED_CST
5392 && !targetm.fixed_point_supported_p ())
5394 error_at (loc, "fixed-point types not supported for this target");
5395 expr.value = error_mark_node;
5402 expr.value = c_parser_peek_token (parser)->value;
5403 c_parser_consume_token (parser);
5409 case CPP_UTF8STRING:
5410 expr.value = c_parser_peek_token (parser)->value;
5411 expr.original_code = STRING_CST;
5412 c_parser_consume_token (parser);
5414 case CPP_OBJC_STRING:
5415 gcc_assert (c_dialect_objc ());
5417 = objc_build_string_object (c_parser_peek_token (parser)->value);
5418 c_parser_consume_token (parser);
5421 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5423 c_parser_error (parser, "expected expression");
5424 expr.value = error_mark_node;
5428 tree id = c_parser_peek_token (parser)->value;
5429 c_parser_consume_token (parser);
5430 expr.value = build_external_ref (loc, id,
5431 (c_parser_peek_token (parser)->type
5433 &expr.original_type);
5436 case CPP_OPEN_PAREN:
5437 /* A parenthesized expression, statement expression or compound
5439 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5441 /* A statement expression. */
5443 location_t brace_loc;
5444 c_parser_consume_token (parser);
5445 brace_loc = c_parser_peek_token (parser)->location;
5446 c_parser_consume_token (parser);
5447 if (cur_stmt_list == NULL)
5449 error_at (loc, "braced-group within expression allowed "
5450 "only inside a function");
5451 parser->error = true;
5452 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5453 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5454 expr.value = error_mark_node;
5457 stmt = c_begin_stmt_expr ();
5458 c_parser_compound_statement_nostart (parser);
5459 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5461 pedwarn (loc, OPT_pedantic,
5462 "ISO C forbids braced-groups within expressions");
5463 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5465 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5467 /* A compound literal. ??? Can we actually get here rather
5468 than going directly to
5469 c_parser_postfix_expression_after_paren_type from
5472 struct c_type_name *type_name;
5473 c_parser_consume_token (parser);
5474 loc = c_parser_peek_token (parser)->location;
5475 type_name = c_parser_type_name (parser);
5476 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5478 if (type_name == NULL)
5480 expr.value = error_mark_node;
5483 expr = c_parser_postfix_expression_after_paren_type (parser,
5489 /* A parenthesized expression. */
5490 c_parser_consume_token (parser);
5491 expr = c_parser_expression (parser);
5492 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5493 TREE_NO_WARNING (expr.value) = 1;
5494 if (expr.original_code != C_MAYBE_CONST_EXPR)
5495 expr.original_code = ERROR_MARK;
5496 /* Don't change EXPR.ORIGINAL_TYPE. */
5497 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5502 switch (c_parser_peek_token (parser)->keyword)
5504 case RID_FUNCTION_NAME:
5505 case RID_PRETTY_FUNCTION_NAME:
5506 case RID_C99_FUNCTION_NAME:
5507 expr.value = fname_decl (loc,
5508 c_parser_peek_token (parser)->keyword,
5509 c_parser_peek_token (parser)->value);
5510 c_parser_consume_token (parser);
5513 c_parser_consume_token (parser);
5514 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5516 expr.value = error_mark_node;
5519 e1 = c_parser_expr_no_commas (parser, NULL);
5520 mark_exp_read (e1.value);
5521 e1.value = c_fully_fold (e1.value, false, NULL);
5522 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5524 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5525 expr.value = error_mark_node;
5528 loc = c_parser_peek_token (parser)->location;
5529 t1 = c_parser_type_name (parser);
5530 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5534 expr.value = error_mark_node;
5538 tree type_expr = NULL_TREE;
5539 expr.value = c_build_va_arg (loc, e1.value,
5540 groktypename (t1, &type_expr, NULL));
5543 expr.value = build2 (C_MAYBE_CONST_EXPR,
5544 TREE_TYPE (expr.value), type_expr,
5546 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5551 c_parser_consume_token (parser);
5552 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5554 expr.value = error_mark_node;
5557 t1 = c_parser_type_name (parser);
5560 expr.value = error_mark_node;
5563 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5565 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5566 expr.value = error_mark_node;
5570 tree type = groktypename (t1, NULL, NULL);
5572 if (type == error_mark_node)
5573 offsetof_ref = error_mark_node;
5576 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5577 SET_EXPR_LOCATION (offsetof_ref, loc);
5579 /* Parse the second argument to __builtin_offsetof. We
5580 must have one identifier, and beyond that we want to
5581 accept sub structure and sub array references. */
5582 if (c_parser_next_token_is (parser, CPP_NAME))
5584 offsetof_ref = build_component_ref
5585 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5586 c_parser_consume_token (parser);
5587 while (c_parser_next_token_is (parser, CPP_DOT)
5588 || c_parser_next_token_is (parser,
5590 || c_parser_next_token_is (parser,
5593 if (c_parser_next_token_is (parser, CPP_DEREF))
5595 loc = c_parser_peek_token (parser)->location;
5596 offsetof_ref = build_array_ref (loc,
5601 else if (c_parser_next_token_is (parser, CPP_DOT))
5604 c_parser_consume_token (parser);
5605 if (c_parser_next_token_is_not (parser,
5608 c_parser_error (parser, "expected identifier");
5611 offsetof_ref = build_component_ref
5613 c_parser_peek_token (parser)->value);
5614 c_parser_consume_token (parser);
5619 loc = c_parser_peek_token (parser)->location;
5620 c_parser_consume_token (parser);
5621 idx = c_parser_expression (parser).value;
5622 idx = c_fully_fold (idx, false, NULL);
5623 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5625 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5630 c_parser_error (parser, "expected identifier");
5631 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5633 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5636 case RID_CHOOSE_EXPR:
5637 c_parser_consume_token (parser);
5638 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5640 expr.value = error_mark_node;
5643 loc = c_parser_peek_token (parser)->location;
5644 e1 = c_parser_expr_no_commas (parser, NULL);
5645 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5647 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5648 expr.value = error_mark_node;
5651 e2 = c_parser_expr_no_commas (parser, NULL);
5652 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5654 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5655 expr.value = error_mark_node;
5658 e3 = c_parser_expr_no_commas (parser, NULL);
5659 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5665 mark_exp_read (e2.value);
5666 mark_exp_read (e3.value);
5667 if (TREE_CODE (c) != INTEGER_CST
5668 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5670 "first argument to %<__builtin_choose_expr%> not"
5672 constant_expression_warning (c);
5673 expr = integer_zerop (c) ? e3 : e2;
5676 case RID_TYPES_COMPATIBLE_P:
5677 c_parser_consume_token (parser);
5678 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5680 expr.value = error_mark_node;
5683 t1 = c_parser_type_name (parser);
5686 expr.value = error_mark_node;
5689 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5691 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5692 expr.value = error_mark_node;
5695 t2 = c_parser_type_name (parser);
5698 expr.value = error_mark_node;
5701 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5706 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5707 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5709 expr.value = comptypes (e1, e2)
5710 ? build_int_cst (NULL_TREE, 1)
5711 : build_int_cst (NULL_TREE, 0);
5714 case RID_AT_SELECTOR:
5715 gcc_assert (c_dialect_objc ());
5716 c_parser_consume_token (parser);
5717 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5719 expr.value = error_mark_node;
5723 tree sel = c_parser_objc_selector_arg (parser);
5724 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5726 expr.value = objc_build_selector_expr (loc, sel);
5729 case RID_AT_PROTOCOL:
5730 gcc_assert (c_dialect_objc ());
5731 c_parser_consume_token (parser);
5732 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5734 expr.value = error_mark_node;
5737 if (c_parser_next_token_is_not (parser, CPP_NAME))
5739 c_parser_error (parser, "expected identifier");
5740 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5741 expr.value = error_mark_node;
5745 tree id = c_parser_peek_token (parser)->value;
5746 c_parser_consume_token (parser);
5747 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5749 expr.value = objc_build_protocol_expr (id);
5753 /* Extension to support C-structures in the archiver. */
5754 gcc_assert (c_dialect_objc ());
5755 c_parser_consume_token (parser);
5756 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5758 expr.value = error_mark_node;
5761 t1 = c_parser_type_name (parser);
5764 expr.value = error_mark_node;
5765 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5768 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5771 tree type = groktypename (t1, NULL, NULL);
5772 expr.value = objc_build_encode_expr (type);
5776 c_parser_error (parser, "expected expression");
5777 expr.value = error_mark_node;
5781 case CPP_OPEN_SQUARE:
5782 if (c_dialect_objc ())
5784 tree receiver, args;
5785 c_parser_consume_token (parser);
5786 receiver = c_parser_objc_receiver (parser);
5787 args = c_parser_objc_message_args (parser);
5788 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5790 expr.value = objc_build_message_expr (build_tree_list (receiver,
5794 /* Else fall through to report error. */
5796 c_parser_error (parser, "expected expression");
5797 expr.value = error_mark_node;
5800 return c_parser_postfix_expression_after_primary (parser, loc, expr);
5803 /* Parse a postfix expression after a parenthesized type name: the
5804 brace-enclosed initializer of a compound literal, possibly followed
5805 by some postfix operators. This is separate because it is not
5806 possible to tell until after the type name whether a cast
5807 expression has a cast or a compound literal, or whether the operand
5808 of sizeof is a parenthesized type name or starts with a compound
5809 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5810 location of the first token after the parentheses around the type
5813 static struct c_expr
5814 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5815 struct c_type_name *type_name,
5816 location_t type_loc)
5822 location_t start_loc;
5823 tree type_expr = NULL_TREE;
5824 bool type_expr_const = true;
5825 check_compound_literal_type (type_loc, type_name);
5826 start_init (NULL_TREE, NULL, 0);
5827 type = groktypename (type_name, &type_expr, &type_expr_const);
5828 start_loc = c_parser_peek_token (parser)->location;
5829 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5831 error_at (type_loc, "compound literal has variable size");
5832 type = error_mark_node;
5834 init = c_parser_braced_init (parser, type, false);
5836 maybe_warn_string_init (type, init);
5838 if (type != error_mark_node
5839 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
5840 && current_function_decl)
5842 error ("compound literal qualified by address-space qualifier");
5843 type = error_mark_node;
5847 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5848 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5849 ? CONSTRUCTOR_NON_CONST (init.value)
5850 : init.original_code == C_MAYBE_CONST_EXPR);
5851 non_const |= !type_expr_const;
5852 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
5853 expr.original_code = ERROR_MARK;
5854 expr.original_type = NULL;
5857 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5859 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5860 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5864 gcc_assert (!non_const);
5865 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5866 type_expr, expr.value);
5869 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
5872 /* Parse a postfix expression after the initial primary or compound
5873 literal; that is, parse a series of postfix operators.
5875 EXPR_LOC is the location of the primary expression. */
5877 static struct c_expr
5878 c_parser_postfix_expression_after_primary (c_parser *parser,
5879 location_t expr_loc,
5882 struct c_expr orig_expr;
5884 VEC(tree,gc) *exprlist;
5885 VEC(tree,gc) *origtypes;
5888 location_t op_loc = c_parser_peek_token (parser)->location;
5889 switch (c_parser_peek_token (parser)->type)
5891 case CPP_OPEN_SQUARE:
5892 /* Array reference. */
5893 c_parser_consume_token (parser);
5894 idx = c_parser_expression (parser).value;
5895 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5897 expr.value = build_array_ref (op_loc, expr.value, idx);
5898 expr.original_code = ERROR_MARK;
5899 expr.original_type = NULL;
5901 case CPP_OPEN_PAREN:
5902 /* Function call. */
5903 c_parser_consume_token (parser);
5904 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5907 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
5908 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5911 mark_exp_read (expr.value);
5912 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5913 "(" after the FUNCNAME, which is what we have now. */
5914 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
5916 expr.original_code = ERROR_MARK;
5917 if (TREE_CODE (expr.value) == INTEGER_CST
5918 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5919 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5920 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5921 expr.original_code = C_MAYBE_CONST_EXPR;
5922 expr.original_type = NULL;
5923 if (exprlist != NULL)
5925 release_tree_vector (exprlist);
5926 release_tree_vector (origtypes);
5930 /* Structure element reference. */
5931 c_parser_consume_token (parser);
5932 expr = default_function_array_conversion (expr_loc, expr);
5933 if (c_parser_next_token_is (parser, CPP_NAME))
5934 ident = c_parser_peek_token (parser)->value;
5937 c_parser_error (parser, "expected identifier");
5938 expr.value = error_mark_node;
5939 expr.original_code = ERROR_MARK;
5940 expr.original_type = NULL;
5943 c_parser_consume_token (parser);
5944 expr.value = build_component_ref (op_loc, expr.value, ident);
5945 expr.original_code = ERROR_MARK;
5946 if (TREE_CODE (expr.value) != COMPONENT_REF)
5947 expr.original_type = NULL;
5950 /* Remember the original type of a bitfield. */
5951 tree field = TREE_OPERAND (expr.value, 1);
5952 if (TREE_CODE (field) != FIELD_DECL)
5953 expr.original_type = NULL;
5955 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5959 /* Structure element reference. */
5960 c_parser_consume_token (parser);
5961 expr = default_function_array_conversion (expr_loc, expr);
5962 if (c_parser_next_token_is (parser, CPP_NAME))
5963 ident = c_parser_peek_token (parser)->value;
5966 c_parser_error (parser, "expected identifier");
5967 expr.value = error_mark_node;
5968 expr.original_code = ERROR_MARK;
5969 expr.original_type = NULL;
5972 c_parser_consume_token (parser);
5973 expr.value = build_component_ref (op_loc,
5974 build_indirect_ref (op_loc,
5978 expr.original_code = ERROR_MARK;
5979 if (TREE_CODE (expr.value) != COMPONENT_REF)
5980 expr.original_type = NULL;
5983 /* Remember the original type of a bitfield. */
5984 tree field = TREE_OPERAND (expr.value, 1);
5985 if (TREE_CODE (field) != FIELD_DECL)
5986 expr.original_type = NULL;
5988 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5992 /* Postincrement. */
5993 c_parser_consume_token (parser);
5994 expr = default_function_array_read_conversion (expr_loc, expr);
5995 expr.value = build_unary_op (op_loc,
5996 POSTINCREMENT_EXPR, expr.value, 0);
5997 expr.original_code = ERROR_MARK;
5998 expr.original_type = NULL;
6000 case CPP_MINUS_MINUS:
6001 /* Postdecrement. */
6002 c_parser_consume_token (parser);
6003 expr = default_function_array_read_conversion (expr_loc, expr);
6004 expr.value = build_unary_op (op_loc,
6005 POSTDECREMENT_EXPR, expr.value, 0);
6006 expr.original_code = ERROR_MARK;
6007 expr.original_type = NULL;
6015 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6018 assignment-expression
6019 expression , assignment-expression
6022 static struct c_expr
6023 c_parser_expression (c_parser *parser)
6026 expr = c_parser_expr_no_commas (parser, NULL);
6027 while (c_parser_next_token_is (parser, CPP_COMMA))
6031 location_t loc = c_parser_peek_token (parser)->location;
6032 location_t expr_loc;
6033 c_parser_consume_token (parser);
6034 expr_loc = c_parser_peek_token (parser)->location;
6035 lhsval = expr.value;
6036 while (TREE_CODE (lhsval) == COMPOUND_EXPR)
6037 lhsval = TREE_OPERAND (lhsval, 1);
6038 if (DECL_P (lhsval) || handled_component_p (lhsval))
6039 mark_exp_read (lhsval);
6040 next = c_parser_expr_no_commas (parser, NULL);
6041 next = default_function_array_conversion (expr_loc, next);
6042 expr.value = build_compound_expr (loc, expr.value, next.value);
6043 expr.original_code = COMPOUND_EXPR;
6044 expr.original_type = next.original_type;
6049 /* Parse an expression and convert functions or arrays to
6052 static struct c_expr
6053 c_parser_expression_conv (c_parser *parser)
6056 location_t loc = c_parser_peek_token (parser)->location;
6057 expr = c_parser_expression (parser);
6058 expr = default_function_array_conversion (loc, expr);
6062 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6063 functions and arrays to pointers. If FOLD_P, fold the expressions.
6066 assignment-expression
6067 nonempty-expr-list , assignment-expression
6070 static VEC(tree,gc) *
6071 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6072 VEC(tree,gc) **p_orig_types)
6075 VEC(tree,gc) *orig_types;
6077 location_t loc = c_parser_peek_token (parser)->location;
6079 ret = make_tree_vector ();
6080 if (p_orig_types == NULL)
6083 orig_types = make_tree_vector ();
6085 expr = c_parser_expr_no_commas (parser, NULL);
6087 expr = default_function_array_read_conversion (loc, expr);
6089 expr.value = c_fully_fold (expr.value, false, NULL);
6090 VEC_quick_push (tree, ret, expr.value);
6091 if (orig_types != NULL)
6092 VEC_quick_push (tree, orig_types, expr.original_type);
6093 while (c_parser_next_token_is (parser, CPP_COMMA))
6095 c_parser_consume_token (parser);
6096 loc = c_parser_peek_token (parser)->location;
6097 expr = c_parser_expr_no_commas (parser, NULL);
6099 expr = default_function_array_read_conversion (loc, expr);
6101 expr.value = c_fully_fold (expr.value, false, NULL);
6102 VEC_safe_push (tree, gc, ret, expr.value);
6103 if (orig_types != NULL)
6104 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6106 if (orig_types != NULL)
6107 *p_orig_types = orig_types;
6111 /* Parse Objective-C-specific constructs. */
6113 /* Parse an objc-class-definition.
6115 objc-class-definition:
6116 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6117 objc-class-instance-variables[opt] objc-methodprotolist @end
6118 @implementation identifier objc-superclass[opt]
6119 objc-class-instance-variables[opt]
6120 @interface identifier ( identifier ) objc-protocol-refs[opt]
6121 objc-methodprotolist @end
6122 @implementation identifier ( identifier )
6127 "@interface identifier (" must start "@interface identifier (
6128 identifier ) ...": objc-methodprotolist in the first production may
6129 not start with a parenthesized identifier as a declarator of a data
6130 definition with no declaration specifiers if the objc-superclass,
6131 objc-protocol-refs and objc-class-instance-variables are omitted. */
6134 c_parser_objc_class_definition (c_parser *parser)
6139 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6141 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6145 c_parser_consume_token (parser);
6146 if (c_parser_next_token_is_not (parser, CPP_NAME))
6148 c_parser_error (parser, "expected identifier");
6151 id1 = c_parser_peek_token (parser)->value;
6152 c_parser_consume_token (parser);
6153 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6156 tree proto = NULL_TREE;
6157 c_parser_consume_token (parser);
6158 if (c_parser_next_token_is_not (parser, CPP_NAME))
6160 c_parser_error (parser, "expected identifier");
6161 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6164 id2 = c_parser_peek_token (parser)->value;
6165 c_parser_consume_token (parser);
6166 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6169 objc_start_category_implementation (id1, id2);
6172 if (c_parser_next_token_is (parser, CPP_LESS))
6173 proto = c_parser_objc_protocol_refs (parser);
6174 objc_start_category_interface (id1, id2, proto);
6175 c_parser_objc_methodprotolist (parser);
6176 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6177 objc_finish_interface ();
6180 if (c_parser_next_token_is (parser, CPP_COLON))
6182 c_parser_consume_token (parser);
6183 if (c_parser_next_token_is_not (parser, CPP_NAME))
6185 c_parser_error (parser, "expected identifier");
6188 superclass = c_parser_peek_token (parser)->value;
6189 c_parser_consume_token (parser);
6192 superclass = NULL_TREE;
6195 tree proto = NULL_TREE;
6196 if (c_parser_next_token_is (parser, CPP_LESS))
6197 proto = c_parser_objc_protocol_refs (parser);
6198 objc_start_class_interface (id1, superclass, proto);
6201 objc_start_class_implementation (id1, superclass);
6202 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6203 c_parser_objc_class_instance_variables (parser);
6206 objc_continue_interface ();
6207 c_parser_objc_methodprotolist (parser);
6208 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6209 objc_finish_interface ();
6213 objc_continue_implementation ();
6218 /* Parse objc-class-instance-variables.
6220 objc-class-instance-variables:
6221 { objc-instance-variable-decl-list[opt] }
6223 objc-instance-variable-decl-list:
6224 objc-visibility-spec
6225 objc-instance-variable-decl ;
6227 objc-instance-variable-decl-list objc-visibility-spec
6228 objc-instance-variable-decl-list objc-instance-variable-decl ;
6229 objc-instance-variable-decl-list ;
6231 objc-visibility-spec:
6236 objc-instance-variable-decl:
6241 c_parser_objc_class_instance_variables (c_parser *parser)
6243 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6244 c_parser_consume_token (parser);
6245 while (c_parser_next_token_is_not (parser, CPP_EOF))
6248 /* Parse any stray semicolon. */
6249 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6251 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6252 "extra semicolon in struct or union specified");
6253 c_parser_consume_token (parser);
6256 /* Stop if at the end of the instance variables. */
6257 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6259 c_parser_consume_token (parser);
6262 /* Parse any objc-visibility-spec. */
6263 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6265 c_parser_consume_token (parser);
6266 objc_set_visibility (2);
6269 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6271 c_parser_consume_token (parser);
6272 objc_set_visibility (0);
6275 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6277 c_parser_consume_token (parser);
6278 objc_set_visibility (1);
6281 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6283 c_parser_pragma (parser, pragma_external);
6287 /* Parse some comma-separated declarations. */
6288 decls = c_parser_struct_declaration (parser);
6290 /* Comma-separated instance variables are chained together in
6291 reverse order; add them one by one. */
6292 tree ivar = nreverse (decls);
6293 for (; ivar; ivar = TREE_CHAIN (ivar))
6294 objc_add_instance_variable (copy_node (ivar));
6296 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6300 /* Parse an objc-class-declaration.
6302 objc-class-declaration:
6303 @class identifier-list ;
6307 c_parser_objc_class_declaration (c_parser *parser)
6309 tree list = NULL_TREE;
6310 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6311 c_parser_consume_token (parser);
6312 /* Any identifiers, including those declared as type names, are OK
6317 if (c_parser_next_token_is_not (parser, CPP_NAME))
6319 c_parser_error (parser, "expected identifier");
6322 id = c_parser_peek_token (parser)->value;
6323 list = chainon (list, build_tree_list (NULL_TREE, id));
6324 c_parser_consume_token (parser);
6325 if (c_parser_next_token_is (parser, CPP_COMMA))
6326 c_parser_consume_token (parser);
6330 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6331 objc_declare_class (list);
6334 /* Parse an objc-alias-declaration.
6336 objc-alias-declaration:
6337 @compatibility_alias identifier identifier ;
6341 c_parser_objc_alias_declaration (c_parser *parser)
6344 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6345 c_parser_consume_token (parser);
6346 if (c_parser_next_token_is_not (parser, CPP_NAME))
6348 c_parser_error (parser, "expected identifier");
6349 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6352 id1 = c_parser_peek_token (parser)->value;
6353 c_parser_consume_token (parser);
6354 if (c_parser_next_token_is_not (parser, CPP_NAME))
6356 c_parser_error (parser, "expected identifier");
6357 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6360 id2 = c_parser_peek_token (parser)->value;
6361 c_parser_consume_token (parser);
6362 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6363 objc_declare_alias (id1, id2);
6366 /* Parse an objc-protocol-definition.
6368 objc-protocol-definition:
6369 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6370 @protocol identifier-list ;
6372 "@protocol identifier ;" should be resolved as "@protocol
6373 identifier-list ;": objc-methodprotolist may not start with a
6374 semicolon in the first alternative if objc-protocol-refs are
6378 c_parser_objc_protocol_definition (c_parser *parser)
6380 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6381 c_parser_consume_token (parser);
6382 if (c_parser_next_token_is_not (parser, CPP_NAME))
6384 c_parser_error (parser, "expected identifier");
6387 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6388 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6390 tree list = NULL_TREE;
6391 /* Any identifiers, including those declared as type names, are
6396 if (c_parser_next_token_is_not (parser, CPP_NAME))
6398 c_parser_error (parser, "expected identifier");
6401 id = c_parser_peek_token (parser)->value;
6402 list = chainon (list, build_tree_list (NULL_TREE, id));
6403 c_parser_consume_token (parser);
6404 if (c_parser_next_token_is (parser, CPP_COMMA))
6405 c_parser_consume_token (parser);
6409 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6410 objc_declare_protocols (list);
6414 tree id = c_parser_peek_token (parser)->value;
6415 tree proto = NULL_TREE;
6416 c_parser_consume_token (parser);
6417 if (c_parser_next_token_is (parser, CPP_LESS))
6418 proto = c_parser_objc_protocol_refs (parser);
6419 parser->objc_pq_context = true;
6420 objc_start_protocol (id, proto);
6421 c_parser_objc_methodprotolist (parser);
6422 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6423 parser->objc_pq_context = false;
6424 objc_finish_interface ();
6428 /* Parse an objc-method-type.
6435 static enum tree_code
6436 c_parser_objc_method_type (c_parser *parser)
6438 switch (c_parser_peek_token (parser)->type)
6441 c_parser_consume_token (parser);
6444 c_parser_consume_token (parser);
6451 /* Parse an objc-method-definition.
6453 objc-method-definition:
6454 objc-method-type objc-method-decl ;[opt] compound-statement
6458 c_parser_objc_method_definition (c_parser *parser)
6460 enum tree_code type = c_parser_objc_method_type (parser);
6462 objc_set_method_type (type);
6463 parser->objc_pq_context = true;
6464 decl = c_parser_objc_method_decl (parser);
6465 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6467 c_parser_consume_token (parser);
6468 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6469 "extra semicolon in method definition specified");
6471 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6473 c_parser_error (parser, "expected %<{%>");
6476 parser->objc_pq_context = false;
6477 objc_start_method_definition (decl);
6478 add_stmt (c_parser_compound_statement (parser));
6479 objc_finish_method_definition (current_function_decl);
6482 /* Parse an objc-methodprotolist.
6484 objc-methodprotolist:
6486 objc-methodprotolist objc-methodproto
6487 objc-methodprotolist declaration
6488 objc-methodprotolist ;
6490 The declaration is a data definition, which may be missing
6491 declaration specifiers under the same rules and diagnostics as
6492 other data definitions outside functions, and the stray semicolon
6493 is diagnosed the same way as a stray semicolon outside a
6497 c_parser_objc_methodprotolist (c_parser *parser)
6501 /* The list is terminated by @end. */
6502 switch (c_parser_peek_token (parser)->type)
6505 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6506 "ISO C does not allow extra %<;%> outside of a function");
6507 c_parser_consume_token (parser);
6511 c_parser_objc_methodproto (parser);
6514 c_parser_pragma (parser, pragma_external);
6519 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6521 c_parser_declaration_or_fndef (parser, false, true, false, true);
6527 /* Parse an objc-methodproto.
6530 objc-method-type objc-method-decl ;
6534 c_parser_objc_methodproto (c_parser *parser)
6536 enum tree_code type = c_parser_objc_method_type (parser);
6538 objc_set_method_type (type);
6539 /* Remember protocol qualifiers in prototypes. */
6540 parser->objc_pq_context = true;
6541 decl = c_parser_objc_method_decl (parser);
6542 /* Forget protocol qualifiers here. */
6543 parser->objc_pq_context = false;
6544 objc_add_method_declaration (decl);
6545 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6548 /* Parse an objc-method-decl.
6551 ( objc-type-name ) objc-selector
6553 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6554 objc-keyword-selector objc-optparmlist
6556 objc-keyword-selector:
6558 objc-keyword-selector objc-keyword-decl
6561 objc-selector : ( objc-type-name ) identifier
6562 objc-selector : identifier
6563 : ( objc-type-name ) identifier
6567 objc-optparms objc-optellipsis
6571 objc-opt-parms , parameter-declaration
6579 c_parser_objc_method_decl (c_parser *parser)
6581 tree type = NULL_TREE;
6583 tree parms = NULL_TREE;
6584 bool ellipsis = false;
6586 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6588 c_parser_consume_token (parser);
6589 type = c_parser_objc_type_name (parser);
6590 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6592 sel = c_parser_objc_selector (parser);
6593 /* If there is no selector, or a colon follows, we have an
6594 objc-keyword-selector. If there is a selector, and a colon does
6595 not follow, that selector ends the objc-method-decl. */
6596 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6599 tree list = NULL_TREE;
6602 tree atype = NULL_TREE, id, keyworddecl;
6603 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6605 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6607 c_parser_consume_token (parser);
6608 atype = c_parser_objc_type_name (parser);
6609 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6612 if (c_parser_next_token_is_not (parser, CPP_NAME))
6614 c_parser_error (parser, "expected identifier");
6615 return error_mark_node;
6617 id = c_parser_peek_token (parser)->value;
6618 c_parser_consume_token (parser);
6619 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6620 list = chainon (list, keyworddecl);
6621 tsel = c_parser_objc_selector (parser);
6622 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6625 /* Parse the optional parameter list. Optional Objective-C
6626 method parameters follow the C syntax, and may include '...'
6627 to denote a variable number of arguments. */
6628 parms = make_node (TREE_LIST);
6629 while (c_parser_next_token_is (parser, CPP_COMMA))
6631 struct c_parm *parm;
6632 c_parser_consume_token (parser);
6633 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6636 c_parser_consume_token (parser);
6639 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6642 parms = chainon (parms,
6643 build_tree_list (NULL_TREE, grokparm (parm)));
6647 return objc_build_method_signature (type, sel, parms, ellipsis);
6650 /* Parse an objc-type-name.
6653 objc-type-qualifiers[opt] type-name
6654 objc-type-qualifiers[opt]
6656 objc-type-qualifiers:
6658 objc-type-qualifiers objc-type-qualifier
6660 objc-type-qualifier: one of
6661 in out inout bycopy byref oneway
6665 c_parser_objc_type_name (c_parser *parser)
6667 tree quals = NULL_TREE;
6668 struct c_type_name *type_name = NULL;
6669 tree type = NULL_TREE;
6672 c_token *token = c_parser_peek_token (parser);
6673 if (token->type == CPP_KEYWORD
6674 && (token->keyword == RID_IN
6675 || token->keyword == RID_OUT
6676 || token->keyword == RID_INOUT
6677 || token->keyword == RID_BYCOPY
6678 || token->keyword == RID_BYREF
6679 || token->keyword == RID_ONEWAY))
6681 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6682 c_parser_consume_token (parser);
6687 if (c_parser_next_token_starts_typename (parser))
6688 type_name = c_parser_type_name (parser);
6690 type = groktypename (type_name, NULL, NULL);
6691 return build_tree_list (quals, type);
6694 /* Parse objc-protocol-refs.
6701 c_parser_objc_protocol_refs (c_parser *parser)
6703 tree list = NULL_TREE;
6704 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6705 c_parser_consume_token (parser);
6706 /* Any identifiers, including those declared as type names, are OK
6711 if (c_parser_next_token_is_not (parser, CPP_NAME))
6713 c_parser_error (parser, "expected identifier");
6716 id = c_parser_peek_token (parser)->value;
6717 list = chainon (list, build_tree_list (NULL_TREE, id));
6718 c_parser_consume_token (parser);
6719 if (c_parser_next_token_is (parser, CPP_COMMA))
6720 c_parser_consume_token (parser);
6724 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6728 /* Parse an objc-try-catch-statement.
6730 objc-try-catch-statement:
6731 @try compound-statement objc-catch-list[opt]
6732 @try compound-statement objc-catch-list[opt] @finally compound-statement
6735 @catch ( parameter-declaration ) compound-statement
6736 objc-catch-list @catch ( parameter-declaration ) compound-statement
6740 c_parser_objc_try_catch_statement (c_parser *parser)
6744 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6745 c_parser_consume_token (parser);
6746 loc = c_parser_peek_token (parser)->location;
6747 stmt = c_parser_compound_statement (parser);
6748 objc_begin_try_stmt (loc, stmt);
6749 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6751 struct c_parm *parm;
6752 c_parser_consume_token (parser);
6753 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6755 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6758 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6761 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6762 objc_begin_catch_clause (grokparm (parm));
6763 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6764 c_parser_compound_statement_nostart (parser);
6765 objc_finish_catch_clause ();
6767 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6771 c_parser_consume_token (parser);
6772 finloc = c_parser_peek_token (parser)->location;
6773 finstmt = c_parser_compound_statement (parser);
6774 objc_build_finally_clause (finloc, finstmt);
6776 objc_finish_try_stmt ();
6779 /* Parse an objc-synchronized-statement.
6781 objc-synchronized-statement:
6782 @synchronized ( expression ) compound-statement
6786 c_parser_objc_synchronized_statement (c_parser *parser)
6790 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6791 c_parser_consume_token (parser);
6792 loc = c_parser_peek_token (parser)->location;
6793 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6795 expr = c_parser_expression (parser).value;
6796 expr = c_fully_fold (expr, false, NULL);
6797 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6800 expr = error_mark_node;
6801 stmt = c_parser_compound_statement (parser);
6802 objc_build_synchronized (loc, expr, stmt);
6805 /* Parse an objc-selector; return NULL_TREE without an error if the
6806 next token is not an objc-selector.
6811 enum struct union if else while do for switch case default
6812 break continue return goto asm sizeof typeof __alignof
6813 unsigned long const short volatile signed restrict _Complex
6814 in out inout bycopy byref oneway int char float double void _Bool
6816 ??? Why this selection of keywords but not, for example, storage
6817 class specifiers? */
6820 c_parser_objc_selector (c_parser *parser)
6822 c_token *token = c_parser_peek_token (parser);
6823 tree value = token->value;
6824 if (token->type == CPP_NAME)
6826 c_parser_consume_token (parser);
6829 if (token->type != CPP_KEYWORD)
6831 switch (token->keyword)
6872 c_parser_consume_token (parser);
6879 /* Parse an objc-selector-arg.
6883 objc-keywordname-list
6885 objc-keywordname-list:
6887 objc-keywordname-list objc-keywordname
6895 c_parser_objc_selector_arg (c_parser *parser)
6897 tree sel = c_parser_objc_selector (parser);
6898 tree list = NULL_TREE;
6899 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6903 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6905 list = chainon (list, build_tree_list (sel, NULL_TREE));
6906 sel = c_parser_objc_selector (parser);
6907 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6913 /* Parse an objc-receiver.
6922 c_parser_objc_receiver (c_parser *parser)
6924 if (c_parser_peek_token (parser)->type == CPP_NAME
6925 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6926 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6928 tree id = c_parser_peek_token (parser)->value;
6929 c_parser_consume_token (parser);
6930 return objc_get_class_reference (id);
6932 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6935 /* Parse objc-message-args.
6939 objc-keywordarg-list
6941 objc-keywordarg-list:
6943 objc-keywordarg-list objc-keywordarg
6946 objc-selector : objc-keywordexpr
6951 c_parser_objc_message_args (c_parser *parser)
6953 tree sel = c_parser_objc_selector (parser);
6954 tree list = NULL_TREE;
6955 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6960 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6961 return error_mark_node;
6962 keywordexpr = c_parser_objc_keywordexpr (parser);
6963 list = chainon (list, build_tree_list (sel, keywordexpr));
6964 sel = c_parser_objc_selector (parser);
6965 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6971 /* Parse an objc-keywordexpr.
6978 c_parser_objc_keywordexpr (c_parser *parser)
6981 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
6982 if (VEC_length (tree, expr_list) == 1)
6984 /* Just return the expression, remove a level of
6986 ret = VEC_index (tree, expr_list, 0);
6990 /* We have a comma expression, we will collapse later. */
6991 ret = build_tree_list_vec (expr_list);
6993 release_tree_vector (expr_list);
6998 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6999 should be considered, statements. ALLOW_STMT is true if we're within
7000 the context of a function and such pragmas are to be allowed. Returns
7001 true if we actually parsed such a pragma. */
7004 c_parser_pragma (c_parser *parser, enum pragma_context context)
7008 id = c_parser_peek_token (parser)->pragma_kind;
7009 gcc_assert (id != PRAGMA_NONE);
7013 case PRAGMA_OMP_BARRIER:
7014 if (context != pragma_compound)
7016 if (context == pragma_stmt)
7017 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7018 "used in compound statements");
7021 c_parser_omp_barrier (parser);
7024 case PRAGMA_OMP_FLUSH:
7025 if (context != pragma_compound)
7027 if (context == pragma_stmt)
7028 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7029 "used in compound statements");
7032 c_parser_omp_flush (parser);
7035 case PRAGMA_OMP_TASKWAIT:
7036 if (context != pragma_compound)
7038 if (context == pragma_stmt)
7039 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7040 "used in compound statements");
7043 c_parser_omp_taskwait (parser);
7046 case PRAGMA_OMP_THREADPRIVATE:
7047 c_parser_omp_threadprivate (parser);
7050 case PRAGMA_OMP_SECTION:
7051 error_at (c_parser_peek_token (parser)->location,
7052 "%<#pragma omp section%> may only be used in "
7053 "%<#pragma omp sections%> construct");
7054 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7057 case PRAGMA_GCC_PCH_PREPROCESS:
7058 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7059 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7063 if (id < PRAGMA_FIRST_EXTERNAL)
7065 if (context == pragma_external)
7068 c_parser_error (parser, "expected declaration specifiers");
7069 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7072 c_parser_omp_construct (parser);
7078 c_parser_consume_pragma (parser);
7079 c_invoke_pragma_handler (id);
7081 /* Skip to EOL, but suppress any error message. Those will have been
7082 generated by the handler routine through calling error, as opposed
7083 to calling c_parser_error. */
7084 parser->error = true;
7085 c_parser_skip_to_pragma_eol (parser);
7090 /* The interface the pragma parsers have to the lexer. */
7093 pragma_lex (tree *value)
7095 c_token *tok = c_parser_peek_token (the_parser);
7096 enum cpp_ttype ret = tok->type;
7098 *value = tok->value;
7099 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7103 if (ret == CPP_KEYWORD)
7105 c_parser_consume_token (the_parser);
7112 c_parser_pragma_pch_preprocess (c_parser *parser)
7116 c_parser_consume_pragma (parser);
7117 if (c_parser_next_token_is (parser, CPP_STRING))
7119 name = c_parser_peek_token (parser)->value;
7120 c_parser_consume_token (parser);
7123 c_parser_error (parser, "expected string literal");
7124 c_parser_skip_to_pragma_eol (parser);
7127 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7130 /* OpenMP 2.5 parsing routines. */
7132 /* Returns name of the next clause.
7133 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7134 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7135 returned and the token is consumed. */
7137 static pragma_omp_clause
7138 c_parser_omp_clause_name (c_parser *parser)
7140 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7142 if (c_parser_next_token_is_keyword (parser, RID_IF))
7143 result = PRAGMA_OMP_CLAUSE_IF;
7144 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7145 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7146 else if (c_parser_next_token_is (parser, CPP_NAME))
7148 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7153 if (!strcmp ("collapse", p))
7154 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7155 else if (!strcmp ("copyin", p))
7156 result = PRAGMA_OMP_CLAUSE_COPYIN;
7157 else if (!strcmp ("copyprivate", p))
7158 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7161 if (!strcmp ("firstprivate", p))
7162 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7165 if (!strcmp ("lastprivate", p))
7166 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7169 if (!strcmp ("nowait", p))
7170 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7171 else if (!strcmp ("num_threads", p))
7172 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7175 if (!strcmp ("ordered", p))
7176 result = PRAGMA_OMP_CLAUSE_ORDERED;
7179 if (!strcmp ("private", p))
7180 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7183 if (!strcmp ("reduction", p))
7184 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7187 if (!strcmp ("schedule", p))
7188 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7189 else if (!strcmp ("shared", p))
7190 result = PRAGMA_OMP_CLAUSE_SHARED;
7193 if (!strcmp ("untied", p))
7194 result = PRAGMA_OMP_CLAUSE_UNTIED;
7199 if (result != PRAGMA_OMP_CLAUSE_NONE)
7200 c_parser_consume_token (parser);
7205 /* Validate that a clause of the given type does not already exist. */
7208 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7213 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7214 if (OMP_CLAUSE_CODE (c) == code)
7216 location_t loc = OMP_CLAUSE_LOCATION (c);
7217 error_at (loc, "too many %qs clauses", name);
7225 variable-list , identifier
7227 If KIND is nonzero, create the appropriate node and install the
7228 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7229 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7231 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7232 return the list created. */
7235 c_parser_omp_variable_list (c_parser *parser,
7236 location_t clause_loc,
7237 enum omp_clause_code kind,
7240 if (c_parser_next_token_is_not (parser, CPP_NAME)
7241 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7242 c_parser_error (parser, "expected identifier");
7244 while (c_parser_next_token_is (parser, CPP_NAME)
7245 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7247 tree t = lookup_name (c_parser_peek_token (parser)->value);
7250 undeclared_variable (c_parser_peek_token (parser)->location,
7251 c_parser_peek_token (parser)->value);
7252 else if (t == error_mark_node)
7256 tree u = build_omp_clause (clause_loc, kind);
7257 OMP_CLAUSE_DECL (u) = t;
7258 OMP_CLAUSE_CHAIN (u) = list;
7262 list = tree_cons (t, NULL_TREE, list);
7264 c_parser_consume_token (parser);
7266 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7269 c_parser_consume_token (parser);
7275 /* Similarly, but expect leading and trailing parenthesis. This is a very
7276 common case for omp clauses. */
7279 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7282 /* The clauses location. */
7283 location_t loc = c_parser_peek_token (parser)->location;
7285 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7287 list = c_parser_omp_variable_list (parser, loc, kind, list);
7288 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7294 collapse ( constant-expression ) */
7297 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7299 tree c, num = error_mark_node;
7303 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7305 loc = c_parser_peek_token (parser)->location;
7306 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7308 num = c_parser_expr_no_commas (parser, NULL).value;
7309 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7311 if (num == error_mark_node)
7313 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7314 || !host_integerp (num, 0)
7315 || (n = tree_low_cst (num, 0)) <= 0
7319 "collapse argument needs positive constant integer expression");
7322 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7323 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7324 OMP_CLAUSE_CHAIN (c) = list;
7329 copyin ( variable-list ) */
7332 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7334 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7338 copyprivate ( variable-list ) */
7341 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7343 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7347 default ( shared | none ) */
7350 c_parser_omp_clause_default (c_parser *parser, tree list)
7352 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7353 location_t loc = c_parser_peek_token (parser)->location;
7356 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7358 if (c_parser_next_token_is (parser, CPP_NAME))
7360 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7365 if (strcmp ("none", p) != 0)
7367 kind = OMP_CLAUSE_DEFAULT_NONE;
7371 if (strcmp ("shared", p) != 0)
7373 kind = OMP_CLAUSE_DEFAULT_SHARED;
7380 c_parser_consume_token (parser);
7385 c_parser_error (parser, "expected %<none%> or %<shared%>");
7387 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7389 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7392 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7393 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7394 OMP_CLAUSE_CHAIN (c) = list;
7395 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7401 firstprivate ( variable-list ) */
7404 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7406 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7410 if ( expression ) */
7413 c_parser_omp_clause_if (c_parser *parser, tree list)
7415 location_t loc = c_parser_peek_token (parser)->location;
7416 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7418 tree t = c_parser_paren_condition (parser);
7421 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7423 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7424 OMP_CLAUSE_IF_EXPR (c) = t;
7425 OMP_CLAUSE_CHAIN (c) = list;
7429 c_parser_error (parser, "expected %<(%>");
7435 lastprivate ( variable-list ) */
7438 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7440 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7447 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7450 location_t loc = c_parser_peek_token (parser)->location;
7452 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7454 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7455 OMP_CLAUSE_CHAIN (c) = list;
7460 num_threads ( expression ) */
7463 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7465 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7466 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7468 location_t expr_loc = c_parser_peek_token (parser)->location;
7469 tree c, t = c_parser_expression (parser).value;
7470 t = c_fully_fold (t, false, NULL);
7472 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7474 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7476 c_parser_error (parser, "expected integer expression");
7480 /* Attempt to statically determine when the number isn't positive. */
7481 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7482 build_int_cst (TREE_TYPE (t), 0));
7483 if (CAN_HAVE_LOCATION_P (c))
7484 SET_EXPR_LOCATION (c, expr_loc);
7485 if (c == boolean_true_node)
7487 warning_at (expr_loc, 0,
7488 "%<num_threads%> value must be positive");
7489 t = integer_one_node;
7492 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7494 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7495 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7496 OMP_CLAUSE_CHAIN (c) = list;
7507 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7511 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7513 c = build_omp_clause (c_parser_peek_token (parser)->location,
7514 OMP_CLAUSE_ORDERED);
7515 OMP_CLAUSE_CHAIN (c) = list;
7521 private ( variable-list ) */
7524 c_parser_omp_clause_private (c_parser *parser, tree list)
7526 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7530 reduction ( reduction-operator : variable-list )
7533 One of: + * - & ^ | && || */
7536 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7538 location_t clause_loc = c_parser_peek_token (parser)->location;
7539 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7541 enum tree_code code;
7543 switch (c_parser_peek_token (parser)->type)
7555 code = BIT_AND_EXPR;
7558 code = BIT_XOR_EXPR;
7561 code = BIT_IOR_EXPR;
7564 code = TRUTH_ANDIF_EXPR;
7567 code = TRUTH_ORIF_EXPR;
7570 c_parser_error (parser,
7571 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7572 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7573 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7576 c_parser_consume_token (parser);
7577 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7581 nl = c_parser_omp_variable_list (parser, clause_loc,
7582 OMP_CLAUSE_REDUCTION, list);
7583 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7584 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7588 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7594 schedule ( schedule-kind )
7595 schedule ( schedule-kind , expression )
7598 static | dynamic | guided | runtime | auto
7602 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7605 location_t loc = c_parser_peek_token (parser)->location;
7607 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7610 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7612 if (c_parser_next_token_is (parser, CPP_NAME))
7614 tree kind = c_parser_peek_token (parser)->value;
7615 const char *p = IDENTIFIER_POINTER (kind);
7620 if (strcmp ("dynamic", p) != 0)
7622 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7626 if (strcmp ("guided", p) != 0)
7628 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7632 if (strcmp ("runtime", p) != 0)
7634 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7641 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7642 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7643 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7644 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7648 c_parser_consume_token (parser);
7649 if (c_parser_next_token_is (parser, CPP_COMMA))
7652 c_parser_consume_token (parser);
7654 here = c_parser_peek_token (parser)->location;
7655 t = c_parser_expr_no_commas (parser, NULL).value;
7656 t = c_fully_fold (t, false, NULL);
7658 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7659 error_at (here, "schedule %<runtime%> does not take "
7660 "a %<chunk_size%> parameter");
7661 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7663 "schedule %<auto%> does not take "
7664 "a %<chunk_size%> parameter");
7665 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7666 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7668 c_parser_error (parser, "expected integer expression");
7670 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7673 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7674 "expected %<,%> or %<)%>");
7676 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7677 OMP_CLAUSE_CHAIN (c) = list;
7681 c_parser_error (parser, "invalid schedule kind");
7682 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7687 shared ( variable-list ) */
7690 c_parser_omp_clause_shared (c_parser *parser, tree list)
7692 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7699 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7703 /* FIXME: Should we allow duplicates? */
7704 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7706 c = build_omp_clause (c_parser_peek_token (parser)->location,
7708 OMP_CLAUSE_CHAIN (c) = list;
7713 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7714 is a bitmask in MASK. Return the list of clauses found; the result
7715 of clause default goes in *pdefault. */
7718 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7721 tree clauses = NULL;
7724 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7727 pragma_omp_clause c_kind;
7729 tree prev = clauses;
7731 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7732 c_parser_consume_token (parser);
7735 here = c_parser_peek_token (parser)->location;
7736 c_kind = c_parser_omp_clause_name (parser);
7740 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7741 clauses = c_parser_omp_clause_collapse (parser, clauses);
7742 c_name = "collapse";
7744 case PRAGMA_OMP_CLAUSE_COPYIN:
7745 clauses = c_parser_omp_clause_copyin (parser, clauses);
7748 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7749 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7750 c_name = "copyprivate";
7752 case PRAGMA_OMP_CLAUSE_DEFAULT:
7753 clauses = c_parser_omp_clause_default (parser, clauses);
7756 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7757 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7758 c_name = "firstprivate";
7760 case PRAGMA_OMP_CLAUSE_IF:
7761 clauses = c_parser_omp_clause_if (parser, clauses);
7764 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7765 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7766 c_name = "lastprivate";
7768 case PRAGMA_OMP_CLAUSE_NOWAIT:
7769 clauses = c_parser_omp_clause_nowait (parser, clauses);
7772 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7773 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7774 c_name = "num_threads";
7776 case PRAGMA_OMP_CLAUSE_ORDERED:
7777 clauses = c_parser_omp_clause_ordered (parser, clauses);
7780 case PRAGMA_OMP_CLAUSE_PRIVATE:
7781 clauses = c_parser_omp_clause_private (parser, clauses);
7784 case PRAGMA_OMP_CLAUSE_REDUCTION:
7785 clauses = c_parser_omp_clause_reduction (parser, clauses);
7786 c_name = "reduction";
7788 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7789 clauses = c_parser_omp_clause_schedule (parser, clauses);
7790 c_name = "schedule";
7792 case PRAGMA_OMP_CLAUSE_SHARED:
7793 clauses = c_parser_omp_clause_shared (parser, clauses);
7796 case PRAGMA_OMP_CLAUSE_UNTIED:
7797 clauses = c_parser_omp_clause_untied (parser, clauses);
7801 c_parser_error (parser, "expected %<#pragma omp%> clause");
7805 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7807 /* Remove the invalid clause(s) from the list to avoid
7808 confusing the rest of the compiler. */
7810 error_at (here, "%qs is not valid for %qs", c_name, where);
7815 c_parser_skip_to_pragma_eol (parser);
7817 return c_finish_omp_clauses (clauses);
7824 In practice, we're also interested in adding the statement to an
7825 outer node. So it is convenient if we work around the fact that
7826 c_parser_statement calls add_stmt. */
7829 c_parser_omp_structured_block (c_parser *parser)
7831 tree stmt = push_stmt_list ();
7832 c_parser_statement (parser);
7833 return pop_stmt_list (stmt);
7837 # pragma omp atomic new-line
7841 x binop= expr | x++ | ++x | x-- | --x
7843 +, *, -, /, &, ^, |, <<, >>
7845 where x is an lvalue expression with scalar type.
7847 LOC is the location of the #pragma token. */
7850 c_parser_omp_atomic (location_t loc, c_parser *parser)
7854 enum tree_code code;
7855 struct c_expr rhs_expr;
7857 c_parser_skip_to_pragma_eol (parser);
7859 lhs = c_parser_unary_expression (parser).value;
7860 lhs = c_fully_fold (lhs, false, NULL);
7861 switch (TREE_CODE (lhs))
7865 c_parser_skip_to_end_of_block_or_statement (parser);
7868 case PREINCREMENT_EXPR:
7869 case POSTINCREMENT_EXPR:
7870 lhs = TREE_OPERAND (lhs, 0);
7872 rhs = integer_one_node;
7875 case PREDECREMENT_EXPR:
7876 case POSTDECREMENT_EXPR:
7877 lhs = TREE_OPERAND (lhs, 0);
7879 rhs = integer_one_node;
7883 switch (c_parser_peek_token (parser)->type)
7889 code = TRUNC_DIV_EXPR;
7904 code = BIT_AND_EXPR;
7907 code = BIT_IOR_EXPR;
7910 code = BIT_XOR_EXPR;
7913 c_parser_error (parser,
7914 "invalid operator for %<#pragma omp atomic%>");
7918 c_parser_consume_token (parser);
7920 location_t rhs_loc = c_parser_peek_token (parser)->location;
7921 rhs_expr = c_parser_expression (parser);
7922 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
7924 rhs = rhs_expr.value;
7925 rhs = c_fully_fold (rhs, false, NULL);
7928 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
7929 if (stmt != error_mark_node)
7931 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7936 # pragma omp barrier new-line
7940 c_parser_omp_barrier (c_parser *parser)
7942 location_t loc = c_parser_peek_token (parser)->location;
7943 c_parser_consume_pragma (parser);
7944 c_parser_skip_to_pragma_eol (parser);
7946 c_finish_omp_barrier (loc);
7950 # pragma omp critical [(name)] new-line
7953 LOC is the location of the #pragma itself. */
7956 c_parser_omp_critical (location_t loc, c_parser *parser)
7958 tree stmt, name = NULL;
7960 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7962 c_parser_consume_token (parser);
7963 if (c_parser_next_token_is (parser, CPP_NAME))
7965 name = c_parser_peek_token (parser)->value;
7966 c_parser_consume_token (parser);
7967 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7970 c_parser_error (parser, "expected identifier");
7972 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7973 c_parser_error (parser, "expected %<(%> or end of line");
7974 c_parser_skip_to_pragma_eol (parser);
7976 stmt = c_parser_omp_structured_block (parser);
7977 return c_finish_omp_critical (loc, stmt, name);
7981 # pragma omp flush flush-vars[opt] new-line
7984 ( variable-list ) */
7987 c_parser_omp_flush (c_parser *parser)
7989 location_t loc = c_parser_peek_token (parser)->location;
7990 c_parser_consume_pragma (parser);
7991 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7992 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7993 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7994 c_parser_error (parser, "expected %<(%> or end of line");
7995 c_parser_skip_to_pragma_eol (parser);
7997 c_finish_omp_flush (loc);
8000 /* Parse the restricted form of the for statement allowed by OpenMP.
8001 The real trick here is to determine the loop control variable early
8002 so that we can push a new decl if necessary to make it private.
8003 LOC is the location of the OMP in "#pragma omp". */
8006 c_parser_omp_for_loop (location_t loc,
8007 c_parser *parser, tree clauses, tree *par_clauses)
8009 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8010 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
8011 bool fail = false, open_brace_parsed = false;
8012 int i, collapse = 1, nbraces = 0;
8015 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8016 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8017 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8019 gcc_assert (collapse >= 1);
8021 declv = make_tree_vec (collapse);
8022 initv = make_tree_vec (collapse);
8023 condv = make_tree_vec (collapse);
8024 incrv = make_tree_vec (collapse);
8026 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8028 c_parser_error (parser, "for statement expected");
8031 for_loc = c_parser_peek_token (parser)->location;
8032 c_parser_consume_token (parser);
8034 for (i = 0; i < collapse; i++)
8038 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8041 /* Parse the initialization declaration or expression. */
8042 if (c_parser_next_token_starts_declspecs (parser))
8046 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
8047 c_parser_declaration_or_fndef (parser, true, true, true, true);
8048 decl = check_for_loop_decls (for_loc);
8051 if (DECL_INITIAL (decl) == error_mark_node)
8052 decl = error_mark_node;
8055 else if (c_parser_next_token_is (parser, CPP_NAME)
8056 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8058 struct c_expr decl_exp;
8059 struct c_expr init_exp;
8060 location_t init_loc;
8062 decl_exp = c_parser_postfix_expression (parser);
8063 decl = decl_exp.value;
8065 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8067 init_loc = c_parser_peek_token (parser)->location;
8068 init_exp = c_parser_expr_no_commas (parser, NULL);
8069 init_exp = default_function_array_read_conversion (init_loc,
8071 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8072 NOP_EXPR, init_loc, init_exp.value,
8073 init_exp.original_type);
8074 init = c_process_expr_stmt (init_loc, init);
8076 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8081 c_parser_error (parser,
8082 "expected iteration declaration or initialization");
8083 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8089 /* Parse the loop condition. */
8091 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8093 location_t cond_loc = c_parser_peek_token (parser)->location;
8094 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8096 cond = cond_expr.value;
8097 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8098 cond = c_fully_fold (cond, false, NULL);
8099 switch (cond_expr.original_code)
8107 /* Can't be cond = error_mark_node, because we want to preserve
8108 the location until c_finish_omp_for. */
8109 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8112 protected_set_expr_location (cond, cond_loc);
8114 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8116 /* Parse the increment expression. */
8118 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8120 location_t incr_loc = c_parser_peek_token (parser)->location;
8122 incr = c_process_expr_stmt (incr_loc,
8123 c_parser_expression (parser).value);
8125 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8127 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8131 TREE_VEC_ELT (declv, i) = decl;
8132 TREE_VEC_ELT (initv, i) = init;
8133 TREE_VEC_ELT (condv, i) = cond;
8134 TREE_VEC_ELT (incrv, i) = incr;
8138 if (i == collapse - 1)
8141 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8142 in between the collapsed for loops to be still considered perfectly
8143 nested. Hopefully the final version clarifies this.
8144 For now handle (multiple) {'s and empty statements. */
8147 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8149 c_parser_consume_token (parser);
8152 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8154 c_parser_consume_token (parser);
8158 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8159 c_parser_consume_token (parser);
8162 c_parser_error (parser, "not enough perfectly nested loops");
8165 open_brace_parsed = true;
8175 nbraces += bracecount;
8178 save_break = c_break_label;
8179 c_break_label = size_one_node;
8180 save_cont = c_cont_label;
8181 c_cont_label = NULL_TREE;
8182 body = push_stmt_list ();
8184 if (open_brace_parsed)
8186 location_t here = c_parser_peek_token (parser)->location;
8187 stmt = c_begin_compound_stmt (true);
8188 c_parser_compound_statement_nostart (parser);
8189 add_stmt (c_end_compound_stmt (here, stmt, true));
8192 add_stmt (c_parser_c99_block_statement (parser));
8195 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8196 SET_EXPR_LOCATION (t, loc);
8200 body = pop_stmt_list (body);
8201 c_break_label = save_break;
8202 c_cont_label = save_cont;
8206 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8208 c_parser_consume_token (parser);
8211 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8212 c_parser_consume_token (parser);
8215 c_parser_error (parser, "collapsed loops not perfectly nested");
8218 location_t here = c_parser_peek_token (parser)->location;
8219 stmt = c_begin_compound_stmt (true);
8221 c_parser_compound_statement_nostart (parser);
8222 body = c_end_compound_stmt (here, stmt, true);
8229 /* Only bother calling c_finish_omp_for if we haven't already generated
8230 an error from the initialization parsing. */
8233 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8236 if (par_clauses != NULL)
8239 for (c = par_clauses; *c ; )
8240 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8241 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8242 c = &OMP_CLAUSE_CHAIN (*c);
8245 for (i = 0; i < collapse; i++)
8246 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8249 c = &OMP_CLAUSE_CHAIN (*c);
8250 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8253 "iteration variable %qD should not be firstprivate",
8254 OMP_CLAUSE_DECL (*c));
8255 *c = OMP_CLAUSE_CHAIN (*c);
8259 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8260 change it to shared (decl) in
8261 OMP_PARALLEL_CLAUSES. */
8262 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8263 OMP_CLAUSE_LASTPRIVATE);
8264 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8265 OMP_CLAUSE_CHAIN (l) = clauses;
8267 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8271 OMP_FOR_CLAUSES (stmt) = clauses;
8278 /* FIXME diagnostics: LOC below should be the actual location of
8279 this particular for block. We need to build a list of
8280 locations to go along with FOR_BLOCK. */
8281 stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
8283 for_block = TREE_CHAIN (for_block);
8289 #pragma omp for for-clause[optseq] new-line
8292 LOC is the location of the #pragma token.
8295 #define OMP_FOR_CLAUSE_MASK \
8296 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8297 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8298 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8299 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8300 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8301 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8302 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8303 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8306 c_parser_omp_for (location_t loc, c_parser *parser)
8308 tree block, clauses, ret;
8310 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8313 block = c_begin_compound_stmt (true);
8314 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8315 block = c_end_compound_stmt (loc, block, true);
8322 # pragma omp master new-line
8325 LOC is the location of the #pragma token.
8329 c_parser_omp_master (location_t loc, c_parser *parser)
8331 c_parser_skip_to_pragma_eol (parser);
8332 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8336 # pragma omp ordered new-line
8339 LOC is the location of the #pragma itself.
8343 c_parser_omp_ordered (location_t loc, c_parser *parser)
8345 c_parser_skip_to_pragma_eol (parser);
8346 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8352 { section-sequence }
8355 section-directive[opt] structured-block
8356 section-sequence section-directive structured-block
8358 SECTIONS_LOC is the location of the #pragma omp sections. */
8361 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8364 bool error_suppress = false;
8367 loc = c_parser_peek_token (parser)->location;
8368 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8370 /* Avoid skipping until the end of the block. */
8371 parser->error = false;
8375 stmt = push_stmt_list ();
8377 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8379 substmt = push_stmt_list ();
8383 c_parser_statement (parser);
8385 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8387 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8389 if (c_parser_next_token_is (parser, CPP_EOF))
8393 substmt = pop_stmt_list (substmt);
8394 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8395 SET_EXPR_LOCATION (substmt, loc);
8401 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8403 if (c_parser_next_token_is (parser, CPP_EOF))
8406 loc = c_parser_peek_token (parser)->location;
8407 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8409 c_parser_consume_pragma (parser);
8410 c_parser_skip_to_pragma_eol (parser);
8411 error_suppress = false;
8413 else if (!error_suppress)
8415 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8416 error_suppress = true;
8419 substmt = c_parser_omp_structured_block (parser);
8420 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8421 SET_EXPR_LOCATION (substmt, loc);
8424 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8425 "expected %<#pragma omp section%> or %<}%>");
8427 substmt = pop_stmt_list (stmt);
8429 stmt = make_node (OMP_SECTIONS);
8430 SET_EXPR_LOCATION (stmt, sections_loc);
8431 TREE_TYPE (stmt) = void_type_node;
8432 OMP_SECTIONS_BODY (stmt) = substmt;
8434 return add_stmt (stmt);
8438 # pragma omp sections sections-clause[optseq] newline
8441 LOC is the location of the #pragma token.
8444 #define OMP_SECTIONS_CLAUSE_MASK \
8445 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8446 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8447 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8448 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8449 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8452 c_parser_omp_sections (location_t loc, c_parser *parser)
8454 tree block, clauses, ret;
8456 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8457 "#pragma omp sections");
8459 block = c_begin_compound_stmt (true);
8460 ret = c_parser_omp_sections_scope (loc, parser);
8462 OMP_SECTIONS_CLAUSES (ret) = clauses;
8463 block = c_end_compound_stmt (loc, block, true);
8470 # pragma parallel parallel-clause new-line
8471 # pragma parallel for parallel-for-clause new-line
8472 # pragma parallel sections parallel-sections-clause new-line
8474 LOC is the location of the #pragma token.
8477 #define OMP_PARALLEL_CLAUSE_MASK \
8478 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8479 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8480 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8481 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8482 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8483 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8484 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8485 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8488 c_parser_omp_parallel (location_t loc, c_parser *parser)
8490 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8491 const char *p_name = "#pragma omp parallel";
8492 tree stmt, clauses, par_clause, ws_clause, block;
8493 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8495 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8497 c_parser_consume_token (parser);
8498 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8499 p_name = "#pragma omp parallel for";
8500 mask |= OMP_FOR_CLAUSE_MASK;
8501 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8503 else if (c_parser_next_token_is (parser, CPP_NAME))
8505 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8506 if (strcmp (p, "sections") == 0)
8508 c_parser_consume_token (parser);
8509 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8510 p_name = "#pragma omp parallel sections";
8511 mask |= OMP_SECTIONS_CLAUSE_MASK;
8512 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8516 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8520 case PRAGMA_OMP_PARALLEL:
8521 block = c_begin_omp_parallel ();
8522 c_parser_statement (parser);
8523 stmt = c_finish_omp_parallel (loc, clauses, block);
8526 case PRAGMA_OMP_PARALLEL_FOR:
8527 block = c_begin_omp_parallel ();
8528 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8529 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8530 stmt = c_finish_omp_parallel (loc, par_clause, block);
8531 OMP_PARALLEL_COMBINED (stmt) = 1;
8534 case PRAGMA_OMP_PARALLEL_SECTIONS:
8535 block = c_begin_omp_parallel ();
8536 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8537 stmt = c_parser_omp_sections_scope (loc, parser);
8539 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8540 stmt = c_finish_omp_parallel (loc, par_clause, block);
8541 OMP_PARALLEL_COMBINED (stmt) = 1;
8552 # pragma omp single single-clause[optseq] new-line
8555 LOC is the location of the #pragma.
8558 #define OMP_SINGLE_CLAUSE_MASK \
8559 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8560 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8561 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8562 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8565 c_parser_omp_single (location_t loc, c_parser *parser)
8567 tree stmt = make_node (OMP_SINGLE);
8568 SET_EXPR_LOCATION (stmt, loc);
8569 TREE_TYPE (stmt) = void_type_node;
8571 OMP_SINGLE_CLAUSES (stmt)
8572 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8573 "#pragma omp single");
8574 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8576 return add_stmt (stmt);
8580 # pragma omp task task-clause[optseq] new-line
8582 LOC is the location of the #pragma.
8585 #define OMP_TASK_CLAUSE_MASK \
8586 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8587 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8588 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8589 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8590 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8591 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8594 c_parser_omp_task (location_t loc, c_parser *parser)
8596 tree clauses, block;
8598 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8599 "#pragma omp task");
8601 block = c_begin_omp_task ();
8602 c_parser_statement (parser);
8603 return c_finish_omp_task (loc, clauses, block);
8607 # pragma omp taskwait new-line
8611 c_parser_omp_taskwait (c_parser *parser)
8613 location_t loc = c_parser_peek_token (parser)->location;
8614 c_parser_consume_pragma (parser);
8615 c_parser_skip_to_pragma_eol (parser);
8617 c_finish_omp_taskwait (loc);
8620 /* Main entry point to parsing most OpenMP pragmas. */
8623 c_parser_omp_construct (c_parser *parser)
8625 enum pragma_kind p_kind;
8629 loc = c_parser_peek_token (parser)->location;
8630 p_kind = c_parser_peek_token (parser)->pragma_kind;
8631 c_parser_consume_pragma (parser);
8635 case PRAGMA_OMP_ATOMIC:
8636 c_parser_omp_atomic (loc, parser);
8638 case PRAGMA_OMP_CRITICAL:
8639 stmt = c_parser_omp_critical (loc, parser);
8641 case PRAGMA_OMP_FOR:
8642 stmt = c_parser_omp_for (loc, parser);
8644 case PRAGMA_OMP_MASTER:
8645 stmt = c_parser_omp_master (loc, parser);
8647 case PRAGMA_OMP_ORDERED:
8648 stmt = c_parser_omp_ordered (loc, parser);
8650 case PRAGMA_OMP_PARALLEL:
8651 stmt = c_parser_omp_parallel (loc, parser);
8653 case PRAGMA_OMP_SECTIONS:
8654 stmt = c_parser_omp_sections (loc, parser);
8656 case PRAGMA_OMP_SINGLE:
8657 stmt = c_parser_omp_single (loc, parser);
8659 case PRAGMA_OMP_TASK:
8660 stmt = c_parser_omp_task (loc, parser);
8667 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
8672 # pragma omp threadprivate (variable-list) */
8675 c_parser_omp_threadprivate (c_parser *parser)
8680 c_parser_consume_pragma (parser);
8681 loc = c_parser_peek_token (parser)->location;
8682 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8684 /* Mark every variable in VARS to be assigned thread local storage. */
8685 for (t = vars; t; t = TREE_CHAIN (t))
8687 tree v = TREE_PURPOSE (t);
8689 /* FIXME diagnostics: Ideally we should keep individual
8690 locations for all the variables in the var list to make the
8691 following errors more precise. Perhaps
8692 c_parser_omp_var_list_parens() should construct a list of
8693 locations to go along with the var list. */
8695 /* If V had already been marked threadprivate, it doesn't matter
8696 whether it had been used prior to this point. */
8697 if (TREE_CODE (v) != VAR_DECL)
8698 error_at (loc, "%qD is not a variable", v);
8699 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8700 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
8701 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8702 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
8703 else if (TREE_TYPE (v) == error_mark_node)
8705 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8706 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
8709 if (! DECL_THREAD_LOCAL_P (v))
8711 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8712 /* If rtl has been already set for this var, call
8713 make_decl_rtl once again, so that encode_section_info
8714 has a chance to look at the new decl flags. */
8715 if (DECL_RTL_SET_P (v))
8718 C_DECL_THREADPRIVATE_P (v) = 1;
8722 c_parser_skip_to_pragma_eol (parser);
8726 /* Parse a single source file. */
8731 /* Use local storage to begin. If the first token is a pragma, parse it.
8732 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8733 which will cause garbage collection. */
8736 memset (&tparser, 0, sizeof tparser);
8737 the_parser = &tparser;
8739 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8740 c_parser_pragma_pch_preprocess (&tparser);
8742 the_parser = GGC_NEW (c_parser);
8743 *the_parser = tparser;
8745 /* Initialize EH, if we've been told to do so. */
8746 if (flag_exceptions)
8747 using_eh_for_cleanups ();
8749 c_parser_translation_unit (the_parser);
8753 #include "gt-c-parser.h"