1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
64 /* Initialization routine for this file. */
69 /* The only initialization required is of the reserved word
80 mask
|= D_ASM
| D_EXT
;
84 if (!c_dialect_objc ())
85 mask
|= D_OBJC
| D_CXX_OBJC
;
87 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
88 for (i
= 0; i
< num_c_common_reswords
; i
++)
90 /* If a keyword is disabled, do not enter it into the table
91 and so create a canonical spelling that isn't a keyword. */
92 if (c_common_reswords
[i
].disable
& mask
)
95 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
97 id
= get_identifier (c_common_reswords
[i
].word
);
98 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
99 C_IS_RESERVED_WORD (id
) = 1;
104 id
= get_identifier (c_common_reswords
[i
].word
);
105 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
106 C_IS_RESERVED_WORD (id
) = 1;
107 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
111 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
112 and the C parser. Unlike the C++ lexer, the parser structure
113 stores the lexer information instead of using a separate structure.
114 Identifiers are separated into ordinary identifiers, type names,
115 keywords and some other Objective-C types of identifiers, and some
116 look-ahead is maintained.
118 ??? It might be a good idea to lex the whole file up front (as for
119 C++). It would then be possible to share more of the C and C++
120 lexer code, if desired. */
122 /* The following local token type is used. */
125 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
127 /* More information about the type of a CPP_NAME token. */
128 typedef enum c_id_kind
{
129 /* An ordinary identifier. */
131 /* An identifier declared as a typedef name. */
133 /* An identifier declared as an Objective-C class name. */
135 /* Not an identifier. */
139 /* A single C token after string literal concatenation and conversion
140 of preprocessing tokens to tokens. */
141 typedef struct GTY (()) c_token
{
142 /* The kind of token. */
143 ENUM_BITFIELD (cpp_ttype
) type
: 8;
144 /* If this token is a CPP_NAME, this value indicates whether also
145 declared as some kind of type. Otherwise, it is C_ID_NONE. */
146 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
147 /* If this token is a keyword, this value indicates which keyword.
148 Otherwise, this value is RID_MAX. */
149 ENUM_BITFIELD (rid
) keyword
: 8;
150 /* If this token is a CPP_PRAGMA, this indicates the pragma that
151 was seen. Otherwise it is PRAGMA_NONE. */
152 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
153 /* The value associated with this token, if any. */
155 /* The location at which this token was found. */
159 /* A parser structure recording information about the state and
160 context of parsing. Includes lexer information with up to two
161 tokens of look-ahead; more are not needed for C. */
162 typedef struct GTY(()) c_parser
{
163 /* The look-ahead tokens. */
165 /* How many look-ahead tokens are available (0, 1 or 2). */
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error
: 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma
: 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block
: 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string
: 1;
178 /* Objective-C specific parser/lexer information. */
179 BOOL_BITFIELD objc_pq_context
: 1;
180 /* The following flag is needed to contextualize Objective-C lexical
181 analysis. In some cases (e.g., 'int NSObject;'), it is
182 undesirable to bind an identifier to an Objective-C class, even
183 if a class with that name exists. */
184 BOOL_BITFIELD objc_need_raw_identifier
: 1;
188 /* The actual parser and external interface. ??? Does this need to be
189 garbage-collected? */
191 static GTY (()) c_parser
*the_parser
;
194 /* Read in and lex a single token, storing it in *TOKEN. */
197 c_lex_one_token (c_parser
*parser
, c_token
*token
)
199 timevar_push (TV_LEX
);
201 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
202 (parser
->lex_untranslated_string
203 ? C_LEX_STRING_NO_TRANSLATE
: 0));
204 token
->id_kind
= C_ID_NONE
;
205 token
->keyword
= RID_MAX
;
206 token
->pragma_kind
= PRAGMA_NONE
;
214 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
215 if (c_dialect_objc ())
216 parser
->objc_need_raw_identifier
= false;
218 if (C_IS_RESERVED_WORD (token
->value
))
220 enum rid rid_code
= C_RID_CODE (token
->value
);
222 if (rid_code
== RID_CXX_COMPAT_WARN
)
224 warning_at (token
->location
,
226 "identifier %qE conflicts with C++ keyword",
229 else if (c_dialect_objc ())
231 if (!objc_is_reserved_word (token
->value
)
232 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
233 || parser
->objc_pq_context
))
235 /* Return the canonical spelling for this keyword. */
236 token
->value
= ridpointers
[(int) rid_code
];
237 token
->type
= CPP_KEYWORD
;
238 token
->keyword
= rid_code
;
244 token
->type
= CPP_KEYWORD
;
245 token
->keyword
= rid_code
;
250 decl
= lookup_name (token
->value
);
253 if (TREE_CODE (decl
) == TYPE_DECL
)
255 token
->id_kind
= C_ID_TYPENAME
;
259 else if (c_dialect_objc ())
261 tree objc_interface_decl
= objc_is_class_name (token
->value
);
262 /* Objective-C class names are in the same namespace as
263 variables and typedefs, and hence are shadowed by local
265 if (objc_interface_decl
266 && (global_bindings_p ()
267 || (!objc_force_identifier
&& !decl
)))
269 token
->value
= objc_interface_decl
;
270 token
->id_kind
= C_ID_CLASSNAME
;
274 token
->id_kind
= C_ID_ID
;
278 /* This only happens in Objective-C; it must be a keyword. */
279 token
->type
= CPP_KEYWORD
;
280 token
->keyword
= C_RID_CODE (token
->value
);
284 case CPP_CLOSE_PAREN
:
286 /* These tokens may affect the interpretation of any identifiers
287 following, if doing Objective-C. */
288 if (c_dialect_objc ())
289 parser
->objc_need_raw_identifier
= false;
292 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
293 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
299 timevar_pop (TV_LEX
);
302 /* Return a pointer to the next token from PARSER, reading it in if
305 static inline c_token
*
306 c_parser_peek_token (c_parser
*parser
)
308 if (parser
->tokens_avail
== 0)
310 c_lex_one_token (parser
, &parser
->tokens
[0]);
311 parser
->tokens_avail
= 1;
313 return &parser
->tokens
[0];
316 /* Return true if the next token from PARSER has the indicated
320 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
322 return c_parser_peek_token (parser
)->type
== type
;
325 /* Return true if the next token from PARSER does not have the
329 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
331 return !c_parser_next_token_is (parser
, type
);
334 /* Return true if the next token from PARSER is the indicated
338 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
340 return c_parser_peek_token (parser
)->keyword
== keyword
;
343 /* Return true if TOKEN can start a type name,
346 c_token_starts_typename (c_token
*token
)
351 switch (token
->id_kind
)
358 gcc_assert (c_dialect_objc ());
364 switch (token
->keyword
)
396 if (c_dialect_objc ())
404 /* Return true if the next token from PARSER can start a type name,
407 c_parser_next_token_starts_typename (c_parser
*parser
)
409 c_token
*token
= c_parser_peek_token (parser
);
410 return c_token_starts_typename (token
);
413 /* Return true if TOKEN can start declaration specifiers, false
416 c_token_starts_declspecs (c_token
*token
)
421 switch (token
->id_kind
)
428 gcc_assert (c_dialect_objc ());
434 switch (token
->keyword
)
473 if (c_dialect_objc ())
481 /* Return true if the next token from PARSER can start declaration
482 specifiers, false otherwise. */
484 c_parser_next_token_starts_declspecs (c_parser
*parser
)
486 c_token
*token
= c_parser_peek_token (parser
);
487 return c_token_starts_declspecs (token
);
490 /* Return a pointer to the next-but-one token from PARSER, reading it
491 in if necessary. The next token is already read in. */
494 c_parser_peek_2nd_token (c_parser
*parser
)
496 if (parser
->tokens_avail
>= 2)
497 return &parser
->tokens
[1];
498 gcc_assert (parser
->tokens_avail
== 1);
499 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
500 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
501 c_lex_one_token (parser
, &parser
->tokens
[1]);
502 parser
->tokens_avail
= 2;
503 return &parser
->tokens
[1];
506 /* Consume the next token from PARSER. */
509 c_parser_consume_token (c_parser
*parser
)
511 gcc_assert (parser
->tokens_avail
>= 1);
512 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
513 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
514 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
515 if (parser
->tokens_avail
== 2)
516 parser
->tokens
[0] = parser
->tokens
[1];
517 parser
->tokens_avail
--;
520 /* Expect the current token to be a #pragma. Consume it and remember
521 that we've begun parsing a pragma. */
524 c_parser_consume_pragma (c_parser
*parser
)
526 gcc_assert (!parser
->in_pragma
);
527 gcc_assert (parser
->tokens_avail
>= 1);
528 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
529 if (parser
->tokens_avail
== 2)
530 parser
->tokens
[0] = parser
->tokens
[1];
531 parser
->tokens_avail
--;
532 parser
->in_pragma
= true;
535 /* Update the globals input_location and in_system_header from
538 c_parser_set_source_position_from_token (c_token
*token
)
540 if (token
->type
!= CPP_EOF
)
542 input_location
= token
->location
;
546 /* Issue a diagnostic of the form
547 FILE:LINE: MESSAGE before TOKEN
548 where TOKEN is the next token in the input stream of PARSER.
549 MESSAGE (specified by the caller) is usually of the form "expected
552 Do not issue a diagnostic if still recovering from an error.
554 ??? This is taken from the C++ parser, but building up messages in
555 this way is not i18n-friendly and some other approach should be
559 c_parser_error (c_parser
*parser
, const char *gmsgid
)
561 c_token
*token
= c_parser_peek_token (parser
);
564 parser
->error
= true;
567 /* This diagnostic makes more sense if it is tagged to the line of
568 the token we just peeked at. */
569 c_parser_set_source_position_from_token (token
);
570 c_parse_error (gmsgid
,
571 /* Because c_parse_error does not understand
572 CPP_KEYWORD, keywords are treated like
574 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
575 /* ??? The C parser does not save the cpp flags of a
576 token, we need to pass 0 here and we will not get
577 the source spelling of some tokens but rather the
578 canonical spelling. */
579 token
->value
, /*flags=*/0);
582 /* If the next token is of the indicated TYPE, consume it. Otherwise,
583 issue the error MSGID. If MSGID is NULL then a message has already
584 been produced and no message will be produced this time. Returns
585 true if found, false otherwise. */
588 c_parser_require (c_parser
*parser
,
592 if (c_parser_next_token_is (parser
, type
))
594 c_parser_consume_token (parser
);
599 c_parser_error (parser
, msgid
);
604 /* If the next token is the indicated keyword, consume it. Otherwise,
605 issue the error MSGID. Returns true if found, false otherwise. */
608 c_parser_require_keyword (c_parser
*parser
,
612 if (c_parser_next_token_is_keyword (parser
, keyword
))
614 c_parser_consume_token (parser
);
619 c_parser_error (parser
, msgid
);
624 /* Like c_parser_require, except that tokens will be skipped until the
625 desired token is found. An error message is still produced if the
626 next token is not as expected. If MSGID is NULL then a message has
627 already been produced and no message will be produced this
631 c_parser_skip_until_found (c_parser
*parser
,
635 unsigned nesting_depth
= 0;
637 if (c_parser_require (parser
, type
, msgid
))
640 /* Skip tokens until the desired token is found. */
643 /* Peek at the next token. */
644 c_token
*token
= c_parser_peek_token (parser
);
645 /* If we've reached the token we want, consume it and stop. */
646 if (token
->type
== type
&& !nesting_depth
)
648 c_parser_consume_token (parser
);
652 /* If we've run out of tokens, stop. */
653 if (token
->type
== CPP_EOF
)
655 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
657 if (token
->type
== CPP_OPEN_BRACE
658 || token
->type
== CPP_OPEN_PAREN
659 || token
->type
== CPP_OPEN_SQUARE
)
661 else if (token
->type
== CPP_CLOSE_BRACE
662 || token
->type
== CPP_CLOSE_PAREN
663 || token
->type
== CPP_CLOSE_SQUARE
)
665 if (nesting_depth
-- == 0)
668 /* Consume this token. */
669 c_parser_consume_token (parser
);
671 parser
->error
= false;
674 /* Skip tokens until the end of a parameter is found, but do not
675 consume the comma, semicolon or closing delimiter. */
678 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
680 unsigned nesting_depth
= 0;
684 c_token
*token
= c_parser_peek_token (parser
);
685 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
688 /* If we've run out of tokens, stop. */
689 if (token
->type
== CPP_EOF
)
691 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
693 if (token
->type
== CPP_OPEN_BRACE
694 || token
->type
== CPP_OPEN_PAREN
695 || token
->type
== CPP_OPEN_SQUARE
)
697 else if (token
->type
== CPP_CLOSE_BRACE
698 || token
->type
== CPP_CLOSE_PAREN
699 || token
->type
== CPP_CLOSE_SQUARE
)
701 if (nesting_depth
-- == 0)
704 /* Consume this token. */
705 c_parser_consume_token (parser
);
707 parser
->error
= false;
710 /* Expect to be at the end of the pragma directive and consume an
711 end of line marker. */
714 c_parser_skip_to_pragma_eol (c_parser
*parser
)
716 gcc_assert (parser
->in_pragma
);
717 parser
->in_pragma
= false;
719 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
722 c_token
*token
= c_parser_peek_token (parser
);
723 if (token
->type
== CPP_EOF
)
725 if (token
->type
== CPP_PRAGMA_EOL
)
727 c_parser_consume_token (parser
);
730 c_parser_consume_token (parser
);
733 parser
->error
= false;
736 /* Skip tokens until we have consumed an entire block, or until we
737 have consumed a non-nested ';'. */
740 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
742 unsigned nesting_depth
= 0;
743 bool save_error
= parser
->error
;
749 /* Peek at the next token. */
750 token
= c_parser_peek_token (parser
);
758 if (parser
->in_pragma
)
763 /* If the next token is a ';', we have reached the
764 end of the statement. */
767 /* Consume the ';'. */
768 c_parser_consume_token (parser
);
773 case CPP_CLOSE_BRACE
:
774 /* If the next token is a non-nested '}', then we have
775 reached the end of the current block. */
776 if (nesting_depth
== 0 || --nesting_depth
== 0)
778 c_parser_consume_token (parser
);
784 /* If it the next token is a '{', then we are entering a new
785 block. Consume the entire block. */
790 /* If we see a pragma, consume the whole thing at once. We
791 have some safeguards against consuming pragmas willy-nilly.
792 Normally, we'd expect to be here with parser->error set,
793 which disables these safeguards. But it's possible to get
794 here for secondary error recovery, after parser->error has
796 c_parser_consume_pragma (parser
);
797 c_parser_skip_to_pragma_eol (parser
);
798 parser
->error
= save_error
;
805 c_parser_consume_token (parser
);
809 parser
->error
= false;
812 /* CPP's options (initialized by c-opts.c). */
813 extern cpp_options
*cpp_opts
;
815 /* Save the warning flags which are controlled by __extension__. */
818 disable_extension_diagnostics (void)
821 | (warn_pointer_arith
<< 1)
822 | (warn_traditional
<< 2)
824 | (warn_long_long
<< 4)
825 | (warn_cxx_compat
<< 5));
826 cpp_opts
->pedantic
= pedantic
= 0;
827 warn_pointer_arith
= 0;
828 cpp_opts
->warn_traditional
= warn_traditional
= 0;
830 cpp_opts
->warn_long_long
= warn_long_long
= 0;
835 /* Restore the warning flags which are controlled by __extension__.
836 FLAGS is the return value from disable_extension_diagnostics. */
839 restore_extension_diagnostics (int flags
)
841 cpp_opts
->pedantic
= pedantic
= flags
& 1;
842 warn_pointer_arith
= (flags
>> 1) & 1;
843 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
844 flag_iso
= (flags
>> 3) & 1;
845 cpp_opts
->warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
846 warn_cxx_compat
= (flags
>> 5) & 1;
849 /* Possibly kinds of declarator to parse. */
850 typedef enum c_dtr_syn
{
851 /* A normal declarator with an identifier. */
853 /* An abstract declarator (maybe empty). */
855 /* A parameter declarator: may be either, but after a type name does
856 not redeclare a typedef name as an identifier if it can
857 alternatively be interpreted as a typedef name; see DR#009,
858 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
859 following DR#249. For example, given a typedef T, "int T" and
860 "int *T" are valid parameter declarations redeclaring T, while
861 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
862 abstract declarators rather than involving redundant parentheses;
863 the same applies with attributes inside the parentheses before
868 static void c_parser_external_declaration (c_parser
*);
869 static void c_parser_asm_definition (c_parser
*);
870 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
871 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
873 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
874 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
875 static tree
c_parser_struct_declaration (c_parser
*);
876 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
877 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
879 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
881 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
883 struct c_declarator
*);
884 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
885 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
886 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
887 static tree
c_parser_simple_asm_expr (c_parser
*);
888 static tree
c_parser_attributes (c_parser
*);
889 static struct c_type_name
*c_parser_type_name (c_parser
*);
890 static struct c_expr
c_parser_initializer (c_parser
*);
891 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
892 static void c_parser_initelt (c_parser
*);
893 static void c_parser_initval (c_parser
*, struct c_expr
*);
894 static tree
c_parser_compound_statement (c_parser
*);
895 static void c_parser_compound_statement_nostart (c_parser
*);
896 static void c_parser_label (c_parser
*);
897 static void c_parser_statement (c_parser
*);
898 static void c_parser_statement_after_labels (c_parser
*);
899 static void c_parser_if_statement (c_parser
*);
900 static void c_parser_switch_statement (c_parser
*);
901 static void c_parser_while_statement (c_parser
*);
902 static void c_parser_do_statement (c_parser
*);
903 static void c_parser_for_statement (c_parser
*);
904 static tree
c_parser_asm_statement (c_parser
*);
905 static tree
c_parser_asm_operands (c_parser
*, bool);
906 static tree
c_parser_asm_goto_operands (c_parser
*);
907 static tree
c_parser_asm_clobbers (c_parser
*);
908 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
909 static struct c_expr
c_parser_conditional_expression (c_parser
*,
911 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
912 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
913 static struct c_expr
c_parser_unary_expression (c_parser
*);
914 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
915 static struct c_expr
c_parser_alignof_expression (c_parser
*);
916 static struct c_expr
c_parser_postfix_expression (c_parser
*);
917 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
918 struct c_type_name
*,
920 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
923 static struct c_expr
c_parser_expression (c_parser
*);
924 static struct c_expr
c_parser_expression_conv (c_parser
*);
925 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
927 static void c_parser_omp_construct (c_parser
*);
928 static void c_parser_omp_threadprivate (c_parser
*);
929 static void c_parser_omp_barrier (c_parser
*);
930 static void c_parser_omp_flush (c_parser
*);
931 static void c_parser_omp_taskwait (c_parser
*);
933 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
934 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
936 /* These Objective-C parser functions are only ever called when
937 compiling Objective-C. */
938 static void c_parser_objc_class_definition (c_parser
*);
939 static void c_parser_objc_class_instance_variables (c_parser
*);
940 static void c_parser_objc_class_declaration (c_parser
*);
941 static void c_parser_objc_alias_declaration (c_parser
*);
942 static void c_parser_objc_protocol_definition (c_parser
*);
943 static enum tree_code
c_parser_objc_method_type (c_parser
*);
944 static void c_parser_objc_method_definition (c_parser
*);
945 static void c_parser_objc_methodprotolist (c_parser
*);
946 static void c_parser_objc_methodproto (c_parser
*);
947 static tree
c_parser_objc_method_decl (c_parser
*);
948 static tree
c_parser_objc_type_name (c_parser
*);
949 static tree
c_parser_objc_protocol_refs (c_parser
*);
950 static void c_parser_objc_try_catch_statement (c_parser
*);
951 static void c_parser_objc_synchronized_statement (c_parser
*);
952 static tree
c_parser_objc_selector (c_parser
*);
953 static tree
c_parser_objc_selector_arg (c_parser
*);
954 static tree
c_parser_objc_receiver (c_parser
*);
955 static tree
c_parser_objc_message_args (c_parser
*);
956 static tree
c_parser_objc_keywordexpr (c_parser
*);
958 /* Parse a translation unit (C90 6.7, C99 6.9).
961 external-declarations
963 external-declarations:
965 external-declarations external-declaration
974 c_parser_translation_unit (c_parser
*parser
)
976 if (c_parser_next_token_is (parser
, CPP_EOF
))
978 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
979 "ISO C forbids an empty translation unit");
983 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
984 mark_valid_location_for_stdc_pragma (false);
988 c_parser_external_declaration (parser
);
989 obstack_free (&parser_obstack
, obstack_position
);
991 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
995 /* Parse an external declaration (C90 6.7, C99 6.9).
997 external-declaration:
1003 external-declaration:
1006 __extension__ external-declaration
1010 external-declaration:
1011 objc-class-definition
1012 objc-class-declaration
1013 objc-alias-declaration
1014 objc-protocol-definition
1015 objc-method-definition
1020 c_parser_external_declaration (c_parser
*parser
)
1023 switch (c_parser_peek_token (parser
)->type
)
1026 switch (c_parser_peek_token (parser
)->keyword
)
1029 ext
= disable_extension_diagnostics ();
1030 c_parser_consume_token (parser
);
1031 c_parser_external_declaration (parser
);
1032 restore_extension_diagnostics (ext
);
1035 c_parser_asm_definition (parser
);
1037 case RID_AT_INTERFACE
:
1038 case RID_AT_IMPLEMENTATION
:
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_objc_class_definition (parser
);
1043 gcc_assert (c_dialect_objc ());
1044 c_parser_objc_class_declaration (parser
);
1047 gcc_assert (c_dialect_objc ());
1048 c_parser_objc_alias_declaration (parser
);
1050 case RID_AT_PROTOCOL
:
1051 gcc_assert (c_dialect_objc ());
1052 c_parser_objc_protocol_definition (parser
);
1055 gcc_assert (c_dialect_objc ());
1056 c_parser_consume_token (parser
);
1057 objc_finish_implementation ();
1064 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1065 "ISO C does not allow extra %<;%> outside of a function");
1066 c_parser_consume_token (parser
);
1069 mark_valid_location_for_stdc_pragma (true);
1070 c_parser_pragma (parser
, pragma_external
);
1071 mark_valid_location_for_stdc_pragma (false);
1075 if (c_dialect_objc ())
1077 c_parser_objc_method_definition (parser
);
1080 /* Else fall through, and yield a syntax error trying to parse
1081 as a declaration or function definition. */
1084 /* A declaration or a function definition. We can only tell
1085 which after parsing the declaration specifiers, if any, and
1086 the first declarator. */
1087 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1093 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1094 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1095 accepted; otherwise (old-style parameter declarations) only other
1096 declarations are accepted. If NESTED is true, we are inside a
1097 function or parsing old-style parameter declarations; any functions
1098 encountered are nested functions and declaration specifiers are
1099 required; otherwise we are at top level and functions are normal
1100 functions and declaration specifiers may be optional. If EMPTY_OK
1101 is true, empty declarations are OK (subject to all other
1102 constraints); otherwise (old-style parameter declarations) they are
1103 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1104 may start with attributes; otherwise they may not.
1107 declaration-specifiers init-declarator-list[opt] ;
1109 function-definition:
1110 declaration-specifiers[opt] declarator declaration-list[opt]
1115 declaration-list declaration
1117 init-declarator-list:
1119 init-declarator-list , init-declarator
1122 declarator simple-asm-expr[opt] attributes[opt]
1123 declarator simple-asm-expr[opt] attributes[opt] = initializer
1127 nested-function-definition:
1128 declaration-specifiers declarator declaration-list[opt]
1131 The simple-asm-expr and attributes are GNU extensions.
1133 This function does not handle __extension__; that is handled in its
1134 callers. ??? Following the old parser, __extension__ may start
1135 external declarations, declarations in functions and declarations
1136 at the start of "for" loops, but not old-style parameter
1139 C99 requires declaration specifiers in a function definition; the
1140 absence is diagnosed through the diagnosis of implicit int. In GNU
1141 C we also allow but diagnose declarations without declaration
1142 specifiers, but only at top level (elsewhere they conflict with
1148 threadprivate-directive */
1151 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1152 bool nested
, bool start_attr_ok
)
1154 struct c_declspecs
*specs
;
1156 tree all_prefix_attrs
;
1157 bool diagnosed_no_specs
= false;
1158 location_t here
= c_parser_peek_token (parser
)->location
;
1160 specs
= build_null_declspecs ();
1161 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1164 c_parser_skip_to_end_of_block_or_statement (parser
);
1167 if (nested
&& !specs
->declspecs_seen_p
)
1169 c_parser_error (parser
, "expected declaration specifiers");
1170 c_parser_skip_to_end_of_block_or_statement (parser
);
1173 finish_declspecs (specs
);
1174 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1180 shadow_tag_warned (specs
, 1);
1181 pedwarn (here
, 0, "empty declaration");
1183 c_parser_consume_token (parser
);
1186 pending_xref_error ();
1187 prefix_attrs
= specs
->attrs
;
1188 all_prefix_attrs
= prefix_attrs
;
1189 specs
->attrs
= NULL_TREE
;
1192 struct c_declarator
*declarator
;
1195 /* Declaring either one or more declarators (in which case we
1196 should diagnose if there were no declaration specifiers) or a
1197 function definition (in which case the diagnostic for
1198 implicit int suffices). */
1199 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1200 C_DTR_NORMAL
, &dummy
);
1201 if (declarator
== NULL
)
1203 c_parser_skip_to_end_of_block_or_statement (parser
);
1206 if (c_parser_next_token_is (parser
, CPP_EQ
)
1207 || c_parser_next_token_is (parser
, CPP_COMMA
)
1208 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1209 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1210 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1212 tree asm_name
= NULL_TREE
;
1213 tree postfix_attrs
= NULL_TREE
;
1214 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1216 diagnosed_no_specs
= true;
1217 pedwarn (here
, 0, "data definition has no type or storage class");
1219 /* Having seen a data definition, there cannot now be a
1220 function definition. */
1222 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1223 asm_name
= c_parser_simple_asm_expr (parser
);
1224 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1225 postfix_attrs
= c_parser_attributes (parser
);
1226 if (c_parser_next_token_is (parser
, CPP_EQ
))
1230 location_t init_loc
;
1231 c_parser_consume_token (parser
);
1232 /* The declaration of the variable is in effect while
1233 its initializer is parsed. */
1234 d
= start_decl (declarator
, specs
, true,
1235 chainon (postfix_attrs
, all_prefix_attrs
));
1237 d
= error_mark_node
;
1238 start_init (d
, asm_name
, global_bindings_p ());
1239 init_loc
= c_parser_peek_token (parser
)->location
;
1240 init
= c_parser_initializer (parser
);
1242 if (d
!= error_mark_node
)
1244 maybe_warn_string_init (TREE_TYPE (d
), init
);
1245 finish_decl (d
, init_loc
, init
.value
,
1246 init
.original_type
, asm_name
);
1251 tree d
= start_decl (declarator
, specs
, false,
1252 chainon (postfix_attrs
,
1255 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1256 NULL_TREE
, asm_name
);
1258 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1260 c_parser_consume_token (parser
);
1261 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1262 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1265 all_prefix_attrs
= prefix_attrs
;
1268 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1270 c_parser_consume_token (parser
);
1275 c_parser_error (parser
, "expected %<,%> or %<;%>");
1276 c_parser_skip_to_end_of_block_or_statement (parser
);
1282 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1283 "%<asm%> or %<__attribute__%>");
1284 c_parser_skip_to_end_of_block_or_statement (parser
);
1287 /* Function definition (nested or otherwise). */
1290 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1291 c_push_function_context ();
1293 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1295 /* This can appear in many cases looking nothing like a
1296 function definition, so we don't give a more specific
1297 error suggesting there was one. */
1298 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1299 "or %<__attribute__%>");
1301 c_pop_function_context ();
1304 /* Parse old-style parameter declarations. ??? Attributes are
1305 not allowed to start declaration specifiers here because of a
1306 syntax conflict between a function declaration with attribute
1307 suffix and a function definition with an attribute prefix on
1308 first old-style parameter declaration. Following the old
1309 parser, they are not accepted on subsequent old-style
1310 parameter declarations either. However, there is no
1311 ambiguity after the first declaration, nor indeed on the
1312 first as long as we don't allow postfix attributes after a
1313 declarator with a nonempty identifier list in a definition;
1314 and postfix attributes have never been accepted here in
1315 function definitions either. */
1316 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1317 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1318 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1319 store_parm_decls ();
1320 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1321 = c_parser_peek_token (parser
)->location
;
1322 fnbody
= c_parser_compound_statement (parser
);
1325 tree decl
= current_function_decl
;
1326 /* Mark nested functions as needing static-chain initially.
1327 lower_nested_functions will recompute it but the
1328 DECL_STATIC_CHAIN flag is also used before that happens,
1329 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1330 DECL_STATIC_CHAIN (decl
) = 1;
1333 c_pop_function_context ();
1334 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1345 /* Parse an asm-definition (asm() outside a function body). This is a
1353 c_parser_asm_definition (c_parser
*parser
)
1355 tree asm_str
= c_parser_simple_asm_expr (parser
);
1357 cgraph_add_asm_node (asm_str
);
1358 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1361 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1362 6.7), adding them to SPECS (which may already include some).
1363 Storage class specifiers are accepted iff SCSPEC_OK; type
1364 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1365 the start iff START_ATTR_OK.
1367 declaration-specifiers:
1368 storage-class-specifier declaration-specifiers[opt]
1369 type-specifier declaration-specifiers[opt]
1370 type-qualifier declaration-specifiers[opt]
1371 function-specifier declaration-specifiers[opt]
1373 Function specifiers (inline) are from C99, and are currently
1374 handled as storage class specifiers, as is __thread.
1376 C90 6.5.1, C99 6.7.1:
1377 storage-class-specifier:
1388 C90 6.5.2, C99 6.7.2:
1401 [_Imaginary removed in C99 TC2]
1402 struct-or-union-specifier
1406 (_Bool and _Complex are new in C99.)
1408 C90 6.5.3, C99 6.7.3:
1415 (restrict is new in C99.)
1419 declaration-specifiers:
1420 attributes declaration-specifiers[opt]
1422 storage-class-specifier:
1434 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1435 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1440 class-name objc-protocol-refs[opt]
1441 typedef-name objc-protocol-refs
1446 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1447 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1449 bool attrs_ok
= start_attr_ok
;
1450 bool seen_type
= specs
->type_seen_p
;
1451 while (c_parser_next_token_is (parser
, CPP_NAME
)
1452 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1453 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1455 struct c_typespec t
;
1457 location_t loc
= c_parser_peek_token (parser
)->location
;
1458 if (c_parser_next_token_is (parser
, CPP_NAME
))
1460 tree value
= c_parser_peek_token (parser
)->value
;
1461 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1462 /* This finishes the specifiers unless a type name is OK, it
1463 is declared as a type name and a type name hasn't yet
1465 if (!typespec_ok
|| seen_type
1466 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1468 c_parser_consume_token (parser
);
1471 if (kind
== C_ID_TYPENAME
1472 && (!c_dialect_objc ()
1473 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1475 t
.kind
= ctsk_typedef
;
1476 /* For a typedef name, record the meaning, not the name.
1477 In case of 'foo foo, bar;'. */
1478 t
.spec
= lookup_name (value
);
1480 t
.expr_const_operands
= true;
1484 tree proto
= NULL_TREE
;
1485 gcc_assert (c_dialect_objc ());
1487 if (c_parser_next_token_is (parser
, CPP_LESS
))
1488 proto
= c_parser_objc_protocol_refs (parser
);
1489 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1491 t
.expr_const_operands
= true;
1493 declspecs_add_type (loc
, specs
, t
);
1496 if (c_parser_next_token_is (parser
, CPP_LESS
))
1498 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1499 nisse@lysator.liu.se. */
1501 gcc_assert (c_dialect_objc ());
1502 if (!typespec_ok
|| seen_type
)
1504 proto
= c_parser_objc_protocol_refs (parser
);
1506 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1508 t
.expr_const_operands
= true;
1509 declspecs_add_type (loc
, specs
, t
);
1512 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1513 switch (c_parser_peek_token (parser
)->keyword
)
1525 /* TODO: Distinguish between function specifiers (inline)
1526 and storage class specifiers, either here or in
1527 declspecs_add_scspec. */
1528 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1529 c_parser_consume_token (parser
);
1552 if (c_dialect_objc ())
1553 parser
->objc_need_raw_identifier
= true;
1554 t
.kind
= ctsk_resword
;
1555 t
.spec
= c_parser_peek_token (parser
)->value
;
1557 t
.expr_const_operands
= true;
1558 declspecs_add_type (loc
, specs
, t
);
1559 c_parser_consume_token (parser
);
1566 t
= c_parser_enum_specifier (parser
);
1567 declspecs_add_type (loc
, specs
, t
);
1575 t
= c_parser_struct_or_union_specifier (parser
);
1576 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1577 declspecs_add_type (loc
, specs
, t
);
1580 /* ??? The old parser rejected typeof after other type
1581 specifiers, but is a syntax error the best way of
1583 if (!typespec_ok
|| seen_type
)
1587 t
= c_parser_typeof_specifier (parser
);
1588 declspecs_add_type (loc
, specs
, t
);
1594 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1595 c_parser_consume_token (parser
);
1600 attrs
= c_parser_attributes (parser
);
1601 declspecs_add_attrs (specs
, attrs
);
1610 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1613 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1614 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1615 enum attributes[opt] identifier
1617 The form with trailing comma is new in C99. The forms with
1618 attributes are GNU extensions. In GNU C, we accept any expression
1619 without commas in the syntax (assignment expressions, not just
1620 conditional expressions); assignment expressions will be diagnosed
1625 enumerator-list , enumerator
1628 enumeration-constant
1629 enumeration-constant = constant-expression
1632 static struct c_typespec
1633 c_parser_enum_specifier (c_parser
*parser
)
1635 struct c_typespec ret
;
1637 tree ident
= NULL_TREE
;
1638 location_t enum_loc
;
1639 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1640 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1641 enum_loc
= c_parser_peek_token (parser
)->location
;
1642 c_parser_consume_token (parser
);
1643 attrs
= c_parser_attributes (parser
);
1644 enum_loc
= c_parser_peek_token (parser
)->location
;
1645 /* Set the location in case we create a decl now. */
1646 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1647 if (c_parser_next_token_is (parser
, CPP_NAME
))
1649 ident
= c_parser_peek_token (parser
)->value
;
1650 ident_loc
= c_parser_peek_token (parser
)->location
;
1651 enum_loc
= ident_loc
;
1652 c_parser_consume_token (parser
);
1654 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1656 /* Parse an enum definition. */
1657 struct c_enum_contents the_enum
;
1658 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
1660 /* We chain the enumerators in reverse order, then put them in
1661 forward order at the end. */
1662 tree values
= NULL_TREE
;
1663 c_parser_consume_token (parser
);
1671 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1672 location_t value_loc
;
1673 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1675 c_parser_error (parser
, "expected identifier");
1676 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1677 values
= error_mark_node
;
1680 token
= c_parser_peek_token (parser
);
1681 enum_id
= token
->value
;
1682 /* Set the location in case we create a decl now. */
1683 c_parser_set_source_position_from_token (token
);
1684 value_loc
= token
->location
;
1685 c_parser_consume_token (parser
);
1686 if (c_parser_next_token_is (parser
, CPP_EQ
))
1688 c_parser_consume_token (parser
);
1689 value_loc
= c_parser_peek_token (parser
)->location
;
1690 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1693 enum_value
= NULL_TREE
;
1694 enum_decl
= build_enumerator (value_loc
,
1695 &the_enum
, enum_id
, enum_value
);
1696 TREE_CHAIN (enum_decl
) = values
;
1699 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1701 comma_loc
= c_parser_peek_token (parser
)->location
;
1703 c_parser_consume_token (parser
);
1705 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1707 if (seen_comma
&& !flag_isoc99
)
1708 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1709 c_parser_consume_token (parser
);
1714 c_parser_error (parser
, "expected %<,%> or %<}%>");
1715 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1716 values
= error_mark_node
;
1720 postfix_attrs
= c_parser_attributes (parser
);
1721 ret
.spec
= finish_enum (type
, nreverse (values
),
1722 chainon (attrs
, postfix_attrs
));
1723 ret
.kind
= ctsk_tagdef
;
1724 ret
.expr
= NULL_TREE
;
1725 ret
.expr_const_operands
= true;
1730 c_parser_error (parser
, "expected %<{%>");
1731 ret
.spec
= error_mark_node
;
1732 ret
.kind
= ctsk_tagref
;
1733 ret
.expr
= NULL_TREE
;
1734 ret
.expr_const_operands
= true;
1737 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
1738 /* In ISO C, enumerated types can be referred to only if already
1740 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1743 pedwarn (enum_loc
, OPT_pedantic
,
1744 "ISO C forbids forward references to %<enum%> types");
1749 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1751 struct-or-union-specifier:
1752 struct-or-union attributes[opt] identifier[opt]
1753 { struct-contents } attributes[opt]
1754 struct-or-union attributes[opt] identifier
1757 struct-declaration-list
1759 struct-declaration-list:
1760 struct-declaration ;
1761 struct-declaration-list struct-declaration ;
1768 struct-declaration-list struct-declaration
1770 struct-declaration-list:
1771 struct-declaration-list ;
1774 (Note that in the syntax here, unlike that in ISO C, the semicolons
1775 are included here rather than in struct-declaration, in order to
1776 describe the syntax with extra semicolons and missing semicolon at
1781 struct-declaration-list:
1782 @defs ( class-name )
1784 (Note this does not include a trailing semicolon, but can be
1785 followed by further declarations, and gets a pedwarn-if-pedantic
1786 when followed by a semicolon.) */
1788 static struct c_typespec
1789 c_parser_struct_or_union_specifier (c_parser
*parser
)
1791 struct c_typespec ret
;
1793 tree ident
= NULL_TREE
;
1794 location_t struct_loc
;
1795 location_t ident_loc
= UNKNOWN_LOCATION
;
1796 enum tree_code code
;
1797 switch (c_parser_peek_token (parser
)->keyword
)
1808 struct_loc
= c_parser_peek_token (parser
)->location
;
1809 c_parser_consume_token (parser
);
1810 attrs
= c_parser_attributes (parser
);
1812 /* Set the location in case we create a decl now. */
1813 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1815 if (c_parser_next_token_is (parser
, CPP_NAME
))
1817 ident
= c_parser_peek_token (parser
)->value
;
1818 ident_loc
= c_parser_peek_token (parser
)->location
;
1819 struct_loc
= ident_loc
;
1820 c_parser_consume_token (parser
);
1822 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1824 /* Parse a struct or union definition. Start the scope of the
1825 tag before parsing components. */
1826 struct c_struct_parse_info
*struct_info
;
1827 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
1829 /* We chain the components in reverse order, then put them in
1830 forward order at the end. Each struct-declaration may
1831 declare multiple components (comma-separated), so we must use
1832 chainon to join them, although when parsing each
1833 struct-declaration we can use TREE_CHAIN directly.
1835 The theory behind all this is that there will be more
1836 semicolon separated fields than comma separated fields, and
1837 so we'll be minimizing the number of node traversals required
1839 tree contents
= NULL_TREE
;
1840 c_parser_consume_token (parser
);
1841 /* Handle the Objective-C @defs construct,
1842 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1843 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1846 gcc_assert (c_dialect_objc ());
1847 c_parser_consume_token (parser
);
1848 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1850 if (c_parser_next_token_is (parser
, CPP_NAME
)
1851 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1853 name
= c_parser_peek_token (parser
)->value
;
1854 c_parser_consume_token (parser
);
1858 c_parser_error (parser
, "expected class name");
1859 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1864 contents
= nreverse (objc_get_class_ivars (name
));
1867 /* Parse the struct-declarations and semicolons. Problems with
1868 semicolons are diagnosed here; empty structures are diagnosed
1873 /* Parse any stray semicolon. */
1874 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1876 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1877 "extra semicolon in struct or union specified");
1878 c_parser_consume_token (parser
);
1881 /* Stop if at the end of the struct or union contents. */
1882 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1884 c_parser_consume_token (parser
);
1887 /* Accept #pragmas at struct scope. */
1888 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1890 c_parser_pragma (parser
, pragma_external
);
1893 /* Parse some comma-separated declarations, but not the
1894 trailing semicolon if any. */
1895 decls
= c_parser_struct_declaration (parser
);
1896 contents
= chainon (decls
, contents
);
1897 /* If no semicolon follows, either we have a parse error or
1898 are at the end of the struct or union and should
1900 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1901 c_parser_consume_token (parser
);
1904 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1905 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1906 "no semicolon at end of struct or union");
1909 c_parser_error (parser
, "expected %<;%>");
1910 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1915 postfix_attrs
= c_parser_attributes (parser
);
1916 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
1917 chainon (attrs
, postfix_attrs
), struct_info
);
1918 ret
.kind
= ctsk_tagdef
;
1919 ret
.expr
= NULL_TREE
;
1920 ret
.expr_const_operands
= true;
1925 c_parser_error (parser
, "expected %<{%>");
1926 ret
.spec
= error_mark_node
;
1927 ret
.kind
= ctsk_tagref
;
1928 ret
.expr
= NULL_TREE
;
1929 ret
.expr_const_operands
= true;
1932 ret
= parser_xref_tag (ident_loc
, code
, ident
);
1936 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1937 the trailing semicolon.
1940 specifier-qualifier-list struct-declarator-list
1942 specifier-qualifier-list:
1943 type-specifier specifier-qualifier-list[opt]
1944 type-qualifier specifier-qualifier-list[opt]
1945 attributes specifier-qualifier-list[opt]
1947 struct-declarator-list:
1949 struct-declarator-list , attributes[opt] struct-declarator
1952 declarator attributes[opt]
1953 declarator[opt] : constant-expression attributes[opt]
1958 __extension__ struct-declaration
1959 specifier-qualifier-list
1961 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1962 of attributes where shown is a GNU extension. In GNU C, we accept
1963 any expression without commas in the syntax (assignment
1964 expressions, not just conditional expressions); assignment
1965 expressions will be diagnosed as non-constant. */
1968 c_parser_struct_declaration (c_parser
*parser
)
1970 struct c_declspecs
*specs
;
1972 tree all_prefix_attrs
;
1974 location_t decl_loc
;
1975 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1979 ext
= disable_extension_diagnostics ();
1980 c_parser_consume_token (parser
);
1981 decl
= c_parser_struct_declaration (parser
);
1982 restore_extension_diagnostics (ext
);
1985 specs
= build_null_declspecs ();
1986 decl_loc
= c_parser_peek_token (parser
)->location
;
1987 c_parser_declspecs (parser
, specs
, false, true, true);
1990 if (!specs
->declspecs_seen_p
)
1992 c_parser_error (parser
, "expected specifier-qualifier-list");
1995 finish_declspecs (specs
);
1996 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1999 if (!specs
->type_seen_p
)
2001 pedwarn (decl_loc
, OPT_pedantic
,
2002 "ISO C forbids member declarations with no members");
2003 shadow_tag_warned (specs
, pedantic
);
2008 /* Support for unnamed structs or unions as members of
2009 structs or unions (which is [a] useful and [b] supports
2013 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2014 build_id_declarator (NULL_TREE
), specs
,
2017 decl_attributes (&ret
, attrs
, 0);
2021 pending_xref_error ();
2022 prefix_attrs
= specs
->attrs
;
2023 all_prefix_attrs
= prefix_attrs
;
2024 specs
->attrs
= NULL_TREE
;
2028 /* Declaring one or more declarators or un-named bit-fields. */
2029 struct c_declarator
*declarator
;
2031 if (c_parser_next_token_is (parser
, CPP_COLON
))
2032 declarator
= build_id_declarator (NULL_TREE
);
2034 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2035 C_DTR_NORMAL
, &dummy
);
2036 if (declarator
== NULL
)
2038 c_parser_skip_to_end_of_block_or_statement (parser
);
2041 if (c_parser_next_token_is (parser
, CPP_COLON
)
2042 || c_parser_next_token_is (parser
, CPP_COMMA
)
2043 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2044 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2045 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2047 tree postfix_attrs
= NULL_TREE
;
2048 tree width
= NULL_TREE
;
2050 if (c_parser_next_token_is (parser
, CPP_COLON
))
2052 c_parser_consume_token (parser
);
2053 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2055 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2056 postfix_attrs
= c_parser_attributes (parser
);
2057 d
= grokfield (c_parser_peek_token (parser
)->location
,
2058 declarator
, specs
, width
, &all_prefix_attrs
);
2059 decl_attributes (&d
, chainon (postfix_attrs
,
2060 all_prefix_attrs
), 0);
2061 TREE_CHAIN (d
) = decls
;
2063 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2064 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2067 all_prefix_attrs
= prefix_attrs
;
2068 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2069 c_parser_consume_token (parser
);
2070 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2071 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2073 /* Semicolon consumed in caller. */
2078 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2084 c_parser_error (parser
,
2085 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2086 "%<__attribute__%>");
2093 /* Parse a typeof specifier (a GNU extension).
2096 typeof ( expression )
2097 typeof ( type-name )
2100 static struct c_typespec
2101 c_parser_typeof_specifier (c_parser
*parser
)
2103 struct c_typespec ret
;
2104 ret
.kind
= ctsk_typeof
;
2105 ret
.spec
= error_mark_node
;
2106 ret
.expr
= NULL_TREE
;
2107 ret
.expr_const_operands
= true;
2108 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2109 c_parser_consume_token (parser
);
2110 c_inhibit_evaluation_warnings
++;
2112 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2114 c_inhibit_evaluation_warnings
--;
2118 if (c_parser_next_token_starts_typename (parser
))
2120 struct c_type_name
*type
= c_parser_type_name (parser
);
2121 c_inhibit_evaluation_warnings
--;
2125 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2126 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2132 location_t here
= c_parser_peek_token (parser
)->location
;
2133 struct c_expr expr
= c_parser_expression (parser
);
2134 c_inhibit_evaluation_warnings
--;
2136 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2137 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2138 error_at (here
, "%<typeof%> applied to a bit-field");
2139 ret
.spec
= TREE_TYPE (expr
.value
);
2140 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2141 /* This is returned with the type so that when the type is
2142 evaluated, this can be evaluated. */
2144 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2145 pop_maybe_used (was_vm
);
2147 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2151 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2152 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2153 be redeclared; otherwise it may not. KIND indicates which kind of
2154 declarator is wanted. Returns a valid declarator except in the
2155 case of a syntax error in which case NULL is returned. *SEEN_ID is
2156 set to true if an identifier being declared is seen; this is used
2157 to diagnose bad forms of abstract array declarators and to
2158 determine whether an identifier list is syntactically permitted.
2161 pointer[opt] direct-declarator
2165 ( attributes[opt] declarator )
2166 direct-declarator array-declarator
2167 direct-declarator ( parameter-type-list )
2168 direct-declarator ( identifier-list[opt] )
2171 * type-qualifier-list[opt]
2172 * type-qualifier-list[opt] pointer
2174 type-qualifier-list:
2177 type-qualifier-list type-qualifier
2178 type-qualifier-list attributes
2180 parameter-type-list:
2182 parameter-list , ...
2185 parameter-declaration
2186 parameter-list , parameter-declaration
2188 parameter-declaration:
2189 declaration-specifiers declarator attributes[opt]
2190 declaration-specifiers abstract-declarator[opt] attributes[opt]
2194 identifier-list , identifier
2196 abstract-declarator:
2198 pointer[opt] direct-abstract-declarator
2200 direct-abstract-declarator:
2201 ( attributes[opt] abstract-declarator )
2202 direct-abstract-declarator[opt] array-declarator
2203 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2208 direct-declarator ( parameter-forward-declarations
2209 parameter-type-list[opt] )
2211 direct-abstract-declarator:
2212 direct-abstract-declarator[opt] ( parameter-forward-declarations
2213 parameter-type-list[opt] )
2215 parameter-forward-declarations:
2217 parameter-forward-declarations parameter-list ;
2219 The uses of attributes shown above are GNU extensions.
2221 Some forms of array declarator are not included in C99 in the
2222 syntax for abstract declarators; these are disallowed elsewhere.
2223 This may be a defect (DR#289).
2225 This function also accepts an omitted abstract declarator as being
2226 an abstract declarator, although not part of the formal syntax. */
2228 static struct c_declarator
*
2229 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2232 /* Parse any initial pointer part. */
2233 if (c_parser_next_token_is (parser
, CPP_MULT
))
2235 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2236 struct c_declarator
*inner
;
2237 c_parser_consume_token (parser
);
2238 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2239 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2243 return make_pointer_declarator (quals_attrs
, inner
);
2245 /* Now we have a direct declarator, direct abstract declarator or
2246 nothing (which counts as a direct abstract declarator here). */
2247 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2250 /* Parse a direct declarator or direct abstract declarator; arguments
2251 as c_parser_declarator. */
2253 static struct c_declarator
*
2254 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2257 /* The direct declarator must start with an identifier (possibly
2258 omitted) or a parenthesized declarator (possibly abstract). In
2259 an ordinary declarator, initial parentheses must start a
2260 parenthesized declarator. In an abstract declarator or parameter
2261 declarator, they could start a parenthesized declarator or a
2262 parameter list. To tell which, the open parenthesis and any
2263 following attributes must be read. If a declaration specifier
2264 follows, then it is a parameter list; if the specifier is a
2265 typedef name, there might be an ambiguity about redeclaring it,
2266 which is resolved in the direction of treating it as a typedef
2267 name. If a close parenthesis follows, it is also an empty
2268 parameter list, as the syntax does not permit empty abstract
2269 declarators. Otherwise, it is a parenthesized declarator (in
2270 which case the analysis may be repeated inside it, recursively).
2272 ??? There is an ambiguity in a parameter declaration "int
2273 (__attribute__((foo)) x)", where x is not a typedef name: it
2274 could be an abstract declarator for a function, or declare x with
2275 parentheses. The proper resolution of this ambiguity needs
2276 documenting. At present we follow an accident of the old
2277 parser's implementation, whereby the first parameter must have
2278 some declaration specifiers other than just attributes. Thus as
2279 a parameter declaration it is treated as a parenthesized
2280 parameter named x, and as an abstract declarator it is
2283 ??? Also following the old parser, attributes inside an empty
2284 parameter list are ignored, making it a list not yielding a
2285 prototype, rather than giving an error or making it have one
2286 parameter with implicit type int.
2288 ??? Also following the old parser, typedef names may be
2289 redeclared in declarators, but not Objective-C class names. */
2291 if (kind
!= C_DTR_ABSTRACT
2292 && c_parser_next_token_is (parser
, CPP_NAME
)
2294 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2295 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2297 struct c_declarator
*inner
2298 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2300 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2301 c_parser_consume_token (parser
);
2302 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2305 if (kind
!= C_DTR_NORMAL
2306 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2308 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2309 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2312 /* Either we are at the end of an abstract declarator, or we have
2315 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2318 struct c_declarator
*inner
;
2319 c_parser_consume_token (parser
);
2320 attrs
= c_parser_attributes (parser
);
2321 if (kind
!= C_DTR_NORMAL
2322 && (c_parser_next_token_starts_declspecs (parser
)
2323 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2325 struct c_arg_info
*args
2326 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2333 = build_function_declarator (args
,
2334 build_id_declarator (NULL_TREE
));
2335 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2339 /* A parenthesized declarator. */
2340 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2341 if (inner
!= NULL
&& attrs
!= NULL
)
2342 inner
= build_attrs_declarator (attrs
, inner
);
2343 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2345 c_parser_consume_token (parser
);
2349 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2360 if (kind
== C_DTR_NORMAL
)
2362 c_parser_error (parser
, "expected identifier or %<(%>");
2366 return build_id_declarator (NULL_TREE
);
2370 /* Parse part of a direct declarator or direct abstract declarator,
2371 given that some (in INNER) has already been parsed; ID_PRESENT is
2372 true if an identifier is present, false for an abstract
2375 static struct c_declarator
*
2376 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2377 struct c_declarator
*inner
)
2379 /* Parse a sequence of array declarators and parameter lists. */
2380 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2382 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2383 struct c_declarator
*declarator
;
2384 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2388 c_parser_consume_token (parser
);
2389 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2390 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2392 c_parser_consume_token (parser
);
2393 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2394 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2395 if (!quals_attrs
->declspecs_seen_p
)
2397 /* If "static" is present, there must be an array dimension.
2398 Otherwise, there may be a dimension, "*", or no
2403 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2407 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2412 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2414 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2418 c_parser_consume_token (parser
);
2423 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2429 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2432 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2433 c_parser_consume_token (parser
);
2436 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2440 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2441 static_seen
, star_seen
);
2442 if (declarator
== NULL
)
2444 inner
= set_array_declarator_inner (declarator
, inner
);
2445 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2447 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2450 struct c_arg_info
*args
;
2451 c_parser_consume_token (parser
);
2452 attrs
= c_parser_attributes (parser
);
2453 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2458 inner
= build_function_declarator (args
, inner
);
2459 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2465 /* Parse a parameter list or identifier list, including the closing
2466 parenthesis but not the opening one. ATTRS are the attributes at
2467 the start of the list. ID_LIST_OK is true if an identifier list is
2468 acceptable; such a list must not have attributes at the start. */
2470 static struct c_arg_info
*
2471 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2474 declare_parm_level ();
2475 /* If the list starts with an identifier, it is an identifier list.
2476 Otherwise, it is either a prototype list or an empty list. */
2479 && c_parser_next_token_is (parser
, CPP_NAME
)
2480 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2482 tree list
= NULL_TREE
, *nextp
= &list
;
2483 while (c_parser_next_token_is (parser
, CPP_NAME
)
2484 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2486 *nextp
= build_tree_list (NULL_TREE
,
2487 c_parser_peek_token (parser
)->value
);
2488 nextp
= & TREE_CHAIN (*nextp
);
2489 c_parser_consume_token (parser
);
2490 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2492 c_parser_consume_token (parser
);
2493 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2495 c_parser_error (parser
, "expected identifier");
2499 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2501 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2506 ret
->pending_sizes
= 0;
2507 ret
->had_vla_unspec
= 0;
2508 c_parser_consume_token (parser
);
2514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2522 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2528 /* Parse a parameter list (possibly empty), including the closing
2529 parenthesis but not the opening one. ATTRS are the attributes at
2530 the start of the list. */
2532 static struct c_arg_info
*
2533 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2535 bool good_parm
= false;
2536 /* ??? Following the old parser, forward parameter declarations may
2537 use abstract declarators, and if no real parameter declarations
2538 follow the forward declarations then this is not diagnosed. Also
2539 note as above that attributes are ignored as the only contents of
2540 the parentheses, or as the only contents after forward
2542 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2544 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2549 ret
->pending_sizes
= 0;
2550 ret
->had_vla_unspec
= 0;
2551 c_parser_consume_token (parser
);
2554 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2556 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2560 ret
->pending_sizes
= 0;
2561 ret
->had_vla_unspec
= 0;
2562 /* Suppress -Wold-style-definition for this case. */
2563 ret
->types
= error_mark_node
;
2564 error_at (c_parser_peek_token (parser
)->location
,
2565 "ISO C requires a named argument before %<...%>");
2566 c_parser_consume_token (parser
);
2567 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2569 c_parser_consume_token (parser
);
2574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2579 /* Nonempty list of parameters, either terminated with semicolon
2580 (forward declarations; recurse) or with close parenthesis (normal
2581 function) or with ", ... )" (variadic function). */
2584 /* Parse a parameter. */
2585 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2590 push_parm_decl (parm
);
2592 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2595 c_parser_consume_token (parser
);
2596 mark_forward_parm_decls ();
2597 new_attrs
= c_parser_attributes (parser
);
2598 return c_parser_parms_list_declarator (parser
, new_attrs
);
2600 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2602 c_parser_consume_token (parser
);
2604 return get_parm_info (false);
2607 struct c_arg_info
*ret
2608 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2613 ret
->pending_sizes
= 0;
2614 ret
->had_vla_unspec
= 0;
2618 if (!c_parser_require (parser
, CPP_COMMA
,
2619 "expected %<;%>, %<,%> or %<)%>"))
2621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2622 get_pending_sizes ();
2625 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2627 c_parser_consume_token (parser
);
2628 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2630 c_parser_consume_token (parser
);
2632 return get_parm_info (true);
2635 struct c_arg_info
*ret
2636 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2641 ret
->pending_sizes
= 0;
2642 ret
->had_vla_unspec
= 0;
2648 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2650 get_pending_sizes ();
2657 /* Parse a parameter declaration. ATTRS are the attributes at the
2658 start of the declaration if it is the first parameter. */
2660 static struct c_parm
*
2661 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2663 struct c_declspecs
*specs
;
2664 struct c_declarator
*declarator
;
2666 tree postfix_attrs
= NULL_TREE
;
2668 if (!c_parser_next_token_starts_declspecs (parser
))
2670 /* ??? In some Objective-C cases '...' isn't applicable so there
2671 should be a different message. */
2672 c_parser_error (parser
,
2673 "expected declaration specifiers or %<...%>");
2674 c_parser_skip_to_end_of_parameter (parser
);
2677 specs
= build_null_declspecs ();
2680 declspecs_add_attrs (specs
, attrs
);
2683 c_parser_declspecs (parser
, specs
, true, true, true);
2684 finish_declspecs (specs
);
2685 pending_xref_error ();
2686 prefix_attrs
= specs
->attrs
;
2687 specs
->attrs
= NULL_TREE
;
2688 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2689 C_DTR_PARM
, &dummy
);
2690 if (declarator
== NULL
)
2692 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2695 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2696 postfix_attrs
= c_parser_attributes (parser
);
2697 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2701 /* Parse a string literal in an asm expression. It should not be
2702 translated, and wide string literals are an error although
2703 permitted by the syntax. This is a GNU extension.
2708 ??? At present, following the old parser, the caller needs to have
2709 set lex_untranslated_string to 1. It would be better to follow the
2710 C++ parser rather than using this kludge. */
2713 c_parser_asm_string_literal (c_parser
*parser
)
2716 if (c_parser_next_token_is (parser
, CPP_STRING
))
2718 str
= c_parser_peek_token (parser
)->value
;
2719 c_parser_consume_token (parser
);
2721 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2723 error_at (c_parser_peek_token (parser
)->location
,
2724 "wide string literal in %<asm%>");
2725 str
= build_string (1, "");
2726 c_parser_consume_token (parser
);
2730 c_parser_error (parser
, "expected string literal");
2736 /* Parse a simple asm expression. This is used in restricted
2737 contexts, where a full expression with inputs and outputs does not
2738 make sense. This is a GNU extension.
2741 asm ( asm-string-literal )
2745 c_parser_simple_asm_expr (c_parser
*parser
)
2748 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2749 /* ??? Follow the C++ parser rather than using the
2750 lex_untranslated_string kludge. */
2751 parser
->lex_untranslated_string
= true;
2752 c_parser_consume_token (parser
);
2753 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2755 parser
->lex_untranslated_string
= false;
2758 str
= c_parser_asm_string_literal (parser
);
2759 parser
->lex_untranslated_string
= false;
2760 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2762 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2768 /* Parse (possibly empty) attributes. This is a GNU extension.
2772 attributes attribute
2775 __attribute__ ( ( attribute-list ) )
2779 attribute_list , attrib
2784 any-word ( identifier )
2785 any-word ( identifier , nonempty-expr-list )
2786 any-word ( expr-list )
2788 where the "identifier" must not be declared as a type, and
2789 "any-word" may be any identifier (including one declared as a
2790 type), a reserved word storage class specifier, type specifier or
2791 type qualifier. ??? This still leaves out most reserved keywords
2792 (following the old parser), shouldn't we include them, and why not
2793 allow identifiers declared as types to start the arguments? */
2796 c_parser_attributes (c_parser
*parser
)
2798 tree attrs
= NULL_TREE
;
2799 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2801 /* ??? Follow the C++ parser rather than using the
2802 lex_untranslated_string kludge. */
2803 parser
->lex_untranslated_string
= true;
2804 c_parser_consume_token (parser
);
2805 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2807 parser
->lex_untranslated_string
= false;
2810 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2812 parser
->lex_untranslated_string
= false;
2813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2816 /* Parse the attribute list. */
2817 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2818 || c_parser_next_token_is (parser
, CPP_NAME
)
2819 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2821 tree attr
, attr_name
, attr_args
;
2822 VEC(tree
,gc
) *expr_list
;
2823 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2825 c_parser_consume_token (parser
);
2828 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2830 /* ??? See comment above about what keywords are
2833 switch (c_parser_peek_token (parser
)->keyword
)
2870 /* Accept __attribute__((__const)) as __attribute__((const))
2873 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2876 attr_name
= c_parser_peek_token (parser
)->value
;
2877 c_parser_consume_token (parser
);
2878 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2880 attr
= build_tree_list (attr_name
, NULL_TREE
);
2881 attrs
= chainon (attrs
, attr
);
2884 c_parser_consume_token (parser
);
2885 /* Parse the attribute contents. If they start with an
2886 identifier which is followed by a comma or close
2887 parenthesis, then the arguments start with that
2888 identifier; otherwise they are an expression list. */
2889 if (c_parser_next_token_is (parser
, CPP_NAME
)
2890 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2891 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2892 || (c_parser_peek_2nd_token (parser
)->type
2893 == CPP_CLOSE_PAREN
)))
2895 tree arg1
= c_parser_peek_token (parser
)->value
;
2896 c_parser_consume_token (parser
);
2897 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2898 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2902 c_parser_consume_token (parser
);
2903 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2904 tree_list
= build_tree_list_vec (expr_list
);
2905 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2906 release_tree_vector (expr_list
);
2911 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2912 attr_args
= NULL_TREE
;
2915 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2916 attr_args
= build_tree_list_vec (expr_list
);
2917 release_tree_vector (expr_list
);
2920 attr
= build_tree_list (attr_name
, attr_args
);
2921 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2922 c_parser_consume_token (parser
);
2925 parser
->lex_untranslated_string
= false;
2926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2930 attrs
= chainon (attrs
, attr
);
2932 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2933 c_parser_consume_token (parser
);
2936 parser
->lex_untranslated_string
= false;
2937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2941 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2942 c_parser_consume_token (parser
);
2945 parser
->lex_untranslated_string
= false;
2946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2950 parser
->lex_untranslated_string
= false;
2955 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2958 specifier-qualifier-list abstract-declarator[opt]
2961 static struct c_type_name
*
2962 c_parser_type_name (c_parser
*parser
)
2964 struct c_declspecs
*specs
= build_null_declspecs ();
2965 struct c_declarator
*declarator
;
2966 struct c_type_name
*ret
;
2968 c_parser_declspecs (parser
, specs
, false, true, true);
2969 if (!specs
->declspecs_seen_p
)
2971 c_parser_error (parser
, "expected specifier-qualifier-list");
2974 pending_xref_error ();
2975 finish_declspecs (specs
);
2976 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2977 C_DTR_ABSTRACT
, &dummy
);
2978 if (declarator
== NULL
)
2980 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2982 ret
->declarator
= declarator
;
2986 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2989 assignment-expression
2990 { initializer-list }
2991 { initializer-list , }
2994 designation[opt] initializer
2995 initializer-list , designation[opt] initializer
3002 designator-list designator
3009 [ constant-expression ]
3021 [ constant-expression ... constant-expression ]
3023 Any expression without commas is accepted in the syntax for the
3024 constant-expressions, with non-constant expressions rejected later.
3026 This function is only used for top-level initializers; for nested
3027 ones, see c_parser_initval. */
3029 static struct c_expr
3030 c_parser_initializer (c_parser
*parser
)
3032 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3033 return c_parser_braced_init (parser
, NULL_TREE
, false);
3037 location_t loc
= c_parser_peek_token (parser
)->location
;
3038 ret
= c_parser_expr_no_commas (parser
, NULL
);
3039 if (TREE_CODE (ret
.value
) != STRING_CST
3040 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3041 ret
= default_function_array_conversion (loc
, ret
);
3046 /* Parse a braced initializer list. TYPE is the type specified for a
3047 compound literal, and NULL_TREE for other initializers and for
3048 nested braced lists. NESTED_P is true for nested braced lists,
3049 false for the list of a compound literal or the list that is the
3050 top-level initializer in a declaration. */
3052 static struct c_expr
3053 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3055 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3056 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3057 c_parser_consume_token (parser
);
3059 push_init_level (0);
3061 really_start_incremental_init (type
);
3062 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3064 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3068 /* Parse a non-empty initializer list, possibly with a trailing
3072 c_parser_initelt (parser
);
3075 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3076 c_parser_consume_token (parser
);
3079 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3083 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3086 ret
.value
= error_mark_node
;
3087 ret
.original_code
= ERROR_MARK
;
3088 ret
.original_type
= NULL
;
3089 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3093 c_parser_consume_token (parser
);
3094 return pop_init_level (0);
3097 /* Parse a nested initializer, including designators. */
3100 c_parser_initelt (c_parser
*parser
)
3102 /* Parse any designator or designator list. A single array
3103 designator may have the subsequent "=" omitted in GNU C, but a
3104 longer list or a structure member designator may not. */
3105 if (c_parser_next_token_is (parser
, CPP_NAME
)
3106 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3108 /* Old-style structure member designator. */
3109 set_init_label (c_parser_peek_token (parser
)->value
);
3110 /* Use the colon as the error location. */
3111 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3112 "obsolete use of designated initializer with %<:%>");
3113 c_parser_consume_token (parser
);
3114 c_parser_consume_token (parser
);
3118 /* des_seen is 0 if there have been no designators, 1 if there
3119 has been a single array designator and 2 otherwise. */
3121 /* Location of a designator. */
3122 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3123 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3124 || c_parser_next_token_is (parser
, CPP_DOT
))
3126 int des_prev
= des_seen
;
3128 des_loc
= c_parser_peek_token (parser
)->location
;
3131 if (c_parser_next_token_is (parser
, CPP_DOT
))
3134 c_parser_consume_token (parser
);
3135 if (c_parser_next_token_is (parser
, CPP_NAME
))
3137 set_init_label (c_parser_peek_token (parser
)->value
);
3138 c_parser_consume_token (parser
);
3143 init
.value
= error_mark_node
;
3144 init
.original_code
= ERROR_MARK
;
3145 init
.original_type
= NULL
;
3146 c_parser_error (parser
, "expected identifier");
3147 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3148 process_init_element (init
, false);
3155 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3156 /* ??? Following the old parser, [ objc-receiver
3157 objc-message-args ] is accepted as an initializer,
3158 being distinguished from a designator by what follows
3159 the first assignment expression inside the square
3160 brackets, but after a first array designator a
3161 subsequent square bracket is for Objective-C taken to
3162 start an expression, using the obsolete form of
3163 designated initializer without '=', rather than
3164 possibly being a second level of designation: in LALR
3165 terms, the '[' is shifted rather than reducing
3166 designator to designator-list. */
3167 if (des_prev
== 1 && c_dialect_objc ())
3169 des_seen
= des_prev
;
3172 if (des_prev
== 0 && c_dialect_objc ())
3174 /* This might be an array designator or an
3175 Objective-C message expression. If the former,
3176 continue parsing here; if the latter, parse the
3177 remainder of the initializer given the starting
3178 primary-expression. ??? It might make sense to
3179 distinguish when des_prev == 1 as well; see
3180 previous comment. */
3182 struct c_expr mexpr
;
3183 c_parser_consume_token (parser
);
3184 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3185 && ((c_parser_peek_token (parser
)->id_kind
3187 || (c_parser_peek_token (parser
)->id_kind
3188 == C_ID_CLASSNAME
)))
3190 /* Type name receiver. */
3191 tree id
= c_parser_peek_token (parser
)->value
;
3192 c_parser_consume_token (parser
);
3193 rec
= objc_get_class_reference (id
);
3194 goto parse_message_args
;
3196 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3197 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3198 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3199 goto array_desig_after_first
;
3200 /* Expression receiver. So far only one part
3201 without commas has been parsed; there might be
3202 more of the expression. */
3204 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3207 location_t comma_loc
, exp_loc
;
3208 comma_loc
= c_parser_peek_token (parser
)->location
;
3209 c_parser_consume_token (parser
);
3210 exp_loc
= c_parser_peek_token (parser
)->location
;
3211 next
= c_parser_expr_no_commas (parser
, NULL
);
3212 next
= default_function_array_conversion (exp_loc
, next
);
3213 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3216 /* Now parse the objc-message-args. */
3217 args
= c_parser_objc_message_args (parser
);
3218 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3221 = objc_build_message_expr (build_tree_list (rec
, args
));
3222 mexpr
.original_code
= ERROR_MARK
;
3223 mexpr
.original_type
= NULL
;
3224 /* Now parse and process the remainder of the
3225 initializer, starting with this message
3226 expression as a primary-expression. */
3227 c_parser_initval (parser
, &mexpr
);
3230 c_parser_consume_token (parser
);
3231 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3232 array_desig_after_first
:
3233 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3235 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3236 c_parser_consume_token (parser
);
3237 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3241 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3243 c_parser_consume_token (parser
);
3244 set_init_index (first
, second
);
3246 pedwarn (ellipsis_loc
, OPT_pedantic
,
3247 "ISO C forbids specifying range of elements to initialize");
3250 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3256 if (c_parser_next_token_is (parser
, CPP_EQ
))
3259 pedwarn (des_loc
, OPT_pedantic
,
3260 "ISO C90 forbids specifying subobject to initialize");
3261 c_parser_consume_token (parser
);
3266 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3267 "obsolete use of designated initializer without %<=%>");
3271 init
.value
= error_mark_node
;
3272 init
.original_code
= ERROR_MARK
;
3273 init
.original_type
= NULL
;
3274 c_parser_error (parser
, "expected %<=%>");
3275 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3276 process_init_element (init
, false);
3282 c_parser_initval (parser
, NULL
);
3285 /* Parse a nested initializer; as c_parser_initializer but parses
3286 initializers within braced lists, after any designators have been
3287 applied. If AFTER is not NULL then it is an Objective-C message
3288 expression which is the primary-expression starting the
3292 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3295 gcc_assert (!after
|| c_dialect_objc ());
3296 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3297 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3300 location_t loc
= c_parser_peek_token (parser
)->location
;
3301 init
= c_parser_expr_no_commas (parser
, after
);
3302 if (init
.value
!= NULL_TREE
3303 && TREE_CODE (init
.value
) != STRING_CST
3304 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3305 init
= default_function_array_conversion (loc
, init
);
3307 process_init_element (init
, false);
3310 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3314 { block-item-list[opt] }
3315 { label-declarations block-item-list }
3319 block-item-list block-item
3331 { label-declarations block-item-list }
3334 __extension__ nested-declaration
3335 nested-function-definition
3339 label-declarations label-declaration
3342 __label__ identifier-list ;
3344 Allowing the mixing of declarations and code is new in C99. The
3345 GNU syntax also permits (not shown above) labels at the end of
3346 compound statements, which yield an error. We don't allow labels
3347 on declarations; this might seem like a natural extension, but
3348 there would be a conflict between attributes on the label and
3349 prefix attributes on the declaration. ??? The syntax follows the
3350 old parser in requiring something after label declarations.
3351 Although they are erroneous if the labels declared aren't defined,
3352 is it useful for the syntax to be this way?
3364 c_parser_compound_statement (c_parser
*parser
)
3367 location_t brace_loc
;
3368 brace_loc
= c_parser_peek_token (parser
)->location
;
3369 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3371 /* Ensure a scope is entered and left anyway to avoid confusion
3372 if we have just prepared to enter a function body. */
3373 stmt
= c_begin_compound_stmt (true);
3374 c_end_compound_stmt (brace_loc
, stmt
, true);
3375 return error_mark_node
;
3377 stmt
= c_begin_compound_stmt (true);
3378 c_parser_compound_statement_nostart (parser
);
3379 return c_end_compound_stmt (brace_loc
, stmt
, true);
3382 /* Parse a compound statement except for the opening brace. This is
3383 used for parsing both compound statements and statement expressions
3384 (which follow different paths to handling the opening). */
3387 c_parser_compound_statement_nostart (c_parser
*parser
)
3389 bool last_stmt
= false;
3390 bool last_label
= false;
3391 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3392 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3393 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3395 c_parser_consume_token (parser
);
3398 mark_valid_location_for_stdc_pragma (true);
3399 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3401 /* Read zero or more forward-declarations for labels that nested
3402 functions can jump to. */
3403 mark_valid_location_for_stdc_pragma (false);
3404 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3406 label_loc
= c_parser_peek_token (parser
)->location
;
3407 c_parser_consume_token (parser
);
3408 /* Any identifiers, including those declared as type names,
3413 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3415 c_parser_error (parser
, "expected identifier");
3419 = declare_label (c_parser_peek_token (parser
)->value
);
3420 C_DECLARED_LABEL_FLAG (label
) = 1;
3421 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3422 c_parser_consume_token (parser
);
3423 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3424 c_parser_consume_token (parser
);
3428 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3430 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3432 /* We must now have at least one statement, label or declaration. */
3433 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3435 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3436 c_parser_error (parser
, "expected declaration or statement");
3437 c_parser_consume_token (parser
);
3440 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3442 location_t loc
= c_parser_peek_token (parser
)->location
;
3443 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3444 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3445 || (c_parser_next_token_is (parser
, CPP_NAME
)
3446 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3448 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3449 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3451 label_loc
= c_parser_peek_token (parser
)->location
;
3454 mark_valid_location_for_stdc_pragma (false);
3455 c_parser_label (parser
);
3457 else if (!last_label
3458 && c_parser_next_token_starts_declspecs (parser
))
3461 mark_valid_location_for_stdc_pragma (false);
3462 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3465 (pedantic
&& !flag_isoc99
)
3467 : OPT_Wdeclaration_after_statement
,
3468 "ISO C90 forbids mixed declarations and code");
3471 else if (!last_label
3472 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3474 /* __extension__ can start a declaration, but is also an
3475 unary operator that can start an expression. Consume all
3476 but the last of a possible series of __extension__ to
3478 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3479 && (c_parser_peek_2nd_token (parser
)->keyword
3481 c_parser_consume_token (parser
);
3482 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3485 ext
= disable_extension_diagnostics ();
3486 c_parser_consume_token (parser
);
3488 mark_valid_location_for_stdc_pragma (false);
3489 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3490 /* Following the old parser, __extension__ does not
3491 disable this diagnostic. */
3492 restore_extension_diagnostics (ext
);
3494 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3496 : OPT_Wdeclaration_after_statement
,
3497 "ISO C90 forbids mixed declarations and code");
3503 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3505 /* External pragmas, and some omp pragmas, are not associated
3506 with regular c code, and so are not to be considered statements
3507 syntactically. This ensures that the user doesn't put them
3508 places that would turn into syntax errors if the directive
3510 if (c_parser_pragma (parser
, pragma_compound
))
3511 last_label
= false, last_stmt
= true;
3513 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3515 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3516 c_parser_error (parser
, "expected declaration or statement");
3519 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3521 if (parser
->in_if_block
)
3523 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3524 error_at (loc
, """expected %<}%> before %<else%>");
3529 error_at (loc
, "%<else%> without a previous %<if%>");
3530 c_parser_consume_token (parser
);
3539 mark_valid_location_for_stdc_pragma (false);
3540 c_parser_statement_after_labels (parser
);
3543 parser
->error
= false;
3546 error_at (label_loc
, "label at end of compound statement");
3547 c_parser_consume_token (parser
);
3548 /* Restore the value we started with. */
3549 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3552 /* Parse a label (C90 6.6.1, C99 6.8.1).
3555 identifier : attributes[opt]
3556 case constant-expression :
3562 case constant-expression ... constant-expression :
3564 The use of attributes on labels is a GNU extension. The syntax in
3565 GNU C accepts any expressions without commas, non-constant
3566 expressions being rejected later. */
3569 c_parser_label (c_parser
*parser
)
3571 location_t loc1
= c_parser_peek_token (parser
)->location
;
3572 tree label
= NULL_TREE
;
3573 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3576 c_parser_consume_token (parser
);
3577 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3578 if (c_parser_next_token_is (parser
, CPP_COLON
))
3580 c_parser_consume_token (parser
);
3581 label
= do_case (loc1
, exp1
, NULL_TREE
);
3583 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3585 c_parser_consume_token (parser
);
3586 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3587 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3588 label
= do_case (loc1
, exp1
, exp2
);
3591 c_parser_error (parser
, "expected %<:%> or %<...%>");
3593 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3595 c_parser_consume_token (parser
);
3596 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3597 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3601 tree name
= c_parser_peek_token (parser
)->value
;
3604 location_t loc2
= c_parser_peek_token (parser
)->location
;
3605 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3606 c_parser_consume_token (parser
);
3607 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3608 c_parser_consume_token (parser
);
3609 attrs
= c_parser_attributes (parser
);
3610 tlab
= define_label (loc2
, name
);
3613 decl_attributes (&tlab
, attrs
, 0);
3614 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
3619 if (c_parser_next_token_starts_declspecs (parser
)
3620 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3621 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3623 error_at (c_parser_peek_token (parser
)->location
,
3624 "a label can only be part of a statement and "
3625 "a declaration is not a statement");
3626 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3627 /*nested*/ true, /*empty_ok*/ false,
3628 /*start_attr_ok*/ true);
3633 /* Parse a statement (C90 6.6, C99 6.8).
3638 expression-statement
3646 expression-statement:
3649 selection-statement:
3653 iteration-statement:
3662 return expression[opt] ;
3675 objc-throw-statement
3676 objc-try-catch-statement
3677 objc-synchronized-statement
3679 objc-throw-statement:
3693 parallel-for-construct
3694 parallel-sections-construct
3701 parallel-directive structured-block
3704 for-directive iteration-statement
3707 sections-directive section-scope
3710 single-directive structured-block
3712 parallel-for-construct:
3713 parallel-for-directive iteration-statement
3715 parallel-sections-construct:
3716 parallel-sections-directive section-scope
3719 master-directive structured-block
3722 critical-directive structured-block
3725 atomic-directive expression-statement
3728 ordered-directive structured-block */
3731 c_parser_statement (c_parser
*parser
)
3733 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3734 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3735 || (c_parser_next_token_is (parser
, CPP_NAME
)
3736 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3737 c_parser_label (parser
);
3738 c_parser_statement_after_labels (parser
);
3741 /* Parse a statement, other than a labeled statement. */
3744 c_parser_statement_after_labels (c_parser
*parser
)
3746 location_t loc
= c_parser_peek_token (parser
)->location
;
3747 tree stmt
= NULL_TREE
;
3748 bool in_if_block
= parser
->in_if_block
;
3749 parser
->in_if_block
= false;
3750 switch (c_parser_peek_token (parser
)->type
)
3752 case CPP_OPEN_BRACE
:
3753 add_stmt (c_parser_compound_statement (parser
));
3756 switch (c_parser_peek_token (parser
)->keyword
)
3759 c_parser_if_statement (parser
);
3762 c_parser_switch_statement (parser
);
3765 c_parser_while_statement (parser
);
3768 c_parser_do_statement (parser
);
3771 c_parser_for_statement (parser
);
3774 c_parser_consume_token (parser
);
3775 if (c_parser_next_token_is (parser
, CPP_NAME
))
3777 stmt
= c_finish_goto_label (loc
,
3778 c_parser_peek_token (parser
)->value
);
3779 c_parser_consume_token (parser
);
3781 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3783 c_parser_consume_token (parser
);
3784 stmt
= c_finish_goto_ptr (loc
,
3785 c_parser_expression (parser
).value
);
3788 c_parser_error (parser
, "expected identifier or %<*%>");
3789 goto expect_semicolon
;
3791 c_parser_consume_token (parser
);
3792 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
3793 goto expect_semicolon
;
3795 c_parser_consume_token (parser
);
3796 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
3797 goto expect_semicolon
;
3799 c_parser_consume_token (parser
);
3800 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3802 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
3803 c_parser_consume_token (parser
);
3807 struct c_expr expr
= c_parser_expression_conv (parser
);
3808 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
3809 goto expect_semicolon
;
3813 stmt
= c_parser_asm_statement (parser
);
3816 gcc_assert (c_dialect_objc ());
3817 c_parser_consume_token (parser
);
3818 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3820 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
3821 c_parser_consume_token (parser
);
3825 tree expr
= c_parser_expression (parser
).value
;
3826 expr
= c_fully_fold (expr
, false, NULL
);
3827 stmt
= objc_build_throw_stmt (loc
, expr
);
3828 goto expect_semicolon
;
3832 gcc_assert (c_dialect_objc ());
3833 c_parser_objc_try_catch_statement (parser
);
3835 case RID_AT_SYNCHRONIZED
:
3836 gcc_assert (c_dialect_objc ());
3837 c_parser_objc_synchronized_statement (parser
);
3844 c_parser_consume_token (parser
);
3846 case CPP_CLOSE_PAREN
:
3847 case CPP_CLOSE_SQUARE
:
3848 /* Avoid infinite loop in error recovery:
3849 c_parser_skip_until_found stops at a closing nesting
3850 delimiter without consuming it, but here we need to consume
3851 it to proceed further. */
3852 c_parser_error (parser
, "expected statement");
3853 c_parser_consume_token (parser
);
3856 c_parser_pragma (parser
, pragma_stmt
);
3860 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
3862 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3865 /* Two cases cannot and do not have line numbers associated: If stmt
3866 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3867 cannot hold line numbers. But that's OK because the statement
3868 will either be changed to a MODIFY_EXPR during gimplification of
3869 the statement expr, or discarded. If stmt was compound, but
3870 without new variables, we will have skipped the creation of a
3871 BIND and will have a bare STATEMENT_LIST. But that's OK because
3872 (recursively) all of the component statements should already have
3873 line numbers assigned. ??? Can we discard no-op statements
3875 if (CAN_HAVE_LOCATION_P (stmt
)
3876 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
3877 SET_EXPR_LOCATION (stmt
, loc
);
3879 parser
->in_if_block
= in_if_block
;
3882 /* Parse the condition from an if, do, while or for statements. */
3885 c_parser_condition (c_parser
*parser
)
3887 location_t loc
= c_parser_peek_token (parser
)->location
;
3889 cond
= c_parser_expression_conv (parser
).value
;
3890 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3891 cond
= c_fully_fold (cond
, false, NULL
);
3892 if (warn_sequence_point
)
3893 verify_sequence_points (cond
);
3897 /* Parse a parenthesized condition from an if, do or while statement.
3903 c_parser_paren_condition (c_parser
*parser
)
3906 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3907 return error_mark_node
;
3908 cond
= c_parser_condition (parser
);
3909 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3913 /* Parse a statement which is a block in C99. */
3916 c_parser_c99_block_statement (c_parser
*parser
)
3918 tree block
= c_begin_compound_stmt (flag_isoc99
);
3919 location_t loc
= c_parser_peek_token (parser
)->location
;
3920 c_parser_statement (parser
);
3921 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
3924 /* Parse the body of an if statement. This is just parsing a
3925 statement but (a) it is a block in C99, (b) we track whether the
3926 body is an if statement for the sake of -Wparentheses warnings, (c)
3927 we handle an empty body specially for the sake of -Wempty-body
3928 warnings, and (d) we call parser_compound_statement directly
3929 because c_parser_statement_after_labels resets
3930 parser->in_if_block. */
3933 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3935 tree block
= c_begin_compound_stmt (flag_isoc99
);
3936 location_t body_loc
= c_parser_peek_token (parser
)->location
;
3937 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3938 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3939 || (c_parser_next_token_is (parser
, CPP_NAME
)
3940 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3941 c_parser_label (parser
);
3942 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3943 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3945 location_t loc
= c_parser_peek_token (parser
)->location
;
3946 add_stmt (build_empty_stmt (loc
));
3947 c_parser_consume_token (parser
);
3948 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3949 warning_at (loc
, OPT_Wempty_body
,
3950 "suggest braces around empty body in an %<if%> statement");
3952 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3953 add_stmt (c_parser_compound_statement (parser
));
3955 c_parser_statement_after_labels (parser
);
3956 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
3959 /* Parse the else body of an if statement. This is just parsing a
3960 statement but (a) it is a block in C99, (b) we handle an empty body
3961 specially for the sake of -Wempty-body warnings. */
3964 c_parser_else_body (c_parser
*parser
)
3966 location_t else_loc
= c_parser_peek_token (parser
)->location
;
3967 tree block
= c_begin_compound_stmt (flag_isoc99
);
3968 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3969 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3970 || (c_parser_next_token_is (parser
, CPP_NAME
)
3971 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3972 c_parser_label (parser
);
3973 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3975 location_t loc
= c_parser_peek_token (parser
)->location
;
3978 "suggest braces around empty body in an %<else%> statement");
3979 add_stmt (build_empty_stmt (loc
));
3980 c_parser_consume_token (parser
);
3983 c_parser_statement_after_labels (parser
);
3984 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
3987 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3990 if ( expression ) statement
3991 if ( expression ) statement else statement
3995 c_parser_if_statement (c_parser
*parser
)
4000 bool first_if
= false;
4001 tree first_body
, second_body
;
4004 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4005 c_parser_consume_token (parser
);
4006 block
= c_begin_compound_stmt (flag_isoc99
);
4007 loc
= c_parser_peek_token (parser
)->location
;
4008 cond
= c_parser_paren_condition (parser
);
4009 in_if_block
= parser
->in_if_block
;
4010 parser
->in_if_block
= true;
4011 first_body
= c_parser_if_body (parser
, &first_if
);
4012 parser
->in_if_block
= in_if_block
;
4013 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4015 c_parser_consume_token (parser
);
4016 second_body
= c_parser_else_body (parser
);
4019 second_body
= NULL_TREE
;
4020 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4021 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4024 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4027 switch (expression) statement
4031 c_parser_switch_statement (c_parser
*parser
)
4033 tree block
, expr
, body
, save_break
;
4034 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4035 location_t switch_cond_loc
;
4036 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4037 c_parser_consume_token (parser
);
4038 block
= c_begin_compound_stmt (flag_isoc99
);
4039 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4041 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4042 expr
= c_parser_expression (parser
).value
;
4043 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4047 switch_cond_loc
= UNKNOWN_LOCATION
;
4048 expr
= error_mark_node
;
4050 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4051 save_break
= c_break_label
;
4052 c_break_label
= NULL_TREE
;
4053 body
= c_parser_c99_block_statement (parser
);
4054 c_finish_case (body
);
4057 location_t here
= c_parser_peek_token (parser
)->location
;
4058 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4059 SET_EXPR_LOCATION (t
, here
);
4062 c_break_label
= save_break
;
4063 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4066 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4069 while (expression) statement
4073 c_parser_while_statement (c_parser
*parser
)
4075 tree block
, cond
, body
, save_break
, save_cont
;
4077 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4078 c_parser_consume_token (parser
);
4079 block
= c_begin_compound_stmt (flag_isoc99
);
4080 loc
= c_parser_peek_token (parser
)->location
;
4081 cond
= c_parser_paren_condition (parser
);
4082 save_break
= c_break_label
;
4083 c_break_label
= NULL_TREE
;
4084 save_cont
= c_cont_label
;
4085 c_cont_label
= NULL_TREE
;
4086 body
= c_parser_c99_block_statement (parser
);
4087 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4088 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4089 c_break_label
= save_break
;
4090 c_cont_label
= save_cont
;
4093 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4096 do statement while ( expression ) ;
4100 c_parser_do_statement (c_parser
*parser
)
4102 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4104 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4105 c_parser_consume_token (parser
);
4106 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4107 warning_at (c_parser_peek_token (parser
)->location
,
4109 "suggest braces around empty body in %<do%> statement");
4110 block
= c_begin_compound_stmt (flag_isoc99
);
4111 loc
= c_parser_peek_token (parser
)->location
;
4112 save_break
= c_break_label
;
4113 c_break_label
= NULL_TREE
;
4114 save_cont
= c_cont_label
;
4115 c_cont_label
= NULL_TREE
;
4116 body
= c_parser_c99_block_statement (parser
);
4117 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4118 new_break
= c_break_label
;
4119 c_break_label
= save_break
;
4120 new_cont
= c_cont_label
;
4121 c_cont_label
= save_cont
;
4122 cond
= c_parser_paren_condition (parser
);
4123 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4124 c_parser_skip_to_end_of_block_or_statement (parser
);
4125 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4126 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4129 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4132 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4133 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4135 The form with a declaration is new in C99.
4137 ??? In accordance with the old parser, the declaration may be a
4138 nested function, which is then rejected in check_for_loop_decls,
4139 but does it make any sense for this to be included in the grammar?
4140 Note in particular that the nested function does not include a
4141 trailing ';', whereas the "declaration" production includes one.
4142 Also, can we reject bad declarations earlier and cheaper than
4143 check_for_loop_decls? */
4146 c_parser_for_statement (c_parser
*parser
)
4148 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4149 location_t loc
= c_parser_peek_token (parser
)->location
;
4150 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4151 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4152 c_parser_consume_token (parser
);
4153 block
= c_begin_compound_stmt (flag_isoc99
);
4154 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4156 /* Parse the initialization declaration or expression. */
4157 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4159 c_parser_consume_token (parser
);
4160 c_finish_expr_stmt (loc
, NULL_TREE
);
4162 else if (c_parser_next_token_starts_declspecs (parser
))
4164 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4165 check_for_loop_decls (for_loc
);
4167 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4169 /* __extension__ can start a declaration, but is also an
4170 unary operator that can start an expression. Consume all
4171 but the last of a possible series of __extension__ to
4173 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4174 && (c_parser_peek_2nd_token (parser
)->keyword
4176 c_parser_consume_token (parser
);
4177 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4180 ext
= disable_extension_diagnostics ();
4181 c_parser_consume_token (parser
);
4182 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4183 restore_extension_diagnostics (ext
);
4184 check_for_loop_decls (for_loc
);
4192 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
4193 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4195 /* Parse the loop condition. */
4196 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4198 c_parser_consume_token (parser
);
4203 cond
= c_parser_condition (parser
);
4204 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4206 /* Parse the increment expression. */
4207 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4208 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4210 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4211 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4215 cond
= error_mark_node
;
4216 incr
= error_mark_node
;
4218 save_break
= c_break_label
;
4219 c_break_label
= NULL_TREE
;
4220 save_cont
= c_cont_label
;
4221 c_cont_label
= NULL_TREE
;
4222 body
= c_parser_c99_block_statement (parser
);
4223 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4224 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4225 c_break_label
= save_break
;
4226 c_cont_label
= save_cont
;
4229 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4230 statement with inputs, outputs, clobbers, and volatile tag
4234 asm type-qualifier[opt] ( asm-argument ) ;
4235 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4239 asm-string-literal : asm-operands[opt]
4240 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4241 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4244 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4247 Qualifiers other than volatile are accepted in the syntax but
4251 c_parser_asm_statement (c_parser
*parser
)
4253 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4254 bool simple
, is_goto
;
4255 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4256 int section
, nsections
;
4258 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4259 c_parser_consume_token (parser
);
4260 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4262 quals
= c_parser_peek_token (parser
)->value
;
4263 c_parser_consume_token (parser
);
4265 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4266 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4268 warning_at (c_parser_peek_token (parser
)->location
,
4270 "%E qualifier ignored on asm",
4271 c_parser_peek_token (parser
)->value
);
4273 c_parser_consume_token (parser
);
4279 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4281 c_parser_consume_token (parser
);
4285 /* ??? Follow the C++ parser rather than using the
4286 lex_untranslated_string kludge. */
4287 parser
->lex_untranslated_string
= true;
4290 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4293 str
= c_parser_asm_string_literal (parser
);
4294 if (str
== NULL_TREE
)
4295 goto error_close_paren
;
4298 outputs
= NULL_TREE
;
4300 clobbers
= NULL_TREE
;
4303 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4306 /* Parse each colon-delimited section of operands. */
4307 nsections
= 3 + is_goto
;
4308 for (section
= 0; section
< nsections
; ++section
)
4310 if (!c_parser_require (parser
, CPP_COLON
,
4313 : "expected %<:%> or %<)%>"))
4314 goto error_close_paren
;
4316 /* Once past any colon, we're no longer a simple asm. */
4319 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4320 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4325 /* For asm goto, we don't allow output operands, but reserve
4326 the slot for a future extension that does allow them. */
4328 outputs
= c_parser_asm_operands (parser
, false);
4331 inputs
= c_parser_asm_operands (parser
, true);
4334 clobbers
= c_parser_asm_clobbers (parser
);
4337 labels
= c_parser_asm_goto_operands (parser
);
4343 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4348 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4354 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4355 c_parser_skip_to_end_of_block_or_statement (parser
);
4357 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4358 clobbers
, labels
, simple
));
4361 parser
->lex_untranslated_string
= false;
4365 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4369 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4370 not outputs), apply the default conversion of functions and arrays
4375 asm-operands , asm-operand
4378 asm-string-literal ( expression )
4379 [ identifier ] asm-string-literal ( expression )
4383 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4385 tree list
= NULL_TREE
;
4391 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4393 c_parser_consume_token (parser
);
4394 if (c_parser_next_token_is (parser
, CPP_NAME
))
4396 tree id
= c_parser_peek_token (parser
)->value
;
4397 c_parser_consume_token (parser
);
4398 name
= build_string (IDENTIFIER_LENGTH (id
),
4399 IDENTIFIER_POINTER (id
));
4403 c_parser_error (parser
, "expected identifier");
4404 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4407 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4412 str
= c_parser_asm_string_literal (parser
);
4413 if (str
== NULL_TREE
)
4415 parser
->lex_untranslated_string
= false;
4416 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4418 parser
->lex_untranslated_string
= true;
4421 loc
= c_parser_peek_token (parser
)->location
;
4422 expr
= c_parser_expression (parser
);
4424 expr
= default_function_array_conversion (loc
, expr
);
4425 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4426 parser
->lex_untranslated_string
= true;
4427 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4432 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4434 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4435 c_parser_consume_token (parser
);
4442 /* Parse asm clobbers, a GNU extension.
4446 asm-clobbers , asm-string-literal
4450 c_parser_asm_clobbers (c_parser
*parser
)
4452 tree list
= NULL_TREE
;
4455 tree str
= c_parser_asm_string_literal (parser
);
4457 list
= tree_cons (NULL_TREE
, str
, list
);
4460 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4461 c_parser_consume_token (parser
);
4468 /* Parse asm goto labels, a GNU extension.
4472 asm-goto-operands , identifier
4476 c_parser_asm_goto_operands (c_parser
*parser
)
4478 tree list
= NULL_TREE
;
4483 if (c_parser_next_token_is (parser
, CPP_NAME
))
4485 c_token
*tok
= c_parser_peek_token (parser
);
4487 label
= lookup_label_for_goto (tok
->location
, name
);
4488 c_parser_consume_token (parser
);
4489 TREE_USED (label
) = 1;
4493 c_parser_error (parser
, "expected identifier");
4497 name
= build_string (IDENTIFIER_LENGTH (name
),
4498 IDENTIFIER_POINTER (name
));
4499 list
= tree_cons (name
, label
, list
);
4500 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4501 c_parser_consume_token (parser
);
4503 return nreverse (list
);
4507 /* Parse an expression other than a compound expression; that is, an
4508 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4509 NULL then it is an Objective-C message expression which is the
4510 primary-expression starting the expression as an initializer.
4512 assignment-expression:
4513 conditional-expression
4514 unary-expression assignment-operator assignment-expression
4516 assignment-operator: one of
4517 = *= /= %= += -= <<= >>= &= ^= |=
4519 In GNU C we accept any conditional expression on the LHS and
4520 diagnose the invalid lvalue rather than producing a syntax
4523 static struct c_expr
4524 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4526 struct c_expr lhs
, rhs
, ret
;
4527 enum tree_code code
;
4528 location_t op_location
, exp_location
;
4529 gcc_assert (!after
|| c_dialect_objc ());
4530 lhs
= c_parser_conditional_expression (parser
, after
);
4531 op_location
= c_parser_peek_token (parser
)->location
;
4532 switch (c_parser_peek_token (parser
)->type
)
4541 code
= TRUNC_DIV_EXPR
;
4544 code
= TRUNC_MOD_EXPR
;
4559 code
= BIT_AND_EXPR
;
4562 code
= BIT_XOR_EXPR
;
4565 code
= BIT_IOR_EXPR
;
4570 c_parser_consume_token (parser
);
4571 exp_location
= c_parser_peek_token (parser
)->location
;
4572 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4573 rhs
= default_function_array_conversion (exp_location
, rhs
);
4574 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4575 code
, exp_location
, rhs
.value
,
4577 if (code
== NOP_EXPR
)
4578 ret
.original_code
= MODIFY_EXPR
;
4581 TREE_NO_WARNING (ret
.value
) = 1;
4582 ret
.original_code
= ERROR_MARK
;
4584 ret
.original_type
= NULL
;
4588 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4589 is not NULL then it is an Objective-C message expression which is
4590 the primary-expression starting the expression as an initializer.
4592 conditional-expression:
4593 logical-OR-expression
4594 logical-OR-expression ? expression : conditional-expression
4598 conditional-expression:
4599 logical-OR-expression ? : conditional-expression
4602 static struct c_expr
4603 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4605 struct c_expr cond
, exp1
, exp2
, ret
;
4606 location_t cond_loc
, colon_loc
;
4608 gcc_assert (!after
|| c_dialect_objc ());
4610 cond
= c_parser_binary_expression (parser
, after
);
4612 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4614 cond_loc
= c_parser_peek_token (parser
)->location
;
4615 cond
= default_function_array_conversion (cond_loc
, cond
);
4616 c_parser_consume_token (parser
);
4617 if (c_parser_next_token_is (parser
, CPP_COLON
))
4619 tree eptype
= NULL_TREE
;
4620 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4621 "ISO C forbids omitting the middle term of a ?: expression");
4622 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4624 eptype
= TREE_TYPE (cond
.value
);
4625 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4627 /* Make sure first operand is calculated only once. */
4628 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4630 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4631 exp1
.original_type
= NULL
;
4632 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4633 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
4638 = c_objc_common_truthvalue_conversion
4639 (cond_loc
, default_conversion (cond
.value
));
4640 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
4641 exp1
= c_parser_expression_conv (parser
);
4642 c_inhibit_evaluation_warnings
+=
4643 ((cond
.value
== truthvalue_true_node
)
4644 - (cond
.value
== truthvalue_false_node
));
4647 colon_loc
= c_parser_peek_token (parser
)->location
;
4648 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4650 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4651 ret
.value
= error_mark_node
;
4652 ret
.original_code
= ERROR_MARK
;
4653 ret
.original_type
= NULL
;
4657 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
4658 exp2
= c_parser_conditional_expression (parser
, NULL
);
4659 exp2
= default_function_array_conversion (exp2_loc
, exp2
);
4661 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4662 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
4663 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4664 exp1
.value
, exp1
.original_type
,
4665 exp2
.value
, exp2
.original_type
);
4666 ret
.original_code
= ERROR_MARK
;
4667 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4668 ret
.original_type
= NULL
;
4673 /* If both sides are enum type, the default conversion will have
4674 made the type of the result be an integer type. We want to
4675 remember the enum types we started with. */
4676 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4677 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4678 ret
.original_type
= ((t1
!= error_mark_node
4679 && t2
!= error_mark_node
4680 && (TYPE_MAIN_VARIANT (t1
)
4681 == TYPE_MAIN_VARIANT (t2
)))
4688 /* Parse a binary expression; that is, a logical-OR-expression (C90
4689 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4690 an Objective-C message expression which is the primary-expression
4691 starting the expression as an initializer.
4693 multiplicative-expression:
4695 multiplicative-expression * cast-expression
4696 multiplicative-expression / cast-expression
4697 multiplicative-expression % cast-expression
4699 additive-expression:
4700 multiplicative-expression
4701 additive-expression + multiplicative-expression
4702 additive-expression - multiplicative-expression
4706 shift-expression << additive-expression
4707 shift-expression >> additive-expression
4709 relational-expression:
4711 relational-expression < shift-expression
4712 relational-expression > shift-expression
4713 relational-expression <= shift-expression
4714 relational-expression >= shift-expression
4716 equality-expression:
4717 relational-expression
4718 equality-expression == relational-expression
4719 equality-expression != relational-expression
4723 AND-expression & equality-expression
4725 exclusive-OR-expression:
4727 exclusive-OR-expression ^ AND-expression
4729 inclusive-OR-expression:
4730 exclusive-OR-expression
4731 inclusive-OR-expression | exclusive-OR-expression
4733 logical-AND-expression:
4734 inclusive-OR-expression
4735 logical-AND-expression && inclusive-OR-expression
4737 logical-OR-expression:
4738 logical-AND-expression
4739 logical-OR-expression || logical-AND-expression
4742 static struct c_expr
4743 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4745 /* A binary expression is parsed using operator-precedence parsing,
4746 with the operands being cast expressions. All the binary
4747 operators are left-associative. Thus a binary expression is of
4750 E0 op1 E1 op2 E2 ...
4752 which we represent on a stack. On the stack, the precedence
4753 levels are strictly increasing. When a new operator is
4754 encountered of higher precedence than that at the top of the
4755 stack, it is pushed; its LHS is the top expression, and its RHS
4756 is everything parsed until it is popped. When a new operator is
4757 encountered with precedence less than or equal to that at the top
4758 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4759 by the result of the operation until the operator at the top of
4760 the stack has lower precedence than the new operator or there is
4761 only one element on the stack; then the top expression is the LHS
4762 of the new operator. In the case of logical AND and OR
4763 expressions, we also need to adjust c_inhibit_evaluation_warnings
4764 as appropriate when the operators are pushed and popped. */
4766 /* The precedence levels, where 0 is a dummy lowest level used for
4767 the bottom of the stack. */
4783 /* The expression at this stack level. */
4785 /* The precedence of the operator on its left, PREC_NONE at the
4786 bottom of the stack. */
4788 /* The operation on its left. */
4790 /* The source location of this operation. */
4794 /* Location of the binary operator. */
4795 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4798 switch (stack[sp].op) \
4800 case TRUTH_ANDIF_EXPR: \
4801 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4802 == truthvalue_false_node); \
4804 case TRUTH_ORIF_EXPR: \
4805 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4806 == truthvalue_true_node); \
4811 stack[sp - 1].expr \
4812 = default_function_array_conversion (stack[sp - 1].loc, \
4813 stack[sp - 1].expr); \
4815 = default_function_array_conversion (stack[sp].loc, stack[sp].expr); \
4816 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4818 stack[sp - 1].expr, \
4822 gcc_assert (!after
|| c_dialect_objc ());
4823 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4824 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4825 stack
[0].prec
= PREC_NONE
;
4830 enum tree_code ocode
;
4833 switch (c_parser_peek_token (parser
)->type
)
4841 ocode
= TRUNC_DIV_EXPR
;
4845 ocode
= TRUNC_MOD_EXPR
;
4857 ocode
= LSHIFT_EXPR
;
4861 ocode
= RSHIFT_EXPR
;
4875 case CPP_GREATER_EQ
:
4888 oprec
= PREC_BITAND
;
4889 ocode
= BIT_AND_EXPR
;
4892 oprec
= PREC_BITXOR
;
4893 ocode
= BIT_XOR_EXPR
;
4897 ocode
= BIT_IOR_EXPR
;
4900 oprec
= PREC_LOGAND
;
4901 ocode
= TRUTH_ANDIF_EXPR
;
4905 ocode
= TRUTH_ORIF_EXPR
;
4908 /* Not a binary operator, so end of the binary
4912 binary_loc
= c_parser_peek_token (parser
)->location
;
4913 c_parser_consume_token (parser
);
4914 while (oprec
<= stack
[sp
].prec
)
4918 case TRUTH_ANDIF_EXPR
:
4920 = default_function_array_conversion (stack
[sp
].loc
,
4922 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4923 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4924 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4925 == truthvalue_false_node
);
4927 case TRUTH_ORIF_EXPR
:
4929 = default_function_array_conversion (stack
[sp
].loc
,
4931 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4932 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4933 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4934 == truthvalue_true_node
);
4940 stack
[sp
].loc
= binary_loc
;
4941 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4942 stack
[sp
].prec
= oprec
;
4943 stack
[sp
].op
= ocode
;
4944 stack
[sp
].loc
= binary_loc
;
4949 return stack
[0].expr
;
4953 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4954 NULL then it is an Objective-C message expression which is the
4955 primary-expression starting the expression as an initializer.
4959 ( type-name ) unary-expression
4962 static struct c_expr
4963 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4965 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
4966 gcc_assert (!after
|| c_dialect_objc ());
4968 return c_parser_postfix_expression_after_primary (parser
,
4970 /* If the expression begins with a parenthesized type name, it may
4971 be either a cast or a compound literal; we need to see whether
4972 the next character is '{' to tell the difference. If not, it is
4973 an unary expression. */
4974 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4975 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4977 struct c_type_name
*type_name
;
4980 c_parser_consume_token (parser
);
4981 type_name
= c_parser_type_name (parser
);
4982 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4983 if (type_name
== NULL
)
4985 ret
.value
= error_mark_node
;
4986 ret
.original_code
= ERROR_MARK
;
4987 ret
.original_type
= NULL
;
4991 /* Save casted types in the function's used types hash table. */
4992 used_types_insert (type_name
->specs
->type
);
4994 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4995 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
4998 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
4999 expr
= c_parser_cast_expression (parser
, NULL
);
5000 expr
= default_function_array_conversion (expr_loc
, expr
);
5002 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5003 ret
.original_code
= ERROR_MARK
;
5004 ret
.original_type
= NULL
;
5008 return c_parser_unary_expression (parser
);
5011 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5017 unary-operator cast-expression
5018 sizeof unary-expression
5019 sizeof ( type-name )
5021 unary-operator: one of
5027 __alignof__ unary-expression
5028 __alignof__ ( type-name )
5031 unary-operator: one of
5032 __extension__ __real__ __imag__
5034 In addition, the GNU syntax treats ++ and -- as unary operators, so
5035 they may be applied to cast expressions with errors for non-lvalues
5038 static struct c_expr
5039 c_parser_unary_expression (c_parser
*parser
)
5042 struct c_expr ret
, op
;
5043 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5045 ret
.original_code
= ERROR_MARK
;
5046 ret
.original_type
= NULL
;
5047 switch (c_parser_peek_token (parser
)->type
)
5050 c_parser_consume_token (parser
);
5051 exp_loc
= c_parser_peek_token (parser
)->location
;
5052 op
= c_parser_cast_expression (parser
, NULL
);
5053 op
= default_function_array_conversion (exp_loc
, op
);
5054 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5055 case CPP_MINUS_MINUS
:
5056 c_parser_consume_token (parser
);
5057 exp_loc
= c_parser_peek_token (parser
)->location
;
5058 op
= c_parser_cast_expression (parser
, NULL
);
5059 op
= default_function_array_conversion (exp_loc
, op
);
5060 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5062 c_parser_consume_token (parser
);
5063 return parser_build_unary_op (op_loc
, ADDR_EXPR
,
5064 c_parser_cast_expression (parser
, NULL
));
5066 c_parser_consume_token (parser
);
5067 exp_loc
= c_parser_peek_token (parser
)->location
;
5068 op
= c_parser_cast_expression (parser
, NULL
);
5069 op
= default_function_array_conversion (exp_loc
, op
);
5070 ret
.value
= build_indirect_ref (op_loc
, op
.value
, "unary *");
5073 if (!c_dialect_objc () && !in_system_header
)
5076 "traditional C rejects the unary plus operator");
5077 c_parser_consume_token (parser
);
5078 exp_loc
= c_parser_peek_token (parser
)->location
;
5079 op
= c_parser_cast_expression (parser
, NULL
);
5080 op
= default_function_array_conversion (exp_loc
, op
);
5081 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5083 c_parser_consume_token (parser
);
5084 exp_loc
= c_parser_peek_token (parser
)->location
;
5085 op
= c_parser_cast_expression (parser
, NULL
);
5086 op
= default_function_array_conversion (exp_loc
, op
);
5087 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5089 c_parser_consume_token (parser
);
5090 exp_loc
= c_parser_peek_token (parser
)->location
;
5091 op
= c_parser_cast_expression (parser
, NULL
);
5092 op
= default_function_array_conversion (exp_loc
, op
);
5093 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5095 c_parser_consume_token (parser
);
5096 exp_loc
= c_parser_peek_token (parser
)->location
;
5097 op
= c_parser_cast_expression (parser
, NULL
);
5098 op
= default_function_array_conversion (exp_loc
, op
);
5099 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5101 /* Refer to the address of a label as a pointer. */
5102 c_parser_consume_token (parser
);
5103 if (c_parser_next_token_is (parser
, CPP_NAME
))
5105 ret
.value
= finish_label_address_expr
5106 (c_parser_peek_token (parser
)->value
, op_loc
);
5107 c_parser_consume_token (parser
);
5111 c_parser_error (parser
, "expected identifier");
5112 ret
.value
= error_mark_node
;
5116 switch (c_parser_peek_token (parser
)->keyword
)
5119 return c_parser_sizeof_expression (parser
);
5121 return c_parser_alignof_expression (parser
);
5123 c_parser_consume_token (parser
);
5124 ext
= disable_extension_diagnostics ();
5125 ret
= c_parser_cast_expression (parser
, NULL
);
5126 restore_extension_diagnostics (ext
);
5129 c_parser_consume_token (parser
);
5130 exp_loc
= c_parser_peek_token (parser
)->location
;
5131 op
= c_parser_cast_expression (parser
, NULL
);
5132 op
= default_function_array_conversion (exp_loc
, op
);
5133 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5135 c_parser_consume_token (parser
);
5136 exp_loc
= c_parser_peek_token (parser
)->location
;
5137 op
= c_parser_cast_expression (parser
, NULL
);
5138 op
= default_function_array_conversion (exp_loc
, op
);
5139 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5141 return c_parser_postfix_expression (parser
);
5144 return c_parser_postfix_expression (parser
);
5148 /* Parse a sizeof expression. */
5150 static struct c_expr
5151 c_parser_sizeof_expression (c_parser
*parser
)
5154 location_t expr_loc
;
5155 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5156 c_parser_consume_token (parser
);
5157 c_inhibit_evaluation_warnings
++;
5159 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5160 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5162 /* Either sizeof ( type-name ) or sizeof unary-expression
5163 starting with a compound literal. */
5164 struct c_type_name
*type_name
;
5165 c_parser_consume_token (parser
);
5166 expr_loc
= c_parser_peek_token (parser
)->location
;
5167 type_name
= c_parser_type_name (parser
);
5168 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5169 if (type_name
== NULL
)
5172 c_inhibit_evaluation_warnings
--;
5174 ret
.value
= error_mark_node
;
5175 ret
.original_code
= ERROR_MARK
;
5176 ret
.original_type
= NULL
;
5179 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5181 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5186 /* sizeof ( type-name ). */
5187 c_inhibit_evaluation_warnings
--;
5189 return c_expr_sizeof_type (expr_loc
, type_name
);
5193 expr_loc
= c_parser_peek_token (parser
)->location
;
5194 expr
= c_parser_unary_expression (parser
);
5196 c_inhibit_evaluation_warnings
--;
5198 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5199 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5200 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5201 return c_expr_sizeof_expr (expr_loc
, expr
);
5205 /* Parse an alignof expression. */
5207 static struct c_expr
5208 c_parser_alignof_expression (c_parser
*parser
)
5211 location_t loc
= c_parser_peek_token (parser
)->location
;
5212 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5213 c_parser_consume_token (parser
);
5214 c_inhibit_evaluation_warnings
++;
5216 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5217 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5219 /* Either __alignof__ ( type-name ) or __alignof__
5220 unary-expression starting with a compound literal. */
5222 struct c_type_name
*type_name
;
5224 c_parser_consume_token (parser
);
5225 loc
= c_parser_peek_token (parser
)->location
;
5226 type_name
= c_parser_type_name (parser
);
5227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5228 if (type_name
== NULL
)
5231 c_inhibit_evaluation_warnings
--;
5233 ret
.value
= error_mark_node
;
5234 ret
.original_code
= ERROR_MARK
;
5235 ret
.original_type
= NULL
;
5238 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5240 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5245 /* alignof ( type-name ). */
5246 c_inhibit_evaluation_warnings
--;
5248 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5249 ret
.original_code
= ERROR_MARK
;
5250 ret
.original_type
= NULL
;
5256 expr
= c_parser_unary_expression (parser
);
5258 c_inhibit_evaluation_warnings
--;
5260 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5261 ret
.original_code
= ERROR_MARK
;
5262 ret
.original_type
= NULL
;
5267 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5271 postfix-expression [ expression ]
5272 postfix-expression ( argument-expression-list[opt] )
5273 postfix-expression . identifier
5274 postfix-expression -> identifier
5275 postfix-expression ++
5276 postfix-expression --
5277 ( type-name ) { initializer-list }
5278 ( type-name ) { initializer-list , }
5280 argument-expression-list:
5282 argument-expression-list , argument-expression
5294 (treated as a keyword in GNU C)
5297 ( compound-statement )
5298 __builtin_va_arg ( assignment-expression , type-name )
5299 __builtin_offsetof ( type-name , offsetof-member-designator )
5300 __builtin_choose_expr ( assignment-expression ,
5301 assignment-expression ,
5302 assignment-expression )
5303 __builtin_types_compatible_p ( type-name , type-name )
5305 offsetof-member-designator:
5307 offsetof-member-designator . identifier
5308 offsetof-member-designator [ expression ]
5313 [ objc-receiver objc-message-args ]
5314 @selector ( objc-selector-arg )
5315 @protocol ( identifier )
5316 @encode ( type-name )
5320 static struct c_expr
5321 c_parser_postfix_expression (c_parser
*parser
)
5323 struct c_expr expr
, e1
, e2
, e3
;
5324 struct c_type_name
*t1
, *t2
;
5325 location_t loc
= c_parser_peek_token (parser
)->location
;;
5326 expr
.original_code
= ERROR_MARK
;
5327 expr
.original_type
= NULL
;
5328 switch (c_parser_peek_token (parser
)->type
)
5331 expr
.value
= c_parser_peek_token (parser
)->value
;
5332 loc
= c_parser_peek_token (parser
)->location
;
5333 c_parser_consume_token (parser
);
5334 if (TREE_CODE (expr
.value
) == FIXED_CST
5335 && !targetm
.fixed_point_supported_p ())
5337 error_at (loc
, "fixed-point types not supported for this target");
5338 expr
.value
= error_mark_node
;
5345 expr
.value
= c_parser_peek_token (parser
)->value
;
5346 c_parser_consume_token (parser
);
5352 expr
.value
= c_parser_peek_token (parser
)->value
;
5353 expr
.original_code
= STRING_CST
;
5354 c_parser_consume_token (parser
);
5356 case CPP_OBJC_STRING
:
5357 gcc_assert (c_dialect_objc ());
5359 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5360 c_parser_consume_token (parser
);
5363 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5365 c_parser_error (parser
, "expected expression");
5366 expr
.value
= error_mark_node
;
5370 tree id
= c_parser_peek_token (parser
)->value
;
5371 c_parser_consume_token (parser
);
5372 expr
.value
= build_external_ref (loc
, id
,
5373 (c_parser_peek_token (parser
)->type
5375 &expr
.original_type
);
5378 case CPP_OPEN_PAREN
:
5379 /* A parenthesized expression, statement expression or compound
5381 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5383 /* A statement expression. */
5385 location_t brace_loc
;
5386 c_parser_consume_token (parser
);
5387 brace_loc
= c_parser_peek_token (parser
)->location
;
5388 c_parser_consume_token (parser
);
5389 if (cur_stmt_list
== NULL
)
5391 error_at (loc
, "braced-group within expression allowed "
5392 "only inside a function");
5393 parser
->error
= true;
5394 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5396 expr
.value
= error_mark_node
;
5399 stmt
= c_begin_stmt_expr ();
5400 c_parser_compound_statement_nostart (parser
);
5401 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5403 pedwarn (loc
, OPT_pedantic
,
5404 "ISO C forbids braced-groups within expressions");
5405 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5407 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5409 /* A compound literal. ??? Can we actually get here rather
5410 than going directly to
5411 c_parser_postfix_expression_after_paren_type from
5414 struct c_type_name
*type_name
;
5415 c_parser_consume_token (parser
);
5416 loc
= c_parser_peek_token (parser
)->location
;
5417 type_name
= c_parser_type_name (parser
);
5418 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5420 if (type_name
== NULL
)
5422 expr
.value
= error_mark_node
;
5425 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5431 /* A parenthesized expression. */
5432 c_parser_consume_token (parser
);
5433 expr
= c_parser_expression (parser
);
5434 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5435 TREE_NO_WARNING (expr
.value
) = 1;
5436 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5437 expr
.original_code
= ERROR_MARK
;
5438 /* Don't change EXPR.ORIGINAL_TYPE. */
5439 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5444 switch (c_parser_peek_token (parser
)->keyword
)
5446 case RID_FUNCTION_NAME
:
5447 case RID_PRETTY_FUNCTION_NAME
:
5448 case RID_C99_FUNCTION_NAME
:
5449 expr
.value
= fname_decl (loc
,
5450 c_parser_peek_token (parser
)->keyword
,
5451 c_parser_peek_token (parser
)->value
);
5452 c_parser_consume_token (parser
);
5455 c_parser_consume_token (parser
);
5456 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5458 expr
.value
= error_mark_node
;
5461 e1
= c_parser_expr_no_commas (parser
, NULL
);
5462 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5463 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5465 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5466 expr
.value
= error_mark_node
;
5469 loc
= c_parser_peek_token (parser
)->location
;
5470 t1
= c_parser_type_name (parser
);
5471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5475 expr
.value
= error_mark_node
;
5479 tree type_expr
= NULL_TREE
;
5480 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5481 groktypename (t1
, &type_expr
, NULL
));
5484 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5485 TREE_TYPE (expr
.value
), type_expr
,
5487 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5492 c_parser_consume_token (parser
);
5493 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5495 expr
.value
= error_mark_node
;
5498 t1
= c_parser_type_name (parser
);
5501 expr
.value
= error_mark_node
;
5504 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5507 expr
.value
= error_mark_node
;
5511 tree type
= groktypename (t1
, NULL
, NULL
);
5513 if (type
== error_mark_node
)
5514 offsetof_ref
= error_mark_node
;
5517 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5518 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5520 /* Parse the second argument to __builtin_offsetof. We
5521 must have one identifier, and beyond that we want to
5522 accept sub structure and sub array references. */
5523 if (c_parser_next_token_is (parser
, CPP_NAME
))
5525 offsetof_ref
= build_component_ref
5526 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5527 c_parser_consume_token (parser
);
5528 while (c_parser_next_token_is (parser
, CPP_DOT
)
5529 || c_parser_next_token_is (parser
,
5531 || c_parser_next_token_is (parser
,
5534 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5536 loc
= c_parser_peek_token (parser
)->location
;
5537 offsetof_ref
= build_array_ref (loc
,
5542 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5545 c_parser_consume_token (parser
);
5546 if (c_parser_next_token_is_not (parser
,
5549 c_parser_error (parser
, "expected identifier");
5552 offsetof_ref
= build_component_ref
5554 c_parser_peek_token (parser
)->value
);
5555 c_parser_consume_token (parser
);
5560 loc
= c_parser_peek_token (parser
)->location
;
5561 c_parser_consume_token (parser
);
5562 idx
= c_parser_expression (parser
).value
;
5563 idx
= c_fully_fold (idx
, false, NULL
);
5564 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5566 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5571 c_parser_error (parser
, "expected identifier");
5572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5574 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5577 case RID_CHOOSE_EXPR
:
5578 c_parser_consume_token (parser
);
5579 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5581 expr
.value
= error_mark_node
;
5584 loc
= c_parser_peek_token (parser
)->location
;
5585 e1
= c_parser_expr_no_commas (parser
, NULL
);
5586 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5589 expr
.value
= error_mark_node
;
5592 e2
= c_parser_expr_no_commas (parser
, NULL
);
5593 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5595 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5596 expr
.value
= error_mark_node
;
5599 e3
= c_parser_expr_no_commas (parser
, NULL
);
5600 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5606 if (TREE_CODE (c
) != INTEGER_CST
5607 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5609 "first argument to %<__builtin_choose_expr%> not"
5611 constant_expression_warning (c
);
5612 expr
= integer_zerop (c
) ? e3
: e2
;
5615 case RID_TYPES_COMPATIBLE_P
:
5616 c_parser_consume_token (parser
);
5617 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5619 expr
.value
= error_mark_node
;
5622 t1
= c_parser_type_name (parser
);
5625 expr
.value
= error_mark_node
;
5628 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5631 expr
.value
= error_mark_node
;
5634 t2
= c_parser_type_name (parser
);
5637 expr
.value
= error_mark_node
;
5640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5645 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5646 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5648 expr
.value
= comptypes (e1
, e2
)
5649 ? build_int_cst (NULL_TREE
, 1)
5650 : build_int_cst (NULL_TREE
, 0);
5653 case RID_AT_SELECTOR
:
5654 gcc_assert (c_dialect_objc ());
5655 c_parser_consume_token (parser
);
5656 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5658 expr
.value
= error_mark_node
;
5662 tree sel
= c_parser_objc_selector_arg (parser
);
5663 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5665 expr
.value
= objc_build_selector_expr (loc
, sel
);
5668 case RID_AT_PROTOCOL
:
5669 gcc_assert (c_dialect_objc ());
5670 c_parser_consume_token (parser
);
5671 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5673 expr
.value
= error_mark_node
;
5676 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5678 c_parser_error (parser
, "expected identifier");
5679 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5680 expr
.value
= error_mark_node
;
5684 tree id
= c_parser_peek_token (parser
)->value
;
5685 c_parser_consume_token (parser
);
5686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5688 expr
.value
= objc_build_protocol_expr (id
);
5692 /* Extension to support C-structures in the archiver. */
5693 gcc_assert (c_dialect_objc ());
5694 c_parser_consume_token (parser
);
5695 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5697 expr
.value
= error_mark_node
;
5700 t1
= c_parser_type_name (parser
);
5703 expr
.value
= error_mark_node
;
5704 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5710 tree type
= groktypename (t1
, NULL
, NULL
);
5711 expr
.value
= objc_build_encode_expr (type
);
5715 c_parser_error (parser
, "expected expression");
5716 expr
.value
= error_mark_node
;
5720 case CPP_OPEN_SQUARE
:
5721 if (c_dialect_objc ())
5723 tree receiver
, args
;
5724 c_parser_consume_token (parser
);
5725 receiver
= c_parser_objc_receiver (parser
);
5726 args
= c_parser_objc_message_args (parser
);
5727 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5729 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5733 /* Else fall through to report error. */
5735 c_parser_error (parser
, "expected expression");
5736 expr
.value
= error_mark_node
;
5739 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
5742 /* Parse a postfix expression after a parenthesized type name: the
5743 brace-enclosed initializer of a compound literal, possibly followed
5744 by some postfix operators. This is separate because it is not
5745 possible to tell until after the type name whether a cast
5746 expression has a cast or a compound literal, or whether the operand
5747 of sizeof is a parenthesized type name or starts with a compound
5748 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5749 location of the first token after the parentheses around the type
5752 static struct c_expr
5753 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5754 struct c_type_name
*type_name
,
5755 location_t type_loc
)
5761 location_t start_loc
;
5762 tree type_expr
= NULL_TREE
;
5763 bool type_expr_const
= true;
5764 check_compound_literal_type (type_loc
, type_name
);
5765 start_init (NULL_TREE
, NULL
, 0);
5766 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5767 start_loc
= c_parser_peek_token (parser
)->location
;
5768 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5770 error_at (type_loc
, "compound literal has variable size");
5771 type
= error_mark_node
;
5773 init
= c_parser_braced_init (parser
, type
, false);
5775 maybe_warn_string_init (type
, init
);
5778 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5779 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5780 ? CONSTRUCTOR_NON_CONST (init
.value
)
5781 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5782 non_const
|= !type_expr_const
;
5783 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
5784 expr
.original_code
= ERROR_MARK
;
5785 expr
.original_type
= NULL
;
5788 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5790 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5791 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5795 gcc_assert (!non_const
);
5796 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5797 type_expr
, expr
.value
);
5800 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
5803 /* Parse a postfix expression after the initial primary or compound
5804 literal; that is, parse a series of postfix operators.
5806 EXPR_LOC is the location of the primary expression. */
5808 static struct c_expr
5809 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5810 location_t expr_loc
,
5813 struct c_expr orig_expr
;
5815 VEC(tree
,gc
) *exprlist
;
5816 VEC(tree
,gc
) *origtypes
;
5819 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5820 switch (c_parser_peek_token (parser
)->type
)
5822 case CPP_OPEN_SQUARE
:
5823 /* Array reference. */
5824 c_parser_consume_token (parser
);
5825 idx
= c_parser_expression (parser
).value
;
5826 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5828 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
5829 expr
.original_code
= ERROR_MARK
;
5830 expr
.original_type
= NULL
;
5832 case CPP_OPEN_PAREN
:
5833 /* Function call. */
5834 c_parser_consume_token (parser
);
5835 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5838 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5839 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5842 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5843 "(" after the FUNCNAME, which is what we have now. */
5844 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
5846 expr
.original_code
= ERROR_MARK
;
5847 if (TREE_CODE (expr
.value
) == INTEGER_CST
5848 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5849 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5850 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5851 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5852 expr
.original_type
= NULL
;
5853 if (exprlist
!= NULL
)
5855 release_tree_vector (exprlist
);
5856 release_tree_vector (origtypes
);
5860 /* Structure element reference. */
5861 c_parser_consume_token (parser
);
5862 expr
= default_function_array_conversion (expr_loc
, expr
);
5863 if (c_parser_next_token_is (parser
, CPP_NAME
))
5864 ident
= c_parser_peek_token (parser
)->value
;
5867 c_parser_error (parser
, "expected identifier");
5868 expr
.value
= error_mark_node
;
5869 expr
.original_code
= ERROR_MARK
;
5870 expr
.original_type
= NULL
;
5873 c_parser_consume_token (parser
);
5874 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
5875 expr
.original_code
= ERROR_MARK
;
5876 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5877 expr
.original_type
= NULL
;
5880 /* Remember the original type of a bitfield. */
5881 tree field
= TREE_OPERAND (expr
.value
, 1);
5882 if (TREE_CODE (field
) != FIELD_DECL
)
5883 expr
.original_type
= NULL
;
5885 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5889 /* Structure element reference. */
5890 c_parser_consume_token (parser
);
5891 expr
= default_function_array_conversion (expr_loc
, expr
);
5892 if (c_parser_next_token_is (parser
, CPP_NAME
))
5893 ident
= c_parser_peek_token (parser
)->value
;
5896 c_parser_error (parser
, "expected identifier");
5897 expr
.value
= error_mark_node
;
5898 expr
.original_code
= ERROR_MARK
;
5899 expr
.original_type
= NULL
;
5902 c_parser_consume_token (parser
);
5903 expr
.value
= build_component_ref (op_loc
,
5904 build_indirect_ref (op_loc
,
5908 expr
.original_code
= ERROR_MARK
;
5909 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5910 expr
.original_type
= NULL
;
5913 /* Remember the original type of a bitfield. */
5914 tree field
= TREE_OPERAND (expr
.value
, 1);
5915 if (TREE_CODE (field
) != FIELD_DECL
)
5916 expr
.original_type
= NULL
;
5918 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5922 /* Postincrement. */
5923 c_parser_consume_token (parser
);
5924 expr
= default_function_array_conversion (expr_loc
, expr
);
5925 expr
.value
= build_unary_op (op_loc
,
5926 POSTINCREMENT_EXPR
, expr
.value
, 0);
5927 expr
.original_code
= ERROR_MARK
;
5928 expr
.original_type
= NULL
;
5930 case CPP_MINUS_MINUS
:
5931 /* Postdecrement. */
5932 c_parser_consume_token (parser
);
5933 expr
= default_function_array_conversion (expr_loc
, expr
);
5934 expr
.value
= build_unary_op (op_loc
,
5935 POSTDECREMENT_EXPR
, expr
.value
, 0);
5936 expr
.original_code
= ERROR_MARK
;
5937 expr
.original_type
= NULL
;
5945 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5948 assignment-expression
5949 expression , assignment-expression
5952 static struct c_expr
5953 c_parser_expression (c_parser
*parser
)
5956 expr
= c_parser_expr_no_commas (parser
, NULL
);
5957 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5960 location_t loc
= c_parser_peek_token (parser
)->location
;
5961 location_t expr_loc
;
5962 c_parser_consume_token (parser
);
5963 expr_loc
= c_parser_peek_token (parser
)->location
;
5964 next
= c_parser_expr_no_commas (parser
, NULL
);
5965 next
= default_function_array_conversion (expr_loc
, next
);
5966 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
5967 expr
.original_code
= COMPOUND_EXPR
;
5968 expr
.original_type
= next
.original_type
;
5973 /* Parse an expression and convert functions or arrays to
5976 static struct c_expr
5977 c_parser_expression_conv (c_parser
*parser
)
5980 location_t loc
= c_parser_peek_token (parser
)->location
;
5981 expr
= c_parser_expression (parser
);
5982 expr
= default_function_array_conversion (loc
, expr
);
5986 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5987 functions and arrays to pointers. If FOLD_P, fold the expressions.
5990 assignment-expression
5991 nonempty-expr-list , assignment-expression
5994 static VEC(tree
,gc
) *
5995 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5996 VEC(tree
,gc
) **p_orig_types
)
5999 VEC(tree
,gc
) *orig_types
;
6001 location_t loc
= c_parser_peek_token (parser
)->location
;
6003 ret
= make_tree_vector ();
6004 if (p_orig_types
== NULL
)
6007 orig_types
= make_tree_vector ();
6009 expr
= c_parser_expr_no_commas (parser
, NULL
);
6011 expr
= default_function_array_conversion (loc
, expr
);
6013 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6014 VEC_quick_push (tree
, ret
, expr
.value
);
6015 if (orig_types
!= NULL
)
6016 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6017 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6019 c_parser_consume_token (parser
);
6020 loc
= c_parser_peek_token (parser
)->location
;
6021 expr
= c_parser_expr_no_commas (parser
, NULL
);
6023 expr
= default_function_array_conversion (loc
, expr
);
6025 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6026 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6027 if (orig_types
!= NULL
)
6028 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6030 if (orig_types
!= NULL
)
6031 *p_orig_types
= orig_types
;
6035 /* Parse Objective-C-specific constructs. */
6037 /* Parse an objc-class-definition.
6039 objc-class-definition:
6040 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6041 objc-class-instance-variables[opt] objc-methodprotolist @end
6042 @implementation identifier objc-superclass[opt]
6043 objc-class-instance-variables[opt]
6044 @interface identifier ( identifier ) objc-protocol-refs[opt]
6045 objc-methodprotolist @end
6046 @implementation identifier ( identifier )
6051 "@interface identifier (" must start "@interface identifier (
6052 identifier ) ...": objc-methodprotolist in the first production may
6053 not start with a parenthesized identifier as a declarator of a data
6054 definition with no declaration specifiers if the objc-superclass,
6055 objc-protocol-refs and objc-class-instance-variables are omitted. */
6058 c_parser_objc_class_definition (c_parser
*parser
)
6063 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6065 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6069 c_parser_consume_token (parser
);
6070 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6072 c_parser_error (parser
, "expected identifier");
6075 id1
= c_parser_peek_token (parser
)->value
;
6076 c_parser_consume_token (parser
);
6077 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6080 tree proto
= NULL_TREE
;
6081 c_parser_consume_token (parser
);
6082 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6084 c_parser_error (parser
, "expected identifier");
6085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6088 id2
= c_parser_peek_token (parser
)->value
;
6089 c_parser_consume_token (parser
);
6090 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6093 objc_start_category_implementation (id1
, id2
);
6096 if (c_parser_next_token_is (parser
, CPP_LESS
))
6097 proto
= c_parser_objc_protocol_refs (parser
);
6098 objc_start_category_interface (id1
, id2
, proto
);
6099 c_parser_objc_methodprotolist (parser
);
6100 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6101 objc_finish_interface ();
6104 if (c_parser_next_token_is (parser
, CPP_COLON
))
6106 c_parser_consume_token (parser
);
6107 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6109 c_parser_error (parser
, "expected identifier");
6112 superclass
= c_parser_peek_token (parser
)->value
;
6113 c_parser_consume_token (parser
);
6116 superclass
= NULL_TREE
;
6119 tree proto
= NULL_TREE
;
6120 if (c_parser_next_token_is (parser
, CPP_LESS
))
6121 proto
= c_parser_objc_protocol_refs (parser
);
6122 objc_start_class_interface (id1
, superclass
, proto
);
6125 objc_start_class_implementation (id1
, superclass
);
6126 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6127 c_parser_objc_class_instance_variables (parser
);
6130 objc_continue_interface ();
6131 c_parser_objc_methodprotolist (parser
);
6132 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6133 objc_finish_interface ();
6137 objc_continue_implementation ();
6142 /* Parse objc-class-instance-variables.
6144 objc-class-instance-variables:
6145 { objc-instance-variable-decl-list[opt] }
6147 objc-instance-variable-decl-list:
6148 objc-visibility-spec
6149 objc-instance-variable-decl ;
6151 objc-instance-variable-decl-list objc-visibility-spec
6152 objc-instance-variable-decl-list objc-instance-variable-decl ;
6153 objc-instance-variable-decl-list ;
6155 objc-visibility-spec:
6160 objc-instance-variable-decl:
6165 c_parser_objc_class_instance_variables (c_parser
*parser
)
6167 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6168 c_parser_consume_token (parser
);
6169 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6172 /* Parse any stray semicolon. */
6173 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6175 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6176 "extra semicolon in struct or union specified");
6177 c_parser_consume_token (parser
);
6180 /* Stop if at the end of the instance variables. */
6181 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6183 c_parser_consume_token (parser
);
6186 /* Parse any objc-visibility-spec. */
6187 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6189 c_parser_consume_token (parser
);
6190 objc_set_visibility (2);
6193 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6195 c_parser_consume_token (parser
);
6196 objc_set_visibility (0);
6199 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6201 c_parser_consume_token (parser
);
6202 objc_set_visibility (1);
6205 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6207 c_parser_pragma (parser
, pragma_external
);
6211 /* Parse some comma-separated declarations. */
6212 decls
= c_parser_struct_declaration (parser
);
6214 /* Comma-separated instance variables are chained together in
6215 reverse order; add them one by one. */
6216 tree ivar
= nreverse (decls
);
6217 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6218 objc_add_instance_variable (copy_node (ivar
));
6220 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6224 /* Parse an objc-class-declaration.
6226 objc-class-declaration:
6227 @class identifier-list ;
6231 c_parser_objc_class_declaration (c_parser
*parser
)
6233 tree list
= NULL_TREE
;
6234 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6235 c_parser_consume_token (parser
);
6236 /* Any identifiers, including those declared as type names, are OK
6241 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6243 c_parser_error (parser
, "expected identifier");
6246 id
= c_parser_peek_token (parser
)->value
;
6247 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6248 c_parser_consume_token (parser
);
6249 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6250 c_parser_consume_token (parser
);
6254 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6255 objc_declare_class (list
);
6258 /* Parse an objc-alias-declaration.
6260 objc-alias-declaration:
6261 @compatibility_alias identifier identifier ;
6265 c_parser_objc_alias_declaration (c_parser
*parser
)
6268 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6269 c_parser_consume_token (parser
);
6270 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6272 c_parser_error (parser
, "expected identifier");
6273 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6276 id1
= c_parser_peek_token (parser
)->value
;
6277 c_parser_consume_token (parser
);
6278 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6280 c_parser_error (parser
, "expected identifier");
6281 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6284 id2
= c_parser_peek_token (parser
)->value
;
6285 c_parser_consume_token (parser
);
6286 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6287 objc_declare_alias (id1
, id2
);
6290 /* Parse an objc-protocol-definition.
6292 objc-protocol-definition:
6293 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6294 @protocol identifier-list ;
6296 "@protocol identifier ;" should be resolved as "@protocol
6297 identifier-list ;": objc-methodprotolist may not start with a
6298 semicolon in the first alternative if objc-protocol-refs are
6302 c_parser_objc_protocol_definition (c_parser
*parser
)
6304 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6305 c_parser_consume_token (parser
);
6306 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6308 c_parser_error (parser
, "expected identifier");
6311 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6312 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6314 tree list
= NULL_TREE
;
6315 /* Any identifiers, including those declared as type names, are
6320 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6322 c_parser_error (parser
, "expected identifier");
6325 id
= c_parser_peek_token (parser
)->value
;
6326 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6327 c_parser_consume_token (parser
);
6328 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6329 c_parser_consume_token (parser
);
6333 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6334 objc_declare_protocols (list
);
6338 tree id
= c_parser_peek_token (parser
)->value
;
6339 tree proto
= NULL_TREE
;
6340 c_parser_consume_token (parser
);
6341 if (c_parser_next_token_is (parser
, CPP_LESS
))
6342 proto
= c_parser_objc_protocol_refs (parser
);
6343 parser
->objc_pq_context
= true;
6344 objc_start_protocol (id
, proto
);
6345 c_parser_objc_methodprotolist (parser
);
6346 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6347 parser
->objc_pq_context
= false;
6348 objc_finish_interface ();
6352 /* Parse an objc-method-type.
6359 static enum tree_code
6360 c_parser_objc_method_type (c_parser
*parser
)
6362 switch (c_parser_peek_token (parser
)->type
)
6365 c_parser_consume_token (parser
);
6368 c_parser_consume_token (parser
);
6375 /* Parse an objc-method-definition.
6377 objc-method-definition:
6378 objc-method-type objc-method-decl ;[opt] compound-statement
6382 c_parser_objc_method_definition (c_parser
*parser
)
6384 enum tree_code type
= c_parser_objc_method_type (parser
);
6386 objc_set_method_type (type
);
6387 parser
->objc_pq_context
= true;
6388 decl
= c_parser_objc_method_decl (parser
);
6389 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6391 c_parser_consume_token (parser
);
6392 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6393 "extra semicolon in method definition specified");
6395 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6397 c_parser_error (parser
, "expected %<{%>");
6400 parser
->objc_pq_context
= false;
6401 objc_start_method_definition (decl
);
6402 add_stmt (c_parser_compound_statement (parser
));
6403 objc_finish_method_definition (current_function_decl
);
6406 /* Parse an objc-methodprotolist.
6408 objc-methodprotolist:
6410 objc-methodprotolist objc-methodproto
6411 objc-methodprotolist declaration
6412 objc-methodprotolist ;
6414 The declaration is a data definition, which may be missing
6415 declaration specifiers under the same rules and diagnostics as
6416 other data definitions outside functions, and the stray semicolon
6417 is diagnosed the same way as a stray semicolon outside a
6421 c_parser_objc_methodprotolist (c_parser
*parser
)
6425 /* The list is terminated by @end. */
6426 switch (c_parser_peek_token (parser
)->type
)
6429 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6430 "ISO C does not allow extra %<;%> outside of a function");
6431 c_parser_consume_token (parser
);
6435 c_parser_objc_methodproto (parser
);
6438 c_parser_pragma (parser
, pragma_external
);
6443 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6445 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6451 /* Parse an objc-methodproto.
6454 objc-method-type objc-method-decl ;
6458 c_parser_objc_methodproto (c_parser
*parser
)
6460 enum tree_code type
= c_parser_objc_method_type (parser
);
6462 objc_set_method_type (type
);
6463 /* Remember protocol qualifiers in prototypes. */
6464 parser
->objc_pq_context
= true;
6465 decl
= c_parser_objc_method_decl (parser
);
6466 /* Forget protocol qualifiers here. */
6467 parser
->objc_pq_context
= false;
6468 objc_add_method_declaration (decl
);
6469 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6472 /* Parse an objc-method-decl.
6475 ( objc-type-name ) objc-selector
6477 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6478 objc-keyword-selector objc-optparmlist
6480 objc-keyword-selector:
6482 objc-keyword-selector objc-keyword-decl
6485 objc-selector : ( objc-type-name ) identifier
6486 objc-selector : identifier
6487 : ( objc-type-name ) identifier
6491 objc-optparms objc-optellipsis
6495 objc-opt-parms , parameter-declaration
6503 c_parser_objc_method_decl (c_parser
*parser
)
6505 tree type
= NULL_TREE
;
6507 tree parms
= NULL_TREE
;
6508 bool ellipsis
= false;
6510 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6512 c_parser_consume_token (parser
);
6513 type
= c_parser_objc_type_name (parser
);
6514 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6516 sel
= c_parser_objc_selector (parser
);
6517 /* If there is no selector, or a colon follows, we have an
6518 objc-keyword-selector. If there is a selector, and a colon does
6519 not follow, that selector ends the objc-method-decl. */
6520 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6523 tree list
= NULL_TREE
;
6526 tree atype
= NULL_TREE
, id
, keyworddecl
;
6527 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6529 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6531 c_parser_consume_token (parser
);
6532 atype
= c_parser_objc_type_name (parser
);
6533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6536 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6538 c_parser_error (parser
, "expected identifier");
6539 return error_mark_node
;
6541 id
= c_parser_peek_token (parser
)->value
;
6542 c_parser_consume_token (parser
);
6543 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6544 list
= chainon (list
, keyworddecl
);
6545 tsel
= c_parser_objc_selector (parser
);
6546 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6549 /* Parse the optional parameter list. Optional Objective-C
6550 method parameters follow the C syntax, and may include '...'
6551 to denote a variable number of arguments. */
6552 parms
= make_node (TREE_LIST
);
6553 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6555 struct c_parm
*parm
;
6556 c_parser_consume_token (parser
);
6557 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6560 c_parser_consume_token (parser
);
6563 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6566 parms
= chainon (parms
,
6567 build_tree_list (NULL_TREE
, grokparm (parm
)));
6571 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6574 /* Parse an objc-type-name.
6577 objc-type-qualifiers[opt] type-name
6578 objc-type-qualifiers[opt]
6580 objc-type-qualifiers:
6582 objc-type-qualifiers objc-type-qualifier
6584 objc-type-qualifier: one of
6585 in out inout bycopy byref oneway
6589 c_parser_objc_type_name (c_parser
*parser
)
6591 tree quals
= NULL_TREE
;
6592 struct c_type_name
*type_name
= NULL
;
6593 tree type
= NULL_TREE
;
6596 c_token
*token
= c_parser_peek_token (parser
);
6597 if (token
->type
== CPP_KEYWORD
6598 && (token
->keyword
== RID_IN
6599 || token
->keyword
== RID_OUT
6600 || token
->keyword
== RID_INOUT
6601 || token
->keyword
== RID_BYCOPY
6602 || token
->keyword
== RID_BYREF
6603 || token
->keyword
== RID_ONEWAY
))
6605 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6606 c_parser_consume_token (parser
);
6611 if (c_parser_next_token_starts_typename (parser
))
6612 type_name
= c_parser_type_name (parser
);
6614 type
= groktypename (type_name
, NULL
, NULL
);
6615 return build_tree_list (quals
, type
);
6618 /* Parse objc-protocol-refs.
6625 c_parser_objc_protocol_refs (c_parser
*parser
)
6627 tree list
= NULL_TREE
;
6628 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6629 c_parser_consume_token (parser
);
6630 /* Any identifiers, including those declared as type names, are OK
6635 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6637 c_parser_error (parser
, "expected identifier");
6640 id
= c_parser_peek_token (parser
)->value
;
6641 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6642 c_parser_consume_token (parser
);
6643 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6644 c_parser_consume_token (parser
);
6648 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6652 /* Parse an objc-try-catch-statement.
6654 objc-try-catch-statement:
6655 @try compound-statement objc-catch-list[opt]
6656 @try compound-statement objc-catch-list[opt] @finally compound-statement
6659 @catch ( parameter-declaration ) compound-statement
6660 objc-catch-list @catch ( parameter-declaration ) compound-statement
6664 c_parser_objc_try_catch_statement (c_parser
*parser
)
6668 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6669 c_parser_consume_token (parser
);
6670 loc
= c_parser_peek_token (parser
)->location
;
6671 stmt
= c_parser_compound_statement (parser
);
6672 objc_begin_try_stmt (loc
, stmt
);
6673 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6675 struct c_parm
*parm
;
6676 c_parser_consume_token (parser
);
6677 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6679 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6682 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6685 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6686 objc_begin_catch_clause (grokparm (parm
));
6687 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6688 c_parser_compound_statement_nostart (parser
);
6689 objc_finish_catch_clause ();
6691 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6695 c_parser_consume_token (parser
);
6696 finloc
= c_parser_peek_token (parser
)->location
;
6697 finstmt
= c_parser_compound_statement (parser
);
6698 objc_build_finally_clause (finloc
, finstmt
);
6700 objc_finish_try_stmt ();
6703 /* Parse an objc-synchronized-statement.
6705 objc-synchronized-statement:
6706 @synchronized ( expression ) compound-statement
6710 c_parser_objc_synchronized_statement (c_parser
*parser
)
6714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6715 c_parser_consume_token (parser
);
6716 loc
= c_parser_peek_token (parser
)->location
;
6717 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6719 expr
= c_parser_expression (parser
).value
;
6720 expr
= c_fully_fold (expr
, false, NULL
);
6721 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6724 expr
= error_mark_node
;
6725 stmt
= c_parser_compound_statement (parser
);
6726 objc_build_synchronized (loc
, expr
, stmt
);
6729 /* Parse an objc-selector; return NULL_TREE without an error if the
6730 next token is not an objc-selector.
6735 enum struct union if else while do for switch case default
6736 break continue return goto asm sizeof typeof __alignof
6737 unsigned long const short volatile signed restrict _Complex
6738 in out inout bycopy byref oneway int char float double void _Bool
6740 ??? Why this selection of keywords but not, for example, storage
6741 class specifiers? */
6744 c_parser_objc_selector (c_parser
*parser
)
6746 c_token
*token
= c_parser_peek_token (parser
);
6747 tree value
= token
->value
;
6748 if (token
->type
== CPP_NAME
)
6750 c_parser_consume_token (parser
);
6753 if (token
->type
!= CPP_KEYWORD
)
6755 switch (token
->keyword
)
6796 c_parser_consume_token (parser
);
6803 /* Parse an objc-selector-arg.
6807 objc-keywordname-list
6809 objc-keywordname-list:
6811 objc-keywordname-list objc-keywordname
6819 c_parser_objc_selector_arg (c_parser
*parser
)
6821 tree sel
= c_parser_objc_selector (parser
);
6822 tree list
= NULL_TREE
;
6823 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6827 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6829 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6830 sel
= c_parser_objc_selector (parser
);
6831 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6837 /* Parse an objc-receiver.
6846 c_parser_objc_receiver (c_parser
*parser
)
6848 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6849 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6850 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6852 tree id
= c_parser_peek_token (parser
)->value
;
6853 c_parser_consume_token (parser
);
6854 return objc_get_class_reference (id
);
6856 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6859 /* Parse objc-message-args.
6863 objc-keywordarg-list
6865 objc-keywordarg-list:
6867 objc-keywordarg-list objc-keywordarg
6870 objc-selector : objc-keywordexpr
6875 c_parser_objc_message_args (c_parser
*parser
)
6877 tree sel
= c_parser_objc_selector (parser
);
6878 tree list
= NULL_TREE
;
6879 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6884 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6885 return error_mark_node
;
6886 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6887 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6888 sel
= c_parser_objc_selector (parser
);
6889 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6895 /* Parse an objc-keywordexpr.
6902 c_parser_objc_keywordexpr (c_parser
*parser
)
6905 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6906 if (VEC_length (tree
, expr_list
) == 1)
6908 /* Just return the expression, remove a level of
6910 ret
= VEC_index (tree
, expr_list
, 0);
6914 /* We have a comma expression, we will collapse later. */
6915 ret
= build_tree_list_vec (expr_list
);
6917 release_tree_vector (expr_list
);
6922 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6923 should be considered, statements. ALLOW_STMT is true if we're within
6924 the context of a function and such pragmas are to be allowed. Returns
6925 true if we actually parsed such a pragma. */
6928 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6932 id
= c_parser_peek_token (parser
)->pragma_kind
;
6933 gcc_assert (id
!= PRAGMA_NONE
);
6937 case PRAGMA_OMP_BARRIER
:
6938 if (context
!= pragma_compound
)
6940 if (context
== pragma_stmt
)
6941 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6942 "used in compound statements");
6945 c_parser_omp_barrier (parser
);
6948 case PRAGMA_OMP_FLUSH
:
6949 if (context
!= pragma_compound
)
6951 if (context
== pragma_stmt
)
6952 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6953 "used in compound statements");
6956 c_parser_omp_flush (parser
);
6959 case PRAGMA_OMP_TASKWAIT
:
6960 if (context
!= pragma_compound
)
6962 if (context
== pragma_stmt
)
6963 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6964 "used in compound statements");
6967 c_parser_omp_taskwait (parser
);
6970 case PRAGMA_OMP_THREADPRIVATE
:
6971 c_parser_omp_threadprivate (parser
);
6974 case PRAGMA_OMP_SECTION
:
6975 error_at (c_parser_peek_token (parser
)->location
,
6976 "%<#pragma omp section%> may only be used in "
6977 "%<#pragma omp sections%> construct");
6978 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6981 case PRAGMA_GCC_PCH_PREPROCESS
:
6982 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6983 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6987 if (id
< PRAGMA_FIRST_EXTERNAL
)
6989 if (context
== pragma_external
)
6992 c_parser_error (parser
, "expected declaration specifiers");
6993 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6996 c_parser_omp_construct (parser
);
7002 c_parser_consume_pragma (parser
);
7003 c_invoke_pragma_handler (id
);
7005 /* Skip to EOL, but suppress any error message. Those will have been
7006 generated by the handler routine through calling error, as opposed
7007 to calling c_parser_error. */
7008 parser
->error
= true;
7009 c_parser_skip_to_pragma_eol (parser
);
7014 /* The interface the pragma parsers have to the lexer. */
7017 pragma_lex (tree
*value
)
7019 c_token
*tok
= c_parser_peek_token (the_parser
);
7020 enum cpp_ttype ret
= tok
->type
;
7022 *value
= tok
->value
;
7023 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7027 if (ret
== CPP_KEYWORD
)
7029 c_parser_consume_token (the_parser
);
7036 c_parser_pragma_pch_preprocess (c_parser
*parser
)
7040 c_parser_consume_pragma (parser
);
7041 if (c_parser_next_token_is (parser
, CPP_STRING
))
7043 name
= c_parser_peek_token (parser
)->value
;
7044 c_parser_consume_token (parser
);
7047 c_parser_error (parser
, "expected string literal");
7048 c_parser_skip_to_pragma_eol (parser
);
7051 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
7054 /* OpenMP 2.5 parsing routines. */
7056 /* Returns name of the next clause.
7057 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7058 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7059 returned and the token is consumed. */
7061 static pragma_omp_clause
7062 c_parser_omp_clause_name (c_parser
*parser
)
7064 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7066 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7067 result
= PRAGMA_OMP_CLAUSE_IF
;
7068 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7069 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7070 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7072 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7077 if (!strcmp ("collapse", p
))
7078 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7079 else if (!strcmp ("copyin", p
))
7080 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7081 else if (!strcmp ("copyprivate", p
))
7082 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7085 if (!strcmp ("firstprivate", p
))
7086 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7089 if (!strcmp ("lastprivate", p
))
7090 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7093 if (!strcmp ("nowait", p
))
7094 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7095 else if (!strcmp ("num_threads", p
))
7096 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7099 if (!strcmp ("ordered", p
))
7100 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7103 if (!strcmp ("private", p
))
7104 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7107 if (!strcmp ("reduction", p
))
7108 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7111 if (!strcmp ("schedule", p
))
7112 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7113 else if (!strcmp ("shared", p
))
7114 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7117 if (!strcmp ("untied", p
))
7118 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7123 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7124 c_parser_consume_token (parser
);
7129 /* Validate that a clause of the given type does not already exist. */
7132 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7137 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7138 if (OMP_CLAUSE_CODE (c
) == code
)
7140 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7141 error_at (loc
, "too many %qs clauses", name
);
7149 variable-list , identifier
7151 If KIND is nonzero, create the appropriate node and install the
7152 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7153 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7155 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7156 return the list created. */
7159 c_parser_omp_variable_list (c_parser
*parser
,
7160 location_t clause_loc
,
7161 enum omp_clause_code kind
,
7164 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7165 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7166 c_parser_error (parser
, "expected identifier");
7168 while (c_parser_next_token_is (parser
, CPP_NAME
)
7169 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7171 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7174 undeclared_variable (c_parser_peek_token (parser
)->location
,
7175 c_parser_peek_token (parser
)->value
);
7176 else if (t
== error_mark_node
)
7180 tree u
= build_omp_clause (clause_loc
, kind
);
7181 OMP_CLAUSE_DECL (u
) = t
;
7182 OMP_CLAUSE_CHAIN (u
) = list
;
7186 list
= tree_cons (t
, NULL_TREE
, list
);
7188 c_parser_consume_token (parser
);
7190 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7193 c_parser_consume_token (parser
);
7199 /* Similarly, but expect leading and trailing parenthesis. This is a very
7200 common case for omp clauses. */
7203 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7206 /* The clauses location. */
7207 location_t loc
= c_parser_peek_token (parser
)->location
;
7209 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7211 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7212 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7218 collapse ( constant-expression ) */
7221 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7223 tree c
, num
= error_mark_node
;
7227 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7229 loc
= c_parser_peek_token (parser
)->location
;
7230 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7232 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7233 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7235 if (num
== error_mark_node
)
7237 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7238 || !host_integerp (num
, 0)
7239 || (n
= tree_low_cst (num
, 0)) <= 0
7243 "collapse argument needs positive constant integer expression");
7246 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7247 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7248 OMP_CLAUSE_CHAIN (c
) = list
;
7253 copyin ( variable-list ) */
7256 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7258 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7262 copyprivate ( variable-list ) */
7265 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7267 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7271 default ( shared | none ) */
7274 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7276 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7277 location_t loc
= c_parser_peek_token (parser
)->location
;
7280 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7282 if (c_parser_next_token_is (parser
, CPP_NAME
))
7284 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7289 if (strcmp ("none", p
) != 0)
7291 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7295 if (strcmp ("shared", p
) != 0)
7297 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7304 c_parser_consume_token (parser
);
7309 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7313 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7316 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7317 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7318 OMP_CLAUSE_CHAIN (c
) = list
;
7319 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7325 firstprivate ( variable-list ) */
7328 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7330 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7334 if ( expression ) */
7337 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7339 location_t loc
= c_parser_peek_token (parser
)->location
;
7340 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7342 tree t
= c_parser_paren_condition (parser
);
7345 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7347 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7348 OMP_CLAUSE_IF_EXPR (c
) = t
;
7349 OMP_CLAUSE_CHAIN (c
) = list
;
7353 c_parser_error (parser
, "expected %<(%>");
7359 lastprivate ( variable-list ) */
7362 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7364 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7371 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7374 location_t loc
= c_parser_peek_token (parser
)->location
;
7376 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7378 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7379 OMP_CLAUSE_CHAIN (c
) = list
;
7384 num_threads ( expression ) */
7387 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7389 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7390 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7392 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7393 tree c
, t
= c_parser_expression (parser
).value
;
7394 t
= c_fully_fold (t
, false, NULL
);
7396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7398 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7400 c_parser_error (parser
, "expected integer expression");
7404 /* Attempt to statically determine when the number isn't positive. */
7405 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7406 build_int_cst (TREE_TYPE (t
), 0));
7407 if (CAN_HAVE_LOCATION_P (c
))
7408 SET_EXPR_LOCATION (c
, expr_loc
);
7409 if (c
== boolean_true_node
)
7411 warning_at (expr_loc
, 0,
7412 "%<num_threads%> value must be positive");
7413 t
= integer_one_node
;
7416 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7418 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7419 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7420 OMP_CLAUSE_CHAIN (c
) = list
;
7431 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7435 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7437 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7438 OMP_CLAUSE_ORDERED
);
7439 OMP_CLAUSE_CHAIN (c
) = list
;
7445 private ( variable-list ) */
7448 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7450 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7454 reduction ( reduction-operator : variable-list )
7457 One of: + * - & ^ | && || */
7460 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7462 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7463 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7465 enum tree_code code
;
7467 switch (c_parser_peek_token (parser
)->type
)
7479 code
= BIT_AND_EXPR
;
7482 code
= BIT_XOR_EXPR
;
7485 code
= BIT_IOR_EXPR
;
7488 code
= TRUTH_ANDIF_EXPR
;
7491 code
= TRUTH_ORIF_EXPR
;
7494 c_parser_error (parser
,
7495 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7496 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7500 c_parser_consume_token (parser
);
7501 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7505 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7506 OMP_CLAUSE_REDUCTION
, list
);
7507 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7508 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7512 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7518 schedule ( schedule-kind )
7519 schedule ( schedule-kind , expression )
7522 static | dynamic | guided | runtime | auto
7526 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7529 location_t loc
= c_parser_peek_token (parser
)->location
;
7531 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7534 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7536 if (c_parser_next_token_is (parser
, CPP_NAME
))
7538 tree kind
= c_parser_peek_token (parser
)->value
;
7539 const char *p
= IDENTIFIER_POINTER (kind
);
7544 if (strcmp ("dynamic", p
) != 0)
7546 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7550 if (strcmp ("guided", p
) != 0)
7552 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7556 if (strcmp ("runtime", p
) != 0)
7558 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7565 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7566 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7567 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7568 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7572 c_parser_consume_token (parser
);
7573 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7576 c_parser_consume_token (parser
);
7578 here
= c_parser_peek_token (parser
)->location
;
7579 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7580 t
= c_fully_fold (t
, false, NULL
);
7582 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7583 error_at (here
, "schedule %<runtime%> does not take "
7584 "a %<chunk_size%> parameter");
7585 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7587 "schedule %<auto%> does not take "
7588 "a %<chunk_size%> parameter");
7589 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7590 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7592 c_parser_error (parser
, "expected integer expression");
7594 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7597 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7598 "expected %<,%> or %<)%>");
7600 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7601 OMP_CLAUSE_CHAIN (c
) = list
;
7605 c_parser_error (parser
, "invalid schedule kind");
7606 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7611 shared ( variable-list ) */
7614 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7616 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7623 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7627 /* FIXME: Should we allow duplicates? */
7628 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7630 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7632 OMP_CLAUSE_CHAIN (c
) = list
;
7637 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7638 is a bitmask in MASK. Return the list of clauses found; the result
7639 of clause default goes in *pdefault. */
7642 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7645 tree clauses
= NULL
;
7648 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7651 pragma_omp_clause c_kind
;
7653 tree prev
= clauses
;
7655 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7656 c_parser_consume_token (parser
);
7659 here
= c_parser_peek_token (parser
)->location
;
7660 c_kind
= c_parser_omp_clause_name (parser
);
7664 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7665 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7666 c_name
= "collapse";
7668 case PRAGMA_OMP_CLAUSE_COPYIN
:
7669 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7672 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7673 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7674 c_name
= "copyprivate";
7676 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7677 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7680 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7681 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7682 c_name
= "firstprivate";
7684 case PRAGMA_OMP_CLAUSE_IF
:
7685 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7688 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7689 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7690 c_name
= "lastprivate";
7692 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7693 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7696 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7697 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7698 c_name
= "num_threads";
7700 case PRAGMA_OMP_CLAUSE_ORDERED
:
7701 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7704 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7705 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7708 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7709 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7710 c_name
= "reduction";
7712 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7713 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7714 c_name
= "schedule";
7716 case PRAGMA_OMP_CLAUSE_SHARED
:
7717 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7720 case PRAGMA_OMP_CLAUSE_UNTIED
:
7721 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7725 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7729 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7731 /* Remove the invalid clause(s) from the list to avoid
7732 confusing the rest of the compiler. */
7734 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7739 c_parser_skip_to_pragma_eol (parser
);
7741 return c_finish_omp_clauses (clauses
);
7748 In practice, we're also interested in adding the statement to an
7749 outer node. So it is convenient if we work around the fact that
7750 c_parser_statement calls add_stmt. */
7753 c_parser_omp_structured_block (c_parser
*parser
)
7755 tree stmt
= push_stmt_list ();
7756 c_parser_statement (parser
);
7757 return pop_stmt_list (stmt
);
7761 # pragma omp atomic new-line
7765 x binop= expr | x++ | ++x | x-- | --x
7767 +, *, -, /, &, ^, |, <<, >>
7769 where x is an lvalue expression with scalar type.
7771 LOC is the location of the #pragma token. */
7774 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
7778 enum tree_code code
;
7779 struct c_expr rhs_expr
;
7781 c_parser_skip_to_pragma_eol (parser
);
7783 lhs
= c_parser_unary_expression (parser
).value
;
7784 lhs
= c_fully_fold (lhs
, false, NULL
);
7785 switch (TREE_CODE (lhs
))
7789 c_parser_skip_to_end_of_block_or_statement (parser
);
7792 case PREINCREMENT_EXPR
:
7793 case POSTINCREMENT_EXPR
:
7794 lhs
= TREE_OPERAND (lhs
, 0);
7796 rhs
= integer_one_node
;
7799 case PREDECREMENT_EXPR
:
7800 case POSTDECREMENT_EXPR
:
7801 lhs
= TREE_OPERAND (lhs
, 0);
7803 rhs
= integer_one_node
;
7807 switch (c_parser_peek_token (parser
)->type
)
7813 code
= TRUNC_DIV_EXPR
;
7828 code
= BIT_AND_EXPR
;
7831 code
= BIT_IOR_EXPR
;
7834 code
= BIT_XOR_EXPR
;
7837 c_parser_error (parser
,
7838 "invalid operator for %<#pragma omp atomic%>");
7842 c_parser_consume_token (parser
);
7844 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
7845 rhs_expr
= c_parser_expression (parser
);
7846 rhs_expr
= default_function_array_conversion (rhs_loc
, rhs_expr
);
7848 rhs
= rhs_expr
.value
;
7849 rhs
= c_fully_fold (rhs
, false, NULL
);
7852 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
7853 if (stmt
!= error_mark_node
)
7855 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7860 # pragma omp barrier new-line
7864 c_parser_omp_barrier (c_parser
*parser
)
7866 location_t loc
= c_parser_peek_token (parser
)->location
;
7867 c_parser_consume_pragma (parser
);
7868 c_parser_skip_to_pragma_eol (parser
);
7870 c_finish_omp_barrier (loc
);
7874 # pragma omp critical [(name)] new-line
7877 LOC is the location of the #pragma itself. */
7880 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
7882 tree stmt
, name
= NULL
;
7884 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7886 c_parser_consume_token (parser
);
7887 if (c_parser_next_token_is (parser
, CPP_NAME
))
7889 name
= c_parser_peek_token (parser
)->value
;
7890 c_parser_consume_token (parser
);
7891 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7894 c_parser_error (parser
, "expected identifier");
7896 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7897 c_parser_error (parser
, "expected %<(%> or end of line");
7898 c_parser_skip_to_pragma_eol (parser
);
7900 stmt
= c_parser_omp_structured_block (parser
);
7901 return c_finish_omp_critical (loc
, stmt
, name
);
7905 # pragma omp flush flush-vars[opt] new-line
7908 ( variable-list ) */
7911 c_parser_omp_flush (c_parser
*parser
)
7913 location_t loc
= c_parser_peek_token (parser
)->location
;
7914 c_parser_consume_pragma (parser
);
7915 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7916 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7917 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7918 c_parser_error (parser
, "expected %<(%> or end of line");
7919 c_parser_skip_to_pragma_eol (parser
);
7921 c_finish_omp_flush (loc
);
7924 /* Parse the restricted form of the for statement allowed by OpenMP.
7925 The real trick here is to determine the loop control variable early
7926 so that we can push a new decl if necessary to make it private.
7927 LOC is the location of the OMP in "#pragma omp". */
7930 c_parser_omp_for_loop (location_t loc
,
7931 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7933 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7934 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7935 bool fail
= false, open_brace_parsed
= false;
7936 int i
, collapse
= 1, nbraces
= 0;
7939 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7940 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7941 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7943 gcc_assert (collapse
>= 1);
7945 declv
= make_tree_vec (collapse
);
7946 initv
= make_tree_vec (collapse
);
7947 condv
= make_tree_vec (collapse
);
7948 incrv
= make_tree_vec (collapse
);
7950 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7952 c_parser_error (parser
, "for statement expected");
7955 for_loc
= c_parser_peek_token (parser
)->location
;
7956 c_parser_consume_token (parser
);
7958 for (i
= 0; i
< collapse
; i
++)
7962 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7965 /* Parse the initialization declaration or expression. */
7966 if (c_parser_next_token_starts_declspecs (parser
))
7970 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7971 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7972 decl
= check_for_loop_decls (for_loc
);
7975 if (DECL_INITIAL (decl
) == error_mark_node
)
7976 decl
= error_mark_node
;
7979 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7980 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7982 struct c_expr decl_exp
;
7983 struct c_expr init_exp
;
7984 location_t init_loc
;
7986 decl_exp
= c_parser_postfix_expression (parser
);
7987 decl
= decl_exp
.value
;
7989 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7991 init_loc
= c_parser_peek_token (parser
)->location
;
7992 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7993 init_exp
= default_function_array_conversion (init_loc
, init_exp
);
7994 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7995 NOP_EXPR
, init_loc
, init_exp
.value
,
7996 init_exp
.original_type
);
7997 init
= c_process_expr_stmt (init_loc
, init
);
7999 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8004 c_parser_error (parser
,
8005 "expected iteration declaration or initialization");
8006 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8012 /* Parse the loop condition. */
8014 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
8016 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
8017 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
8019 cond
= cond_expr
.value
;
8020 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
8021 cond
= c_fully_fold (cond
, false, NULL
);
8022 switch (cond_expr
.original_code
)
8030 /* Can't be cond = error_mark_node, because we want to preserve
8031 the location until c_finish_omp_for. */
8032 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
8035 protected_set_expr_location (cond
, cond_loc
);
8037 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8039 /* Parse the increment expression. */
8041 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
8043 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
8045 incr
= c_process_expr_stmt (incr_loc
,
8046 c_parser_expression (parser
).value
);
8048 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8050 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
8054 TREE_VEC_ELT (declv
, i
) = decl
;
8055 TREE_VEC_ELT (initv
, i
) = init
;
8056 TREE_VEC_ELT (condv
, i
) = cond
;
8057 TREE_VEC_ELT (incrv
, i
) = incr
;
8061 if (i
== collapse
- 1)
8064 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8065 in between the collapsed for loops to be still considered perfectly
8066 nested. Hopefully the final version clarifies this.
8067 For now handle (multiple) {'s and empty statements. */
8070 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8072 c_parser_consume_token (parser
);
8075 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8077 c_parser_consume_token (parser
);
8081 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8082 c_parser_consume_token (parser
);
8085 c_parser_error (parser
, "not enough perfectly nested loops");
8088 open_brace_parsed
= true;
8098 nbraces
+= bracecount
;
8101 save_break
= c_break_label
;
8102 c_break_label
= size_one_node
;
8103 save_cont
= c_cont_label
;
8104 c_cont_label
= NULL_TREE
;
8105 body
= push_stmt_list ();
8107 if (open_brace_parsed
)
8109 location_t here
= c_parser_peek_token (parser
)->location
;
8110 stmt
= c_begin_compound_stmt (true);
8111 c_parser_compound_statement_nostart (parser
);
8112 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8115 add_stmt (c_parser_c99_block_statement (parser
));
8118 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8119 SET_EXPR_LOCATION (t
, loc
);
8123 body
= pop_stmt_list (body
);
8124 c_break_label
= save_break
;
8125 c_cont_label
= save_cont
;
8129 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8131 c_parser_consume_token (parser
);
8134 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8135 c_parser_consume_token (parser
);
8138 c_parser_error (parser
, "collapsed loops not perfectly nested");
8141 location_t here
= c_parser_peek_token (parser
)->location
;
8142 stmt
= c_begin_compound_stmt (true);
8144 c_parser_compound_statement_nostart (parser
);
8145 body
= c_end_compound_stmt (here
, stmt
, true);
8152 /* Only bother calling c_finish_omp_for if we haven't already generated
8153 an error from the initialization parsing. */
8156 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8159 if (par_clauses
!= NULL
)
8162 for (c
= par_clauses
; *c
; )
8163 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8164 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8165 c
= &OMP_CLAUSE_CHAIN (*c
);
8168 for (i
= 0; i
< collapse
; i
++)
8169 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8172 c
= &OMP_CLAUSE_CHAIN (*c
);
8173 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8176 "iteration variable %qD should not be firstprivate",
8177 OMP_CLAUSE_DECL (*c
));
8178 *c
= OMP_CLAUSE_CHAIN (*c
);
8182 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8183 change it to shared (decl) in
8184 OMP_PARALLEL_CLAUSES. */
8185 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8186 OMP_CLAUSE_LASTPRIVATE
);
8187 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8188 OMP_CLAUSE_CHAIN (l
) = clauses
;
8190 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8194 OMP_FOR_CLAUSES (stmt
) = clauses
;
8201 /* FIXME diagnostics: LOC below should be the actual location of
8202 this particular for block. We need to build a list of
8203 locations to go along with FOR_BLOCK. */
8204 stmt
= c_end_compound_stmt (loc
, TREE_VALUE (for_block
), true);
8206 for_block
= TREE_CHAIN (for_block
);
8212 #pragma omp for for-clause[optseq] new-line
8215 LOC is the location of the #pragma token.
8218 #define OMP_FOR_CLAUSE_MASK \
8219 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8220 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8221 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8222 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8223 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8224 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8225 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8226 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8229 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8231 tree block
, clauses
, ret
;
8233 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8236 block
= c_begin_compound_stmt (true);
8237 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8238 block
= c_end_compound_stmt (loc
, block
, true);
8245 # pragma omp master new-line
8248 LOC is the location of the #pragma token.
8252 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8254 c_parser_skip_to_pragma_eol (parser
);
8255 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8259 # pragma omp ordered new-line
8262 LOC is the location of the #pragma itself.
8266 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8268 c_parser_skip_to_pragma_eol (parser
);
8269 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8275 { section-sequence }
8278 section-directive[opt] structured-block
8279 section-sequence section-directive structured-block
8281 SECTIONS_LOC is the location of the #pragma omp sections. */
8284 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8287 bool error_suppress
= false;
8290 loc
= c_parser_peek_token (parser
)->location
;
8291 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8293 /* Avoid skipping until the end of the block. */
8294 parser
->error
= false;
8298 stmt
= push_stmt_list ();
8300 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8302 substmt
= push_stmt_list ();
8306 c_parser_statement (parser
);
8308 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8310 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8312 if (c_parser_next_token_is (parser
, CPP_EOF
))
8316 substmt
= pop_stmt_list (substmt
);
8317 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8318 SET_EXPR_LOCATION (substmt
, loc
);
8324 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8326 if (c_parser_next_token_is (parser
, CPP_EOF
))
8329 loc
= c_parser_peek_token (parser
)->location
;
8330 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8332 c_parser_consume_pragma (parser
);
8333 c_parser_skip_to_pragma_eol (parser
);
8334 error_suppress
= false;
8336 else if (!error_suppress
)
8338 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8339 error_suppress
= true;
8342 substmt
= c_parser_omp_structured_block (parser
);
8343 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8344 SET_EXPR_LOCATION (substmt
, loc
);
8347 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8348 "expected %<#pragma omp section%> or %<}%>");
8350 substmt
= pop_stmt_list (stmt
);
8352 stmt
= make_node (OMP_SECTIONS
);
8353 SET_EXPR_LOCATION (stmt
, sections_loc
);
8354 TREE_TYPE (stmt
) = void_type_node
;
8355 OMP_SECTIONS_BODY (stmt
) = substmt
;
8357 return add_stmt (stmt
);
8361 # pragma omp sections sections-clause[optseq] newline
8364 LOC is the location of the #pragma token.
8367 #define OMP_SECTIONS_CLAUSE_MASK \
8368 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8369 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8370 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8371 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8372 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8375 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8377 tree block
, clauses
, ret
;
8379 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8380 "#pragma omp sections");
8382 block
= c_begin_compound_stmt (true);
8383 ret
= c_parser_omp_sections_scope (loc
, parser
);
8385 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8386 block
= c_end_compound_stmt (loc
, block
, true);
8393 # pragma parallel parallel-clause new-line
8394 # pragma parallel for parallel-for-clause new-line
8395 # pragma parallel sections parallel-sections-clause new-line
8397 LOC is the location of the #pragma token.
8400 #define OMP_PARALLEL_CLAUSE_MASK \
8401 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8402 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8403 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8404 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8405 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8406 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8407 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8408 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8411 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8413 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8414 const char *p_name
= "#pragma omp parallel";
8415 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8416 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8418 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8420 c_parser_consume_token (parser
);
8421 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8422 p_name
= "#pragma omp parallel for";
8423 mask
|= OMP_FOR_CLAUSE_MASK
;
8424 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8426 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8428 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8429 if (strcmp (p
, "sections") == 0)
8431 c_parser_consume_token (parser
);
8432 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8433 p_name
= "#pragma omp parallel sections";
8434 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8435 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8439 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8443 case PRAGMA_OMP_PARALLEL
:
8444 block
= c_begin_omp_parallel ();
8445 c_parser_statement (parser
);
8446 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8449 case PRAGMA_OMP_PARALLEL_FOR
:
8450 block
= c_begin_omp_parallel ();
8451 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8452 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8453 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8454 OMP_PARALLEL_COMBINED (stmt
) = 1;
8457 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8458 block
= c_begin_omp_parallel ();
8459 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8460 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8462 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8463 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8464 OMP_PARALLEL_COMBINED (stmt
) = 1;
8475 # pragma omp single single-clause[optseq] new-line
8478 LOC is the location of the #pragma.
8481 #define OMP_SINGLE_CLAUSE_MASK \
8482 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8483 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8484 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8485 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8488 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8490 tree stmt
= make_node (OMP_SINGLE
);
8491 SET_EXPR_LOCATION (stmt
, loc
);
8492 TREE_TYPE (stmt
) = void_type_node
;
8494 OMP_SINGLE_CLAUSES (stmt
)
8495 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8496 "#pragma omp single");
8497 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8499 return add_stmt (stmt
);
8503 # pragma omp task task-clause[optseq] new-line
8505 LOC is the location of the #pragma.
8508 #define OMP_TASK_CLAUSE_MASK \
8509 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8510 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8511 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8512 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8513 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8514 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8517 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8519 tree clauses
, block
;
8521 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8522 "#pragma omp task");
8524 block
= c_begin_omp_task ();
8525 c_parser_statement (parser
);
8526 return c_finish_omp_task (loc
, clauses
, block
);
8530 # pragma omp taskwait new-line
8534 c_parser_omp_taskwait (c_parser
*parser
)
8536 location_t loc
= c_parser_peek_token (parser
)->location
;
8537 c_parser_consume_pragma (parser
);
8538 c_parser_skip_to_pragma_eol (parser
);
8540 c_finish_omp_taskwait (loc
);
8543 /* Main entry point to parsing most OpenMP pragmas. */
8546 c_parser_omp_construct (c_parser
*parser
)
8548 enum pragma_kind p_kind
;
8552 loc
= c_parser_peek_token (parser
)->location
;
8553 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8554 c_parser_consume_pragma (parser
);
8558 case PRAGMA_OMP_ATOMIC
:
8559 c_parser_omp_atomic (loc
, parser
);
8561 case PRAGMA_OMP_CRITICAL
:
8562 stmt
= c_parser_omp_critical (loc
, parser
);
8564 case PRAGMA_OMP_FOR
:
8565 stmt
= c_parser_omp_for (loc
, parser
);
8567 case PRAGMA_OMP_MASTER
:
8568 stmt
= c_parser_omp_master (loc
, parser
);
8570 case PRAGMA_OMP_ORDERED
:
8571 stmt
= c_parser_omp_ordered (loc
, parser
);
8573 case PRAGMA_OMP_PARALLEL
:
8574 stmt
= c_parser_omp_parallel (loc
, parser
);
8576 case PRAGMA_OMP_SECTIONS
:
8577 stmt
= c_parser_omp_sections (loc
, parser
);
8579 case PRAGMA_OMP_SINGLE
:
8580 stmt
= c_parser_omp_single (loc
, parser
);
8582 case PRAGMA_OMP_TASK
:
8583 stmt
= c_parser_omp_task (loc
, parser
);
8590 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
8595 # pragma omp threadprivate (variable-list) */
8598 c_parser_omp_threadprivate (c_parser
*parser
)
8603 c_parser_consume_pragma (parser
);
8604 loc
= c_parser_peek_token (parser
)->location
;
8605 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8607 /* Mark every variable in VARS to be assigned thread local storage. */
8608 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8610 tree v
= TREE_PURPOSE (t
);
8612 /* FIXME diagnostics: Ideally we should keep individual
8613 locations for all the variables in the var list to make the
8614 following errors more precise. Perhaps
8615 c_parser_omp_var_list_parens() should construct a list of
8616 locations to go along with the var list. */
8618 /* If V had already been marked threadprivate, it doesn't matter
8619 whether it had been used prior to this point. */
8620 if (TREE_CODE (v
) != VAR_DECL
)
8621 error_at (loc
, "%qD is not a variable", v
);
8622 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8623 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
8624 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8625 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
8626 else if (TREE_TYPE (v
) == error_mark_node
)
8628 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8629 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
8632 if (! DECL_THREAD_LOCAL_P (v
))
8634 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8635 /* If rtl has been already set for this var, call
8636 make_decl_rtl once again, so that encode_section_info
8637 has a chance to look at the new decl flags. */
8638 if (DECL_RTL_SET_P (v
))
8641 C_DECL_THREADPRIVATE_P (v
) = 1;
8645 c_parser_skip_to_pragma_eol (parser
);
8649 /* Parse a single source file. */
8654 /* Use local storage to begin. If the first token is a pragma, parse it.
8655 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8656 which will cause garbage collection. */
8659 memset (&tparser
, 0, sizeof tparser
);
8660 the_parser
= &tparser
;
8662 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8663 c_parser_pragma_pch_preprocess (&tparser
);
8665 the_parser
= GGC_NEW (c_parser
);
8666 *the_parser
= tparser
;
8668 /* Initialize EH, if we've been told to do so. */
8669 if (flag_exceptions
)
8670 using_eh_for_cleanups ();
8672 c_parser_translation_unit (the_parser
);
8676 #include "gt-c-parser.h"