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 GTY (()) c_token
{
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype
) type
: 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid
) keyword
: 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
152 /* The value associated with this token, if any. */
154 /* The location at which this token was found. */
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 typedef struct GTY(()) c_parser
{
162 /* The look-ahead tokens. */
164 /* How many look-ahead tokens are available (0, 1 or 2). */
166 /* True if a syntax error is being recovered from; false otherwise.
167 c_parser_error sets this flag. It should clear this flag when
168 enough tokens have been consumed to recover from the error. */
169 BOOL_BITFIELD error
: 1;
170 /* True if we're processing a pragma, and shouldn't automatically
171 consume CPP_PRAGMA_EOL. */
172 BOOL_BITFIELD in_pragma
: 1;
173 /* True if we're parsing the outermost block of an if statement. */
174 BOOL_BITFIELD in_if_block
: 1;
175 /* True if we want to lex an untranslated string. */
176 BOOL_BITFIELD lex_untranslated_string
: 1;
177 /* Objective-C specific parser/lexer information. */
178 BOOL_BITFIELD objc_pq_context
: 1;
179 /* The following flag is needed to contextualize Objective-C lexical
180 analysis. In some cases (e.g., 'int NSObject;'), it is
181 undesirable to bind an identifier to an Objective-C class, even
182 if a class with that name exists. */
183 BOOL_BITFIELD objc_need_raw_identifier
: 1;
187 /* The actual parser and external interface. ??? Does this need to be
188 garbage-collected? */
190 static GTY (()) c_parser
*the_parser
;
193 /* Read in and lex a single token, storing it in *TOKEN. */
196 c_lex_one_token (c_parser
*parser
, c_token
*token
)
198 timevar_push (TV_LEX
);
200 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
201 (parser
->lex_untranslated_string
202 ? C_LEX_STRING_NO_TRANSLATE
: 0));
203 token
->id_kind
= C_ID_NONE
;
204 token
->keyword
= RID_MAX
;
205 token
->pragma_kind
= PRAGMA_NONE
;
213 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
214 if (c_dialect_objc ())
215 parser
->objc_need_raw_identifier
= false;
217 if (C_IS_RESERVED_WORD (token
->value
))
219 enum rid rid_code
= C_RID_CODE (token
->value
);
221 if (rid_code
== RID_CXX_COMPAT_WARN
)
223 warning_at (token
->location
,
225 "identifier %qE conflicts with C++ keyword",
228 else if (c_dialect_objc ())
230 if (!objc_is_reserved_word (token
->value
)
231 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
232 || parser
->objc_pq_context
))
234 /* Return the canonical spelling for this keyword. */
235 token
->value
= ridpointers
[(int) rid_code
];
236 token
->type
= CPP_KEYWORD
;
237 token
->keyword
= rid_code
;
243 token
->type
= CPP_KEYWORD
;
244 token
->keyword
= rid_code
;
249 decl
= lookup_name (token
->value
);
252 if (TREE_CODE (decl
) == TYPE_DECL
)
254 token
->id_kind
= C_ID_TYPENAME
;
258 else if (c_dialect_objc ())
260 tree objc_interface_decl
= objc_is_class_name (token
->value
);
261 /* Objective-C class names are in the same namespace as
262 variables and typedefs, and hence are shadowed by local
264 if (objc_interface_decl
265 && (global_bindings_p ()
266 || (!objc_force_identifier
&& !decl
)))
268 token
->value
= objc_interface_decl
;
269 token
->id_kind
= C_ID_CLASSNAME
;
273 token
->id_kind
= C_ID_ID
;
277 /* This only happens in Objective-C; it must be a keyword. */
278 token
->type
= CPP_KEYWORD
;
279 token
->keyword
= C_RID_CODE (token
->value
);
283 case CPP_CLOSE_PAREN
:
285 /* These tokens may affect the interpretation of any identifiers
286 following, if doing Objective-C. */
287 if (c_dialect_objc ())
288 parser
->objc_need_raw_identifier
= false;
291 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
292 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
298 timevar_pop (TV_LEX
);
301 /* Return a pointer to the next token from PARSER, reading it in if
304 static inline c_token
*
305 c_parser_peek_token (c_parser
*parser
)
307 if (parser
->tokens_avail
== 0)
309 c_lex_one_token (parser
, &parser
->tokens
[0]);
310 parser
->tokens_avail
= 1;
312 return &parser
->tokens
[0];
315 /* Return true if the next token from PARSER has the indicated
319 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
321 return c_parser_peek_token (parser
)->type
== type
;
324 /* Return true if the next token from PARSER does not have the
328 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
330 return !c_parser_next_token_is (parser
, type
);
333 /* Return true if the next token from PARSER is the indicated
337 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
339 return c_parser_peek_token (parser
)->keyword
== keyword
;
342 /* Return true if TOKEN can start a type name,
345 c_token_starts_typename (c_token
*token
)
350 switch (token
->id_kind
)
357 gcc_assert (c_dialect_objc ());
363 switch (token
->keyword
)
395 if (c_dialect_objc ())
403 /* Return true if the next token from PARSER can start a type name,
406 c_parser_next_token_starts_typename (c_parser
*parser
)
408 c_token
*token
= c_parser_peek_token (parser
);
409 return c_token_starts_typename (token
);
412 /* Return true if TOKEN can start declaration specifiers, false
415 c_token_starts_declspecs (c_token
*token
)
420 switch (token
->id_kind
)
427 gcc_assert (c_dialect_objc ());
433 switch (token
->keyword
)
472 if (c_dialect_objc ())
480 /* Return true if the next token from PARSER can start declaration
481 specifiers, false otherwise. */
483 c_parser_next_token_starts_declspecs (c_parser
*parser
)
485 c_token
*token
= c_parser_peek_token (parser
);
486 return c_token_starts_declspecs (token
);
489 /* Return a pointer to the next-but-one token from PARSER, reading it
490 in if necessary. The next token is already read in. */
493 c_parser_peek_2nd_token (c_parser
*parser
)
495 if (parser
->tokens_avail
>= 2)
496 return &parser
->tokens
[1];
497 gcc_assert (parser
->tokens_avail
== 1);
498 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
499 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
500 c_lex_one_token (parser
, &parser
->tokens
[1]);
501 parser
->tokens_avail
= 2;
502 return &parser
->tokens
[1];
505 /* Consume the next token from PARSER. */
508 c_parser_consume_token (c_parser
*parser
)
510 gcc_assert (parser
->tokens_avail
>= 1);
511 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
512 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
513 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
514 if (parser
->tokens_avail
== 2)
515 parser
->tokens
[0] = parser
->tokens
[1];
516 parser
->tokens_avail
--;
519 /* Expect the current token to be a #pragma. Consume it and remember
520 that we've begun parsing a pragma. */
523 c_parser_consume_pragma (c_parser
*parser
)
525 gcc_assert (!parser
->in_pragma
);
526 gcc_assert (parser
->tokens_avail
>= 1);
527 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
528 if (parser
->tokens_avail
== 2)
529 parser
->tokens
[0] = parser
->tokens
[1];
530 parser
->tokens_avail
--;
531 parser
->in_pragma
= true;
534 /* Update the globals input_location and in_system_header from
537 c_parser_set_source_position_from_token (c_token
*token
)
539 if (token
->type
!= CPP_EOF
)
541 input_location
= token
->location
;
545 /* Issue a diagnostic of the form
546 FILE:LINE: MESSAGE before TOKEN
547 where TOKEN is the next token in the input stream of PARSER.
548 MESSAGE (specified by the caller) is usually of the form "expected
551 Do not issue a diagnostic if still recovering from an error.
553 ??? This is taken from the C++ parser, but building up messages in
554 this way is not i18n-friendly and some other approach should be
558 c_parser_error (c_parser
*parser
, const char *gmsgid
)
560 c_token
*token
= c_parser_peek_token (parser
);
563 parser
->error
= true;
566 /* This diagnostic makes more sense if it is tagged to the line of
567 the token we just peeked at. */
568 c_parser_set_source_position_from_token (token
);
569 c_parse_error (gmsgid
,
570 /* Because c_parse_error does not understand
571 CPP_KEYWORD, keywords are treated like
573 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
574 /* ??? The C parser does not save the cpp flags of a
575 token, we need to pass 0 here and we will not get
576 the source spelling of some tokens but rather the
577 canonical spelling. */
578 token
->value
, /*flags=*/0);
581 /* If the next token is of the indicated TYPE, consume it. Otherwise,
582 issue the error MSGID. If MSGID is NULL then a message has already
583 been produced and no message will be produced this time. Returns
584 true if found, false otherwise. */
587 c_parser_require (c_parser
*parser
,
591 if (c_parser_next_token_is (parser
, type
))
593 c_parser_consume_token (parser
);
598 c_parser_error (parser
, msgid
);
603 /* If the next token is the indicated keyword, consume it. Otherwise,
604 issue the error MSGID. Returns true if found, false otherwise. */
607 c_parser_require_keyword (c_parser
*parser
,
611 if (c_parser_next_token_is_keyword (parser
, keyword
))
613 c_parser_consume_token (parser
);
618 c_parser_error (parser
, msgid
);
623 /* Like c_parser_require, except that tokens will be skipped until the
624 desired token is found. An error message is still produced if the
625 next token is not as expected. If MSGID is NULL then a message has
626 already been produced and no message will be produced this
630 c_parser_skip_until_found (c_parser
*parser
,
634 unsigned nesting_depth
= 0;
636 if (c_parser_require (parser
, type
, msgid
))
639 /* Skip tokens until the desired token is found. */
642 /* Peek at the next token. */
643 c_token
*token
= c_parser_peek_token (parser
);
644 /* If we've reached the token we want, consume it and stop. */
645 if (token
->type
== type
&& !nesting_depth
)
647 c_parser_consume_token (parser
);
651 /* If we've run out of tokens, stop. */
652 if (token
->type
== CPP_EOF
)
654 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
656 if (token
->type
== CPP_OPEN_BRACE
657 || token
->type
== CPP_OPEN_PAREN
658 || token
->type
== CPP_OPEN_SQUARE
)
660 else if (token
->type
== CPP_CLOSE_BRACE
661 || token
->type
== CPP_CLOSE_PAREN
662 || token
->type
== CPP_CLOSE_SQUARE
)
664 if (nesting_depth
-- == 0)
667 /* Consume this token. */
668 c_parser_consume_token (parser
);
670 parser
->error
= false;
673 /* Skip tokens until the end of a parameter is found, but do not
674 consume the comma, semicolon or closing delimiter. */
677 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
679 unsigned nesting_depth
= 0;
683 c_token
*token
= c_parser_peek_token (parser
);
684 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
687 /* If we've run out of tokens, stop. */
688 if (token
->type
== CPP_EOF
)
690 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
692 if (token
->type
== CPP_OPEN_BRACE
693 || token
->type
== CPP_OPEN_PAREN
694 || token
->type
== CPP_OPEN_SQUARE
)
696 else if (token
->type
== CPP_CLOSE_BRACE
697 || token
->type
== CPP_CLOSE_PAREN
698 || token
->type
== CPP_CLOSE_SQUARE
)
700 if (nesting_depth
-- == 0)
703 /* Consume this token. */
704 c_parser_consume_token (parser
);
706 parser
->error
= false;
709 /* Expect to be at the end of the pragma directive and consume an
710 end of line marker. */
713 c_parser_skip_to_pragma_eol (c_parser
*parser
)
715 gcc_assert (parser
->in_pragma
);
716 parser
->in_pragma
= false;
718 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
721 c_token
*token
= c_parser_peek_token (parser
);
722 if (token
->type
== CPP_EOF
)
724 if (token
->type
== CPP_PRAGMA_EOL
)
726 c_parser_consume_token (parser
);
729 c_parser_consume_token (parser
);
732 parser
->error
= false;
735 /* Skip tokens until we have consumed an entire block, or until we
736 have consumed a non-nested ';'. */
739 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
741 unsigned nesting_depth
= 0;
742 bool save_error
= parser
->error
;
748 /* Peek at the next token. */
749 token
= c_parser_peek_token (parser
);
757 if (parser
->in_pragma
)
762 /* If the next token is a ';', we have reached the
763 end of the statement. */
766 /* Consume the ';'. */
767 c_parser_consume_token (parser
);
772 case CPP_CLOSE_BRACE
:
773 /* If the next token is a non-nested '}', then we have
774 reached the end of the current block. */
775 if (nesting_depth
== 0 || --nesting_depth
== 0)
777 c_parser_consume_token (parser
);
783 /* If it the next token is a '{', then we are entering a new
784 block. Consume the entire block. */
789 /* If we see a pragma, consume the whole thing at once. We
790 have some safeguards against consuming pragmas willy-nilly.
791 Normally, we'd expect to be here with parser->error set,
792 which disables these safeguards. But it's possible to get
793 here for secondary error recovery, after parser->error has
795 c_parser_consume_pragma (parser
);
796 c_parser_skip_to_pragma_eol (parser
);
797 parser
->error
= save_error
;
804 c_parser_consume_token (parser
);
808 parser
->error
= false;
811 /* CPP's options (initialized by c-opts.c). */
812 extern cpp_options
*cpp_opts
;
814 /* Save the warning flags which are controlled by __extension__. */
817 disable_extension_diagnostics (void)
820 | (warn_pointer_arith
<< 1)
821 | (warn_traditional
<< 2)
823 | (warn_long_long
<< 4)
824 | (warn_cxx_compat
<< 5));
825 cpp_opts
->pedantic
= pedantic
= 0;
826 warn_pointer_arith
= 0;
827 cpp_opts
->warn_traditional
= warn_traditional
= 0;
829 cpp_opts
->warn_long_long
= warn_long_long
= 0;
834 /* Restore the warning flags which are controlled by __extension__.
835 FLAGS is the return value from disable_extension_diagnostics. */
838 restore_extension_diagnostics (int flags
)
840 cpp_opts
->pedantic
= pedantic
= flags
& 1;
841 warn_pointer_arith
= (flags
>> 1) & 1;
842 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
843 flag_iso
= (flags
>> 3) & 1;
844 cpp_opts
->warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
845 warn_cxx_compat
= (flags
>> 5) & 1;
848 /* Possibly kinds of declarator to parse. */
849 typedef enum c_dtr_syn
{
850 /* A normal declarator with an identifier. */
852 /* An abstract declarator (maybe empty). */
854 /* A parameter declarator: may be either, but after a type name does
855 not redeclare a typedef name as an identifier if it can
856 alternatively be interpreted as a typedef name; see DR#009,
857 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
858 following DR#249. For example, given a typedef T, "int T" and
859 "int *T" are valid parameter declarations redeclaring T, while
860 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
861 abstract declarators rather than involving redundant parentheses;
862 the same applies with attributes inside the parentheses before
867 static void c_parser_external_declaration (c_parser
*);
868 static void c_parser_asm_definition (c_parser
*);
869 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
870 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
872 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
873 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
874 static tree
c_parser_struct_declaration (c_parser
*);
875 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
876 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
878 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
880 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
882 struct c_declarator
*);
883 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
884 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
885 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
886 static tree
c_parser_simple_asm_expr (c_parser
*);
887 static tree
c_parser_attributes (c_parser
*);
888 static struct c_type_name
*c_parser_type_name (c_parser
*);
889 static struct c_expr
c_parser_initializer (c_parser
*);
890 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
891 static void c_parser_initelt (c_parser
*);
892 static void c_parser_initval (c_parser
*, struct c_expr
*);
893 static tree
c_parser_compound_statement (c_parser
*);
894 static void c_parser_compound_statement_nostart (c_parser
*);
895 static void c_parser_label (c_parser
*);
896 static void c_parser_statement (c_parser
*);
897 static void c_parser_statement_after_labels (c_parser
*);
898 static void c_parser_if_statement (c_parser
*);
899 static void c_parser_switch_statement (c_parser
*);
900 static void c_parser_while_statement (c_parser
*);
901 static void c_parser_do_statement (c_parser
*);
902 static void c_parser_for_statement (c_parser
*);
903 static tree
c_parser_asm_statement (c_parser
*);
904 static tree
c_parser_asm_operands (c_parser
*, bool);
905 static tree
c_parser_asm_clobbers (c_parser
*);
906 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
907 static struct c_expr
c_parser_conditional_expression (c_parser
*,
909 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
910 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
911 static struct c_expr
c_parser_unary_expression (c_parser
*);
912 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
913 static struct c_expr
c_parser_alignof_expression (c_parser
*);
914 static struct c_expr
c_parser_postfix_expression (c_parser
*);
915 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
916 struct c_type_name
*,
918 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
920 static struct c_expr
c_parser_expression (c_parser
*);
921 static struct c_expr
c_parser_expression_conv (c_parser
*);
922 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
924 static void c_parser_release_expr_list (VEC(tree
,gc
) *);
925 static tree
c_parser_vec_to_tree_list (VEC(tree
,gc
) *);
926 static void c_parser_omp_construct (c_parser
*);
927 static void c_parser_omp_threadprivate (c_parser
*);
928 static void c_parser_omp_barrier (c_parser
*);
929 static void c_parser_omp_flush (c_parser
*);
930 static void c_parser_omp_taskwait (c_parser
*);
932 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
933 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
935 /* These Objective-C parser functions are only ever called when
936 compiling Objective-C. */
937 static void c_parser_objc_class_definition (c_parser
*);
938 static void c_parser_objc_class_instance_variables (c_parser
*);
939 static void c_parser_objc_class_declaration (c_parser
*);
940 static void c_parser_objc_alias_declaration (c_parser
*);
941 static void c_parser_objc_protocol_definition (c_parser
*);
942 static enum tree_code
c_parser_objc_method_type (c_parser
*);
943 static void c_parser_objc_method_definition (c_parser
*);
944 static void c_parser_objc_methodprotolist (c_parser
*);
945 static void c_parser_objc_methodproto (c_parser
*);
946 static tree
c_parser_objc_method_decl (c_parser
*);
947 static tree
c_parser_objc_type_name (c_parser
*);
948 static tree
c_parser_objc_protocol_refs (c_parser
*);
949 static void c_parser_objc_try_catch_statement (c_parser
*);
950 static void c_parser_objc_synchronized_statement (c_parser
*);
951 static tree
c_parser_objc_selector (c_parser
*);
952 static tree
c_parser_objc_selector_arg (c_parser
*);
953 static tree
c_parser_objc_receiver (c_parser
*);
954 static tree
c_parser_objc_message_args (c_parser
*);
955 static tree
c_parser_objc_keywordexpr (c_parser
*);
957 /* Parse a translation unit (C90 6.7, C99 6.9).
960 external-declarations
962 external-declarations:
964 external-declarations external-declaration
973 c_parser_translation_unit (c_parser
*parser
)
975 if (c_parser_next_token_is (parser
, CPP_EOF
))
977 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
978 "ISO C forbids an empty translation unit");
982 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
983 mark_valid_location_for_stdc_pragma (false);
987 c_parser_external_declaration (parser
);
988 obstack_free (&parser_obstack
, obstack_position
);
990 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
994 /* Parse an external declaration (C90 6.7, C99 6.9).
996 external-declaration:
1002 external-declaration:
1005 __extension__ external-declaration
1009 external-declaration:
1010 objc-class-definition
1011 objc-class-declaration
1012 objc-alias-declaration
1013 objc-protocol-definition
1014 objc-method-definition
1019 c_parser_external_declaration (c_parser
*parser
)
1022 switch (c_parser_peek_token (parser
)->type
)
1025 switch (c_parser_peek_token (parser
)->keyword
)
1028 ext
= disable_extension_diagnostics ();
1029 c_parser_consume_token (parser
);
1030 c_parser_external_declaration (parser
);
1031 restore_extension_diagnostics (ext
);
1034 c_parser_asm_definition (parser
);
1036 case RID_AT_INTERFACE
:
1037 case RID_AT_IMPLEMENTATION
:
1038 gcc_assert (c_dialect_objc ());
1039 c_parser_objc_class_definition (parser
);
1042 gcc_assert (c_dialect_objc ());
1043 c_parser_objc_class_declaration (parser
);
1046 gcc_assert (c_dialect_objc ());
1047 c_parser_objc_alias_declaration (parser
);
1049 case RID_AT_PROTOCOL
:
1050 gcc_assert (c_dialect_objc ());
1051 c_parser_objc_protocol_definition (parser
);
1054 gcc_assert (c_dialect_objc ());
1055 c_parser_consume_token (parser
);
1056 objc_finish_implementation ();
1063 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1064 "ISO C does not allow extra %<;%> outside of a function");
1065 c_parser_consume_token (parser
);
1068 mark_valid_location_for_stdc_pragma (true);
1069 c_parser_pragma (parser
, pragma_external
);
1070 mark_valid_location_for_stdc_pragma (false);
1074 if (c_dialect_objc ())
1076 c_parser_objc_method_definition (parser
);
1079 /* Else fall through, and yield a syntax error trying to parse
1080 as a declaration or function definition. */
1083 /* A declaration or a function definition. We can only tell
1084 which after parsing the declaration specifiers, if any, and
1085 the first declarator. */
1086 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1092 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1093 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1094 accepted; otherwise (old-style parameter declarations) only other
1095 declarations are accepted. If NESTED is true, we are inside a
1096 function or parsing old-style parameter declarations; any functions
1097 encountered are nested functions and declaration specifiers are
1098 required; otherwise we are at top level and functions are normal
1099 functions and declaration specifiers may be optional. If EMPTY_OK
1100 is true, empty declarations are OK (subject to all other
1101 constraints); otherwise (old-style parameter declarations) they are
1102 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1103 may start with attributes; otherwise they may not.
1106 declaration-specifiers init-declarator-list[opt] ;
1108 function-definition:
1109 declaration-specifiers[opt] declarator declaration-list[opt]
1114 declaration-list declaration
1116 init-declarator-list:
1118 init-declarator-list , init-declarator
1121 declarator simple-asm-expr[opt] attributes[opt]
1122 declarator simple-asm-expr[opt] attributes[opt] = initializer
1126 nested-function-definition:
1127 declaration-specifiers declarator declaration-list[opt]
1130 The simple-asm-expr and attributes are GNU extensions.
1132 This function does not handle __extension__; that is handled in its
1133 callers. ??? Following the old parser, __extension__ may start
1134 external declarations, declarations in functions and declarations
1135 at the start of "for" loops, but not old-style parameter
1138 C99 requires declaration specifiers in a function definition; the
1139 absence is diagnosed through the diagnosis of implicit int. In GNU
1140 C we also allow but diagnose declarations without declaration
1141 specifiers, but only at top level (elsewhere they conflict with
1147 threadprivate-directive */
1150 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1151 bool nested
, bool start_attr_ok
)
1153 struct c_declspecs
*specs
;
1155 tree all_prefix_attrs
;
1156 bool diagnosed_no_specs
= false;
1157 location_t here
= c_parser_peek_token (parser
)->location
;
1159 specs
= build_null_declspecs ();
1160 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1163 c_parser_skip_to_end_of_block_or_statement (parser
);
1166 if (nested
&& !specs
->declspecs_seen_p
)
1168 c_parser_error (parser
, "expected declaration specifiers");
1169 c_parser_skip_to_end_of_block_or_statement (parser
);
1172 finish_declspecs (specs
);
1173 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1179 shadow_tag_warned (specs
, 1);
1180 pedwarn (here
, 0, "empty declaration");
1182 c_parser_consume_token (parser
);
1185 pending_xref_error ();
1186 prefix_attrs
= specs
->attrs
;
1187 all_prefix_attrs
= prefix_attrs
;
1188 specs
->attrs
= NULL_TREE
;
1191 struct c_declarator
*declarator
;
1194 /* Declaring either one or more declarators (in which case we
1195 should diagnose if there were no declaration specifiers) or a
1196 function definition (in which case the diagnostic for
1197 implicit int suffices). */
1198 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1199 C_DTR_NORMAL
, &dummy
);
1200 if (declarator
== NULL
)
1202 c_parser_skip_to_end_of_block_or_statement (parser
);
1205 if (c_parser_next_token_is (parser
, CPP_EQ
)
1206 || c_parser_next_token_is (parser
, CPP_COMMA
)
1207 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1208 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1209 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1211 tree asm_name
= NULL_TREE
;
1212 tree postfix_attrs
= NULL_TREE
;
1213 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1215 diagnosed_no_specs
= true;
1216 pedwarn (here
, 0, "data definition has no type or storage class");
1218 /* Having seen a data definition, there cannot now be a
1219 function definition. */
1221 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1222 asm_name
= c_parser_simple_asm_expr (parser
);
1223 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1224 postfix_attrs
= c_parser_attributes (parser
);
1225 if (c_parser_next_token_is (parser
, CPP_EQ
))
1229 c_parser_consume_token (parser
);
1230 /* The declaration of the variable is in effect while
1231 its initializer is parsed. */
1232 d
= start_decl (declarator
, specs
, true,
1233 chainon (postfix_attrs
, all_prefix_attrs
));
1235 d
= error_mark_node
;
1236 start_init (d
, asm_name
, global_bindings_p ());
1237 init
= c_parser_initializer (parser
);
1239 if (d
!= error_mark_node
)
1241 maybe_warn_string_init (TREE_TYPE (d
), init
);
1242 finish_decl (d
, init
.value
, init
.original_type
, asm_name
);
1247 tree d
= start_decl (declarator
, specs
, false,
1248 chainon (postfix_attrs
,
1251 finish_decl (d
, NULL_TREE
, NULL_TREE
, asm_name
);
1253 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1255 c_parser_consume_token (parser
);
1256 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1257 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1260 all_prefix_attrs
= prefix_attrs
;
1263 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1265 c_parser_consume_token (parser
);
1270 c_parser_error (parser
, "expected %<,%> or %<;%>");
1271 c_parser_skip_to_end_of_block_or_statement (parser
);
1277 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1278 "%<asm%> or %<__attribute__%>");
1279 c_parser_skip_to_end_of_block_or_statement (parser
);
1282 /* Function definition (nested or otherwise). */
1285 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1286 c_push_function_context ();
1288 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1290 /* This can appear in many cases looking nothing like a
1291 function definition, so we don't give a more specific
1292 error suggesting there was one. */
1293 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1294 "or %<__attribute__%>");
1296 c_pop_function_context ();
1299 /* Parse old-style parameter declarations. ??? Attributes are
1300 not allowed to start declaration specifiers here because of a
1301 syntax conflict between a function declaration with attribute
1302 suffix and a function definition with an attribute prefix on
1303 first old-style parameter declaration. Following the old
1304 parser, they are not accepted on subsequent old-style
1305 parameter declarations either. However, there is no
1306 ambiguity after the first declaration, nor indeed on the
1307 first as long as we don't allow postfix attributes after a
1308 declarator with a nonempty identifier list in a definition;
1309 and postfix attributes have never been accepted here in
1310 function definitions either. */
1311 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1312 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1313 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1314 store_parm_decls ();
1315 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1316 = c_parser_peek_token (parser
)->location
;
1317 fnbody
= c_parser_compound_statement (parser
);
1320 tree decl
= current_function_decl
;
1323 c_pop_function_context ();
1324 add_stmt (build_stmt (DECL_EXPR
, decl
));
1335 /* Parse an asm-definition (asm() outside a function body). This is a
1343 c_parser_asm_definition (c_parser
*parser
)
1345 tree asm_str
= c_parser_simple_asm_expr (parser
);
1347 cgraph_add_asm_node (asm_str
);
1348 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1351 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1352 6.7), adding them to SPECS (which may already include some).
1353 Storage class specifiers are accepted iff SCSPEC_OK; type
1354 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1355 the start iff START_ATTR_OK.
1357 declaration-specifiers:
1358 storage-class-specifier declaration-specifiers[opt]
1359 type-specifier declaration-specifiers[opt]
1360 type-qualifier declaration-specifiers[opt]
1361 function-specifier declaration-specifiers[opt]
1363 Function specifiers (inline) are from C99, and are currently
1364 handled as storage class specifiers, as is __thread.
1366 C90 6.5.1, C99 6.7.1:
1367 storage-class-specifier:
1378 C90 6.5.2, C99 6.7.2:
1391 [_Imaginary removed in C99 TC2]
1392 struct-or-union-specifier
1396 (_Bool and _Complex are new in C99.)
1398 C90 6.5.3, C99 6.7.3:
1405 (restrict is new in C99.)
1409 declaration-specifiers:
1410 attributes declaration-specifiers[opt]
1412 storage-class-specifier:
1424 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1425 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1430 class-name objc-protocol-refs[opt]
1431 typedef-name objc-protocol-refs
1436 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1437 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1439 bool attrs_ok
= start_attr_ok
;
1440 bool seen_type
= specs
->type_seen_p
;
1441 while (c_parser_next_token_is (parser
, CPP_NAME
)
1442 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1443 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1445 struct c_typespec t
;
1447 if (c_parser_next_token_is (parser
, CPP_NAME
))
1449 tree value
= c_parser_peek_token (parser
)->value
;
1450 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1451 /* This finishes the specifiers unless a type name is OK, it
1452 is declared as a type name and a type name hasn't yet
1454 if (!typespec_ok
|| seen_type
1455 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1457 c_parser_consume_token (parser
);
1460 if (kind
== C_ID_TYPENAME
1461 && (!c_dialect_objc ()
1462 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1464 t
.kind
= ctsk_typedef
;
1465 /* For a typedef name, record the meaning, not the name.
1466 In case of 'foo foo, bar;'. */
1467 t
.spec
= lookup_name (value
);
1469 t
.expr_const_operands
= true;
1473 tree proto
= NULL_TREE
;
1474 gcc_assert (c_dialect_objc ());
1476 if (c_parser_next_token_is (parser
, CPP_LESS
))
1477 proto
= c_parser_objc_protocol_refs (parser
);
1478 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1480 t
.expr_const_operands
= true;
1482 declspecs_add_type (specs
, t
);
1485 if (c_parser_next_token_is (parser
, CPP_LESS
))
1487 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1488 nisse@lysator.liu.se. */
1490 gcc_assert (c_dialect_objc ());
1491 if (!typespec_ok
|| seen_type
)
1493 proto
= c_parser_objc_protocol_refs (parser
);
1495 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1497 t
.expr_const_operands
= true;
1498 declspecs_add_type (specs
, t
);
1501 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1502 switch (c_parser_peek_token (parser
)->keyword
)
1514 /* TODO: Distinguish between function specifiers (inline)
1515 and storage class specifiers, either here or in
1516 declspecs_add_scspec. */
1517 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1518 c_parser_consume_token (parser
);
1541 if (c_dialect_objc ())
1542 parser
->objc_need_raw_identifier
= true;
1543 t
.kind
= ctsk_resword
;
1544 t
.spec
= c_parser_peek_token (parser
)->value
;
1546 t
.expr_const_operands
= true;
1547 declspecs_add_type (specs
, t
);
1548 c_parser_consume_token (parser
);
1555 t
= c_parser_enum_specifier (parser
);
1556 declspecs_add_type (specs
, t
);
1564 t
= c_parser_struct_or_union_specifier (parser
);
1565 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1566 declspecs_add_type (specs
, t
);
1569 /* ??? The old parser rejected typeof after other type
1570 specifiers, but is a syntax error the best way of
1572 if (!typespec_ok
|| seen_type
)
1576 t
= c_parser_typeof_specifier (parser
);
1577 declspecs_add_type (specs
, t
);
1583 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1584 c_parser_consume_token (parser
);
1589 attrs
= c_parser_attributes (parser
);
1590 declspecs_add_attrs (specs
, attrs
);
1599 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1602 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1603 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1604 enum attributes[opt] identifier
1606 The form with trailing comma is new in C99. The forms with
1607 attributes are GNU extensions. In GNU C, we accept any expression
1608 without commas in the syntax (assignment expressions, not just
1609 conditional expressions); assignment expressions will be diagnosed
1614 enumerator-list , enumerator
1617 enumeration-constant
1618 enumeration-constant = constant-expression
1621 static struct c_typespec
1622 c_parser_enum_specifier (c_parser
*parser
)
1624 struct c_typespec ret
;
1626 tree ident
= NULL_TREE
;
1627 location_t enum_loc
;
1628 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1629 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1630 enum_loc
= c_parser_peek_token (parser
)->location
;
1631 c_parser_consume_token (parser
);
1632 attrs
= c_parser_attributes (parser
);
1633 /* Set the location in case we create a decl now. */
1634 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1635 if (c_parser_next_token_is (parser
, CPP_NAME
))
1637 ident
= c_parser_peek_token (parser
)->value
;
1638 ident_loc
= c_parser_peek_token (parser
)->location
;
1639 enum_loc
= ident_loc
;
1640 c_parser_consume_token (parser
);
1642 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1644 /* Parse an enum definition. */
1645 struct c_enum_contents the_enum
;
1646 tree type
= start_enum (&the_enum
, ident
, enum_loc
);
1648 /* We chain the enumerators in reverse order, then put them in
1649 forward order at the end. */
1650 tree values
= NULL_TREE
;
1651 c_parser_consume_token (parser
);
1659 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1660 location_t value_loc
;
1661 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1663 c_parser_error (parser
, "expected identifier");
1664 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1665 values
= error_mark_node
;
1668 token
= c_parser_peek_token (parser
);
1669 enum_id
= token
->value
;
1670 /* Set the location in case we create a decl now. */
1671 c_parser_set_source_position_from_token (token
);
1672 value_loc
= token
->location
;
1673 c_parser_consume_token (parser
);
1674 if (c_parser_next_token_is (parser
, CPP_EQ
))
1676 c_parser_consume_token (parser
);
1677 value_loc
= c_parser_peek_token (parser
)->location
;
1678 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1681 enum_value
= NULL_TREE
;
1682 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
,
1684 TREE_CHAIN (enum_decl
) = values
;
1687 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1689 comma_loc
= c_parser_peek_token (parser
)->location
;
1691 c_parser_consume_token (parser
);
1693 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1695 if (seen_comma
&& !flag_isoc99
)
1696 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1697 c_parser_consume_token (parser
);
1702 c_parser_error (parser
, "expected %<,%> or %<}%>");
1703 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1704 values
= error_mark_node
;
1708 postfix_attrs
= c_parser_attributes (parser
);
1709 ret
.spec
= finish_enum (type
, nreverse (values
),
1710 chainon (attrs
, postfix_attrs
));
1711 ret
.kind
= ctsk_tagdef
;
1712 ret
.expr
= NULL_TREE
;
1713 ret
.expr_const_operands
= true;
1718 c_parser_error (parser
, "expected %<{%>");
1719 ret
.spec
= error_mark_node
;
1720 ret
.kind
= ctsk_tagref
;
1721 ret
.expr
= NULL_TREE
;
1722 ret
.expr_const_operands
= true;
1725 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
, ident_loc
);
1726 /* In ISO C, enumerated types can be referred to only if already
1728 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1731 pedwarn (ident_loc
, OPT_pedantic
,
1732 "ISO C forbids forward references to %<enum%> types");
1737 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1739 struct-or-union-specifier:
1740 struct-or-union attributes[opt] identifier[opt]
1741 { struct-contents } attributes[opt]
1742 struct-or-union attributes[opt] identifier
1745 struct-declaration-list
1747 struct-declaration-list:
1748 struct-declaration ;
1749 struct-declaration-list struct-declaration ;
1756 struct-declaration-list struct-declaration
1758 struct-declaration-list:
1759 struct-declaration-list ;
1762 (Note that in the syntax here, unlike that in ISO C, the semicolons
1763 are included here rather than in struct-declaration, in order to
1764 describe the syntax with extra semicolons and missing semicolon at
1769 struct-declaration-list:
1770 @defs ( class-name )
1772 (Note this does not include a trailing semicolon, but can be
1773 followed by further declarations, and gets a pedwarn-if-pedantic
1774 when followed by a semicolon.) */
1776 static struct c_typespec
1777 c_parser_struct_or_union_specifier (c_parser
*parser
)
1779 struct c_typespec ret
;
1781 tree ident
= NULL_TREE
;
1782 location_t struct_loc
;
1783 location_t ident_loc
= UNKNOWN_LOCATION
;
1784 enum tree_code code
;
1785 switch (c_parser_peek_token (parser
)->keyword
)
1796 struct_loc
= c_parser_peek_token (parser
)->location
;
1797 c_parser_consume_token (parser
);
1798 attrs
= c_parser_attributes (parser
);
1799 /* Set the location in case we create a decl now. */
1800 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1801 if (c_parser_next_token_is (parser
, CPP_NAME
))
1803 ident
= c_parser_peek_token (parser
)->value
;
1804 ident_loc
= c_parser_peek_token (parser
)->location
;
1805 struct_loc
= ident_loc
;
1806 c_parser_consume_token (parser
);
1808 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1810 /* Parse a struct or union definition. Start the scope of the
1811 tag before parsing components. */
1813 VEC(tree
,heap
) *struct_types
;
1814 tree type
= start_struct (code
, ident
, &in_struct
, &struct_types
,
1817 /* We chain the components in reverse order, then put them in
1818 forward order at the end. Each struct-declaration may
1819 declare multiple components (comma-separated), so we must use
1820 chainon to join them, although when parsing each
1821 struct-declaration we can use TREE_CHAIN directly.
1823 The theory behind all this is that there will be more
1824 semicolon separated fields than comma separated fields, and
1825 so we'll be minimizing the number of node traversals required
1827 tree contents
= NULL_TREE
;
1828 c_parser_consume_token (parser
);
1829 /* Handle the Objective-C @defs construct,
1830 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1831 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1834 gcc_assert (c_dialect_objc ());
1835 c_parser_consume_token (parser
);
1836 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1838 if (c_parser_next_token_is (parser
, CPP_NAME
)
1839 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1841 name
= c_parser_peek_token (parser
)->value
;
1842 c_parser_consume_token (parser
);
1846 c_parser_error (parser
, "expected class name");
1847 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1850 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1852 contents
= nreverse (objc_get_class_ivars (name
));
1855 /* Parse the struct-declarations and semicolons. Problems with
1856 semicolons are diagnosed here; empty structures are diagnosed
1861 /* Parse any stray semicolon. */
1862 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1864 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1865 "extra semicolon in struct or union specified");
1866 c_parser_consume_token (parser
);
1869 /* Stop if at the end of the struct or union contents. */
1870 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1872 c_parser_consume_token (parser
);
1875 /* Accept #pragmas at struct scope. */
1876 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1878 c_parser_pragma (parser
, pragma_external
);
1881 /* Parse some comma-separated declarations, but not the
1882 trailing semicolon if any. */
1883 decls
= c_parser_struct_declaration (parser
);
1884 contents
= chainon (decls
, contents
);
1885 /* If no semicolon follows, either we have a parse error or
1886 are at the end of the struct or union and should
1888 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1889 c_parser_consume_token (parser
);
1892 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1893 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1894 "no semicolon at end of struct or union");
1897 c_parser_error (parser
, "expected %<;%>");
1898 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1903 postfix_attrs
= c_parser_attributes (parser
);
1904 ret
.spec
= finish_struct (type
, nreverse (contents
),
1905 chainon (attrs
, postfix_attrs
),
1906 in_struct
, struct_types
);
1907 ret
.kind
= ctsk_tagdef
;
1908 ret
.expr
= NULL_TREE
;
1909 ret
.expr_const_operands
= true;
1914 c_parser_error (parser
, "expected %<{%>");
1915 ret
.spec
= error_mark_node
;
1916 ret
.kind
= ctsk_tagref
;
1917 ret
.expr
= NULL_TREE
;
1918 ret
.expr_const_operands
= true;
1921 ret
= parser_xref_tag (code
, ident
, ident_loc
);
1925 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1926 the trailing semicolon.
1929 specifier-qualifier-list struct-declarator-list
1931 specifier-qualifier-list:
1932 type-specifier specifier-qualifier-list[opt]
1933 type-qualifier specifier-qualifier-list[opt]
1934 attributes specifier-qualifier-list[opt]
1936 struct-declarator-list:
1938 struct-declarator-list , attributes[opt] struct-declarator
1941 declarator attributes[opt]
1942 declarator[opt] : constant-expression attributes[opt]
1947 __extension__ struct-declaration
1948 specifier-qualifier-list
1950 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1951 of attributes where shown is a GNU extension. In GNU C, we accept
1952 any expression without commas in the syntax (assignment
1953 expressions, not just conditional expressions); assignment
1954 expressions will be diagnosed as non-constant. */
1957 c_parser_struct_declaration (c_parser
*parser
)
1959 struct c_declspecs
*specs
;
1961 tree all_prefix_attrs
;
1963 location_t decl_loc
;
1964 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1968 ext
= disable_extension_diagnostics ();
1969 c_parser_consume_token (parser
);
1970 decl
= c_parser_struct_declaration (parser
);
1971 restore_extension_diagnostics (ext
);
1974 specs
= build_null_declspecs ();
1975 decl_loc
= c_parser_peek_token (parser
)->location
;
1976 c_parser_declspecs (parser
, specs
, false, true, true);
1979 if (!specs
->declspecs_seen_p
)
1981 c_parser_error (parser
, "expected specifier-qualifier-list");
1984 finish_declspecs (specs
);
1985 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1988 if (!specs
->type_seen_p
)
1990 pedwarn (decl_loc
, OPT_pedantic
,
1991 "ISO C forbids member declarations with no members");
1992 shadow_tag_warned (specs
, pedantic
);
1997 /* Support for unnamed structs or unions as members of
1998 structs or unions (which is [a] useful and [b] supports
2002 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2003 build_id_declarator (NULL_TREE
), specs
,
2006 decl_attributes (&ret
, attrs
, 0);
2010 pending_xref_error ();
2011 prefix_attrs
= specs
->attrs
;
2012 all_prefix_attrs
= prefix_attrs
;
2013 specs
->attrs
= NULL_TREE
;
2017 /* Declaring one or more declarators or un-named bit-fields. */
2018 struct c_declarator
*declarator
;
2020 if (c_parser_next_token_is (parser
, CPP_COLON
))
2021 declarator
= build_id_declarator (NULL_TREE
);
2023 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2024 C_DTR_NORMAL
, &dummy
);
2025 if (declarator
== NULL
)
2027 c_parser_skip_to_end_of_block_or_statement (parser
);
2030 if (c_parser_next_token_is (parser
, CPP_COLON
)
2031 || c_parser_next_token_is (parser
, CPP_COMMA
)
2032 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2033 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2034 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2036 tree postfix_attrs
= NULL_TREE
;
2037 tree width
= NULL_TREE
;
2039 if (c_parser_next_token_is (parser
, CPP_COLON
))
2041 c_parser_consume_token (parser
);
2042 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2044 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2045 postfix_attrs
= c_parser_attributes (parser
);
2046 d
= grokfield (c_parser_peek_token (parser
)->location
,
2047 declarator
, specs
, width
, &all_prefix_attrs
);
2048 decl_attributes (&d
, chainon (postfix_attrs
,
2049 all_prefix_attrs
), 0);
2050 TREE_CHAIN (d
) = decls
;
2052 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2053 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2056 all_prefix_attrs
= prefix_attrs
;
2057 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2058 c_parser_consume_token (parser
);
2059 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2060 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2062 /* Semicolon consumed in caller. */
2067 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2073 c_parser_error (parser
,
2074 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2075 "%<__attribute__%>");
2082 /* Parse a typeof specifier (a GNU extension).
2085 typeof ( expression )
2086 typeof ( type-name )
2089 static struct c_typespec
2090 c_parser_typeof_specifier (c_parser
*parser
)
2092 struct c_typespec ret
;
2093 ret
.kind
= ctsk_typeof
;
2094 ret
.spec
= error_mark_node
;
2095 ret
.expr
= NULL_TREE
;
2096 ret
.expr_const_operands
= true;
2097 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2098 c_parser_consume_token (parser
);
2101 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2107 if (c_parser_next_token_starts_typename (parser
))
2109 struct c_type_name
*type
= c_parser_type_name (parser
);
2114 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2115 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2121 location_t here
= c_parser_peek_token (parser
)->location
;
2122 struct c_expr expr
= c_parser_expression (parser
);
2125 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2126 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2127 error_at (here
, "%<typeof%> applied to a bit-field");
2128 ret
.spec
= TREE_TYPE (expr
.value
);
2129 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2130 /* This is returned with the type so that when the type is
2131 evaluated, this can be evaluated. */
2133 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2134 pop_maybe_used (was_vm
);
2136 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2140 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2141 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2142 be redeclared; otherwise it may not. KIND indicates which kind of
2143 declarator is wanted. Returns a valid declarator except in the
2144 case of a syntax error in which case NULL is returned. *SEEN_ID is
2145 set to true if an identifier being declared is seen; this is used
2146 to diagnose bad forms of abstract array declarators and to
2147 determine whether an identifier list is syntactically permitted.
2150 pointer[opt] direct-declarator
2154 ( attributes[opt] declarator )
2155 direct-declarator array-declarator
2156 direct-declarator ( parameter-type-list )
2157 direct-declarator ( identifier-list[opt] )
2160 * type-qualifier-list[opt]
2161 * type-qualifier-list[opt] pointer
2163 type-qualifier-list:
2166 type-qualifier-list type-qualifier
2167 type-qualifier-list attributes
2169 parameter-type-list:
2171 parameter-list , ...
2174 parameter-declaration
2175 parameter-list , parameter-declaration
2177 parameter-declaration:
2178 declaration-specifiers declarator attributes[opt]
2179 declaration-specifiers abstract-declarator[opt] attributes[opt]
2183 identifier-list , identifier
2185 abstract-declarator:
2187 pointer[opt] direct-abstract-declarator
2189 direct-abstract-declarator:
2190 ( attributes[opt] abstract-declarator )
2191 direct-abstract-declarator[opt] array-declarator
2192 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2197 direct-declarator ( parameter-forward-declarations
2198 parameter-type-list[opt] )
2200 direct-abstract-declarator:
2201 direct-abstract-declarator[opt] ( parameter-forward-declarations
2202 parameter-type-list[opt] )
2204 parameter-forward-declarations:
2206 parameter-forward-declarations parameter-list ;
2208 The uses of attributes shown above are GNU extensions.
2210 Some forms of array declarator are not included in C99 in the
2211 syntax for abstract declarators; these are disallowed elsewhere.
2212 This may be a defect (DR#289).
2214 This function also accepts an omitted abstract declarator as being
2215 an abstract declarator, although not part of the formal syntax. */
2217 static struct c_declarator
*
2218 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2221 /* Parse any initial pointer part. */
2222 if (c_parser_next_token_is (parser
, CPP_MULT
))
2224 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2225 struct c_declarator
*inner
;
2226 c_parser_consume_token (parser
);
2227 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2228 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2232 return make_pointer_declarator (quals_attrs
, inner
);
2234 /* Now we have a direct declarator, direct abstract declarator or
2235 nothing (which counts as a direct abstract declarator here). */
2236 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2239 /* Parse a direct declarator or direct abstract declarator; arguments
2240 as c_parser_declarator. */
2242 static struct c_declarator
*
2243 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2246 /* The direct declarator must start with an identifier (possibly
2247 omitted) or a parenthesized declarator (possibly abstract). In
2248 an ordinary declarator, initial parentheses must start a
2249 parenthesized declarator. In an abstract declarator or parameter
2250 declarator, they could start a parenthesized declarator or a
2251 parameter list. To tell which, the open parenthesis and any
2252 following attributes must be read. If a declaration specifier
2253 follows, then it is a parameter list; if the specifier is a
2254 typedef name, there might be an ambiguity about redeclaring it,
2255 which is resolved in the direction of treating it as a typedef
2256 name. If a close parenthesis follows, it is also an empty
2257 parameter list, as the syntax does not permit empty abstract
2258 declarators. Otherwise, it is a parenthesized declarator (in
2259 which case the analysis may be repeated inside it, recursively).
2261 ??? There is an ambiguity in a parameter declaration "int
2262 (__attribute__((foo)) x)", where x is not a typedef name: it
2263 could be an abstract declarator for a function, or declare x with
2264 parentheses. The proper resolution of this ambiguity needs
2265 documenting. At present we follow an accident of the old
2266 parser's implementation, whereby the first parameter must have
2267 some declaration specifiers other than just attributes. Thus as
2268 a parameter declaration it is treated as a parenthesized
2269 parameter named x, and as an abstract declarator it is
2272 ??? Also following the old parser, attributes inside an empty
2273 parameter list are ignored, making it a list not yielding a
2274 prototype, rather than giving an error or making it have one
2275 parameter with implicit type int.
2277 ??? Also following the old parser, typedef names may be
2278 redeclared in declarators, but not Objective-C class names. */
2280 if (kind
!= C_DTR_ABSTRACT
2281 && c_parser_next_token_is (parser
, CPP_NAME
)
2283 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2284 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2286 struct c_declarator
*inner
2287 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2289 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2290 c_parser_consume_token (parser
);
2291 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2294 if (kind
!= C_DTR_NORMAL
2295 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2297 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2298 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2301 /* Either we are at the end of an abstract declarator, or we have
2304 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2307 struct c_declarator
*inner
;
2308 c_parser_consume_token (parser
);
2309 attrs
= c_parser_attributes (parser
);
2310 if (kind
!= C_DTR_NORMAL
2311 && (c_parser_next_token_starts_declspecs (parser
)
2312 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2314 struct c_arg_info
*args
2315 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2322 = build_function_declarator (args
,
2323 build_id_declarator (NULL_TREE
));
2324 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2328 /* A parenthesized declarator. */
2329 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2330 if (inner
!= NULL
&& attrs
!= NULL
)
2331 inner
= build_attrs_declarator (attrs
, inner
);
2332 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2334 c_parser_consume_token (parser
);
2338 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2349 if (kind
== C_DTR_NORMAL
)
2351 c_parser_error (parser
, "expected identifier or %<(%>");
2355 return build_id_declarator (NULL_TREE
);
2359 /* Parse part of a direct declarator or direct abstract declarator,
2360 given that some (in INNER) has already been parsed; ID_PRESENT is
2361 true if an identifier is present, false for an abstract
2364 static struct c_declarator
*
2365 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2366 struct c_declarator
*inner
)
2368 /* Parse a sequence of array declarators and parameter lists. */
2369 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2371 struct c_declarator
*declarator
;
2372 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2376 c_parser_consume_token (parser
);
2377 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2378 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2380 c_parser_consume_token (parser
);
2381 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2382 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2383 if (!quals_attrs
->declspecs_seen_p
)
2385 /* If "static" is present, there must be an array dimension.
2386 Otherwise, there may be a dimension, "*", or no
2391 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2395 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2400 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2402 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2406 c_parser_consume_token (parser
);
2411 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2417 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2420 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2421 c_parser_consume_token (parser
);
2424 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2428 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2430 if (declarator
== NULL
)
2432 inner
= set_array_declarator_inner (declarator
, inner
);
2433 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2435 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2438 struct c_arg_info
*args
;
2439 c_parser_consume_token (parser
);
2440 attrs
= c_parser_attributes (parser
);
2441 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2446 inner
= build_function_declarator (args
, inner
);
2447 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2453 /* Parse a parameter list or identifier list, including the closing
2454 parenthesis but not the opening one. ATTRS are the attributes at
2455 the start of the list. ID_LIST_OK is true if an identifier list is
2456 acceptable; such a list must not have attributes at the start. */
2458 static struct c_arg_info
*
2459 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2462 declare_parm_level ();
2463 /* If the list starts with an identifier, it is an identifier list.
2464 Otherwise, it is either a prototype list or an empty list. */
2467 && c_parser_next_token_is (parser
, CPP_NAME
)
2468 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2470 tree list
= NULL_TREE
, *nextp
= &list
;
2471 while (c_parser_next_token_is (parser
, CPP_NAME
)
2472 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2474 *nextp
= build_tree_list (NULL_TREE
,
2475 c_parser_peek_token (parser
)->value
);
2476 nextp
= & TREE_CHAIN (*nextp
);
2477 c_parser_consume_token (parser
);
2478 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2480 c_parser_consume_token (parser
);
2481 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2483 c_parser_error (parser
, "expected identifier");
2487 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2489 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2494 ret
->pending_sizes
= 0;
2495 ret
->had_vla_unspec
= 0;
2496 c_parser_consume_token (parser
);
2502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2510 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2516 /* Parse a parameter list (possibly empty), including the closing
2517 parenthesis but not the opening one. ATTRS are the attributes at
2518 the start of the list. */
2520 static struct c_arg_info
*
2521 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2523 bool good_parm
= false;
2524 /* ??? Following the old parser, forward parameter declarations may
2525 use abstract declarators, and if no real parameter declarations
2526 follow the forward declarations then this is not diagnosed. Also
2527 note as above that attributes are ignored as the only contents of
2528 the parentheses, or as the only contents after forward
2530 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2532 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2537 ret
->pending_sizes
= 0;
2538 ret
->had_vla_unspec
= 0;
2539 c_parser_consume_token (parser
);
2542 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2544 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2548 ret
->pending_sizes
= 0;
2549 ret
->had_vla_unspec
= 0;
2550 /* Suppress -Wold-style-definition for this case. */
2551 ret
->types
= error_mark_node
;
2552 error_at (c_parser_peek_token (parser
)->location
,
2553 "ISO C requires a named argument before %<...%>");
2554 c_parser_consume_token (parser
);
2555 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2557 c_parser_consume_token (parser
);
2562 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2567 /* Nonempty list of parameters, either terminated with semicolon
2568 (forward declarations; recurse) or with close parenthesis (normal
2569 function) or with ", ... )" (variadic function). */
2572 /* Parse a parameter. */
2573 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2578 push_parm_decl (parm
);
2580 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2583 c_parser_consume_token (parser
);
2584 mark_forward_parm_decls ();
2585 new_attrs
= c_parser_attributes (parser
);
2586 return c_parser_parms_list_declarator (parser
, new_attrs
);
2588 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2590 c_parser_consume_token (parser
);
2592 return get_parm_info (false);
2595 struct c_arg_info
*ret
2596 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2601 ret
->pending_sizes
= 0;
2602 ret
->had_vla_unspec
= 0;
2606 if (!c_parser_require (parser
, CPP_COMMA
,
2607 "expected %<;%>, %<,%> or %<)%>"))
2609 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2610 get_pending_sizes ();
2613 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2615 c_parser_consume_token (parser
);
2616 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2618 c_parser_consume_token (parser
);
2620 return get_parm_info (true);
2623 struct c_arg_info
*ret
2624 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2629 ret
->pending_sizes
= 0;
2630 ret
->had_vla_unspec
= 0;
2636 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2638 get_pending_sizes ();
2645 /* Parse a parameter declaration. ATTRS are the attributes at the
2646 start of the declaration if it is the first parameter. */
2648 static struct c_parm
*
2649 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2651 struct c_declspecs
*specs
;
2652 struct c_declarator
*declarator
;
2654 tree postfix_attrs
= NULL_TREE
;
2656 if (!c_parser_next_token_starts_declspecs (parser
))
2658 /* ??? In some Objective-C cases '...' isn't applicable so there
2659 should be a different message. */
2660 c_parser_error (parser
,
2661 "expected declaration specifiers or %<...%>");
2662 c_parser_skip_to_end_of_parameter (parser
);
2665 specs
= build_null_declspecs ();
2668 declspecs_add_attrs (specs
, attrs
);
2671 c_parser_declspecs (parser
, specs
, true, true, true);
2672 finish_declspecs (specs
);
2673 pending_xref_error ();
2674 prefix_attrs
= specs
->attrs
;
2675 specs
->attrs
= NULL_TREE
;
2676 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2677 C_DTR_PARM
, &dummy
);
2678 if (declarator
== NULL
)
2680 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2683 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2684 postfix_attrs
= c_parser_attributes (parser
);
2685 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2689 /* Parse a string literal in an asm expression. It should not be
2690 translated, and wide string literals are an error although
2691 permitted by the syntax. This is a GNU extension.
2696 ??? At present, following the old parser, the caller needs to have
2697 set lex_untranslated_string to 1. It would be better to follow the
2698 C++ parser rather than using this kludge. */
2701 c_parser_asm_string_literal (c_parser
*parser
)
2704 if (c_parser_next_token_is (parser
, CPP_STRING
))
2706 str
= c_parser_peek_token (parser
)->value
;
2707 c_parser_consume_token (parser
);
2709 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2711 error_at (c_parser_peek_token (parser
)->location
,
2712 "wide string literal in %<asm%>");
2713 str
= build_string (1, "");
2714 c_parser_consume_token (parser
);
2718 c_parser_error (parser
, "expected string literal");
2724 /* Parse a simple asm expression. This is used in restricted
2725 contexts, where a full expression with inputs and outputs does not
2726 make sense. This is a GNU extension.
2729 asm ( asm-string-literal )
2733 c_parser_simple_asm_expr (c_parser
*parser
)
2736 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2737 /* ??? Follow the C++ parser rather than using the
2738 lex_untranslated_string kludge. */
2739 parser
->lex_untranslated_string
= true;
2740 c_parser_consume_token (parser
);
2741 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2743 parser
->lex_untranslated_string
= false;
2746 str
= c_parser_asm_string_literal (parser
);
2747 parser
->lex_untranslated_string
= false;
2748 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2756 /* Parse (possibly empty) attributes. This is a GNU extension.
2760 attributes attribute
2763 __attribute__ ( ( attribute-list ) )
2767 attribute_list , attrib
2772 any-word ( identifier )
2773 any-word ( identifier , nonempty-expr-list )
2774 any-word ( expr-list )
2776 where the "identifier" must not be declared as a type, and
2777 "any-word" may be any identifier (including one declared as a
2778 type), a reserved word storage class specifier, type specifier or
2779 type qualifier. ??? This still leaves out most reserved keywords
2780 (following the old parser), shouldn't we include them, and why not
2781 allow identifiers declared as types to start the arguments? */
2784 c_parser_attributes (c_parser
*parser
)
2786 tree attrs
= NULL_TREE
;
2787 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2789 /* ??? Follow the C++ parser rather than using the
2790 lex_untranslated_string kludge. */
2791 parser
->lex_untranslated_string
= true;
2792 c_parser_consume_token (parser
);
2793 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2795 parser
->lex_untranslated_string
= false;
2798 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2800 parser
->lex_untranslated_string
= false;
2801 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2804 /* Parse the attribute list. */
2805 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2806 || c_parser_next_token_is (parser
, CPP_NAME
)
2807 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2809 tree attr
, attr_name
, attr_args
;
2810 VEC(tree
,gc
) *expr_list
;
2811 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2813 c_parser_consume_token (parser
);
2816 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2818 /* ??? See comment above about what keywords are
2821 switch (c_parser_peek_token (parser
)->keyword
)
2858 /* Accept __attribute__((__const)) as __attribute__((const))
2861 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2864 attr_name
= c_parser_peek_token (parser
)->value
;
2865 c_parser_consume_token (parser
);
2866 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2868 attr
= build_tree_list (attr_name
, NULL_TREE
);
2869 attrs
= chainon (attrs
, attr
);
2872 c_parser_consume_token (parser
);
2873 /* Parse the attribute contents. If they start with an
2874 identifier which is followed by a comma or close
2875 parenthesis, then the arguments start with that
2876 identifier; otherwise they are an expression list. */
2877 if (c_parser_next_token_is (parser
, CPP_NAME
)
2878 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2879 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2880 || (c_parser_peek_2nd_token (parser
)->type
2881 == CPP_CLOSE_PAREN
)))
2883 tree arg1
= c_parser_peek_token (parser
)->value
;
2884 c_parser_consume_token (parser
);
2885 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2886 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2890 c_parser_consume_token (parser
);
2891 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2892 tree_list
= c_parser_vec_to_tree_list (expr_list
);
2893 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2894 c_parser_release_expr_list (expr_list
);
2899 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2900 attr_args
= NULL_TREE
;
2903 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2904 attr_args
= c_parser_vec_to_tree_list (expr_list
);
2905 c_parser_release_expr_list (expr_list
);
2908 attr
= build_tree_list (attr_name
, attr_args
);
2909 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2910 c_parser_consume_token (parser
);
2913 parser
->lex_untranslated_string
= false;
2914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2918 attrs
= chainon (attrs
, attr
);
2920 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2921 c_parser_consume_token (parser
);
2924 parser
->lex_untranslated_string
= false;
2925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2929 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2930 c_parser_consume_token (parser
);
2933 parser
->lex_untranslated_string
= false;
2934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2938 parser
->lex_untranslated_string
= false;
2943 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2946 specifier-qualifier-list abstract-declarator[opt]
2949 static struct c_type_name
*
2950 c_parser_type_name (c_parser
*parser
)
2952 struct c_declspecs
*specs
= build_null_declspecs ();
2953 struct c_declarator
*declarator
;
2954 struct c_type_name
*ret
;
2956 c_parser_declspecs (parser
, specs
, false, true, true);
2957 if (!specs
->declspecs_seen_p
)
2959 c_parser_error (parser
, "expected specifier-qualifier-list");
2962 pending_xref_error ();
2963 finish_declspecs (specs
);
2964 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2965 C_DTR_ABSTRACT
, &dummy
);
2966 if (declarator
== NULL
)
2968 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2970 ret
->declarator
= declarator
;
2974 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2977 assignment-expression
2978 { initializer-list }
2979 { initializer-list , }
2982 designation[opt] initializer
2983 initializer-list , designation[opt] initializer
2990 designator-list designator
2997 [ constant-expression ]
3009 [ constant-expression ... constant-expression ]
3011 Any expression without commas is accepted in the syntax for the
3012 constant-expressions, with non-constant expressions rejected later.
3014 This function is only used for top-level initializers; for nested
3015 ones, see c_parser_initval. */
3017 static struct c_expr
3018 c_parser_initializer (c_parser
*parser
)
3020 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3021 return c_parser_braced_init (parser
, NULL_TREE
, false);
3025 ret
= c_parser_expr_no_commas (parser
, NULL
);
3026 if (TREE_CODE (ret
.value
) != STRING_CST
3027 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3028 ret
= default_function_array_conversion (ret
);
3033 /* Parse a braced initializer list. TYPE is the type specified for a
3034 compound literal, and NULL_TREE for other initializers and for
3035 nested braced lists. NESTED_P is true for nested braced lists,
3036 false for the list of a compound literal or the list that is the
3037 top-level initializer in a declaration. */
3039 static struct c_expr
3040 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3042 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3043 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3044 c_parser_consume_token (parser
);
3046 push_init_level (0);
3048 really_start_incremental_init (type
);
3049 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3051 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3055 /* Parse a non-empty initializer list, possibly with a trailing
3059 c_parser_initelt (parser
);
3062 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3063 c_parser_consume_token (parser
);
3066 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3070 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3073 ret
.value
= error_mark_node
;
3074 ret
.original_code
= ERROR_MARK
;
3075 ret
.original_type
= NULL
;
3076 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3080 c_parser_consume_token (parser
);
3081 return pop_init_level (0);
3084 /* Parse a nested initializer, including designators. */
3087 c_parser_initelt (c_parser
*parser
)
3089 /* Parse any designator or designator list. A single array
3090 designator may have the subsequent "=" omitted in GNU C, but a
3091 longer list or a structure member designator may not. */
3092 if (c_parser_next_token_is (parser
, CPP_NAME
)
3093 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3095 /* Old-style structure member designator. */
3096 set_init_label (c_parser_peek_token (parser
)->value
);
3097 /* Use the colon as the error location. */
3098 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3099 "obsolete use of designated initializer with %<:%>");
3100 c_parser_consume_token (parser
);
3101 c_parser_consume_token (parser
);
3105 /* des_seen is 0 if there have been no designators, 1 if there
3106 has been a single array designator and 2 otherwise. */
3108 /* Location of a designator. */
3109 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3110 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3111 || c_parser_next_token_is (parser
, CPP_DOT
))
3113 int des_prev
= des_seen
;
3115 des_loc
= c_parser_peek_token (parser
)->location
;
3118 if (c_parser_next_token_is (parser
, CPP_DOT
))
3121 c_parser_consume_token (parser
);
3122 if (c_parser_next_token_is (parser
, CPP_NAME
))
3124 set_init_label (c_parser_peek_token (parser
)->value
);
3125 c_parser_consume_token (parser
);
3130 init
.value
= error_mark_node
;
3131 init
.original_code
= ERROR_MARK
;
3132 init
.original_type
= NULL
;
3133 c_parser_error (parser
, "expected identifier");
3134 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3135 process_init_element (init
, false);
3142 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3143 /* ??? Following the old parser, [ objc-receiver
3144 objc-message-args ] is accepted as an initializer,
3145 being distinguished from a designator by what follows
3146 the first assignment expression inside the square
3147 brackets, but after a first array designator a
3148 subsequent square bracket is for Objective-C taken to
3149 start an expression, using the obsolete form of
3150 designated initializer without '=', rather than
3151 possibly being a second level of designation: in LALR
3152 terms, the '[' is shifted rather than reducing
3153 designator to designator-list. */
3154 if (des_prev
== 1 && c_dialect_objc ())
3156 des_seen
= des_prev
;
3159 if (des_prev
== 0 && c_dialect_objc ())
3161 /* This might be an array designator or an
3162 Objective-C message expression. If the former,
3163 continue parsing here; if the latter, parse the
3164 remainder of the initializer given the starting
3165 primary-expression. ??? It might make sense to
3166 distinguish when des_prev == 1 as well; see
3167 previous comment. */
3169 struct c_expr mexpr
;
3170 c_parser_consume_token (parser
);
3171 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3172 && ((c_parser_peek_token (parser
)->id_kind
3174 || (c_parser_peek_token (parser
)->id_kind
3175 == C_ID_CLASSNAME
)))
3177 /* Type name receiver. */
3178 tree id
= c_parser_peek_token (parser
)->value
;
3179 c_parser_consume_token (parser
);
3180 rec
= objc_get_class_reference (id
);
3181 goto parse_message_args
;
3183 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3184 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3185 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3186 goto array_desig_after_first
;
3187 /* Expression receiver. So far only one part
3188 without commas has been parsed; there might be
3189 more of the expression. */
3191 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3194 c_parser_consume_token (parser
);
3195 next
= c_parser_expr_no_commas (parser
, NULL
);
3196 next
= default_function_array_conversion (next
);
3197 rec
= build_compound_expr (rec
, next
.value
);
3200 /* Now parse the objc-message-args. */
3201 args
= c_parser_objc_message_args (parser
);
3202 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3205 = objc_build_message_expr (build_tree_list (rec
, args
));
3206 mexpr
.original_code
= ERROR_MARK
;
3207 mexpr
.original_type
= NULL
;
3208 /* Now parse and process the remainder of the
3209 initializer, starting with this message
3210 expression as a primary-expression. */
3211 c_parser_initval (parser
, &mexpr
);
3214 c_parser_consume_token (parser
);
3215 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3216 array_desig_after_first
:
3217 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3219 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3220 c_parser_consume_token (parser
);
3221 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3225 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3227 c_parser_consume_token (parser
);
3228 set_init_index (first
, second
);
3230 pedwarn (ellipsis_loc
, OPT_pedantic
,
3231 "ISO C forbids specifying range of elements to initialize");
3234 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3240 if (c_parser_next_token_is (parser
, CPP_EQ
))
3243 pedwarn (des_loc
, OPT_pedantic
,
3244 "ISO C90 forbids specifying subobject to initialize");
3245 c_parser_consume_token (parser
);
3250 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3251 "obsolete use of designated initializer without %<=%>");
3255 init
.value
= error_mark_node
;
3256 init
.original_code
= ERROR_MARK
;
3257 init
.original_type
= NULL
;
3258 c_parser_error (parser
, "expected %<=%>");
3259 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3260 process_init_element (init
, false);
3266 c_parser_initval (parser
, NULL
);
3269 /* Parse a nested initializer; as c_parser_initializer but parses
3270 initializers within braced lists, after any designators have been
3271 applied. If AFTER is not NULL then it is an Objective-C message
3272 expression which is the primary-expression starting the
3276 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3279 gcc_assert (!after
|| c_dialect_objc ());
3280 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3281 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3284 init
= c_parser_expr_no_commas (parser
, after
);
3285 if (init
.value
!= NULL_TREE
3286 && TREE_CODE (init
.value
) != STRING_CST
3287 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3288 init
= default_function_array_conversion (init
);
3290 process_init_element (init
, false);
3293 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3297 { block-item-list[opt] }
3298 { label-declarations block-item-list }
3302 block-item-list block-item
3314 { label-declarations block-item-list }
3317 __extension__ nested-declaration
3318 nested-function-definition
3322 label-declarations label-declaration
3325 __label__ identifier-list ;
3327 Allowing the mixing of declarations and code is new in C99. The
3328 GNU syntax also permits (not shown above) labels at the end of
3329 compound statements, which yield an error. We don't allow labels
3330 on declarations; this might seem like a natural extension, but
3331 there would be a conflict between attributes on the label and
3332 prefix attributes on the declaration. ??? The syntax follows the
3333 old parser in requiring something after label declarations.
3334 Although they are erroneous if the labels declared aren't defined,
3335 is it useful for the syntax to be this way?
3347 c_parser_compound_statement (c_parser
*parser
)
3350 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3352 /* Ensure a scope is entered and left anyway to avoid confusion
3353 if we have just prepared to enter a function body. */
3354 stmt
= c_begin_compound_stmt (true);
3355 c_end_compound_stmt (stmt
, true);
3356 return error_mark_node
;
3358 stmt
= c_begin_compound_stmt (true);
3359 c_parser_compound_statement_nostart (parser
);
3360 return c_end_compound_stmt (stmt
, true);
3363 /* Parse a compound statement except for the opening brace. This is
3364 used for parsing both compound statements and statement expressions
3365 (which follow different paths to handling the opening). */
3368 c_parser_compound_statement_nostart (c_parser
*parser
)
3370 bool last_stmt
= false;
3371 bool last_label
= false;
3372 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3373 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3374 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3376 c_parser_consume_token (parser
);
3379 mark_valid_location_for_stdc_pragma (true);
3380 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3382 location_t err_loc
= c_parser_peek_token (parser
)->location
;
3383 /* Read zero or more forward-declarations for labels that nested
3384 functions can jump to. */
3385 mark_valid_location_for_stdc_pragma (false);
3386 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3388 c_parser_consume_token (parser
);
3389 /* Any identifiers, including those declared as type names,
3394 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3396 c_parser_error (parser
, "expected identifier");
3400 = declare_label (c_parser_peek_token (parser
)->value
);
3401 C_DECLARED_LABEL_FLAG (label
) = 1;
3402 add_stmt (build_stmt (DECL_EXPR
, label
));
3403 c_parser_consume_token (parser
);
3404 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3405 c_parser_consume_token (parser
);
3409 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3411 pedwarn (err_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3413 /* We must now have at least one statement, label or declaration. */
3414 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3416 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3417 c_parser_error (parser
, "expected declaration or statement");
3418 c_parser_consume_token (parser
);
3421 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3423 location_t loc
= c_parser_peek_token (parser
)->location
;
3424 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3425 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3426 || (c_parser_next_token_is (parser
, CPP_NAME
)
3427 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3429 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3430 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3432 label_loc
= c_parser_peek_token (parser
)->location
;
3435 mark_valid_location_for_stdc_pragma (false);
3436 c_parser_label (parser
);
3438 else if (!last_label
3439 && c_parser_next_token_starts_declspecs (parser
))
3442 mark_valid_location_for_stdc_pragma (false);
3443 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3446 (pedantic
&& !flag_isoc99
)
3448 : OPT_Wdeclaration_after_statement
,
3449 "ISO C90 forbids mixed declarations and code");
3452 else if (!last_label
3453 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3455 /* __extension__ can start a declaration, but is also an
3456 unary operator that can start an expression. Consume all
3457 but the last of a possible series of __extension__ to
3459 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3460 && (c_parser_peek_2nd_token (parser
)->keyword
3462 c_parser_consume_token (parser
);
3463 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3466 ext
= disable_extension_diagnostics ();
3467 c_parser_consume_token (parser
);
3469 mark_valid_location_for_stdc_pragma (false);
3470 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3471 /* Following the old parser, __extension__ does not
3472 disable this diagnostic. */
3473 restore_extension_diagnostics (ext
);
3475 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3477 : OPT_Wdeclaration_after_statement
,
3478 "ISO C90 forbids mixed declarations and code");
3484 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3486 /* External pragmas, and some omp pragmas, are not associated
3487 with regular c code, and so are not to be considered statements
3488 syntactically. This ensures that the user doesn't put them
3489 places that would turn into syntax errors if the directive
3491 if (c_parser_pragma (parser
, pragma_compound
))
3492 last_label
= false, last_stmt
= true;
3494 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3496 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3497 c_parser_error (parser
, "expected declaration or statement");
3500 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3502 if (parser
->in_if_block
)
3504 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3505 error_at (loc
, """expected %<}%> before %<else%>");
3510 error_at (loc
, "%<else%> without a previous %<if%>");
3511 c_parser_consume_token (parser
);
3520 mark_valid_location_for_stdc_pragma (false);
3521 c_parser_statement_after_labels (parser
);
3524 parser
->error
= false;
3527 error_at (label_loc
, "label at end of compound statement");
3528 c_parser_consume_token (parser
);
3529 /* Restore the value we started with. */
3530 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3533 /* Parse a label (C90 6.6.1, C99 6.8.1).
3536 identifier : attributes[opt]
3537 case constant-expression :
3543 case constant-expression ... constant-expression :
3545 The use of attributes on labels is a GNU extension. The syntax in
3546 GNU C accepts any expressions without commas, non-constant
3547 expressions being rejected later. */
3550 c_parser_label (c_parser
*parser
)
3552 location_t loc1
= c_parser_peek_token (parser
)->location
;
3553 tree label
= NULL_TREE
;
3554 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3557 c_parser_consume_token (parser
);
3558 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3559 if (c_parser_next_token_is (parser
, CPP_COLON
))
3561 c_parser_consume_token (parser
);
3562 label
= do_case (exp1
, NULL_TREE
);
3564 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3566 c_parser_consume_token (parser
);
3567 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3568 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3569 label
= do_case (exp1
, exp2
);
3572 c_parser_error (parser
, "expected %<:%> or %<...%>");
3574 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3576 c_parser_consume_token (parser
);
3577 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3578 label
= do_case (NULL_TREE
, NULL_TREE
);
3582 tree name
= c_parser_peek_token (parser
)->value
;
3585 location_t loc2
= c_parser_peek_token (parser
)->location
;
3586 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3587 c_parser_consume_token (parser
);
3588 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3589 c_parser_consume_token (parser
);
3590 attrs
= c_parser_attributes (parser
);
3591 tlab
= define_label (loc2
, name
);
3594 decl_attributes (&tlab
, attrs
, 0);
3595 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3600 SET_EXPR_LOCATION (label
, loc1
);
3601 if (c_parser_next_token_starts_declspecs (parser
)
3602 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3603 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3605 error_at (c_parser_peek_token (parser
)->location
,
3606 "a label can only be part of a statement and "
3607 "a declaration is not a statement");
3608 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3609 /*nested*/ true, /*empty_ok*/ false,
3610 /*start_attr_ok*/ true);
3615 /* Parse a statement (C90 6.6, C99 6.8).
3620 expression-statement
3628 expression-statement:
3631 selection-statement:
3635 iteration-statement:
3644 return expression[opt] ;
3657 objc-throw-statement
3658 objc-try-catch-statement
3659 objc-synchronized-statement
3661 objc-throw-statement:
3675 parallel-for-construct
3676 parallel-sections-construct
3683 parallel-directive structured-block
3686 for-directive iteration-statement
3689 sections-directive section-scope
3692 single-directive structured-block
3694 parallel-for-construct:
3695 parallel-for-directive iteration-statement
3697 parallel-sections-construct:
3698 parallel-sections-directive section-scope
3701 master-directive structured-block
3704 critical-directive structured-block
3707 atomic-directive expression-statement
3710 ordered-directive structured-block */
3713 c_parser_statement (c_parser
*parser
)
3715 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3716 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3717 || (c_parser_next_token_is (parser
, CPP_NAME
)
3718 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3719 c_parser_label (parser
);
3720 c_parser_statement_after_labels (parser
);
3723 /* Parse a statement, other than a labeled statement. */
3726 c_parser_statement_after_labels (c_parser
*parser
)
3728 location_t loc
= c_parser_peek_token (parser
)->location
;
3729 tree stmt
= NULL_TREE
;
3730 bool in_if_block
= parser
->in_if_block
;
3731 parser
->in_if_block
= false;
3732 switch (c_parser_peek_token (parser
)->type
)
3734 case CPP_OPEN_BRACE
:
3735 add_stmt (c_parser_compound_statement (parser
));
3738 switch (c_parser_peek_token (parser
)->keyword
)
3741 c_parser_if_statement (parser
);
3744 c_parser_switch_statement (parser
);
3747 c_parser_while_statement (parser
);
3750 c_parser_do_statement (parser
);
3753 c_parser_for_statement (parser
);
3756 c_parser_consume_token (parser
);
3757 if (c_parser_next_token_is (parser
, CPP_NAME
))
3759 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3760 c_parser_consume_token (parser
);
3762 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3764 c_parser_consume_token (parser
);
3765 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3768 c_parser_error (parser
, "expected identifier or %<*%>");
3769 goto expect_semicolon
;
3771 c_parser_consume_token (parser
);
3772 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3773 goto expect_semicolon
;
3775 c_parser_consume_token (parser
);
3776 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3777 goto expect_semicolon
;
3779 c_parser_consume_token (parser
);
3780 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3782 stmt
= c_finish_return (NULL_TREE
, NULL_TREE
);
3783 c_parser_consume_token (parser
);
3787 struct c_expr expr
= c_parser_expression_conv (parser
);
3788 stmt
= c_finish_return (expr
.value
, expr
.original_type
);
3789 goto expect_semicolon
;
3793 stmt
= c_parser_asm_statement (parser
);
3796 gcc_assert (c_dialect_objc ());
3797 c_parser_consume_token (parser
);
3798 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3800 stmt
= objc_build_throw_stmt (NULL_TREE
);
3801 c_parser_consume_token (parser
);
3805 tree expr
= c_parser_expression (parser
).value
;
3806 expr
= c_fully_fold (expr
, false, NULL
);
3807 stmt
= objc_build_throw_stmt (expr
);
3808 goto expect_semicolon
;
3812 gcc_assert (c_dialect_objc ());
3813 c_parser_objc_try_catch_statement (parser
);
3815 case RID_AT_SYNCHRONIZED
:
3816 gcc_assert (c_dialect_objc ());
3817 c_parser_objc_synchronized_statement (parser
);
3824 c_parser_consume_token (parser
);
3826 case CPP_CLOSE_PAREN
:
3827 case CPP_CLOSE_SQUARE
:
3828 /* Avoid infinite loop in error recovery:
3829 c_parser_skip_until_found stops at a closing nesting
3830 delimiter without consuming it, but here we need to consume
3831 it to proceed further. */
3832 c_parser_error (parser
, "expected statement");
3833 c_parser_consume_token (parser
);
3836 c_parser_pragma (parser
, pragma_stmt
);
3840 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3842 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3845 /* Two cases cannot and do not have line numbers associated: If stmt
3846 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3847 cannot hold line numbers. But that's OK because the statement
3848 will either be changed to a MODIFY_EXPR during gimplification of
3849 the statement expr, or discarded. If stmt was compound, but
3850 without new variables, we will have skipped the creation of a
3851 BIND and will have a bare STATEMENT_LIST. But that's OK because
3852 (recursively) all of the component statements should already have
3853 line numbers assigned. ??? Can we discard no-op statements
3855 protected_set_expr_location (stmt
, loc
);
3857 parser
->in_if_block
= in_if_block
;
3860 /* Parse the condition from an if, do, while or for statements. */
3863 c_parser_condition (c_parser
*parser
)
3867 loc
= c_parser_peek_token (parser
)->location
;
3868 cond
= c_parser_expression_conv (parser
).value
;
3869 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3870 cond
= c_fully_fold (cond
, false, NULL
);
3871 if (warn_sequence_point
)
3872 verify_sequence_points (cond
);
3876 /* Parse a parenthesized condition from an if, do or while statement.
3882 c_parser_paren_condition (c_parser
*parser
)
3885 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3886 return error_mark_node
;
3887 cond
= c_parser_condition (parser
);
3888 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3892 /* Parse a statement which is a block in C99. */
3895 c_parser_c99_block_statement (c_parser
*parser
)
3897 tree block
= c_begin_compound_stmt (flag_isoc99
);
3898 c_parser_statement (parser
);
3899 return c_end_compound_stmt (block
, flag_isoc99
);
3902 /* Parse the body of an if statement. This is just parsing a
3903 statement but (a) it is a block in C99, (b) we track whether the
3904 body is an if statement for the sake of -Wparentheses warnings, (c)
3905 we handle an empty body specially for the sake of -Wempty-body
3906 warnings, and (d) we call parser_compound_statement directly
3907 because c_parser_statement_after_labels resets
3908 parser->in_if_block. */
3911 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3913 tree block
= c_begin_compound_stmt (flag_isoc99
);
3914 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3915 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3916 || (c_parser_next_token_is (parser
, CPP_NAME
)
3917 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3918 c_parser_label (parser
);
3919 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3920 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3922 location_t loc
= c_parser_peek_token (parser
)->location
;
3923 add_stmt (build_empty_stmt ());
3924 c_parser_consume_token (parser
);
3925 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3926 warning_at (loc
, OPT_Wempty_body
,
3927 "suggest braces around empty body in an %<if%> statement");
3929 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3930 add_stmt (c_parser_compound_statement (parser
));
3932 c_parser_statement_after_labels (parser
);
3933 return c_end_compound_stmt (block
, flag_isoc99
);
3936 /* Parse the else body of an if statement. This is just parsing a
3937 statement but (a) it is a block in C99, (b) we handle an empty body
3938 specially for the sake of -Wempty-body warnings. */
3941 c_parser_else_body (c_parser
*parser
)
3943 tree block
= c_begin_compound_stmt (flag_isoc99
);
3944 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3945 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3946 || (c_parser_next_token_is (parser
, CPP_NAME
)
3947 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3948 c_parser_label (parser
);
3949 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3951 warning_at (c_parser_peek_token (parser
)->location
,
3953 "suggest braces around empty body in an %<else%> statement");
3954 add_stmt (build_empty_stmt ());
3955 c_parser_consume_token (parser
);
3958 c_parser_statement_after_labels (parser
);
3959 return c_end_compound_stmt (block
, flag_isoc99
);
3962 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3965 if ( expression ) statement
3966 if ( expression ) statement else statement
3970 c_parser_if_statement (c_parser
*parser
)
3975 bool first_if
= false;
3976 tree first_body
, second_body
;
3979 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3980 c_parser_consume_token (parser
);
3981 block
= c_begin_compound_stmt (flag_isoc99
);
3982 loc
= c_parser_peek_token (parser
)->location
;
3983 cond
= c_parser_paren_condition (parser
);
3984 in_if_block
= parser
->in_if_block
;
3985 parser
->in_if_block
= true;
3986 first_body
= c_parser_if_body (parser
, &first_if
);
3987 parser
->in_if_block
= in_if_block
;
3988 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3990 c_parser_consume_token (parser
);
3991 second_body
= c_parser_else_body (parser
);
3994 second_body
= NULL_TREE
;
3995 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3996 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3999 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4002 switch (expression) statement
4006 c_parser_switch_statement (c_parser
*parser
)
4008 tree block
, expr
, body
, save_break
;
4009 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4010 c_parser_consume_token (parser
);
4011 block
= c_begin_compound_stmt (flag_isoc99
);
4012 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4014 expr
= c_parser_expression (parser
).value
;
4015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4018 expr
= error_mark_node
;
4019 c_start_case (expr
);
4020 save_break
= c_break_label
;
4021 c_break_label
= NULL_TREE
;
4022 body
= c_parser_c99_block_statement (parser
);
4023 c_finish_case (body
);
4025 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
4026 c_break_label
= save_break
;
4027 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4030 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4033 while (expression) statement
4037 c_parser_while_statement (c_parser
*parser
)
4039 tree block
, cond
, body
, save_break
, save_cont
;
4041 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4042 c_parser_consume_token (parser
);
4043 block
= c_begin_compound_stmt (flag_isoc99
);
4044 loc
= c_parser_peek_token (parser
)->location
;
4045 cond
= c_parser_paren_condition (parser
);
4046 save_break
= c_break_label
;
4047 c_break_label
= NULL_TREE
;
4048 save_cont
= c_cont_label
;
4049 c_cont_label
= NULL_TREE
;
4050 body
= c_parser_c99_block_statement (parser
);
4051 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4052 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4053 c_break_label
= save_break
;
4054 c_cont_label
= save_cont
;
4057 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4060 do statement while ( expression ) ;
4064 c_parser_do_statement (c_parser
*parser
)
4066 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4068 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4069 c_parser_consume_token (parser
);
4070 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4071 warning_at (c_parser_peek_token (parser
)->location
,
4073 "suggest braces around empty body in %<do%> statement");
4074 block
= c_begin_compound_stmt (flag_isoc99
);
4075 loc
= c_parser_peek_token (parser
)->location
;
4076 save_break
= c_break_label
;
4077 c_break_label
= NULL_TREE
;
4078 save_cont
= c_cont_label
;
4079 c_cont_label
= NULL_TREE
;
4080 body
= c_parser_c99_block_statement (parser
);
4081 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4082 new_break
= c_break_label
;
4083 c_break_label
= save_break
;
4084 new_cont
= c_cont_label
;
4085 c_cont_label
= save_cont
;
4086 cond
= c_parser_paren_condition (parser
);
4087 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4088 c_parser_skip_to_end_of_block_or_statement (parser
);
4089 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4090 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4093 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4096 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4097 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4099 The form with a declaration is new in C99.
4101 ??? In accordance with the old parser, the declaration may be a
4102 nested function, which is then rejected in check_for_loop_decls,
4103 but does it make any sense for this to be included in the grammar?
4104 Note in particular that the nested function does not include a
4105 trailing ';', whereas the "declaration" production includes one.
4106 Also, can we reject bad declarations earlier and cheaper than
4107 check_for_loop_decls? */
4110 c_parser_for_statement (c_parser
*parser
)
4112 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4114 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4115 loc
= c_parser_peek_token (parser
)->location
;
4116 c_parser_consume_token (parser
);
4117 block
= c_begin_compound_stmt (flag_isoc99
);
4118 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4120 /* Parse the initialization declaration or expression. */
4121 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4123 c_parser_consume_token (parser
);
4124 c_finish_expr_stmt (NULL_TREE
);
4126 else if (c_parser_next_token_starts_declspecs (parser
))
4128 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4129 check_for_loop_decls ();
4131 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4133 /* __extension__ can start a declaration, but is also an
4134 unary operator that can start an expression. Consume all
4135 but the last of a possible series of __extension__ to
4137 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4138 && (c_parser_peek_2nd_token (parser
)->keyword
4140 c_parser_consume_token (parser
);
4141 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4144 ext
= disable_extension_diagnostics ();
4145 c_parser_consume_token (parser
);
4146 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4147 restore_extension_diagnostics (ext
);
4148 check_for_loop_decls ();
4156 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4157 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4159 /* Parse the loop condition. */
4160 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4162 c_parser_consume_token (parser
);
4167 cond
= c_parser_condition (parser
);
4168 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4170 /* Parse the increment expression. */
4171 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4172 incr
= c_process_expr_stmt (NULL_TREE
);
4174 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4179 cond
= error_mark_node
;
4180 incr
= error_mark_node
;
4182 save_break
= c_break_label
;
4183 c_break_label
= NULL_TREE
;
4184 save_cont
= c_cont_label
;
4185 c_cont_label
= NULL_TREE
;
4186 body
= c_parser_c99_block_statement (parser
);
4187 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4188 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4189 c_break_label
= save_break
;
4190 c_cont_label
= save_cont
;
4193 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4194 statement with inputs, outputs, clobbers, and volatile tag
4198 asm type-qualifier[opt] ( asm-argument ) ;
4202 asm-string-literal : asm-operands[opt]
4203 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4204 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4206 Qualifiers other than volatile are accepted in the syntax but
4210 c_parser_asm_statement (c_parser
*parser
)
4212 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4214 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4215 c_parser_consume_token (parser
);
4216 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4218 quals
= c_parser_peek_token (parser
)->value
;
4219 c_parser_consume_token (parser
);
4221 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4222 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4224 warning_at (c_parser_peek_token (parser
)->location
,
4226 "%E qualifier ignored on asm",
4227 c_parser_peek_token (parser
)->value
);
4229 c_parser_consume_token (parser
);
4233 /* ??? Follow the C++ parser rather than using the
4234 lex_untranslated_string kludge. */
4235 parser
->lex_untranslated_string
= true;
4236 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4238 parser
->lex_untranslated_string
= false;
4241 str
= c_parser_asm_string_literal (parser
);
4242 if (str
== NULL_TREE
)
4244 parser
->lex_untranslated_string
= false;
4245 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4248 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4251 outputs
= NULL_TREE
;
4253 clobbers
= NULL_TREE
;
4256 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4258 parser
->lex_untranslated_string
= false;
4259 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4263 /* Parse outputs. */
4264 if (c_parser_next_token_is (parser
, CPP_COLON
)
4265 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4266 outputs
= NULL_TREE
;
4268 outputs
= c_parser_asm_operands (parser
, false);
4269 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4272 clobbers
= NULL_TREE
;
4275 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4277 parser
->lex_untranslated_string
= false;
4278 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4282 if (c_parser_next_token_is (parser
, CPP_COLON
)
4283 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4286 inputs
= c_parser_asm_operands (parser
, true);
4287 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4289 clobbers
= NULL_TREE
;
4292 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4294 parser
->lex_untranslated_string
= false;
4295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4298 /* Parse clobbers. */
4299 clobbers
= c_parser_asm_clobbers (parser
);
4301 parser
->lex_untranslated_string
= false;
4302 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4307 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4308 c_parser_skip_to_end_of_block_or_statement (parser
);
4309 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4314 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4315 not outputs), apply the default conversion of functions and arrays
4320 asm-operands , asm-operand
4323 asm-string-literal ( expression )
4324 [ identifier ] asm-string-literal ( expression )
4328 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4330 tree list
= NULL_TREE
;
4335 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4337 c_parser_consume_token (parser
);
4338 if (c_parser_next_token_is (parser
, CPP_NAME
))
4340 tree id
= c_parser_peek_token (parser
)->value
;
4341 c_parser_consume_token (parser
);
4342 name
= build_string (IDENTIFIER_LENGTH (id
),
4343 IDENTIFIER_POINTER (id
));
4347 c_parser_error (parser
, "expected identifier");
4348 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4351 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4356 str
= c_parser_asm_string_literal (parser
);
4357 if (str
== NULL_TREE
)
4359 parser
->lex_untranslated_string
= false;
4360 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4362 parser
->lex_untranslated_string
= true;
4365 expr
= c_parser_expression (parser
);
4367 expr
= default_function_array_conversion (expr
);
4368 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4369 parser
->lex_untranslated_string
= true;
4370 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4372 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4375 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4377 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4378 c_parser_consume_token (parser
);
4385 /* Parse asm clobbers, a GNU extension.
4389 asm-clobbers , asm-string-literal
4393 c_parser_asm_clobbers (c_parser
*parser
)
4395 tree list
= NULL_TREE
;
4398 tree str
= c_parser_asm_string_literal (parser
);
4400 list
= tree_cons (NULL_TREE
, str
, list
);
4403 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4404 c_parser_consume_token (parser
);
4411 /* Parse an expression other than a compound expression; that is, an
4412 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4413 NULL then it is an Objective-C message expression which is the
4414 primary-expression starting the expression as an initializer.
4416 assignment-expression:
4417 conditional-expression
4418 unary-expression assignment-operator assignment-expression
4420 assignment-operator: one of
4421 = *= /= %= += -= <<= >>= &= ^= |=
4423 In GNU C we accept any conditional expression on the LHS and
4424 diagnose the invalid lvalue rather than producing a syntax
4427 static struct c_expr
4428 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4430 struct c_expr lhs
, rhs
, ret
;
4431 enum tree_code code
;
4432 location_t op_location
;
4433 gcc_assert (!after
|| c_dialect_objc ());
4434 lhs
= c_parser_conditional_expression (parser
, after
);
4435 op_location
= c_parser_peek_token (parser
)->location
;
4436 switch (c_parser_peek_token (parser
)->type
)
4445 code
= TRUNC_DIV_EXPR
;
4448 code
= TRUNC_MOD_EXPR
;
4463 code
= BIT_AND_EXPR
;
4466 code
= BIT_XOR_EXPR
;
4469 code
= BIT_IOR_EXPR
;
4474 c_parser_consume_token (parser
);
4475 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4476 rhs
= default_function_array_conversion (rhs
);
4477 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4478 code
, rhs
.value
, rhs
.original_type
);
4479 if (code
== NOP_EXPR
)
4480 ret
.original_code
= MODIFY_EXPR
;
4483 TREE_NO_WARNING (ret
.value
) = 1;
4484 ret
.original_code
= ERROR_MARK
;
4486 ret
.original_type
= NULL
;
4490 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4491 is not NULL then it is an Objective-C message expression which is
4492 the primary-expression starting the expression as an initializer.
4494 conditional-expression:
4495 logical-OR-expression
4496 logical-OR-expression ? expression : conditional-expression
4500 conditional-expression:
4501 logical-OR-expression ? : conditional-expression
4504 static struct c_expr
4505 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4507 struct c_expr cond
, exp1
, exp2
, ret
;
4508 location_t cond_loc
;
4510 gcc_assert (!after
|| c_dialect_objc ());
4512 cond_loc
= c_parser_peek_token (parser
)->location
;
4513 cond
= c_parser_binary_expression (parser
, after
);
4515 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4517 cond
= default_function_array_conversion (cond
);
4518 c_parser_consume_token (parser
);
4519 if (c_parser_next_token_is (parser
, CPP_COLON
))
4521 tree eptype
= NULL_TREE
;
4522 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4523 "ISO C forbids omitting the middle term of a ?: expression");
4524 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4526 eptype
= TREE_TYPE (cond
.value
);
4527 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4529 /* Make sure first operand is calculated only once. */
4530 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4532 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4533 exp1
.original_type
= NULL
;
4534 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4535 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4540 = c_objc_common_truthvalue_conversion
4541 (cond_loc
, default_conversion (cond
.value
));
4542 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4543 exp1
= c_parser_expression_conv (parser
);
4544 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4545 - (cond
.value
== truthvalue_false_node
));
4547 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4549 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4550 ret
.value
= error_mark_node
;
4551 ret
.original_code
= ERROR_MARK
;
4552 ret
.original_type
= NULL
;
4555 exp2
= c_parser_conditional_expression (parser
, NULL
);
4556 exp2
= default_function_array_conversion (exp2
);
4557 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4558 ret
.value
= build_conditional_expr (cond
.value
,
4559 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4560 exp1
.value
, exp2
.value
);
4561 ret
.original_code
= ERROR_MARK
;
4562 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4563 ret
.original_type
= NULL
;
4568 /* If both sides are enum type, the default conversion will have
4569 made the type of the result be an integer type. We want to
4570 remember the enum types we started with. */
4571 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4572 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4573 ret
.original_type
= ((t1
!= error_mark_node
4574 && t2
!= error_mark_node
4575 && (TYPE_MAIN_VARIANT (t1
)
4576 == TYPE_MAIN_VARIANT (t2
)))
4583 /* Parse a binary expression; that is, a logical-OR-expression (C90
4584 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4585 an Objective-C message expression which is the primary-expression
4586 starting the expression as an initializer.
4588 multiplicative-expression:
4590 multiplicative-expression * cast-expression
4591 multiplicative-expression / cast-expression
4592 multiplicative-expression % cast-expression
4594 additive-expression:
4595 multiplicative-expression
4596 additive-expression + multiplicative-expression
4597 additive-expression - multiplicative-expression
4601 shift-expression << additive-expression
4602 shift-expression >> additive-expression
4604 relational-expression:
4606 relational-expression < shift-expression
4607 relational-expression > shift-expression
4608 relational-expression <= shift-expression
4609 relational-expression >= shift-expression
4611 equality-expression:
4612 relational-expression
4613 equality-expression == relational-expression
4614 equality-expression != relational-expression
4618 AND-expression & equality-expression
4620 exclusive-OR-expression:
4622 exclusive-OR-expression ^ AND-expression
4624 inclusive-OR-expression:
4625 exclusive-OR-expression
4626 inclusive-OR-expression | exclusive-OR-expression
4628 logical-AND-expression:
4629 inclusive-OR-expression
4630 logical-AND-expression && inclusive-OR-expression
4632 logical-OR-expression:
4633 logical-AND-expression
4634 logical-OR-expression || logical-AND-expression
4637 static struct c_expr
4638 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4640 /* A binary expression is parsed using operator-precedence parsing,
4641 with the operands being cast expressions. All the binary
4642 operators are left-associative. Thus a binary expression is of
4645 E0 op1 E1 op2 E2 ...
4647 which we represent on a stack. On the stack, the precedence
4648 levels are strictly increasing. When a new operator is
4649 encountered of higher precedence than that at the top of the
4650 stack, it is pushed; its LHS is the top expression, and its RHS
4651 is everything parsed until it is popped. When a new operator is
4652 encountered with precedence less than or equal to that at the top
4653 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4654 by the result of the operation until the operator at the top of
4655 the stack has lower precedence than the new operator or there is
4656 only one element on the stack; then the top expression is the LHS
4657 of the new operator. In the case of logical AND and OR
4658 expressions, we also need to adjust skip_evaluation as
4659 appropriate when the operators are pushed and popped. */
4661 /* The precedence levels, where 0 is a dummy lowest level used for
4662 the bottom of the stack. */
4678 /* The expression at this stack level. */
4680 /* The precedence of the operator on its left, PREC_NONE at the
4681 bottom of the stack. */
4683 /* The operation on its left. */
4685 /* The source location of this operation. */
4689 /* Location of the binary operator. */
4690 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4693 switch (stack[sp].op) \
4695 case TRUTH_ANDIF_EXPR: \
4696 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4698 case TRUTH_ORIF_EXPR: \
4699 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4704 stack[sp - 1].expr \
4705 = default_function_array_conversion (stack[sp - 1].expr); \
4707 = default_function_array_conversion (stack[sp].expr); \
4708 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4710 stack[sp - 1].expr, \
4714 gcc_assert (!after
|| c_dialect_objc ());
4715 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4716 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4717 stack
[0].prec
= PREC_NONE
;
4722 enum tree_code ocode
;
4725 switch (c_parser_peek_token (parser
)->type
)
4733 ocode
= TRUNC_DIV_EXPR
;
4737 ocode
= TRUNC_MOD_EXPR
;
4749 ocode
= LSHIFT_EXPR
;
4753 ocode
= RSHIFT_EXPR
;
4767 case CPP_GREATER_EQ
:
4780 oprec
= PREC_BITAND
;
4781 ocode
= BIT_AND_EXPR
;
4784 oprec
= PREC_BITXOR
;
4785 ocode
= BIT_XOR_EXPR
;
4789 ocode
= BIT_IOR_EXPR
;
4792 oprec
= PREC_LOGAND
;
4793 ocode
= TRUTH_ANDIF_EXPR
;
4797 ocode
= TRUTH_ORIF_EXPR
;
4800 /* Not a binary operator, so end of the binary
4804 binary_loc
= c_parser_peek_token (parser
)->location
;
4805 c_parser_consume_token (parser
);
4806 while (oprec
<= stack
[sp
].prec
)
4810 case TRUTH_ANDIF_EXPR
:
4812 = default_function_array_conversion (stack
[sp
].expr
);
4813 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4814 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4815 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4817 case TRUTH_ORIF_EXPR
:
4819 = default_function_array_conversion (stack
[sp
].expr
);
4820 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4821 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4822 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4828 stack
[sp
].loc
= binary_loc
;
4829 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4830 stack
[sp
].prec
= oprec
;
4831 stack
[sp
].op
= ocode
;
4836 return stack
[0].expr
;
4840 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4841 NULL then it is an Objective-C message expression which is the
4842 primary-expression starting the expression as an initializer.
4846 ( type-name ) unary-expression
4849 static struct c_expr
4850 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4852 gcc_assert (!after
|| c_dialect_objc ());
4854 return c_parser_postfix_expression_after_primary (parser
, *after
);
4855 /* If the expression begins with a parenthesized type name, it may
4856 be either a cast or a compound literal; we need to see whether
4857 the next character is '{' to tell the difference. If not, it is
4858 an unary expression. */
4859 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4860 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4863 struct c_type_name
*type_name
;
4866 c_parser_consume_token (parser
);
4867 loc
= c_parser_peek_token (parser
)->location
;
4868 type_name
= c_parser_type_name (parser
);
4869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4870 if (type_name
== NULL
)
4872 ret
.value
= error_mark_node
;
4873 ret
.original_code
= ERROR_MARK
;
4874 ret
.original_type
= NULL
;
4878 /* Save casted types in the function's used types hash table. */
4879 used_types_insert (type_name
->specs
->type
);
4881 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4882 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
4884 expr
= c_parser_cast_expression (parser
, NULL
);
4885 expr
= default_function_array_conversion (expr
);
4886 ret
.value
= c_cast_expr (type_name
, expr
.value
, loc
);
4887 ret
.original_code
= ERROR_MARK
;
4888 ret
.original_type
= NULL
;
4892 return c_parser_unary_expression (parser
);
4895 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4901 unary-operator cast-expression
4902 sizeof unary-expression
4903 sizeof ( type-name )
4905 unary-operator: one of
4911 __alignof__ unary-expression
4912 __alignof__ ( type-name )
4915 unary-operator: one of
4916 __extension__ __real__ __imag__
4918 In addition, the GNU syntax treats ++ and -- as unary operators, so
4919 they may be applied to cast expressions with errors for non-lvalues
4922 static struct c_expr
4923 c_parser_unary_expression (c_parser
*parser
)
4926 struct c_expr ret
, op
;
4927 location_t loc
= c_parser_peek_token (parser
)->location
;
4928 ret
.original_code
= ERROR_MARK
;
4929 ret
.original_type
= NULL
;
4930 switch (c_parser_peek_token (parser
)->type
)
4933 c_parser_consume_token (parser
);
4934 op
= c_parser_cast_expression (parser
, NULL
);
4935 op
= default_function_array_conversion (op
);
4936 return parser_build_unary_op (PREINCREMENT_EXPR
, op
, loc
);
4937 case CPP_MINUS_MINUS
:
4938 c_parser_consume_token (parser
);
4939 op
= c_parser_cast_expression (parser
, NULL
);
4940 op
= default_function_array_conversion (op
);
4941 return parser_build_unary_op (PREDECREMENT_EXPR
, op
, loc
);
4943 c_parser_consume_token (parser
);
4944 return parser_build_unary_op (ADDR_EXPR
,
4945 c_parser_cast_expression (parser
, NULL
),
4948 c_parser_consume_token (parser
);
4949 op
= c_parser_cast_expression (parser
, NULL
);
4950 op
= default_function_array_conversion (op
);
4951 ret
.value
= build_indirect_ref (loc
, op
.value
, "unary *");
4954 if (!c_dialect_objc () && !in_system_header
)
4955 warning_at (c_parser_peek_token (parser
)->location
,
4957 "traditional C rejects the unary plus operator");
4958 c_parser_consume_token (parser
);
4959 op
= c_parser_cast_expression (parser
, NULL
);
4960 op
= default_function_array_conversion (op
);
4961 return parser_build_unary_op (CONVERT_EXPR
, op
, loc
);
4963 c_parser_consume_token (parser
);
4964 op
= c_parser_cast_expression (parser
, NULL
);
4965 op
= default_function_array_conversion (op
);
4966 return parser_build_unary_op (NEGATE_EXPR
, op
, loc
);
4968 c_parser_consume_token (parser
);
4969 op
= c_parser_cast_expression (parser
, NULL
);
4970 op
= default_function_array_conversion (op
);
4971 return parser_build_unary_op (BIT_NOT_EXPR
, op
, loc
);
4973 c_parser_consume_token (parser
);
4974 op
= c_parser_cast_expression (parser
, NULL
);
4975 op
= default_function_array_conversion (op
);
4976 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
, loc
);
4978 /* Refer to the address of a label as a pointer. */
4979 c_parser_consume_token (parser
);
4980 if (c_parser_next_token_is (parser
, CPP_NAME
))
4982 ret
.value
= finish_label_address_expr
4983 (c_parser_peek_token (parser
)->value
, loc
);
4984 c_parser_consume_token (parser
);
4988 c_parser_error (parser
, "expected identifier");
4989 ret
.value
= error_mark_node
;
4993 switch (c_parser_peek_token (parser
)->keyword
)
4996 return c_parser_sizeof_expression (parser
);
4998 return c_parser_alignof_expression (parser
);
5000 c_parser_consume_token (parser
);
5001 ext
= disable_extension_diagnostics ();
5002 ret
= c_parser_cast_expression (parser
, NULL
);
5003 restore_extension_diagnostics (ext
);
5006 c_parser_consume_token (parser
);
5007 op
= c_parser_cast_expression (parser
, NULL
);
5008 op
= default_function_array_conversion (op
);
5009 return parser_build_unary_op (REALPART_EXPR
, op
, loc
);
5011 c_parser_consume_token (parser
);
5012 op
= c_parser_cast_expression (parser
, NULL
);
5013 op
= default_function_array_conversion (op
);
5014 return parser_build_unary_op (IMAGPART_EXPR
, op
, loc
);
5016 return c_parser_postfix_expression (parser
);
5019 return c_parser_postfix_expression (parser
);
5023 /* Parse a sizeof expression. */
5025 static struct c_expr
5026 c_parser_sizeof_expression (c_parser
*parser
)
5029 location_t expr_loc
;
5030 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5031 c_parser_consume_token (parser
);
5034 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5035 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5037 /* Either sizeof ( type-name ) or sizeof unary-expression
5038 starting with a compound literal. */
5039 struct c_type_name
*type_name
;
5040 c_parser_consume_token (parser
);
5041 expr_loc
= c_parser_peek_token (parser
)->location
;
5042 type_name
= c_parser_type_name (parser
);
5043 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5044 if (type_name
== NULL
)
5049 ret
.value
= error_mark_node
;
5050 ret
.original_code
= ERROR_MARK
;
5051 ret
.original_type
= NULL
;
5054 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5056 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5061 /* sizeof ( type-name ). */
5064 return c_expr_sizeof_type (type_name
);
5068 expr_loc
= c_parser_peek_token (parser
)->location
;
5069 expr
= c_parser_unary_expression (parser
);
5073 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5074 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5075 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5076 return c_expr_sizeof_expr (expr
);
5080 /* Parse an alignof expression. */
5082 static struct c_expr
5083 c_parser_alignof_expression (c_parser
*parser
)
5086 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5087 c_parser_consume_token (parser
);
5090 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5091 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5093 /* Either __alignof__ ( type-name ) or __alignof__
5094 unary-expression starting with a compound literal. */
5096 struct c_type_name
*type_name
;
5098 c_parser_consume_token (parser
);
5099 loc
= c_parser_peek_token (parser
)->location
;
5100 type_name
= c_parser_type_name (parser
);
5101 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5102 if (type_name
== NULL
)
5107 ret
.value
= error_mark_node
;
5108 ret
.original_code
= ERROR_MARK
;
5109 ret
.original_type
= NULL
;
5112 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5114 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5119 /* alignof ( type-name ). */
5122 ret
.value
= c_alignof (groktypename (type_name
, NULL
, NULL
));
5123 ret
.original_code
= ERROR_MARK
;
5124 ret
.original_type
= NULL
;
5130 expr
= c_parser_unary_expression (parser
);
5134 ret
.value
= c_alignof_expr (expr
.value
);
5135 ret
.original_code
= ERROR_MARK
;
5136 ret
.original_type
= NULL
;
5141 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5145 postfix-expression [ expression ]
5146 postfix-expression ( argument-expression-list[opt] )
5147 postfix-expression . identifier
5148 postfix-expression -> identifier
5149 postfix-expression ++
5150 postfix-expression --
5151 ( type-name ) { initializer-list }
5152 ( type-name ) { initializer-list , }
5154 argument-expression-list:
5156 argument-expression-list , argument-expression
5168 (treated as a keyword in GNU C)
5171 ( compound-statement )
5172 __builtin_va_arg ( assignment-expression , type-name )
5173 __builtin_offsetof ( type-name , offsetof-member-designator )
5174 __builtin_choose_expr ( assignment-expression ,
5175 assignment-expression ,
5176 assignment-expression )
5177 __builtin_types_compatible_p ( type-name , type-name )
5179 offsetof-member-designator:
5181 offsetof-member-designator . identifier
5182 offsetof-member-designator [ expression ]
5187 [ objc-receiver objc-message-args ]
5188 @selector ( objc-selector-arg )
5189 @protocol ( identifier )
5190 @encode ( type-name )
5194 static struct c_expr
5195 c_parser_postfix_expression (c_parser
*parser
)
5197 struct c_expr expr
, e1
, e2
, e3
;
5198 struct c_type_name
*t1
, *t2
;
5200 expr
.original_code
= ERROR_MARK
;
5201 expr
.original_type
= NULL
;
5202 switch (c_parser_peek_token (parser
)->type
)
5205 expr
.value
= c_parser_peek_token (parser
)->value
;
5206 loc
= c_parser_peek_token (parser
)->location
;
5207 c_parser_consume_token (parser
);
5208 if (TREE_CODE (expr
.value
) == FIXED_CST
5209 && !targetm
.fixed_point_supported_p ())
5211 error_at (loc
, "fixed-point types not supported for this target");
5212 expr
.value
= error_mark_node
;
5219 expr
.value
= c_parser_peek_token (parser
)->value
;
5220 c_parser_consume_token (parser
);
5226 expr
.value
= c_parser_peek_token (parser
)->value
;
5227 expr
.original_code
= STRING_CST
;
5228 c_parser_consume_token (parser
);
5230 case CPP_OBJC_STRING
:
5231 gcc_assert (c_dialect_objc ());
5233 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5234 c_parser_consume_token (parser
);
5237 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5239 c_parser_error (parser
, "expected expression");
5240 expr
.value
= error_mark_node
;
5244 tree id
= c_parser_peek_token (parser
)->value
;
5245 location_t loc
= c_parser_peek_token (parser
)->location
;
5246 c_parser_consume_token (parser
);
5247 expr
.value
= build_external_ref (id
,
5248 (c_parser_peek_token (parser
)->type
5249 == CPP_OPEN_PAREN
), loc
,
5250 &expr
.original_type
);
5253 case CPP_OPEN_PAREN
:
5254 /* A parenthesized expression, statement expression or compound
5256 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5258 /* A statement expression. */
5260 location_t here
= c_parser_peek_token (parser
)->location
;
5261 c_parser_consume_token (parser
);
5262 c_parser_consume_token (parser
);
5263 if (cur_stmt_list
== NULL
)
5265 error_at (here
, "braced-group within expression allowed "
5266 "only inside a function");
5267 parser
->error
= true;
5268 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5269 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5270 expr
.value
= error_mark_node
;
5273 stmt
= c_begin_stmt_expr ();
5274 c_parser_compound_statement_nostart (parser
);
5275 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5277 pedwarn (here
, OPT_pedantic
,
5278 "ISO C forbids braced-groups within expressions");
5279 expr
.value
= c_finish_stmt_expr (stmt
);
5281 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5283 /* A compound literal. ??? Can we actually get here rather
5284 than going directly to
5285 c_parser_postfix_expression_after_paren_type from
5288 struct c_type_name
*type_name
;
5289 c_parser_consume_token (parser
);
5290 loc
= c_parser_peek_token (parser
)->location
;
5291 type_name
= c_parser_type_name (parser
);
5292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5294 if (type_name
== NULL
)
5296 expr
.value
= error_mark_node
;
5299 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5305 /* A parenthesized expression. */
5306 c_parser_consume_token (parser
);
5307 expr
= c_parser_expression (parser
);
5308 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5309 TREE_NO_WARNING (expr
.value
) = 1;
5310 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5311 expr
.original_code
= ERROR_MARK
;
5312 /* Don't change EXPR.ORIGINAL_TYPE. */
5313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5318 switch (c_parser_peek_token (parser
)->keyword
)
5320 case RID_FUNCTION_NAME
:
5321 case RID_PRETTY_FUNCTION_NAME
:
5322 case RID_C99_FUNCTION_NAME
:
5323 expr
.value
= fname_decl (c_parser_peek_token (parser
)->location
,
5324 c_parser_peek_token (parser
)->keyword
,
5325 c_parser_peek_token (parser
)->value
);
5326 c_parser_consume_token (parser
);
5329 c_parser_consume_token (parser
);
5330 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5332 expr
.value
= error_mark_node
;
5335 e1
= c_parser_expr_no_commas (parser
, NULL
);
5336 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5337 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5340 expr
.value
= error_mark_node
;
5343 t1
= c_parser_type_name (parser
);
5344 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5348 expr
.value
= error_mark_node
;
5352 tree type_expr
= NULL_TREE
;
5353 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
,
5358 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5359 TREE_TYPE (expr
.value
), type_expr
,
5361 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5366 c_parser_consume_token (parser
);
5367 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5369 expr
.value
= error_mark_node
;
5372 t1
= c_parser_type_name (parser
);
5375 expr
.value
= error_mark_node
;
5378 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5381 expr
.value
= error_mark_node
;
5385 tree type
= groktypename (t1
, NULL
, NULL
);
5387 if (type
== error_mark_node
)
5388 offsetof_ref
= error_mark_node
;
5390 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5391 /* Parse the second argument to __builtin_offsetof. We
5392 must have one identifier, and beyond that we want to
5393 accept sub structure and sub array references. */
5394 if (c_parser_next_token_is (parser
, CPP_NAME
))
5396 offsetof_ref
= build_component_ref
5397 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5398 c_parser_consume_token (parser
);
5399 while (c_parser_next_token_is (parser
, CPP_DOT
)
5400 || c_parser_next_token_is (parser
,
5402 || c_parser_next_token_is (parser
,
5405 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5407 loc
= c_parser_peek_token (parser
)->location
;
5408 offsetof_ref
= build_array_ref (offsetof_ref
,
5413 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5416 c_parser_consume_token (parser
);
5417 if (c_parser_next_token_is_not (parser
,
5420 c_parser_error (parser
, "expected identifier");
5423 offsetof_ref
= build_component_ref
5425 c_parser_peek_token (parser
)->value
);
5426 c_parser_consume_token (parser
);
5431 loc
= c_parser_peek_token (parser
)->location
;
5432 c_parser_consume_token (parser
);
5433 idx
= c_parser_expression (parser
).value
;
5434 idx
= c_fully_fold (idx
, false, NULL
);
5435 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5437 offsetof_ref
= build_array_ref (offsetof_ref
, idx
, loc
);
5442 c_parser_error (parser
, "expected identifier");
5443 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5445 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5448 case RID_CHOOSE_EXPR
:
5449 c_parser_consume_token (parser
);
5450 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5452 expr
.value
= error_mark_node
;
5455 loc
= c_parser_peek_token (parser
)->location
;
5456 e1
= c_parser_expr_no_commas (parser
, NULL
);
5457 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5459 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5460 expr
.value
= error_mark_node
;
5463 e2
= c_parser_expr_no_commas (parser
, NULL
);
5464 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5466 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5467 expr
.value
= error_mark_node
;
5470 e3
= c_parser_expr_no_commas (parser
, NULL
);
5471 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5477 if (TREE_CODE (c
) != INTEGER_CST
5478 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5480 "first argument to %<__builtin_choose_expr%> not"
5482 constant_expression_warning (c
);
5483 expr
= integer_zerop (c
) ? e3
: e2
;
5486 case RID_TYPES_COMPATIBLE_P
:
5487 c_parser_consume_token (parser
);
5488 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5490 expr
.value
= error_mark_node
;
5493 t1
= c_parser_type_name (parser
);
5496 expr
.value
= error_mark_node
;
5499 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5501 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5502 expr
.value
= error_mark_node
;
5505 t2
= c_parser_type_name (parser
);
5508 expr
.value
= error_mark_node
;
5511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5516 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5517 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5519 expr
.value
= comptypes (e1
, e2
)
5520 ? build_int_cst (NULL_TREE
, 1)
5521 : build_int_cst (NULL_TREE
, 0);
5524 case RID_AT_SELECTOR
:
5525 gcc_assert (c_dialect_objc ());
5526 c_parser_consume_token (parser
);
5527 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5529 expr
.value
= error_mark_node
;
5533 tree sel
= c_parser_objc_selector_arg (parser
);
5534 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5536 expr
.value
= objc_build_selector_expr (sel
);
5539 case RID_AT_PROTOCOL
:
5540 gcc_assert (c_dialect_objc ());
5541 c_parser_consume_token (parser
);
5542 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5544 expr
.value
= error_mark_node
;
5547 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5549 c_parser_error (parser
, "expected identifier");
5550 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5551 expr
.value
= error_mark_node
;
5555 tree id
= c_parser_peek_token (parser
)->value
;
5556 c_parser_consume_token (parser
);
5557 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5559 expr
.value
= objc_build_protocol_expr (id
);
5563 /* Extension to support C-structures in the archiver. */
5564 gcc_assert (c_dialect_objc ());
5565 c_parser_consume_token (parser
);
5566 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5568 expr
.value
= error_mark_node
;
5571 t1
= c_parser_type_name (parser
);
5574 expr
.value
= error_mark_node
;
5575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5581 tree type
= groktypename (t1
, NULL
, NULL
);
5582 expr
.value
= objc_build_encode_expr (type
);
5586 c_parser_error (parser
, "expected expression");
5587 expr
.value
= error_mark_node
;
5591 case CPP_OPEN_SQUARE
:
5592 if (c_dialect_objc ())
5594 tree receiver
, args
;
5595 c_parser_consume_token (parser
);
5596 receiver
= c_parser_objc_receiver (parser
);
5597 args
= c_parser_objc_message_args (parser
);
5598 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5600 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5604 /* Else fall through to report error. */
5606 c_parser_error (parser
, "expected expression");
5607 expr
.value
= error_mark_node
;
5610 return c_parser_postfix_expression_after_primary (parser
, expr
);
5613 /* Parse a postfix expression after a parenthesized type name: the
5614 brace-enclosed initializer of a compound literal, possibly followed
5615 by some postfix operators. This is separate because it is not
5616 possible to tell until after the type name whether a cast
5617 expression has a cast or a compound literal, or whether the operand
5618 of sizeof is a parenthesized type name or starts with a compound
5619 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5620 location of the first token after the parentheses around the type
5623 static struct c_expr
5624 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5625 struct c_type_name
*type_name
,
5626 location_t type_loc
)
5632 location_t start_loc
;
5633 tree type_expr
= NULL_TREE
;
5634 bool type_expr_const
= true;
5635 check_compound_literal_type (type_name
, type_loc
);
5636 start_init (NULL_TREE
, NULL
, 0);
5637 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5638 start_loc
= c_parser_peek_token (parser
)->location
;
5639 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5641 error_at (type_loc
, "compound literal has variable size");
5642 type
= error_mark_node
;
5644 init
= c_parser_braced_init (parser
, type
, false);
5646 maybe_warn_string_init (type
, init
);
5649 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5650 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5651 ? CONSTRUCTOR_NON_CONST (init
.value
)
5652 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5653 non_const
|= !type_expr_const
;
5654 expr
.value
= build_compound_literal (type
, init
.value
, non_const
);
5655 expr
.original_code
= ERROR_MARK
;
5656 expr
.original_type
= NULL
;
5659 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5661 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5662 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5666 gcc_assert (!non_const
);
5667 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5668 type_expr
, expr
.value
);
5671 return c_parser_postfix_expression_after_primary (parser
, expr
);
5674 /* Parse a postfix expression after the initial primary or compound
5675 literal; that is, parse a series of postfix operators. */
5677 static struct c_expr
5678 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5681 struct c_expr orig_expr
;
5683 VEC(tree
,gc
) *exprlist
;
5684 VEC(tree
,gc
) *origtypes
;
5685 location_t loc
= c_parser_peek_token (parser
)->location
;
5688 switch (c_parser_peek_token (parser
)->type
)
5690 case CPP_OPEN_SQUARE
:
5691 /* Array reference. */
5692 loc
= c_parser_peek_token (parser
)->location
;
5693 c_parser_consume_token (parser
);
5694 idx
= c_parser_expression (parser
).value
;
5695 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5697 expr
.value
= build_array_ref (expr
.value
, idx
, loc
);
5698 expr
.original_code
= ERROR_MARK
;
5699 expr
.original_type
= NULL
;
5701 case CPP_OPEN_PAREN
:
5702 /* Function call. */
5703 c_parser_consume_token (parser
);
5704 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5707 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5711 expr
.value
= build_function_call_vec (expr
.value
, exprlist
,
5713 expr
.original_code
= ERROR_MARK
;
5714 if (TREE_CODE (expr
.value
) == INTEGER_CST
5715 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5716 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5717 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5718 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5719 expr
.original_type
= NULL
;
5720 if (exprlist
!= NULL
)
5722 c_parser_release_expr_list (exprlist
);
5723 c_parser_release_expr_list (origtypes
);
5727 /* Structure element reference. */
5728 c_parser_consume_token (parser
);
5729 expr
= default_function_array_conversion (expr
);
5730 if (c_parser_next_token_is (parser
, CPP_NAME
))
5731 ident
= c_parser_peek_token (parser
)->value
;
5734 c_parser_error (parser
, "expected identifier");
5735 expr
.value
= error_mark_node
;
5736 expr
.original_code
= ERROR_MARK
;
5737 expr
.original_type
= NULL
;
5740 c_parser_consume_token (parser
);
5741 expr
.value
= build_component_ref (expr
.value
, ident
);
5742 expr
.original_code
= ERROR_MARK
;
5743 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5744 expr
.original_type
= NULL
;
5747 /* Remember the original type of a bitfield. */
5748 tree field
= TREE_OPERAND (expr
.value
, 1);
5749 if (TREE_CODE (field
) != FIELD_DECL
)
5750 expr
.original_type
= NULL
;
5752 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5756 /* Structure element reference. */
5757 c_parser_consume_token (parser
);
5758 expr
= default_function_array_conversion (expr
);
5759 if (c_parser_next_token_is (parser
, CPP_NAME
))
5760 ident
= c_parser_peek_token (parser
)->value
;
5763 c_parser_error (parser
, "expected identifier");
5764 expr
.value
= error_mark_node
;
5765 expr
.original_code
= ERROR_MARK
;
5766 expr
.original_type
= NULL
;
5769 c_parser_consume_token (parser
);
5770 expr
.value
= build_component_ref (build_indirect_ref (loc
,
5774 expr
.original_code
= ERROR_MARK
;
5775 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5776 expr
.original_type
= NULL
;
5779 /* Remember the original type of a bitfield. */
5780 tree field
= TREE_OPERAND (expr
.value
, 1);
5781 if (TREE_CODE (field
) != FIELD_DECL
)
5782 expr
.original_type
= NULL
;
5784 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5788 /* Postincrement. */
5789 c_parser_consume_token (parser
);
5790 expr
= default_function_array_conversion (expr
);
5791 expr
.value
= build_unary_op (loc
,
5792 POSTINCREMENT_EXPR
, expr
.value
, 0);
5793 expr
.original_code
= ERROR_MARK
;
5794 expr
.original_type
= NULL
;
5796 case CPP_MINUS_MINUS
:
5797 /* Postdecrement. */
5798 c_parser_consume_token (parser
);
5799 expr
= default_function_array_conversion (expr
);
5800 expr
.value
= build_unary_op (loc
,
5801 POSTDECREMENT_EXPR
, expr
.value
, 0);
5802 expr
.original_code
= ERROR_MARK
;
5803 expr
.original_type
= NULL
;
5811 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5814 assignment-expression
5815 expression , assignment-expression
5818 static struct c_expr
5819 c_parser_expression (c_parser
*parser
)
5822 expr
= c_parser_expr_no_commas (parser
, NULL
);
5823 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5826 c_parser_consume_token (parser
);
5827 next
= c_parser_expr_no_commas (parser
, NULL
);
5828 next
= default_function_array_conversion (next
);
5829 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5830 expr
.original_code
= COMPOUND_EXPR
;
5831 expr
.original_type
= next
.original_type
;
5836 /* Parse an expression and convert functions or arrays to
5839 static struct c_expr
5840 c_parser_expression_conv (c_parser
*parser
)
5843 expr
= c_parser_expression (parser
);
5844 expr
= default_function_array_conversion (expr
);
5848 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5849 functions and arrays to pointers. If FOLD_P, fold the expressions.
5852 assignment-expression
5853 nonempty-expr-list , assignment-expression
5856 /* We cache two vectors, to save most allocation and deallocation. */
5857 static GTY((deletable
)) VEC(tree
,gc
) *cached_expr_list_1
;
5858 static GTY((deletable
)) VEC(tree
,gc
) *cached_expr_list_2
;
5860 static VEC(tree
,gc
) *
5861 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5862 VEC(tree
,gc
) **p_orig_types
)
5865 VEC(tree
,gc
) *orig_types
;
5868 if (cached_expr_list_1
!= NULL
)
5870 ret
= cached_expr_list_1
;
5871 cached_expr_list_1
= NULL
;
5872 VEC_truncate (tree
, ret
, 0);
5874 else if (cached_expr_list_2
!= NULL
)
5876 ret
= cached_expr_list_2
;
5877 cached_expr_list_2
= NULL
;
5878 VEC_truncate (tree
, ret
, 0);
5881 ret
= VEC_alloc (tree
, gc
, 16);
5883 if (p_orig_types
== NULL
)
5887 if (cached_expr_list_2
!= NULL
)
5889 orig_types
= cached_expr_list_2
;
5890 cached_expr_list_2
= NULL
;
5891 VEC_truncate (tree
, orig_types
, 0);
5894 orig_types
= VEC_alloc (tree
, gc
, 16);
5897 expr
= c_parser_expr_no_commas (parser
, NULL
);
5899 expr
= default_function_array_conversion (expr
);
5901 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5902 VEC_quick_push (tree
, ret
, expr
.value
);
5903 if (orig_types
!= NULL
)
5904 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
5905 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5907 c_parser_consume_token (parser
);
5908 expr
= c_parser_expr_no_commas (parser
, NULL
);
5910 expr
= default_function_array_conversion (expr
);
5912 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5913 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
5914 if (orig_types
!= NULL
)
5915 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
5917 if (orig_types
!= NULL
)
5918 *p_orig_types
= orig_types
;
5922 /* Release a vector returned by c_parser_expr_list. */
5925 c_parser_release_expr_list (VEC(tree
,gc
) *vec
)
5927 if (cached_expr_list_1
== NULL
)
5928 cached_expr_list_1
= vec
;
5929 else if (cached_expr_list_2
== NULL
)
5930 cached_expr_list_2
= vec
;
5932 VEC_free (tree
, gc
, vec
);
5935 /* Convert a vector, as returned by c_parser_expr_list, to a
5939 c_parser_vec_to_tree_list (VEC(tree
,gc
) *vec
)
5941 tree ret
= NULL_TREE
;
5945 for (i
= 0; VEC_iterate (tree
, vec
, i
, t
); ++i
)
5947 *pp
= build_tree_list (NULL
, t
);
5948 pp
= &TREE_CHAIN (*pp
);
5953 /* Parse Objective-C-specific constructs. */
5955 /* Parse an objc-class-definition.
5957 objc-class-definition:
5958 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5959 objc-class-instance-variables[opt] objc-methodprotolist @end
5960 @implementation identifier objc-superclass[opt]
5961 objc-class-instance-variables[opt]
5962 @interface identifier ( identifier ) objc-protocol-refs[opt]
5963 objc-methodprotolist @end
5964 @implementation identifier ( identifier )
5969 "@interface identifier (" must start "@interface identifier (
5970 identifier ) ...": objc-methodprotolist in the first production may
5971 not start with a parenthesized identifier as a declarator of a data
5972 definition with no declaration specifiers if the objc-superclass,
5973 objc-protocol-refs and objc-class-instance-variables are omitted. */
5976 c_parser_objc_class_definition (c_parser
*parser
)
5981 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5983 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5987 c_parser_consume_token (parser
);
5988 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5990 c_parser_error (parser
, "expected identifier");
5993 id1
= c_parser_peek_token (parser
)->value
;
5994 c_parser_consume_token (parser
);
5995 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5998 tree proto
= NULL_TREE
;
5999 c_parser_consume_token (parser
);
6000 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6002 c_parser_error (parser
, "expected identifier");
6003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6006 id2
= c_parser_peek_token (parser
)->value
;
6007 c_parser_consume_token (parser
);
6008 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6011 objc_start_category_implementation (id1
, id2
);
6014 if (c_parser_next_token_is (parser
, CPP_LESS
))
6015 proto
= c_parser_objc_protocol_refs (parser
);
6016 objc_start_category_interface (id1
, id2
, proto
);
6017 c_parser_objc_methodprotolist (parser
);
6018 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6019 objc_finish_interface ();
6022 if (c_parser_next_token_is (parser
, CPP_COLON
))
6024 c_parser_consume_token (parser
);
6025 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6027 c_parser_error (parser
, "expected identifier");
6030 superclass
= c_parser_peek_token (parser
)->value
;
6031 c_parser_consume_token (parser
);
6034 superclass
= NULL_TREE
;
6037 tree proto
= NULL_TREE
;
6038 if (c_parser_next_token_is (parser
, CPP_LESS
))
6039 proto
= c_parser_objc_protocol_refs (parser
);
6040 objc_start_class_interface (id1
, superclass
, proto
);
6043 objc_start_class_implementation (id1
, superclass
);
6044 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6045 c_parser_objc_class_instance_variables (parser
);
6048 objc_continue_interface ();
6049 c_parser_objc_methodprotolist (parser
);
6050 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6051 objc_finish_interface ();
6055 objc_continue_implementation ();
6060 /* Parse objc-class-instance-variables.
6062 objc-class-instance-variables:
6063 { objc-instance-variable-decl-list[opt] }
6065 objc-instance-variable-decl-list:
6066 objc-visibility-spec
6067 objc-instance-variable-decl ;
6069 objc-instance-variable-decl-list objc-visibility-spec
6070 objc-instance-variable-decl-list objc-instance-variable-decl ;
6071 objc-instance-variable-decl-list ;
6073 objc-visibility-spec:
6078 objc-instance-variable-decl:
6083 c_parser_objc_class_instance_variables (c_parser
*parser
)
6085 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6086 c_parser_consume_token (parser
);
6087 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6090 /* Parse any stray semicolon. */
6091 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6093 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6094 "extra semicolon in struct or union specified");
6095 c_parser_consume_token (parser
);
6098 /* Stop if at the end of the instance variables. */
6099 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6101 c_parser_consume_token (parser
);
6104 /* Parse any objc-visibility-spec. */
6105 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6107 c_parser_consume_token (parser
);
6108 objc_set_visibility (2);
6111 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6113 c_parser_consume_token (parser
);
6114 objc_set_visibility (0);
6117 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6119 c_parser_consume_token (parser
);
6120 objc_set_visibility (1);
6123 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6125 c_parser_pragma (parser
, pragma_external
);
6129 /* Parse some comma-separated declarations. */
6130 decls
= c_parser_struct_declaration (parser
);
6132 /* Comma-separated instance variables are chained together in
6133 reverse order; add them one by one. */
6134 tree ivar
= nreverse (decls
);
6135 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6136 objc_add_instance_variable (copy_node (ivar
));
6138 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6142 /* Parse an objc-class-declaration.
6144 objc-class-declaration:
6145 @class identifier-list ;
6149 c_parser_objc_class_declaration (c_parser
*parser
)
6151 tree list
= NULL_TREE
;
6152 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6153 c_parser_consume_token (parser
);
6154 /* Any identifiers, including those declared as type names, are OK
6159 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6161 c_parser_error (parser
, "expected identifier");
6164 id
= c_parser_peek_token (parser
)->value
;
6165 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6166 c_parser_consume_token (parser
);
6167 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6168 c_parser_consume_token (parser
);
6172 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6173 objc_declare_class (list
);
6176 /* Parse an objc-alias-declaration.
6178 objc-alias-declaration:
6179 @compatibility_alias identifier identifier ;
6183 c_parser_objc_alias_declaration (c_parser
*parser
)
6186 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6187 c_parser_consume_token (parser
);
6188 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6190 c_parser_error (parser
, "expected identifier");
6191 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6194 id1
= c_parser_peek_token (parser
)->value
;
6195 c_parser_consume_token (parser
);
6196 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6198 c_parser_error (parser
, "expected identifier");
6199 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6202 id2
= c_parser_peek_token (parser
)->value
;
6203 c_parser_consume_token (parser
);
6204 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6205 objc_declare_alias (id1
, id2
);
6208 /* Parse an objc-protocol-definition.
6210 objc-protocol-definition:
6211 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6212 @protocol identifier-list ;
6214 "@protocol identifier ;" should be resolved as "@protocol
6215 identifier-list ;": objc-methodprotolist may not start with a
6216 semicolon in the first alternative if objc-protocol-refs are
6220 c_parser_objc_protocol_definition (c_parser
*parser
)
6222 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6223 c_parser_consume_token (parser
);
6224 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6226 c_parser_error (parser
, "expected identifier");
6229 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6230 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6232 tree list
= NULL_TREE
;
6233 /* Any identifiers, including those declared as type names, are
6238 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6240 c_parser_error (parser
, "expected identifier");
6243 id
= c_parser_peek_token (parser
)->value
;
6244 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6245 c_parser_consume_token (parser
);
6246 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6247 c_parser_consume_token (parser
);
6251 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6252 objc_declare_protocols (list
);
6256 tree id
= c_parser_peek_token (parser
)->value
;
6257 tree proto
= NULL_TREE
;
6258 c_parser_consume_token (parser
);
6259 if (c_parser_next_token_is (parser
, CPP_LESS
))
6260 proto
= c_parser_objc_protocol_refs (parser
);
6261 parser
->objc_pq_context
= true;
6262 objc_start_protocol (id
, proto
);
6263 c_parser_objc_methodprotolist (parser
);
6264 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6265 parser
->objc_pq_context
= false;
6266 objc_finish_interface ();
6270 /* Parse an objc-method-type.
6277 static enum tree_code
6278 c_parser_objc_method_type (c_parser
*parser
)
6280 switch (c_parser_peek_token (parser
)->type
)
6283 c_parser_consume_token (parser
);
6286 c_parser_consume_token (parser
);
6293 /* Parse an objc-method-definition.
6295 objc-method-definition:
6296 objc-method-type objc-method-decl ;[opt] compound-statement
6300 c_parser_objc_method_definition (c_parser
*parser
)
6302 enum tree_code type
= c_parser_objc_method_type (parser
);
6304 objc_set_method_type (type
);
6305 parser
->objc_pq_context
= true;
6306 decl
= c_parser_objc_method_decl (parser
);
6307 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6309 c_parser_consume_token (parser
);
6310 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6311 "extra semicolon in method definition specified");
6313 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6315 c_parser_error (parser
, "expected %<{%>");
6318 parser
->objc_pq_context
= false;
6319 objc_start_method_definition (decl
);
6320 add_stmt (c_parser_compound_statement (parser
));
6321 objc_finish_method_definition (current_function_decl
);
6324 /* Parse an objc-methodprotolist.
6326 objc-methodprotolist:
6328 objc-methodprotolist objc-methodproto
6329 objc-methodprotolist declaration
6330 objc-methodprotolist ;
6332 The declaration is a data definition, which may be missing
6333 declaration specifiers under the same rules and diagnostics as
6334 other data definitions outside functions, and the stray semicolon
6335 is diagnosed the same way as a stray semicolon outside a
6339 c_parser_objc_methodprotolist (c_parser
*parser
)
6343 /* The list is terminated by @end. */
6344 switch (c_parser_peek_token (parser
)->type
)
6347 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6348 "ISO C does not allow extra %<;%> outside of a function");
6349 c_parser_consume_token (parser
);
6353 c_parser_objc_methodproto (parser
);
6356 c_parser_pragma (parser
, pragma_external
);
6361 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6363 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6369 /* Parse an objc-methodproto.
6372 objc-method-type objc-method-decl ;
6376 c_parser_objc_methodproto (c_parser
*parser
)
6378 enum tree_code type
= c_parser_objc_method_type (parser
);
6380 objc_set_method_type (type
);
6381 /* Remember protocol qualifiers in prototypes. */
6382 parser
->objc_pq_context
= true;
6383 decl
= c_parser_objc_method_decl (parser
);
6384 /* Forget protocol qualifiers here. */
6385 parser
->objc_pq_context
= false;
6386 objc_add_method_declaration (decl
);
6387 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6390 /* Parse an objc-method-decl.
6393 ( objc-type-name ) objc-selector
6395 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6396 objc-keyword-selector objc-optparmlist
6398 objc-keyword-selector:
6400 objc-keyword-selector objc-keyword-decl
6403 objc-selector : ( objc-type-name ) identifier
6404 objc-selector : identifier
6405 : ( objc-type-name ) identifier
6409 objc-optparms objc-optellipsis
6413 objc-opt-parms , parameter-declaration
6421 c_parser_objc_method_decl (c_parser
*parser
)
6423 tree type
= NULL_TREE
;
6425 tree parms
= NULL_TREE
;
6426 bool ellipsis
= false;
6428 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6430 c_parser_consume_token (parser
);
6431 type
= c_parser_objc_type_name (parser
);
6432 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6434 sel
= c_parser_objc_selector (parser
);
6435 /* If there is no selector, or a colon follows, we have an
6436 objc-keyword-selector. If there is a selector, and a colon does
6437 not follow, that selector ends the objc-method-decl. */
6438 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6441 tree list
= NULL_TREE
;
6444 tree atype
= NULL_TREE
, id
, keyworddecl
;
6445 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6447 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6449 c_parser_consume_token (parser
);
6450 atype
= c_parser_objc_type_name (parser
);
6451 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6454 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6456 c_parser_error (parser
, "expected identifier");
6457 return error_mark_node
;
6459 id
= c_parser_peek_token (parser
)->value
;
6460 c_parser_consume_token (parser
);
6461 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6462 list
= chainon (list
, keyworddecl
);
6463 tsel
= c_parser_objc_selector (parser
);
6464 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6467 /* Parse the optional parameter list. Optional Objective-C
6468 method parameters follow the C syntax, and may include '...'
6469 to denote a variable number of arguments. */
6470 parms
= make_node (TREE_LIST
);
6471 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6473 struct c_parm
*parm
;
6474 c_parser_consume_token (parser
);
6475 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6478 c_parser_consume_token (parser
);
6481 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6484 parms
= chainon (parms
,
6485 build_tree_list (NULL_TREE
, grokparm (parm
)));
6489 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6492 /* Parse an objc-type-name.
6495 objc-type-qualifiers[opt] type-name
6496 objc-type-qualifiers[opt]
6498 objc-type-qualifiers:
6500 objc-type-qualifiers objc-type-qualifier
6502 objc-type-qualifier: one of
6503 in out inout bycopy byref oneway
6507 c_parser_objc_type_name (c_parser
*parser
)
6509 tree quals
= NULL_TREE
;
6510 struct c_type_name
*type_name
= NULL
;
6511 tree type
= NULL_TREE
;
6514 c_token
*token
= c_parser_peek_token (parser
);
6515 if (token
->type
== CPP_KEYWORD
6516 && (token
->keyword
== RID_IN
6517 || token
->keyword
== RID_OUT
6518 || token
->keyword
== RID_INOUT
6519 || token
->keyword
== RID_BYCOPY
6520 || token
->keyword
== RID_BYREF
6521 || token
->keyword
== RID_ONEWAY
))
6523 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6524 c_parser_consume_token (parser
);
6529 if (c_parser_next_token_starts_typename (parser
))
6530 type_name
= c_parser_type_name (parser
);
6532 type
= groktypename (type_name
, NULL
, NULL
);
6533 return build_tree_list (quals
, type
);
6536 /* Parse objc-protocol-refs.
6543 c_parser_objc_protocol_refs (c_parser
*parser
)
6545 tree list
= NULL_TREE
;
6546 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6547 c_parser_consume_token (parser
);
6548 /* Any identifiers, including those declared as type names, are OK
6553 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6555 c_parser_error (parser
, "expected identifier");
6558 id
= c_parser_peek_token (parser
)->value
;
6559 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6560 c_parser_consume_token (parser
);
6561 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6562 c_parser_consume_token (parser
);
6566 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6570 /* Parse an objc-try-catch-statement.
6572 objc-try-catch-statement:
6573 @try compound-statement objc-catch-list[opt]
6574 @try compound-statement objc-catch-list[opt] @finally compound-statement
6577 @catch ( parameter-declaration ) compound-statement
6578 objc-catch-list @catch ( parameter-declaration ) compound-statement
6582 c_parser_objc_try_catch_statement (c_parser
*parser
)
6586 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6587 c_parser_consume_token (parser
);
6588 loc
= c_parser_peek_token (parser
)->location
;
6589 stmt
= c_parser_compound_statement (parser
);
6590 objc_begin_try_stmt (loc
, stmt
);
6591 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6593 struct c_parm
*parm
;
6594 c_parser_consume_token (parser
);
6595 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6597 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6600 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6603 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6604 objc_begin_catch_clause (grokparm (parm
));
6605 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6606 c_parser_compound_statement_nostart (parser
);
6607 objc_finish_catch_clause ();
6609 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6613 c_parser_consume_token (parser
);
6614 finloc
= c_parser_peek_token (parser
)->location
;
6615 finstmt
= c_parser_compound_statement (parser
);
6616 objc_build_finally_clause (finloc
, finstmt
);
6618 objc_finish_try_stmt ();
6621 /* Parse an objc-synchronized-statement.
6623 objc-synchronized-statement:
6624 @synchronized ( expression ) compound-statement
6628 c_parser_objc_synchronized_statement (c_parser
*parser
)
6632 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6633 c_parser_consume_token (parser
);
6634 loc
= c_parser_peek_token (parser
)->location
;
6635 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6637 expr
= c_parser_expression (parser
).value
;
6638 expr
= c_fully_fold (expr
, false, NULL
);
6639 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6642 expr
= error_mark_node
;
6643 stmt
= c_parser_compound_statement (parser
);
6644 objc_build_synchronized (loc
, expr
, stmt
);
6647 /* Parse an objc-selector; return NULL_TREE without an error if the
6648 next token is not an objc-selector.
6653 enum struct union if else while do for switch case default
6654 break continue return goto asm sizeof typeof __alignof
6655 unsigned long const short volatile signed restrict _Complex
6656 in out inout bycopy byref oneway int char float double void _Bool
6658 ??? Why this selection of keywords but not, for example, storage
6659 class specifiers? */
6662 c_parser_objc_selector (c_parser
*parser
)
6664 c_token
*token
= c_parser_peek_token (parser
);
6665 tree value
= token
->value
;
6666 if (token
->type
== CPP_NAME
)
6668 c_parser_consume_token (parser
);
6671 if (token
->type
!= CPP_KEYWORD
)
6673 switch (token
->keyword
)
6714 c_parser_consume_token (parser
);
6721 /* Parse an objc-selector-arg.
6725 objc-keywordname-list
6727 objc-keywordname-list:
6729 objc-keywordname-list objc-keywordname
6737 c_parser_objc_selector_arg (c_parser
*parser
)
6739 tree sel
= c_parser_objc_selector (parser
);
6740 tree list
= NULL_TREE
;
6741 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6745 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6747 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6748 sel
= c_parser_objc_selector (parser
);
6749 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6755 /* Parse an objc-receiver.
6764 c_parser_objc_receiver (c_parser
*parser
)
6766 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6767 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6768 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6770 tree id
= c_parser_peek_token (parser
)->value
;
6771 c_parser_consume_token (parser
);
6772 return objc_get_class_reference (id
);
6774 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6777 /* Parse objc-message-args.
6781 objc-keywordarg-list
6783 objc-keywordarg-list:
6785 objc-keywordarg-list objc-keywordarg
6788 objc-selector : objc-keywordexpr
6793 c_parser_objc_message_args (c_parser
*parser
)
6795 tree sel
= c_parser_objc_selector (parser
);
6796 tree list
= NULL_TREE
;
6797 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6802 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6804 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6805 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6806 sel
= c_parser_objc_selector (parser
);
6807 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6813 /* Parse an objc-keywordexpr.
6820 c_parser_objc_keywordexpr (c_parser
*parser
)
6823 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6824 if (VEC_length (tree
, expr_list
) == 1)
6826 /* Just return the expression, remove a level of
6828 ret
= VEC_index (tree
, expr_list
, 0);
6832 /* We have a comma expression, we will collapse later. */
6833 ret
= c_parser_vec_to_tree_list (expr_list
);
6835 c_parser_release_expr_list (expr_list
);
6840 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6841 should be considered, statements. ALLOW_STMT is true if we're within
6842 the context of a function and such pragmas are to be allowed. Returns
6843 true if we actually parsed such a pragma. */
6846 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6850 id
= c_parser_peek_token (parser
)->pragma_kind
;
6851 gcc_assert (id
!= PRAGMA_NONE
);
6855 case PRAGMA_OMP_BARRIER
:
6856 if (context
!= pragma_compound
)
6858 if (context
== pragma_stmt
)
6859 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6860 "used in compound statements");
6863 c_parser_omp_barrier (parser
);
6866 case PRAGMA_OMP_FLUSH
:
6867 if (context
!= pragma_compound
)
6869 if (context
== pragma_stmt
)
6870 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6871 "used in compound statements");
6874 c_parser_omp_flush (parser
);
6877 case PRAGMA_OMP_TASKWAIT
:
6878 if (context
!= pragma_compound
)
6880 if (context
== pragma_stmt
)
6881 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6882 "used in compound statements");
6885 c_parser_omp_taskwait (parser
);
6888 case PRAGMA_OMP_THREADPRIVATE
:
6889 c_parser_omp_threadprivate (parser
);
6892 case PRAGMA_OMP_SECTION
:
6893 error_at (c_parser_peek_token (parser
)->location
,
6894 "%<#pragma omp section%> may only be used in "
6895 "%<#pragma omp sections%> construct");
6896 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6899 case PRAGMA_GCC_PCH_PREPROCESS
:
6900 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6901 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6905 if (id
< PRAGMA_FIRST_EXTERNAL
)
6907 if (context
== pragma_external
)
6910 c_parser_error (parser
, "expected declaration specifiers");
6911 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6914 c_parser_omp_construct (parser
);
6920 c_parser_consume_pragma (parser
);
6921 c_invoke_pragma_handler (id
);
6923 /* Skip to EOL, but suppress any error message. Those will have been
6924 generated by the handler routine through calling error, as opposed
6925 to calling c_parser_error. */
6926 parser
->error
= true;
6927 c_parser_skip_to_pragma_eol (parser
);
6932 /* The interface the pragma parsers have to the lexer. */
6935 pragma_lex (tree
*value
)
6937 c_token
*tok
= c_parser_peek_token (the_parser
);
6938 enum cpp_ttype ret
= tok
->type
;
6940 *value
= tok
->value
;
6941 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6945 if (ret
== CPP_KEYWORD
)
6947 c_parser_consume_token (the_parser
);
6954 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6958 c_parser_consume_pragma (parser
);
6959 if (c_parser_next_token_is (parser
, CPP_STRING
))
6961 name
= c_parser_peek_token (parser
)->value
;
6962 c_parser_consume_token (parser
);
6965 c_parser_error (parser
, "expected string literal");
6966 c_parser_skip_to_pragma_eol (parser
);
6969 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6972 /* OpenMP 2.5 parsing routines. */
6974 /* Returns name of the next clause.
6975 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6976 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6977 returned and the token is consumed. */
6979 static pragma_omp_clause
6980 c_parser_omp_clause_name (c_parser
*parser
)
6982 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6984 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6985 result
= PRAGMA_OMP_CLAUSE_IF
;
6986 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6987 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6988 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6990 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6995 if (!strcmp ("collapse", p
))
6996 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6997 else if (!strcmp ("copyin", p
))
6998 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6999 else if (!strcmp ("copyprivate", p
))
7000 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7003 if (!strcmp ("firstprivate", p
))
7004 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7007 if (!strcmp ("lastprivate", p
))
7008 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7011 if (!strcmp ("nowait", p
))
7012 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7013 else if (!strcmp ("num_threads", p
))
7014 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7017 if (!strcmp ("ordered", p
))
7018 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7021 if (!strcmp ("private", p
))
7022 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7025 if (!strcmp ("reduction", p
))
7026 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7029 if (!strcmp ("schedule", p
))
7030 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7031 else if (!strcmp ("shared", p
))
7032 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7035 if (!strcmp ("untied", p
))
7036 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7041 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7042 c_parser_consume_token (parser
);
7047 /* Validate that a clause of the given type does not already exist. */
7050 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7055 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7056 if (OMP_CLAUSE_CODE (c
) == code
)
7058 error ("too many %qs clauses", name
);
7066 variable-list , identifier
7068 If KIND is nonzero, create the appropriate node and install the decl
7069 in OMP_CLAUSE_DECL and add the node to the head of the list.
7071 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7072 return the list created. */
7075 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
7078 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7079 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7080 c_parser_error (parser
, "expected identifier");
7082 while (c_parser_next_token_is (parser
, CPP_NAME
)
7083 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7085 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7088 undeclared_variable (c_parser_peek_token (parser
)->value
,
7089 c_parser_peek_token (parser
)->location
);
7090 else if (t
== error_mark_node
)
7094 tree u
= build_omp_clause (kind
);
7095 OMP_CLAUSE_DECL (u
) = t
;
7096 OMP_CLAUSE_CHAIN (u
) = list
;
7100 list
= tree_cons (t
, NULL_TREE
, list
);
7102 c_parser_consume_token (parser
);
7104 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7107 c_parser_consume_token (parser
);
7113 /* Similarly, but expect leading and trailing parenthesis. This is a very
7114 common case for omp clauses. */
7117 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7120 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7122 list
= c_parser_omp_variable_list (parser
, kind
, list
);
7123 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7129 collapse ( constant-expression ) */
7132 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7134 tree c
, num
= error_mark_node
;
7138 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7140 loc
= c_parser_peek_token (parser
)->location
;
7141 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7143 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7146 if (num
== error_mark_node
)
7148 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7149 || !host_integerp (num
, 0)
7150 || (n
= tree_low_cst (num
, 0)) <= 0
7154 "collapse argument needs positive constant integer expression");
7157 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
7158 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7159 OMP_CLAUSE_CHAIN (c
) = list
;
7164 copyin ( variable-list ) */
7167 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7169 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7173 copyprivate ( variable-list ) */
7176 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7178 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7182 default ( shared | none ) */
7185 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7187 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7190 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7192 if (c_parser_next_token_is (parser
, CPP_NAME
))
7194 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7199 if (strcmp ("none", p
) != 0)
7201 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7205 if (strcmp ("shared", p
) != 0)
7207 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7214 c_parser_consume_token (parser
);
7219 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7223 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7226 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7227 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
7228 OMP_CLAUSE_CHAIN (c
) = list
;
7229 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7235 firstprivate ( variable-list ) */
7238 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7240 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7244 if ( expression ) */
7247 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7249 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7251 tree t
= c_parser_paren_condition (parser
);
7254 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7256 c
= build_omp_clause (OMP_CLAUSE_IF
);
7257 OMP_CLAUSE_IF_EXPR (c
) = t
;
7258 OMP_CLAUSE_CHAIN (c
) = list
;
7262 c_parser_error (parser
, "expected %<(%>");
7268 lastprivate ( variable-list ) */
7271 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7273 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7280 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7284 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7286 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
7287 OMP_CLAUSE_CHAIN (c
) = list
;
7292 num_threads ( expression ) */
7295 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7297 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7299 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7300 tree c
, t
= c_parser_expression (parser
).value
;
7301 t
= c_fully_fold (t
, false, NULL
);
7303 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7305 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7307 c_parser_error (parser
, "expected integer expression");
7311 /* Attempt to statically determine when the number isn't positive. */
7312 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7313 build_int_cst (TREE_TYPE (t
), 0));
7314 if (c
== boolean_true_node
)
7316 warning_at (expr_loc
, 0,
7317 "%<num_threads%> value must be positive");
7318 t
= integer_one_node
;
7321 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7323 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7324 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7325 OMP_CLAUSE_CHAIN (c
) = list
;
7336 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7340 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7342 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7343 OMP_CLAUSE_CHAIN (c
) = list
;
7348 private ( variable-list ) */
7351 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7353 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7357 reduction ( reduction-operator : variable-list )
7360 One of: + * - & ^ | && || */
7363 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7365 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7367 enum tree_code code
;
7369 switch (c_parser_peek_token (parser
)->type
)
7381 code
= BIT_AND_EXPR
;
7384 code
= BIT_XOR_EXPR
;
7387 code
= BIT_IOR_EXPR
;
7390 code
= TRUTH_ANDIF_EXPR
;
7393 code
= TRUTH_ORIF_EXPR
;
7396 c_parser_error (parser
,
7397 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7398 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7402 c_parser_consume_token (parser
);
7403 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7407 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7408 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7409 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7413 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7419 schedule ( schedule-kind )
7420 schedule ( schedule-kind , expression )
7423 static | dynamic | guided | runtime | auto
7427 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7431 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7434 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7436 if (c_parser_next_token_is (parser
, CPP_NAME
))
7438 tree kind
= c_parser_peek_token (parser
)->value
;
7439 const char *p
= IDENTIFIER_POINTER (kind
);
7444 if (strcmp ("dynamic", p
) != 0)
7446 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7450 if (strcmp ("guided", p
) != 0)
7452 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7456 if (strcmp ("runtime", p
) != 0)
7458 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7465 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7466 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7467 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7468 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7472 c_parser_consume_token (parser
);
7473 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7476 c_parser_consume_token (parser
);
7478 here
= c_parser_peek_token (parser
)->location
;
7479 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7480 t
= c_fully_fold (t
, false, NULL
);
7482 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7483 error_at (here
, "schedule %<runtime%> does not take "
7484 "a %<chunk_size%> parameter");
7485 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7487 "schedule %<auto%> does not take "
7488 "a %<chunk_size%> parameter");
7489 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7490 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7492 c_parser_error (parser
, "expected integer expression");
7494 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7498 "expected %<,%> or %<)%>");
7500 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7501 OMP_CLAUSE_CHAIN (c
) = list
;
7505 c_parser_error (parser
, "invalid schedule kind");
7506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7511 shared ( variable-list ) */
7514 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7516 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7523 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7527 /* FIXME: Should we allow duplicates? */
7528 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7530 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7531 OMP_CLAUSE_CHAIN (c
) = list
;
7535 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7536 is a bitmask in MASK. Return the list of clauses found; the result
7537 of clause default goes in *pdefault. */
7540 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7543 tree clauses
= NULL
;
7546 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7549 pragma_omp_clause c_kind
;
7551 tree prev
= clauses
;
7553 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7554 c_parser_consume_token (parser
);
7557 here
= c_parser_peek_token (parser
)->location
;
7558 c_kind
= c_parser_omp_clause_name (parser
);
7562 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7563 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7564 c_name
= "collapse";
7566 case PRAGMA_OMP_CLAUSE_COPYIN
:
7567 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7570 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7571 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7572 c_name
= "copyprivate";
7574 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7575 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7578 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7579 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7580 c_name
= "firstprivate";
7582 case PRAGMA_OMP_CLAUSE_IF
:
7583 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7586 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7587 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7588 c_name
= "lastprivate";
7590 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7591 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7594 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7595 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7596 c_name
= "num_threads";
7598 case PRAGMA_OMP_CLAUSE_ORDERED
:
7599 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7602 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7603 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7606 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7607 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7608 c_name
= "reduction";
7610 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7611 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7612 c_name
= "schedule";
7614 case PRAGMA_OMP_CLAUSE_SHARED
:
7615 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7618 case PRAGMA_OMP_CLAUSE_UNTIED
:
7619 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7623 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7627 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7629 /* Remove the invalid clause(s) from the list to avoid
7630 confusing the rest of the compiler. */
7632 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7637 c_parser_skip_to_pragma_eol (parser
);
7639 return c_finish_omp_clauses (clauses
);
7646 In practice, we're also interested in adding the statement to an
7647 outer node. So it is convenient if we work around the fact that
7648 c_parser_statement calls add_stmt. */
7651 c_parser_omp_structured_block (c_parser
*parser
)
7653 tree stmt
= push_stmt_list ();
7654 c_parser_statement (parser
);
7655 return pop_stmt_list (stmt
);
7659 # pragma omp atomic new-line
7663 x binop= expr | x++ | ++x | x-- | --x
7665 +, *, -, /, &, ^, |, <<, >>
7667 where x is an lvalue expression with scalar type. */
7670 c_parser_omp_atomic (c_parser
*parser
)
7674 enum tree_code code
;
7675 struct c_expr rhs_expr
;
7677 c_parser_skip_to_pragma_eol (parser
);
7679 lhs
= c_parser_unary_expression (parser
).value
;
7680 lhs
= c_fully_fold (lhs
, false, NULL
);
7681 switch (TREE_CODE (lhs
))
7685 c_parser_skip_to_end_of_block_or_statement (parser
);
7688 case PREINCREMENT_EXPR
:
7689 case POSTINCREMENT_EXPR
:
7690 lhs
= TREE_OPERAND (lhs
, 0);
7692 rhs
= integer_one_node
;
7695 case PREDECREMENT_EXPR
:
7696 case POSTDECREMENT_EXPR
:
7697 lhs
= TREE_OPERAND (lhs
, 0);
7699 rhs
= integer_one_node
;
7703 switch (c_parser_peek_token (parser
)->type
)
7709 code
= TRUNC_DIV_EXPR
;
7724 code
= BIT_AND_EXPR
;
7727 code
= BIT_IOR_EXPR
;
7730 code
= BIT_XOR_EXPR
;
7733 c_parser_error (parser
,
7734 "invalid operator for %<#pragma omp atomic%>");
7738 c_parser_consume_token (parser
);
7739 rhs_expr
= c_parser_expression (parser
);
7740 rhs_expr
= default_function_array_conversion (rhs_expr
);
7741 rhs
= rhs_expr
.value
;
7742 rhs
= c_fully_fold (rhs
, false, NULL
);
7745 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7746 if (stmt
!= error_mark_node
)
7748 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7753 # pragma omp barrier new-line
7757 c_parser_omp_barrier (c_parser
*parser
)
7759 c_parser_consume_pragma (parser
);
7760 c_parser_skip_to_pragma_eol (parser
);
7762 c_finish_omp_barrier ();
7766 # pragma omp critical [(name)] new-line
7771 c_parser_omp_critical (c_parser
*parser
)
7773 tree stmt
, name
= NULL
;
7775 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7777 c_parser_consume_token (parser
);
7778 if (c_parser_next_token_is (parser
, CPP_NAME
))
7780 name
= c_parser_peek_token (parser
)->value
;
7781 c_parser_consume_token (parser
);
7782 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7785 c_parser_error (parser
, "expected identifier");
7787 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7788 c_parser_error (parser
, "expected %<(%> or end of line");
7789 c_parser_skip_to_pragma_eol (parser
);
7791 stmt
= c_parser_omp_structured_block (parser
);
7792 return c_finish_omp_critical (stmt
, name
);
7796 # pragma omp flush flush-vars[opt] new-line
7799 ( variable-list ) */
7802 c_parser_omp_flush (c_parser
*parser
)
7804 c_parser_consume_pragma (parser
);
7805 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7806 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7807 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7808 c_parser_error (parser
, "expected %<(%> or end of line");
7809 c_parser_skip_to_pragma_eol (parser
);
7811 c_finish_omp_flush ();
7814 /* Parse the restricted form of the for statement allowed by OpenMP.
7815 The real trick here is to determine the loop control variable early
7816 so that we can push a new decl if necessary to make it private. */
7819 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7821 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7822 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7824 bool fail
= false, open_brace_parsed
= false;
7825 int i
, collapse
= 1, nbraces
= 0;
7827 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7828 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7829 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7831 gcc_assert (collapse
>= 1);
7833 declv
= make_tree_vec (collapse
);
7834 initv
= make_tree_vec (collapse
);
7835 condv
= make_tree_vec (collapse
);
7836 incrv
= make_tree_vec (collapse
);
7838 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7840 c_parser_error (parser
, "for statement expected");
7843 loc
= c_parser_peek_token (parser
)->location
;
7844 c_parser_consume_token (parser
);
7846 for (i
= 0; i
< collapse
; i
++)
7850 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7853 /* Parse the initialization declaration or expression. */
7854 if (c_parser_next_token_starts_declspecs (parser
))
7858 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7859 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7860 decl
= check_for_loop_decls ();
7863 if (DECL_INITIAL (decl
) == error_mark_node
)
7864 decl
= error_mark_node
;
7867 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7868 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7870 struct c_expr decl_exp
;
7871 struct c_expr init_exp
;
7872 location_t init_loc
;
7874 decl_exp
= c_parser_postfix_expression (parser
);
7875 decl
= decl_exp
.value
;
7877 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7878 init_loc
= c_parser_peek_token (parser
)->location
;
7880 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7881 init_exp
= default_function_array_conversion (init_exp
);
7882 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7883 NOP_EXPR
, init_exp
.value
,
7884 init_exp
.original_type
);
7885 init
= c_process_expr_stmt (init
);
7887 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7892 c_parser_error (parser
,
7893 "expected iteration declaration or initialization");
7894 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7900 /* Parse the loop condition. */
7902 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7904 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7905 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
7907 cond
= cond_expr
.value
;
7908 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7909 cond
= c_fully_fold (cond
, false, NULL
);
7910 switch (cond_expr
.original_code
)
7918 /* Can't be cond = error_mark_node, because we want to preserve
7919 the location until c_finish_omp_for. */
7920 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
7923 protected_set_expr_location (cond
, cond_loc
);
7925 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7927 /* Parse the increment expression. */
7929 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7931 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7933 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7934 protected_set_expr_location (incr
, incr_loc
);
7936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7938 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7942 TREE_VEC_ELT (declv
, i
) = decl
;
7943 TREE_VEC_ELT (initv
, i
) = init
;
7944 TREE_VEC_ELT (condv
, i
) = cond
;
7945 TREE_VEC_ELT (incrv
, i
) = incr
;
7949 if (i
== collapse
- 1)
7952 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7953 in between the collapsed for loops to be still considered perfectly
7954 nested. Hopefully the final version clarifies this.
7955 For now handle (multiple) {'s and empty statements. */
7958 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7960 c_parser_consume_token (parser
);
7963 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7965 c_parser_consume_token (parser
);
7969 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7970 c_parser_consume_token (parser
);
7973 c_parser_error (parser
, "not enough perfectly nested loops");
7976 open_brace_parsed
= true;
7986 nbraces
+= bracecount
;
7989 save_break
= c_break_label
;
7990 c_break_label
= size_one_node
;
7991 save_cont
= c_cont_label
;
7992 c_cont_label
= NULL_TREE
;
7993 body
= push_stmt_list ();
7995 if (open_brace_parsed
)
7997 stmt
= c_begin_compound_stmt (true);
7998 c_parser_compound_statement_nostart (parser
);
7999 add_stmt (c_end_compound_stmt (stmt
, true));
8002 add_stmt (c_parser_c99_block_statement (parser
));
8004 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
8006 body
= pop_stmt_list (body
);
8007 c_break_label
= save_break
;
8008 c_cont_label
= save_cont
;
8012 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8014 c_parser_consume_token (parser
);
8017 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8018 c_parser_consume_token (parser
);
8021 c_parser_error (parser
, "collapsed loops not perfectly nested");
8024 stmt
= c_begin_compound_stmt (true);
8026 c_parser_compound_statement_nostart (parser
);
8027 body
= c_end_compound_stmt (stmt
, true);
8034 /* Only bother calling c_finish_omp_for if we haven't already generated
8035 an error from the initialization parsing. */
8038 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8041 if (par_clauses
!= NULL
)
8044 for (c
= par_clauses
; *c
; )
8045 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8046 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8047 c
= &OMP_CLAUSE_CHAIN (*c
);
8050 for (i
= 0; i
< collapse
; i
++)
8051 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8054 c
= &OMP_CLAUSE_CHAIN (*c
);
8055 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8058 "iteration variable %qD should not be firstprivate",
8059 OMP_CLAUSE_DECL (*c
));
8060 *c
= OMP_CLAUSE_CHAIN (*c
);
8064 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8065 change it to shared (decl) in
8066 OMP_PARALLEL_CLAUSES. */
8067 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
8068 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8069 OMP_CLAUSE_CHAIN (l
) = clauses
;
8071 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8075 OMP_FOR_CLAUSES (stmt
) = clauses
;
8082 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
8084 for_block
= TREE_CHAIN (for_block
);
8090 #pragma omp for for-clause[optseq] new-line
8094 #define OMP_FOR_CLAUSE_MASK \
8095 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8096 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8097 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8098 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8099 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8100 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8101 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8102 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8105 c_parser_omp_for (c_parser
*parser
)
8107 tree block
, clauses
, ret
;
8109 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8112 block
= c_begin_compound_stmt (true);
8113 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
8114 block
= c_end_compound_stmt (block
, true);
8121 # pragma omp master new-line
8126 c_parser_omp_master (c_parser
*parser
)
8128 c_parser_skip_to_pragma_eol (parser
);
8129 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
8133 # pragma omp ordered new-line
8138 c_parser_omp_ordered (c_parser
*parser
)
8140 c_parser_skip_to_pragma_eol (parser
);
8141 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
8147 { section-sequence }
8150 section-directive[opt] structured-block
8151 section-sequence section-directive structured-block */
8154 c_parser_omp_sections_scope (c_parser
*parser
)
8157 bool error_suppress
= false;
8160 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8162 /* Avoid skipping until the end of the block. */
8163 parser
->error
= false;
8167 stmt
= push_stmt_list ();
8169 loc
= c_parser_peek_token (parser
)->location
;
8170 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8172 substmt
= push_stmt_list ();
8176 c_parser_statement (parser
);
8178 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8180 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8182 if (c_parser_next_token_is (parser
, CPP_EOF
))
8186 substmt
= pop_stmt_list (substmt
);
8187 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8188 SET_EXPR_LOCATION (substmt
, loc
);
8194 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8196 if (c_parser_next_token_is (parser
, CPP_EOF
))
8199 loc
= c_parser_peek_token (parser
)->location
;
8200 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8202 c_parser_consume_pragma (parser
);
8203 c_parser_skip_to_pragma_eol (parser
);
8204 error_suppress
= false;
8206 else if (!error_suppress
)
8208 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8209 error_suppress
= true;
8212 substmt
= c_parser_omp_structured_block (parser
);
8213 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8214 SET_EXPR_LOCATION (substmt
, loc
);
8217 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8218 "expected %<#pragma omp section%> or %<}%>");
8220 substmt
= pop_stmt_list (stmt
);
8222 stmt
= make_node (OMP_SECTIONS
);
8223 TREE_TYPE (stmt
) = void_type_node
;
8224 OMP_SECTIONS_BODY (stmt
) = substmt
;
8226 return add_stmt (stmt
);
8230 # pragma omp sections sections-clause[optseq] newline
8234 #define OMP_SECTIONS_CLAUSE_MASK \
8235 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8236 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8237 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8238 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8239 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8242 c_parser_omp_sections (c_parser
*parser
)
8244 tree block
, clauses
, ret
;
8246 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8247 "#pragma omp sections");
8249 block
= c_begin_compound_stmt (true);
8250 ret
= c_parser_omp_sections_scope (parser
);
8252 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8253 block
= c_end_compound_stmt (block
, true);
8260 # pragma parallel parallel-clause new-line
8261 # pragma parallel for parallel-for-clause new-line
8262 # pragma parallel sections parallel-sections-clause new-line
8265 #define OMP_PARALLEL_CLAUSE_MASK \
8266 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8267 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8268 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8269 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8270 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8271 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8272 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8273 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8276 c_parser_omp_parallel (c_parser
*parser
)
8278 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8279 const char *p_name
= "#pragma omp parallel";
8280 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8281 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8283 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8285 c_parser_consume_token (parser
);
8286 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8287 p_name
= "#pragma omp parallel for";
8288 mask
|= OMP_FOR_CLAUSE_MASK
;
8289 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8291 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8293 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8294 if (strcmp (p
, "sections") == 0)
8296 c_parser_consume_token (parser
);
8297 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8298 p_name
= "#pragma omp parallel sections";
8299 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8300 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8304 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8308 case PRAGMA_OMP_PARALLEL
:
8309 block
= c_begin_omp_parallel ();
8310 c_parser_statement (parser
);
8311 stmt
= c_finish_omp_parallel (clauses
, block
);
8314 case PRAGMA_OMP_PARALLEL_FOR
:
8315 block
= c_begin_omp_parallel ();
8316 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8317 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
8318 stmt
= c_finish_omp_parallel (par_clause
, block
);
8319 OMP_PARALLEL_COMBINED (stmt
) = 1;
8322 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8323 block
= c_begin_omp_parallel ();
8324 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8325 stmt
= c_parser_omp_sections_scope (parser
);
8327 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8328 stmt
= c_finish_omp_parallel (par_clause
, block
);
8329 OMP_PARALLEL_COMBINED (stmt
) = 1;
8340 # pragma omp single single-clause[optseq] new-line
8344 #define OMP_SINGLE_CLAUSE_MASK \
8345 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8346 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8347 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8348 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8351 c_parser_omp_single (c_parser
*parser
)
8353 tree stmt
= make_node (OMP_SINGLE
);
8354 TREE_TYPE (stmt
) = void_type_node
;
8356 OMP_SINGLE_CLAUSES (stmt
)
8357 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8358 "#pragma omp single");
8359 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8361 return add_stmt (stmt
);
8365 # pragma omp task task-clause[optseq] new-line
8368 #define OMP_TASK_CLAUSE_MASK \
8369 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8370 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8371 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8372 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8373 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8374 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8377 c_parser_omp_task (c_parser
*parser
)
8379 tree clauses
, block
;
8381 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8382 "#pragma omp task");
8384 block
= c_begin_omp_task ();
8385 c_parser_statement (parser
);
8386 return c_finish_omp_task (clauses
, block
);
8390 # pragma omp taskwait new-line
8394 c_parser_omp_taskwait (c_parser
*parser
)
8396 c_parser_consume_pragma (parser
);
8397 c_parser_skip_to_pragma_eol (parser
);
8399 c_finish_omp_taskwait ();
8402 /* Main entry point to parsing most OpenMP pragmas. */
8405 c_parser_omp_construct (c_parser
*parser
)
8407 enum pragma_kind p_kind
;
8411 loc
= c_parser_peek_token (parser
)->location
;
8412 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8413 c_parser_consume_pragma (parser
);
8415 /* For all constructs below except #pragma omp atomic
8416 MUST_NOT_THROW catch handlers are needed when exceptions
8418 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8419 c_maybe_initialize_eh ();
8423 case PRAGMA_OMP_ATOMIC
:
8424 c_parser_omp_atomic (parser
);
8426 case PRAGMA_OMP_CRITICAL
:
8427 stmt
= c_parser_omp_critical (parser
);
8429 case PRAGMA_OMP_FOR
:
8430 stmt
= c_parser_omp_for (parser
);
8432 case PRAGMA_OMP_MASTER
:
8433 stmt
= c_parser_omp_master (parser
);
8435 case PRAGMA_OMP_ORDERED
:
8436 stmt
= c_parser_omp_ordered (parser
);
8438 case PRAGMA_OMP_PARALLEL
:
8439 stmt
= c_parser_omp_parallel (parser
);
8441 case PRAGMA_OMP_SECTIONS
:
8442 stmt
= c_parser_omp_sections (parser
);
8444 case PRAGMA_OMP_SINGLE
:
8445 stmt
= c_parser_omp_single (parser
);
8447 case PRAGMA_OMP_TASK
:
8448 stmt
= c_parser_omp_task (parser
);
8455 SET_EXPR_LOCATION (stmt
, loc
);
8460 # pragma omp threadprivate (variable-list) */
8463 c_parser_omp_threadprivate (c_parser
*parser
)
8467 c_parser_consume_pragma (parser
);
8468 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8470 /* Mark every variable in VARS to be assigned thread local storage. */
8471 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8473 tree v
= TREE_PURPOSE (t
);
8475 /* If V had already been marked threadprivate, it doesn't matter
8476 whether it had been used prior to this point. */
8477 if (TREE_CODE (v
) != VAR_DECL
)
8478 error ("%qD is not a variable", v
);
8479 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8480 error ("%qE declared %<threadprivate%> after first use", v
);
8481 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8482 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8483 else if (TREE_TYPE (v
) == error_mark_node
)
8485 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8486 error ("%<threadprivate%> %qE has incomplete type", v
);
8489 if (! DECL_THREAD_LOCAL_P (v
))
8491 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8492 /* If rtl has been already set for this var, call
8493 make_decl_rtl once again, so that encode_section_info
8494 has a chance to look at the new decl flags. */
8495 if (DECL_RTL_SET_P (v
))
8498 C_DECL_THREADPRIVATE_P (v
) = 1;
8502 c_parser_skip_to_pragma_eol (parser
);
8506 /* Parse a single source file. */
8511 /* Use local storage to begin. If the first token is a pragma, parse it.
8512 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8513 which will cause garbage collection. */
8516 memset (&tparser
, 0, sizeof tparser
);
8517 the_parser
= &tparser
;
8519 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8520 c_parser_pragma_pch_preprocess (&tparser
);
8522 the_parser
= GGC_NEW (c_parser
);
8523 *the_parser
= tparser
;
8525 c_parser_translation_unit (the_parser
);
8529 #include "gt-c-parser.h"