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 case CPP_UTF8STRING
:
5353 expr
.value
= c_parser_peek_token (parser
)->value
;
5354 expr
.original_code
= STRING_CST
;
5355 c_parser_consume_token (parser
);
5357 case CPP_OBJC_STRING
:
5358 gcc_assert (c_dialect_objc ());
5360 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5361 c_parser_consume_token (parser
);
5364 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5366 c_parser_error (parser
, "expected expression");
5367 expr
.value
= error_mark_node
;
5371 tree id
= c_parser_peek_token (parser
)->value
;
5372 c_parser_consume_token (parser
);
5373 expr
.value
= build_external_ref (loc
, id
,
5374 (c_parser_peek_token (parser
)->type
5376 &expr
.original_type
);
5379 case CPP_OPEN_PAREN
:
5380 /* A parenthesized expression, statement expression or compound
5382 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5384 /* A statement expression. */
5386 location_t brace_loc
;
5387 c_parser_consume_token (parser
);
5388 brace_loc
= c_parser_peek_token (parser
)->location
;
5389 c_parser_consume_token (parser
);
5390 if (cur_stmt_list
== NULL
)
5392 error_at (loc
, "braced-group within expression allowed "
5393 "only inside a function");
5394 parser
->error
= true;
5395 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5397 expr
.value
= error_mark_node
;
5400 stmt
= c_begin_stmt_expr ();
5401 c_parser_compound_statement_nostart (parser
);
5402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5404 pedwarn (loc
, OPT_pedantic
,
5405 "ISO C forbids braced-groups within expressions");
5406 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5408 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5410 /* A compound literal. ??? Can we actually get here rather
5411 than going directly to
5412 c_parser_postfix_expression_after_paren_type from
5415 struct c_type_name
*type_name
;
5416 c_parser_consume_token (parser
);
5417 loc
= c_parser_peek_token (parser
)->location
;
5418 type_name
= c_parser_type_name (parser
);
5419 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5421 if (type_name
== NULL
)
5423 expr
.value
= error_mark_node
;
5426 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5432 /* A parenthesized expression. */
5433 c_parser_consume_token (parser
);
5434 expr
= c_parser_expression (parser
);
5435 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5436 TREE_NO_WARNING (expr
.value
) = 1;
5437 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5438 expr
.original_code
= ERROR_MARK
;
5439 /* Don't change EXPR.ORIGINAL_TYPE. */
5440 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5445 switch (c_parser_peek_token (parser
)->keyword
)
5447 case RID_FUNCTION_NAME
:
5448 case RID_PRETTY_FUNCTION_NAME
:
5449 case RID_C99_FUNCTION_NAME
:
5450 expr
.value
= fname_decl (loc
,
5451 c_parser_peek_token (parser
)->keyword
,
5452 c_parser_peek_token (parser
)->value
);
5453 c_parser_consume_token (parser
);
5456 c_parser_consume_token (parser
);
5457 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5459 expr
.value
= error_mark_node
;
5462 e1
= c_parser_expr_no_commas (parser
, NULL
);
5463 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5464 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5467 expr
.value
= error_mark_node
;
5470 loc
= c_parser_peek_token (parser
)->location
;
5471 t1
= c_parser_type_name (parser
);
5472 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5476 expr
.value
= error_mark_node
;
5480 tree type_expr
= NULL_TREE
;
5481 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5482 groktypename (t1
, &type_expr
, NULL
));
5485 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5486 TREE_TYPE (expr
.value
), type_expr
,
5488 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5493 c_parser_consume_token (parser
);
5494 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5496 expr
.value
= error_mark_node
;
5499 t1
= c_parser_type_name (parser
);
5502 expr
.value
= error_mark_node
;
5505 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5508 expr
.value
= error_mark_node
;
5512 tree type
= groktypename (t1
, NULL
, NULL
);
5514 if (type
== error_mark_node
)
5515 offsetof_ref
= error_mark_node
;
5518 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5519 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5521 /* Parse the second argument to __builtin_offsetof. We
5522 must have one identifier, and beyond that we want to
5523 accept sub structure and sub array references. */
5524 if (c_parser_next_token_is (parser
, CPP_NAME
))
5526 offsetof_ref
= build_component_ref
5527 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5528 c_parser_consume_token (parser
);
5529 while (c_parser_next_token_is (parser
, CPP_DOT
)
5530 || c_parser_next_token_is (parser
,
5532 || c_parser_next_token_is (parser
,
5535 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5537 loc
= c_parser_peek_token (parser
)->location
;
5538 offsetof_ref
= build_array_ref (loc
,
5543 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5546 c_parser_consume_token (parser
);
5547 if (c_parser_next_token_is_not (parser
,
5550 c_parser_error (parser
, "expected identifier");
5553 offsetof_ref
= build_component_ref
5555 c_parser_peek_token (parser
)->value
);
5556 c_parser_consume_token (parser
);
5561 loc
= c_parser_peek_token (parser
)->location
;
5562 c_parser_consume_token (parser
);
5563 idx
= c_parser_expression (parser
).value
;
5564 idx
= c_fully_fold (idx
, false, NULL
);
5565 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5567 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5572 c_parser_error (parser
, "expected identifier");
5573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5575 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5578 case RID_CHOOSE_EXPR
:
5579 c_parser_consume_token (parser
);
5580 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5582 expr
.value
= error_mark_node
;
5585 loc
= c_parser_peek_token (parser
)->location
;
5586 e1
= c_parser_expr_no_commas (parser
, NULL
);
5587 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5590 expr
.value
= error_mark_node
;
5593 e2
= c_parser_expr_no_commas (parser
, NULL
);
5594 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5596 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5597 expr
.value
= error_mark_node
;
5600 e3
= c_parser_expr_no_commas (parser
, NULL
);
5601 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5607 if (TREE_CODE (c
) != INTEGER_CST
5608 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5610 "first argument to %<__builtin_choose_expr%> not"
5612 constant_expression_warning (c
);
5613 expr
= integer_zerop (c
) ? e3
: e2
;
5616 case RID_TYPES_COMPATIBLE_P
:
5617 c_parser_consume_token (parser
);
5618 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5620 expr
.value
= error_mark_node
;
5623 t1
= c_parser_type_name (parser
);
5626 expr
.value
= error_mark_node
;
5629 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5632 expr
.value
= error_mark_node
;
5635 t2
= c_parser_type_name (parser
);
5638 expr
.value
= error_mark_node
;
5641 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5646 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5647 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5649 expr
.value
= comptypes (e1
, e2
)
5650 ? build_int_cst (NULL_TREE
, 1)
5651 : build_int_cst (NULL_TREE
, 0);
5654 case RID_AT_SELECTOR
:
5655 gcc_assert (c_dialect_objc ());
5656 c_parser_consume_token (parser
);
5657 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5659 expr
.value
= error_mark_node
;
5663 tree sel
= c_parser_objc_selector_arg (parser
);
5664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5666 expr
.value
= objc_build_selector_expr (loc
, sel
);
5669 case RID_AT_PROTOCOL
:
5670 gcc_assert (c_dialect_objc ());
5671 c_parser_consume_token (parser
);
5672 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5674 expr
.value
= error_mark_node
;
5677 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5679 c_parser_error (parser
, "expected identifier");
5680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5681 expr
.value
= error_mark_node
;
5685 tree id
= c_parser_peek_token (parser
)->value
;
5686 c_parser_consume_token (parser
);
5687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5689 expr
.value
= objc_build_protocol_expr (id
);
5693 /* Extension to support C-structures in the archiver. */
5694 gcc_assert (c_dialect_objc ());
5695 c_parser_consume_token (parser
);
5696 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5698 expr
.value
= error_mark_node
;
5701 t1
= c_parser_type_name (parser
);
5704 expr
.value
= error_mark_node
;
5705 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5711 tree type
= groktypename (t1
, NULL
, NULL
);
5712 expr
.value
= objc_build_encode_expr (type
);
5716 c_parser_error (parser
, "expected expression");
5717 expr
.value
= error_mark_node
;
5721 case CPP_OPEN_SQUARE
:
5722 if (c_dialect_objc ())
5724 tree receiver
, args
;
5725 c_parser_consume_token (parser
);
5726 receiver
= c_parser_objc_receiver (parser
);
5727 args
= c_parser_objc_message_args (parser
);
5728 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5730 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5734 /* Else fall through to report error. */
5736 c_parser_error (parser
, "expected expression");
5737 expr
.value
= error_mark_node
;
5740 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
5743 /* Parse a postfix expression after a parenthesized type name: the
5744 brace-enclosed initializer of a compound literal, possibly followed
5745 by some postfix operators. This is separate because it is not
5746 possible to tell until after the type name whether a cast
5747 expression has a cast or a compound literal, or whether the operand
5748 of sizeof is a parenthesized type name or starts with a compound
5749 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5750 location of the first token after the parentheses around the type
5753 static struct c_expr
5754 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5755 struct c_type_name
*type_name
,
5756 location_t type_loc
)
5762 location_t start_loc
;
5763 tree type_expr
= NULL_TREE
;
5764 bool type_expr_const
= true;
5765 check_compound_literal_type (type_loc
, type_name
);
5766 start_init (NULL_TREE
, NULL
, 0);
5767 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5768 start_loc
= c_parser_peek_token (parser
)->location
;
5769 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5771 error_at (type_loc
, "compound literal has variable size");
5772 type
= error_mark_node
;
5774 init
= c_parser_braced_init (parser
, type
, false);
5776 maybe_warn_string_init (type
, init
);
5779 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5780 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5781 ? CONSTRUCTOR_NON_CONST (init
.value
)
5782 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5783 non_const
|= !type_expr_const
;
5784 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
5785 expr
.original_code
= ERROR_MARK
;
5786 expr
.original_type
= NULL
;
5789 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5791 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5792 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5796 gcc_assert (!non_const
);
5797 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5798 type_expr
, expr
.value
);
5801 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
5804 /* Parse a postfix expression after the initial primary or compound
5805 literal; that is, parse a series of postfix operators.
5807 EXPR_LOC is the location of the primary expression. */
5809 static struct c_expr
5810 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5811 location_t expr_loc
,
5814 struct c_expr orig_expr
;
5816 VEC(tree
,gc
) *exprlist
;
5817 VEC(tree
,gc
) *origtypes
;
5820 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5821 switch (c_parser_peek_token (parser
)->type
)
5823 case CPP_OPEN_SQUARE
:
5824 /* Array reference. */
5825 c_parser_consume_token (parser
);
5826 idx
= c_parser_expression (parser
).value
;
5827 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5829 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
5830 expr
.original_code
= ERROR_MARK
;
5831 expr
.original_type
= NULL
;
5833 case CPP_OPEN_PAREN
:
5834 /* Function call. */
5835 c_parser_consume_token (parser
);
5836 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5839 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5843 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5844 "(" after the FUNCNAME, which is what we have now. */
5845 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
5847 expr
.original_code
= ERROR_MARK
;
5848 if (TREE_CODE (expr
.value
) == INTEGER_CST
5849 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5850 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5851 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5852 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5853 expr
.original_type
= NULL
;
5854 if (exprlist
!= NULL
)
5856 release_tree_vector (exprlist
);
5857 release_tree_vector (origtypes
);
5861 /* Structure element reference. */
5862 c_parser_consume_token (parser
);
5863 expr
= default_function_array_conversion (expr_loc
, expr
);
5864 if (c_parser_next_token_is (parser
, CPP_NAME
))
5865 ident
= c_parser_peek_token (parser
)->value
;
5868 c_parser_error (parser
, "expected identifier");
5869 expr
.value
= error_mark_node
;
5870 expr
.original_code
= ERROR_MARK
;
5871 expr
.original_type
= NULL
;
5874 c_parser_consume_token (parser
);
5875 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
5876 expr
.original_code
= ERROR_MARK
;
5877 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5878 expr
.original_type
= NULL
;
5881 /* Remember the original type of a bitfield. */
5882 tree field
= TREE_OPERAND (expr
.value
, 1);
5883 if (TREE_CODE (field
) != FIELD_DECL
)
5884 expr
.original_type
= NULL
;
5886 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5890 /* Structure element reference. */
5891 c_parser_consume_token (parser
);
5892 expr
= default_function_array_conversion (expr_loc
, expr
);
5893 if (c_parser_next_token_is (parser
, CPP_NAME
))
5894 ident
= c_parser_peek_token (parser
)->value
;
5897 c_parser_error (parser
, "expected identifier");
5898 expr
.value
= error_mark_node
;
5899 expr
.original_code
= ERROR_MARK
;
5900 expr
.original_type
= NULL
;
5903 c_parser_consume_token (parser
);
5904 expr
.value
= build_component_ref (op_loc
,
5905 build_indirect_ref (op_loc
,
5909 expr
.original_code
= ERROR_MARK
;
5910 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5911 expr
.original_type
= NULL
;
5914 /* Remember the original type of a bitfield. */
5915 tree field
= TREE_OPERAND (expr
.value
, 1);
5916 if (TREE_CODE (field
) != FIELD_DECL
)
5917 expr
.original_type
= NULL
;
5919 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5923 /* Postincrement. */
5924 c_parser_consume_token (parser
);
5925 expr
= default_function_array_conversion (expr_loc
, expr
);
5926 expr
.value
= build_unary_op (op_loc
,
5927 POSTINCREMENT_EXPR
, expr
.value
, 0);
5928 expr
.original_code
= ERROR_MARK
;
5929 expr
.original_type
= NULL
;
5931 case CPP_MINUS_MINUS
:
5932 /* Postdecrement. */
5933 c_parser_consume_token (parser
);
5934 expr
= default_function_array_conversion (expr_loc
, expr
);
5935 expr
.value
= build_unary_op (op_loc
,
5936 POSTDECREMENT_EXPR
, expr
.value
, 0);
5937 expr
.original_code
= ERROR_MARK
;
5938 expr
.original_type
= NULL
;
5946 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5949 assignment-expression
5950 expression , assignment-expression
5953 static struct c_expr
5954 c_parser_expression (c_parser
*parser
)
5957 expr
= c_parser_expr_no_commas (parser
, NULL
);
5958 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5961 location_t loc
= c_parser_peek_token (parser
)->location
;
5962 location_t expr_loc
;
5963 c_parser_consume_token (parser
);
5964 expr_loc
= c_parser_peek_token (parser
)->location
;
5965 next
= c_parser_expr_no_commas (parser
, NULL
);
5966 next
= default_function_array_conversion (expr_loc
, next
);
5967 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
5968 expr
.original_code
= COMPOUND_EXPR
;
5969 expr
.original_type
= next
.original_type
;
5974 /* Parse an expression and convert functions or arrays to
5977 static struct c_expr
5978 c_parser_expression_conv (c_parser
*parser
)
5981 location_t loc
= c_parser_peek_token (parser
)->location
;
5982 expr
= c_parser_expression (parser
);
5983 expr
= default_function_array_conversion (loc
, expr
);
5987 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5988 functions and arrays to pointers. If FOLD_P, fold the expressions.
5991 assignment-expression
5992 nonempty-expr-list , assignment-expression
5995 static VEC(tree
,gc
) *
5996 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5997 VEC(tree
,gc
) **p_orig_types
)
6000 VEC(tree
,gc
) *orig_types
;
6002 location_t loc
= c_parser_peek_token (parser
)->location
;
6004 ret
= make_tree_vector ();
6005 if (p_orig_types
== NULL
)
6008 orig_types
= make_tree_vector ();
6010 expr
= c_parser_expr_no_commas (parser
, NULL
);
6012 expr
= default_function_array_conversion (loc
, expr
);
6014 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6015 VEC_quick_push (tree
, ret
, expr
.value
);
6016 if (orig_types
!= NULL
)
6017 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6018 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6020 c_parser_consume_token (parser
);
6021 loc
= c_parser_peek_token (parser
)->location
;
6022 expr
= c_parser_expr_no_commas (parser
, NULL
);
6024 expr
= default_function_array_conversion (loc
, expr
);
6026 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6027 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6028 if (orig_types
!= NULL
)
6029 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6031 if (orig_types
!= NULL
)
6032 *p_orig_types
= orig_types
;
6036 /* Parse Objective-C-specific constructs. */
6038 /* Parse an objc-class-definition.
6040 objc-class-definition:
6041 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6042 objc-class-instance-variables[opt] objc-methodprotolist @end
6043 @implementation identifier objc-superclass[opt]
6044 objc-class-instance-variables[opt]
6045 @interface identifier ( identifier ) objc-protocol-refs[opt]
6046 objc-methodprotolist @end
6047 @implementation identifier ( identifier )
6052 "@interface identifier (" must start "@interface identifier (
6053 identifier ) ...": objc-methodprotolist in the first production may
6054 not start with a parenthesized identifier as a declarator of a data
6055 definition with no declaration specifiers if the objc-superclass,
6056 objc-protocol-refs and objc-class-instance-variables are omitted. */
6059 c_parser_objc_class_definition (c_parser
*parser
)
6064 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6066 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6070 c_parser_consume_token (parser
);
6071 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6073 c_parser_error (parser
, "expected identifier");
6076 id1
= c_parser_peek_token (parser
)->value
;
6077 c_parser_consume_token (parser
);
6078 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6081 tree proto
= NULL_TREE
;
6082 c_parser_consume_token (parser
);
6083 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6085 c_parser_error (parser
, "expected identifier");
6086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6089 id2
= c_parser_peek_token (parser
)->value
;
6090 c_parser_consume_token (parser
);
6091 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6094 objc_start_category_implementation (id1
, id2
);
6097 if (c_parser_next_token_is (parser
, CPP_LESS
))
6098 proto
= c_parser_objc_protocol_refs (parser
);
6099 objc_start_category_interface (id1
, id2
, proto
);
6100 c_parser_objc_methodprotolist (parser
);
6101 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6102 objc_finish_interface ();
6105 if (c_parser_next_token_is (parser
, CPP_COLON
))
6107 c_parser_consume_token (parser
);
6108 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6110 c_parser_error (parser
, "expected identifier");
6113 superclass
= c_parser_peek_token (parser
)->value
;
6114 c_parser_consume_token (parser
);
6117 superclass
= NULL_TREE
;
6120 tree proto
= NULL_TREE
;
6121 if (c_parser_next_token_is (parser
, CPP_LESS
))
6122 proto
= c_parser_objc_protocol_refs (parser
);
6123 objc_start_class_interface (id1
, superclass
, proto
);
6126 objc_start_class_implementation (id1
, superclass
);
6127 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6128 c_parser_objc_class_instance_variables (parser
);
6131 objc_continue_interface ();
6132 c_parser_objc_methodprotolist (parser
);
6133 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6134 objc_finish_interface ();
6138 objc_continue_implementation ();
6143 /* Parse objc-class-instance-variables.
6145 objc-class-instance-variables:
6146 { objc-instance-variable-decl-list[opt] }
6148 objc-instance-variable-decl-list:
6149 objc-visibility-spec
6150 objc-instance-variable-decl ;
6152 objc-instance-variable-decl-list objc-visibility-spec
6153 objc-instance-variable-decl-list objc-instance-variable-decl ;
6154 objc-instance-variable-decl-list ;
6156 objc-visibility-spec:
6161 objc-instance-variable-decl:
6166 c_parser_objc_class_instance_variables (c_parser
*parser
)
6168 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6169 c_parser_consume_token (parser
);
6170 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6173 /* Parse any stray semicolon. */
6174 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6176 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6177 "extra semicolon in struct or union specified");
6178 c_parser_consume_token (parser
);
6181 /* Stop if at the end of the instance variables. */
6182 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6184 c_parser_consume_token (parser
);
6187 /* Parse any objc-visibility-spec. */
6188 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6190 c_parser_consume_token (parser
);
6191 objc_set_visibility (2);
6194 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6196 c_parser_consume_token (parser
);
6197 objc_set_visibility (0);
6200 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6202 c_parser_consume_token (parser
);
6203 objc_set_visibility (1);
6206 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6208 c_parser_pragma (parser
, pragma_external
);
6212 /* Parse some comma-separated declarations. */
6213 decls
= c_parser_struct_declaration (parser
);
6215 /* Comma-separated instance variables are chained together in
6216 reverse order; add them one by one. */
6217 tree ivar
= nreverse (decls
);
6218 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6219 objc_add_instance_variable (copy_node (ivar
));
6221 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6225 /* Parse an objc-class-declaration.
6227 objc-class-declaration:
6228 @class identifier-list ;
6232 c_parser_objc_class_declaration (c_parser
*parser
)
6234 tree list
= NULL_TREE
;
6235 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6236 c_parser_consume_token (parser
);
6237 /* Any identifiers, including those declared as type names, are OK
6242 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6244 c_parser_error (parser
, "expected identifier");
6247 id
= c_parser_peek_token (parser
)->value
;
6248 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6249 c_parser_consume_token (parser
);
6250 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6251 c_parser_consume_token (parser
);
6255 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6256 objc_declare_class (list
);
6259 /* Parse an objc-alias-declaration.
6261 objc-alias-declaration:
6262 @compatibility_alias identifier identifier ;
6266 c_parser_objc_alias_declaration (c_parser
*parser
)
6269 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6270 c_parser_consume_token (parser
);
6271 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6273 c_parser_error (parser
, "expected identifier");
6274 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6277 id1
= c_parser_peek_token (parser
)->value
;
6278 c_parser_consume_token (parser
);
6279 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6281 c_parser_error (parser
, "expected identifier");
6282 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6285 id2
= c_parser_peek_token (parser
)->value
;
6286 c_parser_consume_token (parser
);
6287 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6288 objc_declare_alias (id1
, id2
);
6291 /* Parse an objc-protocol-definition.
6293 objc-protocol-definition:
6294 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6295 @protocol identifier-list ;
6297 "@protocol identifier ;" should be resolved as "@protocol
6298 identifier-list ;": objc-methodprotolist may not start with a
6299 semicolon in the first alternative if objc-protocol-refs are
6303 c_parser_objc_protocol_definition (c_parser
*parser
)
6305 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6306 c_parser_consume_token (parser
);
6307 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6309 c_parser_error (parser
, "expected identifier");
6312 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6313 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6315 tree list
= NULL_TREE
;
6316 /* Any identifiers, including those declared as type names, are
6321 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6323 c_parser_error (parser
, "expected identifier");
6326 id
= c_parser_peek_token (parser
)->value
;
6327 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6328 c_parser_consume_token (parser
);
6329 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6330 c_parser_consume_token (parser
);
6334 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6335 objc_declare_protocols (list
);
6339 tree id
= c_parser_peek_token (parser
)->value
;
6340 tree proto
= NULL_TREE
;
6341 c_parser_consume_token (parser
);
6342 if (c_parser_next_token_is (parser
, CPP_LESS
))
6343 proto
= c_parser_objc_protocol_refs (parser
);
6344 parser
->objc_pq_context
= true;
6345 objc_start_protocol (id
, proto
);
6346 c_parser_objc_methodprotolist (parser
);
6347 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6348 parser
->objc_pq_context
= false;
6349 objc_finish_interface ();
6353 /* Parse an objc-method-type.
6360 static enum tree_code
6361 c_parser_objc_method_type (c_parser
*parser
)
6363 switch (c_parser_peek_token (parser
)->type
)
6366 c_parser_consume_token (parser
);
6369 c_parser_consume_token (parser
);
6376 /* Parse an objc-method-definition.
6378 objc-method-definition:
6379 objc-method-type objc-method-decl ;[opt] compound-statement
6383 c_parser_objc_method_definition (c_parser
*parser
)
6385 enum tree_code type
= c_parser_objc_method_type (parser
);
6387 objc_set_method_type (type
);
6388 parser
->objc_pq_context
= true;
6389 decl
= c_parser_objc_method_decl (parser
);
6390 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6392 c_parser_consume_token (parser
);
6393 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6394 "extra semicolon in method definition specified");
6396 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6398 c_parser_error (parser
, "expected %<{%>");
6401 parser
->objc_pq_context
= false;
6402 objc_start_method_definition (decl
);
6403 add_stmt (c_parser_compound_statement (parser
));
6404 objc_finish_method_definition (current_function_decl
);
6407 /* Parse an objc-methodprotolist.
6409 objc-methodprotolist:
6411 objc-methodprotolist objc-methodproto
6412 objc-methodprotolist declaration
6413 objc-methodprotolist ;
6415 The declaration is a data definition, which may be missing
6416 declaration specifiers under the same rules and diagnostics as
6417 other data definitions outside functions, and the stray semicolon
6418 is diagnosed the same way as a stray semicolon outside a
6422 c_parser_objc_methodprotolist (c_parser
*parser
)
6426 /* The list is terminated by @end. */
6427 switch (c_parser_peek_token (parser
)->type
)
6430 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6431 "ISO C does not allow extra %<;%> outside of a function");
6432 c_parser_consume_token (parser
);
6436 c_parser_objc_methodproto (parser
);
6439 c_parser_pragma (parser
, pragma_external
);
6444 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6446 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6452 /* Parse an objc-methodproto.
6455 objc-method-type objc-method-decl ;
6459 c_parser_objc_methodproto (c_parser
*parser
)
6461 enum tree_code type
= c_parser_objc_method_type (parser
);
6463 objc_set_method_type (type
);
6464 /* Remember protocol qualifiers in prototypes. */
6465 parser
->objc_pq_context
= true;
6466 decl
= c_parser_objc_method_decl (parser
);
6467 /* Forget protocol qualifiers here. */
6468 parser
->objc_pq_context
= false;
6469 objc_add_method_declaration (decl
);
6470 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6473 /* Parse an objc-method-decl.
6476 ( objc-type-name ) objc-selector
6478 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6479 objc-keyword-selector objc-optparmlist
6481 objc-keyword-selector:
6483 objc-keyword-selector objc-keyword-decl
6486 objc-selector : ( objc-type-name ) identifier
6487 objc-selector : identifier
6488 : ( objc-type-name ) identifier
6492 objc-optparms objc-optellipsis
6496 objc-opt-parms , parameter-declaration
6504 c_parser_objc_method_decl (c_parser
*parser
)
6506 tree type
= NULL_TREE
;
6508 tree parms
= NULL_TREE
;
6509 bool ellipsis
= false;
6511 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6513 c_parser_consume_token (parser
);
6514 type
= c_parser_objc_type_name (parser
);
6515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6517 sel
= c_parser_objc_selector (parser
);
6518 /* If there is no selector, or a colon follows, we have an
6519 objc-keyword-selector. If there is a selector, and a colon does
6520 not follow, that selector ends the objc-method-decl. */
6521 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6524 tree list
= NULL_TREE
;
6527 tree atype
= NULL_TREE
, id
, keyworddecl
;
6528 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6530 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6532 c_parser_consume_token (parser
);
6533 atype
= c_parser_objc_type_name (parser
);
6534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6537 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6539 c_parser_error (parser
, "expected identifier");
6540 return error_mark_node
;
6542 id
= c_parser_peek_token (parser
)->value
;
6543 c_parser_consume_token (parser
);
6544 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6545 list
= chainon (list
, keyworddecl
);
6546 tsel
= c_parser_objc_selector (parser
);
6547 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6550 /* Parse the optional parameter list. Optional Objective-C
6551 method parameters follow the C syntax, and may include '...'
6552 to denote a variable number of arguments. */
6553 parms
= make_node (TREE_LIST
);
6554 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6556 struct c_parm
*parm
;
6557 c_parser_consume_token (parser
);
6558 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6561 c_parser_consume_token (parser
);
6564 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6567 parms
= chainon (parms
,
6568 build_tree_list (NULL_TREE
, grokparm (parm
)));
6572 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6575 /* Parse an objc-type-name.
6578 objc-type-qualifiers[opt] type-name
6579 objc-type-qualifiers[opt]
6581 objc-type-qualifiers:
6583 objc-type-qualifiers objc-type-qualifier
6585 objc-type-qualifier: one of
6586 in out inout bycopy byref oneway
6590 c_parser_objc_type_name (c_parser
*parser
)
6592 tree quals
= NULL_TREE
;
6593 struct c_type_name
*type_name
= NULL
;
6594 tree type
= NULL_TREE
;
6597 c_token
*token
= c_parser_peek_token (parser
);
6598 if (token
->type
== CPP_KEYWORD
6599 && (token
->keyword
== RID_IN
6600 || token
->keyword
== RID_OUT
6601 || token
->keyword
== RID_INOUT
6602 || token
->keyword
== RID_BYCOPY
6603 || token
->keyword
== RID_BYREF
6604 || token
->keyword
== RID_ONEWAY
))
6606 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6607 c_parser_consume_token (parser
);
6612 if (c_parser_next_token_starts_typename (parser
))
6613 type_name
= c_parser_type_name (parser
);
6615 type
= groktypename (type_name
, NULL
, NULL
);
6616 return build_tree_list (quals
, type
);
6619 /* Parse objc-protocol-refs.
6626 c_parser_objc_protocol_refs (c_parser
*parser
)
6628 tree list
= NULL_TREE
;
6629 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6630 c_parser_consume_token (parser
);
6631 /* Any identifiers, including those declared as type names, are OK
6636 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6638 c_parser_error (parser
, "expected identifier");
6641 id
= c_parser_peek_token (parser
)->value
;
6642 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6643 c_parser_consume_token (parser
);
6644 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6645 c_parser_consume_token (parser
);
6649 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6653 /* Parse an objc-try-catch-statement.
6655 objc-try-catch-statement:
6656 @try compound-statement objc-catch-list[opt]
6657 @try compound-statement objc-catch-list[opt] @finally compound-statement
6660 @catch ( parameter-declaration ) compound-statement
6661 objc-catch-list @catch ( parameter-declaration ) compound-statement
6665 c_parser_objc_try_catch_statement (c_parser
*parser
)
6669 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6670 c_parser_consume_token (parser
);
6671 loc
= c_parser_peek_token (parser
)->location
;
6672 stmt
= c_parser_compound_statement (parser
);
6673 objc_begin_try_stmt (loc
, stmt
);
6674 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6676 struct c_parm
*parm
;
6677 c_parser_consume_token (parser
);
6678 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6680 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6683 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6687 objc_begin_catch_clause (grokparm (parm
));
6688 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6689 c_parser_compound_statement_nostart (parser
);
6690 objc_finish_catch_clause ();
6692 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6696 c_parser_consume_token (parser
);
6697 finloc
= c_parser_peek_token (parser
)->location
;
6698 finstmt
= c_parser_compound_statement (parser
);
6699 objc_build_finally_clause (finloc
, finstmt
);
6701 objc_finish_try_stmt ();
6704 /* Parse an objc-synchronized-statement.
6706 objc-synchronized-statement:
6707 @synchronized ( expression ) compound-statement
6711 c_parser_objc_synchronized_statement (c_parser
*parser
)
6715 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6716 c_parser_consume_token (parser
);
6717 loc
= c_parser_peek_token (parser
)->location
;
6718 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6720 expr
= c_parser_expression (parser
).value
;
6721 expr
= c_fully_fold (expr
, false, NULL
);
6722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6725 expr
= error_mark_node
;
6726 stmt
= c_parser_compound_statement (parser
);
6727 objc_build_synchronized (loc
, expr
, stmt
);
6730 /* Parse an objc-selector; return NULL_TREE without an error if the
6731 next token is not an objc-selector.
6736 enum struct union if else while do for switch case default
6737 break continue return goto asm sizeof typeof __alignof
6738 unsigned long const short volatile signed restrict _Complex
6739 in out inout bycopy byref oneway int char float double void _Bool
6741 ??? Why this selection of keywords but not, for example, storage
6742 class specifiers? */
6745 c_parser_objc_selector (c_parser
*parser
)
6747 c_token
*token
= c_parser_peek_token (parser
);
6748 tree value
= token
->value
;
6749 if (token
->type
== CPP_NAME
)
6751 c_parser_consume_token (parser
);
6754 if (token
->type
!= CPP_KEYWORD
)
6756 switch (token
->keyword
)
6797 c_parser_consume_token (parser
);
6804 /* Parse an objc-selector-arg.
6808 objc-keywordname-list
6810 objc-keywordname-list:
6812 objc-keywordname-list objc-keywordname
6820 c_parser_objc_selector_arg (c_parser
*parser
)
6822 tree sel
= c_parser_objc_selector (parser
);
6823 tree list
= NULL_TREE
;
6824 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6828 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6830 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6831 sel
= c_parser_objc_selector (parser
);
6832 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6838 /* Parse an objc-receiver.
6847 c_parser_objc_receiver (c_parser
*parser
)
6849 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6850 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6851 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6853 tree id
= c_parser_peek_token (parser
)->value
;
6854 c_parser_consume_token (parser
);
6855 return objc_get_class_reference (id
);
6857 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6860 /* Parse objc-message-args.
6864 objc-keywordarg-list
6866 objc-keywordarg-list:
6868 objc-keywordarg-list objc-keywordarg
6871 objc-selector : objc-keywordexpr
6876 c_parser_objc_message_args (c_parser
*parser
)
6878 tree sel
= c_parser_objc_selector (parser
);
6879 tree list
= NULL_TREE
;
6880 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6885 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6886 return error_mark_node
;
6887 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6888 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6889 sel
= c_parser_objc_selector (parser
);
6890 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6896 /* Parse an objc-keywordexpr.
6903 c_parser_objc_keywordexpr (c_parser
*parser
)
6906 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6907 if (VEC_length (tree
, expr_list
) == 1)
6909 /* Just return the expression, remove a level of
6911 ret
= VEC_index (tree
, expr_list
, 0);
6915 /* We have a comma expression, we will collapse later. */
6916 ret
= build_tree_list_vec (expr_list
);
6918 release_tree_vector (expr_list
);
6923 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6924 should be considered, statements. ALLOW_STMT is true if we're within
6925 the context of a function and such pragmas are to be allowed. Returns
6926 true if we actually parsed such a pragma. */
6929 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6933 id
= c_parser_peek_token (parser
)->pragma_kind
;
6934 gcc_assert (id
!= PRAGMA_NONE
);
6938 case PRAGMA_OMP_BARRIER
:
6939 if (context
!= pragma_compound
)
6941 if (context
== pragma_stmt
)
6942 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6943 "used in compound statements");
6946 c_parser_omp_barrier (parser
);
6949 case PRAGMA_OMP_FLUSH
:
6950 if (context
!= pragma_compound
)
6952 if (context
== pragma_stmt
)
6953 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6954 "used in compound statements");
6957 c_parser_omp_flush (parser
);
6960 case PRAGMA_OMP_TASKWAIT
:
6961 if (context
!= pragma_compound
)
6963 if (context
== pragma_stmt
)
6964 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6965 "used in compound statements");
6968 c_parser_omp_taskwait (parser
);
6971 case PRAGMA_OMP_THREADPRIVATE
:
6972 c_parser_omp_threadprivate (parser
);
6975 case PRAGMA_OMP_SECTION
:
6976 error_at (c_parser_peek_token (parser
)->location
,
6977 "%<#pragma omp section%> may only be used in "
6978 "%<#pragma omp sections%> construct");
6979 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6982 case PRAGMA_GCC_PCH_PREPROCESS
:
6983 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6984 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6988 if (id
< PRAGMA_FIRST_EXTERNAL
)
6990 if (context
== pragma_external
)
6993 c_parser_error (parser
, "expected declaration specifiers");
6994 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6997 c_parser_omp_construct (parser
);
7003 c_parser_consume_pragma (parser
);
7004 c_invoke_pragma_handler (id
);
7006 /* Skip to EOL, but suppress any error message. Those will have been
7007 generated by the handler routine through calling error, as opposed
7008 to calling c_parser_error. */
7009 parser
->error
= true;
7010 c_parser_skip_to_pragma_eol (parser
);
7015 /* The interface the pragma parsers have to the lexer. */
7018 pragma_lex (tree
*value
)
7020 c_token
*tok
= c_parser_peek_token (the_parser
);
7021 enum cpp_ttype ret
= tok
->type
;
7023 *value
= tok
->value
;
7024 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7028 if (ret
== CPP_KEYWORD
)
7030 c_parser_consume_token (the_parser
);
7037 c_parser_pragma_pch_preprocess (c_parser
*parser
)
7041 c_parser_consume_pragma (parser
);
7042 if (c_parser_next_token_is (parser
, CPP_STRING
))
7044 name
= c_parser_peek_token (parser
)->value
;
7045 c_parser_consume_token (parser
);
7048 c_parser_error (parser
, "expected string literal");
7049 c_parser_skip_to_pragma_eol (parser
);
7052 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
7055 /* OpenMP 2.5 parsing routines. */
7057 /* Returns name of the next clause.
7058 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7059 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7060 returned and the token is consumed. */
7062 static pragma_omp_clause
7063 c_parser_omp_clause_name (c_parser
*parser
)
7065 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7067 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7068 result
= PRAGMA_OMP_CLAUSE_IF
;
7069 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7070 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7071 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7073 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7078 if (!strcmp ("collapse", p
))
7079 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7080 else if (!strcmp ("copyin", p
))
7081 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7082 else if (!strcmp ("copyprivate", p
))
7083 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7086 if (!strcmp ("firstprivate", p
))
7087 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7090 if (!strcmp ("lastprivate", p
))
7091 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7094 if (!strcmp ("nowait", p
))
7095 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7096 else if (!strcmp ("num_threads", p
))
7097 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7100 if (!strcmp ("ordered", p
))
7101 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7104 if (!strcmp ("private", p
))
7105 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7108 if (!strcmp ("reduction", p
))
7109 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7112 if (!strcmp ("schedule", p
))
7113 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7114 else if (!strcmp ("shared", p
))
7115 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7118 if (!strcmp ("untied", p
))
7119 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7124 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7125 c_parser_consume_token (parser
);
7130 /* Validate that a clause of the given type does not already exist. */
7133 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7138 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7139 if (OMP_CLAUSE_CODE (c
) == code
)
7141 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7142 error_at (loc
, "too many %qs clauses", name
);
7150 variable-list , identifier
7152 If KIND is nonzero, create the appropriate node and install the
7153 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7154 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7156 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7157 return the list created. */
7160 c_parser_omp_variable_list (c_parser
*parser
,
7161 location_t clause_loc
,
7162 enum omp_clause_code kind
,
7165 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7166 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7167 c_parser_error (parser
, "expected identifier");
7169 while (c_parser_next_token_is (parser
, CPP_NAME
)
7170 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7172 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7175 undeclared_variable (c_parser_peek_token (parser
)->location
,
7176 c_parser_peek_token (parser
)->value
);
7177 else if (t
== error_mark_node
)
7181 tree u
= build_omp_clause (clause_loc
, kind
);
7182 OMP_CLAUSE_DECL (u
) = t
;
7183 OMP_CLAUSE_CHAIN (u
) = list
;
7187 list
= tree_cons (t
, NULL_TREE
, list
);
7189 c_parser_consume_token (parser
);
7191 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7194 c_parser_consume_token (parser
);
7200 /* Similarly, but expect leading and trailing parenthesis. This is a very
7201 common case for omp clauses. */
7204 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7207 /* The clauses location. */
7208 location_t loc
= c_parser_peek_token (parser
)->location
;
7210 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7212 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7213 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7219 collapse ( constant-expression ) */
7222 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7224 tree c
, num
= error_mark_node
;
7228 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7230 loc
= c_parser_peek_token (parser
)->location
;
7231 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7233 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7236 if (num
== error_mark_node
)
7238 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7239 || !host_integerp (num
, 0)
7240 || (n
= tree_low_cst (num
, 0)) <= 0
7244 "collapse argument needs positive constant integer expression");
7247 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7248 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7249 OMP_CLAUSE_CHAIN (c
) = list
;
7254 copyin ( variable-list ) */
7257 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7259 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7263 copyprivate ( variable-list ) */
7266 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7268 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7272 default ( shared | none ) */
7275 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7277 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7278 location_t loc
= c_parser_peek_token (parser
)->location
;
7281 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7283 if (c_parser_next_token_is (parser
, CPP_NAME
))
7285 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7290 if (strcmp ("none", p
) != 0)
7292 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7296 if (strcmp ("shared", p
) != 0)
7298 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7305 c_parser_consume_token (parser
);
7310 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7312 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7314 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7317 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7318 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7319 OMP_CLAUSE_CHAIN (c
) = list
;
7320 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7326 firstprivate ( variable-list ) */
7329 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7331 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7335 if ( expression ) */
7338 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7340 location_t loc
= c_parser_peek_token (parser
)->location
;
7341 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7343 tree t
= c_parser_paren_condition (parser
);
7346 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7348 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7349 OMP_CLAUSE_IF_EXPR (c
) = t
;
7350 OMP_CLAUSE_CHAIN (c
) = list
;
7354 c_parser_error (parser
, "expected %<(%>");
7360 lastprivate ( variable-list ) */
7363 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7365 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7372 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7375 location_t loc
= c_parser_peek_token (parser
)->location
;
7377 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7379 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7380 OMP_CLAUSE_CHAIN (c
) = list
;
7385 num_threads ( expression ) */
7388 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7390 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7391 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7393 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7394 tree c
, t
= c_parser_expression (parser
).value
;
7395 t
= c_fully_fold (t
, false, NULL
);
7397 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7399 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7401 c_parser_error (parser
, "expected integer expression");
7405 /* Attempt to statically determine when the number isn't positive. */
7406 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7407 build_int_cst (TREE_TYPE (t
), 0));
7408 if (CAN_HAVE_LOCATION_P (c
))
7409 SET_EXPR_LOCATION (c
, expr_loc
);
7410 if (c
== boolean_true_node
)
7412 warning_at (expr_loc
, 0,
7413 "%<num_threads%> value must be positive");
7414 t
= integer_one_node
;
7417 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7419 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7420 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7421 OMP_CLAUSE_CHAIN (c
) = list
;
7432 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7436 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7438 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7439 OMP_CLAUSE_ORDERED
);
7440 OMP_CLAUSE_CHAIN (c
) = list
;
7446 private ( variable-list ) */
7449 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7451 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7455 reduction ( reduction-operator : variable-list )
7458 One of: + * - & ^ | && || */
7461 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7463 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7464 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7466 enum tree_code code
;
7468 switch (c_parser_peek_token (parser
)->type
)
7480 code
= BIT_AND_EXPR
;
7483 code
= BIT_XOR_EXPR
;
7486 code
= BIT_IOR_EXPR
;
7489 code
= TRUTH_ANDIF_EXPR
;
7492 code
= TRUTH_ORIF_EXPR
;
7495 c_parser_error (parser
,
7496 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7497 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7498 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7501 c_parser_consume_token (parser
);
7502 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7506 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7507 OMP_CLAUSE_REDUCTION
, list
);
7508 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7509 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7513 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7519 schedule ( schedule-kind )
7520 schedule ( schedule-kind , expression )
7523 static | dynamic | guided | runtime | auto
7527 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7530 location_t loc
= c_parser_peek_token (parser
)->location
;
7532 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7535 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7537 if (c_parser_next_token_is (parser
, CPP_NAME
))
7539 tree kind
= c_parser_peek_token (parser
)->value
;
7540 const char *p
= IDENTIFIER_POINTER (kind
);
7545 if (strcmp ("dynamic", p
) != 0)
7547 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7551 if (strcmp ("guided", p
) != 0)
7553 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7557 if (strcmp ("runtime", p
) != 0)
7559 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7566 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7567 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7568 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7569 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7573 c_parser_consume_token (parser
);
7574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7577 c_parser_consume_token (parser
);
7579 here
= c_parser_peek_token (parser
)->location
;
7580 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7581 t
= c_fully_fold (t
, false, NULL
);
7583 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7584 error_at (here
, "schedule %<runtime%> does not take "
7585 "a %<chunk_size%> parameter");
7586 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7588 "schedule %<auto%> does not take "
7589 "a %<chunk_size%> parameter");
7590 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7591 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7593 c_parser_error (parser
, "expected integer expression");
7595 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7598 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7599 "expected %<,%> or %<)%>");
7601 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7602 OMP_CLAUSE_CHAIN (c
) = list
;
7606 c_parser_error (parser
, "invalid schedule kind");
7607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7612 shared ( variable-list ) */
7615 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7617 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7624 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7628 /* FIXME: Should we allow duplicates? */
7629 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7631 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7633 OMP_CLAUSE_CHAIN (c
) = list
;
7638 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7639 is a bitmask in MASK. Return the list of clauses found; the result
7640 of clause default goes in *pdefault. */
7643 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7646 tree clauses
= NULL
;
7649 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7652 pragma_omp_clause c_kind
;
7654 tree prev
= clauses
;
7656 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7657 c_parser_consume_token (parser
);
7660 here
= c_parser_peek_token (parser
)->location
;
7661 c_kind
= c_parser_omp_clause_name (parser
);
7665 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7666 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7667 c_name
= "collapse";
7669 case PRAGMA_OMP_CLAUSE_COPYIN
:
7670 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7673 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7674 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7675 c_name
= "copyprivate";
7677 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7678 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7681 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7682 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7683 c_name
= "firstprivate";
7685 case PRAGMA_OMP_CLAUSE_IF
:
7686 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7689 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7690 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7691 c_name
= "lastprivate";
7693 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7694 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7697 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7698 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7699 c_name
= "num_threads";
7701 case PRAGMA_OMP_CLAUSE_ORDERED
:
7702 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7705 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7706 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7709 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7710 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7711 c_name
= "reduction";
7713 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7714 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7715 c_name
= "schedule";
7717 case PRAGMA_OMP_CLAUSE_SHARED
:
7718 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7721 case PRAGMA_OMP_CLAUSE_UNTIED
:
7722 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7726 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7730 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7732 /* Remove the invalid clause(s) from the list to avoid
7733 confusing the rest of the compiler. */
7735 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7740 c_parser_skip_to_pragma_eol (parser
);
7742 return c_finish_omp_clauses (clauses
);
7749 In practice, we're also interested in adding the statement to an
7750 outer node. So it is convenient if we work around the fact that
7751 c_parser_statement calls add_stmt. */
7754 c_parser_omp_structured_block (c_parser
*parser
)
7756 tree stmt
= push_stmt_list ();
7757 c_parser_statement (parser
);
7758 return pop_stmt_list (stmt
);
7762 # pragma omp atomic new-line
7766 x binop= expr | x++ | ++x | x-- | --x
7768 +, *, -, /, &, ^, |, <<, >>
7770 where x is an lvalue expression with scalar type.
7772 LOC is the location of the #pragma token. */
7775 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
7779 enum tree_code code
;
7780 struct c_expr rhs_expr
;
7782 c_parser_skip_to_pragma_eol (parser
);
7784 lhs
= c_parser_unary_expression (parser
).value
;
7785 lhs
= c_fully_fold (lhs
, false, NULL
);
7786 switch (TREE_CODE (lhs
))
7790 c_parser_skip_to_end_of_block_or_statement (parser
);
7793 case PREINCREMENT_EXPR
:
7794 case POSTINCREMENT_EXPR
:
7795 lhs
= TREE_OPERAND (lhs
, 0);
7797 rhs
= integer_one_node
;
7800 case PREDECREMENT_EXPR
:
7801 case POSTDECREMENT_EXPR
:
7802 lhs
= TREE_OPERAND (lhs
, 0);
7804 rhs
= integer_one_node
;
7808 switch (c_parser_peek_token (parser
)->type
)
7814 code
= TRUNC_DIV_EXPR
;
7829 code
= BIT_AND_EXPR
;
7832 code
= BIT_IOR_EXPR
;
7835 code
= BIT_XOR_EXPR
;
7838 c_parser_error (parser
,
7839 "invalid operator for %<#pragma omp atomic%>");
7843 c_parser_consume_token (parser
);
7845 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
7846 rhs_expr
= c_parser_expression (parser
);
7847 rhs_expr
= default_function_array_conversion (rhs_loc
, rhs_expr
);
7849 rhs
= rhs_expr
.value
;
7850 rhs
= c_fully_fold (rhs
, false, NULL
);
7853 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
7854 if (stmt
!= error_mark_node
)
7856 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7861 # pragma omp barrier new-line
7865 c_parser_omp_barrier (c_parser
*parser
)
7867 location_t loc
= c_parser_peek_token (parser
)->location
;
7868 c_parser_consume_pragma (parser
);
7869 c_parser_skip_to_pragma_eol (parser
);
7871 c_finish_omp_barrier (loc
);
7875 # pragma omp critical [(name)] new-line
7878 LOC is the location of the #pragma itself. */
7881 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
7883 tree stmt
, name
= NULL
;
7885 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7887 c_parser_consume_token (parser
);
7888 if (c_parser_next_token_is (parser
, CPP_NAME
))
7890 name
= c_parser_peek_token (parser
)->value
;
7891 c_parser_consume_token (parser
);
7892 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7895 c_parser_error (parser
, "expected identifier");
7897 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7898 c_parser_error (parser
, "expected %<(%> or end of line");
7899 c_parser_skip_to_pragma_eol (parser
);
7901 stmt
= c_parser_omp_structured_block (parser
);
7902 return c_finish_omp_critical (loc
, stmt
, name
);
7906 # pragma omp flush flush-vars[opt] new-line
7909 ( variable-list ) */
7912 c_parser_omp_flush (c_parser
*parser
)
7914 location_t loc
= c_parser_peek_token (parser
)->location
;
7915 c_parser_consume_pragma (parser
);
7916 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7917 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7918 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7919 c_parser_error (parser
, "expected %<(%> or end of line");
7920 c_parser_skip_to_pragma_eol (parser
);
7922 c_finish_omp_flush (loc
);
7925 /* Parse the restricted form of the for statement allowed by OpenMP.
7926 The real trick here is to determine the loop control variable early
7927 so that we can push a new decl if necessary to make it private.
7928 LOC is the location of the OMP in "#pragma omp". */
7931 c_parser_omp_for_loop (location_t loc
,
7932 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7934 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7935 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7936 bool fail
= false, open_brace_parsed
= false;
7937 int i
, collapse
= 1, nbraces
= 0;
7940 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7941 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7942 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7944 gcc_assert (collapse
>= 1);
7946 declv
= make_tree_vec (collapse
);
7947 initv
= make_tree_vec (collapse
);
7948 condv
= make_tree_vec (collapse
);
7949 incrv
= make_tree_vec (collapse
);
7951 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7953 c_parser_error (parser
, "for statement expected");
7956 for_loc
= c_parser_peek_token (parser
)->location
;
7957 c_parser_consume_token (parser
);
7959 for (i
= 0; i
< collapse
; i
++)
7963 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7966 /* Parse the initialization declaration or expression. */
7967 if (c_parser_next_token_starts_declspecs (parser
))
7971 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7972 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7973 decl
= check_for_loop_decls (for_loc
);
7976 if (DECL_INITIAL (decl
) == error_mark_node
)
7977 decl
= error_mark_node
;
7980 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7981 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7983 struct c_expr decl_exp
;
7984 struct c_expr init_exp
;
7985 location_t init_loc
;
7987 decl_exp
= c_parser_postfix_expression (parser
);
7988 decl
= decl_exp
.value
;
7990 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7992 init_loc
= c_parser_peek_token (parser
)->location
;
7993 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7994 init_exp
= default_function_array_conversion (init_loc
, init_exp
);
7995 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7996 NOP_EXPR
, init_loc
, init_exp
.value
,
7997 init_exp
.original_type
);
7998 init
= c_process_expr_stmt (init_loc
, init
);
8000 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8005 c_parser_error (parser
,
8006 "expected iteration declaration or initialization");
8007 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8013 /* Parse the loop condition. */
8015 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
8017 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
8018 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
8020 cond
= cond_expr
.value
;
8021 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
8022 cond
= c_fully_fold (cond
, false, NULL
);
8023 switch (cond_expr
.original_code
)
8031 /* Can't be cond = error_mark_node, because we want to preserve
8032 the location until c_finish_omp_for. */
8033 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
8036 protected_set_expr_location (cond
, cond_loc
);
8038 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8040 /* Parse the increment expression. */
8042 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
8044 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
8046 incr
= c_process_expr_stmt (incr_loc
,
8047 c_parser_expression (parser
).value
);
8049 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8051 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
8055 TREE_VEC_ELT (declv
, i
) = decl
;
8056 TREE_VEC_ELT (initv
, i
) = init
;
8057 TREE_VEC_ELT (condv
, i
) = cond
;
8058 TREE_VEC_ELT (incrv
, i
) = incr
;
8062 if (i
== collapse
- 1)
8065 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8066 in between the collapsed for loops to be still considered perfectly
8067 nested. Hopefully the final version clarifies this.
8068 For now handle (multiple) {'s and empty statements. */
8071 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8073 c_parser_consume_token (parser
);
8076 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8078 c_parser_consume_token (parser
);
8082 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8083 c_parser_consume_token (parser
);
8086 c_parser_error (parser
, "not enough perfectly nested loops");
8089 open_brace_parsed
= true;
8099 nbraces
+= bracecount
;
8102 save_break
= c_break_label
;
8103 c_break_label
= size_one_node
;
8104 save_cont
= c_cont_label
;
8105 c_cont_label
= NULL_TREE
;
8106 body
= push_stmt_list ();
8108 if (open_brace_parsed
)
8110 location_t here
= c_parser_peek_token (parser
)->location
;
8111 stmt
= c_begin_compound_stmt (true);
8112 c_parser_compound_statement_nostart (parser
);
8113 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8116 add_stmt (c_parser_c99_block_statement (parser
));
8119 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8120 SET_EXPR_LOCATION (t
, loc
);
8124 body
= pop_stmt_list (body
);
8125 c_break_label
= save_break
;
8126 c_cont_label
= save_cont
;
8130 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8132 c_parser_consume_token (parser
);
8135 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8136 c_parser_consume_token (parser
);
8139 c_parser_error (parser
, "collapsed loops not perfectly nested");
8142 location_t here
= c_parser_peek_token (parser
)->location
;
8143 stmt
= c_begin_compound_stmt (true);
8145 c_parser_compound_statement_nostart (parser
);
8146 body
= c_end_compound_stmt (here
, stmt
, true);
8153 /* Only bother calling c_finish_omp_for if we haven't already generated
8154 an error from the initialization parsing. */
8157 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8160 if (par_clauses
!= NULL
)
8163 for (c
= par_clauses
; *c
; )
8164 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8165 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8166 c
= &OMP_CLAUSE_CHAIN (*c
);
8169 for (i
= 0; i
< collapse
; i
++)
8170 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8173 c
= &OMP_CLAUSE_CHAIN (*c
);
8174 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8177 "iteration variable %qD should not be firstprivate",
8178 OMP_CLAUSE_DECL (*c
));
8179 *c
= OMP_CLAUSE_CHAIN (*c
);
8183 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8184 change it to shared (decl) in
8185 OMP_PARALLEL_CLAUSES. */
8186 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8187 OMP_CLAUSE_LASTPRIVATE
);
8188 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8189 OMP_CLAUSE_CHAIN (l
) = clauses
;
8191 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8195 OMP_FOR_CLAUSES (stmt
) = clauses
;
8202 /* FIXME diagnostics: LOC below should be the actual location of
8203 this particular for block. We need to build a list of
8204 locations to go along with FOR_BLOCK. */
8205 stmt
= c_end_compound_stmt (loc
, TREE_VALUE (for_block
), true);
8207 for_block
= TREE_CHAIN (for_block
);
8213 #pragma omp for for-clause[optseq] new-line
8216 LOC is the location of the #pragma token.
8219 #define OMP_FOR_CLAUSE_MASK \
8220 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8221 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8222 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8223 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8224 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8225 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8226 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8227 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8230 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8232 tree block
, clauses
, ret
;
8234 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8237 block
= c_begin_compound_stmt (true);
8238 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8239 block
= c_end_compound_stmt (loc
, block
, true);
8246 # pragma omp master new-line
8249 LOC is the location of the #pragma token.
8253 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8255 c_parser_skip_to_pragma_eol (parser
);
8256 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8260 # pragma omp ordered new-line
8263 LOC is the location of the #pragma itself.
8267 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8269 c_parser_skip_to_pragma_eol (parser
);
8270 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8276 { section-sequence }
8279 section-directive[opt] structured-block
8280 section-sequence section-directive structured-block
8282 SECTIONS_LOC is the location of the #pragma omp sections. */
8285 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8288 bool error_suppress
= false;
8291 loc
= c_parser_peek_token (parser
)->location
;
8292 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8294 /* Avoid skipping until the end of the block. */
8295 parser
->error
= false;
8299 stmt
= push_stmt_list ();
8301 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8303 substmt
= push_stmt_list ();
8307 c_parser_statement (parser
);
8309 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8311 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8313 if (c_parser_next_token_is (parser
, CPP_EOF
))
8317 substmt
= pop_stmt_list (substmt
);
8318 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8319 SET_EXPR_LOCATION (substmt
, loc
);
8325 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8327 if (c_parser_next_token_is (parser
, CPP_EOF
))
8330 loc
= c_parser_peek_token (parser
)->location
;
8331 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8333 c_parser_consume_pragma (parser
);
8334 c_parser_skip_to_pragma_eol (parser
);
8335 error_suppress
= false;
8337 else if (!error_suppress
)
8339 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8340 error_suppress
= true;
8343 substmt
= c_parser_omp_structured_block (parser
);
8344 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8345 SET_EXPR_LOCATION (substmt
, loc
);
8348 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8349 "expected %<#pragma omp section%> or %<}%>");
8351 substmt
= pop_stmt_list (stmt
);
8353 stmt
= make_node (OMP_SECTIONS
);
8354 SET_EXPR_LOCATION (stmt
, sections_loc
);
8355 TREE_TYPE (stmt
) = void_type_node
;
8356 OMP_SECTIONS_BODY (stmt
) = substmt
;
8358 return add_stmt (stmt
);
8362 # pragma omp sections sections-clause[optseq] newline
8365 LOC is the location of the #pragma token.
8368 #define OMP_SECTIONS_CLAUSE_MASK \
8369 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8370 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8371 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8372 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8373 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8376 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8378 tree block
, clauses
, ret
;
8380 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8381 "#pragma omp sections");
8383 block
= c_begin_compound_stmt (true);
8384 ret
= c_parser_omp_sections_scope (loc
, parser
);
8386 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8387 block
= c_end_compound_stmt (loc
, block
, true);
8394 # pragma parallel parallel-clause new-line
8395 # pragma parallel for parallel-for-clause new-line
8396 # pragma parallel sections parallel-sections-clause new-line
8398 LOC is the location of the #pragma token.
8401 #define OMP_PARALLEL_CLAUSE_MASK \
8402 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8403 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8404 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8405 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8406 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8407 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8408 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8409 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8412 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8414 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8415 const char *p_name
= "#pragma omp parallel";
8416 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8417 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8419 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8421 c_parser_consume_token (parser
);
8422 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8423 p_name
= "#pragma omp parallel for";
8424 mask
|= OMP_FOR_CLAUSE_MASK
;
8425 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8427 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8429 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8430 if (strcmp (p
, "sections") == 0)
8432 c_parser_consume_token (parser
);
8433 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8434 p_name
= "#pragma omp parallel sections";
8435 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8436 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8440 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8444 case PRAGMA_OMP_PARALLEL
:
8445 block
= c_begin_omp_parallel ();
8446 c_parser_statement (parser
);
8447 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8450 case PRAGMA_OMP_PARALLEL_FOR
:
8451 block
= c_begin_omp_parallel ();
8452 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8453 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8454 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8455 OMP_PARALLEL_COMBINED (stmt
) = 1;
8458 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8459 block
= c_begin_omp_parallel ();
8460 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8461 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8463 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8464 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8465 OMP_PARALLEL_COMBINED (stmt
) = 1;
8476 # pragma omp single single-clause[optseq] new-line
8479 LOC is the location of the #pragma.
8482 #define OMP_SINGLE_CLAUSE_MASK \
8483 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8484 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8485 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8486 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8489 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8491 tree stmt
= make_node (OMP_SINGLE
);
8492 SET_EXPR_LOCATION (stmt
, loc
);
8493 TREE_TYPE (stmt
) = void_type_node
;
8495 OMP_SINGLE_CLAUSES (stmt
)
8496 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8497 "#pragma omp single");
8498 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8500 return add_stmt (stmt
);
8504 # pragma omp task task-clause[optseq] new-line
8506 LOC is the location of the #pragma.
8509 #define OMP_TASK_CLAUSE_MASK \
8510 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8511 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8512 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8513 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8514 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8515 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8518 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8520 tree clauses
, block
;
8522 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8523 "#pragma omp task");
8525 block
= c_begin_omp_task ();
8526 c_parser_statement (parser
);
8527 return c_finish_omp_task (loc
, clauses
, block
);
8531 # pragma omp taskwait new-line
8535 c_parser_omp_taskwait (c_parser
*parser
)
8537 location_t loc
= c_parser_peek_token (parser
)->location
;
8538 c_parser_consume_pragma (parser
);
8539 c_parser_skip_to_pragma_eol (parser
);
8541 c_finish_omp_taskwait (loc
);
8544 /* Main entry point to parsing most OpenMP pragmas. */
8547 c_parser_omp_construct (c_parser
*parser
)
8549 enum pragma_kind p_kind
;
8553 loc
= c_parser_peek_token (parser
)->location
;
8554 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8555 c_parser_consume_pragma (parser
);
8559 case PRAGMA_OMP_ATOMIC
:
8560 c_parser_omp_atomic (loc
, parser
);
8562 case PRAGMA_OMP_CRITICAL
:
8563 stmt
= c_parser_omp_critical (loc
, parser
);
8565 case PRAGMA_OMP_FOR
:
8566 stmt
= c_parser_omp_for (loc
, parser
);
8568 case PRAGMA_OMP_MASTER
:
8569 stmt
= c_parser_omp_master (loc
, parser
);
8571 case PRAGMA_OMP_ORDERED
:
8572 stmt
= c_parser_omp_ordered (loc
, parser
);
8574 case PRAGMA_OMP_PARALLEL
:
8575 stmt
= c_parser_omp_parallel (loc
, parser
);
8577 case PRAGMA_OMP_SECTIONS
:
8578 stmt
= c_parser_omp_sections (loc
, parser
);
8580 case PRAGMA_OMP_SINGLE
:
8581 stmt
= c_parser_omp_single (loc
, parser
);
8583 case PRAGMA_OMP_TASK
:
8584 stmt
= c_parser_omp_task (loc
, parser
);
8591 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
8596 # pragma omp threadprivate (variable-list) */
8599 c_parser_omp_threadprivate (c_parser
*parser
)
8604 c_parser_consume_pragma (parser
);
8605 loc
= c_parser_peek_token (parser
)->location
;
8606 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8608 /* Mark every variable in VARS to be assigned thread local storage. */
8609 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8611 tree v
= TREE_PURPOSE (t
);
8613 /* FIXME diagnostics: Ideally we should keep individual
8614 locations for all the variables in the var list to make the
8615 following errors more precise. Perhaps
8616 c_parser_omp_var_list_parens() should construct a list of
8617 locations to go along with the var list. */
8619 /* If V had already been marked threadprivate, it doesn't matter
8620 whether it had been used prior to this point. */
8621 if (TREE_CODE (v
) != VAR_DECL
)
8622 error_at (loc
, "%qD is not a variable", v
);
8623 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8624 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
8625 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8626 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
8627 else if (TREE_TYPE (v
) == error_mark_node
)
8629 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8630 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
8633 if (! DECL_THREAD_LOCAL_P (v
))
8635 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8636 /* If rtl has been already set for this var, call
8637 make_decl_rtl once again, so that encode_section_info
8638 has a chance to look at the new decl flags. */
8639 if (DECL_RTL_SET_P (v
))
8642 C_DECL_THREADPRIVATE_P (v
) = 1;
8646 c_parser_skip_to_pragma_eol (parser
);
8650 /* Parse a single source file. */
8655 /* Use local storage to begin. If the first token is a pragma, parse it.
8656 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8657 which will cause garbage collection. */
8660 memset (&tparser
, 0, sizeof tparser
);
8661 the_parser
= &tparser
;
8663 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8664 c_parser_pragma_pch_preprocess (&tparser
);
8666 the_parser
= GGC_NEW (c_parser
);
8667 *the_parser
= tparser
;
8669 /* Initialize EH, if we've been told to do so. */
8670 if (flag_exceptions
)
8671 using_eh_for_cleanups ();
8673 c_parser_translation_unit (the_parser
);
8677 #include "gt-c-parser.h"