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"
63 /* Initialization routine for this file. */
68 /* The only initialization required is of the reserved word
79 mask
|= D_ASM
| D_EXT
;
83 if (!c_dialect_objc ())
84 mask
|= D_OBJC
| D_CXX_OBJC
;
86 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
87 for (i
= 0; i
< num_c_common_reswords
; i
++)
89 /* If a keyword is disabled, do not enter it into the table
90 and so create a canonical spelling that isn't a keyword. */
91 if (c_common_reswords
[i
].disable
& mask
)
94 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
96 id
= get_identifier (c_common_reswords
[i
].word
);
97 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
98 C_IS_RESERVED_WORD (id
) = 1;
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
105 C_IS_RESERVED_WORD (id
) = 1;
106 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111 and the C parser. Unlike the C++ lexer, the parser structure
112 stores the lexer information instead of using a separate structure.
113 Identifiers are separated into ordinary identifiers, type names,
114 keywords and some other Objective-C types of identifiers, and some
115 look-ahead is maintained.
117 ??? It might be a good idea to lex the whole file up front (as for
118 C++). It would then be possible to share more of the C and C++
119 lexer code, if desired. */
121 /* The following local token type is used. */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
126 /* More information about the type of a CPP_NAME token. */
127 typedef enum c_id_kind
{
128 /* An ordinary identifier. */
130 /* An identifier declared as a typedef name. */
132 /* An identifier declared as an Objective-C class name. */
134 /* Not an identifier. */
138 /* A single C token after string literal concatenation and conversion
139 of preprocessing tokens to tokens. */
140 typedef struct c_token
GTY (())
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 c_parser
GTY(())
164 /* The look-ahead tokens. */
166 /* How many look-ahead tokens are available (0, 1 or 2). */
168 /* True if a syntax error is being recovered from; false otherwise.
169 c_parser_error sets this flag. It should clear this flag when
170 enough tokens have been consumed to recover from the error. */
171 BOOL_BITFIELD error
: 1;
172 /* True if we're processing a pragma, and shouldn't automatically
173 consume CPP_PRAGMA_EOL. */
174 BOOL_BITFIELD in_pragma
: 1;
175 /* True if we're parsing the outermost block of an if statement. */
176 BOOL_BITFIELD in_if_block
: 1;
177 /* True if we want to lex an untranslated string. */
178 BOOL_BITFIELD lex_untranslated_string
: 1;
179 /* Objective-C specific parser/lexer information. */
180 BOOL_BITFIELD objc_pq_context
: 1;
181 /* The following flag is needed to contextualize Objective-C lexical
182 analysis. In some cases (e.g., 'int NSObject;'), it is
183 undesirable to bind an identifier to an Objective-C class, even
184 if a class with that name exists. */
185 BOOL_BITFIELD objc_need_raw_identifier
: 1;
189 /* The actual parser and external interface. ??? Does this need to be
190 garbage-collected? */
192 static GTY (()) c_parser
*the_parser
;
195 /* Read in and lex a single token, storing it in *TOKEN. */
198 c_lex_one_token (c_parser
*parser
, c_token
*token
)
200 timevar_push (TV_LEX
);
202 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
203 (parser
->lex_untranslated_string
204 ? C_LEX_STRING_NO_TRANSLATE
: 0));
205 token
->id_kind
= C_ID_NONE
;
206 token
->keyword
= RID_MAX
;
207 token
->pragma_kind
= PRAGMA_NONE
;
215 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
216 if (c_dialect_objc ())
217 parser
->objc_need_raw_identifier
= false;
219 if (C_IS_RESERVED_WORD (token
->value
))
221 enum rid rid_code
= C_RID_CODE (token
->value
);
223 if (rid_code
== RID_CXX_COMPAT_WARN
)
225 warning_at (token
->location
,
227 "identifier %qs conflicts with C++ keyword",
228 IDENTIFIER_POINTER (token
->value
));
230 else if (c_dialect_objc ())
232 if (!objc_is_reserved_word (token
->value
)
233 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
234 || parser
->objc_pq_context
))
236 /* Return the canonical spelling for this keyword. */
237 token
->value
= ridpointers
[(int) rid_code
];
238 token
->type
= CPP_KEYWORD
;
239 token
->keyword
= rid_code
;
245 token
->type
= CPP_KEYWORD
;
246 token
->keyword
= rid_code
;
251 decl
= lookup_name (token
->value
);
254 if (TREE_CODE (decl
) == TYPE_DECL
)
256 token
->id_kind
= C_ID_TYPENAME
;
260 else if (c_dialect_objc ())
262 tree objc_interface_decl
= objc_is_class_name (token
->value
);
263 /* Objective-C class names are in the same namespace as
264 variables and typedefs, and hence are shadowed by local
266 if (objc_interface_decl
267 && (global_bindings_p ()
268 || (!objc_force_identifier
&& !decl
)))
270 token
->value
= objc_interface_decl
;
271 token
->id_kind
= C_ID_CLASSNAME
;
275 token
->id_kind
= C_ID_ID
;
279 /* This only happens in Objective-C; it must be a keyword. */
280 token
->type
= CPP_KEYWORD
;
281 token
->keyword
= C_RID_CODE (token
->value
);
285 case CPP_CLOSE_PAREN
:
287 /* These tokens may affect the interpretation of any identifiers
288 following, if doing Objective-C. */
289 if (c_dialect_objc ())
290 parser
->objc_need_raw_identifier
= false;
293 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
294 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
300 timevar_pop (TV_LEX
);
303 /* Return a pointer to the next token from PARSER, reading it in if
306 static inline c_token
*
307 c_parser_peek_token (c_parser
*parser
)
309 if (parser
->tokens_avail
== 0)
311 c_lex_one_token (parser
, &parser
->tokens
[0]);
312 parser
->tokens_avail
= 1;
314 return &parser
->tokens
[0];
317 /* Return true if the next token from PARSER has the indicated
321 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
323 return c_parser_peek_token (parser
)->type
== type
;
326 /* Return true if the next token from PARSER does not have the
330 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
332 return !c_parser_next_token_is (parser
, type
);
335 /* Return true if the next token from PARSER is the indicated
339 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
341 return c_parser_peek_token (parser
)->keyword
== keyword
;
344 /* Return true if TOKEN can start a type name,
347 c_token_starts_typename (c_token
*token
)
352 switch (token
->id_kind
)
359 gcc_assert (c_dialect_objc ());
365 switch (token
->keyword
)
397 if (c_dialect_objc ())
405 /* Return true if the next token from PARSER can start a type name,
408 c_parser_next_token_starts_typename (c_parser
*parser
)
410 c_token
*token
= c_parser_peek_token (parser
);
411 return c_token_starts_typename (token
);
414 /* Return true if TOKEN can start declaration specifiers, false
417 c_token_starts_declspecs (c_token
*token
)
422 switch (token
->id_kind
)
429 gcc_assert (c_dialect_objc ());
435 switch (token
->keyword
)
474 if (c_dialect_objc ())
482 /* Return true if the next token from PARSER can start declaration
483 specifiers, false otherwise. */
485 c_parser_next_token_starts_declspecs (c_parser
*parser
)
487 c_token
*token
= c_parser_peek_token (parser
);
488 return c_token_starts_declspecs (token
);
491 /* Return a pointer to the next-but-one token from PARSER, reading it
492 in if necessary. The next token is already read in. */
495 c_parser_peek_2nd_token (c_parser
*parser
)
497 if (parser
->tokens_avail
>= 2)
498 return &parser
->tokens
[1];
499 gcc_assert (parser
->tokens_avail
== 1);
500 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
501 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
502 c_lex_one_token (parser
, &parser
->tokens
[1]);
503 parser
->tokens_avail
= 2;
504 return &parser
->tokens
[1];
507 /* Consume the next token from PARSER. */
510 c_parser_consume_token (c_parser
*parser
)
512 gcc_assert (parser
->tokens_avail
>= 1);
513 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
514 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
515 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
516 if (parser
->tokens_avail
== 2)
517 parser
->tokens
[0] = parser
->tokens
[1];
518 parser
->tokens_avail
--;
521 /* Expect the current token to be a #pragma. Consume it and remember
522 that we've begun parsing a pragma. */
525 c_parser_consume_pragma (c_parser
*parser
)
527 gcc_assert (!parser
->in_pragma
);
528 gcc_assert (parser
->tokens_avail
>= 1);
529 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
530 if (parser
->tokens_avail
== 2)
531 parser
->tokens
[0] = parser
->tokens
[1];
532 parser
->tokens_avail
--;
533 parser
->in_pragma
= true;
536 /* Update the globals input_location and in_system_header from
539 c_parser_set_source_position_from_token (c_token
*token
)
541 if (token
->type
!= CPP_EOF
)
543 input_location
= token
->location
;
547 /* Issue a diagnostic of the form
548 FILE:LINE: MESSAGE before TOKEN
549 where TOKEN is the next token in the input stream of PARSER.
550 MESSAGE (specified by the caller) is usually of the form "expected
553 Do not issue a diagnostic if still recovering from an error.
555 ??? This is taken from the C++ parser, but building up messages in
556 this way is not i18n-friendly and some other approach should be
560 c_parser_error (c_parser
*parser
, const char *gmsgid
)
562 c_token
*token
= c_parser_peek_token (parser
);
565 parser
->error
= true;
568 /* This diagnostic makes more sense if it is tagged to the line of
569 the token we just peeked at. */
570 c_parser_set_source_position_from_token (token
);
571 c_parse_error (gmsgid
,
572 /* Because c_parse_error does not understand
573 CPP_KEYWORD, keywords are treated like
575 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
579 /* If the next token is of the indicated TYPE, consume it. Otherwise,
580 issue the error MSGID. If MSGID is NULL then a message has already
581 been produced and no message will be produced this time. Returns
582 true if found, false otherwise. */
585 c_parser_require (c_parser
*parser
,
589 if (c_parser_next_token_is (parser
, type
))
591 c_parser_consume_token (parser
);
596 c_parser_error (parser
, msgid
);
601 /* If the next token is the indicated keyword, consume it. Otherwise,
602 issue the error MSGID. Returns true if found, false otherwise. */
605 c_parser_require_keyword (c_parser
*parser
,
609 if (c_parser_next_token_is_keyword (parser
, keyword
))
611 c_parser_consume_token (parser
);
616 c_parser_error (parser
, msgid
);
621 /* Like c_parser_require, except that tokens will be skipped until the
622 desired token is found. An error message is still produced if the
623 next token is not as expected. If MSGID is NULL then a message has
624 already been produced and no message will be produced this
628 c_parser_skip_until_found (c_parser
*parser
,
632 unsigned nesting_depth
= 0;
634 if (c_parser_require (parser
, type
, msgid
))
637 /* Skip tokens until the desired token is found. */
640 /* Peek at the next token. */
641 c_token
*token
= c_parser_peek_token (parser
);
642 /* If we've reached the token we want, consume it and stop. */
643 if (token
->type
== type
&& !nesting_depth
)
645 c_parser_consume_token (parser
);
649 /* If we've run out of tokens, stop. */
650 if (token
->type
== CPP_EOF
)
652 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
654 if (token
->type
== CPP_OPEN_BRACE
655 || token
->type
== CPP_OPEN_PAREN
656 || token
->type
== CPP_OPEN_SQUARE
)
658 else if (token
->type
== CPP_CLOSE_BRACE
659 || token
->type
== CPP_CLOSE_PAREN
660 || token
->type
== CPP_CLOSE_SQUARE
)
662 if (nesting_depth
-- == 0)
665 /* Consume this token. */
666 c_parser_consume_token (parser
);
668 parser
->error
= false;
671 /* Skip tokens until the end of a parameter is found, but do not
672 consume the comma, semicolon or closing delimiter. */
675 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
677 unsigned nesting_depth
= 0;
681 c_token
*token
= c_parser_peek_token (parser
);
682 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
685 /* If we've run out of tokens, stop. */
686 if (token
->type
== CPP_EOF
)
688 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
690 if (token
->type
== CPP_OPEN_BRACE
691 || token
->type
== CPP_OPEN_PAREN
692 || token
->type
== CPP_OPEN_SQUARE
)
694 else if (token
->type
== CPP_CLOSE_BRACE
695 || token
->type
== CPP_CLOSE_PAREN
696 || token
->type
== CPP_CLOSE_SQUARE
)
698 if (nesting_depth
-- == 0)
701 /* Consume this token. */
702 c_parser_consume_token (parser
);
704 parser
->error
= false;
707 /* Expect to be at the end of the pragma directive and consume an
708 end of line marker. */
711 c_parser_skip_to_pragma_eol (c_parser
*parser
)
713 gcc_assert (parser
->in_pragma
);
714 parser
->in_pragma
= false;
716 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
719 c_token
*token
= c_parser_peek_token (parser
);
720 if (token
->type
== CPP_EOF
)
722 if (token
->type
== CPP_PRAGMA_EOL
)
724 c_parser_consume_token (parser
);
727 c_parser_consume_token (parser
);
730 parser
->error
= false;
733 /* Skip tokens until we have consumed an entire block, or until we
734 have consumed a non-nested ';'. */
737 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
739 unsigned nesting_depth
= 0;
740 bool save_error
= parser
->error
;
746 /* Peek at the next token. */
747 token
= c_parser_peek_token (parser
);
755 if (parser
->in_pragma
)
760 /* If the next token is a ';', we have reached the
761 end of the statement. */
764 /* Consume the ';'. */
765 c_parser_consume_token (parser
);
770 case CPP_CLOSE_BRACE
:
771 /* If the next token is a non-nested '}', then we have
772 reached the end of the current block. */
773 if (nesting_depth
== 0 || --nesting_depth
== 0)
775 c_parser_consume_token (parser
);
781 /* If it the next token is a '{', then we are entering a new
782 block. Consume the entire block. */
787 /* If we see a pragma, consume the whole thing at once. We
788 have some safeguards against consuming pragmas willy-nilly.
789 Normally, we'd expect to be here with parser->error set,
790 which disables these safeguards. But it's possible to get
791 here for secondary error recovery, after parser->error has
793 c_parser_consume_pragma (parser
);
794 c_parser_skip_to_pragma_eol (parser
);
795 parser
->error
= save_error
;
802 c_parser_consume_token (parser
);
806 parser
->error
= false;
809 /* CPP's options (initialized by c-opts.c). */
810 extern cpp_options
*cpp_opts
;
812 /* Save the warning flags which are controlled by __extension__. */
815 disable_extension_diagnostics (void)
818 | (warn_pointer_arith
<< 1)
819 | (warn_traditional
<< 2)
821 | (warn_long_long
<< 4)
822 | (cpp_opts
->warn_long_long
<< 5));
823 cpp_opts
->pedantic
= pedantic
= 0;
824 warn_pointer_arith
= 0;
825 cpp_opts
->warn_traditional
= warn_traditional
= 0;
828 cpp_opts
->warn_long_long
= 0;
832 /* Restore the warning flags which are controlled by __extension__.
833 FLAGS is the return value from disable_extension_diagnostics. */
836 restore_extension_diagnostics (int flags
)
838 cpp_opts
->pedantic
= pedantic
= flags
& 1;
839 warn_pointer_arith
= (flags
>> 1) & 1;
840 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
841 flag_iso
= (flags
>> 3) & 1;
842 warn_long_long
= (flags
>> 4) & 1;
843 cpp_opts
->warn_long_long
= (flags
>> 5) & 1;
846 /* Possibly kinds of declarator to parse. */
847 typedef enum c_dtr_syn
{
848 /* A normal declarator with an identifier. */
850 /* An abstract declarator (maybe empty). */
852 /* A parameter declarator: may be either, but after a type name does
853 not redeclare a typedef name as an identifier if it can
854 alternatively be interpreted as a typedef name; see DR#009,
855 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
856 following DR#249. For example, given a typedef T, "int T" and
857 "int *T" are valid parameter declarations redeclaring T, while
858 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
859 abstract declarators rather than involving redundant parentheses;
860 the same applies with attributes inside the parentheses before
865 static void c_parser_external_declaration (c_parser
*);
866 static void c_parser_asm_definition (c_parser
*);
867 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
868 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
870 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
871 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
872 static tree
c_parser_struct_declaration (c_parser
*);
873 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
874 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
876 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
878 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
880 struct c_declarator
*);
881 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
882 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
883 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
884 static tree
c_parser_simple_asm_expr (c_parser
*);
885 static tree
c_parser_attributes (c_parser
*);
886 static struct c_type_name
*c_parser_type_name (c_parser
*);
887 static struct c_expr
c_parser_initializer (c_parser
*);
888 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
889 static void c_parser_initelt (c_parser
*);
890 static void c_parser_initval (c_parser
*, struct c_expr
*);
891 static tree
c_parser_compound_statement (c_parser
*);
892 static void c_parser_compound_statement_nostart (c_parser
*);
893 static void c_parser_label (c_parser
*);
894 static void c_parser_statement (c_parser
*);
895 static void c_parser_statement_after_labels (c_parser
*);
896 static void c_parser_if_statement (c_parser
*);
897 static void c_parser_switch_statement (c_parser
*);
898 static void c_parser_while_statement (c_parser
*);
899 static void c_parser_do_statement (c_parser
*);
900 static void c_parser_for_statement (c_parser
*);
901 static tree
c_parser_asm_statement (c_parser
*);
902 static tree
c_parser_asm_operands (c_parser
*, bool);
903 static tree
c_parser_asm_clobbers (c_parser
*);
904 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
905 static struct c_expr
c_parser_conditional_expression (c_parser
*,
907 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
908 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
909 static struct c_expr
c_parser_unary_expression (c_parser
*);
910 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
911 static struct c_expr
c_parser_alignof_expression (c_parser
*);
912 static struct c_expr
c_parser_postfix_expression (c_parser
*);
913 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
914 struct c_type_name
*);
915 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
917 static struct c_expr
c_parser_expression (c_parser
*);
918 static struct c_expr
c_parser_expression_conv (c_parser
*);
919 static tree
c_parser_expr_list (c_parser
*, bool, bool);
920 static void c_parser_omp_construct (c_parser
*);
921 static void c_parser_omp_threadprivate (c_parser
*);
922 static void c_parser_omp_barrier (c_parser
*);
923 static void c_parser_omp_flush (c_parser
*);
924 static void c_parser_omp_taskwait (c_parser
*);
926 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
927 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
929 /* These Objective-C parser functions are only ever called when
930 compiling Objective-C. */
931 static void c_parser_objc_class_definition (c_parser
*);
932 static void c_parser_objc_class_instance_variables (c_parser
*);
933 static void c_parser_objc_class_declaration (c_parser
*);
934 static void c_parser_objc_alias_declaration (c_parser
*);
935 static void c_parser_objc_protocol_definition (c_parser
*);
936 static enum tree_code
c_parser_objc_method_type (c_parser
*);
937 static void c_parser_objc_method_definition (c_parser
*);
938 static void c_parser_objc_methodprotolist (c_parser
*);
939 static void c_parser_objc_methodproto (c_parser
*);
940 static tree
c_parser_objc_method_decl (c_parser
*);
941 static tree
c_parser_objc_type_name (c_parser
*);
942 static tree
c_parser_objc_protocol_refs (c_parser
*);
943 static void c_parser_objc_try_catch_statement (c_parser
*);
944 static void c_parser_objc_synchronized_statement (c_parser
*);
945 static tree
c_parser_objc_selector (c_parser
*);
946 static tree
c_parser_objc_selector_arg (c_parser
*);
947 static tree
c_parser_objc_receiver (c_parser
*);
948 static tree
c_parser_objc_message_args (c_parser
*);
949 static tree
c_parser_objc_keywordexpr (c_parser
*);
951 /* Parse a translation unit (C90 6.7, C99 6.9).
954 external-declarations
956 external-declarations:
958 external-declarations external-declaration
967 c_parser_translation_unit (c_parser
*parser
)
969 if (c_parser_next_token_is (parser
, CPP_EOF
))
971 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
972 "ISO C forbids an empty translation unit");
976 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
980 c_parser_external_declaration (parser
);
981 obstack_free (&parser_obstack
, obstack_position
);
983 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
987 /* Parse an external declaration (C90 6.7, C99 6.9).
989 external-declaration:
995 external-declaration:
998 __extension__ external-declaration
1002 external-declaration:
1003 objc-class-definition
1004 objc-class-declaration
1005 objc-alias-declaration
1006 objc-protocol-definition
1007 objc-method-definition
1012 c_parser_external_declaration (c_parser
*parser
)
1015 switch (c_parser_peek_token (parser
)->type
)
1018 switch (c_parser_peek_token (parser
)->keyword
)
1021 ext
= disable_extension_diagnostics ();
1022 c_parser_consume_token (parser
);
1023 c_parser_external_declaration (parser
);
1024 restore_extension_diagnostics (ext
);
1027 c_parser_asm_definition (parser
);
1029 case RID_AT_INTERFACE
:
1030 case RID_AT_IMPLEMENTATION
:
1031 gcc_assert (c_dialect_objc ());
1032 c_parser_objc_class_definition (parser
);
1035 gcc_assert (c_dialect_objc ());
1036 c_parser_objc_class_declaration (parser
);
1039 gcc_assert (c_dialect_objc ());
1040 c_parser_objc_alias_declaration (parser
);
1042 case RID_AT_PROTOCOL
:
1043 gcc_assert (c_dialect_objc ());
1044 c_parser_objc_protocol_definition (parser
);
1047 gcc_assert (c_dialect_objc ());
1048 c_parser_consume_token (parser
);
1049 objc_finish_implementation ();
1056 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1057 "ISO C does not allow extra %<;%> outside of a function");
1058 c_parser_consume_token (parser
);
1061 c_parser_pragma (parser
, pragma_external
);
1065 if (c_dialect_objc ())
1067 c_parser_objc_method_definition (parser
);
1070 /* Else fall through, and yield a syntax error trying to parse
1071 as a declaration or function definition. */
1074 /* A declaration or a function definition. We can only tell
1075 which after parsing the declaration specifiers, if any, and
1076 the first declarator. */
1077 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1083 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1084 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1085 accepted; otherwise (old-style parameter declarations) only other
1086 declarations are accepted. If NESTED is true, we are inside a
1087 function or parsing old-style parameter declarations; any functions
1088 encountered are nested functions and declaration specifiers are
1089 required; otherwise we are at top level and functions are normal
1090 functions and declaration specifiers may be optional. If EMPTY_OK
1091 is true, empty declarations are OK (subject to all other
1092 constraints); otherwise (old-style parameter declarations) they are
1093 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1094 may start with attributes; otherwise they may not.
1097 declaration-specifiers init-declarator-list[opt] ;
1099 function-definition:
1100 declaration-specifiers[opt] declarator declaration-list[opt]
1105 declaration-list declaration
1107 init-declarator-list:
1109 init-declarator-list , init-declarator
1112 declarator simple-asm-expr[opt] attributes[opt]
1113 declarator simple-asm-expr[opt] attributes[opt] = initializer
1117 nested-function-definition:
1118 declaration-specifiers declarator declaration-list[opt]
1121 The simple-asm-expr and attributes are GNU extensions.
1123 This function does not handle __extension__; that is handled in its
1124 callers. ??? Following the old parser, __extension__ may start
1125 external declarations, declarations in functions and declarations
1126 at the start of "for" loops, but not old-style parameter
1129 C99 requires declaration specifiers in a function definition; the
1130 absence is diagnosed through the diagnosis of implicit int. In GNU
1131 C we also allow but diagnose declarations without declaration
1132 specifiers, but only at top level (elsewhere they conflict with
1138 threadprivate-directive */
1141 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1142 bool nested
, bool start_attr_ok
)
1144 struct c_declspecs
*specs
;
1146 tree all_prefix_attrs
;
1147 bool diagnosed_no_specs
= false;
1148 location_t here
= c_parser_peek_token (parser
)->location
;
1150 specs
= build_null_declspecs ();
1151 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1154 c_parser_skip_to_end_of_block_or_statement (parser
);
1157 if (nested
&& !specs
->declspecs_seen_p
)
1159 c_parser_error (parser
, "expected declaration specifiers");
1160 c_parser_skip_to_end_of_block_or_statement (parser
);
1163 finish_declspecs (specs
);
1164 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1170 shadow_tag_warned (specs
, 1);
1171 pedwarn (here
, 0, "empty declaration");
1173 c_parser_consume_token (parser
);
1176 pending_xref_error ();
1177 prefix_attrs
= specs
->attrs
;
1178 all_prefix_attrs
= prefix_attrs
;
1179 specs
->attrs
= NULL_TREE
;
1182 struct c_declarator
*declarator
;
1185 /* Declaring either one or more declarators (in which case we
1186 should diagnose if there were no declaration specifiers) or a
1187 function definition (in which case the diagnostic for
1188 implicit int suffices). */
1189 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1190 C_DTR_NORMAL
, &dummy
);
1191 if (declarator
== NULL
)
1193 c_parser_skip_to_end_of_block_or_statement (parser
);
1196 if (c_parser_next_token_is (parser
, CPP_EQ
)
1197 || c_parser_next_token_is (parser
, CPP_COMMA
)
1198 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1199 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1200 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1202 tree asm_name
= NULL_TREE
;
1203 tree postfix_attrs
= NULL_TREE
;
1204 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1206 diagnosed_no_specs
= true;
1207 pedwarn (here
, 0, "data definition has no type or storage class");
1209 /* Having seen a data definition, there cannot now be a
1210 function definition. */
1212 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1213 asm_name
= c_parser_simple_asm_expr (parser
);
1214 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1215 postfix_attrs
= c_parser_attributes (parser
);
1216 if (c_parser_next_token_is (parser
, CPP_EQ
))
1220 c_parser_consume_token (parser
);
1221 /* The declaration of the variable is in effect while
1222 its initializer is parsed. */
1223 d
= start_decl (declarator
, specs
, true,
1224 chainon (postfix_attrs
, all_prefix_attrs
));
1226 d
= error_mark_node
;
1227 start_init (d
, asm_name
, global_bindings_p ());
1228 init
= c_parser_initializer (parser
);
1230 if (d
!= error_mark_node
)
1232 maybe_warn_string_init (TREE_TYPE (d
), init
);
1233 finish_decl (d
, init
.value
, asm_name
);
1238 tree d
= start_decl (declarator
, specs
, false,
1239 chainon (postfix_attrs
,
1242 finish_decl (d
, NULL_TREE
, asm_name
);
1244 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1246 c_parser_consume_token (parser
);
1247 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1248 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1251 all_prefix_attrs
= prefix_attrs
;
1254 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1256 c_parser_consume_token (parser
);
1261 c_parser_error (parser
, "expected %<,%> or %<;%>");
1262 c_parser_skip_to_end_of_block_or_statement (parser
);
1268 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1269 "%<asm%> or %<__attribute__%>");
1270 c_parser_skip_to_end_of_block_or_statement (parser
);
1273 /* Function definition (nested or otherwise). */
1276 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1277 c_push_function_context ();
1279 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1281 /* This can appear in many cases looking nothing like a
1282 function definition, so we don't give a more specific
1283 error suggesting there was one. */
1284 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1285 "or %<__attribute__%>");
1287 c_pop_function_context ();
1290 /* Parse old-style parameter declarations. ??? Attributes are
1291 not allowed to start declaration specifiers here because of a
1292 syntax conflict between a function declaration with attribute
1293 suffix and a function definition with an attribute prefix on
1294 first old-style parameter declaration. Following the old
1295 parser, they are not accepted on subsequent old-style
1296 parameter declarations either. However, there is no
1297 ambiguity after the first declaration, nor indeed on the
1298 first as long as we don't allow postfix attributes after a
1299 declarator with a nonempty identifier list in a definition;
1300 and postfix attributes have never been accepted here in
1301 function definitions either. */
1302 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1303 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1304 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1305 store_parm_decls ();
1306 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1307 = c_parser_peek_token (parser
)->location
;
1308 fnbody
= c_parser_compound_statement (parser
);
1311 tree decl
= current_function_decl
;
1314 c_pop_function_context ();
1315 add_stmt (build_stmt (DECL_EXPR
, decl
));
1326 /* Parse an asm-definition (asm() outside a function body). This is a
1334 c_parser_asm_definition (c_parser
*parser
)
1336 tree asm_str
= c_parser_simple_asm_expr (parser
);
1338 cgraph_add_asm_node (asm_str
);
1339 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1342 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1343 6.7), adding them to SPECS (which may already include some).
1344 Storage class specifiers are accepted iff SCSPEC_OK; type
1345 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1346 the start iff START_ATTR_OK.
1348 declaration-specifiers:
1349 storage-class-specifier declaration-specifiers[opt]
1350 type-specifier declaration-specifiers[opt]
1351 type-qualifier declaration-specifiers[opt]
1352 function-specifier declaration-specifiers[opt]
1354 Function specifiers (inline) are from C99, and are currently
1355 handled as storage class specifiers, as is __thread.
1357 C90 6.5.1, C99 6.7.1:
1358 storage-class-specifier:
1369 C90 6.5.2, C99 6.7.2:
1382 [_Imaginary removed in C99 TC2]
1383 struct-or-union-specifier
1387 (_Bool and _Complex are new in C99.)
1389 C90 6.5.3, C99 6.7.3:
1396 (restrict is new in C99.)
1400 declaration-specifiers:
1401 attributes declaration-specifiers[opt]
1403 storage-class-specifier:
1415 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1416 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1421 class-name objc-protocol-refs[opt]
1422 typedef-name objc-protocol-refs
1427 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1428 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1430 bool attrs_ok
= start_attr_ok
;
1431 bool seen_type
= specs
->type_seen_p
;
1432 while (c_parser_next_token_is (parser
, CPP_NAME
)
1433 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1434 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1436 struct c_typespec t
;
1438 if (c_parser_next_token_is (parser
, CPP_NAME
))
1440 tree value
= c_parser_peek_token (parser
)->value
;
1441 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1442 /* This finishes the specifiers unless a type name is OK, it
1443 is declared as a type name and a type name hasn't yet
1445 if (!typespec_ok
|| seen_type
1446 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1448 c_parser_consume_token (parser
);
1451 if (kind
== C_ID_TYPENAME
1452 && (!c_dialect_objc ()
1453 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1455 t
.kind
= ctsk_typedef
;
1456 /* For a typedef name, record the meaning, not the name.
1457 In case of 'foo foo, bar;'. */
1458 t
.spec
= lookup_name (value
);
1460 t
.expr_const_operands
= true;
1464 tree proto
= NULL_TREE
;
1465 gcc_assert (c_dialect_objc ());
1467 if (c_parser_next_token_is (parser
, CPP_LESS
))
1468 proto
= c_parser_objc_protocol_refs (parser
);
1469 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1471 t
.expr_const_operands
= true;
1473 declspecs_add_type (specs
, t
);
1476 if (c_parser_next_token_is (parser
, CPP_LESS
))
1478 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1479 nisse@lysator.liu.se. */
1481 gcc_assert (c_dialect_objc ());
1482 if (!typespec_ok
|| seen_type
)
1484 proto
= c_parser_objc_protocol_refs (parser
);
1486 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1488 t
.expr_const_operands
= true;
1489 declspecs_add_type (specs
, t
);
1492 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1493 switch (c_parser_peek_token (parser
)->keyword
)
1505 /* TODO: Distinguish between function specifiers (inline)
1506 and storage class specifiers, either here or in
1507 declspecs_add_scspec. */
1508 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1509 c_parser_consume_token (parser
);
1532 if (c_dialect_objc ())
1533 parser
->objc_need_raw_identifier
= true;
1534 t
.kind
= ctsk_resword
;
1535 t
.spec
= c_parser_peek_token (parser
)->value
;
1537 t
.expr_const_operands
= true;
1538 declspecs_add_type (specs
, t
);
1539 c_parser_consume_token (parser
);
1546 t
= c_parser_enum_specifier (parser
);
1547 declspecs_add_type (specs
, t
);
1555 t
= c_parser_struct_or_union_specifier (parser
);
1556 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1557 declspecs_add_type (specs
, t
);
1560 /* ??? The old parser rejected typeof after other type
1561 specifiers, but is a syntax error the best way of
1563 if (!typespec_ok
|| seen_type
)
1567 t
= c_parser_typeof_specifier (parser
);
1568 declspecs_add_type (specs
, t
);
1574 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1575 c_parser_consume_token (parser
);
1580 attrs
= c_parser_attributes (parser
);
1581 declspecs_add_attrs (specs
, attrs
);
1590 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1593 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1594 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1595 enum attributes[opt] identifier
1597 The form with trailing comma is new in C99. The forms with
1598 attributes are GNU extensions. In GNU C, we accept any expression
1599 without commas in the syntax (assignment expressions, not just
1600 conditional expressions); assignment expressions will be diagnosed
1605 enumerator-list , enumerator
1608 enumeration-constant
1609 enumeration-constant = constant-expression
1612 static struct c_typespec
1613 c_parser_enum_specifier (c_parser
*parser
)
1615 struct c_typespec ret
;
1617 tree ident
= NULL_TREE
;
1618 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1619 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1620 c_parser_consume_token (parser
);
1621 attrs
= c_parser_attributes (parser
);
1622 /* Set the location in case we create a decl now. */
1623 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1624 if (c_parser_next_token_is (parser
, CPP_NAME
))
1626 ident
= c_parser_peek_token (parser
)->value
;
1627 ident_loc
= c_parser_peek_token (parser
)->location
;
1628 c_parser_consume_token (parser
);
1630 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1632 /* Parse an enum definition. */
1633 struct c_enum_contents the_enum
;
1634 tree type
= start_enum (&the_enum
, ident
);
1636 /* We chain the enumerators in reverse order, then put them in
1637 forward order at the end. */
1638 tree values
= NULL_TREE
;
1639 c_parser_consume_token (parser
);
1647 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1648 location_t value_loc
;
1649 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1651 c_parser_error (parser
, "expected identifier");
1652 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1653 values
= error_mark_node
;
1656 token
= c_parser_peek_token (parser
);
1657 enum_id
= token
->value
;
1658 /* Set the location in case we create a decl now. */
1659 c_parser_set_source_position_from_token (token
);
1660 value_loc
= token
->location
;
1661 c_parser_consume_token (parser
);
1662 if (c_parser_next_token_is (parser
, CPP_EQ
))
1664 c_parser_consume_token (parser
);
1665 value_loc
= c_parser_peek_token (parser
)->location
;
1666 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1669 enum_value
= NULL_TREE
;
1670 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
,
1672 TREE_CHAIN (enum_decl
) = values
;
1675 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1677 comma_loc
= c_parser_peek_token (parser
)->location
;
1679 c_parser_consume_token (parser
);
1681 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1683 if (seen_comma
&& !flag_isoc99
)
1684 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1685 c_parser_consume_token (parser
);
1690 c_parser_error (parser
, "expected %<,%> or %<}%>");
1691 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1692 values
= error_mark_node
;
1696 postfix_attrs
= c_parser_attributes (parser
);
1697 ret
.spec
= finish_enum (type
, nreverse (values
),
1698 chainon (attrs
, postfix_attrs
));
1699 ret
.kind
= ctsk_tagdef
;
1700 ret
.expr
= NULL_TREE
;
1701 ret
.expr_const_operands
= true;
1706 c_parser_error (parser
, "expected %<{%>");
1707 ret
.spec
= error_mark_node
;
1708 ret
.kind
= ctsk_tagref
;
1709 ret
.expr
= NULL_TREE
;
1710 ret
.expr_const_operands
= true;
1713 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1714 /* In ISO C, enumerated types can be referred to only if already
1716 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1719 pedwarn (ident_loc
, OPT_pedantic
,
1720 "ISO C forbids forward references to %<enum%> types");
1725 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1727 struct-or-union-specifier:
1728 struct-or-union attributes[opt] identifier[opt]
1729 { struct-contents } attributes[opt]
1730 struct-or-union attributes[opt] identifier
1733 struct-declaration-list
1735 struct-declaration-list:
1736 struct-declaration ;
1737 struct-declaration-list struct-declaration ;
1744 struct-declaration-list struct-declaration
1746 struct-declaration-list:
1747 struct-declaration-list ;
1750 (Note that in the syntax here, unlike that in ISO C, the semicolons
1751 are included here rather than in struct-declaration, in order to
1752 describe the syntax with extra semicolons and missing semicolon at
1757 struct-declaration-list:
1758 @defs ( class-name )
1760 (Note this does not include a trailing semicolon, but can be
1761 followed by further declarations, and gets a pedwarn-if-pedantic
1762 when followed by a semicolon.) */
1764 static struct c_typespec
1765 c_parser_struct_or_union_specifier (c_parser
*parser
)
1767 struct c_typespec ret
;
1769 tree ident
= NULL_TREE
;
1770 enum tree_code code
;
1771 switch (c_parser_peek_token (parser
)->keyword
)
1782 c_parser_consume_token (parser
);
1783 attrs
= c_parser_attributes (parser
);
1784 /* Set the location in case we create a decl now. */
1785 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1786 if (c_parser_next_token_is (parser
, CPP_NAME
))
1788 ident
= c_parser_peek_token (parser
)->value
;
1789 c_parser_consume_token (parser
);
1791 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1793 /* Parse a struct or union definition. Start the scope of the
1794 tag before parsing components. */
1795 tree type
= start_struct (code
, ident
);
1797 /* We chain the components in reverse order, then put them in
1798 forward order at the end. Each struct-declaration may
1799 declare multiple components (comma-separated), so we must use
1800 chainon to join them, although when parsing each
1801 struct-declaration we can use TREE_CHAIN directly.
1803 The theory behind all this is that there will be more
1804 semicolon separated fields than comma separated fields, and
1805 so we'll be minimizing the number of node traversals required
1807 tree contents
= NULL_TREE
;
1808 c_parser_consume_token (parser
);
1809 /* Handle the Objective-C @defs construct,
1810 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1811 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1814 gcc_assert (c_dialect_objc ());
1815 c_parser_consume_token (parser
);
1816 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1818 if (c_parser_next_token_is (parser
, CPP_NAME
)
1819 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1821 name
= c_parser_peek_token (parser
)->value
;
1822 c_parser_consume_token (parser
);
1826 c_parser_error (parser
, "expected class name");
1827 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1832 contents
= nreverse (objc_get_class_ivars (name
));
1835 /* Parse the struct-declarations and semicolons. Problems with
1836 semicolons are diagnosed here; empty structures are diagnosed
1841 /* Parse any stray semicolon. */
1842 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1844 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1845 "extra semicolon in struct or union specified");
1846 c_parser_consume_token (parser
);
1849 /* Stop if at the end of the struct or union contents. */
1850 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1852 c_parser_consume_token (parser
);
1855 /* Accept #pragmas at struct scope. */
1856 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1858 c_parser_pragma (parser
, pragma_external
);
1861 /* Parse some comma-separated declarations, but not the
1862 trailing semicolon if any. */
1863 decls
= c_parser_struct_declaration (parser
);
1864 contents
= chainon (decls
, contents
);
1865 /* If no semicolon follows, either we have a parse error or
1866 are at the end of the struct or union and should
1868 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1869 c_parser_consume_token (parser
);
1872 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1873 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1874 "no semicolon at end of struct or union");
1877 c_parser_error (parser
, "expected %<;%>");
1878 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1883 postfix_attrs
= c_parser_attributes (parser
);
1884 ret
.spec
= finish_struct (type
, nreverse (contents
),
1885 chainon (attrs
, postfix_attrs
));
1886 ret
.kind
= ctsk_tagdef
;
1887 ret
.expr
= NULL_TREE
;
1888 ret
.expr_const_operands
= true;
1893 c_parser_error (parser
, "expected %<{%>");
1894 ret
.spec
= error_mark_node
;
1895 ret
.kind
= ctsk_tagref
;
1896 ret
.expr
= NULL_TREE
;
1897 ret
.expr_const_operands
= true;
1900 ret
= parser_xref_tag (code
, ident
);
1904 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1905 the trailing semicolon.
1908 specifier-qualifier-list struct-declarator-list
1910 specifier-qualifier-list:
1911 type-specifier specifier-qualifier-list[opt]
1912 type-qualifier specifier-qualifier-list[opt]
1913 attributes specifier-qualifier-list[opt]
1915 struct-declarator-list:
1917 struct-declarator-list , attributes[opt] struct-declarator
1920 declarator attributes[opt]
1921 declarator[opt] : constant-expression attributes[opt]
1926 __extension__ struct-declaration
1927 specifier-qualifier-list
1929 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1930 of attributes where shown is a GNU extension. In GNU C, we accept
1931 any expression without commas in the syntax (assignment
1932 expressions, not just conditional expressions); assignment
1933 expressions will be diagnosed as non-constant. */
1936 c_parser_struct_declaration (c_parser
*parser
)
1938 struct c_declspecs
*specs
;
1940 tree all_prefix_attrs
;
1942 location_t decl_loc
;
1943 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1947 ext
= disable_extension_diagnostics ();
1948 c_parser_consume_token (parser
);
1949 decl
= c_parser_struct_declaration (parser
);
1950 restore_extension_diagnostics (ext
);
1953 specs
= build_null_declspecs ();
1954 decl_loc
= c_parser_peek_token (parser
)->location
;
1955 c_parser_declspecs (parser
, specs
, false, true, true);
1958 if (!specs
->declspecs_seen_p
)
1960 c_parser_error (parser
, "expected specifier-qualifier-list");
1963 finish_declspecs (specs
);
1964 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1967 if (!specs
->type_seen_p
)
1969 pedwarn (decl_loc
, OPT_pedantic
,
1970 "ISO C forbids member declarations with no members");
1971 shadow_tag_warned (specs
, pedantic
);
1976 /* Support for unnamed structs or unions as members of
1977 structs or unions (which is [a] useful and [b] supports
1981 ret
= grokfield (c_parser_peek_token (parser
)->location
,
1982 build_id_declarator (NULL_TREE
), specs
,
1985 decl_attributes (&ret
, attrs
, 0);
1989 pending_xref_error ();
1990 prefix_attrs
= specs
->attrs
;
1991 all_prefix_attrs
= prefix_attrs
;
1992 specs
->attrs
= NULL_TREE
;
1996 /* Declaring one or more declarators or un-named bit-fields. */
1997 struct c_declarator
*declarator
;
1999 if (c_parser_next_token_is (parser
, CPP_COLON
))
2000 declarator
= build_id_declarator (NULL_TREE
);
2002 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2003 C_DTR_NORMAL
, &dummy
);
2004 if (declarator
== NULL
)
2006 c_parser_skip_to_end_of_block_or_statement (parser
);
2009 if (c_parser_next_token_is (parser
, CPP_COLON
)
2010 || c_parser_next_token_is (parser
, CPP_COMMA
)
2011 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2012 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2013 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2015 tree postfix_attrs
= NULL_TREE
;
2016 tree width
= NULL_TREE
;
2018 if (c_parser_next_token_is (parser
, CPP_COLON
))
2020 c_parser_consume_token (parser
);
2021 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2023 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2024 postfix_attrs
= c_parser_attributes (parser
);
2025 d
= grokfield (c_parser_peek_token (parser
)->location
,
2026 declarator
, specs
, width
, &all_prefix_attrs
);
2027 decl_attributes (&d
, chainon (postfix_attrs
,
2028 all_prefix_attrs
), 0);
2029 TREE_CHAIN (d
) = decls
;
2031 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2032 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2035 all_prefix_attrs
= prefix_attrs
;
2036 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2037 c_parser_consume_token (parser
);
2038 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2039 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2041 /* Semicolon consumed in caller. */
2046 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2052 c_parser_error (parser
,
2053 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2054 "%<__attribute__%>");
2061 /* Parse a typeof specifier (a GNU extension).
2064 typeof ( expression )
2065 typeof ( type-name )
2068 static struct c_typespec
2069 c_parser_typeof_specifier (c_parser
*parser
)
2071 struct c_typespec ret
;
2072 ret
.kind
= ctsk_typeof
;
2073 ret
.spec
= error_mark_node
;
2074 ret
.expr
= NULL_TREE
;
2075 ret
.expr_const_operands
= true;
2076 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2077 c_parser_consume_token (parser
);
2080 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2086 if (c_parser_next_token_starts_typename (parser
))
2088 struct c_type_name
*type
= c_parser_type_name (parser
);
2093 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2094 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2100 location_t here
= c_parser_peek_token (parser
)->location
;
2101 struct c_expr expr
= c_parser_expression (parser
);
2104 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2105 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2106 error_at (here
, "%<typeof%> applied to a bit-field");
2107 ret
.spec
= TREE_TYPE (expr
.value
);
2108 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2109 /* This is returned with the type so that when the type is
2110 evaluated, this can be evaluated. */
2112 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2113 pop_maybe_used (was_vm
);
2115 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2119 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2120 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2121 be redeclared; otherwise it may not. KIND indicates which kind of
2122 declarator is wanted. Returns a valid declarator except in the
2123 case of a syntax error in which case NULL is returned. *SEEN_ID is
2124 set to true if an identifier being declared is seen; this is used
2125 to diagnose bad forms of abstract array declarators and to
2126 determine whether an identifier list is syntactically permitted.
2129 pointer[opt] direct-declarator
2133 ( attributes[opt] declarator )
2134 direct-declarator array-declarator
2135 direct-declarator ( parameter-type-list )
2136 direct-declarator ( identifier-list[opt] )
2139 * type-qualifier-list[opt]
2140 * type-qualifier-list[opt] pointer
2142 type-qualifier-list:
2145 type-qualifier-list type-qualifier
2146 type-qualifier-list attributes
2148 parameter-type-list:
2150 parameter-list , ...
2153 parameter-declaration
2154 parameter-list , parameter-declaration
2156 parameter-declaration:
2157 declaration-specifiers declarator attributes[opt]
2158 declaration-specifiers abstract-declarator[opt] attributes[opt]
2162 identifier-list , identifier
2164 abstract-declarator:
2166 pointer[opt] direct-abstract-declarator
2168 direct-abstract-declarator:
2169 ( attributes[opt] abstract-declarator )
2170 direct-abstract-declarator[opt] array-declarator
2171 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2176 direct-declarator ( parameter-forward-declarations
2177 parameter-type-list[opt] )
2179 direct-abstract-declarator:
2180 direct-abstract-declarator[opt] ( parameter-forward-declarations
2181 parameter-type-list[opt] )
2183 parameter-forward-declarations:
2185 parameter-forward-declarations parameter-list ;
2187 The uses of attributes shown above are GNU extensions.
2189 Some forms of array declarator are not included in C99 in the
2190 syntax for abstract declarators; these are disallowed elsewhere.
2191 This may be a defect (DR#289).
2193 This function also accepts an omitted abstract declarator as being
2194 an abstract declarator, although not part of the formal syntax. */
2196 static struct c_declarator
*
2197 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2200 /* Parse any initial pointer part. */
2201 if (c_parser_next_token_is (parser
, CPP_MULT
))
2203 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2204 struct c_declarator
*inner
;
2205 c_parser_consume_token (parser
);
2206 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2207 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2211 return make_pointer_declarator (quals_attrs
, inner
);
2213 /* Now we have a direct declarator, direct abstract declarator or
2214 nothing (which counts as a direct abstract declarator here). */
2215 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2218 /* Parse a direct declarator or direct abstract declarator; arguments
2219 as c_parser_declarator. */
2221 static struct c_declarator
*
2222 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2225 /* The direct declarator must start with an identifier (possibly
2226 omitted) or a parenthesized declarator (possibly abstract). In
2227 an ordinary declarator, initial parentheses must start a
2228 parenthesized declarator. In an abstract declarator or parameter
2229 declarator, they could start a parenthesized declarator or a
2230 parameter list. To tell which, the open parenthesis and any
2231 following attributes must be read. If a declaration specifier
2232 follows, then it is a parameter list; if the specifier is a
2233 typedef name, there might be an ambiguity about redeclaring it,
2234 which is resolved in the direction of treating it as a typedef
2235 name. If a close parenthesis follows, it is also an empty
2236 parameter list, as the syntax does not permit empty abstract
2237 declarators. Otherwise, it is a parenthesized declarator (in
2238 which case the analysis may be repeated inside it, recursively).
2240 ??? There is an ambiguity in a parameter declaration "int
2241 (__attribute__((foo)) x)", where x is not a typedef name: it
2242 could be an abstract declarator for a function, or declare x with
2243 parentheses. The proper resolution of this ambiguity needs
2244 documenting. At present we follow an accident of the old
2245 parser's implementation, whereby the first parameter must have
2246 some declaration specifiers other than just attributes. Thus as
2247 a parameter declaration it is treated as a parenthesized
2248 parameter named x, and as an abstract declarator it is
2251 ??? Also following the old parser, attributes inside an empty
2252 parameter list are ignored, making it a list not yielding a
2253 prototype, rather than giving an error or making it have one
2254 parameter with implicit type int.
2256 ??? Also following the old parser, typedef names may be
2257 redeclared in declarators, but not Objective-C class names. */
2259 if (kind
!= C_DTR_ABSTRACT
2260 && c_parser_next_token_is (parser
, CPP_NAME
)
2262 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2263 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2265 struct c_declarator
*inner
2266 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2268 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2269 c_parser_consume_token (parser
);
2270 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2273 if (kind
!= C_DTR_NORMAL
2274 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2276 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2277 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2280 /* Either we are at the end of an abstract declarator, or we have
2283 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2286 struct c_declarator
*inner
;
2287 c_parser_consume_token (parser
);
2288 attrs
= c_parser_attributes (parser
);
2289 if (kind
!= C_DTR_NORMAL
2290 && (c_parser_next_token_starts_declspecs (parser
)
2291 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2293 struct c_arg_info
*args
2294 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2301 = build_function_declarator (args
,
2302 build_id_declarator (NULL_TREE
));
2303 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2307 /* A parenthesized declarator. */
2308 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2309 if (inner
!= NULL
&& attrs
!= NULL
)
2310 inner
= build_attrs_declarator (attrs
, inner
);
2311 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2313 c_parser_consume_token (parser
);
2317 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2321 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2328 if (kind
== C_DTR_NORMAL
)
2330 c_parser_error (parser
, "expected identifier or %<(%>");
2334 return build_id_declarator (NULL_TREE
);
2338 /* Parse part of a direct declarator or direct abstract declarator,
2339 given that some (in INNER) has already been parsed; ID_PRESENT is
2340 true if an identifier is present, false for an abstract
2343 static struct c_declarator
*
2344 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2345 struct c_declarator
*inner
)
2347 /* Parse a sequence of array declarators and parameter lists. */
2348 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2350 struct c_declarator
*declarator
;
2351 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2355 c_parser_consume_token (parser
);
2356 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2357 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2359 c_parser_consume_token (parser
);
2360 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2361 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2362 if (!quals_attrs
->declspecs_seen_p
)
2364 /* If "static" is present, there must be an array dimension.
2365 Otherwise, there may be a dimension, "*", or no
2370 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2374 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2379 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2381 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2385 c_parser_consume_token (parser
);
2390 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2396 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2399 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2400 c_parser_consume_token (parser
);
2403 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2407 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2409 if (declarator
== NULL
)
2411 inner
= set_array_declarator_inner (declarator
, inner
);
2412 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2414 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2417 struct c_arg_info
*args
;
2418 c_parser_consume_token (parser
);
2419 attrs
= c_parser_attributes (parser
);
2420 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2425 inner
= build_function_declarator (args
, inner
);
2426 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2432 /* Parse a parameter list or identifier list, including the closing
2433 parenthesis but not the opening one. ATTRS are the attributes at
2434 the start of the list. ID_LIST_OK is true if an identifier list is
2435 acceptable; such a list must not have attributes at the start. */
2437 static struct c_arg_info
*
2438 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2441 declare_parm_level ();
2442 /* If the list starts with an identifier, it is an identifier list.
2443 Otherwise, it is either a prototype list or an empty list. */
2446 && c_parser_next_token_is (parser
, CPP_NAME
)
2447 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2449 tree list
= NULL_TREE
, *nextp
= &list
;
2450 while (c_parser_next_token_is (parser
, CPP_NAME
)
2451 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2453 *nextp
= build_tree_list (NULL_TREE
,
2454 c_parser_peek_token (parser
)->value
);
2455 nextp
= & TREE_CHAIN (*nextp
);
2456 c_parser_consume_token (parser
);
2457 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2459 c_parser_consume_token (parser
);
2460 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2462 c_parser_error (parser
, "expected identifier");
2466 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2468 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2473 ret
->pending_sizes
= 0;
2474 ret
->had_vla_unspec
= 0;
2475 c_parser_consume_token (parser
);
2481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2489 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2495 /* Parse a parameter list (possibly empty), including the closing
2496 parenthesis but not the opening one. ATTRS are the attributes at
2497 the start of the list. */
2499 static struct c_arg_info
*
2500 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2502 bool good_parm
= false;
2503 /* ??? Following the old parser, forward parameter declarations may
2504 use abstract declarators, and if no real parameter declarations
2505 follow the forward declarations then this is not diagnosed. Also
2506 note as above that attributes are ignored as the only contents of
2507 the parentheses, or as the only contents after forward
2509 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2511 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2516 ret
->pending_sizes
= 0;
2517 ret
->had_vla_unspec
= 0;
2518 c_parser_consume_token (parser
);
2521 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2523 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2527 ret
->pending_sizes
= 0;
2528 ret
->had_vla_unspec
= 0;
2529 /* Suppress -Wold-style-definition for this case. */
2530 ret
->types
= error_mark_node
;
2531 error_at (c_parser_peek_token (parser
)->location
,
2532 "ISO C requires a named argument before %<...%>");
2533 c_parser_consume_token (parser
);
2534 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2536 c_parser_consume_token (parser
);
2541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2546 /* Nonempty list of parameters, either terminated with semicolon
2547 (forward declarations; recurse) or with close parenthesis (normal
2548 function) or with ", ... )" (variadic function). */
2551 /* Parse a parameter. */
2552 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2557 push_parm_decl (parm
);
2559 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2562 c_parser_consume_token (parser
);
2563 mark_forward_parm_decls ();
2564 new_attrs
= c_parser_attributes (parser
);
2565 return c_parser_parms_list_declarator (parser
, new_attrs
);
2567 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2569 c_parser_consume_token (parser
);
2571 return get_parm_info (false);
2574 struct c_arg_info
*ret
2575 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2580 ret
->pending_sizes
= 0;
2581 ret
->had_vla_unspec
= 0;
2585 if (!c_parser_require (parser
, CPP_COMMA
,
2586 "expected %<;%>, %<,%> or %<)%>"))
2588 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2589 get_pending_sizes ();
2592 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2594 c_parser_consume_token (parser
);
2595 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2597 c_parser_consume_token (parser
);
2599 return get_parm_info (true);
2602 struct c_arg_info
*ret
2603 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2608 ret
->pending_sizes
= 0;
2609 ret
->had_vla_unspec
= 0;
2615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2617 get_pending_sizes ();
2624 /* Parse a parameter declaration. ATTRS are the attributes at the
2625 start of the declaration if it is the first parameter. */
2627 static struct c_parm
*
2628 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2630 struct c_declspecs
*specs
;
2631 struct c_declarator
*declarator
;
2633 tree postfix_attrs
= NULL_TREE
;
2635 if (!c_parser_next_token_starts_declspecs (parser
))
2637 /* ??? In some Objective-C cases '...' isn't applicable so there
2638 should be a different message. */
2639 c_parser_error (parser
,
2640 "expected declaration specifiers or %<...%>");
2641 c_parser_skip_to_end_of_parameter (parser
);
2644 specs
= build_null_declspecs ();
2647 declspecs_add_attrs (specs
, attrs
);
2650 c_parser_declspecs (parser
, specs
, true, true, true);
2651 finish_declspecs (specs
);
2652 pending_xref_error ();
2653 prefix_attrs
= specs
->attrs
;
2654 specs
->attrs
= NULL_TREE
;
2655 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2656 C_DTR_PARM
, &dummy
);
2657 if (declarator
== NULL
)
2659 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2662 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2663 postfix_attrs
= c_parser_attributes (parser
);
2664 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2668 /* Parse a string literal in an asm expression. It should not be
2669 translated, and wide string literals are an error although
2670 permitted by the syntax. This is a GNU extension.
2675 ??? At present, following the old parser, the caller needs to have
2676 set lex_untranslated_string to 1. It would be better to follow the
2677 C++ parser rather than using this kludge. */
2680 c_parser_asm_string_literal (c_parser
*parser
)
2683 if (c_parser_next_token_is (parser
, CPP_STRING
))
2685 str
= c_parser_peek_token (parser
)->value
;
2686 c_parser_consume_token (parser
);
2688 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2690 error_at (c_parser_peek_token (parser
)->location
,
2691 "wide string literal in %<asm%>");
2692 str
= build_string (1, "");
2693 c_parser_consume_token (parser
);
2697 c_parser_error (parser
, "expected string literal");
2703 /* Parse a simple asm expression. This is used in restricted
2704 contexts, where a full expression with inputs and outputs does not
2705 make sense. This is a GNU extension.
2708 asm ( asm-string-literal )
2712 c_parser_simple_asm_expr (c_parser
*parser
)
2715 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2716 /* ??? Follow the C++ parser rather than using the
2717 lex_untranslated_string kludge. */
2718 parser
->lex_untranslated_string
= true;
2719 c_parser_consume_token (parser
);
2720 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2722 parser
->lex_untranslated_string
= false;
2725 str
= c_parser_asm_string_literal (parser
);
2726 parser
->lex_untranslated_string
= false;
2727 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2729 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2735 /* Parse (possibly empty) attributes. This is a GNU extension.
2739 attributes attribute
2742 __attribute__ ( ( attribute-list ) )
2746 attribute_list , attrib
2751 any-word ( identifier )
2752 any-word ( identifier , nonempty-expr-list )
2753 any-word ( expr-list )
2755 where the "identifier" must not be declared as a type, and
2756 "any-word" may be any identifier (including one declared as a
2757 type), a reserved word storage class specifier, type specifier or
2758 type qualifier. ??? This still leaves out most reserved keywords
2759 (following the old parser), shouldn't we include them, and why not
2760 allow identifiers declared as types to start the arguments? */
2763 c_parser_attributes (c_parser
*parser
)
2765 tree attrs
= NULL_TREE
;
2766 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2768 /* ??? Follow the C++ parser rather than using the
2769 lex_untranslated_string kludge. */
2770 parser
->lex_untranslated_string
= true;
2771 c_parser_consume_token (parser
);
2772 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2774 parser
->lex_untranslated_string
= false;
2777 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2779 parser
->lex_untranslated_string
= false;
2780 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2783 /* Parse the attribute list. */
2784 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2785 || c_parser_next_token_is (parser
, CPP_NAME
)
2786 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2788 tree attr
, attr_name
, attr_args
;
2789 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2791 c_parser_consume_token (parser
);
2794 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2796 /* ??? See comment above about what keywords are
2799 switch (c_parser_peek_token (parser
)->keyword
)
2836 /* Accept __attribute__((__const)) as __attribute__((const))
2839 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2842 attr_name
= c_parser_peek_token (parser
)->value
;
2843 c_parser_consume_token (parser
);
2844 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2846 attr
= build_tree_list (attr_name
, NULL_TREE
);
2847 attrs
= chainon (attrs
, attr
);
2850 c_parser_consume_token (parser
);
2851 /* Parse the attribute contents. If they start with an
2852 identifier which is followed by a comma or close
2853 parenthesis, then the arguments start with that
2854 identifier; otherwise they are an expression list. */
2855 if (c_parser_next_token_is (parser
, CPP_NAME
)
2856 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2857 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2858 || (c_parser_peek_2nd_token (parser
)->type
2859 == CPP_CLOSE_PAREN
)))
2861 tree arg1
= c_parser_peek_token (parser
)->value
;
2862 c_parser_consume_token (parser
);
2863 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2864 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2867 c_parser_consume_token (parser
);
2868 attr_args
= tree_cons (NULL_TREE
, arg1
,
2869 c_parser_expr_list (parser
, false,
2875 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2876 attr_args
= NULL_TREE
;
2878 attr_args
= c_parser_expr_list (parser
, false, true);
2880 attr
= build_tree_list (attr_name
, attr_args
);
2881 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2882 c_parser_consume_token (parser
);
2885 parser
->lex_untranslated_string
= false;
2886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2890 attrs
= chainon (attrs
, attr
);
2892 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2893 c_parser_consume_token (parser
);
2896 parser
->lex_untranslated_string
= false;
2897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2901 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2902 c_parser_consume_token (parser
);
2905 parser
->lex_untranslated_string
= false;
2906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2910 parser
->lex_untranslated_string
= false;
2915 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2918 specifier-qualifier-list abstract-declarator[opt]
2921 static struct c_type_name
*
2922 c_parser_type_name (c_parser
*parser
)
2924 struct c_declspecs
*specs
= build_null_declspecs ();
2925 struct c_declarator
*declarator
;
2926 struct c_type_name
*ret
;
2928 c_parser_declspecs (parser
, specs
, false, true, true);
2929 if (!specs
->declspecs_seen_p
)
2931 c_parser_error (parser
, "expected specifier-qualifier-list");
2934 pending_xref_error ();
2935 finish_declspecs (specs
);
2936 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2937 C_DTR_ABSTRACT
, &dummy
);
2938 if (declarator
== NULL
)
2940 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2942 ret
->declarator
= declarator
;
2946 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2949 assignment-expression
2950 { initializer-list }
2951 { initializer-list , }
2954 designation[opt] initializer
2955 initializer-list , designation[opt] initializer
2962 designator-list designator
2969 [ constant-expression ]
2981 [ constant-expression ... constant-expression ]
2983 Any expression without commas is accepted in the syntax for the
2984 constant-expressions, with non-constant expressions rejected later.
2986 This function is only used for top-level initializers; for nested
2987 ones, see c_parser_initval. */
2989 static struct c_expr
2990 c_parser_initializer (c_parser
*parser
)
2992 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2993 return c_parser_braced_init (parser
, NULL_TREE
, false);
2997 ret
= c_parser_expr_no_commas (parser
, NULL
);
2998 if (TREE_CODE (ret
.value
) != STRING_CST
2999 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3000 ret
= default_function_array_conversion (ret
);
3005 /* Parse a braced initializer list. TYPE is the type specified for a
3006 compound literal, and NULL_TREE for other initializers and for
3007 nested braced lists. NESTED_P is true for nested braced lists,
3008 false for the list of a compound literal or the list that is the
3009 top-level initializer in a declaration. */
3011 static struct c_expr
3012 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3014 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3015 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3016 c_parser_consume_token (parser
);
3018 push_init_level (0);
3020 really_start_incremental_init (type
);
3021 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3023 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3027 /* Parse a non-empty initializer list, possibly with a trailing
3031 c_parser_initelt (parser
);
3034 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3035 c_parser_consume_token (parser
);
3038 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3042 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3045 ret
.value
= error_mark_node
;
3046 ret
.original_code
= ERROR_MARK
;
3047 ret
.original_type
= NULL
;
3048 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3052 c_parser_consume_token (parser
);
3053 return pop_init_level (0);
3056 /* Parse a nested initializer, including designators. */
3059 c_parser_initelt (c_parser
*parser
)
3061 /* Parse any designator or designator list. A single array
3062 designator may have the subsequent "=" omitted in GNU C, but a
3063 longer list or a structure member designator may not. */
3064 if (c_parser_next_token_is (parser
, CPP_NAME
)
3065 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3067 /* Old-style structure member designator. */
3068 set_init_label (c_parser_peek_token (parser
)->value
);
3069 /* Use the colon as the error location. */
3070 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3071 "obsolete use of designated initializer with %<:%>");
3072 c_parser_consume_token (parser
);
3073 c_parser_consume_token (parser
);
3077 /* des_seen is 0 if there have been no designators, 1 if there
3078 has been a single array designator and 2 otherwise. */
3080 /* Location of a designator. */
3081 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3082 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3083 || c_parser_next_token_is (parser
, CPP_DOT
))
3085 int des_prev
= des_seen
;
3087 des_loc
= c_parser_peek_token (parser
)->location
;
3090 if (c_parser_next_token_is (parser
, CPP_DOT
))
3093 c_parser_consume_token (parser
);
3094 if (c_parser_next_token_is (parser
, CPP_NAME
))
3096 set_init_label (c_parser_peek_token (parser
)->value
);
3097 c_parser_consume_token (parser
);
3102 init
.value
= error_mark_node
;
3103 init
.original_code
= ERROR_MARK
;
3104 init
.original_type
= NULL
;
3105 c_parser_error (parser
, "expected identifier");
3106 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3107 process_init_element (init
, false);
3114 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3115 /* ??? Following the old parser, [ objc-receiver
3116 objc-message-args ] is accepted as an initializer,
3117 being distinguished from a designator by what follows
3118 the first assignment expression inside the square
3119 brackets, but after a first array designator a
3120 subsequent square bracket is for Objective-C taken to
3121 start an expression, using the obsolete form of
3122 designated initializer without '=', rather than
3123 possibly being a second level of designation: in LALR
3124 terms, the '[' is shifted rather than reducing
3125 designator to designator-list. */
3126 if (des_prev
== 1 && c_dialect_objc ())
3128 des_seen
= des_prev
;
3131 if (des_prev
== 0 && c_dialect_objc ())
3133 /* This might be an array designator or an
3134 Objective-C message expression. If the former,
3135 continue parsing here; if the latter, parse the
3136 remainder of the initializer given the starting
3137 primary-expression. ??? It might make sense to
3138 distinguish when des_prev == 1 as well; see
3139 previous comment. */
3141 struct c_expr mexpr
;
3142 c_parser_consume_token (parser
);
3143 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3144 && ((c_parser_peek_token (parser
)->id_kind
3146 || (c_parser_peek_token (parser
)->id_kind
3147 == C_ID_CLASSNAME
)))
3149 /* Type name receiver. */
3150 tree id
= c_parser_peek_token (parser
)->value
;
3151 c_parser_consume_token (parser
);
3152 rec
= objc_get_class_reference (id
);
3153 goto parse_message_args
;
3155 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3156 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3157 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3158 goto array_desig_after_first
;
3159 /* Expression receiver. So far only one part
3160 without commas has been parsed; there might be
3161 more of the expression. */
3163 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3166 c_parser_consume_token (parser
);
3167 next
= c_parser_expr_no_commas (parser
, NULL
);
3168 next
= default_function_array_conversion (next
);
3169 rec
= build_compound_expr (rec
, next
.value
);
3172 /* Now parse the objc-message-args. */
3173 args
= c_parser_objc_message_args (parser
);
3174 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3177 = objc_build_message_expr (build_tree_list (rec
, args
));
3178 mexpr
.original_code
= ERROR_MARK
;
3179 mexpr
.original_type
= NULL
;
3180 /* Now parse and process the remainder of the
3181 initializer, starting with this message
3182 expression as a primary-expression. */
3183 c_parser_initval (parser
, &mexpr
);
3186 c_parser_consume_token (parser
);
3187 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3188 array_desig_after_first
:
3189 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3191 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3192 c_parser_consume_token (parser
);
3193 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3197 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3199 c_parser_consume_token (parser
);
3200 set_init_index (first
, second
);
3202 pedwarn (ellipsis_loc
, OPT_pedantic
,
3203 "ISO C forbids specifying range of elements to initialize");
3206 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3212 if (c_parser_next_token_is (parser
, CPP_EQ
))
3215 pedwarn (des_loc
, OPT_pedantic
,
3216 "ISO C90 forbids specifying subobject to initialize");
3217 c_parser_consume_token (parser
);
3222 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3223 "obsolete use of designated initializer without %<=%>");
3227 init
.value
= error_mark_node
;
3228 init
.original_code
= ERROR_MARK
;
3229 init
.original_type
= NULL
;
3230 c_parser_error (parser
, "expected %<=%>");
3231 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3232 process_init_element (init
, false);
3238 c_parser_initval (parser
, NULL
);
3241 /* Parse a nested initializer; as c_parser_initializer but parses
3242 initializers within braced lists, after any designators have been
3243 applied. If AFTER is not NULL then it is an Objective-C message
3244 expression which is the primary-expression starting the
3248 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3251 gcc_assert (!after
|| c_dialect_objc ());
3252 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3253 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3256 init
= c_parser_expr_no_commas (parser
, after
);
3257 if (init
.value
!= NULL_TREE
3258 && TREE_CODE (init
.value
) != STRING_CST
3259 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3260 init
= default_function_array_conversion (init
);
3262 process_init_element (init
, false);
3265 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3269 { block-item-list[opt] }
3270 { label-declarations block-item-list }
3274 block-item-list block-item
3286 { label-declarations block-item-list }
3289 __extension__ nested-declaration
3290 nested-function-definition
3294 label-declarations label-declaration
3297 __label__ identifier-list ;
3299 Allowing the mixing of declarations and code is new in C99. The
3300 GNU syntax also permits (not shown above) labels at the end of
3301 compound statements, which yield an error. We don't allow labels
3302 on declarations; this might seem like a natural extension, but
3303 there would be a conflict between attributes on the label and
3304 prefix attributes on the declaration. ??? The syntax follows the
3305 old parser in requiring something after label declarations.
3306 Although they are erroneous if the labels declared aren't defined,
3307 is it useful for the syntax to be this way?
3319 c_parser_compound_statement (c_parser
*parser
)
3322 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3324 /* Ensure a scope is entered and left anyway to avoid confusion
3325 if we have just prepared to enter a function body. */
3326 stmt
= c_begin_compound_stmt (true);
3327 c_end_compound_stmt (stmt
, true);
3328 return error_mark_node
;
3330 stmt
= c_begin_compound_stmt (true);
3331 c_parser_compound_statement_nostart (parser
);
3332 return c_end_compound_stmt (stmt
, true);
3335 /* Parse a compound statement except for the opening brace. This is
3336 used for parsing both compound statements and statement expressions
3337 (which follow different paths to handling the opening). */
3340 c_parser_compound_statement_nostart (c_parser
*parser
)
3342 bool last_stmt
= false;
3343 bool last_label
= false;
3344 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3345 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3347 c_parser_consume_token (parser
);
3350 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3352 location_t err_loc
= c_parser_peek_token (parser
)->location
;
3353 /* Read zero or more forward-declarations for labels that nested
3354 functions can jump to. */
3355 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3357 c_parser_consume_token (parser
);
3358 /* Any identifiers, including those declared as type names,
3363 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3365 c_parser_error (parser
, "expected identifier");
3369 = declare_label (c_parser_peek_token (parser
)->value
);
3370 C_DECLARED_LABEL_FLAG (label
) = 1;
3371 add_stmt (build_stmt (DECL_EXPR
, label
));
3372 c_parser_consume_token (parser
);
3373 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3374 c_parser_consume_token (parser
);
3378 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3380 pedwarn (err_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3382 /* We must now have at least one statement, label or declaration. */
3383 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3385 c_parser_error (parser
, "expected declaration or statement");
3386 c_parser_consume_token (parser
);
3389 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3391 location_t loc
= c_parser_peek_token (parser
)->location
;
3392 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3393 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3394 || (c_parser_next_token_is (parser
, CPP_NAME
)
3395 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3397 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3398 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3400 label_loc
= c_parser_peek_token (parser
)->location
;
3403 c_parser_label (parser
);
3405 else if (!last_label
3406 && c_parser_next_token_starts_declspecs (parser
))
3409 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3412 (pedantic
&& !flag_isoc99
)
3414 : OPT_Wdeclaration_after_statement
,
3415 "ISO C90 forbids mixed declarations and code");
3418 else if (!last_label
3419 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3421 /* __extension__ can start a declaration, but is also an
3422 unary operator that can start an expression. Consume all
3423 but the last of a possible series of __extension__ to
3425 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3426 && (c_parser_peek_2nd_token (parser
)->keyword
3428 c_parser_consume_token (parser
);
3429 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3432 ext
= disable_extension_diagnostics ();
3433 c_parser_consume_token (parser
);
3435 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3436 /* Following the old parser, __extension__ does not
3437 disable this diagnostic. */
3438 restore_extension_diagnostics (ext
);
3440 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3442 : OPT_Wdeclaration_after_statement
,
3443 "ISO C90 forbids mixed declarations and code");
3449 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3451 /* External pragmas, and some omp pragmas, are not associated
3452 with regular c code, and so are not to be considered statements
3453 syntactically. This ensures that the user doesn't put them
3454 places that would turn into syntax errors if the directive
3456 if (c_parser_pragma (parser
, pragma_compound
))
3457 last_label
= false, last_stmt
= true;
3459 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3461 c_parser_error (parser
, "expected declaration or statement");
3464 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3466 if (parser
->in_if_block
)
3468 error_at (loc
, """expected %<}%> before %<else%>");
3473 error_at (loc
, "%<else%> without a previous %<if%>");
3474 c_parser_consume_token (parser
);
3483 c_parser_statement_after_labels (parser
);
3486 parser
->error
= false;
3489 error_at (label_loc
, "label at end of compound statement");
3490 c_parser_consume_token (parser
);
3493 /* Parse a label (C90 6.6.1, C99 6.8.1).
3496 identifier : attributes[opt]
3497 case constant-expression :
3503 case constant-expression ... constant-expression :
3505 The use of attributes on labels is a GNU extension. The syntax in
3506 GNU C accepts any expressions without commas, non-constant
3507 expressions being rejected later. */
3510 c_parser_label (c_parser
*parser
)
3512 location_t loc1
= c_parser_peek_token (parser
)->location
;
3513 tree label
= NULL_TREE
;
3514 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3517 c_parser_consume_token (parser
);
3518 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3519 if (c_parser_next_token_is (parser
, CPP_COLON
))
3521 c_parser_consume_token (parser
);
3522 label
= do_case (exp1
, NULL_TREE
);
3524 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3526 c_parser_consume_token (parser
);
3527 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3528 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3529 label
= do_case (exp1
, exp2
);
3532 c_parser_error (parser
, "expected %<:%> or %<...%>");
3534 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3536 c_parser_consume_token (parser
);
3537 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3538 label
= do_case (NULL_TREE
, NULL_TREE
);
3542 tree name
= c_parser_peek_token (parser
)->value
;
3545 location_t loc2
= c_parser_peek_token (parser
)->location
;
3546 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3547 c_parser_consume_token (parser
);
3548 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3549 c_parser_consume_token (parser
);
3550 attrs
= c_parser_attributes (parser
);
3551 tlab
= define_label (loc2
, name
);
3554 decl_attributes (&tlab
, attrs
, 0);
3555 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3560 SET_EXPR_LOCATION (label
, loc1
);
3561 if (c_parser_next_token_starts_declspecs (parser
)
3562 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3563 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3565 error_at (c_parser_peek_token (parser
)->location
,
3566 "a label can only be part of a statement and "
3567 "a declaration is not a statement");
3568 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3569 /*nested*/ true, /*empty_ok*/ false,
3570 /*start_attr_ok*/ true);
3575 /* Parse a statement (C90 6.6, C99 6.8).
3580 expression-statement
3588 expression-statement:
3591 selection-statement:
3595 iteration-statement:
3604 return expression[opt] ;
3617 objc-throw-statement
3618 objc-try-catch-statement
3619 objc-synchronized-statement
3621 objc-throw-statement:
3635 parallel-for-construct
3636 parallel-sections-construct
3643 parallel-directive structured-block
3646 for-directive iteration-statement
3649 sections-directive section-scope
3652 single-directive structured-block
3654 parallel-for-construct:
3655 parallel-for-directive iteration-statement
3657 parallel-sections-construct:
3658 parallel-sections-directive section-scope
3661 master-directive structured-block
3664 critical-directive structured-block
3667 atomic-directive expression-statement
3670 ordered-directive structured-block */
3673 c_parser_statement (c_parser
*parser
)
3675 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3676 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3677 || (c_parser_next_token_is (parser
, CPP_NAME
)
3678 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3679 c_parser_label (parser
);
3680 c_parser_statement_after_labels (parser
);
3683 /* Parse a statement, other than a labeled statement. */
3686 c_parser_statement_after_labels (c_parser
*parser
)
3688 location_t loc
= c_parser_peek_token (parser
)->location
;
3689 tree stmt
= NULL_TREE
;
3690 bool in_if_block
= parser
->in_if_block
;
3691 parser
->in_if_block
= false;
3692 switch (c_parser_peek_token (parser
)->type
)
3694 case CPP_OPEN_BRACE
:
3695 add_stmt (c_parser_compound_statement (parser
));
3698 switch (c_parser_peek_token (parser
)->keyword
)
3701 c_parser_if_statement (parser
);
3704 c_parser_switch_statement (parser
);
3707 c_parser_while_statement (parser
);
3710 c_parser_do_statement (parser
);
3713 c_parser_for_statement (parser
);
3716 c_parser_consume_token (parser
);
3717 if (c_parser_next_token_is (parser
, CPP_NAME
))
3719 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3720 c_parser_consume_token (parser
);
3722 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3724 c_parser_consume_token (parser
);
3725 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3728 c_parser_error (parser
, "expected identifier or %<*%>");
3729 goto expect_semicolon
;
3731 c_parser_consume_token (parser
);
3732 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3733 goto expect_semicolon
;
3735 c_parser_consume_token (parser
);
3736 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3737 goto expect_semicolon
;
3739 c_parser_consume_token (parser
);
3740 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3742 stmt
= c_finish_return (NULL_TREE
);
3743 c_parser_consume_token (parser
);
3747 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3748 goto expect_semicolon
;
3752 stmt
= c_parser_asm_statement (parser
);
3755 gcc_assert (c_dialect_objc ());
3756 c_parser_consume_token (parser
);
3757 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3759 stmt
= objc_build_throw_stmt (NULL_TREE
);
3760 c_parser_consume_token (parser
);
3764 tree expr
= c_parser_expression (parser
).value
;
3765 expr
= c_fully_fold (expr
, false, NULL
);
3766 stmt
= objc_build_throw_stmt (expr
);
3767 goto expect_semicolon
;
3771 gcc_assert (c_dialect_objc ());
3772 c_parser_objc_try_catch_statement (parser
);
3774 case RID_AT_SYNCHRONIZED
:
3775 gcc_assert (c_dialect_objc ());
3776 c_parser_objc_synchronized_statement (parser
);
3783 c_parser_consume_token (parser
);
3785 case CPP_CLOSE_PAREN
:
3786 case CPP_CLOSE_SQUARE
:
3787 /* Avoid infinite loop in error recovery:
3788 c_parser_skip_until_found stops at a closing nesting
3789 delimiter without consuming it, but here we need to consume
3790 it to proceed further. */
3791 c_parser_error (parser
, "expected statement");
3792 c_parser_consume_token (parser
);
3795 c_parser_pragma (parser
, pragma_stmt
);
3799 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3801 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3804 /* Two cases cannot and do not have line numbers associated: If stmt
3805 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3806 cannot hold line numbers. But that's OK because the statement
3807 will either be changed to a MODIFY_EXPR during gimplification of
3808 the statement expr, or discarded. If stmt was compound, but
3809 without new variables, we will have skipped the creation of a
3810 BIND and will have a bare STATEMENT_LIST. But that's OK because
3811 (recursively) all of the component statements should already have
3812 line numbers assigned. ??? Can we discard no-op statements
3814 protected_set_expr_location (stmt
, loc
);
3816 parser
->in_if_block
= in_if_block
;
3819 /* Parse the condition from an if, do, while or for statements. */
3822 c_parser_condition (c_parser
*parser
)
3826 loc
= c_parser_peek_token (parser
)->location
;
3827 cond
= c_parser_expression_conv (parser
).value
;
3828 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3829 cond
= c_fully_fold (cond
, false, NULL
);
3830 protected_set_expr_location (cond
, loc
);
3831 if (warn_sequence_point
)
3832 verify_sequence_points (cond
);
3836 /* Parse a parenthesized condition from an if, do or while statement.
3842 c_parser_paren_condition (c_parser
*parser
)
3845 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3846 return error_mark_node
;
3847 cond
= c_parser_condition (parser
);
3848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3852 /* Parse a statement which is a block in C99. */
3855 c_parser_c99_block_statement (c_parser
*parser
)
3857 tree block
= c_begin_compound_stmt (flag_isoc99
);
3858 c_parser_statement (parser
);
3859 return c_end_compound_stmt (block
, flag_isoc99
);
3862 /* Parse the body of an if statement. This is just parsing a
3863 statement but (a) it is a block in C99, (b) we track whether the
3864 body is an if statement for the sake of -Wparentheses warnings, (c)
3865 we handle an empty body specially for the sake of -Wempty-body
3866 warnings, and (d) we call parser_compound_statement directly
3867 because c_parser_statement_after_labels resets
3868 parser->in_if_block. */
3871 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3873 tree block
= c_begin_compound_stmt (flag_isoc99
);
3874 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3875 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3876 || (c_parser_next_token_is (parser
, CPP_NAME
)
3877 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3878 c_parser_label (parser
);
3879 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3880 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3882 location_t loc
= c_parser_peek_token (parser
)->location
;
3883 add_stmt (build_empty_stmt ());
3884 c_parser_consume_token (parser
);
3885 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3886 warning_at (loc
, OPT_Wempty_body
,
3887 "suggest braces around empty body in an %<if%> statement");
3889 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3890 add_stmt (c_parser_compound_statement (parser
));
3892 c_parser_statement_after_labels (parser
);
3893 return c_end_compound_stmt (block
, flag_isoc99
);
3896 /* Parse the else body of an if statement. This is just parsing a
3897 statement but (a) it is a block in C99, (b) we handle an empty body
3898 specially for the sake of -Wempty-body warnings. */
3901 c_parser_else_body (c_parser
*parser
)
3903 tree block
= c_begin_compound_stmt (flag_isoc99
);
3904 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3905 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3906 || (c_parser_next_token_is (parser
, CPP_NAME
)
3907 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3908 c_parser_label (parser
);
3909 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3911 warning_at (c_parser_peek_token (parser
)->location
,
3913 "suggest braces around empty body in an %<else%> statement");
3914 add_stmt (build_empty_stmt ());
3915 c_parser_consume_token (parser
);
3918 c_parser_statement_after_labels (parser
);
3919 return c_end_compound_stmt (block
, flag_isoc99
);
3922 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3925 if ( expression ) statement
3926 if ( expression ) statement else statement
3930 c_parser_if_statement (c_parser
*parser
)
3935 bool first_if
= false;
3936 tree first_body
, second_body
;
3939 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3940 c_parser_consume_token (parser
);
3941 block
= c_begin_compound_stmt (flag_isoc99
);
3942 loc
= c_parser_peek_token (parser
)->location
;
3943 cond
= c_parser_paren_condition (parser
);
3944 in_if_block
= parser
->in_if_block
;
3945 parser
->in_if_block
= true;
3946 first_body
= c_parser_if_body (parser
, &first_if
);
3947 parser
->in_if_block
= in_if_block
;
3948 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3950 c_parser_consume_token (parser
);
3951 second_body
= c_parser_else_body (parser
);
3954 second_body
= NULL_TREE
;
3955 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3956 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3959 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3962 switch (expression) statement
3966 c_parser_switch_statement (c_parser
*parser
)
3968 tree block
, expr
, body
, save_break
;
3969 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3970 c_parser_consume_token (parser
);
3971 block
= c_begin_compound_stmt (flag_isoc99
);
3972 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3974 expr
= c_parser_expression (parser
).value
;
3975 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3978 expr
= error_mark_node
;
3979 c_start_case (expr
);
3980 save_break
= c_break_label
;
3981 c_break_label
= NULL_TREE
;
3982 body
= c_parser_c99_block_statement (parser
);
3983 c_finish_case (body
);
3985 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3986 c_break_label
= save_break
;
3987 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3990 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3993 while (expression) statement
3997 c_parser_while_statement (c_parser
*parser
)
3999 tree block
, cond
, body
, save_break
, save_cont
;
4001 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4002 c_parser_consume_token (parser
);
4003 block
= c_begin_compound_stmt (flag_isoc99
);
4004 loc
= c_parser_peek_token (parser
)->location
;
4005 cond
= c_parser_paren_condition (parser
);
4006 save_break
= c_break_label
;
4007 c_break_label
= NULL_TREE
;
4008 save_cont
= c_cont_label
;
4009 c_cont_label
= NULL_TREE
;
4010 body
= c_parser_c99_block_statement (parser
);
4011 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4012 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4013 c_break_label
= save_break
;
4014 c_cont_label
= save_cont
;
4017 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4020 do statement while ( expression ) ;
4024 c_parser_do_statement (c_parser
*parser
)
4026 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4028 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4029 c_parser_consume_token (parser
);
4030 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4031 warning_at (c_parser_peek_token (parser
)->location
,
4033 "suggest braces around empty body in %<do%> statement");
4034 block
= c_begin_compound_stmt (flag_isoc99
);
4035 loc
= c_parser_peek_token (parser
)->location
;
4036 save_break
= c_break_label
;
4037 c_break_label
= NULL_TREE
;
4038 save_cont
= c_cont_label
;
4039 c_cont_label
= NULL_TREE
;
4040 body
= c_parser_c99_block_statement (parser
);
4041 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4042 new_break
= c_break_label
;
4043 c_break_label
= save_break
;
4044 new_cont
= c_cont_label
;
4045 c_cont_label
= save_cont
;
4046 cond
= c_parser_paren_condition (parser
);
4047 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4048 c_parser_skip_to_end_of_block_or_statement (parser
);
4049 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4050 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4053 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4056 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4057 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4059 The form with a declaration is new in C99.
4061 ??? In accordance with the old parser, the declaration may be a
4062 nested function, which is then rejected in check_for_loop_decls,
4063 but does it make any sense for this to be included in the grammar?
4064 Note in particular that the nested function does not include a
4065 trailing ';', whereas the "declaration" production includes one.
4066 Also, can we reject bad declarations earlier and cheaper than
4067 check_for_loop_decls? */
4070 c_parser_for_statement (c_parser
*parser
)
4072 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4074 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4075 loc
= c_parser_peek_token (parser
)->location
;
4076 c_parser_consume_token (parser
);
4077 block
= c_begin_compound_stmt (flag_isoc99
);
4078 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4080 /* Parse the initialization declaration or expression. */
4081 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4083 c_parser_consume_token (parser
);
4084 c_finish_expr_stmt (NULL_TREE
);
4086 else if (c_parser_next_token_starts_declspecs (parser
))
4088 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4089 check_for_loop_decls ();
4091 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4093 /* __extension__ can start a declaration, but is also an
4094 unary operator that can start an expression. Consume all
4095 but the last of a possible series of __extension__ to
4097 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4098 && (c_parser_peek_2nd_token (parser
)->keyword
4100 c_parser_consume_token (parser
);
4101 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4104 ext
= disable_extension_diagnostics ();
4105 c_parser_consume_token (parser
);
4106 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4107 restore_extension_diagnostics (ext
);
4108 check_for_loop_decls ();
4116 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4117 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4119 /* Parse the loop condition. */
4120 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4122 c_parser_consume_token (parser
);
4127 cond
= c_parser_condition (parser
);
4128 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4130 /* Parse the increment expression. */
4131 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4132 incr
= c_process_expr_stmt (NULL_TREE
);
4134 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4135 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4139 cond
= error_mark_node
;
4140 incr
= error_mark_node
;
4142 save_break
= c_break_label
;
4143 c_break_label
= NULL_TREE
;
4144 save_cont
= c_cont_label
;
4145 c_cont_label
= NULL_TREE
;
4146 body
= c_parser_c99_block_statement (parser
);
4147 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4148 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4149 c_break_label
= save_break
;
4150 c_cont_label
= save_cont
;
4153 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4154 statement with inputs, outputs, clobbers, and volatile tag
4158 asm type-qualifier[opt] ( asm-argument ) ;
4162 asm-string-literal : asm-operands[opt]
4163 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4164 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4166 Qualifiers other than volatile are accepted in the syntax but
4170 c_parser_asm_statement (c_parser
*parser
)
4172 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4174 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4175 c_parser_consume_token (parser
);
4176 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4178 quals
= c_parser_peek_token (parser
)->value
;
4179 c_parser_consume_token (parser
);
4181 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4182 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4184 warning_at (c_parser_peek_token (parser
)->location
,
4186 "%E qualifier ignored on asm",
4187 c_parser_peek_token (parser
)->value
);
4189 c_parser_consume_token (parser
);
4193 /* ??? Follow the C++ parser rather than using the
4194 lex_untranslated_string kludge. */
4195 parser
->lex_untranslated_string
= true;
4196 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4198 parser
->lex_untranslated_string
= false;
4201 str
= c_parser_asm_string_literal (parser
);
4202 if (str
== NULL_TREE
)
4204 parser
->lex_untranslated_string
= false;
4205 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4208 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4211 outputs
= NULL_TREE
;
4213 clobbers
= NULL_TREE
;
4216 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4218 parser
->lex_untranslated_string
= false;
4219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4223 /* Parse outputs. */
4224 if (c_parser_next_token_is (parser
, CPP_COLON
)
4225 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4226 outputs
= NULL_TREE
;
4228 outputs
= c_parser_asm_operands (parser
, false);
4229 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4232 clobbers
= NULL_TREE
;
4235 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4237 parser
->lex_untranslated_string
= false;
4238 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4242 if (c_parser_next_token_is (parser
, CPP_COLON
)
4243 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4246 inputs
= c_parser_asm_operands (parser
, true);
4247 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4249 clobbers
= NULL_TREE
;
4252 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4254 parser
->lex_untranslated_string
= false;
4255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4258 /* Parse clobbers. */
4259 clobbers
= c_parser_asm_clobbers (parser
);
4261 parser
->lex_untranslated_string
= false;
4262 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4264 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4267 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4268 c_parser_skip_to_end_of_block_or_statement (parser
);
4269 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4274 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4275 not outputs), apply the default conversion of functions and arrays
4280 asm-operands , asm-operand
4283 asm-string-literal ( expression )
4284 [ identifier ] asm-string-literal ( expression )
4288 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4290 tree list
= NULL_TREE
;
4295 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4297 c_parser_consume_token (parser
);
4298 if (c_parser_next_token_is (parser
, CPP_NAME
))
4300 tree id
= c_parser_peek_token (parser
)->value
;
4301 c_parser_consume_token (parser
);
4302 name
= build_string (IDENTIFIER_LENGTH (id
),
4303 IDENTIFIER_POINTER (id
));
4307 c_parser_error (parser
, "expected identifier");
4308 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4311 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4316 str
= c_parser_asm_string_literal (parser
);
4317 if (str
== NULL_TREE
)
4319 parser
->lex_untranslated_string
= false;
4320 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4322 parser
->lex_untranslated_string
= true;
4325 expr
= c_parser_expression (parser
);
4327 expr
= default_function_array_conversion (expr
);
4328 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4329 parser
->lex_untranslated_string
= true;
4330 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4332 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4335 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4337 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4338 c_parser_consume_token (parser
);
4345 /* Parse asm clobbers, a GNU extension.
4349 asm-clobbers , asm-string-literal
4353 c_parser_asm_clobbers (c_parser
*parser
)
4355 tree list
= NULL_TREE
;
4358 tree str
= c_parser_asm_string_literal (parser
);
4360 list
= tree_cons (NULL_TREE
, str
, list
);
4363 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4364 c_parser_consume_token (parser
);
4371 /* Parse an expression other than a compound expression; that is, an
4372 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4373 NULL then it is an Objective-C message expression which is the
4374 primary-expression starting the expression as an initializer.
4376 assignment-expression:
4377 conditional-expression
4378 unary-expression assignment-operator assignment-expression
4380 assignment-operator: one of
4381 = *= /= %= += -= <<= >>= &= ^= |=
4383 In GNU C we accept any conditional expression on the LHS and
4384 diagnose the invalid lvalue rather than producing a syntax
4387 static struct c_expr
4388 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4390 struct c_expr lhs
, rhs
, ret
;
4391 enum tree_code code
;
4392 location_t op_location
;
4393 gcc_assert (!after
|| c_dialect_objc ());
4394 lhs
= c_parser_conditional_expression (parser
, after
);
4395 op_location
= c_parser_peek_token (parser
)->location
;
4396 switch (c_parser_peek_token (parser
)->type
)
4405 code
= TRUNC_DIV_EXPR
;
4408 code
= TRUNC_MOD_EXPR
;
4423 code
= BIT_AND_EXPR
;
4426 code
= BIT_XOR_EXPR
;
4429 code
= BIT_IOR_EXPR
;
4434 c_parser_consume_token (parser
);
4435 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4436 rhs
= default_function_array_conversion (rhs
);
4437 ret
.value
= build_modify_expr (op_location
, lhs
.value
, code
, rhs
.value
);
4438 if (code
== NOP_EXPR
)
4439 ret
.original_code
= MODIFY_EXPR
;
4442 TREE_NO_WARNING (ret
.value
) = 1;
4443 ret
.original_code
= ERROR_MARK
;
4445 ret
.original_type
= NULL
;
4449 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4450 is not NULL then it is an Objective-C message expression which is
4451 the primary-expression starting the expression as an initializer.
4453 conditional-expression:
4454 logical-OR-expression
4455 logical-OR-expression ? expression : conditional-expression
4459 conditional-expression:
4460 logical-OR-expression ? : conditional-expression
4463 static struct c_expr
4464 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4466 struct c_expr cond
, exp1
, exp2
, ret
;
4467 location_t cond_loc
;
4469 gcc_assert (!after
|| c_dialect_objc ());
4471 cond_loc
= c_parser_peek_token (parser
)->location
;
4472 cond
= c_parser_binary_expression (parser
, after
);
4473 protected_set_expr_location (cond
.value
, cond_loc
);
4475 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4477 cond
= default_function_array_conversion (cond
);
4478 c_parser_consume_token (parser
);
4479 if (c_parser_next_token_is (parser
, CPP_COLON
))
4481 tree eptype
= NULL_TREE
;
4482 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4483 "ISO C forbids omitting the middle term of a ?: expression");
4484 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4486 eptype
= TREE_TYPE (cond
.value
);
4487 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4489 /* Make sure first operand is calculated only once. */
4490 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4492 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4493 exp1
.original_type
= NULL
;
4494 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4495 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4500 = c_objc_common_truthvalue_conversion
4501 (cond_loc
, default_conversion (cond
.value
));
4502 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4503 exp1
= c_parser_expression_conv (parser
);
4504 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4505 - (cond
.value
== truthvalue_false_node
));
4507 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4509 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4510 ret
.value
= error_mark_node
;
4511 ret
.original_code
= ERROR_MARK
;
4512 ret
.original_type
= NULL
;
4515 exp2
= c_parser_conditional_expression (parser
, NULL
);
4516 exp2
= default_function_array_conversion (exp2
);
4517 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4518 ret
.value
= build_conditional_expr (cond
.value
,
4519 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4520 exp1
.value
, exp2
.value
);
4521 ret
.original_code
= ERROR_MARK
;
4522 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4523 ret
.original_type
= NULL
;
4528 /* If both sides are enum type, the default conversion will have
4529 made the type of the result be an integer type. We want to
4530 remember the enum types we started with. */
4531 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4532 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4533 ret
.original_type
= ((t1
!= error_mark_node
4534 && t2
!= error_mark_node
4535 && (TYPE_MAIN_VARIANT (t1
)
4536 == TYPE_MAIN_VARIANT (t2
)))
4543 /* Parse a binary expression; that is, a logical-OR-expression (C90
4544 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4545 an Objective-C message expression which is the primary-expression
4546 starting the expression as an initializer.
4548 multiplicative-expression:
4550 multiplicative-expression * cast-expression
4551 multiplicative-expression / cast-expression
4552 multiplicative-expression % cast-expression
4554 additive-expression:
4555 multiplicative-expression
4556 additive-expression + multiplicative-expression
4557 additive-expression - multiplicative-expression
4561 shift-expression << additive-expression
4562 shift-expression >> additive-expression
4564 relational-expression:
4566 relational-expression < shift-expression
4567 relational-expression > shift-expression
4568 relational-expression <= shift-expression
4569 relational-expression >= shift-expression
4571 equality-expression:
4572 relational-expression
4573 equality-expression == relational-expression
4574 equality-expression != relational-expression
4578 AND-expression & equality-expression
4580 exclusive-OR-expression:
4582 exclusive-OR-expression ^ AND-expression
4584 inclusive-OR-expression:
4585 exclusive-OR-expression
4586 inclusive-OR-expression | exclusive-OR-expression
4588 logical-AND-expression:
4589 inclusive-OR-expression
4590 logical-AND-expression && inclusive-OR-expression
4592 logical-OR-expression:
4593 logical-AND-expression
4594 logical-OR-expression || logical-AND-expression
4597 static struct c_expr
4598 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4600 /* A binary expression is parsed using operator-precedence parsing,
4601 with the operands being cast expressions. All the binary
4602 operators are left-associative. Thus a binary expression is of
4605 E0 op1 E1 op2 E2 ...
4607 which we represent on a stack. On the stack, the precedence
4608 levels are strictly increasing. When a new operator is
4609 encountered of higher precedence than that at the top of the
4610 stack, it is pushed; its LHS is the top expression, and its RHS
4611 is everything parsed until it is popped. When a new operator is
4612 encountered with precedence less than or equal to that at the top
4613 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4614 by the result of the operation until the operator at the top of
4615 the stack has lower precedence than the new operator or there is
4616 only one element on the stack; then the top expression is the LHS
4617 of the new operator. In the case of logical AND and OR
4618 expressions, we also need to adjust skip_evaluation as
4619 appropriate when the operators are pushed and popped. */
4621 /* The precedence levels, where 0 is a dummy lowest level used for
4622 the bottom of the stack. */
4638 /* The expression at this stack level. */
4640 /* The precedence of the operator on its left, PREC_NONE at the
4641 bottom of the stack. */
4643 /* The operation on its left. */
4647 /* Location of the binary operator. */
4648 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4651 switch (stack[sp].op) \
4653 case TRUTH_ANDIF_EXPR: \
4654 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4656 case TRUTH_ORIF_EXPR: \
4657 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4662 stack[sp - 1].expr \
4663 = default_function_array_conversion (stack[sp - 1].expr); \
4665 = default_function_array_conversion (stack[sp].expr); \
4666 stack[sp - 1].expr = parser_build_binary_op (binary_loc, \
4668 stack[sp - 1].expr, \
4672 gcc_assert (!after
|| c_dialect_objc ());
4673 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4674 stack
[0].prec
= PREC_NONE
;
4679 enum tree_code ocode
;
4682 switch (c_parser_peek_token (parser
)->type
)
4690 ocode
= TRUNC_DIV_EXPR
;
4694 ocode
= TRUNC_MOD_EXPR
;
4706 ocode
= LSHIFT_EXPR
;
4710 ocode
= RSHIFT_EXPR
;
4724 case CPP_GREATER_EQ
:
4737 oprec
= PREC_BITAND
;
4738 ocode
= BIT_AND_EXPR
;
4741 oprec
= PREC_BITXOR
;
4742 ocode
= BIT_XOR_EXPR
;
4746 ocode
= BIT_IOR_EXPR
;
4749 oprec
= PREC_LOGAND
;
4750 ocode
= TRUTH_ANDIF_EXPR
;
4754 ocode
= TRUTH_ORIF_EXPR
;
4757 /* Not a binary operator, so end of the binary
4761 binary_loc
= c_parser_peek_token (parser
)->location
;
4762 c_parser_consume_token (parser
);
4763 while (oprec
<= stack
[sp
].prec
)
4767 case TRUTH_ANDIF_EXPR
:
4769 = default_function_array_conversion (stack
[sp
].expr
);
4770 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4771 (binary_loc
, default_conversion (stack
[sp
].expr
.value
));
4772 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4774 case TRUTH_ORIF_EXPR
:
4776 = default_function_array_conversion (stack
[sp
].expr
);
4777 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4778 (binary_loc
, default_conversion (stack
[sp
].expr
.value
));
4779 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4785 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4786 stack
[sp
].prec
= oprec
;
4787 stack
[sp
].op
= ocode
;
4792 return stack
[0].expr
;
4796 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4797 NULL then it is an Objective-C message expression which is the
4798 primary-expression starting the expression as an initializer.
4802 ( type-name ) unary-expression
4805 static struct c_expr
4806 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4808 gcc_assert (!after
|| c_dialect_objc ());
4810 return c_parser_postfix_expression_after_primary (parser
, *after
);
4811 /* If the expression begins with a parenthesized type name, it may
4812 be either a cast or a compound literal; we need to see whether
4813 the next character is '{' to tell the difference. If not, it is
4814 an unary expression. */
4815 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4816 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4818 struct c_type_name
*type_name
;
4821 c_parser_consume_token (parser
);
4822 type_name
= c_parser_type_name (parser
);
4823 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4824 if (type_name
== NULL
)
4826 ret
.value
= error_mark_node
;
4827 ret
.original_code
= ERROR_MARK
;
4828 ret
.original_type
= NULL
;
4832 /* Save casted types in the function's used types hash table. */
4833 used_types_insert (type_name
->specs
->type
);
4835 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4836 return c_parser_postfix_expression_after_paren_type (parser
,
4838 expr
= c_parser_cast_expression (parser
, NULL
);
4839 expr
= default_function_array_conversion (expr
);
4840 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4841 ret
.original_code
= ERROR_MARK
;
4842 ret
.original_type
= NULL
;
4846 return c_parser_unary_expression (parser
);
4849 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4855 unary-operator cast-expression
4856 sizeof unary-expression
4857 sizeof ( type-name )
4859 unary-operator: one of
4865 __alignof__ unary-expression
4866 __alignof__ ( type-name )
4869 unary-operator: one of
4870 __extension__ __real__ __imag__
4872 In addition, the GNU syntax treats ++ and -- as unary operators, so
4873 they may be applied to cast expressions with errors for non-lvalues
4876 static struct c_expr
4877 c_parser_unary_expression (c_parser
*parser
)
4880 struct c_expr ret
, op
;
4881 location_t loc
= c_parser_peek_token (parser
)->location
;
4882 ret
.original_code
= ERROR_MARK
;
4883 ret
.original_type
= NULL
;
4884 switch (c_parser_peek_token (parser
)->type
)
4887 c_parser_consume_token (parser
);
4888 op
= c_parser_cast_expression (parser
, NULL
);
4889 op
= default_function_array_conversion (op
);
4890 return parser_build_unary_op (PREINCREMENT_EXPR
, op
, loc
);
4891 case CPP_MINUS_MINUS
:
4892 c_parser_consume_token (parser
);
4893 op
= c_parser_cast_expression (parser
, NULL
);
4894 op
= default_function_array_conversion (op
);
4895 return parser_build_unary_op (PREDECREMENT_EXPR
, op
, loc
);
4897 c_parser_consume_token (parser
);
4898 return parser_build_unary_op (ADDR_EXPR
,
4899 c_parser_cast_expression (parser
, NULL
),
4902 c_parser_consume_token (parser
);
4903 op
= c_parser_cast_expression (parser
, NULL
);
4904 op
= default_function_array_conversion (op
);
4905 ret
.value
= build_indirect_ref (loc
, op
.value
, "unary *");
4908 if (!c_dialect_objc () && !in_system_header
)
4909 warning_at (c_parser_peek_token (parser
)->location
,
4911 "traditional C rejects the unary plus operator");
4912 c_parser_consume_token (parser
);
4913 op
= c_parser_cast_expression (parser
, NULL
);
4914 op
= default_function_array_conversion (op
);
4915 return parser_build_unary_op (CONVERT_EXPR
, op
, loc
);
4917 c_parser_consume_token (parser
);
4918 op
= c_parser_cast_expression (parser
, NULL
);
4919 op
= default_function_array_conversion (op
);
4920 return parser_build_unary_op (NEGATE_EXPR
, op
, loc
);
4922 c_parser_consume_token (parser
);
4923 op
= c_parser_cast_expression (parser
, NULL
);
4924 op
= default_function_array_conversion (op
);
4925 return parser_build_unary_op (BIT_NOT_EXPR
, op
, loc
);
4927 c_parser_consume_token (parser
);
4928 op
= c_parser_cast_expression (parser
, NULL
);
4929 op
= default_function_array_conversion (op
);
4930 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
, loc
);
4932 /* Refer to the address of a label as a pointer. */
4933 c_parser_consume_token (parser
);
4934 if (c_parser_next_token_is (parser
, CPP_NAME
))
4936 ret
.value
= finish_label_address_expr
4937 (c_parser_peek_token (parser
)->value
, loc
);
4938 c_parser_consume_token (parser
);
4942 c_parser_error (parser
, "expected identifier");
4943 ret
.value
= error_mark_node
;
4947 switch (c_parser_peek_token (parser
)->keyword
)
4950 return c_parser_sizeof_expression (parser
);
4952 return c_parser_alignof_expression (parser
);
4954 c_parser_consume_token (parser
);
4955 ext
= disable_extension_diagnostics ();
4956 ret
= c_parser_cast_expression (parser
, NULL
);
4957 restore_extension_diagnostics (ext
);
4960 c_parser_consume_token (parser
);
4961 op
= c_parser_cast_expression (parser
, NULL
);
4962 op
= default_function_array_conversion (op
);
4963 return parser_build_unary_op (REALPART_EXPR
, op
, loc
);
4965 c_parser_consume_token (parser
);
4966 op
= c_parser_cast_expression (parser
, NULL
);
4967 op
= default_function_array_conversion (op
);
4968 return parser_build_unary_op (IMAGPART_EXPR
, op
, loc
);
4970 return c_parser_postfix_expression (parser
);
4973 return c_parser_postfix_expression (parser
);
4977 /* Parse a sizeof expression. */
4979 static struct c_expr
4980 c_parser_sizeof_expression (c_parser
*parser
)
4983 location_t expr_loc
;
4984 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4985 c_parser_consume_token (parser
);
4988 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4989 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4991 /* Either sizeof ( type-name ) or sizeof unary-expression
4992 starting with a compound literal. */
4993 struct c_type_name
*type_name
;
4994 c_parser_consume_token (parser
);
4995 expr_loc
= c_parser_peek_token (parser
)->location
;
4996 type_name
= c_parser_type_name (parser
);
4997 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4998 if (type_name
== NULL
)
5003 ret
.value
= error_mark_node
;
5004 ret
.original_code
= ERROR_MARK
;
5005 ret
.original_type
= NULL
;
5008 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5010 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5014 /* sizeof ( type-name ). */
5017 return c_expr_sizeof_type (type_name
);
5021 expr_loc
= c_parser_peek_token (parser
)->location
;
5022 expr
= c_parser_unary_expression (parser
);
5026 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5027 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5028 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5029 return c_expr_sizeof_expr (expr
);
5033 /* Parse an alignof expression. */
5035 static struct c_expr
5036 c_parser_alignof_expression (c_parser
*parser
)
5039 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5040 c_parser_consume_token (parser
);
5043 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5044 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5046 /* Either __alignof__ ( type-name ) or __alignof__
5047 unary-expression starting with a compound literal. */
5048 struct c_type_name
*type_name
;
5050 c_parser_consume_token (parser
);
5051 type_name
= c_parser_type_name (parser
);
5052 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5053 if (type_name
== NULL
)
5058 ret
.value
= error_mark_node
;
5059 ret
.original_code
= ERROR_MARK
;
5060 ret
.original_type
= NULL
;
5063 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5065 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5069 /* alignof ( type-name ). */
5072 ret
.value
= c_alignof (groktypename (type_name
, NULL
, NULL
));
5073 ret
.original_code
= ERROR_MARK
;
5074 ret
.original_type
= NULL
;
5080 expr
= c_parser_unary_expression (parser
);
5084 ret
.value
= c_alignof_expr (expr
.value
);
5085 ret
.original_code
= ERROR_MARK
;
5086 ret
.original_type
= NULL
;
5091 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5095 postfix-expression [ expression ]
5096 postfix-expression ( argument-expression-list[opt] )
5097 postfix-expression . identifier
5098 postfix-expression -> identifier
5099 postfix-expression ++
5100 postfix-expression --
5101 ( type-name ) { initializer-list }
5102 ( type-name ) { initializer-list , }
5104 argument-expression-list:
5106 argument-expression-list , argument-expression
5118 (treated as a keyword in GNU C)
5121 ( compound-statement )
5122 __builtin_va_arg ( assignment-expression , type-name )
5123 __builtin_offsetof ( type-name , offsetof-member-designator )
5124 __builtin_choose_expr ( assignment-expression ,
5125 assignment-expression ,
5126 assignment-expression )
5127 __builtin_types_compatible_p ( type-name , type-name )
5129 offsetof-member-designator:
5131 offsetof-member-designator . identifier
5132 offsetof-member-designator [ expression ]
5137 [ objc-receiver objc-message-args ]
5138 @selector ( objc-selector-arg )
5139 @protocol ( identifier )
5140 @encode ( type-name )
5144 static struct c_expr
5145 c_parser_postfix_expression (c_parser
*parser
)
5147 struct c_expr expr
, e1
, e2
, e3
;
5148 struct c_type_name
*t1
, *t2
;
5150 expr
.original_code
= ERROR_MARK
;
5151 expr
.original_type
= NULL
;
5152 switch (c_parser_peek_token (parser
)->type
)
5155 expr
.value
= c_parser_peek_token (parser
)->value
;
5156 loc
= c_parser_peek_token (parser
)->location
;
5157 c_parser_consume_token (parser
);
5158 if (TREE_CODE (expr
.value
) == FIXED_CST
5159 && !targetm
.fixed_point_supported_p ())
5161 error_at (loc
, "fixed-point types not supported for this target");
5162 expr
.value
= error_mark_node
;
5169 expr
.value
= c_parser_peek_token (parser
)->value
;
5170 c_parser_consume_token (parser
);
5176 expr
.value
= c_parser_peek_token (parser
)->value
;
5177 expr
.original_code
= STRING_CST
;
5178 c_parser_consume_token (parser
);
5180 case CPP_OBJC_STRING
:
5181 gcc_assert (c_dialect_objc ());
5183 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5184 c_parser_consume_token (parser
);
5187 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5189 c_parser_error (parser
, "expected expression");
5190 expr
.value
= error_mark_node
;
5194 tree id
= c_parser_peek_token (parser
)->value
;
5195 location_t loc
= c_parser_peek_token (parser
)->location
;
5196 c_parser_consume_token (parser
);
5197 expr
.value
= build_external_ref (id
,
5198 (c_parser_peek_token (parser
)->type
5199 == CPP_OPEN_PAREN
), loc
,
5200 &expr
.original_type
);
5203 case CPP_OPEN_PAREN
:
5204 /* A parenthesized expression, statement expression or compound
5206 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5208 /* A statement expression. */
5210 location_t here
= c_parser_peek_token (parser
)->location
;
5211 c_parser_consume_token (parser
);
5212 c_parser_consume_token (parser
);
5213 if (cur_stmt_list
== NULL
)
5215 error_at (here
, "braced-group within expression allowed "
5216 "only inside a function");
5217 parser
->error
= true;
5218 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5220 expr
.value
= error_mark_node
;
5223 stmt
= c_begin_stmt_expr ();
5224 c_parser_compound_statement_nostart (parser
);
5225 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5227 pedwarn (here
, OPT_pedantic
,
5228 "ISO C forbids braced-groups within expressions");
5229 expr
.value
= c_finish_stmt_expr (stmt
);
5231 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5233 /* A compound literal. ??? Can we actually get here rather
5234 than going directly to
5235 c_parser_postfix_expression_after_paren_type from
5237 struct c_type_name
*type_name
;
5238 c_parser_consume_token (parser
);
5239 type_name
= c_parser_type_name (parser
);
5240 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5242 if (type_name
== NULL
)
5244 expr
.value
= error_mark_node
;
5247 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5252 /* A parenthesized expression. */
5253 c_parser_consume_token (parser
);
5254 expr
= c_parser_expression (parser
);
5255 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5256 TREE_NO_WARNING (expr
.value
) = 1;
5257 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5258 expr
.original_code
= ERROR_MARK
;
5259 /* Don't change EXPR.ORIGINAL_TYPE. */
5260 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5265 switch (c_parser_peek_token (parser
)->keyword
)
5267 case RID_FUNCTION_NAME
:
5268 case RID_PRETTY_FUNCTION_NAME
:
5269 case RID_C99_FUNCTION_NAME
:
5270 expr
.value
= fname_decl (c_parser_peek_token (parser
)->location
,
5271 c_parser_peek_token (parser
)->keyword
,
5272 c_parser_peek_token (parser
)->value
);
5273 c_parser_consume_token (parser
);
5276 c_parser_consume_token (parser
);
5277 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5279 expr
.value
= error_mark_node
;
5282 e1
= c_parser_expr_no_commas (parser
, NULL
);
5283 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5284 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5286 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5287 expr
.value
= error_mark_node
;
5290 t1
= c_parser_type_name (parser
);
5291 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5295 expr
.value
= error_mark_node
;
5299 tree type_expr
= NULL_TREE
;
5300 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
,
5305 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5306 TREE_TYPE (expr
.value
), type_expr
,
5308 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5313 c_parser_consume_token (parser
);
5314 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5316 expr
.value
= error_mark_node
;
5319 t1
= c_parser_type_name (parser
);
5322 expr
.value
= error_mark_node
;
5325 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5327 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5328 expr
.value
= error_mark_node
;
5332 tree type
= groktypename (t1
, NULL
, NULL
);
5334 if (type
== error_mark_node
)
5335 offsetof_ref
= error_mark_node
;
5337 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5338 /* Parse the second argument to __builtin_offsetof. We
5339 must have one identifier, and beyond that we want to
5340 accept sub structure and sub array references. */
5341 if (c_parser_next_token_is (parser
, CPP_NAME
))
5343 offsetof_ref
= build_component_ref
5344 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5345 c_parser_consume_token (parser
);
5346 while (c_parser_next_token_is (parser
, CPP_DOT
)
5347 || c_parser_next_token_is (parser
,
5349 || c_parser_next_token_is (parser
,
5352 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5354 loc
= c_parser_peek_token (parser
)->location
;
5355 offsetof_ref
= build_array_ref (offsetof_ref
,
5360 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5363 c_parser_consume_token (parser
);
5364 if (c_parser_next_token_is_not (parser
,
5367 c_parser_error (parser
, "expected identifier");
5370 offsetof_ref
= build_component_ref
5372 c_parser_peek_token (parser
)->value
);
5373 c_parser_consume_token (parser
);
5378 loc
= c_parser_peek_token (parser
)->location
;
5379 c_parser_consume_token (parser
);
5380 idx
= c_parser_expression (parser
).value
;
5381 idx
= c_fully_fold (idx
, false, NULL
);
5382 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5384 offsetof_ref
= build_array_ref (offsetof_ref
, idx
, loc
);
5389 c_parser_error (parser
, "expected identifier");
5390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5392 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5395 case RID_CHOOSE_EXPR
:
5396 c_parser_consume_token (parser
);
5397 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5399 expr
.value
= error_mark_node
;
5402 loc
= c_parser_peek_token (parser
)->location
;
5403 e1
= c_parser_expr_no_commas (parser
, NULL
);
5404 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5407 expr
.value
= error_mark_node
;
5410 e2
= c_parser_expr_no_commas (parser
, NULL
);
5411 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5413 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5414 expr
.value
= error_mark_node
;
5417 e3
= c_parser_expr_no_commas (parser
, NULL
);
5418 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5424 if (TREE_CODE (c
) != INTEGER_CST
5425 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5427 "first argument to %<__builtin_choose_expr%> not"
5429 constant_expression_warning (c
);
5430 expr
= integer_zerop (c
) ? e3
: e2
;
5433 case RID_TYPES_COMPATIBLE_P
:
5434 c_parser_consume_token (parser
);
5435 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5437 expr
.value
= error_mark_node
;
5440 t1
= c_parser_type_name (parser
);
5443 expr
.value
= error_mark_node
;
5446 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5449 expr
.value
= error_mark_node
;
5452 t2
= c_parser_type_name (parser
);
5455 expr
.value
= error_mark_node
;
5458 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5463 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5464 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5466 expr
.value
= comptypes (e1
, e2
)
5467 ? build_int_cst (NULL_TREE
, 1)
5468 : build_int_cst (NULL_TREE
, 0);
5471 case RID_AT_SELECTOR
:
5472 gcc_assert (c_dialect_objc ());
5473 c_parser_consume_token (parser
);
5474 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5476 expr
.value
= error_mark_node
;
5480 tree sel
= c_parser_objc_selector_arg (parser
);
5481 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5483 expr
.value
= objc_build_selector_expr (sel
);
5486 case RID_AT_PROTOCOL
:
5487 gcc_assert (c_dialect_objc ());
5488 c_parser_consume_token (parser
);
5489 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5491 expr
.value
= error_mark_node
;
5494 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5496 c_parser_error (parser
, "expected identifier");
5497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5498 expr
.value
= error_mark_node
;
5502 tree id
= c_parser_peek_token (parser
)->value
;
5503 c_parser_consume_token (parser
);
5504 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5506 expr
.value
= objc_build_protocol_expr (id
);
5510 /* Extension to support C-structures in the archiver. */
5511 gcc_assert (c_dialect_objc ());
5512 c_parser_consume_token (parser
);
5513 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5515 expr
.value
= error_mark_node
;
5518 t1
= c_parser_type_name (parser
);
5521 expr
.value
= error_mark_node
;
5522 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5525 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5528 tree type
= groktypename (t1
, NULL
, NULL
);
5529 expr
.value
= objc_build_encode_expr (type
);
5533 c_parser_error (parser
, "expected expression");
5534 expr
.value
= error_mark_node
;
5538 case CPP_OPEN_SQUARE
:
5539 if (c_dialect_objc ())
5541 tree receiver
, args
;
5542 c_parser_consume_token (parser
);
5543 receiver
= c_parser_objc_receiver (parser
);
5544 args
= c_parser_objc_message_args (parser
);
5545 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5547 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5551 /* Else fall through to report error. */
5553 c_parser_error (parser
, "expected expression");
5554 expr
.value
= error_mark_node
;
5557 return c_parser_postfix_expression_after_primary (parser
, expr
);
5560 /* Parse a postfix expression after a parenthesized type name: the
5561 brace-enclosed initializer of a compound literal, possibly followed
5562 by some postfix operators. This is separate because it is not
5563 possible to tell until after the type name whether a cast
5564 expression has a cast or a compound literal, or whether the operand
5565 of sizeof is a parenthesized type name or starts with a compound
5568 static struct c_expr
5569 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5570 struct c_type_name
*type_name
)
5576 location_t start_loc
;
5577 tree type_expr
= NULL_TREE
;
5578 bool type_expr_const
= true;
5579 start_init (NULL_TREE
, NULL
, 0);
5580 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5581 start_loc
= c_parser_peek_token (parser
)->location
;
5582 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5584 error_at (start_loc
, "compound literal has variable size");
5585 type
= error_mark_node
;
5587 init
= c_parser_braced_init (parser
, type
, false);
5589 maybe_warn_string_init (type
, init
);
5592 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5593 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5594 ? CONSTRUCTOR_NON_CONST (init
.value
)
5595 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5596 non_const
|= !type_expr_const
;
5597 expr
.value
= build_compound_literal (type
, init
.value
, non_const
);
5598 expr
.original_code
= ERROR_MARK
;
5599 expr
.original_type
= NULL
;
5602 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5604 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5605 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5609 gcc_assert (!non_const
);
5610 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5611 type_expr
, expr
.value
);
5614 return c_parser_postfix_expression_after_primary (parser
, expr
);
5617 /* Parse a postfix expression after the initial primary or compound
5618 literal; that is, parse a series of postfix operators. */
5620 static struct c_expr
5621 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5624 struct c_expr orig_expr
;
5625 tree ident
, idx
, exprlist
;
5626 location_t loc
= c_parser_peek_token (parser
)->location
;
5629 switch (c_parser_peek_token (parser
)->type
)
5631 case CPP_OPEN_SQUARE
:
5632 /* Array reference. */
5633 loc
= c_parser_peek_token (parser
)->location
;
5634 c_parser_consume_token (parser
);
5635 idx
= c_parser_expression (parser
).value
;
5636 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5638 expr
.value
= build_array_ref (expr
.value
, idx
, loc
);
5639 expr
.original_code
= ERROR_MARK
;
5640 expr
.original_type
= NULL
;
5642 case CPP_OPEN_PAREN
:
5643 /* Function call. */
5644 c_parser_consume_token (parser
);
5645 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5646 exprlist
= NULL_TREE
;
5648 exprlist
= c_parser_expr_list (parser
, true, false);
5649 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5652 expr
.value
= build_function_call (expr
.value
, exprlist
);
5653 expr
.original_code
= ERROR_MARK
;
5654 if (TREE_CODE (expr
.value
) == INTEGER_CST
5655 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5656 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5657 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5658 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5659 expr
.original_type
= NULL
;
5662 /* Structure element reference. */
5663 c_parser_consume_token (parser
);
5664 expr
= default_function_array_conversion (expr
);
5665 if (c_parser_next_token_is (parser
, CPP_NAME
))
5666 ident
= c_parser_peek_token (parser
)->value
;
5669 c_parser_error (parser
, "expected identifier");
5670 expr
.value
= error_mark_node
;
5671 expr
.original_code
= ERROR_MARK
;
5672 expr
.original_type
= NULL
;
5675 c_parser_consume_token (parser
);
5676 expr
.value
= build_component_ref (expr
.value
, ident
);
5677 expr
.original_code
= ERROR_MARK
;
5678 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5679 expr
.original_type
= NULL
;
5682 /* Remember the original type of a bitfield. */
5683 tree field
= TREE_OPERAND (expr
.value
, 1);
5684 if (TREE_CODE (field
) != FIELD_DECL
)
5685 expr
.original_type
= NULL
;
5687 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5691 /* Structure element reference. */
5692 c_parser_consume_token (parser
);
5693 expr
= default_function_array_conversion (expr
);
5694 if (c_parser_next_token_is (parser
, CPP_NAME
))
5695 ident
= c_parser_peek_token (parser
)->value
;
5698 c_parser_error (parser
, "expected identifier");
5699 expr
.value
= error_mark_node
;
5700 expr
.original_code
= ERROR_MARK
;
5701 expr
.original_type
= NULL
;
5704 c_parser_consume_token (parser
);
5705 expr
.value
= build_component_ref (build_indirect_ref (loc
,
5709 expr
.original_code
= ERROR_MARK
;
5710 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5711 expr
.original_type
= NULL
;
5714 /* Remember the original type of a bitfield. */
5715 tree field
= TREE_OPERAND (expr
.value
, 1);
5716 if (TREE_CODE (field
) != FIELD_DECL
)
5717 expr
.original_type
= NULL
;
5719 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5723 /* Postincrement. */
5724 c_parser_consume_token (parser
);
5725 expr
= default_function_array_conversion (expr
);
5726 expr
.value
= build_unary_op (loc
,
5727 POSTINCREMENT_EXPR
, expr
.value
, 0);
5728 expr
.original_code
= ERROR_MARK
;
5729 expr
.original_type
= NULL
;
5731 case CPP_MINUS_MINUS
:
5732 /* Postdecrement. */
5733 c_parser_consume_token (parser
);
5734 expr
= default_function_array_conversion (expr
);
5735 expr
.value
= build_unary_op (loc
,
5736 POSTDECREMENT_EXPR
, expr
.value
, 0);
5737 expr
.original_code
= ERROR_MARK
;
5738 expr
.original_type
= NULL
;
5746 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5749 assignment-expression
5750 expression , assignment-expression
5753 static struct c_expr
5754 c_parser_expression (c_parser
*parser
)
5757 expr
= c_parser_expr_no_commas (parser
, NULL
);
5758 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5761 c_parser_consume_token (parser
);
5762 next
= c_parser_expr_no_commas (parser
, NULL
);
5763 next
= default_function_array_conversion (next
);
5764 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5765 expr
.original_code
= COMPOUND_EXPR
;
5766 expr
.original_type
= NULL
;
5771 /* Parse an expression and convert functions or arrays to
5774 static struct c_expr
5775 c_parser_expression_conv (c_parser
*parser
)
5778 expr
= c_parser_expression (parser
);
5779 expr
= default_function_array_conversion (expr
);
5783 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5784 functions and arrays to pointers. If FOLD_P, fold the expressions.
5787 assignment-expression
5788 nonempty-expr-list , assignment-expression
5792 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
)
5796 expr
= c_parser_expr_no_commas (parser
, NULL
);
5798 expr
= default_function_array_conversion (expr
);
5800 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5801 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5802 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5804 c_parser_consume_token (parser
);
5805 expr
= c_parser_expr_no_commas (parser
, NULL
);
5807 expr
= default_function_array_conversion (expr
);
5809 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5810 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5816 /* Parse Objective-C-specific constructs. */
5818 /* Parse an objc-class-definition.
5820 objc-class-definition:
5821 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5822 objc-class-instance-variables[opt] objc-methodprotolist @end
5823 @implementation identifier objc-superclass[opt]
5824 objc-class-instance-variables[opt]
5825 @interface identifier ( identifier ) objc-protocol-refs[opt]
5826 objc-methodprotolist @end
5827 @implementation identifier ( identifier )
5832 "@interface identifier (" must start "@interface identifier (
5833 identifier ) ...": objc-methodprotolist in the first production may
5834 not start with a parenthesized identifier as a declarator of a data
5835 definition with no declaration specifiers if the objc-superclass,
5836 objc-protocol-refs and objc-class-instance-variables are omitted. */
5839 c_parser_objc_class_definition (c_parser
*parser
)
5844 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5846 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5850 c_parser_consume_token (parser
);
5851 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5853 c_parser_error (parser
, "expected identifier");
5856 id1
= c_parser_peek_token (parser
)->value
;
5857 c_parser_consume_token (parser
);
5858 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5861 tree proto
= NULL_TREE
;
5862 c_parser_consume_token (parser
);
5863 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5865 c_parser_error (parser
, "expected identifier");
5866 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5869 id2
= c_parser_peek_token (parser
)->value
;
5870 c_parser_consume_token (parser
);
5871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5874 objc_start_category_implementation (id1
, id2
);
5877 if (c_parser_next_token_is (parser
, CPP_LESS
))
5878 proto
= c_parser_objc_protocol_refs (parser
);
5879 objc_start_category_interface (id1
, id2
, proto
);
5880 c_parser_objc_methodprotolist (parser
);
5881 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5882 objc_finish_interface ();
5885 if (c_parser_next_token_is (parser
, CPP_COLON
))
5887 c_parser_consume_token (parser
);
5888 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5890 c_parser_error (parser
, "expected identifier");
5893 superclass
= c_parser_peek_token (parser
)->value
;
5894 c_parser_consume_token (parser
);
5897 superclass
= NULL_TREE
;
5900 tree proto
= NULL_TREE
;
5901 if (c_parser_next_token_is (parser
, CPP_LESS
))
5902 proto
= c_parser_objc_protocol_refs (parser
);
5903 objc_start_class_interface (id1
, superclass
, proto
);
5906 objc_start_class_implementation (id1
, superclass
);
5907 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5908 c_parser_objc_class_instance_variables (parser
);
5911 objc_continue_interface ();
5912 c_parser_objc_methodprotolist (parser
);
5913 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5914 objc_finish_interface ();
5918 objc_continue_implementation ();
5923 /* Parse objc-class-instance-variables.
5925 objc-class-instance-variables:
5926 { objc-instance-variable-decl-list[opt] }
5928 objc-instance-variable-decl-list:
5929 objc-visibility-spec
5930 objc-instance-variable-decl ;
5932 objc-instance-variable-decl-list objc-visibility-spec
5933 objc-instance-variable-decl-list objc-instance-variable-decl ;
5934 objc-instance-variable-decl-list ;
5936 objc-visibility-spec:
5941 objc-instance-variable-decl:
5946 c_parser_objc_class_instance_variables (c_parser
*parser
)
5948 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5949 c_parser_consume_token (parser
);
5950 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5953 /* Parse any stray semicolon. */
5954 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5956 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
5957 "extra semicolon in struct or union specified");
5958 c_parser_consume_token (parser
);
5961 /* Stop if at the end of the instance variables. */
5962 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5964 c_parser_consume_token (parser
);
5967 /* Parse any objc-visibility-spec. */
5968 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
5970 c_parser_consume_token (parser
);
5971 objc_set_visibility (2);
5974 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
5976 c_parser_consume_token (parser
);
5977 objc_set_visibility (0);
5980 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
5982 c_parser_consume_token (parser
);
5983 objc_set_visibility (1);
5986 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5988 c_parser_pragma (parser
, pragma_external
);
5992 /* Parse some comma-separated declarations. */
5993 decls
= c_parser_struct_declaration (parser
);
5995 /* Comma-separated instance variables are chained together in
5996 reverse order; add them one by one. */
5997 tree ivar
= nreverse (decls
);
5998 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5999 objc_add_instance_variable (copy_node (ivar
));
6001 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6005 /* Parse an objc-class-declaration.
6007 objc-class-declaration:
6008 @class identifier-list ;
6012 c_parser_objc_class_declaration (c_parser
*parser
)
6014 tree list
= NULL_TREE
;
6015 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6016 c_parser_consume_token (parser
);
6017 /* Any identifiers, including those declared as type names, are OK
6022 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6024 c_parser_error (parser
, "expected identifier");
6027 id
= c_parser_peek_token (parser
)->value
;
6028 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6029 c_parser_consume_token (parser
);
6030 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6031 c_parser_consume_token (parser
);
6035 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6036 objc_declare_class (list
);
6039 /* Parse an objc-alias-declaration.
6041 objc-alias-declaration:
6042 @compatibility_alias identifier identifier ;
6046 c_parser_objc_alias_declaration (c_parser
*parser
)
6049 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6050 c_parser_consume_token (parser
);
6051 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6053 c_parser_error (parser
, "expected identifier");
6054 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6057 id1
= c_parser_peek_token (parser
)->value
;
6058 c_parser_consume_token (parser
);
6059 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6061 c_parser_error (parser
, "expected identifier");
6062 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6065 id2
= c_parser_peek_token (parser
)->value
;
6066 c_parser_consume_token (parser
);
6067 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6068 objc_declare_alias (id1
, id2
);
6071 /* Parse an objc-protocol-definition.
6073 objc-protocol-definition:
6074 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6075 @protocol identifier-list ;
6077 "@protocol identifier ;" should be resolved as "@protocol
6078 identifier-list ;": objc-methodprotolist may not start with a
6079 semicolon in the first alternative if objc-protocol-refs are
6083 c_parser_objc_protocol_definition (c_parser
*parser
)
6085 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6086 c_parser_consume_token (parser
);
6087 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6089 c_parser_error (parser
, "expected identifier");
6092 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6093 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6095 tree list
= NULL_TREE
;
6096 /* Any identifiers, including those declared as type names, are
6101 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6103 c_parser_error (parser
, "expected identifier");
6106 id
= c_parser_peek_token (parser
)->value
;
6107 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6108 c_parser_consume_token (parser
);
6109 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6110 c_parser_consume_token (parser
);
6114 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6115 objc_declare_protocols (list
);
6119 tree id
= c_parser_peek_token (parser
)->value
;
6120 tree proto
= NULL_TREE
;
6121 c_parser_consume_token (parser
);
6122 if (c_parser_next_token_is (parser
, CPP_LESS
))
6123 proto
= c_parser_objc_protocol_refs (parser
);
6124 parser
->objc_pq_context
= true;
6125 objc_start_protocol (id
, proto
);
6126 c_parser_objc_methodprotolist (parser
);
6127 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6128 parser
->objc_pq_context
= false;
6129 objc_finish_interface ();
6133 /* Parse an objc-method-type.
6140 static enum tree_code
6141 c_parser_objc_method_type (c_parser
*parser
)
6143 switch (c_parser_peek_token (parser
)->type
)
6146 c_parser_consume_token (parser
);
6149 c_parser_consume_token (parser
);
6156 /* Parse an objc-method-definition.
6158 objc-method-definition:
6159 objc-method-type objc-method-decl ;[opt] compound-statement
6163 c_parser_objc_method_definition (c_parser
*parser
)
6165 enum tree_code type
= c_parser_objc_method_type (parser
);
6167 objc_set_method_type (type
);
6168 parser
->objc_pq_context
= true;
6169 decl
= c_parser_objc_method_decl (parser
);
6170 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6172 c_parser_consume_token (parser
);
6173 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6174 "extra semicolon in method definition specified");
6176 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6178 c_parser_error (parser
, "expected %<{%>");
6181 parser
->objc_pq_context
= false;
6182 objc_start_method_definition (decl
);
6183 add_stmt (c_parser_compound_statement (parser
));
6184 objc_finish_method_definition (current_function_decl
);
6187 /* Parse an objc-methodprotolist.
6189 objc-methodprotolist:
6191 objc-methodprotolist objc-methodproto
6192 objc-methodprotolist declaration
6193 objc-methodprotolist ;
6195 The declaration is a data definition, which may be missing
6196 declaration specifiers under the same rules and diagnostics as
6197 other data definitions outside functions, and the stray semicolon
6198 is diagnosed the same way as a stray semicolon outside a
6202 c_parser_objc_methodprotolist (c_parser
*parser
)
6206 /* The list is terminated by @end. */
6207 switch (c_parser_peek_token (parser
)->type
)
6210 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6211 "ISO C does not allow extra %<;%> outside of a function");
6212 c_parser_consume_token (parser
);
6216 c_parser_objc_methodproto (parser
);
6219 c_parser_pragma (parser
, pragma_external
);
6224 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6226 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6232 /* Parse an objc-methodproto.
6235 objc-method-type objc-method-decl ;
6239 c_parser_objc_methodproto (c_parser
*parser
)
6241 enum tree_code type
= c_parser_objc_method_type (parser
);
6243 objc_set_method_type (type
);
6244 /* Remember protocol qualifiers in prototypes. */
6245 parser
->objc_pq_context
= true;
6246 decl
= c_parser_objc_method_decl (parser
);
6247 /* Forget protocol qualifiers here. */
6248 parser
->objc_pq_context
= false;
6249 objc_add_method_declaration (decl
);
6250 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6253 /* Parse an objc-method-decl.
6256 ( objc-type-name ) objc-selector
6258 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6259 objc-keyword-selector objc-optparmlist
6261 objc-keyword-selector:
6263 objc-keyword-selector objc-keyword-decl
6266 objc-selector : ( objc-type-name ) identifier
6267 objc-selector : identifier
6268 : ( objc-type-name ) identifier
6272 objc-optparms objc-optellipsis
6276 objc-opt-parms , parameter-declaration
6284 c_parser_objc_method_decl (c_parser
*parser
)
6286 tree type
= NULL_TREE
;
6288 tree parms
= NULL_TREE
;
6289 bool ellipsis
= false;
6291 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6293 c_parser_consume_token (parser
);
6294 type
= c_parser_objc_type_name (parser
);
6295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6297 sel
= c_parser_objc_selector (parser
);
6298 /* If there is no selector, or a colon follows, we have an
6299 objc-keyword-selector. If there is a selector, and a colon does
6300 not follow, that selector ends the objc-method-decl. */
6301 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6304 tree list
= NULL_TREE
;
6307 tree atype
= NULL_TREE
, id
, keyworddecl
;
6308 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6310 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6312 c_parser_consume_token (parser
);
6313 atype
= c_parser_objc_type_name (parser
);
6314 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6317 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6319 c_parser_error (parser
, "expected identifier");
6320 return error_mark_node
;
6322 id
= c_parser_peek_token (parser
)->value
;
6323 c_parser_consume_token (parser
);
6324 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6325 list
= chainon (list
, keyworddecl
);
6326 tsel
= c_parser_objc_selector (parser
);
6327 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6330 /* Parse the optional parameter list. Optional Objective-C
6331 method parameters follow the C syntax, and may include '...'
6332 to denote a variable number of arguments. */
6333 parms
= make_node (TREE_LIST
);
6334 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6336 struct c_parm
*parm
;
6337 c_parser_consume_token (parser
);
6338 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6341 c_parser_consume_token (parser
);
6344 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6347 parms
= chainon (parms
,
6348 build_tree_list (NULL_TREE
, grokparm (parm
)));
6352 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6355 /* Parse an objc-type-name.
6358 objc-type-qualifiers[opt] type-name
6359 objc-type-qualifiers[opt]
6361 objc-type-qualifiers:
6363 objc-type-qualifiers objc-type-qualifier
6365 objc-type-qualifier: one of
6366 in out inout bycopy byref oneway
6370 c_parser_objc_type_name (c_parser
*parser
)
6372 tree quals
= NULL_TREE
;
6373 struct c_type_name
*type_name
= NULL
;
6374 tree type
= NULL_TREE
;
6377 c_token
*token
= c_parser_peek_token (parser
);
6378 if (token
->type
== CPP_KEYWORD
6379 && (token
->keyword
== RID_IN
6380 || token
->keyword
== RID_OUT
6381 || token
->keyword
== RID_INOUT
6382 || token
->keyword
== RID_BYCOPY
6383 || token
->keyword
== RID_BYREF
6384 || token
->keyword
== RID_ONEWAY
))
6386 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6387 c_parser_consume_token (parser
);
6392 if (c_parser_next_token_starts_typename (parser
))
6393 type_name
= c_parser_type_name (parser
);
6395 type
= groktypename (type_name
, NULL
, NULL
);
6396 return build_tree_list (quals
, type
);
6399 /* Parse objc-protocol-refs.
6406 c_parser_objc_protocol_refs (c_parser
*parser
)
6408 tree list
= NULL_TREE
;
6409 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6410 c_parser_consume_token (parser
);
6411 /* Any identifiers, including those declared as type names, are OK
6416 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6418 c_parser_error (parser
, "expected identifier");
6421 id
= c_parser_peek_token (parser
)->value
;
6422 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6423 c_parser_consume_token (parser
);
6424 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6425 c_parser_consume_token (parser
);
6429 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6433 /* Parse an objc-try-catch-statement.
6435 objc-try-catch-statement:
6436 @try compound-statement objc-catch-list[opt]
6437 @try compound-statement objc-catch-list[opt] @finally compound-statement
6440 @catch ( parameter-declaration ) compound-statement
6441 objc-catch-list @catch ( parameter-declaration ) compound-statement
6445 c_parser_objc_try_catch_statement (c_parser
*parser
)
6449 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6450 c_parser_consume_token (parser
);
6451 loc
= c_parser_peek_token (parser
)->location
;
6452 stmt
= c_parser_compound_statement (parser
);
6453 objc_begin_try_stmt (loc
, stmt
);
6454 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6456 struct c_parm
*parm
;
6457 c_parser_consume_token (parser
);
6458 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6460 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6463 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6467 objc_begin_catch_clause (grokparm (parm
));
6468 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6469 c_parser_compound_statement_nostart (parser
);
6470 objc_finish_catch_clause ();
6472 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6476 c_parser_consume_token (parser
);
6477 finloc
= c_parser_peek_token (parser
)->location
;
6478 finstmt
= c_parser_compound_statement (parser
);
6479 objc_build_finally_clause (finloc
, finstmt
);
6481 objc_finish_try_stmt ();
6484 /* Parse an objc-synchronized-statement.
6486 objc-synchronized-statement:
6487 @synchronized ( expression ) compound-statement
6491 c_parser_objc_synchronized_statement (c_parser
*parser
)
6495 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6496 c_parser_consume_token (parser
);
6497 loc
= c_parser_peek_token (parser
)->location
;
6498 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6500 expr
= c_parser_expression (parser
).value
;
6501 expr
= c_fully_fold (expr
, false, NULL
);
6502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6505 expr
= error_mark_node
;
6506 stmt
= c_parser_compound_statement (parser
);
6507 objc_build_synchronized (loc
, expr
, stmt
);
6510 /* Parse an objc-selector; return NULL_TREE without an error if the
6511 next token is not an objc-selector.
6516 enum struct union if else while do for switch case default
6517 break continue return goto asm sizeof typeof __alignof
6518 unsigned long const short volatile signed restrict _Complex
6519 in out inout bycopy byref oneway int char float double void _Bool
6521 ??? Why this selection of keywords but not, for example, storage
6522 class specifiers? */
6525 c_parser_objc_selector (c_parser
*parser
)
6527 c_token
*token
= c_parser_peek_token (parser
);
6528 tree value
= token
->value
;
6529 if (token
->type
== CPP_NAME
)
6531 c_parser_consume_token (parser
);
6534 if (token
->type
!= CPP_KEYWORD
)
6536 switch (token
->keyword
)
6577 c_parser_consume_token (parser
);
6584 /* Parse an objc-selector-arg.
6588 objc-keywordname-list
6590 objc-keywordname-list:
6592 objc-keywordname-list objc-keywordname
6600 c_parser_objc_selector_arg (c_parser
*parser
)
6602 tree sel
= c_parser_objc_selector (parser
);
6603 tree list
= NULL_TREE
;
6604 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6608 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6610 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6611 sel
= c_parser_objc_selector (parser
);
6612 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6618 /* Parse an objc-receiver.
6627 c_parser_objc_receiver (c_parser
*parser
)
6629 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6630 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6631 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6633 tree id
= c_parser_peek_token (parser
)->value
;
6634 c_parser_consume_token (parser
);
6635 return objc_get_class_reference (id
);
6637 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6640 /* Parse objc-message-args.
6644 objc-keywordarg-list
6646 objc-keywordarg-list:
6648 objc-keywordarg-list objc-keywordarg
6651 objc-selector : objc-keywordexpr
6656 c_parser_objc_message_args (c_parser
*parser
)
6658 tree sel
= c_parser_objc_selector (parser
);
6659 tree list
= NULL_TREE
;
6660 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6665 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6667 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6668 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6669 sel
= c_parser_objc_selector (parser
);
6670 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6676 /* Parse an objc-keywordexpr.
6683 c_parser_objc_keywordexpr (c_parser
*parser
)
6685 tree list
= c_parser_expr_list (parser
, true, true);
6686 if (TREE_CHAIN (list
) == NULL_TREE
)
6688 /* Just return the expression, remove a level of
6690 return TREE_VALUE (list
);
6694 /* We have a comma expression, we will collapse later. */
6700 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6701 should be considered, statements. ALLOW_STMT is true if we're within
6702 the context of a function and such pragmas are to be allowed. Returns
6703 true if we actually parsed such a pragma. */
6706 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6710 id
= c_parser_peek_token (parser
)->pragma_kind
;
6711 gcc_assert (id
!= PRAGMA_NONE
);
6715 case PRAGMA_OMP_BARRIER
:
6716 if (context
!= pragma_compound
)
6718 if (context
== pragma_stmt
)
6719 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6720 "used in compound statements");
6723 c_parser_omp_barrier (parser
);
6726 case PRAGMA_OMP_FLUSH
:
6727 if (context
!= pragma_compound
)
6729 if (context
== pragma_stmt
)
6730 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6731 "used in compound statements");
6734 c_parser_omp_flush (parser
);
6737 case PRAGMA_OMP_TASKWAIT
:
6738 if (context
!= pragma_compound
)
6740 if (context
== pragma_stmt
)
6741 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6742 "used in compound statements");
6745 c_parser_omp_taskwait (parser
);
6748 case PRAGMA_OMP_THREADPRIVATE
:
6749 c_parser_omp_threadprivate (parser
);
6752 case PRAGMA_OMP_SECTION
:
6753 error_at (c_parser_peek_token (parser
)->location
,
6754 "%<#pragma omp section%> may only be used in "
6755 "%<#pragma omp sections%> construct");
6756 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6759 case PRAGMA_GCC_PCH_PREPROCESS
:
6760 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6761 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6765 if (id
< PRAGMA_FIRST_EXTERNAL
)
6767 if (context
== pragma_external
)
6770 c_parser_error (parser
, "expected declaration specifiers");
6771 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6774 c_parser_omp_construct (parser
);
6780 c_parser_consume_pragma (parser
);
6781 c_invoke_pragma_handler (id
);
6783 /* Skip to EOL, but suppress any error message. Those will have been
6784 generated by the handler routine through calling error, as opposed
6785 to calling c_parser_error. */
6786 parser
->error
= true;
6787 c_parser_skip_to_pragma_eol (parser
);
6792 /* The interface the pragma parsers have to the lexer. */
6795 pragma_lex (tree
*value
)
6797 c_token
*tok
= c_parser_peek_token (the_parser
);
6798 enum cpp_ttype ret
= tok
->type
;
6800 *value
= tok
->value
;
6801 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6805 if (ret
== CPP_KEYWORD
)
6807 c_parser_consume_token (the_parser
);
6814 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6818 c_parser_consume_pragma (parser
);
6819 if (c_parser_next_token_is (parser
, CPP_STRING
))
6821 name
= c_parser_peek_token (parser
)->value
;
6822 c_parser_consume_token (parser
);
6825 c_parser_error (parser
, "expected string literal");
6826 c_parser_skip_to_pragma_eol (parser
);
6829 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6832 /* OpenMP 2.5 parsing routines. */
6834 /* Returns name of the next clause.
6835 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6836 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6837 returned and the token is consumed. */
6839 static pragma_omp_clause
6840 c_parser_omp_clause_name (c_parser
*parser
)
6842 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6844 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6845 result
= PRAGMA_OMP_CLAUSE_IF
;
6846 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6847 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6848 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6850 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6855 if (!strcmp ("collapse", p
))
6856 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6857 else if (!strcmp ("copyin", p
))
6858 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6859 else if (!strcmp ("copyprivate", p
))
6860 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6863 if (!strcmp ("firstprivate", p
))
6864 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6867 if (!strcmp ("lastprivate", p
))
6868 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6871 if (!strcmp ("nowait", p
))
6872 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6873 else if (!strcmp ("num_threads", p
))
6874 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6877 if (!strcmp ("ordered", p
))
6878 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6881 if (!strcmp ("private", p
))
6882 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6885 if (!strcmp ("reduction", p
))
6886 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6889 if (!strcmp ("schedule", p
))
6890 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6891 else if (!strcmp ("shared", p
))
6892 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6895 if (!strcmp ("untied", p
))
6896 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
6901 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6902 c_parser_consume_token (parser
);
6907 /* Validate that a clause of the given type does not already exist. */
6910 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
6915 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6916 if (OMP_CLAUSE_CODE (c
) == code
)
6918 error ("too many %qs clauses", name
);
6926 variable-list , identifier
6928 If KIND is nonzero, create the appropriate node and install the decl
6929 in OMP_CLAUSE_DECL and add the node to the head of the list.
6931 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6932 return the list created. */
6935 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6938 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6939 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6940 c_parser_error (parser
, "expected identifier");
6942 while (c_parser_next_token_is (parser
, CPP_NAME
)
6943 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6945 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6948 undeclared_variable (c_parser_peek_token (parser
)->value
,
6949 c_parser_peek_token (parser
)->location
);
6950 else if (t
== error_mark_node
)
6954 tree u
= build_omp_clause (kind
);
6955 OMP_CLAUSE_DECL (u
) = t
;
6956 OMP_CLAUSE_CHAIN (u
) = list
;
6960 list
= tree_cons (t
, NULL_TREE
, list
);
6962 c_parser_consume_token (parser
);
6964 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6967 c_parser_consume_token (parser
);
6973 /* Similarly, but expect leading and trailing parenthesis. This is a very
6974 common case for omp clauses. */
6977 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
6980 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6982 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6983 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6989 collapse ( constant-expression ) */
6992 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
6994 tree c
, num
= error_mark_node
;
6998 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7000 loc
= c_parser_peek_token (parser
)->location
;
7001 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7003 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7006 if (num
== error_mark_node
)
7008 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7009 || !host_integerp (num
, 0)
7010 || (n
= tree_low_cst (num
, 0)) <= 0
7014 "collapse argument needs positive constant integer expression");
7017 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
7018 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7019 OMP_CLAUSE_CHAIN (c
) = list
;
7024 copyin ( variable-list ) */
7027 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7029 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7033 copyprivate ( variable-list ) */
7036 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7038 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7042 default ( shared | none ) */
7045 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7047 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7050 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7052 if (c_parser_next_token_is (parser
, CPP_NAME
))
7054 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7059 if (strcmp ("none", p
) != 0)
7061 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7065 if (strcmp ("shared", p
) != 0)
7067 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7074 c_parser_consume_token (parser
);
7079 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7081 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7083 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7086 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7087 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
7088 OMP_CLAUSE_CHAIN (c
) = list
;
7089 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7095 firstprivate ( variable-list ) */
7098 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7100 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7104 if ( expression ) */
7107 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7109 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7111 tree t
= c_parser_paren_condition (parser
);
7114 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7116 c
= build_omp_clause (OMP_CLAUSE_IF
);
7117 OMP_CLAUSE_IF_EXPR (c
) = t
;
7118 OMP_CLAUSE_CHAIN (c
) = list
;
7122 c_parser_error (parser
, "expected %<(%>");
7128 lastprivate ( variable-list ) */
7131 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7133 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7140 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7144 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7146 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
7147 OMP_CLAUSE_CHAIN (c
) = list
;
7152 num_threads ( expression ) */
7155 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7157 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7159 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7160 tree c
, t
= c_parser_expression (parser
).value
;
7161 t
= c_fully_fold (t
, false, NULL
);
7163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7165 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7167 c_parser_error (parser
, "expected integer expression");
7171 /* Attempt to statically determine when the number isn't positive. */
7172 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7173 build_int_cst (TREE_TYPE (t
), 0));
7174 if (c
== boolean_true_node
)
7176 warning_at (expr_loc
, 0,
7177 "%<num_threads%> value must be positive");
7178 t
= integer_one_node
;
7181 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7183 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7184 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7185 OMP_CLAUSE_CHAIN (c
) = list
;
7196 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7200 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7202 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7203 OMP_CLAUSE_CHAIN (c
) = list
;
7208 private ( variable-list ) */
7211 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7213 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7217 reduction ( reduction-operator : variable-list )
7220 One of: + * - & ^ | && || */
7223 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7225 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7227 enum tree_code code
;
7229 switch (c_parser_peek_token (parser
)->type
)
7241 code
= BIT_AND_EXPR
;
7244 code
= BIT_XOR_EXPR
;
7247 code
= BIT_IOR_EXPR
;
7250 code
= TRUTH_ANDIF_EXPR
;
7253 code
= TRUTH_ORIF_EXPR
;
7256 c_parser_error (parser
,
7257 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7258 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7259 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7262 c_parser_consume_token (parser
);
7263 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7267 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7268 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7269 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7279 schedule ( schedule-kind )
7280 schedule ( schedule-kind , expression )
7283 static | dynamic | guided | runtime | auto
7287 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7291 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7294 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7296 if (c_parser_next_token_is (parser
, CPP_NAME
))
7298 tree kind
= c_parser_peek_token (parser
)->value
;
7299 const char *p
= IDENTIFIER_POINTER (kind
);
7304 if (strcmp ("dynamic", p
) != 0)
7306 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7310 if (strcmp ("guided", p
) != 0)
7312 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7316 if (strcmp ("runtime", p
) != 0)
7318 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7325 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7326 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7327 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7328 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7332 c_parser_consume_token (parser
);
7333 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7336 c_parser_consume_token (parser
);
7338 here
= c_parser_peek_token (parser
)->location
;
7339 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7340 t
= c_fully_fold (t
, false, NULL
);
7342 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7343 error_at (here
, "schedule %<runtime%> does not take "
7344 "a %<chunk_size%> parameter");
7345 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7347 "schedule %<auto%> does not take "
7348 "a %<chunk_size%> parameter");
7349 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7350 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7352 c_parser_error (parser
, "expected integer expression");
7354 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7357 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7358 "expected %<,%> or %<)%>");
7360 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7361 OMP_CLAUSE_CHAIN (c
) = list
;
7365 c_parser_error (parser
, "invalid schedule kind");
7366 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7371 shared ( variable-list ) */
7374 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7376 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7383 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7387 /* FIXME: Should we allow duplicates? */
7388 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7390 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7391 OMP_CLAUSE_CHAIN (c
) = list
;
7395 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7396 is a bitmask in MASK. Return the list of clauses found; the result
7397 of clause default goes in *pdefault. */
7400 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7403 tree clauses
= NULL
;
7406 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7409 pragma_omp_clause c_kind
;
7411 tree prev
= clauses
;
7413 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7414 c_parser_consume_token (parser
);
7417 here
= c_parser_peek_token (parser
)->location
;
7418 c_kind
= c_parser_omp_clause_name (parser
);
7422 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7423 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7424 c_name
= "collapse";
7426 case PRAGMA_OMP_CLAUSE_COPYIN
:
7427 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7430 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7431 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7432 c_name
= "copyprivate";
7434 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7435 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7438 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7439 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7440 c_name
= "firstprivate";
7442 case PRAGMA_OMP_CLAUSE_IF
:
7443 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7446 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7447 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7448 c_name
= "lastprivate";
7450 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7451 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7454 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7455 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7456 c_name
= "num_threads";
7458 case PRAGMA_OMP_CLAUSE_ORDERED
:
7459 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7462 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7463 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7466 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7467 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7468 c_name
= "reduction";
7470 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7471 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7472 c_name
= "schedule";
7474 case PRAGMA_OMP_CLAUSE_SHARED
:
7475 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7478 case PRAGMA_OMP_CLAUSE_UNTIED
:
7479 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7483 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7487 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7489 /* Remove the invalid clause(s) from the list to avoid
7490 confusing the rest of the compiler. */
7492 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7497 c_parser_skip_to_pragma_eol (parser
);
7499 return c_finish_omp_clauses (clauses
);
7506 In practice, we're also interested in adding the statement to an
7507 outer node. So it is convenient if we work around the fact that
7508 c_parser_statement calls add_stmt. */
7511 c_parser_omp_structured_block (c_parser
*parser
)
7513 tree stmt
= push_stmt_list ();
7514 c_parser_statement (parser
);
7515 return pop_stmt_list (stmt
);
7519 # pragma omp atomic new-line
7523 x binop= expr | x++ | ++x | x-- | --x
7525 +, *, -, /, &, ^, |, <<, >>
7527 where x is an lvalue expression with scalar type. */
7530 c_parser_omp_atomic (c_parser
*parser
)
7534 enum tree_code code
;
7535 struct c_expr rhs_expr
;
7537 c_parser_skip_to_pragma_eol (parser
);
7539 lhs
= c_parser_unary_expression (parser
).value
;
7540 lhs
= c_fully_fold (lhs
, false, NULL
);
7541 switch (TREE_CODE (lhs
))
7545 c_parser_skip_to_end_of_block_or_statement (parser
);
7548 case PREINCREMENT_EXPR
:
7549 case POSTINCREMENT_EXPR
:
7550 lhs
= TREE_OPERAND (lhs
, 0);
7552 rhs
= integer_one_node
;
7555 case PREDECREMENT_EXPR
:
7556 case POSTDECREMENT_EXPR
:
7557 lhs
= TREE_OPERAND (lhs
, 0);
7559 rhs
= integer_one_node
;
7563 switch (c_parser_peek_token (parser
)->type
)
7569 code
= TRUNC_DIV_EXPR
;
7584 code
= BIT_AND_EXPR
;
7587 code
= BIT_IOR_EXPR
;
7590 code
= BIT_XOR_EXPR
;
7593 c_parser_error (parser
,
7594 "invalid operator for %<#pragma omp atomic%>");
7598 c_parser_consume_token (parser
);
7599 rhs_expr
= c_parser_expression (parser
);
7600 rhs_expr
= default_function_array_conversion (rhs_expr
);
7601 rhs
= rhs_expr
.value
;
7602 rhs
= c_fully_fold (rhs
, false, NULL
);
7605 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7606 if (stmt
!= error_mark_node
)
7608 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7613 # pragma omp barrier new-line
7617 c_parser_omp_barrier (c_parser
*parser
)
7619 c_parser_consume_pragma (parser
);
7620 c_parser_skip_to_pragma_eol (parser
);
7622 c_finish_omp_barrier ();
7626 # pragma omp critical [(name)] new-line
7631 c_parser_omp_critical (c_parser
*parser
)
7633 tree stmt
, name
= NULL
;
7635 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7637 c_parser_consume_token (parser
);
7638 if (c_parser_next_token_is (parser
, CPP_NAME
))
7640 name
= c_parser_peek_token (parser
)->value
;
7641 c_parser_consume_token (parser
);
7642 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7645 c_parser_error (parser
, "expected identifier");
7647 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7648 c_parser_error (parser
, "expected %<(%> or end of line");
7649 c_parser_skip_to_pragma_eol (parser
);
7651 stmt
= c_parser_omp_structured_block (parser
);
7652 return c_finish_omp_critical (stmt
, name
);
7656 # pragma omp flush flush-vars[opt] new-line
7659 ( variable-list ) */
7662 c_parser_omp_flush (c_parser
*parser
)
7664 c_parser_consume_pragma (parser
);
7665 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7666 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7667 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7668 c_parser_error (parser
, "expected %<(%> or end of line");
7669 c_parser_skip_to_pragma_eol (parser
);
7671 c_finish_omp_flush ();
7674 /* Parse the restricted form of the for statement allowed by OpenMP.
7675 The real trick here is to determine the loop control variable early
7676 so that we can push a new decl if necessary to make it private. */
7679 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7681 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7682 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7684 bool fail
= false, open_brace_parsed
= false;
7685 int i
, collapse
= 1, nbraces
= 0;
7687 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7688 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7689 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7691 gcc_assert (collapse
>= 1);
7693 declv
= make_tree_vec (collapse
);
7694 initv
= make_tree_vec (collapse
);
7695 condv
= make_tree_vec (collapse
);
7696 incrv
= make_tree_vec (collapse
);
7698 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7700 c_parser_error (parser
, "for statement expected");
7703 loc
= c_parser_peek_token (parser
)->location
;
7704 c_parser_consume_token (parser
);
7706 for (i
= 0; i
< collapse
; i
++)
7710 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7713 /* Parse the initialization declaration or expression. */
7714 if (c_parser_next_token_starts_declspecs (parser
))
7718 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7719 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7720 decl
= check_for_loop_decls ();
7723 if (DECL_INITIAL (decl
) == error_mark_node
)
7724 decl
= error_mark_node
;
7727 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7728 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7730 struct c_expr init_exp
;
7731 location_t init_loc
;
7733 decl
= c_parser_postfix_expression (parser
).value
;
7735 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7736 init_loc
= c_parser_peek_token (parser
)->location
;
7738 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7739 init_exp
= default_function_array_conversion (init_exp
);
7740 init
= build_modify_expr (init_loc
,
7741 decl
, NOP_EXPR
, init_exp
.value
);
7742 init
= c_process_expr_stmt (init
);
7744 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7749 c_parser_error (parser
,
7750 "expected iteration declaration or initialization");
7751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7757 /* Parse the loop condition. */
7759 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7761 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7762 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
7764 cond
= cond_expr
.value
;
7765 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7766 cond
= c_fully_fold (cond
, false, NULL
);
7767 switch (cond_expr
.original_code
)
7775 /* Can't be cond = error_mark_node, because we want to preserve
7776 the location until c_finish_omp_for. */
7777 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
7780 protected_set_expr_location (cond
, cond_loc
);
7782 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7784 /* Parse the increment expression. */
7786 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7788 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7790 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7791 protected_set_expr_location (incr
, incr_loc
);
7793 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7795 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7799 TREE_VEC_ELT (declv
, i
) = decl
;
7800 TREE_VEC_ELT (initv
, i
) = init
;
7801 TREE_VEC_ELT (condv
, i
) = cond
;
7802 TREE_VEC_ELT (incrv
, i
) = incr
;
7806 if (i
== collapse
- 1)
7809 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7810 in between the collapsed for loops to be still considered perfectly
7811 nested. Hopefully the final version clarifies this.
7812 For now handle (multiple) {'s and empty statements. */
7815 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7817 c_parser_consume_token (parser
);
7820 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7822 c_parser_consume_token (parser
);
7826 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7827 c_parser_consume_token (parser
);
7830 c_parser_error (parser
, "not enough perfectly nested loops");
7833 open_brace_parsed
= true;
7843 nbraces
+= bracecount
;
7846 save_break
= c_break_label
;
7847 c_break_label
= size_one_node
;
7848 save_cont
= c_cont_label
;
7849 c_cont_label
= NULL_TREE
;
7850 body
= push_stmt_list ();
7852 if (open_brace_parsed
)
7854 stmt
= c_begin_compound_stmt (true);
7855 c_parser_compound_statement_nostart (parser
);
7856 add_stmt (c_end_compound_stmt (stmt
, true));
7859 add_stmt (c_parser_c99_block_statement (parser
));
7861 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7863 body
= pop_stmt_list (body
);
7864 c_break_label
= save_break
;
7865 c_cont_label
= save_cont
;
7869 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7871 c_parser_consume_token (parser
);
7874 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7875 c_parser_consume_token (parser
);
7878 c_parser_error (parser
, "collapsed loops not perfectly nested");
7881 stmt
= c_begin_compound_stmt (true);
7883 c_parser_compound_statement_nostart (parser
);
7884 body
= c_end_compound_stmt (stmt
, true);
7891 /* Only bother calling c_finish_omp_for if we haven't already generated
7892 an error from the initialization parsing. */
7895 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
7898 if (par_clauses
!= NULL
)
7901 for (c
= par_clauses
; *c
; )
7902 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
7903 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
7904 c
= &OMP_CLAUSE_CHAIN (*c
);
7907 for (i
= 0; i
< collapse
; i
++)
7908 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
7911 c
= &OMP_CLAUSE_CHAIN (*c
);
7912 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7915 "iteration variable %qD should not be firstprivate",
7916 OMP_CLAUSE_DECL (*c
));
7917 *c
= OMP_CLAUSE_CHAIN (*c
);
7921 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
7922 change it to shared (decl) in
7923 OMP_PARALLEL_CLAUSES. */
7924 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
7925 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
7926 OMP_CLAUSE_CHAIN (l
) = clauses
;
7928 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
7932 OMP_FOR_CLAUSES (stmt
) = clauses
;
7939 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
7941 for_block
= TREE_CHAIN (for_block
);
7947 #pragma omp for for-clause[optseq] new-line
7951 #define OMP_FOR_CLAUSE_MASK \
7952 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7953 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7954 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7955 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7956 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7957 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7958 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
7959 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7962 c_parser_omp_for (c_parser
*parser
)
7964 tree block
, clauses
, ret
;
7966 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7969 block
= c_begin_compound_stmt (true);
7970 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
7971 block
= c_end_compound_stmt (block
, true);
7978 # pragma omp master new-line
7983 c_parser_omp_master (c_parser
*parser
)
7985 c_parser_skip_to_pragma_eol (parser
);
7986 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7990 # pragma omp ordered new-line
7995 c_parser_omp_ordered (c_parser
*parser
)
7997 c_parser_skip_to_pragma_eol (parser
);
7998 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
8004 { section-sequence }
8007 section-directive[opt] structured-block
8008 section-sequence section-directive structured-block */
8011 c_parser_omp_sections_scope (c_parser
*parser
)
8014 bool error_suppress
= false;
8017 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8019 /* Avoid skipping until the end of the block. */
8020 parser
->error
= false;
8024 stmt
= push_stmt_list ();
8026 loc
= c_parser_peek_token (parser
)->location
;
8027 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8029 substmt
= push_stmt_list ();
8033 c_parser_statement (parser
);
8035 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8037 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8039 if (c_parser_next_token_is (parser
, CPP_EOF
))
8043 substmt
= pop_stmt_list (substmt
);
8044 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8045 SET_EXPR_LOCATION (substmt
, loc
);
8051 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8053 if (c_parser_next_token_is (parser
, CPP_EOF
))
8056 loc
= c_parser_peek_token (parser
)->location
;
8057 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8059 c_parser_consume_pragma (parser
);
8060 c_parser_skip_to_pragma_eol (parser
);
8061 error_suppress
= false;
8063 else if (!error_suppress
)
8065 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8066 error_suppress
= true;
8069 substmt
= c_parser_omp_structured_block (parser
);
8070 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8071 SET_EXPR_LOCATION (substmt
, loc
);
8074 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8075 "expected %<#pragma omp section%> or %<}%>");
8077 substmt
= pop_stmt_list (stmt
);
8079 stmt
= make_node (OMP_SECTIONS
);
8080 TREE_TYPE (stmt
) = void_type_node
;
8081 OMP_SECTIONS_BODY (stmt
) = substmt
;
8083 return add_stmt (stmt
);
8087 # pragma omp sections sections-clause[optseq] newline
8091 #define OMP_SECTIONS_CLAUSE_MASK \
8092 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8093 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8094 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8095 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8096 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8099 c_parser_omp_sections (c_parser
*parser
)
8101 tree block
, clauses
, ret
;
8103 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8104 "#pragma omp sections");
8106 block
= c_begin_compound_stmt (true);
8107 ret
= c_parser_omp_sections_scope (parser
);
8109 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8110 block
= c_end_compound_stmt (block
, true);
8117 # pragma parallel parallel-clause new-line
8118 # pragma parallel for parallel-for-clause new-line
8119 # pragma parallel sections parallel-sections-clause new-line
8122 #define OMP_PARALLEL_CLAUSE_MASK \
8123 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8124 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8125 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8126 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8127 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8128 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8129 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8130 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8133 c_parser_omp_parallel (c_parser
*parser
)
8135 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8136 const char *p_name
= "#pragma omp parallel";
8137 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8138 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8140 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8142 c_parser_consume_token (parser
);
8143 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8144 p_name
= "#pragma omp parallel for";
8145 mask
|= OMP_FOR_CLAUSE_MASK
;
8146 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8148 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8150 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8151 if (strcmp (p
, "sections") == 0)
8153 c_parser_consume_token (parser
);
8154 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8155 p_name
= "#pragma omp parallel sections";
8156 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8157 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8161 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8165 case PRAGMA_OMP_PARALLEL
:
8166 block
= c_begin_omp_parallel ();
8167 c_parser_statement (parser
);
8168 stmt
= c_finish_omp_parallel (clauses
, block
);
8171 case PRAGMA_OMP_PARALLEL_FOR
:
8172 block
= c_begin_omp_parallel ();
8173 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8174 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
8175 stmt
= c_finish_omp_parallel (par_clause
, block
);
8176 OMP_PARALLEL_COMBINED (stmt
) = 1;
8179 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8180 block
= c_begin_omp_parallel ();
8181 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8182 stmt
= c_parser_omp_sections_scope (parser
);
8184 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8185 stmt
= c_finish_omp_parallel (par_clause
, block
);
8186 OMP_PARALLEL_COMBINED (stmt
) = 1;
8197 # pragma omp single single-clause[optseq] new-line
8201 #define OMP_SINGLE_CLAUSE_MASK \
8202 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8203 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8204 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8205 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8208 c_parser_omp_single (c_parser
*parser
)
8210 tree stmt
= make_node (OMP_SINGLE
);
8211 TREE_TYPE (stmt
) = void_type_node
;
8213 OMP_SINGLE_CLAUSES (stmt
)
8214 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8215 "#pragma omp single");
8216 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8218 return add_stmt (stmt
);
8222 # pragma omp task task-clause[optseq] new-line
8225 #define OMP_TASK_CLAUSE_MASK \
8226 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8227 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8228 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8229 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8230 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8231 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8234 c_parser_omp_task (c_parser
*parser
)
8236 tree clauses
, block
;
8238 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8239 "#pragma omp task");
8241 block
= c_begin_omp_task ();
8242 c_parser_statement (parser
);
8243 return c_finish_omp_task (clauses
, block
);
8247 # pragma omp taskwait new-line
8251 c_parser_omp_taskwait (c_parser
*parser
)
8253 c_parser_consume_pragma (parser
);
8254 c_parser_skip_to_pragma_eol (parser
);
8256 c_finish_omp_taskwait ();
8259 /* Main entry point to parsing most OpenMP pragmas. */
8262 c_parser_omp_construct (c_parser
*parser
)
8264 enum pragma_kind p_kind
;
8268 loc
= c_parser_peek_token (parser
)->location
;
8269 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8270 c_parser_consume_pragma (parser
);
8272 /* For all constructs below except #pragma omp atomic
8273 MUST_NOT_THROW catch handlers are needed when exceptions
8275 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8276 c_maybe_initialize_eh ();
8280 case PRAGMA_OMP_ATOMIC
:
8281 c_parser_omp_atomic (parser
);
8283 case PRAGMA_OMP_CRITICAL
:
8284 stmt
= c_parser_omp_critical (parser
);
8286 case PRAGMA_OMP_FOR
:
8287 stmt
= c_parser_omp_for (parser
);
8289 case PRAGMA_OMP_MASTER
:
8290 stmt
= c_parser_omp_master (parser
);
8292 case PRAGMA_OMP_ORDERED
:
8293 stmt
= c_parser_omp_ordered (parser
);
8295 case PRAGMA_OMP_PARALLEL
:
8296 stmt
= c_parser_omp_parallel (parser
);
8298 case PRAGMA_OMP_SECTIONS
:
8299 stmt
= c_parser_omp_sections (parser
);
8301 case PRAGMA_OMP_SINGLE
:
8302 stmt
= c_parser_omp_single (parser
);
8304 case PRAGMA_OMP_TASK
:
8305 stmt
= c_parser_omp_task (parser
);
8312 SET_EXPR_LOCATION (stmt
, loc
);
8317 # pragma omp threadprivate (variable-list) */
8320 c_parser_omp_threadprivate (c_parser
*parser
)
8324 c_parser_consume_pragma (parser
);
8325 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8327 /* Mark every variable in VARS to be assigned thread local storage. */
8328 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8330 tree v
= TREE_PURPOSE (t
);
8332 /* If V had already been marked threadprivate, it doesn't matter
8333 whether it had been used prior to this point. */
8334 if (TREE_CODE (v
) != VAR_DECL
)
8335 error ("%qD is not a variable", v
);
8336 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8337 error ("%qE declared %<threadprivate%> after first use", v
);
8338 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8339 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8340 else if (TREE_TYPE (v
) == error_mark_node
)
8342 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8343 error ("%<threadprivate%> %qE has incomplete type", v
);
8346 if (! DECL_THREAD_LOCAL_P (v
))
8348 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8349 /* If rtl has been already set for this var, call
8350 make_decl_rtl once again, so that encode_section_info
8351 has a chance to look at the new decl flags. */
8352 if (DECL_RTL_SET_P (v
))
8355 C_DECL_THREADPRIVATE_P (v
) = 1;
8359 c_parser_skip_to_pragma_eol (parser
);
8363 /* Parse a single source file. */
8368 /* Use local storage to begin. If the first token is a pragma, parse it.
8369 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8370 which will cause garbage collection. */
8373 memset (&tparser
, 0, sizeof tparser
);
8374 the_parser
= &tparser
;
8376 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8377 c_parser_pragma_pch_preprocess (&tparser
);
8379 the_parser
= GGC_NEW (c_parser
);
8380 *the_parser
= tparser
;
8382 c_parser_translation_unit (the_parser
);
8386 #include "gt-c-parser.h"