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 t1
= c_parser_type_name (parser
);
5342 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5346 expr
.value
= error_mark_node
;
5350 tree type_expr
= NULL_TREE
;
5351 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
,
5356 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5357 TREE_TYPE (expr
.value
), type_expr
,
5359 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5364 c_parser_consume_token (parser
);
5365 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5367 expr
.value
= error_mark_node
;
5370 t1
= c_parser_type_name (parser
);
5373 expr
.value
= error_mark_node
;
5376 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5379 expr
.value
= error_mark_node
;
5383 tree type
= groktypename (t1
, NULL
, NULL
);
5385 if (type
== error_mark_node
)
5386 offsetof_ref
= error_mark_node
;
5388 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5389 /* Parse the second argument to __builtin_offsetof. We
5390 must have one identifier, and beyond that we want to
5391 accept sub structure and sub array references. */
5392 if (c_parser_next_token_is (parser
, CPP_NAME
))
5394 offsetof_ref
= build_component_ref
5395 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5396 c_parser_consume_token (parser
);
5397 while (c_parser_next_token_is (parser
, CPP_DOT
)
5398 || c_parser_next_token_is (parser
,
5400 || c_parser_next_token_is (parser
,
5403 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5405 loc
= c_parser_peek_token (parser
)->location
;
5406 offsetof_ref
= build_array_ref (offsetof_ref
,
5411 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5414 c_parser_consume_token (parser
);
5415 if (c_parser_next_token_is_not (parser
,
5418 c_parser_error (parser
, "expected identifier");
5421 offsetof_ref
= build_component_ref
5423 c_parser_peek_token (parser
)->value
);
5424 c_parser_consume_token (parser
);
5429 loc
= c_parser_peek_token (parser
)->location
;
5430 c_parser_consume_token (parser
);
5431 idx
= c_parser_expression (parser
).value
;
5432 idx
= c_fully_fold (idx
, false, NULL
);
5433 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5435 offsetof_ref
= build_array_ref (offsetof_ref
, idx
, loc
);
5440 c_parser_error (parser
, "expected identifier");
5441 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5443 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5446 case RID_CHOOSE_EXPR
:
5447 c_parser_consume_token (parser
);
5448 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5450 expr
.value
= error_mark_node
;
5453 loc
= c_parser_peek_token (parser
)->location
;
5454 e1
= c_parser_expr_no_commas (parser
, NULL
);
5455 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5457 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5458 expr
.value
= error_mark_node
;
5461 e2
= c_parser_expr_no_commas (parser
, NULL
);
5462 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5464 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5465 expr
.value
= error_mark_node
;
5468 e3
= c_parser_expr_no_commas (parser
, NULL
);
5469 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5475 if (TREE_CODE (c
) != INTEGER_CST
5476 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5478 "first argument to %<__builtin_choose_expr%> not"
5480 constant_expression_warning (c
);
5481 expr
= integer_zerop (c
) ? e3
: e2
;
5484 case RID_TYPES_COMPATIBLE_P
:
5485 c_parser_consume_token (parser
);
5486 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5488 expr
.value
= error_mark_node
;
5491 t1
= c_parser_type_name (parser
);
5494 expr
.value
= error_mark_node
;
5497 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5500 expr
.value
= error_mark_node
;
5503 t2
= c_parser_type_name (parser
);
5506 expr
.value
= error_mark_node
;
5509 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5514 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5515 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5517 expr
.value
= comptypes (e1
, e2
)
5518 ? build_int_cst (NULL_TREE
, 1)
5519 : build_int_cst (NULL_TREE
, 0);
5522 case RID_AT_SELECTOR
:
5523 gcc_assert (c_dialect_objc ());
5524 c_parser_consume_token (parser
);
5525 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5527 expr
.value
= error_mark_node
;
5531 tree sel
= c_parser_objc_selector_arg (parser
);
5532 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5534 expr
.value
= objc_build_selector_expr (sel
);
5537 case RID_AT_PROTOCOL
:
5538 gcc_assert (c_dialect_objc ());
5539 c_parser_consume_token (parser
);
5540 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5542 expr
.value
= error_mark_node
;
5545 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5547 c_parser_error (parser
, "expected identifier");
5548 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5549 expr
.value
= error_mark_node
;
5553 tree id
= c_parser_peek_token (parser
)->value
;
5554 c_parser_consume_token (parser
);
5555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5557 expr
.value
= objc_build_protocol_expr (id
);
5561 /* Extension to support C-structures in the archiver. */
5562 gcc_assert (c_dialect_objc ());
5563 c_parser_consume_token (parser
);
5564 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5566 expr
.value
= error_mark_node
;
5569 t1
= c_parser_type_name (parser
);
5572 expr
.value
= error_mark_node
;
5573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5576 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5579 tree type
= groktypename (t1
, NULL
, NULL
);
5580 expr
.value
= objc_build_encode_expr (type
);
5584 c_parser_error (parser
, "expected expression");
5585 expr
.value
= error_mark_node
;
5589 case CPP_OPEN_SQUARE
:
5590 if (c_dialect_objc ())
5592 tree receiver
, args
;
5593 c_parser_consume_token (parser
);
5594 receiver
= c_parser_objc_receiver (parser
);
5595 args
= c_parser_objc_message_args (parser
);
5596 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5598 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5602 /* Else fall through to report error. */
5604 c_parser_error (parser
, "expected expression");
5605 expr
.value
= error_mark_node
;
5608 return c_parser_postfix_expression_after_primary (parser
, expr
);
5611 /* Parse a postfix expression after a parenthesized type name: the
5612 brace-enclosed initializer of a compound literal, possibly followed
5613 by some postfix operators. This is separate because it is not
5614 possible to tell until after the type name whether a cast
5615 expression has a cast or a compound literal, or whether the operand
5616 of sizeof is a parenthesized type name or starts with a compound
5617 literal. TYPE_LOC is the location where TYPE_NAME starts--the
5618 location of the first token after the parentheses around the type
5621 static struct c_expr
5622 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5623 struct c_type_name
*type_name
,
5624 location_t type_loc
)
5630 location_t start_loc
;
5631 tree type_expr
= NULL_TREE
;
5632 bool type_expr_const
= true;
5633 check_compound_literal_type (type_name
, type_loc
);
5634 start_init (NULL_TREE
, NULL
, 0);
5635 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5636 start_loc
= c_parser_peek_token (parser
)->location
;
5637 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5639 error_at (type_loc
, "compound literal has variable size");
5640 type
= error_mark_node
;
5642 init
= c_parser_braced_init (parser
, type
, false);
5644 maybe_warn_string_init (type
, init
);
5647 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
5648 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
5649 ? CONSTRUCTOR_NON_CONST (init
.value
)
5650 : init
.original_code
== C_MAYBE_CONST_EXPR
);
5651 non_const
|= !type_expr_const
;
5652 expr
.value
= build_compound_literal (type
, init
.value
, non_const
);
5653 expr
.original_code
= ERROR_MARK
;
5654 expr
.original_type
= NULL
;
5657 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
5659 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
5660 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
5664 gcc_assert (!non_const
);
5665 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
5666 type_expr
, expr
.value
);
5669 return c_parser_postfix_expression_after_primary (parser
, expr
);
5672 /* Parse a postfix expression after the initial primary or compound
5673 literal; that is, parse a series of postfix operators. */
5675 static struct c_expr
5676 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5679 struct c_expr orig_expr
;
5681 VEC(tree
,gc
) *exprlist
;
5682 VEC(tree
,gc
) *origtypes
;
5683 location_t loc
= c_parser_peek_token (parser
)->location
;
5686 switch (c_parser_peek_token (parser
)->type
)
5688 case CPP_OPEN_SQUARE
:
5689 /* Array reference. */
5690 loc
= c_parser_peek_token (parser
)->location
;
5691 c_parser_consume_token (parser
);
5692 idx
= c_parser_expression (parser
).value
;
5693 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5695 expr
.value
= build_array_ref (expr
.value
, idx
, loc
);
5696 expr
.original_code
= ERROR_MARK
;
5697 expr
.original_type
= NULL
;
5699 case CPP_OPEN_PAREN
:
5700 /* Function call. */
5701 c_parser_consume_token (parser
);
5702 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5705 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
5706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5709 expr
.value
= build_function_call_vec (expr
.value
, exprlist
,
5711 expr
.original_code
= ERROR_MARK
;
5712 if (TREE_CODE (expr
.value
) == INTEGER_CST
5713 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
5714 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
5715 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
5716 expr
.original_code
= C_MAYBE_CONST_EXPR
;
5717 expr
.original_type
= NULL
;
5718 if (exprlist
!= NULL
)
5720 release_tree_vector (exprlist
);
5721 release_tree_vector (origtypes
);
5725 /* Structure element reference. */
5726 c_parser_consume_token (parser
);
5727 expr
= default_function_array_conversion (expr
);
5728 if (c_parser_next_token_is (parser
, CPP_NAME
))
5729 ident
= c_parser_peek_token (parser
)->value
;
5732 c_parser_error (parser
, "expected identifier");
5733 expr
.value
= error_mark_node
;
5734 expr
.original_code
= ERROR_MARK
;
5735 expr
.original_type
= NULL
;
5738 c_parser_consume_token (parser
);
5739 expr
.value
= build_component_ref (expr
.value
, ident
);
5740 expr
.original_code
= ERROR_MARK
;
5741 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5742 expr
.original_type
= NULL
;
5745 /* Remember the original type of a bitfield. */
5746 tree field
= TREE_OPERAND (expr
.value
, 1);
5747 if (TREE_CODE (field
) != FIELD_DECL
)
5748 expr
.original_type
= NULL
;
5750 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5754 /* Structure element reference. */
5755 c_parser_consume_token (parser
);
5756 expr
= default_function_array_conversion (expr
);
5757 if (c_parser_next_token_is (parser
, CPP_NAME
))
5758 ident
= c_parser_peek_token (parser
)->value
;
5761 c_parser_error (parser
, "expected identifier");
5762 expr
.value
= error_mark_node
;
5763 expr
.original_code
= ERROR_MARK
;
5764 expr
.original_type
= NULL
;
5767 c_parser_consume_token (parser
);
5768 expr
.value
= build_component_ref (build_indirect_ref (loc
,
5772 expr
.original_code
= ERROR_MARK
;
5773 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
5774 expr
.original_type
= NULL
;
5777 /* Remember the original type of a bitfield. */
5778 tree field
= TREE_OPERAND (expr
.value
, 1);
5779 if (TREE_CODE (field
) != FIELD_DECL
)
5780 expr
.original_type
= NULL
;
5782 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
5786 /* Postincrement. */
5787 c_parser_consume_token (parser
);
5788 expr
= default_function_array_conversion (expr
);
5789 expr
.value
= build_unary_op (loc
,
5790 POSTINCREMENT_EXPR
, expr
.value
, 0);
5791 expr
.original_code
= ERROR_MARK
;
5792 expr
.original_type
= NULL
;
5794 case CPP_MINUS_MINUS
:
5795 /* Postdecrement. */
5796 c_parser_consume_token (parser
);
5797 expr
= default_function_array_conversion (expr
);
5798 expr
.value
= build_unary_op (loc
,
5799 POSTDECREMENT_EXPR
, expr
.value
, 0);
5800 expr
.original_code
= ERROR_MARK
;
5801 expr
.original_type
= NULL
;
5809 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5812 assignment-expression
5813 expression , assignment-expression
5816 static struct c_expr
5817 c_parser_expression (c_parser
*parser
)
5820 expr
= c_parser_expr_no_commas (parser
, NULL
);
5821 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5824 c_parser_consume_token (parser
);
5825 next
= c_parser_expr_no_commas (parser
, NULL
);
5826 next
= default_function_array_conversion (next
);
5827 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5828 expr
.original_code
= COMPOUND_EXPR
;
5829 expr
.original_type
= next
.original_type
;
5834 /* Parse an expression and convert functions or arrays to
5837 static struct c_expr
5838 c_parser_expression_conv (c_parser
*parser
)
5841 expr
= c_parser_expression (parser
);
5842 expr
= default_function_array_conversion (expr
);
5846 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5847 functions and arrays to pointers. If FOLD_P, fold the expressions.
5850 assignment-expression
5851 nonempty-expr-list , assignment-expression
5854 static VEC(tree
,gc
) *
5855 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
5856 VEC(tree
,gc
) **p_orig_types
)
5859 VEC(tree
,gc
) *orig_types
;
5862 ret
= make_tree_vector ();
5863 if (p_orig_types
== NULL
)
5866 orig_types
= make_tree_vector ();
5868 expr
= c_parser_expr_no_commas (parser
, NULL
);
5870 expr
= default_function_array_conversion (expr
);
5872 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5873 VEC_quick_push (tree
, ret
, expr
.value
);
5874 if (orig_types
!= NULL
)
5875 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
5876 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5878 c_parser_consume_token (parser
);
5879 expr
= c_parser_expr_no_commas (parser
, NULL
);
5881 expr
= default_function_array_conversion (expr
);
5883 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5884 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
5885 if (orig_types
!= NULL
)
5886 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
5888 if (orig_types
!= NULL
)
5889 *p_orig_types
= orig_types
;
5893 /* Parse Objective-C-specific constructs. */
5895 /* Parse an objc-class-definition.
5897 objc-class-definition:
5898 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5899 objc-class-instance-variables[opt] objc-methodprotolist @end
5900 @implementation identifier objc-superclass[opt]
5901 objc-class-instance-variables[opt]
5902 @interface identifier ( identifier ) objc-protocol-refs[opt]
5903 objc-methodprotolist @end
5904 @implementation identifier ( identifier )
5909 "@interface identifier (" must start "@interface identifier (
5910 identifier ) ...": objc-methodprotolist in the first production may
5911 not start with a parenthesized identifier as a declarator of a data
5912 definition with no declaration specifiers if the objc-superclass,
5913 objc-protocol-refs and objc-class-instance-variables are omitted. */
5916 c_parser_objc_class_definition (c_parser
*parser
)
5921 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5923 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5927 c_parser_consume_token (parser
);
5928 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5930 c_parser_error (parser
, "expected identifier");
5933 id1
= c_parser_peek_token (parser
)->value
;
5934 c_parser_consume_token (parser
);
5935 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5938 tree proto
= NULL_TREE
;
5939 c_parser_consume_token (parser
);
5940 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5942 c_parser_error (parser
, "expected identifier");
5943 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5946 id2
= c_parser_peek_token (parser
)->value
;
5947 c_parser_consume_token (parser
);
5948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5951 objc_start_category_implementation (id1
, id2
);
5954 if (c_parser_next_token_is (parser
, CPP_LESS
))
5955 proto
= c_parser_objc_protocol_refs (parser
);
5956 objc_start_category_interface (id1
, id2
, proto
);
5957 c_parser_objc_methodprotolist (parser
);
5958 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5959 objc_finish_interface ();
5962 if (c_parser_next_token_is (parser
, CPP_COLON
))
5964 c_parser_consume_token (parser
);
5965 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5967 c_parser_error (parser
, "expected identifier");
5970 superclass
= c_parser_peek_token (parser
)->value
;
5971 c_parser_consume_token (parser
);
5974 superclass
= NULL_TREE
;
5977 tree proto
= NULL_TREE
;
5978 if (c_parser_next_token_is (parser
, CPP_LESS
))
5979 proto
= c_parser_objc_protocol_refs (parser
);
5980 objc_start_class_interface (id1
, superclass
, proto
);
5983 objc_start_class_implementation (id1
, superclass
);
5984 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5985 c_parser_objc_class_instance_variables (parser
);
5988 objc_continue_interface ();
5989 c_parser_objc_methodprotolist (parser
);
5990 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5991 objc_finish_interface ();
5995 objc_continue_implementation ();
6000 /* Parse objc-class-instance-variables.
6002 objc-class-instance-variables:
6003 { objc-instance-variable-decl-list[opt] }
6005 objc-instance-variable-decl-list:
6006 objc-visibility-spec
6007 objc-instance-variable-decl ;
6009 objc-instance-variable-decl-list objc-visibility-spec
6010 objc-instance-variable-decl-list objc-instance-variable-decl ;
6011 objc-instance-variable-decl-list ;
6013 objc-visibility-spec:
6018 objc-instance-variable-decl:
6023 c_parser_objc_class_instance_variables (c_parser
*parser
)
6025 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6026 c_parser_consume_token (parser
);
6027 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6030 /* Parse any stray semicolon. */
6031 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6033 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6034 "extra semicolon in struct or union specified");
6035 c_parser_consume_token (parser
);
6038 /* Stop if at the end of the instance variables. */
6039 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6041 c_parser_consume_token (parser
);
6044 /* Parse any objc-visibility-spec. */
6045 if (c_parser_next_token_is_keyword (parser
, RID_PRIVATE
))
6047 c_parser_consume_token (parser
);
6048 objc_set_visibility (2);
6051 else if (c_parser_next_token_is_keyword (parser
, RID_PROTECTED
))
6053 c_parser_consume_token (parser
);
6054 objc_set_visibility (0);
6057 else if (c_parser_next_token_is_keyword (parser
, RID_PUBLIC
))
6059 c_parser_consume_token (parser
);
6060 objc_set_visibility (1);
6063 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6065 c_parser_pragma (parser
, pragma_external
);
6069 /* Parse some comma-separated declarations. */
6070 decls
= c_parser_struct_declaration (parser
);
6072 /* Comma-separated instance variables are chained together in
6073 reverse order; add them one by one. */
6074 tree ivar
= nreverse (decls
);
6075 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
6076 objc_add_instance_variable (copy_node (ivar
));
6078 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6082 /* Parse an objc-class-declaration.
6084 objc-class-declaration:
6085 @class identifier-list ;
6089 c_parser_objc_class_declaration (c_parser
*parser
)
6091 tree list
= NULL_TREE
;
6092 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_CLASS
));
6093 c_parser_consume_token (parser
);
6094 /* Any identifiers, including those declared as type names, are OK
6099 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6101 c_parser_error (parser
, "expected identifier");
6104 id
= c_parser_peek_token (parser
)->value
;
6105 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6106 c_parser_consume_token (parser
);
6107 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6108 c_parser_consume_token (parser
);
6112 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6113 objc_declare_class (list
);
6116 /* Parse an objc-alias-declaration.
6118 objc-alias-declaration:
6119 @compatibility_alias identifier identifier ;
6123 c_parser_objc_alias_declaration (c_parser
*parser
)
6126 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6127 c_parser_consume_token (parser
);
6128 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6130 c_parser_error (parser
, "expected identifier");
6131 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6134 id1
= c_parser_peek_token (parser
)->value
;
6135 c_parser_consume_token (parser
);
6136 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6138 c_parser_error (parser
, "expected identifier");
6139 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6142 id2
= c_parser_peek_token (parser
)->value
;
6143 c_parser_consume_token (parser
);
6144 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6145 objc_declare_alias (id1
, id2
);
6148 /* Parse an objc-protocol-definition.
6150 objc-protocol-definition:
6151 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6152 @protocol identifier-list ;
6154 "@protocol identifier ;" should be resolved as "@protocol
6155 identifier-list ;": objc-methodprotolist may not start with a
6156 semicolon in the first alternative if objc-protocol-refs are
6160 c_parser_objc_protocol_definition (c_parser
*parser
)
6162 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6163 c_parser_consume_token (parser
);
6164 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6166 c_parser_error (parser
, "expected identifier");
6169 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6170 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6172 tree list
= NULL_TREE
;
6173 /* Any identifiers, including those declared as type names, are
6178 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6180 c_parser_error (parser
, "expected identifier");
6183 id
= c_parser_peek_token (parser
)->value
;
6184 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6185 c_parser_consume_token (parser
);
6186 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6187 c_parser_consume_token (parser
);
6191 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6192 objc_declare_protocols (list
);
6196 tree id
= c_parser_peek_token (parser
)->value
;
6197 tree proto
= NULL_TREE
;
6198 c_parser_consume_token (parser
);
6199 if (c_parser_next_token_is (parser
, CPP_LESS
))
6200 proto
= c_parser_objc_protocol_refs (parser
);
6201 parser
->objc_pq_context
= true;
6202 objc_start_protocol (id
, proto
);
6203 c_parser_objc_methodprotolist (parser
);
6204 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6205 parser
->objc_pq_context
= false;
6206 objc_finish_interface ();
6210 /* Parse an objc-method-type.
6217 static enum tree_code
6218 c_parser_objc_method_type (c_parser
*parser
)
6220 switch (c_parser_peek_token (parser
)->type
)
6223 c_parser_consume_token (parser
);
6226 c_parser_consume_token (parser
);
6233 /* Parse an objc-method-definition.
6235 objc-method-definition:
6236 objc-method-type objc-method-decl ;[opt] compound-statement
6240 c_parser_objc_method_definition (c_parser
*parser
)
6242 enum tree_code type
= c_parser_objc_method_type (parser
);
6244 objc_set_method_type (type
);
6245 parser
->objc_pq_context
= true;
6246 decl
= c_parser_objc_method_decl (parser
);
6247 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6249 c_parser_consume_token (parser
);
6250 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6251 "extra semicolon in method definition specified");
6253 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6255 c_parser_error (parser
, "expected %<{%>");
6258 parser
->objc_pq_context
= false;
6259 objc_start_method_definition (decl
);
6260 add_stmt (c_parser_compound_statement (parser
));
6261 objc_finish_method_definition (current_function_decl
);
6264 /* Parse an objc-methodprotolist.
6266 objc-methodprotolist:
6268 objc-methodprotolist objc-methodproto
6269 objc-methodprotolist declaration
6270 objc-methodprotolist ;
6272 The declaration is a data definition, which may be missing
6273 declaration specifiers under the same rules and diagnostics as
6274 other data definitions outside functions, and the stray semicolon
6275 is diagnosed the same way as a stray semicolon outside a
6279 c_parser_objc_methodprotolist (c_parser
*parser
)
6283 /* The list is terminated by @end. */
6284 switch (c_parser_peek_token (parser
)->type
)
6287 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6288 "ISO C does not allow extra %<;%> outside of a function");
6289 c_parser_consume_token (parser
);
6293 c_parser_objc_methodproto (parser
);
6296 c_parser_pragma (parser
, pragma_external
);
6301 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6303 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6309 /* Parse an objc-methodproto.
6312 objc-method-type objc-method-decl ;
6316 c_parser_objc_methodproto (c_parser
*parser
)
6318 enum tree_code type
= c_parser_objc_method_type (parser
);
6320 objc_set_method_type (type
);
6321 /* Remember protocol qualifiers in prototypes. */
6322 parser
->objc_pq_context
= true;
6323 decl
= c_parser_objc_method_decl (parser
);
6324 /* Forget protocol qualifiers here. */
6325 parser
->objc_pq_context
= false;
6326 objc_add_method_declaration (decl
);
6327 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6330 /* Parse an objc-method-decl.
6333 ( objc-type-name ) objc-selector
6335 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6336 objc-keyword-selector objc-optparmlist
6338 objc-keyword-selector:
6340 objc-keyword-selector objc-keyword-decl
6343 objc-selector : ( objc-type-name ) identifier
6344 objc-selector : identifier
6345 : ( objc-type-name ) identifier
6349 objc-optparms objc-optellipsis
6353 objc-opt-parms , parameter-declaration
6361 c_parser_objc_method_decl (c_parser
*parser
)
6363 tree type
= NULL_TREE
;
6365 tree parms
= NULL_TREE
;
6366 bool ellipsis
= false;
6368 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6370 c_parser_consume_token (parser
);
6371 type
= c_parser_objc_type_name (parser
);
6372 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6374 sel
= c_parser_objc_selector (parser
);
6375 /* If there is no selector, or a colon follows, we have an
6376 objc-keyword-selector. If there is a selector, and a colon does
6377 not follow, that selector ends the objc-method-decl. */
6378 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6381 tree list
= NULL_TREE
;
6384 tree atype
= NULL_TREE
, id
, keyworddecl
;
6385 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6387 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6389 c_parser_consume_token (parser
);
6390 atype
= c_parser_objc_type_name (parser
);
6391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6394 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6396 c_parser_error (parser
, "expected identifier");
6397 return error_mark_node
;
6399 id
= c_parser_peek_token (parser
)->value
;
6400 c_parser_consume_token (parser
);
6401 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6402 list
= chainon (list
, keyworddecl
);
6403 tsel
= c_parser_objc_selector (parser
);
6404 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6407 /* Parse the optional parameter list. Optional Objective-C
6408 method parameters follow the C syntax, and may include '...'
6409 to denote a variable number of arguments. */
6410 parms
= make_node (TREE_LIST
);
6411 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6413 struct c_parm
*parm
;
6414 c_parser_consume_token (parser
);
6415 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6418 c_parser_consume_token (parser
);
6421 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6424 parms
= chainon (parms
,
6425 build_tree_list (NULL_TREE
, grokparm (parm
)));
6429 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6432 /* Parse an objc-type-name.
6435 objc-type-qualifiers[opt] type-name
6436 objc-type-qualifiers[opt]
6438 objc-type-qualifiers:
6440 objc-type-qualifiers objc-type-qualifier
6442 objc-type-qualifier: one of
6443 in out inout bycopy byref oneway
6447 c_parser_objc_type_name (c_parser
*parser
)
6449 tree quals
= NULL_TREE
;
6450 struct c_type_name
*type_name
= NULL
;
6451 tree type
= NULL_TREE
;
6454 c_token
*token
= c_parser_peek_token (parser
);
6455 if (token
->type
== CPP_KEYWORD
6456 && (token
->keyword
== RID_IN
6457 || token
->keyword
== RID_OUT
6458 || token
->keyword
== RID_INOUT
6459 || token
->keyword
== RID_BYCOPY
6460 || token
->keyword
== RID_BYREF
6461 || token
->keyword
== RID_ONEWAY
))
6463 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6464 c_parser_consume_token (parser
);
6469 if (c_parser_next_token_starts_typename (parser
))
6470 type_name
= c_parser_type_name (parser
);
6472 type
= groktypename (type_name
, NULL
, NULL
);
6473 return build_tree_list (quals
, type
);
6476 /* Parse objc-protocol-refs.
6483 c_parser_objc_protocol_refs (c_parser
*parser
)
6485 tree list
= NULL_TREE
;
6486 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6487 c_parser_consume_token (parser
);
6488 /* Any identifiers, including those declared as type names, are OK
6493 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6495 c_parser_error (parser
, "expected identifier");
6498 id
= c_parser_peek_token (parser
)->value
;
6499 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6500 c_parser_consume_token (parser
);
6501 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6502 c_parser_consume_token (parser
);
6506 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6510 /* Parse an objc-try-catch-statement.
6512 objc-try-catch-statement:
6513 @try compound-statement objc-catch-list[opt]
6514 @try compound-statement objc-catch-list[opt] @finally compound-statement
6517 @catch ( parameter-declaration ) compound-statement
6518 objc-catch-list @catch ( parameter-declaration ) compound-statement
6522 c_parser_objc_try_catch_statement (c_parser
*parser
)
6526 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRY
));
6527 c_parser_consume_token (parser
);
6528 loc
= c_parser_peek_token (parser
)->location
;
6529 stmt
= c_parser_compound_statement (parser
);
6530 objc_begin_try_stmt (loc
, stmt
);
6531 while (c_parser_next_token_is_keyword (parser
, RID_CATCH
))
6533 struct c_parm
*parm
;
6534 c_parser_consume_token (parser
);
6535 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6537 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6540 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6543 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6544 objc_begin_catch_clause (grokparm (parm
));
6545 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6546 c_parser_compound_statement_nostart (parser
);
6547 objc_finish_catch_clause ();
6549 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6553 c_parser_consume_token (parser
);
6554 finloc
= c_parser_peek_token (parser
)->location
;
6555 finstmt
= c_parser_compound_statement (parser
);
6556 objc_build_finally_clause (finloc
, finstmt
);
6558 objc_finish_try_stmt ();
6561 /* Parse an objc-synchronized-statement.
6563 objc-synchronized-statement:
6564 @synchronized ( expression ) compound-statement
6568 c_parser_objc_synchronized_statement (c_parser
*parser
)
6572 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6573 c_parser_consume_token (parser
);
6574 loc
= c_parser_peek_token (parser
)->location
;
6575 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6577 expr
= c_parser_expression (parser
).value
;
6578 expr
= c_fully_fold (expr
, false, NULL
);
6579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6582 expr
= error_mark_node
;
6583 stmt
= c_parser_compound_statement (parser
);
6584 objc_build_synchronized (loc
, expr
, stmt
);
6587 /* Parse an objc-selector; return NULL_TREE without an error if the
6588 next token is not an objc-selector.
6593 enum struct union if else while do for switch case default
6594 break continue return goto asm sizeof typeof __alignof
6595 unsigned long const short volatile signed restrict _Complex
6596 in out inout bycopy byref oneway int char float double void _Bool
6598 ??? Why this selection of keywords but not, for example, storage
6599 class specifiers? */
6602 c_parser_objc_selector (c_parser
*parser
)
6604 c_token
*token
= c_parser_peek_token (parser
);
6605 tree value
= token
->value
;
6606 if (token
->type
== CPP_NAME
)
6608 c_parser_consume_token (parser
);
6611 if (token
->type
!= CPP_KEYWORD
)
6613 switch (token
->keyword
)
6654 c_parser_consume_token (parser
);
6661 /* Parse an objc-selector-arg.
6665 objc-keywordname-list
6667 objc-keywordname-list:
6669 objc-keywordname-list objc-keywordname
6677 c_parser_objc_selector_arg (c_parser
*parser
)
6679 tree sel
= c_parser_objc_selector (parser
);
6680 tree list
= NULL_TREE
;
6681 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6685 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6687 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6688 sel
= c_parser_objc_selector (parser
);
6689 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6695 /* Parse an objc-receiver.
6704 c_parser_objc_receiver (c_parser
*parser
)
6706 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6707 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6708 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6710 tree id
= c_parser_peek_token (parser
)->value
;
6711 c_parser_consume_token (parser
);
6712 return objc_get_class_reference (id
);
6714 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
6717 /* Parse objc-message-args.
6721 objc-keywordarg-list
6723 objc-keywordarg-list:
6725 objc-keywordarg-list objc-keywordarg
6728 objc-selector : objc-keywordexpr
6733 c_parser_objc_message_args (c_parser
*parser
)
6735 tree sel
= c_parser_objc_selector (parser
);
6736 tree list
= NULL_TREE
;
6737 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6742 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6744 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6745 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6746 sel
= c_parser_objc_selector (parser
);
6747 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6753 /* Parse an objc-keywordexpr.
6760 c_parser_objc_keywordexpr (c_parser
*parser
)
6763 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
6764 if (VEC_length (tree
, expr_list
) == 1)
6766 /* Just return the expression, remove a level of
6768 ret
= VEC_index (tree
, expr_list
, 0);
6772 /* We have a comma expression, we will collapse later. */
6773 ret
= build_tree_list_vec (expr_list
);
6775 release_tree_vector (expr_list
);
6780 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6781 should be considered, statements. ALLOW_STMT is true if we're within
6782 the context of a function and such pragmas are to be allowed. Returns
6783 true if we actually parsed such a pragma. */
6786 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6790 id
= c_parser_peek_token (parser
)->pragma_kind
;
6791 gcc_assert (id
!= PRAGMA_NONE
);
6795 case PRAGMA_OMP_BARRIER
:
6796 if (context
!= pragma_compound
)
6798 if (context
== pragma_stmt
)
6799 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6800 "used in compound statements");
6803 c_parser_omp_barrier (parser
);
6806 case PRAGMA_OMP_FLUSH
:
6807 if (context
!= pragma_compound
)
6809 if (context
== pragma_stmt
)
6810 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6811 "used in compound statements");
6814 c_parser_omp_flush (parser
);
6817 case PRAGMA_OMP_TASKWAIT
:
6818 if (context
!= pragma_compound
)
6820 if (context
== pragma_stmt
)
6821 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
6822 "used in compound statements");
6825 c_parser_omp_taskwait (parser
);
6828 case PRAGMA_OMP_THREADPRIVATE
:
6829 c_parser_omp_threadprivate (parser
);
6832 case PRAGMA_OMP_SECTION
:
6833 error_at (c_parser_peek_token (parser
)->location
,
6834 "%<#pragma omp section%> may only be used in "
6835 "%<#pragma omp sections%> construct");
6836 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6839 case PRAGMA_GCC_PCH_PREPROCESS
:
6840 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6841 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6845 if (id
< PRAGMA_FIRST_EXTERNAL
)
6847 if (context
== pragma_external
)
6850 c_parser_error (parser
, "expected declaration specifiers");
6851 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6854 c_parser_omp_construct (parser
);
6860 c_parser_consume_pragma (parser
);
6861 c_invoke_pragma_handler (id
);
6863 /* Skip to EOL, but suppress any error message. Those will have been
6864 generated by the handler routine through calling error, as opposed
6865 to calling c_parser_error. */
6866 parser
->error
= true;
6867 c_parser_skip_to_pragma_eol (parser
);
6872 /* The interface the pragma parsers have to the lexer. */
6875 pragma_lex (tree
*value
)
6877 c_token
*tok
= c_parser_peek_token (the_parser
);
6878 enum cpp_ttype ret
= tok
->type
;
6880 *value
= tok
->value
;
6881 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6885 if (ret
== CPP_KEYWORD
)
6887 c_parser_consume_token (the_parser
);
6894 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6898 c_parser_consume_pragma (parser
);
6899 if (c_parser_next_token_is (parser
, CPP_STRING
))
6901 name
= c_parser_peek_token (parser
)->value
;
6902 c_parser_consume_token (parser
);
6905 c_parser_error (parser
, "expected string literal");
6906 c_parser_skip_to_pragma_eol (parser
);
6909 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6912 /* OpenMP 2.5 parsing routines. */
6914 /* Returns name of the next clause.
6915 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6916 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6917 returned and the token is consumed. */
6919 static pragma_omp_clause
6920 c_parser_omp_clause_name (c_parser
*parser
)
6922 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6924 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6925 result
= PRAGMA_OMP_CLAUSE_IF
;
6926 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6927 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6928 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6930 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6935 if (!strcmp ("collapse", p
))
6936 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
6937 else if (!strcmp ("copyin", p
))
6938 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6939 else if (!strcmp ("copyprivate", p
))
6940 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6943 if (!strcmp ("firstprivate", p
))
6944 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6947 if (!strcmp ("lastprivate", p
))
6948 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6951 if (!strcmp ("nowait", p
))
6952 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6953 else if (!strcmp ("num_threads", p
))
6954 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6957 if (!strcmp ("ordered", p
))
6958 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6961 if (!strcmp ("private", p
))
6962 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6965 if (!strcmp ("reduction", p
))
6966 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6969 if (!strcmp ("schedule", p
))
6970 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6971 else if (!strcmp ("shared", p
))
6972 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6975 if (!strcmp ("untied", p
))
6976 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
6981 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6982 c_parser_consume_token (parser
);
6987 /* Validate that a clause of the given type does not already exist. */
6990 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
6995 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6996 if (OMP_CLAUSE_CODE (c
) == code
)
6998 error ("too many %qs clauses", name
);
7006 variable-list , identifier
7008 If KIND is nonzero, create the appropriate node and install the decl
7009 in OMP_CLAUSE_DECL and add the node to the head of the list.
7011 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7012 return the list created. */
7015 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
7018 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7019 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7020 c_parser_error (parser
, "expected identifier");
7022 while (c_parser_next_token_is (parser
, CPP_NAME
)
7023 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7025 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7028 undeclared_variable (c_parser_peek_token (parser
)->value
,
7029 c_parser_peek_token (parser
)->location
);
7030 else if (t
== error_mark_node
)
7034 tree u
= build_omp_clause (kind
);
7035 OMP_CLAUSE_DECL (u
) = t
;
7036 OMP_CLAUSE_CHAIN (u
) = list
;
7040 list
= tree_cons (t
, NULL_TREE
, list
);
7042 c_parser_consume_token (parser
);
7044 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7047 c_parser_consume_token (parser
);
7053 /* Similarly, but expect leading and trailing parenthesis. This is a very
7054 common case for omp clauses. */
7057 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7060 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7062 list
= c_parser_omp_variable_list (parser
, kind
, list
);
7063 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7069 collapse ( constant-expression ) */
7072 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7074 tree c
, num
= error_mark_node
;
7078 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7080 loc
= c_parser_peek_token (parser
)->location
;
7081 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7083 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7086 if (num
== error_mark_node
)
7088 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7089 || !host_integerp (num
, 0)
7090 || (n
= tree_low_cst (num
, 0)) <= 0
7094 "collapse argument needs positive constant integer expression");
7097 c
= build_omp_clause (OMP_CLAUSE_COLLAPSE
);
7098 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7099 OMP_CLAUSE_CHAIN (c
) = list
;
7104 copyin ( variable-list ) */
7107 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7109 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7113 copyprivate ( variable-list ) */
7116 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7118 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7122 default ( shared | none ) */
7125 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7127 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7130 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7132 if (c_parser_next_token_is (parser
, CPP_NAME
))
7134 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7139 if (strcmp ("none", p
) != 0)
7141 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7145 if (strcmp ("shared", p
) != 0)
7147 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7154 c_parser_consume_token (parser
);
7159 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7163 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7166 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7167 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
7168 OMP_CLAUSE_CHAIN (c
) = list
;
7169 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7175 firstprivate ( variable-list ) */
7178 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7180 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7184 if ( expression ) */
7187 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7189 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7191 tree t
= c_parser_paren_condition (parser
);
7194 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7196 c
= build_omp_clause (OMP_CLAUSE_IF
);
7197 OMP_CLAUSE_IF_EXPR (c
) = t
;
7198 OMP_CLAUSE_CHAIN (c
) = list
;
7202 c_parser_error (parser
, "expected %<(%>");
7208 lastprivate ( variable-list ) */
7211 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7213 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7220 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7224 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7226 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
7227 OMP_CLAUSE_CHAIN (c
) = list
;
7232 num_threads ( expression ) */
7235 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7237 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7239 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7240 tree c
, t
= c_parser_expression (parser
).value
;
7241 t
= c_fully_fold (t
, false, NULL
);
7243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7245 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7247 c_parser_error (parser
, "expected integer expression");
7251 /* Attempt to statically determine when the number isn't positive. */
7252 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
7253 build_int_cst (TREE_TYPE (t
), 0));
7254 if (c
== boolean_true_node
)
7256 warning_at (expr_loc
, 0,
7257 "%<num_threads%> value must be positive");
7258 t
= integer_one_node
;
7261 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7263 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
7264 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7265 OMP_CLAUSE_CHAIN (c
) = list
;
7276 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7280 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7282 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
7283 OMP_CLAUSE_CHAIN (c
) = list
;
7288 private ( variable-list ) */
7291 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7293 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7297 reduction ( reduction-operator : variable-list )
7300 One of: + * - & ^ | && || */
7303 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7305 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7307 enum tree_code code
;
7309 switch (c_parser_peek_token (parser
)->type
)
7321 code
= BIT_AND_EXPR
;
7324 code
= BIT_XOR_EXPR
;
7327 code
= BIT_IOR_EXPR
;
7330 code
= TRUTH_ANDIF_EXPR
;
7333 code
= TRUTH_ORIF_EXPR
;
7336 c_parser_error (parser
,
7337 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7338 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7342 c_parser_consume_token (parser
);
7343 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7347 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7348 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7349 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7353 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7359 schedule ( schedule-kind )
7360 schedule ( schedule-kind , expression )
7363 static | dynamic | guided | runtime | auto
7367 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7371 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7374 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7376 if (c_parser_next_token_is (parser
, CPP_NAME
))
7378 tree kind
= c_parser_peek_token (parser
)->value
;
7379 const char *p
= IDENTIFIER_POINTER (kind
);
7384 if (strcmp ("dynamic", p
) != 0)
7386 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7390 if (strcmp ("guided", p
) != 0)
7392 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7396 if (strcmp ("runtime", p
) != 0)
7398 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7405 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7406 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7407 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
7408 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
7412 c_parser_consume_token (parser
);
7413 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7416 c_parser_consume_token (parser
);
7418 here
= c_parser_peek_token (parser
)->location
;
7419 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7420 t
= c_fully_fold (t
, false, NULL
);
7422 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7423 error_at (here
, "schedule %<runtime%> does not take "
7424 "a %<chunk_size%> parameter");
7425 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
7427 "schedule %<auto%> does not take "
7428 "a %<chunk_size%> parameter");
7429 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7430 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7432 c_parser_error (parser
, "expected integer expression");
7434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7438 "expected %<,%> or %<)%>");
7440 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7441 OMP_CLAUSE_CHAIN (c
) = list
;
7445 c_parser_error (parser
, "invalid schedule kind");
7446 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7451 shared ( variable-list ) */
7454 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7456 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7463 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7467 /* FIXME: Should we allow duplicates? */
7468 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
7470 c
= build_omp_clause (OMP_CLAUSE_UNTIED
);
7471 OMP_CLAUSE_CHAIN (c
) = list
;
7475 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7476 is a bitmask in MASK. Return the list of clauses found; the result
7477 of clause default goes in *pdefault. */
7480 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7483 tree clauses
= NULL
;
7486 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7489 pragma_omp_clause c_kind
;
7491 tree prev
= clauses
;
7493 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
7494 c_parser_consume_token (parser
);
7497 here
= c_parser_peek_token (parser
)->location
;
7498 c_kind
= c_parser_omp_clause_name (parser
);
7502 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
7503 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
7504 c_name
= "collapse";
7506 case PRAGMA_OMP_CLAUSE_COPYIN
:
7507 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7510 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7511 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7512 c_name
= "copyprivate";
7514 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7515 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7518 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7519 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7520 c_name
= "firstprivate";
7522 case PRAGMA_OMP_CLAUSE_IF
:
7523 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7526 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7527 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7528 c_name
= "lastprivate";
7530 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7531 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7534 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7535 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7536 c_name
= "num_threads";
7538 case PRAGMA_OMP_CLAUSE_ORDERED
:
7539 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7542 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7543 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7546 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7547 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7548 c_name
= "reduction";
7550 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7551 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7552 c_name
= "schedule";
7554 case PRAGMA_OMP_CLAUSE_SHARED
:
7555 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7558 case PRAGMA_OMP_CLAUSE_UNTIED
:
7559 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
7563 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7567 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7569 /* Remove the invalid clause(s) from the list to avoid
7570 confusing the rest of the compiler. */
7572 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
7577 c_parser_skip_to_pragma_eol (parser
);
7579 return c_finish_omp_clauses (clauses
);
7586 In practice, we're also interested in adding the statement to an
7587 outer node. So it is convenient if we work around the fact that
7588 c_parser_statement calls add_stmt. */
7591 c_parser_omp_structured_block (c_parser
*parser
)
7593 tree stmt
= push_stmt_list ();
7594 c_parser_statement (parser
);
7595 return pop_stmt_list (stmt
);
7599 # pragma omp atomic new-line
7603 x binop= expr | x++ | ++x | x-- | --x
7605 +, *, -, /, &, ^, |, <<, >>
7607 where x is an lvalue expression with scalar type. */
7610 c_parser_omp_atomic (c_parser
*parser
)
7614 enum tree_code code
;
7615 struct c_expr rhs_expr
;
7617 c_parser_skip_to_pragma_eol (parser
);
7619 lhs
= c_parser_unary_expression (parser
).value
;
7620 lhs
= c_fully_fold (lhs
, false, NULL
);
7621 switch (TREE_CODE (lhs
))
7625 c_parser_skip_to_end_of_block_or_statement (parser
);
7628 case PREINCREMENT_EXPR
:
7629 case POSTINCREMENT_EXPR
:
7630 lhs
= TREE_OPERAND (lhs
, 0);
7632 rhs
= integer_one_node
;
7635 case PREDECREMENT_EXPR
:
7636 case POSTDECREMENT_EXPR
:
7637 lhs
= TREE_OPERAND (lhs
, 0);
7639 rhs
= integer_one_node
;
7643 switch (c_parser_peek_token (parser
)->type
)
7649 code
= TRUNC_DIV_EXPR
;
7664 code
= BIT_AND_EXPR
;
7667 code
= BIT_IOR_EXPR
;
7670 code
= BIT_XOR_EXPR
;
7673 c_parser_error (parser
,
7674 "invalid operator for %<#pragma omp atomic%>");
7678 c_parser_consume_token (parser
);
7679 rhs_expr
= c_parser_expression (parser
);
7680 rhs_expr
= default_function_array_conversion (rhs_expr
);
7681 rhs
= rhs_expr
.value
;
7682 rhs
= c_fully_fold (rhs
, false, NULL
);
7685 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7686 if (stmt
!= error_mark_node
)
7688 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7693 # pragma omp barrier new-line
7697 c_parser_omp_barrier (c_parser
*parser
)
7699 c_parser_consume_pragma (parser
);
7700 c_parser_skip_to_pragma_eol (parser
);
7702 c_finish_omp_barrier ();
7706 # pragma omp critical [(name)] new-line
7711 c_parser_omp_critical (c_parser
*parser
)
7713 tree stmt
, name
= NULL
;
7715 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7717 c_parser_consume_token (parser
);
7718 if (c_parser_next_token_is (parser
, CPP_NAME
))
7720 name
= c_parser_peek_token (parser
)->value
;
7721 c_parser_consume_token (parser
);
7722 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7725 c_parser_error (parser
, "expected identifier");
7727 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7728 c_parser_error (parser
, "expected %<(%> or end of line");
7729 c_parser_skip_to_pragma_eol (parser
);
7731 stmt
= c_parser_omp_structured_block (parser
);
7732 return c_finish_omp_critical (stmt
, name
);
7736 # pragma omp flush flush-vars[opt] new-line
7739 ( variable-list ) */
7742 c_parser_omp_flush (c_parser
*parser
)
7744 c_parser_consume_pragma (parser
);
7745 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7746 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
7747 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7748 c_parser_error (parser
, "expected %<(%> or end of line");
7749 c_parser_skip_to_pragma_eol (parser
);
7751 c_finish_omp_flush ();
7754 /* Parse the restricted form of the for statement allowed by OpenMP.
7755 The real trick here is to determine the loop control variable early
7756 so that we can push a new decl if necessary to make it private. */
7759 c_parser_omp_for_loop (c_parser
*parser
, tree clauses
, tree
*par_clauses
)
7761 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
7762 tree declv
, condv
, incrv
, initv
, for_block
= NULL
, ret
= NULL
;
7764 bool fail
= false, open_brace_parsed
= false;
7765 int i
, collapse
= 1, nbraces
= 0;
7767 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
7768 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
7769 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
7771 gcc_assert (collapse
>= 1);
7773 declv
= make_tree_vec (collapse
);
7774 initv
= make_tree_vec (collapse
);
7775 condv
= make_tree_vec (collapse
);
7776 incrv
= make_tree_vec (collapse
);
7778 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7780 c_parser_error (parser
, "for statement expected");
7783 loc
= c_parser_peek_token (parser
)->location
;
7784 c_parser_consume_token (parser
);
7786 for (i
= 0; i
< collapse
; i
++)
7790 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7793 /* Parse the initialization declaration or expression. */
7794 if (c_parser_next_token_starts_declspecs (parser
))
7798 = tree_cons (NULL
, c_begin_compound_stmt (true), for_block
);
7799 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7800 decl
= check_for_loop_decls ();
7803 if (DECL_INITIAL (decl
) == error_mark_node
)
7804 decl
= error_mark_node
;
7807 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7808 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7810 struct c_expr decl_exp
;
7811 struct c_expr init_exp
;
7812 location_t init_loc
;
7814 decl_exp
= c_parser_postfix_expression (parser
);
7815 decl
= decl_exp
.value
;
7817 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7818 init_loc
= c_parser_peek_token (parser
)->location
;
7820 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
7821 init_exp
= default_function_array_conversion (init_exp
);
7822 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
7823 NOP_EXPR
, init_exp
.value
,
7824 init_exp
.original_type
);
7825 init
= c_process_expr_stmt (init
);
7827 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7832 c_parser_error (parser
,
7833 "expected iteration declaration or initialization");
7834 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7840 /* Parse the loop condition. */
7842 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7844 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
7845 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
7847 cond
= cond_expr
.value
;
7848 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
7849 cond
= c_fully_fold (cond
, false, NULL
);
7850 switch (cond_expr
.original_code
)
7858 /* Can't be cond = error_mark_node, because we want to preserve
7859 the location until c_finish_omp_for. */
7860 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
7863 protected_set_expr_location (cond
, cond_loc
);
7865 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7867 /* Parse the increment expression. */
7869 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7871 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
7873 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7874 protected_set_expr_location (incr
, incr_loc
);
7876 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7878 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
7882 TREE_VEC_ELT (declv
, i
) = decl
;
7883 TREE_VEC_ELT (initv
, i
) = init
;
7884 TREE_VEC_ELT (condv
, i
) = cond
;
7885 TREE_VEC_ELT (incrv
, i
) = incr
;
7889 if (i
== collapse
- 1)
7892 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
7893 in between the collapsed for loops to be still considered perfectly
7894 nested. Hopefully the final version clarifies this.
7895 For now handle (multiple) {'s and empty statements. */
7898 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7900 c_parser_consume_token (parser
);
7903 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7905 c_parser_consume_token (parser
);
7909 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7910 c_parser_consume_token (parser
);
7913 c_parser_error (parser
, "not enough perfectly nested loops");
7916 open_brace_parsed
= true;
7926 nbraces
+= bracecount
;
7929 save_break
= c_break_label
;
7930 c_break_label
= size_one_node
;
7931 save_cont
= c_cont_label
;
7932 c_cont_label
= NULL_TREE
;
7933 body
= push_stmt_list ();
7935 if (open_brace_parsed
)
7937 stmt
= c_begin_compound_stmt (true);
7938 c_parser_compound_statement_nostart (parser
);
7939 add_stmt (c_end_compound_stmt (stmt
, true));
7942 add_stmt (c_parser_c99_block_statement (parser
));
7944 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7946 body
= pop_stmt_list (body
);
7947 c_break_label
= save_break
;
7948 c_cont_label
= save_cont
;
7952 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7954 c_parser_consume_token (parser
);
7957 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7958 c_parser_consume_token (parser
);
7961 c_parser_error (parser
, "collapsed loops not perfectly nested");
7964 stmt
= c_begin_compound_stmt (true);
7966 c_parser_compound_statement_nostart (parser
);
7967 body
= c_end_compound_stmt (stmt
, true);
7974 /* Only bother calling c_finish_omp_for if we haven't already generated
7975 an error from the initialization parsing. */
7978 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
7981 if (par_clauses
!= NULL
)
7984 for (c
= par_clauses
; *c
; )
7985 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
7986 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
7987 c
= &OMP_CLAUSE_CHAIN (*c
);
7990 for (i
= 0; i
< collapse
; i
++)
7991 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
7994 c
= &OMP_CLAUSE_CHAIN (*c
);
7995 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7998 "iteration variable %qD should not be firstprivate",
7999 OMP_CLAUSE_DECL (*c
));
8000 *c
= OMP_CLAUSE_CHAIN (*c
);
8004 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8005 change it to shared (decl) in
8006 OMP_PARALLEL_CLAUSES. */
8007 tree l
= build_omp_clause (OMP_CLAUSE_LASTPRIVATE
);
8008 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8009 OMP_CLAUSE_CHAIN (l
) = clauses
;
8011 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8015 OMP_FOR_CLAUSES (stmt
) = clauses
;
8022 stmt
= c_end_compound_stmt (TREE_VALUE (for_block
), true);
8024 for_block
= TREE_CHAIN (for_block
);
8030 #pragma omp for for-clause[optseq] new-line
8034 #define OMP_FOR_CLAUSE_MASK \
8035 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8036 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8037 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8038 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8039 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8040 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8041 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8042 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8045 c_parser_omp_for (c_parser
*parser
)
8047 tree block
, clauses
, ret
;
8049 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8052 block
= c_begin_compound_stmt (true);
8053 ret
= c_parser_omp_for_loop (parser
, clauses
, NULL
);
8054 block
= c_end_compound_stmt (block
, true);
8061 # pragma omp master new-line
8066 c_parser_omp_master (c_parser
*parser
)
8068 c_parser_skip_to_pragma_eol (parser
);
8069 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
8073 # pragma omp ordered new-line
8078 c_parser_omp_ordered (c_parser
*parser
)
8080 c_parser_skip_to_pragma_eol (parser
);
8081 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
8087 { section-sequence }
8090 section-directive[opt] structured-block
8091 section-sequence section-directive structured-block */
8094 c_parser_omp_sections_scope (c_parser
*parser
)
8097 bool error_suppress
= false;
8100 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8102 /* Avoid skipping until the end of the block. */
8103 parser
->error
= false;
8107 stmt
= push_stmt_list ();
8109 loc
= c_parser_peek_token (parser
)->location
;
8110 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8112 substmt
= push_stmt_list ();
8116 c_parser_statement (parser
);
8118 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8120 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8122 if (c_parser_next_token_is (parser
, CPP_EOF
))
8126 substmt
= pop_stmt_list (substmt
);
8127 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8128 SET_EXPR_LOCATION (substmt
, loc
);
8134 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8136 if (c_parser_next_token_is (parser
, CPP_EOF
))
8139 loc
= c_parser_peek_token (parser
)->location
;
8140 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8142 c_parser_consume_pragma (parser
);
8143 c_parser_skip_to_pragma_eol (parser
);
8144 error_suppress
= false;
8146 else if (!error_suppress
)
8148 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8149 error_suppress
= true;
8152 substmt
= c_parser_omp_structured_block (parser
);
8153 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8154 SET_EXPR_LOCATION (substmt
, loc
);
8157 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8158 "expected %<#pragma omp section%> or %<}%>");
8160 substmt
= pop_stmt_list (stmt
);
8162 stmt
= make_node (OMP_SECTIONS
);
8163 TREE_TYPE (stmt
) = void_type_node
;
8164 OMP_SECTIONS_BODY (stmt
) = substmt
;
8166 return add_stmt (stmt
);
8170 # pragma omp sections sections-clause[optseq] newline
8174 #define OMP_SECTIONS_CLAUSE_MASK \
8175 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8176 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8177 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8178 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8179 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8182 c_parser_omp_sections (c_parser
*parser
)
8184 tree block
, clauses
, ret
;
8186 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8187 "#pragma omp sections");
8189 block
= c_begin_compound_stmt (true);
8190 ret
= c_parser_omp_sections_scope (parser
);
8192 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8193 block
= c_end_compound_stmt (block
, true);
8200 # pragma parallel parallel-clause new-line
8201 # pragma parallel for parallel-for-clause new-line
8202 # pragma parallel sections parallel-sections-clause new-line
8205 #define OMP_PARALLEL_CLAUSE_MASK \
8206 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8207 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8208 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8209 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8210 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8211 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8212 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8213 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8216 c_parser_omp_parallel (c_parser
*parser
)
8218 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8219 const char *p_name
= "#pragma omp parallel";
8220 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8221 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8223 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8225 c_parser_consume_token (parser
);
8226 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8227 p_name
= "#pragma omp parallel for";
8228 mask
|= OMP_FOR_CLAUSE_MASK
;
8229 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8231 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8233 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8234 if (strcmp (p
, "sections") == 0)
8236 c_parser_consume_token (parser
);
8237 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8238 p_name
= "#pragma omp parallel sections";
8239 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8240 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8244 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8248 case PRAGMA_OMP_PARALLEL
:
8249 block
= c_begin_omp_parallel ();
8250 c_parser_statement (parser
);
8251 stmt
= c_finish_omp_parallel (clauses
, block
);
8254 case PRAGMA_OMP_PARALLEL_FOR
:
8255 block
= c_begin_omp_parallel ();
8256 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8257 c_parser_omp_for_loop (parser
, ws_clause
, &par_clause
);
8258 stmt
= c_finish_omp_parallel (par_clause
, block
);
8259 OMP_PARALLEL_COMBINED (stmt
) = 1;
8262 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8263 block
= c_begin_omp_parallel ();
8264 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
8265 stmt
= c_parser_omp_sections_scope (parser
);
8267 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8268 stmt
= c_finish_omp_parallel (par_clause
, block
);
8269 OMP_PARALLEL_COMBINED (stmt
) = 1;
8280 # pragma omp single single-clause[optseq] new-line
8284 #define OMP_SINGLE_CLAUSE_MASK \
8285 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8286 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8287 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8288 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8291 c_parser_omp_single (c_parser
*parser
)
8293 tree stmt
= make_node (OMP_SINGLE
);
8294 TREE_TYPE (stmt
) = void_type_node
;
8296 OMP_SINGLE_CLAUSES (stmt
)
8297 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8298 "#pragma omp single");
8299 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8301 return add_stmt (stmt
);
8305 # pragma omp task task-clause[optseq] new-line
8308 #define OMP_TASK_CLAUSE_MASK \
8309 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8310 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8311 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8312 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8313 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8314 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8317 c_parser_omp_task (c_parser
*parser
)
8319 tree clauses
, block
;
8321 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8322 "#pragma omp task");
8324 block
= c_begin_omp_task ();
8325 c_parser_statement (parser
);
8326 return c_finish_omp_task (clauses
, block
);
8330 # pragma omp taskwait new-line
8334 c_parser_omp_taskwait (c_parser
*parser
)
8336 c_parser_consume_pragma (parser
);
8337 c_parser_skip_to_pragma_eol (parser
);
8339 c_finish_omp_taskwait ();
8342 /* Main entry point to parsing most OpenMP pragmas. */
8345 c_parser_omp_construct (c_parser
*parser
)
8347 enum pragma_kind p_kind
;
8351 loc
= c_parser_peek_token (parser
)->location
;
8352 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
8353 c_parser_consume_pragma (parser
);
8355 /* For all constructs below except #pragma omp atomic
8356 MUST_NOT_THROW catch handlers are needed when exceptions
8358 if (p_kind
!= PRAGMA_OMP_ATOMIC
)
8359 c_maybe_initialize_eh ();
8363 case PRAGMA_OMP_ATOMIC
:
8364 c_parser_omp_atomic (parser
);
8366 case PRAGMA_OMP_CRITICAL
:
8367 stmt
= c_parser_omp_critical (parser
);
8369 case PRAGMA_OMP_FOR
:
8370 stmt
= c_parser_omp_for (parser
);
8372 case PRAGMA_OMP_MASTER
:
8373 stmt
= c_parser_omp_master (parser
);
8375 case PRAGMA_OMP_ORDERED
:
8376 stmt
= c_parser_omp_ordered (parser
);
8378 case PRAGMA_OMP_PARALLEL
:
8379 stmt
= c_parser_omp_parallel (parser
);
8381 case PRAGMA_OMP_SECTIONS
:
8382 stmt
= c_parser_omp_sections (parser
);
8384 case PRAGMA_OMP_SINGLE
:
8385 stmt
= c_parser_omp_single (parser
);
8387 case PRAGMA_OMP_TASK
:
8388 stmt
= c_parser_omp_task (parser
);
8395 SET_EXPR_LOCATION (stmt
, loc
);
8400 # pragma omp threadprivate (variable-list) */
8403 c_parser_omp_threadprivate (c_parser
*parser
)
8407 c_parser_consume_pragma (parser
);
8408 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8410 /* Mark every variable in VARS to be assigned thread local storage. */
8411 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8413 tree v
= TREE_PURPOSE (t
);
8415 /* If V had already been marked threadprivate, it doesn't matter
8416 whether it had been used prior to this point. */
8417 if (TREE_CODE (v
) != VAR_DECL
)
8418 error ("%qD is not a variable", v
);
8419 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
8420 error ("%qE declared %<threadprivate%> after first use", v
);
8421 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8422 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8423 else if (TREE_TYPE (v
) == error_mark_node
)
8425 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
8426 error ("%<threadprivate%> %qE has incomplete type", v
);
8429 if (! DECL_THREAD_LOCAL_P (v
))
8431 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
8432 /* If rtl has been already set for this var, call
8433 make_decl_rtl once again, so that encode_section_info
8434 has a chance to look at the new decl flags. */
8435 if (DECL_RTL_SET_P (v
))
8438 C_DECL_THREADPRIVATE_P (v
) = 1;
8442 c_parser_skip_to_pragma_eol (parser
);
8446 /* Parse a single source file. */
8451 /* Use local storage to begin. If the first token is a pragma, parse it.
8452 If it is #pragma GCC pch_preprocess, then this will load a PCH file
8453 which will cause garbage collection. */
8456 memset (&tparser
, 0, sizeof tparser
);
8457 the_parser
= &tparser
;
8459 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
8460 c_parser_pragma_pch_preprocess (&tparser
);
8462 the_parser
= GGC_NEW (c_parser
);
8463 *the_parser
= tparser
;
8465 c_parser_translation_unit (the_parser
);
8469 #include "gt-c-parser.h"