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
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"
46 #include "langhooks.h"
64 /* Initialization routine for this file. */
69 /* The only initialization required is of the reserved word
80 mask |= D_ASM | D_EXT;
84 if (!c_dialect_objc ())
85 mask |= D_OBJC | D_CXX_OBJC;
87 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
88 for (i = 0; i < num_c_common_reswords; i++)
90 /* If a keyword is disabled, do not enter it into the table
91 and so create a canonical spelling that isn't a keyword. */
92 if (c_common_reswords[i].disable & mask)
95 && (c_common_reswords[i].disable & D_CXXWARN))
97 id = get_identifier (c_common_reswords[i].word);
98 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
99 C_IS_RESERVED_WORD (id) = 1;
104 id = get_identifier (c_common_reswords[i].word);
105 C_SET_RID_CODE (id, c_common_reswords[i].rid);
106 C_IS_RESERVED_WORD (id) = 1;
107 ridpointers [(int) c_common_reswords[i].rid] = id;
111 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
112 and the C parser. Unlike the C++ lexer, the parser structure
113 stores the lexer information instead of using a separate structure.
114 Identifiers are separated into ordinary identifiers, type names,
115 keywords and some other Objective-C types of identifiers, and some
116 look-ahead is maintained.
118 ??? It might be a good idea to lex the whole file up front (as for
119 C++). It would then be possible to share more of the C and C++
120 lexer code, if desired. */
122 /* The following local token type is used. */
125 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
127 /* More information about the type of a CPP_NAME token. */
128 typedef enum c_id_kind {
129 /* An ordinary identifier. */
131 /* An identifier declared as a typedef name. */
133 /* An identifier declared as an Objective-C class name. */
135 /* Not an identifier. */
139 /* A single C token after string literal concatenation and conversion
140 of preprocessing tokens to tokens. */
141 typedef struct GTY (()) c_token {
142 /* The kind of token. */
143 ENUM_BITFIELD (cpp_ttype) type : 8;
144 /* If this token is a CPP_NAME, this value indicates whether also
145 declared as some kind of type. Otherwise, it is C_ID_NONE. */
146 ENUM_BITFIELD (c_id_kind) id_kind : 8;
147 /* If this token is a keyword, this value indicates which keyword.
148 Otherwise, this value is RID_MAX. */
149 ENUM_BITFIELD (rid) keyword : 8;
150 /* If this token is a CPP_PRAGMA, this indicates the pragma that
151 was seen. Otherwise it is PRAGMA_NONE. */
152 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
153 /* The value associated with this token, if any. */
155 /* The location at which this token was found. */
159 /* A parser structure recording information about the state and
160 context of parsing. Includes lexer information with up to two
161 tokens of look-ahead; more are not needed for C. */
162 typedef struct GTY(()) c_parser {
163 /* The look-ahead tokens. */
165 /* How many look-ahead tokens are available (0, 1 or 2). */
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error : 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma : 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block : 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string : 1;
178 /* Objective-C specific parser/lexer information. */
179 BOOL_BITFIELD objc_pq_context : 1;
180 /* The following flag is needed to contextualize Objective-C lexical
181 analysis. In some cases (e.g., 'int NSObject;'), it is
182 undesirable to bind an identifier to an Objective-C class, even
183 if a class with that name exists. */
184 BOOL_BITFIELD objc_need_raw_identifier : 1;
188 /* The actual parser and external interface. ??? Does this need to be
189 garbage-collected? */
191 static GTY (()) c_parser *the_parser;
194 /* Read in and lex a single token, storing it in *TOKEN. */
197 c_lex_one_token (c_parser *parser, c_token *token)
199 timevar_push (TV_LEX);
201 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
202 (parser->lex_untranslated_string
203 ? C_LEX_STRING_NO_TRANSLATE : 0));
204 token->id_kind = C_ID_NONE;
205 token->keyword = RID_MAX;
206 token->pragma_kind = PRAGMA_NONE;
214 bool objc_force_identifier = parser->objc_need_raw_identifier;
215 if (c_dialect_objc ())
216 parser->objc_need_raw_identifier = false;
218 if (C_IS_RESERVED_WORD (token->value))
220 enum rid rid_code = C_RID_CODE (token->value);
222 if (rid_code == RID_CXX_COMPAT_WARN)
224 warning_at (token->location,
226 "identifier %qE conflicts with C++ keyword",
229 else if (c_dialect_objc ())
231 if (!objc_is_reserved_word (token->value)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code)
233 || parser->objc_pq_context))
235 /* Return the canonical spelling for this keyword. */
236 token->value = ridpointers[(int) rid_code];
237 token->type = CPP_KEYWORD;
238 token->keyword = rid_code;
244 token->type = CPP_KEYWORD;
245 token->keyword = rid_code;
250 decl = lookup_name (token->value);
253 if (TREE_CODE (decl) == TYPE_DECL)
255 token->id_kind = C_ID_TYPENAME;
259 else if (c_dialect_objc ())
261 tree objc_interface_decl = objc_is_class_name (token->value);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier && !decl)))
269 token->value = objc_interface_decl;
270 token->id_kind = C_ID_CLASSNAME;
274 token->id_kind = C_ID_ID;
278 /* This only happens in Objective-C; it must be a keyword. */
279 token->type = CPP_KEYWORD;
280 token->keyword = C_RID_CODE (token->value);
284 case CPP_CLOSE_PAREN:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser->objc_need_raw_identifier = false;
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
299 timevar_pop (TV_LEX);
302 /* Return a pointer to the next token from PARSER, reading it in if
305 static inline c_token *
306 c_parser_peek_token (c_parser *parser)
308 if (parser->tokens_avail == 0)
310 c_lex_one_token (parser, &parser->tokens[0]);
311 parser->tokens_avail = 1;
313 return &parser->tokens[0];
316 /* Return true if the next token from PARSER has the indicated
320 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
322 return c_parser_peek_token (parser)->type == type;
325 /* Return true if the next token from PARSER does not have the
329 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
331 return !c_parser_next_token_is (parser, type);
334 /* Return true if the next token from PARSER is the indicated
338 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
340 return c_parser_peek_token (parser)->keyword == keyword;
343 /* Return true if TOKEN can start a type name,
346 c_token_starts_typename (c_token *token)
351 switch (token->id_kind)
358 gcc_assert (c_dialect_objc ());
364 switch (token->keyword)
396 if (c_dialect_objc ())
404 /* Return true if the next token from PARSER can start a type name,
407 c_parser_next_token_starts_typename (c_parser *parser)
409 c_token *token = c_parser_peek_token (parser);
410 return c_token_starts_typename (token);
413 /* Return true if TOKEN can start declaration specifiers, false
416 c_token_starts_declspecs (c_token *token)
421 switch (token->id_kind)
428 gcc_assert (c_dialect_objc ());
434 switch (token->keyword)
473 if (c_dialect_objc ())
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
484 c_parser_next_token_starts_declspecs (c_parser *parser)
486 c_token *token = c_parser_peek_token (parser);
487 return c_token_starts_declspecs (token);
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
494 c_parser_peek_2nd_token (c_parser *parser)
496 if (parser->tokens_avail >= 2)
497 return &parser->tokens[1];
498 gcc_assert (parser->tokens_avail == 1);
499 gcc_assert (parser->tokens[0].type != CPP_EOF);
500 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
501 c_lex_one_token (parser, &parser->tokens[1]);
502 parser->tokens_avail = 2;
503 return &parser->tokens[1];
506 /* Consume the next token from PARSER. */
509 c_parser_consume_token (c_parser *parser)
511 gcc_assert (parser->tokens_avail >= 1);
512 gcc_assert (parser->tokens[0].type != CPP_EOF);
513 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
514 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
515 if (parser->tokens_avail == 2)
516 parser->tokens[0] = parser->tokens[1];
517 parser->tokens_avail--;
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
524 c_parser_consume_pragma (c_parser *parser)
526 gcc_assert (!parser->in_pragma);
527 gcc_assert (parser->tokens_avail >= 1);
528 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
529 if (parser->tokens_avail == 2)
530 parser->tokens[0] = parser->tokens[1];
531 parser->tokens_avail--;
532 parser->in_pragma = true;
535 /* Update the globals input_location and in_system_header from
538 c_parser_set_source_position_from_token (c_token *token)
540 if (token->type != CPP_EOF)
542 input_location = token->location;
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
552 Do not issue a diagnostic if still recovering from an error.
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
559 c_parser_error (c_parser *parser, const char *gmsgid)
561 c_token *token = c_parser_peek_token (parser);
564 parser->error = true;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token);
570 c_parse_error (gmsgid,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
574 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
575 /* ??? The C parser does not save the cpp flags of a
576 token, we need to pass 0 here and we will not get
577 the source spelling of some tokens but rather the
578 canonical spelling. */
579 token->value, /*flags=*/0);
582 /* If the next token is of the indicated TYPE, consume it. Otherwise,
583 issue the error MSGID. If MSGID is NULL then a message has already
584 been produced and no message will be produced this time. Returns
585 true if found, false otherwise. */
588 c_parser_require (c_parser *parser,
592 if (c_parser_next_token_is (parser, type))
594 c_parser_consume_token (parser);
599 c_parser_error (parser, msgid);
604 /* If the next token is the indicated keyword, consume it. Otherwise,
605 issue the error MSGID. Returns true if found, false otherwise. */
608 c_parser_require_keyword (c_parser *parser,
612 if (c_parser_next_token_is_keyword (parser, keyword))
614 c_parser_consume_token (parser);
619 c_parser_error (parser, msgid);
624 /* Like c_parser_require, except that tokens will be skipped until the
625 desired token is found. An error message is still produced if the
626 next token is not as expected. If MSGID is NULL then a message has
627 already been produced and no message will be produced this
631 c_parser_skip_until_found (c_parser *parser,
635 unsigned nesting_depth = 0;
637 if (c_parser_require (parser, type, msgid))
640 /* Skip tokens until the desired token is found. */
643 /* Peek at the next token. */
644 c_token *token = c_parser_peek_token (parser);
645 /* If we've reached the token we want, consume it and stop. */
646 if (token->type == type && !nesting_depth)
648 c_parser_consume_token (parser);
652 /* If we've run out of tokens, stop. */
653 if (token->type == CPP_EOF)
655 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
657 if (token->type == CPP_OPEN_BRACE
658 || token->type == CPP_OPEN_PAREN
659 || token->type == CPP_OPEN_SQUARE)
661 else if (token->type == CPP_CLOSE_BRACE
662 || token->type == CPP_CLOSE_PAREN
663 || token->type == CPP_CLOSE_SQUARE)
665 if (nesting_depth-- == 0)
668 /* Consume this token. */
669 c_parser_consume_token (parser);
671 parser->error = false;
674 /* Skip tokens until the end of a parameter is found, but do not
675 consume the comma, semicolon or closing delimiter. */
678 c_parser_skip_to_end_of_parameter (c_parser *parser)
680 unsigned nesting_depth = 0;
684 c_token *token = c_parser_peek_token (parser);
685 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
688 /* If we've run out of tokens, stop. */
689 if (token->type == CPP_EOF)
691 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
693 if (token->type == CPP_OPEN_BRACE
694 || token->type == CPP_OPEN_PAREN
695 || token->type == CPP_OPEN_SQUARE)
697 else if (token->type == CPP_CLOSE_BRACE
698 || token->type == CPP_CLOSE_PAREN
699 || token->type == CPP_CLOSE_SQUARE)
701 if (nesting_depth-- == 0)
704 /* Consume this token. */
705 c_parser_consume_token (parser);
707 parser->error = false;
710 /* Expect to be at the end of the pragma directive and consume an
711 end of line marker. */
714 c_parser_skip_to_pragma_eol (c_parser *parser)
716 gcc_assert (parser->in_pragma);
717 parser->in_pragma = false;
719 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
722 c_token *token = c_parser_peek_token (parser);
723 if (token->type == CPP_EOF)
725 if (token->type == CPP_PRAGMA_EOL)
727 c_parser_consume_token (parser);
730 c_parser_consume_token (parser);
733 parser->error = false;
736 /* Skip tokens until we have consumed an entire block, or until we
737 have consumed a non-nested ';'. */
740 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
742 unsigned nesting_depth = 0;
743 bool save_error = parser->error;
749 /* Peek at the next token. */
750 token = c_parser_peek_token (parser);
758 if (parser->in_pragma)
763 /* If the next token is a ';', we have reached the
764 end of the statement. */
767 /* Consume the ';'. */
768 c_parser_consume_token (parser);
773 case CPP_CLOSE_BRACE:
774 /* If the next token is a non-nested '}', then we have
775 reached the end of the current block. */
776 if (nesting_depth == 0 || --nesting_depth == 0)
778 c_parser_consume_token (parser);
784 /* If it the next token is a '{', then we are entering a new
785 block. Consume the entire block. */
790 /* If we see a pragma, consume the whole thing at once. We
791 have some safeguards against consuming pragmas willy-nilly.
792 Normally, we'd expect to be here with parser->error set,
793 which disables these safeguards. But it's possible to get
794 here for secondary error recovery, after parser->error has
796 c_parser_consume_pragma (parser);
797 c_parser_skip_to_pragma_eol (parser);
798 parser->error = save_error;
805 c_parser_consume_token (parser);
809 parser->error = false;
812 /* CPP's options (initialized by c-opts.c). */
813 extern cpp_options *cpp_opts;
815 /* Save the warning flags which are controlled by __extension__. */
818 disable_extension_diagnostics (void)
821 | (warn_pointer_arith << 1)
822 | (warn_traditional << 2)
824 | (warn_long_long << 4)
825 | (warn_cxx_compat << 5));
826 cpp_opts->pedantic = pedantic = 0;
827 warn_pointer_arith = 0;
828 cpp_opts->warn_traditional = warn_traditional = 0;
830 cpp_opts->warn_long_long = warn_long_long = 0;
835 /* Restore the warning flags which are controlled by __extension__.
836 FLAGS is the return value from disable_extension_diagnostics. */
839 restore_extension_diagnostics (int flags)
841 cpp_opts->pedantic = pedantic = flags & 1;
842 warn_pointer_arith = (flags >> 1) & 1;
843 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
844 flag_iso = (flags >> 3) & 1;
845 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
846 warn_cxx_compat = (flags >> 5) & 1;
849 /* Possibly kinds of declarator to parse. */
850 typedef enum c_dtr_syn {
851 /* A normal declarator with an identifier. */
853 /* An abstract declarator (maybe empty). */
855 /* A parameter declarator: may be either, but after a type name does
856 not redeclare a typedef name as an identifier if it can
857 alternatively be interpreted as a typedef name; see DR#009,
858 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
859 following DR#249. For example, given a typedef T, "int T" and
860 "int *T" are valid parameter declarations redeclaring T, while
861 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
862 abstract declarators rather than involving redundant parentheses;
863 the same applies with attributes inside the parentheses before
868 static void c_parser_external_declaration (c_parser *);
869 static void c_parser_asm_definition (c_parser *);
870 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
871 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
873 static struct c_typespec c_parser_enum_specifier (c_parser *);
874 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
875 static tree c_parser_struct_declaration (c_parser *);
876 static struct c_typespec c_parser_typeof_specifier (c_parser *);
877 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
879 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
881 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
883 struct c_declarator *);
884 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
885 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
886 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
887 static tree c_parser_simple_asm_expr (c_parser *);
888 static tree c_parser_attributes (c_parser *);
889 static struct c_type_name *c_parser_type_name (c_parser *);
890 static struct c_expr c_parser_initializer (c_parser *);
891 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
892 static void c_parser_initelt (c_parser *);
893 static void c_parser_initval (c_parser *, struct c_expr *);
894 static tree c_parser_compound_statement (c_parser *);
895 static void c_parser_compound_statement_nostart (c_parser *);
896 static void c_parser_label (c_parser *);
897 static void c_parser_statement (c_parser *);
898 static void c_parser_statement_after_labels (c_parser *);
899 static void c_parser_if_statement (c_parser *);
900 static void c_parser_switch_statement (c_parser *);
901 static void c_parser_while_statement (c_parser *);
902 static void c_parser_do_statement (c_parser *);
903 static void c_parser_for_statement (c_parser *);
904 static tree c_parser_asm_statement (c_parser *);
905 static tree c_parser_asm_operands (c_parser *, bool);
906 static tree c_parser_asm_goto_operands (c_parser *);
907 static tree c_parser_asm_clobbers (c_parser *);
908 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
909 static struct c_expr c_parser_conditional_expression (c_parser *,
911 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
912 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
913 static struct c_expr c_parser_unary_expression (c_parser *);
914 static struct c_expr c_parser_sizeof_expression (c_parser *);
915 static struct c_expr c_parser_alignof_expression (c_parser *);
916 static struct c_expr c_parser_postfix_expression (c_parser *);
917 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
918 struct c_type_name *,
920 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
923 static struct c_expr c_parser_expression (c_parser *);
924 static struct c_expr c_parser_expression_conv (c_parser *);
925 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
927 static void c_parser_omp_construct (c_parser *);
928 static void c_parser_omp_threadprivate (c_parser *);
929 static void c_parser_omp_barrier (c_parser *);
930 static void c_parser_omp_flush (c_parser *);
931 static void c_parser_omp_taskwait (c_parser *);
933 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
934 static bool c_parser_pragma (c_parser *, enum pragma_context);
936 /* These Objective-C parser functions are only ever called when
937 compiling Objective-C. */
938 static void c_parser_objc_class_definition (c_parser *);
939 static void c_parser_objc_class_instance_variables (c_parser *);
940 static void c_parser_objc_class_declaration (c_parser *);
941 static void c_parser_objc_alias_declaration (c_parser *);
942 static void c_parser_objc_protocol_definition (c_parser *);
943 static enum tree_code c_parser_objc_method_type (c_parser *);
944 static void c_parser_objc_method_definition (c_parser *);
945 static void c_parser_objc_methodprotolist (c_parser *);
946 static void c_parser_objc_methodproto (c_parser *);
947 static tree c_parser_objc_method_decl (c_parser *);
948 static tree c_parser_objc_type_name (c_parser *);
949 static tree c_parser_objc_protocol_refs (c_parser *);
950 static void c_parser_objc_try_catch_statement (c_parser *);
951 static void c_parser_objc_synchronized_statement (c_parser *);
952 static tree c_parser_objc_selector (c_parser *);
953 static tree c_parser_objc_selector_arg (c_parser *);
954 static tree c_parser_objc_receiver (c_parser *);
955 static tree c_parser_objc_message_args (c_parser *);
956 static tree c_parser_objc_keywordexpr (c_parser *);
958 /* Parse a translation unit (C90 6.7, C99 6.9).
961 external-declarations
963 external-declarations:
965 external-declarations external-declaration
974 c_parser_translation_unit (c_parser *parser)
976 if (c_parser_next_token_is (parser, CPP_EOF))
978 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
979 "ISO C forbids an empty translation unit");
983 void *obstack_position = obstack_alloc (&parser_obstack, 0);
984 mark_valid_location_for_stdc_pragma (false);
988 c_parser_external_declaration (parser);
989 obstack_free (&parser_obstack, obstack_position);
991 while (c_parser_next_token_is_not (parser, CPP_EOF));
995 /* Parse an external declaration (C90 6.7, C99 6.9).
997 external-declaration:
1003 external-declaration:
1006 __extension__ external-declaration
1010 external-declaration:
1011 objc-class-definition
1012 objc-class-declaration
1013 objc-alias-declaration
1014 objc-protocol-definition
1015 objc-method-definition
1020 c_parser_external_declaration (c_parser *parser)
1023 switch (c_parser_peek_token (parser)->type)
1026 switch (c_parser_peek_token (parser)->keyword)
1029 ext = disable_extension_diagnostics ();
1030 c_parser_consume_token (parser);
1031 c_parser_external_declaration (parser);
1032 restore_extension_diagnostics (ext);
1035 c_parser_asm_definition (parser);
1037 case RID_AT_INTERFACE:
1038 case RID_AT_IMPLEMENTATION:
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_objc_class_definition (parser);
1043 gcc_assert (c_dialect_objc ());
1044 c_parser_objc_class_declaration (parser);
1047 gcc_assert (c_dialect_objc ());
1048 c_parser_objc_alias_declaration (parser);
1050 case RID_AT_PROTOCOL:
1051 gcc_assert (c_dialect_objc ());
1052 c_parser_objc_protocol_definition (parser);
1055 gcc_assert (c_dialect_objc ());
1056 c_parser_consume_token (parser);
1057 objc_finish_implementation ();
1064 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1065 "ISO C does not allow extra %<;%> outside of a function");
1066 c_parser_consume_token (parser);
1069 mark_valid_location_for_stdc_pragma (true);
1070 c_parser_pragma (parser, pragma_external);
1071 mark_valid_location_for_stdc_pragma (false);
1075 if (c_dialect_objc ())
1077 c_parser_objc_method_definition (parser);
1080 /* Else fall through, and yield a syntax error trying to parse
1081 as a declaration or function definition. */
1084 /* A declaration or a function definition. We can only tell
1085 which after parsing the declaration specifiers, if any, and
1086 the first declarator. */
1087 c_parser_declaration_or_fndef (parser, true, true, false, true);
1093 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1094 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1095 accepted; otherwise (old-style parameter declarations) only other
1096 declarations are accepted. If NESTED is true, we are inside a
1097 function or parsing old-style parameter declarations; any functions
1098 encountered are nested functions and declaration specifiers are
1099 required; otherwise we are at top level and functions are normal
1100 functions and declaration specifiers may be optional. If EMPTY_OK
1101 is true, empty declarations are OK (subject to all other
1102 constraints); otherwise (old-style parameter declarations) they are
1103 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1104 may start with attributes; otherwise they may not.
1107 declaration-specifiers init-declarator-list[opt] ;
1109 function-definition:
1110 declaration-specifiers[opt] declarator declaration-list[opt]
1115 declaration-list declaration
1117 init-declarator-list:
1119 init-declarator-list , init-declarator
1122 declarator simple-asm-expr[opt] attributes[opt]
1123 declarator simple-asm-expr[opt] attributes[opt] = initializer
1127 nested-function-definition:
1128 declaration-specifiers declarator declaration-list[opt]
1131 The simple-asm-expr and attributes are GNU extensions.
1133 This function does not handle __extension__; that is handled in its
1134 callers. ??? Following the old parser, __extension__ may start
1135 external declarations, declarations in functions and declarations
1136 at the start of "for" loops, but not old-style parameter
1139 C99 requires declaration specifiers in a function definition; the
1140 absence is diagnosed through the diagnosis of implicit int. In GNU
1141 C we also allow but diagnose declarations without declaration
1142 specifiers, but only at top level (elsewhere they conflict with
1148 threadprivate-directive */
1151 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1152 bool nested, bool start_attr_ok)
1154 struct c_declspecs *specs;
1156 tree all_prefix_attrs;
1157 bool diagnosed_no_specs = false;
1158 location_t here = c_parser_peek_token (parser)->location;
1160 specs = build_null_declspecs ();
1161 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1164 c_parser_skip_to_end_of_block_or_statement (parser);
1167 if (nested && !specs->declspecs_seen_p)
1169 c_parser_error (parser, "expected declaration specifiers");
1170 c_parser_skip_to_end_of_block_or_statement (parser);
1173 finish_declspecs (specs);
1174 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1180 shadow_tag_warned (specs, 1);
1181 pedwarn (here, 0, "empty declaration");
1183 c_parser_consume_token (parser);
1186 pending_xref_error ();
1187 prefix_attrs = specs->attrs;
1188 all_prefix_attrs = prefix_attrs;
1189 specs->attrs = NULL_TREE;
1192 struct c_declarator *declarator;
1195 /* Declaring either one or more declarators (in which case we
1196 should diagnose if there were no declaration specifiers) or a
1197 function definition (in which case the diagnostic for
1198 implicit int suffices). */
1199 declarator = c_parser_declarator (parser, specs->type_seen_p,
1200 C_DTR_NORMAL, &dummy);
1201 if (declarator == NULL)
1203 c_parser_skip_to_end_of_block_or_statement (parser);
1206 if (c_parser_next_token_is (parser, CPP_EQ)
1207 || c_parser_next_token_is (parser, CPP_COMMA)
1208 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1209 || c_parser_next_token_is_keyword (parser, RID_ASM)
1210 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1212 tree asm_name = NULL_TREE;
1213 tree postfix_attrs = NULL_TREE;
1214 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1216 diagnosed_no_specs = true;
1217 pedwarn (here, 0, "data definition has no type or storage class");
1219 /* Having seen a data definition, there cannot now be a
1220 function definition. */
1222 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1223 asm_name = c_parser_simple_asm_expr (parser);
1224 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1225 postfix_attrs = c_parser_attributes (parser);
1226 if (c_parser_next_token_is (parser, CPP_EQ))
1230 location_t init_loc;
1231 c_parser_consume_token (parser);
1232 /* The declaration of the variable is in effect while
1233 its initializer is parsed. */
1234 d = start_decl (declarator, specs, true,
1235 chainon (postfix_attrs, all_prefix_attrs));
1237 d = error_mark_node;
1238 start_init (d, asm_name, global_bindings_p ());
1239 init_loc = c_parser_peek_token (parser)->location;
1240 init = c_parser_initializer (parser);
1242 if (d != error_mark_node)
1244 maybe_warn_string_init (TREE_TYPE (d), init);
1245 finish_decl (d, init_loc, init.value,
1246 init.original_type, asm_name);
1251 tree d = start_decl (declarator, specs, false,
1252 chainon (postfix_attrs,
1255 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1256 NULL_TREE, asm_name);
1258 if (c_parser_next_token_is (parser, CPP_COMMA))
1260 c_parser_consume_token (parser);
1261 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1262 all_prefix_attrs = chainon (c_parser_attributes (parser),
1265 all_prefix_attrs = prefix_attrs;
1268 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1270 c_parser_consume_token (parser);
1275 c_parser_error (parser, "expected %<,%> or %<;%>");
1276 c_parser_skip_to_end_of_block_or_statement (parser);
1282 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1283 "%<asm%> or %<__attribute__%>");
1284 c_parser_skip_to_end_of_block_or_statement (parser);
1287 /* Function definition (nested or otherwise). */
1290 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1291 c_push_function_context ();
1293 if (!start_function (specs, declarator, all_prefix_attrs))
1295 /* This can appear in many cases looking nothing like a
1296 function definition, so we don't give a more specific
1297 error suggesting there was one. */
1298 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1299 "or %<__attribute__%>");
1301 c_pop_function_context ();
1304 /* Parse old-style parameter declarations. ??? Attributes are
1305 not allowed to start declaration specifiers here because of a
1306 syntax conflict between a function declaration with attribute
1307 suffix and a function definition with an attribute prefix on
1308 first old-style parameter declaration. Following the old
1309 parser, they are not accepted on subsequent old-style
1310 parameter declarations either. However, there is no
1311 ambiguity after the first declaration, nor indeed on the
1312 first as long as we don't allow postfix attributes after a
1313 declarator with a nonempty identifier list in a definition;
1314 and postfix attributes have never been accepted here in
1315 function definitions either. */
1316 while (c_parser_next_token_is_not (parser, CPP_EOF)
1317 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1318 c_parser_declaration_or_fndef (parser, false, false, true, false);
1319 store_parm_decls ();
1320 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1321 = c_parser_peek_token (parser)->location;
1322 fnbody = c_parser_compound_statement (parser);
1325 tree decl = current_function_decl;
1328 c_pop_function_context ();
1329 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1340 /* Parse an asm-definition (asm() outside a function body). This is a
1348 c_parser_asm_definition (c_parser *parser)
1350 tree asm_str = c_parser_simple_asm_expr (parser);
1352 cgraph_add_asm_node (asm_str);
1353 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1356 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1357 6.7), adding them to SPECS (which may already include some).
1358 Storage class specifiers are accepted iff SCSPEC_OK; type
1359 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1360 the start iff START_ATTR_OK.
1362 declaration-specifiers:
1363 storage-class-specifier declaration-specifiers[opt]
1364 type-specifier declaration-specifiers[opt]
1365 type-qualifier declaration-specifiers[opt]
1366 function-specifier declaration-specifiers[opt]
1368 Function specifiers (inline) are from C99, and are currently
1369 handled as storage class specifiers, as is __thread.
1371 C90 6.5.1, C99 6.7.1:
1372 storage-class-specifier:
1383 C90 6.5.2, C99 6.7.2:
1396 [_Imaginary removed in C99 TC2]
1397 struct-or-union-specifier
1401 (_Bool and _Complex are new in C99.)
1403 C90 6.5.3, C99 6.7.3:
1410 (restrict is new in C99.)
1414 declaration-specifiers:
1415 attributes declaration-specifiers[opt]
1417 storage-class-specifier:
1429 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1430 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1435 class-name objc-protocol-refs[opt]
1436 typedef-name objc-protocol-refs
1441 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1442 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1444 bool attrs_ok = start_attr_ok;
1445 bool seen_type = specs->type_seen_p;
1446 while (c_parser_next_token_is (parser, CPP_NAME)
1447 || c_parser_next_token_is (parser, CPP_KEYWORD)
1448 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1450 struct c_typespec t;
1452 location_t loc = c_parser_peek_token (parser)->location;
1453 if (c_parser_next_token_is (parser, CPP_NAME))
1455 tree value = c_parser_peek_token (parser)->value;
1456 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1457 /* This finishes the specifiers unless a type name is OK, it
1458 is declared as a type name and a type name hasn't yet
1460 if (!typespec_ok || seen_type
1461 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1463 c_parser_consume_token (parser);
1466 if (kind == C_ID_TYPENAME
1467 && (!c_dialect_objc ()
1468 || c_parser_next_token_is_not (parser, CPP_LESS)))
1470 t.kind = ctsk_typedef;
1471 /* For a typedef name, record the meaning, not the name.
1472 In case of 'foo foo, bar;'. */
1473 t.spec = lookup_name (value);
1475 t.expr_const_operands = true;
1479 tree proto = NULL_TREE;
1480 gcc_assert (c_dialect_objc ());
1482 if (c_parser_next_token_is (parser, CPP_LESS))
1483 proto = c_parser_objc_protocol_refs (parser);
1484 t.spec = objc_get_protocol_qualified_type (value, proto);
1486 t.expr_const_operands = true;
1488 declspecs_add_type (loc, specs, t);
1491 if (c_parser_next_token_is (parser, CPP_LESS))
1493 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1494 nisse@lysator.liu.se. */
1496 gcc_assert (c_dialect_objc ());
1497 if (!typespec_ok || seen_type)
1499 proto = c_parser_objc_protocol_refs (parser);
1501 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1503 t.expr_const_operands = true;
1504 declspecs_add_type (loc, specs, t);
1507 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1508 switch (c_parser_peek_token (parser)->keyword)
1520 /* TODO: Distinguish between function specifiers (inline)
1521 and storage class specifiers, either here or in
1522 declspecs_add_scspec. */
1523 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1524 c_parser_consume_token (parser);
1547 if (c_dialect_objc ())
1548 parser->objc_need_raw_identifier = true;
1549 t.kind = ctsk_resword;
1550 t.spec = c_parser_peek_token (parser)->value;
1552 t.expr_const_operands = true;
1553 declspecs_add_type (loc, specs, t);
1554 c_parser_consume_token (parser);
1561 t = c_parser_enum_specifier (parser);
1562 declspecs_add_type (loc, specs, t);
1570 t = c_parser_struct_or_union_specifier (parser);
1571 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1572 declspecs_add_type (loc, specs, t);
1575 /* ??? The old parser rejected typeof after other type
1576 specifiers, but is a syntax error the best way of
1578 if (!typespec_ok || seen_type)
1582 t = c_parser_typeof_specifier (parser);
1583 declspecs_add_type (loc, specs, t);
1589 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1590 c_parser_consume_token (parser);
1595 attrs = c_parser_attributes (parser);
1596 declspecs_add_attrs (specs, attrs);
1605 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1608 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1609 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1610 enum attributes[opt] identifier
1612 The form with trailing comma is new in C99. The forms with
1613 attributes are GNU extensions. In GNU C, we accept any expression
1614 without commas in the syntax (assignment expressions, not just
1615 conditional expressions); assignment expressions will be diagnosed
1620 enumerator-list , enumerator
1623 enumeration-constant
1624 enumeration-constant = constant-expression
1627 static struct c_typespec
1628 c_parser_enum_specifier (c_parser *parser)
1630 struct c_typespec ret;
1632 tree ident = NULL_TREE;
1633 location_t enum_loc;
1634 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1635 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1636 enum_loc = c_parser_peek_token (parser)->location;
1637 c_parser_consume_token (parser);
1638 attrs = c_parser_attributes (parser);
1639 enum_loc = c_parser_peek_token (parser)->location;
1640 /* Set the location in case we create a decl now. */
1641 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1642 if (c_parser_next_token_is (parser, CPP_NAME))
1644 ident = c_parser_peek_token (parser)->value;
1645 ident_loc = c_parser_peek_token (parser)->location;
1646 enum_loc = ident_loc;
1647 c_parser_consume_token (parser);
1649 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1651 /* Parse an enum definition. */
1652 struct c_enum_contents the_enum;
1653 tree type = start_enum (enum_loc, &the_enum, ident);
1655 /* We chain the enumerators in reverse order, then put them in
1656 forward order at the end. */
1657 tree values = NULL_TREE;
1658 c_parser_consume_token (parser);
1666 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1667 location_t value_loc;
1668 if (c_parser_next_token_is_not (parser, CPP_NAME))
1670 c_parser_error (parser, "expected identifier");
1671 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1672 values = error_mark_node;
1675 token = c_parser_peek_token (parser);
1676 enum_id = token->value;
1677 /* Set the location in case we create a decl now. */
1678 c_parser_set_source_position_from_token (token);
1679 value_loc = token->location;
1680 c_parser_consume_token (parser);
1681 if (c_parser_next_token_is (parser, CPP_EQ))
1683 c_parser_consume_token (parser);
1684 value_loc = c_parser_peek_token (parser)->location;
1685 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1688 enum_value = NULL_TREE;
1689 enum_decl = build_enumerator (value_loc,
1690 &the_enum, enum_id, enum_value);
1691 TREE_CHAIN (enum_decl) = values;
1694 if (c_parser_next_token_is (parser, CPP_COMMA))
1696 comma_loc = c_parser_peek_token (parser)->location;
1698 c_parser_consume_token (parser);
1700 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1702 if (seen_comma && !flag_isoc99)
1703 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1704 c_parser_consume_token (parser);
1709 c_parser_error (parser, "expected %<,%> or %<}%>");
1710 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1711 values = error_mark_node;
1715 postfix_attrs = c_parser_attributes (parser);
1716 ret.spec = finish_enum (type, nreverse (values),
1717 chainon (attrs, postfix_attrs));
1718 ret.kind = ctsk_tagdef;
1719 ret.expr = NULL_TREE;
1720 ret.expr_const_operands = true;
1725 c_parser_error (parser, "expected %<{%>");
1726 ret.spec = error_mark_node;
1727 ret.kind = ctsk_tagref;
1728 ret.expr = NULL_TREE;
1729 ret.expr_const_operands = true;
1732 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1733 /* In ISO C, enumerated types can be referred to only if already
1735 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1738 pedwarn (enum_loc, OPT_pedantic,
1739 "ISO C forbids forward references to %<enum%> types");
1744 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1746 struct-or-union-specifier:
1747 struct-or-union attributes[opt] identifier[opt]
1748 { struct-contents } attributes[opt]
1749 struct-or-union attributes[opt] identifier
1752 struct-declaration-list
1754 struct-declaration-list:
1755 struct-declaration ;
1756 struct-declaration-list struct-declaration ;
1763 struct-declaration-list struct-declaration
1765 struct-declaration-list:
1766 struct-declaration-list ;
1769 (Note that in the syntax here, unlike that in ISO C, the semicolons
1770 are included here rather than in struct-declaration, in order to
1771 describe the syntax with extra semicolons and missing semicolon at
1776 struct-declaration-list:
1777 @defs ( class-name )
1779 (Note this does not include a trailing semicolon, but can be
1780 followed by further declarations, and gets a pedwarn-if-pedantic
1781 when followed by a semicolon.) */
1783 static struct c_typespec
1784 c_parser_struct_or_union_specifier (c_parser *parser)
1786 struct c_typespec ret;
1788 tree ident = NULL_TREE;
1789 location_t struct_loc;
1790 location_t ident_loc = UNKNOWN_LOCATION;
1791 enum tree_code code;
1792 switch (c_parser_peek_token (parser)->keyword)
1803 struct_loc = c_parser_peek_token (parser)->location;
1804 c_parser_consume_token (parser);
1805 attrs = c_parser_attributes (parser);
1807 /* Set the location in case we create a decl now. */
1808 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1810 if (c_parser_next_token_is (parser, CPP_NAME))
1812 ident = c_parser_peek_token (parser)->value;
1813 ident_loc = c_parser_peek_token (parser)->location;
1814 struct_loc = ident_loc;
1815 c_parser_consume_token (parser);
1817 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1819 /* Parse a struct or union definition. Start the scope of the
1820 tag before parsing components. */
1821 struct c_struct_parse_info *struct_info;
1822 tree type = start_struct (struct_loc, code, ident, &struct_info);
1824 /* We chain the components in reverse order, then put them in
1825 forward order at the end. Each struct-declaration may
1826 declare multiple components (comma-separated), so we must use
1827 chainon to join them, although when parsing each
1828 struct-declaration we can use TREE_CHAIN directly.
1830 The theory behind all this is that there will be more
1831 semicolon separated fields than comma separated fields, and
1832 so we'll be minimizing the number of node traversals required
1834 tree contents = NULL_TREE;
1835 c_parser_consume_token (parser);
1836 /* Handle the Objective-C @defs construct,
1837 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1838 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1841 gcc_assert (c_dialect_objc ());
1842 c_parser_consume_token (parser);
1843 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1845 if (c_parser_next_token_is (parser, CPP_NAME)
1846 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1848 name = c_parser_peek_token (parser)->value;
1849 c_parser_consume_token (parser);
1853 c_parser_error (parser, "expected class name");
1854 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1857 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1859 contents = nreverse (objc_get_class_ivars (name));
1862 /* Parse the struct-declarations and semicolons. Problems with
1863 semicolons are diagnosed here; empty structures are diagnosed
1868 /* Parse any stray semicolon. */
1869 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1871 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1872 "extra semicolon in struct or union specified");
1873 c_parser_consume_token (parser);
1876 /* Stop if at the end of the struct or union contents. */
1877 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1879 c_parser_consume_token (parser);
1882 /* Accept #pragmas at struct scope. */
1883 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1885 c_parser_pragma (parser, pragma_external);
1888 /* Parse some comma-separated declarations, but not the
1889 trailing semicolon if any. */
1890 decls = c_parser_struct_declaration (parser);
1891 contents = chainon (decls, contents);
1892 /* If no semicolon follows, either we have a parse error or
1893 are at the end of the struct or union and should
1895 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1896 c_parser_consume_token (parser);
1899 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1900 pedwarn (c_parser_peek_token (parser)->location, 0,
1901 "no semicolon at end of struct or union");
1904 c_parser_error (parser, "expected %<;%>");
1905 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1910 postfix_attrs = c_parser_attributes (parser);
1911 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
1912 chainon (attrs, postfix_attrs), struct_info);
1913 ret.kind = ctsk_tagdef;
1914 ret.expr = NULL_TREE;
1915 ret.expr_const_operands = true;
1920 c_parser_error (parser, "expected %<{%>");
1921 ret.spec = error_mark_node;
1922 ret.kind = ctsk_tagref;
1923 ret.expr = NULL_TREE;
1924 ret.expr_const_operands = true;
1927 ret = parser_xref_tag (ident_loc, code, ident);
1931 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1932 the trailing semicolon.
1935 specifier-qualifier-list struct-declarator-list
1937 specifier-qualifier-list:
1938 type-specifier specifier-qualifier-list[opt]
1939 type-qualifier specifier-qualifier-list[opt]
1940 attributes specifier-qualifier-list[opt]
1942 struct-declarator-list:
1944 struct-declarator-list , attributes[opt] struct-declarator
1947 declarator attributes[opt]
1948 declarator[opt] : constant-expression attributes[opt]
1953 __extension__ struct-declaration
1954 specifier-qualifier-list
1956 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1957 of attributes where shown is a GNU extension. In GNU C, we accept
1958 any expression without commas in the syntax (assignment
1959 expressions, not just conditional expressions); assignment
1960 expressions will be diagnosed as non-constant. */
1963 c_parser_struct_declaration (c_parser *parser)
1965 struct c_declspecs *specs;
1967 tree all_prefix_attrs;
1969 location_t decl_loc;
1970 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
1974 ext = disable_extension_diagnostics ();
1975 c_parser_consume_token (parser);
1976 decl = c_parser_struct_declaration (parser);
1977 restore_extension_diagnostics (ext);
1980 specs = build_null_declspecs ();
1981 decl_loc = c_parser_peek_token (parser)->location;
1982 c_parser_declspecs (parser, specs, false, true, true);
1985 if (!specs->declspecs_seen_p)
1987 c_parser_error (parser, "expected specifier-qualifier-list");
1990 finish_declspecs (specs);
1991 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1994 if (!specs->type_seen_p)
1996 pedwarn (decl_loc, OPT_pedantic,
1997 "ISO C forbids member declarations with no members");
1998 shadow_tag_warned (specs, pedantic);
2003 /* Support for unnamed structs or unions as members of
2004 structs or unions (which is [a] useful and [b] supports
2008 ret = grokfield (c_parser_peek_token (parser)->location,
2009 build_id_declarator (NULL_TREE), specs,
2012 decl_attributes (&ret, attrs, 0);
2016 pending_xref_error ();
2017 prefix_attrs = specs->attrs;
2018 all_prefix_attrs = prefix_attrs;
2019 specs->attrs = NULL_TREE;
2023 /* Declaring one or more declarators or un-named bit-fields. */
2024 struct c_declarator *declarator;
2026 if (c_parser_next_token_is (parser, CPP_COLON))
2027 declarator = build_id_declarator (NULL_TREE);
2029 declarator = c_parser_declarator (parser, specs->type_seen_p,
2030 C_DTR_NORMAL, &dummy);
2031 if (declarator == NULL)
2033 c_parser_skip_to_end_of_block_or_statement (parser);
2036 if (c_parser_next_token_is (parser, CPP_COLON)
2037 || c_parser_next_token_is (parser, CPP_COMMA)
2038 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2039 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2040 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2042 tree postfix_attrs = NULL_TREE;
2043 tree width = NULL_TREE;
2045 if (c_parser_next_token_is (parser, CPP_COLON))
2047 c_parser_consume_token (parser);
2048 width = c_parser_expr_no_commas (parser, NULL).value;
2050 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2051 postfix_attrs = c_parser_attributes (parser);
2052 d = grokfield (c_parser_peek_token (parser)->location,
2053 declarator, specs, width, &all_prefix_attrs);
2054 decl_attributes (&d, chainon (postfix_attrs,
2055 all_prefix_attrs), 0);
2056 TREE_CHAIN (d) = decls;
2058 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2059 all_prefix_attrs = chainon (c_parser_attributes (parser),
2062 all_prefix_attrs = prefix_attrs;
2063 if (c_parser_next_token_is (parser, CPP_COMMA))
2064 c_parser_consume_token (parser);
2065 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2066 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2068 /* Semicolon consumed in caller. */
2073 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2079 c_parser_error (parser,
2080 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2081 "%<__attribute__%>");
2088 /* Parse a typeof specifier (a GNU extension).
2091 typeof ( expression )
2092 typeof ( type-name )
2095 static struct c_typespec
2096 c_parser_typeof_specifier (c_parser *parser)
2098 struct c_typespec ret;
2099 ret.kind = ctsk_typeof;
2100 ret.spec = error_mark_node;
2101 ret.expr = NULL_TREE;
2102 ret.expr_const_operands = true;
2103 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2104 c_parser_consume_token (parser);
2105 c_inhibit_evaluation_warnings++;
2107 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2109 c_inhibit_evaluation_warnings--;
2113 if (c_parser_next_token_starts_typename (parser))
2115 struct c_type_name *type = c_parser_type_name (parser);
2116 c_inhibit_evaluation_warnings--;
2120 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2121 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2127 location_t here = c_parser_peek_token (parser)->location;
2128 struct c_expr expr = c_parser_expression (parser);
2129 c_inhibit_evaluation_warnings--;
2131 if (TREE_CODE (expr.value) == COMPONENT_REF
2132 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2133 error_at (here, "%<typeof%> applied to a bit-field");
2134 ret.spec = TREE_TYPE (expr.value);
2135 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2136 /* This is returned with the type so that when the type is
2137 evaluated, this can be evaluated. */
2139 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2140 pop_maybe_used (was_vm);
2142 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2146 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2147 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2148 be redeclared; otherwise it may not. KIND indicates which kind of
2149 declarator is wanted. Returns a valid declarator except in the
2150 case of a syntax error in which case NULL is returned. *SEEN_ID is
2151 set to true if an identifier being declared is seen; this is used
2152 to diagnose bad forms of abstract array declarators and to
2153 determine whether an identifier list is syntactically permitted.
2156 pointer[opt] direct-declarator
2160 ( attributes[opt] declarator )
2161 direct-declarator array-declarator
2162 direct-declarator ( parameter-type-list )
2163 direct-declarator ( identifier-list[opt] )
2166 * type-qualifier-list[opt]
2167 * type-qualifier-list[opt] pointer
2169 type-qualifier-list:
2172 type-qualifier-list type-qualifier
2173 type-qualifier-list attributes
2175 parameter-type-list:
2177 parameter-list , ...
2180 parameter-declaration
2181 parameter-list , parameter-declaration
2183 parameter-declaration:
2184 declaration-specifiers declarator attributes[opt]
2185 declaration-specifiers abstract-declarator[opt] attributes[opt]
2189 identifier-list , identifier
2191 abstract-declarator:
2193 pointer[opt] direct-abstract-declarator
2195 direct-abstract-declarator:
2196 ( attributes[opt] abstract-declarator )
2197 direct-abstract-declarator[opt] array-declarator
2198 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2203 direct-declarator ( parameter-forward-declarations
2204 parameter-type-list[opt] )
2206 direct-abstract-declarator:
2207 direct-abstract-declarator[opt] ( parameter-forward-declarations
2208 parameter-type-list[opt] )
2210 parameter-forward-declarations:
2212 parameter-forward-declarations parameter-list ;
2214 The uses of attributes shown above are GNU extensions.
2216 Some forms of array declarator are not included in C99 in the
2217 syntax for abstract declarators; these are disallowed elsewhere.
2218 This may be a defect (DR#289).
2220 This function also accepts an omitted abstract declarator as being
2221 an abstract declarator, although not part of the formal syntax. */
2223 static struct c_declarator *
2224 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2227 /* Parse any initial pointer part. */
2228 if (c_parser_next_token_is (parser, CPP_MULT))
2230 struct c_declspecs *quals_attrs = build_null_declspecs ();
2231 struct c_declarator *inner;
2232 c_parser_consume_token (parser);
2233 c_parser_declspecs (parser, quals_attrs, false, false, true);
2234 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2238 return make_pointer_declarator (quals_attrs, inner);
2240 /* Now we have a direct declarator, direct abstract declarator or
2241 nothing (which counts as a direct abstract declarator here). */
2242 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2245 /* Parse a direct declarator or direct abstract declarator; arguments
2246 as c_parser_declarator. */
2248 static struct c_declarator *
2249 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2252 /* The direct declarator must start with an identifier (possibly
2253 omitted) or a parenthesized declarator (possibly abstract). In
2254 an ordinary declarator, initial parentheses must start a
2255 parenthesized declarator. In an abstract declarator or parameter
2256 declarator, they could start a parenthesized declarator or a
2257 parameter list. To tell which, the open parenthesis and any
2258 following attributes must be read. If a declaration specifier
2259 follows, then it is a parameter list; if the specifier is a
2260 typedef name, there might be an ambiguity about redeclaring it,
2261 which is resolved in the direction of treating it as a typedef
2262 name. If a close parenthesis follows, it is also an empty
2263 parameter list, as the syntax does not permit empty abstract
2264 declarators. Otherwise, it is a parenthesized declarator (in
2265 which case the analysis may be repeated inside it, recursively).
2267 ??? There is an ambiguity in a parameter declaration "int
2268 (__attribute__((foo)) x)", where x is not a typedef name: it
2269 could be an abstract declarator for a function, or declare x with
2270 parentheses. The proper resolution of this ambiguity needs
2271 documenting. At present we follow an accident of the old
2272 parser's implementation, whereby the first parameter must have
2273 some declaration specifiers other than just attributes. Thus as
2274 a parameter declaration it is treated as a parenthesized
2275 parameter named x, and as an abstract declarator it is
2278 ??? Also following the old parser, attributes inside an empty
2279 parameter list are ignored, making it a list not yielding a
2280 prototype, rather than giving an error or making it have one
2281 parameter with implicit type int.
2283 ??? Also following the old parser, typedef names may be
2284 redeclared in declarators, but not Objective-C class names. */
2286 if (kind != C_DTR_ABSTRACT
2287 && c_parser_next_token_is (parser, CPP_NAME)
2289 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2290 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2292 struct c_declarator *inner
2293 = build_id_declarator (c_parser_peek_token (parser)->value);
2295 inner->id_loc = c_parser_peek_token (parser)->location;
2296 c_parser_consume_token (parser);
2297 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2300 if (kind != C_DTR_NORMAL
2301 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2303 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2304 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2307 /* Either we are at the end of an abstract declarator, or we have
2310 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2313 struct c_declarator *inner;
2314 c_parser_consume_token (parser);
2315 attrs = c_parser_attributes (parser);
2316 if (kind != C_DTR_NORMAL
2317 && (c_parser_next_token_starts_declspecs (parser)
2318 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2320 struct c_arg_info *args
2321 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2328 = build_function_declarator (args,
2329 build_id_declarator (NULL_TREE));
2330 return c_parser_direct_declarator_inner (parser, *seen_id,
2334 /* A parenthesized declarator. */
2335 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2336 if (inner != NULL && attrs != NULL)
2337 inner = build_attrs_declarator (attrs, inner);
2338 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2340 c_parser_consume_token (parser);
2344 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2348 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2355 if (kind == C_DTR_NORMAL)
2357 c_parser_error (parser, "expected identifier or %<(%>");
2361 return build_id_declarator (NULL_TREE);
2365 /* Parse part of a direct declarator or direct abstract declarator,
2366 given that some (in INNER) has already been parsed; ID_PRESENT is
2367 true if an identifier is present, false for an abstract
2370 static struct c_declarator *
2371 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2372 struct c_declarator *inner)
2374 /* Parse a sequence of array declarators and parameter lists. */
2375 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2377 location_t brace_loc = c_parser_peek_token (parser)->location;
2378 struct c_declarator *declarator;
2379 struct c_declspecs *quals_attrs = build_null_declspecs ();
2383 c_parser_consume_token (parser);
2384 c_parser_declspecs (parser, quals_attrs, false, false, true);
2385 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2387 c_parser_consume_token (parser);
2388 if (static_seen && !quals_attrs->declspecs_seen_p)
2389 c_parser_declspecs (parser, quals_attrs, false, false, true);
2390 if (!quals_attrs->declspecs_seen_p)
2392 /* If "static" is present, there must be an array dimension.
2393 Otherwise, there may be a dimension, "*", or no
2398 dimen = c_parser_expr_no_commas (parser, NULL).value;
2402 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2407 else if (c_parser_next_token_is (parser, CPP_MULT))
2409 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2413 c_parser_consume_token (parser);
2418 dimen = c_parser_expr_no_commas (parser, NULL).value;
2424 dimen = c_parser_expr_no_commas (parser, NULL).value;
2427 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2428 c_parser_consume_token (parser);
2431 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2435 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2436 static_seen, star_seen);
2437 if (declarator == NULL)
2439 inner = set_array_declarator_inner (declarator, inner);
2440 return c_parser_direct_declarator_inner (parser, id_present, inner);
2442 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2445 struct c_arg_info *args;
2446 c_parser_consume_token (parser);
2447 attrs = c_parser_attributes (parser);
2448 args = c_parser_parms_declarator (parser, id_present, attrs);
2453 inner = build_function_declarator (args, inner);
2454 return c_parser_direct_declarator_inner (parser, id_present, inner);
2460 /* Parse a parameter list or identifier list, including the closing
2461 parenthesis but not the opening one. ATTRS are the attributes at
2462 the start of the list. ID_LIST_OK is true if an identifier list is
2463 acceptable; such a list must not have attributes at the start. */
2465 static struct c_arg_info *
2466 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2469 declare_parm_level ();
2470 /* If the list starts with an identifier, it is an identifier list.
2471 Otherwise, it is either a prototype list or an empty list. */
2474 && c_parser_next_token_is (parser, CPP_NAME)
2475 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2477 tree list = NULL_TREE, *nextp = &list;
2478 while (c_parser_next_token_is (parser, CPP_NAME)
2479 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2481 *nextp = build_tree_list (NULL_TREE,
2482 c_parser_peek_token (parser)->value);
2483 nextp = & TREE_CHAIN (*nextp);
2484 c_parser_consume_token (parser);
2485 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2487 c_parser_consume_token (parser);
2488 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2490 c_parser_error (parser, "expected identifier");
2494 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2496 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2501 ret->pending_sizes = 0;
2502 ret->had_vla_unspec = 0;
2503 c_parser_consume_token (parser);
2509 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2517 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2523 /* Parse a parameter list (possibly empty), including the closing
2524 parenthesis but not the opening one. ATTRS are the attributes at
2525 the start of the list. */
2527 static struct c_arg_info *
2528 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2530 bool good_parm = false;
2531 /* ??? Following the old parser, forward parameter declarations may
2532 use abstract declarators, and if no real parameter declarations
2533 follow the forward declarations then this is not diagnosed. Also
2534 note as above that attributes are ignored as the only contents of
2535 the parentheses, or as the only contents after forward
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);
2549 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2551 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2555 ret->pending_sizes = 0;
2556 ret->had_vla_unspec = 0;
2557 /* Suppress -Wold-style-definition for this case. */
2558 ret->types = error_mark_node;
2559 error_at (c_parser_peek_token (parser)->location,
2560 "ISO C requires a named argument before %<...%>");
2561 c_parser_consume_token (parser);
2562 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2564 c_parser_consume_token (parser);
2569 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2574 /* Nonempty list of parameters, either terminated with semicolon
2575 (forward declarations; recurse) or with close parenthesis (normal
2576 function) or with ", ... )" (variadic function). */
2579 /* Parse a parameter. */
2580 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2585 push_parm_decl (parm);
2587 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2590 c_parser_consume_token (parser);
2591 mark_forward_parm_decls ();
2592 new_attrs = c_parser_attributes (parser);
2593 return c_parser_parms_list_declarator (parser, new_attrs);
2595 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2597 c_parser_consume_token (parser);
2599 return get_parm_info (false);
2602 struct c_arg_info *ret
2603 = XOBNEW (&parser_obstack, struct c_arg_info);
2608 ret->pending_sizes = 0;
2609 ret->had_vla_unspec = 0;
2613 if (!c_parser_require (parser, CPP_COMMA,
2614 "expected %<;%>, %<,%> or %<)%>"))
2616 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2617 get_pending_sizes ();
2620 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2622 c_parser_consume_token (parser);
2623 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2625 c_parser_consume_token (parser);
2627 return get_parm_info (true);
2630 struct c_arg_info *ret
2631 = XOBNEW (&parser_obstack, struct c_arg_info);
2636 ret->pending_sizes = 0;
2637 ret->had_vla_unspec = 0;
2643 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2645 get_pending_sizes ();
2652 /* Parse a parameter declaration. ATTRS are the attributes at the
2653 start of the declaration if it is the first parameter. */
2655 static struct c_parm *
2656 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2658 struct c_declspecs *specs;
2659 struct c_declarator *declarator;
2661 tree postfix_attrs = NULL_TREE;
2663 if (!c_parser_next_token_starts_declspecs (parser))
2665 /* ??? In some Objective-C cases '...' isn't applicable so there
2666 should be a different message. */
2667 c_parser_error (parser,
2668 "expected declaration specifiers or %<...%>");
2669 c_parser_skip_to_end_of_parameter (parser);
2672 specs = build_null_declspecs ();
2675 declspecs_add_attrs (specs, attrs);
2678 c_parser_declspecs (parser, specs, true, true, true);
2679 finish_declspecs (specs);
2680 pending_xref_error ();
2681 prefix_attrs = specs->attrs;
2682 specs->attrs = NULL_TREE;
2683 declarator = c_parser_declarator (parser, specs->type_seen_p,
2684 C_DTR_PARM, &dummy);
2685 if (declarator == NULL)
2687 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2690 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2691 postfix_attrs = c_parser_attributes (parser);
2692 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2696 /* Parse a string literal in an asm expression. It should not be
2697 translated, and wide string literals are an error although
2698 permitted by the syntax. This is a GNU extension.
2703 ??? At present, following the old parser, the caller needs to have
2704 set lex_untranslated_string to 1. It would be better to follow the
2705 C++ parser rather than using this kludge. */
2708 c_parser_asm_string_literal (c_parser *parser)
2711 if (c_parser_next_token_is (parser, CPP_STRING))
2713 str = c_parser_peek_token (parser)->value;
2714 c_parser_consume_token (parser);
2716 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2718 error_at (c_parser_peek_token (parser)->location,
2719 "wide string literal in %<asm%>");
2720 str = build_string (1, "");
2721 c_parser_consume_token (parser);
2725 c_parser_error (parser, "expected string literal");
2731 /* Parse a simple asm expression. This is used in restricted
2732 contexts, where a full expression with inputs and outputs does not
2733 make sense. This is a GNU extension.
2736 asm ( asm-string-literal )
2740 c_parser_simple_asm_expr (c_parser *parser)
2743 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2744 /* ??? Follow the C++ parser rather than using the
2745 lex_untranslated_string kludge. */
2746 parser->lex_untranslated_string = true;
2747 c_parser_consume_token (parser);
2748 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2750 parser->lex_untranslated_string = false;
2753 str = c_parser_asm_string_literal (parser);
2754 parser->lex_untranslated_string = false;
2755 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2757 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2763 /* Parse (possibly empty) attributes. This is a GNU extension.
2767 attributes attribute
2770 __attribute__ ( ( attribute-list ) )
2774 attribute_list , attrib
2779 any-word ( identifier )
2780 any-word ( identifier , nonempty-expr-list )
2781 any-word ( expr-list )
2783 where the "identifier" must not be declared as a type, and
2784 "any-word" may be any identifier (including one declared as a
2785 type), a reserved word storage class specifier, type specifier or
2786 type qualifier. ??? This still leaves out most reserved keywords
2787 (following the old parser), shouldn't we include them, and why not
2788 allow identifiers declared as types to start the arguments? */
2791 c_parser_attributes (c_parser *parser)
2793 tree attrs = NULL_TREE;
2794 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2796 /* ??? Follow the C++ parser rather than using the
2797 lex_untranslated_string kludge. */
2798 parser->lex_untranslated_string = true;
2799 c_parser_consume_token (parser);
2800 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2802 parser->lex_untranslated_string = false;
2805 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2807 parser->lex_untranslated_string = false;
2808 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2811 /* Parse the attribute list. */
2812 while (c_parser_next_token_is (parser, CPP_COMMA)
2813 || c_parser_next_token_is (parser, CPP_NAME)
2814 || c_parser_next_token_is (parser, CPP_KEYWORD))
2816 tree attr, attr_name, attr_args;
2817 VEC(tree,gc) *expr_list;
2818 if (c_parser_next_token_is (parser, CPP_COMMA))
2820 c_parser_consume_token (parser);
2823 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2825 /* ??? See comment above about what keywords are
2828 switch (c_parser_peek_token (parser)->keyword)
2865 /* Accept __attribute__((__const)) as __attribute__((const))
2868 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2871 attr_name = c_parser_peek_token (parser)->value;
2872 c_parser_consume_token (parser);
2873 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2875 attr = build_tree_list (attr_name, NULL_TREE);
2876 attrs = chainon (attrs, attr);
2879 c_parser_consume_token (parser);
2880 /* Parse the attribute contents. If they start with an
2881 identifier which is followed by a comma or close
2882 parenthesis, then the arguments start with that
2883 identifier; otherwise they are an expression list. */
2884 if (c_parser_next_token_is (parser, CPP_NAME)
2885 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2886 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2887 || (c_parser_peek_2nd_token (parser)->type
2888 == CPP_CLOSE_PAREN)))
2890 tree arg1 = c_parser_peek_token (parser)->value;
2891 c_parser_consume_token (parser);
2892 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2893 attr_args = build_tree_list (NULL_TREE, arg1);
2897 c_parser_consume_token (parser);
2898 expr_list = c_parser_expr_list (parser, false, true, NULL);
2899 tree_list = build_tree_list_vec (expr_list);
2900 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
2901 release_tree_vector (expr_list);
2906 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2907 attr_args = NULL_TREE;
2910 expr_list = c_parser_expr_list (parser, false, true, NULL);
2911 attr_args = build_tree_list_vec (expr_list);
2912 release_tree_vector (expr_list);
2915 attr = build_tree_list (attr_name, attr_args);
2916 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2917 c_parser_consume_token (parser);
2920 parser->lex_untranslated_string = false;
2921 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2925 attrs = chainon (attrs, attr);
2927 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2928 c_parser_consume_token (parser);
2931 parser->lex_untranslated_string = false;
2932 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2936 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2937 c_parser_consume_token (parser);
2940 parser->lex_untranslated_string = false;
2941 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2945 parser->lex_untranslated_string = false;
2950 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2953 specifier-qualifier-list abstract-declarator[opt]
2956 static struct c_type_name *
2957 c_parser_type_name (c_parser *parser)
2959 struct c_declspecs *specs = build_null_declspecs ();
2960 struct c_declarator *declarator;
2961 struct c_type_name *ret;
2963 c_parser_declspecs (parser, specs, false, true, true);
2964 if (!specs->declspecs_seen_p)
2966 c_parser_error (parser, "expected specifier-qualifier-list");
2969 pending_xref_error ();
2970 finish_declspecs (specs);
2971 declarator = c_parser_declarator (parser, specs->type_seen_p,
2972 C_DTR_ABSTRACT, &dummy);
2973 if (declarator == NULL)
2975 ret = XOBNEW (&parser_obstack, struct c_type_name);
2977 ret->declarator = declarator;
2981 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2984 assignment-expression
2985 { initializer-list }
2986 { initializer-list , }
2989 designation[opt] initializer
2990 initializer-list , designation[opt] initializer
2997 designator-list designator
3004 [ constant-expression ]
3016 [ constant-expression ... constant-expression ]
3018 Any expression without commas is accepted in the syntax for the
3019 constant-expressions, with non-constant expressions rejected later.
3021 This function is only used for top-level initializers; for nested
3022 ones, see c_parser_initval. */
3024 static struct c_expr
3025 c_parser_initializer (c_parser *parser)
3027 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3028 return c_parser_braced_init (parser, NULL_TREE, false);
3032 location_t loc = c_parser_peek_token (parser)->location;
3033 ret = c_parser_expr_no_commas (parser, NULL);
3034 if (TREE_CODE (ret.value) != STRING_CST
3035 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3036 ret = default_function_array_conversion (loc, ret);
3041 /* Parse a braced initializer list. TYPE is the type specified for a
3042 compound literal, and NULL_TREE for other initializers and for
3043 nested braced lists. NESTED_P is true for nested braced lists,
3044 false for the list of a compound literal or the list that is the
3045 top-level initializer in a declaration. */
3047 static struct c_expr
3048 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3050 location_t brace_loc = c_parser_peek_token (parser)->location;
3051 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3052 c_parser_consume_token (parser);
3054 push_init_level (0);
3056 really_start_incremental_init (type);
3057 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3059 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3063 /* Parse a non-empty initializer list, possibly with a trailing
3067 c_parser_initelt (parser);
3070 if (c_parser_next_token_is (parser, CPP_COMMA))
3071 c_parser_consume_token (parser);
3074 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3078 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3081 ret.value = error_mark_node;
3082 ret.original_code = ERROR_MARK;
3083 ret.original_type = NULL;
3084 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3088 c_parser_consume_token (parser);
3089 return pop_init_level (0);
3092 /* Parse a nested initializer, including designators. */
3095 c_parser_initelt (c_parser *parser)
3097 /* Parse any designator or designator list. A single array
3098 designator may have the subsequent "=" omitted in GNU C, but a
3099 longer list or a structure member designator may not. */
3100 if (c_parser_next_token_is (parser, CPP_NAME)
3101 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3103 /* Old-style structure member designator. */
3104 set_init_label (c_parser_peek_token (parser)->value);
3105 /* Use the colon as the error location. */
3106 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3107 "obsolete use of designated initializer with %<:%>");
3108 c_parser_consume_token (parser);
3109 c_parser_consume_token (parser);
3113 /* des_seen is 0 if there have been no designators, 1 if there
3114 has been a single array designator and 2 otherwise. */
3116 /* Location of a designator. */
3117 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3118 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3119 || c_parser_next_token_is (parser, CPP_DOT))
3121 int des_prev = des_seen;
3123 des_loc = c_parser_peek_token (parser)->location;
3126 if (c_parser_next_token_is (parser, CPP_DOT))
3129 c_parser_consume_token (parser);
3130 if (c_parser_next_token_is (parser, CPP_NAME))
3132 set_init_label (c_parser_peek_token (parser)->value);
3133 c_parser_consume_token (parser);
3138 init.value = error_mark_node;
3139 init.original_code = ERROR_MARK;
3140 init.original_type = NULL;
3141 c_parser_error (parser, "expected identifier");
3142 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3143 process_init_element (init, false);
3150 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3151 /* ??? Following the old parser, [ objc-receiver
3152 objc-message-args ] is accepted as an initializer,
3153 being distinguished from a designator by what follows
3154 the first assignment expression inside the square
3155 brackets, but after a first array designator a
3156 subsequent square bracket is for Objective-C taken to
3157 start an expression, using the obsolete form of
3158 designated initializer without '=', rather than
3159 possibly being a second level of designation: in LALR
3160 terms, the '[' is shifted rather than reducing
3161 designator to designator-list. */
3162 if (des_prev == 1 && c_dialect_objc ())
3164 des_seen = des_prev;
3167 if (des_prev == 0 && c_dialect_objc ())
3169 /* This might be an array designator or an
3170 Objective-C message expression. If the former,
3171 continue parsing here; if the latter, parse the
3172 remainder of the initializer given the starting
3173 primary-expression. ??? It might make sense to
3174 distinguish when des_prev == 1 as well; see
3175 previous comment. */
3177 struct c_expr mexpr;
3178 c_parser_consume_token (parser);
3179 if (c_parser_peek_token (parser)->type == CPP_NAME
3180 && ((c_parser_peek_token (parser)->id_kind
3182 || (c_parser_peek_token (parser)->id_kind
3183 == C_ID_CLASSNAME)))
3185 /* Type name receiver. */
3186 tree id = c_parser_peek_token (parser)->value;
3187 c_parser_consume_token (parser);
3188 rec = objc_get_class_reference (id);
3189 goto parse_message_args;
3191 first = c_parser_expr_no_commas (parser, NULL).value;
3192 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3193 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3194 goto array_desig_after_first;
3195 /* Expression receiver. So far only one part
3196 without commas has been parsed; there might be
3197 more of the expression. */
3199 while (c_parser_next_token_is (parser, CPP_COMMA))
3202 location_t comma_loc, exp_loc;
3203 comma_loc = c_parser_peek_token (parser)->location;
3204 c_parser_consume_token (parser);
3205 exp_loc = c_parser_peek_token (parser)->location;
3206 next = c_parser_expr_no_commas (parser, NULL);
3207 next = default_function_array_conversion (exp_loc, next);
3208 rec = build_compound_expr (comma_loc, rec, next.value);
3211 /* Now parse the objc-message-args. */
3212 args = c_parser_objc_message_args (parser);
3213 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3216 = objc_build_message_expr (build_tree_list (rec, args));
3217 mexpr.original_code = ERROR_MARK;
3218 mexpr.original_type = NULL;
3219 /* Now parse and process the remainder of the
3220 initializer, starting with this message
3221 expression as a primary-expression. */
3222 c_parser_initval (parser, &mexpr);
3225 c_parser_consume_token (parser);
3226 first = c_parser_expr_no_commas (parser, NULL).value;
3227 array_desig_after_first:
3228 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3230 ellipsis_loc = c_parser_peek_token (parser)->location;
3231 c_parser_consume_token (parser);
3232 second = c_parser_expr_no_commas (parser, NULL).value;
3236 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3238 c_parser_consume_token (parser);
3239 set_init_index (first, second);
3241 pedwarn (ellipsis_loc, OPT_pedantic,
3242 "ISO C forbids specifying range of elements to initialize");
3245 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3251 if (c_parser_next_token_is (parser, CPP_EQ))
3254 pedwarn (des_loc, OPT_pedantic,
3255 "ISO C90 forbids specifying subobject to initialize");
3256 c_parser_consume_token (parser);
3261 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3262 "obsolete use of designated initializer without %<=%>");
3266 init.value = error_mark_node;
3267 init.original_code = ERROR_MARK;
3268 init.original_type = NULL;
3269 c_parser_error (parser, "expected %<=%>");
3270 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3271 process_init_element (init, false);
3277 c_parser_initval (parser, NULL);
3280 /* Parse a nested initializer; as c_parser_initializer but parses
3281 initializers within braced lists, after any designators have been
3282 applied. If AFTER is not NULL then it is an Objective-C message
3283 expression which is the primary-expression starting the
3287 c_parser_initval (c_parser *parser, struct c_expr *after)
3290 gcc_assert (!after || c_dialect_objc ());
3291 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3292 init = c_parser_braced_init (parser, NULL_TREE, true);
3295 location_t loc = c_parser_peek_token (parser)->location;
3296 init = c_parser_expr_no_commas (parser, after);
3297 if (init.value != NULL_TREE
3298 && TREE_CODE (init.value) != STRING_CST
3299 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3300 init = default_function_array_conversion (loc, init);
3302 process_init_element (init, false);
3305 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3309 { block-item-list[opt] }
3310 { label-declarations block-item-list }
3314 block-item-list block-item
3326 { label-declarations block-item-list }
3329 __extension__ nested-declaration
3330 nested-function-definition
3334 label-declarations label-declaration
3337 __label__ identifier-list ;
3339 Allowing the mixing of declarations and code is new in C99. The
3340 GNU syntax also permits (not shown above) labels at the end of
3341 compound statements, which yield an error. We don't allow labels
3342 on declarations; this might seem like a natural extension, but
3343 there would be a conflict between attributes on the label and
3344 prefix attributes on the declaration. ??? The syntax follows the
3345 old parser in requiring something after label declarations.
3346 Although they are erroneous if the labels declared aren't defined,
3347 is it useful for the syntax to be this way?
3359 c_parser_compound_statement (c_parser *parser)
3362 location_t brace_loc;
3363 brace_loc = c_parser_peek_token (parser)->location;
3364 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3366 /* Ensure a scope is entered and left anyway to avoid confusion
3367 if we have just prepared to enter a function body. */
3368 stmt = c_begin_compound_stmt (true);
3369 c_end_compound_stmt (brace_loc, stmt, true);
3370 return error_mark_node;
3372 stmt = c_begin_compound_stmt (true);
3373 c_parser_compound_statement_nostart (parser);
3374 return c_end_compound_stmt (brace_loc, stmt, true);
3377 /* Parse a compound statement except for the opening brace. This is
3378 used for parsing both compound statements and statement expressions
3379 (which follow different paths to handling the opening). */
3382 c_parser_compound_statement_nostart (c_parser *parser)
3384 bool last_stmt = false;
3385 bool last_label = false;
3386 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3387 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3388 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3390 c_parser_consume_token (parser);
3393 mark_valid_location_for_stdc_pragma (true);
3394 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3396 /* Read zero or more forward-declarations for labels that nested
3397 functions can jump to. */
3398 mark_valid_location_for_stdc_pragma (false);
3399 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3401 label_loc = c_parser_peek_token (parser)->location;
3402 c_parser_consume_token (parser);
3403 /* Any identifiers, including those declared as type names,
3408 if (c_parser_next_token_is_not (parser, CPP_NAME))
3410 c_parser_error (parser, "expected identifier");
3414 = declare_label (c_parser_peek_token (parser)->value);
3415 C_DECLARED_LABEL_FLAG (label) = 1;
3416 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3417 c_parser_consume_token (parser);
3418 if (c_parser_next_token_is (parser, CPP_COMMA))
3419 c_parser_consume_token (parser);
3423 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3425 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3427 /* We must now have at least one statement, label or declaration. */
3428 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3430 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3431 c_parser_error (parser, "expected declaration or statement");
3432 c_parser_consume_token (parser);
3435 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3437 location_t loc = c_parser_peek_token (parser)->location;
3438 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3439 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3440 || (c_parser_next_token_is (parser, CPP_NAME)
3441 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3443 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3444 label_loc = c_parser_peek_2nd_token (parser)->location;
3446 label_loc = c_parser_peek_token (parser)->location;
3449 mark_valid_location_for_stdc_pragma (false);
3450 c_parser_label (parser);
3452 else if (!last_label
3453 && c_parser_next_token_starts_declspecs (parser))
3456 mark_valid_location_for_stdc_pragma (false);
3457 c_parser_declaration_or_fndef (parser, true, true, true, true);
3460 (pedantic && !flag_isoc99)
3462 : OPT_Wdeclaration_after_statement,
3463 "ISO C90 forbids mixed declarations and code");
3466 else if (!last_label
3467 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3469 /* __extension__ can start a declaration, but is also an
3470 unary operator that can start an expression. Consume all
3471 but the last of a possible series of __extension__ to
3473 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3474 && (c_parser_peek_2nd_token (parser)->keyword
3476 c_parser_consume_token (parser);
3477 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3480 ext = disable_extension_diagnostics ();
3481 c_parser_consume_token (parser);
3483 mark_valid_location_for_stdc_pragma (false);
3484 c_parser_declaration_or_fndef (parser, true, true, true, true);
3485 /* Following the old parser, __extension__ does not
3486 disable this diagnostic. */
3487 restore_extension_diagnostics (ext);
3489 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3491 : OPT_Wdeclaration_after_statement,
3492 "ISO C90 forbids mixed declarations and code");
3498 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3500 /* External pragmas, and some omp pragmas, are not associated
3501 with regular c code, and so are not to be considered statements
3502 syntactically. This ensures that the user doesn't put them
3503 places that would turn into syntax errors if the directive
3505 if (c_parser_pragma (parser, pragma_compound))
3506 last_label = false, last_stmt = true;
3508 else if (c_parser_next_token_is (parser, CPP_EOF))
3510 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3511 c_parser_error (parser, "expected declaration or statement");
3514 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3516 if (parser->in_if_block)
3518 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3519 error_at (loc, """expected %<}%> before %<else%>");
3524 error_at (loc, "%<else%> without a previous %<if%>");
3525 c_parser_consume_token (parser);
3534 mark_valid_location_for_stdc_pragma (false);
3535 c_parser_statement_after_labels (parser);
3538 parser->error = false;
3541 error_at (label_loc, "label at end of compound statement");
3542 c_parser_consume_token (parser);
3543 /* Restore the value we started with. */
3544 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3547 /* Parse a label (C90 6.6.1, C99 6.8.1).
3550 identifier : attributes[opt]
3551 case constant-expression :
3557 case constant-expression ... constant-expression :
3559 The use of attributes on labels is a GNU extension. The syntax in
3560 GNU C accepts any expressions without commas, non-constant
3561 expressions being rejected later. */
3564 c_parser_label (c_parser *parser)
3566 location_t loc1 = c_parser_peek_token (parser)->location;
3567 tree label = NULL_TREE;
3568 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3571 c_parser_consume_token (parser);
3572 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3573 if (c_parser_next_token_is (parser, CPP_COLON))
3575 c_parser_consume_token (parser);
3576 label = do_case (loc1, exp1, NULL_TREE);
3578 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3580 c_parser_consume_token (parser);
3581 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3582 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3583 label = do_case (loc1, exp1, exp2);
3586 c_parser_error (parser, "expected %<:%> or %<...%>");
3588 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3590 c_parser_consume_token (parser);
3591 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3592 label = do_case (loc1, NULL_TREE, NULL_TREE);
3596 tree name = c_parser_peek_token (parser)->value;
3599 location_t loc2 = c_parser_peek_token (parser)->location;
3600 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3601 c_parser_consume_token (parser);
3602 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3603 c_parser_consume_token (parser);
3604 attrs = c_parser_attributes (parser);
3605 tlab = define_label (loc2, name);
3608 decl_attributes (&tlab, attrs, 0);
3609 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3614 if (c_parser_next_token_starts_declspecs (parser)
3615 && !(c_parser_next_token_is (parser, CPP_NAME)
3616 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3618 error_at (c_parser_peek_token (parser)->location,
3619 "a label can only be part of a statement and "
3620 "a declaration is not a statement");
3621 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3622 /*nested*/ true, /*empty_ok*/ false,
3623 /*start_attr_ok*/ true);
3628 /* Parse a statement (C90 6.6, C99 6.8).
3633 expression-statement
3641 expression-statement:
3644 selection-statement:
3648 iteration-statement:
3657 return expression[opt] ;
3670 objc-throw-statement
3671 objc-try-catch-statement
3672 objc-synchronized-statement
3674 objc-throw-statement:
3688 parallel-for-construct
3689 parallel-sections-construct
3696 parallel-directive structured-block
3699 for-directive iteration-statement
3702 sections-directive section-scope
3705 single-directive structured-block
3707 parallel-for-construct:
3708 parallel-for-directive iteration-statement
3710 parallel-sections-construct:
3711 parallel-sections-directive section-scope
3714 master-directive structured-block
3717 critical-directive structured-block
3720 atomic-directive expression-statement
3723 ordered-directive structured-block */
3726 c_parser_statement (c_parser *parser)
3728 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3729 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3730 || (c_parser_next_token_is (parser, CPP_NAME)
3731 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3732 c_parser_label (parser);
3733 c_parser_statement_after_labels (parser);
3736 /* Parse a statement, other than a labeled statement. */
3739 c_parser_statement_after_labels (c_parser *parser)
3741 location_t loc = c_parser_peek_token (parser)->location;
3742 tree stmt = NULL_TREE;
3743 bool in_if_block = parser->in_if_block;
3744 parser->in_if_block = false;
3745 switch (c_parser_peek_token (parser)->type)
3747 case CPP_OPEN_BRACE:
3748 add_stmt (c_parser_compound_statement (parser));
3751 switch (c_parser_peek_token (parser)->keyword)
3754 c_parser_if_statement (parser);
3757 c_parser_switch_statement (parser);
3760 c_parser_while_statement (parser);
3763 c_parser_do_statement (parser);
3766 c_parser_for_statement (parser);
3769 c_parser_consume_token (parser);
3770 if (c_parser_next_token_is (parser, CPP_NAME))
3772 stmt = c_finish_goto_label (loc,
3773 c_parser_peek_token (parser)->value);
3774 c_parser_consume_token (parser);
3776 else if (c_parser_next_token_is (parser, CPP_MULT))
3778 c_parser_consume_token (parser);
3779 stmt = c_finish_goto_ptr (loc,
3780 c_parser_expression (parser).value);
3783 c_parser_error (parser, "expected identifier or %<*%>");
3784 goto expect_semicolon;
3786 c_parser_consume_token (parser);
3787 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
3788 goto expect_semicolon;
3790 c_parser_consume_token (parser);
3791 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
3792 goto expect_semicolon;
3794 c_parser_consume_token (parser);
3795 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3797 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
3798 c_parser_consume_token (parser);
3802 struct c_expr expr = c_parser_expression_conv (parser);
3803 stmt = c_finish_return (loc, expr.value, expr.original_type);
3804 goto expect_semicolon;
3808 stmt = c_parser_asm_statement (parser);
3811 gcc_assert (c_dialect_objc ());
3812 c_parser_consume_token (parser);
3813 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3815 stmt = objc_build_throw_stmt (loc, NULL_TREE);
3816 c_parser_consume_token (parser);
3820 tree expr = c_parser_expression (parser).value;
3821 expr = c_fully_fold (expr, false, NULL);
3822 stmt = objc_build_throw_stmt (loc, expr);
3823 goto expect_semicolon;
3827 gcc_assert (c_dialect_objc ());
3828 c_parser_objc_try_catch_statement (parser);
3830 case RID_AT_SYNCHRONIZED:
3831 gcc_assert (c_dialect_objc ());
3832 c_parser_objc_synchronized_statement (parser);
3839 c_parser_consume_token (parser);
3841 case CPP_CLOSE_PAREN:
3842 case CPP_CLOSE_SQUARE:
3843 /* Avoid infinite loop in error recovery:
3844 c_parser_skip_until_found stops at a closing nesting
3845 delimiter without consuming it, but here we need to consume
3846 it to proceed further. */
3847 c_parser_error (parser, "expected statement");
3848 c_parser_consume_token (parser);
3851 c_parser_pragma (parser, pragma_stmt);
3855 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
3857 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3860 /* Two cases cannot and do not have line numbers associated: If stmt
3861 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3862 cannot hold line numbers. But that's OK because the statement
3863 will either be changed to a MODIFY_EXPR during gimplification of
3864 the statement expr, or discarded. If stmt was compound, but
3865 without new variables, we will have skipped the creation of a
3866 BIND and will have a bare STATEMENT_LIST. But that's OK because
3867 (recursively) all of the component statements should already have
3868 line numbers assigned. ??? Can we discard no-op statements
3870 if (CAN_HAVE_LOCATION_P (stmt)
3871 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
3872 SET_EXPR_LOCATION (stmt, loc);
3874 parser->in_if_block = in_if_block;
3877 /* Parse the condition from an if, do, while or for statements. */
3880 c_parser_condition (c_parser *parser)
3882 location_t loc = c_parser_peek_token (parser)->location;
3884 cond = c_parser_expression_conv (parser).value;
3885 cond = c_objc_common_truthvalue_conversion (loc, cond);
3886 cond = c_fully_fold (cond, false, NULL);
3887 if (warn_sequence_point)
3888 verify_sequence_points (cond);
3892 /* Parse a parenthesized condition from an if, do or while statement.
3898 c_parser_paren_condition (c_parser *parser)
3901 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3902 return error_mark_node;
3903 cond = c_parser_condition (parser);
3904 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3908 /* Parse a statement which is a block in C99. */
3911 c_parser_c99_block_statement (c_parser *parser)
3913 tree block = c_begin_compound_stmt (flag_isoc99);
3914 location_t loc = c_parser_peek_token (parser)->location;
3915 c_parser_statement (parser);
3916 return c_end_compound_stmt (loc, block, flag_isoc99);
3919 /* Parse the body of an if statement. This is just parsing a
3920 statement but (a) it is a block in C99, (b) we track whether the
3921 body is an if statement for the sake of -Wparentheses warnings, (c)
3922 we handle an empty body specially for the sake of -Wempty-body
3923 warnings, and (d) we call parser_compound_statement directly
3924 because c_parser_statement_after_labels resets
3925 parser->in_if_block. */
3928 c_parser_if_body (c_parser *parser, bool *if_p)
3930 tree block = c_begin_compound_stmt (flag_isoc99);
3931 location_t body_loc = c_parser_peek_token (parser)->location;
3932 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3933 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3934 || (c_parser_next_token_is (parser, CPP_NAME)
3935 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3936 c_parser_label (parser);
3937 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3938 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3940 location_t loc = c_parser_peek_token (parser)->location;
3941 add_stmt (build_empty_stmt (loc));
3942 c_parser_consume_token (parser);
3943 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3944 warning_at (loc, OPT_Wempty_body,
3945 "suggest braces around empty body in an %<if%> statement");
3947 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3948 add_stmt (c_parser_compound_statement (parser));
3950 c_parser_statement_after_labels (parser);
3951 return c_end_compound_stmt (body_loc, block, flag_isoc99);
3954 /* Parse the else body of an if statement. This is just parsing a
3955 statement but (a) it is a block in C99, (b) we handle an empty body
3956 specially for the sake of -Wempty-body warnings. */
3959 c_parser_else_body (c_parser *parser)
3961 location_t else_loc = c_parser_peek_token (parser)->location;
3962 tree block = c_begin_compound_stmt (flag_isoc99);
3963 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3964 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3965 || (c_parser_next_token_is (parser, CPP_NAME)
3966 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3967 c_parser_label (parser);
3968 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3970 location_t loc = c_parser_peek_token (parser)->location;
3973 "suggest braces around empty body in an %<else%> statement");
3974 add_stmt (build_empty_stmt (loc));
3975 c_parser_consume_token (parser);
3978 c_parser_statement_after_labels (parser);
3979 return c_end_compound_stmt (else_loc, block, flag_isoc99);
3982 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3985 if ( expression ) statement
3986 if ( expression ) statement else statement
3990 c_parser_if_statement (c_parser *parser)
3995 bool first_if = false;
3996 tree first_body, second_body;
3999 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4000 c_parser_consume_token (parser);
4001 block = c_begin_compound_stmt (flag_isoc99);
4002 loc = c_parser_peek_token (parser)->location;
4003 cond = c_parser_paren_condition (parser);
4004 in_if_block = parser->in_if_block;
4005 parser->in_if_block = true;
4006 first_body = c_parser_if_body (parser, &first_if);
4007 parser->in_if_block = in_if_block;
4008 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4010 c_parser_consume_token (parser);
4011 second_body = c_parser_else_body (parser);
4014 second_body = NULL_TREE;
4015 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4016 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4019 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4022 switch (expression) statement
4026 c_parser_switch_statement (c_parser *parser)
4028 tree block, expr, body, save_break;
4029 location_t switch_loc = c_parser_peek_token (parser)->location;
4030 location_t switch_cond_loc;
4031 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4032 c_parser_consume_token (parser);
4033 block = c_begin_compound_stmt (flag_isoc99);
4034 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4036 switch_cond_loc = c_parser_peek_token (parser)->location;
4037 expr = c_parser_expression (parser).value;
4038 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4042 switch_cond_loc = UNKNOWN_LOCATION;
4043 expr = error_mark_node;
4045 c_start_case (switch_loc, switch_cond_loc, expr);
4046 save_break = c_break_label;
4047 c_break_label = NULL_TREE;
4048 body = c_parser_c99_block_statement (parser);
4049 c_finish_case (body);
4052 location_t here = c_parser_peek_token (parser)->location;
4053 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4054 SET_EXPR_LOCATION (t, here);
4057 c_break_label = save_break;
4058 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4061 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4064 while (expression) statement
4068 c_parser_while_statement (c_parser *parser)
4070 tree block, cond, body, save_break, save_cont;
4072 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4073 c_parser_consume_token (parser);
4074 block = c_begin_compound_stmt (flag_isoc99);
4075 loc = c_parser_peek_token (parser)->location;
4076 cond = c_parser_paren_condition (parser);
4077 save_break = c_break_label;
4078 c_break_label = NULL_TREE;
4079 save_cont = c_cont_label;
4080 c_cont_label = NULL_TREE;
4081 body = c_parser_c99_block_statement (parser);
4082 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4083 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4084 c_break_label = save_break;
4085 c_cont_label = save_cont;
4088 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4091 do statement while ( expression ) ;
4095 c_parser_do_statement (c_parser *parser)
4097 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4099 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4100 c_parser_consume_token (parser);
4101 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4102 warning_at (c_parser_peek_token (parser)->location,
4104 "suggest braces around empty body in %<do%> statement");
4105 block = c_begin_compound_stmt (flag_isoc99);
4106 loc = c_parser_peek_token (parser)->location;
4107 save_break = c_break_label;
4108 c_break_label = NULL_TREE;
4109 save_cont = c_cont_label;
4110 c_cont_label = NULL_TREE;
4111 body = c_parser_c99_block_statement (parser);
4112 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4113 new_break = c_break_label;
4114 c_break_label = save_break;
4115 new_cont = c_cont_label;
4116 c_cont_label = save_cont;
4117 cond = c_parser_paren_condition (parser);
4118 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4119 c_parser_skip_to_end_of_block_or_statement (parser);
4120 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4121 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4124 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4127 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4128 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4130 The form with a declaration is new in C99.
4132 ??? In accordance with the old parser, the declaration may be a
4133 nested function, which is then rejected in check_for_loop_decls,
4134 but does it make any sense for this to be included in the grammar?
4135 Note in particular that the nested function does not include a
4136 trailing ';', whereas the "declaration" production includes one.
4137 Also, can we reject bad declarations earlier and cheaper than
4138 check_for_loop_decls? */
4141 c_parser_for_statement (c_parser *parser)
4143 tree block, cond, incr, save_break, save_cont, body;
4144 location_t loc = c_parser_peek_token (parser)->location;
4145 location_t for_loc = c_parser_peek_token (parser)->location;
4146 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4147 c_parser_consume_token (parser);
4148 block = c_begin_compound_stmt (flag_isoc99);
4149 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4151 /* Parse the initialization declaration or expression. */
4152 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4154 c_parser_consume_token (parser);
4155 c_finish_expr_stmt (loc, NULL_TREE);
4157 else if (c_parser_next_token_starts_declspecs (parser))
4159 c_parser_declaration_or_fndef (parser, true, true, true, true);
4160 check_for_loop_decls (for_loc);
4162 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4164 /* __extension__ can start a declaration, but is also an
4165 unary operator that can start an expression. Consume all
4166 but the last of a possible series of __extension__ to
4168 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4169 && (c_parser_peek_2nd_token (parser)->keyword
4171 c_parser_consume_token (parser);
4172 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4175 ext = disable_extension_diagnostics ();
4176 c_parser_consume_token (parser);
4177 c_parser_declaration_or_fndef (parser, true, true, true, true);
4178 restore_extension_diagnostics (ext);
4179 check_for_loop_decls (for_loc);
4187 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4188 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4190 /* Parse the loop condition. */
4191 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4193 c_parser_consume_token (parser);
4198 cond = c_parser_condition (parser);
4199 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4201 /* Parse the increment expression. */
4202 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4203 incr = c_process_expr_stmt (loc, NULL_TREE);
4205 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4206 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4210 cond = error_mark_node;
4211 incr = error_mark_node;
4213 save_break = c_break_label;
4214 c_break_label = NULL_TREE;
4215 save_cont = c_cont_label;
4216 c_cont_label = NULL_TREE;
4217 body = c_parser_c99_block_statement (parser);
4218 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4219 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4220 c_break_label = save_break;
4221 c_cont_label = save_cont;
4224 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4225 statement with inputs, outputs, clobbers, and volatile tag
4229 asm type-qualifier[opt] ( asm-argument ) ;
4230 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4234 asm-string-literal : asm-operands[opt]
4235 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4236 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4239 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4242 Qualifiers other than volatile are accepted in the syntax but
4246 c_parser_asm_statement (c_parser *parser)
4248 tree quals, str, outputs, inputs, clobbers, labels, ret;
4249 bool simple, is_goto;
4250 location_t asm_loc = c_parser_peek_token (parser)->location;
4251 int section, nsections;
4253 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4254 c_parser_consume_token (parser);
4255 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4257 quals = c_parser_peek_token (parser)->value;
4258 c_parser_consume_token (parser);
4260 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4261 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4263 warning_at (c_parser_peek_token (parser)->location,
4265 "%E qualifier ignored on asm",
4266 c_parser_peek_token (parser)->value);
4268 c_parser_consume_token (parser);
4274 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4276 c_parser_consume_token (parser);
4280 /* ??? Follow the C++ parser rather than using the
4281 lex_untranslated_string kludge. */
4282 parser->lex_untranslated_string = true;
4285 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4288 str = c_parser_asm_string_literal (parser);
4289 if (str == NULL_TREE)
4290 goto error_close_paren;
4293 outputs = NULL_TREE;
4295 clobbers = NULL_TREE;
4298 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4301 /* Parse each colon-delimited section of operands. */
4302 nsections = 3 + is_goto;
4303 for (section = 0; section < nsections; ++section)
4305 if (!c_parser_require (parser, CPP_COLON,
4308 : "expected %<:%> or %<)%>"))
4309 goto error_close_paren;
4311 /* Once past any colon, we're no longer a simple asm. */
4314 if ((!c_parser_next_token_is (parser, CPP_COLON)
4315 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4320 /* For asm goto, we don't allow output operands, but reserve
4321 the slot for a future extension that does allow them. */
4323 outputs = c_parser_asm_operands (parser, false);
4326 inputs = c_parser_asm_operands (parser, true);
4329 clobbers = c_parser_asm_clobbers (parser);
4332 labels = c_parser_asm_goto_operands (parser);
4338 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4343 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4345 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4349 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4350 c_parser_skip_to_end_of_block_or_statement (parser);
4352 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4353 clobbers, labels, simple));
4356 parser->lex_untranslated_string = false;
4360 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4364 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4365 not outputs), apply the default conversion of functions and arrays
4370 asm-operands , asm-operand
4373 asm-string-literal ( expression )
4374 [ identifier ] asm-string-literal ( expression )
4378 c_parser_asm_operands (c_parser *parser, bool convert_p)
4380 tree list = NULL_TREE;
4386 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4388 c_parser_consume_token (parser);
4389 if (c_parser_next_token_is (parser, CPP_NAME))
4391 tree id = c_parser_peek_token (parser)->value;
4392 c_parser_consume_token (parser);
4393 name = build_string (IDENTIFIER_LENGTH (id),
4394 IDENTIFIER_POINTER (id));
4398 c_parser_error (parser, "expected identifier");
4399 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4402 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4407 str = c_parser_asm_string_literal (parser);
4408 if (str == NULL_TREE)
4410 parser->lex_untranslated_string = false;
4411 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4413 parser->lex_untranslated_string = true;
4416 loc = c_parser_peek_token (parser)->location;
4417 expr = c_parser_expression (parser);
4419 expr = default_function_array_conversion (loc, expr);
4420 expr.value = c_fully_fold (expr.value, false, NULL);
4421 parser->lex_untranslated_string = true;
4422 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4424 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4427 list = chainon (list, build_tree_list (build_tree_list (name, str),
4429 if (c_parser_next_token_is (parser, CPP_COMMA))
4430 c_parser_consume_token (parser);
4437 /* Parse asm clobbers, a GNU extension.
4441 asm-clobbers , asm-string-literal
4445 c_parser_asm_clobbers (c_parser *parser)
4447 tree list = NULL_TREE;
4450 tree str = c_parser_asm_string_literal (parser);
4452 list = tree_cons (NULL_TREE, str, list);
4455 if (c_parser_next_token_is (parser, CPP_COMMA))
4456 c_parser_consume_token (parser);
4463 /* Parse asm goto labels, a GNU extension.
4467 asm-goto-operands , identifier
4471 c_parser_asm_goto_operands (c_parser *parser)
4473 tree list = NULL_TREE;
4478 if (c_parser_next_token_is (parser, CPP_NAME))
4480 c_token *tok = c_parser_peek_token (parser);
4482 label = lookup_label_for_goto (tok->location, name);
4483 c_parser_consume_token (parser);
4484 TREE_USED (label) = 1;
4488 c_parser_error (parser, "expected identifier");
4492 name = build_string (IDENTIFIER_LENGTH (name),
4493 IDENTIFIER_POINTER (name));
4494 list = tree_cons (name, label, list);
4495 if (c_parser_next_token_is (parser, CPP_COMMA))
4496 c_parser_consume_token (parser);
4498 return nreverse (list);
4502 /* Parse an expression other than a compound expression; that is, an
4503 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4504 NULL then it is an Objective-C message expression which is the
4505 primary-expression starting the expression as an initializer.
4507 assignment-expression:
4508 conditional-expression
4509 unary-expression assignment-operator assignment-expression
4511 assignment-operator: one of
4512 = *= /= %= += -= <<= >>= &= ^= |=
4514 In GNU C we accept any conditional expression on the LHS and
4515 diagnose the invalid lvalue rather than producing a syntax
4518 static struct c_expr
4519 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4521 struct c_expr lhs, rhs, ret;
4522 enum tree_code code;
4523 location_t op_location, exp_location;
4524 gcc_assert (!after || c_dialect_objc ());
4525 lhs = c_parser_conditional_expression (parser, after);
4526 op_location = c_parser_peek_token (parser)->location;
4527 switch (c_parser_peek_token (parser)->type)
4536 code = TRUNC_DIV_EXPR;
4539 code = TRUNC_MOD_EXPR;
4554 code = BIT_AND_EXPR;
4557 code = BIT_XOR_EXPR;
4560 code = BIT_IOR_EXPR;
4565 c_parser_consume_token (parser);
4566 exp_location = c_parser_peek_token (parser)->location;
4567 rhs = c_parser_expr_no_commas (parser, NULL);
4568 rhs = default_function_array_conversion (exp_location, rhs);
4569 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4570 code, exp_location, rhs.value,
4572 if (code == NOP_EXPR)
4573 ret.original_code = MODIFY_EXPR;
4576 TREE_NO_WARNING (ret.value) = 1;
4577 ret.original_code = ERROR_MARK;
4579 ret.original_type = NULL;
4583 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4584 is not NULL then it is an Objective-C message expression which is
4585 the primary-expression starting the expression as an initializer.
4587 conditional-expression:
4588 logical-OR-expression
4589 logical-OR-expression ? expression : conditional-expression
4593 conditional-expression:
4594 logical-OR-expression ? : conditional-expression
4597 static struct c_expr
4598 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4600 struct c_expr cond, exp1, exp2, ret;
4601 location_t cond_loc, colon_loc;
4603 gcc_assert (!after || c_dialect_objc ());
4605 cond = c_parser_binary_expression (parser, after);
4607 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4609 cond_loc = c_parser_peek_token (parser)->location;
4610 cond = default_function_array_conversion (cond_loc, cond);
4611 c_parser_consume_token (parser);
4612 if (c_parser_next_token_is (parser, CPP_COLON))
4614 tree eptype = NULL_TREE;
4615 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4616 "ISO C forbids omitting the middle term of a ?: expression");
4617 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4619 eptype = TREE_TYPE (cond.value);
4620 cond.value = TREE_OPERAND (cond.value, 0);
4622 /* Make sure first operand is calculated only once. */
4623 exp1.value = c_save_expr (default_conversion (cond.value));
4625 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4626 exp1.original_type = NULL;
4627 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4628 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4633 = c_objc_common_truthvalue_conversion
4634 (cond_loc, default_conversion (cond.value));
4635 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4636 exp1 = c_parser_expression_conv (parser);
4637 c_inhibit_evaluation_warnings +=
4638 ((cond.value == truthvalue_true_node)
4639 - (cond.value == truthvalue_false_node));
4642 colon_loc = c_parser_peek_token (parser)->location;
4643 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4645 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4646 ret.value = error_mark_node;
4647 ret.original_code = ERROR_MARK;
4648 ret.original_type = NULL;
4652 location_t exp2_loc = c_parser_peek_token (parser)->location;
4653 exp2 = c_parser_conditional_expression (parser, NULL);
4654 exp2 = default_function_array_conversion (exp2_loc, exp2);
4656 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4657 ret.value = build_conditional_expr (colon_loc, cond.value,
4658 cond.original_code == C_MAYBE_CONST_EXPR,
4659 exp1.value, exp1.original_type,
4660 exp2.value, exp2.original_type);
4661 ret.original_code = ERROR_MARK;
4662 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4663 ret.original_type = NULL;
4668 /* If both sides are enum type, the default conversion will have
4669 made the type of the result be an integer type. We want to
4670 remember the enum types we started with. */
4671 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4672 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4673 ret.original_type = ((t1 != error_mark_node
4674 && t2 != error_mark_node
4675 && (TYPE_MAIN_VARIANT (t1)
4676 == TYPE_MAIN_VARIANT (t2)))
4683 /* Parse a binary expression; that is, a logical-OR-expression (C90
4684 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4685 an Objective-C message expression which is the primary-expression
4686 starting the expression as an initializer.
4688 multiplicative-expression:
4690 multiplicative-expression * cast-expression
4691 multiplicative-expression / cast-expression
4692 multiplicative-expression % cast-expression
4694 additive-expression:
4695 multiplicative-expression
4696 additive-expression + multiplicative-expression
4697 additive-expression - multiplicative-expression
4701 shift-expression << additive-expression
4702 shift-expression >> additive-expression
4704 relational-expression:
4706 relational-expression < shift-expression
4707 relational-expression > shift-expression
4708 relational-expression <= shift-expression
4709 relational-expression >= shift-expression
4711 equality-expression:
4712 relational-expression
4713 equality-expression == relational-expression
4714 equality-expression != relational-expression
4718 AND-expression & equality-expression
4720 exclusive-OR-expression:
4722 exclusive-OR-expression ^ AND-expression
4724 inclusive-OR-expression:
4725 exclusive-OR-expression
4726 inclusive-OR-expression | exclusive-OR-expression
4728 logical-AND-expression:
4729 inclusive-OR-expression
4730 logical-AND-expression && inclusive-OR-expression
4732 logical-OR-expression:
4733 logical-AND-expression
4734 logical-OR-expression || logical-AND-expression
4737 static struct c_expr
4738 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4740 /* A binary expression is parsed using operator-precedence parsing,
4741 with the operands being cast expressions. All the binary
4742 operators are left-associative. Thus a binary expression is of
4745 E0 op1 E1 op2 E2 ...
4747 which we represent on a stack. On the stack, the precedence
4748 levels are strictly increasing. When a new operator is
4749 encountered of higher precedence than that at the top of the
4750 stack, it is pushed; its LHS is the top expression, and its RHS
4751 is everything parsed until it is popped. When a new operator is
4752 encountered with precedence less than or equal to that at the top
4753 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4754 by the result of the operation until the operator at the top of
4755 the stack has lower precedence than the new operator or there is
4756 only one element on the stack; then the top expression is the LHS
4757 of the new operator. In the case of logical AND and OR
4758 expressions, we also need to adjust c_inhibit_evaluation_warnings
4759 as appropriate when the operators are pushed and popped. */
4761 /* The precedence levels, where 0 is a dummy lowest level used for
4762 the bottom of the stack. */
4778 /* The expression at this stack level. */
4780 /* The precedence of the operator on its left, PREC_NONE at the
4781 bottom of the stack. */
4783 /* The operation on its left. */
4785 /* The source location of this operation. */
4789 /* Location of the binary operator. */
4790 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4793 switch (stack[sp].op) \
4795 case TRUTH_ANDIF_EXPR: \
4796 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4797 == truthvalue_false_node); \
4799 case TRUTH_ORIF_EXPR: \
4800 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4801 == truthvalue_true_node); \
4806 stack[sp - 1].expr \
4807 = default_function_array_conversion (stack[sp - 1].loc, \
4808 stack[sp - 1].expr); \
4810 = default_function_array_conversion (stack[sp].loc, stack[sp].expr); \
4811 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4813 stack[sp - 1].expr, \
4817 gcc_assert (!after || c_dialect_objc ());
4818 stack[0].loc = c_parser_peek_token (parser)->location;
4819 stack[0].expr = c_parser_cast_expression (parser, after);
4820 stack[0].prec = PREC_NONE;
4825 enum tree_code ocode;
4828 switch (c_parser_peek_token (parser)->type)
4836 ocode = TRUNC_DIV_EXPR;
4840 ocode = TRUNC_MOD_EXPR;
4852 ocode = LSHIFT_EXPR;
4856 ocode = RSHIFT_EXPR;
4870 case CPP_GREATER_EQ:
4883 oprec = PREC_BITAND;
4884 ocode = BIT_AND_EXPR;
4887 oprec = PREC_BITXOR;
4888 ocode = BIT_XOR_EXPR;
4892 ocode = BIT_IOR_EXPR;
4895 oprec = PREC_LOGAND;
4896 ocode = TRUTH_ANDIF_EXPR;
4900 ocode = TRUTH_ORIF_EXPR;
4903 /* Not a binary operator, so end of the binary
4907 binary_loc = c_parser_peek_token (parser)->location;
4908 c_parser_consume_token (parser);
4909 while (oprec <= stack[sp].prec)
4913 case TRUTH_ANDIF_EXPR:
4915 = default_function_array_conversion (stack[sp].loc,
4917 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4918 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4919 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4920 == truthvalue_false_node);
4922 case TRUTH_ORIF_EXPR:
4924 = default_function_array_conversion (stack[sp].loc,
4926 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4927 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4928 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4929 == truthvalue_true_node);
4935 stack[sp].loc = binary_loc;
4936 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4937 stack[sp].prec = oprec;
4938 stack[sp].op = ocode;
4939 stack[sp].loc = binary_loc;
4944 return stack[0].expr;
4948 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4949 NULL then it is an Objective-C message expression which is the
4950 primary-expression starting the expression as an initializer.
4954 ( type-name ) unary-expression
4957 static struct c_expr
4958 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
4960 location_t cast_loc = c_parser_peek_token (parser)->location;
4961 gcc_assert (!after || c_dialect_objc ());
4963 return c_parser_postfix_expression_after_primary (parser,
4965 /* If the expression begins with a parenthesized type name, it may
4966 be either a cast or a compound literal; we need to see whether
4967 the next character is '{' to tell the difference. If not, it is
4968 an unary expression. */
4969 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
4970 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
4972 struct c_type_name *type_name;
4975 c_parser_consume_token (parser);
4976 type_name = c_parser_type_name (parser);
4977 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4978 if (type_name == NULL)
4980 ret.value = error_mark_node;
4981 ret.original_code = ERROR_MARK;
4982 ret.original_type = NULL;
4986 /* Save casted types in the function's used types hash table. */
4987 used_types_insert (type_name->specs->type);
4989 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4990 return c_parser_postfix_expression_after_paren_type (parser, type_name,
4993 location_t expr_loc = c_parser_peek_token (parser)->location;
4994 expr = c_parser_cast_expression (parser, NULL);
4995 expr = default_function_array_conversion (expr_loc, expr);
4997 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
4998 ret.original_code = ERROR_MARK;
4999 ret.original_type = NULL;
5003 return c_parser_unary_expression (parser);
5006 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5012 unary-operator cast-expression
5013 sizeof unary-expression
5014 sizeof ( type-name )
5016 unary-operator: one of
5022 __alignof__ unary-expression
5023 __alignof__ ( type-name )
5026 unary-operator: one of
5027 __extension__ __real__ __imag__
5029 In addition, the GNU syntax treats ++ and -- as unary operators, so
5030 they may be applied to cast expressions with errors for non-lvalues
5033 static struct c_expr
5034 c_parser_unary_expression (c_parser *parser)
5037 struct c_expr ret, op;
5038 location_t op_loc = c_parser_peek_token (parser)->location;
5040 ret.original_code = ERROR_MARK;
5041 ret.original_type = NULL;
5042 switch (c_parser_peek_token (parser)->type)
5045 c_parser_consume_token (parser);
5046 exp_loc = c_parser_peek_token (parser)->location;
5047 op = c_parser_cast_expression (parser, NULL);
5048 op = default_function_array_conversion (exp_loc, op);
5049 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5050 case CPP_MINUS_MINUS:
5051 c_parser_consume_token (parser);
5052 exp_loc = c_parser_peek_token (parser)->location;
5053 op = c_parser_cast_expression (parser, NULL);
5054 op = default_function_array_conversion (exp_loc, op);
5055 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5057 c_parser_consume_token (parser);
5058 return parser_build_unary_op (op_loc, ADDR_EXPR,
5059 c_parser_cast_expression (parser, NULL));
5061 c_parser_consume_token (parser);
5062 exp_loc = c_parser_peek_token (parser)->location;
5063 op = c_parser_cast_expression (parser, NULL);
5064 op = default_function_array_conversion (exp_loc, op);
5065 ret.value = build_indirect_ref (op_loc, op.value, "unary *");
5068 if (!c_dialect_objc () && !in_system_header)
5071 "traditional C rejects the unary plus operator");
5072 c_parser_consume_token (parser);
5073 exp_loc = c_parser_peek_token (parser)->location;
5074 op = c_parser_cast_expression (parser, NULL);
5075 op = default_function_array_conversion (exp_loc, op);
5076 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5078 c_parser_consume_token (parser);
5079 exp_loc = c_parser_peek_token (parser)->location;
5080 op = c_parser_cast_expression (parser, NULL);
5081 op = default_function_array_conversion (exp_loc, op);
5082 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5084 c_parser_consume_token (parser);
5085 exp_loc = c_parser_peek_token (parser)->location;
5086 op = c_parser_cast_expression (parser, NULL);
5087 op = default_function_array_conversion (exp_loc, op);
5088 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5090 c_parser_consume_token (parser);
5091 exp_loc = c_parser_peek_token (parser)->location;
5092 op = c_parser_cast_expression (parser, NULL);
5093 op = default_function_array_conversion (exp_loc, op);
5094 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5096 /* Refer to the address of a label as a pointer. */
5097 c_parser_consume_token (parser);
5098 if (c_parser_next_token_is (parser, CPP_NAME))
5100 ret.value = finish_label_address_expr
5101 (c_parser_peek_token (parser)->value, op_loc);
5102 c_parser_consume_token (parser);
5106 c_parser_error (parser, "expected identifier");
5107 ret.value = error_mark_node;
5111 switch (c_parser_peek_token (parser)->keyword)
5114 return c_parser_sizeof_expression (parser);
5116 return c_parser_alignof_expression (parser);
5118 c_parser_consume_token (parser);
5119 ext = disable_extension_diagnostics ();
5120 ret = c_parser_cast_expression (parser, NULL);
5121 restore_extension_diagnostics (ext);
5124 c_parser_consume_token (parser);
5125 exp_loc = c_parser_peek_token (parser)->location;
5126 op = c_parser_cast_expression (parser, NULL);
5127 op = default_function_array_conversion (exp_loc, op);
5128 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5130 c_parser_consume_token (parser);
5131 exp_loc = c_parser_peek_token (parser)->location;
5132 op = c_parser_cast_expression (parser, NULL);
5133 op = default_function_array_conversion (exp_loc, op);
5134 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5136 return c_parser_postfix_expression (parser);
5139 return c_parser_postfix_expression (parser);
5143 /* Parse a sizeof expression. */
5145 static struct c_expr
5146 c_parser_sizeof_expression (c_parser *parser)
5149 location_t expr_loc;
5150 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5151 c_parser_consume_token (parser);
5152 c_inhibit_evaluation_warnings++;
5154 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5155 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5157 /* Either sizeof ( type-name ) or sizeof unary-expression
5158 starting with a compound literal. */
5159 struct c_type_name *type_name;
5160 c_parser_consume_token (parser);
5161 expr_loc = c_parser_peek_token (parser)->location;
5162 type_name = c_parser_type_name (parser);
5163 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5164 if (type_name == NULL)
5167 c_inhibit_evaluation_warnings--;
5169 ret.value = error_mark_node;
5170 ret.original_code = ERROR_MARK;
5171 ret.original_type = NULL;
5174 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5176 expr = c_parser_postfix_expression_after_paren_type (parser,
5181 /* sizeof ( type-name ). */
5182 c_inhibit_evaluation_warnings--;
5184 return c_expr_sizeof_type (expr_loc, type_name);
5188 expr_loc = c_parser_peek_token (parser)->location;
5189 expr = c_parser_unary_expression (parser);
5191 c_inhibit_evaluation_warnings--;
5193 if (TREE_CODE (expr.value) == COMPONENT_REF
5194 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5195 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5196 return c_expr_sizeof_expr (expr_loc, expr);
5200 /* Parse an alignof expression. */
5202 static struct c_expr
5203 c_parser_alignof_expression (c_parser *parser)
5206 location_t loc = c_parser_peek_token (parser)->location;
5207 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5208 c_parser_consume_token (parser);
5209 c_inhibit_evaluation_warnings++;
5211 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5212 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5214 /* Either __alignof__ ( type-name ) or __alignof__
5215 unary-expression starting with a compound literal. */
5217 struct c_type_name *type_name;
5219 c_parser_consume_token (parser);
5220 loc = c_parser_peek_token (parser)->location;
5221 type_name = c_parser_type_name (parser);
5222 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5223 if (type_name == NULL)
5226 c_inhibit_evaluation_warnings--;
5228 ret.value = error_mark_node;
5229 ret.original_code = ERROR_MARK;
5230 ret.original_type = NULL;
5233 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5235 expr = c_parser_postfix_expression_after_paren_type (parser,
5240 /* alignof ( type-name ). */
5241 c_inhibit_evaluation_warnings--;
5243 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5244 ret.original_code = ERROR_MARK;
5245 ret.original_type = NULL;
5251 expr = c_parser_unary_expression (parser);
5253 c_inhibit_evaluation_warnings--;
5255 ret.value = c_alignof_expr (loc, expr.value);
5256 ret.original_code = ERROR_MARK;
5257 ret.original_type = NULL;
5262 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5266 postfix-expression [ expression ]
5267 postfix-expression ( argument-expression-list[opt] )
5268 postfix-expression . identifier
5269 postfix-expression -> identifier
5270 postfix-expression ++
5271 postfix-expression --
5272 ( type-name ) { initializer-list }
5273 ( type-name ) { initializer-list , }
5275 argument-expression-list:
5277 argument-expression-list , argument-expression
5289 (treated as a keyword in GNU C)
5292 ( compound-statement )
5293 __builtin_va_arg ( assignment-expression , type-name )
5294 __builtin_offsetof ( type-name , offsetof-member-designator )
5295 __builtin_choose_expr ( assignment-expression ,
5296 assignment-expression ,
5297 assignment-expression )
5298 __builtin_types_compatible_p ( type-name , type-name )
5300 offsetof-member-designator:
5302 offsetof-member-designator . identifier
5303 offsetof-member-designator [ expression ]
5308 [ objc-receiver objc-message-args ]
5309 @selector ( objc-selector-arg )
5310 @protocol ( identifier )
5311 @encode ( type-name )
5315 static struct c_expr
5316 c_parser_postfix_expression (c_parser *parser)
5318 struct c_expr expr, e1, e2, e3;
5319 struct c_type_name *t1, *t2;
5320 location_t loc = c_parser_peek_token (parser)->location;;
5321 expr.original_code = ERROR_MARK;
5322 expr.original_type = NULL;
5323 switch (c_parser_peek_token (parser)->type)
5326 expr.value = c_parser_peek_token (parser)->value;
5327 loc = c_parser_peek_token (parser)->location;
5328 c_parser_consume_token (parser);
5329 if (TREE_CODE (expr.value) == FIXED_CST
5330 && !targetm.fixed_point_supported_p ())
5332 error_at (loc, "fixed-point types not supported for this target");
5333 expr.value = error_mark_node;
5340 expr.value = c_parser_peek_token (parser)->value;
5341 c_parser_consume_token (parser);
5347 expr.value = c_parser_peek_token (parser)->value;
5348 expr.original_code = STRING_CST;
5349 c_parser_consume_token (parser);
5351 case CPP_OBJC_STRING:
5352 gcc_assert (c_dialect_objc ());
5354 = objc_build_string_object (c_parser_peek_token (parser)->value);
5355 c_parser_consume_token (parser);
5358 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5360 c_parser_error (parser, "expected expression");
5361 expr.value = error_mark_node;
5365 tree id = c_parser_peek_token (parser)->value;
5366 c_parser_consume_token (parser);
5367 expr.value = build_external_ref (loc, id,
5368 (c_parser_peek_token (parser)->type
5370 &expr.original_type);
5373 case CPP_OPEN_PAREN:
5374 /* A parenthesized expression, statement expression or compound
5376 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5378 /* A statement expression. */
5380 location_t brace_loc;
5381 c_parser_consume_token (parser);
5382 brace_loc = c_parser_peek_token (parser)->location;
5383 c_parser_consume_token (parser);
5384 if (cur_stmt_list == NULL)
5386 error_at (loc, "braced-group within expression allowed "
5387 "only inside a function");
5388 parser->error = true;
5389 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5390 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5391 expr.value = error_mark_node;
5394 stmt = c_begin_stmt_expr ();
5395 c_parser_compound_statement_nostart (parser);
5396 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5398 pedwarn (loc, OPT_pedantic,
5399 "ISO C forbids braced-groups within expressions");
5400 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5402 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5404 /* A compound literal. ??? Can we actually get here rather
5405 than going directly to
5406 c_parser_postfix_expression_after_paren_type from
5409 struct c_type_name *type_name;
5410 c_parser_consume_token (parser);
5411 loc = c_parser_peek_token (parser)->location;
5412 type_name = c_parser_type_name (parser);
5413 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5415 if (type_name == NULL)
5417 expr.value = error_mark_node;
5420 expr = c_parser_postfix_expression_after_paren_type (parser,
5426 /* A parenthesized expression. */
5427 c_parser_consume_token (parser);
5428 expr = c_parser_expression (parser);
5429 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5430 TREE_NO_WARNING (expr.value) = 1;
5431 if (expr.original_code != C_MAYBE_CONST_EXPR)
5432 expr.original_code = ERROR_MARK;
5433 /* Don't change EXPR.ORIGINAL_TYPE. */
5434 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5439 switch (c_parser_peek_token (parser)->keyword)
5441 case RID_FUNCTION_NAME:
5442 case RID_PRETTY_FUNCTION_NAME:
5443 case RID_C99_FUNCTION_NAME:
5444 expr.value = fname_decl (loc,
5445 c_parser_peek_token (parser)->keyword,
5446 c_parser_peek_token (parser)->value);
5447 c_parser_consume_token (parser);
5450 c_parser_consume_token (parser);
5451 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5453 expr.value = error_mark_node;
5456 e1 = c_parser_expr_no_commas (parser, NULL);
5457 e1.value = c_fully_fold (e1.value, false, NULL);
5458 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5460 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5461 expr.value = error_mark_node;
5464 loc = c_parser_peek_token (parser)->location;
5465 t1 = c_parser_type_name (parser);
5466 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5470 expr.value = error_mark_node;
5474 tree type_expr = NULL_TREE;
5475 expr.value = c_build_va_arg (loc, e1.value,
5476 groktypename (t1, &type_expr, NULL));
5479 expr.value = build2 (C_MAYBE_CONST_EXPR,
5480 TREE_TYPE (expr.value), type_expr,
5482 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5487 c_parser_consume_token (parser);
5488 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5490 expr.value = error_mark_node;
5493 t1 = c_parser_type_name (parser);
5496 expr.value = error_mark_node;
5499 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5501 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5502 expr.value = error_mark_node;
5506 tree type = groktypename (t1, NULL, NULL);
5508 if (type == error_mark_node)
5509 offsetof_ref = error_mark_node;
5512 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5513 SET_EXPR_LOCATION (offsetof_ref, loc);
5515 /* Parse the second argument to __builtin_offsetof. We
5516 must have one identifier, and beyond that we want to
5517 accept sub structure and sub array references. */
5518 if (c_parser_next_token_is (parser, CPP_NAME))
5520 offsetof_ref = build_component_ref
5521 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5522 c_parser_consume_token (parser);
5523 while (c_parser_next_token_is (parser, CPP_DOT)
5524 || c_parser_next_token_is (parser,
5526 || c_parser_next_token_is (parser,
5529 if (c_parser_next_token_is (parser, CPP_DEREF))
5531 loc = c_parser_peek_token (parser)->location;
5532 offsetof_ref = build_array_ref (loc,
5537 else if (c_parser_next_token_is (parser, CPP_DOT))
5540 c_parser_consume_token (parser);
5541 if (c_parser_next_token_is_not (parser,
5544 c_parser_error (parser, "expected identifier");
5547 offsetof_ref = build_component_ref
5549 c_parser_peek_token (parser)->value);
5550 c_parser_consume_token (parser);
5555 loc = c_parser_peek_token (parser)->location;
5556 c_parser_consume_token (parser);
5557 idx = c_parser_expression (parser).value;
5558 idx = c_fully_fold (idx, false, NULL);
5559 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5561 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5566 c_parser_error (parser, "expected identifier");
5567 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5569 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5572 case RID_CHOOSE_EXPR:
5573 c_parser_consume_token (parser);
5574 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5576 expr.value = error_mark_node;
5579 loc = c_parser_peek_token (parser)->location;
5580 e1 = c_parser_expr_no_commas (parser, NULL);
5581 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5583 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5584 expr.value = error_mark_node;
5587 e2 = c_parser_expr_no_commas (parser, NULL);
5588 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5590 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5591 expr.value = error_mark_node;
5594 e3 = c_parser_expr_no_commas (parser, NULL);
5595 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5601 if (TREE_CODE (c) != INTEGER_CST
5602 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5604 "first argument to %<__builtin_choose_expr%> not"
5606 constant_expression_warning (c);
5607 expr = integer_zerop (c) ? e3 : e2;
5610 case RID_TYPES_COMPATIBLE_P:
5611 c_parser_consume_token (parser);
5612 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5614 expr.value = error_mark_node;
5617 t1 = c_parser_type_name (parser);
5620 expr.value = error_mark_node;
5623 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5625 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5626 expr.value = error_mark_node;
5629 t2 = c_parser_type_name (parser);
5632 expr.value = error_mark_node;
5635 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5640 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5641 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5643 expr.value = comptypes (e1, e2)
5644 ? build_int_cst (NULL_TREE, 1)
5645 : build_int_cst (NULL_TREE, 0);
5648 case RID_AT_SELECTOR:
5649 gcc_assert (c_dialect_objc ());
5650 c_parser_consume_token (parser);
5651 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5653 expr.value = error_mark_node;
5657 tree sel = c_parser_objc_selector_arg (parser);
5658 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5660 expr.value = objc_build_selector_expr (loc, sel);
5663 case RID_AT_PROTOCOL:
5664 gcc_assert (c_dialect_objc ());
5665 c_parser_consume_token (parser);
5666 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5668 expr.value = error_mark_node;
5671 if (c_parser_next_token_is_not (parser, CPP_NAME))
5673 c_parser_error (parser, "expected identifier");
5674 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5675 expr.value = error_mark_node;
5679 tree id = c_parser_peek_token (parser)->value;
5680 c_parser_consume_token (parser);
5681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5683 expr.value = objc_build_protocol_expr (id);
5687 /* Extension to support C-structures in the archiver. */
5688 gcc_assert (c_dialect_objc ());
5689 c_parser_consume_token (parser);
5690 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5692 expr.value = error_mark_node;
5695 t1 = c_parser_type_name (parser);
5698 expr.value = error_mark_node;
5699 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5702 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5705 tree type = groktypename (t1, NULL, NULL);
5706 expr.value = objc_build_encode_expr (type);
5710 c_parser_error (parser, "expected expression");
5711 expr.value = error_mark_node;
5715 case CPP_OPEN_SQUARE:
5716 if (c_dialect_objc ())
5718 tree receiver, args;
5719 c_parser_consume_token (parser);
5720 receiver = c_parser_objc_receiver (parser);
5721 args = c_parser_objc_message_args (parser);
5722 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5724 expr.value = objc_build_message_expr (build_tree_list (receiver,
5728 /* Else fall through to report error. */
5730 c_parser_error (parser, "expected expression");
5731 expr.value = error_mark_node;
5734 return c_parser_postfix_expression_after_primary (parser, loc, expr);
5737 /* Parse a postfix expression after a parenthesized type name: the
5738 brace-enclosed initializer of a compound literal, possibly followed
5739 by some postfix operators. This is separate because it is not
5740 possible to tell until after the type name whether a cast
5741 expression has a cast or a compound literal, or whether the operand
5742 of sizeof is a parenthesized type name or starts with a compound
5743 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5744 location of the first token after the parentheses around the type
5747 static struct c_expr
5748 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5749 struct c_type_name *type_name,
5750 location_t type_loc)
5756 location_t start_loc;
5757 tree type_expr = NULL_TREE;
5758 bool type_expr_const = true;
5759 check_compound_literal_type (type_loc, type_name);
5760 start_init (NULL_TREE, NULL, 0);
5761 type = groktypename (type_name, &type_expr, &type_expr_const);
5762 start_loc = c_parser_peek_token (parser)->location;
5763 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5765 error_at (type_loc, "compound literal has variable size");
5766 type = error_mark_node;
5768 init = c_parser_braced_init (parser, type, false);
5770 maybe_warn_string_init (type, init);
5773 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5774 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5775 ? CONSTRUCTOR_NON_CONST (init.value)
5776 : init.original_code == C_MAYBE_CONST_EXPR);
5777 non_const |= !type_expr_const;
5778 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
5779 expr.original_code = ERROR_MARK;
5780 expr.original_type = NULL;
5783 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5785 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5786 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5790 gcc_assert (!non_const);
5791 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5792 type_expr, expr.value);
5795 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
5798 /* Parse a postfix expression after the initial primary or compound
5799 literal; that is, parse a series of postfix operators.
5801 EXPR_LOC is the location of the primary expression. */
5803 static struct c_expr
5804 c_parser_postfix_expression_after_primary (c_parser *parser,
5805 location_t expr_loc,
5808 struct c_expr orig_expr;
5810 VEC(tree,gc) *exprlist;
5811 VEC(tree,gc) *origtypes;
5814 location_t op_loc = c_parser_peek_token (parser)->location;
5815 switch (c_parser_peek_token (parser)->type)
5817 case CPP_OPEN_SQUARE:
5818 /* Array reference. */
5819 c_parser_consume_token (parser);
5820 idx = c_parser_expression (parser).value;
5821 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5823 expr.value = build_array_ref (op_loc, expr.value, idx);
5824 expr.original_code = ERROR_MARK;
5825 expr.original_type = NULL;
5827 case CPP_OPEN_PAREN:
5828 /* Function call. */
5829 c_parser_consume_token (parser);
5830 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5833 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
5834 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5837 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5838 "(" after the FUNCNAME, which is what we have now. */
5839 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
5841 expr.original_code = ERROR_MARK;
5842 if (TREE_CODE (expr.value) == INTEGER_CST
5843 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5844 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5845 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5846 expr.original_code = C_MAYBE_CONST_EXPR;
5847 expr.original_type = NULL;
5848 if (exprlist != NULL)
5850 release_tree_vector (exprlist);
5851 release_tree_vector (origtypes);
5855 /* Structure element reference. */
5856 c_parser_consume_token (parser);
5857 expr = default_function_array_conversion (expr_loc, expr);
5858 if (c_parser_next_token_is (parser, CPP_NAME))
5859 ident = c_parser_peek_token (parser)->value;
5862 c_parser_error (parser, "expected identifier");
5863 expr.value = error_mark_node;
5864 expr.original_code = ERROR_MARK;
5865 expr.original_type = NULL;
5868 c_parser_consume_token (parser);
5869 expr.value = build_component_ref (op_loc, expr.value, ident);
5870 expr.original_code = ERROR_MARK;
5871 if (TREE_CODE (expr.value) != COMPONENT_REF)
5872 expr.original_type = NULL;
5875 /* Remember the original type of a bitfield. */
5876 tree field = TREE_OPERAND (expr.value, 1);
5877 if (TREE_CODE (field) != FIELD_DECL)
5878 expr.original_type = NULL;
5880 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5884 /* Structure element reference. */
5885 c_parser_consume_token (parser);
5886 expr = default_function_array_conversion (expr_loc, expr);
5887 if (c_parser_next_token_is (parser, CPP_NAME))
5888 ident = c_parser_peek_token (parser)->value;
5891 c_parser_error (parser, "expected identifier");
5892 expr.value = error_mark_node;
5893 expr.original_code = ERROR_MARK;
5894 expr.original_type = NULL;
5897 c_parser_consume_token (parser);
5898 expr.value = build_component_ref (op_loc,
5899 build_indirect_ref (op_loc,
5903 expr.original_code = ERROR_MARK;
5904 if (TREE_CODE (expr.value) != COMPONENT_REF)
5905 expr.original_type = NULL;
5908 /* Remember the original type of a bitfield. */
5909 tree field = TREE_OPERAND (expr.value, 1);
5910 if (TREE_CODE (field) != FIELD_DECL)
5911 expr.original_type = NULL;
5913 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5917 /* Postincrement. */
5918 c_parser_consume_token (parser);
5919 expr = default_function_array_conversion (expr_loc, expr);
5920 expr.value = build_unary_op (op_loc,
5921 POSTINCREMENT_EXPR, expr.value, 0);
5922 expr.original_code = ERROR_MARK;
5923 expr.original_type = NULL;
5925 case CPP_MINUS_MINUS:
5926 /* Postdecrement. */
5927 c_parser_consume_token (parser);
5928 expr = default_function_array_conversion (expr_loc, expr);
5929 expr.value = build_unary_op (op_loc,
5930 POSTDECREMENT_EXPR, expr.value, 0);
5931 expr.original_code = ERROR_MARK;
5932 expr.original_type = NULL;
5940 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5943 assignment-expression
5944 expression , assignment-expression
5947 static struct c_expr
5948 c_parser_expression (c_parser *parser)
5951 expr = c_parser_expr_no_commas (parser, NULL);
5952 while (c_parser_next_token_is (parser, CPP_COMMA))
5955 location_t loc = c_parser_peek_token (parser)->location;
5956 location_t expr_loc;
5957 c_parser_consume_token (parser);
5958 expr_loc = c_parser_peek_token (parser)->location;
5959 next = c_parser_expr_no_commas (parser, NULL);
5960 next = default_function_array_conversion (expr_loc, next);
5961 expr.value = build_compound_expr (loc, expr.value, next.value);
5962 expr.original_code = COMPOUND_EXPR;
5963 expr.original_type = next.original_type;
5968 /* Parse an expression and convert functions or arrays to
5971 static struct c_expr
5972 c_parser_expression_conv (c_parser *parser)
5975 location_t loc = c_parser_peek_token (parser)->location;
5976 expr = c_parser_expression (parser);
5977 expr = default_function_array_conversion (loc, expr);
5981 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5982 functions and arrays to pointers. If FOLD_P, fold the expressions.
5985 assignment-expression
5986 nonempty-expr-list , assignment-expression
5989 static VEC(tree,gc) *
5990 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
5991 VEC(tree,gc) **p_orig_types)
5994 VEC(tree,gc) *orig_types;
5996 location_t loc = c_parser_peek_token (parser)->location;
5998 ret = make_tree_vector ();
5999 if (p_orig_types == NULL)
6002 orig_types = make_tree_vector ();
6004 expr = c_parser_expr_no_commas (parser, NULL);
6006 expr = default_function_array_conversion (loc, expr);
6008 expr.value = c_fully_fold (expr.value, false, NULL);
6009 VEC_quick_push (tree, ret, expr.value);
6010 if (orig_types != NULL)
6011 VEC_quick_push (tree, orig_types, expr.original_type);
6012 while (c_parser_next_token_is (parser, CPP_COMMA))
6014 c_parser_consume_token (parser);
6015 loc = c_parser_peek_token (parser)->location;
6016 expr = c_parser_expr_no_commas (parser, NULL);
6018 expr = default_function_array_conversion (loc, expr);
6020 expr.value = c_fully_fold (expr.value, false, NULL);
6021 VEC_safe_push (tree, gc, ret, expr.value);
6022 if (orig_types != NULL)
6023 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6025 if (orig_types != NULL)
6026 *p_orig_types = orig_types;
6030 /* Parse Objective-C-specific constructs. */
6032 /* Parse an objc-class-definition.
6034 objc-class-definition:
6035 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6036 objc-class-instance-variables[opt] objc-methodprotolist @end
6037 @implementation identifier objc-superclass[opt]
6038 objc-class-instance-variables[opt]
6039 @interface identifier ( identifier ) objc-protocol-refs[opt]
6040 objc-methodprotolist @end
6041 @implementation identifier ( identifier )
6046 "@interface identifier (" must start "@interface identifier (
6047 identifier ) ...": objc-methodprotolist in the first production may
6048 not start with a parenthesized identifier as a declarator of a data
6049 definition with no declaration specifiers if the objc-superclass,
6050 objc-protocol-refs and objc-class-instance-variables are omitted. */
6053 c_parser_objc_class_definition (c_parser *parser)
6058 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6060 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6064 c_parser_consume_token (parser);
6065 if (c_parser_next_token_is_not (parser, CPP_NAME))
6067 c_parser_error (parser, "expected identifier");
6070 id1 = c_parser_peek_token (parser)->value;
6071 c_parser_consume_token (parser);
6072 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6075 tree proto = NULL_TREE;
6076 c_parser_consume_token (parser);
6077 if (c_parser_next_token_is_not (parser, CPP_NAME))
6079 c_parser_error (parser, "expected identifier");
6080 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6083 id2 = c_parser_peek_token (parser)->value;
6084 c_parser_consume_token (parser);
6085 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6088 objc_start_category_implementation (id1, id2);
6091 if (c_parser_next_token_is (parser, CPP_LESS))
6092 proto = c_parser_objc_protocol_refs (parser);
6093 objc_start_category_interface (id1, id2, proto);
6094 c_parser_objc_methodprotolist (parser);
6095 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6096 objc_finish_interface ();
6099 if (c_parser_next_token_is (parser, CPP_COLON))
6101 c_parser_consume_token (parser);
6102 if (c_parser_next_token_is_not (parser, CPP_NAME))
6104 c_parser_error (parser, "expected identifier");
6107 superclass = c_parser_peek_token (parser)->value;
6108 c_parser_consume_token (parser);
6111 superclass = NULL_TREE;
6114 tree proto = NULL_TREE;
6115 if (c_parser_next_token_is (parser, CPP_LESS))
6116 proto = c_parser_objc_protocol_refs (parser);
6117 objc_start_class_interface (id1, superclass, proto);
6120 objc_start_class_implementation (id1, superclass);
6121 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6122 c_parser_objc_class_instance_variables (parser);
6125 objc_continue_interface ();
6126 c_parser_objc_methodprotolist (parser);
6127 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6128 objc_finish_interface ();
6132 objc_continue_implementation ();
6137 /* Parse objc-class-instance-variables.
6139 objc-class-instance-variables:
6140 { objc-instance-variable-decl-list[opt] }
6142 objc-instance-variable-decl-list:
6143 objc-visibility-spec
6144 objc-instance-variable-decl ;
6146 objc-instance-variable-decl-list objc-visibility-spec
6147 objc-instance-variable-decl-list objc-instance-variable-decl ;
6148 objc-instance-variable-decl-list ;
6150 objc-visibility-spec:
6155 objc-instance-variable-decl:
6160 c_parser_objc_class_instance_variables (c_parser *parser)
6162 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6163 c_parser_consume_token (parser);
6164 while (c_parser_next_token_is_not (parser, CPP_EOF))
6167 /* Parse any stray semicolon. */
6168 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6170 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6171 "extra semicolon in struct or union specified");
6172 c_parser_consume_token (parser);
6175 /* Stop if at the end of the instance variables. */
6176 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6178 c_parser_consume_token (parser);
6181 /* Parse any objc-visibility-spec. */
6182 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6184 c_parser_consume_token (parser);
6185 objc_set_visibility (2);
6188 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6190 c_parser_consume_token (parser);
6191 objc_set_visibility (0);
6194 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6196 c_parser_consume_token (parser);
6197 objc_set_visibility (1);
6200 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6202 c_parser_pragma (parser, pragma_external);
6206 /* Parse some comma-separated declarations. */
6207 decls = c_parser_struct_declaration (parser);
6209 /* Comma-separated instance variables are chained together in
6210 reverse order; add them one by one. */
6211 tree ivar = nreverse (decls);
6212 for (; ivar; ivar = TREE_CHAIN (ivar))
6213 objc_add_instance_variable (copy_node (ivar));
6215 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6219 /* Parse an objc-class-declaration.
6221 objc-class-declaration:
6222 @class identifier-list ;
6226 c_parser_objc_class_declaration (c_parser *parser)
6228 tree list = NULL_TREE;
6229 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6230 c_parser_consume_token (parser);
6231 /* Any identifiers, including those declared as type names, are OK
6236 if (c_parser_next_token_is_not (parser, CPP_NAME))
6238 c_parser_error (parser, "expected identifier");
6241 id = c_parser_peek_token (parser)->value;
6242 list = chainon (list, build_tree_list (NULL_TREE, id));
6243 c_parser_consume_token (parser);
6244 if (c_parser_next_token_is (parser, CPP_COMMA))
6245 c_parser_consume_token (parser);
6249 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6250 objc_declare_class (list);
6253 /* Parse an objc-alias-declaration.
6255 objc-alias-declaration:
6256 @compatibility_alias identifier identifier ;
6260 c_parser_objc_alias_declaration (c_parser *parser)
6263 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6264 c_parser_consume_token (parser);
6265 if (c_parser_next_token_is_not (parser, CPP_NAME))
6267 c_parser_error (parser, "expected identifier");
6268 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6271 id1 = c_parser_peek_token (parser)->value;
6272 c_parser_consume_token (parser);
6273 if (c_parser_next_token_is_not (parser, CPP_NAME))
6275 c_parser_error (parser, "expected identifier");
6276 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6279 id2 = c_parser_peek_token (parser)->value;
6280 c_parser_consume_token (parser);
6281 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6282 objc_declare_alias (id1, id2);
6285 /* Parse an objc-protocol-definition.
6287 objc-protocol-definition:
6288 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6289 @protocol identifier-list ;
6291 "@protocol identifier ;" should be resolved as "@protocol
6292 identifier-list ;": objc-methodprotolist may not start with a
6293 semicolon in the first alternative if objc-protocol-refs are
6297 c_parser_objc_protocol_definition (c_parser *parser)
6299 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6300 c_parser_consume_token (parser);
6301 if (c_parser_next_token_is_not (parser, CPP_NAME))
6303 c_parser_error (parser, "expected identifier");
6306 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6307 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6309 tree list = NULL_TREE;
6310 /* Any identifiers, including those declared as type names, are
6315 if (c_parser_next_token_is_not (parser, CPP_NAME))
6317 c_parser_error (parser, "expected identifier");
6320 id = c_parser_peek_token (parser)->value;
6321 list = chainon (list, build_tree_list (NULL_TREE, id));
6322 c_parser_consume_token (parser);
6323 if (c_parser_next_token_is (parser, CPP_COMMA))
6324 c_parser_consume_token (parser);
6328 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6329 objc_declare_protocols (list);
6333 tree id = c_parser_peek_token (parser)->value;
6334 tree proto = NULL_TREE;
6335 c_parser_consume_token (parser);
6336 if (c_parser_next_token_is (parser, CPP_LESS))
6337 proto = c_parser_objc_protocol_refs (parser);
6338 parser->objc_pq_context = true;
6339 objc_start_protocol (id, proto);
6340 c_parser_objc_methodprotolist (parser);
6341 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6342 parser->objc_pq_context = false;
6343 objc_finish_interface ();
6347 /* Parse an objc-method-type.
6354 static enum tree_code
6355 c_parser_objc_method_type (c_parser *parser)
6357 switch (c_parser_peek_token (parser)->type)
6360 c_parser_consume_token (parser);
6363 c_parser_consume_token (parser);
6370 /* Parse an objc-method-definition.
6372 objc-method-definition:
6373 objc-method-type objc-method-decl ;[opt] compound-statement
6377 c_parser_objc_method_definition (c_parser *parser)
6379 enum tree_code type = c_parser_objc_method_type (parser);
6381 objc_set_method_type (type);
6382 parser->objc_pq_context = true;
6383 decl = c_parser_objc_method_decl (parser);
6384 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6386 c_parser_consume_token (parser);
6387 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6388 "extra semicolon in method definition specified");
6390 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6392 c_parser_error (parser, "expected %<{%>");
6395 parser->objc_pq_context = false;
6396 objc_start_method_definition (decl);
6397 add_stmt (c_parser_compound_statement (parser));
6398 objc_finish_method_definition (current_function_decl);
6401 /* Parse an objc-methodprotolist.
6403 objc-methodprotolist:
6405 objc-methodprotolist objc-methodproto
6406 objc-methodprotolist declaration
6407 objc-methodprotolist ;
6409 The declaration is a data definition, which may be missing
6410 declaration specifiers under the same rules and diagnostics as
6411 other data definitions outside functions, and the stray semicolon
6412 is diagnosed the same way as a stray semicolon outside a
6416 c_parser_objc_methodprotolist (c_parser *parser)
6420 /* The list is terminated by @end. */
6421 switch (c_parser_peek_token (parser)->type)
6424 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6425 "ISO C does not allow extra %<;%> outside of a function");
6426 c_parser_consume_token (parser);
6430 c_parser_objc_methodproto (parser);
6433 c_parser_pragma (parser, pragma_external);
6438 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6440 c_parser_declaration_or_fndef (parser, false, true, false, true);
6446 /* Parse an objc-methodproto.
6449 objc-method-type objc-method-decl ;
6453 c_parser_objc_methodproto (c_parser *parser)
6455 enum tree_code type = c_parser_objc_method_type (parser);
6457 objc_set_method_type (type);
6458 /* Remember protocol qualifiers in prototypes. */
6459 parser->objc_pq_context = true;
6460 decl = c_parser_objc_method_decl (parser);
6461 /* Forget protocol qualifiers here. */
6462 parser->objc_pq_context = false;
6463 objc_add_method_declaration (decl);
6464 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6467 /* Parse an objc-method-decl.
6470 ( objc-type-name ) objc-selector
6472 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6473 objc-keyword-selector objc-optparmlist
6475 objc-keyword-selector:
6477 objc-keyword-selector objc-keyword-decl
6480 objc-selector : ( objc-type-name ) identifier
6481 objc-selector : identifier
6482 : ( objc-type-name ) identifier
6486 objc-optparms objc-optellipsis
6490 objc-opt-parms , parameter-declaration
6498 c_parser_objc_method_decl (c_parser *parser)
6500 tree type = NULL_TREE;
6502 tree parms = NULL_TREE;
6503 bool ellipsis = false;
6505 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6507 c_parser_consume_token (parser);
6508 type = c_parser_objc_type_name (parser);
6509 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6511 sel = c_parser_objc_selector (parser);
6512 /* If there is no selector, or a colon follows, we have an
6513 objc-keyword-selector. If there is a selector, and a colon does
6514 not follow, that selector ends the objc-method-decl. */
6515 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6518 tree list = NULL_TREE;
6521 tree atype = NULL_TREE, id, keyworddecl;
6522 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6524 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6526 c_parser_consume_token (parser);
6527 atype = c_parser_objc_type_name (parser);
6528 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6531 if (c_parser_next_token_is_not (parser, CPP_NAME))
6533 c_parser_error (parser, "expected identifier");
6534 return error_mark_node;
6536 id = c_parser_peek_token (parser)->value;
6537 c_parser_consume_token (parser);
6538 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6539 list = chainon (list, keyworddecl);
6540 tsel = c_parser_objc_selector (parser);
6541 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6544 /* Parse the optional parameter list. Optional Objective-C
6545 method parameters follow the C syntax, and may include '...'
6546 to denote a variable number of arguments. */
6547 parms = make_node (TREE_LIST);
6548 while (c_parser_next_token_is (parser, CPP_COMMA))
6550 struct c_parm *parm;
6551 c_parser_consume_token (parser);
6552 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6555 c_parser_consume_token (parser);
6558 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6561 parms = chainon (parms,
6562 build_tree_list (NULL_TREE, grokparm (parm)));
6566 return objc_build_method_signature (type, sel, parms, ellipsis);
6569 /* Parse an objc-type-name.
6572 objc-type-qualifiers[opt] type-name
6573 objc-type-qualifiers[opt]
6575 objc-type-qualifiers:
6577 objc-type-qualifiers objc-type-qualifier
6579 objc-type-qualifier: one of
6580 in out inout bycopy byref oneway
6584 c_parser_objc_type_name (c_parser *parser)
6586 tree quals = NULL_TREE;
6587 struct c_type_name *type_name = NULL;
6588 tree type = NULL_TREE;
6591 c_token *token = c_parser_peek_token (parser);
6592 if (token->type == CPP_KEYWORD
6593 && (token->keyword == RID_IN
6594 || token->keyword == RID_OUT
6595 || token->keyword == RID_INOUT
6596 || token->keyword == RID_BYCOPY
6597 || token->keyword == RID_BYREF
6598 || token->keyword == RID_ONEWAY))
6600 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6601 c_parser_consume_token (parser);
6606 if (c_parser_next_token_starts_typename (parser))
6607 type_name = c_parser_type_name (parser);
6609 type = groktypename (type_name, NULL, NULL);
6610 return build_tree_list (quals, type);
6613 /* Parse objc-protocol-refs.
6620 c_parser_objc_protocol_refs (c_parser *parser)
6622 tree list = NULL_TREE;
6623 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6624 c_parser_consume_token (parser);
6625 /* Any identifiers, including those declared as type names, are OK
6630 if (c_parser_next_token_is_not (parser, CPP_NAME))
6632 c_parser_error (parser, "expected identifier");
6635 id = c_parser_peek_token (parser)->value;
6636 list = chainon (list, build_tree_list (NULL_TREE, id));
6637 c_parser_consume_token (parser);
6638 if (c_parser_next_token_is (parser, CPP_COMMA))
6639 c_parser_consume_token (parser);
6643 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6647 /* Parse an objc-try-catch-statement.
6649 objc-try-catch-statement:
6650 @try compound-statement objc-catch-list[opt]
6651 @try compound-statement objc-catch-list[opt] @finally compound-statement
6654 @catch ( parameter-declaration ) compound-statement
6655 objc-catch-list @catch ( parameter-declaration ) compound-statement
6659 c_parser_objc_try_catch_statement (c_parser *parser)
6663 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6664 c_parser_consume_token (parser);
6665 loc = c_parser_peek_token (parser)->location;
6666 stmt = c_parser_compound_statement (parser);
6667 objc_begin_try_stmt (loc, stmt);
6668 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6670 struct c_parm *parm;
6671 c_parser_consume_token (parser);
6672 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6674 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6677 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6680 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6681 objc_begin_catch_clause (grokparm (parm));
6682 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6683 c_parser_compound_statement_nostart (parser);
6684 objc_finish_catch_clause ();
6686 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6690 c_parser_consume_token (parser);
6691 finloc = c_parser_peek_token (parser)->location;
6692 finstmt = c_parser_compound_statement (parser);
6693 objc_build_finally_clause (finloc, finstmt);
6695 objc_finish_try_stmt ();
6698 /* Parse an objc-synchronized-statement.
6700 objc-synchronized-statement:
6701 @synchronized ( expression ) compound-statement
6705 c_parser_objc_synchronized_statement (c_parser *parser)
6709 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6710 c_parser_consume_token (parser);
6711 loc = c_parser_peek_token (parser)->location;
6712 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6714 expr = c_parser_expression (parser).value;
6715 expr = c_fully_fold (expr, false, NULL);
6716 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6719 expr = error_mark_node;
6720 stmt = c_parser_compound_statement (parser);
6721 objc_build_synchronized (loc, expr, stmt);
6724 /* Parse an objc-selector; return NULL_TREE without an error if the
6725 next token is not an objc-selector.
6730 enum struct union if else while do for switch case default
6731 break continue return goto asm sizeof typeof __alignof
6732 unsigned long const short volatile signed restrict _Complex
6733 in out inout bycopy byref oneway int char float double void _Bool
6735 ??? Why this selection of keywords but not, for example, storage
6736 class specifiers? */
6739 c_parser_objc_selector (c_parser *parser)
6741 c_token *token = c_parser_peek_token (parser);
6742 tree value = token->value;
6743 if (token->type == CPP_NAME)
6745 c_parser_consume_token (parser);
6748 if (token->type != CPP_KEYWORD)
6750 switch (token->keyword)
6791 c_parser_consume_token (parser);
6798 /* Parse an objc-selector-arg.
6802 objc-keywordname-list
6804 objc-keywordname-list:
6806 objc-keywordname-list objc-keywordname
6814 c_parser_objc_selector_arg (c_parser *parser)
6816 tree sel = c_parser_objc_selector (parser);
6817 tree list = NULL_TREE;
6818 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6822 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6824 list = chainon (list, build_tree_list (sel, NULL_TREE));
6825 sel = c_parser_objc_selector (parser);
6826 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6832 /* Parse an objc-receiver.
6841 c_parser_objc_receiver (c_parser *parser)
6843 if (c_parser_peek_token (parser)->type == CPP_NAME
6844 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6845 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6847 tree id = c_parser_peek_token (parser)->value;
6848 c_parser_consume_token (parser);
6849 return objc_get_class_reference (id);
6851 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6854 /* Parse objc-message-args.
6858 objc-keywordarg-list
6860 objc-keywordarg-list:
6862 objc-keywordarg-list objc-keywordarg
6865 objc-selector : objc-keywordexpr
6870 c_parser_objc_message_args (c_parser *parser)
6872 tree sel = c_parser_objc_selector (parser);
6873 tree list = NULL_TREE;
6874 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6879 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6880 return error_mark_node;
6881 keywordexpr = c_parser_objc_keywordexpr (parser);
6882 list = chainon (list, build_tree_list (sel, keywordexpr));
6883 sel = c_parser_objc_selector (parser);
6884 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6890 /* Parse an objc-keywordexpr.
6897 c_parser_objc_keywordexpr (c_parser *parser)
6900 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
6901 if (VEC_length (tree, expr_list) == 1)
6903 /* Just return the expression, remove a level of
6905 ret = VEC_index (tree, expr_list, 0);
6909 /* We have a comma expression, we will collapse later. */
6910 ret = build_tree_list_vec (expr_list);
6912 release_tree_vector (expr_list);
6917 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6918 should be considered, statements. ALLOW_STMT is true if we're within
6919 the context of a function and such pragmas are to be allowed. Returns
6920 true if we actually parsed such a pragma. */
6923 c_parser_pragma (c_parser *parser, enum pragma_context context)
6927 id = c_parser_peek_token (parser)->pragma_kind;
6928 gcc_assert (id != PRAGMA_NONE);
6932 case PRAGMA_OMP_BARRIER:
6933 if (context != pragma_compound)
6935 if (context == pragma_stmt)
6936 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
6937 "used in compound statements");
6940 c_parser_omp_barrier (parser);
6943 case PRAGMA_OMP_FLUSH:
6944 if (context != pragma_compound)
6946 if (context == pragma_stmt)
6947 c_parser_error (parser, "%<#pragma omp flush%> may only be "
6948 "used in compound statements");
6951 c_parser_omp_flush (parser);
6954 case PRAGMA_OMP_TASKWAIT:
6955 if (context != pragma_compound)
6957 if (context == pragma_stmt)
6958 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
6959 "used in compound statements");
6962 c_parser_omp_taskwait (parser);
6965 case PRAGMA_OMP_THREADPRIVATE:
6966 c_parser_omp_threadprivate (parser);
6969 case PRAGMA_OMP_SECTION:
6970 error_at (c_parser_peek_token (parser)->location,
6971 "%<#pragma omp section%> may only be used in "
6972 "%<#pragma omp sections%> construct");
6973 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6976 case PRAGMA_GCC_PCH_PREPROCESS:
6977 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
6978 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6982 if (id < PRAGMA_FIRST_EXTERNAL)
6984 if (context == pragma_external)
6987 c_parser_error (parser, "expected declaration specifiers");
6988 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
6991 c_parser_omp_construct (parser);
6997 c_parser_consume_pragma (parser);
6998 c_invoke_pragma_handler (id);
7000 /* Skip to EOL, but suppress any error message. Those will have been
7001 generated by the handler routine through calling error, as opposed
7002 to calling c_parser_error. */
7003 parser->error = true;
7004 c_parser_skip_to_pragma_eol (parser);
7009 /* The interface the pragma parsers have to the lexer. */
7012 pragma_lex (tree *value)
7014 c_token *tok = c_parser_peek_token (the_parser);
7015 enum cpp_ttype ret = tok->type;
7017 *value = tok->value;
7018 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7022 if (ret == CPP_KEYWORD)
7024 c_parser_consume_token (the_parser);
7031 c_parser_pragma_pch_preprocess (c_parser *parser)
7035 c_parser_consume_pragma (parser);
7036 if (c_parser_next_token_is (parser, CPP_STRING))
7038 name = c_parser_peek_token (parser)->value;
7039 c_parser_consume_token (parser);
7042 c_parser_error (parser, "expected string literal");
7043 c_parser_skip_to_pragma_eol (parser);
7046 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7049 /* OpenMP 2.5 parsing routines. */
7051 /* Returns name of the next clause.
7052 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7053 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7054 returned and the token is consumed. */
7056 static pragma_omp_clause
7057 c_parser_omp_clause_name (c_parser *parser)
7059 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7061 if (c_parser_next_token_is_keyword (parser, RID_IF))
7062 result = PRAGMA_OMP_CLAUSE_IF;
7063 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7064 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7065 else if (c_parser_next_token_is (parser, CPP_NAME))
7067 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7072 if (!strcmp ("collapse", p))
7073 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7074 else if (!strcmp ("copyin", p))
7075 result = PRAGMA_OMP_CLAUSE_COPYIN;
7076 else if (!strcmp ("copyprivate", p))
7077 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7080 if (!strcmp ("firstprivate", p))
7081 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7084 if (!strcmp ("lastprivate", p))
7085 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7088 if (!strcmp ("nowait", p))
7089 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7090 else if (!strcmp ("num_threads", p))
7091 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7094 if (!strcmp ("ordered", p))
7095 result = PRAGMA_OMP_CLAUSE_ORDERED;
7098 if (!strcmp ("private", p))
7099 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7102 if (!strcmp ("reduction", p))
7103 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7106 if (!strcmp ("schedule", p))
7107 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7108 else if (!strcmp ("shared", p))
7109 result = PRAGMA_OMP_CLAUSE_SHARED;
7112 if (!strcmp ("untied", p))
7113 result = PRAGMA_OMP_CLAUSE_UNTIED;
7118 if (result != PRAGMA_OMP_CLAUSE_NONE)
7119 c_parser_consume_token (parser);
7124 /* Validate that a clause of the given type does not already exist. */
7127 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7132 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7133 if (OMP_CLAUSE_CODE (c) == code)
7135 location_t loc = OMP_CLAUSE_LOCATION (c);
7136 error_at (loc, "too many %qs clauses", name);
7144 variable-list , identifier
7146 If KIND is nonzero, create the appropriate node and install the
7147 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7148 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7150 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7151 return the list created. */
7154 c_parser_omp_variable_list (c_parser *parser,
7155 location_t clause_loc,
7156 enum omp_clause_code kind,
7159 if (c_parser_next_token_is_not (parser, CPP_NAME)
7160 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7161 c_parser_error (parser, "expected identifier");
7163 while (c_parser_next_token_is (parser, CPP_NAME)
7164 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7166 tree t = lookup_name (c_parser_peek_token (parser)->value);
7169 undeclared_variable (c_parser_peek_token (parser)->location,
7170 c_parser_peek_token (parser)->value);
7171 else if (t == error_mark_node)
7175 tree u = build_omp_clause (clause_loc, kind);
7176 OMP_CLAUSE_DECL (u) = t;
7177 OMP_CLAUSE_CHAIN (u) = list;
7181 list = tree_cons (t, NULL_TREE, list);
7183 c_parser_consume_token (parser);
7185 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7188 c_parser_consume_token (parser);
7194 /* Similarly, but expect leading and trailing parenthesis. This is a very
7195 common case for omp clauses. */
7198 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7201 /* The clauses location. */
7202 location_t loc = c_parser_peek_token (parser)->location;
7204 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7206 list = c_parser_omp_variable_list (parser, loc, kind, list);
7207 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7213 collapse ( constant-expression ) */
7216 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7218 tree c, num = error_mark_node;
7222 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7224 loc = c_parser_peek_token (parser)->location;
7225 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7227 num = c_parser_expr_no_commas (parser, NULL).value;
7228 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7230 if (num == error_mark_node)
7232 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7233 || !host_integerp (num, 0)
7234 || (n = tree_low_cst (num, 0)) <= 0
7238 "collapse argument needs positive constant integer expression");
7241 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7242 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7243 OMP_CLAUSE_CHAIN (c) = list;
7248 copyin ( variable-list ) */
7251 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7253 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7257 copyprivate ( variable-list ) */
7260 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7262 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7266 default ( shared | none ) */
7269 c_parser_omp_clause_default (c_parser *parser, tree list)
7271 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7272 location_t loc = c_parser_peek_token (parser)->location;
7275 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7277 if (c_parser_next_token_is (parser, CPP_NAME))
7279 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7284 if (strcmp ("none", p) != 0)
7286 kind = OMP_CLAUSE_DEFAULT_NONE;
7290 if (strcmp ("shared", p) != 0)
7292 kind = OMP_CLAUSE_DEFAULT_SHARED;
7299 c_parser_consume_token (parser);
7304 c_parser_error (parser, "expected %<none%> or %<shared%>");
7306 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7308 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7311 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7312 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7313 OMP_CLAUSE_CHAIN (c) = list;
7314 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7320 firstprivate ( variable-list ) */
7323 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7325 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7329 if ( expression ) */
7332 c_parser_omp_clause_if (c_parser *parser, tree list)
7334 location_t loc = c_parser_peek_token (parser)->location;
7335 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7337 tree t = c_parser_paren_condition (parser);
7340 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7342 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7343 OMP_CLAUSE_IF_EXPR (c) = t;
7344 OMP_CLAUSE_CHAIN (c) = list;
7348 c_parser_error (parser, "expected %<(%>");
7354 lastprivate ( variable-list ) */
7357 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7359 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7366 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7369 location_t loc = c_parser_peek_token (parser)->location;
7371 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7373 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7374 OMP_CLAUSE_CHAIN (c) = list;
7379 num_threads ( expression ) */
7382 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7384 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7385 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7387 location_t expr_loc = c_parser_peek_token (parser)->location;
7388 tree c, t = c_parser_expression (parser).value;
7389 t = c_fully_fold (t, false, NULL);
7391 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7393 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7395 c_parser_error (parser, "expected integer expression");
7399 /* Attempt to statically determine when the number isn't positive. */
7400 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7401 build_int_cst (TREE_TYPE (t), 0));
7402 if (CAN_HAVE_LOCATION_P (c))
7403 SET_EXPR_LOCATION (c, expr_loc);
7404 if (c == boolean_true_node)
7406 warning_at (expr_loc, 0,
7407 "%<num_threads%> value must be positive");
7408 t = integer_one_node;
7411 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7413 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7414 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7415 OMP_CLAUSE_CHAIN (c) = list;
7426 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7430 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7432 c = build_omp_clause (c_parser_peek_token (parser)->location,
7433 OMP_CLAUSE_ORDERED);
7434 OMP_CLAUSE_CHAIN (c) = list;
7440 private ( variable-list ) */
7443 c_parser_omp_clause_private (c_parser *parser, tree list)
7445 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7449 reduction ( reduction-operator : variable-list )
7452 One of: + * - & ^ | && || */
7455 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7457 location_t clause_loc = c_parser_peek_token (parser)->location;
7458 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7460 enum tree_code code;
7462 switch (c_parser_peek_token (parser)->type)
7474 code = BIT_AND_EXPR;
7477 code = BIT_XOR_EXPR;
7480 code = BIT_IOR_EXPR;
7483 code = TRUTH_ANDIF_EXPR;
7486 code = TRUTH_ORIF_EXPR;
7489 c_parser_error (parser,
7490 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7491 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7492 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7495 c_parser_consume_token (parser);
7496 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7500 nl = c_parser_omp_variable_list (parser, clause_loc,
7501 OMP_CLAUSE_REDUCTION, list);
7502 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7503 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7507 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7513 schedule ( schedule-kind )
7514 schedule ( schedule-kind , expression )
7517 static | dynamic | guided | runtime | auto
7521 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7524 location_t loc = c_parser_peek_token (parser)->location;
7526 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7529 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7531 if (c_parser_next_token_is (parser, CPP_NAME))
7533 tree kind = c_parser_peek_token (parser)->value;
7534 const char *p = IDENTIFIER_POINTER (kind);
7539 if (strcmp ("dynamic", p) != 0)
7541 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7545 if (strcmp ("guided", p) != 0)
7547 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7551 if (strcmp ("runtime", p) != 0)
7553 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7560 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7561 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7562 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7563 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7567 c_parser_consume_token (parser);
7568 if (c_parser_next_token_is (parser, CPP_COMMA))
7571 c_parser_consume_token (parser);
7573 here = c_parser_peek_token (parser)->location;
7574 t = c_parser_expr_no_commas (parser, NULL).value;
7575 t = c_fully_fold (t, false, NULL);
7577 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7578 error_at (here, "schedule %<runtime%> does not take "
7579 "a %<chunk_size%> parameter");
7580 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7582 "schedule %<auto%> does not take "
7583 "a %<chunk_size%> parameter");
7584 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7585 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7587 c_parser_error (parser, "expected integer expression");
7589 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7592 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7593 "expected %<,%> or %<)%>");
7595 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7596 OMP_CLAUSE_CHAIN (c) = list;
7600 c_parser_error (parser, "invalid schedule kind");
7601 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7606 shared ( variable-list ) */
7609 c_parser_omp_clause_shared (c_parser *parser, tree list)
7611 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7618 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7622 /* FIXME: Should we allow duplicates? */
7623 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7625 c = build_omp_clause (c_parser_peek_token (parser)->location,
7627 OMP_CLAUSE_CHAIN (c) = list;
7632 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7633 is a bitmask in MASK. Return the list of clauses found; the result
7634 of clause default goes in *pdefault. */
7637 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7640 tree clauses = NULL;
7643 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7646 pragma_omp_clause c_kind;
7648 tree prev = clauses;
7650 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7651 c_parser_consume_token (parser);
7654 here = c_parser_peek_token (parser)->location;
7655 c_kind = c_parser_omp_clause_name (parser);
7659 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7660 clauses = c_parser_omp_clause_collapse (parser, clauses);
7661 c_name = "collapse";
7663 case PRAGMA_OMP_CLAUSE_COPYIN:
7664 clauses = c_parser_omp_clause_copyin (parser, clauses);
7667 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7668 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7669 c_name = "copyprivate";
7671 case PRAGMA_OMP_CLAUSE_DEFAULT:
7672 clauses = c_parser_omp_clause_default (parser, clauses);
7675 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7676 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7677 c_name = "firstprivate";
7679 case PRAGMA_OMP_CLAUSE_IF:
7680 clauses = c_parser_omp_clause_if (parser, clauses);
7683 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7684 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7685 c_name = "lastprivate";
7687 case PRAGMA_OMP_CLAUSE_NOWAIT:
7688 clauses = c_parser_omp_clause_nowait (parser, clauses);
7691 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7692 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7693 c_name = "num_threads";
7695 case PRAGMA_OMP_CLAUSE_ORDERED:
7696 clauses = c_parser_omp_clause_ordered (parser, clauses);
7699 case PRAGMA_OMP_CLAUSE_PRIVATE:
7700 clauses = c_parser_omp_clause_private (parser, clauses);
7703 case PRAGMA_OMP_CLAUSE_REDUCTION:
7704 clauses = c_parser_omp_clause_reduction (parser, clauses);
7705 c_name = "reduction";
7707 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7708 clauses = c_parser_omp_clause_schedule (parser, clauses);
7709 c_name = "schedule";
7711 case PRAGMA_OMP_CLAUSE_SHARED:
7712 clauses = c_parser_omp_clause_shared (parser, clauses);
7715 case PRAGMA_OMP_CLAUSE_UNTIED:
7716 clauses = c_parser_omp_clause_untied (parser, clauses);
7720 c_parser_error (parser, "expected %<#pragma omp%> clause");
7724 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7726 /* Remove the invalid clause(s) from the list to avoid
7727 confusing the rest of the compiler. */
7729 error_at (here, "%qs is not valid for %qs", c_name, where);
7734 c_parser_skip_to_pragma_eol (parser);
7736 return c_finish_omp_clauses (clauses);
7743 In practice, we're also interested in adding the statement to an
7744 outer node. So it is convenient if we work around the fact that
7745 c_parser_statement calls add_stmt. */
7748 c_parser_omp_structured_block (c_parser *parser)
7750 tree stmt = push_stmt_list ();
7751 c_parser_statement (parser);
7752 return pop_stmt_list (stmt);
7756 # pragma omp atomic new-line
7760 x binop= expr | x++ | ++x | x-- | --x
7762 +, *, -, /, &, ^, |, <<, >>
7764 where x is an lvalue expression with scalar type.
7766 LOC is the location of the #pragma token. */
7769 c_parser_omp_atomic (location_t loc, c_parser *parser)
7773 enum tree_code code;
7774 struct c_expr rhs_expr;
7776 c_parser_skip_to_pragma_eol (parser);
7778 lhs = c_parser_unary_expression (parser).value;
7779 lhs = c_fully_fold (lhs, false, NULL);
7780 switch (TREE_CODE (lhs))
7784 c_parser_skip_to_end_of_block_or_statement (parser);
7787 case PREINCREMENT_EXPR:
7788 case POSTINCREMENT_EXPR:
7789 lhs = TREE_OPERAND (lhs, 0);
7791 rhs = integer_one_node;
7794 case PREDECREMENT_EXPR:
7795 case POSTDECREMENT_EXPR:
7796 lhs = TREE_OPERAND (lhs, 0);
7798 rhs = integer_one_node;
7802 switch (c_parser_peek_token (parser)->type)
7808 code = TRUNC_DIV_EXPR;
7823 code = BIT_AND_EXPR;
7826 code = BIT_IOR_EXPR;
7829 code = BIT_XOR_EXPR;
7832 c_parser_error (parser,
7833 "invalid operator for %<#pragma omp atomic%>");
7837 c_parser_consume_token (parser);
7839 location_t rhs_loc = c_parser_peek_token (parser)->location;
7840 rhs_expr = c_parser_expression (parser);
7841 rhs_expr = default_function_array_conversion (rhs_loc, rhs_expr);
7843 rhs = rhs_expr.value;
7844 rhs = c_fully_fold (rhs, false, NULL);
7847 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
7848 if (stmt != error_mark_node)
7850 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7855 # pragma omp barrier new-line
7859 c_parser_omp_barrier (c_parser *parser)
7861 location_t loc = c_parser_peek_token (parser)->location;
7862 c_parser_consume_pragma (parser);
7863 c_parser_skip_to_pragma_eol (parser);
7865 c_finish_omp_barrier (loc);
7869 # pragma omp critical [(name)] new-line
7872 LOC is the location of the #pragma itself. */
7875 c_parser_omp_critical (location_t loc, c_parser *parser)
7877 tree stmt, name = NULL;
7879 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7881 c_parser_consume_token (parser);
7882 if (c_parser_next_token_is (parser, CPP_NAME))
7884 name = c_parser_peek_token (parser)->value;
7885 c_parser_consume_token (parser);
7886 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7889 c_parser_error (parser, "expected identifier");
7891 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7892 c_parser_error (parser, "expected %<(%> or end of line");
7893 c_parser_skip_to_pragma_eol (parser);
7895 stmt = c_parser_omp_structured_block (parser);
7896 return c_finish_omp_critical (loc, stmt, name);
7900 # pragma omp flush flush-vars[opt] new-line
7903 ( variable-list ) */
7906 c_parser_omp_flush (c_parser *parser)
7908 location_t loc = c_parser_peek_token (parser)->location;
7909 c_parser_consume_pragma (parser);
7910 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7911 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7912 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7913 c_parser_error (parser, "expected %<(%> or end of line");
7914 c_parser_skip_to_pragma_eol (parser);
7916 c_finish_omp_flush (loc);
7919 /* Parse the restricted form of the for statement allowed by OpenMP.
7920 The real trick here is to determine the loop control variable early
7921 so that we can push a new decl if necessary to make it private.
7922 LOC is the location of the OMP in "#pragma omp". */
7925 c_parser_omp_for_loop (location_t loc,
7926 c_parser *parser, tree clauses, tree *par_clauses)
7928 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
7929 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
7930 bool fail = false, open_brace_parsed = false;
7931 int i, collapse = 1, nbraces = 0;
7934 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
7935 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
7936 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
7938 gcc_assert (collapse >= 1);
7940 declv = make_tree_vec (collapse);
7941 initv = make_tree_vec (collapse);
7942 condv = make_tree_vec (collapse);
7943 incrv = make_tree_vec (collapse);
7945 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
7947 c_parser_error (parser, "for statement expected");
7950 for_loc = c_parser_peek_token (parser)->location;
7951 c_parser_consume_token (parser);
7953 for (i = 0; i < collapse; i++)
7957 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7960 /* Parse the initialization declaration or expression. */
7961 if (c_parser_next_token_starts_declspecs (parser))
7965 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
7966 c_parser_declaration_or_fndef (parser, true, true, true, true);
7967 decl = check_for_loop_decls (for_loc);
7970 if (DECL_INITIAL (decl) == error_mark_node)
7971 decl = error_mark_node;
7974 else if (c_parser_next_token_is (parser, CPP_NAME)
7975 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
7977 struct c_expr decl_exp;
7978 struct c_expr init_exp;
7979 location_t init_loc;
7981 decl_exp = c_parser_postfix_expression (parser);
7982 decl = decl_exp.value;
7984 c_parser_require (parser, CPP_EQ, "expected %<=%>");
7986 init_loc = c_parser_peek_token (parser)->location;
7987 init_exp = c_parser_expr_no_commas (parser, NULL);
7988 init_exp = default_function_array_conversion (init_loc, init_exp);
7989 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
7990 NOP_EXPR, init_loc, init_exp.value,
7991 init_exp.original_type);
7992 init = c_process_expr_stmt (init_loc, init);
7994 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7999 c_parser_error (parser,
8000 "expected iteration declaration or initialization");
8001 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8007 /* Parse the loop condition. */
8009 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8011 location_t cond_loc = c_parser_peek_token (parser)->location;
8012 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8014 cond = cond_expr.value;
8015 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8016 cond = c_fully_fold (cond, false, NULL);
8017 switch (cond_expr.original_code)
8025 /* Can't be cond = error_mark_node, because we want to preserve
8026 the location until c_finish_omp_for. */
8027 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8030 protected_set_expr_location (cond, cond_loc);
8032 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8034 /* Parse the increment expression. */
8036 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8038 location_t incr_loc = c_parser_peek_token (parser)->location;
8040 incr = c_process_expr_stmt (incr_loc,
8041 c_parser_expression (parser).value);
8043 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8045 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8049 TREE_VEC_ELT (declv, i) = decl;
8050 TREE_VEC_ELT (initv, i) = init;
8051 TREE_VEC_ELT (condv, i) = cond;
8052 TREE_VEC_ELT (incrv, i) = incr;
8056 if (i == collapse - 1)
8059 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8060 in between the collapsed for loops to be still considered perfectly
8061 nested. Hopefully the final version clarifies this.
8062 For now handle (multiple) {'s and empty statements. */
8065 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8067 c_parser_consume_token (parser);
8070 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8072 c_parser_consume_token (parser);
8076 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8077 c_parser_consume_token (parser);
8080 c_parser_error (parser, "not enough perfectly nested loops");
8083 open_brace_parsed = true;
8093 nbraces += bracecount;
8096 save_break = c_break_label;
8097 c_break_label = size_one_node;
8098 save_cont = c_cont_label;
8099 c_cont_label = NULL_TREE;
8100 body = push_stmt_list ();
8102 if (open_brace_parsed)
8104 location_t here = c_parser_peek_token (parser)->location;
8105 stmt = c_begin_compound_stmt (true);
8106 c_parser_compound_statement_nostart (parser);
8107 add_stmt (c_end_compound_stmt (here, stmt, true));
8110 add_stmt (c_parser_c99_block_statement (parser));
8113 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8114 SET_EXPR_LOCATION (t, loc);
8118 body = pop_stmt_list (body);
8119 c_break_label = save_break;
8120 c_cont_label = save_cont;
8124 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8126 c_parser_consume_token (parser);
8129 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8130 c_parser_consume_token (parser);
8133 c_parser_error (parser, "collapsed loops not perfectly nested");
8136 location_t here = c_parser_peek_token (parser)->location;
8137 stmt = c_begin_compound_stmt (true);
8139 c_parser_compound_statement_nostart (parser);
8140 body = c_end_compound_stmt (here, stmt, true);
8147 /* Only bother calling c_finish_omp_for if we haven't already generated
8148 an error from the initialization parsing. */
8151 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8154 if (par_clauses != NULL)
8157 for (c = par_clauses; *c ; )
8158 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8159 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8160 c = &OMP_CLAUSE_CHAIN (*c);
8163 for (i = 0; i < collapse; i++)
8164 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8167 c = &OMP_CLAUSE_CHAIN (*c);
8168 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8171 "iteration variable %qD should not be firstprivate",
8172 OMP_CLAUSE_DECL (*c));
8173 *c = OMP_CLAUSE_CHAIN (*c);
8177 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8178 change it to shared (decl) in
8179 OMP_PARALLEL_CLAUSES. */
8180 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8181 OMP_CLAUSE_LASTPRIVATE);
8182 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8183 OMP_CLAUSE_CHAIN (l) = clauses;
8185 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8189 OMP_FOR_CLAUSES (stmt) = clauses;
8196 /* FIXME diagnostics: LOC below should be the actual location of
8197 this particular for block. We need to build a list of
8198 locations to go along with FOR_BLOCK. */
8199 stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
8201 for_block = TREE_CHAIN (for_block);
8207 #pragma omp for for-clause[optseq] new-line
8210 LOC is the location of the #pragma token.
8213 #define OMP_FOR_CLAUSE_MASK \
8214 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8215 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8216 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8217 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8218 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8219 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8220 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8221 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8224 c_parser_omp_for (location_t loc, c_parser *parser)
8226 tree block, clauses, ret;
8228 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8231 block = c_begin_compound_stmt (true);
8232 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8233 block = c_end_compound_stmt (loc, block, true);
8240 # pragma omp master new-line
8243 LOC is the location of the #pragma token.
8247 c_parser_omp_master (location_t loc, c_parser *parser)
8249 c_parser_skip_to_pragma_eol (parser);
8250 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8254 # pragma omp ordered new-line
8257 LOC is the location of the #pragma itself.
8261 c_parser_omp_ordered (location_t loc, c_parser *parser)
8263 c_parser_skip_to_pragma_eol (parser);
8264 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8270 { section-sequence }
8273 section-directive[opt] structured-block
8274 section-sequence section-directive structured-block
8276 SECTIONS_LOC is the location of the #pragma omp sections. */
8279 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8282 bool error_suppress = false;
8285 loc = c_parser_peek_token (parser)->location;
8286 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8288 /* Avoid skipping until the end of the block. */
8289 parser->error = false;
8293 stmt = push_stmt_list ();
8295 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8297 substmt = push_stmt_list ();
8301 c_parser_statement (parser);
8303 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8305 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8307 if (c_parser_next_token_is (parser, CPP_EOF))
8311 substmt = pop_stmt_list (substmt);
8312 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8313 SET_EXPR_LOCATION (substmt, loc);
8319 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8321 if (c_parser_next_token_is (parser, CPP_EOF))
8324 loc = c_parser_peek_token (parser)->location;
8325 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8327 c_parser_consume_pragma (parser);
8328 c_parser_skip_to_pragma_eol (parser);
8329 error_suppress = false;
8331 else if (!error_suppress)
8333 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8334 error_suppress = true;
8337 substmt = c_parser_omp_structured_block (parser);
8338 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8339 SET_EXPR_LOCATION (substmt, loc);
8342 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8343 "expected %<#pragma omp section%> or %<}%>");
8345 substmt = pop_stmt_list (stmt);
8347 stmt = make_node (OMP_SECTIONS);
8348 SET_EXPR_LOCATION (stmt, sections_loc);
8349 TREE_TYPE (stmt) = void_type_node;
8350 OMP_SECTIONS_BODY (stmt) = substmt;
8352 return add_stmt (stmt);
8356 # pragma omp sections sections-clause[optseq] newline
8359 LOC is the location of the #pragma token.
8362 #define OMP_SECTIONS_CLAUSE_MASK \
8363 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8364 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8365 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8366 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8367 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8370 c_parser_omp_sections (location_t loc, c_parser *parser)
8372 tree block, clauses, ret;
8374 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8375 "#pragma omp sections");
8377 block = c_begin_compound_stmt (true);
8378 ret = c_parser_omp_sections_scope (loc, parser);
8380 OMP_SECTIONS_CLAUSES (ret) = clauses;
8381 block = c_end_compound_stmt (loc, block, true);
8388 # pragma parallel parallel-clause new-line
8389 # pragma parallel for parallel-for-clause new-line
8390 # pragma parallel sections parallel-sections-clause new-line
8392 LOC is the location of the #pragma token.
8395 #define OMP_PARALLEL_CLAUSE_MASK \
8396 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8397 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8398 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8399 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8400 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8401 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8402 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8403 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8406 c_parser_omp_parallel (location_t loc, c_parser *parser)
8408 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8409 const char *p_name = "#pragma omp parallel";
8410 tree stmt, clauses, par_clause, ws_clause, block;
8411 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8413 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8415 c_parser_consume_token (parser);
8416 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8417 p_name = "#pragma omp parallel for";
8418 mask |= OMP_FOR_CLAUSE_MASK;
8419 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8421 else if (c_parser_next_token_is (parser, CPP_NAME))
8423 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8424 if (strcmp (p, "sections") == 0)
8426 c_parser_consume_token (parser);
8427 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8428 p_name = "#pragma omp parallel sections";
8429 mask |= OMP_SECTIONS_CLAUSE_MASK;
8430 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8434 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8438 case PRAGMA_OMP_PARALLEL:
8439 block = c_begin_omp_parallel ();
8440 c_parser_statement (parser);
8441 stmt = c_finish_omp_parallel (loc, clauses, block);
8444 case PRAGMA_OMP_PARALLEL_FOR:
8445 block = c_begin_omp_parallel ();
8446 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8447 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8448 stmt = c_finish_omp_parallel (loc, par_clause, block);
8449 OMP_PARALLEL_COMBINED (stmt) = 1;
8452 case PRAGMA_OMP_PARALLEL_SECTIONS:
8453 block = c_begin_omp_parallel ();
8454 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8455 stmt = c_parser_omp_sections_scope (loc, parser);
8457 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8458 stmt = c_finish_omp_parallel (loc, par_clause, block);
8459 OMP_PARALLEL_COMBINED (stmt) = 1;
8470 # pragma omp single single-clause[optseq] new-line
8473 LOC is the location of the #pragma.
8476 #define OMP_SINGLE_CLAUSE_MASK \
8477 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8478 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8479 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8480 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8483 c_parser_omp_single (location_t loc, c_parser *parser)
8485 tree stmt = make_node (OMP_SINGLE);
8486 SET_EXPR_LOCATION (stmt, loc);
8487 TREE_TYPE (stmt) = void_type_node;
8489 OMP_SINGLE_CLAUSES (stmt)
8490 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8491 "#pragma omp single");
8492 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8494 return add_stmt (stmt);
8498 # pragma omp task task-clause[optseq] new-line
8500 LOC is the location of the #pragma.
8503 #define OMP_TASK_CLAUSE_MASK \
8504 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8505 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8506 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8507 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8508 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8509 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8512 c_parser_omp_task (location_t loc, c_parser *parser)
8514 tree clauses, block;
8516 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8517 "#pragma omp task");
8519 block = c_begin_omp_task ();
8520 c_parser_statement (parser);
8521 return c_finish_omp_task (loc, clauses, block);
8525 # pragma omp taskwait new-line
8529 c_parser_omp_taskwait (c_parser *parser)
8531 location_t loc = c_parser_peek_token (parser)->location;
8532 c_parser_consume_pragma (parser);
8533 c_parser_skip_to_pragma_eol (parser);
8535 c_finish_omp_taskwait (loc);
8538 /* Main entry point to parsing most OpenMP pragmas. */
8541 c_parser_omp_construct (c_parser *parser)
8543 enum pragma_kind p_kind;
8547 loc = c_parser_peek_token (parser)->location;
8548 p_kind = c_parser_peek_token (parser)->pragma_kind;
8549 c_parser_consume_pragma (parser);
8553 case PRAGMA_OMP_ATOMIC:
8554 c_parser_omp_atomic (loc, parser);
8556 case PRAGMA_OMP_CRITICAL:
8557 stmt = c_parser_omp_critical (loc, parser);
8559 case PRAGMA_OMP_FOR:
8560 stmt = c_parser_omp_for (loc, parser);
8562 case PRAGMA_OMP_MASTER:
8563 stmt = c_parser_omp_master (loc, parser);
8565 case PRAGMA_OMP_ORDERED:
8566 stmt = c_parser_omp_ordered (loc, parser);
8568 case PRAGMA_OMP_PARALLEL:
8569 stmt = c_parser_omp_parallel (loc, parser);
8571 case PRAGMA_OMP_SECTIONS:
8572 stmt = c_parser_omp_sections (loc, parser);
8574 case PRAGMA_OMP_SINGLE:
8575 stmt = c_parser_omp_single (loc, parser);
8577 case PRAGMA_OMP_TASK:
8578 stmt = c_parser_omp_task (loc, parser);
8585 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
8590 # pragma omp threadprivate (variable-list) */
8593 c_parser_omp_threadprivate (c_parser *parser)
8598 c_parser_consume_pragma (parser);
8599 loc = c_parser_peek_token (parser)->location;
8600 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8602 /* Mark every variable in VARS to be assigned thread local storage. */
8603 for (t = vars; t; t = TREE_CHAIN (t))
8605 tree v = TREE_PURPOSE (t);
8607 /* FIXME diagnostics: Ideally we should keep individual
8608 locations for all the variables in the var list to make the
8609 following errors more precise. Perhaps
8610 c_parser_omp_var_list_parens() should construct a list of
8611 locations to go along with the var list. */
8613 /* If V had already been marked threadprivate, it doesn't matter
8614 whether it had been used prior to this point. */
8615 if (TREE_CODE (v) != VAR_DECL)
8616 error_at (loc, "%qD is not a variable", v);
8617 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8618 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
8619 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8620 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
8621 else if (TREE_TYPE (v) == error_mark_node)
8623 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8624 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
8627 if (! DECL_THREAD_LOCAL_P (v))
8629 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8630 /* If rtl has been already set for this var, call
8631 make_decl_rtl once again, so that encode_section_info
8632 has a chance to look at the new decl flags. */
8633 if (DECL_RTL_SET_P (v))
8636 C_DECL_THREADPRIVATE_P (v) = 1;
8640 c_parser_skip_to_pragma_eol (parser);
8644 /* Parse a single source file. */
8649 /* Use local storage to begin. If the first token is a pragma, parse it.
8650 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8651 which will cause garbage collection. */
8654 memset (&tparser, 0, sizeof tparser);
8655 the_parser = &tparser;
8657 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8658 c_parser_pragma_pch_preprocess (&tparser);
8660 the_parser = GGC_NEW (c_parser);
8661 *the_parser = tparser;
8663 /* Initialize EH, if we've been told to do so. */
8664 if (flag_exceptions)
8665 using_eh_for_cleanups ();
8667 c_parser_translation_unit (the_parser);
8671 #include "gt-c-parser.h"