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
*,
921 static struct c_expr
c_parser_expression (c_parser
*);
922 static struct c_expr
c_parser_expression_conv (c_parser
*);
923 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
925 static void c_parser_omp_construct (c_parser
*);
926 static void c_parser_omp_threadprivate (c_parser
*);
927 static void c_parser_omp_barrier (c_parser
*);
928 static void c_parser_omp_flush (c_parser
*);
929 static void c_parser_omp_taskwait (c_parser
*);
931 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
932 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
934 /* These Objective-C parser functions are only ever called when
935 compiling Objective-C. */
936 static void c_parser_objc_class_definition (c_parser
*);
937 static void c_parser_objc_class_instance_variables (c_parser
*);
938 static void c_parser_objc_class_declaration (c_parser
*);
939 static void c_parser_objc_alias_declaration (c_parser
*);
940 static void c_parser_objc_protocol_definition (c_parser
*);
941 static enum tree_code
c_parser_objc_method_type (c_parser
*);
942 static void c_parser_objc_method_definition (c_parser
*);
943 static void c_parser_objc_methodprotolist (c_parser
*);
944 static void c_parser_objc_methodproto (c_parser
*);
945 static tree
c_parser_objc_method_decl (c_parser
*);
946 static tree
c_parser_objc_type_name (c_parser
*);
947 static tree
c_parser_objc_protocol_refs (c_parser
*);
948 static void c_parser_objc_try_catch_statement (c_parser
*);
949 static void c_parser_objc_synchronized_statement (c_parser
*);
950 static tree
c_parser_objc_selector (c_parser
*);
951 static tree
c_parser_objc_selector_arg (c_parser
*);
952 static tree
c_parser_objc_receiver (c_parser
*);
953 static tree
c_parser_objc_message_args (c_parser
*);
954 static tree
c_parser_objc_keywordexpr (c_parser
*);
956 /* Parse a translation unit (C90 6.7, C99 6.9).
959 external-declarations
961 external-declarations:
963 external-declarations external-declaration
972 c_parser_translation_unit (c_parser
*parser
)
974 if (c_parser_next_token_is (parser
, CPP_EOF
))
976 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
977 "ISO C forbids an empty translation unit");
981 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
982 mark_valid_location_for_stdc_pragma (false);
986 c_parser_external_declaration (parser
);
987 obstack_free (&parser_obstack
, obstack_position
);
989 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
993 /* Parse an external declaration (C90 6.7, C99 6.9).
995 external-declaration:
1001 external-declaration:
1004 __extension__ external-declaration
1008 external-declaration:
1009 objc-class-definition
1010 objc-class-declaration
1011 objc-alias-declaration
1012 objc-protocol-definition
1013 objc-method-definition
1018 c_parser_external_declaration (c_parser
*parser
)
1021 switch (c_parser_peek_token (parser
)->type
)
1024 switch (c_parser_peek_token (parser
)->keyword
)
1027 ext
= disable_extension_diagnostics ();
1028 c_parser_consume_token (parser
);
1029 c_parser_external_declaration (parser
);
1030 restore_extension_diagnostics (ext
);
1033 c_parser_asm_definition (parser
);
1035 case RID_AT_INTERFACE
:
1036 case RID_AT_IMPLEMENTATION
:
1037 gcc_assert (c_dialect_objc ());
1038 c_parser_objc_class_definition (parser
);
1041 gcc_assert (c_dialect_objc ());
1042 c_parser_objc_class_declaration (parser
);
1045 gcc_assert (c_dialect_objc ());
1046 c_parser_objc_alias_declaration (parser
);
1048 case RID_AT_PROTOCOL
:
1049 gcc_assert (c_dialect_objc ());
1050 c_parser_objc_protocol_definition (parser
);
1053 gcc_assert (c_dialect_objc ());
1054 c_parser_consume_token (parser
);
1055 objc_finish_implementation ();
1062 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1063 "ISO C does not allow extra %<;%> outside of a function");
1064 c_parser_consume_token (parser
);
1067 mark_valid_location_for_stdc_pragma (true);
1068 c_parser_pragma (parser
, pragma_external
);
1069 mark_valid_location_for_stdc_pragma (false);
1073 if (c_dialect_objc ())
1075 c_parser_objc_method_definition (parser
);
1078 /* Else fall through, and yield a syntax error trying to parse
1079 as a declaration or function definition. */
1082 /* A declaration or a function definition. We can only tell
1083 which after parsing the declaration specifiers, if any, and
1084 the first declarator. */
1085 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1091 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1092 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1093 accepted; otherwise (old-style parameter declarations) only other
1094 declarations are accepted. If NESTED is true, we are inside a
1095 function or parsing old-style parameter declarations; any functions
1096 encountered are nested functions and declaration specifiers are
1097 required; otherwise we are at top level and functions are normal
1098 functions and declaration specifiers may be optional. If EMPTY_OK
1099 is true, empty declarations are OK (subject to all other
1100 constraints); otherwise (old-style parameter declarations) they are
1101 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1102 may start with attributes; otherwise they may not.
1105 declaration-specifiers init-declarator-list[opt] ;
1107 function-definition:
1108 declaration-specifiers[opt] declarator declaration-list[opt]
1113 declaration-list declaration
1115 init-declarator-list:
1117 init-declarator-list , init-declarator
1120 declarator simple-asm-expr[opt] attributes[opt]
1121 declarator simple-asm-expr[opt] attributes[opt] = initializer
1125 nested-function-definition:
1126 declaration-specifiers declarator declaration-list[opt]
1129 The simple-asm-expr and attributes are GNU extensions.
1131 This function does not handle __extension__; that is handled in its
1132 callers. ??? Following the old parser, __extension__ may start
1133 external declarations, declarations in functions and declarations
1134 at the start of "for" loops, but not old-style parameter
1137 C99 requires declaration specifiers in a function definition; the
1138 absence is diagnosed through the diagnosis of implicit int. In GNU
1139 C we also allow but diagnose declarations without declaration
1140 specifiers, but only at top level (elsewhere they conflict with
1146 threadprivate-directive */
1149 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1150 bool nested
, bool start_attr_ok
)
1152 struct c_declspecs
*specs
;
1154 tree all_prefix_attrs
;
1155 bool diagnosed_no_specs
= false;
1156 location_t here
= c_parser_peek_token (parser
)->location
;
1158 specs
= build_null_declspecs ();
1159 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1162 c_parser_skip_to_end_of_block_or_statement (parser
);
1165 if (nested
&& !specs
->declspecs_seen_p
)
1167 c_parser_error (parser
, "expected declaration specifiers");
1168 c_parser_skip_to_end_of_block_or_statement (parser
);
1171 finish_declspecs (specs
);
1172 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1178 shadow_tag_warned (specs
, 1);
1179 pedwarn (here
, 0, "empty declaration");
1181 c_parser_consume_token (parser
);
1184 pending_xref_error ();
1185 prefix_attrs
= specs
->attrs
;
1186 all_prefix_attrs
= prefix_attrs
;
1187 specs
->attrs
= NULL_TREE
;
1190 struct c_declarator
*declarator
;
1193 /* Declaring either one or more declarators (in which case we
1194 should diagnose if there were no declaration specifiers) or a
1195 function definition (in which case the diagnostic for
1196 implicit int suffices). */
1197 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1198 C_DTR_NORMAL
, &dummy
);
1199 if (declarator
== NULL
)
1201 c_parser_skip_to_end_of_block_or_statement (parser
);
1204 if (c_parser_next_token_is (parser
, CPP_EQ
)
1205 || c_parser_next_token_is (parser
, CPP_COMMA
)
1206 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1207 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1208 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1210 tree asm_name
= NULL_TREE
;
1211 tree postfix_attrs
= NULL_TREE
;
1212 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1214 diagnosed_no_specs
= true;
1215 pedwarn (here
, 0, "data definition has no type or storage class");
1217 /* Having seen a data definition, there cannot now be a
1218 function definition. */
1220 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1221 asm_name
= c_parser_simple_asm_expr (parser
);
1222 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1223 postfix_attrs
= c_parser_attributes (parser
);
1224 if (c_parser_next_token_is (parser
, CPP_EQ
))
1228 location_t init_loc
;
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_loc
= c_parser_peek_token (parser
)->location
;
1238 init
= c_parser_initializer (parser
);
1240 if (d
!= error_mark_node
)
1242 maybe_warn_string_init (TREE_TYPE (d
), init
);
1243 finish_decl (d
, init_loc
, init
.value
,
1244 init
.original_type
, asm_name
);
1249 tree d
= start_decl (declarator
, specs
, false,
1250 chainon (postfix_attrs
,
1253 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1254 NULL_TREE
, asm_name
);
1256 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1258 c_parser_consume_token (parser
);
1259 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1260 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1263 all_prefix_attrs
= prefix_attrs
;
1266 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1268 c_parser_consume_token (parser
);
1273 c_parser_error (parser
, "expected %<,%> or %<;%>");
1274 c_parser_skip_to_end_of_block_or_statement (parser
);
1280 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1281 "%<asm%> or %<__attribute__%>");
1282 c_parser_skip_to_end_of_block_or_statement (parser
);
1285 /* Function definition (nested or otherwise). */
1288 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1289 c_push_function_context ();
1291 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1293 /* This can appear in many cases looking nothing like a
1294 function definition, so we don't give a more specific
1295 error suggesting there was one. */
1296 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1297 "or %<__attribute__%>");
1299 c_pop_function_context ();
1302 /* Parse old-style parameter declarations. ??? Attributes are
1303 not allowed to start declaration specifiers here because of a
1304 syntax conflict between a function declaration with attribute
1305 suffix and a function definition with an attribute prefix on
1306 first old-style parameter declaration. Following the old
1307 parser, they are not accepted on subsequent old-style
1308 parameter declarations either. However, there is no
1309 ambiguity after the first declaration, nor indeed on the
1310 first as long as we don't allow postfix attributes after a
1311 declarator with a nonempty identifier list in a definition;
1312 and postfix attributes have never been accepted here in
1313 function definitions either. */
1314 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1315 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1316 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1317 store_parm_decls ();
1318 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1319 = c_parser_peek_token (parser
)->location
;
1320 fnbody
= c_parser_compound_statement (parser
);
1323 tree decl
= current_function_decl
;
1326 c_pop_function_context ();
1327 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1338 /* Parse an asm-definition (asm() outside a function body). This is a
1346 c_parser_asm_definition (c_parser
*parser
)
1348 tree asm_str
= c_parser_simple_asm_expr (parser
);
1350 cgraph_add_asm_node (asm_str
);
1351 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1354 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1355 6.7), adding them to SPECS (which may already include some).
1356 Storage class specifiers are accepted iff SCSPEC_OK; type
1357 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1358 the start iff START_ATTR_OK.
1360 declaration-specifiers:
1361 storage-class-specifier declaration-specifiers[opt]
1362 type-specifier declaration-specifiers[opt]
1363 type-qualifier declaration-specifiers[opt]
1364 function-specifier declaration-specifiers[opt]
1366 Function specifiers (inline) are from C99, and are currently
1367 handled as storage class specifiers, as is __thread.
1369 C90 6.5.1, C99 6.7.1:
1370 storage-class-specifier:
1381 C90 6.5.2, C99 6.7.2:
1394 [_Imaginary removed in C99 TC2]
1395 struct-or-union-specifier
1399 (_Bool and _Complex are new in C99.)
1401 C90 6.5.3, C99 6.7.3:
1408 (restrict is new in C99.)
1412 declaration-specifiers:
1413 attributes declaration-specifiers[opt]
1415 storage-class-specifier:
1427 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1428 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1433 class-name objc-protocol-refs[opt]
1434 typedef-name objc-protocol-refs
1439 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1440 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1442 bool attrs_ok
= start_attr_ok
;
1443 bool seen_type
= specs
->type_seen_p
;
1444 while (c_parser_next_token_is (parser
, CPP_NAME
)
1445 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1446 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1448 struct c_typespec t
;
1450 location_t loc
= c_parser_peek_token (parser
)->location
;
1451 if (c_parser_next_token_is (parser
, CPP_NAME
))
1453 tree value
= c_parser_peek_token (parser
)->value
;
1454 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1455 /* This finishes the specifiers unless a type name is OK, it
1456 is declared as a type name and a type name hasn't yet
1458 if (!typespec_ok
|| seen_type
1459 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1461 c_parser_consume_token (parser
);
1464 if (kind
== C_ID_TYPENAME
1465 && (!c_dialect_objc ()
1466 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1468 t
.kind
= ctsk_typedef
;
1469 /* For a typedef name, record the meaning, not the name.
1470 In case of 'foo foo, bar;'. */
1471 t
.spec
= lookup_name (value
);
1473 t
.expr_const_operands
= true;
1477 tree proto
= NULL_TREE
;
1478 gcc_assert (c_dialect_objc ());
1480 if (c_parser_next_token_is (parser
, CPP_LESS
))
1481 proto
= c_parser_objc_protocol_refs (parser
);
1482 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1484 t
.expr_const_operands
= true;
1486 declspecs_add_type (loc
, specs
, t
);
1489 if (c_parser_next_token_is (parser
, CPP_LESS
))
1491 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1492 nisse@lysator.liu.se. */
1494 gcc_assert (c_dialect_objc ());
1495 if (!typespec_ok
|| seen_type
)
1497 proto
= c_parser_objc_protocol_refs (parser
);
1499 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1501 t
.expr_const_operands
= true;
1502 declspecs_add_type (loc
, specs
, t
);
1505 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1506 switch (c_parser_peek_token (parser
)->keyword
)
1518 /* TODO: Distinguish between function specifiers (inline)
1519 and storage class specifiers, either here or in
1520 declspecs_add_scspec. */
1521 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1522 c_parser_consume_token (parser
);
1545 if (c_dialect_objc ())
1546 parser
->objc_need_raw_identifier
= true;
1547 t
.kind
= ctsk_resword
;
1548 t
.spec
= c_parser_peek_token (parser
)->value
;
1550 t
.expr_const_operands
= true;
1551 declspecs_add_type (loc
, specs
, t
);
1552 c_parser_consume_token (parser
);
1559 t
= c_parser_enum_specifier (parser
);
1560 declspecs_add_type (loc
, specs
, t
);
1568 t
= c_parser_struct_or_union_specifier (parser
);
1569 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1570 declspecs_add_type (loc
, specs
, t
);
1573 /* ??? The old parser rejected typeof after other type
1574 specifiers, but is a syntax error the best way of
1576 if (!typespec_ok
|| seen_type
)
1580 t
= c_parser_typeof_specifier (parser
);
1581 declspecs_add_type (loc
, specs
, t
);
1587 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1588 c_parser_consume_token (parser
);
1593 attrs
= c_parser_attributes (parser
);
1594 declspecs_add_attrs (specs
, attrs
);
1603 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1606 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1607 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1608 enum attributes[opt] identifier
1610 The form with trailing comma is new in C99. The forms with
1611 attributes are GNU extensions. In GNU C, we accept any expression
1612 without commas in the syntax (assignment expressions, not just
1613 conditional expressions); assignment expressions will be diagnosed
1618 enumerator-list , enumerator
1621 enumeration-constant
1622 enumeration-constant = constant-expression
1625 static struct c_typespec
1626 c_parser_enum_specifier (c_parser
*parser
)
1628 struct c_typespec ret
;
1630 tree ident
= NULL_TREE
;
1631 location_t enum_loc
;
1632 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1633 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1634 enum_loc
= c_parser_peek_token (parser
)->location
;
1635 c_parser_consume_token (parser
);
1636 attrs
= c_parser_attributes (parser
);
1637 enum_loc
= c_parser_peek_token (parser
)->location
;
1638 /* Set the location in case we create a decl now. */
1639 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1640 if (c_parser_next_token_is (parser
, CPP_NAME
))
1642 ident
= c_parser_peek_token (parser
)->value
;
1643 ident_loc
= c_parser_peek_token (parser
)->location
;
1644 enum_loc
= ident_loc
;
1645 c_parser_consume_token (parser
);
1647 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1649 /* Parse an enum definition. */
1650 struct c_enum_contents the_enum
;
1651 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
1653 /* We chain the enumerators in reverse order, then put them in
1654 forward order at the end. */
1655 tree values
= NULL_TREE
;
1656 c_parser_consume_token (parser
);
1664 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1665 location_t value_loc
;
1666 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1668 c_parser_error (parser
, "expected identifier");
1669 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1670 values
= error_mark_node
;
1673 token
= c_parser_peek_token (parser
);
1674 enum_id
= token
->value
;
1675 /* Set the location in case we create a decl now. */
1676 c_parser_set_source_position_from_token (token
);
1677 value_loc
= token
->location
;
1678 c_parser_consume_token (parser
);
1679 if (c_parser_next_token_is (parser
, CPP_EQ
))
1681 c_parser_consume_token (parser
);
1682 value_loc
= c_parser_peek_token (parser
)->location
;
1683 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1686 enum_value
= NULL_TREE
;
1687 enum_decl
= build_enumerator (value_loc
,
1688 &the_enum
, enum_id
, enum_value
);
1689 TREE_CHAIN (enum_decl
) = values
;
1692 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1694 comma_loc
= c_parser_peek_token (parser
)->location
;
1696 c_parser_consume_token (parser
);
1698 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1700 if (seen_comma
&& !flag_isoc99
)
1701 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1702 c_parser_consume_token (parser
);
1707 c_parser_error (parser
, "expected %<,%> or %<}%>");
1708 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1709 values
= error_mark_node
;
1713 postfix_attrs
= c_parser_attributes (parser
);
1714 ret
.spec
= finish_enum (type
, nreverse (values
),
1715 chainon (attrs
, postfix_attrs
));
1716 ret
.kind
= ctsk_tagdef
;
1717 ret
.expr
= NULL_TREE
;
1718 ret
.expr_const_operands
= true;
1723 c_parser_error (parser
, "expected %<{%>");
1724 ret
.spec
= error_mark_node
;
1725 ret
.kind
= ctsk_tagref
;
1726 ret
.expr
= NULL_TREE
;
1727 ret
.expr_const_operands
= true;
1730 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
1731 /* In ISO C, enumerated types can be referred to only if already
1733 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1736 pedwarn (enum_loc
, OPT_pedantic
,
1737 "ISO C forbids forward references to %<enum%> types");
1742 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1744 struct-or-union-specifier:
1745 struct-or-union attributes[opt] identifier[opt]
1746 { struct-contents } attributes[opt]
1747 struct-or-union attributes[opt] identifier
1750 struct-declaration-list
1752 struct-declaration-list:
1753 struct-declaration ;
1754 struct-declaration-list struct-declaration ;
1761 struct-declaration-list struct-declaration
1763 struct-declaration-list:
1764 struct-declaration-list ;
1767 (Note that in the syntax here, unlike that in ISO C, the semicolons
1768 are included here rather than in struct-declaration, in order to
1769 describe the syntax with extra semicolons and missing semicolon at
1774 struct-declaration-list:
1775 @defs ( class-name )
1777 (Note this does not include a trailing semicolon, but can be
1778 followed by further declarations, and gets a pedwarn-if-pedantic
1779 when followed by a semicolon.) */
1781 static struct c_typespec
1782 c_parser_struct_or_union_specifier (c_parser
*parser
)
1784 struct c_typespec ret
;
1786 tree ident
= NULL_TREE
;
1787 location_t struct_loc
;
1788 location_t ident_loc
= UNKNOWN_LOCATION
;
1789 enum tree_code code
;
1790 switch (c_parser_peek_token (parser
)->keyword
)
1801 struct_loc
= c_parser_peek_token (parser
)->location
;
1802 c_parser_consume_token (parser
);
1803 attrs
= c_parser_attributes (parser
);
1805 /* Set the location in case we create a decl now. */
1806 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1808 if (c_parser_next_token_is (parser
, CPP_NAME
))
1810 ident
= c_parser_peek_token (parser
)->value
;
1811 ident_loc
= c_parser_peek_token (parser
)->location
;
1812 struct_loc
= ident_loc
;
1813 c_parser_consume_token (parser
);
1815 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1817 /* Parse a struct or union definition. Start the scope of the
1818 tag before parsing components. */
1819 struct c_struct_parse_info
*struct_info
;
1820 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
1822 /* We chain the components in reverse order, then put them in
1823 forward order at the end. Each struct-declaration may
1824 declare multiple components (comma-separated), so we must use
1825 chainon to join them, although when parsing each
1826 struct-declaration we can use TREE_CHAIN directly.
1828 The theory behind all this is that there will be more
1829 semicolon separated fields than comma separated fields, and
1830 so we'll be minimizing the number of node traversals required
1832 tree contents
= NULL_TREE
;
1833 c_parser_consume_token (parser
);
1834 /* Handle the Objective-C @defs construct,
1835 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1836 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1839 gcc_assert (c_dialect_objc ());
1840 c_parser_consume_token (parser
);
1841 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1843 if (c_parser_next_token_is (parser
, CPP_NAME
)
1844 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1846 name
= c_parser_peek_token (parser
)->value
;
1847 c_parser_consume_token (parser
);
1851 c_parser_error (parser
, "expected class name");
1852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1855 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1857 contents
= nreverse (objc_get_class_ivars (name
));
1860 /* Parse the struct-declarations and semicolons. Problems with
1861 semicolons are diagnosed here; empty structures are diagnosed
1866 /* Parse any stray semicolon. */
1867 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1869 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1870 "extra semicolon in struct or union specified");
1871 c_parser_consume_token (parser
);
1874 /* Stop if at the end of the struct or union contents. */
1875 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1877 c_parser_consume_token (parser
);
1880 /* Accept #pragmas at struct scope. */
1881 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1883 c_parser_pragma (parser
, pragma_external
);
1886 /* Parse some comma-separated declarations, but not the
1887 trailing semicolon if any. */
1888 decls
= c_parser_struct_declaration (parser
);
1889 contents
= chainon (decls
, contents
);
1890 /* If no semicolon follows, either we have a parse error or
1891 are at the end of the struct or union and should
1893 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1894 c_parser_consume_token (parser
);
1897 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1898 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1899 "no semicolon at end of struct or union");
1902 c_parser_error (parser
, "expected %<;%>");
1903 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1908 postfix_attrs
= c_parser_attributes (parser
);
1909 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
1910 chainon (attrs
, postfix_attrs
), struct_info
);
1911 ret
.kind
= ctsk_tagdef
;
1912 ret
.expr
= NULL_TREE
;
1913 ret
.expr_const_operands
= true;
1918 c_parser_error (parser
, "expected %<{%>");
1919 ret
.spec
= error_mark_node
;
1920 ret
.kind
= ctsk_tagref
;
1921 ret
.expr
= NULL_TREE
;
1922 ret
.expr_const_operands
= true;
1925 ret
= parser_xref_tag (ident_loc
, code
, ident
);
1929 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1930 the trailing semicolon.
1933 specifier-qualifier-list struct-declarator-list
1935 specifier-qualifier-list:
1936 type-specifier specifier-qualifier-list[opt]
1937 type-qualifier specifier-qualifier-list[opt]
1938 attributes specifier-qualifier-list[opt]
1940 struct-declarator-list:
1942 struct-declarator-list , attributes[opt] struct-declarator
1945 declarator attributes[opt]
1946 declarator[opt] : constant-expression attributes[opt]
1951 __extension__ struct-declaration
1952 specifier-qualifier-list
1954 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1955 of attributes where shown is a GNU extension. In GNU C, we accept
1956 any expression without commas in the syntax (assignment
1957 expressions, not just conditional expressions); assignment
1958 expressions will be diagnosed as non-constant. */
1961 c_parser_struct_declaration (c_parser
*parser
)
1963 struct c_declspecs
*specs
;
1965 tree all_prefix_attrs
;
1967 location_t decl_loc
;
1968 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1972 ext
= disable_extension_diagnostics ();
1973 c_parser_consume_token (parser
);
1974 decl
= c_parser_struct_declaration (parser
);
1975 restore_extension_diagnostics (ext
);
1978 specs
= build_null_declspecs ();
1979 decl_loc
= c_parser_peek_token (parser
)->location
;
1980 c_parser_declspecs (parser
, specs
, false, true, true);
1983 if (!specs
->declspecs_seen_p
)
1985 c_parser_error (parser
, "expected specifier-qualifier-list");
1988 finish_declspecs (specs
);
1989 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1992 if (!specs
->type_seen_p
)
1994 pedwarn (decl_loc
, OPT_pedantic
,
1995 "ISO C forbids member declarations with no members");
1996 shadow_tag_warned (specs
, pedantic
);
2001 /* Support for unnamed structs or unions as members of
2002 structs or unions (which is [a] useful and [b] supports
2006 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2007 build_id_declarator (NULL_TREE
), specs
,
2010 decl_attributes (&ret
, attrs
, 0);
2014 pending_xref_error ();
2015 prefix_attrs
= specs
->attrs
;
2016 all_prefix_attrs
= prefix_attrs
;
2017 specs
->attrs
= NULL_TREE
;
2021 /* Declaring one or more declarators or un-named bit-fields. */
2022 struct c_declarator
*declarator
;
2024 if (c_parser_next_token_is (parser
, CPP_COLON
))
2025 declarator
= build_id_declarator (NULL_TREE
);
2027 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2028 C_DTR_NORMAL
, &dummy
);
2029 if (declarator
== NULL
)
2031 c_parser_skip_to_end_of_block_or_statement (parser
);
2034 if (c_parser_next_token_is (parser
, CPP_COLON
)
2035 || c_parser_next_token_is (parser
, CPP_COMMA
)
2036 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2037 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2038 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2040 tree postfix_attrs
= NULL_TREE
;
2041 tree width
= NULL_TREE
;
2043 if (c_parser_next_token_is (parser
, CPP_COLON
))
2045 c_parser_consume_token (parser
);
2046 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2048 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2049 postfix_attrs
= c_parser_attributes (parser
);
2050 d
= grokfield (c_parser_peek_token (parser
)->location
,
2051 declarator
, specs
, width
, &all_prefix_attrs
);
2052 decl_attributes (&d
, chainon (postfix_attrs
,
2053 all_prefix_attrs
), 0);
2054 TREE_CHAIN (d
) = decls
;
2056 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2057 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2060 all_prefix_attrs
= prefix_attrs
;
2061 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2062 c_parser_consume_token (parser
);
2063 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2064 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2066 /* Semicolon consumed in caller. */
2071 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2077 c_parser_error (parser
,
2078 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2079 "%<__attribute__%>");
2086 /* Parse a typeof specifier (a GNU extension).
2089 typeof ( expression )
2090 typeof ( type-name )
2093 static struct c_typespec
2094 c_parser_typeof_specifier (c_parser
*parser
)
2096 struct c_typespec ret
;
2097 ret
.kind
= ctsk_typeof
;
2098 ret
.spec
= error_mark_node
;
2099 ret
.expr
= NULL_TREE
;
2100 ret
.expr_const_operands
= true;
2101 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2102 c_parser_consume_token (parser
);
2103 c_inhibit_evaluation_warnings
++;
2105 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2107 c_inhibit_evaluation_warnings
--;
2111 if (c_parser_next_token_starts_typename (parser
))
2113 struct c_type_name
*type
= c_parser_type_name (parser
);
2114 c_inhibit_evaluation_warnings
--;
2118 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2119 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2125 location_t here
= c_parser_peek_token (parser
)->location
;
2126 struct c_expr expr
= c_parser_expression (parser
);
2127 c_inhibit_evaluation_warnings
--;
2129 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2130 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2131 error_at (here
, "%<typeof%> applied to a bit-field");
2132 ret
.spec
= TREE_TYPE (expr
.value
);
2133 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2134 /* This is returned with the type so that when the type is
2135 evaluated, this can be evaluated. */
2137 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2138 pop_maybe_used (was_vm
);
2140 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2144 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2145 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2146 be redeclared; otherwise it may not. KIND indicates which kind of
2147 declarator is wanted. Returns a valid declarator except in the
2148 case of a syntax error in which case NULL is returned. *SEEN_ID is
2149 set to true if an identifier being declared is seen; this is used
2150 to diagnose bad forms of abstract array declarators and to
2151 determine whether an identifier list is syntactically permitted.
2154 pointer[opt] direct-declarator
2158 ( attributes[opt] declarator )
2159 direct-declarator array-declarator
2160 direct-declarator ( parameter-type-list )
2161 direct-declarator ( identifier-list[opt] )
2164 * type-qualifier-list[opt]
2165 * type-qualifier-list[opt] pointer
2167 type-qualifier-list:
2170 type-qualifier-list type-qualifier
2171 type-qualifier-list attributes
2173 parameter-type-list:
2175 parameter-list , ...
2178 parameter-declaration
2179 parameter-list , parameter-declaration
2181 parameter-declaration:
2182 declaration-specifiers declarator attributes[opt]
2183 declaration-specifiers abstract-declarator[opt] attributes[opt]
2187 identifier-list , identifier
2189 abstract-declarator:
2191 pointer[opt] direct-abstract-declarator
2193 direct-abstract-declarator:
2194 ( attributes[opt] abstract-declarator )
2195 direct-abstract-declarator[opt] array-declarator
2196 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2201 direct-declarator ( parameter-forward-declarations
2202 parameter-type-list[opt] )
2204 direct-abstract-declarator:
2205 direct-abstract-declarator[opt] ( parameter-forward-declarations
2206 parameter-type-list[opt] )
2208 parameter-forward-declarations:
2210 parameter-forward-declarations parameter-list ;
2212 The uses of attributes shown above are GNU extensions.
2214 Some forms of array declarator are not included in C99 in the
2215 syntax for abstract declarators; these are disallowed elsewhere.
2216 This may be a defect (DR#289).
2218 This function also accepts an omitted abstract declarator as being
2219 an abstract declarator, although not part of the formal syntax. */
2221 static struct c_declarator
*
2222 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2225 /* Parse any initial pointer part. */
2226 if (c_parser_next_token_is (parser
, CPP_MULT
))
2228 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2229 struct c_declarator
*inner
;
2230 c_parser_consume_token (parser
);
2231 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2232 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2236 return make_pointer_declarator (quals_attrs
, inner
);
2238 /* Now we have a direct declarator, direct abstract declarator or
2239 nothing (which counts as a direct abstract declarator here). */
2240 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2243 /* Parse a direct declarator or direct abstract declarator; arguments
2244 as c_parser_declarator. */
2246 static struct c_declarator
*
2247 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2250 /* The direct declarator must start with an identifier (possibly
2251 omitted) or a parenthesized declarator (possibly abstract). In
2252 an ordinary declarator, initial parentheses must start a
2253 parenthesized declarator. In an abstract declarator or parameter
2254 declarator, they could start a parenthesized declarator or a
2255 parameter list. To tell which, the open parenthesis and any
2256 following attributes must be read. If a declaration specifier
2257 follows, then it is a parameter list; if the specifier is a
2258 typedef name, there might be an ambiguity about redeclaring it,
2259 which is resolved in the direction of treating it as a typedef
2260 name. If a close parenthesis follows, it is also an empty
2261 parameter list, as the syntax does not permit empty abstract
2262 declarators. Otherwise, it is a parenthesized declarator (in
2263 which case the analysis may be repeated inside it, recursively).
2265 ??? There is an ambiguity in a parameter declaration "int
2266 (__attribute__((foo)) x)", where x is not a typedef name: it
2267 could be an abstract declarator for a function, or declare x with
2268 parentheses. The proper resolution of this ambiguity needs
2269 documenting. At present we follow an accident of the old
2270 parser's implementation, whereby the first parameter must have
2271 some declaration specifiers other than just attributes. Thus as
2272 a parameter declaration it is treated as a parenthesized
2273 parameter named x, and as an abstract declarator it is
2276 ??? Also following the old parser, attributes inside an empty
2277 parameter list are ignored, making it a list not yielding a
2278 prototype, rather than giving an error or making it have one
2279 parameter with implicit type int.
2281 ??? Also following the old parser, typedef names may be
2282 redeclared in declarators, but not Objective-C class names. */
2284 if (kind
!= C_DTR_ABSTRACT
2285 && c_parser_next_token_is (parser
, CPP_NAME
)
2287 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2288 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2290 struct c_declarator
*inner
2291 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2293 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2294 c_parser_consume_token (parser
);
2295 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2298 if (kind
!= C_DTR_NORMAL
2299 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2301 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2302 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2305 /* Either we are at the end of an abstract declarator, or we have
2308 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2311 struct c_declarator
*inner
;
2312 c_parser_consume_token (parser
);
2313 attrs
= c_parser_attributes (parser
);
2314 if (kind
!= C_DTR_NORMAL
2315 && (c_parser_next_token_starts_declspecs (parser
)
2316 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2318 struct c_arg_info
*args
2319 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2326 = build_function_declarator (args
,
2327 build_id_declarator (NULL_TREE
));
2328 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2332 /* A parenthesized declarator. */
2333 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2334 if (inner
!= NULL
&& attrs
!= NULL
)
2335 inner
= build_attrs_declarator (attrs
, inner
);
2336 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2338 c_parser_consume_token (parser
);
2342 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2346 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2353 if (kind
== C_DTR_NORMAL
)
2355 c_parser_error (parser
, "expected identifier or %<(%>");
2359 return build_id_declarator (NULL_TREE
);
2363 /* Parse part of a direct declarator or direct abstract declarator,
2364 given that some (in INNER) has already been parsed; ID_PRESENT is
2365 true if an identifier is present, false for an abstract
2368 static struct c_declarator
*
2369 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2370 struct c_declarator
*inner
)
2372 /* Parse a sequence of array declarators and parameter lists. */
2373 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2375 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2376 struct c_declarator
*declarator
;
2377 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2381 c_parser_consume_token (parser
);
2382 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2383 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2385 c_parser_consume_token (parser
);
2386 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2387 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2388 if (!quals_attrs
->declspecs_seen_p
)
2390 /* If "static" is present, there must be an array dimension.
2391 Otherwise, there may be a dimension, "*", or no
2396 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2400 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2405 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2407 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2411 c_parser_consume_token (parser
);
2416 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2422 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2425 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2426 c_parser_consume_token (parser
);
2429 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2433 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2434 static_seen
, star_seen
);
2435 if (declarator
== NULL
)
2437 inner
= set_array_declarator_inner (declarator
, inner
);
2438 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2440 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2443 struct c_arg_info
*args
;
2444 c_parser_consume_token (parser
);
2445 attrs
= c_parser_attributes (parser
);
2446 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2451 inner
= build_function_declarator (args
, inner
);
2452 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2458 /* Parse a parameter list or identifier list, including the closing
2459 parenthesis but not the opening one. ATTRS are the attributes at
2460 the start of the list. ID_LIST_OK is true if an identifier list is
2461 acceptable; such a list must not have attributes at the start. */
2463 static struct c_arg_info
*
2464 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2467 declare_parm_level ();
2468 /* If the list starts with an identifier, it is an identifier list.
2469 Otherwise, it is either a prototype list or an empty list. */
2472 && c_parser_next_token_is (parser
, CPP_NAME
)
2473 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2475 tree list
= NULL_TREE
, *nextp
= &list
;
2476 while (c_parser_next_token_is (parser
, CPP_NAME
)
2477 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2479 *nextp
= build_tree_list (NULL_TREE
,
2480 c_parser_peek_token (parser
)->value
);
2481 nextp
= & TREE_CHAIN (*nextp
);
2482 c_parser_consume_token (parser
);
2483 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2485 c_parser_consume_token (parser
);
2486 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2488 c_parser_error (parser
, "expected identifier");
2492 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2494 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2499 ret
->pending_sizes
= 0;
2500 ret
->had_vla_unspec
= 0;
2501 c_parser_consume_token (parser
);
2507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2515 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2521 /* Parse a parameter list (possibly empty), including the closing
2522 parenthesis but not the opening one. ATTRS are the attributes at
2523 the start of the list. */
2525 static struct c_arg_info
*
2526 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2528 bool good_parm
= false;
2529 /* ??? Following the old parser, forward parameter declarations may
2530 use abstract declarators, and if no real parameter declarations
2531 follow the forward declarations then this is not diagnosed. Also
2532 note as above that attributes are ignored as the only contents of
2533 the parentheses, or as the only contents after forward
2535 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2537 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2542 ret
->pending_sizes
= 0;
2543 ret
->had_vla_unspec
= 0;
2544 c_parser_consume_token (parser
);
2547 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2549 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2553 ret
->pending_sizes
= 0;
2554 ret
->had_vla_unspec
= 0;
2555 /* Suppress -Wold-style-definition for this case. */
2556 ret
->types
= error_mark_node
;
2557 error_at (c_parser_peek_token (parser
)->location
,
2558 "ISO C requires a named argument before %<...%>");
2559 c_parser_consume_token (parser
);
2560 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2562 c_parser_consume_token (parser
);
2567 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2572 /* Nonempty list of parameters, either terminated with semicolon
2573 (forward declarations; recurse) or with close parenthesis (normal
2574 function) or with ", ... )" (variadic function). */
2577 /* Parse a parameter. */
2578 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2583 push_parm_decl (parm
);
2585 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2588 c_parser_consume_token (parser
);
2589 mark_forward_parm_decls ();
2590 new_attrs
= c_parser_attributes (parser
);
2591 return c_parser_parms_list_declarator (parser
, new_attrs
);
2593 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2595 c_parser_consume_token (parser
);
2597 return get_parm_info (false);
2600 struct c_arg_info
*ret
2601 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2606 ret
->pending_sizes
= 0;
2607 ret
->had_vla_unspec
= 0;
2611 if (!c_parser_require (parser
, CPP_COMMA
,
2612 "expected %<;%>, %<,%> or %<)%>"))
2614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2615 get_pending_sizes ();
2618 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2620 c_parser_consume_token (parser
);
2621 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2623 c_parser_consume_token (parser
);
2625 return get_parm_info (true);
2628 struct c_arg_info
*ret
2629 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2634 ret
->pending_sizes
= 0;
2635 ret
->had_vla_unspec
= 0;
2641 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2643 get_pending_sizes ();
2650 /* Parse a parameter declaration. ATTRS are the attributes at the
2651 start of the declaration if it is the first parameter. */
2653 static struct c_parm
*
2654 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2656 struct c_declspecs
*specs
;
2657 struct c_declarator
*declarator
;
2659 tree postfix_attrs
= NULL_TREE
;
2661 if (!c_parser_next_token_starts_declspecs (parser
))
2663 /* ??? In some Objective-C cases '...' isn't applicable so there
2664 should be a different message. */
2665 c_parser_error (parser
,
2666 "expected declaration specifiers or %<...%>");
2667 c_parser_skip_to_end_of_parameter (parser
);
2670 specs
= build_null_declspecs ();
2673 declspecs_add_attrs (specs
, attrs
);
2676 c_parser_declspecs (parser
, specs
, true, true, true);
2677 finish_declspecs (specs
);
2678 pending_xref_error ();
2679 prefix_attrs
= specs
->attrs
;
2680 specs
->attrs
= NULL_TREE
;
2681 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2682 C_DTR_PARM
, &dummy
);
2683 if (declarator
== NULL
)
2685 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2688 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2689 postfix_attrs
= c_parser_attributes (parser
);
2690 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2694 /* Parse a string literal in an asm expression. It should not be
2695 translated, and wide string literals are an error although
2696 permitted by the syntax. This is a GNU extension.
2701 ??? At present, following the old parser, the caller needs to have
2702 set lex_untranslated_string to 1. It would be better to follow the
2703 C++ parser rather than using this kludge. */
2706 c_parser_asm_string_literal (c_parser
*parser
)
2709 if (c_parser_next_token_is (parser
, CPP_STRING
))
2711 str
= c_parser_peek_token (parser
)->value
;
2712 c_parser_consume_token (parser
);
2714 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2716 error_at (c_parser_peek_token (parser
)->location
,
2717 "wide string literal in %<asm%>");
2718 str
= build_string (1, "");
2719 c_parser_consume_token (parser
);
2723 c_parser_error (parser
, "expected string literal");
2729 /* Parse a simple asm expression. This is used in restricted
2730 contexts, where a full expression with inputs and outputs does not
2731 make sense. This is a GNU extension.
2734 asm ( asm-string-literal )
2738 c_parser_simple_asm_expr (c_parser
*parser
)
2741 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2742 /* ??? Follow the C++ parser rather than using the
2743 lex_untranslated_string kludge. */
2744 parser
->lex_untranslated_string
= true;
2745 c_parser_consume_token (parser
);
2746 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2748 parser
->lex_untranslated_string
= false;
2751 str
= c_parser_asm_string_literal (parser
);
2752 parser
->lex_untranslated_string
= false;
2753 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2761 /* Parse (possibly empty) attributes. This is a GNU extension.
2765 attributes attribute
2768 __attribute__ ( ( attribute-list ) )
2772 attribute_list , attrib
2777 any-word ( identifier )
2778 any-word ( identifier , nonempty-expr-list )
2779 any-word ( expr-list )
2781 where the "identifier" must not be declared as a type, and
2782 "any-word" may be any identifier (including one declared as a
2783 type), a reserved word storage class specifier, type specifier or
2784 type qualifier. ??? This still leaves out most reserved keywords
2785 (following the old parser), shouldn't we include them, and why not
2786 allow identifiers declared as types to start the arguments? */
2789 c_parser_attributes (c_parser
*parser
)
2791 tree attrs
= NULL_TREE
;
2792 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2794 /* ??? Follow the C++ parser rather than using the
2795 lex_untranslated_string kludge. */
2796 parser
->lex_untranslated_string
= true;
2797 c_parser_consume_token (parser
);
2798 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2800 parser
->lex_untranslated_string
= false;
2803 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2805 parser
->lex_untranslated_string
= false;
2806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2809 /* Parse the attribute list. */
2810 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2811 || c_parser_next_token_is (parser
, CPP_NAME
)
2812 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2814 tree attr
, attr_name
, attr_args
;
2815 VEC(tree
,gc
) *expr_list
;
2816 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2818 c_parser_consume_token (parser
);
2821 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2823 /* ??? See comment above about what keywords are
2826 switch (c_parser_peek_token (parser
)->keyword
)
2863 /* Accept __attribute__((__const)) as __attribute__((const))
2866 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2869 attr_name
= c_parser_peek_token (parser
)->value
;
2870 c_parser_consume_token (parser
);
2871 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2873 attr
= build_tree_list (attr_name
, NULL_TREE
);
2874 attrs
= chainon (attrs
, attr
);
2877 c_parser_consume_token (parser
);
2878 /* Parse the attribute contents. If they start with an
2879 identifier which is followed by a comma or close
2880 parenthesis, then the arguments start with that
2881 identifier; otherwise they are an expression list. */
2882 if (c_parser_next_token_is (parser
, CPP_NAME
)
2883 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2884 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2885 || (c_parser_peek_2nd_token (parser
)->type
2886 == CPP_CLOSE_PAREN
)))
2888 tree arg1
= c_parser_peek_token (parser
)->value
;
2889 c_parser_consume_token (parser
);
2890 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2891 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2895 c_parser_consume_token (parser
);
2896 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2897 tree_list
= build_tree_list_vec (expr_list
);
2898 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2899 release_tree_vector (expr_list
);
2904 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2905 attr_args
= NULL_TREE
;
2908 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2909 attr_args
= build_tree_list_vec (expr_list
);
2910 release_tree_vector (expr_list
);
2913 attr
= build_tree_list (attr_name
, attr_args
);
2914 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2915 c_parser_consume_token (parser
);
2918 parser
->lex_untranslated_string
= false;
2919 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2923 attrs
= chainon (attrs
, attr
);
2925 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2926 c_parser_consume_token (parser
);
2929 parser
->lex_untranslated_string
= false;
2930 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2934 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2935 c_parser_consume_token (parser
);
2938 parser
->lex_untranslated_string
= false;
2939 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2943 parser
->lex_untranslated_string
= false;
2948 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2951 specifier-qualifier-list abstract-declarator[opt]
2954 static struct c_type_name
*
2955 c_parser_type_name (c_parser
*parser
)
2957 struct c_declspecs
*specs
= build_null_declspecs ();
2958 struct c_declarator
*declarator
;
2959 struct c_type_name
*ret
;
2961 c_parser_declspecs (parser
, specs
, false, true, true);
2962 if (!specs
->declspecs_seen_p
)
2964 c_parser_error (parser
, "expected specifier-qualifier-list");
2967 pending_xref_error ();
2968 finish_declspecs (specs
);
2969 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2970 C_DTR_ABSTRACT
, &dummy
);
2971 if (declarator
== NULL
)
2973 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2975 ret
->declarator
= declarator
;
2979 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2982 assignment-expression
2983 { initializer-list }
2984 { initializer-list , }
2987 designation[opt] initializer
2988 initializer-list , designation[opt] initializer
2995 designator-list designator
3002 [ constant-expression ]
3014 [ constant-expression ... constant-expression ]
3016 Any expression without commas is accepted in the syntax for the
3017 constant-expressions, with non-constant expressions rejected later.
3019 This function is only used for top-level initializers; for nested
3020 ones, see c_parser_initval. */
3022 static struct c_expr
3023 c_parser_initializer (c_parser
*parser
)
3025 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3026 return c_parser_braced_init (parser
, NULL_TREE
, false);
3030 location_t loc
= c_parser_peek_token (parser
)->location
;
3031 ret
= c_parser_expr_no_commas (parser
, NULL
);
3032 if (TREE_CODE (ret
.value
) != STRING_CST
3033 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3034 ret
= default_function_array_conversion (loc
, ret
);
3039 /* Parse a braced initializer list. TYPE is the type specified for a
3040 compound literal, and NULL_TREE for other initializers and for
3041 nested braced lists. NESTED_P is true for nested braced lists,
3042 false for the list of a compound literal or the list that is the
3043 top-level initializer in a declaration. */
3045 static struct c_expr
3046 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3048 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3049 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3050 c_parser_consume_token (parser
);
3052 push_init_level (0);
3054 really_start_incremental_init (type
);
3055 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3057 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3061 /* Parse a non-empty initializer list, possibly with a trailing
3065 c_parser_initelt (parser
);
3068 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3069 c_parser_consume_token (parser
);
3072 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3076 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3079 ret
.value
= error_mark_node
;
3080 ret
.original_code
= ERROR_MARK
;
3081 ret
.original_type
= NULL
;
3082 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3086 c_parser_consume_token (parser
);
3087 return pop_init_level (0);
3090 /* Parse a nested initializer, including designators. */
3093 c_parser_initelt (c_parser
*parser
)
3095 /* Parse any designator or designator list. A single array
3096 designator may have the subsequent "=" omitted in GNU C, but a
3097 longer list or a structure member designator may not. */
3098 if (c_parser_next_token_is (parser
, CPP_NAME
)
3099 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3101 /* Old-style structure member designator. */
3102 set_init_label (c_parser_peek_token (parser
)->value
);
3103 /* Use the colon as the error location. */
3104 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3105 "obsolete use of designated initializer with %<:%>");
3106 c_parser_consume_token (parser
);
3107 c_parser_consume_token (parser
);
3111 /* des_seen is 0 if there have been no designators, 1 if there
3112 has been a single array designator and 2 otherwise. */
3114 /* Location of a designator. */
3115 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3116 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3117 || c_parser_next_token_is (parser
, CPP_DOT
))
3119 int des_prev
= des_seen
;
3121 des_loc
= c_parser_peek_token (parser
)->location
;
3124 if (c_parser_next_token_is (parser
, CPP_DOT
))
3127 c_parser_consume_token (parser
);
3128 if (c_parser_next_token_is (parser
, CPP_NAME
))
3130 set_init_label (c_parser_peek_token (parser
)->value
);
3131 c_parser_consume_token (parser
);
3136 init
.value
= error_mark_node
;
3137 init
.original_code
= ERROR_MARK
;
3138 init
.original_type
= NULL
;
3139 c_parser_error (parser
, "expected identifier");
3140 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3141 process_init_element (init
, false);
3148 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3149 /* ??? Following the old parser, [ objc-receiver
3150 objc-message-args ] is accepted as an initializer,
3151 being distinguished from a designator by what follows
3152 the first assignment expression inside the square
3153 brackets, but after a first array designator a
3154 subsequent square bracket is for Objective-C taken to
3155 start an expression, using the obsolete form of
3156 designated initializer without '=', rather than
3157 possibly being a second level of designation: in LALR
3158 terms, the '[' is shifted rather than reducing
3159 designator to designator-list. */
3160 if (des_prev
== 1 && c_dialect_objc ())
3162 des_seen
= des_prev
;
3165 if (des_prev
== 0 && c_dialect_objc ())
3167 /* This might be an array designator or an
3168 Objective-C message expression. If the former,
3169 continue parsing here; if the latter, parse the
3170 remainder of the initializer given the starting
3171 primary-expression. ??? It might make sense to
3172 distinguish when des_prev == 1 as well; see
3173 previous comment. */
3175 struct c_expr mexpr
;
3176 c_parser_consume_token (parser
);
3177 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3178 && ((c_parser_peek_token (parser
)->id_kind
3180 || (c_parser_peek_token (parser
)->id_kind
3181 == C_ID_CLASSNAME
)))
3183 /* Type name receiver. */
3184 tree id
= c_parser_peek_token (parser
)->value
;
3185 c_parser_consume_token (parser
);
3186 rec
= objc_get_class_reference (id
);
3187 goto parse_message_args
;
3189 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3190 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3191 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3192 goto array_desig_after_first
;
3193 /* Expression receiver. So far only one part
3194 without commas has been parsed; there might be
3195 more of the expression. */
3197 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3200 location_t comma_loc
, exp_loc
;
3201 comma_loc
= c_parser_peek_token (parser
)->location
;
3202 c_parser_consume_token (parser
);
3203 exp_loc
= c_parser_peek_token (parser
)->location
;
3204 next
= c_parser_expr_no_commas (parser
, NULL
);
3205 next
= default_function_array_conversion (exp_loc
, next
);
3206 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3209 /* Now parse the objc-message-args. */
3210 args
= c_parser_objc_message_args (parser
);
3211 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3214 = objc_build_message_expr (build_tree_list (rec
, args
));
3215 mexpr
.original_code
= ERROR_MARK
;
3216 mexpr
.original_type
= NULL
;
3217 /* Now parse and process the remainder of the
3218 initializer, starting with this message
3219 expression as a primary-expression. */
3220 c_parser_initval (parser
, &mexpr
);
3223 c_parser_consume_token (parser
);
3224 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3225 array_desig_after_first
:
3226 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3228 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3229 c_parser_consume_token (parser
);
3230 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3234 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3236 c_parser_consume_token (parser
);
3237 set_init_index (first
, second
);
3239 pedwarn (ellipsis_loc
, OPT_pedantic
,
3240 "ISO C forbids specifying range of elements to initialize");
3243 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3249 if (c_parser_next_token_is (parser
, CPP_EQ
))
3252 pedwarn (des_loc
, OPT_pedantic
,
3253 "ISO C90 forbids specifying subobject to initialize");
3254 c_parser_consume_token (parser
);
3259 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3260 "obsolete use of designated initializer without %<=%>");
3264 init
.value
= error_mark_node
;
3265 init
.original_code
= ERROR_MARK
;
3266 init
.original_type
= NULL
;
3267 c_parser_error (parser
, "expected %<=%>");
3268 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3269 process_init_element (init
, false);
3275 c_parser_initval (parser
, NULL
);
3278 /* Parse a nested initializer; as c_parser_initializer but parses
3279 initializers within braced lists, after any designators have been
3280 applied. If AFTER is not NULL then it is an Objective-C message
3281 expression which is the primary-expression starting the
3285 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3288 gcc_assert (!after
|| c_dialect_objc ());
3289 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3290 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3293 location_t loc
= c_parser_peek_token (parser
)->location
;
3294 init
= c_parser_expr_no_commas (parser
, after
);
3295 if (init
.value
!= NULL_TREE
3296 && TREE_CODE (init
.value
) != STRING_CST
3297 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3298 init
= default_function_array_conversion (loc
, init
);
3300 process_init_element (init
, false);
3303 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3307 { block-item-list[opt] }
3308 { label-declarations block-item-list }
3312 block-item-list block-item
3324 { label-declarations block-item-list }
3327 __extension__ nested-declaration
3328 nested-function-definition
3332 label-declarations label-declaration
3335 __label__ identifier-list ;
3337 Allowing the mixing of declarations and code is new in C99. The
3338 GNU syntax also permits (not shown above) labels at the end of
3339 compound statements, which yield an error. We don't allow labels
3340 on declarations; this might seem like a natural extension, but
3341 there would be a conflict between attributes on the label and
3342 prefix attributes on the declaration. ??? The syntax follows the
3343 old parser in requiring something after label declarations.
3344 Although they are erroneous if the labels declared aren't defined,
3345 is it useful for the syntax to be this way?
3357 c_parser_compound_statement (c_parser
*parser
)
3360 location_t brace_loc
;
3361 brace_loc
= c_parser_peek_token (parser
)->location
;
3362 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3364 /* Ensure a scope is entered and left anyway to avoid confusion
3365 if we have just prepared to enter a function body. */
3366 stmt
= c_begin_compound_stmt (true);
3367 c_end_compound_stmt (brace_loc
, stmt
, true);
3368 return error_mark_node
;
3370 stmt
= c_begin_compound_stmt (true);
3371 c_parser_compound_statement_nostart (parser
);
3372 return c_end_compound_stmt (brace_loc
, stmt
, true);
3375 /* Parse a compound statement except for the opening brace. This is
3376 used for parsing both compound statements and statement expressions
3377 (which follow different paths to handling the opening). */
3380 c_parser_compound_statement_nostart (c_parser
*parser
)
3382 bool last_stmt
= false;
3383 bool last_label
= false;
3384 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3385 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3386 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3388 c_parser_consume_token (parser
);
3391 mark_valid_location_for_stdc_pragma (true);
3392 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3394 /* Read zero or more forward-declarations for labels that nested
3395 functions can jump to. */
3396 mark_valid_location_for_stdc_pragma (false);
3397 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3399 label_loc
= c_parser_peek_token (parser
)->location
;
3400 c_parser_consume_token (parser
);
3401 /* Any identifiers, including those declared as type names,
3406 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3408 c_parser_error (parser
, "expected identifier");
3412 = declare_label (c_parser_peek_token (parser
)->value
);
3413 C_DECLARED_LABEL_FLAG (label
) = 1;
3414 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3415 c_parser_consume_token (parser
);
3416 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3417 c_parser_consume_token (parser
);
3421 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3423 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3425 /* We must now have at least one statement, label or declaration. */
3426 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3428 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3429 c_parser_error (parser
, "expected declaration or statement");
3430 c_parser_consume_token (parser
);
3433 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3435 location_t loc
= c_parser_peek_token (parser
)->location
;
3436 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3437 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3438 || (c_parser_next_token_is (parser
, CPP_NAME
)
3439 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3441 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3442 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3444 label_loc
= c_parser_peek_token (parser
)->location
;
3447 mark_valid_location_for_stdc_pragma (false);
3448 c_parser_label (parser
);
3450 else if (!last_label
3451 && c_parser_next_token_starts_declspecs (parser
))
3454 mark_valid_location_for_stdc_pragma (false);
3455 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3458 (pedantic
&& !flag_isoc99
)
3460 : OPT_Wdeclaration_after_statement
,
3461 "ISO C90 forbids mixed declarations and code");
3464 else if (!last_label
3465 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3467 /* __extension__ can start a declaration, but is also an
3468 unary operator that can start an expression. Consume all
3469 but the last of a possible series of __extension__ to
3471 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3472 && (c_parser_peek_2nd_token (parser
)->keyword
3474 c_parser_consume_token (parser
);
3475 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3478 ext
= disable_extension_diagnostics ();
3479 c_parser_consume_token (parser
);
3481 mark_valid_location_for_stdc_pragma (false);
3482 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3483 /* Following the old parser, __extension__ does not
3484 disable this diagnostic. */
3485 restore_extension_diagnostics (ext
);
3487 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3489 : OPT_Wdeclaration_after_statement
,
3490 "ISO C90 forbids mixed declarations and code");
3496 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3498 /* External pragmas, and some omp pragmas, are not associated
3499 with regular c code, and so are not to be considered statements
3500 syntactically. This ensures that the user doesn't put them
3501 places that would turn into syntax errors if the directive
3503 if (c_parser_pragma (parser
, pragma_compound
))
3504 last_label
= false, last_stmt
= true;
3506 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3508 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3509 c_parser_error (parser
, "expected declaration or statement");
3512 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3514 if (parser
->in_if_block
)
3516 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3517 error_at (loc
, """expected %<}%> before %<else%>");
3522 error_at (loc
, "%<else%> without a previous %<if%>");
3523 c_parser_consume_token (parser
);
3532 mark_valid_location_for_stdc_pragma (false);
3533 c_parser_statement_after_labels (parser
);
3536 parser
->error
= false;
3539 error_at (label_loc
, "label at end of compound statement");
3540 c_parser_consume_token (parser
);
3541 /* Restore the value we started with. */
3542 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3545 /* Parse a label (C90 6.6.1, C99 6.8.1).
3548 identifier : attributes[opt]
3549 case constant-expression :
3555 case constant-expression ... constant-expression :
3557 The use of attributes on labels is a GNU extension. The syntax in
3558 GNU C accepts any expressions without commas, non-constant
3559 expressions being rejected later. */
3562 c_parser_label (c_parser
*parser
)
3564 location_t loc1
= c_parser_peek_token (parser
)->location
;
3565 tree label
= NULL_TREE
;
3566 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3569 c_parser_consume_token (parser
);
3570 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3571 if (c_parser_next_token_is (parser
, CPP_COLON
))
3573 c_parser_consume_token (parser
);
3574 label
= do_case (loc1
, exp1
, NULL_TREE
);
3576 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3578 c_parser_consume_token (parser
);
3579 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3580 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3581 label
= do_case (loc1
, exp1
, exp2
);
3584 c_parser_error (parser
, "expected %<:%> or %<...%>");
3586 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3588 c_parser_consume_token (parser
);
3589 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3590 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3594 tree name
= c_parser_peek_token (parser
)->value
;
3597 location_t loc2
= c_parser_peek_token (parser
)->location
;
3598 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3599 c_parser_consume_token (parser
);
3600 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3601 c_parser_consume_token (parser
);
3602 attrs
= c_parser_attributes (parser
);
3603 tlab
= define_label (loc2
, name
);
3606 decl_attributes (&tlab
, attrs
, 0);
3607 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
3612 if (c_parser_next_token_starts_declspecs (parser
)
3613 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3614 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3616 error_at (c_parser_peek_token (parser
)->location
,
3617 "a label can only be part of a statement and "
3618 "a declaration is not a statement");
3619 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3620 /*nested*/ true, /*empty_ok*/ false,
3621 /*start_attr_ok*/ true);
3626 /* Parse a statement (C90 6.6, C99 6.8).
3631 expression-statement
3639 expression-statement:
3642 selection-statement:
3646 iteration-statement:
3655 return expression[opt] ;
3668 objc-throw-statement
3669 objc-try-catch-statement
3670 objc-synchronized-statement
3672 objc-throw-statement:
3686 parallel-for-construct
3687 parallel-sections-construct
3694 parallel-directive structured-block
3697 for-directive iteration-statement
3700 sections-directive section-scope
3703 single-directive structured-block
3705 parallel-for-construct:
3706 parallel-for-directive iteration-statement
3708 parallel-sections-construct:
3709 parallel-sections-directive section-scope
3712 master-directive structured-block
3715 critical-directive structured-block
3718 atomic-directive expression-statement
3721 ordered-directive structured-block */
3724 c_parser_statement (c_parser
*parser
)
3726 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3727 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3728 || (c_parser_next_token_is (parser
, CPP_NAME
)
3729 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3730 c_parser_label (parser
);
3731 c_parser_statement_after_labels (parser
);
3734 /* Parse a statement, other than a labeled statement. */
3737 c_parser_statement_after_labels (c_parser
*parser
)
3739 location_t loc
= c_parser_peek_token (parser
)->location
;
3740 tree stmt
= NULL_TREE
;
3741 bool in_if_block
= parser
->in_if_block
;
3742 parser
->in_if_block
= false;
3743 switch (c_parser_peek_token (parser
)->type
)
3745 case CPP_OPEN_BRACE
:
3746 add_stmt (c_parser_compound_statement (parser
));
3749 switch (c_parser_peek_token (parser
)->keyword
)
3752 c_parser_if_statement (parser
);
3755 c_parser_switch_statement (parser
);
3758 c_parser_while_statement (parser
);
3761 c_parser_do_statement (parser
);
3764 c_parser_for_statement (parser
);
3767 c_parser_consume_token (parser
);
3768 if (c_parser_next_token_is (parser
, CPP_NAME
))
3770 stmt
= c_finish_goto_label (loc
,
3771 c_parser_peek_token (parser
)->value
);
3772 c_parser_consume_token (parser
);
3774 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3776 c_parser_consume_token (parser
);
3777 stmt
= c_finish_goto_ptr (loc
,
3778 c_parser_expression (parser
).value
);
3781 c_parser_error (parser
, "expected identifier or %<*%>");
3782 goto expect_semicolon
;
3784 c_parser_consume_token (parser
);
3785 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
3786 goto expect_semicolon
;
3788 c_parser_consume_token (parser
);
3789 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
3790 goto expect_semicolon
;
3792 c_parser_consume_token (parser
);
3793 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3795 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
3796 c_parser_consume_token (parser
);
3800 struct c_expr expr
= c_parser_expression_conv (parser
);
3801 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
3802 goto expect_semicolon
;
3806 stmt
= c_parser_asm_statement (parser
);
3809 gcc_assert (c_dialect_objc ());
3810 c_parser_consume_token (parser
);
3811 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3813 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
3814 c_parser_consume_token (parser
);
3818 tree expr
= c_parser_expression (parser
).value
;
3819 expr
= c_fully_fold (expr
, false, NULL
);
3820 stmt
= objc_build_throw_stmt (loc
, expr
);
3821 goto expect_semicolon
;
3825 gcc_assert (c_dialect_objc ());
3826 c_parser_objc_try_catch_statement (parser
);
3828 case RID_AT_SYNCHRONIZED
:
3829 gcc_assert (c_dialect_objc ());
3830 c_parser_objc_synchronized_statement (parser
);
3837 c_parser_consume_token (parser
);
3839 case CPP_CLOSE_PAREN
:
3840 case CPP_CLOSE_SQUARE
:
3841 /* Avoid infinite loop in error recovery:
3842 c_parser_skip_until_found stops at a closing nesting
3843 delimiter without consuming it, but here we need to consume
3844 it to proceed further. */
3845 c_parser_error (parser
, "expected statement");
3846 c_parser_consume_token (parser
);
3849 c_parser_pragma (parser
, pragma_stmt
);
3853 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
3855 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3858 /* Two cases cannot and do not have line numbers associated: If stmt
3859 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3860 cannot hold line numbers. But that's OK because the statement
3861 will either be changed to a MODIFY_EXPR during gimplification of
3862 the statement expr, or discarded. If stmt was compound, but
3863 without new variables, we will have skipped the creation of a
3864 BIND and will have a bare STATEMENT_LIST. But that's OK because
3865 (recursively) all of the component statements should already have
3866 line numbers assigned. ??? Can we discard no-op statements
3868 if (CAN_HAVE_LOCATION_P (stmt
)
3869 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
3870 SET_EXPR_LOCATION (stmt
, loc
);
3872 parser
->in_if_block
= in_if_block
;
3875 /* Parse the condition from an if, do, while or for statements. */
3878 c_parser_condition (c_parser
*parser
)
3880 location_t loc
= c_parser_peek_token (parser
)->location
;
3882 cond
= c_parser_expression_conv (parser
).value
;
3883 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3884 cond
= c_fully_fold (cond
, false, NULL
);
3885 if (warn_sequence_point
)
3886 verify_sequence_points (cond
);
3890 /* Parse a parenthesized condition from an if, do or while statement.
3896 c_parser_paren_condition (c_parser
*parser
)
3899 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3900 return error_mark_node
;
3901 cond
= c_parser_condition (parser
);
3902 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3906 /* Parse a statement which is a block in C99. */
3909 c_parser_c99_block_statement (c_parser
*parser
)
3911 tree block
= c_begin_compound_stmt (flag_isoc99
);
3912 location_t loc
= c_parser_peek_token (parser
)->location
;
3913 c_parser_statement (parser
);
3914 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
3917 /* Parse the body of an if statement. This is just parsing a
3918 statement but (a) it is a block in C99, (b) we track whether the
3919 body is an if statement for the sake of -Wparentheses warnings, (c)
3920 we handle an empty body specially for the sake of -Wempty-body
3921 warnings, and (d) we call parser_compound_statement directly
3922 because c_parser_statement_after_labels resets
3923 parser->in_if_block. */
3926 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3928 tree block
= c_begin_compound_stmt (flag_isoc99
);
3929 location_t body_loc
= c_parser_peek_token (parser
)->location
;
3930 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3931 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3932 || (c_parser_next_token_is (parser
, CPP_NAME
)
3933 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3934 c_parser_label (parser
);
3935 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3936 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3938 location_t loc
= c_parser_peek_token (parser
)->location
;
3939 add_stmt (build_empty_stmt (loc
));
3940 c_parser_consume_token (parser
);
3941 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3942 warning_at (loc
, OPT_Wempty_body
,
3943 "suggest braces around empty body in an %<if%> statement");
3945 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3946 add_stmt (c_parser_compound_statement (parser
));
3948 c_parser_statement_after_labels (parser
);
3949 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
3952 /* Parse the else body of an if statement. This is just parsing a
3953 statement but (a) it is a block in C99, (b) we handle an empty body
3954 specially for the sake of -Wempty-body warnings. */
3957 c_parser_else_body (c_parser
*parser
)
3959 location_t else_loc
= c_parser_peek_token (parser
)->location
;
3960 tree block
= c_begin_compound_stmt (flag_isoc99
);
3961 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3962 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3963 || (c_parser_next_token_is (parser
, CPP_NAME
)
3964 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3965 c_parser_label (parser
);
3966 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3968 location_t loc
= c_parser_peek_token (parser
)->location
;
3971 "suggest braces around empty body in an %<else%> statement");
3972 add_stmt (build_empty_stmt (loc
));
3973 c_parser_consume_token (parser
);
3976 c_parser_statement_after_labels (parser
);
3977 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
3980 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3983 if ( expression ) statement
3984 if ( expression ) statement else statement
3988 c_parser_if_statement (c_parser
*parser
)
3993 bool first_if
= false;
3994 tree first_body
, second_body
;
3997 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3998 c_parser_consume_token (parser
);
3999 block
= c_begin_compound_stmt (flag_isoc99
);
4000 loc
= c_parser_peek_token (parser
)->location
;
4001 cond
= c_parser_paren_condition (parser
);
4002 in_if_block
= parser
->in_if_block
;
4003 parser
->in_if_block
= true;
4004 first_body
= c_parser_if_body (parser
, &first_if
);
4005 parser
->in_if_block
= in_if_block
;
4006 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4008 c_parser_consume_token (parser
);
4009 second_body
= c_parser_else_body (parser
);
4012 second_body
= NULL_TREE
;
4013 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4014 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4017 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4020 switch (expression) statement
4024 c_parser_switch_statement (c_parser
*parser
)
4026 tree block
, expr
, body
, save_break
;
4027 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4028 location_t switch_cond_loc
;
4029 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4030 c_parser_consume_token (parser
);
4031 block
= c_begin_compound_stmt (flag_isoc99
);
4032 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4034 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4035 expr
= c_parser_expression (parser
).value
;
4036 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4040 switch_cond_loc
= UNKNOWN_LOCATION
;
4041 expr
= error_mark_node
;
4043 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4044 save_break
= c_break_label
;
4045 c_break_label
= NULL_TREE
;
4046 body
= c_parser_c99_block_statement (parser
);
4047 c_finish_case (body
);
4050 location_t here
= c_parser_peek_token (parser
)->location
;
4051 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4052 SET_EXPR_LOCATION (t
, here
);
4055 c_break_label
= save_break
;
4056 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4059 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4062 while (expression) statement
4066 c_parser_while_statement (c_parser
*parser
)
4068 tree block
, cond
, body
, save_break
, save_cont
;
4070 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4071 c_parser_consume_token (parser
);
4072 block
= c_begin_compound_stmt (flag_isoc99
);
4073 loc
= c_parser_peek_token (parser
)->location
;
4074 cond
= c_parser_paren_condition (parser
);
4075 save_break
= c_break_label
;
4076 c_break_label
= NULL_TREE
;
4077 save_cont
= c_cont_label
;
4078 c_cont_label
= NULL_TREE
;
4079 body
= c_parser_c99_block_statement (parser
);
4080 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4081 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4082 c_break_label
= save_break
;
4083 c_cont_label
= save_cont
;
4086 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4089 do statement while ( expression ) ;
4093 c_parser_do_statement (c_parser
*parser
)
4095 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4097 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4098 c_parser_consume_token (parser
);
4099 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4100 warning_at (c_parser_peek_token (parser
)->location
,
4102 "suggest braces around empty body in %<do%> statement");
4103 block
= c_begin_compound_stmt (flag_isoc99
);
4104 loc
= c_parser_peek_token (parser
)->location
;
4105 save_break
= c_break_label
;
4106 c_break_label
= NULL_TREE
;
4107 save_cont
= c_cont_label
;
4108 c_cont_label
= NULL_TREE
;
4109 body
= c_parser_c99_block_statement (parser
);
4110 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4111 new_break
= c_break_label
;
4112 c_break_label
= save_break
;
4113 new_cont
= c_cont_label
;
4114 c_cont_label
= save_cont
;
4115 cond
= c_parser_paren_condition (parser
);
4116 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4117 c_parser_skip_to_end_of_block_or_statement (parser
);
4118 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4119 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4122 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4125 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4126 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4128 The form with a declaration is new in C99.
4130 ??? In accordance with the old parser, the declaration may be a
4131 nested function, which is then rejected in check_for_loop_decls,
4132 but does it make any sense for this to be included in the grammar?
4133 Note in particular that the nested function does not include a
4134 trailing ';', whereas the "declaration" production includes one.
4135 Also, can we reject bad declarations earlier and cheaper than
4136 check_for_loop_decls? */
4139 c_parser_for_statement (c_parser
*parser
)
4141 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4142 location_t loc
= c_parser_peek_token (parser
)->location
;
4143 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4144 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4145 c_parser_consume_token (parser
);
4146 block
= c_begin_compound_stmt (flag_isoc99
);
4147 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4149 /* Parse the initialization declaration or expression. */
4150 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4152 c_parser_consume_token (parser
);
4153 c_finish_expr_stmt (loc
, NULL_TREE
);
4155 else if (c_parser_next_token_starts_declspecs (parser
))
4157 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4158 check_for_loop_decls (for_loc
);
4160 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4162 /* __extension__ can start a declaration, but is also an
4163 unary operator that can start an expression. Consume all
4164 but the last of a possible series of __extension__ to
4166 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4167 && (c_parser_peek_2nd_token (parser
)->keyword
4169 c_parser_consume_token (parser
);
4170 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4173 ext
= disable_extension_diagnostics ();
4174 c_parser_consume_token (parser
);
4175 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4176 restore_extension_diagnostics (ext
);
4177 check_for_loop_decls (for_loc
);
4185 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
4186 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4188 /* Parse the loop condition. */
4189 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4191 c_parser_consume_token (parser
);
4196 cond
= c_parser_condition (parser
);
4197 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4199 /* Parse the increment expression. */
4200 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4201 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4203 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4204 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4208 cond
= error_mark_node
;
4209 incr
= error_mark_node
;
4211 save_break
= c_break_label
;
4212 c_break_label
= NULL_TREE
;
4213 save_cont
= c_cont_label
;
4214 c_cont_label
= NULL_TREE
;
4215 body
= c_parser_c99_block_statement (parser
);
4216 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4217 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4218 c_break_label
= save_break
;
4219 c_cont_label
= save_cont
;
4222 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4223 statement with inputs, outputs, clobbers, and volatile tag
4227 asm type-qualifier[opt] ( asm-argument ) ;
4231 asm-string-literal : asm-operands[opt]
4232 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4233 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4235 Qualifiers other than volatile are accepted in the syntax but
4239 c_parser_asm_statement (c_parser
*parser
)
4241 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4243 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4244 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4245 c_parser_consume_token (parser
);
4246 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4248 quals
= c_parser_peek_token (parser
)->value
;
4249 c_parser_consume_token (parser
);
4251 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4252 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4254 warning_at (c_parser_peek_token (parser
)->location
,
4256 "%E qualifier ignored on asm",
4257 c_parser_peek_token (parser
)->value
);
4259 c_parser_consume_token (parser
);
4263 /* ??? Follow the C++ parser rather than using the
4264 lex_untranslated_string kludge. */
4265 parser
->lex_untranslated_string
= true;
4266 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4268 parser
->lex_untranslated_string
= false;
4271 str
= c_parser_asm_string_literal (parser
);
4272 if (str
== NULL_TREE
)
4274 parser
->lex_untranslated_string
= false;
4275 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4278 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4281 outputs
= NULL_TREE
;
4283 clobbers
= NULL_TREE
;
4286 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4288 parser
->lex_untranslated_string
= false;
4289 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4293 /* Parse outputs. */
4294 if (c_parser_next_token_is (parser
, CPP_COLON
)
4295 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4296 outputs
= NULL_TREE
;
4298 outputs
= c_parser_asm_operands (parser
, false);
4299 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4302 clobbers
= NULL_TREE
;
4305 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4307 parser
->lex_untranslated_string
= false;
4308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4312 if (c_parser_next_token_is (parser
, CPP_COLON
)
4313 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4316 inputs
= c_parser_asm_operands (parser
, true);
4317 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4319 clobbers
= NULL_TREE
;
4322 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4324 parser
->lex_untranslated_string
= false;
4325 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4328 /* Parse clobbers. */
4329 clobbers
= c_parser_asm_clobbers (parser
);
4331 parser
->lex_untranslated_string
= false;
4332 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4337 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4338 c_parser_skip_to_end_of_block_or_statement (parser
);
4339 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4344 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4345 not outputs), apply the default conversion of functions and arrays
4350 asm-operands , asm-operand
4353 asm-string-literal ( expression )
4354 [ identifier ] asm-string-literal ( expression )
4358 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4360 tree list
= NULL_TREE
;
4366 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4368 c_parser_consume_token (parser
);
4369 if (c_parser_next_token_is (parser
, CPP_NAME
))
4371 tree id
= c_parser_peek_token (parser
)->value
;
4372 c_parser_consume_token (parser
);
4373 name
= build_string (IDENTIFIER_LENGTH (id
),
4374 IDENTIFIER_POINTER (id
));
4378 c_parser_error (parser
, "expected identifier");
4379 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4382 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4387 str
= c_parser_asm_string_literal (parser
);
4388 if (str
== NULL_TREE
)
4390 parser
->lex_untranslated_string
= false;
4391 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4393 parser
->lex_untranslated_string
= true;
4396 loc
= c_parser_peek_token (parser
)->location
;
4397 expr
= c_parser_expression (parser
);
4399 expr
= default_function_array_conversion (loc
, expr
);
4400 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4401 parser
->lex_untranslated_string
= true;
4402 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4407 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4409 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4410 c_parser_consume_token (parser
);
4417 /* Parse asm clobbers, a GNU extension.
4421 asm-clobbers , asm-string-literal
4425 c_parser_asm_clobbers (c_parser
*parser
)
4427 tree list
= NULL_TREE
;
4430 tree str
= c_parser_asm_string_literal (parser
);
4432 list
= tree_cons (NULL_TREE
, str
, list
);
4435 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4436 c_parser_consume_token (parser
);
4443 /* Parse an expression other than a compound expression; that is, an
4444 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4445 NULL then it is an Objective-C message expression which is the
4446 primary-expression starting the expression as an initializer.
4448 assignment-expression:
4449 conditional-expression
4450 unary-expression assignment-operator assignment-expression
4452 assignment-operator: one of
4453 = *= /= %= += -= <<= >>= &= ^= |=
4455 In GNU C we accept any conditional expression on the LHS and
4456 diagnose the invalid lvalue rather than producing a syntax
4459 static struct c_expr
4460 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4462 struct c_expr lhs
, rhs
, ret
;
4463 enum tree_code code
;
4464 location_t op_location
, exp_location
;
4465 gcc_assert (!after
|| c_dialect_objc ());
4466 lhs
= c_parser_conditional_expression (parser
, after
);
4467 op_location
= c_parser_peek_token (parser
)->location
;
4468 switch (c_parser_peek_token (parser
)->type
)
4477 code
= TRUNC_DIV_EXPR
;
4480 code
= TRUNC_MOD_EXPR
;
4495 code
= BIT_AND_EXPR
;
4498 code
= BIT_XOR_EXPR
;
4501 code
= BIT_IOR_EXPR
;
4506 c_parser_consume_token (parser
);
4507 exp_location
= c_parser_peek_token (parser
)->location
;
4508 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4509 rhs
= default_function_array_conversion (exp_location
, rhs
);
4510 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4511 code
, exp_location
, rhs
.value
,
4513 if (code
== NOP_EXPR
)
4514 ret
.original_code
= MODIFY_EXPR
;
4517 TREE_NO_WARNING (ret
.value
) = 1;
4518 ret
.original_code
= ERROR_MARK
;
4520 ret
.original_type
= NULL
;
4524 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4525 is not NULL then it is an Objective-C message expression which is
4526 the primary-expression starting the expression as an initializer.
4528 conditional-expression:
4529 logical-OR-expression
4530 logical-OR-expression ? expression : conditional-expression
4534 conditional-expression:
4535 logical-OR-expression ? : conditional-expression
4538 static struct c_expr
4539 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4541 struct c_expr cond
, exp1
, exp2
, ret
;
4542 location_t cond_loc
, colon_loc
;
4544 gcc_assert (!after
|| c_dialect_objc ());
4546 cond
= c_parser_binary_expression (parser
, after
);
4548 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4550 cond_loc
= c_parser_peek_token (parser
)->location
;
4551 cond
= default_function_array_conversion (cond_loc
, cond
);
4552 c_parser_consume_token (parser
);
4553 if (c_parser_next_token_is (parser
, CPP_COLON
))
4555 tree eptype
= NULL_TREE
;
4556 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4557 "ISO C forbids omitting the middle term of a ?: expression");
4558 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4560 eptype
= TREE_TYPE (cond
.value
);
4561 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4563 /* Make sure first operand is calculated only once. */
4564 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4566 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4567 exp1
.original_type
= NULL
;
4568 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4569 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
4574 = c_objc_common_truthvalue_conversion
4575 (cond_loc
, default_conversion (cond
.value
));
4576 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
4577 exp1
= c_parser_expression_conv (parser
);
4578 c_inhibit_evaluation_warnings
+=
4579 ((cond
.value
== truthvalue_true_node
)
4580 - (cond
.value
== truthvalue_false_node
));
4583 colon_loc
= c_parser_peek_token (parser
)->location
;
4584 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4586 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4587 ret
.value
= error_mark_node
;
4588 ret
.original_code
= ERROR_MARK
;
4589 ret
.original_type
= NULL
;
4593 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
4594 exp2
= c_parser_conditional_expression (parser
, NULL
);
4595 exp2
= default_function_array_conversion (exp2_loc
, exp2
);
4597 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4598 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
4599 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4600 exp1
.value
, exp1
.original_type
,
4601 exp2
.value
, exp2
.original_type
);
4602 ret
.original_code
= ERROR_MARK
;
4603 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4604 ret
.original_type
= NULL
;
4609 /* If both sides are enum type, the default conversion will have
4610 made the type of the result be an integer type. We want to
4611 remember the enum types we started with. */
4612 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4613 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4614 ret
.original_type
= ((t1
!= error_mark_node
4615 && t2
!= error_mark_node
4616 && (TYPE_MAIN_VARIANT (t1
)
4617 == TYPE_MAIN_VARIANT (t2
)))
4624 /* Parse a binary expression; that is, a logical-OR-expression (C90
4625 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4626 an Objective-C message expression which is the primary-expression
4627 starting the expression as an initializer.
4629 multiplicative-expression:
4631 multiplicative-expression * cast-expression
4632 multiplicative-expression / cast-expression
4633 multiplicative-expression % cast-expression
4635 additive-expression:
4636 multiplicative-expression
4637 additive-expression + multiplicative-expression
4638 additive-expression - multiplicative-expression
4642 shift-expression << additive-expression
4643 shift-expression >> additive-expression
4645 relational-expression:
4647 relational-expression < shift-expression
4648 relational-expression > shift-expression
4649 relational-expression <= shift-expression
4650 relational-expression >= shift-expression
4652 equality-expression:
4653 relational-expression
4654 equality-expression == relational-expression
4655 equality-expression != relational-expression
4659 AND-expression & equality-expression
4661 exclusive-OR-expression:
4663 exclusive-OR-expression ^ AND-expression
4665 inclusive-OR-expression:
4666 exclusive-OR-expression
4667 inclusive-OR-expression | exclusive-OR-expression
4669 logical-AND-expression:
4670 inclusive-OR-expression
4671 logical-AND-expression && inclusive-OR-expression
4673 logical-OR-expression:
4674 logical-AND-expression
4675 logical-OR-expression || logical-AND-expression
4678 static struct c_expr
4679 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4681 /* A binary expression is parsed using operator-precedence parsing,
4682 with the operands being cast expressions. All the binary
4683 operators are left-associative. Thus a binary expression is of
4686 E0 op1 E1 op2 E2 ...
4688 which we represent on a stack. On the stack, the precedence
4689 levels are strictly increasing. When a new operator is
4690 encountered of higher precedence than that at the top of the
4691 stack, it is pushed; its LHS is the top expression, and its RHS
4692 is everything parsed until it is popped. When a new operator is
4693 encountered with precedence less than or equal to that at the top
4694 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4695 by the result of the operation until the operator at the top of
4696 the stack has lower precedence than the new operator or there is
4697 only one element on the stack; then the top expression is the LHS
4698 of the new operator. In the case of logical AND and OR
4699 expressions, we also need to adjust c_inhibit_evaluation_warnings
4700 as appropriate when the operators are pushed and popped. */
4702 /* The precedence levels, where 0 is a dummy lowest level used for
4703 the bottom of the stack. */
4719 /* The expression at this stack level. */
4721 /* The precedence of the operator on its left, PREC_NONE at the
4722 bottom of the stack. */
4724 /* The operation on its left. */
4726 /* The source location of this operation. */
4730 /* Location of the binary operator. */
4731 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4734 switch (stack[sp].op) \
4736 case TRUTH_ANDIF_EXPR: \
4737 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4738 == truthvalue_false_node); \
4740 case TRUTH_ORIF_EXPR: \
4741 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
4742 == truthvalue_true_node); \
4747 stack[sp - 1].expr \
4748 = default_function_array_conversion (stack[sp - 1].loc, \
4749 stack[sp - 1].expr); \
4751 = default_function_array_conversion (stack[sp].loc, stack[sp].expr); \
4752 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4754 stack[sp - 1].expr, \
4758 gcc_assert (!after
|| c_dialect_objc ());
4759 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4760 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4761 stack
[0].prec
= PREC_NONE
;
4766 enum tree_code ocode
;
4769 switch (c_parser_peek_token (parser
)->type
)
4777 ocode
= TRUNC_DIV_EXPR
;
4781 ocode
= TRUNC_MOD_EXPR
;
4793 ocode
= LSHIFT_EXPR
;
4797 ocode
= RSHIFT_EXPR
;
4811 case CPP_GREATER_EQ
:
4824 oprec
= PREC_BITAND
;
4825 ocode
= BIT_AND_EXPR
;
4828 oprec
= PREC_BITXOR
;
4829 ocode
= BIT_XOR_EXPR
;
4833 ocode
= BIT_IOR_EXPR
;
4836 oprec
= PREC_LOGAND
;
4837 ocode
= TRUTH_ANDIF_EXPR
;
4841 ocode
= TRUTH_ORIF_EXPR
;
4844 /* Not a binary operator, so end of the binary
4848 binary_loc
= c_parser_peek_token (parser
)->location
;
4849 c_parser_consume_token (parser
);
4850 while (oprec
<= stack
[sp
].prec
)
4854 case TRUTH_ANDIF_EXPR
:
4856 = default_function_array_conversion (stack
[sp
].loc
,
4858 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4859 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4860 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4861 == truthvalue_false_node
);
4863 case TRUTH_ORIF_EXPR
:
4865 = default_function_array_conversion (stack
[sp
].loc
,
4867 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4868 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4869 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
4870 == truthvalue_true_node
);
4876 stack
[sp
].loc
= binary_loc
;
4877 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4878 stack
[sp
].prec
= oprec
;
4879 stack
[sp
].op
= ocode
;
4880 stack
[sp
].loc
= binary_loc
;
4885 return stack
[0].expr
;
4889 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4890 NULL then it is an Objective-C message expression which is the
4891 primary-expression starting the expression as an initializer.
4895 ( type-name ) unary-expression
4898 static struct c_expr
4899 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4901 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
4902 gcc_assert (!after
|| c_dialect_objc ());
4904 return c_parser_postfix_expression_after_primary (parser
,
4906 /* If the expression begins with a parenthesized type name, it may
4907 be either a cast or a compound literal; we need to see whether
4908 the next character is '{' to tell the difference. If not, it is
4909 an unary expression. */
4910 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4911 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4913 struct c_type_name
*type_name
;
4916 c_parser_consume_token (parser
);
4917 type_name
= c_parser_type_name (parser
);
4918 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4919 if (type_name
== NULL
)
4921 ret
.value
= error_mark_node
;
4922 ret
.original_code
= ERROR_MARK
;
4923 ret
.original_type
= NULL
;
4927 /* Save casted types in the function's used types hash table. */
4928 used_types_insert (type_name
->specs
->type
);
4930 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4931 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
4934 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
4935 expr
= c_parser_cast_expression (parser
, NULL
);
4936 expr
= default_function_array_conversion (expr_loc
, expr
);
4938 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
4939 ret
.original_code
= ERROR_MARK
;
4940 ret
.original_type
= NULL
;
4944 return c_parser_unary_expression (parser
);
4947 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4953 unary-operator cast-expression
4954 sizeof unary-expression
4955 sizeof ( type-name )
4957 unary-operator: one of
4963 __alignof__ unary-expression
4964 __alignof__ ( type-name )
4967 unary-operator: one of
4968 __extension__ __real__ __imag__
4970 In addition, the GNU syntax treats ++ and -- as unary operators, so
4971 they may be applied to cast expressions with errors for non-lvalues
4974 static struct c_expr
4975 c_parser_unary_expression (c_parser
*parser
)
4978 struct c_expr ret
, op
;
4979 location_t op_loc
= c_parser_peek_token (parser
)->location
;
4981 ret
.original_code
= ERROR_MARK
;
4982 ret
.original_type
= NULL
;
4983 switch (c_parser_peek_token (parser
)->type
)
4986 c_parser_consume_token (parser
);
4987 exp_loc
= c_parser_peek_token (parser
)->location
;
4988 op
= c_parser_cast_expression (parser
, NULL
);
4989 op
= default_function_array_conversion (exp_loc
, op
);
4990 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
4991 case CPP_MINUS_MINUS
:
4992 c_parser_consume_token (parser
);
4993 exp_loc
= c_parser_peek_token (parser
)->location
;
4994 op
= c_parser_cast_expression (parser
, NULL
);
4995 op
= default_function_array_conversion (exp_loc
, op
);
4996 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
4998 c_parser_consume_token (parser
);
4999 return parser_build_unary_op (op_loc
, ADDR_EXPR
,
5000 c_parser_cast_expression (parser
, NULL
));
5002 c_parser_consume_token (parser
);
5003 exp_loc
= c_parser_peek_token (parser
)->location
;
5004 op
= c_parser_cast_expression (parser
, NULL
);
5005 op
= default_function_array_conversion (exp_loc
, op
);
5006 ret
.value
= build_indirect_ref (op_loc
, op
.value
, "unary *");
5009 if (!c_dialect_objc () && !in_system_header
)
5012 "traditional C rejects the unary plus operator");
5013 c_parser_consume_token (parser
);
5014 exp_loc
= c_parser_peek_token (parser
)->location
;
5015 op
= c_parser_cast_expression (parser
, NULL
);
5016 op
= default_function_array_conversion (exp_loc
, op
);
5017 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5019 c_parser_consume_token (parser
);
5020 exp_loc
= c_parser_peek_token (parser
)->location
;
5021 op
= c_parser_cast_expression (parser
, NULL
);
5022 op
= default_function_array_conversion (exp_loc
, op
);
5023 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5025 c_parser_consume_token (parser
);
5026 exp_loc
= c_parser_peek_token (parser
)->location
;
5027 op
= c_parser_cast_expression (parser
, NULL
);
5028 op
= default_function_array_conversion (exp_loc
, op
);
5029 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5031 c_parser_consume_token (parser
);
5032 exp_loc
= c_parser_peek_token (parser
)->location
;
5033 op
= c_parser_cast_expression (parser
, NULL
);
5034 op
= default_function_array_conversion (exp_loc
, op
);
5035 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5037 /* Refer to the address of a label as a pointer. */
5038 c_parser_consume_token (parser
);
5039 if (c_parser_next_token_is (parser
, CPP_NAME
))
5041 ret
.value
= finish_label_address_expr
5042 (c_parser_peek_token (parser
)->value
, op_loc
);
5043 c_parser_consume_token (parser
);
5047 c_parser_error (parser
, "expected identifier");
5048 ret
.value
= error_mark_node
;
5052 switch (c_parser_peek_token (parser
)->keyword
)
5055 return c_parser_sizeof_expression (parser
);
5057 return c_parser_alignof_expression (parser
);
5059 c_parser_consume_token (parser
);
5060 ext
= disable_extension_diagnostics ();
5061 ret
= c_parser_cast_expression (parser
, NULL
);
5062 restore_extension_diagnostics (ext
);
5065 c_parser_consume_token (parser
);
5066 exp_loc
= c_parser_peek_token (parser
)->location
;
5067 op
= c_parser_cast_expression (parser
, NULL
);
5068 op
= default_function_array_conversion (exp_loc
, op
);
5069 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5071 c_parser_consume_token (parser
);
5072 exp_loc
= c_parser_peek_token (parser
)->location
;
5073 op
= c_parser_cast_expression (parser
, NULL
);
5074 op
= default_function_array_conversion (exp_loc
, op
);
5075 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5077 return c_parser_postfix_expression (parser
);
5080 return c_parser_postfix_expression (parser
);
5084 /* Parse a sizeof expression. */
5086 static struct c_expr
5087 c_parser_sizeof_expression (c_parser
*parser
)
5090 location_t expr_loc
;
5091 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5092 c_parser_consume_token (parser
);
5093 c_inhibit_evaluation_warnings
++;
5095 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5096 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5098 /* Either sizeof ( type-name ) or sizeof unary-expression
5099 starting with a compound literal. */
5100 struct c_type_name
*type_name
;
5101 c_parser_consume_token (parser
);
5102 expr_loc
= c_parser_peek_token (parser
)->location
;
5103 type_name
= c_parser_type_name (parser
);
5104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5105 if (type_name
== NULL
)
5108 c_inhibit_evaluation_warnings
--;
5110 ret
.value
= error_mark_node
;
5111 ret
.original_code
= ERROR_MARK
;
5112 ret
.original_type
= NULL
;
5115 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5117 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5122 /* sizeof ( type-name ). */
5123 c_inhibit_evaluation_warnings
--;
5125 return c_expr_sizeof_type (expr_loc
, type_name
);
5129 expr_loc
= c_parser_peek_token (parser
)->location
;
5130 expr
= c_parser_unary_expression (parser
);
5132 c_inhibit_evaluation_warnings
--;
5134 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5135 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5136 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5137 return c_expr_sizeof_expr (expr_loc
, expr
);
5141 /* Parse an alignof expression. */
5143 static struct c_expr
5144 c_parser_alignof_expression (c_parser
*parser
)
5147 location_t loc
= c_parser_peek_token (parser
)->location
;
5148 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5149 c_parser_consume_token (parser
);
5150 c_inhibit_evaluation_warnings
++;
5152 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5153 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5155 /* Either __alignof__ ( type-name ) or __alignof__
5156 unary-expression starting with a compound literal. */
5158 struct c_type_name
*type_name
;
5160 c_parser_consume_token (parser
);
5161 loc
= c_parser_peek_token (parser
)->location
;
5162 type_name
= c_parser_type_name (parser
);
5163 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5164 if (type_name
== NULL
)
5167 c_inhibit_evaluation_warnings
--;
5169 ret
.value
= error_mark_node
;
5170 ret
.original_code
= ERROR_MARK
;
5171 ret
.original_type
= NULL
;
5174 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5176 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5181 /* alignof ( type-name ). */
5182 c_inhibit_evaluation_warnings
--;
5184 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5185 ret
.original_code
= ERROR_MARK
;
5186 ret
.original_type
= NULL
;
5192 expr
= c_parser_unary_expression (parser
);
5194 c_inhibit_evaluation_warnings
--;
5196 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5197 ret
.original_code
= ERROR_MARK
;
5198 ret
.original_type
= NULL
;
5203 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5207 postfix-expression [ expression ]
5208 postfix-expression ( argument-expression-list[opt] )
5209 postfix-expression . identifier
5210 postfix-expression -> identifier
5211 postfix-expression ++
5212 postfix-expression --
5213 ( type-name ) { initializer-list }
5214 ( type-name ) { initializer-list , }
5216 argument-expression-list:
5218 argument-expression-list , argument-expression
5230 (treated as a keyword in GNU C)
5233 ( compound-statement )
5234 __builtin_va_arg ( assignment-expression , type-name )
5235 __builtin_offsetof ( type-name , offsetof-member-designator )
5236 __builtin_choose_expr ( assignment-expression ,
5237 assignment-expression ,
5238 assignment-expression )
5239 __builtin_types_compatible_p ( type-name , type-name )
5241 offsetof-member-designator:
5243 offsetof-member-designator . identifier
5244 offsetof-member-designator [ expression ]
5249 [ objc-receiver objc-message-args ]
5250 @selector ( objc-selector-arg )
5251 @protocol ( identifier )
5252 @encode ( type-name )
5256 static struct c_expr
5257 c_parser_postfix_expression (c_parser
*parser
)
5259 struct c_expr expr
, e1
, e2
, e3
;
5260 struct c_type_name
*t1
, *t2
;
5261 location_t loc
= c_parser_peek_token (parser
)->location
;;
5262 expr
.original_code
= ERROR_MARK
;
5263 expr
.original_type
= NULL
;
5264 switch (c_parser_peek_token (parser
)->type
)
5267 expr
.value
= c_parser_peek_token (parser
)->value
;
5268 loc
= c_parser_peek_token (parser
)->location
;
5269 c_parser_consume_token (parser
);
5270 if (TREE_CODE (expr
.value
) == FIXED_CST
5271 && !targetm
.fixed_point_supported_p ())
5273 error_at (loc
, "fixed-point types not supported for this target");
5274 expr
.value
= error_mark_node
;
5281 expr
.value
= c_parser_peek_token (parser
)->value
;
5282 c_parser_consume_token (parser
);
5288 expr
.value
= c_parser_peek_token (parser
)->value
;
5289 expr
.original_code
= STRING_CST
;
5290 c_parser_consume_token (parser
);
5292 case CPP_OBJC_STRING
:
5293 gcc_assert (c_dialect_objc ());
5295 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5296 c_parser_consume_token (parser
);
5299 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5301 c_parser_error (parser
, "expected expression");
5302 expr
.value
= error_mark_node
;
5306 tree id
= c_parser_peek_token (parser
)->value
;
5307 c_parser_consume_token (parser
);
5308 expr
.value
= build_external_ref (loc
, id
,
5309 (c_parser_peek_token (parser
)->type
5311 &expr
.original_type
);
5314 case CPP_OPEN_PAREN
:
5315 /* A parenthesized expression, statement expression or compound
5317 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5319 /* A statement expression. */
5321 location_t brace_loc
;
5322 c_parser_consume_token (parser
);
5323 brace_loc
= c_parser_peek_token (parser
)->location
;
5324 c_parser_consume_token (parser
);
5325 if (cur_stmt_list
== NULL
)
5327 error_at (loc
, "braced-group within expression allowed "
5328 "only inside a function");
5329 parser
->error
= true;
5330 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5331 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5332 expr
.value
= error_mark_node
;
5335 stmt
= c_begin_stmt_expr ();
5336 c_parser_compound_statement_nostart (parser
);
5337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5339 pedwarn (loc
, OPT_pedantic
,
5340 "ISO C forbids braced-groups within expressions");
5341 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5343 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5345 /* A compound literal. ??? Can we actually get here rather
5346 than going directly to
5347 c_parser_postfix_expression_after_paren_type from
5350 struct c_type_name
*type_name
;
5351 c_parser_consume_token (parser
);
5352 loc
= c_parser_peek_token (parser
)->location
;
5353 type_name
= c_parser_type_name (parser
);
5354 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5356 if (type_name
== NULL
)
5358 expr
.value
= error_mark_node
;
5361 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5367 /* A parenthesized expression. */
5368 c_parser_consume_token (parser
);
5369 expr
= c_parser_expression (parser
);
5370 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5371 TREE_NO_WARNING (expr
.value
) = 1;
5372 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5373 expr
.original_code
= ERROR_MARK
;
5374 /* Don't change EXPR.ORIGINAL_TYPE. */
5375 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5380 switch (c_parser_peek_token (parser
)->keyword
)
5382 case RID_FUNCTION_NAME
:
5383 case RID_PRETTY_FUNCTION_NAME
:
5384 case RID_C99_FUNCTION_NAME
:
5385 expr
.value
= fname_decl (loc
,
5386 c_parser_peek_token (parser
)->keyword
,
5387 c_parser_peek_token (parser
)->value
);
5388 c_parser_consume_token (parser
);
5391 c_parser_consume_token (parser
);
5392 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5394 expr
.value
= error_mark_node
;
5397 e1
= c_parser_expr_no_commas (parser
, NULL
);
5398 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5399 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5401 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5402 expr
.value
= error_mark_node
;
5405 loc
= c_parser_peek_token (parser
)->location
;
5406 t1
= c_parser_type_name (parser
);
5407 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5411 expr
.value
= error_mark_node
;
5415 tree type_expr
= NULL_TREE
;
5416 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5417 groktypename (t1
, &type_expr
, NULL
));
5420 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5421 TREE_TYPE (expr
.value
), type_expr
,
5423 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5428 c_parser_consume_token (parser
);
5429 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5431 expr
.value
= error_mark_node
;
5434 t1
= c_parser_type_name (parser
);
5437 expr
.value
= error_mark_node
;
5440 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5443 expr
.value
= error_mark_node
;
5447 tree type
= groktypename (t1
, NULL
, NULL
);
5449 if (type
== error_mark_node
)
5450 offsetof_ref
= error_mark_node
;
5453 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5454 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5456 /* Parse the second argument to __builtin_offsetof. We
5457 must have one identifier, and beyond that we want to
5458 accept sub structure and sub array references. */
5459 if (c_parser_next_token_is (parser
, CPP_NAME
))
5461 offsetof_ref
= build_component_ref
5462 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5463 c_parser_consume_token (parser
);
5464 while (c_parser_next_token_is (parser
, CPP_DOT
)
5465 || c_parser_next_token_is (parser
,
5467 || c_parser_next_token_is (parser
,
5470 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5472 loc
= c_parser_peek_token (parser
)->location
;
5473 offsetof_ref
= build_array_ref (loc
,
5478 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5481 c_parser_consume_token (parser
);
5482 if (c_parser_next_token_is_not (parser
,
5485 c_parser_error (parser
, "expected identifier");
5488 offsetof_ref
= build_component_ref
5490 c_parser_peek_token (parser
)->value
);
5491 c_parser_consume_token (parser
);
5496 loc
= c_parser_peek_token (parser
)->location
;
5497 c_parser_consume_token (parser
);
5498 idx
= c_parser_expression (parser
).value
;
5499 idx
= c_fully_fold (idx
, false, NULL
);
5500 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5502 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5507 c_parser_error (parser
, "expected identifier");
5508 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5510 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5513 case RID_CHOOSE_EXPR
:
5514 c_parser_consume_token (parser
);
5515 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5517 expr
.value
= error_mark_node
;
5520 loc
= c_parser_peek_token (parser
)->location
;
5521 e1
= c_parser_expr_no_commas (parser
, NULL
);
5522 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5524 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5525 expr
.value
= error_mark_node
;
5528 e2
= c_parser_expr_no_commas (parser
, NULL
);
5529 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5531 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5532 expr
.value
= error_mark_node
;
5535 e3
= c_parser_expr_no_commas (parser
, NULL
);
5536 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5542 if (TREE_CODE (c
) != INTEGER_CST
5543 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5545 "first argument to %<__builtin_choose_expr%> not"
5547 constant_expression_warning (c
);
5548 expr
= integer_zerop (c
) ? e3
: e2
;
5551 case RID_TYPES_COMPATIBLE_P
:
5552 c_parser_consume_token (parser
);
5553 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5555 expr
.value
= error_mark_node
;
5558 t1
= c_parser_type_name (parser
);
5561 expr
.value
= error_mark_node
;
5564 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5566 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5567 expr
.value
= error_mark_node
;
5570 t2
= c_parser_type_name (parser
);
5573 expr
.value
= error_mark_node
;
5576 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5581 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5582 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5584 expr
.value
= comptypes (e1
, e2
)
5585 ? build_int_cst (NULL_TREE
, 1)
5586 : build_int_cst (NULL_TREE
, 0);
5589 case RID_AT_SELECTOR
:
5590 gcc_assert (c_dialect_objc ());
5591 c_parser_consume_token (parser
);
5592 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5594 expr
.value
= error_mark_node
;
5598 tree sel
= c_parser_objc_selector_arg (parser
);
5599 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5601 expr
.value
= objc_build_selector_expr (loc
, sel
);
5604 case RID_AT_PROTOCOL
:
5605 gcc_assert (c_dialect_objc ());
5606 c_parser_consume_token (parser
);
5607 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5609 expr
.value
= error_mark_node
;
5612 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5614 c_parser_error (parser
, "expected identifier");
5615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5616 expr
.value
= error_mark_node
;
5620 tree id
= c_parser_peek_token (parser
)->value
;
5621 c_parser_consume_token (parser
);
5622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5624 expr
.value
= objc_build_protocol_expr (id
);
5628 /* Extension to support C-structures in the archiver. */
5629 gcc_assert (c_dialect_objc ());
5630 c_parser_consume_token (parser
);
5631 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5633 expr
.value
= error_mark_node
;
5636 t1
= c_parser_type_name (parser
);
5639 expr
.value
= error_mark_node
;
5640 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5643 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5646 tree type
= groktypename (t1
, NULL
, NULL
);
5647 expr
.value
= objc_build_encode_expr (type
);
5651 c_parser_error (parser
, "expected expression");
5652 expr
.value
= error_mark_node
;
5656 case CPP_OPEN_SQUARE
:
5657 if (c_dialect_objc ())
5659 tree receiver
, args
;
5660 c_parser_consume_token (parser
);
5661 receiver
= c_parser_objc_receiver (parser
);
5662 args
= c_parser_objc_message_args (parser
);
5663 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5665 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5669 /* Else fall through to report error. */
5671 c_parser_error (parser
, "expected expression");
5672 expr
.value
= error_mark_node
;
5675 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
5678 /* Parse a postfix expression after a parenthesized type name: the
5679 brace-enclosed initializer of a compound literal, possibly followed
5680 by some postfix operators. This is separate because it is not
5681 possible to tell until after the type name whether a cast
5682 expression has a cast or a compound literal, or whether the operand
5683 of sizeof is a parenthesized type name or starts with a compound
5684 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5685 location of the first token after the parentheses around the type
5688 static struct c_expr
5689 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5690 struct c_type_name
*type_name
,
5691 location_t type_loc
)
5697 location_t start_loc
;
5698 tree type_expr
= NULL_TREE
;
5699 bool type_expr_const
= true;
5700 check_compound_literal_type (type_loc
, type_name
);
5701 start_init (NULL_TREE
, NULL
, 0);
5702 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5703 start_loc
= c_parser_peek_token (parser
)->location
;
5704 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5706 error_at (type_loc
, "compound literal has variable size");
5707 type
= error_mark_node
;
5709 init
= c_parser_braced_init (parser
, type
, false);
5711 maybe_warn_string_init (type
, init
);
5714 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5715 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5716 ? CONSTRUCTOR_NON_CONST (init
.value
)
5717 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5718 non_const
|= !type_expr_const
;
5719 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
5720 expr
.original_code
= ERROR_MARK
;
5721 expr
.original_type
= NULL
;
5724 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5726 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5727 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5731 gcc_assert (!non_const
);
5732 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5733 type_expr
, expr
.value
);
5736 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
5739 /* Parse a postfix expression after the initial primary or compound
5740 literal; that is, parse a series of postfix operators.
5742 EXPR_LOC is the location of the primary expression. */
5744 static struct c_expr
5745 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5746 location_t expr_loc
,
5749 struct c_expr orig_expr
;
5751 VEC(tree
,gc
) *exprlist
;
5752 VEC(tree
,gc
) *origtypes
;
5755 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5756 switch (c_parser_peek_token (parser
)->type
)
5758 case CPP_OPEN_SQUARE
:
5759 /* Array reference. */
5760 c_parser_consume_token (parser
);
5761 idx
= c_parser_expression (parser
).value
;
5762 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5764 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
5765 expr
.original_code
= ERROR_MARK
;
5766 expr
.original_type
= NULL
;
5768 case CPP_OPEN_PAREN
:
5769 /* Function call. */
5770 c_parser_consume_token (parser
);
5771 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5774 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5775 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5778 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
5779 "(" after the FUNCNAME, which is what we have now. */
5780 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
5782 expr
.original_code
= ERROR_MARK
;
5783 if (TREE_CODE (expr
.value
) == INTEGER_CST
5784 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5785 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5786 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5787 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5788 expr
.original_type
= NULL
;
5789 if (exprlist
!= NULL
)
5791 release_tree_vector (exprlist
);
5792 release_tree_vector (origtypes
);
5796 /* Structure element reference. */
5797 c_parser_consume_token (parser
);
5798 expr
= default_function_array_conversion (expr_loc
, expr
);
5799 if (c_parser_next_token_is (parser
, CPP_NAME
))
5800 ident
= c_parser_peek_token (parser
)->value
;
5803 c_parser_error (parser
, "expected identifier");
5804 expr
.value
= error_mark_node
;
5805 expr
.original_code
= ERROR_MARK
;
5806 expr
.original_type
= NULL
;
5809 c_parser_consume_token (parser
);
5810 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
5811 expr
.original_code
= ERROR_MARK
;
5812 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5813 expr
.original_type
= NULL
;
5816 /* Remember the original type of a bitfield. */
5817 tree field
= TREE_OPERAND (expr
.value
, 1);
5818 if (TREE_CODE (field
) != FIELD_DECL
)
5819 expr
.original_type
= NULL
;
5821 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5825 /* Structure element reference. */
5826 c_parser_consume_token (parser
);
5827 expr
= default_function_array_conversion (expr_loc
, expr
);
5828 if (c_parser_next_token_is (parser
, CPP_NAME
))
5829 ident
= c_parser_peek_token (parser
)->value
;
5832 c_parser_error (parser
, "expected identifier");
5833 expr
.value
= error_mark_node
;
5834 expr
.original_code
= ERROR_MARK
;
5835 expr
.original_type
= NULL
;
5838 c_parser_consume_token (parser
);
5839 expr
.value
= build_component_ref (op_loc
,
5840 build_indirect_ref (op_loc
,
5844 expr
.original_code
= ERROR_MARK
;
5845 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5846 expr
.original_type
= NULL
;
5849 /* Remember the original type of a bitfield. */
5850 tree field
= TREE_OPERAND (expr
.value
, 1);
5851 if (TREE_CODE (field
) != FIELD_DECL
)
5852 expr
.original_type
= NULL
;
5854 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5858 /* Postincrement. */
5859 c_parser_consume_token (parser
);
5860 expr
= default_function_array_conversion (expr_loc
, expr
);
5861 expr
.value
= build_unary_op (op_loc
,
5862 POSTINCREMENT_EXPR
, expr
.value
, 0);
5863 expr
.original_code
= ERROR_MARK
;
5864 expr
.original_type
= NULL
;
5866 case CPP_MINUS_MINUS
:
5867 /* Postdecrement. */
5868 c_parser_consume_token (parser
);
5869 expr
= default_function_array_conversion (expr_loc
, expr
);
5870 expr
.value
= build_unary_op (op_loc
,
5871 POSTDECREMENT_EXPR
, expr
.value
, 0);
5872 expr
.original_code
= ERROR_MARK
;
5873 expr
.original_type
= NULL
;
5881 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5884 assignment-expression
5885 expression , assignment-expression
5888 static struct c_expr
5889 c_parser_expression (c_parser
*parser
)
5892 expr
= c_parser_expr_no_commas (parser
, NULL
);
5893 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5896 location_t loc
= c_parser_peek_token (parser
)->location
;
5897 location_t expr_loc
;
5898 c_parser_consume_token (parser
);
5899 expr_loc
= c_parser_peek_token (parser
)->location
;
5900 next
= c_parser_expr_no_commas (parser
, NULL
);
5901 next
= default_function_array_conversion (expr_loc
, next
);
5902 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
5903 expr
.original_code
= COMPOUND_EXPR
;
5904 expr
.original_type
= next
.original_type
;
5909 /* Parse an expression and convert functions or arrays to
5912 static struct c_expr
5913 c_parser_expression_conv (c_parser
*parser
)
5916 location_t loc
= c_parser_peek_token (parser
)->location
;
5917 expr
= c_parser_expression (parser
);
5918 expr
= default_function_array_conversion (loc
, expr
);
5922 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5923 functions and arrays to pointers. If FOLD_P, fold the expressions.
5926 assignment-expression
5927 nonempty-expr-list , assignment-expression
5930 static VEC(tree
,gc
) *
5931 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5932 VEC(tree
,gc
) **p_orig_types
)
5935 VEC(tree
,gc
) *orig_types
;
5937 location_t loc
= c_parser_peek_token (parser
)->location
;
5939 ret
= make_tree_vector ();
5940 if (p_orig_types
== NULL
)
5943 orig_types
= make_tree_vector ();
5945 expr
= c_parser_expr_no_commas (parser
, NULL
);
5947 expr
= default_function_array_conversion (loc
, expr
);
5949 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5950 VEC_quick_push (tree
, ret
, expr
.value
);
5951 if (orig_types
!= NULL
)
5952 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
5953 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5955 c_parser_consume_token (parser
);
5956 loc
= c_parser_peek_token (parser
)->location
;
5957 expr
= c_parser_expr_no_commas (parser
, NULL
);
5959 expr
= default_function_array_conversion (loc
, expr
);
5961 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5962 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
5963 if (orig_types
!= NULL
)
5964 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
5966 if (orig_types
!= NULL
)
5967 *p_orig_types
= orig_types
;
5971 /* Parse Objective-C-specific constructs. */
5973 /* Parse an objc-class-definition.
5975 objc-class-definition:
5976 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5977 objc-class-instance-variables[opt] objc-methodprotolist @end
5978 @implementation identifier objc-superclass[opt]
5979 objc-class-instance-variables[opt]
5980 @interface identifier ( identifier ) objc-protocol-refs[opt]
5981 objc-methodprotolist @end
5982 @implementation identifier ( identifier )
5987 "@interface identifier (" must start "@interface identifier (
5988 identifier ) ...": objc-methodprotolist in the first production may
5989 not start with a parenthesized identifier as a declarator of a data
5990 definition with no declaration specifiers if the objc-superclass,
5991 objc-protocol-refs and objc-class-instance-variables are omitted. */
5994 c_parser_objc_class_definition (c_parser
*parser
)
5999 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6001 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6005 c_parser_consume_token (parser
);
6006 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6008 c_parser_error (parser
, "expected identifier");
6011 id1
= c_parser_peek_token (parser
)->value
;
6012 c_parser_consume_token (parser
);
6013 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6016 tree proto
= NULL_TREE
;
6017 c_parser_consume_token (parser
);
6018 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6020 c_parser_error (parser
, "expected identifier");
6021 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6024 id2
= c_parser_peek_token (parser
)->value
;
6025 c_parser_consume_token (parser
);
6026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6029 objc_start_category_implementation (id1
, id2
);
6032 if (c_parser_next_token_is (parser
, CPP_LESS
))
6033 proto
= c_parser_objc_protocol_refs (parser
);
6034 objc_start_category_interface (id1
, id2
, proto
);
6035 c_parser_objc_methodprotolist (parser
);
6036 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6037 objc_finish_interface ();
6040 if (c_parser_next_token_is (parser
, CPP_COLON
))
6042 c_parser_consume_token (parser
);
6043 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6045 c_parser_error (parser
, "expected identifier");
6048 superclass
= c_parser_peek_token (parser
)->value
;
6049 c_parser_consume_token (parser
);
6052 superclass
= NULL_TREE
;
6055 tree proto
= NULL_TREE
;
6056 if (c_parser_next_token_is (parser
, CPP_LESS
))
6057 proto
= c_parser_objc_protocol_refs (parser
);
6058 objc_start_class_interface (id1
, superclass
, proto
);
6061 objc_start_class_implementation (id1
, superclass
);
6062 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6063 c_parser_objc_class_instance_variables (parser
);
6066 objc_continue_interface ();
6067 c_parser_objc_methodprotolist (parser
);
6068 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6069 objc_finish_interface ();
6073 objc_continue_implementation ();
6078 /* Parse objc-class-instance-variables.
6080 objc-class-instance-variables:
6081 { objc-instance-variable-decl-list[opt] }
6083 objc-instance-variable-decl-list:
6084 objc-visibility-spec
6085 objc-instance-variable-decl ;
6087 objc-instance-variable-decl-list objc-visibility-spec
6088 objc-instance-variable-decl-list objc-instance-variable-decl ;
6089 objc-instance-variable-decl-list ;
6091 objc-visibility-spec:
6096 objc-instance-variable-decl:
6101 c_parser_objc_class_instance_variables (c_parser
*parser
)
6103 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6104 c_parser_consume_token (parser
);
6105 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6108 /* Parse any stray semicolon. */
6109 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6111 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6112 "extra semicolon in struct or union specified");
6113 c_parser_consume_token (parser
);
6116 /* Stop if at the end of the instance variables. */
6117 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6119 c_parser_consume_token (parser
);
6122 /* Parse any objc-visibility-spec. */
6123 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6125 c_parser_consume_token (parser
);
6126 objc_set_visibility (2);
6129 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6131 c_parser_consume_token (parser
);
6132 objc_set_visibility (0);
6135 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6137 c_parser_consume_token (parser
);
6138 objc_set_visibility (1);
6141 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6143 c_parser_pragma (parser
, pragma_external
);
6147 /* Parse some comma-separated declarations. */
6148 decls
= c_parser_struct_declaration (parser
);
6150 /* Comma-separated instance variables are chained together in
6151 reverse order; add them one by one. */
6152 tree ivar
= nreverse (decls
);
6153 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6154 objc_add_instance_variable (copy_node (ivar
));
6156 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6160 /* Parse an objc-class-declaration.
6162 objc-class-declaration:
6163 @class identifier-list ;
6167 c_parser_objc_class_declaration (c_parser
*parser
)
6169 tree list
= NULL_TREE
;
6170 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6171 c_parser_consume_token (parser
);
6172 /* Any identifiers, including those declared as type names, are OK
6177 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6179 c_parser_error (parser
, "expected identifier");
6182 id
= c_parser_peek_token (parser
)->value
;
6183 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6184 c_parser_consume_token (parser
);
6185 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6186 c_parser_consume_token (parser
);
6190 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6191 objc_declare_class (list
);
6194 /* Parse an objc-alias-declaration.
6196 objc-alias-declaration:
6197 @compatibility_alias identifier identifier ;
6201 c_parser_objc_alias_declaration (c_parser
*parser
)
6204 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6205 c_parser_consume_token (parser
);
6206 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6208 c_parser_error (parser
, "expected identifier");
6209 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6212 id1
= c_parser_peek_token (parser
)->value
;
6213 c_parser_consume_token (parser
);
6214 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6216 c_parser_error (parser
, "expected identifier");
6217 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6220 id2
= c_parser_peek_token (parser
)->value
;
6221 c_parser_consume_token (parser
);
6222 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6223 objc_declare_alias (id1
, id2
);
6226 /* Parse an objc-protocol-definition.
6228 objc-protocol-definition:
6229 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6230 @protocol identifier-list ;
6232 "@protocol identifier ;" should be resolved as "@protocol
6233 identifier-list ;": objc-methodprotolist may not start with a
6234 semicolon in the first alternative if objc-protocol-refs are
6238 c_parser_objc_protocol_definition (c_parser
*parser
)
6240 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6241 c_parser_consume_token (parser
);
6242 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6244 c_parser_error (parser
, "expected identifier");
6247 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6248 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6250 tree list
= NULL_TREE
;
6251 /* Any identifiers, including those declared as type names, are
6256 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6258 c_parser_error (parser
, "expected identifier");
6261 id
= c_parser_peek_token (parser
)->value
;
6262 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6263 c_parser_consume_token (parser
);
6264 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6265 c_parser_consume_token (parser
);
6269 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6270 objc_declare_protocols (list
);
6274 tree id
= c_parser_peek_token (parser
)->value
;
6275 tree proto
= NULL_TREE
;
6276 c_parser_consume_token (parser
);
6277 if (c_parser_next_token_is (parser
, CPP_LESS
))
6278 proto
= c_parser_objc_protocol_refs (parser
);
6279 parser
->objc_pq_context
= true;
6280 objc_start_protocol (id
, proto
);
6281 c_parser_objc_methodprotolist (parser
);
6282 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6283 parser
->objc_pq_context
= false;
6284 objc_finish_interface ();
6288 /* Parse an objc-method-type.
6295 static enum tree_code
6296 c_parser_objc_method_type (c_parser
*parser
)
6298 switch (c_parser_peek_token (parser
)->type
)
6301 c_parser_consume_token (parser
);
6304 c_parser_consume_token (parser
);
6311 /* Parse an objc-method-definition.
6313 objc-method-definition:
6314 objc-method-type objc-method-decl ;[opt] compound-statement
6318 c_parser_objc_method_definition (c_parser
*parser
)
6320 enum tree_code type
= c_parser_objc_method_type (parser
);
6322 objc_set_method_type (type
);
6323 parser
->objc_pq_context
= true;
6324 decl
= c_parser_objc_method_decl (parser
);
6325 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6327 c_parser_consume_token (parser
);
6328 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6329 "extra semicolon in method definition specified");
6331 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6333 c_parser_error (parser
, "expected %<{%>");
6336 parser
->objc_pq_context
= false;
6337 objc_start_method_definition (decl
);
6338 add_stmt (c_parser_compound_statement (parser
));
6339 objc_finish_method_definition (current_function_decl
);
6342 /* Parse an objc-methodprotolist.
6344 objc-methodprotolist:
6346 objc-methodprotolist objc-methodproto
6347 objc-methodprotolist declaration
6348 objc-methodprotolist ;
6350 The declaration is a data definition, which may be missing
6351 declaration specifiers under the same rules and diagnostics as
6352 other data definitions outside functions, and the stray semicolon
6353 is diagnosed the same way as a stray semicolon outside a
6357 c_parser_objc_methodprotolist (c_parser
*parser
)
6361 /* The list is terminated by @end. */
6362 switch (c_parser_peek_token (parser
)->type
)
6365 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6366 "ISO C does not allow extra %<;%> outside of a function");
6367 c_parser_consume_token (parser
);
6371 c_parser_objc_methodproto (parser
);
6374 c_parser_pragma (parser
, pragma_external
);
6379 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6381 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6387 /* Parse an objc-methodproto.
6390 objc-method-type objc-method-decl ;
6394 c_parser_objc_methodproto (c_parser
*parser
)
6396 enum tree_code type
= c_parser_objc_method_type (parser
);
6398 objc_set_method_type (type
);
6399 /* Remember protocol qualifiers in prototypes. */
6400 parser
->objc_pq_context
= true;
6401 decl
= c_parser_objc_method_decl (parser
);
6402 /* Forget protocol qualifiers here. */
6403 parser
->objc_pq_context
= false;
6404 objc_add_method_declaration (decl
);
6405 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6408 /* Parse an objc-method-decl.
6411 ( objc-type-name ) objc-selector
6413 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6414 objc-keyword-selector objc-optparmlist
6416 objc-keyword-selector:
6418 objc-keyword-selector objc-keyword-decl
6421 objc-selector : ( objc-type-name ) identifier
6422 objc-selector : identifier
6423 : ( objc-type-name ) identifier
6427 objc-optparms objc-optellipsis
6431 objc-opt-parms , parameter-declaration
6439 c_parser_objc_method_decl (c_parser
*parser
)
6441 tree type
= NULL_TREE
;
6443 tree parms
= NULL_TREE
;
6444 bool ellipsis
= false;
6446 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6448 c_parser_consume_token (parser
);
6449 type
= c_parser_objc_type_name (parser
);
6450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6452 sel
= c_parser_objc_selector (parser
);
6453 /* If there is no selector, or a colon follows, we have an
6454 objc-keyword-selector. If there is a selector, and a colon does
6455 not follow, that selector ends the objc-method-decl. */
6456 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6459 tree list
= NULL_TREE
;
6462 tree atype
= NULL_TREE
, id
, keyworddecl
;
6463 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6465 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6467 c_parser_consume_token (parser
);
6468 atype
= c_parser_objc_type_name (parser
);
6469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6472 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6474 c_parser_error (parser
, "expected identifier");
6475 return error_mark_node
;
6477 id
= c_parser_peek_token (parser
)->value
;
6478 c_parser_consume_token (parser
);
6479 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6480 list
= chainon (list
, keyworddecl
);
6481 tsel
= c_parser_objc_selector (parser
);
6482 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6485 /* Parse the optional parameter list. Optional Objective-C
6486 method parameters follow the C syntax, and may include '...'
6487 to denote a variable number of arguments. */
6488 parms
= make_node (TREE_LIST
);
6489 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6491 struct c_parm
*parm
;
6492 c_parser_consume_token (parser
);
6493 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6496 c_parser_consume_token (parser
);
6499 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6502 parms
= chainon (parms
,
6503 build_tree_list (NULL_TREE
, grokparm (parm
)));
6507 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6510 /* Parse an objc-type-name.
6513 objc-type-qualifiers[opt] type-name
6514 objc-type-qualifiers[opt]
6516 objc-type-qualifiers:
6518 objc-type-qualifiers objc-type-qualifier
6520 objc-type-qualifier: one of
6521 in out inout bycopy byref oneway
6525 c_parser_objc_type_name (c_parser
*parser
)
6527 tree quals
= NULL_TREE
;
6528 struct c_type_name
*type_name
= NULL
;
6529 tree type
= NULL_TREE
;
6532 c_token
*token
= c_parser_peek_token (parser
);
6533 if (token
->type
== CPP_KEYWORD
6534 && (token
->keyword
== RID_IN
6535 || token
->keyword
== RID_OUT
6536 || token
->keyword
== RID_INOUT
6537 || token
->keyword
== RID_BYCOPY
6538 || token
->keyword
== RID_BYREF
6539 || token
->keyword
== RID_ONEWAY
))
6541 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6542 c_parser_consume_token (parser
);
6547 if (c_parser_next_token_starts_typename (parser
))
6548 type_name
= c_parser_type_name (parser
);
6550 type
= groktypename (type_name
, NULL
, NULL
);
6551 return build_tree_list (quals
, type
);
6554 /* Parse objc-protocol-refs.
6561 c_parser_objc_protocol_refs (c_parser
*parser
)
6563 tree list
= NULL_TREE
;
6564 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6565 c_parser_consume_token (parser
);
6566 /* Any identifiers, including those declared as type names, are OK
6571 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6573 c_parser_error (parser
, "expected identifier");
6576 id
= c_parser_peek_token (parser
)->value
;
6577 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6578 c_parser_consume_token (parser
);
6579 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6580 c_parser_consume_token (parser
);
6584 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6588 /* Parse an objc-try-catch-statement.
6590 objc-try-catch-statement:
6591 @try compound-statement objc-catch-list[opt]
6592 @try compound-statement objc-catch-list[opt] @finally compound-statement
6595 @catch ( parameter-declaration ) compound-statement
6596 objc-catch-list @catch ( parameter-declaration ) compound-statement
6600 c_parser_objc_try_catch_statement (c_parser
*parser
)
6604 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6605 c_parser_consume_token (parser
);
6606 loc
= c_parser_peek_token (parser
)->location
;
6607 stmt
= c_parser_compound_statement (parser
);
6608 objc_begin_try_stmt (loc
, stmt
);
6609 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6611 struct c_parm
*parm
;
6612 c_parser_consume_token (parser
);
6613 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6615 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6618 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6622 objc_begin_catch_clause (grokparm (parm
));
6623 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6624 c_parser_compound_statement_nostart (parser
);
6625 objc_finish_catch_clause ();
6627 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6631 c_parser_consume_token (parser
);
6632 finloc
= c_parser_peek_token (parser
)->location
;
6633 finstmt
= c_parser_compound_statement (parser
);
6634 objc_build_finally_clause (finloc
, finstmt
);
6636 objc_finish_try_stmt ();
6639 /* Parse an objc-synchronized-statement.
6641 objc-synchronized-statement:
6642 @synchronized ( expression ) compound-statement
6646 c_parser_objc_synchronized_statement (c_parser
*parser
)
6650 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6651 c_parser_consume_token (parser
);
6652 loc
= c_parser_peek_token (parser
)->location
;
6653 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6655 expr
= c_parser_expression (parser
).value
;
6656 expr
= c_fully_fold (expr
, false, NULL
);
6657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6660 expr
= error_mark_node
;
6661 stmt
= c_parser_compound_statement (parser
);
6662 objc_build_synchronized (loc
, expr
, stmt
);
6665 /* Parse an objc-selector; return NULL_TREE without an error if the
6666 next token is not an objc-selector.
6671 enum struct union if else while do for switch case default
6672 break continue return goto asm sizeof typeof __alignof
6673 unsigned long const short volatile signed restrict _Complex
6674 in out inout bycopy byref oneway int char float double void _Bool
6676 ??? Why this selection of keywords but not, for example, storage
6677 class specifiers? */
6680 c_parser_objc_selector (c_parser
*parser
)
6682 c_token
*token
= c_parser_peek_token (parser
);
6683 tree value
= token
->value
;
6684 if (token
->type
== CPP_NAME
)
6686 c_parser_consume_token (parser
);
6689 if (token
->type
!= CPP_KEYWORD
)
6691 switch (token
->keyword
)
6732 c_parser_consume_token (parser
);
6739 /* Parse an objc-selector-arg.
6743 objc-keywordname-list
6745 objc-keywordname-list:
6747 objc-keywordname-list objc-keywordname
6755 c_parser_objc_selector_arg (c_parser
*parser
)
6757 tree sel
= c_parser_objc_selector (parser
);
6758 tree list
= NULL_TREE
;
6759 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6763 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6765 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6766 sel
= c_parser_objc_selector (parser
);
6767 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6773 /* Parse an objc-receiver.
6782 c_parser_objc_receiver (c_parser
*parser
)
6784 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6785 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6786 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6788 tree id
= c_parser_peek_token (parser
)->value
;
6789 c_parser_consume_token (parser
);
6790 return objc_get_class_reference (id
);
6792 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6795 /* Parse objc-message-args.
6799 objc-keywordarg-list
6801 objc-keywordarg-list:
6803 objc-keywordarg-list objc-keywordarg
6806 objc-selector : objc-keywordexpr
6811 c_parser_objc_message_args (c_parser
*parser
)
6813 tree sel
= c_parser_objc_selector (parser
);
6814 tree list
= NULL_TREE
;
6815 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6820 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6821 return error_mark_node
;
6822 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6823 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6824 sel
= c_parser_objc_selector (parser
);
6825 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6831 /* Parse an objc-keywordexpr.
6838 c_parser_objc_keywordexpr (c_parser
*parser
)
6841 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6842 if (VEC_length (tree
, expr_list
) == 1)
6844 /* Just return the expression, remove a level of
6846 ret
= VEC_index (tree
, expr_list
, 0);
6850 /* We have a comma expression, we will collapse later. */
6851 ret
= build_tree_list_vec (expr_list
);
6853 release_tree_vector (expr_list
);
6858 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6859 should be considered, statements. ALLOW_STMT is true if we're within
6860 the context of a function and such pragmas are to be allowed. Returns
6861 true if we actually parsed such a pragma. */
6864 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6868 id
= c_parser_peek_token (parser
)->pragma_kind
;
6869 gcc_assert (id
!= PRAGMA_NONE
);
6873 case PRAGMA_OMP_BARRIER
:
6874 if (context
!= pragma_compound
)
6876 if (context
== pragma_stmt
)
6877 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6878 "used in compound statements");
6881 c_parser_omp_barrier (parser
);
6884 case PRAGMA_OMP_FLUSH
:
6885 if (context
!= pragma_compound
)
6887 if (context
== pragma_stmt
)
6888 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6889 "used in compound statements");
6892 c_parser_omp_flush (parser
);
6895 case PRAGMA_OMP_TASKWAIT
:
6896 if (context
!= pragma_compound
)
6898 if (context
== pragma_stmt
)
6899 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6900 "used in compound statements");
6903 c_parser_omp_taskwait (parser
);
6906 case PRAGMA_OMP_THREADPRIVATE
:
6907 c_parser_omp_threadprivate (parser
);
6910 case PRAGMA_OMP_SECTION
:
6911 error_at (c_parser_peek_token (parser
)->location
,
6912 "%<#pragma omp section%> may only be used in "
6913 "%<#pragma omp sections%> construct");
6914 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6917 case PRAGMA_GCC_PCH_PREPROCESS
:
6918 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6919 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6923 if (id
< PRAGMA_FIRST_EXTERNAL
)
6925 if (context
== pragma_external
)
6928 c_parser_error (parser
, "expected declaration specifiers");
6929 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6932 c_parser_omp_construct (parser
);
6938 c_parser_consume_pragma (parser
);
6939 c_invoke_pragma_handler (id
);
6941 /* Skip to EOL, but suppress any error message. Those will have been
6942 generated by the handler routine through calling error, as opposed
6943 to calling c_parser_error. */
6944 parser
->error
= true;
6945 c_parser_skip_to_pragma_eol (parser
);
6950 /* The interface the pragma parsers have to the lexer. */
6953 pragma_lex (tree
*value
)
6955 c_token
*tok
= c_parser_peek_token (the_parser
);
6956 enum cpp_ttype ret
= tok
->type
;
6958 *value
= tok
->value
;
6959 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6963 if (ret
== CPP_KEYWORD
)
6965 c_parser_consume_token (the_parser
);
6972 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6976 c_parser_consume_pragma (parser
);
6977 if (c_parser_next_token_is (parser
, CPP_STRING
))
6979 name
= c_parser_peek_token (parser
)->value
;
6980 c_parser_consume_token (parser
);
6983 c_parser_error (parser
, "expected string literal");
6984 c_parser_skip_to_pragma_eol (parser
);
6987 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6990 /* OpenMP 2.5 parsing routines. */
6992 /* Returns name of the next clause.
6993 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6994 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6995 returned and the token is consumed. */
6997 static pragma_omp_clause
6998 c_parser_omp_clause_name (c_parser
*parser
)
7000 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7002 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7003 result
= PRAGMA_OMP_CLAUSE_IF
;
7004 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7005 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7006 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7008 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7013 if (!strcmp ("collapse", p
))
7014 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7015 else if (!strcmp ("copyin", p
))
7016 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7017 else if (!strcmp ("copyprivate", p
))
7018 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7021 if (!strcmp ("firstprivate", p
))
7022 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7025 if (!strcmp ("lastprivate", p
))
7026 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7029 if (!strcmp ("nowait", p
))
7030 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7031 else if (!strcmp ("num_threads", p
))
7032 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7035 if (!strcmp ("ordered", p
))
7036 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7039 if (!strcmp ("private", p
))
7040 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7043 if (!strcmp ("reduction", p
))
7044 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7047 if (!strcmp ("schedule", p
))
7048 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7049 else if (!strcmp ("shared", p
))
7050 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7053 if (!strcmp ("untied", p
))
7054 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7059 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7060 c_parser_consume_token (parser
);
7065 /* Validate that a clause of the given type does not already exist. */
7068 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7073 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7074 if (OMP_CLAUSE_CODE (c
) == code
)
7076 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7077 error_at (loc
, "too many %qs clauses", name
);
7085 variable-list , identifier
7087 If KIND is nonzero, create the appropriate node and install the
7088 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7089 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7091 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7092 return the list created. */
7095 c_parser_omp_variable_list (c_parser
*parser
,
7096 location_t clause_loc
,
7097 enum omp_clause_code kind
,
7100 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7101 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7102 c_parser_error (parser
, "expected identifier");
7104 while (c_parser_next_token_is (parser
, CPP_NAME
)
7105 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7107 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7110 undeclared_variable (c_parser_peek_token (parser
)->location
,
7111 c_parser_peek_token (parser
)->value
);
7112 else if (t
== error_mark_node
)
7116 tree u
= build_omp_clause (clause_loc
, kind
);
7117 OMP_CLAUSE_DECL (u
) = t
;
7118 OMP_CLAUSE_CHAIN (u
) = list
;
7122 list
= tree_cons (t
, NULL_TREE
, list
);
7124 c_parser_consume_token (parser
);
7126 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7129 c_parser_consume_token (parser
);
7135 /* Similarly, but expect leading and trailing parenthesis. This is a very
7136 common case for omp clauses. */
7139 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7142 /* The clauses location. */
7143 location_t loc
= c_parser_peek_token (parser
)->location
;
7145 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7147 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7154 collapse ( constant-expression ) */
7157 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7159 tree c
, num
= error_mark_node
;
7163 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7165 loc
= c_parser_peek_token (parser
)->location
;
7166 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7168 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7169 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7171 if (num
== error_mark_node
)
7173 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7174 || !host_integerp (num
, 0)
7175 || (n
= tree_low_cst (num
, 0)) <= 0
7179 "collapse argument needs positive constant integer expression");
7182 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7183 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7184 OMP_CLAUSE_CHAIN (c
) = list
;
7189 copyin ( variable-list ) */
7192 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7194 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7198 copyprivate ( variable-list ) */
7201 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7203 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7207 default ( shared | none ) */
7210 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7212 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7213 location_t loc
= c_parser_peek_token (parser
)->location
;
7216 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7218 if (c_parser_next_token_is (parser
, CPP_NAME
))
7220 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7225 if (strcmp ("none", p
) != 0)
7227 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7231 if (strcmp ("shared", p
) != 0)
7233 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7240 c_parser_consume_token (parser
);
7245 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7247 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7249 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7252 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7253 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7254 OMP_CLAUSE_CHAIN (c
) = list
;
7255 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7261 firstprivate ( variable-list ) */
7264 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7266 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7270 if ( expression ) */
7273 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7275 location_t loc
= c_parser_peek_token (parser
)->location
;
7276 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7278 tree t
= c_parser_paren_condition (parser
);
7281 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7283 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7284 OMP_CLAUSE_IF_EXPR (c
) = t
;
7285 OMP_CLAUSE_CHAIN (c
) = list
;
7289 c_parser_error (parser
, "expected %<(%>");
7295 lastprivate ( variable-list ) */
7298 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7300 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7307 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7310 location_t loc
= c_parser_peek_token (parser
)->location
;
7312 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7314 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7315 OMP_CLAUSE_CHAIN (c
) = list
;
7320 num_threads ( expression ) */
7323 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7325 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7326 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7328 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7329 tree c
, t
= c_parser_expression (parser
).value
;
7330 t
= c_fully_fold (t
, false, NULL
);
7332 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7334 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7336 c_parser_error (parser
, "expected integer expression");
7340 /* Attempt to statically determine when the number isn't positive. */
7341 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7342 build_int_cst (TREE_TYPE (t
), 0));
7343 if (CAN_HAVE_LOCATION_P (c
))
7344 SET_EXPR_LOCATION (c
, expr_loc
);
7345 if (c
== boolean_true_node
)
7347 warning_at (expr_loc
, 0,
7348 "%<num_threads%> value must be positive");
7349 t
= integer_one_node
;
7352 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7354 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7355 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7356 OMP_CLAUSE_CHAIN (c
) = list
;
7367 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7371 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7373 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7374 OMP_CLAUSE_ORDERED
);
7375 OMP_CLAUSE_CHAIN (c
) = list
;
7381 private ( variable-list ) */
7384 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7386 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7390 reduction ( reduction-operator : variable-list )
7393 One of: + * - & ^ | && || */
7396 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7398 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7399 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7401 enum tree_code code
;
7403 switch (c_parser_peek_token (parser
)->type
)
7415 code
= BIT_AND_EXPR
;
7418 code
= BIT_XOR_EXPR
;
7421 code
= BIT_IOR_EXPR
;
7424 code
= TRUTH_ANDIF_EXPR
;
7427 code
= TRUTH_ORIF_EXPR
;
7430 c_parser_error (parser
,
7431 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7432 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7436 c_parser_consume_token (parser
);
7437 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7441 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7442 OMP_CLAUSE_REDUCTION
, list
);
7443 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7444 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7448 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7454 schedule ( schedule-kind )
7455 schedule ( schedule-kind , expression )
7458 static | dynamic | guided | runtime | auto
7462 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7465 location_t loc
= c_parser_peek_token (parser
)->location
;
7467 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7470 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7472 if (c_parser_next_token_is (parser
, CPP_NAME
))
7474 tree kind
= c_parser_peek_token (parser
)->value
;
7475 const char *p
= IDENTIFIER_POINTER (kind
);
7480 if (strcmp ("dynamic", p
) != 0)
7482 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7486 if (strcmp ("guided", p
) != 0)
7488 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7492 if (strcmp ("runtime", p
) != 0)
7494 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7501 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7502 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7503 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7504 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7508 c_parser_consume_token (parser
);
7509 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7512 c_parser_consume_token (parser
);
7514 here
= c_parser_peek_token (parser
)->location
;
7515 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7516 t
= c_fully_fold (t
, false, NULL
);
7518 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7519 error_at (here
, "schedule %<runtime%> does not take "
7520 "a %<chunk_size%> parameter");
7521 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7523 "schedule %<auto%> does not take "
7524 "a %<chunk_size%> parameter");
7525 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7526 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7528 c_parser_error (parser
, "expected integer expression");
7530 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7534 "expected %<,%> or %<)%>");
7536 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7537 OMP_CLAUSE_CHAIN (c
) = list
;
7541 c_parser_error (parser
, "invalid schedule kind");
7542 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7547 shared ( variable-list ) */
7550 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7552 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7559 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7563 /* FIXME: Should we allow duplicates? */
7564 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7566 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7568 OMP_CLAUSE_CHAIN (c
) = list
;
7573 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7574 is a bitmask in MASK. Return the list of clauses found; the result
7575 of clause default goes in *pdefault. */
7578 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7581 tree clauses
= NULL
;
7584 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7587 pragma_omp_clause c_kind
;
7589 tree prev
= clauses
;
7591 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7592 c_parser_consume_token (parser
);
7595 here
= c_parser_peek_token (parser
)->location
;
7596 c_kind
= c_parser_omp_clause_name (parser
);
7600 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7601 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7602 c_name
= "collapse";
7604 case PRAGMA_OMP_CLAUSE_COPYIN
:
7605 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7608 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7609 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7610 c_name
= "copyprivate";
7612 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7613 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7616 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7617 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7618 c_name
= "firstprivate";
7620 case PRAGMA_OMP_CLAUSE_IF
:
7621 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7624 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7625 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7626 c_name
= "lastprivate";
7628 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7629 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7632 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7633 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7634 c_name
= "num_threads";
7636 case PRAGMA_OMP_CLAUSE_ORDERED
:
7637 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7640 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7641 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7644 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7645 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7646 c_name
= "reduction";
7648 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7649 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7650 c_name
= "schedule";
7652 case PRAGMA_OMP_CLAUSE_SHARED
:
7653 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7656 case PRAGMA_OMP_CLAUSE_UNTIED
:
7657 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7661 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7665 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7667 /* Remove the invalid clause(s) from the list to avoid
7668 confusing the rest of the compiler. */
7670 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7675 c_parser_skip_to_pragma_eol (parser
);
7677 return c_finish_omp_clauses (clauses
);
7684 In practice, we're also interested in adding the statement to an
7685 outer node. So it is convenient if we work around the fact that
7686 c_parser_statement calls add_stmt. */
7689 c_parser_omp_structured_block (c_parser
*parser
)
7691 tree stmt
= push_stmt_list ();
7692 c_parser_statement (parser
);
7693 return pop_stmt_list (stmt
);
7697 # pragma omp atomic new-line
7701 x binop= expr | x++ | ++x | x-- | --x
7703 +, *, -, /, &, ^, |, <<, >>
7705 where x is an lvalue expression with scalar type.
7707 LOC is the location of the #pragma token. */
7710 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
7714 enum tree_code code
;
7715 struct c_expr rhs_expr
;
7717 c_parser_skip_to_pragma_eol (parser
);
7719 lhs
= c_parser_unary_expression (parser
).value
;
7720 lhs
= c_fully_fold (lhs
, false, NULL
);
7721 switch (TREE_CODE (lhs
))
7725 c_parser_skip_to_end_of_block_or_statement (parser
);
7728 case PREINCREMENT_EXPR
:
7729 case POSTINCREMENT_EXPR
:
7730 lhs
= TREE_OPERAND (lhs
, 0);
7732 rhs
= integer_one_node
;
7735 case PREDECREMENT_EXPR
:
7736 case POSTDECREMENT_EXPR
:
7737 lhs
= TREE_OPERAND (lhs
, 0);
7739 rhs
= integer_one_node
;
7743 switch (c_parser_peek_token (parser
)->type
)
7749 code
= TRUNC_DIV_EXPR
;
7764 code
= BIT_AND_EXPR
;
7767 code
= BIT_IOR_EXPR
;
7770 code
= BIT_XOR_EXPR
;
7773 c_parser_error (parser
,
7774 "invalid operator for %<#pragma omp atomic%>");
7778 c_parser_consume_token (parser
);
7780 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
7781 rhs_expr
= c_parser_expression (parser
);
7782 rhs_expr
= default_function_array_conversion (rhs_loc
, rhs_expr
);
7784 rhs
= rhs_expr
.value
;
7785 rhs
= c_fully_fold (rhs
, false, NULL
);
7788 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
7789 if (stmt
!= error_mark_node
)
7791 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7796 # pragma omp barrier new-line
7800 c_parser_omp_barrier (c_parser
*parser
)
7802 location_t loc
= c_parser_peek_token (parser
)->location
;
7803 c_parser_consume_pragma (parser
);
7804 c_parser_skip_to_pragma_eol (parser
);
7806 c_finish_omp_barrier (loc
);
7810 # pragma omp critical [(name)] new-line
7813 LOC is the location of the #pragma itself. */
7816 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
7818 tree stmt
, name
= NULL
;
7820 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7822 c_parser_consume_token (parser
);
7823 if (c_parser_next_token_is (parser
, CPP_NAME
))
7825 name
= c_parser_peek_token (parser
)->value
;
7826 c_parser_consume_token (parser
);
7827 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7830 c_parser_error (parser
, "expected identifier");
7832 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7833 c_parser_error (parser
, "expected %<(%> or end of line");
7834 c_parser_skip_to_pragma_eol (parser
);
7836 stmt
= c_parser_omp_structured_block (parser
);
7837 return c_finish_omp_critical (loc
, stmt
, name
);
7841 # pragma omp flush flush-vars[opt] new-line
7844 ( variable-list ) */
7847 c_parser_omp_flush (c_parser
*parser
)
7849 location_t loc
= c_parser_peek_token (parser
)->location
;
7850 c_parser_consume_pragma (parser
);
7851 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7852 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7853 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7854 c_parser_error (parser
, "expected %<(%> or end of line");
7855 c_parser_skip_to_pragma_eol (parser
);
7857 c_finish_omp_flush (loc
);
7860 /* Parse the restricted form of the for statement allowed by OpenMP.
7861 The real trick here is to determine the loop control variable early
7862 so that we can push a new decl if necessary to make it private.
7863 LOC is the location of the OMP in "#pragma omp". */
7866 c_parser_omp_for_loop (location_t loc
,
7867 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7869 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7870 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7871 bool fail
= false, open_brace_parsed
= false;
7872 int i
, collapse
= 1, nbraces
= 0;
7875 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7876 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7877 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7879 gcc_assert (collapse
>= 1);
7881 declv
= make_tree_vec (collapse
);
7882 initv
= make_tree_vec (collapse
);
7883 condv
= make_tree_vec (collapse
);
7884 incrv
= make_tree_vec (collapse
);
7886 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7888 c_parser_error (parser
, "for statement expected");
7891 for_loc
= c_parser_peek_token (parser
)->location
;
7892 c_parser_consume_token (parser
);
7894 for (i
= 0; i
< collapse
; i
++)
7898 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7901 /* Parse the initialization declaration or expression. */
7902 if (c_parser_next_token_starts_declspecs (parser
))
7906 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7907 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7908 decl
= check_for_loop_decls (for_loc
);
7911 if (DECL_INITIAL (decl
) == error_mark_node
)
7912 decl
= error_mark_node
;
7915 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7916 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7918 struct c_expr decl_exp
;
7919 struct c_expr init_exp
;
7920 location_t init_loc
;
7922 decl_exp
= c_parser_postfix_expression (parser
);
7923 decl
= decl_exp
.value
;
7925 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7927 init_loc
= c_parser_peek_token (parser
)->location
;
7928 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7929 init_exp
= default_function_array_conversion (init_loc
, init_exp
);
7930 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7931 NOP_EXPR
, init_loc
, init_exp
.value
,
7932 init_exp
.original_type
);
7933 init
= c_process_expr_stmt (init_loc
, init
);
7935 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7940 c_parser_error (parser
,
7941 "expected iteration declaration or initialization");
7942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7948 /* Parse the loop condition. */
7950 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7952 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7953 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
7955 cond
= cond_expr
.value
;
7956 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7957 cond
= c_fully_fold (cond
, false, NULL
);
7958 switch (cond_expr
.original_code
)
7966 /* Can't be cond = error_mark_node, because we want to preserve
7967 the location until c_finish_omp_for. */
7968 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
7971 protected_set_expr_location (cond
, cond_loc
);
7973 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7975 /* Parse the increment expression. */
7977 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7979 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7981 incr
= c_process_expr_stmt (incr_loc
,
7982 c_parser_expression (parser
).value
);
7984 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7986 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7990 TREE_VEC_ELT (declv
, i
) = decl
;
7991 TREE_VEC_ELT (initv
, i
) = init
;
7992 TREE_VEC_ELT (condv
, i
) = cond
;
7993 TREE_VEC_ELT (incrv
, i
) = incr
;
7997 if (i
== collapse
- 1)
8000 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8001 in between the collapsed for loops to be still considered perfectly
8002 nested. Hopefully the final version clarifies this.
8003 For now handle (multiple) {'s and empty statements. */
8006 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8008 c_parser_consume_token (parser
);
8011 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8013 c_parser_consume_token (parser
);
8017 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8018 c_parser_consume_token (parser
);
8021 c_parser_error (parser
, "not enough perfectly nested loops");
8024 open_brace_parsed
= true;
8034 nbraces
+= bracecount
;
8037 save_break
= c_break_label
;
8038 c_break_label
= size_one_node
;
8039 save_cont
= c_cont_label
;
8040 c_cont_label
= NULL_TREE
;
8041 body
= push_stmt_list ();
8043 if (open_brace_parsed
)
8045 location_t here
= c_parser_peek_token (parser
)->location
;
8046 stmt
= c_begin_compound_stmt (true);
8047 c_parser_compound_statement_nostart (parser
);
8048 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8051 add_stmt (c_parser_c99_block_statement (parser
));
8054 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8055 SET_EXPR_LOCATION (t
, loc
);
8059 body
= pop_stmt_list (body
);
8060 c_break_label
= save_break
;
8061 c_cont_label
= save_cont
;
8065 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8067 c_parser_consume_token (parser
);
8070 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8071 c_parser_consume_token (parser
);
8074 c_parser_error (parser
, "collapsed loops not perfectly nested");
8077 location_t here
= c_parser_peek_token (parser
)->location
;
8078 stmt
= c_begin_compound_stmt (true);
8080 c_parser_compound_statement_nostart (parser
);
8081 body
= c_end_compound_stmt (here
, stmt
, true);
8088 /* Only bother calling c_finish_omp_for if we haven't already generated
8089 an error from the initialization parsing. */
8092 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8095 if (par_clauses
!= NULL
)
8098 for (c
= par_clauses
; *c
; )
8099 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8100 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8101 c
= &OMP_CLAUSE_CHAIN (*c
);
8104 for (i
= 0; i
< collapse
; i
++)
8105 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8108 c
= &OMP_CLAUSE_CHAIN (*c
);
8109 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8112 "iteration variable %qD should not be firstprivate",
8113 OMP_CLAUSE_DECL (*c
));
8114 *c
= OMP_CLAUSE_CHAIN (*c
);
8118 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8119 change it to shared (decl) in
8120 OMP_PARALLEL_CLAUSES. */
8121 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8122 OMP_CLAUSE_LASTPRIVATE
);
8123 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8124 OMP_CLAUSE_CHAIN (l
) = clauses
;
8126 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8130 OMP_FOR_CLAUSES (stmt
) = clauses
;
8137 /* FIXME diagnostics: LOC below should be the actual location of
8138 this particular for block. We need to build a list of
8139 locations to go along with FOR_BLOCK. */
8140 stmt
= c_end_compound_stmt (loc
, TREE_VALUE (for_block
), true);
8142 for_block
= TREE_CHAIN (for_block
);
8148 #pragma omp for for-clause[optseq] new-line
8151 LOC is the location of the #pragma token.
8154 #define OMP_FOR_CLAUSE_MASK \
8155 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8156 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8157 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8158 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8159 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8160 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8161 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8162 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8165 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8167 tree block
, clauses
, ret
;
8169 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8172 block
= c_begin_compound_stmt (true);
8173 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8174 block
= c_end_compound_stmt (loc
, block
, true);
8181 # pragma omp master new-line
8184 LOC is the location of the #pragma token.
8188 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8190 c_parser_skip_to_pragma_eol (parser
);
8191 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8195 # pragma omp ordered new-line
8198 LOC is the location of the #pragma itself.
8202 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8204 c_parser_skip_to_pragma_eol (parser
);
8205 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8211 { section-sequence }
8214 section-directive[opt] structured-block
8215 section-sequence section-directive structured-block
8217 SECTIONS_LOC is the location of the #pragma omp sections. */
8220 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8223 bool error_suppress
= false;
8226 loc
= c_parser_peek_token (parser
)->location
;
8227 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8229 /* Avoid skipping until the end of the block. */
8230 parser
->error
= false;
8234 stmt
= push_stmt_list ();
8236 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8238 substmt
= push_stmt_list ();
8242 c_parser_statement (parser
);
8244 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8246 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8248 if (c_parser_next_token_is (parser
, CPP_EOF
))
8252 substmt
= pop_stmt_list (substmt
);
8253 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8254 SET_EXPR_LOCATION (substmt
, loc
);
8260 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8262 if (c_parser_next_token_is (parser
, CPP_EOF
))
8265 loc
= c_parser_peek_token (parser
)->location
;
8266 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8268 c_parser_consume_pragma (parser
);
8269 c_parser_skip_to_pragma_eol (parser
);
8270 error_suppress
= false;
8272 else if (!error_suppress
)
8274 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8275 error_suppress
= true;
8278 substmt
= c_parser_omp_structured_block (parser
);
8279 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8280 SET_EXPR_LOCATION (substmt
, loc
);
8283 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8284 "expected %<#pragma omp section%> or %<}%>");
8286 substmt
= pop_stmt_list (stmt
);
8288 stmt
= make_node (OMP_SECTIONS
);
8289 SET_EXPR_LOCATION (stmt
, sections_loc
);
8290 TREE_TYPE (stmt
) = void_type_node
;
8291 OMP_SECTIONS_BODY (stmt
) = substmt
;
8293 return add_stmt (stmt
);
8297 # pragma omp sections sections-clause[optseq] newline
8300 LOC is the location of the #pragma token.
8303 #define OMP_SECTIONS_CLAUSE_MASK \
8304 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8305 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8306 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8307 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8308 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8311 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8313 tree block
, clauses
, ret
;
8315 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8316 "#pragma omp sections");
8318 block
= c_begin_compound_stmt (true);
8319 ret
= c_parser_omp_sections_scope (loc
, parser
);
8321 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8322 block
= c_end_compound_stmt (loc
, block
, true);
8329 # pragma parallel parallel-clause new-line
8330 # pragma parallel for parallel-for-clause new-line
8331 # pragma parallel sections parallel-sections-clause new-line
8333 LOC is the location of the #pragma token.
8336 #define OMP_PARALLEL_CLAUSE_MASK \
8337 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8338 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8339 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8340 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8341 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8342 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8343 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8344 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8347 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8349 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8350 const char *p_name
= "#pragma omp parallel";
8351 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8352 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8354 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8356 c_parser_consume_token (parser
);
8357 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8358 p_name
= "#pragma omp parallel for";
8359 mask
|= OMP_FOR_CLAUSE_MASK
;
8360 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8362 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8364 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8365 if (strcmp (p
, "sections") == 0)
8367 c_parser_consume_token (parser
);
8368 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8369 p_name
= "#pragma omp parallel sections";
8370 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8371 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8375 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8379 case PRAGMA_OMP_PARALLEL
:
8380 block
= c_begin_omp_parallel ();
8381 c_parser_statement (parser
);
8382 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8385 case PRAGMA_OMP_PARALLEL_FOR
:
8386 block
= c_begin_omp_parallel ();
8387 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8388 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8389 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8390 OMP_PARALLEL_COMBINED (stmt
) = 1;
8393 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8394 block
= c_begin_omp_parallel ();
8395 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8396 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8398 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8399 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8400 OMP_PARALLEL_COMBINED (stmt
) = 1;
8411 # pragma omp single single-clause[optseq] new-line
8414 LOC is the location of the #pragma.
8417 #define OMP_SINGLE_CLAUSE_MASK \
8418 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8419 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8420 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8421 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8424 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8426 tree stmt
= make_node (OMP_SINGLE
);
8427 SET_EXPR_LOCATION (stmt
, loc
);
8428 TREE_TYPE (stmt
) = void_type_node
;
8430 OMP_SINGLE_CLAUSES (stmt
)
8431 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8432 "#pragma omp single");
8433 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8435 return add_stmt (stmt
);
8439 # pragma omp task task-clause[optseq] new-line
8441 LOC is the location of the #pragma.
8444 #define OMP_TASK_CLAUSE_MASK \
8445 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8446 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8447 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8448 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8449 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8450 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8453 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8455 tree clauses
, block
;
8457 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8458 "#pragma omp task");
8460 block
= c_begin_omp_task ();
8461 c_parser_statement (parser
);
8462 return c_finish_omp_task (loc
, clauses
, block
);
8466 # pragma omp taskwait new-line
8470 c_parser_omp_taskwait (c_parser
*parser
)
8472 location_t loc
= c_parser_peek_token (parser
)->location
;
8473 c_parser_consume_pragma (parser
);
8474 c_parser_skip_to_pragma_eol (parser
);
8476 c_finish_omp_taskwait (loc
);
8479 /* Main entry point to parsing most OpenMP pragmas. */
8482 c_parser_omp_construct (c_parser
*parser
)
8484 enum pragma_kind p_kind
;
8488 loc
= c_parser_peek_token (parser
)->location
;
8489 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8490 c_parser_consume_pragma (parser
);
8492 /* For all constructs below except #pragma omp atomic
8493 MUST_NOT_THROW catch handlers are needed when exceptions
8495 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8496 c_maybe_initialize_eh ();
8500 case PRAGMA_OMP_ATOMIC
:
8501 c_parser_omp_atomic (loc
, parser
);
8503 case PRAGMA_OMP_CRITICAL
:
8504 stmt
= c_parser_omp_critical (loc
, parser
);
8506 case PRAGMA_OMP_FOR
:
8507 stmt
= c_parser_omp_for (loc
, parser
);
8509 case PRAGMA_OMP_MASTER
:
8510 stmt
= c_parser_omp_master (loc
, parser
);
8512 case PRAGMA_OMP_ORDERED
:
8513 stmt
= c_parser_omp_ordered (loc
, parser
);
8515 case PRAGMA_OMP_PARALLEL
:
8516 stmt
= c_parser_omp_parallel (loc
, parser
);
8518 case PRAGMA_OMP_SECTIONS
:
8519 stmt
= c_parser_omp_sections (loc
, parser
);
8521 case PRAGMA_OMP_SINGLE
:
8522 stmt
= c_parser_omp_single (loc
, parser
);
8524 case PRAGMA_OMP_TASK
:
8525 stmt
= c_parser_omp_task (loc
, parser
);
8532 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
8537 # pragma omp threadprivate (variable-list) */
8540 c_parser_omp_threadprivate (c_parser
*parser
)
8545 c_parser_consume_pragma (parser
);
8546 loc
= c_parser_peek_token (parser
)->location
;
8547 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8549 /* Mark every variable in VARS to be assigned thread local storage. */
8550 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8552 tree v
= TREE_PURPOSE (t
);
8554 /* FIXME diagnostics: Ideally we should keep individual
8555 locations for all the variables in the var list to make the
8556 following errors more precise. Perhaps
8557 c_parser_omp_var_list_parens() should construct a list of
8558 locations to go along with the var list. */
8560 /* If V had already been marked threadprivate, it doesn't matter
8561 whether it had been used prior to this point. */
8562 if (TREE_CODE (v
) != VAR_DECL
)
8563 error_at (loc
, "%qD is not a variable", v
);
8564 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8565 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
8566 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8567 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
8568 else if (TREE_TYPE (v
) == error_mark_node
)
8570 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8571 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
8574 if (! DECL_THREAD_LOCAL_P (v
))
8576 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8577 /* If rtl has been already set for this var, call
8578 make_decl_rtl once again, so that encode_section_info
8579 has a chance to look at the new decl flags. */
8580 if (DECL_RTL_SET_P (v
))
8583 C_DECL_THREADPRIVATE_P (v
) = 1;
8587 c_parser_skip_to_pragma_eol (parser
);
8591 /* Parse a single source file. */
8596 /* Use local storage to begin. If the first token is a pragma, parse it.
8597 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8598 which will cause garbage collection. */
8601 memset (&tparser
, 0, sizeof tparser
);
8602 the_parser
= &tparser
;
8604 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8605 c_parser_pragma_pch_preprocess (&tparser
);
8607 the_parser
= GGC_NEW (c_parser
);
8608 *the_parser
= tparser
;
8610 c_parser_translation_unit (the_parser
);
8614 #include "gt-c-parser.h"