1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
64 /* Initialization routine for this file. */
69 /* The only initialization required is of the reserved word
75 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
76 the c_token structure. */
77 gcc_assert (RID_MAX <= 255);
84 mask |= D_ASM | D_EXT;
88 if (!c_dialect_objc ())
89 mask |= D_OBJC | D_CXX_OBJC;
91 ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
92 for (i = 0; i < num_c_common_reswords; i++)
94 /* If a keyword is disabled, do not enter it into the table
95 and so create a canonical spelling that isn't a keyword. */
96 if (c_common_reswords[i].disable & mask)
99 && (c_common_reswords[i].disable & D_CXXWARN))
101 id = get_identifier (c_common_reswords[i].word);
102 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN);
103 C_IS_RESERVED_WORD (id) = 1;
108 id = get_identifier (c_common_reswords[i].word);
109 C_SET_RID_CODE (id, c_common_reswords[i].rid);
110 C_IS_RESERVED_WORD (id) = 1;
111 ridpointers [(int) c_common_reswords[i].rid] = id;
115 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
116 and the C parser. Unlike the C++ lexer, the parser structure
117 stores the lexer information instead of using a separate structure.
118 Identifiers are separated into ordinary identifiers, type names,
119 keywords and some other Objective-C types of identifiers, and some
120 look-ahead is maintained.
122 ??? It might be a good idea to lex the whole file up front (as for
123 C++). It would then be possible to share more of the C and C++
124 lexer code, if desired. */
126 /* The following local token type is used. */
129 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
131 /* More information about the type of a CPP_NAME token. */
132 typedef enum c_id_kind {
133 /* An ordinary identifier. */
135 /* An identifier declared as a typedef name. */
137 /* An identifier declared as an Objective-C class name. */
139 /* An address space identifier. */
141 /* Not an identifier. */
145 /* A single C token after string literal concatenation and conversion
146 of preprocessing tokens to tokens. */
147 typedef struct GTY (()) c_token {
148 /* The kind of token. */
149 ENUM_BITFIELD (cpp_ttype) type : 8;
150 /* If this token is a CPP_NAME, this value indicates whether also
151 declared as some kind of type. Otherwise, it is C_ID_NONE. */
152 ENUM_BITFIELD (c_id_kind) id_kind : 8;
153 /* If this token is a keyword, this value indicates which keyword.
154 Otherwise, this value is RID_MAX. */
155 ENUM_BITFIELD (rid) keyword : 8;
156 /* If this token is a CPP_PRAGMA, this indicates the pragma that
157 was seen. Otherwise it is PRAGMA_NONE. */
158 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
159 /* The location at which this token was found. */
161 /* The value associated with this token, if any. */
165 /* A parser structure recording information about the state and
166 context of parsing. Includes lexer information with up to two
167 tokens of look-ahead; more are not needed for C. */
168 typedef struct GTY(()) c_parser {
169 /* The look-ahead tokens. */
171 /* How many look-ahead tokens are available (0, 1 or 2). */
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error : 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma : 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block : 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string : 1;
184 /* Objective-C specific parser/lexer information. */
185 BOOL_BITFIELD objc_pq_context : 1;
186 /* The following flag is needed to contextualize Objective-C lexical
187 analysis. In some cases (e.g., 'int NSObject;'), it is
188 undesirable to bind an identifier to an Objective-C class, even
189 if a class with that name exists. */
190 BOOL_BITFIELD objc_need_raw_identifier : 1;
194 /* The actual parser and external interface. ??? Does this need to be
195 garbage-collected? */
197 static GTY (()) c_parser *the_parser;
200 /* Read in and lex a single token, storing it in *TOKEN. */
203 c_lex_one_token (c_parser *parser, c_token *token)
205 timevar_push (TV_LEX);
207 token->type = c_lex_with_flags (&token->value, &token->location, NULL,
208 (parser->lex_untranslated_string
209 ? C_LEX_STRING_NO_TRANSLATE : 0));
210 token->id_kind = C_ID_NONE;
211 token->keyword = RID_MAX;
212 token->pragma_kind = PRAGMA_NONE;
220 bool objc_force_identifier = parser->objc_need_raw_identifier;
221 if (c_dialect_objc ())
222 parser->objc_need_raw_identifier = false;
224 if (C_IS_RESERVED_WORD (token->value))
226 enum rid rid_code = C_RID_CODE (token->value);
228 if (rid_code == RID_CXX_COMPAT_WARN)
230 warning_at (token->location,
232 "identifier %qE conflicts with C++ keyword",
235 else if (rid_code >= RID_FIRST_ADDR_SPACE
236 && rid_code <= RID_LAST_ADDR_SPACE)
238 token->id_kind = C_ID_ADDRSPACE;
239 token->keyword = rid_code;
242 else if (c_dialect_objc ())
244 if (!objc_is_reserved_word (token->value)
245 && (!OBJC_IS_PQ_KEYWORD (rid_code)
246 || parser->objc_pq_context))
248 /* Return the canonical spelling for this keyword. */
249 token->value = ridpointers[(int) rid_code];
250 token->type = CPP_KEYWORD;
251 token->keyword = rid_code;
257 token->type = CPP_KEYWORD;
258 token->keyword = rid_code;
263 decl = lookup_name (token->value);
266 if (TREE_CODE (decl) == TYPE_DECL)
268 token->id_kind = C_ID_TYPENAME;
272 else if (c_dialect_objc ())
274 tree objc_interface_decl = objc_is_class_name (token->value);
275 /* Objective-C class names are in the same namespace as
276 variables and typedefs, and hence are shadowed by local
278 if (objc_interface_decl
279 && (global_bindings_p ()
280 || (!objc_force_identifier && !decl)))
282 token->value = objc_interface_decl;
283 token->id_kind = C_ID_CLASSNAME;
287 token->id_kind = C_ID_ID;
291 /* This only happens in Objective-C; it must be a keyword. */
292 token->type = CPP_KEYWORD;
293 token->keyword = C_RID_CODE (token->value);
297 case CPP_CLOSE_PAREN:
299 /* These tokens may affect the interpretation of any identifiers
300 following, if doing Objective-C. */
301 if (c_dialect_objc ())
302 parser->objc_need_raw_identifier = false;
305 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
306 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value);
312 timevar_pop (TV_LEX);
315 /* Return a pointer to the next token from PARSER, reading it in if
318 static inline c_token *
319 c_parser_peek_token (c_parser *parser)
321 if (parser->tokens_avail == 0)
323 c_lex_one_token (parser, &parser->tokens[0]);
324 parser->tokens_avail = 1;
326 return &parser->tokens[0];
329 /* Return true if the next token from PARSER has the indicated
333 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
335 return c_parser_peek_token (parser)->type == type;
338 /* Return true if the next token from PARSER does not have the
342 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
344 return !c_parser_next_token_is (parser, type);
347 /* Return true if the next token from PARSER is the indicated
351 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
353 return c_parser_peek_token (parser)->keyword == keyword;
356 /* Return true if TOKEN can start a type name,
359 c_token_starts_typename (c_token *token)
364 switch (token->id_kind)
373 gcc_assert (c_dialect_objc ());
379 switch (token->keyword)
411 if (c_dialect_objc ())
419 /* Return true if the next token from PARSER can start a type name,
422 c_parser_next_token_starts_typename (c_parser *parser)
424 c_token *token = c_parser_peek_token (parser);
425 return c_token_starts_typename (token);
428 /* Return true if TOKEN can start declaration specifiers, false
431 c_token_starts_declspecs (c_token *token)
436 switch (token->id_kind)
445 gcc_assert (c_dialect_objc ());
451 switch (token->keyword)
490 if (c_dialect_objc ())
498 /* Return true if the next token from PARSER can start declaration
499 specifiers, false otherwise. */
501 c_parser_next_token_starts_declspecs (c_parser *parser)
503 c_token *token = c_parser_peek_token (parser);
504 return c_token_starts_declspecs (token);
507 /* Return a pointer to the next-but-one token from PARSER, reading it
508 in if necessary. The next token is already read in. */
511 c_parser_peek_2nd_token (c_parser *parser)
513 if (parser->tokens_avail >= 2)
514 return &parser->tokens[1];
515 gcc_assert (parser->tokens_avail == 1);
516 gcc_assert (parser->tokens[0].type != CPP_EOF);
517 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL);
518 c_lex_one_token (parser, &parser->tokens[1]);
519 parser->tokens_avail = 2;
520 return &parser->tokens[1];
523 /* Consume the next token from PARSER. */
526 c_parser_consume_token (c_parser *parser)
528 gcc_assert (parser->tokens_avail >= 1);
529 gcc_assert (parser->tokens[0].type != CPP_EOF);
530 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL);
531 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA);
532 if (parser->tokens_avail == 2)
533 parser->tokens[0] = parser->tokens[1];
534 parser->tokens_avail--;
537 /* Expect the current token to be a #pragma. Consume it and remember
538 that we've begun parsing a pragma. */
541 c_parser_consume_pragma (c_parser *parser)
543 gcc_assert (!parser->in_pragma);
544 gcc_assert (parser->tokens_avail >= 1);
545 gcc_assert (parser->tokens[0].type == CPP_PRAGMA);
546 if (parser->tokens_avail == 2)
547 parser->tokens[0] = parser->tokens[1];
548 parser->tokens_avail--;
549 parser->in_pragma = true;
552 /* Update the globals input_location and in_system_header from
555 c_parser_set_source_position_from_token (c_token *token)
557 if (token->type != CPP_EOF)
559 input_location = token->location;
563 /* Issue a diagnostic of the form
564 FILE:LINE: MESSAGE before TOKEN
565 where TOKEN is the next token in the input stream of PARSER.
566 MESSAGE (specified by the caller) is usually of the form "expected
569 Do not issue a diagnostic if still recovering from an error.
571 ??? This is taken from the C++ parser, but building up messages in
572 this way is not i18n-friendly and some other approach should be
576 c_parser_error (c_parser *parser, const char *gmsgid)
578 c_token *token = c_parser_peek_token (parser);
581 parser->error = true;
584 /* This diagnostic makes more sense if it is tagged to the line of
585 the token we just peeked at. */
586 c_parser_set_source_position_from_token (token);
587 c_parse_error (gmsgid,
588 /* Because c_parse_error does not understand
589 CPP_KEYWORD, keywords are treated like
591 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
592 /* ??? The C parser does not save the cpp flags of a
593 token, we need to pass 0 here and we will not get
594 the source spelling of some tokens but rather the
595 canonical spelling. */
596 token->value, /*flags=*/0);
599 /* If the next token is of the indicated TYPE, consume it. Otherwise,
600 issue the error MSGID. If MSGID is NULL then a message has already
601 been produced and no message will be produced this time. Returns
602 true if found, false otherwise. */
605 c_parser_require (c_parser *parser,
609 if (c_parser_next_token_is (parser, type))
611 c_parser_consume_token (parser);
616 c_parser_error (parser, msgid);
621 /* If the next token is the indicated keyword, consume it. Otherwise,
622 issue the error MSGID. Returns true if found, false otherwise. */
625 c_parser_require_keyword (c_parser *parser,
629 if (c_parser_next_token_is_keyword (parser, keyword))
631 c_parser_consume_token (parser);
636 c_parser_error (parser, msgid);
641 /* Like c_parser_require, except that tokens will be skipped until the
642 desired token is found. An error message is still produced if the
643 next token is not as expected. If MSGID is NULL then a message has
644 already been produced and no message will be produced this
648 c_parser_skip_until_found (c_parser *parser,
652 unsigned nesting_depth = 0;
654 if (c_parser_require (parser, type, msgid))
657 /* Skip tokens until the desired token is found. */
660 /* Peek at the next token. */
661 c_token *token = c_parser_peek_token (parser);
662 /* If we've reached the token we want, consume it and stop. */
663 if (token->type == type && !nesting_depth)
665 c_parser_consume_token (parser);
669 /* If we've run out of tokens, stop. */
670 if (token->type == CPP_EOF)
672 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
674 if (token->type == CPP_OPEN_BRACE
675 || token->type == CPP_OPEN_PAREN
676 || token->type == CPP_OPEN_SQUARE)
678 else if (token->type == CPP_CLOSE_BRACE
679 || token->type == CPP_CLOSE_PAREN
680 || token->type == CPP_CLOSE_SQUARE)
682 if (nesting_depth-- == 0)
685 /* Consume this token. */
686 c_parser_consume_token (parser);
688 parser->error = false;
691 /* Skip tokens until the end of a parameter is found, but do not
692 consume the comma, semicolon or closing delimiter. */
695 c_parser_skip_to_end_of_parameter (c_parser *parser)
697 unsigned nesting_depth = 0;
701 c_token *token = c_parser_peek_token (parser);
702 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
705 /* If we've run out of tokens, stop. */
706 if (token->type == CPP_EOF)
708 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma)
710 if (token->type == CPP_OPEN_BRACE
711 || token->type == CPP_OPEN_PAREN
712 || token->type == CPP_OPEN_SQUARE)
714 else if (token->type == CPP_CLOSE_BRACE
715 || token->type == CPP_CLOSE_PAREN
716 || token->type == CPP_CLOSE_SQUARE)
718 if (nesting_depth-- == 0)
721 /* Consume this token. */
722 c_parser_consume_token (parser);
724 parser->error = false;
727 /* Expect to be at the end of the pragma directive and consume an
728 end of line marker. */
731 c_parser_skip_to_pragma_eol (c_parser *parser)
733 gcc_assert (parser->in_pragma);
734 parser->in_pragma = false;
736 if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
739 c_token *token = c_parser_peek_token (parser);
740 if (token->type == CPP_EOF)
742 if (token->type == CPP_PRAGMA_EOL)
744 c_parser_consume_token (parser);
747 c_parser_consume_token (parser);
750 parser->error = false;
753 /* Skip tokens until we have consumed an entire block, or until we
754 have consumed a non-nested ';'. */
757 c_parser_skip_to_end_of_block_or_statement (c_parser *parser)
759 unsigned nesting_depth = 0;
760 bool save_error = parser->error;
766 /* Peek at the next token. */
767 token = c_parser_peek_token (parser);
775 if (parser->in_pragma)
780 /* If the next token is a ';', we have reached the
781 end of the statement. */
784 /* Consume the ';'. */
785 c_parser_consume_token (parser);
790 case CPP_CLOSE_BRACE:
791 /* If the next token is a non-nested '}', then we have
792 reached the end of the current block. */
793 if (nesting_depth == 0 || --nesting_depth == 0)
795 c_parser_consume_token (parser);
801 /* If it the next token is a '{', then we are entering a new
802 block. Consume the entire block. */
807 /* If we see a pragma, consume the whole thing at once. We
808 have some safeguards against consuming pragmas willy-nilly.
809 Normally, we'd expect to be here with parser->error set,
810 which disables these safeguards. But it's possible to get
811 here for secondary error recovery, after parser->error has
813 c_parser_consume_pragma (parser);
814 c_parser_skip_to_pragma_eol (parser);
815 parser->error = save_error;
822 c_parser_consume_token (parser);
826 parser->error = false;
829 /* CPP's options (initialized by c-opts.c). */
830 extern cpp_options *cpp_opts;
832 /* Save the warning flags which are controlled by __extension__. */
835 disable_extension_diagnostics (void)
838 | (warn_pointer_arith << 1)
839 | (warn_traditional << 2)
841 | (warn_long_long << 4)
842 | (warn_cxx_compat << 5));
843 cpp_opts->pedantic = pedantic = 0;
844 warn_pointer_arith = 0;
845 cpp_opts->warn_traditional = warn_traditional = 0;
847 cpp_opts->warn_long_long = warn_long_long = 0;
852 /* Restore the warning flags which are controlled by __extension__.
853 FLAGS is the return value from disable_extension_diagnostics. */
856 restore_extension_diagnostics (int flags)
858 cpp_opts->pedantic = pedantic = flags & 1;
859 warn_pointer_arith = (flags >> 1) & 1;
860 cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1;
861 flag_iso = (flags >> 3) & 1;
862 cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1;
863 warn_cxx_compat = (flags >> 5) & 1;
866 /* Possibly kinds of declarator to parse. */
867 typedef enum c_dtr_syn {
868 /* A normal declarator with an identifier. */
870 /* An abstract declarator (maybe empty). */
872 /* A parameter declarator: may be either, but after a type name does
873 not redeclare a typedef name as an identifier if it can
874 alternatively be interpreted as a typedef name; see DR#009,
875 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
876 following DR#249. For example, given a typedef T, "int T" and
877 "int *T" are valid parameter declarations redeclaring T, while
878 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
879 abstract declarators rather than involving redundant parentheses;
880 the same applies with attributes inside the parentheses before
885 static void c_parser_external_declaration (c_parser *);
886 static void c_parser_asm_definition (c_parser *);
887 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool);
888 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
890 static struct c_typespec c_parser_enum_specifier (c_parser *);
891 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
892 static tree c_parser_struct_declaration (c_parser *);
893 static struct c_typespec c_parser_typeof_specifier (c_parser *);
894 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn,
896 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
898 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *,
900 struct c_declarator *);
901 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree);
902 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree);
903 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree);
904 static tree c_parser_simple_asm_expr (c_parser *);
905 static tree c_parser_attributes (c_parser *);
906 static struct c_type_name *c_parser_type_name (c_parser *);
907 static struct c_expr c_parser_initializer (c_parser *);
908 static struct c_expr c_parser_braced_init (c_parser *, tree, bool);
909 static void c_parser_initelt (c_parser *, struct obstack *);
910 static void c_parser_initval (c_parser *, struct c_expr *,
912 static tree c_parser_compound_statement (c_parser *);
913 static void c_parser_compound_statement_nostart (c_parser *);
914 static void c_parser_label (c_parser *);
915 static void c_parser_statement (c_parser *);
916 static void c_parser_statement_after_labels (c_parser *);
917 static void c_parser_if_statement (c_parser *);
918 static void c_parser_switch_statement (c_parser *);
919 static void c_parser_while_statement (c_parser *);
920 static void c_parser_do_statement (c_parser *);
921 static void c_parser_for_statement (c_parser *);
922 static tree c_parser_asm_statement (c_parser *);
923 static tree c_parser_asm_operands (c_parser *, bool);
924 static tree c_parser_asm_goto_operands (c_parser *);
925 static tree c_parser_asm_clobbers (c_parser *);
926 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
927 static struct c_expr c_parser_conditional_expression (c_parser *,
929 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
930 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
931 static struct c_expr c_parser_unary_expression (c_parser *);
932 static struct c_expr c_parser_sizeof_expression (c_parser *);
933 static struct c_expr c_parser_alignof_expression (c_parser *);
934 static struct c_expr c_parser_postfix_expression (c_parser *);
935 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *,
936 struct c_type_name *,
938 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *,
941 static struct c_expr c_parser_expression (c_parser *);
942 static struct c_expr c_parser_expression_conv (c_parser *);
943 static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool,
945 static void c_parser_omp_construct (c_parser *);
946 static void c_parser_omp_threadprivate (c_parser *);
947 static void c_parser_omp_barrier (c_parser *);
948 static void c_parser_omp_flush (c_parser *);
949 static void c_parser_omp_taskwait (c_parser *);
951 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
952 static bool c_parser_pragma (c_parser *, enum pragma_context);
954 /* These Objective-C parser functions are only ever called when
955 compiling Objective-C. */
956 static void c_parser_objc_class_definition (c_parser *);
957 static void c_parser_objc_class_instance_variables (c_parser *);
958 static void c_parser_objc_class_declaration (c_parser *);
959 static void c_parser_objc_alias_declaration (c_parser *);
960 static void c_parser_objc_protocol_definition (c_parser *);
961 static enum tree_code c_parser_objc_method_type (c_parser *);
962 static void c_parser_objc_method_definition (c_parser *);
963 static void c_parser_objc_methodprotolist (c_parser *);
964 static void c_parser_objc_methodproto (c_parser *);
965 static tree c_parser_objc_method_decl (c_parser *);
966 static tree c_parser_objc_type_name (c_parser *);
967 static tree c_parser_objc_protocol_refs (c_parser *);
968 static void c_parser_objc_try_catch_statement (c_parser *);
969 static void c_parser_objc_synchronized_statement (c_parser *);
970 static tree c_parser_objc_selector (c_parser *);
971 static tree c_parser_objc_selector_arg (c_parser *);
972 static tree c_parser_objc_receiver (c_parser *);
973 static tree c_parser_objc_message_args (c_parser *);
974 static tree c_parser_objc_keywordexpr (c_parser *);
976 /* Parse a translation unit (C90 6.7, C99 6.9).
979 external-declarations
981 external-declarations:
983 external-declarations external-declaration
992 c_parser_translation_unit (c_parser *parser)
994 if (c_parser_next_token_is (parser, CPP_EOF))
996 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
997 "ISO C forbids an empty translation unit");
1001 void *obstack_position = obstack_alloc (&parser_obstack, 0);
1002 mark_valid_location_for_stdc_pragma (false);
1006 c_parser_external_declaration (parser);
1007 obstack_free (&parser_obstack, obstack_position);
1009 while (c_parser_next_token_is_not (parser, CPP_EOF));
1013 /* Parse an external declaration (C90 6.7, C99 6.9).
1015 external-declaration:
1021 external-declaration:
1024 __extension__ external-declaration
1028 external-declaration:
1029 objc-class-definition
1030 objc-class-declaration
1031 objc-alias-declaration
1032 objc-protocol-definition
1033 objc-method-definition
1038 c_parser_external_declaration (c_parser *parser)
1041 switch (c_parser_peek_token (parser)->type)
1044 switch (c_parser_peek_token (parser)->keyword)
1047 ext = disable_extension_diagnostics ();
1048 c_parser_consume_token (parser);
1049 c_parser_external_declaration (parser);
1050 restore_extension_diagnostics (ext);
1053 c_parser_asm_definition (parser);
1055 case RID_AT_INTERFACE:
1056 case RID_AT_IMPLEMENTATION:
1057 gcc_assert (c_dialect_objc ());
1058 c_parser_objc_class_definition (parser);
1061 gcc_assert (c_dialect_objc ());
1062 c_parser_objc_class_declaration (parser);
1065 gcc_assert (c_dialect_objc ());
1066 c_parser_objc_alias_declaration (parser);
1068 case RID_AT_PROTOCOL:
1069 gcc_assert (c_dialect_objc ());
1070 c_parser_objc_protocol_definition (parser);
1073 gcc_assert (c_dialect_objc ());
1074 c_parser_consume_token (parser);
1075 objc_finish_implementation ();
1082 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1083 "ISO C does not allow extra %<;%> outside of a function");
1084 c_parser_consume_token (parser);
1087 mark_valid_location_for_stdc_pragma (true);
1088 c_parser_pragma (parser, pragma_external);
1089 mark_valid_location_for_stdc_pragma (false);
1093 if (c_dialect_objc ())
1095 c_parser_objc_method_definition (parser);
1098 /* Else fall through, and yield a syntax error trying to parse
1099 as a declaration or function definition. */
1102 /* A declaration or a function definition. We can only tell
1103 which after parsing the declaration specifiers, if any, and
1104 the first declarator. */
1105 c_parser_declaration_or_fndef (parser, true, true, false, true);
1111 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1112 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1113 accepted; otherwise (old-style parameter declarations) only other
1114 declarations are accepted. If NESTED is true, we are inside a
1115 function or parsing old-style parameter declarations; any functions
1116 encountered are nested functions and declaration specifiers are
1117 required; otherwise we are at top level and functions are normal
1118 functions and declaration specifiers may be optional. If EMPTY_OK
1119 is true, empty declarations are OK (subject to all other
1120 constraints); otherwise (old-style parameter declarations) they are
1121 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1122 may start with attributes; otherwise they may not.
1125 declaration-specifiers init-declarator-list[opt] ;
1127 function-definition:
1128 declaration-specifiers[opt] declarator declaration-list[opt]
1133 declaration-list declaration
1135 init-declarator-list:
1137 init-declarator-list , init-declarator
1140 declarator simple-asm-expr[opt] attributes[opt]
1141 declarator simple-asm-expr[opt] attributes[opt] = initializer
1145 nested-function-definition:
1146 declaration-specifiers declarator declaration-list[opt]
1149 The simple-asm-expr and attributes are GNU extensions.
1151 This function does not handle __extension__; that is handled in its
1152 callers. ??? Following the old parser, __extension__ may start
1153 external declarations, declarations in functions and declarations
1154 at the start of "for" loops, but not old-style parameter
1157 C99 requires declaration specifiers in a function definition; the
1158 absence is diagnosed through the diagnosis of implicit int. In GNU
1159 C we also allow but diagnose declarations without declaration
1160 specifiers, but only at top level (elsewhere they conflict with
1166 threadprivate-directive */
1169 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1170 bool nested, bool start_attr_ok)
1172 struct c_declspecs *specs;
1174 tree all_prefix_attrs;
1175 bool diagnosed_no_specs = false;
1176 location_t here = c_parser_peek_token (parser)->location;
1178 specs = build_null_declspecs ();
1179 c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1182 c_parser_skip_to_end_of_block_or_statement (parser);
1185 if (nested && !specs->declspecs_seen_p)
1187 c_parser_error (parser, "expected declaration specifiers");
1188 c_parser_skip_to_end_of_block_or_statement (parser);
1191 finish_declspecs (specs);
1192 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1198 shadow_tag_warned (specs, 1);
1199 pedwarn (here, 0, "empty declaration");
1201 c_parser_consume_token (parser);
1204 pending_xref_error ();
1205 prefix_attrs = specs->attrs;
1206 all_prefix_attrs = prefix_attrs;
1207 specs->attrs = NULL_TREE;
1210 struct c_declarator *declarator;
1213 /* Declaring either one or more declarators (in which case we
1214 should diagnose if there were no declaration specifiers) or a
1215 function definition (in which case the diagnostic for
1216 implicit int suffices). */
1217 declarator = c_parser_declarator (parser, specs->type_seen_p,
1218 C_DTR_NORMAL, &dummy);
1219 if (declarator == NULL)
1221 c_parser_skip_to_end_of_block_or_statement (parser);
1224 if (c_parser_next_token_is (parser, CPP_EQ)
1225 || c_parser_next_token_is (parser, CPP_COMMA)
1226 || c_parser_next_token_is (parser, CPP_SEMICOLON)
1227 || c_parser_next_token_is_keyword (parser, RID_ASM)
1228 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1230 tree asm_name = NULL_TREE;
1231 tree postfix_attrs = NULL_TREE;
1232 if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1234 diagnosed_no_specs = true;
1235 pedwarn (here, 0, "data definition has no type or storage class");
1237 /* Having seen a data definition, there cannot now be a
1238 function definition. */
1240 if (c_parser_next_token_is_keyword (parser, RID_ASM))
1241 asm_name = c_parser_simple_asm_expr (parser);
1242 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1243 postfix_attrs = c_parser_attributes (parser);
1244 if (c_parser_next_token_is (parser, CPP_EQ))
1248 location_t init_loc;
1249 c_parser_consume_token (parser);
1250 /* The declaration of the variable is in effect while
1251 its initializer is parsed. */
1252 d = start_decl (declarator, specs, true,
1253 chainon (postfix_attrs, all_prefix_attrs));
1255 d = error_mark_node;
1256 start_init (d, asm_name, global_bindings_p ());
1257 init_loc = c_parser_peek_token (parser)->location;
1258 init = c_parser_initializer (parser);
1260 if (d != error_mark_node)
1262 maybe_warn_string_init (TREE_TYPE (d), init);
1263 finish_decl (d, init_loc, init.value,
1264 init.original_type, asm_name);
1269 tree d = start_decl (declarator, specs, false,
1270 chainon (postfix_attrs,
1273 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
1274 NULL_TREE, asm_name);
1276 if (c_parser_next_token_is (parser, CPP_COMMA))
1278 c_parser_consume_token (parser);
1279 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1280 all_prefix_attrs = chainon (c_parser_attributes (parser),
1283 all_prefix_attrs = prefix_attrs;
1286 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1288 c_parser_consume_token (parser);
1293 c_parser_error (parser, "expected %<,%> or %<;%>");
1294 c_parser_skip_to_end_of_block_or_statement (parser);
1300 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1301 "%<asm%> or %<__attribute__%>");
1302 c_parser_skip_to_end_of_block_or_statement (parser);
1305 /* Function definition (nested or otherwise). */
1308 pedwarn (here, OPT_pedantic, "ISO C forbids nested functions");
1309 c_push_function_context ();
1311 if (!start_function (specs, declarator, all_prefix_attrs))
1313 /* This can appear in many cases looking nothing like a
1314 function definition, so we don't give a more specific
1315 error suggesting there was one. */
1316 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1317 "or %<__attribute__%>");
1319 c_pop_function_context ();
1322 /* Parse old-style parameter declarations. ??? Attributes are
1323 not allowed to start declaration specifiers here because of a
1324 syntax conflict between a function declaration with attribute
1325 suffix and a function definition with an attribute prefix on
1326 first old-style parameter declaration. Following the old
1327 parser, they are not accepted on subsequent old-style
1328 parameter declarations either. However, there is no
1329 ambiguity after the first declaration, nor indeed on the
1330 first as long as we don't allow postfix attributes after a
1331 declarator with a nonempty identifier list in a definition;
1332 and postfix attributes have never been accepted here in
1333 function definitions either. */
1334 while (c_parser_next_token_is_not (parser, CPP_EOF)
1335 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1336 c_parser_declaration_or_fndef (parser, false, false, true, false);
1337 store_parm_decls ();
1338 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
1339 = c_parser_peek_token (parser)->location;
1340 fnbody = c_parser_compound_statement (parser);
1343 tree decl = current_function_decl;
1344 /* Mark nested functions as needing static-chain initially.
1345 lower_nested_functions will recompute it but the
1346 DECL_STATIC_CHAIN flag is also used before that happens,
1347 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1348 DECL_STATIC_CHAIN (decl) = 1;
1351 c_pop_function_context ();
1352 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
1363 /* Parse an asm-definition (asm() outside a function body). This is a
1371 c_parser_asm_definition (c_parser *parser)
1373 tree asm_str = c_parser_simple_asm_expr (parser);
1375 cgraph_add_asm_node (asm_str);
1376 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
1379 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1380 6.7), adding them to SPECS (which may already include some).
1381 Storage class specifiers are accepted iff SCSPEC_OK; type
1382 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1383 the start iff START_ATTR_OK.
1385 declaration-specifiers:
1386 storage-class-specifier declaration-specifiers[opt]
1387 type-specifier declaration-specifiers[opt]
1388 type-qualifier declaration-specifiers[opt]
1389 function-specifier declaration-specifiers[opt]
1391 Function specifiers (inline) are from C99, and are currently
1392 handled as storage class specifiers, as is __thread.
1394 C90 6.5.1, C99 6.7.1:
1395 storage-class-specifier:
1406 C90 6.5.2, C99 6.7.2:
1419 [_Imaginary removed in C99 TC2]
1420 struct-or-union-specifier
1424 (_Bool and _Complex are new in C99.)
1426 C90 6.5.3, C99 6.7.3:
1432 address-space-qualifier
1434 (restrict is new in C99.)
1438 declaration-specifiers:
1439 attributes declaration-specifiers[opt]
1445 identifier recognized by the target
1447 storage-class-specifier:
1459 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1460 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1465 class-name objc-protocol-refs[opt]
1466 typedef-name objc-protocol-refs
1471 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
1472 bool scspec_ok, bool typespec_ok, bool start_attr_ok)
1474 bool attrs_ok = start_attr_ok;
1475 bool seen_type = specs->type_seen_p;
1476 while (c_parser_next_token_is (parser, CPP_NAME)
1477 || c_parser_next_token_is (parser, CPP_KEYWORD)
1478 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS)))
1480 struct c_typespec t;
1482 location_t loc = c_parser_peek_token (parser)->location;
1483 if (c_parser_next_token_is (parser, CPP_NAME))
1485 tree value = c_parser_peek_token (parser)->value;
1486 c_id_kind kind = c_parser_peek_token (parser)->id_kind;
1488 if (kind == C_ID_ADDRSPACE)
1491 = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE;
1492 declspecs_add_addrspace (specs, as);
1493 c_parser_consume_token (parser);
1498 /* This finishes the specifiers unless a type name is OK, it
1499 is declared as a type name and a type name hasn't yet
1501 if (!typespec_ok || seen_type
1502 || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME))
1504 c_parser_consume_token (parser);
1507 if (kind == C_ID_TYPENAME
1508 && (!c_dialect_objc ()
1509 || c_parser_next_token_is_not (parser, CPP_LESS)))
1511 t.kind = ctsk_typedef;
1512 /* For a typedef name, record the meaning, not the name.
1513 In case of 'foo foo, bar;'. */
1514 t.spec = lookup_name (value);
1516 t.expr_const_operands = true;
1520 tree proto = NULL_TREE;
1521 gcc_assert (c_dialect_objc ());
1523 if (c_parser_next_token_is (parser, CPP_LESS))
1524 proto = c_parser_objc_protocol_refs (parser);
1525 t.spec = objc_get_protocol_qualified_type (value, proto);
1527 t.expr_const_operands = true;
1529 declspecs_add_type (loc, specs, t);
1532 if (c_parser_next_token_is (parser, CPP_LESS))
1534 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1535 nisse@lysator.liu.se. */
1537 gcc_assert (c_dialect_objc ());
1538 if (!typespec_ok || seen_type)
1540 proto = c_parser_objc_protocol_refs (parser);
1542 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto);
1544 t.expr_const_operands = true;
1545 declspecs_add_type (loc, specs, t);
1548 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD));
1549 switch (c_parser_peek_token (parser)->keyword)
1561 /* TODO: Distinguish between function specifiers (inline)
1562 and storage class specifiers, either here or in
1563 declspecs_add_scspec. */
1564 declspecs_add_scspec (specs, c_parser_peek_token (parser)->value);
1565 c_parser_consume_token (parser);
1588 if (c_dialect_objc ())
1589 parser->objc_need_raw_identifier = true;
1590 t.kind = ctsk_resword;
1591 t.spec = c_parser_peek_token (parser)->value;
1593 t.expr_const_operands = true;
1594 declspecs_add_type (loc, specs, t);
1595 c_parser_consume_token (parser);
1602 t = c_parser_enum_specifier (parser);
1603 declspecs_add_type (loc, specs, t);
1611 t = c_parser_struct_or_union_specifier (parser);
1612 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec);
1613 declspecs_add_type (loc, specs, t);
1616 /* ??? The old parser rejected typeof after other type
1617 specifiers, but is a syntax error the best way of
1619 if (!typespec_ok || seen_type)
1623 t = c_parser_typeof_specifier (parser);
1624 declspecs_add_type (loc, specs, t);
1630 declspecs_add_qual (specs, c_parser_peek_token (parser)->value);
1631 c_parser_consume_token (parser);
1636 attrs = c_parser_attributes (parser);
1637 declspecs_add_attrs (specs, attrs);
1646 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1649 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1650 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1651 enum attributes[opt] identifier
1653 The form with trailing comma is new in C99. The forms with
1654 attributes are GNU extensions. In GNU C, we accept any expression
1655 without commas in the syntax (assignment expressions, not just
1656 conditional expressions); assignment expressions will be diagnosed
1661 enumerator-list , enumerator
1664 enumeration-constant
1665 enumeration-constant = constant-expression
1668 static struct c_typespec
1669 c_parser_enum_specifier (c_parser *parser)
1671 struct c_typespec ret;
1673 tree ident = NULL_TREE;
1674 location_t enum_loc;
1675 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1676 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
1677 enum_loc = c_parser_peek_token (parser)->location;
1678 c_parser_consume_token (parser);
1679 attrs = c_parser_attributes (parser);
1680 enum_loc = c_parser_peek_token (parser)->location;
1681 /* Set the location in case we create a decl now. */
1682 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1683 if (c_parser_next_token_is (parser, CPP_NAME))
1685 ident = c_parser_peek_token (parser)->value;
1686 ident_loc = c_parser_peek_token (parser)->location;
1687 enum_loc = ident_loc;
1688 c_parser_consume_token (parser);
1690 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1692 /* Parse an enum definition. */
1693 struct c_enum_contents the_enum;
1694 tree type = start_enum (enum_loc, &the_enum, ident);
1696 /* We chain the enumerators in reverse order, then put them in
1697 forward order at the end. */
1698 tree values = NULL_TREE;
1699 c_parser_consume_token (parser);
1707 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */
1708 location_t value_loc;
1709 if (c_parser_next_token_is_not (parser, CPP_NAME))
1711 c_parser_error (parser, "expected identifier");
1712 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1713 values = error_mark_node;
1716 token = c_parser_peek_token (parser);
1717 enum_id = token->value;
1718 /* Set the location in case we create a decl now. */
1719 c_parser_set_source_position_from_token (token);
1720 value_loc = token->location;
1721 c_parser_consume_token (parser);
1722 if (c_parser_next_token_is (parser, CPP_EQ))
1724 c_parser_consume_token (parser);
1725 value_loc = c_parser_peek_token (parser)->location;
1726 enum_value = c_parser_expr_no_commas (parser, NULL).value;
1729 enum_value = NULL_TREE;
1730 enum_decl = build_enumerator (value_loc,
1731 &the_enum, enum_id, enum_value);
1732 TREE_CHAIN (enum_decl) = values;
1735 if (c_parser_next_token_is (parser, CPP_COMMA))
1737 comma_loc = c_parser_peek_token (parser)->location;
1739 c_parser_consume_token (parser);
1741 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1743 if (seen_comma && !flag_isoc99)
1744 pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list");
1745 c_parser_consume_token (parser);
1750 c_parser_error (parser, "expected %<,%> or %<}%>");
1751 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1752 values = error_mark_node;
1756 postfix_attrs = c_parser_attributes (parser);
1757 ret.spec = finish_enum (type, nreverse (values),
1758 chainon (attrs, postfix_attrs));
1759 ret.kind = ctsk_tagdef;
1760 ret.expr = NULL_TREE;
1761 ret.expr_const_operands = true;
1766 c_parser_error (parser, "expected %<{%>");
1767 ret.spec = error_mark_node;
1768 ret.kind = ctsk_tagref;
1769 ret.expr = NULL_TREE;
1770 ret.expr_const_operands = true;
1773 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident);
1774 /* In ISO C, enumerated types can be referred to only if already
1776 if (pedantic && !COMPLETE_TYPE_P (ret.spec))
1779 pedwarn (enum_loc, OPT_pedantic,
1780 "ISO C forbids forward references to %<enum%> types");
1785 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1787 struct-or-union-specifier:
1788 struct-or-union attributes[opt] identifier[opt]
1789 { struct-contents } attributes[opt]
1790 struct-or-union attributes[opt] identifier
1793 struct-declaration-list
1795 struct-declaration-list:
1796 struct-declaration ;
1797 struct-declaration-list struct-declaration ;
1804 struct-declaration-list struct-declaration
1806 struct-declaration-list:
1807 struct-declaration-list ;
1810 (Note that in the syntax here, unlike that in ISO C, the semicolons
1811 are included here rather than in struct-declaration, in order to
1812 describe the syntax with extra semicolons and missing semicolon at
1817 struct-declaration-list:
1818 @defs ( class-name )
1820 (Note this does not include a trailing semicolon, but can be
1821 followed by further declarations, and gets a pedwarn-if-pedantic
1822 when followed by a semicolon.) */
1824 static struct c_typespec
1825 c_parser_struct_or_union_specifier (c_parser *parser)
1827 struct c_typespec ret;
1829 tree ident = NULL_TREE;
1830 location_t struct_loc;
1831 location_t ident_loc = UNKNOWN_LOCATION;
1832 enum tree_code code;
1833 switch (c_parser_peek_token (parser)->keyword)
1844 struct_loc = c_parser_peek_token (parser)->location;
1845 c_parser_consume_token (parser);
1846 attrs = c_parser_attributes (parser);
1848 /* Set the location in case we create a decl now. */
1849 c_parser_set_source_position_from_token (c_parser_peek_token (parser));
1851 if (c_parser_next_token_is (parser, CPP_NAME))
1853 ident = c_parser_peek_token (parser)->value;
1854 ident_loc = c_parser_peek_token (parser)->location;
1855 struct_loc = ident_loc;
1856 c_parser_consume_token (parser);
1858 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
1860 /* Parse a struct or union definition. Start the scope of the
1861 tag before parsing components. */
1862 struct c_struct_parse_info *struct_info;
1863 tree type = start_struct (struct_loc, code, ident, &struct_info);
1865 /* We chain the components in reverse order, then put them in
1866 forward order at the end. Each struct-declaration may
1867 declare multiple components (comma-separated), so we must use
1868 chainon to join them, although when parsing each
1869 struct-declaration we can use TREE_CHAIN directly.
1871 The theory behind all this is that there will be more
1872 semicolon separated fields than comma separated fields, and
1873 so we'll be minimizing the number of node traversals required
1875 tree contents = NULL_TREE;
1876 c_parser_consume_token (parser);
1877 /* Handle the Objective-C @defs construct,
1878 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1879 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS))
1882 gcc_assert (c_dialect_objc ());
1883 c_parser_consume_token (parser);
1884 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
1886 if (c_parser_next_token_is (parser, CPP_NAME)
1887 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
1889 name = c_parser_peek_token (parser)->value;
1890 c_parser_consume_token (parser);
1894 c_parser_error (parser, "expected class name");
1895 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
1898 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
1900 contents = nreverse (objc_get_class_ivars (name));
1903 /* Parse the struct-declarations and semicolons. Problems with
1904 semicolons are diagnosed here; empty structures are diagnosed
1909 /* Parse any stray semicolon. */
1910 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1912 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
1913 "extra semicolon in struct or union specified");
1914 c_parser_consume_token (parser);
1917 /* Stop if at the end of the struct or union contents. */
1918 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1920 c_parser_consume_token (parser);
1923 /* Accept #pragmas at struct scope. */
1924 if (c_parser_next_token_is (parser, CPP_PRAGMA))
1926 c_parser_pragma (parser, pragma_external);
1929 /* Parse some comma-separated declarations, but not the
1930 trailing semicolon if any. */
1931 decls = c_parser_struct_declaration (parser);
1932 contents = chainon (decls, contents);
1933 /* If no semicolon follows, either we have a parse error or
1934 are at the end of the struct or union and should
1936 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1937 c_parser_consume_token (parser);
1940 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
1941 pedwarn (c_parser_peek_token (parser)->location, 0,
1942 "no semicolon at end of struct or union");
1945 c_parser_error (parser, "expected %<;%>");
1946 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
1951 postfix_attrs = c_parser_attributes (parser);
1952 ret.spec = finish_struct (struct_loc, type, nreverse (contents),
1953 chainon (attrs, postfix_attrs), struct_info);
1954 ret.kind = ctsk_tagdef;
1955 ret.expr = NULL_TREE;
1956 ret.expr_const_operands = true;
1961 c_parser_error (parser, "expected %<{%>");
1962 ret.spec = error_mark_node;
1963 ret.kind = ctsk_tagref;
1964 ret.expr = NULL_TREE;
1965 ret.expr_const_operands = true;
1968 ret = parser_xref_tag (ident_loc, code, ident);
1972 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1973 the trailing semicolon.
1976 specifier-qualifier-list struct-declarator-list
1978 specifier-qualifier-list:
1979 type-specifier specifier-qualifier-list[opt]
1980 type-qualifier specifier-qualifier-list[opt]
1981 attributes specifier-qualifier-list[opt]
1983 struct-declarator-list:
1985 struct-declarator-list , attributes[opt] struct-declarator
1988 declarator attributes[opt]
1989 declarator[opt] : constant-expression attributes[opt]
1994 __extension__ struct-declaration
1995 specifier-qualifier-list
1997 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1998 of attributes where shown is a GNU extension. In GNU C, we accept
1999 any expression without commas in the syntax (assignment
2000 expressions, not just conditional expressions); assignment
2001 expressions will be diagnosed as non-constant. */
2004 c_parser_struct_declaration (c_parser *parser)
2006 struct c_declspecs *specs;
2008 tree all_prefix_attrs;
2010 location_t decl_loc;
2011 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
2015 ext = disable_extension_diagnostics ();
2016 c_parser_consume_token (parser);
2017 decl = c_parser_struct_declaration (parser);
2018 restore_extension_diagnostics (ext);
2021 specs = build_null_declspecs ();
2022 decl_loc = c_parser_peek_token (parser)->location;
2023 c_parser_declspecs (parser, specs, false, true, true);
2026 if (!specs->declspecs_seen_p)
2028 c_parser_error (parser, "expected specifier-qualifier-list");
2031 finish_declspecs (specs);
2032 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2035 if (!specs->type_seen_p)
2037 pedwarn (decl_loc, OPT_pedantic,
2038 "ISO C forbids member declarations with no members");
2039 shadow_tag_warned (specs, pedantic);
2044 /* Support for unnamed structs or unions as members of
2045 structs or unions (which is [a] useful and [b] supports
2049 ret = grokfield (c_parser_peek_token (parser)->location,
2050 build_id_declarator (NULL_TREE), specs,
2053 decl_attributes (&ret, attrs, 0);
2057 pending_xref_error ();
2058 prefix_attrs = specs->attrs;
2059 all_prefix_attrs = prefix_attrs;
2060 specs->attrs = NULL_TREE;
2064 /* Declaring one or more declarators or un-named bit-fields. */
2065 struct c_declarator *declarator;
2067 if (c_parser_next_token_is (parser, CPP_COLON))
2068 declarator = build_id_declarator (NULL_TREE);
2070 declarator = c_parser_declarator (parser, specs->type_seen_p,
2071 C_DTR_NORMAL, &dummy);
2072 if (declarator == NULL)
2074 c_parser_skip_to_end_of_block_or_statement (parser);
2077 if (c_parser_next_token_is (parser, CPP_COLON)
2078 || c_parser_next_token_is (parser, CPP_COMMA)
2079 || c_parser_next_token_is (parser, CPP_SEMICOLON)
2080 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
2081 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2083 tree postfix_attrs = NULL_TREE;
2084 tree width = NULL_TREE;
2086 if (c_parser_next_token_is (parser, CPP_COLON))
2088 c_parser_consume_token (parser);
2089 width = c_parser_expr_no_commas (parser, NULL).value;
2091 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2092 postfix_attrs = c_parser_attributes (parser);
2093 d = grokfield (c_parser_peek_token (parser)->location,
2094 declarator, specs, width, &all_prefix_attrs);
2095 decl_attributes (&d, chainon (postfix_attrs,
2096 all_prefix_attrs), 0);
2097 TREE_CHAIN (d) = decls;
2099 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2100 all_prefix_attrs = chainon (c_parser_attributes (parser),
2103 all_prefix_attrs = prefix_attrs;
2104 if (c_parser_next_token_is (parser, CPP_COMMA))
2105 c_parser_consume_token (parser);
2106 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
2107 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
2109 /* Semicolon consumed in caller. */
2114 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
2120 c_parser_error (parser,
2121 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2122 "%<__attribute__%>");
2129 /* Parse a typeof specifier (a GNU extension).
2132 typeof ( expression )
2133 typeof ( type-name )
2136 static struct c_typespec
2137 c_parser_typeof_specifier (c_parser *parser)
2139 struct c_typespec ret;
2140 ret.kind = ctsk_typeof;
2141 ret.spec = error_mark_node;
2142 ret.expr = NULL_TREE;
2143 ret.expr_const_operands = true;
2144 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
2145 c_parser_consume_token (parser);
2146 c_inhibit_evaluation_warnings++;
2148 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2150 c_inhibit_evaluation_warnings--;
2154 if (c_parser_next_token_starts_typename (parser))
2156 struct c_type_name *type = c_parser_type_name (parser);
2157 c_inhibit_evaluation_warnings--;
2161 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands);
2162 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE));
2168 location_t here = c_parser_peek_token (parser)->location;
2169 struct c_expr expr = c_parser_expression (parser);
2170 c_inhibit_evaluation_warnings--;
2172 if (TREE_CODE (expr.value) == COMPONENT_REF
2173 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
2174 error_at (here, "%<typeof%> applied to a bit-field");
2175 mark_exp_read (expr.value);
2176 ret.spec = TREE_TYPE (expr.value);
2177 was_vm = variably_modified_type_p (ret.spec, NULL_TREE);
2178 /* This is returned with the type so that when the type is
2179 evaluated, this can be evaluated. */
2181 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
2182 pop_maybe_used (was_vm);
2184 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
2188 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2189 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2190 be redeclared; otherwise it may not. KIND indicates which kind of
2191 declarator is wanted. Returns a valid declarator except in the
2192 case of a syntax error in which case NULL is returned. *SEEN_ID is
2193 set to true if an identifier being declared is seen; this is used
2194 to diagnose bad forms of abstract array declarators and to
2195 determine whether an identifier list is syntactically permitted.
2198 pointer[opt] direct-declarator
2202 ( attributes[opt] declarator )
2203 direct-declarator array-declarator
2204 direct-declarator ( parameter-type-list )
2205 direct-declarator ( identifier-list[opt] )
2208 * type-qualifier-list[opt]
2209 * type-qualifier-list[opt] pointer
2211 type-qualifier-list:
2214 type-qualifier-list type-qualifier
2215 type-qualifier-list attributes
2217 parameter-type-list:
2219 parameter-list , ...
2222 parameter-declaration
2223 parameter-list , parameter-declaration
2225 parameter-declaration:
2226 declaration-specifiers declarator attributes[opt]
2227 declaration-specifiers abstract-declarator[opt] attributes[opt]
2231 identifier-list , identifier
2233 abstract-declarator:
2235 pointer[opt] direct-abstract-declarator
2237 direct-abstract-declarator:
2238 ( attributes[opt] abstract-declarator )
2239 direct-abstract-declarator[opt] array-declarator
2240 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2245 direct-declarator ( parameter-forward-declarations
2246 parameter-type-list[opt] )
2248 direct-abstract-declarator:
2249 direct-abstract-declarator[opt] ( parameter-forward-declarations
2250 parameter-type-list[opt] )
2252 parameter-forward-declarations:
2254 parameter-forward-declarations parameter-list ;
2256 The uses of attributes shown above are GNU extensions.
2258 Some forms of array declarator are not included in C99 in the
2259 syntax for abstract declarators; these are disallowed elsewhere.
2260 This may be a defect (DR#289).
2262 This function also accepts an omitted abstract declarator as being
2263 an abstract declarator, although not part of the formal syntax. */
2265 static struct c_declarator *
2266 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2269 /* Parse any initial pointer part. */
2270 if (c_parser_next_token_is (parser, CPP_MULT))
2272 struct c_declspecs *quals_attrs = build_null_declspecs ();
2273 struct c_declarator *inner;
2274 c_parser_consume_token (parser);
2275 c_parser_declspecs (parser, quals_attrs, false, false, true);
2276 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2280 return make_pointer_declarator (quals_attrs, inner);
2282 /* Now we have a direct declarator, direct abstract declarator or
2283 nothing (which counts as a direct abstract declarator here). */
2284 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id);
2287 /* Parse a direct declarator or direct abstract declarator; arguments
2288 as c_parser_declarator. */
2290 static struct c_declarator *
2291 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
2294 /* The direct declarator must start with an identifier (possibly
2295 omitted) or a parenthesized declarator (possibly abstract). In
2296 an ordinary declarator, initial parentheses must start a
2297 parenthesized declarator. In an abstract declarator or parameter
2298 declarator, they could start a parenthesized declarator or a
2299 parameter list. To tell which, the open parenthesis and any
2300 following attributes must be read. If a declaration specifier
2301 follows, then it is a parameter list; if the specifier is a
2302 typedef name, there might be an ambiguity about redeclaring it,
2303 which is resolved in the direction of treating it as a typedef
2304 name. If a close parenthesis follows, it is also an empty
2305 parameter list, as the syntax does not permit empty abstract
2306 declarators. Otherwise, it is a parenthesized declarator (in
2307 which case the analysis may be repeated inside it, recursively).
2309 ??? There is an ambiguity in a parameter declaration "int
2310 (__attribute__((foo)) x)", where x is not a typedef name: it
2311 could be an abstract declarator for a function, or declare x with
2312 parentheses. The proper resolution of this ambiguity needs
2313 documenting. At present we follow an accident of the old
2314 parser's implementation, whereby the first parameter must have
2315 some declaration specifiers other than just attributes. Thus as
2316 a parameter declaration it is treated as a parenthesized
2317 parameter named x, and as an abstract declarator it is
2320 ??? Also following the old parser, attributes inside an empty
2321 parameter list are ignored, making it a list not yielding a
2322 prototype, rather than giving an error or making it have one
2323 parameter with implicit type int.
2325 ??? Also following the old parser, typedef names may be
2326 redeclared in declarators, but not Objective-C class names. */
2328 if (kind != C_DTR_ABSTRACT
2329 && c_parser_next_token_is (parser, CPP_NAME)
2331 && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME)
2332 || c_parser_peek_token (parser)->id_kind == C_ID_ID))
2334 struct c_declarator *inner
2335 = build_id_declarator (c_parser_peek_token (parser)->value);
2337 inner->id_loc = c_parser_peek_token (parser)->location;
2338 c_parser_consume_token (parser);
2339 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2342 if (kind != C_DTR_NORMAL
2343 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2345 struct c_declarator *inner = build_id_declarator (NULL_TREE);
2346 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2349 /* Either we are at the end of an abstract declarator, or we have
2352 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2355 struct c_declarator *inner;
2356 c_parser_consume_token (parser);
2357 attrs = c_parser_attributes (parser);
2358 if (kind != C_DTR_NORMAL
2359 && (c_parser_next_token_starts_declspecs (parser)
2360 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN)))
2362 struct c_arg_info *args
2363 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL,
2370 = build_function_declarator (args,
2371 build_id_declarator (NULL_TREE));
2372 return c_parser_direct_declarator_inner (parser, *seen_id,
2376 /* A parenthesized declarator. */
2377 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id);
2378 if (inner != NULL && attrs != NULL)
2379 inner = build_attrs_declarator (attrs, inner);
2380 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2382 c_parser_consume_token (parser);
2386 return c_parser_direct_declarator_inner (parser, *seen_id, inner);
2390 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2397 if (kind == C_DTR_NORMAL)
2399 c_parser_error (parser, "expected identifier or %<(%>");
2403 return build_id_declarator (NULL_TREE);
2407 /* Parse part of a direct declarator or direct abstract declarator,
2408 given that some (in INNER) has already been parsed; ID_PRESENT is
2409 true if an identifier is present, false for an abstract
2412 static struct c_declarator *
2413 c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
2414 struct c_declarator *inner)
2416 /* Parse a sequence of array declarators and parameter lists. */
2417 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
2419 location_t brace_loc = c_parser_peek_token (parser)->location;
2420 struct c_declarator *declarator;
2421 struct c_declspecs *quals_attrs = build_null_declspecs ();
2425 c_parser_consume_token (parser);
2426 c_parser_declspecs (parser, quals_attrs, false, false, true);
2427 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC);
2429 c_parser_consume_token (parser);
2430 if (static_seen && !quals_attrs->declspecs_seen_p)
2431 c_parser_declspecs (parser, quals_attrs, false, false, true);
2432 if (!quals_attrs->declspecs_seen_p)
2434 /* If "static" is present, there must be an array dimension.
2435 Otherwise, there may be a dimension, "*", or no
2440 dimen = c_parser_expr_no_commas (parser, NULL).value;
2444 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2449 else if (c_parser_next_token_is (parser, CPP_MULT))
2451 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE)
2455 c_parser_consume_token (parser);
2460 dimen = c_parser_expr_no_commas (parser, NULL).value;
2466 dimen = c_parser_expr_no_commas (parser, NULL).value;
2469 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
2470 c_parser_consume_token (parser);
2473 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
2477 declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
2478 static_seen, star_seen);
2479 if (declarator == NULL)
2481 inner = set_array_declarator_inner (declarator, inner);
2482 return c_parser_direct_declarator_inner (parser, id_present, inner);
2484 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
2487 struct c_arg_info *args;
2488 c_parser_consume_token (parser);
2489 attrs = c_parser_attributes (parser);
2490 args = c_parser_parms_declarator (parser, id_present, attrs);
2495 inner = build_function_declarator (args, inner);
2496 return c_parser_direct_declarator_inner (parser, id_present, inner);
2502 /* Parse a parameter list or identifier list, including the closing
2503 parenthesis but not the opening one. ATTRS are the attributes at
2504 the start of the list. ID_LIST_OK is true if an identifier list is
2505 acceptable; such a list must not have attributes at the start. */
2507 static struct c_arg_info *
2508 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
2511 declare_parm_level ();
2512 /* If the list starts with an identifier, it is an identifier list.
2513 Otherwise, it is either a prototype list or an empty list. */
2516 && c_parser_next_token_is (parser, CPP_NAME)
2517 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2519 tree list = NULL_TREE, *nextp = &list;
2520 while (c_parser_next_token_is (parser, CPP_NAME)
2521 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
2523 *nextp = build_tree_list (NULL_TREE,
2524 c_parser_peek_token (parser)->value);
2525 nextp = & TREE_CHAIN (*nextp);
2526 c_parser_consume_token (parser);
2527 if (c_parser_next_token_is_not (parser, CPP_COMMA))
2529 c_parser_consume_token (parser);
2530 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2532 c_parser_error (parser, "expected identifier");
2536 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2538 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2543 ret->pending_sizes = 0;
2544 ret->had_vla_unspec = 0;
2545 c_parser_consume_token (parser);
2551 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2559 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs);
2565 /* Parse a parameter list (possibly empty), including the closing
2566 parenthesis but not the opening one. ATTRS are the attributes at
2567 the start of the list. */
2569 static struct c_arg_info *
2570 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
2572 bool good_parm = false;
2573 /* ??? Following the old parser, forward parameter declarations may
2574 use abstract declarators, and if no real parameter declarations
2575 follow the forward declarations then this is not diagnosed. Also
2576 note as above that attributes are ignored as the only contents of
2577 the parentheses, or as the only contents after forward
2579 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2581 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2586 ret->pending_sizes = 0;
2587 ret->had_vla_unspec = 0;
2588 c_parser_consume_token (parser);
2591 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2593 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
2597 ret->pending_sizes = 0;
2598 ret->had_vla_unspec = 0;
2599 /* Suppress -Wold-style-definition for this case. */
2600 ret->types = error_mark_node;
2601 error_at (c_parser_peek_token (parser)->location,
2602 "ISO C requires a named argument before %<...%>");
2603 c_parser_consume_token (parser);
2604 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2606 c_parser_consume_token (parser);
2611 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2616 /* Nonempty list of parameters, either terminated with semicolon
2617 (forward declarations; recurse) or with close parenthesis (normal
2618 function) or with ", ... )" (variadic function). */
2621 /* Parse a parameter. */
2622 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
2627 push_parm_decl (parm);
2629 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
2632 c_parser_consume_token (parser);
2633 mark_forward_parm_decls ();
2634 new_attrs = c_parser_attributes (parser);
2635 return c_parser_parms_list_declarator (parser, new_attrs);
2637 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2639 c_parser_consume_token (parser);
2641 return get_parm_info (false);
2644 struct c_arg_info *ret
2645 = XOBNEW (&parser_obstack, struct c_arg_info);
2650 ret->pending_sizes = 0;
2651 ret->had_vla_unspec = 0;
2655 if (!c_parser_require (parser, CPP_COMMA,
2656 "expected %<;%>, %<,%> or %<)%>"))
2658 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2659 get_pending_sizes ();
2662 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
2664 c_parser_consume_token (parser);
2665 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2667 c_parser_consume_token (parser);
2669 return get_parm_info (true);
2672 struct c_arg_info *ret
2673 = XOBNEW (&parser_obstack, struct c_arg_info);
2678 ret->pending_sizes = 0;
2679 ret->had_vla_unspec = 0;
2685 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2687 get_pending_sizes ();
2694 /* Parse a parameter declaration. ATTRS are the attributes at the
2695 start of the declaration if it is the first parameter. */
2697 static struct c_parm *
2698 c_parser_parameter_declaration (c_parser *parser, tree attrs)
2700 struct c_declspecs *specs;
2701 struct c_declarator *declarator;
2703 tree postfix_attrs = NULL_TREE;
2705 if (!c_parser_next_token_starts_declspecs (parser))
2707 /* ??? In some Objective-C cases '...' isn't applicable so there
2708 should be a different message. */
2709 c_parser_error (parser,
2710 "expected declaration specifiers or %<...%>");
2711 c_parser_skip_to_end_of_parameter (parser);
2714 specs = build_null_declspecs ();
2717 declspecs_add_attrs (specs, attrs);
2720 c_parser_declspecs (parser, specs, true, true, true);
2721 finish_declspecs (specs);
2722 pending_xref_error ();
2723 prefix_attrs = specs->attrs;
2724 specs->attrs = NULL_TREE;
2725 declarator = c_parser_declarator (parser, specs->type_seen_p,
2726 C_DTR_PARM, &dummy);
2727 if (declarator == NULL)
2729 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
2732 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2733 postfix_attrs = c_parser_attributes (parser);
2734 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs),
2738 /* Parse a string literal in an asm expression. It should not be
2739 translated, and wide string literals are an error although
2740 permitted by the syntax. This is a GNU extension.
2745 ??? At present, following the old parser, the caller needs to have
2746 set lex_untranslated_string to 1. It would be better to follow the
2747 C++ parser rather than using this kludge. */
2750 c_parser_asm_string_literal (c_parser *parser)
2753 if (c_parser_next_token_is (parser, CPP_STRING))
2755 str = c_parser_peek_token (parser)->value;
2756 c_parser_consume_token (parser);
2758 else if (c_parser_next_token_is (parser, CPP_WSTRING))
2760 error_at (c_parser_peek_token (parser)->location,
2761 "wide string literal in %<asm%>");
2762 str = build_string (1, "");
2763 c_parser_consume_token (parser);
2767 c_parser_error (parser, "expected string literal");
2773 /* Parse a simple asm expression. This is used in restricted
2774 contexts, where a full expression with inputs and outputs does not
2775 make sense. This is a GNU extension.
2778 asm ( asm-string-literal )
2782 c_parser_simple_asm_expr (c_parser *parser)
2785 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
2786 /* ??? Follow the C++ parser rather than using the
2787 lex_untranslated_string kludge. */
2788 parser->lex_untranslated_string = true;
2789 c_parser_consume_token (parser);
2790 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2792 parser->lex_untranslated_string = false;
2795 str = c_parser_asm_string_literal (parser);
2796 parser->lex_untranslated_string = false;
2797 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
2799 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2805 /* Parse (possibly empty) attributes. This is a GNU extension.
2809 attributes attribute
2812 __attribute__ ( ( attribute-list ) )
2816 attribute_list , attrib
2821 any-word ( identifier )
2822 any-word ( identifier , nonempty-expr-list )
2823 any-word ( expr-list )
2825 where the "identifier" must not be declared as a type, and
2826 "any-word" may be any identifier (including one declared as a
2827 type), a reserved word storage class specifier, type specifier or
2828 type qualifier. ??? This still leaves out most reserved keywords
2829 (following the old parser), shouldn't we include them, and why not
2830 allow identifiers declared as types to start the arguments? */
2833 c_parser_attributes (c_parser *parser)
2835 tree attrs = NULL_TREE;
2836 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
2838 /* ??? Follow the C++ parser rather than using the
2839 lex_untranslated_string kludge. */
2840 parser->lex_untranslated_string = true;
2841 c_parser_consume_token (parser);
2842 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2844 parser->lex_untranslated_string = false;
2847 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
2849 parser->lex_untranslated_string = false;
2850 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
2853 /* Parse the attribute list. */
2854 while (c_parser_next_token_is (parser, CPP_COMMA)
2855 || c_parser_next_token_is (parser, CPP_NAME)
2856 || c_parser_next_token_is (parser, CPP_KEYWORD))
2858 tree attr, attr_name, attr_args;
2859 VEC(tree,gc) *expr_list;
2860 if (c_parser_next_token_is (parser, CPP_COMMA))
2862 c_parser_consume_token (parser);
2865 if (c_parser_next_token_is (parser, CPP_KEYWORD))
2867 /* ??? See comment above about what keywords are
2870 switch (c_parser_peek_token (parser)->keyword)
2907 /* Accept __attribute__((__const)) as __attribute__((const))
2910 = ridpointers[(int) c_parser_peek_token (parser)->keyword];
2913 attr_name = c_parser_peek_token (parser)->value;
2914 c_parser_consume_token (parser);
2915 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
2917 attr = build_tree_list (attr_name, NULL_TREE);
2918 attrs = chainon (attrs, attr);
2921 c_parser_consume_token (parser);
2922 /* Parse the attribute contents. If they start with an
2923 identifier which is followed by a comma or close
2924 parenthesis, then the arguments start with that
2925 identifier; otherwise they are an expression list. */
2926 if (c_parser_next_token_is (parser, CPP_NAME)
2927 && c_parser_peek_token (parser)->id_kind == C_ID_ID
2928 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
2929 || (c_parser_peek_2nd_token (parser)->type
2930 == CPP_CLOSE_PAREN)))
2932 tree arg1 = c_parser_peek_token (parser)->value;
2933 c_parser_consume_token (parser);
2934 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2935 attr_args = build_tree_list (NULL_TREE, arg1);
2939 c_parser_consume_token (parser);
2940 expr_list = c_parser_expr_list (parser, false, true, NULL);
2941 tree_list = build_tree_list_vec (expr_list);
2942 attr_args = tree_cons (NULL_TREE, arg1, tree_list);
2943 release_tree_vector (expr_list);
2948 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2949 attr_args = NULL_TREE;
2952 expr_list = c_parser_expr_list (parser, false, true, NULL);
2953 attr_args = build_tree_list_vec (expr_list);
2954 release_tree_vector (expr_list);
2957 attr = build_tree_list (attr_name, attr_args);
2958 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2959 c_parser_consume_token (parser);
2962 parser->lex_untranslated_string = false;
2963 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2967 attrs = chainon (attrs, attr);
2969 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2970 c_parser_consume_token (parser);
2973 parser->lex_untranslated_string = false;
2974 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2978 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
2979 c_parser_consume_token (parser);
2982 parser->lex_untranslated_string = false;
2983 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
2987 parser->lex_untranslated_string = false;
2992 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2995 specifier-qualifier-list abstract-declarator[opt]
2998 static struct c_type_name *
2999 c_parser_type_name (c_parser *parser)
3001 struct c_declspecs *specs = build_null_declspecs ();
3002 struct c_declarator *declarator;
3003 struct c_type_name *ret;
3005 c_parser_declspecs (parser, specs, false, true, true);
3006 if (!specs->declspecs_seen_p)
3008 c_parser_error (parser, "expected specifier-qualifier-list");
3011 pending_xref_error ();
3012 finish_declspecs (specs);
3013 declarator = c_parser_declarator (parser, specs->type_seen_p,
3014 C_DTR_ABSTRACT, &dummy);
3015 if (declarator == NULL)
3017 ret = XOBNEW (&parser_obstack, struct c_type_name);
3019 ret->declarator = declarator;
3023 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3026 assignment-expression
3027 { initializer-list }
3028 { initializer-list , }
3031 designation[opt] initializer
3032 initializer-list , designation[opt] initializer
3039 designator-list designator
3046 [ constant-expression ]
3058 [ constant-expression ... constant-expression ]
3060 Any expression without commas is accepted in the syntax for the
3061 constant-expressions, with non-constant expressions rejected later.
3063 This function is only used for top-level initializers; for nested
3064 ones, see c_parser_initval. */
3066 static struct c_expr
3067 c_parser_initializer (c_parser *parser)
3069 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
3070 return c_parser_braced_init (parser, NULL_TREE, false);
3074 location_t loc = c_parser_peek_token (parser)->location;
3075 ret = c_parser_expr_no_commas (parser, NULL);
3076 if (TREE_CODE (ret.value) != STRING_CST
3077 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR)
3078 ret = default_function_array_read_conversion (loc, ret);
3083 /* Parse a braced initializer list. TYPE is the type specified for a
3084 compound literal, and NULL_TREE for other initializers and for
3085 nested braced lists. NESTED_P is true for nested braced lists,
3086 false for the list of a compound literal or the list that is the
3087 top-level initializer in a declaration. */
3089 static struct c_expr
3090 c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
3093 struct obstack braced_init_obstack;
3094 location_t brace_loc = c_parser_peek_token (parser)->location;
3095 gcc_obstack_init (&braced_init_obstack);
3096 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
3097 c_parser_consume_token (parser);
3099 push_init_level (0, &braced_init_obstack);
3101 really_start_incremental_init (type);
3102 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3104 pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces");
3108 /* Parse a non-empty initializer list, possibly with a trailing
3112 c_parser_initelt (parser, &braced_init_obstack);
3115 if (c_parser_next_token_is (parser, CPP_COMMA))
3116 c_parser_consume_token (parser);
3119 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3123 if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3125 ret.value = error_mark_node;
3126 ret.original_code = ERROR_MARK;
3127 ret.original_type = NULL;
3128 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
3129 pop_init_level (0, &braced_init_obstack);
3130 obstack_free (&braced_init_obstack, NULL);
3133 c_parser_consume_token (parser);
3134 ret = pop_init_level (0, &braced_init_obstack);
3135 obstack_free (&braced_init_obstack, NULL);
3139 /* Parse a nested initializer, including designators. */
3142 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
3144 /* Parse any designator or designator list. A single array
3145 designator may have the subsequent "=" omitted in GNU C, but a
3146 longer list or a structure member designator may not. */
3147 if (c_parser_next_token_is (parser, CPP_NAME)
3148 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)
3150 /* Old-style structure member designator. */
3151 set_init_label (c_parser_peek_token (parser)->value,
3152 braced_init_obstack);
3153 /* Use the colon as the error location. */
3154 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic,
3155 "obsolete use of designated initializer with %<:%>");
3156 c_parser_consume_token (parser);
3157 c_parser_consume_token (parser);
3161 /* des_seen is 0 if there have been no designators, 1 if there
3162 has been a single array designator and 2 otherwise. */
3164 /* Location of a designator. */
3165 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3166 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)
3167 || c_parser_next_token_is (parser, CPP_DOT))
3169 int des_prev = des_seen;
3171 des_loc = c_parser_peek_token (parser)->location;
3174 if (c_parser_next_token_is (parser, CPP_DOT))
3177 c_parser_consume_token (parser);
3178 if (c_parser_next_token_is (parser, CPP_NAME))
3180 set_init_label (c_parser_peek_token (parser)->value,
3181 braced_init_obstack);
3182 c_parser_consume_token (parser);
3187 init.value = error_mark_node;
3188 init.original_code = ERROR_MARK;
3189 init.original_type = NULL;
3190 c_parser_error (parser, "expected identifier");
3191 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3192 process_init_element (init, false, braced_init_obstack);
3199 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3200 /* ??? Following the old parser, [ objc-receiver
3201 objc-message-args ] is accepted as an initializer,
3202 being distinguished from a designator by what follows
3203 the first assignment expression inside the square
3204 brackets, but after a first array designator a
3205 subsequent square bracket is for Objective-C taken to
3206 start an expression, using the obsolete form of
3207 designated initializer without '=', rather than
3208 possibly being a second level of designation: in LALR
3209 terms, the '[' is shifted rather than reducing
3210 designator to designator-list. */
3211 if (des_prev == 1 && c_dialect_objc ())
3213 des_seen = des_prev;
3216 if (des_prev == 0 && c_dialect_objc ())
3218 /* This might be an array designator or an
3219 Objective-C message expression. If the former,
3220 continue parsing here; if the latter, parse the
3221 remainder of the initializer given the starting
3222 primary-expression. ??? It might make sense to
3223 distinguish when des_prev == 1 as well; see
3224 previous comment. */
3226 struct c_expr mexpr;
3227 c_parser_consume_token (parser);
3228 if (c_parser_peek_token (parser)->type == CPP_NAME
3229 && ((c_parser_peek_token (parser)->id_kind
3231 || (c_parser_peek_token (parser)->id_kind
3232 == C_ID_CLASSNAME)))
3234 /* Type name receiver. */
3235 tree id = c_parser_peek_token (parser)->value;
3236 c_parser_consume_token (parser);
3237 rec = objc_get_class_reference (id);
3238 goto parse_message_args;
3240 first = c_parser_expr_no_commas (parser, NULL).value;
3241 mark_exp_read (first);
3242 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)
3243 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3244 goto array_desig_after_first;
3245 /* Expression receiver. So far only one part
3246 without commas has been parsed; there might be
3247 more of the expression. */
3249 while (c_parser_next_token_is (parser, CPP_COMMA))
3252 location_t comma_loc, exp_loc;
3253 comma_loc = c_parser_peek_token (parser)->location;
3254 c_parser_consume_token (parser);
3255 exp_loc = c_parser_peek_token (parser)->location;
3256 next = c_parser_expr_no_commas (parser, NULL);
3257 next = default_function_array_read_conversion (exp_loc,
3259 rec = build_compound_expr (comma_loc, rec, next.value);
3262 /* Now parse the objc-message-args. */
3263 args = c_parser_objc_message_args (parser);
3264 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3267 = objc_build_message_expr (build_tree_list (rec, args));
3268 mexpr.original_code = ERROR_MARK;
3269 mexpr.original_type = NULL;
3270 /* Now parse and process the remainder of the
3271 initializer, starting with this message
3272 expression as a primary-expression. */
3273 c_parser_initval (parser, &mexpr, braced_init_obstack);
3276 c_parser_consume_token (parser);
3277 first = c_parser_expr_no_commas (parser, NULL).value;
3278 mark_exp_read (first);
3279 array_desig_after_first:
3280 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3282 ellipsis_loc = c_parser_peek_token (parser)->location;
3283 c_parser_consume_token (parser);
3284 second = c_parser_expr_no_commas (parser, NULL).value;
3285 mark_exp_read (second);
3289 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
3291 c_parser_consume_token (parser);
3292 set_init_index (first, second, braced_init_obstack);
3294 pedwarn (ellipsis_loc, OPT_pedantic,
3295 "ISO C forbids specifying range of elements to initialize");
3298 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
3304 if (c_parser_next_token_is (parser, CPP_EQ))
3307 pedwarn (des_loc, OPT_pedantic,
3308 "ISO C90 forbids specifying subobject to initialize");
3309 c_parser_consume_token (parser);
3314 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
3315 "obsolete use of designated initializer without %<=%>");
3319 init.value = error_mark_node;
3320 init.original_code = ERROR_MARK;
3321 init.original_type = NULL;
3322 c_parser_error (parser, "expected %<=%>");
3323 c_parser_skip_until_found (parser, CPP_COMMA, NULL);
3324 process_init_element (init, false, braced_init_obstack);
3330 c_parser_initval (parser, NULL, braced_init_obstack);
3333 /* Parse a nested initializer; as c_parser_initializer but parses
3334 initializers within braced lists, after any designators have been
3335 applied. If AFTER is not NULL then it is an Objective-C message
3336 expression which is the primary-expression starting the
3340 c_parser_initval (c_parser *parser, struct c_expr *after,
3341 struct obstack * braced_init_obstack)
3344 gcc_assert (!after || c_dialect_objc ());
3345 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
3346 init = c_parser_braced_init (parser, NULL_TREE, true);
3349 location_t loc = c_parser_peek_token (parser)->location;
3350 init = c_parser_expr_no_commas (parser, after);
3351 if (init.value != NULL_TREE
3352 && TREE_CODE (init.value) != STRING_CST
3353 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
3354 init = default_function_array_read_conversion (loc, init);
3356 process_init_element (init, false, braced_init_obstack);
3359 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3363 { block-item-list[opt] }
3364 { label-declarations block-item-list }
3368 block-item-list block-item
3380 { label-declarations block-item-list }
3383 __extension__ nested-declaration
3384 nested-function-definition
3388 label-declarations label-declaration
3391 __label__ identifier-list ;
3393 Allowing the mixing of declarations and code is new in C99. The
3394 GNU syntax also permits (not shown above) labels at the end of
3395 compound statements, which yield an error. We don't allow labels
3396 on declarations; this might seem like a natural extension, but
3397 there would be a conflict between attributes on the label and
3398 prefix attributes on the declaration. ??? The syntax follows the
3399 old parser in requiring something after label declarations.
3400 Although they are erroneous if the labels declared aren't defined,
3401 is it useful for the syntax to be this way?
3413 c_parser_compound_statement (c_parser *parser)
3416 location_t brace_loc;
3417 brace_loc = c_parser_peek_token (parser)->location;
3418 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
3420 /* Ensure a scope is entered and left anyway to avoid confusion
3421 if we have just prepared to enter a function body. */
3422 stmt = c_begin_compound_stmt (true);
3423 c_end_compound_stmt (brace_loc, stmt, true);
3424 return error_mark_node;
3426 stmt = c_begin_compound_stmt (true);
3427 c_parser_compound_statement_nostart (parser);
3428 return c_end_compound_stmt (brace_loc, stmt, true);
3431 /* Parse a compound statement except for the opening brace. This is
3432 used for parsing both compound statements and statement expressions
3433 (which follow different paths to handling the opening). */
3436 c_parser_compound_statement_nostart (c_parser *parser)
3438 bool last_stmt = false;
3439 bool last_label = false;
3440 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p ();
3441 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */
3442 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3444 c_parser_consume_token (parser);
3447 mark_valid_location_for_stdc_pragma (true);
3448 if (c_parser_next_token_is_keyword (parser, RID_LABEL))
3450 /* Read zero or more forward-declarations for labels that nested
3451 functions can jump to. */
3452 mark_valid_location_for_stdc_pragma (false);
3453 while (c_parser_next_token_is_keyword (parser, RID_LABEL))
3455 label_loc = c_parser_peek_token (parser)->location;
3456 c_parser_consume_token (parser);
3457 /* Any identifiers, including those declared as type names,
3462 if (c_parser_next_token_is_not (parser, CPP_NAME))
3464 c_parser_error (parser, "expected identifier");
3468 = declare_label (c_parser_peek_token (parser)->value);
3469 C_DECLARED_LABEL_FLAG (label) = 1;
3470 add_stmt (build_stmt (label_loc, DECL_EXPR, label));
3471 c_parser_consume_token (parser);
3472 if (c_parser_next_token_is (parser, CPP_COMMA))
3473 c_parser_consume_token (parser);
3477 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3479 pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations");
3481 /* We must now have at least one statement, label or declaration. */
3482 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
3484 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3485 c_parser_error (parser, "expected declaration or statement");
3486 c_parser_consume_token (parser);
3489 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE))
3491 location_t loc = c_parser_peek_token (parser)->location;
3492 if (c_parser_next_token_is_keyword (parser, RID_CASE)
3493 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3494 || (c_parser_next_token_is (parser, CPP_NAME)
3495 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3497 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3498 label_loc = c_parser_peek_2nd_token (parser)->location;
3500 label_loc = c_parser_peek_token (parser)->location;
3503 mark_valid_location_for_stdc_pragma (false);
3504 c_parser_label (parser);
3506 else if (!last_label
3507 && c_parser_next_token_starts_declspecs (parser))
3510 mark_valid_location_for_stdc_pragma (false);
3511 c_parser_declaration_or_fndef (parser, true, true, true, true);
3514 (pedantic && !flag_isoc99)
3516 : OPT_Wdeclaration_after_statement,
3517 "ISO C90 forbids mixed declarations and code");
3520 else if (!last_label
3521 && c_parser_next_token_is_keyword (parser, RID_EXTENSION))
3523 /* __extension__ can start a declaration, but is also an
3524 unary operator that can start an expression. Consume all
3525 but the last of a possible series of __extension__ to
3527 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
3528 && (c_parser_peek_2nd_token (parser)->keyword
3530 c_parser_consume_token (parser);
3531 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
3534 ext = disable_extension_diagnostics ();
3535 c_parser_consume_token (parser);
3537 mark_valid_location_for_stdc_pragma (false);
3538 c_parser_declaration_or_fndef (parser, true, true, true, true);
3539 /* Following the old parser, __extension__ does not
3540 disable this diagnostic. */
3541 restore_extension_diagnostics (ext);
3543 pedwarn_c90 (loc, (pedantic && !flag_isoc99)
3545 : OPT_Wdeclaration_after_statement,
3546 "ISO C90 forbids mixed declarations and code");
3552 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
3554 /* External pragmas, and some omp pragmas, are not associated
3555 with regular c code, and so are not to be considered statements
3556 syntactically. This ensures that the user doesn't put them
3557 places that would turn into syntax errors if the directive
3559 if (c_parser_pragma (parser, pragma_compound))
3560 last_label = false, last_stmt = true;
3562 else if (c_parser_next_token_is (parser, CPP_EOF))
3564 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3565 c_parser_error (parser, "expected declaration or statement");
3568 else if (c_parser_next_token_is_keyword (parser, RID_ELSE))
3570 if (parser->in_if_block)
3572 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3573 error_at (loc, """expected %<}%> before %<else%>");
3578 error_at (loc, "%<else%> without a previous %<if%>");
3579 c_parser_consume_token (parser);
3588 mark_valid_location_for_stdc_pragma (false);
3589 c_parser_statement_after_labels (parser);
3592 parser->error = false;
3595 error_at (label_loc, "label at end of compound statement");
3596 c_parser_consume_token (parser);
3597 /* Restore the value we started with. */
3598 mark_valid_location_for_stdc_pragma (save_valid_for_pragma);
3601 /* Parse a label (C90 6.6.1, C99 6.8.1).
3604 identifier : attributes[opt]
3605 case constant-expression :
3611 case constant-expression ... constant-expression :
3613 The use of attributes on labels is a GNU extension. The syntax in
3614 GNU C accepts any expressions without commas, non-constant
3615 expressions being rejected later. */
3618 c_parser_label (c_parser *parser)
3620 location_t loc1 = c_parser_peek_token (parser)->location;
3621 tree label = NULL_TREE;
3622 if (c_parser_next_token_is_keyword (parser, RID_CASE))
3625 c_parser_consume_token (parser);
3626 exp1 = c_parser_expr_no_commas (parser, NULL).value;
3627 if (c_parser_next_token_is (parser, CPP_COLON))
3629 c_parser_consume_token (parser);
3630 label = do_case (loc1, exp1, NULL_TREE);
3632 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
3634 c_parser_consume_token (parser);
3635 exp2 = c_parser_expr_no_commas (parser, NULL).value;
3636 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3637 label = do_case (loc1, exp1, exp2);
3640 c_parser_error (parser, "expected %<:%> or %<...%>");
3642 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
3644 c_parser_consume_token (parser);
3645 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
3646 label = do_case (loc1, NULL_TREE, NULL_TREE);
3650 tree name = c_parser_peek_token (parser)->value;
3653 location_t loc2 = c_parser_peek_token (parser)->location;
3654 gcc_assert (c_parser_next_token_is (parser, CPP_NAME));
3655 c_parser_consume_token (parser);
3656 gcc_assert (c_parser_next_token_is (parser, CPP_COLON));
3657 c_parser_consume_token (parser);
3658 attrs = c_parser_attributes (parser);
3659 tlab = define_label (loc2, name);
3662 decl_attributes (&tlab, attrs, 0);
3663 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab));
3668 if (c_parser_next_token_starts_declspecs (parser)
3669 && !(c_parser_next_token_is (parser, CPP_NAME)
3670 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3672 error_at (c_parser_peek_token (parser)->location,
3673 "a label can only be part of a statement and "
3674 "a declaration is not a statement");
3675 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
3676 /*nested*/ true, /*empty_ok*/ false,
3677 /*start_attr_ok*/ true);
3682 /* Parse a statement (C90 6.6, C99 6.8).
3687 expression-statement
3695 expression-statement:
3698 selection-statement:
3702 iteration-statement:
3711 return expression[opt] ;
3724 objc-throw-statement
3725 objc-try-catch-statement
3726 objc-synchronized-statement
3728 objc-throw-statement:
3742 parallel-for-construct
3743 parallel-sections-construct
3750 parallel-directive structured-block
3753 for-directive iteration-statement
3756 sections-directive section-scope
3759 single-directive structured-block
3761 parallel-for-construct:
3762 parallel-for-directive iteration-statement
3764 parallel-sections-construct:
3765 parallel-sections-directive section-scope
3768 master-directive structured-block
3771 critical-directive structured-block
3774 atomic-directive expression-statement
3777 ordered-directive structured-block */
3780 c_parser_statement (c_parser *parser)
3782 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3783 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3784 || (c_parser_next_token_is (parser, CPP_NAME)
3785 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3786 c_parser_label (parser);
3787 c_parser_statement_after_labels (parser);
3790 /* Parse a statement, other than a labeled statement. */
3793 c_parser_statement_after_labels (c_parser *parser)
3795 location_t loc = c_parser_peek_token (parser)->location;
3796 tree stmt = NULL_TREE;
3797 bool in_if_block = parser->in_if_block;
3798 parser->in_if_block = false;
3799 switch (c_parser_peek_token (parser)->type)
3801 case CPP_OPEN_BRACE:
3802 add_stmt (c_parser_compound_statement (parser));
3805 switch (c_parser_peek_token (parser)->keyword)
3808 c_parser_if_statement (parser);
3811 c_parser_switch_statement (parser);
3814 c_parser_while_statement (parser);
3817 c_parser_do_statement (parser);
3820 c_parser_for_statement (parser);
3823 c_parser_consume_token (parser);
3824 if (c_parser_next_token_is (parser, CPP_NAME))
3826 stmt = c_finish_goto_label (loc,
3827 c_parser_peek_token (parser)->value);
3828 c_parser_consume_token (parser);
3830 else if (c_parser_next_token_is (parser, CPP_MULT))
3832 c_parser_consume_token (parser);
3833 stmt = c_finish_goto_ptr (loc,
3834 c_parser_expression (parser).value);
3837 c_parser_error (parser, "expected identifier or %<*%>");
3838 goto expect_semicolon;
3840 c_parser_consume_token (parser);
3841 stmt = c_finish_bc_stmt (loc, &c_cont_label, false);
3842 goto expect_semicolon;
3844 c_parser_consume_token (parser);
3845 stmt = c_finish_bc_stmt (loc, &c_break_label, true);
3846 goto expect_semicolon;
3848 c_parser_consume_token (parser);
3849 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3851 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE);
3852 c_parser_consume_token (parser);
3856 struct c_expr expr = c_parser_expression_conv (parser);
3857 mark_exp_read (expr.value);
3858 stmt = c_finish_return (loc, expr.value, expr.original_type);
3859 goto expect_semicolon;
3863 stmt = c_parser_asm_statement (parser);
3866 gcc_assert (c_dialect_objc ());
3867 c_parser_consume_token (parser);
3868 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3870 stmt = objc_build_throw_stmt (loc, NULL_TREE);
3871 c_parser_consume_token (parser);
3875 tree expr = c_parser_expression (parser).value;
3876 expr = c_fully_fold (expr, false, NULL);
3877 stmt = objc_build_throw_stmt (loc, expr);
3878 goto expect_semicolon;
3882 gcc_assert (c_dialect_objc ());
3883 c_parser_objc_try_catch_statement (parser);
3885 case RID_AT_SYNCHRONIZED:
3886 gcc_assert (c_dialect_objc ());
3887 c_parser_objc_synchronized_statement (parser);
3894 c_parser_consume_token (parser);
3896 case CPP_CLOSE_PAREN:
3897 case CPP_CLOSE_SQUARE:
3898 /* Avoid infinite loop in error recovery:
3899 c_parser_skip_until_found stops at a closing nesting
3900 delimiter without consuming it, but here we need to consume
3901 it to proceed further. */
3902 c_parser_error (parser, "expected statement");
3903 c_parser_consume_token (parser);
3906 c_parser_pragma (parser, pragma_stmt);
3910 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value);
3912 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
3915 /* Two cases cannot and do not have line numbers associated: If stmt
3916 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3917 cannot hold line numbers. But that's OK because the statement
3918 will either be changed to a MODIFY_EXPR during gimplification of
3919 the statement expr, or discarded. If stmt was compound, but
3920 without new variables, we will have skipped the creation of a
3921 BIND and will have a bare STATEMENT_LIST. But that's OK because
3922 (recursively) all of the component statements should already have
3923 line numbers assigned. ??? Can we discard no-op statements
3925 if (CAN_HAVE_LOCATION_P (stmt)
3926 && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION)
3927 SET_EXPR_LOCATION (stmt, loc);
3929 parser->in_if_block = in_if_block;
3932 /* Parse the condition from an if, do, while or for statements. */
3935 c_parser_condition (c_parser *parser)
3937 location_t loc = c_parser_peek_token (parser)->location;
3939 cond = c_parser_expression_conv (parser).value;
3940 cond = c_objc_common_truthvalue_conversion (loc, cond);
3941 cond = c_fully_fold (cond, false, NULL);
3942 if (warn_sequence_point)
3943 verify_sequence_points (cond);
3947 /* Parse a parenthesized condition from an if, do or while statement.
3953 c_parser_paren_condition (c_parser *parser)
3956 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
3957 return error_mark_node;
3958 cond = c_parser_condition (parser);
3959 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
3963 /* Parse a statement which is a block in C99. */
3966 c_parser_c99_block_statement (c_parser *parser)
3968 tree block = c_begin_compound_stmt (flag_isoc99);
3969 location_t loc = c_parser_peek_token (parser)->location;
3970 c_parser_statement (parser);
3971 return c_end_compound_stmt (loc, block, flag_isoc99);
3974 /* Parse the body of an if statement. This is just parsing a
3975 statement but (a) it is a block in C99, (b) we track whether the
3976 body is an if statement for the sake of -Wparentheses warnings, (c)
3977 we handle an empty body specially for the sake of -Wempty-body
3978 warnings, and (d) we call parser_compound_statement directly
3979 because c_parser_statement_after_labels resets
3980 parser->in_if_block. */
3983 c_parser_if_body (c_parser *parser, bool *if_p)
3985 tree block = c_begin_compound_stmt (flag_isoc99);
3986 location_t body_loc = c_parser_peek_token (parser)->location;
3987 while (c_parser_next_token_is_keyword (parser, RID_CASE)
3988 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
3989 || (c_parser_next_token_is (parser, CPP_NAME)
3990 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
3991 c_parser_label (parser);
3992 *if_p = c_parser_next_token_is_keyword (parser, RID_IF);
3993 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
3995 location_t loc = c_parser_peek_token (parser)->location;
3996 add_stmt (build_empty_stmt (loc));
3997 c_parser_consume_token (parser);
3998 if (!c_parser_next_token_is_keyword (parser, RID_ELSE))
3999 warning_at (loc, OPT_Wempty_body,
4000 "suggest braces around empty body in an %<if%> statement");
4002 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
4003 add_stmt (c_parser_compound_statement (parser));
4005 c_parser_statement_after_labels (parser);
4006 return c_end_compound_stmt (body_loc, block, flag_isoc99);
4009 /* Parse the else body of an if statement. This is just parsing a
4010 statement but (a) it is a block in C99, (b) we handle an empty body
4011 specially for the sake of -Wempty-body warnings. */
4014 c_parser_else_body (c_parser *parser)
4016 location_t else_loc = c_parser_peek_token (parser)->location;
4017 tree block = c_begin_compound_stmt (flag_isoc99);
4018 while (c_parser_next_token_is_keyword (parser, RID_CASE)
4019 || c_parser_next_token_is_keyword (parser, RID_DEFAULT)
4020 || (c_parser_next_token_is (parser, CPP_NAME)
4021 && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
4022 c_parser_label (parser);
4023 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4025 location_t loc = c_parser_peek_token (parser)->location;
4028 "suggest braces around empty body in an %<else%> statement");
4029 add_stmt (build_empty_stmt (loc));
4030 c_parser_consume_token (parser);
4033 c_parser_statement_after_labels (parser);
4034 return c_end_compound_stmt (else_loc, block, flag_isoc99);
4037 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4040 if ( expression ) statement
4041 if ( expression ) statement else statement
4045 c_parser_if_statement (c_parser *parser)
4050 bool first_if = false;
4051 tree first_body, second_body;
4054 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF));
4055 c_parser_consume_token (parser);
4056 block = c_begin_compound_stmt (flag_isoc99);
4057 loc = c_parser_peek_token (parser)->location;
4058 cond = c_parser_paren_condition (parser);
4059 in_if_block = parser->in_if_block;
4060 parser->in_if_block = true;
4061 first_body = c_parser_if_body (parser, &first_if);
4062 parser->in_if_block = in_if_block;
4063 if (c_parser_next_token_is_keyword (parser, RID_ELSE))
4065 c_parser_consume_token (parser);
4066 second_body = c_parser_else_body (parser);
4069 second_body = NULL_TREE;
4070 c_finish_if_stmt (loc, cond, first_body, second_body, first_if);
4071 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4074 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4077 switch (expression) statement
4081 c_parser_switch_statement (c_parser *parser)
4083 tree block, expr, body, save_break;
4084 location_t switch_loc = c_parser_peek_token (parser)->location;
4085 location_t switch_cond_loc;
4086 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
4087 c_parser_consume_token (parser);
4088 block = c_begin_compound_stmt (flag_isoc99);
4089 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4091 switch_cond_loc = c_parser_peek_token (parser)->location;
4092 expr = c_parser_expression (parser).value;
4093 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4097 switch_cond_loc = UNKNOWN_LOCATION;
4098 expr = error_mark_node;
4100 c_start_case (switch_loc, switch_cond_loc, expr);
4101 save_break = c_break_label;
4102 c_break_label = NULL_TREE;
4103 body = c_parser_c99_block_statement (parser);
4104 c_finish_case (body);
4107 location_t here = c_parser_peek_token (parser)->location;
4108 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label);
4109 SET_EXPR_LOCATION (t, here);
4112 c_break_label = save_break;
4113 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99));
4116 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4119 while (expression) statement
4123 c_parser_while_statement (c_parser *parser)
4125 tree block, cond, body, save_break, save_cont;
4127 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE));
4128 c_parser_consume_token (parser);
4129 block = c_begin_compound_stmt (flag_isoc99);
4130 loc = c_parser_peek_token (parser)->location;
4131 cond = c_parser_paren_condition (parser);
4132 save_break = c_break_label;
4133 c_break_label = NULL_TREE;
4134 save_cont = c_cont_label;
4135 c_cont_label = NULL_TREE;
4136 body = c_parser_c99_block_statement (parser);
4137 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true);
4138 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4139 c_break_label = save_break;
4140 c_cont_label = save_cont;
4143 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4146 do statement while ( expression ) ;
4150 c_parser_do_statement (c_parser *parser)
4152 tree block, cond, body, save_break, save_cont, new_break, new_cont;
4154 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO));
4155 c_parser_consume_token (parser);
4156 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4157 warning_at (c_parser_peek_token (parser)->location,
4159 "suggest braces around empty body in %<do%> statement");
4160 block = c_begin_compound_stmt (flag_isoc99);
4161 loc = c_parser_peek_token (parser)->location;
4162 save_break = c_break_label;
4163 c_break_label = NULL_TREE;
4164 save_cont = c_cont_label;
4165 c_cont_label = NULL_TREE;
4166 body = c_parser_c99_block_statement (parser);
4167 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>");
4168 new_break = c_break_label;
4169 c_break_label = save_break;
4170 new_cont = c_cont_label;
4171 c_cont_label = save_cont;
4172 cond = c_parser_paren_condition (parser);
4173 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4174 c_parser_skip_to_end_of_block_or_statement (parser);
4175 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false);
4176 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4179 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4182 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4183 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4185 The form with a declaration is new in C99.
4187 ??? In accordance with the old parser, the declaration may be a
4188 nested function, which is then rejected in check_for_loop_decls,
4189 but does it make any sense for this to be included in the grammar?
4190 Note in particular that the nested function does not include a
4191 trailing ';', whereas the "declaration" production includes one.
4192 Also, can we reject bad declarations earlier and cheaper than
4193 check_for_loop_decls? */
4196 c_parser_for_statement (c_parser *parser)
4198 tree block, cond, incr, save_break, save_cont, body;
4199 location_t loc = c_parser_peek_token (parser)->location;
4200 location_t for_loc = c_parser_peek_token (parser)->location;
4201 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
4202 c_parser_consume_token (parser);
4203 block = c_begin_compound_stmt (flag_isoc99);
4204 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4206 /* Parse the initialization declaration or expression. */
4207 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4209 c_parser_consume_token (parser);
4210 c_finish_expr_stmt (loc, NULL_TREE);
4212 else if (c_parser_next_token_starts_declspecs (parser))
4214 c_parser_declaration_or_fndef (parser, true, true, true, true);
4215 check_for_loop_decls (for_loc);
4217 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION))
4219 /* __extension__ can start a declaration, but is also an
4220 unary operator that can start an expression. Consume all
4221 but the last of a possible series of __extension__ to
4223 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD
4224 && (c_parser_peek_2nd_token (parser)->keyword
4226 c_parser_consume_token (parser);
4227 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser)))
4230 ext = disable_extension_diagnostics ();
4231 c_parser_consume_token (parser);
4232 c_parser_declaration_or_fndef (parser, true, true, true, true);
4233 restore_extension_diagnostics (ext);
4234 check_for_loop_decls (for_loc);
4242 c_finish_expr_stmt (loc, c_parser_expression (parser).value);
4243 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4245 /* Parse the loop condition. */
4246 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
4248 c_parser_consume_token (parser);
4253 cond = c_parser_condition (parser);
4254 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
4256 /* Parse the increment expression. */
4257 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4258 incr = c_process_expr_stmt (loc, NULL_TREE);
4260 incr = c_process_expr_stmt (loc, c_parser_expression (parser).value);
4261 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
4265 cond = error_mark_node;
4266 incr = error_mark_node;
4268 save_break = c_break_label;
4269 c_break_label = NULL_TREE;
4270 save_cont = c_cont_label;
4271 c_cont_label = NULL_TREE;
4272 body = c_parser_c99_block_statement (parser);
4273 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
4274 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));
4275 c_break_label = save_break;
4276 c_cont_label = save_cont;
4279 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4280 statement with inputs, outputs, clobbers, and volatile tag
4284 asm type-qualifier[opt] ( asm-argument ) ;
4285 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4289 asm-string-literal : asm-operands[opt]
4290 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4291 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4294 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4297 Qualifiers other than volatile are accepted in the syntax but
4301 c_parser_asm_statement (c_parser *parser)
4303 tree quals, str, outputs, inputs, clobbers, labels, ret;
4304 bool simple, is_goto;
4305 location_t asm_loc = c_parser_peek_token (parser)->location;
4306 int section, nsections;
4308 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
4309 c_parser_consume_token (parser);
4310 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE))
4312 quals = c_parser_peek_token (parser)->value;
4313 c_parser_consume_token (parser);
4315 else if (c_parser_next_token_is_keyword (parser, RID_CONST)
4316 || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
4318 warning_at (c_parser_peek_token (parser)->location,
4320 "%E qualifier ignored on asm",
4321 c_parser_peek_token (parser)->value);
4323 c_parser_consume_token (parser);
4329 if (c_parser_next_token_is_keyword (parser, RID_GOTO))
4331 c_parser_consume_token (parser);
4335 /* ??? Follow the C++ parser rather than using the
4336 lex_untranslated_string kludge. */
4337 parser->lex_untranslated_string = true;
4340 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4343 str = c_parser_asm_string_literal (parser);
4344 if (str == NULL_TREE)
4345 goto error_close_paren;
4348 outputs = NULL_TREE;
4350 clobbers = NULL_TREE;
4353 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4356 /* Parse each colon-delimited section of operands. */
4357 nsections = 3 + is_goto;
4358 for (section = 0; section < nsections; ++section)
4360 if (!c_parser_require (parser, CPP_COLON,
4363 : "expected %<:%> or %<)%>"))
4364 goto error_close_paren;
4366 /* Once past any colon, we're no longer a simple asm. */
4369 if ((!c_parser_next_token_is (parser, CPP_COLON)
4370 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
4375 /* For asm goto, we don't allow output operands, but reserve
4376 the slot for a future extension that does allow them. */
4378 outputs = c_parser_asm_operands (parser, false);
4381 inputs = c_parser_asm_operands (parser, true);
4384 clobbers = c_parser_asm_clobbers (parser);
4387 labels = c_parser_asm_goto_operands (parser);
4393 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto)
4398 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4400 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4404 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
4405 c_parser_skip_to_end_of_block_or_statement (parser);
4407 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs,
4408 clobbers, labels, simple));
4411 parser->lex_untranslated_string = false;
4415 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4419 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4420 not outputs), apply the default conversion of functions and arrays
4425 asm-operands , asm-operand
4428 asm-string-literal ( expression )
4429 [ identifier ] asm-string-literal ( expression )
4433 c_parser_asm_operands (c_parser *parser, bool convert_p)
4435 tree list = NULL_TREE;
4441 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
4443 c_parser_consume_token (parser);
4444 if (c_parser_next_token_is (parser, CPP_NAME))
4446 tree id = c_parser_peek_token (parser)->value;
4447 c_parser_consume_token (parser);
4448 name = build_string (IDENTIFIER_LENGTH (id),
4449 IDENTIFIER_POINTER (id));
4453 c_parser_error (parser, "expected identifier");
4454 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
4457 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
4462 str = c_parser_asm_string_literal (parser);
4463 if (str == NULL_TREE)
4465 parser->lex_untranslated_string = false;
4466 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
4468 parser->lex_untranslated_string = true;
4471 loc = c_parser_peek_token (parser)->location;
4472 expr = c_parser_expression (parser);
4473 mark_exp_read (expr.value);
4475 expr = default_function_array_conversion (loc, expr);
4476 expr.value = c_fully_fold (expr.value, false, NULL);
4477 parser->lex_untranslated_string = true;
4478 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
4480 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
4483 list = chainon (list, build_tree_list (build_tree_list (name, str),
4485 if (c_parser_next_token_is (parser, CPP_COMMA))
4486 c_parser_consume_token (parser);
4493 /* Parse asm clobbers, a GNU extension.
4497 asm-clobbers , asm-string-literal
4501 c_parser_asm_clobbers (c_parser *parser)
4503 tree list = NULL_TREE;
4506 tree str = c_parser_asm_string_literal (parser);
4508 list = tree_cons (NULL_TREE, str, list);
4511 if (c_parser_next_token_is (parser, CPP_COMMA))
4512 c_parser_consume_token (parser);
4519 /* Parse asm goto labels, a GNU extension.
4523 asm-goto-operands , identifier
4527 c_parser_asm_goto_operands (c_parser *parser)
4529 tree list = NULL_TREE;
4534 if (c_parser_next_token_is (parser, CPP_NAME))
4536 c_token *tok = c_parser_peek_token (parser);
4538 label = lookup_label_for_goto (tok->location, name);
4539 c_parser_consume_token (parser);
4540 TREE_USED (label) = 1;
4544 c_parser_error (parser, "expected identifier");
4548 name = build_string (IDENTIFIER_LENGTH (name),
4549 IDENTIFIER_POINTER (name));
4550 list = tree_cons (name, label, list);
4551 if (c_parser_next_token_is (parser, CPP_COMMA))
4552 c_parser_consume_token (parser);
4554 return nreverse (list);
4558 /* Parse an expression other than a compound expression; that is, an
4559 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4560 NULL then it is an Objective-C message expression which is the
4561 primary-expression starting the expression as an initializer.
4563 assignment-expression:
4564 conditional-expression
4565 unary-expression assignment-operator assignment-expression
4567 assignment-operator: one of
4568 = *= /= %= += -= <<= >>= &= ^= |=
4570 In GNU C we accept any conditional expression on the LHS and
4571 diagnose the invalid lvalue rather than producing a syntax
4574 static struct c_expr
4575 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after)
4577 struct c_expr lhs, rhs, ret;
4578 enum tree_code code;
4579 location_t op_location, exp_location;
4580 gcc_assert (!after || c_dialect_objc ());
4581 lhs = c_parser_conditional_expression (parser, after);
4582 op_location = c_parser_peek_token (parser)->location;
4583 switch (c_parser_peek_token (parser)->type)
4592 code = TRUNC_DIV_EXPR;
4595 code = TRUNC_MOD_EXPR;
4610 code = BIT_AND_EXPR;
4613 code = BIT_XOR_EXPR;
4616 code = BIT_IOR_EXPR;
4621 c_parser_consume_token (parser);
4622 exp_location = c_parser_peek_token (parser)->location;
4623 rhs = c_parser_expr_no_commas (parser, NULL);
4624 rhs = default_function_array_read_conversion (exp_location, rhs);
4625 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type,
4626 code, exp_location, rhs.value,
4628 if (code == NOP_EXPR)
4629 ret.original_code = MODIFY_EXPR;
4632 TREE_NO_WARNING (ret.value) = 1;
4633 ret.original_code = ERROR_MARK;
4635 ret.original_type = NULL;
4639 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4640 is not NULL then it is an Objective-C message expression which is
4641 the primary-expression starting the expression as an initializer.
4643 conditional-expression:
4644 logical-OR-expression
4645 logical-OR-expression ? expression : conditional-expression
4649 conditional-expression:
4650 logical-OR-expression ? : conditional-expression
4653 static struct c_expr
4654 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
4656 struct c_expr cond, exp1, exp2, ret;
4657 location_t cond_loc, colon_loc;
4659 gcc_assert (!after || c_dialect_objc ());
4661 cond = c_parser_binary_expression (parser, after);
4663 if (c_parser_next_token_is_not (parser, CPP_QUERY))
4665 cond_loc = c_parser_peek_token (parser)->location;
4666 cond = default_function_array_read_conversion (cond_loc, cond);
4667 c_parser_consume_token (parser);
4668 if (c_parser_next_token_is (parser, CPP_COLON))
4670 tree eptype = NULL_TREE;
4671 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
4672 "ISO C forbids omitting the middle term of a ?: expression");
4673 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
4675 eptype = TREE_TYPE (cond.value);
4676 cond.value = TREE_OPERAND (cond.value, 0);
4678 /* Make sure first operand is calculated only once. */
4679 exp1.value = c_save_expr (default_conversion (cond.value));
4681 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
4682 exp1.original_type = NULL;
4683 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
4684 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
4689 = c_objc_common_truthvalue_conversion
4690 (cond_loc, default_conversion (cond.value));
4691 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
4692 exp1 = c_parser_expression_conv (parser);
4693 mark_exp_read (exp1.value);
4694 c_inhibit_evaluation_warnings +=
4695 ((cond.value == truthvalue_true_node)
4696 - (cond.value == truthvalue_false_node));
4699 colon_loc = c_parser_peek_token (parser)->location;
4700 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
4702 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4703 ret.value = error_mark_node;
4704 ret.original_code = ERROR_MARK;
4705 ret.original_type = NULL;
4709 location_t exp2_loc = c_parser_peek_token (parser)->location;
4710 exp2 = c_parser_conditional_expression (parser, NULL);
4711 exp2 = default_function_array_read_conversion (exp2_loc, exp2);
4713 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
4714 ret.value = build_conditional_expr (colon_loc, cond.value,
4715 cond.original_code == C_MAYBE_CONST_EXPR,
4716 exp1.value, exp1.original_type,
4717 exp2.value, exp2.original_type);
4718 ret.original_code = ERROR_MARK;
4719 if (exp1.value == error_mark_node || exp2.value == error_mark_node)
4720 ret.original_type = NULL;
4725 /* If both sides are enum type, the default conversion will have
4726 made the type of the result be an integer type. We want to
4727 remember the enum types we started with. */
4728 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value);
4729 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value);
4730 ret.original_type = ((t1 != error_mark_node
4731 && t2 != error_mark_node
4732 && (TYPE_MAIN_VARIANT (t1)
4733 == TYPE_MAIN_VARIANT (t2)))
4740 /* Parse a binary expression; that is, a logical-OR-expression (C90
4741 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4742 an Objective-C message expression which is the primary-expression
4743 starting the expression as an initializer.
4745 multiplicative-expression:
4747 multiplicative-expression * cast-expression
4748 multiplicative-expression / cast-expression
4749 multiplicative-expression % cast-expression
4751 additive-expression:
4752 multiplicative-expression
4753 additive-expression + multiplicative-expression
4754 additive-expression - multiplicative-expression
4758 shift-expression << additive-expression
4759 shift-expression >> additive-expression
4761 relational-expression:
4763 relational-expression < shift-expression
4764 relational-expression > shift-expression
4765 relational-expression <= shift-expression
4766 relational-expression >= shift-expression
4768 equality-expression:
4769 relational-expression
4770 equality-expression == relational-expression
4771 equality-expression != relational-expression
4775 AND-expression & equality-expression
4777 exclusive-OR-expression:
4779 exclusive-OR-expression ^ AND-expression
4781 inclusive-OR-expression:
4782 exclusive-OR-expression
4783 inclusive-OR-expression | exclusive-OR-expression
4785 logical-AND-expression:
4786 inclusive-OR-expression
4787 logical-AND-expression && inclusive-OR-expression
4789 logical-OR-expression:
4790 logical-AND-expression
4791 logical-OR-expression || logical-AND-expression
4794 static struct c_expr
4795 c_parser_binary_expression (c_parser *parser, struct c_expr *after)
4797 /* A binary expression is parsed using operator-precedence parsing,
4798 with the operands being cast expressions. All the binary
4799 operators are left-associative. Thus a binary expression is of
4802 E0 op1 E1 op2 E2 ...
4804 which we represent on a stack. On the stack, the precedence
4805 levels are strictly increasing. When a new operator is
4806 encountered of higher precedence than that at the top of the
4807 stack, it is pushed; its LHS is the top expression, and its RHS
4808 is everything parsed until it is popped. When a new operator is
4809 encountered with precedence less than or equal to that at the top
4810 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4811 by the result of the operation until the operator at the top of
4812 the stack has lower precedence than the new operator or there is
4813 only one element on the stack; then the top expression is the LHS
4814 of the new operator. In the case of logical AND and OR
4815 expressions, we also need to adjust c_inhibit_evaluation_warnings
4816 as appropriate when the operators are pushed and popped. */
4818 /* The precedence levels, where 0 is a dummy lowest level used for
4819 the bottom of the stack. */
4835 /* The expression at this stack level. */
4837 /* The precedence of the operator on its left, PREC_NONE at the
4838 bottom of the stack. */
4840 /* The operation on its left. */
4842 /* The source location of this operation. */
4846 /* Location of the binary operator. */
4847 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
4850 switch (stack[sp].op) \
4852 case TRUTH_ANDIF_EXPR: \
4853 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4854 == truthvalue_false_node); \
4856 case TRUTH_ORIF_EXPR: \
4857 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4858 == truthvalue_true_node); \
4863 stack[sp - 1].expr \
4864 = default_function_array_read_conversion (stack[sp - 1].loc, \
4865 stack[sp - 1].expr); \
4867 = default_function_array_read_conversion (stack[sp].loc, \
4869 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4871 stack[sp - 1].expr, \
4875 gcc_assert (!after || c_dialect_objc ());
4876 stack[0].loc = c_parser_peek_token (parser)->location;
4877 stack[0].expr = c_parser_cast_expression (parser, after);
4878 stack[0].prec = PREC_NONE;
4883 enum tree_code ocode;
4886 switch (c_parser_peek_token (parser)->type)
4894 ocode = TRUNC_DIV_EXPR;
4898 ocode = TRUNC_MOD_EXPR;
4910 ocode = LSHIFT_EXPR;
4914 ocode = RSHIFT_EXPR;
4928 case CPP_GREATER_EQ:
4941 oprec = PREC_BITAND;
4942 ocode = BIT_AND_EXPR;
4945 oprec = PREC_BITXOR;
4946 ocode = BIT_XOR_EXPR;
4950 ocode = BIT_IOR_EXPR;
4953 oprec = PREC_LOGAND;
4954 ocode = TRUTH_ANDIF_EXPR;
4958 ocode = TRUTH_ORIF_EXPR;
4961 /* Not a binary operator, so end of the binary
4965 binary_loc = c_parser_peek_token (parser)->location;
4966 c_parser_consume_token (parser);
4967 while (oprec <= stack[sp].prec)
4971 case TRUTH_ANDIF_EXPR:
4973 = default_function_array_read_conversion (stack[sp].loc,
4975 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4976 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4977 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4978 == truthvalue_false_node);
4980 case TRUTH_ORIF_EXPR:
4982 = default_function_array_read_conversion (stack[sp].loc,
4984 stack[sp].expr.value = c_objc_common_truthvalue_conversion
4985 (stack[sp].loc, default_conversion (stack[sp].expr.value));
4986 c_inhibit_evaluation_warnings += (stack[sp].expr.value
4987 == truthvalue_true_node);
4993 stack[sp].loc = binary_loc;
4994 stack[sp].expr = c_parser_cast_expression (parser, NULL);
4995 stack[sp].prec = oprec;
4996 stack[sp].op = ocode;
4997 stack[sp].loc = binary_loc;
5002 return stack[0].expr;
5006 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5007 NULL then it is an Objective-C message expression which is the
5008 primary-expression starting the expression as an initializer.
5012 ( type-name ) unary-expression
5015 static struct c_expr
5016 c_parser_cast_expression (c_parser *parser, struct c_expr *after)
5018 location_t cast_loc = c_parser_peek_token (parser)->location;
5019 gcc_assert (!after || c_dialect_objc ());
5021 return c_parser_postfix_expression_after_primary (parser,
5023 /* If the expression begins with a parenthesized type name, it may
5024 be either a cast or a compound literal; we need to see whether
5025 the next character is '{' to tell the difference. If not, it is
5026 an unary expression. */
5027 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5028 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5030 struct c_type_name *type_name;
5033 c_parser_consume_token (parser);
5034 type_name = c_parser_type_name (parser);
5035 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5036 if (type_name == NULL)
5038 ret.value = error_mark_node;
5039 ret.original_code = ERROR_MARK;
5040 ret.original_type = NULL;
5044 /* Save casted types in the function's used types hash table. */
5045 used_types_insert (type_name->specs->type);
5047 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5048 return c_parser_postfix_expression_after_paren_type (parser, type_name,
5051 location_t expr_loc = c_parser_peek_token (parser)->location;
5052 expr = c_parser_cast_expression (parser, NULL);
5053 expr = default_function_array_read_conversion (expr_loc, expr);
5055 ret.value = c_cast_expr (cast_loc, type_name, expr.value);
5056 ret.original_code = ERROR_MARK;
5057 ret.original_type = NULL;
5061 return c_parser_unary_expression (parser);
5064 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5070 unary-operator cast-expression
5071 sizeof unary-expression
5072 sizeof ( type-name )
5074 unary-operator: one of
5080 __alignof__ unary-expression
5081 __alignof__ ( type-name )
5084 unary-operator: one of
5085 __extension__ __real__ __imag__
5087 In addition, the GNU syntax treats ++ and -- as unary operators, so
5088 they may be applied to cast expressions with errors for non-lvalues
5091 static struct c_expr
5092 c_parser_unary_expression (c_parser *parser)
5095 struct c_expr ret, op;
5096 location_t op_loc = c_parser_peek_token (parser)->location;
5098 ret.original_code = ERROR_MARK;
5099 ret.original_type = NULL;
5100 switch (c_parser_peek_token (parser)->type)
5103 c_parser_consume_token (parser);
5104 exp_loc = c_parser_peek_token (parser)->location;
5105 op = c_parser_cast_expression (parser, NULL);
5106 op = default_function_array_read_conversion (exp_loc, op);
5107 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op);
5108 case CPP_MINUS_MINUS:
5109 c_parser_consume_token (parser);
5110 exp_loc = c_parser_peek_token (parser)->location;
5111 op = c_parser_cast_expression (parser, NULL);
5112 op = default_function_array_read_conversion (exp_loc, op);
5113 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op);
5115 c_parser_consume_token (parser);
5116 op = c_parser_cast_expression (parser, NULL);
5117 mark_exp_read (op.value);
5118 return parser_build_unary_op (op_loc, ADDR_EXPR, op);
5120 c_parser_consume_token (parser);
5121 exp_loc = c_parser_peek_token (parser)->location;
5122 op = c_parser_cast_expression (parser, NULL);
5123 op = default_function_array_read_conversion (exp_loc, op);
5124 ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR);
5127 if (!c_dialect_objc () && !in_system_header)
5130 "traditional C rejects the unary plus operator");
5131 c_parser_consume_token (parser);
5132 exp_loc = c_parser_peek_token (parser)->location;
5133 op = c_parser_cast_expression (parser, NULL);
5134 op = default_function_array_read_conversion (exp_loc, op);
5135 return parser_build_unary_op (op_loc, CONVERT_EXPR, op);
5137 c_parser_consume_token (parser);
5138 exp_loc = c_parser_peek_token (parser)->location;
5139 op = c_parser_cast_expression (parser, NULL);
5140 op = default_function_array_read_conversion (exp_loc, op);
5141 return parser_build_unary_op (op_loc, NEGATE_EXPR, op);
5143 c_parser_consume_token (parser);
5144 exp_loc = c_parser_peek_token (parser)->location;
5145 op = c_parser_cast_expression (parser, NULL);
5146 op = default_function_array_read_conversion (exp_loc, op);
5147 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op);
5149 c_parser_consume_token (parser);
5150 exp_loc = c_parser_peek_token (parser)->location;
5151 op = c_parser_cast_expression (parser, NULL);
5152 op = default_function_array_read_conversion (exp_loc, op);
5153 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op);
5155 /* Refer to the address of a label as a pointer. */
5156 c_parser_consume_token (parser);
5157 if (c_parser_next_token_is (parser, CPP_NAME))
5159 ret.value = finish_label_address_expr
5160 (c_parser_peek_token (parser)->value, op_loc);
5161 c_parser_consume_token (parser);
5165 c_parser_error (parser, "expected identifier");
5166 ret.value = error_mark_node;
5170 switch (c_parser_peek_token (parser)->keyword)
5173 return c_parser_sizeof_expression (parser);
5175 return c_parser_alignof_expression (parser);
5177 c_parser_consume_token (parser);
5178 ext = disable_extension_diagnostics ();
5179 ret = c_parser_cast_expression (parser, NULL);
5180 restore_extension_diagnostics (ext);
5183 c_parser_consume_token (parser);
5184 exp_loc = c_parser_peek_token (parser)->location;
5185 op = c_parser_cast_expression (parser, NULL);
5186 op = default_function_array_conversion (exp_loc, op);
5187 return parser_build_unary_op (op_loc, REALPART_EXPR, op);
5189 c_parser_consume_token (parser);
5190 exp_loc = c_parser_peek_token (parser)->location;
5191 op = c_parser_cast_expression (parser, NULL);
5192 op = default_function_array_conversion (exp_loc, op);
5193 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op);
5195 return c_parser_postfix_expression (parser);
5198 return c_parser_postfix_expression (parser);
5202 /* Parse a sizeof expression. */
5204 static struct c_expr
5205 c_parser_sizeof_expression (c_parser *parser)
5208 location_t expr_loc;
5209 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
5210 c_parser_consume_token (parser);
5211 c_inhibit_evaluation_warnings++;
5213 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5214 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5216 /* Either sizeof ( type-name ) or sizeof unary-expression
5217 starting with a compound literal. */
5218 struct c_type_name *type_name;
5219 c_parser_consume_token (parser);
5220 expr_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 /* sizeof ( type-name ). */
5241 c_inhibit_evaluation_warnings--;
5243 return c_expr_sizeof_type (expr_loc, type_name);
5247 expr_loc = c_parser_peek_token (parser)->location;
5248 expr = c_parser_unary_expression (parser);
5250 c_inhibit_evaluation_warnings--;
5252 mark_exp_read (expr.value);
5253 if (TREE_CODE (expr.value) == COMPONENT_REF
5254 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
5255 error_at (expr_loc, "%<sizeof%> applied to a bit-field");
5256 return c_expr_sizeof_expr (expr_loc, expr);
5260 /* Parse an alignof expression. */
5262 static struct c_expr
5263 c_parser_alignof_expression (c_parser *parser)
5266 location_t loc = c_parser_peek_token (parser)->location;
5267 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
5268 c_parser_consume_token (parser);
5269 c_inhibit_evaluation_warnings++;
5271 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
5272 && c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5274 /* Either __alignof__ ( type-name ) or __alignof__
5275 unary-expression starting with a compound literal. */
5277 struct c_type_name *type_name;
5279 c_parser_consume_token (parser);
5280 loc = c_parser_peek_token (parser)->location;
5281 type_name = c_parser_type_name (parser);
5282 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
5283 if (type_name == NULL)
5286 c_inhibit_evaluation_warnings--;
5288 ret.value = error_mark_node;
5289 ret.original_code = ERROR_MARK;
5290 ret.original_type = NULL;
5293 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
5295 expr = c_parser_postfix_expression_after_paren_type (parser,
5300 /* alignof ( type-name ). */
5301 c_inhibit_evaluation_warnings--;
5303 ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
5304 ret.original_code = ERROR_MARK;
5305 ret.original_type = NULL;
5311 expr = c_parser_unary_expression (parser);
5313 mark_exp_read (expr.value);
5314 c_inhibit_evaluation_warnings--;
5316 ret.value = c_alignof_expr (loc, expr.value);
5317 ret.original_code = ERROR_MARK;
5318 ret.original_type = NULL;
5323 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5327 postfix-expression [ expression ]
5328 postfix-expression ( argument-expression-list[opt] )
5329 postfix-expression . identifier
5330 postfix-expression -> identifier
5331 postfix-expression ++
5332 postfix-expression --
5333 ( type-name ) { initializer-list }
5334 ( type-name ) { initializer-list , }
5336 argument-expression-list:
5338 argument-expression-list , argument-expression
5350 (treated as a keyword in GNU C)
5353 ( compound-statement )
5354 __builtin_va_arg ( assignment-expression , type-name )
5355 __builtin_offsetof ( type-name , offsetof-member-designator )
5356 __builtin_choose_expr ( assignment-expression ,
5357 assignment-expression ,
5358 assignment-expression )
5359 __builtin_types_compatible_p ( type-name , type-name )
5361 offsetof-member-designator:
5363 offsetof-member-designator . identifier
5364 offsetof-member-designator [ expression ]
5369 [ objc-receiver objc-message-args ]
5370 @selector ( objc-selector-arg )
5371 @protocol ( identifier )
5372 @encode ( type-name )
5376 static struct c_expr
5377 c_parser_postfix_expression (c_parser *parser)
5379 struct c_expr expr, e1, e2, e3;
5380 struct c_type_name *t1, *t2;
5381 location_t loc = c_parser_peek_token (parser)->location;;
5382 expr.original_code = ERROR_MARK;
5383 expr.original_type = NULL;
5384 switch (c_parser_peek_token (parser)->type)
5387 expr.value = c_parser_peek_token (parser)->value;
5388 loc = c_parser_peek_token (parser)->location;
5389 c_parser_consume_token (parser);
5390 if (TREE_CODE (expr.value) == FIXED_CST
5391 && !targetm.fixed_point_supported_p ())
5393 error_at (loc, "fixed-point types not supported for this target");
5394 expr.value = error_mark_node;
5401 expr.value = c_parser_peek_token (parser)->value;
5402 c_parser_consume_token (parser);
5408 case CPP_UTF8STRING:
5409 expr.value = c_parser_peek_token (parser)->value;
5410 expr.original_code = STRING_CST;
5411 c_parser_consume_token (parser);
5413 case CPP_OBJC_STRING:
5414 gcc_assert (c_dialect_objc ());
5416 = objc_build_string_object (c_parser_peek_token (parser)->value);
5417 c_parser_consume_token (parser);
5420 if (c_parser_peek_token (parser)->id_kind != C_ID_ID)
5422 c_parser_error (parser, "expected expression");
5423 expr.value = error_mark_node;
5427 tree id = c_parser_peek_token (parser)->value;
5428 c_parser_consume_token (parser);
5429 expr.value = build_external_ref (loc, id,
5430 (c_parser_peek_token (parser)->type
5432 &expr.original_type);
5435 case CPP_OPEN_PAREN:
5436 /* A parenthesized expression, statement expression or compound
5438 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE)
5440 /* A statement expression. */
5442 location_t brace_loc;
5443 c_parser_consume_token (parser);
5444 brace_loc = c_parser_peek_token (parser)->location;
5445 c_parser_consume_token (parser);
5446 if (cur_stmt_list == NULL)
5448 error_at (loc, "braced-group within expression allowed "
5449 "only inside a function");
5450 parser->error = true;
5451 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
5452 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5453 expr.value = error_mark_node;
5456 stmt = c_begin_stmt_expr ();
5457 c_parser_compound_statement_nostart (parser);
5458 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5460 pedwarn (loc, OPT_pedantic,
5461 "ISO C forbids braced-groups within expressions");
5462 expr.value = c_finish_stmt_expr (brace_loc, stmt);
5464 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
5466 /* A compound literal. ??? Can we actually get here rather
5467 than going directly to
5468 c_parser_postfix_expression_after_paren_type from
5471 struct c_type_name *type_name;
5472 c_parser_consume_token (parser);
5473 loc = c_parser_peek_token (parser)->location;
5474 type_name = c_parser_type_name (parser);
5475 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5477 if (type_name == NULL)
5479 expr.value = error_mark_node;
5482 expr = c_parser_postfix_expression_after_paren_type (parser,
5488 /* A parenthesized expression. */
5489 c_parser_consume_token (parser);
5490 expr = c_parser_expression (parser);
5491 if (TREE_CODE (expr.value) == MODIFY_EXPR)
5492 TREE_NO_WARNING (expr.value) = 1;
5493 if (expr.original_code != C_MAYBE_CONST_EXPR)
5494 expr.original_code = ERROR_MARK;
5495 /* Don't change EXPR.ORIGINAL_TYPE. */
5496 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5501 switch (c_parser_peek_token (parser)->keyword)
5503 case RID_FUNCTION_NAME:
5504 case RID_PRETTY_FUNCTION_NAME:
5505 case RID_C99_FUNCTION_NAME:
5506 expr.value = fname_decl (loc,
5507 c_parser_peek_token (parser)->keyword,
5508 c_parser_peek_token (parser)->value);
5509 c_parser_consume_token (parser);
5512 c_parser_consume_token (parser);
5513 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5515 expr.value = error_mark_node;
5518 e1 = c_parser_expr_no_commas (parser, NULL);
5519 mark_exp_read (e1.value);
5520 e1.value = c_fully_fold (e1.value, false, NULL);
5521 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5523 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5524 expr.value = error_mark_node;
5527 loc = c_parser_peek_token (parser)->location;
5528 t1 = c_parser_type_name (parser);
5529 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5533 expr.value = error_mark_node;
5537 tree type_expr = NULL_TREE;
5538 expr.value = c_build_va_arg (loc, e1.value,
5539 groktypename (t1, &type_expr, NULL));
5542 expr.value = build2 (C_MAYBE_CONST_EXPR,
5543 TREE_TYPE (expr.value), type_expr,
5545 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true;
5550 c_parser_consume_token (parser);
5551 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5553 expr.value = error_mark_node;
5556 t1 = c_parser_type_name (parser);
5559 expr.value = error_mark_node;
5562 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5564 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5565 expr.value = error_mark_node;
5569 tree type = groktypename (t1, NULL, NULL);
5571 if (type == error_mark_node)
5572 offsetof_ref = error_mark_node;
5575 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
5576 SET_EXPR_LOCATION (offsetof_ref, loc);
5578 /* Parse the second argument to __builtin_offsetof. We
5579 must have one identifier, and beyond that we want to
5580 accept sub structure and sub array references. */
5581 if (c_parser_next_token_is (parser, CPP_NAME))
5583 offsetof_ref = build_component_ref
5584 (loc, offsetof_ref, c_parser_peek_token (parser)->value);
5585 c_parser_consume_token (parser);
5586 while (c_parser_next_token_is (parser, CPP_DOT)
5587 || c_parser_next_token_is (parser,
5589 || c_parser_next_token_is (parser,
5592 if (c_parser_next_token_is (parser, CPP_DEREF))
5594 loc = c_parser_peek_token (parser)->location;
5595 offsetof_ref = build_array_ref (loc,
5600 else if (c_parser_next_token_is (parser, CPP_DOT))
5603 c_parser_consume_token (parser);
5604 if (c_parser_next_token_is_not (parser,
5607 c_parser_error (parser, "expected identifier");
5610 offsetof_ref = build_component_ref
5612 c_parser_peek_token (parser)->value);
5613 c_parser_consume_token (parser);
5618 loc = c_parser_peek_token (parser)->location;
5619 c_parser_consume_token (parser);
5620 idx = c_parser_expression (parser).value;
5621 idx = c_fully_fold (idx, false, NULL);
5622 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5624 offsetof_ref = build_array_ref (loc, offsetof_ref, idx);
5629 c_parser_error (parser, "expected identifier");
5630 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5632 expr.value = fold_offsetof (offsetof_ref, NULL_TREE);
5635 case RID_CHOOSE_EXPR:
5636 c_parser_consume_token (parser);
5637 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5639 expr.value = error_mark_node;
5642 loc = c_parser_peek_token (parser)->location;
5643 e1 = c_parser_expr_no_commas (parser, NULL);
5644 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5646 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5647 expr.value = error_mark_node;
5650 e2 = c_parser_expr_no_commas (parser, NULL);
5651 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5653 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5654 expr.value = error_mark_node;
5657 e3 = c_parser_expr_no_commas (parser, NULL);
5658 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5664 mark_exp_read (e2.value);
5665 mark_exp_read (e3.value);
5666 if (TREE_CODE (c) != INTEGER_CST
5667 || !INTEGRAL_TYPE_P (TREE_TYPE (c)))
5669 "first argument to %<__builtin_choose_expr%> not"
5671 constant_expression_warning (c);
5672 expr = integer_zerop (c) ? e3 : e2;
5675 case RID_TYPES_COMPATIBLE_P:
5676 c_parser_consume_token (parser);
5677 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5679 expr.value = error_mark_node;
5682 t1 = c_parser_type_name (parser);
5685 expr.value = error_mark_node;
5688 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
5690 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5691 expr.value = error_mark_node;
5694 t2 = c_parser_type_name (parser);
5697 expr.value = error_mark_node;
5700 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5705 e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
5706 e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
5708 expr.value = comptypes (e1, e2)
5709 ? build_int_cst (NULL_TREE, 1)
5710 : build_int_cst (NULL_TREE, 0);
5713 case RID_AT_SELECTOR:
5714 gcc_assert (c_dialect_objc ());
5715 c_parser_consume_token (parser);
5716 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5718 expr.value = error_mark_node;
5722 tree sel = c_parser_objc_selector_arg (parser);
5723 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5725 expr.value = objc_build_selector_expr (loc, sel);
5728 case RID_AT_PROTOCOL:
5729 gcc_assert (c_dialect_objc ());
5730 c_parser_consume_token (parser);
5731 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5733 expr.value = error_mark_node;
5736 if (c_parser_next_token_is_not (parser, CPP_NAME))
5738 c_parser_error (parser, "expected identifier");
5739 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5740 expr.value = error_mark_node;
5744 tree id = c_parser_peek_token (parser)->value;
5745 c_parser_consume_token (parser);
5746 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5748 expr.value = objc_build_protocol_expr (id);
5752 /* Extension to support C-structures in the archiver. */
5753 gcc_assert (c_dialect_objc ());
5754 c_parser_consume_token (parser);
5755 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
5757 expr.value = error_mark_node;
5760 t1 = c_parser_type_name (parser);
5763 expr.value = error_mark_node;
5764 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
5767 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5770 tree type = groktypename (t1, NULL, NULL);
5771 expr.value = objc_build_encode_expr (type);
5775 c_parser_error (parser, "expected expression");
5776 expr.value = error_mark_node;
5780 case CPP_OPEN_SQUARE:
5781 if (c_dialect_objc ())
5783 tree receiver, args;
5784 c_parser_consume_token (parser);
5785 receiver = c_parser_objc_receiver (parser);
5786 args = c_parser_objc_message_args (parser);
5787 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5789 expr.value = objc_build_message_expr (build_tree_list (receiver,
5793 /* Else fall through to report error. */
5795 c_parser_error (parser, "expected expression");
5796 expr.value = error_mark_node;
5799 return c_parser_postfix_expression_after_primary (parser, loc, expr);
5802 /* Parse a postfix expression after a parenthesized type name: the
5803 brace-enclosed initializer of a compound literal, possibly followed
5804 by some postfix operators. This is separate because it is not
5805 possible to tell until after the type name whether a cast
5806 expression has a cast or a compound literal, or whether the operand
5807 of sizeof is a parenthesized type name or starts with a compound
5808 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5809 location of the first token after the parentheses around the type
5812 static struct c_expr
5813 c_parser_postfix_expression_after_paren_type (c_parser *parser,
5814 struct c_type_name *type_name,
5815 location_t type_loc)
5821 location_t start_loc;
5822 tree type_expr = NULL_TREE;
5823 bool type_expr_const = true;
5824 check_compound_literal_type (type_loc, type_name);
5825 start_init (NULL_TREE, NULL, 0);
5826 type = groktypename (type_name, &type_expr, &type_expr_const);
5827 start_loc = c_parser_peek_token (parser)->location;
5828 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type))
5830 error_at (type_loc, "compound literal has variable size");
5831 type = error_mark_node;
5833 init = c_parser_braced_init (parser, type, false);
5835 maybe_warn_string_init (type, init);
5837 if (type != error_mark_node
5838 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
5839 && current_function_decl)
5841 error ("compound literal qualified by address-space qualifier");
5842 type = error_mark_node;
5846 pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals");
5847 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR)
5848 ? CONSTRUCTOR_NON_CONST (init.value)
5849 : init.original_code == C_MAYBE_CONST_EXPR);
5850 non_const |= !type_expr_const;
5851 expr.value = build_compound_literal (start_loc, type, init.value, non_const);
5852 expr.original_code = ERROR_MARK;
5853 expr.original_type = NULL;
5856 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
5858 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE);
5859 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr;
5863 gcc_assert (!non_const);
5864 expr.value = build2 (C_MAYBE_CONST_EXPR, type,
5865 type_expr, expr.value);
5868 return c_parser_postfix_expression_after_primary (parser, start_loc, expr);
5871 /* Parse a postfix expression after the initial primary or compound
5872 literal; that is, parse a series of postfix operators.
5874 EXPR_LOC is the location of the primary expression. */
5876 static struct c_expr
5877 c_parser_postfix_expression_after_primary (c_parser *parser,
5878 location_t expr_loc,
5881 struct c_expr orig_expr;
5883 VEC(tree,gc) *exprlist;
5884 VEC(tree,gc) *origtypes;
5887 location_t op_loc = c_parser_peek_token (parser)->location;
5888 switch (c_parser_peek_token (parser)->type)
5890 case CPP_OPEN_SQUARE:
5891 /* Array reference. */
5892 c_parser_consume_token (parser);
5893 idx = c_parser_expression (parser).value;
5894 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
5896 expr.value = build_array_ref (op_loc, expr.value, idx);
5897 expr.original_code = ERROR_MARK;
5898 expr.original_type = NULL;
5900 case CPP_OPEN_PAREN:
5901 /* Function call. */
5902 c_parser_consume_token (parser);
5903 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
5906 exprlist = c_parser_expr_list (parser, true, false, &origtypes);
5907 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
5910 mark_exp_read (expr.value);
5911 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5912 "(" after the FUNCNAME, which is what we have now. */
5913 expr.value = build_function_call_vec (op_loc, expr.value, exprlist,
5915 expr.original_code = ERROR_MARK;
5916 if (TREE_CODE (expr.value) == INTEGER_CST
5917 && TREE_CODE (orig_expr.value) == FUNCTION_DECL
5918 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
5919 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
5920 expr.original_code = C_MAYBE_CONST_EXPR;
5921 expr.original_type = NULL;
5922 if (exprlist != NULL)
5924 release_tree_vector (exprlist);
5925 release_tree_vector (origtypes);
5929 /* Structure element reference. */
5930 c_parser_consume_token (parser);
5931 expr = default_function_array_conversion (expr_loc, expr);
5932 if (c_parser_next_token_is (parser, CPP_NAME))
5933 ident = c_parser_peek_token (parser)->value;
5936 c_parser_error (parser, "expected identifier");
5937 expr.value = error_mark_node;
5938 expr.original_code = ERROR_MARK;
5939 expr.original_type = NULL;
5942 c_parser_consume_token (parser);
5943 expr.value = build_component_ref (op_loc, expr.value, ident);
5944 expr.original_code = ERROR_MARK;
5945 if (TREE_CODE (expr.value) != COMPONENT_REF)
5946 expr.original_type = NULL;
5949 /* Remember the original type of a bitfield. */
5950 tree field = TREE_OPERAND (expr.value, 1);
5951 if (TREE_CODE (field) != FIELD_DECL)
5952 expr.original_type = NULL;
5954 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5958 /* Structure element reference. */
5959 c_parser_consume_token (parser);
5960 expr = default_function_array_conversion (expr_loc, expr);
5961 if (c_parser_next_token_is (parser, CPP_NAME))
5962 ident = c_parser_peek_token (parser)->value;
5965 c_parser_error (parser, "expected identifier");
5966 expr.value = error_mark_node;
5967 expr.original_code = ERROR_MARK;
5968 expr.original_type = NULL;
5971 c_parser_consume_token (parser);
5972 expr.value = build_component_ref (op_loc,
5973 build_indirect_ref (op_loc,
5977 expr.original_code = ERROR_MARK;
5978 if (TREE_CODE (expr.value) != COMPONENT_REF)
5979 expr.original_type = NULL;
5982 /* Remember the original type of a bitfield. */
5983 tree field = TREE_OPERAND (expr.value, 1);
5984 if (TREE_CODE (field) != FIELD_DECL)
5985 expr.original_type = NULL;
5987 expr.original_type = DECL_BIT_FIELD_TYPE (field);
5991 /* Postincrement. */
5992 c_parser_consume_token (parser);
5993 expr = default_function_array_read_conversion (expr_loc, expr);
5994 expr.value = build_unary_op (op_loc,
5995 POSTINCREMENT_EXPR, expr.value, 0);
5996 expr.original_code = ERROR_MARK;
5997 expr.original_type = NULL;
5999 case CPP_MINUS_MINUS:
6000 /* Postdecrement. */
6001 c_parser_consume_token (parser);
6002 expr = default_function_array_read_conversion (expr_loc, expr);
6003 expr.value = build_unary_op (op_loc,
6004 POSTDECREMENT_EXPR, expr.value, 0);
6005 expr.original_code = ERROR_MARK;
6006 expr.original_type = NULL;
6014 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6017 assignment-expression
6018 expression , assignment-expression
6021 static struct c_expr
6022 c_parser_expression (c_parser *parser)
6025 expr = c_parser_expr_no_commas (parser, NULL);
6026 while (c_parser_next_token_is (parser, CPP_COMMA))
6029 location_t loc = c_parser_peek_token (parser)->location;
6030 location_t expr_loc;
6031 c_parser_consume_token (parser);
6032 expr_loc = c_parser_peek_token (parser)->location;
6033 next = c_parser_expr_no_commas (parser, NULL);
6034 next = default_function_array_conversion (expr_loc, next);
6035 expr.value = build_compound_expr (loc, expr.value, next.value);
6036 expr.original_code = COMPOUND_EXPR;
6037 expr.original_type = next.original_type;
6042 /* Parse an expression and convert functions or arrays to
6045 static struct c_expr
6046 c_parser_expression_conv (c_parser *parser)
6049 location_t loc = c_parser_peek_token (parser)->location;
6050 expr = c_parser_expression (parser);
6051 expr = default_function_array_conversion (loc, expr);
6055 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6056 functions and arrays to pointers. If FOLD_P, fold the expressions.
6059 assignment-expression
6060 nonempty-expr-list , assignment-expression
6063 static VEC(tree,gc) *
6064 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
6065 VEC(tree,gc) **p_orig_types)
6068 VEC(tree,gc) *orig_types;
6070 location_t loc = c_parser_peek_token (parser)->location;
6072 ret = make_tree_vector ();
6073 if (p_orig_types == NULL)
6076 orig_types = make_tree_vector ();
6078 expr = c_parser_expr_no_commas (parser, NULL);
6080 expr = default_function_array_read_conversion (loc, expr);
6082 expr.value = c_fully_fold (expr.value, false, NULL);
6083 VEC_quick_push (tree, ret, expr.value);
6084 if (orig_types != NULL)
6085 VEC_quick_push (tree, orig_types, expr.original_type);
6086 while (c_parser_next_token_is (parser, CPP_COMMA))
6088 c_parser_consume_token (parser);
6089 loc = c_parser_peek_token (parser)->location;
6090 expr = c_parser_expr_no_commas (parser, NULL);
6092 expr = default_function_array_read_conversion (loc, expr);
6094 expr.value = c_fully_fold (expr.value, false, NULL);
6095 VEC_safe_push (tree, gc, ret, expr.value);
6096 if (orig_types != NULL)
6097 VEC_safe_push (tree, gc, orig_types, expr.original_type);
6099 if (orig_types != NULL)
6100 *p_orig_types = orig_types;
6104 /* Parse Objective-C-specific constructs. */
6106 /* Parse an objc-class-definition.
6108 objc-class-definition:
6109 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6110 objc-class-instance-variables[opt] objc-methodprotolist @end
6111 @implementation identifier objc-superclass[opt]
6112 objc-class-instance-variables[opt]
6113 @interface identifier ( identifier ) objc-protocol-refs[opt]
6114 objc-methodprotolist @end
6115 @implementation identifier ( identifier )
6120 "@interface identifier (" must start "@interface identifier (
6121 identifier ) ...": objc-methodprotolist in the first production may
6122 not start with a parenthesized identifier as a declarator of a data
6123 definition with no declaration specifiers if the objc-superclass,
6124 objc-protocol-refs and objc-class-instance-variables are omitted. */
6127 c_parser_objc_class_definition (c_parser *parser)
6132 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE))
6134 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION))
6138 c_parser_consume_token (parser);
6139 if (c_parser_next_token_is_not (parser, CPP_NAME))
6141 c_parser_error (parser, "expected identifier");
6144 id1 = c_parser_peek_token (parser)->value;
6145 c_parser_consume_token (parser);
6146 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6149 tree proto = NULL_TREE;
6150 c_parser_consume_token (parser);
6151 if (c_parser_next_token_is_not (parser, CPP_NAME))
6153 c_parser_error (parser, "expected identifier");
6154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6157 id2 = c_parser_peek_token (parser)->value;
6158 c_parser_consume_token (parser);
6159 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6162 objc_start_category_implementation (id1, id2);
6165 if (c_parser_next_token_is (parser, CPP_LESS))
6166 proto = c_parser_objc_protocol_refs (parser);
6167 objc_start_category_interface (id1, id2, proto);
6168 c_parser_objc_methodprotolist (parser);
6169 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6170 objc_finish_interface ();
6173 if (c_parser_next_token_is (parser, CPP_COLON))
6175 c_parser_consume_token (parser);
6176 if (c_parser_next_token_is_not (parser, CPP_NAME))
6178 c_parser_error (parser, "expected identifier");
6181 superclass = c_parser_peek_token (parser)->value;
6182 c_parser_consume_token (parser);
6185 superclass = NULL_TREE;
6188 tree proto = NULL_TREE;
6189 if (c_parser_next_token_is (parser, CPP_LESS))
6190 proto = c_parser_objc_protocol_refs (parser);
6191 objc_start_class_interface (id1, superclass, proto);
6194 objc_start_class_implementation (id1, superclass);
6195 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6196 c_parser_objc_class_instance_variables (parser);
6199 objc_continue_interface ();
6200 c_parser_objc_methodprotolist (parser);
6201 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6202 objc_finish_interface ();
6206 objc_continue_implementation ();
6211 /* Parse objc-class-instance-variables.
6213 objc-class-instance-variables:
6214 { objc-instance-variable-decl-list[opt] }
6216 objc-instance-variable-decl-list:
6217 objc-visibility-spec
6218 objc-instance-variable-decl ;
6220 objc-instance-variable-decl-list objc-visibility-spec
6221 objc-instance-variable-decl-list objc-instance-variable-decl ;
6222 objc-instance-variable-decl-list ;
6224 objc-visibility-spec:
6229 objc-instance-variable-decl:
6234 c_parser_objc_class_instance_variables (c_parser *parser)
6236 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
6237 c_parser_consume_token (parser);
6238 while (c_parser_next_token_is_not (parser, CPP_EOF))
6241 /* Parse any stray semicolon. */
6242 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6244 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6245 "extra semicolon in struct or union specified");
6246 c_parser_consume_token (parser);
6249 /* Stop if at the end of the instance variables. */
6250 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
6252 c_parser_consume_token (parser);
6255 /* Parse any objc-visibility-spec. */
6256 if (c_parser_next_token_is_keyword (parser, RID_PRIVATE))
6258 c_parser_consume_token (parser);
6259 objc_set_visibility (2);
6262 else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED))
6264 c_parser_consume_token (parser);
6265 objc_set_visibility (0);
6268 else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC))
6270 c_parser_consume_token (parser);
6271 objc_set_visibility (1);
6274 else if (c_parser_next_token_is (parser, CPP_PRAGMA))
6276 c_parser_pragma (parser, pragma_external);
6280 /* Parse some comma-separated declarations. */
6281 decls = c_parser_struct_declaration (parser);
6283 /* Comma-separated instance variables are chained together in
6284 reverse order; add them one by one. */
6285 tree ivar = nreverse (decls);
6286 for (; ivar; ivar = TREE_CHAIN (ivar))
6287 objc_add_instance_variable (copy_node (ivar));
6289 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6293 /* Parse an objc-class-declaration.
6295 objc-class-declaration:
6296 @class identifier-list ;
6300 c_parser_objc_class_declaration (c_parser *parser)
6302 tree list = NULL_TREE;
6303 gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS));
6304 c_parser_consume_token (parser);
6305 /* Any identifiers, including those declared as type names, are OK
6310 if (c_parser_next_token_is_not (parser, CPP_NAME))
6312 c_parser_error (parser, "expected identifier");
6315 id = c_parser_peek_token (parser)->value;
6316 list = chainon (list, build_tree_list (NULL_TREE, id));
6317 c_parser_consume_token (parser);
6318 if (c_parser_next_token_is (parser, CPP_COMMA))
6319 c_parser_consume_token (parser);
6323 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6324 objc_declare_class (list);
6327 /* Parse an objc-alias-declaration.
6329 objc-alias-declaration:
6330 @compatibility_alias identifier identifier ;
6334 c_parser_objc_alias_declaration (c_parser *parser)
6337 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS));
6338 c_parser_consume_token (parser);
6339 if (c_parser_next_token_is_not (parser, CPP_NAME))
6341 c_parser_error (parser, "expected identifier");
6342 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6345 id1 = c_parser_peek_token (parser)->value;
6346 c_parser_consume_token (parser);
6347 if (c_parser_next_token_is_not (parser, CPP_NAME))
6349 c_parser_error (parser, "expected identifier");
6350 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
6353 id2 = c_parser_peek_token (parser)->value;
6354 c_parser_consume_token (parser);
6355 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6356 objc_declare_alias (id1, id2);
6359 /* Parse an objc-protocol-definition.
6361 objc-protocol-definition:
6362 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6363 @protocol identifier-list ;
6365 "@protocol identifier ;" should be resolved as "@protocol
6366 identifier-list ;": objc-methodprotolist may not start with a
6367 semicolon in the first alternative if objc-protocol-refs are
6371 c_parser_objc_protocol_definition (c_parser *parser)
6373 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL));
6374 c_parser_consume_token (parser);
6375 if (c_parser_next_token_is_not (parser, CPP_NAME))
6377 c_parser_error (parser, "expected identifier");
6380 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
6381 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
6383 tree list = NULL_TREE;
6384 /* Any identifiers, including those declared as type names, are
6389 if (c_parser_next_token_is_not (parser, CPP_NAME))
6391 c_parser_error (parser, "expected identifier");
6394 id = c_parser_peek_token (parser)->value;
6395 list = chainon (list, build_tree_list (NULL_TREE, id));
6396 c_parser_consume_token (parser);
6397 if (c_parser_next_token_is (parser, CPP_COMMA))
6398 c_parser_consume_token (parser);
6402 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6403 objc_declare_protocols (list);
6407 tree id = c_parser_peek_token (parser)->value;
6408 tree proto = NULL_TREE;
6409 c_parser_consume_token (parser);
6410 if (c_parser_next_token_is (parser, CPP_LESS))
6411 proto = c_parser_objc_protocol_refs (parser);
6412 parser->objc_pq_context = true;
6413 objc_start_protocol (id, proto);
6414 c_parser_objc_methodprotolist (parser);
6415 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
6416 parser->objc_pq_context = false;
6417 objc_finish_interface ();
6421 /* Parse an objc-method-type.
6428 static enum tree_code
6429 c_parser_objc_method_type (c_parser *parser)
6431 switch (c_parser_peek_token (parser)->type)
6434 c_parser_consume_token (parser);
6437 c_parser_consume_token (parser);
6444 /* Parse an objc-method-definition.
6446 objc-method-definition:
6447 objc-method-type objc-method-decl ;[opt] compound-statement
6451 c_parser_objc_method_definition (c_parser *parser)
6453 enum tree_code type = c_parser_objc_method_type (parser);
6455 objc_set_method_type (type);
6456 parser->objc_pq_context = true;
6457 decl = c_parser_objc_method_decl (parser);
6458 if (c_parser_next_token_is (parser, CPP_SEMICOLON))
6460 c_parser_consume_token (parser);
6461 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6462 "extra semicolon in method definition specified");
6464 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
6466 c_parser_error (parser, "expected %<{%>");
6469 parser->objc_pq_context = false;
6470 objc_start_method_definition (decl);
6471 add_stmt (c_parser_compound_statement (parser));
6472 objc_finish_method_definition (current_function_decl);
6475 /* Parse an objc-methodprotolist.
6477 objc-methodprotolist:
6479 objc-methodprotolist objc-methodproto
6480 objc-methodprotolist declaration
6481 objc-methodprotolist ;
6483 The declaration is a data definition, which may be missing
6484 declaration specifiers under the same rules and diagnostics as
6485 other data definitions outside functions, and the stray semicolon
6486 is diagnosed the same way as a stray semicolon outside a
6490 c_parser_objc_methodprotolist (c_parser *parser)
6494 /* The list is terminated by @end. */
6495 switch (c_parser_peek_token (parser)->type)
6498 pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
6499 "ISO C does not allow extra %<;%> outside of a function");
6500 c_parser_consume_token (parser);
6504 c_parser_objc_methodproto (parser);
6507 c_parser_pragma (parser, pragma_external);
6512 if (c_parser_next_token_is_keyword (parser, RID_AT_END))
6514 c_parser_declaration_or_fndef (parser, false, true, false, true);
6520 /* Parse an objc-methodproto.
6523 objc-method-type objc-method-decl ;
6527 c_parser_objc_methodproto (c_parser *parser)
6529 enum tree_code type = c_parser_objc_method_type (parser);
6531 objc_set_method_type (type);
6532 /* Remember protocol qualifiers in prototypes. */
6533 parser->objc_pq_context = true;
6534 decl = c_parser_objc_method_decl (parser);
6535 /* Forget protocol qualifiers here. */
6536 parser->objc_pq_context = false;
6537 objc_add_method_declaration (decl);
6538 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
6541 /* Parse an objc-method-decl.
6544 ( objc-type-name ) objc-selector
6546 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6547 objc-keyword-selector objc-optparmlist
6549 objc-keyword-selector:
6551 objc-keyword-selector objc-keyword-decl
6554 objc-selector : ( objc-type-name ) identifier
6555 objc-selector : identifier
6556 : ( objc-type-name ) identifier
6560 objc-optparms objc-optellipsis
6564 objc-opt-parms , parameter-declaration
6572 c_parser_objc_method_decl (c_parser *parser)
6574 tree type = NULL_TREE;
6576 tree parms = NULL_TREE;
6577 bool ellipsis = false;
6579 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6581 c_parser_consume_token (parser);
6582 type = c_parser_objc_type_name (parser);
6583 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6585 sel = c_parser_objc_selector (parser);
6586 /* If there is no selector, or a colon follows, we have an
6587 objc-keyword-selector. If there is a selector, and a colon does
6588 not follow, that selector ends the objc-method-decl. */
6589 if (!sel || c_parser_next_token_is (parser, CPP_COLON))
6592 tree list = NULL_TREE;
6595 tree atype = NULL_TREE, id, keyworddecl;
6596 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6598 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
6600 c_parser_consume_token (parser);
6601 atype = c_parser_objc_type_name (parser);
6602 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
6605 if (c_parser_next_token_is_not (parser, CPP_NAME))
6607 c_parser_error (parser, "expected identifier");
6608 return error_mark_node;
6610 id = c_parser_peek_token (parser)->value;
6611 c_parser_consume_token (parser);
6612 keyworddecl = objc_build_keyword_decl (tsel, atype, id);
6613 list = chainon (list, keyworddecl);
6614 tsel = c_parser_objc_selector (parser);
6615 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON))
6618 /* Parse the optional parameter list. Optional Objective-C
6619 method parameters follow the C syntax, and may include '...'
6620 to denote a variable number of arguments. */
6621 parms = make_node (TREE_LIST);
6622 while (c_parser_next_token_is (parser, CPP_COMMA))
6624 struct c_parm *parm;
6625 c_parser_consume_token (parser);
6626 if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
6629 c_parser_consume_token (parser);
6632 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6635 parms = chainon (parms,
6636 build_tree_list (NULL_TREE, grokparm (parm)));
6640 return objc_build_method_signature (type, sel, parms, ellipsis);
6643 /* Parse an objc-type-name.
6646 objc-type-qualifiers[opt] type-name
6647 objc-type-qualifiers[opt]
6649 objc-type-qualifiers:
6651 objc-type-qualifiers objc-type-qualifier
6653 objc-type-qualifier: one of
6654 in out inout bycopy byref oneway
6658 c_parser_objc_type_name (c_parser *parser)
6660 tree quals = NULL_TREE;
6661 struct c_type_name *type_name = NULL;
6662 tree type = NULL_TREE;
6665 c_token *token = c_parser_peek_token (parser);
6666 if (token->type == CPP_KEYWORD
6667 && (token->keyword == RID_IN
6668 || token->keyword == RID_OUT
6669 || token->keyword == RID_INOUT
6670 || token->keyword == RID_BYCOPY
6671 || token->keyword == RID_BYREF
6672 || token->keyword == RID_ONEWAY))
6674 quals = chainon (quals, build_tree_list (NULL_TREE, token->value));
6675 c_parser_consume_token (parser);
6680 if (c_parser_next_token_starts_typename (parser))
6681 type_name = c_parser_type_name (parser);
6683 type = groktypename (type_name, NULL, NULL);
6684 return build_tree_list (quals, type);
6687 /* Parse objc-protocol-refs.
6694 c_parser_objc_protocol_refs (c_parser *parser)
6696 tree list = NULL_TREE;
6697 gcc_assert (c_parser_next_token_is (parser, CPP_LESS));
6698 c_parser_consume_token (parser);
6699 /* Any identifiers, including those declared as type names, are OK
6704 if (c_parser_next_token_is_not (parser, CPP_NAME))
6706 c_parser_error (parser, "expected identifier");
6709 id = c_parser_peek_token (parser)->value;
6710 list = chainon (list, build_tree_list (NULL_TREE, id));
6711 c_parser_consume_token (parser);
6712 if (c_parser_next_token_is (parser, CPP_COMMA))
6713 c_parser_consume_token (parser);
6717 c_parser_require (parser, CPP_GREATER, "expected %<>%>");
6721 /* Parse an objc-try-catch-statement.
6723 objc-try-catch-statement:
6724 @try compound-statement objc-catch-list[opt]
6725 @try compound-statement objc-catch-list[opt] @finally compound-statement
6728 @catch ( parameter-declaration ) compound-statement
6729 objc-catch-list @catch ( parameter-declaration ) compound-statement
6733 c_parser_objc_try_catch_statement (c_parser *parser)
6737 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY));
6738 c_parser_consume_token (parser);
6739 loc = c_parser_peek_token (parser)->location;
6740 stmt = c_parser_compound_statement (parser);
6741 objc_begin_try_stmt (loc, stmt);
6742 while (c_parser_next_token_is_keyword (parser, RID_CATCH))
6744 struct c_parm *parm;
6745 c_parser_consume_token (parser);
6746 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6748 parm = c_parser_parameter_declaration (parser, NULL_TREE);
6751 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
6754 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6755 objc_begin_catch_clause (grokparm (parm));
6756 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
6757 c_parser_compound_statement_nostart (parser);
6758 objc_finish_catch_clause ();
6760 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY))
6764 c_parser_consume_token (parser);
6765 finloc = c_parser_peek_token (parser)->location;
6766 finstmt = c_parser_compound_statement (parser);
6767 objc_build_finally_clause (finloc, finstmt);
6769 objc_finish_try_stmt ();
6772 /* Parse an objc-synchronized-statement.
6774 objc-synchronized-statement:
6775 @synchronized ( expression ) compound-statement
6779 c_parser_objc_synchronized_statement (c_parser *parser)
6783 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
6784 c_parser_consume_token (parser);
6785 loc = c_parser_peek_token (parser)->location;
6786 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
6788 expr = c_parser_expression (parser).value;
6789 expr = c_fully_fold (expr, false, NULL);
6790 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
6793 expr = error_mark_node;
6794 stmt = c_parser_compound_statement (parser);
6795 objc_build_synchronized (loc, expr, stmt);
6798 /* Parse an objc-selector; return NULL_TREE without an error if the
6799 next token is not an objc-selector.
6804 enum struct union if else while do for switch case default
6805 break continue return goto asm sizeof typeof __alignof
6806 unsigned long const short volatile signed restrict _Complex
6807 in out inout bycopy byref oneway int char float double void _Bool
6809 ??? Why this selection of keywords but not, for example, storage
6810 class specifiers? */
6813 c_parser_objc_selector (c_parser *parser)
6815 c_token *token = c_parser_peek_token (parser);
6816 tree value = token->value;
6817 if (token->type == CPP_NAME)
6819 c_parser_consume_token (parser);
6822 if (token->type != CPP_KEYWORD)
6824 switch (token->keyword)
6865 c_parser_consume_token (parser);
6872 /* Parse an objc-selector-arg.
6876 objc-keywordname-list
6878 objc-keywordname-list:
6880 objc-keywordname-list objc-keywordname
6888 c_parser_objc_selector_arg (c_parser *parser)
6890 tree sel = c_parser_objc_selector (parser);
6891 tree list = NULL_TREE;
6892 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6896 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6898 list = chainon (list, build_tree_list (sel, NULL_TREE));
6899 sel = c_parser_objc_selector (parser);
6900 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6906 /* Parse an objc-receiver.
6915 c_parser_objc_receiver (c_parser *parser)
6917 if (c_parser_peek_token (parser)->type == CPP_NAME
6918 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME
6919 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
6921 tree id = c_parser_peek_token (parser)->value;
6922 c_parser_consume_token (parser);
6923 return objc_get_class_reference (id);
6925 return c_fully_fold (c_parser_expression (parser).value, false, NULL);
6928 /* Parse objc-message-args.
6932 objc-keywordarg-list
6934 objc-keywordarg-list:
6936 objc-keywordarg-list objc-keywordarg
6939 objc-selector : objc-keywordexpr
6944 c_parser_objc_message_args (c_parser *parser)
6946 tree sel = c_parser_objc_selector (parser);
6947 tree list = NULL_TREE;
6948 if (sel && c_parser_next_token_is_not (parser, CPP_COLON))
6953 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
6954 return error_mark_node;
6955 keywordexpr = c_parser_objc_keywordexpr (parser);
6956 list = chainon (list, build_tree_list (sel, keywordexpr));
6957 sel = c_parser_objc_selector (parser);
6958 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON))
6964 /* Parse an objc-keywordexpr.
6971 c_parser_objc_keywordexpr (c_parser *parser)
6974 VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL);
6975 if (VEC_length (tree, expr_list) == 1)
6977 /* Just return the expression, remove a level of
6979 ret = VEC_index (tree, expr_list, 0);
6983 /* We have a comma expression, we will collapse later. */
6984 ret = build_tree_list_vec (expr_list);
6986 release_tree_vector (expr_list);
6991 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6992 should be considered, statements. ALLOW_STMT is true if we're within
6993 the context of a function and such pragmas are to be allowed. Returns
6994 true if we actually parsed such a pragma. */
6997 c_parser_pragma (c_parser *parser, enum pragma_context context)
7001 id = c_parser_peek_token (parser)->pragma_kind;
7002 gcc_assert (id != PRAGMA_NONE);
7006 case PRAGMA_OMP_BARRIER:
7007 if (context != pragma_compound)
7009 if (context == pragma_stmt)
7010 c_parser_error (parser, "%<#pragma omp barrier%> may only be "
7011 "used in compound statements");
7014 c_parser_omp_barrier (parser);
7017 case PRAGMA_OMP_FLUSH:
7018 if (context != pragma_compound)
7020 if (context == pragma_stmt)
7021 c_parser_error (parser, "%<#pragma omp flush%> may only be "
7022 "used in compound statements");
7025 c_parser_omp_flush (parser);
7028 case PRAGMA_OMP_TASKWAIT:
7029 if (context != pragma_compound)
7031 if (context == pragma_stmt)
7032 c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
7033 "used in compound statements");
7036 c_parser_omp_taskwait (parser);
7039 case PRAGMA_OMP_THREADPRIVATE:
7040 c_parser_omp_threadprivate (parser);
7043 case PRAGMA_OMP_SECTION:
7044 error_at (c_parser_peek_token (parser)->location,
7045 "%<#pragma omp section%> may only be used in "
7046 "%<#pragma omp sections%> construct");
7047 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7050 case PRAGMA_GCC_PCH_PREPROCESS:
7051 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first");
7052 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7056 if (id < PRAGMA_FIRST_EXTERNAL)
7058 if (context == pragma_external)
7061 c_parser_error (parser, "expected declaration specifiers");
7062 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
7065 c_parser_omp_construct (parser);
7071 c_parser_consume_pragma (parser);
7072 c_invoke_pragma_handler (id);
7074 /* Skip to EOL, but suppress any error message. Those will have been
7075 generated by the handler routine through calling error, as opposed
7076 to calling c_parser_error. */
7077 parser->error = true;
7078 c_parser_skip_to_pragma_eol (parser);
7083 /* The interface the pragma parsers have to the lexer. */
7086 pragma_lex (tree *value)
7088 c_token *tok = c_parser_peek_token (the_parser);
7089 enum cpp_ttype ret = tok->type;
7091 *value = tok->value;
7092 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
7096 if (ret == CPP_KEYWORD)
7098 c_parser_consume_token (the_parser);
7105 c_parser_pragma_pch_preprocess (c_parser *parser)
7109 c_parser_consume_pragma (parser);
7110 if (c_parser_next_token_is (parser, CPP_STRING))
7112 name = c_parser_peek_token (parser)->value;
7113 c_parser_consume_token (parser);
7116 c_parser_error (parser, "expected string literal");
7117 c_parser_skip_to_pragma_eol (parser);
7120 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
7123 /* OpenMP 2.5 parsing routines. */
7125 /* Returns name of the next clause.
7126 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7127 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7128 returned and the token is consumed. */
7130 static pragma_omp_clause
7131 c_parser_omp_clause_name (c_parser *parser)
7133 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
7135 if (c_parser_next_token_is_keyword (parser, RID_IF))
7136 result = PRAGMA_OMP_CLAUSE_IF;
7137 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT))
7138 result = PRAGMA_OMP_CLAUSE_DEFAULT;
7139 else if (c_parser_next_token_is (parser, CPP_NAME))
7141 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7146 if (!strcmp ("collapse", p))
7147 result = PRAGMA_OMP_CLAUSE_COLLAPSE;
7148 else if (!strcmp ("copyin", p))
7149 result = PRAGMA_OMP_CLAUSE_COPYIN;
7150 else if (!strcmp ("copyprivate", p))
7151 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
7154 if (!strcmp ("firstprivate", p))
7155 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
7158 if (!strcmp ("lastprivate", p))
7159 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
7162 if (!strcmp ("nowait", p))
7163 result = PRAGMA_OMP_CLAUSE_NOWAIT;
7164 else if (!strcmp ("num_threads", p))
7165 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
7168 if (!strcmp ("ordered", p))
7169 result = PRAGMA_OMP_CLAUSE_ORDERED;
7172 if (!strcmp ("private", p))
7173 result = PRAGMA_OMP_CLAUSE_PRIVATE;
7176 if (!strcmp ("reduction", p))
7177 result = PRAGMA_OMP_CLAUSE_REDUCTION;
7180 if (!strcmp ("schedule", p))
7181 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
7182 else if (!strcmp ("shared", p))
7183 result = PRAGMA_OMP_CLAUSE_SHARED;
7186 if (!strcmp ("untied", p))
7187 result = PRAGMA_OMP_CLAUSE_UNTIED;
7192 if (result != PRAGMA_OMP_CLAUSE_NONE)
7193 c_parser_consume_token (parser);
7198 /* Validate that a clause of the given type does not already exist. */
7201 check_no_duplicate_clause (tree clauses, enum omp_clause_code code,
7206 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7207 if (OMP_CLAUSE_CODE (c) == code)
7209 location_t loc = OMP_CLAUSE_LOCATION (c);
7210 error_at (loc, "too many %qs clauses", name);
7218 variable-list , identifier
7220 If KIND is nonzero, create the appropriate node and install the
7221 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7222 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7224 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7225 return the list created. */
7228 c_parser_omp_variable_list (c_parser *parser,
7229 location_t clause_loc,
7230 enum omp_clause_code kind,
7233 if (c_parser_next_token_is_not (parser, CPP_NAME)
7234 || c_parser_peek_token (parser)->id_kind != C_ID_ID)
7235 c_parser_error (parser, "expected identifier");
7237 while (c_parser_next_token_is (parser, CPP_NAME)
7238 && c_parser_peek_token (parser)->id_kind == C_ID_ID)
7240 tree t = lookup_name (c_parser_peek_token (parser)->value);
7243 undeclared_variable (c_parser_peek_token (parser)->location,
7244 c_parser_peek_token (parser)->value);
7245 else if (t == error_mark_node)
7249 tree u = build_omp_clause (clause_loc, kind);
7250 OMP_CLAUSE_DECL (u) = t;
7251 OMP_CLAUSE_CHAIN (u) = list;
7255 list = tree_cons (t, NULL_TREE, list);
7257 c_parser_consume_token (parser);
7259 if (c_parser_next_token_is_not (parser, CPP_COMMA))
7262 c_parser_consume_token (parser);
7268 /* Similarly, but expect leading and trailing parenthesis. This is a very
7269 common case for omp clauses. */
7272 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind,
7275 /* The clauses location. */
7276 location_t loc = c_parser_peek_token (parser)->location;
7278 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7280 list = c_parser_omp_variable_list (parser, loc, kind, list);
7281 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7287 collapse ( constant-expression ) */
7290 c_parser_omp_clause_collapse (c_parser *parser, tree list)
7292 tree c, num = error_mark_node;
7296 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
7298 loc = c_parser_peek_token (parser)->location;
7299 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7301 num = c_parser_expr_no_commas (parser, NULL).value;
7302 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7304 if (num == error_mark_node)
7306 if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
7307 || !host_integerp (num, 0)
7308 || (n = tree_low_cst (num, 0)) <= 0
7312 "collapse argument needs positive constant integer expression");
7315 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE);
7316 OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
7317 OMP_CLAUSE_CHAIN (c) = list;
7322 copyin ( variable-list ) */
7325 c_parser_omp_clause_copyin (c_parser *parser, tree list)
7327 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list);
7331 copyprivate ( variable-list ) */
7334 c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
7336 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list);
7340 default ( shared | none ) */
7343 c_parser_omp_clause_default (c_parser *parser, tree list)
7345 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
7346 location_t loc = c_parser_peek_token (parser)->location;
7349 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7351 if (c_parser_next_token_is (parser, CPP_NAME))
7353 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
7358 if (strcmp ("none", p) != 0)
7360 kind = OMP_CLAUSE_DEFAULT_NONE;
7364 if (strcmp ("shared", p) != 0)
7366 kind = OMP_CLAUSE_DEFAULT_SHARED;
7373 c_parser_consume_token (parser);
7378 c_parser_error (parser, "expected %<none%> or %<shared%>");
7380 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7382 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
7385 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
7386 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT);
7387 OMP_CLAUSE_CHAIN (c) = list;
7388 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
7394 firstprivate ( variable-list ) */
7397 c_parser_omp_clause_firstprivate (c_parser *parser, tree list)
7399 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list);
7403 if ( expression ) */
7406 c_parser_omp_clause_if (c_parser *parser, tree list)
7408 location_t loc = c_parser_peek_token (parser)->location;
7409 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7411 tree t = c_parser_paren_condition (parser);
7414 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
7416 c = build_omp_clause (loc, OMP_CLAUSE_IF);
7417 OMP_CLAUSE_IF_EXPR (c) = t;
7418 OMP_CLAUSE_CHAIN (c) = list;
7422 c_parser_error (parser, "expected %<(%>");
7428 lastprivate ( variable-list ) */
7431 c_parser_omp_clause_lastprivate (c_parser *parser, tree list)
7433 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list);
7440 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7443 location_t loc = c_parser_peek_token (parser)->location;
7445 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
7447 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT);
7448 OMP_CLAUSE_CHAIN (c) = list;
7453 num_threads ( expression ) */
7456 c_parser_omp_clause_num_threads (c_parser *parser, tree list)
7458 location_t num_threads_loc = c_parser_peek_token (parser)->location;
7459 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7461 location_t expr_loc = c_parser_peek_token (parser)->location;
7462 tree c, t = c_parser_expression (parser).value;
7463 t = c_fully_fold (t, false, NULL);
7465 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7467 if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
7469 c_parser_error (parser, "expected integer expression");
7473 /* Attempt to statically determine when the number isn't positive. */
7474 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t,
7475 build_int_cst (TREE_TYPE (t), 0));
7476 if (CAN_HAVE_LOCATION_P (c))
7477 SET_EXPR_LOCATION (c, expr_loc);
7478 if (c == boolean_true_node)
7480 warning_at (expr_loc, 0,
7481 "%<num_threads%> value must be positive");
7482 t = integer_one_node;
7485 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
7487 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS);
7488 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
7489 OMP_CLAUSE_CHAIN (c) = list;
7500 c_parser_omp_clause_ordered (c_parser *parser, tree list)
7504 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
7506 c = build_omp_clause (c_parser_peek_token (parser)->location,
7507 OMP_CLAUSE_ORDERED);
7508 OMP_CLAUSE_CHAIN (c) = list;
7514 private ( variable-list ) */
7517 c_parser_omp_clause_private (c_parser *parser, tree list)
7519 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list);
7523 reduction ( reduction-operator : variable-list )
7526 One of: + * - & ^ | && || */
7529 c_parser_omp_clause_reduction (c_parser *parser, tree list)
7531 location_t clause_loc = c_parser_peek_token (parser)->location;
7532 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7534 enum tree_code code;
7536 switch (c_parser_peek_token (parser)->type)
7548 code = BIT_AND_EXPR;
7551 code = BIT_XOR_EXPR;
7554 code = BIT_IOR_EXPR;
7557 code = TRUTH_ANDIF_EXPR;
7560 code = TRUTH_ORIF_EXPR;
7563 c_parser_error (parser,
7564 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7565 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7566 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7569 c_parser_consume_token (parser);
7570 if (c_parser_require (parser, CPP_COLON, "expected %<:%>"))
7574 nl = c_parser_omp_variable_list (parser, clause_loc,
7575 OMP_CLAUSE_REDUCTION, list);
7576 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
7577 OMP_CLAUSE_REDUCTION_CODE (c) = code;
7581 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7587 schedule ( schedule-kind )
7588 schedule ( schedule-kind , expression )
7591 static | dynamic | guided | runtime | auto
7595 c_parser_omp_clause_schedule (c_parser *parser, tree list)
7598 location_t loc = c_parser_peek_token (parser)->location;
7600 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
7603 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
7605 if (c_parser_next_token_is (parser, CPP_NAME))
7607 tree kind = c_parser_peek_token (parser)->value;
7608 const char *p = IDENTIFIER_POINTER (kind);
7613 if (strcmp ("dynamic", p) != 0)
7615 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
7619 if (strcmp ("guided", p) != 0)
7621 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
7625 if (strcmp ("runtime", p) != 0)
7627 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
7634 else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
7635 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
7636 else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
7637 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
7641 c_parser_consume_token (parser);
7642 if (c_parser_next_token_is (parser, CPP_COMMA))
7645 c_parser_consume_token (parser);
7647 here = c_parser_peek_token (parser)->location;
7648 t = c_parser_expr_no_commas (parser, NULL).value;
7649 t = c_fully_fold (t, false, NULL);
7651 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
7652 error_at (here, "schedule %<runtime%> does not take "
7653 "a %<chunk_size%> parameter");
7654 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
7656 "schedule %<auto%> does not take "
7657 "a %<chunk_size%> parameter");
7658 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
7659 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7661 c_parser_error (parser, "expected integer expression");
7663 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7666 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
7667 "expected %<,%> or %<)%>");
7669 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
7670 OMP_CLAUSE_CHAIN (c) = list;
7674 c_parser_error (parser, "invalid schedule kind");
7675 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
7680 shared ( variable-list ) */
7683 c_parser_omp_clause_shared (c_parser *parser, tree list)
7685 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
7692 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
7696 /* FIXME: Should we allow duplicates? */
7697 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
7699 c = build_omp_clause (c_parser_peek_token (parser)->location,
7701 OMP_CLAUSE_CHAIN (c) = list;
7706 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7707 is a bitmask in MASK. Return the list of clauses found; the result
7708 of clause default goes in *pdefault. */
7711 c_parser_omp_all_clauses (c_parser *parser, unsigned int mask,
7714 tree clauses = NULL;
7717 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7720 pragma_omp_clause c_kind;
7722 tree prev = clauses;
7724 if (!first && c_parser_next_token_is (parser, CPP_COMMA))
7725 c_parser_consume_token (parser);
7728 here = c_parser_peek_token (parser)->location;
7729 c_kind = c_parser_omp_clause_name (parser);
7733 case PRAGMA_OMP_CLAUSE_COLLAPSE:
7734 clauses = c_parser_omp_clause_collapse (parser, clauses);
7735 c_name = "collapse";
7737 case PRAGMA_OMP_CLAUSE_COPYIN:
7738 clauses = c_parser_omp_clause_copyin (parser, clauses);
7741 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
7742 clauses = c_parser_omp_clause_copyprivate (parser, clauses);
7743 c_name = "copyprivate";
7745 case PRAGMA_OMP_CLAUSE_DEFAULT:
7746 clauses = c_parser_omp_clause_default (parser, clauses);
7749 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
7750 clauses = c_parser_omp_clause_firstprivate (parser, clauses);
7751 c_name = "firstprivate";
7753 case PRAGMA_OMP_CLAUSE_IF:
7754 clauses = c_parser_omp_clause_if (parser, clauses);
7757 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
7758 clauses = c_parser_omp_clause_lastprivate (parser, clauses);
7759 c_name = "lastprivate";
7761 case PRAGMA_OMP_CLAUSE_NOWAIT:
7762 clauses = c_parser_omp_clause_nowait (parser, clauses);
7765 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
7766 clauses = c_parser_omp_clause_num_threads (parser, clauses);
7767 c_name = "num_threads";
7769 case PRAGMA_OMP_CLAUSE_ORDERED:
7770 clauses = c_parser_omp_clause_ordered (parser, clauses);
7773 case PRAGMA_OMP_CLAUSE_PRIVATE:
7774 clauses = c_parser_omp_clause_private (parser, clauses);
7777 case PRAGMA_OMP_CLAUSE_REDUCTION:
7778 clauses = c_parser_omp_clause_reduction (parser, clauses);
7779 c_name = "reduction";
7781 case PRAGMA_OMP_CLAUSE_SCHEDULE:
7782 clauses = c_parser_omp_clause_schedule (parser, clauses);
7783 c_name = "schedule";
7785 case PRAGMA_OMP_CLAUSE_SHARED:
7786 clauses = c_parser_omp_clause_shared (parser, clauses);
7789 case PRAGMA_OMP_CLAUSE_UNTIED:
7790 clauses = c_parser_omp_clause_untied (parser, clauses);
7794 c_parser_error (parser, "expected %<#pragma omp%> clause");
7798 if (((mask >> c_kind) & 1) == 0 && !parser->error)
7800 /* Remove the invalid clause(s) from the list to avoid
7801 confusing the rest of the compiler. */
7803 error_at (here, "%qs is not valid for %qs", c_name, where);
7808 c_parser_skip_to_pragma_eol (parser);
7810 return c_finish_omp_clauses (clauses);
7817 In practice, we're also interested in adding the statement to an
7818 outer node. So it is convenient if we work around the fact that
7819 c_parser_statement calls add_stmt. */
7822 c_parser_omp_structured_block (c_parser *parser)
7824 tree stmt = push_stmt_list ();
7825 c_parser_statement (parser);
7826 return pop_stmt_list (stmt);
7830 # pragma omp atomic new-line
7834 x binop= expr | x++ | ++x | x-- | --x
7836 +, *, -, /, &, ^, |, <<, >>
7838 where x is an lvalue expression with scalar type.
7840 LOC is the location of the #pragma token. */
7843 c_parser_omp_atomic (location_t loc, c_parser *parser)
7847 enum tree_code code;
7848 struct c_expr rhs_expr;
7850 c_parser_skip_to_pragma_eol (parser);
7852 lhs = c_parser_unary_expression (parser).value;
7853 lhs = c_fully_fold (lhs, false, NULL);
7854 switch (TREE_CODE (lhs))
7858 c_parser_skip_to_end_of_block_or_statement (parser);
7861 case PREINCREMENT_EXPR:
7862 case POSTINCREMENT_EXPR:
7863 lhs = TREE_OPERAND (lhs, 0);
7865 rhs = integer_one_node;
7868 case PREDECREMENT_EXPR:
7869 case POSTDECREMENT_EXPR:
7870 lhs = TREE_OPERAND (lhs, 0);
7872 rhs = integer_one_node;
7876 switch (c_parser_peek_token (parser)->type)
7882 code = TRUNC_DIV_EXPR;
7897 code = BIT_AND_EXPR;
7900 code = BIT_IOR_EXPR;
7903 code = BIT_XOR_EXPR;
7906 c_parser_error (parser,
7907 "invalid operator for %<#pragma omp atomic%>");
7911 c_parser_consume_token (parser);
7913 location_t rhs_loc = c_parser_peek_token (parser)->location;
7914 rhs_expr = c_parser_expression (parser);
7915 rhs_expr = default_function_array_read_conversion (rhs_loc, rhs_expr);
7917 rhs = rhs_expr.value;
7918 rhs = c_fully_fold (rhs, false, NULL);
7921 stmt = c_finish_omp_atomic (loc, code, lhs, rhs);
7922 if (stmt != error_mark_node)
7924 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
7929 # pragma omp barrier new-line
7933 c_parser_omp_barrier (c_parser *parser)
7935 location_t loc = c_parser_peek_token (parser)->location;
7936 c_parser_consume_pragma (parser);
7937 c_parser_skip_to_pragma_eol (parser);
7939 c_finish_omp_barrier (loc);
7943 # pragma omp critical [(name)] new-line
7946 LOC is the location of the #pragma itself. */
7949 c_parser_omp_critical (location_t loc, c_parser *parser)
7951 tree stmt, name = NULL;
7953 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7955 c_parser_consume_token (parser);
7956 if (c_parser_next_token_is (parser, CPP_NAME))
7958 name = c_parser_peek_token (parser)->value;
7959 c_parser_consume_token (parser);
7960 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
7963 c_parser_error (parser, "expected identifier");
7965 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7966 c_parser_error (parser, "expected %<(%> or end of line");
7967 c_parser_skip_to_pragma_eol (parser);
7969 stmt = c_parser_omp_structured_block (parser);
7970 return c_finish_omp_critical (loc, stmt, name);
7974 # pragma omp flush flush-vars[opt] new-line
7977 ( variable-list ) */
7980 c_parser_omp_flush (c_parser *parser)
7982 location_t loc = c_parser_peek_token (parser)->location;
7983 c_parser_consume_pragma (parser);
7984 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
7985 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
7986 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
7987 c_parser_error (parser, "expected %<(%> or end of line");
7988 c_parser_skip_to_pragma_eol (parser);
7990 c_finish_omp_flush (loc);
7993 /* Parse the restricted form of the for statement allowed by OpenMP.
7994 The real trick here is to determine the loop control variable early
7995 so that we can push a new decl if necessary to make it private.
7996 LOC is the location of the OMP in "#pragma omp". */
7999 c_parser_omp_for_loop (location_t loc,
8000 c_parser *parser, tree clauses, tree *par_clauses)
8002 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
8003 tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
8004 bool fail = false, open_brace_parsed = false;
8005 int i, collapse = 1, nbraces = 0;
8008 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
8009 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
8010 collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
8012 gcc_assert (collapse >= 1);
8014 declv = make_tree_vec (collapse);
8015 initv = make_tree_vec (collapse);
8016 condv = make_tree_vec (collapse);
8017 incrv = make_tree_vec (collapse);
8019 if (!c_parser_next_token_is_keyword (parser, RID_FOR))
8021 c_parser_error (parser, "for statement expected");
8024 for_loc = c_parser_peek_token (parser)->location;
8025 c_parser_consume_token (parser);
8027 for (i = 0; i < collapse; i++)
8031 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
8034 /* Parse the initialization declaration or expression. */
8035 if (c_parser_next_token_starts_declspecs (parser))
8039 = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
8040 c_parser_declaration_or_fndef (parser, true, true, true, true);
8041 decl = check_for_loop_decls (for_loc);
8044 if (DECL_INITIAL (decl) == error_mark_node)
8045 decl = error_mark_node;
8048 else if (c_parser_next_token_is (parser, CPP_NAME)
8049 && c_parser_peek_2nd_token (parser)->type == CPP_EQ)
8051 struct c_expr decl_exp;
8052 struct c_expr init_exp;
8053 location_t init_loc;
8055 decl_exp = c_parser_postfix_expression (parser);
8056 decl = decl_exp.value;
8058 c_parser_require (parser, CPP_EQ, "expected %<=%>");
8060 init_loc = c_parser_peek_token (parser)->location;
8061 init_exp = c_parser_expr_no_commas (parser, NULL);
8062 init_exp = default_function_array_read_conversion (init_loc,
8064 init = build_modify_expr (init_loc, decl, decl_exp.original_type,
8065 NOP_EXPR, init_loc, init_exp.value,
8066 init_exp.original_type);
8067 init = c_process_expr_stmt (init_loc, init);
8069 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8074 c_parser_error (parser,
8075 "expected iteration declaration or initialization");
8076 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
8082 /* Parse the loop condition. */
8084 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
8086 location_t cond_loc = c_parser_peek_token (parser)->location;
8087 struct c_expr cond_expr = c_parser_binary_expression (parser, NULL);
8089 cond = cond_expr.value;
8090 cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
8091 cond = c_fully_fold (cond, false, NULL);
8092 switch (cond_expr.original_code)
8100 /* Can't be cond = error_mark_node, because we want to preserve
8101 the location until c_finish_omp_for. */
8102 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node);
8105 protected_set_expr_location (cond, cond_loc);
8107 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
8109 /* Parse the increment expression. */
8111 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN))
8113 location_t incr_loc = c_parser_peek_token (parser)->location;
8115 incr = c_process_expr_stmt (incr_loc,
8116 c_parser_expression (parser).value);
8118 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
8120 if (decl == NULL || decl == error_mark_node || init == error_mark_node)
8124 TREE_VEC_ELT (declv, i) = decl;
8125 TREE_VEC_ELT (initv, i) = init;
8126 TREE_VEC_ELT (condv, i) = cond;
8127 TREE_VEC_ELT (incrv, i) = incr;
8131 if (i == collapse - 1)
8134 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8135 in between the collapsed for loops to be still considered perfectly
8136 nested. Hopefully the final version clarifies this.
8137 For now handle (multiple) {'s and empty statements. */
8140 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8142 c_parser_consume_token (parser);
8145 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
8147 c_parser_consume_token (parser);
8151 && c_parser_next_token_is (parser, CPP_SEMICOLON))
8152 c_parser_consume_token (parser);
8155 c_parser_error (parser, "not enough perfectly nested loops");
8158 open_brace_parsed = true;
8168 nbraces += bracecount;
8171 save_break = c_break_label;
8172 c_break_label = size_one_node;
8173 save_cont = c_cont_label;
8174 c_cont_label = NULL_TREE;
8175 body = push_stmt_list ();
8177 if (open_brace_parsed)
8179 location_t here = c_parser_peek_token (parser)->location;
8180 stmt = c_begin_compound_stmt (true);
8181 c_parser_compound_statement_nostart (parser);
8182 add_stmt (c_end_compound_stmt (here, stmt, true));
8185 add_stmt (c_parser_c99_block_statement (parser));
8188 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label);
8189 SET_EXPR_LOCATION (t, loc);
8193 body = pop_stmt_list (body);
8194 c_break_label = save_break;
8195 c_cont_label = save_cont;
8199 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8201 c_parser_consume_token (parser);
8204 else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
8205 c_parser_consume_token (parser);
8208 c_parser_error (parser, "collapsed loops not perfectly nested");
8211 location_t here = c_parser_peek_token (parser)->location;
8212 stmt = c_begin_compound_stmt (true);
8214 c_parser_compound_statement_nostart (parser);
8215 body = c_end_compound_stmt (here, stmt, true);
8222 /* Only bother calling c_finish_omp_for if we haven't already generated
8223 an error from the initialization parsing. */
8226 stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL);
8229 if (par_clauses != NULL)
8232 for (c = par_clauses; *c ; )
8233 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE
8234 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE)
8235 c = &OMP_CLAUSE_CHAIN (*c);
8238 for (i = 0; i < collapse; i++)
8239 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c))
8242 c = &OMP_CLAUSE_CHAIN (*c);
8243 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE)
8246 "iteration variable %qD should not be firstprivate",
8247 OMP_CLAUSE_DECL (*c));
8248 *c = OMP_CLAUSE_CHAIN (*c);
8252 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8253 change it to shared (decl) in
8254 OMP_PARALLEL_CLAUSES. */
8255 tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c),
8256 OMP_CLAUSE_LASTPRIVATE);
8257 OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c);
8258 OMP_CLAUSE_CHAIN (l) = clauses;
8260 OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
8264 OMP_FOR_CLAUSES (stmt) = clauses;
8271 /* FIXME diagnostics: LOC below should be the actual location of
8272 this particular for block. We need to build a list of
8273 locations to go along with FOR_BLOCK. */
8274 stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
8276 for_block = TREE_CHAIN (for_block);
8282 #pragma omp for for-clause[optseq] new-line
8285 LOC is the location of the #pragma token.
8288 #define OMP_FOR_CLAUSE_MASK \
8289 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8290 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8291 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8292 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8293 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8294 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8295 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8296 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8299 c_parser_omp_for (location_t loc, c_parser *parser)
8301 tree block, clauses, ret;
8303 clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
8306 block = c_begin_compound_stmt (true);
8307 ret = c_parser_omp_for_loop (loc, parser, clauses, NULL);
8308 block = c_end_compound_stmt (loc, block, true);
8315 # pragma omp master new-line
8318 LOC is the location of the #pragma token.
8322 c_parser_omp_master (location_t loc, c_parser *parser)
8324 c_parser_skip_to_pragma_eol (parser);
8325 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser));
8329 # pragma omp ordered new-line
8332 LOC is the location of the #pragma itself.
8336 c_parser_omp_ordered (location_t loc, c_parser *parser)
8338 c_parser_skip_to_pragma_eol (parser);
8339 return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser));
8345 { section-sequence }
8348 section-directive[opt] structured-block
8349 section-sequence section-directive structured-block
8351 SECTIONS_LOC is the location of the #pragma omp sections. */
8354 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser)
8357 bool error_suppress = false;
8360 loc = c_parser_peek_token (parser)->location;
8361 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>"))
8363 /* Avoid skipping until the end of the block. */
8364 parser->error = false;
8368 stmt = push_stmt_list ();
8370 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION)
8372 substmt = push_stmt_list ();
8376 c_parser_statement (parser);
8378 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8380 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8382 if (c_parser_next_token_is (parser, CPP_EOF))
8386 substmt = pop_stmt_list (substmt);
8387 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8388 SET_EXPR_LOCATION (substmt, loc);
8394 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
8396 if (c_parser_next_token_is (parser, CPP_EOF))
8399 loc = c_parser_peek_token (parser)->location;
8400 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION)
8402 c_parser_consume_pragma (parser);
8403 c_parser_skip_to_pragma_eol (parser);
8404 error_suppress = false;
8406 else if (!error_suppress)
8408 error_at (loc, "expected %<#pragma omp section%> or %<}%>");
8409 error_suppress = true;
8412 substmt = c_parser_omp_structured_block (parser);
8413 substmt = build1 (OMP_SECTION, void_type_node, substmt);
8414 SET_EXPR_LOCATION (substmt, loc);
8417 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE,
8418 "expected %<#pragma omp section%> or %<}%>");
8420 substmt = pop_stmt_list (stmt);
8422 stmt = make_node (OMP_SECTIONS);
8423 SET_EXPR_LOCATION (stmt, sections_loc);
8424 TREE_TYPE (stmt) = void_type_node;
8425 OMP_SECTIONS_BODY (stmt) = substmt;
8427 return add_stmt (stmt);
8431 # pragma omp sections sections-clause[optseq] newline
8434 LOC is the location of the #pragma token.
8437 #define OMP_SECTIONS_CLAUSE_MASK \
8438 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8439 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8440 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8441 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8442 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8445 c_parser_omp_sections (location_t loc, c_parser *parser)
8447 tree block, clauses, ret;
8449 clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
8450 "#pragma omp sections");
8452 block = c_begin_compound_stmt (true);
8453 ret = c_parser_omp_sections_scope (loc, parser);
8455 OMP_SECTIONS_CLAUSES (ret) = clauses;
8456 block = c_end_compound_stmt (loc, block, true);
8463 # pragma parallel parallel-clause new-line
8464 # pragma parallel for parallel-for-clause new-line
8465 # pragma parallel sections parallel-sections-clause new-line
8467 LOC is the location of the #pragma token.
8470 #define OMP_PARALLEL_CLAUSE_MASK \
8471 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8472 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8473 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8474 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8475 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8476 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8477 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8478 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8481 c_parser_omp_parallel (location_t loc, c_parser *parser)
8483 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
8484 const char *p_name = "#pragma omp parallel";
8485 tree stmt, clauses, par_clause, ws_clause, block;
8486 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
8488 if (c_parser_next_token_is_keyword (parser, RID_FOR))
8490 c_parser_consume_token (parser);
8491 p_kind = PRAGMA_OMP_PARALLEL_FOR;
8492 p_name = "#pragma omp parallel for";
8493 mask |= OMP_FOR_CLAUSE_MASK;
8494 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8496 else if (c_parser_next_token_is (parser, CPP_NAME))
8498 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
8499 if (strcmp (p, "sections") == 0)
8501 c_parser_consume_token (parser);
8502 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
8503 p_name = "#pragma omp parallel sections";
8504 mask |= OMP_SECTIONS_CLAUSE_MASK;
8505 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
8509 clauses = c_parser_omp_all_clauses (parser, mask, p_name);
8513 case PRAGMA_OMP_PARALLEL:
8514 block = c_begin_omp_parallel ();
8515 c_parser_statement (parser);
8516 stmt = c_finish_omp_parallel (loc, clauses, block);
8519 case PRAGMA_OMP_PARALLEL_FOR:
8520 block = c_begin_omp_parallel ();
8521 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8522 c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause);
8523 stmt = c_finish_omp_parallel (loc, par_clause, block);
8524 OMP_PARALLEL_COMBINED (stmt) = 1;
8527 case PRAGMA_OMP_PARALLEL_SECTIONS:
8528 block = c_begin_omp_parallel ();
8529 c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause);
8530 stmt = c_parser_omp_sections_scope (loc, parser);
8532 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
8533 stmt = c_finish_omp_parallel (loc, par_clause, block);
8534 OMP_PARALLEL_COMBINED (stmt) = 1;
8545 # pragma omp single single-clause[optseq] new-line
8548 LOC is the location of the #pragma.
8551 #define OMP_SINGLE_CLAUSE_MASK \
8552 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8553 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8554 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8555 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8558 c_parser_omp_single (location_t loc, c_parser *parser)
8560 tree stmt = make_node (OMP_SINGLE);
8561 SET_EXPR_LOCATION (stmt, loc);
8562 TREE_TYPE (stmt) = void_type_node;
8564 OMP_SINGLE_CLAUSES (stmt)
8565 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
8566 "#pragma omp single");
8567 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser);
8569 return add_stmt (stmt);
8573 # pragma omp task task-clause[optseq] new-line
8575 LOC is the location of the #pragma.
8578 #define OMP_TASK_CLAUSE_MASK \
8579 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8580 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8581 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8582 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8583 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8584 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8587 c_parser_omp_task (location_t loc, c_parser *parser)
8589 tree clauses, block;
8591 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
8592 "#pragma omp task");
8594 block = c_begin_omp_task ();
8595 c_parser_statement (parser);
8596 return c_finish_omp_task (loc, clauses, block);
8600 # pragma omp taskwait new-line
8604 c_parser_omp_taskwait (c_parser *parser)
8606 location_t loc = c_parser_peek_token (parser)->location;
8607 c_parser_consume_pragma (parser);
8608 c_parser_skip_to_pragma_eol (parser);
8610 c_finish_omp_taskwait (loc);
8613 /* Main entry point to parsing most OpenMP pragmas. */
8616 c_parser_omp_construct (c_parser *parser)
8618 enum pragma_kind p_kind;
8622 loc = c_parser_peek_token (parser)->location;
8623 p_kind = c_parser_peek_token (parser)->pragma_kind;
8624 c_parser_consume_pragma (parser);
8628 case PRAGMA_OMP_ATOMIC:
8629 c_parser_omp_atomic (loc, parser);
8631 case PRAGMA_OMP_CRITICAL:
8632 stmt = c_parser_omp_critical (loc, parser);
8634 case PRAGMA_OMP_FOR:
8635 stmt = c_parser_omp_for (loc, parser);
8637 case PRAGMA_OMP_MASTER:
8638 stmt = c_parser_omp_master (loc, parser);
8640 case PRAGMA_OMP_ORDERED:
8641 stmt = c_parser_omp_ordered (loc, parser);
8643 case PRAGMA_OMP_PARALLEL:
8644 stmt = c_parser_omp_parallel (loc, parser);
8646 case PRAGMA_OMP_SECTIONS:
8647 stmt = c_parser_omp_sections (loc, parser);
8649 case PRAGMA_OMP_SINGLE:
8650 stmt = c_parser_omp_single (loc, parser);
8652 case PRAGMA_OMP_TASK:
8653 stmt = c_parser_omp_task (loc, parser);
8660 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION);
8665 # pragma omp threadprivate (variable-list) */
8668 c_parser_omp_threadprivate (c_parser *parser)
8673 c_parser_consume_pragma (parser);
8674 loc = c_parser_peek_token (parser)->location;
8675 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL);
8677 /* Mark every variable in VARS to be assigned thread local storage. */
8678 for (t = vars; t; t = TREE_CHAIN (t))
8680 tree v = TREE_PURPOSE (t);
8682 /* FIXME diagnostics: Ideally we should keep individual
8683 locations for all the variables in the var list to make the
8684 following errors more precise. Perhaps
8685 c_parser_omp_var_list_parens() should construct a list of
8686 locations to go along with the var list. */
8688 /* If V had already been marked threadprivate, it doesn't matter
8689 whether it had been used prior to this point. */
8690 if (TREE_CODE (v) != VAR_DECL)
8691 error_at (loc, "%qD is not a variable", v);
8692 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
8693 error_at (loc, "%qE declared %<threadprivate%> after first use", v);
8694 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
8695 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
8696 else if (TREE_TYPE (v) == error_mark_node)
8698 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
8699 error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
8702 if (! DECL_THREAD_LOCAL_P (v))
8704 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
8705 /* If rtl has been already set for this var, call
8706 make_decl_rtl once again, so that encode_section_info
8707 has a chance to look at the new decl flags. */
8708 if (DECL_RTL_SET_P (v))
8711 C_DECL_THREADPRIVATE_P (v) = 1;
8715 c_parser_skip_to_pragma_eol (parser);
8719 /* Parse a single source file. */
8724 /* Use local storage to begin. If the first token is a pragma, parse it.
8725 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8726 which will cause garbage collection. */
8729 memset (&tparser, 0, sizeof tparser);
8730 the_parser = &tparser;
8732 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
8733 c_parser_pragma_pch_preprocess (&tparser);
8735 the_parser = GGC_NEW (c_parser);
8736 *the_parser = tparser;
8738 /* Initialize EH, if we've been told to do so. */
8739 if (flag_exceptions)
8740 using_eh_for_cleanups ();
8742 c_parser_translation_unit (the_parser);
8746 #include "gt-c-parser.h"