1 /* Parser for C and Objective-C.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Parser actions based on the old Bison parser; structure somewhat
7 influenced by and fragments based on the C++ parser.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 Make sure all relevant comments, and all relevant code from all
28 actions, brought over from old parser. Verify exact correspondence
31 Add testcases covering every input symbol in every state in old and
34 Include full syntax for GNU C, including erroneous cases accepted
35 with error messages, in syntax productions in comments.
37 Make more diagnostics in the front end generally take an explicit
38 location rather than implicitly using input_location. */
42 #include "coretypes.h"
46 #include "langhooks.h"
63 /* Initialization routine for this file. */
68 /* The only initialization required is of the reserved word
79 mask
|= D_ASM
| D_EXT
;
83 if (!c_dialect_objc ())
84 mask
|= D_OBJC
| D_CXX_OBJC
;
86 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
87 for (i
= 0; i
< num_c_common_reswords
; i
++)
89 /* If a keyword is disabled, do not enter it into the table
90 and so create a canonical spelling that isn't a keyword. */
91 if (c_common_reswords
[i
].disable
& mask
)
94 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
96 id
= get_identifier (c_common_reswords
[i
].word
);
97 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
98 C_IS_RESERVED_WORD (id
) = 1;
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
105 C_IS_RESERVED_WORD (id
) = 1;
106 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
110 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
111 and the C parser. Unlike the C++ lexer, the parser structure
112 stores the lexer information instead of using a separate structure.
113 Identifiers are separated into ordinary identifiers, type names,
114 keywords and some other Objective-C types of identifiers, and some
115 look-ahead is maintained.
117 ??? It might be a good idea to lex the whole file up front (as for
118 C++). It would then be possible to share more of the C and C++
119 lexer code, if desired. */
121 /* The following local token type is used. */
124 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
126 /* More information about the type of a CPP_NAME token. */
127 typedef enum c_id_kind
{
128 /* An ordinary identifier. */
130 /* An identifier declared as a typedef name. */
132 /* An identifier declared as an Objective-C class name. */
134 /* Not an identifier. */
138 /* A single C token after string literal concatenation and conversion
139 of preprocessing tokens to tokens. */
140 typedef struct GTY (()) c_token
{
141 /* The kind of token. */
142 ENUM_BITFIELD (cpp_ttype
) type
: 8;
143 /* If this token is a CPP_NAME, this value indicates whether also
144 declared as some kind of type. Otherwise, it is C_ID_NONE. */
145 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
146 /* If this token is a keyword, this value indicates which keyword.
147 Otherwise, this value is RID_MAX. */
148 ENUM_BITFIELD (rid
) keyword
: 8;
149 /* If this token is a CPP_PRAGMA, this indicates the pragma that
150 was seen. Otherwise it is PRAGMA_NONE. */
151 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
152 /* The value associated with this token, if any. */
154 /* The location at which this token was found. */
158 /* A parser structure recording information about the state and
159 context of parsing. Includes lexer information with up to two
160 tokens of look-ahead; more are not needed for C. */
161 typedef struct GTY(()) c_parser
{
162 /* The look-ahead tokens. */
164 /* How many look-ahead tokens are available (0, 1 or 2). */
166 /* True if a syntax error is being recovered from; false otherwise.
167 c_parser_error sets this flag. It should clear this flag when
168 enough tokens have been consumed to recover from the error. */
169 BOOL_BITFIELD error
: 1;
170 /* True if we're processing a pragma, and shouldn't automatically
171 consume CPP_PRAGMA_EOL. */
172 BOOL_BITFIELD in_pragma
: 1;
173 /* True if we're parsing the outermost block of an if statement. */
174 BOOL_BITFIELD in_if_block
: 1;
175 /* True if we want to lex an untranslated string. */
176 BOOL_BITFIELD lex_untranslated_string
: 1;
177 /* Objective-C specific parser/lexer information. */
178 BOOL_BITFIELD objc_pq_context
: 1;
179 /* The following flag is needed to contextualize Objective-C lexical
180 analysis. In some cases (e.g., 'int NSObject;'), it is
181 undesirable to bind an identifier to an Objective-C class, even
182 if a class with that name exists. */
183 BOOL_BITFIELD objc_need_raw_identifier
: 1;
187 /* The actual parser and external interface. ??? Does this need to be
188 garbage-collected? */
190 static GTY (()) c_parser
*the_parser
;
193 /* Read in and lex a single token, storing it in *TOKEN. */
196 c_lex_one_token (c_parser
*parser
, c_token
*token
)
198 timevar_push (TV_LEX
);
200 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
201 (parser
->lex_untranslated_string
202 ? C_LEX_STRING_NO_TRANSLATE
: 0));
203 token
->id_kind
= C_ID_NONE
;
204 token
->keyword
= RID_MAX
;
205 token
->pragma_kind
= PRAGMA_NONE
;
213 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
214 if (c_dialect_objc ())
215 parser
->objc_need_raw_identifier
= false;
217 if (C_IS_RESERVED_WORD (token
->value
))
219 enum rid rid_code
= C_RID_CODE (token
->value
);
221 if (rid_code
== RID_CXX_COMPAT_WARN
)
223 warning_at (token
->location
,
225 "identifier %qE conflicts with C++ keyword",
228 else if (c_dialect_objc ())
230 if (!objc_is_reserved_word (token
->value
)
231 && (!OBJC_IS_PQ_KEYWORD (rid_code
)
232 || parser
->objc_pq_context
))
234 /* Return the canonical spelling for this keyword. */
235 token
->value
= ridpointers
[(int) rid_code
];
236 token
->type
= CPP_KEYWORD
;
237 token
->keyword
= rid_code
;
243 token
->type
= CPP_KEYWORD
;
244 token
->keyword
= rid_code
;
249 decl
= lookup_name (token
->value
);
252 if (TREE_CODE (decl
) == TYPE_DECL
)
254 token
->id_kind
= C_ID_TYPENAME
;
258 else if (c_dialect_objc ())
260 tree objc_interface_decl
= objc_is_class_name (token
->value
);
261 /* Objective-C class names are in the same namespace as
262 variables and typedefs, and hence are shadowed by local
264 if (objc_interface_decl
265 && (global_bindings_p ()
266 || (!objc_force_identifier
&& !decl
)))
268 token
->value
= objc_interface_decl
;
269 token
->id_kind
= C_ID_CLASSNAME
;
273 token
->id_kind
= C_ID_ID
;
277 /* This only happens in Objective-C; it must be a keyword. */
278 token
->type
= CPP_KEYWORD
;
279 token
->keyword
= C_RID_CODE (token
->value
);
283 case CPP_CLOSE_PAREN
:
285 /* These tokens may affect the interpretation of any identifiers
286 following, if doing Objective-C. */
287 if (c_dialect_objc ())
288 parser
->objc_need_raw_identifier
= false;
291 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
292 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
298 timevar_pop (TV_LEX
);
301 /* Return a pointer to the next token from PARSER, reading it in if
304 static inline c_token
*
305 c_parser_peek_token (c_parser
*parser
)
307 if (parser
->tokens_avail
== 0)
309 c_lex_one_token (parser
, &parser
->tokens
[0]);
310 parser
->tokens_avail
= 1;
312 return &parser
->tokens
[0];
315 /* Return true if the next token from PARSER has the indicated
319 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
321 return c_parser_peek_token (parser
)->type
== type
;
324 /* Return true if the next token from PARSER does not have the
328 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
330 return !c_parser_next_token_is (parser
, type
);
333 /* Return true if the next token from PARSER is the indicated
337 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
339 return c_parser_peek_token (parser
)->keyword
== keyword
;
342 /* Return true if TOKEN can start a type name,
345 c_token_starts_typename (c_token
*token
)
350 switch (token
->id_kind
)
357 gcc_assert (c_dialect_objc ());
363 switch (token
->keyword
)
395 if (c_dialect_objc ())
403 /* Return true if the next token from PARSER can start a type name,
406 c_parser_next_token_starts_typename (c_parser
*parser
)
408 c_token
*token
= c_parser_peek_token (parser
);
409 return c_token_starts_typename (token
);
412 /* Return true if TOKEN can start declaration specifiers, false
415 c_token_starts_declspecs (c_token
*token
)
420 switch (token
->id_kind
)
427 gcc_assert (c_dialect_objc ());
433 switch (token
->keyword
)
472 if (c_dialect_objc ())
480 /* Return true if the next token from PARSER can start declaration
481 specifiers, false otherwise. */
483 c_parser_next_token_starts_declspecs (c_parser
*parser
)
485 c_token
*token
= c_parser_peek_token (parser
);
486 return c_token_starts_declspecs (token
);
489 /* Return a pointer to the next-but-one token from PARSER, reading it
490 in if necessary. The next token is already read in. */
493 c_parser_peek_2nd_token (c_parser
*parser
)
495 if (parser
->tokens_avail
>= 2)
496 return &parser
->tokens
[1];
497 gcc_assert (parser
->tokens_avail
== 1);
498 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
499 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
500 c_lex_one_token (parser
, &parser
->tokens
[1]);
501 parser
->tokens_avail
= 2;
502 return &parser
->tokens
[1];
505 /* Consume the next token from PARSER. */
508 c_parser_consume_token (c_parser
*parser
)
510 gcc_assert (parser
->tokens_avail
>= 1);
511 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
512 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
513 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
514 if (parser
->tokens_avail
== 2)
515 parser
->tokens
[0] = parser
->tokens
[1];
516 parser
->tokens_avail
--;
519 /* Expect the current token to be a #pragma. Consume it and remember
520 that we've begun parsing a pragma. */
523 c_parser_consume_pragma (c_parser
*parser
)
525 gcc_assert (!parser
->in_pragma
);
526 gcc_assert (parser
->tokens_avail
>= 1);
527 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
528 if (parser
->tokens_avail
== 2)
529 parser
->tokens
[0] = parser
->tokens
[1];
530 parser
->tokens_avail
--;
531 parser
->in_pragma
= true;
534 /* Update the globals input_location and in_system_header from
537 c_parser_set_source_position_from_token (c_token
*token
)
539 if (token
->type
!= CPP_EOF
)
541 input_location
= token
->location
;
545 /* Issue a diagnostic of the form
546 FILE:LINE: MESSAGE before TOKEN
547 where TOKEN is the next token in the input stream of PARSER.
548 MESSAGE (specified by the caller) is usually of the form "expected
551 Do not issue a diagnostic if still recovering from an error.
553 ??? This is taken from the C++ parser, but building up messages in
554 this way is not i18n-friendly and some other approach should be
558 c_parser_error (c_parser
*parser
, const char *gmsgid
)
560 c_token
*token
= c_parser_peek_token (parser
);
563 parser
->error
= true;
566 /* This diagnostic makes more sense if it is tagged to the line of
567 the token we just peeked at. */
568 c_parser_set_source_position_from_token (token
);
569 c_parse_error (gmsgid
,
570 /* Because c_parse_error does not understand
571 CPP_KEYWORD, keywords are treated like
573 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
574 /* ??? The C parser does not save the cpp flags of a
575 token, we need to pass 0 here and we will not get
576 the source spelling of some tokens but rather the
577 canonical spelling. */
578 token
->value
, /*flags=*/0);
581 /* If the next token is of the indicated TYPE, consume it. Otherwise,
582 issue the error MSGID. If MSGID is NULL then a message has already
583 been produced and no message will be produced this time. Returns
584 true if found, false otherwise. */
587 c_parser_require (c_parser
*parser
,
591 if (c_parser_next_token_is (parser
, type
))
593 c_parser_consume_token (parser
);
598 c_parser_error (parser
, msgid
);
603 /* If the next token is the indicated keyword, consume it. Otherwise,
604 issue the error MSGID. Returns true if found, false otherwise. */
607 c_parser_require_keyword (c_parser
*parser
,
611 if (c_parser_next_token_is_keyword (parser
, keyword
))
613 c_parser_consume_token (parser
);
618 c_parser_error (parser
, msgid
);
623 /* Like c_parser_require, except that tokens will be skipped until the
624 desired token is found. An error message is still produced if the
625 next token is not as expected. If MSGID is NULL then a message has
626 already been produced and no message will be produced this
630 c_parser_skip_until_found (c_parser
*parser
,
634 unsigned nesting_depth
= 0;
636 if (c_parser_require (parser
, type
, msgid
))
639 /* Skip tokens until the desired token is found. */
642 /* Peek at the next token. */
643 c_token
*token
= c_parser_peek_token (parser
);
644 /* If we've reached the token we want, consume it and stop. */
645 if (token
->type
== type
&& !nesting_depth
)
647 c_parser_consume_token (parser
);
651 /* If we've run out of tokens, stop. */
652 if (token
->type
== CPP_EOF
)
654 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
656 if (token
->type
== CPP_OPEN_BRACE
657 || token
->type
== CPP_OPEN_PAREN
658 || token
->type
== CPP_OPEN_SQUARE
)
660 else if (token
->type
== CPP_CLOSE_BRACE
661 || token
->type
== CPP_CLOSE_PAREN
662 || token
->type
== CPP_CLOSE_SQUARE
)
664 if (nesting_depth
-- == 0)
667 /* Consume this token. */
668 c_parser_consume_token (parser
);
670 parser
->error
= false;
673 /* Skip tokens until the end of a parameter is found, but do not
674 consume the comma, semicolon or closing delimiter. */
677 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
679 unsigned nesting_depth
= 0;
683 c_token
*token
= c_parser_peek_token (parser
);
684 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
687 /* If we've run out of tokens, stop. */
688 if (token
->type
== CPP_EOF
)
690 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
692 if (token
->type
== CPP_OPEN_BRACE
693 || token
->type
== CPP_OPEN_PAREN
694 || token
->type
== CPP_OPEN_SQUARE
)
696 else if (token
->type
== CPP_CLOSE_BRACE
697 || token
->type
== CPP_CLOSE_PAREN
698 || token
->type
== CPP_CLOSE_SQUARE
)
700 if (nesting_depth
-- == 0)
703 /* Consume this token. */
704 c_parser_consume_token (parser
);
706 parser
->error
= false;
709 /* Expect to be at the end of the pragma directive and consume an
710 end of line marker. */
713 c_parser_skip_to_pragma_eol (c_parser
*parser
)
715 gcc_assert (parser
->in_pragma
);
716 parser
->in_pragma
= false;
718 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
721 c_token
*token
= c_parser_peek_token (parser
);
722 if (token
->type
== CPP_EOF
)
724 if (token
->type
== CPP_PRAGMA_EOL
)
726 c_parser_consume_token (parser
);
729 c_parser_consume_token (parser
);
732 parser
->error
= false;
735 /* Skip tokens until we have consumed an entire block, or until we
736 have consumed a non-nested ';'. */
739 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
741 unsigned nesting_depth
= 0;
742 bool save_error
= parser
->error
;
748 /* Peek at the next token. */
749 token
= c_parser_peek_token (parser
);
757 if (parser
->in_pragma
)
762 /* If the next token is a ';', we have reached the
763 end of the statement. */
766 /* Consume the ';'. */
767 c_parser_consume_token (parser
);
772 case CPP_CLOSE_BRACE
:
773 /* If the next token is a non-nested '}', then we have
774 reached the end of the current block. */
775 if (nesting_depth
== 0 || --nesting_depth
== 0)
777 c_parser_consume_token (parser
);
783 /* If it the next token is a '{', then we are entering a new
784 block. Consume the entire block. */
789 /* If we see a pragma, consume the whole thing at once. We
790 have some safeguards against consuming pragmas willy-nilly.
791 Normally, we'd expect to be here with parser->error set,
792 which disables these safeguards. But it's possible to get
793 here for secondary error recovery, after parser->error has
795 c_parser_consume_pragma (parser
);
796 c_parser_skip_to_pragma_eol (parser
);
797 parser
->error
= save_error
;
804 c_parser_consume_token (parser
);
808 parser
->error
= false;
811 /* CPP's options (initialized by c-opts.c). */
812 extern cpp_options
*cpp_opts
;
814 /* Save the warning flags which are controlled by __extension__. */
817 disable_extension_diagnostics (void)
820 | (warn_pointer_arith
<< 1)
821 | (warn_traditional
<< 2)
823 | (warn_long_long
<< 4)
824 | (warn_cxx_compat
<< 5));
825 cpp_opts
->pedantic
= pedantic
= 0;
826 warn_pointer_arith
= 0;
827 cpp_opts
->warn_traditional
= warn_traditional
= 0;
829 cpp_opts
->warn_long_long
= warn_long_long
= 0;
834 /* Restore the warning flags which are controlled by __extension__.
835 FLAGS is the return value from disable_extension_diagnostics. */
838 restore_extension_diagnostics (int flags
)
840 cpp_opts
->pedantic
= pedantic
= flags
& 1;
841 warn_pointer_arith
= (flags
>> 1) & 1;
842 cpp_opts
->warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
843 flag_iso
= (flags
>> 3) & 1;
844 cpp_opts
->warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
845 warn_cxx_compat
= (flags
>> 5) & 1;
848 /* Possibly kinds of declarator to parse. */
849 typedef enum c_dtr_syn
{
850 /* A normal declarator with an identifier. */
852 /* An abstract declarator (maybe empty). */
854 /* A parameter declarator: may be either, but after a type name does
855 not redeclare a typedef name as an identifier if it can
856 alternatively be interpreted as a typedef name; see DR#009,
857 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
858 following DR#249. For example, given a typedef T, "int T" and
859 "int *T" are valid parameter declarations redeclaring T, while
860 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
861 abstract declarators rather than involving redundant parentheses;
862 the same applies with attributes inside the parentheses before
867 static void c_parser_external_declaration (c_parser
*);
868 static void c_parser_asm_definition (c_parser
*);
869 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
870 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
872 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
873 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
874 static tree
c_parser_struct_declaration (c_parser
*);
875 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
876 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
878 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
880 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
882 struct c_declarator
*);
883 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
884 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
885 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
886 static tree
c_parser_simple_asm_expr (c_parser
*);
887 static tree
c_parser_attributes (c_parser
*);
888 static struct c_type_name
*c_parser_type_name (c_parser
*);
889 static struct c_expr
c_parser_initializer (c_parser
*);
890 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
891 static void c_parser_initelt (c_parser
*);
892 static void c_parser_initval (c_parser
*, struct c_expr
*);
893 static tree
c_parser_compound_statement (c_parser
*);
894 static void c_parser_compound_statement_nostart (c_parser
*);
895 static void c_parser_label (c_parser
*);
896 static void c_parser_statement (c_parser
*);
897 static void c_parser_statement_after_labels (c_parser
*);
898 static void c_parser_if_statement (c_parser
*);
899 static void c_parser_switch_statement (c_parser
*);
900 static void c_parser_while_statement (c_parser
*);
901 static void c_parser_do_statement (c_parser
*);
902 static void c_parser_for_statement (c_parser
*);
903 static tree
c_parser_asm_statement (c_parser
*);
904 static tree
c_parser_asm_operands (c_parser
*, bool);
905 static tree
c_parser_asm_clobbers (c_parser
*);
906 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
907 static struct c_expr
c_parser_conditional_expression (c_parser
*,
909 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
910 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
911 static struct c_expr
c_parser_unary_expression (c_parser
*);
912 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
913 static struct c_expr
c_parser_alignof_expression (c_parser
*);
914 static struct c_expr
c_parser_postfix_expression (c_parser
*);
915 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
916 struct c_type_name
*,
918 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
920 static struct c_expr
c_parser_expression (c_parser
*);
921 static struct c_expr
c_parser_expression_conv (c_parser
*);
922 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
924 static void c_parser_omp_construct (c_parser
*);
925 static void c_parser_omp_threadprivate (c_parser
*);
926 static void c_parser_omp_barrier (c_parser
*);
927 static void c_parser_omp_flush (c_parser
*);
928 static void c_parser_omp_taskwait (c_parser
*);
930 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
931 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
933 /* These Objective-C parser functions are only ever called when
934 compiling Objective-C. */
935 static void c_parser_objc_class_definition (c_parser
*);
936 static void c_parser_objc_class_instance_variables (c_parser
*);
937 static void c_parser_objc_class_declaration (c_parser
*);
938 static void c_parser_objc_alias_declaration (c_parser
*);
939 static void c_parser_objc_protocol_definition (c_parser
*);
940 static enum tree_code
c_parser_objc_method_type (c_parser
*);
941 static void c_parser_objc_method_definition (c_parser
*);
942 static void c_parser_objc_methodprotolist (c_parser
*);
943 static void c_parser_objc_methodproto (c_parser
*);
944 static tree
c_parser_objc_method_decl (c_parser
*);
945 static tree
c_parser_objc_type_name (c_parser
*);
946 static tree
c_parser_objc_protocol_refs (c_parser
*);
947 static void c_parser_objc_try_catch_statement (c_parser
*);
948 static void c_parser_objc_synchronized_statement (c_parser
*);
949 static tree
c_parser_objc_selector (c_parser
*);
950 static tree
c_parser_objc_selector_arg (c_parser
*);
951 static tree
c_parser_objc_receiver (c_parser
*);
952 static tree
c_parser_objc_message_args (c_parser
*);
953 static tree
c_parser_objc_keywordexpr (c_parser
*);
955 /* Parse a translation unit (C90 6.7, C99 6.9).
958 external-declarations
960 external-declarations:
962 external-declarations external-declaration
971 c_parser_translation_unit (c_parser
*parser
)
973 if (c_parser_next_token_is (parser
, CPP_EOF
))
975 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
976 "ISO C forbids an empty translation unit");
980 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
981 mark_valid_location_for_stdc_pragma (false);
985 c_parser_external_declaration (parser
);
986 obstack_free (&parser_obstack
, obstack_position
);
988 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
992 /* Parse an external declaration (C90 6.7, C99 6.9).
994 external-declaration:
1000 external-declaration:
1003 __extension__ external-declaration
1007 external-declaration:
1008 objc-class-definition
1009 objc-class-declaration
1010 objc-alias-declaration
1011 objc-protocol-definition
1012 objc-method-definition
1017 c_parser_external_declaration (c_parser
*parser
)
1020 switch (c_parser_peek_token (parser
)->type
)
1023 switch (c_parser_peek_token (parser
)->keyword
)
1026 ext
= disable_extension_diagnostics ();
1027 c_parser_consume_token (parser
);
1028 c_parser_external_declaration (parser
);
1029 restore_extension_diagnostics (ext
);
1032 c_parser_asm_definition (parser
);
1034 case RID_AT_INTERFACE
:
1035 case RID_AT_IMPLEMENTATION
:
1036 gcc_assert (c_dialect_objc ());
1037 c_parser_objc_class_definition (parser
);
1040 gcc_assert (c_dialect_objc ());
1041 c_parser_objc_class_declaration (parser
);
1044 gcc_assert (c_dialect_objc ());
1045 c_parser_objc_alias_declaration (parser
);
1047 case RID_AT_PROTOCOL
:
1048 gcc_assert (c_dialect_objc ());
1049 c_parser_objc_protocol_definition (parser
);
1052 gcc_assert (c_dialect_objc ());
1053 c_parser_consume_token (parser
);
1054 objc_finish_implementation ();
1061 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1062 "ISO C does not allow extra %<;%> outside of a function");
1063 c_parser_consume_token (parser
);
1066 mark_valid_location_for_stdc_pragma (true);
1067 c_parser_pragma (parser
, pragma_external
);
1068 mark_valid_location_for_stdc_pragma (false);
1072 if (c_dialect_objc ())
1074 c_parser_objc_method_definition (parser
);
1077 /* Else fall through, and yield a syntax error trying to parse
1078 as a declaration or function definition. */
1081 /* A declaration or a function definition. We can only tell
1082 which after parsing the declaration specifiers, if any, and
1083 the first declarator. */
1084 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1090 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1091 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1092 accepted; otherwise (old-style parameter declarations) only other
1093 declarations are accepted. If NESTED is true, we are inside a
1094 function or parsing old-style parameter declarations; any functions
1095 encountered are nested functions and declaration specifiers are
1096 required; otherwise we are at top level and functions are normal
1097 functions and declaration specifiers may be optional. If EMPTY_OK
1098 is true, empty declarations are OK (subject to all other
1099 constraints); otherwise (old-style parameter declarations) they are
1100 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1101 may start with attributes; otherwise they may not.
1104 declaration-specifiers init-declarator-list[opt] ;
1106 function-definition:
1107 declaration-specifiers[opt] declarator declaration-list[opt]
1112 declaration-list declaration
1114 init-declarator-list:
1116 init-declarator-list , init-declarator
1119 declarator simple-asm-expr[opt] attributes[opt]
1120 declarator simple-asm-expr[opt] attributes[opt] = initializer
1124 nested-function-definition:
1125 declaration-specifiers declarator declaration-list[opt]
1128 The simple-asm-expr and attributes are GNU extensions.
1130 This function does not handle __extension__; that is handled in its
1131 callers. ??? Following the old parser, __extension__ may start
1132 external declarations, declarations in functions and declarations
1133 at the start of "for" loops, but not old-style parameter
1136 C99 requires declaration specifiers in a function definition; the
1137 absence is diagnosed through the diagnosis of implicit int. In GNU
1138 C we also allow but diagnose declarations without declaration
1139 specifiers, but only at top level (elsewhere they conflict with
1145 threadprivate-directive */
1148 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1149 bool nested
, bool start_attr_ok
)
1151 struct c_declspecs
*specs
;
1153 tree all_prefix_attrs
;
1154 bool diagnosed_no_specs
= false;
1155 location_t here
= c_parser_peek_token (parser
)->location
;
1157 specs
= build_null_declspecs ();
1158 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1161 c_parser_skip_to_end_of_block_or_statement (parser
);
1164 if (nested
&& !specs
->declspecs_seen_p
)
1166 c_parser_error (parser
, "expected declaration specifiers");
1167 c_parser_skip_to_end_of_block_or_statement (parser
);
1170 finish_declspecs (specs
);
1171 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1177 shadow_tag_warned (specs
, 1);
1178 pedwarn (here
, 0, "empty declaration");
1180 c_parser_consume_token (parser
);
1183 pending_xref_error ();
1184 prefix_attrs
= specs
->attrs
;
1185 all_prefix_attrs
= prefix_attrs
;
1186 specs
->attrs
= NULL_TREE
;
1189 struct c_declarator
*declarator
;
1192 /* Declaring either one or more declarators (in which case we
1193 should diagnose if there were no declaration specifiers) or a
1194 function definition (in which case the diagnostic for
1195 implicit int suffices). */
1196 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1197 C_DTR_NORMAL
, &dummy
);
1198 if (declarator
== NULL
)
1200 c_parser_skip_to_end_of_block_or_statement (parser
);
1203 if (c_parser_next_token_is (parser
, CPP_EQ
)
1204 || c_parser_next_token_is (parser
, CPP_COMMA
)
1205 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1206 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1207 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1209 tree asm_name
= NULL_TREE
;
1210 tree postfix_attrs
= NULL_TREE
;
1211 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1213 diagnosed_no_specs
= true;
1214 pedwarn (here
, 0, "data definition has no type or storage class");
1216 /* Having seen a data definition, there cannot now be a
1217 function definition. */
1219 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1220 asm_name
= c_parser_simple_asm_expr (parser
);
1221 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1222 postfix_attrs
= c_parser_attributes (parser
);
1223 if (c_parser_next_token_is (parser
, CPP_EQ
))
1227 c_parser_consume_token (parser
);
1228 /* The declaration of the variable is in effect while
1229 its initializer is parsed. */
1230 d
= start_decl (declarator
, specs
, true,
1231 chainon (postfix_attrs
, all_prefix_attrs
));
1233 d
= error_mark_node
;
1234 start_init (d
, asm_name
, global_bindings_p ());
1235 init
= c_parser_initializer (parser
);
1237 if (d
!= error_mark_node
)
1239 maybe_warn_string_init (TREE_TYPE (d
), init
);
1240 finish_decl (d
, init
.value
, init
.original_type
, asm_name
);
1245 tree d
= start_decl (declarator
, specs
, false,
1246 chainon (postfix_attrs
,
1249 finish_decl (d
, NULL_TREE
, NULL_TREE
, asm_name
);
1251 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1253 c_parser_consume_token (parser
);
1254 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1255 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1258 all_prefix_attrs
= prefix_attrs
;
1261 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1263 c_parser_consume_token (parser
);
1268 c_parser_error (parser
, "expected %<,%> or %<;%>");
1269 c_parser_skip_to_end_of_block_or_statement (parser
);
1275 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1276 "%<asm%> or %<__attribute__%>");
1277 c_parser_skip_to_end_of_block_or_statement (parser
);
1280 /* Function definition (nested or otherwise). */
1283 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1284 c_push_function_context ();
1286 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1288 /* This can appear in many cases looking nothing like a
1289 function definition, so we don't give a more specific
1290 error suggesting there was one. */
1291 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1292 "or %<__attribute__%>");
1294 c_pop_function_context ();
1297 /* Parse old-style parameter declarations. ??? Attributes are
1298 not allowed to start declaration specifiers here because of a
1299 syntax conflict between a function declaration with attribute
1300 suffix and a function definition with an attribute prefix on
1301 first old-style parameter declaration. Following the old
1302 parser, they are not accepted on subsequent old-style
1303 parameter declarations either. However, there is no
1304 ambiguity after the first declaration, nor indeed on the
1305 first as long as we don't allow postfix attributes after a
1306 declarator with a nonempty identifier list in a definition;
1307 and postfix attributes have never been accepted here in
1308 function definitions either. */
1309 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1310 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1311 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1312 store_parm_decls ();
1313 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1314 = c_parser_peek_token (parser
)->location
;
1315 fnbody
= c_parser_compound_statement (parser
);
1318 tree decl
= current_function_decl
;
1321 c_pop_function_context ();
1322 add_stmt (build_stmt (DECL_EXPR
, decl
));
1333 /* Parse an asm-definition (asm() outside a function body). This is a
1341 c_parser_asm_definition (c_parser
*parser
)
1343 tree asm_str
= c_parser_simple_asm_expr (parser
);
1345 cgraph_add_asm_node (asm_str
);
1346 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1349 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1350 6.7), adding them to SPECS (which may already include some).
1351 Storage class specifiers are accepted iff SCSPEC_OK; type
1352 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1353 the start iff START_ATTR_OK.
1355 declaration-specifiers:
1356 storage-class-specifier declaration-specifiers[opt]
1357 type-specifier declaration-specifiers[opt]
1358 type-qualifier declaration-specifiers[opt]
1359 function-specifier declaration-specifiers[opt]
1361 Function specifiers (inline) are from C99, and are currently
1362 handled as storage class specifiers, as is __thread.
1364 C90 6.5.1, C99 6.7.1:
1365 storage-class-specifier:
1376 C90 6.5.2, C99 6.7.2:
1389 [_Imaginary removed in C99 TC2]
1390 struct-or-union-specifier
1394 (_Bool and _Complex are new in C99.)
1396 C90 6.5.3, C99 6.7.3:
1403 (restrict is new in C99.)
1407 declaration-specifiers:
1408 attributes declaration-specifiers[opt]
1410 storage-class-specifier:
1422 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1423 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1428 class-name objc-protocol-refs[opt]
1429 typedef-name objc-protocol-refs
1434 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1435 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1437 bool attrs_ok
= start_attr_ok
;
1438 bool seen_type
= specs
->type_seen_p
;
1439 while (c_parser_next_token_is (parser
, CPP_NAME
)
1440 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1441 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1443 struct c_typespec t
;
1445 if (c_parser_next_token_is (parser
, CPP_NAME
))
1447 tree value
= c_parser_peek_token (parser
)->value
;
1448 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1449 /* This finishes the specifiers unless a type name is OK, it
1450 is declared as a type name and a type name hasn't yet
1452 if (!typespec_ok
|| seen_type
1453 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1455 c_parser_consume_token (parser
);
1458 if (kind
== C_ID_TYPENAME
1459 && (!c_dialect_objc ()
1460 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1462 t
.kind
= ctsk_typedef
;
1463 /* For a typedef name, record the meaning, not the name.
1464 In case of 'foo foo, bar;'. */
1465 t
.spec
= lookup_name (value
);
1467 t
.expr_const_operands
= true;
1471 tree proto
= NULL_TREE
;
1472 gcc_assert (c_dialect_objc ());
1474 if (c_parser_next_token_is (parser
, CPP_LESS
))
1475 proto
= c_parser_objc_protocol_refs (parser
);
1476 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1478 t
.expr_const_operands
= true;
1480 declspecs_add_type (specs
, t
);
1483 if (c_parser_next_token_is (parser
, CPP_LESS
))
1485 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1486 nisse@lysator.liu.se. */
1488 gcc_assert (c_dialect_objc ());
1489 if (!typespec_ok
|| seen_type
)
1491 proto
= c_parser_objc_protocol_refs (parser
);
1493 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1495 t
.expr_const_operands
= true;
1496 declspecs_add_type (specs
, t
);
1499 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1500 switch (c_parser_peek_token (parser
)->keyword
)
1512 /* TODO: Distinguish between function specifiers (inline)
1513 and storage class specifiers, either here or in
1514 declspecs_add_scspec. */
1515 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1516 c_parser_consume_token (parser
);
1539 if (c_dialect_objc ())
1540 parser
->objc_need_raw_identifier
= true;
1541 t
.kind
= ctsk_resword
;
1542 t
.spec
= c_parser_peek_token (parser
)->value
;
1544 t
.expr_const_operands
= true;
1545 declspecs_add_type (specs
, t
);
1546 c_parser_consume_token (parser
);
1553 t
= c_parser_enum_specifier (parser
);
1554 declspecs_add_type (specs
, t
);
1562 t
= c_parser_struct_or_union_specifier (parser
);
1563 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1564 declspecs_add_type (specs
, t
);
1567 /* ??? The old parser rejected typeof after other type
1568 specifiers, but is a syntax error the best way of
1570 if (!typespec_ok
|| seen_type
)
1574 t
= c_parser_typeof_specifier (parser
);
1575 declspecs_add_type (specs
, t
);
1581 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1582 c_parser_consume_token (parser
);
1587 attrs
= c_parser_attributes (parser
);
1588 declspecs_add_attrs (specs
, attrs
);
1597 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1600 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1601 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1602 enum attributes[opt] identifier
1604 The form with trailing comma is new in C99. The forms with
1605 attributes are GNU extensions. In GNU C, we accept any expression
1606 without commas in the syntax (assignment expressions, not just
1607 conditional expressions); assignment expressions will be diagnosed
1612 enumerator-list , enumerator
1615 enumeration-constant
1616 enumeration-constant = constant-expression
1619 static struct c_typespec
1620 c_parser_enum_specifier (c_parser
*parser
)
1622 struct c_typespec ret
;
1624 tree ident
= NULL_TREE
;
1625 location_t enum_loc
;
1626 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1627 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1628 enum_loc
= c_parser_peek_token (parser
)->location
;
1629 c_parser_consume_token (parser
);
1630 attrs
= c_parser_attributes (parser
);
1631 /* Set the location in case we create a decl now. */
1632 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1633 if (c_parser_next_token_is (parser
, CPP_NAME
))
1635 ident
= c_parser_peek_token (parser
)->value
;
1636 ident_loc
= c_parser_peek_token (parser
)->location
;
1637 enum_loc
= ident_loc
;
1638 c_parser_consume_token (parser
);
1640 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1642 /* Parse an enum definition. */
1643 struct c_enum_contents the_enum
;
1644 tree type
= start_enum (&the_enum
, ident
, enum_loc
);
1646 /* We chain the enumerators in reverse order, then put them in
1647 forward order at the end. */
1648 tree values
= NULL_TREE
;
1649 c_parser_consume_token (parser
);
1657 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1658 location_t value_loc
;
1659 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1661 c_parser_error (parser
, "expected identifier");
1662 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1663 values
= error_mark_node
;
1666 token
= c_parser_peek_token (parser
);
1667 enum_id
= token
->value
;
1668 /* Set the location in case we create a decl now. */
1669 c_parser_set_source_position_from_token (token
);
1670 value_loc
= token
->location
;
1671 c_parser_consume_token (parser
);
1672 if (c_parser_next_token_is (parser
, CPP_EQ
))
1674 c_parser_consume_token (parser
);
1675 value_loc
= c_parser_peek_token (parser
)->location
;
1676 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1679 enum_value
= NULL_TREE
;
1680 enum_decl
= build_enumerator (&the_enum
, enum_id
, enum_value
,
1682 TREE_CHAIN (enum_decl
) = values
;
1685 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1687 comma_loc
= c_parser_peek_token (parser
)->location
;
1689 c_parser_consume_token (parser
);
1691 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1693 if (seen_comma
&& !flag_isoc99
)
1694 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1695 c_parser_consume_token (parser
);
1700 c_parser_error (parser
, "expected %<,%> or %<}%>");
1701 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1702 values
= error_mark_node
;
1706 postfix_attrs
= c_parser_attributes (parser
);
1707 ret
.spec
= finish_enum (type
, nreverse (values
),
1708 chainon (attrs
, postfix_attrs
));
1709 ret
.kind
= ctsk_tagdef
;
1710 ret
.expr
= NULL_TREE
;
1711 ret
.expr_const_operands
= true;
1716 c_parser_error (parser
, "expected %<{%>");
1717 ret
.spec
= error_mark_node
;
1718 ret
.kind
= ctsk_tagref
;
1719 ret
.expr
= NULL_TREE
;
1720 ret
.expr_const_operands
= true;
1723 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
, ident_loc
);
1724 /* In ISO C, enumerated types can be referred to only if already
1726 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1729 pedwarn (ident_loc
, OPT_pedantic
,
1730 "ISO C forbids forward references to %<enum%> types");
1735 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1737 struct-or-union-specifier:
1738 struct-or-union attributes[opt] identifier[opt]
1739 { struct-contents } attributes[opt]
1740 struct-or-union attributes[opt] identifier
1743 struct-declaration-list
1745 struct-declaration-list:
1746 struct-declaration ;
1747 struct-declaration-list struct-declaration ;
1754 struct-declaration-list struct-declaration
1756 struct-declaration-list:
1757 struct-declaration-list ;
1760 (Note that in the syntax here, unlike that in ISO C, the semicolons
1761 are included here rather than in struct-declaration, in order to
1762 describe the syntax with extra semicolons and missing semicolon at
1767 struct-declaration-list:
1768 @defs ( class-name )
1770 (Note this does not include a trailing semicolon, but can be
1771 followed by further declarations, and gets a pedwarn-if-pedantic
1772 when followed by a semicolon.) */
1774 static struct c_typespec
1775 c_parser_struct_or_union_specifier (c_parser
*parser
)
1777 struct c_typespec ret
;
1779 tree ident
= NULL_TREE
;
1780 location_t struct_loc
;
1781 location_t ident_loc
= UNKNOWN_LOCATION
;
1782 enum tree_code code
;
1783 switch (c_parser_peek_token (parser
)->keyword
)
1794 struct_loc
= c_parser_peek_token (parser
)->location
;
1795 c_parser_consume_token (parser
);
1796 attrs
= c_parser_attributes (parser
);
1797 /* Set the location in case we create a decl now. */
1798 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1799 if (c_parser_next_token_is (parser
, CPP_NAME
))
1801 ident
= c_parser_peek_token (parser
)->value
;
1802 ident_loc
= c_parser_peek_token (parser
)->location
;
1803 struct_loc
= ident_loc
;
1804 c_parser_consume_token (parser
);
1806 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1808 /* Parse a struct or union definition. Start the scope of the
1809 tag before parsing components. */
1811 VEC(tree
,heap
) *struct_types
;
1812 tree type
= start_struct (code
, ident
, &in_struct
, &struct_types
,
1815 /* We chain the components in reverse order, then put them in
1816 forward order at the end. Each struct-declaration may
1817 declare multiple components (comma-separated), so we must use
1818 chainon to join them, although when parsing each
1819 struct-declaration we can use TREE_CHAIN directly.
1821 The theory behind all this is that there will be more
1822 semicolon separated fields than comma separated fields, and
1823 so we'll be minimizing the number of node traversals required
1825 tree contents
= NULL_TREE
;
1826 c_parser_consume_token (parser
);
1827 /* Handle the Objective-C @defs construct,
1828 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1829 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1832 gcc_assert (c_dialect_objc ());
1833 c_parser_consume_token (parser
);
1834 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1836 if (c_parser_next_token_is (parser
, CPP_NAME
)
1837 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1839 name
= c_parser_peek_token (parser
)->value
;
1840 c_parser_consume_token (parser
);
1844 c_parser_error (parser
, "expected class name");
1845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1850 contents
= nreverse (objc_get_class_ivars (name
));
1853 /* Parse the struct-declarations and semicolons. Problems with
1854 semicolons are diagnosed here; empty structures are diagnosed
1859 /* Parse any stray semicolon. */
1860 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1862 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1863 "extra semicolon in struct or union specified");
1864 c_parser_consume_token (parser
);
1867 /* Stop if at the end of the struct or union contents. */
1868 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1870 c_parser_consume_token (parser
);
1873 /* Accept #pragmas at struct scope. */
1874 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1876 c_parser_pragma (parser
, pragma_external
);
1879 /* Parse some comma-separated declarations, but not the
1880 trailing semicolon if any. */
1881 decls
= c_parser_struct_declaration (parser
);
1882 contents
= chainon (decls
, contents
);
1883 /* If no semicolon follows, either we have a parse error or
1884 are at the end of the struct or union and should
1886 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1887 c_parser_consume_token (parser
);
1890 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1891 pedwarn (c_parser_peek_token (parser
)->location
, 0,
1892 "no semicolon at end of struct or union");
1895 c_parser_error (parser
, "expected %<;%>");
1896 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1901 postfix_attrs
= c_parser_attributes (parser
);
1902 ret
.spec
= finish_struct (type
, nreverse (contents
),
1903 chainon (attrs
, postfix_attrs
),
1904 in_struct
, struct_types
);
1905 ret
.kind
= ctsk_tagdef
;
1906 ret
.expr
= NULL_TREE
;
1907 ret
.expr_const_operands
= true;
1912 c_parser_error (parser
, "expected %<{%>");
1913 ret
.spec
= error_mark_node
;
1914 ret
.kind
= ctsk_tagref
;
1915 ret
.expr
= NULL_TREE
;
1916 ret
.expr_const_operands
= true;
1919 ret
= parser_xref_tag (code
, ident
, ident_loc
);
1923 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1924 the trailing semicolon.
1927 specifier-qualifier-list struct-declarator-list
1929 specifier-qualifier-list:
1930 type-specifier specifier-qualifier-list[opt]
1931 type-qualifier specifier-qualifier-list[opt]
1932 attributes specifier-qualifier-list[opt]
1934 struct-declarator-list:
1936 struct-declarator-list , attributes[opt] struct-declarator
1939 declarator attributes[opt]
1940 declarator[opt] : constant-expression attributes[opt]
1945 __extension__ struct-declaration
1946 specifier-qualifier-list
1948 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1949 of attributes where shown is a GNU extension. In GNU C, we accept
1950 any expression without commas in the syntax (assignment
1951 expressions, not just conditional expressions); assignment
1952 expressions will be diagnosed as non-constant. */
1955 c_parser_struct_declaration (c_parser
*parser
)
1957 struct c_declspecs
*specs
;
1959 tree all_prefix_attrs
;
1961 location_t decl_loc
;
1962 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
1966 ext
= disable_extension_diagnostics ();
1967 c_parser_consume_token (parser
);
1968 decl
= c_parser_struct_declaration (parser
);
1969 restore_extension_diagnostics (ext
);
1972 specs
= build_null_declspecs ();
1973 decl_loc
= c_parser_peek_token (parser
)->location
;
1974 c_parser_declspecs (parser
, specs
, false, true, true);
1977 if (!specs
->declspecs_seen_p
)
1979 c_parser_error (parser
, "expected specifier-qualifier-list");
1982 finish_declspecs (specs
);
1983 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1986 if (!specs
->type_seen_p
)
1988 pedwarn (decl_loc
, OPT_pedantic
,
1989 "ISO C forbids member declarations with no members");
1990 shadow_tag_warned (specs
, pedantic
);
1995 /* Support for unnamed structs or unions as members of
1996 structs or unions (which is [a] useful and [b] supports
2000 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2001 build_id_declarator (NULL_TREE
), specs
,
2004 decl_attributes (&ret
, attrs
, 0);
2008 pending_xref_error ();
2009 prefix_attrs
= specs
->attrs
;
2010 all_prefix_attrs
= prefix_attrs
;
2011 specs
->attrs
= NULL_TREE
;
2015 /* Declaring one or more declarators or un-named bit-fields. */
2016 struct c_declarator
*declarator
;
2018 if (c_parser_next_token_is (parser
, CPP_COLON
))
2019 declarator
= build_id_declarator (NULL_TREE
);
2021 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2022 C_DTR_NORMAL
, &dummy
);
2023 if (declarator
== NULL
)
2025 c_parser_skip_to_end_of_block_or_statement (parser
);
2028 if (c_parser_next_token_is (parser
, CPP_COLON
)
2029 || c_parser_next_token_is (parser
, CPP_COMMA
)
2030 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2031 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2032 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2034 tree postfix_attrs
= NULL_TREE
;
2035 tree width
= NULL_TREE
;
2037 if (c_parser_next_token_is (parser
, CPP_COLON
))
2039 c_parser_consume_token (parser
);
2040 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2042 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2043 postfix_attrs
= c_parser_attributes (parser
);
2044 d
= grokfield (c_parser_peek_token (parser
)->location
,
2045 declarator
, specs
, width
, &all_prefix_attrs
);
2046 decl_attributes (&d
, chainon (postfix_attrs
,
2047 all_prefix_attrs
), 0);
2048 TREE_CHAIN (d
) = decls
;
2050 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2051 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2054 all_prefix_attrs
= prefix_attrs
;
2055 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2056 c_parser_consume_token (parser
);
2057 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2058 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2060 /* Semicolon consumed in caller. */
2065 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2071 c_parser_error (parser
,
2072 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2073 "%<__attribute__%>");
2080 /* Parse a typeof specifier (a GNU extension).
2083 typeof ( expression )
2084 typeof ( type-name )
2087 static struct c_typespec
2088 c_parser_typeof_specifier (c_parser
*parser
)
2090 struct c_typespec ret
;
2091 ret
.kind
= ctsk_typeof
;
2092 ret
.spec
= error_mark_node
;
2093 ret
.expr
= NULL_TREE
;
2094 ret
.expr_const_operands
= true;
2095 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2096 c_parser_consume_token (parser
);
2099 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2105 if (c_parser_next_token_starts_typename (parser
))
2107 struct c_type_name
*type
= c_parser_type_name (parser
);
2112 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2113 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2119 location_t here
= c_parser_peek_token (parser
)->location
;
2120 struct c_expr expr
= c_parser_expression (parser
);
2123 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2124 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2125 error_at (here
, "%<typeof%> applied to a bit-field");
2126 ret
.spec
= TREE_TYPE (expr
.value
);
2127 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2128 /* This is returned with the type so that when the type is
2129 evaluated, this can be evaluated. */
2131 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2132 pop_maybe_used (was_vm
);
2134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2138 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2139 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2140 be redeclared; otherwise it may not. KIND indicates which kind of
2141 declarator is wanted. Returns a valid declarator except in the
2142 case of a syntax error in which case NULL is returned. *SEEN_ID is
2143 set to true if an identifier being declared is seen; this is used
2144 to diagnose bad forms of abstract array declarators and to
2145 determine whether an identifier list is syntactically permitted.
2148 pointer[opt] direct-declarator
2152 ( attributes[opt] declarator )
2153 direct-declarator array-declarator
2154 direct-declarator ( parameter-type-list )
2155 direct-declarator ( identifier-list[opt] )
2158 * type-qualifier-list[opt]
2159 * type-qualifier-list[opt] pointer
2161 type-qualifier-list:
2164 type-qualifier-list type-qualifier
2165 type-qualifier-list attributes
2167 parameter-type-list:
2169 parameter-list , ...
2172 parameter-declaration
2173 parameter-list , parameter-declaration
2175 parameter-declaration:
2176 declaration-specifiers declarator attributes[opt]
2177 declaration-specifiers abstract-declarator[opt] attributes[opt]
2181 identifier-list , identifier
2183 abstract-declarator:
2185 pointer[opt] direct-abstract-declarator
2187 direct-abstract-declarator:
2188 ( attributes[opt] abstract-declarator )
2189 direct-abstract-declarator[opt] array-declarator
2190 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2195 direct-declarator ( parameter-forward-declarations
2196 parameter-type-list[opt] )
2198 direct-abstract-declarator:
2199 direct-abstract-declarator[opt] ( parameter-forward-declarations
2200 parameter-type-list[opt] )
2202 parameter-forward-declarations:
2204 parameter-forward-declarations parameter-list ;
2206 The uses of attributes shown above are GNU extensions.
2208 Some forms of array declarator are not included in C99 in the
2209 syntax for abstract declarators; these are disallowed elsewhere.
2210 This may be a defect (DR#289).
2212 This function also accepts an omitted abstract declarator as being
2213 an abstract declarator, although not part of the formal syntax. */
2215 static struct c_declarator
*
2216 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2219 /* Parse any initial pointer part. */
2220 if (c_parser_next_token_is (parser
, CPP_MULT
))
2222 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2223 struct c_declarator
*inner
;
2224 c_parser_consume_token (parser
);
2225 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2226 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2230 return make_pointer_declarator (quals_attrs
, inner
);
2232 /* Now we have a direct declarator, direct abstract declarator or
2233 nothing (which counts as a direct abstract declarator here). */
2234 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2237 /* Parse a direct declarator or direct abstract declarator; arguments
2238 as c_parser_declarator. */
2240 static struct c_declarator
*
2241 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2244 /* The direct declarator must start with an identifier (possibly
2245 omitted) or a parenthesized declarator (possibly abstract). In
2246 an ordinary declarator, initial parentheses must start a
2247 parenthesized declarator. In an abstract declarator or parameter
2248 declarator, they could start a parenthesized declarator or a
2249 parameter list. To tell which, the open parenthesis and any
2250 following attributes must be read. If a declaration specifier
2251 follows, then it is a parameter list; if the specifier is a
2252 typedef name, there might be an ambiguity about redeclaring it,
2253 which is resolved in the direction of treating it as a typedef
2254 name. If a close parenthesis follows, it is also an empty
2255 parameter list, as the syntax does not permit empty abstract
2256 declarators. Otherwise, it is a parenthesized declarator (in
2257 which case the analysis may be repeated inside it, recursively).
2259 ??? There is an ambiguity in a parameter declaration "int
2260 (__attribute__((foo)) x)", where x is not a typedef name: it
2261 could be an abstract declarator for a function, or declare x with
2262 parentheses. The proper resolution of this ambiguity needs
2263 documenting. At present we follow an accident of the old
2264 parser's implementation, whereby the first parameter must have
2265 some declaration specifiers other than just attributes. Thus as
2266 a parameter declaration it is treated as a parenthesized
2267 parameter named x, and as an abstract declarator it is
2270 ??? Also following the old parser, attributes inside an empty
2271 parameter list are ignored, making it a list not yielding a
2272 prototype, rather than giving an error or making it have one
2273 parameter with implicit type int.
2275 ??? Also following the old parser, typedef names may be
2276 redeclared in declarators, but not Objective-C class names. */
2278 if (kind
!= C_DTR_ABSTRACT
2279 && c_parser_next_token_is (parser
, CPP_NAME
)
2281 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2282 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2284 struct c_declarator
*inner
2285 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2287 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2288 c_parser_consume_token (parser
);
2289 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2292 if (kind
!= C_DTR_NORMAL
2293 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2295 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2296 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2299 /* Either we are at the end of an abstract declarator, or we have
2302 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2305 struct c_declarator
*inner
;
2306 c_parser_consume_token (parser
);
2307 attrs
= c_parser_attributes (parser
);
2308 if (kind
!= C_DTR_NORMAL
2309 && (c_parser_next_token_starts_declspecs (parser
)
2310 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2312 struct c_arg_info
*args
2313 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2320 = build_function_declarator (args
,
2321 build_id_declarator (NULL_TREE
));
2322 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2326 /* A parenthesized declarator. */
2327 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2328 if (inner
!= NULL
&& attrs
!= NULL
)
2329 inner
= build_attrs_declarator (attrs
, inner
);
2330 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2332 c_parser_consume_token (parser
);
2336 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2340 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2347 if (kind
== C_DTR_NORMAL
)
2349 c_parser_error (parser
, "expected identifier or %<(%>");
2353 return build_id_declarator (NULL_TREE
);
2357 /* Parse part of a direct declarator or direct abstract declarator,
2358 given that some (in INNER) has already been parsed; ID_PRESENT is
2359 true if an identifier is present, false for an abstract
2362 static struct c_declarator
*
2363 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2364 struct c_declarator
*inner
)
2366 /* Parse a sequence of array declarators and parameter lists. */
2367 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2369 struct c_declarator
*declarator
;
2370 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2374 c_parser_consume_token (parser
);
2375 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2376 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2378 c_parser_consume_token (parser
);
2379 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2380 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2381 if (!quals_attrs
->declspecs_seen_p
)
2383 /* If "static" is present, there must be an array dimension.
2384 Otherwise, there may be a dimension, "*", or no
2389 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2393 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2398 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2400 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2404 c_parser_consume_token (parser
);
2409 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2415 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2418 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2419 c_parser_consume_token (parser
);
2422 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2426 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2428 if (declarator
== NULL
)
2430 inner
= set_array_declarator_inner (declarator
, inner
);
2431 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2433 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2436 struct c_arg_info
*args
;
2437 c_parser_consume_token (parser
);
2438 attrs
= c_parser_attributes (parser
);
2439 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2444 inner
= build_function_declarator (args
, inner
);
2445 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2451 /* Parse a parameter list or identifier list, including the closing
2452 parenthesis but not the opening one. ATTRS are the attributes at
2453 the start of the list. ID_LIST_OK is true if an identifier list is
2454 acceptable; such a list must not have attributes at the start. */
2456 static struct c_arg_info
*
2457 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2460 declare_parm_level ();
2461 /* If the list starts with an identifier, it is an identifier list.
2462 Otherwise, it is either a prototype list or an empty list. */
2465 && c_parser_next_token_is (parser
, CPP_NAME
)
2466 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2468 tree list
= NULL_TREE
, *nextp
= &list
;
2469 while (c_parser_next_token_is (parser
, CPP_NAME
)
2470 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2472 *nextp
= build_tree_list (NULL_TREE
,
2473 c_parser_peek_token (parser
)->value
);
2474 nextp
= & TREE_CHAIN (*nextp
);
2475 c_parser_consume_token (parser
);
2476 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2478 c_parser_consume_token (parser
);
2479 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2481 c_parser_error (parser
, "expected identifier");
2485 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2487 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2492 ret
->pending_sizes
= 0;
2493 ret
->had_vla_unspec
= 0;
2494 c_parser_consume_token (parser
);
2500 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2508 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2514 /* Parse a parameter list (possibly empty), including the closing
2515 parenthesis but not the opening one. ATTRS are the attributes at
2516 the start of the list. */
2518 static struct c_arg_info
*
2519 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2521 bool good_parm
= false;
2522 /* ??? Following the old parser, forward parameter declarations may
2523 use abstract declarators, and if no real parameter declarations
2524 follow the forward declarations then this is not diagnosed. Also
2525 note as above that attributes are ignored as the only contents of
2526 the parentheses, or as the only contents after forward
2528 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2530 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2535 ret
->pending_sizes
= 0;
2536 ret
->had_vla_unspec
= 0;
2537 c_parser_consume_token (parser
);
2540 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2542 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2546 ret
->pending_sizes
= 0;
2547 ret
->had_vla_unspec
= 0;
2548 /* Suppress -Wold-style-definition for this case. */
2549 ret
->types
= error_mark_node
;
2550 error_at (c_parser_peek_token (parser
)->location
,
2551 "ISO C requires a named argument before %<...%>");
2552 c_parser_consume_token (parser
);
2553 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2555 c_parser_consume_token (parser
);
2560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2565 /* Nonempty list of parameters, either terminated with semicolon
2566 (forward declarations; recurse) or with close parenthesis (normal
2567 function) or with ", ... )" (variadic function). */
2570 /* Parse a parameter. */
2571 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2576 push_parm_decl (parm
);
2578 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2581 c_parser_consume_token (parser
);
2582 mark_forward_parm_decls ();
2583 new_attrs
= c_parser_attributes (parser
);
2584 return c_parser_parms_list_declarator (parser
, new_attrs
);
2586 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2588 c_parser_consume_token (parser
);
2590 return get_parm_info (false);
2593 struct c_arg_info
*ret
2594 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2599 ret
->pending_sizes
= 0;
2600 ret
->had_vla_unspec
= 0;
2604 if (!c_parser_require (parser
, CPP_COMMA
,
2605 "expected %<;%>, %<,%> or %<)%>"))
2607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2608 get_pending_sizes ();
2611 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2613 c_parser_consume_token (parser
);
2614 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2616 c_parser_consume_token (parser
);
2618 return get_parm_info (true);
2621 struct c_arg_info
*ret
2622 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2627 ret
->pending_sizes
= 0;
2628 ret
->had_vla_unspec
= 0;
2634 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2636 get_pending_sizes ();
2643 /* Parse a parameter declaration. ATTRS are the attributes at the
2644 start of the declaration if it is the first parameter. */
2646 static struct c_parm
*
2647 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2649 struct c_declspecs
*specs
;
2650 struct c_declarator
*declarator
;
2652 tree postfix_attrs
= NULL_TREE
;
2654 if (!c_parser_next_token_starts_declspecs (parser
))
2656 /* ??? In some Objective-C cases '...' isn't applicable so there
2657 should be a different message. */
2658 c_parser_error (parser
,
2659 "expected declaration specifiers or %<...%>");
2660 c_parser_skip_to_end_of_parameter (parser
);
2663 specs
= build_null_declspecs ();
2666 declspecs_add_attrs (specs
, attrs
);
2669 c_parser_declspecs (parser
, specs
, true, true, true);
2670 finish_declspecs (specs
);
2671 pending_xref_error ();
2672 prefix_attrs
= specs
->attrs
;
2673 specs
->attrs
= NULL_TREE
;
2674 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2675 C_DTR_PARM
, &dummy
);
2676 if (declarator
== NULL
)
2678 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2681 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2682 postfix_attrs
= c_parser_attributes (parser
);
2683 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2687 /* Parse a string literal in an asm expression. It should not be
2688 translated, and wide string literals are an error although
2689 permitted by the syntax. This is a GNU extension.
2694 ??? At present, following the old parser, the caller needs to have
2695 set lex_untranslated_string to 1. It would be better to follow the
2696 C++ parser rather than using this kludge. */
2699 c_parser_asm_string_literal (c_parser
*parser
)
2702 if (c_parser_next_token_is (parser
, CPP_STRING
))
2704 str
= c_parser_peek_token (parser
)->value
;
2705 c_parser_consume_token (parser
);
2707 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2709 error_at (c_parser_peek_token (parser
)->location
,
2710 "wide string literal in %<asm%>");
2711 str
= build_string (1, "");
2712 c_parser_consume_token (parser
);
2716 c_parser_error (parser
, "expected string literal");
2722 /* Parse a simple asm expression. This is used in restricted
2723 contexts, where a full expression with inputs and outputs does not
2724 make sense. This is a GNU extension.
2727 asm ( asm-string-literal )
2731 c_parser_simple_asm_expr (c_parser
*parser
)
2734 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2735 /* ??? Follow the C++ parser rather than using the
2736 lex_untranslated_string kludge. */
2737 parser
->lex_untranslated_string
= true;
2738 c_parser_consume_token (parser
);
2739 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2741 parser
->lex_untranslated_string
= false;
2744 str
= c_parser_asm_string_literal (parser
);
2745 parser
->lex_untranslated_string
= false;
2746 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2748 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2754 /* Parse (possibly empty) attributes. This is a GNU extension.
2758 attributes attribute
2761 __attribute__ ( ( attribute-list ) )
2765 attribute_list , attrib
2770 any-word ( identifier )
2771 any-word ( identifier , nonempty-expr-list )
2772 any-word ( expr-list )
2774 where the "identifier" must not be declared as a type, and
2775 "any-word" may be any identifier (including one declared as a
2776 type), a reserved word storage class specifier, type specifier or
2777 type qualifier. ??? This still leaves out most reserved keywords
2778 (following the old parser), shouldn't we include them, and why not
2779 allow identifiers declared as types to start the arguments? */
2782 c_parser_attributes (c_parser
*parser
)
2784 tree attrs
= NULL_TREE
;
2785 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2787 /* ??? Follow the C++ parser rather than using the
2788 lex_untranslated_string kludge. */
2789 parser
->lex_untranslated_string
= true;
2790 c_parser_consume_token (parser
);
2791 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2793 parser
->lex_untranslated_string
= false;
2796 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2798 parser
->lex_untranslated_string
= false;
2799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2802 /* Parse the attribute list. */
2803 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2804 || c_parser_next_token_is (parser
, CPP_NAME
)
2805 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2807 tree attr
, attr_name
, attr_args
;
2808 VEC(tree
,gc
) *expr_list
;
2809 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2811 c_parser_consume_token (parser
);
2814 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2816 /* ??? See comment above about what keywords are
2819 switch (c_parser_peek_token (parser
)->keyword
)
2856 /* Accept __attribute__((__const)) as __attribute__((const))
2859 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
2862 attr_name
= c_parser_peek_token (parser
)->value
;
2863 c_parser_consume_token (parser
);
2864 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2866 attr
= build_tree_list (attr_name
, NULL_TREE
);
2867 attrs
= chainon (attrs
, attr
);
2870 c_parser_consume_token (parser
);
2871 /* Parse the attribute contents. If they start with an
2872 identifier which is followed by a comma or close
2873 parenthesis, then the arguments start with that
2874 identifier; otherwise they are an expression list. */
2875 if (c_parser_next_token_is (parser
, CPP_NAME
)
2876 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2877 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2878 || (c_parser_peek_2nd_token (parser
)->type
2879 == CPP_CLOSE_PAREN
)))
2881 tree arg1
= c_parser_peek_token (parser
)->value
;
2882 c_parser_consume_token (parser
);
2883 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2884 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2888 c_parser_consume_token (parser
);
2889 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2890 tree_list
= build_tree_list_vec (expr_list
);
2891 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
2892 release_tree_vector (expr_list
);
2897 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2898 attr_args
= NULL_TREE
;
2901 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
2902 attr_args
= build_tree_list_vec (expr_list
);
2903 release_tree_vector (expr_list
);
2906 attr
= build_tree_list (attr_name
, attr_args
);
2907 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2908 c_parser_consume_token (parser
);
2911 parser
->lex_untranslated_string
= false;
2912 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2916 attrs
= chainon (attrs
, attr
);
2918 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2919 c_parser_consume_token (parser
);
2922 parser
->lex_untranslated_string
= false;
2923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2927 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2928 c_parser_consume_token (parser
);
2931 parser
->lex_untranslated_string
= false;
2932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2936 parser
->lex_untranslated_string
= false;
2941 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2944 specifier-qualifier-list abstract-declarator[opt]
2947 static struct c_type_name
*
2948 c_parser_type_name (c_parser
*parser
)
2950 struct c_declspecs
*specs
= build_null_declspecs ();
2951 struct c_declarator
*declarator
;
2952 struct c_type_name
*ret
;
2954 c_parser_declspecs (parser
, specs
, false, true, true);
2955 if (!specs
->declspecs_seen_p
)
2957 c_parser_error (parser
, "expected specifier-qualifier-list");
2960 pending_xref_error ();
2961 finish_declspecs (specs
);
2962 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2963 C_DTR_ABSTRACT
, &dummy
);
2964 if (declarator
== NULL
)
2966 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2968 ret
->declarator
= declarator
;
2972 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2975 assignment-expression
2976 { initializer-list }
2977 { initializer-list , }
2980 designation[opt] initializer
2981 initializer-list , designation[opt] initializer
2988 designator-list designator
2995 [ constant-expression ]
3007 [ constant-expression ... constant-expression ]
3009 Any expression without commas is accepted in the syntax for the
3010 constant-expressions, with non-constant expressions rejected later.
3012 This function is only used for top-level initializers; for nested
3013 ones, see c_parser_initval. */
3015 static struct c_expr
3016 c_parser_initializer (c_parser
*parser
)
3018 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3019 return c_parser_braced_init (parser
, NULL_TREE
, false);
3023 ret
= c_parser_expr_no_commas (parser
, NULL
);
3024 if (TREE_CODE (ret
.value
) != STRING_CST
3025 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3026 ret
= default_function_array_conversion (ret
);
3031 /* Parse a braced initializer list. TYPE is the type specified for a
3032 compound literal, and NULL_TREE for other initializers and for
3033 nested braced lists. NESTED_P is true for nested braced lists,
3034 false for the list of a compound literal or the list that is the
3035 top-level initializer in a declaration. */
3037 static struct c_expr
3038 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3040 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3041 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3042 c_parser_consume_token (parser
);
3044 push_init_level (0);
3046 really_start_incremental_init (type
);
3047 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3049 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3053 /* Parse a non-empty initializer list, possibly with a trailing
3057 c_parser_initelt (parser
);
3060 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3061 c_parser_consume_token (parser
);
3064 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3068 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3071 ret
.value
= error_mark_node
;
3072 ret
.original_code
= ERROR_MARK
;
3073 ret
.original_type
= NULL
;
3074 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3078 c_parser_consume_token (parser
);
3079 return pop_init_level (0);
3082 /* Parse a nested initializer, including designators. */
3085 c_parser_initelt (c_parser
*parser
)
3087 /* Parse any designator or designator list. A single array
3088 designator may have the subsequent "=" omitted in GNU C, but a
3089 longer list or a structure member designator may not. */
3090 if (c_parser_next_token_is (parser
, CPP_NAME
)
3091 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3093 /* Old-style structure member designator. */
3094 set_init_label (c_parser_peek_token (parser
)->value
);
3095 /* Use the colon as the error location. */
3096 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3097 "obsolete use of designated initializer with %<:%>");
3098 c_parser_consume_token (parser
);
3099 c_parser_consume_token (parser
);
3103 /* des_seen is 0 if there have been no designators, 1 if there
3104 has been a single array designator and 2 otherwise. */
3106 /* Location of a designator. */
3107 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3108 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3109 || c_parser_next_token_is (parser
, CPP_DOT
))
3111 int des_prev
= des_seen
;
3113 des_loc
= c_parser_peek_token (parser
)->location
;
3116 if (c_parser_next_token_is (parser
, CPP_DOT
))
3119 c_parser_consume_token (parser
);
3120 if (c_parser_next_token_is (parser
, CPP_NAME
))
3122 set_init_label (c_parser_peek_token (parser
)->value
);
3123 c_parser_consume_token (parser
);
3128 init
.value
= error_mark_node
;
3129 init
.original_code
= ERROR_MARK
;
3130 init
.original_type
= NULL
;
3131 c_parser_error (parser
, "expected identifier");
3132 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3133 process_init_element (init
, false);
3140 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3141 /* ??? Following the old parser, [ objc-receiver
3142 objc-message-args ] is accepted as an initializer,
3143 being distinguished from a designator by what follows
3144 the first assignment expression inside the square
3145 brackets, but after a first array designator a
3146 subsequent square bracket is for Objective-C taken to
3147 start an expression, using the obsolete form of
3148 designated initializer without '=', rather than
3149 possibly being a second level of designation: in LALR
3150 terms, the '[' is shifted rather than reducing
3151 designator to designator-list. */
3152 if (des_prev
== 1 && c_dialect_objc ())
3154 des_seen
= des_prev
;
3157 if (des_prev
== 0 && c_dialect_objc ())
3159 /* This might be an array designator or an
3160 Objective-C message expression. If the former,
3161 continue parsing here; if the latter, parse the
3162 remainder of the initializer given the starting
3163 primary-expression. ??? It might make sense to
3164 distinguish when des_prev == 1 as well; see
3165 previous comment. */
3167 struct c_expr mexpr
;
3168 c_parser_consume_token (parser
);
3169 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3170 && ((c_parser_peek_token (parser
)->id_kind
3172 || (c_parser_peek_token (parser
)->id_kind
3173 == C_ID_CLASSNAME
)))
3175 /* Type name receiver. */
3176 tree id
= c_parser_peek_token (parser
)->value
;
3177 c_parser_consume_token (parser
);
3178 rec
= objc_get_class_reference (id
);
3179 goto parse_message_args
;
3181 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3182 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3183 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3184 goto array_desig_after_first
;
3185 /* Expression receiver. So far only one part
3186 without commas has been parsed; there might be
3187 more of the expression. */
3189 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3192 c_parser_consume_token (parser
);
3193 next
= c_parser_expr_no_commas (parser
, NULL
);
3194 next
= default_function_array_conversion (next
);
3195 rec
= build_compound_expr (rec
, next
.value
);
3198 /* Now parse the objc-message-args. */
3199 args
= c_parser_objc_message_args (parser
);
3200 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3203 = objc_build_message_expr (build_tree_list (rec
, args
));
3204 mexpr
.original_code
= ERROR_MARK
;
3205 mexpr
.original_type
= NULL
;
3206 /* Now parse and process the remainder of the
3207 initializer, starting with this message
3208 expression as a primary-expression. */
3209 c_parser_initval (parser
, &mexpr
);
3212 c_parser_consume_token (parser
);
3213 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3214 array_desig_after_first
:
3215 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3217 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3218 c_parser_consume_token (parser
);
3219 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3223 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3225 c_parser_consume_token (parser
);
3226 set_init_index (first
, second
);
3228 pedwarn (ellipsis_loc
, OPT_pedantic
,
3229 "ISO C forbids specifying range of elements to initialize");
3232 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3238 if (c_parser_next_token_is (parser
, CPP_EQ
))
3241 pedwarn (des_loc
, OPT_pedantic
,
3242 "ISO C90 forbids specifying subobject to initialize");
3243 c_parser_consume_token (parser
);
3248 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3249 "obsolete use of designated initializer without %<=%>");
3253 init
.value
= error_mark_node
;
3254 init
.original_code
= ERROR_MARK
;
3255 init
.original_type
= NULL
;
3256 c_parser_error (parser
, "expected %<=%>");
3257 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3258 process_init_element (init
, false);
3264 c_parser_initval (parser
, NULL
);
3267 /* Parse a nested initializer; as c_parser_initializer but parses
3268 initializers within braced lists, after any designators have been
3269 applied. If AFTER is not NULL then it is an Objective-C message
3270 expression which is the primary-expression starting the
3274 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3277 gcc_assert (!after
|| c_dialect_objc ());
3278 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3279 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3282 init
= c_parser_expr_no_commas (parser
, after
);
3283 if (init
.value
!= NULL_TREE
3284 && TREE_CODE (init
.value
) != STRING_CST
3285 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3286 init
= default_function_array_conversion (init
);
3288 process_init_element (init
, false);
3291 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3295 { block-item-list[opt] }
3296 { label-declarations block-item-list }
3300 block-item-list block-item
3312 { label-declarations block-item-list }
3315 __extension__ nested-declaration
3316 nested-function-definition
3320 label-declarations label-declaration
3323 __label__ identifier-list ;
3325 Allowing the mixing of declarations and code is new in C99. The
3326 GNU syntax also permits (not shown above) labels at the end of
3327 compound statements, which yield an error. We don't allow labels
3328 on declarations; this might seem like a natural extension, but
3329 there would be a conflict between attributes on the label and
3330 prefix attributes on the declaration. ??? The syntax follows the
3331 old parser in requiring something after label declarations.
3332 Although they are erroneous if the labels declared aren't defined,
3333 is it useful for the syntax to be this way?
3345 c_parser_compound_statement (c_parser
*parser
)
3348 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3350 /* Ensure a scope is entered and left anyway to avoid confusion
3351 if we have just prepared to enter a function body. */
3352 stmt
= c_begin_compound_stmt (true);
3353 c_end_compound_stmt (stmt
, true);
3354 return error_mark_node
;
3356 stmt
= c_begin_compound_stmt (true);
3357 c_parser_compound_statement_nostart (parser
);
3358 return c_end_compound_stmt (stmt
, true);
3361 /* Parse a compound statement except for the opening brace. This is
3362 used for parsing both compound statements and statement expressions
3363 (which follow different paths to handling the opening). */
3366 c_parser_compound_statement_nostart (c_parser
*parser
)
3368 bool last_stmt
= false;
3369 bool last_label
= false;
3370 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3371 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3372 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3374 c_parser_consume_token (parser
);
3377 mark_valid_location_for_stdc_pragma (true);
3378 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3380 location_t err_loc
= c_parser_peek_token (parser
)->location
;
3381 /* Read zero or more forward-declarations for labels that nested
3382 functions can jump to. */
3383 mark_valid_location_for_stdc_pragma (false);
3384 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3386 c_parser_consume_token (parser
);
3387 /* Any identifiers, including those declared as type names,
3392 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3394 c_parser_error (parser
, "expected identifier");
3398 = declare_label (c_parser_peek_token (parser
)->value
);
3399 C_DECLARED_LABEL_FLAG (label
) = 1;
3400 add_stmt (build_stmt (DECL_EXPR
, label
));
3401 c_parser_consume_token (parser
);
3402 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3403 c_parser_consume_token (parser
);
3407 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3409 pedwarn (err_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3411 /* We must now have at least one statement, label or declaration. */
3412 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3414 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3415 c_parser_error (parser
, "expected declaration or statement");
3416 c_parser_consume_token (parser
);
3419 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3421 location_t loc
= c_parser_peek_token (parser
)->location
;
3422 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3423 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3424 || (c_parser_next_token_is (parser
, CPP_NAME
)
3425 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3427 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3428 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3430 label_loc
= c_parser_peek_token (parser
)->location
;
3433 mark_valid_location_for_stdc_pragma (false);
3434 c_parser_label (parser
);
3436 else if (!last_label
3437 && c_parser_next_token_starts_declspecs (parser
))
3440 mark_valid_location_for_stdc_pragma (false);
3441 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3444 (pedantic
&& !flag_isoc99
)
3446 : OPT_Wdeclaration_after_statement
,
3447 "ISO C90 forbids mixed declarations and code");
3450 else if (!last_label
3451 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3453 /* __extension__ can start a declaration, but is also an
3454 unary operator that can start an expression. Consume all
3455 but the last of a possible series of __extension__ to
3457 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3458 && (c_parser_peek_2nd_token (parser
)->keyword
3460 c_parser_consume_token (parser
);
3461 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3464 ext
= disable_extension_diagnostics ();
3465 c_parser_consume_token (parser
);
3467 mark_valid_location_for_stdc_pragma (false);
3468 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3469 /* Following the old parser, __extension__ does not
3470 disable this diagnostic. */
3471 restore_extension_diagnostics (ext
);
3473 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3475 : OPT_Wdeclaration_after_statement
,
3476 "ISO C90 forbids mixed declarations and code");
3482 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3484 /* External pragmas, and some omp pragmas, are not associated
3485 with regular c code, and so are not to be considered statements
3486 syntactically. This ensures that the user doesn't put them
3487 places that would turn into syntax errors if the directive
3489 if (c_parser_pragma (parser
, pragma_compound
))
3490 last_label
= false, last_stmt
= true;
3492 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3494 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3495 c_parser_error (parser
, "expected declaration or statement");
3498 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3500 if (parser
->in_if_block
)
3502 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3503 error_at (loc
, """expected %<}%> before %<else%>");
3508 error_at (loc
, "%<else%> without a previous %<if%>");
3509 c_parser_consume_token (parser
);
3518 mark_valid_location_for_stdc_pragma (false);
3519 c_parser_statement_after_labels (parser
);
3522 parser
->error
= false;
3525 error_at (label_loc
, "label at end of compound statement");
3526 c_parser_consume_token (parser
);
3527 /* Restore the value we started with. */
3528 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3531 /* Parse a label (C90 6.6.1, C99 6.8.1).
3534 identifier : attributes[opt]
3535 case constant-expression :
3541 case constant-expression ... constant-expression :
3543 The use of attributes on labels is a GNU extension. The syntax in
3544 GNU C accepts any expressions without commas, non-constant
3545 expressions being rejected later. */
3548 c_parser_label (c_parser
*parser
)
3550 location_t loc1
= c_parser_peek_token (parser
)->location
;
3551 tree label
= NULL_TREE
;
3552 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3555 c_parser_consume_token (parser
);
3556 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3557 if (c_parser_next_token_is (parser
, CPP_COLON
))
3559 c_parser_consume_token (parser
);
3560 label
= do_case (exp1
, NULL_TREE
);
3562 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3564 c_parser_consume_token (parser
);
3565 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3566 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3567 label
= do_case (exp1
, exp2
);
3570 c_parser_error (parser
, "expected %<:%> or %<...%>");
3572 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3574 c_parser_consume_token (parser
);
3575 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3576 label
= do_case (NULL_TREE
, NULL_TREE
);
3580 tree name
= c_parser_peek_token (parser
)->value
;
3583 location_t loc2
= c_parser_peek_token (parser
)->location
;
3584 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3585 c_parser_consume_token (parser
);
3586 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3587 c_parser_consume_token (parser
);
3588 attrs
= c_parser_attributes (parser
);
3589 tlab
= define_label (loc2
, name
);
3592 decl_attributes (&tlab
, attrs
, 0);
3593 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3598 SET_EXPR_LOCATION (label
, loc1
);
3599 if (c_parser_next_token_starts_declspecs (parser
)
3600 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3601 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3603 error_at (c_parser_peek_token (parser
)->location
,
3604 "a label can only be part of a statement and "
3605 "a declaration is not a statement");
3606 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3607 /*nested*/ true, /*empty_ok*/ false,
3608 /*start_attr_ok*/ true);
3613 /* Parse a statement (C90 6.6, C99 6.8).
3618 expression-statement
3626 expression-statement:
3629 selection-statement:
3633 iteration-statement:
3642 return expression[opt] ;
3655 objc-throw-statement
3656 objc-try-catch-statement
3657 objc-synchronized-statement
3659 objc-throw-statement:
3673 parallel-for-construct
3674 parallel-sections-construct
3681 parallel-directive structured-block
3684 for-directive iteration-statement
3687 sections-directive section-scope
3690 single-directive structured-block
3692 parallel-for-construct:
3693 parallel-for-directive iteration-statement
3695 parallel-sections-construct:
3696 parallel-sections-directive section-scope
3699 master-directive structured-block
3702 critical-directive structured-block
3705 atomic-directive expression-statement
3708 ordered-directive structured-block */
3711 c_parser_statement (c_parser
*parser
)
3713 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3714 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3715 || (c_parser_next_token_is (parser
, CPP_NAME
)
3716 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3717 c_parser_label (parser
);
3718 c_parser_statement_after_labels (parser
);
3721 /* Parse a statement, other than a labeled statement. */
3724 c_parser_statement_after_labels (c_parser
*parser
)
3726 location_t loc
= c_parser_peek_token (parser
)->location
;
3727 tree stmt
= NULL_TREE
;
3728 bool in_if_block
= parser
->in_if_block
;
3729 parser
->in_if_block
= false;
3730 switch (c_parser_peek_token (parser
)->type
)
3732 case CPP_OPEN_BRACE
:
3733 add_stmt (c_parser_compound_statement (parser
));
3736 switch (c_parser_peek_token (parser
)->keyword
)
3739 c_parser_if_statement (parser
);
3742 c_parser_switch_statement (parser
);
3745 c_parser_while_statement (parser
);
3748 c_parser_do_statement (parser
);
3751 c_parser_for_statement (parser
);
3754 c_parser_consume_token (parser
);
3755 if (c_parser_next_token_is (parser
, CPP_NAME
))
3757 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3758 c_parser_consume_token (parser
);
3760 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3762 c_parser_consume_token (parser
);
3763 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3766 c_parser_error (parser
, "expected identifier or %<*%>");
3767 goto expect_semicolon
;
3769 c_parser_consume_token (parser
);
3770 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3771 goto expect_semicolon
;
3773 c_parser_consume_token (parser
);
3774 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3775 goto expect_semicolon
;
3777 c_parser_consume_token (parser
);
3778 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3780 stmt
= c_finish_return (NULL_TREE
, NULL_TREE
);
3781 c_parser_consume_token (parser
);
3785 struct c_expr expr
= c_parser_expression_conv (parser
);
3786 stmt
= c_finish_return (expr
.value
, expr
.original_type
);
3787 goto expect_semicolon
;
3791 stmt
= c_parser_asm_statement (parser
);
3794 gcc_assert (c_dialect_objc ());
3795 c_parser_consume_token (parser
);
3796 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3798 stmt
= objc_build_throw_stmt (NULL_TREE
);
3799 c_parser_consume_token (parser
);
3803 tree expr
= c_parser_expression (parser
).value
;
3804 expr
= c_fully_fold (expr
, false, NULL
);
3805 stmt
= objc_build_throw_stmt (expr
);
3806 goto expect_semicolon
;
3810 gcc_assert (c_dialect_objc ());
3811 c_parser_objc_try_catch_statement (parser
);
3813 case RID_AT_SYNCHRONIZED
:
3814 gcc_assert (c_dialect_objc ());
3815 c_parser_objc_synchronized_statement (parser
);
3822 c_parser_consume_token (parser
);
3824 case CPP_CLOSE_PAREN
:
3825 case CPP_CLOSE_SQUARE
:
3826 /* Avoid infinite loop in error recovery:
3827 c_parser_skip_until_found stops at a closing nesting
3828 delimiter without consuming it, but here we need to consume
3829 it to proceed further. */
3830 c_parser_error (parser
, "expected statement");
3831 c_parser_consume_token (parser
);
3834 c_parser_pragma (parser
, pragma_stmt
);
3838 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3840 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3843 /* Two cases cannot and do not have line numbers associated: If stmt
3844 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3845 cannot hold line numbers. But that's OK because the statement
3846 will either be changed to a MODIFY_EXPR during gimplification of
3847 the statement expr, or discarded. If stmt was compound, but
3848 without new variables, we will have skipped the creation of a
3849 BIND and will have a bare STATEMENT_LIST. But that's OK because
3850 (recursively) all of the component statements should already have
3851 line numbers assigned. ??? Can we discard no-op statements
3853 protected_set_expr_location (stmt
, loc
);
3855 parser
->in_if_block
= in_if_block
;
3858 /* Parse the condition from an if, do, while or for statements. */
3861 c_parser_condition (c_parser
*parser
)
3865 loc
= c_parser_peek_token (parser
)->location
;
3866 cond
= c_parser_expression_conv (parser
).value
;
3867 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
3868 cond
= c_fully_fold (cond
, false, NULL
);
3869 if (warn_sequence_point
)
3870 verify_sequence_points (cond
);
3874 /* Parse a parenthesized condition from an if, do or while statement.
3880 c_parser_paren_condition (c_parser
*parser
)
3883 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3884 return error_mark_node
;
3885 cond
= c_parser_condition (parser
);
3886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3890 /* Parse a statement which is a block in C99. */
3893 c_parser_c99_block_statement (c_parser
*parser
)
3895 tree block
= c_begin_compound_stmt (flag_isoc99
);
3896 c_parser_statement (parser
);
3897 return c_end_compound_stmt (block
, flag_isoc99
);
3900 /* Parse the body of an if statement. This is just parsing a
3901 statement but (a) it is a block in C99, (b) we track whether the
3902 body is an if statement for the sake of -Wparentheses warnings, (c)
3903 we handle an empty body specially for the sake of -Wempty-body
3904 warnings, and (d) we call parser_compound_statement directly
3905 because c_parser_statement_after_labels resets
3906 parser->in_if_block. */
3909 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3911 tree block
= c_begin_compound_stmt (flag_isoc99
);
3912 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3913 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3914 || (c_parser_next_token_is (parser
, CPP_NAME
)
3915 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3916 c_parser_label (parser
);
3917 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3918 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3920 location_t loc
= c_parser_peek_token (parser
)->location
;
3921 add_stmt (build_empty_stmt ());
3922 c_parser_consume_token (parser
);
3923 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3924 warning_at (loc
, OPT_Wempty_body
,
3925 "suggest braces around empty body in an %<if%> statement");
3927 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3928 add_stmt (c_parser_compound_statement (parser
));
3930 c_parser_statement_after_labels (parser
);
3931 return c_end_compound_stmt (block
, flag_isoc99
);
3934 /* Parse the else body of an if statement. This is just parsing a
3935 statement but (a) it is a block in C99, (b) we handle an empty body
3936 specially for the sake of -Wempty-body warnings. */
3939 c_parser_else_body (c_parser
*parser
)
3941 tree block
= c_begin_compound_stmt (flag_isoc99
);
3942 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3943 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3944 || (c_parser_next_token_is (parser
, CPP_NAME
)
3945 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3946 c_parser_label (parser
);
3947 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3949 warning_at (c_parser_peek_token (parser
)->location
,
3951 "suggest braces around empty body in an %<else%> statement");
3952 add_stmt (build_empty_stmt ());
3953 c_parser_consume_token (parser
);
3956 c_parser_statement_after_labels (parser
);
3957 return c_end_compound_stmt (block
, flag_isoc99
);
3960 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3963 if ( expression ) statement
3964 if ( expression ) statement else statement
3968 c_parser_if_statement (c_parser
*parser
)
3973 bool first_if
= false;
3974 tree first_body
, second_body
;
3977 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3978 c_parser_consume_token (parser
);
3979 block
= c_begin_compound_stmt (flag_isoc99
);
3980 loc
= c_parser_peek_token (parser
)->location
;
3981 cond
= c_parser_paren_condition (parser
);
3982 in_if_block
= parser
->in_if_block
;
3983 parser
->in_if_block
= true;
3984 first_body
= c_parser_if_body (parser
, &first_if
);
3985 parser
->in_if_block
= in_if_block
;
3986 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3988 c_parser_consume_token (parser
);
3989 second_body
= c_parser_else_body (parser
);
3992 second_body
= NULL_TREE
;
3993 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3994 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3997 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4000 switch (expression) statement
4004 c_parser_switch_statement (c_parser
*parser
)
4006 tree block
, expr
, body
, save_break
;
4007 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4008 c_parser_consume_token (parser
);
4009 block
= c_begin_compound_stmt (flag_isoc99
);
4010 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4012 expr
= c_parser_expression (parser
).value
;
4013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4016 expr
= error_mark_node
;
4017 c_start_case (expr
);
4018 save_break
= c_break_label
;
4019 c_break_label
= NULL_TREE
;
4020 body
= c_parser_c99_block_statement (parser
);
4021 c_finish_case (body
);
4023 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
4024 c_break_label
= save_break
;
4025 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4028 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4031 while (expression) statement
4035 c_parser_while_statement (c_parser
*parser
)
4037 tree block
, cond
, body
, save_break
, save_cont
;
4039 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4040 c_parser_consume_token (parser
);
4041 block
= c_begin_compound_stmt (flag_isoc99
);
4042 loc
= c_parser_peek_token (parser
)->location
;
4043 cond
= c_parser_paren_condition (parser
);
4044 save_break
= c_break_label
;
4045 c_break_label
= NULL_TREE
;
4046 save_cont
= c_cont_label
;
4047 c_cont_label
= NULL_TREE
;
4048 body
= c_parser_c99_block_statement (parser
);
4049 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4050 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4051 c_break_label
= save_break
;
4052 c_cont_label
= save_cont
;
4055 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4058 do statement while ( expression ) ;
4062 c_parser_do_statement (c_parser
*parser
)
4064 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4066 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4067 c_parser_consume_token (parser
);
4068 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4069 warning_at (c_parser_peek_token (parser
)->location
,
4071 "suggest braces around empty body in %<do%> statement");
4072 block
= c_begin_compound_stmt (flag_isoc99
);
4073 loc
= c_parser_peek_token (parser
)->location
;
4074 save_break
= c_break_label
;
4075 c_break_label
= NULL_TREE
;
4076 save_cont
= c_cont_label
;
4077 c_cont_label
= NULL_TREE
;
4078 body
= c_parser_c99_block_statement (parser
);
4079 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4080 new_break
= c_break_label
;
4081 c_break_label
= save_break
;
4082 new_cont
= c_cont_label
;
4083 c_cont_label
= save_cont
;
4084 cond
= c_parser_paren_condition (parser
);
4085 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4086 c_parser_skip_to_end_of_block_or_statement (parser
);
4087 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4088 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4091 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4094 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4095 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4097 The form with a declaration is new in C99.
4099 ??? In accordance with the old parser, the declaration may be a
4100 nested function, which is then rejected in check_for_loop_decls,
4101 but does it make any sense for this to be included in the grammar?
4102 Note in particular that the nested function does not include a
4103 trailing ';', whereas the "declaration" production includes one.
4104 Also, can we reject bad declarations earlier and cheaper than
4105 check_for_loop_decls? */
4108 c_parser_for_statement (c_parser
*parser
)
4110 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4112 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4113 loc
= c_parser_peek_token (parser
)->location
;
4114 c_parser_consume_token (parser
);
4115 block
= c_begin_compound_stmt (flag_isoc99
);
4116 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4118 /* Parse the initialization declaration or expression. */
4119 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4121 c_parser_consume_token (parser
);
4122 c_finish_expr_stmt (NULL_TREE
);
4124 else if (c_parser_next_token_starts_declspecs (parser
))
4126 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4127 check_for_loop_decls ();
4129 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4131 /* __extension__ can start a declaration, but is also an
4132 unary operator that can start an expression. Consume all
4133 but the last of a possible series of __extension__ to
4135 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4136 && (c_parser_peek_2nd_token (parser
)->keyword
4138 c_parser_consume_token (parser
);
4139 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4142 ext
= disable_extension_diagnostics ();
4143 c_parser_consume_token (parser
);
4144 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4145 restore_extension_diagnostics (ext
);
4146 check_for_loop_decls ();
4154 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4155 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4157 /* Parse the loop condition. */
4158 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4160 c_parser_consume_token (parser
);
4165 cond
= c_parser_condition (parser
);
4166 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4168 /* Parse the increment expression. */
4169 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4170 incr
= c_process_expr_stmt (NULL_TREE
);
4172 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4173 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4177 cond
= error_mark_node
;
4178 incr
= error_mark_node
;
4180 save_break
= c_break_label
;
4181 c_break_label
= NULL_TREE
;
4182 save_cont
= c_cont_label
;
4183 c_cont_label
= NULL_TREE
;
4184 body
= c_parser_c99_block_statement (parser
);
4185 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4186 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4187 c_break_label
= save_break
;
4188 c_cont_label
= save_cont
;
4191 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4192 statement with inputs, outputs, clobbers, and volatile tag
4196 asm type-qualifier[opt] ( asm-argument ) ;
4200 asm-string-literal : asm-operands[opt]
4201 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4202 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4204 Qualifiers other than volatile are accepted in the syntax but
4208 c_parser_asm_statement (c_parser
*parser
)
4210 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4212 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4213 c_parser_consume_token (parser
);
4214 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4216 quals
= c_parser_peek_token (parser
)->value
;
4217 c_parser_consume_token (parser
);
4219 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4220 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4222 warning_at (c_parser_peek_token (parser
)->location
,
4224 "%E qualifier ignored on asm",
4225 c_parser_peek_token (parser
)->value
);
4227 c_parser_consume_token (parser
);
4231 /* ??? Follow the C++ parser rather than using the
4232 lex_untranslated_string kludge. */
4233 parser
->lex_untranslated_string
= true;
4234 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4236 parser
->lex_untranslated_string
= false;
4239 str
= c_parser_asm_string_literal (parser
);
4240 if (str
== NULL_TREE
)
4242 parser
->lex_untranslated_string
= false;
4243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4246 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4249 outputs
= NULL_TREE
;
4251 clobbers
= NULL_TREE
;
4254 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4256 parser
->lex_untranslated_string
= false;
4257 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4261 /* Parse outputs. */
4262 if (c_parser_next_token_is (parser
, CPP_COLON
)
4263 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4264 outputs
= NULL_TREE
;
4266 outputs
= c_parser_asm_operands (parser
, false);
4267 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4270 clobbers
= NULL_TREE
;
4273 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4275 parser
->lex_untranslated_string
= false;
4276 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4280 if (c_parser_next_token_is (parser
, CPP_COLON
)
4281 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4284 inputs
= c_parser_asm_operands (parser
, true);
4285 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4287 clobbers
= NULL_TREE
;
4290 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4292 parser
->lex_untranslated_string
= false;
4293 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4296 /* Parse clobbers. */
4297 clobbers
= c_parser_asm_clobbers (parser
);
4299 parser
->lex_untranslated_string
= false;
4300 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4302 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4305 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4306 c_parser_skip_to_end_of_block_or_statement (parser
);
4307 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4312 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4313 not outputs), apply the default conversion of functions and arrays
4318 asm-operands , asm-operand
4321 asm-string-literal ( expression )
4322 [ identifier ] asm-string-literal ( expression )
4326 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4328 tree list
= NULL_TREE
;
4333 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4335 c_parser_consume_token (parser
);
4336 if (c_parser_next_token_is (parser
, CPP_NAME
))
4338 tree id
= c_parser_peek_token (parser
)->value
;
4339 c_parser_consume_token (parser
);
4340 name
= build_string (IDENTIFIER_LENGTH (id
),
4341 IDENTIFIER_POINTER (id
));
4345 c_parser_error (parser
, "expected identifier");
4346 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4349 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4354 str
= c_parser_asm_string_literal (parser
);
4355 if (str
== NULL_TREE
)
4357 parser
->lex_untranslated_string
= false;
4358 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4360 parser
->lex_untranslated_string
= true;
4363 expr
= c_parser_expression (parser
);
4365 expr
= default_function_array_conversion (expr
);
4366 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4367 parser
->lex_untranslated_string
= true;
4368 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4370 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4373 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4375 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4376 c_parser_consume_token (parser
);
4383 /* Parse asm clobbers, a GNU extension.
4387 asm-clobbers , asm-string-literal
4391 c_parser_asm_clobbers (c_parser
*parser
)
4393 tree list
= NULL_TREE
;
4396 tree str
= c_parser_asm_string_literal (parser
);
4398 list
= tree_cons (NULL_TREE
, str
, list
);
4401 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4402 c_parser_consume_token (parser
);
4409 /* Parse an expression other than a compound expression; that is, an
4410 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4411 NULL then it is an Objective-C message expression which is the
4412 primary-expression starting the expression as an initializer.
4414 assignment-expression:
4415 conditional-expression
4416 unary-expression assignment-operator assignment-expression
4418 assignment-operator: one of
4419 = *= /= %= += -= <<= >>= &= ^= |=
4421 In GNU C we accept any conditional expression on the LHS and
4422 diagnose the invalid lvalue rather than producing a syntax
4425 static struct c_expr
4426 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4428 struct c_expr lhs
, rhs
, ret
;
4429 enum tree_code code
;
4430 location_t op_location
;
4431 gcc_assert (!after
|| c_dialect_objc ());
4432 lhs
= c_parser_conditional_expression (parser
, after
);
4433 op_location
= c_parser_peek_token (parser
)->location
;
4434 switch (c_parser_peek_token (parser
)->type
)
4443 code
= TRUNC_DIV_EXPR
;
4446 code
= TRUNC_MOD_EXPR
;
4461 code
= BIT_AND_EXPR
;
4464 code
= BIT_XOR_EXPR
;
4467 code
= BIT_IOR_EXPR
;
4472 c_parser_consume_token (parser
);
4473 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4474 rhs
= default_function_array_conversion (rhs
);
4475 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4476 code
, rhs
.value
, rhs
.original_type
);
4477 if (code
== NOP_EXPR
)
4478 ret
.original_code
= MODIFY_EXPR
;
4481 TREE_NO_WARNING (ret
.value
) = 1;
4482 ret
.original_code
= ERROR_MARK
;
4484 ret
.original_type
= NULL
;
4488 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4489 is not NULL then it is an Objective-C message expression which is
4490 the primary-expression starting the expression as an initializer.
4492 conditional-expression:
4493 logical-OR-expression
4494 logical-OR-expression ? expression : conditional-expression
4498 conditional-expression:
4499 logical-OR-expression ? : conditional-expression
4502 static struct c_expr
4503 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4505 struct c_expr cond
, exp1
, exp2
, ret
;
4506 location_t cond_loc
;
4508 gcc_assert (!after
|| c_dialect_objc ());
4510 cond_loc
= c_parser_peek_token (parser
)->location
;
4511 cond
= c_parser_binary_expression (parser
, after
);
4513 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4515 cond
= default_function_array_conversion (cond
);
4516 c_parser_consume_token (parser
);
4517 if (c_parser_next_token_is (parser
, CPP_COLON
))
4519 tree eptype
= NULL_TREE
;
4520 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
4521 "ISO C forbids omitting the middle term of a ?: expression");
4522 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4524 eptype
= TREE_TYPE (cond
.value
);
4525 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4527 /* Make sure first operand is calculated only once. */
4528 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4530 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4531 exp1
.original_type
= NULL
;
4532 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4533 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4538 = c_objc_common_truthvalue_conversion
4539 (cond_loc
, default_conversion (cond
.value
));
4540 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4541 exp1
= c_parser_expression_conv (parser
);
4542 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4543 - (cond
.value
== truthvalue_false_node
));
4545 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4547 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4548 ret
.value
= error_mark_node
;
4549 ret
.original_code
= ERROR_MARK
;
4550 ret
.original_type
= NULL
;
4553 exp2
= c_parser_conditional_expression (parser
, NULL
);
4554 exp2
= default_function_array_conversion (exp2
);
4555 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4556 ret
.value
= build_conditional_expr (cond
.value
,
4557 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4558 exp1
.value
, exp2
.value
);
4559 ret
.original_code
= ERROR_MARK
;
4560 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4561 ret
.original_type
= NULL
;
4566 /* If both sides are enum type, the default conversion will have
4567 made the type of the result be an integer type. We want to
4568 remember the enum types we started with. */
4569 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4570 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4571 ret
.original_type
= ((t1
!= error_mark_node
4572 && t2
!= error_mark_node
4573 && (TYPE_MAIN_VARIANT (t1
)
4574 == TYPE_MAIN_VARIANT (t2
)))
4581 /* Parse a binary expression; that is, a logical-OR-expression (C90
4582 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4583 an Objective-C message expression which is the primary-expression
4584 starting the expression as an initializer.
4586 multiplicative-expression:
4588 multiplicative-expression * cast-expression
4589 multiplicative-expression / cast-expression
4590 multiplicative-expression % cast-expression
4592 additive-expression:
4593 multiplicative-expression
4594 additive-expression + multiplicative-expression
4595 additive-expression - multiplicative-expression
4599 shift-expression << additive-expression
4600 shift-expression >> additive-expression
4602 relational-expression:
4604 relational-expression < shift-expression
4605 relational-expression > shift-expression
4606 relational-expression <= shift-expression
4607 relational-expression >= shift-expression
4609 equality-expression:
4610 relational-expression
4611 equality-expression == relational-expression
4612 equality-expression != relational-expression
4616 AND-expression & equality-expression
4618 exclusive-OR-expression:
4620 exclusive-OR-expression ^ AND-expression
4622 inclusive-OR-expression:
4623 exclusive-OR-expression
4624 inclusive-OR-expression | exclusive-OR-expression
4626 logical-AND-expression:
4627 inclusive-OR-expression
4628 logical-AND-expression && inclusive-OR-expression
4630 logical-OR-expression:
4631 logical-AND-expression
4632 logical-OR-expression || logical-AND-expression
4635 static struct c_expr
4636 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4638 /* A binary expression is parsed using operator-precedence parsing,
4639 with the operands being cast expressions. All the binary
4640 operators are left-associative. Thus a binary expression is of
4643 E0 op1 E1 op2 E2 ...
4645 which we represent on a stack. On the stack, the precedence
4646 levels are strictly increasing. When a new operator is
4647 encountered of higher precedence than that at the top of the
4648 stack, it is pushed; its LHS is the top expression, and its RHS
4649 is everything parsed until it is popped. When a new operator is
4650 encountered with precedence less than or equal to that at the top
4651 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4652 by the result of the operation until the operator at the top of
4653 the stack has lower precedence than the new operator or there is
4654 only one element on the stack; then the top expression is the LHS
4655 of the new operator. In the case of logical AND and OR
4656 expressions, we also need to adjust skip_evaluation as
4657 appropriate when the operators are pushed and popped. */
4659 /* The precedence levels, where 0 is a dummy lowest level used for
4660 the bottom of the stack. */
4676 /* The expression at this stack level. */
4678 /* The precedence of the operator on its left, PREC_NONE at the
4679 bottom of the stack. */
4681 /* The operation on its left. */
4683 /* The source location of this operation. */
4687 /* Location of the binary operator. */
4688 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4691 switch (stack[sp].op) \
4693 case TRUTH_ANDIF_EXPR: \
4694 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4696 case TRUTH_ORIF_EXPR: \
4697 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4702 stack[sp - 1].expr \
4703 = default_function_array_conversion (stack[sp - 1].expr); \
4705 = default_function_array_conversion (stack[sp].expr); \
4706 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
4708 stack[sp - 1].expr, \
4712 gcc_assert (!after
|| c_dialect_objc ());
4713 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
4714 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4715 stack
[0].prec
= PREC_NONE
;
4720 enum tree_code ocode
;
4723 switch (c_parser_peek_token (parser
)->type
)
4731 ocode
= TRUNC_DIV_EXPR
;
4735 ocode
= TRUNC_MOD_EXPR
;
4747 ocode
= LSHIFT_EXPR
;
4751 ocode
= RSHIFT_EXPR
;
4765 case CPP_GREATER_EQ
:
4778 oprec
= PREC_BITAND
;
4779 ocode
= BIT_AND_EXPR
;
4782 oprec
= PREC_BITXOR
;
4783 ocode
= BIT_XOR_EXPR
;
4787 ocode
= BIT_IOR_EXPR
;
4790 oprec
= PREC_LOGAND
;
4791 ocode
= TRUTH_ANDIF_EXPR
;
4795 ocode
= TRUTH_ORIF_EXPR
;
4798 /* Not a binary operator, so end of the binary
4802 binary_loc
= c_parser_peek_token (parser
)->location
;
4803 c_parser_consume_token (parser
);
4804 while (oprec
<= stack
[sp
].prec
)
4808 case TRUTH_ANDIF_EXPR
:
4810 = default_function_array_conversion (stack
[sp
].expr
);
4811 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4812 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4813 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4815 case TRUTH_ORIF_EXPR
:
4817 = default_function_array_conversion (stack
[sp
].expr
);
4818 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4819 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
4820 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4826 stack
[sp
].loc
= binary_loc
;
4827 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4828 stack
[sp
].prec
= oprec
;
4829 stack
[sp
].op
= ocode
;
4834 return stack
[0].expr
;
4838 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4839 NULL then it is an Objective-C message expression which is the
4840 primary-expression starting the expression as an initializer.
4844 ( type-name ) unary-expression
4847 static struct c_expr
4848 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4850 gcc_assert (!after
|| c_dialect_objc ());
4852 return c_parser_postfix_expression_after_primary (parser
, *after
);
4853 /* If the expression begins with a parenthesized type name, it may
4854 be either a cast or a compound literal; we need to see whether
4855 the next character is '{' to tell the difference. If not, it is
4856 an unary expression. */
4857 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4858 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4861 struct c_type_name
*type_name
;
4864 c_parser_consume_token (parser
);
4865 loc
= c_parser_peek_token (parser
)->location
;
4866 type_name
= c_parser_type_name (parser
);
4867 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4868 if (type_name
== NULL
)
4870 ret
.value
= error_mark_node
;
4871 ret
.original_code
= ERROR_MARK
;
4872 ret
.original_type
= NULL
;
4876 /* Save casted types in the function's used types hash table. */
4877 used_types_insert (type_name
->specs
->type
);
4879 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4880 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
4882 expr
= c_parser_cast_expression (parser
, NULL
);
4883 expr
= default_function_array_conversion (expr
);
4884 ret
.value
= c_cast_expr (type_name
, expr
.value
, loc
);
4885 ret
.original_code
= ERROR_MARK
;
4886 ret
.original_type
= NULL
;
4890 return c_parser_unary_expression (parser
);
4893 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4899 unary-operator cast-expression
4900 sizeof unary-expression
4901 sizeof ( type-name )
4903 unary-operator: one of
4909 __alignof__ unary-expression
4910 __alignof__ ( type-name )
4913 unary-operator: one of
4914 __extension__ __real__ __imag__
4916 In addition, the GNU syntax treats ++ and -- as unary operators, so
4917 they may be applied to cast expressions with errors for non-lvalues
4920 static struct c_expr
4921 c_parser_unary_expression (c_parser
*parser
)
4924 struct c_expr ret
, op
;
4925 location_t loc
= c_parser_peek_token (parser
)->location
;
4926 ret
.original_code
= ERROR_MARK
;
4927 ret
.original_type
= NULL
;
4928 switch (c_parser_peek_token (parser
)->type
)
4931 c_parser_consume_token (parser
);
4932 op
= c_parser_cast_expression (parser
, NULL
);
4933 op
= default_function_array_conversion (op
);
4934 return parser_build_unary_op (PREINCREMENT_EXPR
, op
, loc
);
4935 case CPP_MINUS_MINUS
:
4936 c_parser_consume_token (parser
);
4937 op
= c_parser_cast_expression (parser
, NULL
);
4938 op
= default_function_array_conversion (op
);
4939 return parser_build_unary_op (PREDECREMENT_EXPR
, op
, loc
);
4941 c_parser_consume_token (parser
);
4942 return parser_build_unary_op (ADDR_EXPR
,
4943 c_parser_cast_expression (parser
, NULL
),
4946 c_parser_consume_token (parser
);
4947 op
= c_parser_cast_expression (parser
, NULL
);
4948 op
= default_function_array_conversion (op
);
4949 ret
.value
= build_indirect_ref (loc
, op
.value
, "unary *");
4952 if (!c_dialect_objc () && !in_system_header
)
4953 warning_at (c_parser_peek_token (parser
)->location
,
4955 "traditional C rejects the unary plus operator");
4956 c_parser_consume_token (parser
);
4957 op
= c_parser_cast_expression (parser
, NULL
);
4958 op
= default_function_array_conversion (op
);
4959 return parser_build_unary_op (CONVERT_EXPR
, op
, loc
);
4961 c_parser_consume_token (parser
);
4962 op
= c_parser_cast_expression (parser
, NULL
);
4963 op
= default_function_array_conversion (op
);
4964 return parser_build_unary_op (NEGATE_EXPR
, op
, loc
);
4966 c_parser_consume_token (parser
);
4967 op
= c_parser_cast_expression (parser
, NULL
);
4968 op
= default_function_array_conversion (op
);
4969 return parser_build_unary_op (BIT_NOT_EXPR
, op
, loc
);
4971 c_parser_consume_token (parser
);
4972 op
= c_parser_cast_expression (parser
, NULL
);
4973 op
= default_function_array_conversion (op
);
4974 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
, loc
);
4976 /* Refer to the address of a label as a pointer. */
4977 c_parser_consume_token (parser
);
4978 if (c_parser_next_token_is (parser
, CPP_NAME
))
4980 ret
.value
= finish_label_address_expr
4981 (c_parser_peek_token (parser
)->value
, loc
);
4982 c_parser_consume_token (parser
);
4986 c_parser_error (parser
, "expected identifier");
4987 ret
.value
= error_mark_node
;
4991 switch (c_parser_peek_token (parser
)->keyword
)
4994 return c_parser_sizeof_expression (parser
);
4996 return c_parser_alignof_expression (parser
);
4998 c_parser_consume_token (parser
);
4999 ext
= disable_extension_diagnostics ();
5000 ret
= c_parser_cast_expression (parser
, NULL
);
5001 restore_extension_diagnostics (ext
);
5004 c_parser_consume_token (parser
);
5005 op
= c_parser_cast_expression (parser
, NULL
);
5006 op
= default_function_array_conversion (op
);
5007 return parser_build_unary_op (REALPART_EXPR
, op
, loc
);
5009 c_parser_consume_token (parser
);
5010 op
= c_parser_cast_expression (parser
, NULL
);
5011 op
= default_function_array_conversion (op
);
5012 return parser_build_unary_op (IMAGPART_EXPR
, op
, loc
);
5014 return c_parser_postfix_expression (parser
);
5017 return c_parser_postfix_expression (parser
);
5021 /* Parse a sizeof expression. */
5023 static struct c_expr
5024 c_parser_sizeof_expression (c_parser
*parser
)
5027 location_t expr_loc
;
5028 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5029 c_parser_consume_token (parser
);
5032 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5033 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5035 /* Either sizeof ( type-name ) or sizeof unary-expression
5036 starting with a compound literal. */
5037 struct c_type_name
*type_name
;
5038 c_parser_consume_token (parser
);
5039 expr_loc
= c_parser_peek_token (parser
)->location
;
5040 type_name
= c_parser_type_name (parser
);
5041 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5042 if (type_name
== NULL
)
5047 ret
.value
= error_mark_node
;
5048 ret
.original_code
= ERROR_MARK
;
5049 ret
.original_type
= NULL
;
5052 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5054 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5059 /* sizeof ( type-name ). */
5062 return c_expr_sizeof_type (type_name
);
5066 expr_loc
= c_parser_peek_token (parser
)->location
;
5067 expr
= c_parser_unary_expression (parser
);
5071 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5072 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5073 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5074 return c_expr_sizeof_expr (expr
);
5078 /* Parse an alignof expression. */
5080 static struct c_expr
5081 c_parser_alignof_expression (c_parser
*parser
)
5084 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5085 c_parser_consume_token (parser
);
5088 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5089 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5091 /* Either __alignof__ ( type-name ) or __alignof__
5092 unary-expression starting with a compound literal. */
5094 struct c_type_name
*type_name
;
5096 c_parser_consume_token (parser
);
5097 loc
= c_parser_peek_token (parser
)->location
;
5098 type_name
= c_parser_type_name (parser
);
5099 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5100 if (type_name
== NULL
)
5105 ret
.value
= error_mark_node
;
5106 ret
.original_code
= ERROR_MARK
;
5107 ret
.original_type
= NULL
;
5110 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5112 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5117 /* alignof ( type-name ). */
5120 ret
.value
= c_alignof (groktypename (type_name
, NULL
, NULL
));
5121 ret
.original_code
= ERROR_MARK
;
5122 ret
.original_type
= NULL
;
5128 expr
= c_parser_unary_expression (parser
);
5132 ret
.value
= c_alignof_expr (expr
.value
);
5133 ret
.original_code
= ERROR_MARK
;
5134 ret
.original_type
= NULL
;
5139 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5143 postfix-expression [ expression ]
5144 postfix-expression ( argument-expression-list[opt] )
5145 postfix-expression . identifier
5146 postfix-expression -> identifier
5147 postfix-expression ++
5148 postfix-expression --
5149 ( type-name ) { initializer-list }
5150 ( type-name ) { initializer-list , }
5152 argument-expression-list:
5154 argument-expression-list , argument-expression
5166 (treated as a keyword in GNU C)
5169 ( compound-statement )
5170 __builtin_va_arg ( assignment-expression , type-name )
5171 __builtin_offsetof ( type-name , offsetof-member-designator )
5172 __builtin_choose_expr ( assignment-expression ,
5173 assignment-expression ,
5174 assignment-expression )
5175 __builtin_types_compatible_p ( type-name , type-name )
5177 offsetof-member-designator:
5179 offsetof-member-designator . identifier
5180 offsetof-member-designator [ expression ]
5185 [ objc-receiver objc-message-args ]
5186 @selector ( objc-selector-arg )
5187 @protocol ( identifier )
5188 @encode ( type-name )
5192 static struct c_expr
5193 c_parser_postfix_expression (c_parser
*parser
)
5195 struct c_expr expr
, e1
, e2
, e3
;
5196 struct c_type_name
*t1
, *t2
;
5198 expr
.original_code
= ERROR_MARK
;
5199 expr
.original_type
= NULL
;
5200 switch (c_parser_peek_token (parser
)->type
)
5203 expr
.value
= c_parser_peek_token (parser
)->value
;
5204 loc
= c_parser_peek_token (parser
)->location
;
5205 c_parser_consume_token (parser
);
5206 if (TREE_CODE (expr
.value
) == FIXED_CST
5207 && !targetm
.fixed_point_supported_p ())
5209 error_at (loc
, "fixed-point types not supported for this target");
5210 expr
.value
= error_mark_node
;
5217 expr
.value
= c_parser_peek_token (parser
)->value
;
5218 c_parser_consume_token (parser
);
5224 expr
.value
= c_parser_peek_token (parser
)->value
;
5225 expr
.original_code
= STRING_CST
;
5226 c_parser_consume_token (parser
);
5228 case CPP_OBJC_STRING
:
5229 gcc_assert (c_dialect_objc ());
5231 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5232 c_parser_consume_token (parser
);
5235 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5237 c_parser_error (parser
, "expected expression");
5238 expr
.value
= error_mark_node
;
5242 tree id
= c_parser_peek_token (parser
)->value
;
5243 location_t loc
= c_parser_peek_token (parser
)->location
;
5244 c_parser_consume_token (parser
);
5245 expr
.value
= build_external_ref (id
,
5246 (c_parser_peek_token (parser
)->type
5247 == CPP_OPEN_PAREN
), loc
,
5248 &expr
.original_type
);
5251 case CPP_OPEN_PAREN
:
5252 /* A parenthesized expression, statement expression or compound
5254 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5256 /* A statement expression. */
5258 location_t here
= c_parser_peek_token (parser
)->location
;
5259 c_parser_consume_token (parser
);
5260 c_parser_consume_token (parser
);
5261 if (cur_stmt_list
== NULL
)
5263 error_at (here
, "braced-group within expression allowed "
5264 "only inside a function");
5265 parser
->error
= true;
5266 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5267 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5268 expr
.value
= error_mark_node
;
5271 stmt
= c_begin_stmt_expr ();
5272 c_parser_compound_statement_nostart (parser
);
5273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5275 pedwarn (here
, OPT_pedantic
,
5276 "ISO C forbids braced-groups within expressions");
5277 expr
.value
= c_finish_stmt_expr (stmt
);
5279 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5281 /* A compound literal. ??? Can we actually get here rather
5282 than going directly to
5283 c_parser_postfix_expression_after_paren_type from
5286 struct c_type_name
*type_name
;
5287 c_parser_consume_token (parser
);
5288 loc
= c_parser_peek_token (parser
)->location
;
5289 type_name
= c_parser_type_name (parser
);
5290 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5292 if (type_name
== NULL
)
5294 expr
.value
= error_mark_node
;
5297 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5303 /* A parenthesized expression. */
5304 c_parser_consume_token (parser
);
5305 expr
= c_parser_expression (parser
);
5306 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5307 TREE_NO_WARNING (expr
.value
) = 1;
5308 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5309 expr
.original_code
= ERROR_MARK
;
5310 /* Don't change EXPR.ORIGINAL_TYPE. */
5311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5316 switch (c_parser_peek_token (parser
)->keyword
)
5318 case RID_FUNCTION_NAME
:
5319 case RID_PRETTY_FUNCTION_NAME
:
5320 case RID_C99_FUNCTION_NAME
:
5321 expr
.value
= fname_decl (c_parser_peek_token (parser
)->location
,
5322 c_parser_peek_token (parser
)->keyword
,
5323 c_parser_peek_token (parser
)->value
);
5324 c_parser_consume_token (parser
);
5327 c_parser_consume_token (parser
);
5328 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5330 expr
.value
= error_mark_node
;
5333 e1
= c_parser_expr_no_commas (parser
, NULL
);
5334 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5335 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5338 expr
.value
= error_mark_node
;
5341 loc
= c_parser_peek_token (parser
)->location
;
5342 t1
= c_parser_type_name (parser
);
5343 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5347 expr
.value
= error_mark_node
;
5351 tree type_expr
= NULL_TREE
;
5352 expr
.value
= c_build_va_arg (e1
.value
,
5353 groktypename (t1
, &type_expr
, NULL
),
5357 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5358 TREE_TYPE (expr
.value
), type_expr
,
5360 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5365 c_parser_consume_token (parser
);
5366 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5368 expr
.value
= error_mark_node
;
5371 t1
= c_parser_type_name (parser
);
5374 expr
.value
= error_mark_node
;
5377 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5380 expr
.value
= error_mark_node
;
5384 tree type
= groktypename (t1
, NULL
, NULL
);
5386 if (type
== error_mark_node
)
5387 offsetof_ref
= error_mark_node
;
5389 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5390 /* Parse the second argument to __builtin_offsetof. We
5391 must have one identifier, and beyond that we want to
5392 accept sub structure and sub array references. */
5393 if (c_parser_next_token_is (parser
, CPP_NAME
))
5395 offsetof_ref
= build_component_ref
5396 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5397 c_parser_consume_token (parser
);
5398 while (c_parser_next_token_is (parser
, CPP_DOT
)
5399 || c_parser_next_token_is (parser
,
5401 || c_parser_next_token_is (parser
,
5404 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5406 loc
= c_parser_peek_token (parser
)->location
;
5407 offsetof_ref
= build_array_ref (offsetof_ref
,
5412 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5415 c_parser_consume_token (parser
);
5416 if (c_parser_next_token_is_not (parser
,
5419 c_parser_error (parser
, "expected identifier");
5422 offsetof_ref
= build_component_ref
5424 c_parser_peek_token (parser
)->value
);
5425 c_parser_consume_token (parser
);
5430 loc
= c_parser_peek_token (parser
)->location
;
5431 c_parser_consume_token (parser
);
5432 idx
= c_parser_expression (parser
).value
;
5433 idx
= c_fully_fold (idx
, false, NULL
);
5434 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5436 offsetof_ref
= build_array_ref (offsetof_ref
, idx
, loc
);
5441 c_parser_error (parser
, "expected identifier");
5442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5444 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5447 case RID_CHOOSE_EXPR
:
5448 c_parser_consume_token (parser
);
5449 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5451 expr
.value
= error_mark_node
;
5454 loc
= c_parser_peek_token (parser
)->location
;
5455 e1
= c_parser_expr_no_commas (parser
, NULL
);
5456 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5458 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5459 expr
.value
= error_mark_node
;
5462 e2
= c_parser_expr_no_commas (parser
, NULL
);
5463 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5465 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5466 expr
.value
= error_mark_node
;
5469 e3
= c_parser_expr_no_commas (parser
, NULL
);
5470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5476 if (TREE_CODE (c
) != INTEGER_CST
5477 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5479 "first argument to %<__builtin_choose_expr%> not"
5481 constant_expression_warning (c
);
5482 expr
= integer_zerop (c
) ? e3
: e2
;
5485 case RID_TYPES_COMPATIBLE_P
:
5486 c_parser_consume_token (parser
);
5487 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5489 expr
.value
= error_mark_node
;
5492 t1
= c_parser_type_name (parser
);
5495 expr
.value
= error_mark_node
;
5498 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5500 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5501 expr
.value
= error_mark_node
;
5504 t2
= c_parser_type_name (parser
);
5507 expr
.value
= error_mark_node
;
5510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5515 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5516 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5518 expr
.value
= comptypes (e1
, e2
)
5519 ? build_int_cst (NULL_TREE
, 1)
5520 : build_int_cst (NULL_TREE
, 0);
5523 case RID_AT_SELECTOR
:
5524 gcc_assert (c_dialect_objc ());
5525 c_parser_consume_token (parser
);
5526 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5528 expr
.value
= error_mark_node
;
5532 tree sel
= c_parser_objc_selector_arg (parser
);
5533 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5535 expr
.value
= objc_build_selector_expr (sel
);
5538 case RID_AT_PROTOCOL
:
5539 gcc_assert (c_dialect_objc ());
5540 c_parser_consume_token (parser
);
5541 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5543 expr
.value
= error_mark_node
;
5546 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5548 c_parser_error (parser
, "expected identifier");
5549 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5550 expr
.value
= error_mark_node
;
5554 tree id
= c_parser_peek_token (parser
)->value
;
5555 c_parser_consume_token (parser
);
5556 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5558 expr
.value
= objc_build_protocol_expr (id
);
5562 /* Extension to support C-structures in the archiver. */
5563 gcc_assert (c_dialect_objc ());
5564 c_parser_consume_token (parser
);
5565 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5567 expr
.value
= error_mark_node
;
5570 t1
= c_parser_type_name (parser
);
5573 expr
.value
= error_mark_node
;
5574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5577 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5580 tree type
= groktypename (t1
, NULL
, NULL
);
5581 expr
.value
= objc_build_encode_expr (type
);
5585 c_parser_error (parser
, "expected expression");
5586 expr
.value
= error_mark_node
;
5590 case CPP_OPEN_SQUARE
:
5591 if (c_dialect_objc ())
5593 tree receiver
, args
;
5594 c_parser_consume_token (parser
);
5595 receiver
= c_parser_objc_receiver (parser
);
5596 args
= c_parser_objc_message_args (parser
);
5597 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5599 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5603 /* Else fall through to report error. */
5605 c_parser_error (parser
, "expected expression");
5606 expr
.value
= error_mark_node
;
5609 return c_parser_postfix_expression_after_primary (parser
, expr
);
5612 /* Parse a postfix expression after a parenthesized type name: the
5613 brace-enclosed initializer of a compound literal, possibly followed
5614 by some postfix operators. This is separate because it is not
5615 possible to tell until after the type name whether a cast
5616 expression has a cast or a compound literal, or whether the operand
5617 of sizeof is a parenthesized type name or starts with a compound
5618 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5619 location of the first token after the parentheses around the type
5622 static struct c_expr
5623 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5624 struct c_type_name
*type_name
,
5625 location_t type_loc
)
5631 location_t start_loc
;
5632 tree type_expr
= NULL_TREE
;
5633 bool type_expr_const
= true;
5634 check_compound_literal_type (type_name
, type_loc
);
5635 start_init (NULL_TREE
, NULL
, 0);
5636 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5637 start_loc
= c_parser_peek_token (parser
)->location
;
5638 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5640 error_at (type_loc
, "compound literal has variable size");
5641 type
= error_mark_node
;
5643 init
= c_parser_braced_init (parser
, type
, false);
5645 maybe_warn_string_init (type
, init
);
5648 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5649 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5650 ? CONSTRUCTOR_NON_CONST (init
.value
)
5651 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5652 non_const
|= !type_expr_const
;
5653 expr
.value
= build_compound_literal (type
, init
.value
, non_const
);
5654 expr
.original_code
= ERROR_MARK
;
5655 expr
.original_type
= NULL
;
5658 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5660 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5661 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5665 gcc_assert (!non_const
);
5666 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5667 type_expr
, expr
.value
);
5670 return c_parser_postfix_expression_after_primary (parser
, expr
);
5673 /* Parse a postfix expression after the initial primary or compound
5674 literal; that is, parse a series of postfix operators. */
5676 static struct c_expr
5677 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5680 struct c_expr orig_expr
;
5682 VEC(tree
,gc
) *exprlist
;
5683 VEC(tree
,gc
) *origtypes
;
5684 location_t loc
= c_parser_peek_token (parser
)->location
;
5687 switch (c_parser_peek_token (parser
)->type
)
5689 case CPP_OPEN_SQUARE
:
5690 /* Array reference. */
5691 loc
= c_parser_peek_token (parser
)->location
;
5692 c_parser_consume_token (parser
);
5693 idx
= c_parser_expression (parser
).value
;
5694 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5696 expr
.value
= build_array_ref (expr
.value
, idx
, loc
);
5697 expr
.original_code
= ERROR_MARK
;
5698 expr
.original_type
= NULL
;
5700 case CPP_OPEN_PAREN
:
5701 /* Function call. */
5702 c_parser_consume_token (parser
);
5703 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5706 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5710 expr
.value
= build_function_call_vec (expr
.value
, exprlist
,
5712 expr
.original_code
= ERROR_MARK
;
5713 if (TREE_CODE (expr
.value
) == INTEGER_CST
5714 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5715 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5716 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5717 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5718 expr
.original_type
= NULL
;
5719 if (exprlist
!= NULL
)
5721 release_tree_vector (exprlist
);
5722 release_tree_vector (origtypes
);
5726 /* Structure element reference. */
5727 c_parser_consume_token (parser
);
5728 expr
= default_function_array_conversion (expr
);
5729 if (c_parser_next_token_is (parser
, CPP_NAME
))
5730 ident
= c_parser_peek_token (parser
)->value
;
5733 c_parser_error (parser
, "expected identifier");
5734 expr
.value
= error_mark_node
;
5735 expr
.original_code
= ERROR_MARK
;
5736 expr
.original_type
= NULL
;
5739 c_parser_consume_token (parser
);
5740 expr
.value
= build_component_ref (expr
.value
, ident
);
5741 expr
.original_code
= ERROR_MARK
;
5742 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5743 expr
.original_type
= NULL
;
5746 /* Remember the original type of a bitfield. */
5747 tree field
= TREE_OPERAND (expr
.value
, 1);
5748 if (TREE_CODE (field
) != FIELD_DECL
)
5749 expr
.original_type
= NULL
;
5751 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5755 /* Structure element reference. */
5756 c_parser_consume_token (parser
);
5757 expr
= default_function_array_conversion (expr
);
5758 if (c_parser_next_token_is (parser
, CPP_NAME
))
5759 ident
= c_parser_peek_token (parser
)->value
;
5762 c_parser_error (parser
, "expected identifier");
5763 expr
.value
= error_mark_node
;
5764 expr
.original_code
= ERROR_MARK
;
5765 expr
.original_type
= NULL
;
5768 c_parser_consume_token (parser
);
5769 expr
.value
= build_component_ref (build_indirect_ref (loc
,
5773 expr
.original_code
= ERROR_MARK
;
5774 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5775 expr
.original_type
= NULL
;
5778 /* Remember the original type of a bitfield. */
5779 tree field
= TREE_OPERAND (expr
.value
, 1);
5780 if (TREE_CODE (field
) != FIELD_DECL
)
5781 expr
.original_type
= NULL
;
5783 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5787 /* Postincrement. */
5788 c_parser_consume_token (parser
);
5789 expr
= default_function_array_conversion (expr
);
5790 expr
.value
= build_unary_op (loc
,
5791 POSTINCREMENT_EXPR
, expr
.value
, 0);
5792 expr
.original_code
= ERROR_MARK
;
5793 expr
.original_type
= NULL
;
5795 case CPP_MINUS_MINUS
:
5796 /* Postdecrement. */
5797 c_parser_consume_token (parser
);
5798 expr
= default_function_array_conversion (expr
);
5799 expr
.value
= build_unary_op (loc
,
5800 POSTDECREMENT_EXPR
, expr
.value
, 0);
5801 expr
.original_code
= ERROR_MARK
;
5802 expr
.original_type
= NULL
;
5810 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5813 assignment-expression
5814 expression , assignment-expression
5817 static struct c_expr
5818 c_parser_expression (c_parser
*parser
)
5821 expr
= c_parser_expr_no_commas (parser
, NULL
);
5822 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5825 c_parser_consume_token (parser
);
5826 next
= c_parser_expr_no_commas (parser
, NULL
);
5827 next
= default_function_array_conversion (next
);
5828 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5829 expr
.original_code
= COMPOUND_EXPR
;
5830 expr
.original_type
= next
.original_type
;
5835 /* Parse an expression and convert functions or arrays to
5838 static struct c_expr
5839 c_parser_expression_conv (c_parser
*parser
)
5842 expr
= c_parser_expression (parser
);
5843 expr
= default_function_array_conversion (expr
);
5847 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5848 functions and arrays to pointers. If FOLD_P, fold the expressions.
5851 assignment-expression
5852 nonempty-expr-list , assignment-expression
5855 static VEC(tree
,gc
) *
5856 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5857 VEC(tree
,gc
) **p_orig_types
)
5860 VEC(tree
,gc
) *orig_types
;
5863 ret
= make_tree_vector ();
5864 if (p_orig_types
== NULL
)
5867 orig_types
= make_tree_vector ();
5869 expr
= c_parser_expr_no_commas (parser
, NULL
);
5871 expr
= default_function_array_conversion (expr
);
5873 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5874 VEC_quick_push (tree
, ret
, expr
.value
);
5875 if (orig_types
!= NULL
)
5876 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
5877 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5879 c_parser_consume_token (parser
);
5880 expr
= c_parser_expr_no_commas (parser
, NULL
);
5882 expr
= default_function_array_conversion (expr
);
5884 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5885 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
5886 if (orig_types
!= NULL
)
5887 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
5889 if (orig_types
!= NULL
)
5890 *p_orig_types
= orig_types
;
5894 /* Parse Objective-C-specific constructs. */
5896 /* Parse an objc-class-definition.
5898 objc-class-definition:
5899 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5900 objc-class-instance-variables[opt] objc-methodprotolist @end
5901 @implementation identifier objc-superclass[opt]
5902 objc-class-instance-variables[opt]
5903 @interface identifier ( identifier ) objc-protocol-refs[opt]
5904 objc-methodprotolist @end
5905 @implementation identifier ( identifier )
5910 "@interface identifier (" must start "@interface identifier (
5911 identifier ) ...": objc-methodprotolist in the first production may
5912 not start with a parenthesized identifier as a declarator of a data
5913 definition with no declaration specifiers if the objc-superclass,
5914 objc-protocol-refs and objc-class-instance-variables are omitted. */
5917 c_parser_objc_class_definition (c_parser
*parser
)
5922 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5924 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5928 c_parser_consume_token (parser
);
5929 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5931 c_parser_error (parser
, "expected identifier");
5934 id1
= c_parser_peek_token (parser
)->value
;
5935 c_parser_consume_token (parser
);
5936 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5939 tree proto
= NULL_TREE
;
5940 c_parser_consume_token (parser
);
5941 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5943 c_parser_error (parser
, "expected identifier");
5944 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5947 id2
= c_parser_peek_token (parser
)->value
;
5948 c_parser_consume_token (parser
);
5949 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5952 objc_start_category_implementation (id1
, id2
);
5955 if (c_parser_next_token_is (parser
, CPP_LESS
))
5956 proto
= c_parser_objc_protocol_refs (parser
);
5957 objc_start_category_interface (id1
, id2
, proto
);
5958 c_parser_objc_methodprotolist (parser
);
5959 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5960 objc_finish_interface ();
5963 if (c_parser_next_token_is (parser
, CPP_COLON
))
5965 c_parser_consume_token (parser
);
5966 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5968 c_parser_error (parser
, "expected identifier");
5971 superclass
= c_parser_peek_token (parser
)->value
;
5972 c_parser_consume_token (parser
);
5975 superclass
= NULL_TREE
;
5978 tree proto
= NULL_TREE
;
5979 if (c_parser_next_token_is (parser
, CPP_LESS
))
5980 proto
= c_parser_objc_protocol_refs (parser
);
5981 objc_start_class_interface (id1
, superclass
, proto
);
5984 objc_start_class_implementation (id1
, superclass
);
5985 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5986 c_parser_objc_class_instance_variables (parser
);
5989 objc_continue_interface ();
5990 c_parser_objc_methodprotolist (parser
);
5991 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5992 objc_finish_interface ();
5996 objc_continue_implementation ();
6001 /* Parse objc-class-instance-variables.
6003 objc-class-instance-variables:
6004 { objc-instance-variable-decl-list[opt] }
6006 objc-instance-variable-decl-list:
6007 objc-visibility-spec
6008 objc-instance-variable-decl ;
6010 objc-instance-variable-decl-list objc-visibility-spec
6011 objc-instance-variable-decl-list objc-instance-variable-decl ;
6012 objc-instance-variable-decl-list ;
6014 objc-visibility-spec:
6019 objc-instance-variable-decl:
6024 c_parser_objc_class_instance_variables (c_parser
*parser
)
6026 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6027 c_parser_consume_token (parser
);
6028 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6031 /* Parse any stray semicolon. */
6032 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6034 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6035 "extra semicolon in struct or union specified");
6036 c_parser_consume_token (parser
);
6039 /* Stop if at the end of the instance variables. */
6040 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6042 c_parser_consume_token (parser
);
6045 /* Parse any objc-visibility-spec. */
6046 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6048 c_parser_consume_token (parser
);
6049 objc_set_visibility (2);
6052 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6054 c_parser_consume_token (parser
);
6055 objc_set_visibility (0);
6058 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6060 c_parser_consume_token (parser
);
6061 objc_set_visibility (1);
6064 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6066 c_parser_pragma (parser
, pragma_external
);
6070 /* Parse some comma-separated declarations. */
6071 decls
= c_parser_struct_declaration (parser
);
6073 /* Comma-separated instance variables are chained together in
6074 reverse order; add them one by one. */
6075 tree ivar
= nreverse (decls
);
6076 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6077 objc_add_instance_variable (copy_node (ivar
));
6079 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6083 /* Parse an objc-class-declaration.
6085 objc-class-declaration:
6086 @class identifier-list ;
6090 c_parser_objc_class_declaration (c_parser
*parser
)
6092 tree list
= NULL_TREE
;
6093 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6094 c_parser_consume_token (parser
);
6095 /* Any identifiers, including those declared as type names, are OK
6100 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6102 c_parser_error (parser
, "expected identifier");
6105 id
= c_parser_peek_token (parser
)->value
;
6106 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6107 c_parser_consume_token (parser
);
6108 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6109 c_parser_consume_token (parser
);
6113 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6114 objc_declare_class (list
);
6117 /* Parse an objc-alias-declaration.
6119 objc-alias-declaration:
6120 @compatibility_alias identifier identifier ;
6124 c_parser_objc_alias_declaration (c_parser
*parser
)
6127 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6128 c_parser_consume_token (parser
);
6129 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6131 c_parser_error (parser
, "expected identifier");
6132 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6135 id1
= c_parser_peek_token (parser
)->value
;
6136 c_parser_consume_token (parser
);
6137 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6139 c_parser_error (parser
, "expected identifier");
6140 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6143 id2
= c_parser_peek_token (parser
)->value
;
6144 c_parser_consume_token (parser
);
6145 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6146 objc_declare_alias (id1
, id2
);
6149 /* Parse an objc-protocol-definition.
6151 objc-protocol-definition:
6152 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6153 @protocol identifier-list ;
6155 "@protocol identifier ;" should be resolved as "@protocol
6156 identifier-list ;": objc-methodprotolist may not start with a
6157 semicolon in the first alternative if objc-protocol-refs are
6161 c_parser_objc_protocol_definition (c_parser
*parser
)
6163 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6164 c_parser_consume_token (parser
);
6165 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6167 c_parser_error (parser
, "expected identifier");
6170 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6171 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6173 tree list
= NULL_TREE
;
6174 /* Any identifiers, including those declared as type names, are
6179 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6181 c_parser_error (parser
, "expected identifier");
6184 id
= c_parser_peek_token (parser
)->value
;
6185 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6186 c_parser_consume_token (parser
);
6187 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6188 c_parser_consume_token (parser
);
6192 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6193 objc_declare_protocols (list
);
6197 tree id
= c_parser_peek_token (parser
)->value
;
6198 tree proto
= NULL_TREE
;
6199 c_parser_consume_token (parser
);
6200 if (c_parser_next_token_is (parser
, CPP_LESS
))
6201 proto
= c_parser_objc_protocol_refs (parser
);
6202 parser
->objc_pq_context
= true;
6203 objc_start_protocol (id
, proto
);
6204 c_parser_objc_methodprotolist (parser
);
6205 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6206 parser
->objc_pq_context
= false;
6207 objc_finish_interface ();
6211 /* Parse an objc-method-type.
6218 static enum tree_code
6219 c_parser_objc_method_type (c_parser
*parser
)
6221 switch (c_parser_peek_token (parser
)->type
)
6224 c_parser_consume_token (parser
);
6227 c_parser_consume_token (parser
);
6234 /* Parse an objc-method-definition.
6236 objc-method-definition:
6237 objc-method-type objc-method-decl ;[opt] compound-statement
6241 c_parser_objc_method_definition (c_parser
*parser
)
6243 enum tree_code type
= c_parser_objc_method_type (parser
);
6245 objc_set_method_type (type
);
6246 parser
->objc_pq_context
= true;
6247 decl
= c_parser_objc_method_decl (parser
);
6248 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6250 c_parser_consume_token (parser
);
6251 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6252 "extra semicolon in method definition specified");
6254 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6256 c_parser_error (parser
, "expected %<{%>");
6259 parser
->objc_pq_context
= false;
6260 objc_start_method_definition (decl
);
6261 add_stmt (c_parser_compound_statement (parser
));
6262 objc_finish_method_definition (current_function_decl
);
6265 /* Parse an objc-methodprotolist.
6267 objc-methodprotolist:
6269 objc-methodprotolist objc-methodproto
6270 objc-methodprotolist declaration
6271 objc-methodprotolist ;
6273 The declaration is a data definition, which may be missing
6274 declaration specifiers under the same rules and diagnostics as
6275 other data definitions outside functions, and the stray semicolon
6276 is diagnosed the same way as a stray semicolon outside a
6280 c_parser_objc_methodprotolist (c_parser
*parser
)
6284 /* The list is terminated by @end. */
6285 switch (c_parser_peek_token (parser
)->type
)
6288 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6289 "ISO C does not allow extra %<;%> outside of a function");
6290 c_parser_consume_token (parser
);
6294 c_parser_objc_methodproto (parser
);
6297 c_parser_pragma (parser
, pragma_external
);
6302 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6304 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6310 /* Parse an objc-methodproto.
6313 objc-method-type objc-method-decl ;
6317 c_parser_objc_methodproto (c_parser
*parser
)
6319 enum tree_code type
= c_parser_objc_method_type (parser
);
6321 objc_set_method_type (type
);
6322 /* Remember protocol qualifiers in prototypes. */
6323 parser
->objc_pq_context
= true;
6324 decl
= c_parser_objc_method_decl (parser
);
6325 /* Forget protocol qualifiers here. */
6326 parser
->objc_pq_context
= false;
6327 objc_add_method_declaration (decl
);
6328 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6331 /* Parse an objc-method-decl.
6334 ( objc-type-name ) objc-selector
6336 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6337 objc-keyword-selector objc-optparmlist
6339 objc-keyword-selector:
6341 objc-keyword-selector objc-keyword-decl
6344 objc-selector : ( objc-type-name ) identifier
6345 objc-selector : identifier
6346 : ( objc-type-name ) identifier
6350 objc-optparms objc-optellipsis
6354 objc-opt-parms , parameter-declaration
6362 c_parser_objc_method_decl (c_parser
*parser
)
6364 tree type
= NULL_TREE
;
6366 tree parms
= NULL_TREE
;
6367 bool ellipsis
= false;
6369 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6371 c_parser_consume_token (parser
);
6372 type
= c_parser_objc_type_name (parser
);
6373 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6375 sel
= c_parser_objc_selector (parser
);
6376 /* If there is no selector, or a colon follows, we have an
6377 objc-keyword-selector. If there is a selector, and a colon does
6378 not follow, that selector ends the objc-method-decl. */
6379 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6382 tree list
= NULL_TREE
;
6385 tree atype
= NULL_TREE
, id
, keyworddecl
;
6386 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6388 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6390 c_parser_consume_token (parser
);
6391 atype
= c_parser_objc_type_name (parser
);
6392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6395 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6397 c_parser_error (parser
, "expected identifier");
6398 return error_mark_node
;
6400 id
= c_parser_peek_token (parser
)->value
;
6401 c_parser_consume_token (parser
);
6402 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6403 list
= chainon (list
, keyworddecl
);
6404 tsel
= c_parser_objc_selector (parser
);
6405 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6408 /* Parse the optional parameter list. Optional Objective-C
6409 method parameters follow the C syntax, and may include '...'
6410 to denote a variable number of arguments. */
6411 parms
= make_node (TREE_LIST
);
6412 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6414 struct c_parm
*parm
;
6415 c_parser_consume_token (parser
);
6416 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6419 c_parser_consume_token (parser
);
6422 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6425 parms
= chainon (parms
,
6426 build_tree_list (NULL_TREE
, grokparm (parm
)));
6430 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6433 /* Parse an objc-type-name.
6436 objc-type-qualifiers[opt] type-name
6437 objc-type-qualifiers[opt]
6439 objc-type-qualifiers:
6441 objc-type-qualifiers objc-type-qualifier
6443 objc-type-qualifier: one of
6444 in out inout bycopy byref oneway
6448 c_parser_objc_type_name (c_parser
*parser
)
6450 tree quals
= NULL_TREE
;
6451 struct c_type_name
*type_name
= NULL
;
6452 tree type
= NULL_TREE
;
6455 c_token
*token
= c_parser_peek_token (parser
);
6456 if (token
->type
== CPP_KEYWORD
6457 && (token
->keyword
== RID_IN
6458 || token
->keyword
== RID_OUT
6459 || token
->keyword
== RID_INOUT
6460 || token
->keyword
== RID_BYCOPY
6461 || token
->keyword
== RID_BYREF
6462 || token
->keyword
== RID_ONEWAY
))
6464 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6465 c_parser_consume_token (parser
);
6470 if (c_parser_next_token_starts_typename (parser
))
6471 type_name
= c_parser_type_name (parser
);
6473 type
= groktypename (type_name
, NULL
, NULL
);
6474 return build_tree_list (quals
, type
);
6477 /* Parse objc-protocol-refs.
6484 c_parser_objc_protocol_refs (c_parser
*parser
)
6486 tree list
= NULL_TREE
;
6487 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6488 c_parser_consume_token (parser
);
6489 /* Any identifiers, including those declared as type names, are OK
6494 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6496 c_parser_error (parser
, "expected identifier");
6499 id
= c_parser_peek_token (parser
)->value
;
6500 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6501 c_parser_consume_token (parser
);
6502 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6503 c_parser_consume_token (parser
);
6507 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6511 /* Parse an objc-try-catch-statement.
6513 objc-try-catch-statement:
6514 @try compound-statement objc-catch-list[opt]
6515 @try compound-statement objc-catch-list[opt] @finally compound-statement
6518 @catch ( parameter-declaration ) compound-statement
6519 objc-catch-list @catch ( parameter-declaration ) compound-statement
6523 c_parser_objc_try_catch_statement (c_parser
*parser
)
6527 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6528 c_parser_consume_token (parser
);
6529 loc
= c_parser_peek_token (parser
)->location
;
6530 stmt
= c_parser_compound_statement (parser
);
6531 objc_begin_try_stmt (loc
, stmt
);
6532 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6534 struct c_parm
*parm
;
6535 c_parser_consume_token (parser
);
6536 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6538 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6541 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6544 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6545 objc_begin_catch_clause (grokparm (parm
));
6546 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6547 c_parser_compound_statement_nostart (parser
);
6548 objc_finish_catch_clause ();
6550 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6554 c_parser_consume_token (parser
);
6555 finloc
= c_parser_peek_token (parser
)->location
;
6556 finstmt
= c_parser_compound_statement (parser
);
6557 objc_build_finally_clause (finloc
, finstmt
);
6559 objc_finish_try_stmt ();
6562 /* Parse an objc-synchronized-statement.
6564 objc-synchronized-statement:
6565 @synchronized ( expression ) compound-statement
6569 c_parser_objc_synchronized_statement (c_parser
*parser
)
6573 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6574 c_parser_consume_token (parser
);
6575 loc
= c_parser_peek_token (parser
)->location
;
6576 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6578 expr
= c_parser_expression (parser
).value
;
6579 expr
= c_fully_fold (expr
, false, NULL
);
6580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6583 expr
= error_mark_node
;
6584 stmt
= c_parser_compound_statement (parser
);
6585 objc_build_synchronized (loc
, expr
, stmt
);
6588 /* Parse an objc-selector; return NULL_TREE without an error if the
6589 next token is not an objc-selector.
6594 enum struct union if else while do for switch case default
6595 break continue return goto asm sizeof typeof __alignof
6596 unsigned long const short volatile signed restrict _Complex
6597 in out inout bycopy byref oneway int char float double void _Bool
6599 ??? Why this selection of keywords but not, for example, storage
6600 class specifiers? */
6603 c_parser_objc_selector (c_parser
*parser
)
6605 c_token
*token
= c_parser_peek_token (parser
);
6606 tree value
= token
->value
;
6607 if (token
->type
== CPP_NAME
)
6609 c_parser_consume_token (parser
);
6612 if (token
->type
!= CPP_KEYWORD
)
6614 switch (token
->keyword
)
6655 c_parser_consume_token (parser
);
6662 /* Parse an objc-selector-arg.
6666 objc-keywordname-list
6668 objc-keywordname-list:
6670 objc-keywordname-list objc-keywordname
6678 c_parser_objc_selector_arg (c_parser
*parser
)
6680 tree sel
= c_parser_objc_selector (parser
);
6681 tree list
= NULL_TREE
;
6682 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6686 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6688 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6689 sel
= c_parser_objc_selector (parser
);
6690 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6696 /* Parse an objc-receiver.
6705 c_parser_objc_receiver (c_parser
*parser
)
6707 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6708 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6709 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6711 tree id
= c_parser_peek_token (parser
)->value
;
6712 c_parser_consume_token (parser
);
6713 return objc_get_class_reference (id
);
6715 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6718 /* Parse objc-message-args.
6722 objc-keywordarg-list
6724 objc-keywordarg-list:
6726 objc-keywordarg-list objc-keywordarg
6729 objc-selector : objc-keywordexpr
6734 c_parser_objc_message_args (c_parser
*parser
)
6736 tree sel
= c_parser_objc_selector (parser
);
6737 tree list
= NULL_TREE
;
6738 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6743 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6745 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6746 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6747 sel
= c_parser_objc_selector (parser
);
6748 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6754 /* Parse an objc-keywordexpr.
6761 c_parser_objc_keywordexpr (c_parser
*parser
)
6764 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6765 if (VEC_length (tree
, expr_list
) == 1)
6767 /* Just return the expression, remove a level of
6769 ret
= VEC_index (tree
, expr_list
, 0);
6773 /* We have a comma expression, we will collapse later. */
6774 ret
= build_tree_list_vec (expr_list
);
6776 release_tree_vector (expr_list
);
6781 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6782 should be considered, statements. ALLOW_STMT is true if we're within
6783 the context of a function and such pragmas are to be allowed. Returns
6784 true if we actually parsed such a pragma. */
6787 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6791 id
= c_parser_peek_token (parser
)->pragma_kind
;
6792 gcc_assert (id
!= PRAGMA_NONE
);
6796 case PRAGMA_OMP_BARRIER
:
6797 if (context
!= pragma_compound
)
6799 if (context
== pragma_stmt
)
6800 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6801 "used in compound statements");
6804 c_parser_omp_barrier (parser
);
6807 case PRAGMA_OMP_FLUSH
:
6808 if (context
!= pragma_compound
)
6810 if (context
== pragma_stmt
)
6811 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6812 "used in compound statements");
6815 c_parser_omp_flush (parser
);
6818 case PRAGMA_OMP_TASKWAIT
:
6819 if (context
!= pragma_compound
)
6821 if (context
== pragma_stmt
)
6822 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6823 "used in compound statements");
6826 c_parser_omp_taskwait (parser
);
6829 case PRAGMA_OMP_THREADPRIVATE
:
6830 c_parser_omp_threadprivate (parser
);
6833 case PRAGMA_OMP_SECTION
:
6834 error_at (c_parser_peek_token (parser
)->location
,
6835 "%<#pragma omp section%> may only be used in "
6836 "%<#pragma omp sections%> construct");
6837 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6840 case PRAGMA_GCC_PCH_PREPROCESS
:
6841 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6842 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6846 if (id
< PRAGMA_FIRST_EXTERNAL
)
6848 if (context
== pragma_external
)
6851 c_parser_error (parser
, "expected declaration specifiers");
6852 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6855 c_parser_omp_construct (parser
);
6861 c_parser_consume_pragma (parser
);
6862 c_invoke_pragma_handler (id
);
6864 /* Skip to EOL, but suppress any error message. Those will have been
6865 generated by the handler routine through calling error, as opposed
6866 to calling c_parser_error. */
6867 parser
->error
= true;
6868 c_parser_skip_to_pragma_eol (parser
);
6873 /* The interface the pragma parsers have to the lexer. */
6876 pragma_lex (tree
*value
)
6878 c_token
*tok
= c_parser_peek_token (the_parser
);
6879 enum cpp_ttype ret
= tok
->type
;
6881 *value
= tok
->value
;
6882 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6886 if (ret
== CPP_KEYWORD
)
6888 c_parser_consume_token (the_parser
);
6895 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6899 c_parser_consume_pragma (parser
);
6900 if (c_parser_next_token_is (parser
, CPP_STRING
))
6902 name
= c_parser_peek_token (parser
)->value
;
6903 c_parser_consume_token (parser
);
6906 c_parser_error (parser
, "expected string literal");
6907 c_parser_skip_to_pragma_eol (parser
);
6910 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6913 /* OpenMP 2.5 parsing routines. */
6915 /* Returns name of the next clause.
6916 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6917 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6918 returned and the token is consumed. */
6920 static pragma_omp_clause
6921 c_parser_omp_clause_name (c_parser
*parser
)
6923 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6925 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6926 result
= PRAGMA_OMP_CLAUSE_IF
;
6927 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6928 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6929 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6931 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6936 if (!strcmp ("collapse", p
))
6937 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6938 else if (!strcmp ("copyin", p
))
6939 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6940 else if (!strcmp ("copyprivate", p
))
6941 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6944 if (!strcmp ("firstprivate", p
))
6945 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6948 if (!strcmp ("lastprivate", p
))
6949 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6952 if (!strcmp ("nowait", p
))
6953 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6954 else if (!strcmp ("num_threads", p
))
6955 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6958 if (!strcmp ("ordered", p
))
6959 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6962 if (!strcmp ("private", p
))
6963 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6966 if (!strcmp ("reduction", p
))
6967 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6970 if (!strcmp ("schedule", p
))
6971 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6972 else if (!strcmp ("shared", p
))
6973 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6976 if (!strcmp ("untied", p
))
6977 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
6982 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6983 c_parser_consume_token (parser
);
6988 /* Validate that a clause of the given type does not already exist. */
6991 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
6996 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6997 if (OMP_CLAUSE_CODE (c
) == code
)
6999 error ("too many %qs clauses", name
);
7007 variable-list , identifier
7009 If KIND is nonzero, create the appropriate node and install the decl
7010 in OMP_CLAUSE_DECL and add the node to the head of the list.
7012 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7013 return the list created. */
7016 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
7019 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7020 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7021 c_parser_error (parser
, "expected identifier");
7023 while (c_parser_next_token_is (parser
, CPP_NAME
)
7024 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7026 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7029 undeclared_variable (c_parser_peek_token (parser
)->value
,
7030 c_parser_peek_token (parser
)->location
);
7031 else if (t
== error_mark_node
)
7035 tree u
= build_omp_clause (kind
);
7036 OMP_CLAUSE_DECL (u
) = t
;
7037 OMP_CLAUSE_CHAIN (u
) = list
;
7041 list
= tree_cons (t
, NULL_TREE
, list
);
7043 c_parser_consume_token (parser
);
7045 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7048 c_parser_consume_token (parser
);
7054 /* Similarly, but expect leading and trailing parenthesis. This is a very
7055 common case for omp clauses. */
7058 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7061 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7063 list
= c_parser_omp_variable_list (parser
, kind
, list
);
7064 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7070 collapse ( constant-expression ) */
7073 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7075 tree c
, num
= error_mark_node
;
7079 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7081 loc
= c_parser_peek_token (parser
)->location
;
7082 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7084 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7087 if (num
== error_mark_node
)
7089 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7090 || !host_integerp (num
, 0)
7091 || (n
= tree_low_cst (num
, 0)) <= 0
7095 "collapse argument needs positive constant integer expression");
7098 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
7099 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7100 OMP_CLAUSE_CHAIN (c
) = list
;
7105 copyin ( variable-list ) */
7108 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7110 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7114 copyprivate ( variable-list ) */
7117 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7119 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7123 default ( shared | none ) */
7126 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7128 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7131 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7133 if (c_parser_next_token_is (parser
, CPP_NAME
))
7135 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7140 if (strcmp ("none", p
) != 0)
7142 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7146 if (strcmp ("shared", p
) != 0)
7148 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7155 c_parser_consume_token (parser
);
7160 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7162 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7164 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7167 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7168 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
7169 OMP_CLAUSE_CHAIN (c
) = list
;
7170 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7176 firstprivate ( variable-list ) */
7179 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7181 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7185 if ( expression ) */
7188 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7190 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7192 tree t
= c_parser_paren_condition (parser
);
7195 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7197 c
= build_omp_clause (OMP_CLAUSE_IF
);
7198 OMP_CLAUSE_IF_EXPR (c
) = t
;
7199 OMP_CLAUSE_CHAIN (c
) = list
;
7203 c_parser_error (parser
, "expected %<(%>");
7209 lastprivate ( variable-list ) */
7212 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7214 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7221 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7225 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7227 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
7228 OMP_CLAUSE_CHAIN (c
) = list
;
7233 num_threads ( expression ) */
7236 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7238 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7240 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7241 tree c
, t
= c_parser_expression (parser
).value
;
7242 t
= c_fully_fold (t
, false, NULL
);
7244 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7246 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7248 c_parser_error (parser
, "expected integer expression");
7252 /* Attempt to statically determine when the number isn't positive. */
7253 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7254 build_int_cst (TREE_TYPE (t
), 0));
7255 if (c
== boolean_true_node
)
7257 warning_at (expr_loc
, 0,
7258 "%<num_threads%> value must be positive");
7259 t
= integer_one_node
;
7262 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7264 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7265 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7266 OMP_CLAUSE_CHAIN (c
) = list
;
7277 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7281 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7283 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7284 OMP_CLAUSE_CHAIN (c
) = list
;
7289 private ( variable-list ) */
7292 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7294 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7298 reduction ( reduction-operator : variable-list )
7301 One of: + * - & ^ | && || */
7304 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7306 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7308 enum tree_code code
;
7310 switch (c_parser_peek_token (parser
)->type
)
7322 code
= BIT_AND_EXPR
;
7325 code
= BIT_XOR_EXPR
;
7328 code
= BIT_IOR_EXPR
;
7331 code
= TRUTH_ANDIF_EXPR
;
7334 code
= TRUTH_ORIF_EXPR
;
7337 c_parser_error (parser
,
7338 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7339 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7340 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7343 c_parser_consume_token (parser
);
7344 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7348 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7349 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7350 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7354 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7360 schedule ( schedule-kind )
7361 schedule ( schedule-kind , expression )
7364 static | dynamic | guided | runtime | auto
7368 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7372 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7375 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7377 if (c_parser_next_token_is (parser
, CPP_NAME
))
7379 tree kind
= c_parser_peek_token (parser
)->value
;
7380 const char *p
= IDENTIFIER_POINTER (kind
);
7385 if (strcmp ("dynamic", p
) != 0)
7387 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7391 if (strcmp ("guided", p
) != 0)
7393 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7397 if (strcmp ("runtime", p
) != 0)
7399 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7406 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7407 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7408 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7409 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7413 c_parser_consume_token (parser
);
7414 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7417 c_parser_consume_token (parser
);
7419 here
= c_parser_peek_token (parser
)->location
;
7420 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7421 t
= c_fully_fold (t
, false, NULL
);
7423 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7424 error_at (here
, "schedule %<runtime%> does not take "
7425 "a %<chunk_size%> parameter");
7426 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7428 "schedule %<auto%> does not take "
7429 "a %<chunk_size%> parameter");
7430 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7431 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7433 c_parser_error (parser
, "expected integer expression");
7435 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7439 "expected %<,%> or %<)%>");
7441 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7442 OMP_CLAUSE_CHAIN (c
) = list
;
7446 c_parser_error (parser
, "invalid schedule kind");
7447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7452 shared ( variable-list ) */
7455 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7457 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7464 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7468 /* FIXME: Should we allow duplicates? */
7469 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7471 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7472 OMP_CLAUSE_CHAIN (c
) = list
;
7476 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7477 is a bitmask in MASK. Return the list of clauses found; the result
7478 of clause default goes in *pdefault. */
7481 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7484 tree clauses
= NULL
;
7487 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7490 pragma_omp_clause c_kind
;
7492 tree prev
= clauses
;
7494 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7495 c_parser_consume_token (parser
);
7498 here
= c_parser_peek_token (parser
)->location
;
7499 c_kind
= c_parser_omp_clause_name (parser
);
7503 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7504 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7505 c_name
= "collapse";
7507 case PRAGMA_OMP_CLAUSE_COPYIN
:
7508 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7511 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7512 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7513 c_name
= "copyprivate";
7515 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7516 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7519 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7520 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7521 c_name
= "firstprivate";
7523 case PRAGMA_OMP_CLAUSE_IF
:
7524 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7527 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7528 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7529 c_name
= "lastprivate";
7531 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7532 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7535 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7536 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7537 c_name
= "num_threads";
7539 case PRAGMA_OMP_CLAUSE_ORDERED
:
7540 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7543 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7544 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7547 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7548 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7549 c_name
= "reduction";
7551 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7552 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7553 c_name
= "schedule";
7555 case PRAGMA_OMP_CLAUSE_SHARED
:
7556 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7559 case PRAGMA_OMP_CLAUSE_UNTIED
:
7560 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7564 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7568 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7570 /* Remove the invalid clause(s) from the list to avoid
7571 confusing the rest of the compiler. */
7573 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7578 c_parser_skip_to_pragma_eol (parser
);
7580 return c_finish_omp_clauses (clauses
);
7587 In practice, we're also interested in adding the statement to an
7588 outer node. So it is convenient if we work around the fact that
7589 c_parser_statement calls add_stmt. */
7592 c_parser_omp_structured_block (c_parser
*parser
)
7594 tree stmt
= push_stmt_list ();
7595 c_parser_statement (parser
);
7596 return pop_stmt_list (stmt
);
7600 # pragma omp atomic new-line
7604 x binop= expr | x++ | ++x | x-- | --x
7606 +, *, -, /, &, ^, |, <<, >>
7608 where x is an lvalue expression with scalar type. */
7611 c_parser_omp_atomic (c_parser
*parser
)
7615 enum tree_code code
;
7616 struct c_expr rhs_expr
;
7618 c_parser_skip_to_pragma_eol (parser
);
7620 lhs
= c_parser_unary_expression (parser
).value
;
7621 lhs
= c_fully_fold (lhs
, false, NULL
);
7622 switch (TREE_CODE (lhs
))
7626 c_parser_skip_to_end_of_block_or_statement (parser
);
7629 case PREINCREMENT_EXPR
:
7630 case POSTINCREMENT_EXPR
:
7631 lhs
= TREE_OPERAND (lhs
, 0);
7633 rhs
= integer_one_node
;
7636 case PREDECREMENT_EXPR
:
7637 case POSTDECREMENT_EXPR
:
7638 lhs
= TREE_OPERAND (lhs
, 0);
7640 rhs
= integer_one_node
;
7644 switch (c_parser_peek_token (parser
)->type
)
7650 code
= TRUNC_DIV_EXPR
;
7665 code
= BIT_AND_EXPR
;
7668 code
= BIT_IOR_EXPR
;
7671 code
= BIT_XOR_EXPR
;
7674 c_parser_error (parser
,
7675 "invalid operator for %<#pragma omp atomic%>");
7679 c_parser_consume_token (parser
);
7680 rhs_expr
= c_parser_expression (parser
);
7681 rhs_expr
= default_function_array_conversion (rhs_expr
);
7682 rhs
= rhs_expr
.value
;
7683 rhs
= c_fully_fold (rhs
, false, NULL
);
7686 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7687 if (stmt
!= error_mark_node
)
7689 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7694 # pragma omp barrier new-line
7698 c_parser_omp_barrier (c_parser
*parser
)
7700 c_parser_consume_pragma (parser
);
7701 c_parser_skip_to_pragma_eol (parser
);
7703 c_finish_omp_barrier ();
7707 # pragma omp critical [(name)] new-line
7712 c_parser_omp_critical (c_parser
*parser
)
7714 tree stmt
, name
= NULL
;
7716 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7718 c_parser_consume_token (parser
);
7719 if (c_parser_next_token_is (parser
, CPP_NAME
))
7721 name
= c_parser_peek_token (parser
)->value
;
7722 c_parser_consume_token (parser
);
7723 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7726 c_parser_error (parser
, "expected identifier");
7728 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7729 c_parser_error (parser
, "expected %<(%> or end of line");
7730 c_parser_skip_to_pragma_eol (parser
);
7732 stmt
= c_parser_omp_structured_block (parser
);
7733 return c_finish_omp_critical (stmt
, name
);
7737 # pragma omp flush flush-vars[opt] new-line
7740 ( variable-list ) */
7743 c_parser_omp_flush (c_parser
*parser
)
7745 c_parser_consume_pragma (parser
);
7746 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7747 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7748 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7749 c_parser_error (parser
, "expected %<(%> or end of line");
7750 c_parser_skip_to_pragma_eol (parser
);
7752 c_finish_omp_flush ();
7755 /* Parse the restricted form of the for statement allowed by OpenMP.
7756 The real trick here is to determine the loop control variable early
7757 so that we can push a new decl if necessary to make it private. */
7760 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7762 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7763 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7765 bool fail
= false, open_brace_parsed
= false;
7766 int i
, collapse
= 1, nbraces
= 0;
7768 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7769 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7770 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7772 gcc_assert (collapse
>= 1);
7774 declv
= make_tree_vec (collapse
);
7775 initv
= make_tree_vec (collapse
);
7776 condv
= make_tree_vec (collapse
);
7777 incrv
= make_tree_vec (collapse
);
7779 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7781 c_parser_error (parser
, "for statement expected");
7784 loc
= c_parser_peek_token (parser
)->location
;
7785 c_parser_consume_token (parser
);
7787 for (i
= 0; i
< collapse
; i
++)
7791 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7794 /* Parse the initialization declaration or expression. */
7795 if (c_parser_next_token_starts_declspecs (parser
))
7799 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7800 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7801 decl
= check_for_loop_decls ();
7804 if (DECL_INITIAL (decl
) == error_mark_node
)
7805 decl
= error_mark_node
;
7808 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7809 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7811 struct c_expr decl_exp
;
7812 struct c_expr init_exp
;
7813 location_t init_loc
;
7815 decl_exp
= c_parser_postfix_expression (parser
);
7816 decl
= decl_exp
.value
;
7818 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7819 init_loc
= c_parser_peek_token (parser
)->location
;
7821 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7822 init_exp
= default_function_array_conversion (init_exp
);
7823 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7824 NOP_EXPR
, init_exp
.value
,
7825 init_exp
.original_type
);
7826 init
= c_process_expr_stmt (init
);
7828 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7833 c_parser_error (parser
,
7834 "expected iteration declaration or initialization");
7835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7841 /* Parse the loop condition. */
7843 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7845 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7846 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
7848 cond
= cond_expr
.value
;
7849 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7850 cond
= c_fully_fold (cond
, false, NULL
);
7851 switch (cond_expr
.original_code
)
7859 /* Can't be cond = error_mark_node, because we want to preserve
7860 the location until c_finish_omp_for. */
7861 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
7864 protected_set_expr_location (cond
, cond_loc
);
7866 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7868 /* Parse the increment expression. */
7870 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7872 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7874 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7875 protected_set_expr_location (incr
, incr_loc
);
7877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7879 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7883 TREE_VEC_ELT (declv
, i
) = decl
;
7884 TREE_VEC_ELT (initv
, i
) = init
;
7885 TREE_VEC_ELT (condv
, i
) = cond
;
7886 TREE_VEC_ELT (incrv
, i
) = incr
;
7890 if (i
== collapse
- 1)
7893 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7894 in between the collapsed for loops to be still considered perfectly
7895 nested. Hopefully the final version clarifies this.
7896 For now handle (multiple) {'s and empty statements. */
7899 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7901 c_parser_consume_token (parser
);
7904 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7906 c_parser_consume_token (parser
);
7910 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7911 c_parser_consume_token (parser
);
7914 c_parser_error (parser
, "not enough perfectly nested loops");
7917 open_brace_parsed
= true;
7927 nbraces
+= bracecount
;
7930 save_break
= c_break_label
;
7931 c_break_label
= size_one_node
;
7932 save_cont
= c_cont_label
;
7933 c_cont_label
= NULL_TREE
;
7934 body
= push_stmt_list ();
7936 if (open_brace_parsed
)
7938 stmt
= c_begin_compound_stmt (true);
7939 c_parser_compound_statement_nostart (parser
);
7940 add_stmt (c_end_compound_stmt (stmt
, true));
7943 add_stmt (c_parser_c99_block_statement (parser
));
7945 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7947 body
= pop_stmt_list (body
);
7948 c_break_label
= save_break
;
7949 c_cont_label
= save_cont
;
7953 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7955 c_parser_consume_token (parser
);
7958 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7959 c_parser_consume_token (parser
);
7962 c_parser_error (parser
, "collapsed loops not perfectly nested");
7965 stmt
= c_begin_compound_stmt (true);
7967 c_parser_compound_statement_nostart (parser
);
7968 body
= c_end_compound_stmt (stmt
, true);
7975 /* Only bother calling c_finish_omp_for if we haven't already generated
7976 an error from the initialization parsing. */
7979 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
7982 if (par_clauses
!= NULL
)
7985 for (c
= par_clauses
; *c
; )
7986 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
7987 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
7988 c
= &OMP_CLAUSE_CHAIN (*c
);
7991 for (i
= 0; i
< collapse
; i
++)
7992 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
7995 c
= &OMP_CLAUSE_CHAIN (*c
);
7996 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7999 "iteration variable %qD should not be firstprivate",
8000 OMP_CLAUSE_DECL (*c
));
8001 *c
= OMP_CLAUSE_CHAIN (*c
);
8005 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8006 change it to shared (decl) in
8007 OMP_PARALLEL_CLAUSES. */
8008 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
8009 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8010 OMP_CLAUSE_CHAIN (l
) = clauses
;
8012 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8016 OMP_FOR_CLAUSES (stmt
) = clauses
;
8023 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
8025 for_block
= TREE_CHAIN (for_block
);
8031 #pragma omp for for-clause[optseq] new-line
8035 #define OMP_FOR_CLAUSE_MASK \
8036 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8037 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8038 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8039 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8040 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8041 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8042 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8043 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8046 c_parser_omp_for (c_parser
*parser
)
8048 tree block
, clauses
, ret
;
8050 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8053 block
= c_begin_compound_stmt (true);
8054 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
8055 block
= c_end_compound_stmt (block
, true);
8062 # pragma omp master new-line
8067 c_parser_omp_master (c_parser
*parser
)
8069 c_parser_skip_to_pragma_eol (parser
);
8070 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
8074 # pragma omp ordered new-line
8079 c_parser_omp_ordered (c_parser
*parser
)
8081 c_parser_skip_to_pragma_eol (parser
);
8082 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
8088 { section-sequence }
8091 section-directive[opt] structured-block
8092 section-sequence section-directive structured-block */
8095 c_parser_omp_sections_scope (c_parser
*parser
)
8098 bool error_suppress
= false;
8101 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8103 /* Avoid skipping until the end of the block. */
8104 parser
->error
= false;
8108 stmt
= push_stmt_list ();
8110 loc
= c_parser_peek_token (parser
)->location
;
8111 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8113 substmt
= push_stmt_list ();
8117 c_parser_statement (parser
);
8119 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8121 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8123 if (c_parser_next_token_is (parser
, CPP_EOF
))
8127 substmt
= pop_stmt_list (substmt
);
8128 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8129 SET_EXPR_LOCATION (substmt
, loc
);
8135 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8137 if (c_parser_next_token_is (parser
, CPP_EOF
))
8140 loc
= c_parser_peek_token (parser
)->location
;
8141 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8143 c_parser_consume_pragma (parser
);
8144 c_parser_skip_to_pragma_eol (parser
);
8145 error_suppress
= false;
8147 else if (!error_suppress
)
8149 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8150 error_suppress
= true;
8153 substmt
= c_parser_omp_structured_block (parser
);
8154 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8155 SET_EXPR_LOCATION (substmt
, loc
);
8158 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8159 "expected %<#pragma omp section%> or %<}%>");
8161 substmt
= pop_stmt_list (stmt
);
8163 stmt
= make_node (OMP_SECTIONS
);
8164 TREE_TYPE (stmt
) = void_type_node
;
8165 OMP_SECTIONS_BODY (stmt
) = substmt
;
8167 return add_stmt (stmt
);
8171 # pragma omp sections sections-clause[optseq] newline
8175 #define OMP_SECTIONS_CLAUSE_MASK \
8176 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8177 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8178 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8179 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8180 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8183 c_parser_omp_sections (c_parser
*parser
)
8185 tree block
, clauses
, ret
;
8187 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8188 "#pragma omp sections");
8190 block
= c_begin_compound_stmt (true);
8191 ret
= c_parser_omp_sections_scope (parser
);
8193 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8194 block
= c_end_compound_stmt (block
, true);
8201 # pragma parallel parallel-clause new-line
8202 # pragma parallel for parallel-for-clause new-line
8203 # pragma parallel sections parallel-sections-clause new-line
8206 #define OMP_PARALLEL_CLAUSE_MASK \
8207 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8208 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8209 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8210 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8211 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8212 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8213 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8214 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8217 c_parser_omp_parallel (c_parser
*parser
)
8219 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8220 const char *p_name
= "#pragma omp parallel";
8221 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8222 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8224 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8226 c_parser_consume_token (parser
);
8227 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8228 p_name
= "#pragma omp parallel for";
8229 mask
|= OMP_FOR_CLAUSE_MASK
;
8230 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8232 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8234 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8235 if (strcmp (p
, "sections") == 0)
8237 c_parser_consume_token (parser
);
8238 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8239 p_name
= "#pragma omp parallel sections";
8240 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8241 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8245 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8249 case PRAGMA_OMP_PARALLEL
:
8250 block
= c_begin_omp_parallel ();
8251 c_parser_statement (parser
);
8252 stmt
= c_finish_omp_parallel (clauses
, block
);
8255 case PRAGMA_OMP_PARALLEL_FOR
:
8256 block
= c_begin_omp_parallel ();
8257 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8258 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
8259 stmt
= c_finish_omp_parallel (par_clause
, block
);
8260 OMP_PARALLEL_COMBINED (stmt
) = 1;
8263 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8264 block
= c_begin_omp_parallel ();
8265 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8266 stmt
= c_parser_omp_sections_scope (parser
);
8268 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8269 stmt
= c_finish_omp_parallel (par_clause
, block
);
8270 OMP_PARALLEL_COMBINED (stmt
) = 1;
8281 # pragma omp single single-clause[optseq] new-line
8285 #define OMP_SINGLE_CLAUSE_MASK \
8286 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8287 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8288 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8289 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8292 c_parser_omp_single (c_parser
*parser
)
8294 tree stmt
= make_node (OMP_SINGLE
);
8295 TREE_TYPE (stmt
) = void_type_node
;
8297 OMP_SINGLE_CLAUSES (stmt
)
8298 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8299 "#pragma omp single");
8300 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8302 return add_stmt (stmt
);
8306 # pragma omp task task-clause[optseq] new-line
8309 #define OMP_TASK_CLAUSE_MASK \
8310 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8311 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8312 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8313 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8314 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8315 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8318 c_parser_omp_task (c_parser
*parser
)
8320 tree clauses
, block
;
8322 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8323 "#pragma omp task");
8325 block
= c_begin_omp_task ();
8326 c_parser_statement (parser
);
8327 return c_finish_omp_task (clauses
, block
);
8331 # pragma omp taskwait new-line
8335 c_parser_omp_taskwait (c_parser
*parser
)
8337 c_parser_consume_pragma (parser
);
8338 c_parser_skip_to_pragma_eol (parser
);
8340 c_finish_omp_taskwait ();
8343 /* Main entry point to parsing most OpenMP pragmas. */
8346 c_parser_omp_construct (c_parser
*parser
)
8348 enum pragma_kind p_kind
;
8352 loc
= c_parser_peek_token (parser
)->location
;
8353 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8354 c_parser_consume_pragma (parser
);
8356 /* For all constructs below except #pragma omp atomic
8357 MUST_NOT_THROW catch handlers are needed when exceptions
8359 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8360 c_maybe_initialize_eh ();
8364 case PRAGMA_OMP_ATOMIC
:
8365 c_parser_omp_atomic (parser
);
8367 case PRAGMA_OMP_CRITICAL
:
8368 stmt
= c_parser_omp_critical (parser
);
8370 case PRAGMA_OMP_FOR
:
8371 stmt
= c_parser_omp_for (parser
);
8373 case PRAGMA_OMP_MASTER
:
8374 stmt
= c_parser_omp_master (parser
);
8376 case PRAGMA_OMP_ORDERED
:
8377 stmt
= c_parser_omp_ordered (parser
);
8379 case PRAGMA_OMP_PARALLEL
:
8380 stmt
= c_parser_omp_parallel (parser
);
8382 case PRAGMA_OMP_SECTIONS
:
8383 stmt
= c_parser_omp_sections (parser
);
8385 case PRAGMA_OMP_SINGLE
:
8386 stmt
= c_parser_omp_single (parser
);
8388 case PRAGMA_OMP_TASK
:
8389 stmt
= c_parser_omp_task (parser
);
8396 SET_EXPR_LOCATION (stmt
, loc
);
8401 # pragma omp threadprivate (variable-list) */
8404 c_parser_omp_threadprivate (c_parser
*parser
)
8408 c_parser_consume_pragma (parser
);
8409 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8411 /* Mark every variable in VARS to be assigned thread local storage. */
8412 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8414 tree v
= TREE_PURPOSE (t
);
8416 /* If V had already been marked threadprivate, it doesn't matter
8417 whether it had been used prior to this point. */
8418 if (TREE_CODE (v
) != VAR_DECL
)
8419 error ("%qD is not a variable", v
);
8420 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8421 error ("%qE declared %<threadprivate%> after first use", v
);
8422 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8423 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8424 else if (TREE_TYPE (v
) == error_mark_node
)
8426 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8427 error ("%<threadprivate%> %qE has incomplete type", v
);
8430 if (! DECL_THREAD_LOCAL_P (v
))
8432 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8433 /* If rtl has been already set for this var, call
8434 make_decl_rtl once again, so that encode_section_info
8435 has a chance to look at the new decl flags. */
8436 if (DECL_RTL_SET_P (v
))
8439 C_DECL_THREADPRIVATE_P (v
) = 1;
8443 c_parser_skip_to_pragma_eol (parser
);
8447 /* Parse a single source file. */
8452 /* Use local storage to begin. If the first token is a pragma, parse it.
8453 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8454 which will cause garbage collection. */
8457 memset (&tparser
, 0, sizeof tparser
);
8458 the_parser
= &tparser
;
8460 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8461 c_parser_pragma_pch_preprocess (&tparser
);
8463 the_parser
= GGC_NEW (c_parser
);
8464 *the_parser
= tparser
;
8466 c_parser_translation_unit (the_parser
);
8470 #include "gt-c-parser.h"