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, 2010
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"
43 #include "tm.h" /* For rtl.h: needs enum reg_class. */
45 #include "langhooks.h"
49 #include "c-family/c-pragma.h"
55 #include "c-family/c-common.h"
62 /* Initialization routine for this file. */
67 /* The only initialization required is of the reserved word
73 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
74 the c_token structure. */
75 gcc_assert (RID_MAX
<= 255);
82 mask
|= D_ASM
| D_EXT
;
86 if (!c_dialect_objc ())
87 mask
|= D_OBJC
| D_CXX_OBJC
;
89 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
90 for (i
= 0; i
< num_c_common_reswords
; i
++)
92 /* If a keyword is disabled, do not enter it into the table
93 and so create a canonical spelling that isn't a keyword. */
94 if (c_common_reswords
[i
].disable
& mask
)
97 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
99 id
= get_identifier (c_common_reswords
[i
].word
);
100 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
101 C_IS_RESERVED_WORD (id
) = 1;
106 id
= get_identifier (c_common_reswords
[i
].word
);
107 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
108 C_IS_RESERVED_WORD (id
) = 1;
109 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
113 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
114 and the C parser. Unlike the C++ lexer, the parser structure
115 stores the lexer information instead of using a separate structure.
116 Identifiers are separated into ordinary identifiers, type names,
117 keywords and some other Objective-C types of identifiers, and some
118 look-ahead is maintained.
120 ??? It might be a good idea to lex the whole file up front (as for
121 C++). It would then be possible to share more of the C and C++
122 lexer code, if desired. */
124 /* The following local token type is used. */
127 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
129 /* More information about the type of a CPP_NAME token. */
130 typedef enum c_id_kind
{
131 /* An ordinary identifier. */
133 /* An identifier declared as a typedef name. */
135 /* An identifier declared as an Objective-C class name. */
137 /* An address space identifier. */
139 /* Not an identifier. */
143 /* A single C token after string literal concatenation and conversion
144 of preprocessing tokens to tokens. */
145 typedef struct GTY (()) c_token
{
146 /* The kind of token. */
147 ENUM_BITFIELD (cpp_ttype
) type
: 8;
148 /* If this token is a CPP_NAME, this value indicates whether also
149 declared as some kind of type. Otherwise, it is C_ID_NONE. */
150 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
151 /* If this token is a keyword, this value indicates which keyword.
152 Otherwise, this value is RID_MAX. */
153 ENUM_BITFIELD (rid
) keyword
: 8;
154 /* If this token is a CPP_PRAGMA, this indicates the pragma that
155 was seen. Otherwise it is PRAGMA_NONE. */
156 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
157 /* The location at which this token was found. */
159 /* The value associated with this token, if any. */
163 /* A parser structure recording information about the state and
164 context of parsing. Includes lexer information with up to two
165 tokens of look-ahead; more are not needed for C. */
166 typedef struct GTY(()) c_parser
{
167 /* The look-ahead tokens. */
169 /* How many look-ahead tokens are available (0, 1 or 2). */
171 /* True if a syntax error is being recovered from; false otherwise.
172 c_parser_error sets this flag. It should clear this flag when
173 enough tokens have been consumed to recover from the error. */
174 BOOL_BITFIELD error
: 1;
175 /* True if we're processing a pragma, and shouldn't automatically
176 consume CPP_PRAGMA_EOL. */
177 BOOL_BITFIELD in_pragma
: 1;
178 /* True if we're parsing the outermost block of an if statement. */
179 BOOL_BITFIELD in_if_block
: 1;
180 /* True if we want to lex an untranslated string. */
181 BOOL_BITFIELD lex_untranslated_string
: 1;
183 /* Objective-C specific parser/lexer information. */
185 /* True if we are in a context where the Objective-C "PQ" keywords
186 are considered keywords. */
187 BOOL_BITFIELD objc_pq_context
: 1;
188 /* The following flag is needed to contextualize Objective-C lexical
189 analysis. In some cases (e.g., 'int NSObject;'), it is
190 undesirable to bind an identifier to an Objective-C class, even
191 if a class with that name exists. */
192 BOOL_BITFIELD objc_need_raw_identifier
: 1;
196 /* The actual parser and external interface. ??? Does this need to be
197 garbage-collected? */
199 static GTY (()) c_parser
*the_parser
;
201 /* Read in and lex a single token, storing it in *TOKEN. */
204 c_lex_one_token (c_parser
*parser
, c_token
*token
)
206 timevar_push (TV_LEX
);
208 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
209 (parser
->lex_untranslated_string
210 ? C_LEX_STRING_NO_TRANSLATE
: 0));
211 token
->id_kind
= C_ID_NONE
;
212 token
->keyword
= RID_MAX
;
213 token
->pragma_kind
= PRAGMA_NONE
;
221 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
222 if (c_dialect_objc ())
223 parser
->objc_need_raw_identifier
= false;
225 if (C_IS_RESERVED_WORD (token
->value
))
227 enum rid rid_code
= C_RID_CODE (token
->value
);
229 if (rid_code
== RID_CXX_COMPAT_WARN
)
231 warning_at (token
->location
,
233 "identifier %qE conflicts with C++ keyword",
236 else if (rid_code
>= RID_FIRST_ADDR_SPACE
237 && rid_code
<= RID_LAST_ADDR_SPACE
)
239 token
->id_kind
= C_ID_ADDRSPACE
;
240 token
->keyword
= rid_code
;
243 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
245 /* We found an Objective-C "pq" keyword (in, out,
246 inout, bycopy, byref, oneway). They need special
247 care because the interpretation depends on the
250 if (parser
->objc_pq_context
)
252 token
->type
= CPP_KEYWORD
;
253 token
->keyword
= rid_code
;
256 /* Else, "pq" keywords outside of the "pq" context are
257 not keywords, and we fall through to the code for
261 else if (c_dialect_objc ()
262 && (OBJC_IS_AT_KEYWORD (rid_code
)
263 || OBJC_IS_CXX_KEYWORD (rid_code
)))
265 /* We found one of the Objective-C "@" keywords (defs,
266 selector, synchronized, etc) or one of the
267 Objective-C "cxx" keywords (class, private,
268 protected, public, try, catch, throw) without a
269 preceding '@' sign. Do nothing and fall through to
270 the code for normal tokens (in C++ we would still
271 consider the CXX ones keywords, but not in C).
277 token
->type
= CPP_KEYWORD
;
278 token
->keyword
= rid_code
;
283 decl
= lookup_name (token
->value
);
286 if (TREE_CODE (decl
) == TYPE_DECL
)
288 token
->id_kind
= C_ID_TYPENAME
;
292 else if (c_dialect_objc ())
294 tree objc_interface_decl
= objc_is_class_name (token
->value
);
295 /* Objective-C class names are in the same namespace as
296 variables and typedefs, and hence are shadowed by local
298 if (objc_interface_decl
299 && (global_bindings_p ()
300 || (!objc_force_identifier
&& !decl
)))
302 token
->value
= objc_interface_decl
;
303 token
->id_kind
= C_ID_CLASSNAME
;
307 token
->id_kind
= C_ID_ID
;
311 /* This only happens in Objective-C; it must be a keyword. */
312 token
->type
= CPP_KEYWORD
;
313 switch (C_RID_CODE (token
->value
))
315 /* Replace 'class' with '@class', 'private' with '@private',
316 etc. This prevents confusion with the C++ keyword
317 'class', and makes the tokens consistent with other
318 Objective-C 'AT' keywords. For example '@class' is
319 reported as RID_AT_CLASS which is consistent with
320 '@synchronized', which is reported as
323 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
324 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
325 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
326 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
327 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
328 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
329 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
330 default: token
->keyword
= C_RID_CODE (token
->value
);
335 case CPP_CLOSE_PAREN
:
337 /* These tokens may affect the interpretation of any identifiers
338 following, if doing Objective-C. */
339 if (c_dialect_objc ())
340 parser
->objc_need_raw_identifier
= false;
343 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
344 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
350 timevar_pop (TV_LEX
);
353 /* Return a pointer to the next token from PARSER, reading it in if
356 static inline c_token
*
357 c_parser_peek_token (c_parser
*parser
)
359 if (parser
->tokens_avail
== 0)
361 c_lex_one_token (parser
, &parser
->tokens
[0]);
362 parser
->tokens_avail
= 1;
364 return &parser
->tokens
[0];
367 /* Return true if the next token from PARSER has the indicated
371 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
373 return c_parser_peek_token (parser
)->type
== type
;
376 /* Return true if the next token from PARSER does not have the
380 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
382 return !c_parser_next_token_is (parser
, type
);
385 /* Return true if the next token from PARSER is the indicated
389 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
391 return c_parser_peek_token (parser
)->keyword
== keyword
;
394 /* Return true if TOKEN can start a type name,
397 c_token_starts_typename (c_token
*token
)
402 switch (token
->id_kind
)
411 gcc_assert (c_dialect_objc ());
417 switch (token
->keyword
)
450 if (c_dialect_objc ())
458 /* Return true if the next token from PARSER can start a type name,
461 c_parser_next_token_starts_typename (c_parser
*parser
)
463 c_token
*token
= c_parser_peek_token (parser
);
464 return c_token_starts_typename (token
);
467 /* Return true if TOKEN can start declaration specifiers, false
470 c_token_starts_declspecs (c_token
*token
)
475 switch (token
->id_kind
)
484 gcc_assert (c_dialect_objc ());
490 switch (token
->keyword
)
530 if (c_dialect_objc ())
539 /* Return true if TOKEN can start declaration specifiers or a static
540 assertion, false otherwise. */
542 c_token_starts_declaration (c_token
*token
)
544 if (c_token_starts_declspecs (token
)
545 || token
->keyword
== RID_STATIC_ASSERT
)
551 /* Return true if the next token from PARSER can start declaration
552 specifiers, false otherwise. */
554 c_parser_next_token_starts_declspecs (c_parser
*parser
)
556 c_token
*token
= c_parser_peek_token (parser
);
557 return c_token_starts_declspecs (token
);
560 /* Return true if the next token from PARSER can start declaration
561 specifiers or a static assertion, false otherwise. */
563 c_parser_next_token_starts_declaration (c_parser
*parser
)
565 c_token
*token
= c_parser_peek_token (parser
);
566 return c_token_starts_declaration (token
);
569 /* Return a pointer to the next-but-one token from PARSER, reading it
570 in if necessary. The next token is already read in. */
573 c_parser_peek_2nd_token (c_parser
*parser
)
575 if (parser
->tokens_avail
>= 2)
576 return &parser
->tokens
[1];
577 gcc_assert (parser
->tokens_avail
== 1);
578 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
579 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
580 c_lex_one_token (parser
, &parser
->tokens
[1]);
581 parser
->tokens_avail
= 2;
582 return &parser
->tokens
[1];
585 /* Consume the next token from PARSER. */
588 c_parser_consume_token (c_parser
*parser
)
590 gcc_assert (parser
->tokens_avail
>= 1);
591 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
592 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
593 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
594 if (parser
->tokens_avail
== 2)
595 parser
->tokens
[0] = parser
->tokens
[1];
596 parser
->tokens_avail
--;
599 /* Expect the current token to be a #pragma. Consume it and remember
600 that we've begun parsing a pragma. */
603 c_parser_consume_pragma (c_parser
*parser
)
605 gcc_assert (!parser
->in_pragma
);
606 gcc_assert (parser
->tokens_avail
>= 1);
607 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
608 if (parser
->tokens_avail
== 2)
609 parser
->tokens
[0] = parser
->tokens
[1];
610 parser
->tokens_avail
--;
611 parser
->in_pragma
= true;
614 /* Update the globals input_location and in_system_header from
617 c_parser_set_source_position_from_token (c_token
*token
)
619 if (token
->type
!= CPP_EOF
)
621 input_location
= token
->location
;
625 /* Issue a diagnostic of the form
626 FILE:LINE: MESSAGE before TOKEN
627 where TOKEN is the next token in the input stream of PARSER.
628 MESSAGE (specified by the caller) is usually of the form "expected
631 Do not issue a diagnostic if still recovering from an error.
633 ??? This is taken from the C++ parser, but building up messages in
634 this way is not i18n-friendly and some other approach should be
638 c_parser_error (c_parser
*parser
, const char *gmsgid
)
640 c_token
*token
= c_parser_peek_token (parser
);
643 parser
->error
= true;
646 /* This diagnostic makes more sense if it is tagged to the line of
647 the token we just peeked at. */
648 c_parser_set_source_position_from_token (token
);
649 c_parse_error (gmsgid
,
650 /* Because c_parse_error does not understand
651 CPP_KEYWORD, keywords are treated like
653 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
654 /* ??? The C parser does not save the cpp flags of a
655 token, we need to pass 0 here and we will not get
656 the source spelling of some tokens but rather the
657 canonical spelling. */
658 token
->value
, /*flags=*/0);
661 /* If the next token is of the indicated TYPE, consume it. Otherwise,
662 issue the error MSGID. If MSGID is NULL then a message has already
663 been produced and no message will be produced this time. Returns
664 true if found, false otherwise. */
667 c_parser_require (c_parser
*parser
,
671 if (c_parser_next_token_is (parser
, type
))
673 c_parser_consume_token (parser
);
678 c_parser_error (parser
, msgid
);
683 /* If the next token is the indicated keyword, consume it. Otherwise,
684 issue the error MSGID. Returns true if found, false otherwise. */
687 c_parser_require_keyword (c_parser
*parser
,
691 if (c_parser_next_token_is_keyword (parser
, keyword
))
693 c_parser_consume_token (parser
);
698 c_parser_error (parser
, msgid
);
703 /* Like c_parser_require, except that tokens will be skipped until the
704 desired token is found. An error message is still produced if the
705 next token is not as expected. If MSGID is NULL then a message has
706 already been produced and no message will be produced this
710 c_parser_skip_until_found (c_parser
*parser
,
714 unsigned nesting_depth
= 0;
716 if (c_parser_require (parser
, type
, msgid
))
719 /* Skip tokens until the desired token is found. */
722 /* Peek at the next token. */
723 c_token
*token
= c_parser_peek_token (parser
);
724 /* If we've reached the token we want, consume it and stop. */
725 if (token
->type
== type
&& !nesting_depth
)
727 c_parser_consume_token (parser
);
731 /* If we've run out of tokens, stop. */
732 if (token
->type
== CPP_EOF
)
734 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
736 if (token
->type
== CPP_OPEN_BRACE
737 || token
->type
== CPP_OPEN_PAREN
738 || token
->type
== CPP_OPEN_SQUARE
)
740 else if (token
->type
== CPP_CLOSE_BRACE
741 || token
->type
== CPP_CLOSE_PAREN
742 || token
->type
== CPP_CLOSE_SQUARE
)
744 if (nesting_depth
-- == 0)
747 /* Consume this token. */
748 c_parser_consume_token (parser
);
750 parser
->error
= false;
753 /* Skip tokens until the end of a parameter is found, but do not
754 consume the comma, semicolon or closing delimiter. */
757 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
759 unsigned nesting_depth
= 0;
763 c_token
*token
= c_parser_peek_token (parser
);
764 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
767 /* If we've run out of tokens, stop. */
768 if (token
->type
== CPP_EOF
)
770 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
772 if (token
->type
== CPP_OPEN_BRACE
773 || token
->type
== CPP_OPEN_PAREN
774 || token
->type
== CPP_OPEN_SQUARE
)
776 else if (token
->type
== CPP_CLOSE_BRACE
777 || token
->type
== CPP_CLOSE_PAREN
778 || token
->type
== CPP_CLOSE_SQUARE
)
780 if (nesting_depth
-- == 0)
783 /* Consume this token. */
784 c_parser_consume_token (parser
);
786 parser
->error
= false;
789 /* Expect to be at the end of the pragma directive and consume an
790 end of line marker. */
793 c_parser_skip_to_pragma_eol (c_parser
*parser
)
795 gcc_assert (parser
->in_pragma
);
796 parser
->in_pragma
= false;
798 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
801 c_token
*token
= c_parser_peek_token (parser
);
802 if (token
->type
== CPP_EOF
)
804 if (token
->type
== CPP_PRAGMA_EOL
)
806 c_parser_consume_token (parser
);
809 c_parser_consume_token (parser
);
812 parser
->error
= false;
815 /* Skip tokens until we have consumed an entire block, or until we
816 have consumed a non-nested ';'. */
819 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
821 unsigned nesting_depth
= 0;
822 bool save_error
= parser
->error
;
828 /* Peek at the next token. */
829 token
= c_parser_peek_token (parser
);
837 if (parser
->in_pragma
)
842 /* If the next token is a ';', we have reached the
843 end of the statement. */
846 /* Consume the ';'. */
847 c_parser_consume_token (parser
);
852 case CPP_CLOSE_BRACE
:
853 /* If the next token is a non-nested '}', then we have
854 reached the end of the current block. */
855 if (nesting_depth
== 0 || --nesting_depth
== 0)
857 c_parser_consume_token (parser
);
863 /* If it the next token is a '{', then we are entering a new
864 block. Consume the entire block. */
869 /* If we see a pragma, consume the whole thing at once. We
870 have some safeguards against consuming pragmas willy-nilly.
871 Normally, we'd expect to be here with parser->error set,
872 which disables these safeguards. But it's possible to get
873 here for secondary error recovery, after parser->error has
875 c_parser_consume_pragma (parser
);
876 c_parser_skip_to_pragma_eol (parser
);
877 parser
->error
= save_error
;
884 c_parser_consume_token (parser
);
888 parser
->error
= false;
891 /* CPP's options (initialized by c-opts.c). */
892 extern cpp_options
*cpp_opts
;
894 /* Save the warning flags which are controlled by __extension__. */
897 disable_extension_diagnostics (void)
900 | (warn_pointer_arith
<< 1)
901 | (warn_traditional
<< 2)
903 | (warn_long_long
<< 4)
904 | (warn_cxx_compat
<< 5));
905 cpp_opts
->cpp_pedantic
= pedantic
= 0;
906 warn_pointer_arith
= 0;
907 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
909 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
914 /* Restore the warning flags which are controlled by __extension__.
915 FLAGS is the return value from disable_extension_diagnostics. */
918 restore_extension_diagnostics (int flags
)
920 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
921 warn_pointer_arith
= (flags
>> 1) & 1;
922 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
923 flag_iso
= (flags
>> 3) & 1;
924 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
925 warn_cxx_compat
= (flags
>> 5) & 1;
928 /* Possibly kinds of declarator to parse. */
929 typedef enum c_dtr_syn
{
930 /* A normal declarator with an identifier. */
932 /* An abstract declarator (maybe empty). */
934 /* A parameter declarator: may be either, but after a type name does
935 not redeclare a typedef name as an identifier if it can
936 alternatively be interpreted as a typedef name; see DR#009,
937 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
938 following DR#249. For example, given a typedef T, "int T" and
939 "int *T" are valid parameter declarations redeclaring T, while
940 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
941 abstract declarators rather than involving redundant parentheses;
942 the same applies with attributes inside the parentheses before
947 static void c_parser_external_declaration (c_parser
*);
948 static void c_parser_asm_definition (c_parser
*);
949 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
951 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
952 static void c_parser_static_assert_declaration (c_parser
*);
953 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
955 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
956 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
957 static tree
c_parser_struct_declaration (c_parser
*);
958 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
959 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
961 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
963 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
965 struct c_declarator
*);
966 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
967 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
968 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
969 static tree
c_parser_simple_asm_expr (c_parser
*);
970 static tree
c_parser_attributes (c_parser
*);
971 static struct c_type_name
*c_parser_type_name (c_parser
*);
972 static struct c_expr
c_parser_initializer (c_parser
*);
973 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
974 static void c_parser_initelt (c_parser
*, struct obstack
*);
975 static void c_parser_initval (c_parser
*, struct c_expr
*,
977 static tree
c_parser_compound_statement (c_parser
*);
978 static void c_parser_compound_statement_nostart (c_parser
*);
979 static void c_parser_label (c_parser
*);
980 static void c_parser_statement (c_parser
*);
981 static void c_parser_statement_after_labels (c_parser
*);
982 static void c_parser_if_statement (c_parser
*);
983 static void c_parser_switch_statement (c_parser
*);
984 static void c_parser_while_statement (c_parser
*);
985 static void c_parser_do_statement (c_parser
*);
986 static void c_parser_for_statement (c_parser
*);
987 static tree
c_parser_asm_statement (c_parser
*);
988 static tree
c_parser_asm_operands (c_parser
*, bool);
989 static tree
c_parser_asm_goto_operands (c_parser
*);
990 static tree
c_parser_asm_clobbers (c_parser
*);
991 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
992 static struct c_expr
c_parser_conditional_expression (c_parser
*,
994 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
995 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
996 static struct c_expr
c_parser_unary_expression (c_parser
*);
997 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
998 static struct c_expr
c_parser_alignof_expression (c_parser
*);
999 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1000 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1001 struct c_type_name
*,
1003 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1006 static struct c_expr
c_parser_expression (c_parser
*);
1007 static struct c_expr
c_parser_expression_conv (c_parser
*);
1008 static VEC(tree
,gc
) *c_parser_expr_list (c_parser
*, bool, bool,
1010 static void c_parser_omp_construct (c_parser
*);
1011 static void c_parser_omp_threadprivate (c_parser
*);
1012 static void c_parser_omp_barrier (c_parser
*);
1013 static void c_parser_omp_flush (c_parser
*);
1014 static void c_parser_omp_taskwait (c_parser
*);
1016 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1017 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1019 /* These Objective-C parser functions are only ever called when
1020 compiling Objective-C. */
1021 static void c_parser_objc_class_definition (c_parser
*, tree
);
1022 static void c_parser_objc_class_instance_variables (c_parser
*);
1023 static void c_parser_objc_class_declaration (c_parser
*);
1024 static void c_parser_objc_alias_declaration (c_parser
*);
1025 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1026 static enum tree_code
c_parser_objc_method_type (c_parser
*);
1027 static void c_parser_objc_method_definition (c_parser
*);
1028 static void c_parser_objc_methodprotolist (c_parser
*);
1029 static void c_parser_objc_methodproto (c_parser
*);
1030 static tree
c_parser_objc_method_decl (c_parser
*, tree
*);
1031 static tree
c_parser_objc_type_name (c_parser
*);
1032 static tree
c_parser_objc_protocol_refs (c_parser
*);
1033 static void c_parser_objc_try_catch_statement (c_parser
*);
1034 static void c_parser_objc_synchronized_statement (c_parser
*);
1035 static tree
c_parser_objc_selector (c_parser
*);
1036 static tree
c_parser_objc_selector_arg (c_parser
*);
1037 static tree
c_parser_objc_receiver (c_parser
*);
1038 static tree
c_parser_objc_message_args (c_parser
*);
1039 static tree
c_parser_objc_keywordexpr (c_parser
*);
1040 static bool c_parser_objc_diagnose_bad_element_prefix
1041 (c_parser
*, struct c_declspecs
*);
1043 /* Parse a translation unit (C90 6.7, C99 6.9).
1046 external-declarations
1048 external-declarations:
1049 external-declaration
1050 external-declarations external-declaration
1059 c_parser_translation_unit (c_parser
*parser
)
1061 if (c_parser_next_token_is (parser
, CPP_EOF
))
1063 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1064 "ISO C forbids an empty translation unit");
1068 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1069 mark_valid_location_for_stdc_pragma (false);
1073 c_parser_external_declaration (parser
);
1074 obstack_free (&parser_obstack
, obstack_position
);
1076 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1080 /* Parse an external declaration (C90 6.7, C99 6.9).
1082 external-declaration:
1088 external-declaration:
1091 __extension__ external-declaration
1095 external-declaration:
1096 objc-class-definition
1097 objc-class-declaration
1098 objc-alias-declaration
1099 objc-protocol-definition
1100 objc-method-definition
1105 c_parser_external_declaration (c_parser
*parser
)
1108 switch (c_parser_peek_token (parser
)->type
)
1111 switch (c_parser_peek_token (parser
)->keyword
)
1114 ext
= disable_extension_diagnostics ();
1115 c_parser_consume_token (parser
);
1116 c_parser_external_declaration (parser
);
1117 restore_extension_diagnostics (ext
);
1120 c_parser_asm_definition (parser
);
1122 case RID_AT_INTERFACE
:
1123 case RID_AT_IMPLEMENTATION
:
1124 gcc_assert (c_dialect_objc ());
1125 c_parser_objc_class_definition (parser
, NULL_TREE
);
1128 gcc_assert (c_dialect_objc ());
1129 c_parser_objc_class_declaration (parser
);
1132 gcc_assert (c_dialect_objc ());
1133 c_parser_objc_alias_declaration (parser
);
1135 case RID_AT_PROTOCOL
:
1136 gcc_assert (c_dialect_objc ());
1137 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1140 gcc_assert (c_dialect_objc ());
1141 c_parser_consume_token (parser
);
1142 objc_finish_implementation ();
1149 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
1150 "ISO C does not allow extra %<;%> outside of a function");
1151 c_parser_consume_token (parser
);
1154 mark_valid_location_for_stdc_pragma (true);
1155 c_parser_pragma (parser
, pragma_external
);
1156 mark_valid_location_for_stdc_pragma (false);
1160 if (c_dialect_objc ())
1162 c_parser_objc_method_definition (parser
);
1165 /* Else fall through, and yield a syntax error trying to parse
1166 as a declaration or function definition. */
1169 /* A declaration or a function definition (or, in Objective-C,
1170 an @interface or @protocol with prefix attributes). We can
1171 only tell which after parsing the declaration specifiers, if
1172 any, and the first declarator. */
1173 c_parser_declaration_or_fndef (parser
, true, true, true, false, true);
1178 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1179 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1180 accepted; otherwise (old-style parameter declarations) only other
1181 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1182 assertion is accepted; otherwise (old-style parameter declarations)
1183 it is not. If NESTED is true, we are inside a function or parsing
1184 old-style parameter declarations; any functions encountered are
1185 nested functions and declaration specifiers are required; otherwise
1186 we are at top level and functions are normal functions and
1187 declaration specifiers may be optional. If EMPTY_OK is true, empty
1188 declarations are OK (subject to all other constraints); otherwise
1189 (old-style parameter declarations) they are diagnosed. If
1190 START_ATTR_OK is true, the declaration specifiers may start with
1191 attributes; otherwise they may not.
1194 declaration-specifiers init-declarator-list[opt] ;
1195 static_assert-declaration
1197 function-definition:
1198 declaration-specifiers[opt] declarator declaration-list[opt]
1203 declaration-list declaration
1205 init-declarator-list:
1207 init-declarator-list , init-declarator
1210 declarator simple-asm-expr[opt] attributes[opt]
1211 declarator simple-asm-expr[opt] attributes[opt] = initializer
1215 nested-function-definition:
1216 declaration-specifiers declarator declaration-list[opt]
1220 attributes objc-class-definition
1221 attributes objc-category-definition
1222 attributes objc-protocol-definition
1224 The simple-asm-expr and attributes are GNU extensions.
1226 This function does not handle __extension__; that is handled in its
1227 callers. ??? Following the old parser, __extension__ may start
1228 external declarations, declarations in functions and declarations
1229 at the start of "for" loops, but not old-style parameter
1232 C99 requires declaration specifiers in a function definition; the
1233 absence is diagnosed through the diagnosis of implicit int. In GNU
1234 C we also allow but diagnose declarations without declaration
1235 specifiers, but only at top level (elsewhere they conflict with
1241 threadprivate-directive */
1244 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1245 bool static_assert_ok
, bool empty_ok
,
1246 bool nested
, bool start_attr_ok
)
1248 struct c_declspecs
*specs
;
1250 tree all_prefix_attrs
;
1251 bool diagnosed_no_specs
= false;
1252 location_t here
= c_parser_peek_token (parser
)->location
;
1254 if (static_assert_ok
1255 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1257 c_parser_static_assert_declaration (parser
);
1260 specs
= build_null_declspecs ();
1261 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1264 c_parser_skip_to_end_of_block_or_statement (parser
);
1267 if (nested
&& !specs
->declspecs_seen_p
)
1269 c_parser_error (parser
, "expected declaration specifiers");
1270 c_parser_skip_to_end_of_block_or_statement (parser
);
1273 finish_declspecs (specs
);
1274 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1280 shadow_tag_warned (specs
, 1);
1281 pedwarn (here
, 0, "empty declaration");
1283 c_parser_consume_token (parser
);
1286 else if (c_dialect_objc ())
1288 /* Prefix attributes are an error on method decls. */
1289 switch (c_parser_peek_token (parser
)->type
)
1293 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1297 warning_at (c_parser_peek_token (parser
)->location
,
1299 "prefix attributes are ignored for methods");
1300 specs
->attrs
= NULL_TREE
;
1303 c_parser_objc_method_definition (parser
);
1305 c_parser_objc_methodproto (parser
);
1311 /* This is where we parse 'attributes @interface ...',
1312 'attributes @implementation ...', 'attributes @protocol ...'
1313 (where attributes could be, for example, __attribute__
1316 switch (c_parser_peek_token (parser
)->keyword
)
1318 case RID_AT_INTERFACE
:
1320 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1322 c_parser_objc_class_definition (parser
, specs
->attrs
);
1326 case RID_AT_IMPLEMENTATION
:
1328 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1332 warning_at (c_parser_peek_token (parser
)->location
,
1334 "prefix attributes are ignored for implementations");
1335 specs
->attrs
= NULL_TREE
;
1337 c_parser_objc_class_definition (parser
, NULL_TREE
);
1341 case RID_AT_PROTOCOL
:
1343 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1345 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1354 pending_xref_error ();
1355 prefix_attrs
= specs
->attrs
;
1356 all_prefix_attrs
= prefix_attrs
;
1357 specs
->attrs
= NULL_TREE
;
1360 struct c_declarator
*declarator
;
1363 /* Declaring either one or more declarators (in which case we
1364 should diagnose if there were no declaration specifiers) or a
1365 function definition (in which case the diagnostic for
1366 implicit int suffices). */
1367 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1368 C_DTR_NORMAL
, &dummy
);
1369 if (declarator
== NULL
)
1371 c_parser_skip_to_end_of_block_or_statement (parser
);
1374 if (c_parser_next_token_is (parser
, CPP_EQ
)
1375 || c_parser_next_token_is (parser
, CPP_COMMA
)
1376 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1377 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1378 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1380 tree asm_name
= NULL_TREE
;
1381 tree postfix_attrs
= NULL_TREE
;
1382 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1384 diagnosed_no_specs
= true;
1385 pedwarn (here
, 0, "data definition has no type or storage class");
1387 /* Having seen a data definition, there cannot now be a
1388 function definition. */
1390 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1391 asm_name
= c_parser_simple_asm_expr (parser
);
1392 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1393 postfix_attrs
= c_parser_attributes (parser
);
1394 if (c_parser_next_token_is (parser
, CPP_EQ
))
1398 location_t init_loc
;
1399 c_parser_consume_token (parser
);
1400 /* The declaration of the variable is in effect while
1401 its initializer is parsed. */
1402 d
= start_decl (declarator
, specs
, true,
1403 chainon (postfix_attrs
, all_prefix_attrs
));
1405 d
= error_mark_node
;
1406 start_init (d
, asm_name
, global_bindings_p ());
1407 init_loc
= c_parser_peek_token (parser
)->location
;
1408 init
= c_parser_initializer (parser
);
1410 if (d
!= error_mark_node
)
1412 maybe_warn_string_init (TREE_TYPE (d
), init
);
1413 finish_decl (d
, init_loc
, init
.value
,
1414 init
.original_type
, asm_name
);
1419 tree d
= start_decl (declarator
, specs
, false,
1420 chainon (postfix_attrs
,
1423 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1424 NULL_TREE
, asm_name
);
1426 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1428 c_parser_consume_token (parser
);
1429 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1430 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1433 all_prefix_attrs
= prefix_attrs
;
1436 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1438 c_parser_consume_token (parser
);
1443 c_parser_error (parser
, "expected %<,%> or %<;%>");
1444 c_parser_skip_to_end_of_block_or_statement (parser
);
1450 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1451 "%<asm%> or %<__attribute__%>");
1452 c_parser_skip_to_end_of_block_or_statement (parser
);
1455 /* Function definition (nested or otherwise). */
1458 pedwarn (here
, OPT_pedantic
, "ISO C forbids nested functions");
1459 c_push_function_context ();
1461 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1463 /* This can appear in many cases looking nothing like a
1464 function definition, so we don't give a more specific
1465 error suggesting there was one. */
1466 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1467 "or %<__attribute__%>");
1469 c_pop_function_context ();
1472 /* Parse old-style parameter declarations. ??? Attributes are
1473 not allowed to start declaration specifiers here because of a
1474 syntax conflict between a function declaration with attribute
1475 suffix and a function definition with an attribute prefix on
1476 first old-style parameter declaration. Following the old
1477 parser, they are not accepted on subsequent old-style
1478 parameter declarations either. However, there is no
1479 ambiguity after the first declaration, nor indeed on the
1480 first as long as we don't allow postfix attributes after a
1481 declarator with a nonempty identifier list in a definition;
1482 and postfix attributes have never been accepted here in
1483 function definitions either. */
1484 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1485 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1486 c_parser_declaration_or_fndef (parser
, false, false, false,
1488 store_parm_decls ();
1489 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1490 = c_parser_peek_token (parser
)->location
;
1491 fnbody
= c_parser_compound_statement (parser
);
1494 tree decl
= current_function_decl
;
1495 /* Mark nested functions as needing static-chain initially.
1496 lower_nested_functions will recompute it but the
1497 DECL_STATIC_CHAIN flag is also used before that happens,
1498 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1499 DECL_STATIC_CHAIN (decl
) = 1;
1502 c_pop_function_context ();
1503 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1514 /* Parse an asm-definition (asm() outside a function body). This is a
1522 c_parser_asm_definition (c_parser
*parser
)
1524 tree asm_str
= c_parser_simple_asm_expr (parser
);
1526 cgraph_add_asm_node (asm_str
);
1527 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1530 /* Parse a static assertion (C1X N1425 6.7.10).
1532 static_assert-declaration:
1533 static_assert-declaration-no-semi ;
1537 c_parser_static_assert_declaration (c_parser
*parser
)
1539 c_parser_static_assert_declaration_no_semi (parser
);
1541 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1542 c_parser_skip_to_end_of_block_or_statement (parser
);
1545 /* Parse a static assertion (C1X N1425 6.7.10), without the trailing
1548 static_assert-declaration-no-semi:
1549 _Static_assert ( constant-expression , string-literal )
1553 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1555 location_t assert_loc
, value_loc
;
1559 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1560 assert_loc
= c_parser_peek_token (parser
)->location
;
1564 pedwarn (assert_loc
, OPT_pedantic
,
1565 "ISO C99 does not support %<_Static_assert%>");
1567 pedwarn (assert_loc
, OPT_pedantic
,
1568 "ISO C90 does not support %<_Static_assert%>");
1570 c_parser_consume_token (parser
);
1571 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1573 value_loc
= c_parser_peek_token (parser
)->location
;
1574 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1575 parser
->lex_untranslated_string
= true;
1576 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1578 parser
->lex_untranslated_string
= false;
1581 switch (c_parser_peek_token (parser
)->type
)
1587 case CPP_UTF8STRING
:
1588 string
= c_parser_peek_token (parser
)->value
;
1589 c_parser_consume_token (parser
);
1590 parser
->lex_untranslated_string
= false;
1593 c_parser_error (parser
, "expected string literal");
1594 parser
->lex_untranslated_string
= false;
1597 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1599 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1601 error_at (value_loc
, "expression in static assertion is not an integer");
1604 if (TREE_CODE (value
) != INTEGER_CST
)
1606 value
= c_fully_fold (value
, false, NULL
);
1607 if (TREE_CODE (value
) == INTEGER_CST
)
1608 pedwarn (value_loc
, OPT_pedantic
, "expression in static assertion "
1609 "is not an integer constant expression");
1611 if (TREE_CODE (value
) != INTEGER_CST
)
1613 error_at (value_loc
, "expression in static assertion is not constant");
1616 constant_expression_warning (value
);
1617 if (integer_zerop (value
))
1618 error_at (assert_loc
, "static assertion failed: %E", string
);
1621 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1622 6.7), adding them to SPECS (which may already include some).
1623 Storage class specifiers are accepted iff SCSPEC_OK; type
1624 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1625 the start iff START_ATTR_OK.
1627 declaration-specifiers:
1628 storage-class-specifier declaration-specifiers[opt]
1629 type-specifier declaration-specifiers[opt]
1630 type-qualifier declaration-specifiers[opt]
1631 function-specifier declaration-specifiers[opt]
1633 Function specifiers (inline) are from C99, and are currently
1634 handled as storage class specifiers, as is __thread.
1636 C90 6.5.1, C99 6.7.1:
1637 storage-class-specifier:
1648 C90 6.5.2, C99 6.7.2:
1661 [_Imaginary removed in C99 TC2]
1662 struct-or-union-specifier
1666 (_Bool and _Complex are new in C99.)
1668 C90 6.5.3, C99 6.7.3:
1674 address-space-qualifier
1676 (restrict is new in C99.)
1680 declaration-specifiers:
1681 attributes declaration-specifiers[opt]
1687 identifier recognized by the target
1689 storage-class-specifier:
1702 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
1703 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
1708 class-name objc-protocol-refs[opt]
1709 typedef-name objc-protocol-refs
1714 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1715 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1717 bool attrs_ok
= start_attr_ok
;
1718 bool seen_type
= specs
->type_seen_p
;
1719 while (c_parser_next_token_is (parser
, CPP_NAME
)
1720 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1721 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1723 struct c_typespec t
;
1725 location_t loc
= c_parser_peek_token (parser
)->location
;
1726 if (c_parser_next_token_is (parser
, CPP_NAME
))
1728 tree value
= c_parser_peek_token (parser
)->value
;
1729 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1731 if (kind
== C_ID_ADDRSPACE
)
1734 = c_parser_peek_token (parser
)->keyword
- RID_FIRST_ADDR_SPACE
;
1735 declspecs_add_addrspace (specs
, as
);
1736 c_parser_consume_token (parser
);
1741 /* This finishes the specifiers unless a type name is OK, it
1742 is declared as a type name and a type name hasn't yet
1744 if (!typespec_ok
|| seen_type
1745 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1747 c_parser_consume_token (parser
);
1750 if (kind
== C_ID_TYPENAME
1751 && (!c_dialect_objc ()
1752 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1754 t
.kind
= ctsk_typedef
;
1755 /* For a typedef name, record the meaning, not the name.
1756 In case of 'foo foo, bar;'. */
1757 t
.spec
= lookup_name (value
);
1759 t
.expr_const_operands
= true;
1763 tree proto
= NULL_TREE
;
1764 gcc_assert (c_dialect_objc ());
1766 if (c_parser_next_token_is (parser
, CPP_LESS
))
1767 proto
= c_parser_objc_protocol_refs (parser
);
1768 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1770 t
.expr_const_operands
= true;
1772 declspecs_add_type (loc
, specs
, t
);
1775 if (c_parser_next_token_is (parser
, CPP_LESS
))
1777 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1778 nisse@lysator.liu.se. */
1780 gcc_assert (c_dialect_objc ());
1781 if (!typespec_ok
|| seen_type
)
1783 proto
= c_parser_objc_protocol_refs (parser
);
1785 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1787 t
.expr_const_operands
= true;
1788 declspecs_add_type (loc
, specs
, t
);
1791 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1792 switch (c_parser_peek_token (parser
)->keyword
)
1804 /* TODO: Distinguish between function specifiers (inline)
1805 and storage class specifiers, either here or in
1806 declspecs_add_scspec. */
1807 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1808 c_parser_consume_token (parser
);
1832 if (c_dialect_objc ())
1833 parser
->objc_need_raw_identifier
= true;
1834 t
.kind
= ctsk_resword
;
1835 t
.spec
= c_parser_peek_token (parser
)->value
;
1837 t
.expr_const_operands
= true;
1838 declspecs_add_type (loc
, specs
, t
);
1839 c_parser_consume_token (parser
);
1846 t
= c_parser_enum_specifier (parser
);
1847 declspecs_add_type (loc
, specs
, t
);
1855 t
= c_parser_struct_or_union_specifier (parser
);
1856 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
1857 declspecs_add_type (loc
, specs
, t
);
1860 /* ??? The old parser rejected typeof after other type
1861 specifiers, but is a syntax error the best way of
1863 if (!typespec_ok
|| seen_type
)
1867 t
= c_parser_typeof_specifier (parser
);
1868 declspecs_add_type (loc
, specs
, t
);
1874 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1875 c_parser_consume_token (parser
);
1880 attrs
= c_parser_attributes (parser
);
1881 declspecs_add_attrs (specs
, attrs
);
1890 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1893 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1894 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1895 enum attributes[opt] identifier
1897 The form with trailing comma is new in C99. The forms with
1898 attributes are GNU extensions. In GNU C, we accept any expression
1899 without commas in the syntax (assignment expressions, not just
1900 conditional expressions); assignment expressions will be diagnosed
1905 enumerator-list , enumerator
1908 enumeration-constant
1909 enumeration-constant = constant-expression
1912 static struct c_typespec
1913 c_parser_enum_specifier (c_parser
*parser
)
1915 struct c_typespec ret
;
1917 tree ident
= NULL_TREE
;
1918 location_t enum_loc
;
1919 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1920 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1921 enum_loc
= c_parser_peek_token (parser
)->location
;
1922 c_parser_consume_token (parser
);
1923 attrs
= c_parser_attributes (parser
);
1924 enum_loc
= c_parser_peek_token (parser
)->location
;
1925 /* Set the location in case we create a decl now. */
1926 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
1927 if (c_parser_next_token_is (parser
, CPP_NAME
))
1929 ident
= c_parser_peek_token (parser
)->value
;
1930 ident_loc
= c_parser_peek_token (parser
)->location
;
1931 enum_loc
= ident_loc
;
1932 c_parser_consume_token (parser
);
1934 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1936 /* Parse an enum definition. */
1937 struct c_enum_contents the_enum
;
1938 tree type
= start_enum (enum_loc
, &the_enum
, ident
);
1940 /* We chain the enumerators in reverse order, then put them in
1941 forward order at the end. */
1942 tree values
= NULL_TREE
;
1943 c_parser_consume_token (parser
);
1951 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
1952 location_t decl_loc
, value_loc
;
1953 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1955 c_parser_error (parser
, "expected identifier");
1956 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1957 values
= error_mark_node
;
1960 token
= c_parser_peek_token (parser
);
1961 enum_id
= token
->value
;
1962 /* Set the location in case we create a decl now. */
1963 c_parser_set_source_position_from_token (token
);
1964 decl_loc
= value_loc
= token
->location
;
1965 c_parser_consume_token (parser
);
1966 if (c_parser_next_token_is (parser
, CPP_EQ
))
1968 c_parser_consume_token (parser
);
1969 value_loc
= c_parser_peek_token (parser
)->location
;
1970 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1973 enum_value
= NULL_TREE
;
1974 enum_decl
= build_enumerator (decl_loc
, value_loc
,
1975 &the_enum
, enum_id
, enum_value
);
1976 TREE_CHAIN (enum_decl
) = values
;
1979 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1981 comma_loc
= c_parser_peek_token (parser
)->location
;
1983 c_parser_consume_token (parser
);
1985 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1987 if (seen_comma
&& !flag_isoc99
)
1988 pedwarn (comma_loc
, OPT_pedantic
, "comma at end of enumerator list");
1989 c_parser_consume_token (parser
);
1994 c_parser_error (parser
, "expected %<,%> or %<}%>");
1995 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1996 values
= error_mark_node
;
2000 postfix_attrs
= c_parser_attributes (parser
);
2001 ret
.spec
= finish_enum (type
, nreverse (values
),
2002 chainon (attrs
, postfix_attrs
));
2003 ret
.kind
= ctsk_tagdef
;
2004 ret
.expr
= NULL_TREE
;
2005 ret
.expr_const_operands
= true;
2010 c_parser_error (parser
, "expected %<{%>");
2011 ret
.spec
= error_mark_node
;
2012 ret
.kind
= ctsk_tagref
;
2013 ret
.expr
= NULL_TREE
;
2014 ret
.expr_const_operands
= true;
2017 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2018 /* In ISO C, enumerated types can be referred to only if already
2020 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2023 pedwarn (enum_loc
, OPT_pedantic
,
2024 "ISO C forbids forward references to %<enum%> types");
2029 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2031 struct-or-union-specifier:
2032 struct-or-union attributes[opt] identifier[opt]
2033 { struct-contents } attributes[opt]
2034 struct-or-union attributes[opt] identifier
2037 struct-declaration-list
2039 struct-declaration-list:
2040 struct-declaration ;
2041 struct-declaration-list struct-declaration ;
2048 struct-declaration-list struct-declaration
2050 struct-declaration-list:
2051 struct-declaration-list ;
2054 (Note that in the syntax here, unlike that in ISO C, the semicolons
2055 are included here rather than in struct-declaration, in order to
2056 describe the syntax with extra semicolons and missing semicolon at
2061 struct-declaration-list:
2062 @defs ( class-name )
2064 (Note this does not include a trailing semicolon, but can be
2065 followed by further declarations, and gets a pedwarn-if-pedantic
2066 when followed by a semicolon.) */
2068 static struct c_typespec
2069 c_parser_struct_or_union_specifier (c_parser
*parser
)
2071 struct c_typespec ret
;
2073 tree ident
= NULL_TREE
;
2074 location_t struct_loc
;
2075 location_t ident_loc
= UNKNOWN_LOCATION
;
2076 enum tree_code code
;
2077 switch (c_parser_peek_token (parser
)->keyword
)
2088 struct_loc
= c_parser_peek_token (parser
)->location
;
2089 c_parser_consume_token (parser
);
2090 attrs
= c_parser_attributes (parser
);
2092 /* Set the location in case we create a decl now. */
2093 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2095 if (c_parser_next_token_is (parser
, CPP_NAME
))
2097 ident
= c_parser_peek_token (parser
)->value
;
2098 ident_loc
= c_parser_peek_token (parser
)->location
;
2099 struct_loc
= ident_loc
;
2100 c_parser_consume_token (parser
);
2102 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2104 /* Parse a struct or union definition. Start the scope of the
2105 tag before parsing components. */
2106 struct c_struct_parse_info
*struct_info
;
2107 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2109 /* We chain the components in reverse order, then put them in
2110 forward order at the end. Each struct-declaration may
2111 declare multiple components (comma-separated), so we must use
2112 chainon to join them, although when parsing each
2113 struct-declaration we can use TREE_CHAIN directly.
2115 The theory behind all this is that there will be more
2116 semicolon separated fields than comma separated fields, and
2117 so we'll be minimizing the number of node traversals required
2119 tree contents
= NULL_TREE
;
2120 c_parser_consume_token (parser
);
2121 /* Handle the Objective-C @defs construct,
2122 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2123 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2126 gcc_assert (c_dialect_objc ());
2127 c_parser_consume_token (parser
);
2128 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2130 if (c_parser_next_token_is (parser
, CPP_NAME
)
2131 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2133 name
= c_parser_peek_token (parser
)->value
;
2134 c_parser_consume_token (parser
);
2138 c_parser_error (parser
, "expected class name");
2139 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2142 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2144 contents
= nreverse (objc_get_class_ivars (name
));
2147 /* Parse the struct-declarations and semicolons. Problems with
2148 semicolons are diagnosed here; empty structures are diagnosed
2153 /* Parse any stray semicolon. */
2154 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2156 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
2157 "extra semicolon in struct or union specified");
2158 c_parser_consume_token (parser
);
2161 /* Stop if at the end of the struct or union contents. */
2162 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2164 c_parser_consume_token (parser
);
2167 /* Accept #pragmas at struct scope. */
2168 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2170 c_parser_pragma (parser
, pragma_external
);
2173 /* Parse some comma-separated declarations, but not the
2174 trailing semicolon if any. */
2175 decls
= c_parser_struct_declaration (parser
);
2176 contents
= chainon (decls
, contents
);
2177 /* If no semicolon follows, either we have a parse error or
2178 are at the end of the struct or union and should
2180 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2181 c_parser_consume_token (parser
);
2184 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2185 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2186 "no semicolon at end of struct or union");
2189 c_parser_error (parser
, "expected %<;%>");
2190 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2195 postfix_attrs
= c_parser_attributes (parser
);
2196 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2197 chainon (attrs
, postfix_attrs
), struct_info
);
2198 ret
.kind
= ctsk_tagdef
;
2199 ret
.expr
= NULL_TREE
;
2200 ret
.expr_const_operands
= true;
2205 c_parser_error (parser
, "expected %<{%>");
2206 ret
.spec
= error_mark_node
;
2207 ret
.kind
= ctsk_tagref
;
2208 ret
.expr
= NULL_TREE
;
2209 ret
.expr_const_operands
= true;
2212 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2216 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2217 the trailing semicolon.
2220 specifier-qualifier-list struct-declarator-list
2221 static_assert-declaration-no-semi
2223 specifier-qualifier-list:
2224 type-specifier specifier-qualifier-list[opt]
2225 type-qualifier specifier-qualifier-list[opt]
2226 attributes specifier-qualifier-list[opt]
2228 struct-declarator-list:
2230 struct-declarator-list , attributes[opt] struct-declarator
2233 declarator attributes[opt]
2234 declarator[opt] : constant-expression attributes[opt]
2239 __extension__ struct-declaration
2240 specifier-qualifier-list
2242 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2243 of attributes where shown is a GNU extension. In GNU C, we accept
2244 any expression without commas in the syntax (assignment
2245 expressions, not just conditional expressions); assignment
2246 expressions will be diagnosed as non-constant. */
2249 c_parser_struct_declaration (c_parser
*parser
)
2251 struct c_declspecs
*specs
;
2253 tree all_prefix_attrs
;
2255 location_t decl_loc
;
2256 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2260 ext
= disable_extension_diagnostics ();
2261 c_parser_consume_token (parser
);
2262 decl
= c_parser_struct_declaration (parser
);
2263 restore_extension_diagnostics (ext
);
2266 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2268 c_parser_static_assert_declaration_no_semi (parser
);
2271 specs
= build_null_declspecs ();
2272 decl_loc
= c_parser_peek_token (parser
)->location
;
2273 c_parser_declspecs (parser
, specs
, false, true, true);
2276 if (!specs
->declspecs_seen_p
)
2278 c_parser_error (parser
, "expected specifier-qualifier-list");
2281 finish_declspecs (specs
);
2282 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2285 if (!specs
->type_seen_p
)
2287 pedwarn (decl_loc
, OPT_pedantic
,
2288 "ISO C forbids member declarations with no members");
2289 shadow_tag_warned (specs
, pedantic
);
2294 /* Support for unnamed structs or unions as members of
2295 structs or unions (which is [a] useful and [b] supports
2299 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2300 build_id_declarator (NULL_TREE
), specs
,
2303 decl_attributes (&ret
, attrs
, 0);
2307 pending_xref_error ();
2308 prefix_attrs
= specs
->attrs
;
2309 all_prefix_attrs
= prefix_attrs
;
2310 specs
->attrs
= NULL_TREE
;
2314 /* Declaring one or more declarators or un-named bit-fields. */
2315 struct c_declarator
*declarator
;
2317 if (c_parser_next_token_is (parser
, CPP_COLON
))
2318 declarator
= build_id_declarator (NULL_TREE
);
2320 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2321 C_DTR_NORMAL
, &dummy
);
2322 if (declarator
== NULL
)
2324 c_parser_skip_to_end_of_block_or_statement (parser
);
2327 if (c_parser_next_token_is (parser
, CPP_COLON
)
2328 || c_parser_next_token_is (parser
, CPP_COMMA
)
2329 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2330 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2331 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2333 tree postfix_attrs
= NULL_TREE
;
2334 tree width
= NULL_TREE
;
2336 if (c_parser_next_token_is (parser
, CPP_COLON
))
2338 c_parser_consume_token (parser
);
2339 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2341 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2342 postfix_attrs
= c_parser_attributes (parser
);
2343 d
= grokfield (c_parser_peek_token (parser
)->location
,
2344 declarator
, specs
, width
, &all_prefix_attrs
);
2345 decl_attributes (&d
, chainon (postfix_attrs
,
2346 all_prefix_attrs
), 0);
2347 DECL_CHAIN (d
) = decls
;
2349 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2350 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2353 all_prefix_attrs
= prefix_attrs
;
2354 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2355 c_parser_consume_token (parser
);
2356 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2357 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2359 /* Semicolon consumed in caller. */
2364 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2370 c_parser_error (parser
,
2371 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2372 "%<__attribute__%>");
2379 /* Parse a typeof specifier (a GNU extension).
2382 typeof ( expression )
2383 typeof ( type-name )
2386 static struct c_typespec
2387 c_parser_typeof_specifier (c_parser
*parser
)
2389 struct c_typespec ret
;
2390 ret
.kind
= ctsk_typeof
;
2391 ret
.spec
= error_mark_node
;
2392 ret
.expr
= NULL_TREE
;
2393 ret
.expr_const_operands
= true;
2394 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2395 c_parser_consume_token (parser
);
2396 c_inhibit_evaluation_warnings
++;
2398 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2400 c_inhibit_evaluation_warnings
--;
2404 if (c_parser_next_token_starts_typename (parser
))
2406 struct c_type_name
*type
= c_parser_type_name (parser
);
2407 c_inhibit_evaluation_warnings
--;
2411 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2412 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2418 location_t here
= c_parser_peek_token (parser
)->location
;
2419 struct c_expr expr
= c_parser_expression (parser
);
2420 c_inhibit_evaluation_warnings
--;
2422 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2423 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2424 error_at (here
, "%<typeof%> applied to a bit-field");
2425 mark_exp_read (expr
.value
);
2426 ret
.spec
= TREE_TYPE (expr
.value
);
2427 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2428 /* This is returned with the type so that when the type is
2429 evaluated, this can be evaluated. */
2431 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2432 pop_maybe_used (was_vm
);
2434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2438 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2439 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2440 be redeclared; otherwise it may not. KIND indicates which kind of
2441 declarator is wanted. Returns a valid declarator except in the
2442 case of a syntax error in which case NULL is returned. *SEEN_ID is
2443 set to true if an identifier being declared is seen; this is used
2444 to diagnose bad forms of abstract array declarators and to
2445 determine whether an identifier list is syntactically permitted.
2448 pointer[opt] direct-declarator
2452 ( attributes[opt] declarator )
2453 direct-declarator array-declarator
2454 direct-declarator ( parameter-type-list )
2455 direct-declarator ( identifier-list[opt] )
2458 * type-qualifier-list[opt]
2459 * type-qualifier-list[opt] pointer
2461 type-qualifier-list:
2464 type-qualifier-list type-qualifier
2465 type-qualifier-list attributes
2467 parameter-type-list:
2469 parameter-list , ...
2472 parameter-declaration
2473 parameter-list , parameter-declaration
2475 parameter-declaration:
2476 declaration-specifiers declarator attributes[opt]
2477 declaration-specifiers abstract-declarator[opt] attributes[opt]
2481 identifier-list , identifier
2483 abstract-declarator:
2485 pointer[opt] direct-abstract-declarator
2487 direct-abstract-declarator:
2488 ( attributes[opt] abstract-declarator )
2489 direct-abstract-declarator[opt] array-declarator
2490 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2495 direct-declarator ( parameter-forward-declarations
2496 parameter-type-list[opt] )
2498 direct-abstract-declarator:
2499 direct-abstract-declarator[opt] ( parameter-forward-declarations
2500 parameter-type-list[opt] )
2502 parameter-forward-declarations:
2504 parameter-forward-declarations parameter-list ;
2506 The uses of attributes shown above are GNU extensions.
2508 Some forms of array declarator are not included in C99 in the
2509 syntax for abstract declarators; these are disallowed elsewhere.
2510 This may be a defect (DR#289).
2512 This function also accepts an omitted abstract declarator as being
2513 an abstract declarator, although not part of the formal syntax. */
2515 static struct c_declarator
*
2516 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2519 /* Parse any initial pointer part. */
2520 if (c_parser_next_token_is (parser
, CPP_MULT
))
2522 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2523 struct c_declarator
*inner
;
2524 c_parser_consume_token (parser
);
2525 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2526 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2530 return make_pointer_declarator (quals_attrs
, inner
);
2532 /* Now we have a direct declarator, direct abstract declarator or
2533 nothing (which counts as a direct abstract declarator here). */
2534 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2537 /* Parse a direct declarator or direct abstract declarator; arguments
2538 as c_parser_declarator. */
2540 static struct c_declarator
*
2541 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2544 /* The direct declarator must start with an identifier (possibly
2545 omitted) or a parenthesized declarator (possibly abstract). In
2546 an ordinary declarator, initial parentheses must start a
2547 parenthesized declarator. In an abstract declarator or parameter
2548 declarator, they could start a parenthesized declarator or a
2549 parameter list. To tell which, the open parenthesis and any
2550 following attributes must be read. If a declaration specifier
2551 follows, then it is a parameter list; if the specifier is a
2552 typedef name, there might be an ambiguity about redeclaring it,
2553 which is resolved in the direction of treating it as a typedef
2554 name. If a close parenthesis follows, it is also an empty
2555 parameter list, as the syntax does not permit empty abstract
2556 declarators. Otherwise, it is a parenthesized declarator (in
2557 which case the analysis may be repeated inside it, recursively).
2559 ??? There is an ambiguity in a parameter declaration "int
2560 (__attribute__((foo)) x)", where x is not a typedef name: it
2561 could be an abstract declarator for a function, or declare x with
2562 parentheses. The proper resolution of this ambiguity needs
2563 documenting. At present we follow an accident of the old
2564 parser's implementation, whereby the first parameter must have
2565 some declaration specifiers other than just attributes. Thus as
2566 a parameter declaration it is treated as a parenthesized
2567 parameter named x, and as an abstract declarator it is
2570 ??? Also following the old parser, attributes inside an empty
2571 parameter list are ignored, making it a list not yielding a
2572 prototype, rather than giving an error or making it have one
2573 parameter with implicit type int.
2575 ??? Also following the old parser, typedef names may be
2576 redeclared in declarators, but not Objective-C class names. */
2578 if (kind
!= C_DTR_ABSTRACT
2579 && c_parser_next_token_is (parser
, CPP_NAME
)
2581 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2582 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2583 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2585 struct c_declarator
*inner
2586 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2588 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2589 c_parser_consume_token (parser
);
2590 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2593 if (kind
!= C_DTR_NORMAL
2594 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2596 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2597 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2600 /* Either we are at the end of an abstract declarator, or we have
2603 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2606 struct c_declarator
*inner
;
2607 c_parser_consume_token (parser
);
2608 attrs
= c_parser_attributes (parser
);
2609 if (kind
!= C_DTR_NORMAL
2610 && (c_parser_next_token_starts_declspecs (parser
)
2611 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2613 struct c_arg_info
*args
2614 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2621 = build_function_declarator (args
,
2622 build_id_declarator (NULL_TREE
));
2623 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2627 /* A parenthesized declarator. */
2628 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2629 if (inner
!= NULL
&& attrs
!= NULL
)
2630 inner
= build_attrs_declarator (attrs
, inner
);
2631 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2633 c_parser_consume_token (parser
);
2637 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2641 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2648 if (kind
== C_DTR_NORMAL
)
2650 c_parser_error (parser
, "expected identifier or %<(%>");
2654 return build_id_declarator (NULL_TREE
);
2658 /* Parse part of a direct declarator or direct abstract declarator,
2659 given that some (in INNER) has already been parsed; ID_PRESENT is
2660 true if an identifier is present, false for an abstract
2663 static struct c_declarator
*
2664 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2665 struct c_declarator
*inner
)
2667 /* Parse a sequence of array declarators and parameter lists. */
2668 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2670 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
2671 struct c_declarator
*declarator
;
2672 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2676 c_parser_consume_token (parser
);
2677 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2678 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2680 c_parser_consume_token (parser
);
2681 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2682 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2683 if (!quals_attrs
->declspecs_seen_p
)
2685 /* If "static" is present, there must be an array dimension.
2686 Otherwise, there may be a dimension, "*", or no
2691 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2695 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2700 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2702 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2706 c_parser_consume_token (parser
);
2711 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2717 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2720 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2721 c_parser_consume_token (parser
);
2724 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2729 mark_exp_read (dimen
);
2730 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
2731 static_seen
, star_seen
);
2732 if (declarator
== NULL
)
2734 inner
= set_array_declarator_inner (declarator
, inner
);
2735 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2737 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2740 struct c_arg_info
*args
;
2741 c_parser_consume_token (parser
);
2742 attrs
= c_parser_attributes (parser
);
2743 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2748 inner
= build_function_declarator (args
, inner
);
2749 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2755 /* Parse a parameter list or identifier list, including the closing
2756 parenthesis but not the opening one. ATTRS are the attributes at
2757 the start of the list. ID_LIST_OK is true if an identifier list is
2758 acceptable; such a list must not have attributes at the start. */
2760 static struct c_arg_info
*
2761 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2764 declare_parm_level ();
2765 /* If the list starts with an identifier, it is an identifier list.
2766 Otherwise, it is either a prototype list or an empty list. */
2769 && c_parser_next_token_is (parser
, CPP_NAME
)
2770 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2772 tree list
= NULL_TREE
, *nextp
= &list
;
2773 while (c_parser_next_token_is (parser
, CPP_NAME
)
2774 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2776 *nextp
= build_tree_list (NULL_TREE
,
2777 c_parser_peek_token (parser
)->value
);
2778 nextp
= & TREE_CHAIN (*nextp
);
2779 c_parser_consume_token (parser
);
2780 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2782 c_parser_consume_token (parser
);
2783 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2785 c_parser_error (parser
, "expected identifier");
2789 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2791 struct c_arg_info
*ret
= build_arg_info ();
2793 c_parser_consume_token (parser
);
2799 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2807 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2813 /* Parse a parameter list (possibly empty), including the closing
2814 parenthesis but not the opening one. ATTRS are the attributes at
2815 the start of the list. */
2817 static struct c_arg_info
*
2818 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2820 bool bad_parm
= false;
2821 /* ??? Following the old parser, forward parameter declarations may
2822 use abstract declarators, and if no real parameter declarations
2823 follow the forward declarations then this is not diagnosed. Also
2824 note as above that attributes are ignored as the only contents of
2825 the parentheses, or as the only contents after forward
2827 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2829 struct c_arg_info
*ret
= build_arg_info ();
2830 c_parser_consume_token (parser
);
2833 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2835 struct c_arg_info
*ret
= build_arg_info ();
2836 /* Suppress -Wold-style-definition for this case. */
2837 ret
->types
= error_mark_node
;
2838 error_at (c_parser_peek_token (parser
)->location
,
2839 "ISO C requires a named argument before %<...%>");
2840 c_parser_consume_token (parser
);
2841 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2843 c_parser_consume_token (parser
);
2848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2853 /* Nonempty list of parameters, either terminated with semicolon
2854 (forward declarations; recurse) or with close parenthesis (normal
2855 function) or with ", ... )" (variadic function). */
2858 /* Parse a parameter. */
2859 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2864 push_parm_decl (parm
);
2865 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2868 c_parser_consume_token (parser
);
2869 mark_forward_parm_decls ();
2870 new_attrs
= c_parser_attributes (parser
);
2871 return c_parser_parms_list_declarator (parser
, new_attrs
);
2873 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2875 c_parser_consume_token (parser
);
2878 get_pending_sizes ();
2882 return get_parm_info (false);
2884 if (!c_parser_require (parser
, CPP_COMMA
,
2885 "expected %<;%>, %<,%> or %<)%>"))
2887 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2888 get_pending_sizes ();
2891 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2893 c_parser_consume_token (parser
);
2894 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2896 c_parser_consume_token (parser
);
2899 get_pending_sizes ();
2903 return get_parm_info (true);
2907 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2909 get_pending_sizes ();
2916 /* Parse a parameter declaration. ATTRS are the attributes at the
2917 start of the declaration if it is the first parameter. */
2919 static struct c_parm
*
2920 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2922 struct c_declspecs
*specs
;
2923 struct c_declarator
*declarator
;
2925 tree postfix_attrs
= NULL_TREE
;
2927 if (!c_parser_next_token_starts_declspecs (parser
))
2929 c_token
*token
= c_parser_peek_token (parser
);
2932 c_parser_set_source_position_from_token (token
);
2933 if (token
->type
== CPP_NAME
2934 && c_parser_peek_2nd_token (parser
)->type
!= CPP_COMMA
2935 && c_parser_peek_2nd_token (parser
)->type
!= CPP_CLOSE_PAREN
)
2937 error ("unknown type name %qE", token
->value
);
2938 parser
->error
= true;
2940 /* ??? In some Objective-C cases '...' isn't applicable so there
2941 should be a different message. */
2943 c_parser_error (parser
,
2944 "expected declaration specifiers or %<...%>");
2945 c_parser_skip_to_end_of_parameter (parser
);
2948 specs
= build_null_declspecs ();
2951 declspecs_add_attrs (specs
, attrs
);
2954 c_parser_declspecs (parser
, specs
, true, true, true);
2955 finish_declspecs (specs
);
2956 pending_xref_error ();
2957 prefix_attrs
= specs
->attrs
;
2958 specs
->attrs
= NULL_TREE
;
2959 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2960 C_DTR_PARM
, &dummy
);
2961 if (declarator
== NULL
)
2963 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2966 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2967 postfix_attrs
= c_parser_attributes (parser
);
2968 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2972 /* Parse a string literal in an asm expression. It should not be
2973 translated, and wide string literals are an error although
2974 permitted by the syntax. This is a GNU extension.
2979 ??? At present, following the old parser, the caller needs to have
2980 set lex_untranslated_string to 1. It would be better to follow the
2981 C++ parser rather than using this kludge. */
2984 c_parser_asm_string_literal (c_parser
*parser
)
2987 if (c_parser_next_token_is (parser
, CPP_STRING
))
2989 str
= c_parser_peek_token (parser
)->value
;
2990 c_parser_consume_token (parser
);
2992 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2994 error_at (c_parser_peek_token (parser
)->location
,
2995 "wide string literal in %<asm%>");
2996 str
= build_string (1, "");
2997 c_parser_consume_token (parser
);
3001 c_parser_error (parser
, "expected string literal");
3007 /* Parse a simple asm expression. This is used in restricted
3008 contexts, where a full expression with inputs and outputs does not
3009 make sense. This is a GNU extension.
3012 asm ( asm-string-literal )
3016 c_parser_simple_asm_expr (c_parser
*parser
)
3019 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3020 /* ??? Follow the C++ parser rather than using the
3021 lex_untranslated_string kludge. */
3022 parser
->lex_untranslated_string
= true;
3023 c_parser_consume_token (parser
);
3024 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3026 parser
->lex_untranslated_string
= false;
3029 str
= c_parser_asm_string_literal (parser
);
3030 parser
->lex_untranslated_string
= false;
3031 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3033 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3039 /* Parse (possibly empty) attributes. This is a GNU extension.
3043 attributes attribute
3046 __attribute__ ( ( attribute-list ) )
3050 attribute_list , attrib
3055 any-word ( identifier )
3056 any-word ( identifier , nonempty-expr-list )
3057 any-word ( expr-list )
3059 where the "identifier" must not be declared as a type, and
3060 "any-word" may be any identifier (including one declared as a
3061 type), a reserved word storage class specifier, type specifier or
3062 type qualifier. ??? This still leaves out most reserved keywords
3063 (following the old parser), shouldn't we include them, and why not
3064 allow identifiers declared as types to start the arguments? */
3067 c_parser_attributes (c_parser
*parser
)
3069 tree attrs
= NULL_TREE
;
3070 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3072 /* ??? Follow the C++ parser rather than using the
3073 lex_untranslated_string kludge. */
3074 parser
->lex_untranslated_string
= true;
3075 c_parser_consume_token (parser
);
3076 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3078 parser
->lex_untranslated_string
= false;
3081 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3083 parser
->lex_untranslated_string
= false;
3084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3087 /* Parse the attribute list. */
3088 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3089 || c_parser_next_token_is (parser
, CPP_NAME
)
3090 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3092 tree attr
, attr_name
, attr_args
;
3093 VEC(tree
,gc
) *expr_list
;
3094 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3096 c_parser_consume_token (parser
);
3099 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3101 /* ??? See comment above about what keywords are
3104 switch (c_parser_peek_token (parser
)->keyword
)
3142 /* Accept __attribute__((__const)) as __attribute__((const))
3145 = ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3148 attr_name
= c_parser_peek_token (parser
)->value
;
3149 c_parser_consume_token (parser
);
3150 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3152 attr
= build_tree_list (attr_name
, NULL_TREE
);
3153 attrs
= chainon (attrs
, attr
);
3156 c_parser_consume_token (parser
);
3157 /* Parse the attribute contents. If they start with an
3158 identifier which is followed by a comma or close
3159 parenthesis, then the arguments start with that
3160 identifier; otherwise they are an expression list. */
3161 if (c_parser_next_token_is (parser
, CPP_NAME
)
3162 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3163 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3164 || (c_parser_peek_2nd_token (parser
)->type
3165 == CPP_CLOSE_PAREN
)))
3167 tree arg1
= c_parser_peek_token (parser
)->value
;
3168 c_parser_consume_token (parser
);
3169 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3170 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3174 c_parser_consume_token (parser
);
3175 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3176 tree_list
= build_tree_list_vec (expr_list
);
3177 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3178 release_tree_vector (expr_list
);
3183 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3184 attr_args
= NULL_TREE
;
3187 expr_list
= c_parser_expr_list (parser
, false, true, NULL
);
3188 attr_args
= build_tree_list_vec (expr_list
);
3189 release_tree_vector (expr_list
);
3192 attr
= build_tree_list (attr_name
, attr_args
);
3193 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3194 c_parser_consume_token (parser
);
3197 parser
->lex_untranslated_string
= false;
3198 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3202 attrs
= chainon (attrs
, attr
);
3204 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3205 c_parser_consume_token (parser
);
3208 parser
->lex_untranslated_string
= false;
3209 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3213 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3214 c_parser_consume_token (parser
);
3217 parser
->lex_untranslated_string
= false;
3218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3222 parser
->lex_untranslated_string
= false;
3227 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3230 specifier-qualifier-list abstract-declarator[opt]
3233 static struct c_type_name
*
3234 c_parser_type_name (c_parser
*parser
)
3236 struct c_declspecs
*specs
= build_null_declspecs ();
3237 struct c_declarator
*declarator
;
3238 struct c_type_name
*ret
;
3240 c_parser_declspecs (parser
, specs
, false, true, true);
3241 if (!specs
->declspecs_seen_p
)
3243 c_parser_error (parser
, "expected specifier-qualifier-list");
3246 pending_xref_error ();
3247 finish_declspecs (specs
);
3248 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
3249 C_DTR_ABSTRACT
, &dummy
);
3250 if (declarator
== NULL
)
3252 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3254 ret
->declarator
= declarator
;
3258 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3261 assignment-expression
3262 { initializer-list }
3263 { initializer-list , }
3266 designation[opt] initializer
3267 initializer-list , designation[opt] initializer
3274 designator-list designator
3281 [ constant-expression ]
3293 [ constant-expression ... constant-expression ]
3295 Any expression without commas is accepted in the syntax for the
3296 constant-expressions, with non-constant expressions rejected later.
3298 This function is only used for top-level initializers; for nested
3299 ones, see c_parser_initval. */
3301 static struct c_expr
3302 c_parser_initializer (c_parser
*parser
)
3304 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3305 return c_parser_braced_init (parser
, NULL_TREE
, false);
3309 location_t loc
= c_parser_peek_token (parser
)->location
;
3310 ret
= c_parser_expr_no_commas (parser
, NULL
);
3311 if (TREE_CODE (ret
.value
) != STRING_CST
3312 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3313 ret
= default_function_array_read_conversion (loc
, ret
);
3318 /* Parse a braced initializer list. TYPE is the type specified for a
3319 compound literal, and NULL_TREE for other initializers and for
3320 nested braced lists. NESTED_P is true for nested braced lists,
3321 false for the list of a compound literal or the list that is the
3322 top-level initializer in a declaration. */
3324 static struct c_expr
3325 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3328 struct obstack braced_init_obstack
;
3329 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3330 gcc_obstack_init (&braced_init_obstack
);
3331 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3332 c_parser_consume_token (parser
);
3334 push_init_level (0, &braced_init_obstack
);
3336 really_start_incremental_init (type
);
3337 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3339 pedwarn (brace_loc
, OPT_pedantic
, "ISO C forbids empty initializer braces");
3343 /* Parse a non-empty initializer list, possibly with a trailing
3347 c_parser_initelt (parser
, &braced_init_obstack
);
3350 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3351 c_parser_consume_token (parser
);
3354 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3358 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3360 ret
.value
= error_mark_node
;
3361 ret
.original_code
= ERROR_MARK
;
3362 ret
.original_type
= NULL
;
3363 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3364 pop_init_level (0, &braced_init_obstack
);
3365 obstack_free (&braced_init_obstack
, NULL
);
3368 c_parser_consume_token (parser
);
3369 ret
= pop_init_level (0, &braced_init_obstack
);
3370 obstack_free (&braced_init_obstack
, NULL
);
3374 /* Parse a nested initializer, including designators. */
3377 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3379 /* Parse any designator or designator list. A single array
3380 designator may have the subsequent "=" omitted in GNU C, but a
3381 longer list or a structure member designator may not. */
3382 if (c_parser_next_token_is (parser
, CPP_NAME
)
3383 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3385 /* Old-style structure member designator. */
3386 set_init_label (c_parser_peek_token (parser
)->value
,
3387 braced_init_obstack
);
3388 /* Use the colon as the error location. */
3389 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_pedantic
,
3390 "obsolete use of designated initializer with %<:%>");
3391 c_parser_consume_token (parser
);
3392 c_parser_consume_token (parser
);
3396 /* des_seen is 0 if there have been no designators, 1 if there
3397 has been a single array designator and 2 otherwise. */
3399 /* Location of a designator. */
3400 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3401 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3402 || c_parser_next_token_is (parser
, CPP_DOT
))
3404 int des_prev
= des_seen
;
3406 des_loc
= c_parser_peek_token (parser
)->location
;
3409 if (c_parser_next_token_is (parser
, CPP_DOT
))
3412 c_parser_consume_token (parser
);
3413 if (c_parser_next_token_is (parser
, CPP_NAME
))
3415 set_init_label (c_parser_peek_token (parser
)->value
,
3416 braced_init_obstack
);
3417 c_parser_consume_token (parser
);
3422 init
.value
= error_mark_node
;
3423 init
.original_code
= ERROR_MARK
;
3424 init
.original_type
= NULL
;
3425 c_parser_error (parser
, "expected identifier");
3426 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3427 process_init_element (init
, false, braced_init_obstack
);
3434 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3435 /* ??? Following the old parser, [ objc-receiver
3436 objc-message-args ] is accepted as an initializer,
3437 being distinguished from a designator by what follows
3438 the first assignment expression inside the square
3439 brackets, but after a first array designator a
3440 subsequent square bracket is for Objective-C taken to
3441 start an expression, using the obsolete form of
3442 designated initializer without '=', rather than
3443 possibly being a second level of designation: in LALR
3444 terms, the '[' is shifted rather than reducing
3445 designator to designator-list. */
3446 if (des_prev
== 1 && c_dialect_objc ())
3448 des_seen
= des_prev
;
3451 if (des_prev
== 0 && c_dialect_objc ())
3453 /* This might be an array designator or an
3454 Objective-C message expression. If the former,
3455 continue parsing here; if the latter, parse the
3456 remainder of the initializer given the starting
3457 primary-expression. ??? It might make sense to
3458 distinguish when des_prev == 1 as well; see
3459 previous comment. */
3461 struct c_expr mexpr
;
3462 c_parser_consume_token (parser
);
3463 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3464 && ((c_parser_peek_token (parser
)->id_kind
3466 || (c_parser_peek_token (parser
)->id_kind
3467 == C_ID_CLASSNAME
)))
3469 /* Type name receiver. */
3470 tree id
= c_parser_peek_token (parser
)->value
;
3471 c_parser_consume_token (parser
);
3472 rec
= objc_get_class_reference (id
);
3473 goto parse_message_args
;
3475 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3476 mark_exp_read (first
);
3477 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3478 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3479 goto array_desig_after_first
;
3480 /* Expression receiver. So far only one part
3481 without commas has been parsed; there might be
3482 more of the expression. */
3484 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3487 location_t comma_loc
, exp_loc
;
3488 comma_loc
= c_parser_peek_token (parser
)->location
;
3489 c_parser_consume_token (parser
);
3490 exp_loc
= c_parser_peek_token (parser
)->location
;
3491 next
= c_parser_expr_no_commas (parser
, NULL
);
3492 next
= default_function_array_read_conversion (exp_loc
,
3494 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3497 /* Now parse the objc-message-args. */
3498 args
= c_parser_objc_message_args (parser
);
3499 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3502 = objc_build_message_expr (build_tree_list (rec
, args
));
3503 mexpr
.original_code
= ERROR_MARK
;
3504 mexpr
.original_type
= NULL
;
3505 /* Now parse and process the remainder of the
3506 initializer, starting with this message
3507 expression as a primary-expression. */
3508 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3511 c_parser_consume_token (parser
);
3512 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3513 mark_exp_read (first
);
3514 array_desig_after_first
:
3515 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3517 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3518 c_parser_consume_token (parser
);
3519 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3520 mark_exp_read (second
);
3524 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3526 c_parser_consume_token (parser
);
3527 set_init_index (first
, second
, braced_init_obstack
);
3529 pedwarn (ellipsis_loc
, OPT_pedantic
,
3530 "ISO C forbids specifying range of elements to initialize");
3533 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3539 if (c_parser_next_token_is (parser
, CPP_EQ
))
3542 pedwarn (des_loc
, OPT_pedantic
,
3543 "ISO C90 forbids specifying subobject to initialize");
3544 c_parser_consume_token (parser
);
3549 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
3550 "obsolete use of designated initializer without %<=%>");
3554 init
.value
= error_mark_node
;
3555 init
.original_code
= ERROR_MARK
;
3556 init
.original_type
= NULL
;
3557 c_parser_error (parser
, "expected %<=%>");
3558 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3559 process_init_element (init
, false, braced_init_obstack
);
3565 c_parser_initval (parser
, NULL
, braced_init_obstack
);
3568 /* Parse a nested initializer; as c_parser_initializer but parses
3569 initializers within braced lists, after any designators have been
3570 applied. If AFTER is not NULL then it is an Objective-C message
3571 expression which is the primary-expression starting the
3575 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
3576 struct obstack
* braced_init_obstack
)
3579 gcc_assert (!after
|| c_dialect_objc ());
3580 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3581 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3584 location_t loc
= c_parser_peek_token (parser
)->location
;
3585 init
= c_parser_expr_no_commas (parser
, after
);
3586 if (init
.value
!= NULL_TREE
3587 && TREE_CODE (init
.value
) != STRING_CST
3588 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3589 init
= default_function_array_read_conversion (loc
, init
);
3591 process_init_element (init
, false, braced_init_obstack
);
3594 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3598 { block-item-list[opt] }
3599 { label-declarations block-item-list }
3603 block-item-list block-item
3615 { label-declarations block-item-list }
3618 __extension__ nested-declaration
3619 nested-function-definition
3623 label-declarations label-declaration
3626 __label__ identifier-list ;
3628 Allowing the mixing of declarations and code is new in C99. The
3629 GNU syntax also permits (not shown above) labels at the end of
3630 compound statements, which yield an error. We don't allow labels
3631 on declarations; this might seem like a natural extension, but
3632 there would be a conflict between attributes on the label and
3633 prefix attributes on the declaration. ??? The syntax follows the
3634 old parser in requiring something after label declarations.
3635 Although they are erroneous if the labels declared aren't defined,
3636 is it useful for the syntax to be this way?
3648 c_parser_compound_statement (c_parser
*parser
)
3651 location_t brace_loc
;
3652 brace_loc
= c_parser_peek_token (parser
)->location
;
3653 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3655 /* Ensure a scope is entered and left anyway to avoid confusion
3656 if we have just prepared to enter a function body. */
3657 stmt
= c_begin_compound_stmt (true);
3658 c_end_compound_stmt (brace_loc
, stmt
, true);
3659 return error_mark_node
;
3661 stmt
= c_begin_compound_stmt (true);
3662 c_parser_compound_statement_nostart (parser
);
3663 return c_end_compound_stmt (brace_loc
, stmt
, true);
3666 /* Parse a compound statement except for the opening brace. This is
3667 used for parsing both compound statements and statement expressions
3668 (which follow different paths to handling the opening). */
3671 c_parser_compound_statement_nostart (c_parser
*parser
)
3673 bool last_stmt
= false;
3674 bool last_label
= false;
3675 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
3676 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3677 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3679 c_parser_consume_token (parser
);
3682 mark_valid_location_for_stdc_pragma (true);
3683 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3685 /* Read zero or more forward-declarations for labels that nested
3686 functions can jump to. */
3687 mark_valid_location_for_stdc_pragma (false);
3688 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3690 label_loc
= c_parser_peek_token (parser
)->location
;
3691 c_parser_consume_token (parser
);
3692 /* Any identifiers, including those declared as type names,
3697 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3699 c_parser_error (parser
, "expected identifier");
3703 = declare_label (c_parser_peek_token (parser
)->value
);
3704 C_DECLARED_LABEL_FLAG (label
) = 1;
3705 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
3706 c_parser_consume_token (parser
);
3707 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3708 c_parser_consume_token (parser
);
3712 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3714 pedwarn (label_loc
, OPT_pedantic
, "ISO C forbids label declarations");
3716 /* We must now have at least one statement, label or declaration. */
3717 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3719 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3720 c_parser_error (parser
, "expected declaration or statement");
3721 c_parser_consume_token (parser
);
3724 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3726 location_t loc
= c_parser_peek_token (parser
)->location
;
3727 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3728 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3729 || (c_parser_next_token_is (parser
, CPP_NAME
)
3730 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3732 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3733 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
3735 label_loc
= c_parser_peek_token (parser
)->location
;
3738 mark_valid_location_for_stdc_pragma (false);
3739 c_parser_label (parser
);
3741 else if (!last_label
3742 && c_parser_next_token_starts_declaration (parser
))
3745 mark_valid_location_for_stdc_pragma (false);
3746 c_parser_declaration_or_fndef (parser
, true, true, true, true, true);
3749 (pedantic
&& !flag_isoc99
)
3751 : OPT_Wdeclaration_after_statement
,
3752 "ISO C90 forbids mixed declarations and code");
3755 else if (!last_label
3756 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3758 /* __extension__ can start a declaration, but is also an
3759 unary operator that can start an expression. Consume all
3760 but the last of a possible series of __extension__ to
3762 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3763 && (c_parser_peek_2nd_token (parser
)->keyword
3765 c_parser_consume_token (parser
);
3766 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
3769 ext
= disable_extension_diagnostics ();
3770 c_parser_consume_token (parser
);
3772 mark_valid_location_for_stdc_pragma (false);
3773 c_parser_declaration_or_fndef (parser
, true, true, true, true,
3775 /* Following the old parser, __extension__ does not
3776 disable this diagnostic. */
3777 restore_extension_diagnostics (ext
);
3779 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
3781 : OPT_Wdeclaration_after_statement
,
3782 "ISO C90 forbids mixed declarations and code");
3788 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3790 /* External pragmas, and some omp pragmas, are not associated
3791 with regular c code, and so are not to be considered statements
3792 syntactically. This ensures that the user doesn't put them
3793 places that would turn into syntax errors if the directive
3795 if (c_parser_pragma (parser
, pragma_compound
))
3796 last_label
= false, last_stmt
= true;
3798 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3800 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3801 c_parser_error (parser
, "expected declaration or statement");
3804 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3806 if (parser
->in_if_block
)
3808 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3809 error_at (loc
, """expected %<}%> before %<else%>");
3814 error_at (loc
, "%<else%> without a previous %<if%>");
3815 c_parser_consume_token (parser
);
3824 mark_valid_location_for_stdc_pragma (false);
3825 c_parser_statement_after_labels (parser
);
3828 parser
->error
= false;
3831 error_at (label_loc
, "label at end of compound statement");
3832 c_parser_consume_token (parser
);
3833 /* Restore the value we started with. */
3834 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
3837 /* Parse a label (C90 6.6.1, C99 6.8.1).
3840 identifier : attributes[opt]
3841 case constant-expression :
3847 case constant-expression ... constant-expression :
3849 The use of attributes on labels is a GNU extension. The syntax in
3850 GNU C accepts any expressions without commas, non-constant
3851 expressions being rejected later. */
3854 c_parser_label (c_parser
*parser
)
3856 location_t loc1
= c_parser_peek_token (parser
)->location
;
3857 tree label
= NULL_TREE
;
3858 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3861 c_parser_consume_token (parser
);
3862 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3863 if (c_parser_next_token_is (parser
, CPP_COLON
))
3865 c_parser_consume_token (parser
);
3866 label
= do_case (loc1
, exp1
, NULL_TREE
);
3868 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3870 c_parser_consume_token (parser
);
3871 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3872 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3873 label
= do_case (loc1
, exp1
, exp2
);
3876 c_parser_error (parser
, "expected %<:%> or %<...%>");
3878 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3880 c_parser_consume_token (parser
);
3881 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3882 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
3886 tree name
= c_parser_peek_token (parser
)->value
;
3889 location_t loc2
= c_parser_peek_token (parser
)->location
;
3890 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3891 c_parser_consume_token (parser
);
3892 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3893 c_parser_consume_token (parser
);
3894 attrs
= c_parser_attributes (parser
);
3895 tlab
= define_label (loc2
, name
);
3898 decl_attributes (&tlab
, attrs
, 0);
3899 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
3904 if (c_parser_next_token_starts_declaration (parser
)
3905 && !(c_parser_next_token_is (parser
, CPP_NAME
)
3906 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3908 error_at (c_parser_peek_token (parser
)->location
,
3909 "a label can only be part of a statement and "
3910 "a declaration is not a statement");
3911 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
3912 /*static_assert_ok*/ true,
3913 /*nested*/ true, /*empty_ok*/ false,
3914 /*start_attr_ok*/ true);
3919 /* Parse a statement (C90 6.6, C99 6.8).
3924 expression-statement
3932 expression-statement:
3935 selection-statement:
3939 iteration-statement:
3948 return expression[opt] ;
3961 objc-throw-statement
3962 objc-try-catch-statement
3963 objc-synchronized-statement
3965 objc-throw-statement:
3979 parallel-for-construct
3980 parallel-sections-construct
3987 parallel-directive structured-block
3990 for-directive iteration-statement
3993 sections-directive section-scope
3996 single-directive structured-block
3998 parallel-for-construct:
3999 parallel-for-directive iteration-statement
4001 parallel-sections-construct:
4002 parallel-sections-directive section-scope
4005 master-directive structured-block
4008 critical-directive structured-block
4011 atomic-directive expression-statement
4014 ordered-directive structured-block */
4017 c_parser_statement (c_parser
*parser
)
4019 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4020 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4021 || (c_parser_next_token_is (parser
, CPP_NAME
)
4022 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4023 c_parser_label (parser
);
4024 c_parser_statement_after_labels (parser
);
4027 /* Parse a statement, other than a labeled statement. */
4030 c_parser_statement_after_labels (c_parser
*parser
)
4032 location_t loc
= c_parser_peek_token (parser
)->location
;
4033 tree stmt
= NULL_TREE
;
4034 bool in_if_block
= parser
->in_if_block
;
4035 parser
->in_if_block
= false;
4036 switch (c_parser_peek_token (parser
)->type
)
4038 case CPP_OPEN_BRACE
:
4039 add_stmt (c_parser_compound_statement (parser
));
4042 switch (c_parser_peek_token (parser
)->keyword
)
4045 c_parser_if_statement (parser
);
4048 c_parser_switch_statement (parser
);
4051 c_parser_while_statement (parser
);
4054 c_parser_do_statement (parser
);
4057 c_parser_for_statement (parser
);
4060 c_parser_consume_token (parser
);
4061 if (c_parser_next_token_is (parser
, CPP_NAME
))
4063 stmt
= c_finish_goto_label (loc
,
4064 c_parser_peek_token (parser
)->value
);
4065 c_parser_consume_token (parser
);
4067 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4069 c_parser_consume_token (parser
);
4070 stmt
= c_finish_goto_ptr (loc
,
4071 c_parser_expression (parser
).value
);
4074 c_parser_error (parser
, "expected identifier or %<*%>");
4075 goto expect_semicolon
;
4077 c_parser_consume_token (parser
);
4078 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4079 goto expect_semicolon
;
4081 c_parser_consume_token (parser
);
4082 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4083 goto expect_semicolon
;
4085 c_parser_consume_token (parser
);
4086 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4088 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4089 c_parser_consume_token (parser
);
4093 struct c_expr expr
= c_parser_expression_conv (parser
);
4094 mark_exp_read (expr
.value
);
4095 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4096 goto expect_semicolon
;
4100 stmt
= c_parser_asm_statement (parser
);
4103 gcc_assert (c_dialect_objc ());
4104 c_parser_consume_token (parser
);
4105 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4107 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4108 c_parser_consume_token (parser
);
4112 tree expr
= c_parser_expression (parser
).value
;
4113 expr
= c_fully_fold (expr
, false, NULL
);
4114 stmt
= objc_build_throw_stmt (loc
, expr
);
4115 goto expect_semicolon
;
4119 gcc_assert (c_dialect_objc ());
4120 c_parser_objc_try_catch_statement (parser
);
4122 case RID_AT_SYNCHRONIZED
:
4123 gcc_assert (c_dialect_objc ());
4124 c_parser_objc_synchronized_statement (parser
);
4131 c_parser_consume_token (parser
);
4133 case CPP_CLOSE_PAREN
:
4134 case CPP_CLOSE_SQUARE
:
4135 /* Avoid infinite loop in error recovery:
4136 c_parser_skip_until_found stops at a closing nesting
4137 delimiter without consuming it, but here we need to consume
4138 it to proceed further. */
4139 c_parser_error (parser
, "expected statement");
4140 c_parser_consume_token (parser
);
4143 c_parser_pragma (parser
, pragma_stmt
);
4147 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4149 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4152 /* Two cases cannot and do not have line numbers associated: If stmt
4153 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4154 cannot hold line numbers. But that's OK because the statement
4155 will either be changed to a MODIFY_EXPR during gimplification of
4156 the statement expr, or discarded. If stmt was compound, but
4157 without new variables, we will have skipped the creation of a
4158 BIND and will have a bare STATEMENT_LIST. But that's OK because
4159 (recursively) all of the component statements should already have
4160 line numbers assigned. ??? Can we discard no-op statements
4162 if (CAN_HAVE_LOCATION_P (stmt
)
4163 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4164 SET_EXPR_LOCATION (stmt
, loc
);
4166 parser
->in_if_block
= in_if_block
;
4169 /* Parse the condition from an if, do, while or for statements. */
4172 c_parser_condition (c_parser
*parser
)
4174 location_t loc
= c_parser_peek_token (parser
)->location
;
4176 cond
= c_parser_expression_conv (parser
).value
;
4177 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4178 cond
= c_fully_fold (cond
, false, NULL
);
4179 if (warn_sequence_point
)
4180 verify_sequence_points (cond
);
4184 /* Parse a parenthesized condition from an if, do or while statement.
4190 c_parser_paren_condition (c_parser
*parser
)
4193 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4194 return error_mark_node
;
4195 cond
= c_parser_condition (parser
);
4196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4200 /* Parse a statement which is a block in C99. */
4203 c_parser_c99_block_statement (c_parser
*parser
)
4205 tree block
= c_begin_compound_stmt (flag_isoc99
);
4206 location_t loc
= c_parser_peek_token (parser
)->location
;
4207 c_parser_statement (parser
);
4208 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4211 /* Parse the body of an if statement. This is just parsing a
4212 statement but (a) it is a block in C99, (b) we track whether the
4213 body is an if statement for the sake of -Wparentheses warnings, (c)
4214 we handle an empty body specially for the sake of -Wempty-body
4215 warnings, and (d) we call parser_compound_statement directly
4216 because c_parser_statement_after_labels resets
4217 parser->in_if_block. */
4220 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4222 tree block
= c_begin_compound_stmt (flag_isoc99
);
4223 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4224 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4225 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4226 || (c_parser_next_token_is (parser
, CPP_NAME
)
4227 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4228 c_parser_label (parser
);
4229 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4230 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4232 location_t loc
= c_parser_peek_token (parser
)->location
;
4233 add_stmt (build_empty_stmt (loc
));
4234 c_parser_consume_token (parser
);
4235 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4236 warning_at (loc
, OPT_Wempty_body
,
4237 "suggest braces around empty body in an %<if%> statement");
4239 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4240 add_stmt (c_parser_compound_statement (parser
));
4242 c_parser_statement_after_labels (parser
);
4243 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4246 /* Parse the else body of an if statement. This is just parsing a
4247 statement but (a) it is a block in C99, (b) we handle an empty body
4248 specially for the sake of -Wempty-body warnings. */
4251 c_parser_else_body (c_parser
*parser
)
4253 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4254 tree block
= c_begin_compound_stmt (flag_isoc99
);
4255 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4256 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4257 || (c_parser_next_token_is (parser
, CPP_NAME
)
4258 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4259 c_parser_label (parser
);
4260 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4262 location_t loc
= c_parser_peek_token (parser
)->location
;
4265 "suggest braces around empty body in an %<else%> statement");
4266 add_stmt (build_empty_stmt (loc
));
4267 c_parser_consume_token (parser
);
4270 c_parser_statement_after_labels (parser
);
4271 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4274 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4277 if ( expression ) statement
4278 if ( expression ) statement else statement
4282 c_parser_if_statement (c_parser
*parser
)
4287 bool first_if
= false;
4288 tree first_body
, second_body
;
4291 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4292 c_parser_consume_token (parser
);
4293 block
= c_begin_compound_stmt (flag_isoc99
);
4294 loc
= c_parser_peek_token (parser
)->location
;
4295 cond
= c_parser_paren_condition (parser
);
4296 in_if_block
= parser
->in_if_block
;
4297 parser
->in_if_block
= true;
4298 first_body
= c_parser_if_body (parser
, &first_if
);
4299 parser
->in_if_block
= in_if_block
;
4300 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4302 c_parser_consume_token (parser
);
4303 second_body
= c_parser_else_body (parser
);
4306 second_body
= NULL_TREE
;
4307 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4308 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4311 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4314 switch (expression) statement
4318 c_parser_switch_statement (c_parser
*parser
)
4320 tree block
, expr
, body
, save_break
;
4321 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4322 location_t switch_cond_loc
;
4323 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4324 c_parser_consume_token (parser
);
4325 block
= c_begin_compound_stmt (flag_isoc99
);
4326 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4328 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4329 expr
= c_parser_expression (parser
).value
;
4330 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4334 switch_cond_loc
= UNKNOWN_LOCATION
;
4335 expr
= error_mark_node
;
4337 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4338 save_break
= c_break_label
;
4339 c_break_label
= NULL_TREE
;
4340 body
= c_parser_c99_block_statement (parser
);
4341 c_finish_case (body
);
4344 location_t here
= c_parser_peek_token (parser
)->location
;
4345 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4346 SET_EXPR_LOCATION (t
, here
);
4349 c_break_label
= save_break
;
4350 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4353 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4356 while (expression) statement
4360 c_parser_while_statement (c_parser
*parser
)
4362 tree block
, cond
, body
, save_break
, save_cont
;
4364 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4365 c_parser_consume_token (parser
);
4366 block
= c_begin_compound_stmt (flag_isoc99
);
4367 loc
= c_parser_peek_token (parser
)->location
;
4368 cond
= c_parser_paren_condition (parser
);
4369 save_break
= c_break_label
;
4370 c_break_label
= NULL_TREE
;
4371 save_cont
= c_cont_label
;
4372 c_cont_label
= NULL_TREE
;
4373 body
= c_parser_c99_block_statement (parser
);
4374 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4375 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4376 c_break_label
= save_break
;
4377 c_cont_label
= save_cont
;
4380 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4383 do statement while ( expression ) ;
4387 c_parser_do_statement (c_parser
*parser
)
4389 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4391 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4392 c_parser_consume_token (parser
);
4393 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4394 warning_at (c_parser_peek_token (parser
)->location
,
4396 "suggest braces around empty body in %<do%> statement");
4397 block
= c_begin_compound_stmt (flag_isoc99
);
4398 loc
= c_parser_peek_token (parser
)->location
;
4399 save_break
= c_break_label
;
4400 c_break_label
= NULL_TREE
;
4401 save_cont
= c_cont_label
;
4402 c_cont_label
= NULL_TREE
;
4403 body
= c_parser_c99_block_statement (parser
);
4404 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4405 new_break
= c_break_label
;
4406 c_break_label
= save_break
;
4407 new_cont
= c_cont_label
;
4408 c_cont_label
= save_cont
;
4409 cond
= c_parser_paren_condition (parser
);
4410 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4411 c_parser_skip_to_end_of_block_or_statement (parser
);
4412 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4413 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4416 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4419 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4420 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4422 The form with a declaration is new in C99.
4424 ??? In accordance with the old parser, the declaration may be a
4425 nested function, which is then rejected in check_for_loop_decls,
4426 but does it make any sense for this to be included in the grammar?
4427 Note in particular that the nested function does not include a
4428 trailing ';', whereas the "declaration" production includes one.
4429 Also, can we reject bad declarations earlier and cheaper than
4430 check_for_loop_decls? */
4433 c_parser_for_statement (c_parser
*parser
)
4435 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4436 location_t loc
= c_parser_peek_token (parser
)->location
;
4437 location_t for_loc
= c_parser_peek_token (parser
)->location
;
4438 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4439 c_parser_consume_token (parser
);
4440 block
= c_begin_compound_stmt (flag_isoc99
);
4441 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4443 /* Parse the initialization declaration or expression. */
4444 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4446 c_parser_consume_token (parser
);
4447 c_finish_expr_stmt (loc
, NULL_TREE
);
4449 else if (c_parser_next_token_starts_declaration (parser
))
4451 c_parser_declaration_or_fndef (parser
, true, true, true, true, true);
4452 check_for_loop_decls (for_loc
);
4454 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4456 /* __extension__ can start a declaration, but is also an
4457 unary operator that can start an expression. Consume all
4458 but the last of a possible series of __extension__ to
4460 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4461 && (c_parser_peek_2nd_token (parser
)->keyword
4463 c_parser_consume_token (parser
);
4464 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4467 ext
= disable_extension_diagnostics ();
4468 c_parser_consume_token (parser
);
4469 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4471 restore_extension_diagnostics (ext
);
4472 check_for_loop_decls (for_loc
);
4480 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
4481 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4483 /* Parse the loop condition. */
4484 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4486 c_parser_consume_token (parser
);
4491 cond
= c_parser_condition (parser
);
4492 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4494 /* Parse the increment expression. */
4495 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4496 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
4498 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
4499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4503 cond
= error_mark_node
;
4504 incr
= error_mark_node
;
4506 save_break
= c_break_label
;
4507 c_break_label
= NULL_TREE
;
4508 save_cont
= c_cont_label
;
4509 c_cont_label
= NULL_TREE
;
4510 body
= c_parser_c99_block_statement (parser
);
4511 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4512 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4513 c_break_label
= save_break
;
4514 c_cont_label
= save_cont
;
4517 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4518 statement with inputs, outputs, clobbers, and volatile tag
4522 asm type-qualifier[opt] ( asm-argument ) ;
4523 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
4527 asm-string-literal : asm-operands[opt]
4528 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4529 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
4532 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
4535 Qualifiers other than volatile are accepted in the syntax but
4539 c_parser_asm_statement (c_parser
*parser
)
4541 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
4542 bool simple
, is_goto
;
4543 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
4544 int section
, nsections
;
4546 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4547 c_parser_consume_token (parser
);
4548 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4550 quals
= c_parser_peek_token (parser
)->value
;
4551 c_parser_consume_token (parser
);
4553 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4554 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4556 warning_at (c_parser_peek_token (parser
)->location
,
4558 "%E qualifier ignored on asm",
4559 c_parser_peek_token (parser
)->value
);
4561 c_parser_consume_token (parser
);
4567 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
4569 c_parser_consume_token (parser
);
4573 /* ??? Follow the C++ parser rather than using the
4574 lex_untranslated_string kludge. */
4575 parser
->lex_untranslated_string
= true;
4578 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4581 str
= c_parser_asm_string_literal (parser
);
4582 if (str
== NULL_TREE
)
4583 goto error_close_paren
;
4586 outputs
= NULL_TREE
;
4588 clobbers
= NULL_TREE
;
4591 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4594 /* Parse each colon-delimited section of operands. */
4595 nsections
= 3 + is_goto
;
4596 for (section
= 0; section
< nsections
; ++section
)
4598 if (!c_parser_require (parser
, CPP_COLON
,
4601 : "expected %<:%> or %<)%>"))
4602 goto error_close_paren
;
4604 /* Once past any colon, we're no longer a simple asm. */
4607 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
4608 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4613 /* For asm goto, we don't allow output operands, but reserve
4614 the slot for a future extension that does allow them. */
4616 outputs
= c_parser_asm_operands (parser
, false);
4619 inputs
= c_parser_asm_operands (parser
, true);
4622 clobbers
= c_parser_asm_clobbers (parser
);
4625 labels
= c_parser_asm_goto_operands (parser
);
4631 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
4636 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4642 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4643 c_parser_skip_to_end_of_block_or_statement (parser
);
4645 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
4646 clobbers
, labels
, simple
));
4649 parser
->lex_untranslated_string
= false;
4653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4657 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4658 not outputs), apply the default conversion of functions and arrays
4663 asm-operands , asm-operand
4666 asm-string-literal ( expression )
4667 [ identifier ] asm-string-literal ( expression )
4671 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4673 tree list
= NULL_TREE
;
4679 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4681 c_parser_consume_token (parser
);
4682 if (c_parser_next_token_is (parser
, CPP_NAME
))
4684 tree id
= c_parser_peek_token (parser
)->value
;
4685 c_parser_consume_token (parser
);
4686 name
= build_string (IDENTIFIER_LENGTH (id
),
4687 IDENTIFIER_POINTER (id
));
4691 c_parser_error (parser
, "expected identifier");
4692 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4695 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4700 str
= c_parser_asm_string_literal (parser
);
4701 if (str
== NULL_TREE
)
4703 parser
->lex_untranslated_string
= false;
4704 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4706 parser
->lex_untranslated_string
= true;
4709 loc
= c_parser_peek_token (parser
)->location
;
4710 expr
= c_parser_expression (parser
);
4711 mark_exp_read (expr
.value
);
4713 expr
= default_function_array_conversion (loc
, expr
);
4714 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4715 parser
->lex_untranslated_string
= true;
4716 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4718 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4721 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4723 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4724 c_parser_consume_token (parser
);
4731 /* Parse asm clobbers, a GNU extension.
4735 asm-clobbers , asm-string-literal
4739 c_parser_asm_clobbers (c_parser
*parser
)
4741 tree list
= NULL_TREE
;
4744 tree str
= c_parser_asm_string_literal (parser
);
4746 list
= tree_cons (NULL_TREE
, str
, list
);
4749 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4750 c_parser_consume_token (parser
);
4757 /* Parse asm goto labels, a GNU extension.
4761 asm-goto-operands , identifier
4765 c_parser_asm_goto_operands (c_parser
*parser
)
4767 tree list
= NULL_TREE
;
4772 if (c_parser_next_token_is (parser
, CPP_NAME
))
4774 c_token
*tok
= c_parser_peek_token (parser
);
4776 label
= lookup_label_for_goto (tok
->location
, name
);
4777 c_parser_consume_token (parser
);
4778 TREE_USED (label
) = 1;
4782 c_parser_error (parser
, "expected identifier");
4786 name
= build_string (IDENTIFIER_LENGTH (name
),
4787 IDENTIFIER_POINTER (name
));
4788 list
= tree_cons (name
, label
, list
);
4789 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4790 c_parser_consume_token (parser
);
4792 return nreverse (list
);
4796 /* Parse an expression other than a compound expression; that is, an
4797 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4798 NULL then it is an Objective-C message expression which is the
4799 primary-expression starting the expression as an initializer.
4801 assignment-expression:
4802 conditional-expression
4803 unary-expression assignment-operator assignment-expression
4805 assignment-operator: one of
4806 = *= /= %= += -= <<= >>= &= ^= |=
4808 In GNU C we accept any conditional expression on the LHS and
4809 diagnose the invalid lvalue rather than producing a syntax
4812 static struct c_expr
4813 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4815 struct c_expr lhs
, rhs
, ret
;
4816 enum tree_code code
;
4817 location_t op_location
, exp_location
;
4818 gcc_assert (!after
|| c_dialect_objc ());
4819 lhs
= c_parser_conditional_expression (parser
, after
);
4820 op_location
= c_parser_peek_token (parser
)->location
;
4821 switch (c_parser_peek_token (parser
)->type
)
4830 code
= TRUNC_DIV_EXPR
;
4833 code
= TRUNC_MOD_EXPR
;
4848 code
= BIT_AND_EXPR
;
4851 code
= BIT_XOR_EXPR
;
4854 code
= BIT_IOR_EXPR
;
4859 c_parser_consume_token (parser
);
4860 exp_location
= c_parser_peek_token (parser
)->location
;
4861 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4862 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
4863 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
4864 code
, exp_location
, rhs
.value
,
4866 if (code
== NOP_EXPR
)
4867 ret
.original_code
= MODIFY_EXPR
;
4870 TREE_NO_WARNING (ret
.value
) = 1;
4871 ret
.original_code
= ERROR_MARK
;
4873 ret
.original_type
= NULL
;
4877 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4878 is not NULL then it is an Objective-C message expression which is
4879 the primary-expression starting the expression as an initializer.
4881 conditional-expression:
4882 logical-OR-expression
4883 logical-OR-expression ? expression : conditional-expression
4887 conditional-expression:
4888 logical-OR-expression ? : conditional-expression
4891 static struct c_expr
4892 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4894 struct c_expr cond
, exp1
, exp2
, ret
;
4895 location_t cond_loc
, colon_loc
, middle_loc
;
4897 gcc_assert (!after
|| c_dialect_objc ());
4899 cond
= c_parser_binary_expression (parser
, after
);
4901 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4903 cond_loc
= c_parser_peek_token (parser
)->location
;
4904 cond
= default_function_array_read_conversion (cond_loc
, cond
);
4905 c_parser_consume_token (parser
);
4906 if (c_parser_next_token_is (parser
, CPP_COLON
))
4908 tree eptype
= NULL_TREE
;
4910 middle_loc
= c_parser_peek_token (parser
)->location
;
4911 pedwarn (middle_loc
, OPT_pedantic
,
4912 "ISO C forbids omitting the middle term of a ?: expression");
4913 warn_for_omitted_condop (middle_loc
, cond
.value
);
4914 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
4916 eptype
= TREE_TYPE (cond
.value
);
4917 cond
.value
= TREE_OPERAND (cond
.value
, 0);
4919 /* Make sure first operand is calculated only once. */
4920 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
4922 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
4923 exp1
.original_type
= NULL
;
4924 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
4925 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
4930 = c_objc_common_truthvalue_conversion
4931 (cond_loc
, default_conversion (cond
.value
));
4932 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
4933 exp1
= c_parser_expression_conv (parser
);
4934 mark_exp_read (exp1
.value
);
4935 c_inhibit_evaluation_warnings
+=
4936 ((cond
.value
== truthvalue_true_node
)
4937 - (cond
.value
== truthvalue_false_node
));
4940 colon_loc
= c_parser_peek_token (parser
)->location
;
4941 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4943 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4944 ret
.value
= error_mark_node
;
4945 ret
.original_code
= ERROR_MARK
;
4946 ret
.original_type
= NULL
;
4950 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
4951 exp2
= c_parser_conditional_expression (parser
, NULL
);
4952 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
4954 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
4955 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
4956 cond
.original_code
== C_MAYBE_CONST_EXPR
,
4957 exp1
.value
, exp1
.original_type
,
4958 exp2
.value
, exp2
.original_type
);
4959 ret
.original_code
= ERROR_MARK
;
4960 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
4961 ret
.original_type
= NULL
;
4966 /* If both sides are enum type, the default conversion will have
4967 made the type of the result be an integer type. We want to
4968 remember the enum types we started with. */
4969 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
4970 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
4971 ret
.original_type
= ((t1
!= error_mark_node
4972 && t2
!= error_mark_node
4973 && (TYPE_MAIN_VARIANT (t1
)
4974 == TYPE_MAIN_VARIANT (t2
)))
4981 /* Parse a binary expression; that is, a logical-OR-expression (C90
4982 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4983 an Objective-C message expression which is the primary-expression
4984 starting the expression as an initializer.
4986 multiplicative-expression:
4988 multiplicative-expression * cast-expression
4989 multiplicative-expression / cast-expression
4990 multiplicative-expression % cast-expression
4992 additive-expression:
4993 multiplicative-expression
4994 additive-expression + multiplicative-expression
4995 additive-expression - multiplicative-expression
4999 shift-expression << additive-expression
5000 shift-expression >> additive-expression
5002 relational-expression:
5004 relational-expression < shift-expression
5005 relational-expression > shift-expression
5006 relational-expression <= shift-expression
5007 relational-expression >= shift-expression
5009 equality-expression:
5010 relational-expression
5011 equality-expression == relational-expression
5012 equality-expression != relational-expression
5016 AND-expression & equality-expression
5018 exclusive-OR-expression:
5020 exclusive-OR-expression ^ AND-expression
5022 inclusive-OR-expression:
5023 exclusive-OR-expression
5024 inclusive-OR-expression | exclusive-OR-expression
5026 logical-AND-expression:
5027 inclusive-OR-expression
5028 logical-AND-expression && inclusive-OR-expression
5030 logical-OR-expression:
5031 logical-AND-expression
5032 logical-OR-expression || logical-AND-expression
5035 static struct c_expr
5036 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
5038 /* A binary expression is parsed using operator-precedence parsing,
5039 with the operands being cast expressions. All the binary
5040 operators are left-associative. Thus a binary expression is of
5043 E0 op1 E1 op2 E2 ...
5045 which we represent on a stack. On the stack, the precedence
5046 levels are strictly increasing. When a new operator is
5047 encountered of higher precedence than that at the top of the
5048 stack, it is pushed; its LHS is the top expression, and its RHS
5049 is everything parsed until it is popped. When a new operator is
5050 encountered with precedence less than or equal to that at the top
5051 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5052 by the result of the operation until the operator at the top of
5053 the stack has lower precedence than the new operator or there is
5054 only one element on the stack; then the top expression is the LHS
5055 of the new operator. In the case of logical AND and OR
5056 expressions, we also need to adjust c_inhibit_evaluation_warnings
5057 as appropriate when the operators are pushed and popped. */
5059 /* The precedence levels, where 0 is a dummy lowest level used for
5060 the bottom of the stack. */
5076 /* The expression at this stack level. */
5078 /* The precedence of the operator on its left, PREC_NONE at the
5079 bottom of the stack. */
5081 /* The operation on its left. */
5083 /* The source location of this operation. */
5087 /* Location of the binary operator. */
5088 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5091 switch (stack[sp].op) \
5093 case TRUTH_ANDIF_EXPR: \
5094 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5095 == truthvalue_false_node); \
5097 case TRUTH_ORIF_EXPR: \
5098 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5099 == truthvalue_true_node); \
5104 stack[sp - 1].expr \
5105 = default_function_array_read_conversion (stack[sp - 1].loc, \
5106 stack[sp - 1].expr); \
5108 = default_function_array_read_conversion (stack[sp].loc, \
5110 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5112 stack[sp - 1].expr, \
5116 gcc_assert (!after
|| c_dialect_objc ());
5117 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5118 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5119 stack
[0].prec
= PREC_NONE
;
5124 enum tree_code ocode
;
5127 switch (c_parser_peek_token (parser
)->type
)
5135 ocode
= TRUNC_DIV_EXPR
;
5139 ocode
= TRUNC_MOD_EXPR
;
5151 ocode
= LSHIFT_EXPR
;
5155 ocode
= RSHIFT_EXPR
;
5169 case CPP_GREATER_EQ
:
5182 oprec
= PREC_BITAND
;
5183 ocode
= BIT_AND_EXPR
;
5186 oprec
= PREC_BITXOR
;
5187 ocode
= BIT_XOR_EXPR
;
5191 ocode
= BIT_IOR_EXPR
;
5194 oprec
= PREC_LOGAND
;
5195 ocode
= TRUTH_ANDIF_EXPR
;
5199 ocode
= TRUTH_ORIF_EXPR
;
5202 /* Not a binary operator, so end of the binary
5206 binary_loc
= c_parser_peek_token (parser
)->location
;
5207 c_parser_consume_token (parser
);
5208 while (oprec
<= stack
[sp
].prec
)
5212 case TRUTH_ANDIF_EXPR
:
5214 = default_function_array_read_conversion (stack
[sp
].loc
,
5216 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5217 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5218 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5219 == truthvalue_false_node
);
5221 case TRUTH_ORIF_EXPR
:
5223 = default_function_array_read_conversion (stack
[sp
].loc
,
5225 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5226 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5227 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5228 == truthvalue_true_node
);
5234 stack
[sp
].loc
= binary_loc
;
5235 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5236 stack
[sp
].prec
= oprec
;
5237 stack
[sp
].op
= ocode
;
5238 stack
[sp
].loc
= binary_loc
;
5243 return stack
[0].expr
;
5247 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5248 NULL then it is an Objective-C message expression which is the
5249 primary-expression starting the expression as an initializer.
5253 ( type-name ) unary-expression
5256 static struct c_expr
5257 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5259 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5260 gcc_assert (!after
|| c_dialect_objc ());
5262 return c_parser_postfix_expression_after_primary (parser
,
5264 /* If the expression begins with a parenthesized type name, it may
5265 be either a cast or a compound literal; we need to see whether
5266 the next character is '{' to tell the difference. If not, it is
5267 an unary expression. */
5268 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5269 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5271 struct c_type_name
*type_name
;
5274 c_parser_consume_token (parser
);
5275 type_name
= c_parser_type_name (parser
);
5276 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5277 if (type_name
== NULL
)
5279 ret
.value
= error_mark_node
;
5280 ret
.original_code
= ERROR_MARK
;
5281 ret
.original_type
= NULL
;
5285 /* Save casted types in the function's used types hash table. */
5286 used_types_insert (type_name
->specs
->type
);
5288 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5289 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5292 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5293 expr
= c_parser_cast_expression (parser
, NULL
);
5294 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5296 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5297 ret
.original_code
= ERROR_MARK
;
5298 ret
.original_type
= NULL
;
5302 return c_parser_unary_expression (parser
);
5305 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5311 unary-operator cast-expression
5312 sizeof unary-expression
5313 sizeof ( type-name )
5315 unary-operator: one of
5321 __alignof__ unary-expression
5322 __alignof__ ( type-name )
5325 unary-operator: one of
5326 __extension__ __real__ __imag__
5328 In addition, the GNU syntax treats ++ and -- as unary operators, so
5329 they may be applied to cast expressions with errors for non-lvalues
5332 static struct c_expr
5333 c_parser_unary_expression (c_parser
*parser
)
5336 struct c_expr ret
, op
;
5337 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5339 ret
.original_code
= ERROR_MARK
;
5340 ret
.original_type
= NULL
;
5341 switch (c_parser_peek_token (parser
)->type
)
5344 c_parser_consume_token (parser
);
5345 exp_loc
= c_parser_peek_token (parser
)->location
;
5346 op
= c_parser_cast_expression (parser
, NULL
);
5347 op
= default_function_array_read_conversion (exp_loc
, op
);
5348 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
5349 case CPP_MINUS_MINUS
:
5350 c_parser_consume_token (parser
);
5351 exp_loc
= c_parser_peek_token (parser
)->location
;
5352 op
= c_parser_cast_expression (parser
, NULL
);
5353 op
= default_function_array_read_conversion (exp_loc
, op
);
5354 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
5356 c_parser_consume_token (parser
);
5357 op
= c_parser_cast_expression (parser
, NULL
);
5358 mark_exp_read (op
.value
);
5359 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
5361 c_parser_consume_token (parser
);
5362 exp_loc
= c_parser_peek_token (parser
)->location
;
5363 op
= c_parser_cast_expression (parser
, NULL
);
5364 op
= default_function_array_read_conversion (exp_loc
, op
);
5365 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
5368 if (!c_dialect_objc () && !in_system_header
)
5371 "traditional C rejects the unary plus operator");
5372 c_parser_consume_token (parser
);
5373 exp_loc
= c_parser_peek_token (parser
)->location
;
5374 op
= c_parser_cast_expression (parser
, NULL
);
5375 op
= default_function_array_read_conversion (exp_loc
, op
);
5376 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
5378 c_parser_consume_token (parser
);
5379 exp_loc
= c_parser_peek_token (parser
)->location
;
5380 op
= c_parser_cast_expression (parser
, NULL
);
5381 op
= default_function_array_read_conversion (exp_loc
, op
);
5382 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
5384 c_parser_consume_token (parser
);
5385 exp_loc
= c_parser_peek_token (parser
)->location
;
5386 op
= c_parser_cast_expression (parser
, NULL
);
5387 op
= default_function_array_read_conversion (exp_loc
, op
);
5388 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
5390 c_parser_consume_token (parser
);
5391 exp_loc
= c_parser_peek_token (parser
)->location
;
5392 op
= c_parser_cast_expression (parser
, NULL
);
5393 op
= default_function_array_read_conversion (exp_loc
, op
);
5394 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
5396 /* Refer to the address of a label as a pointer. */
5397 c_parser_consume_token (parser
);
5398 if (c_parser_next_token_is (parser
, CPP_NAME
))
5400 ret
.value
= finish_label_address_expr
5401 (c_parser_peek_token (parser
)->value
, op_loc
);
5402 c_parser_consume_token (parser
);
5406 c_parser_error (parser
, "expected identifier");
5407 ret
.value
= error_mark_node
;
5411 switch (c_parser_peek_token (parser
)->keyword
)
5414 return c_parser_sizeof_expression (parser
);
5416 return c_parser_alignof_expression (parser
);
5418 c_parser_consume_token (parser
);
5419 ext
= disable_extension_diagnostics ();
5420 ret
= c_parser_cast_expression (parser
, NULL
);
5421 restore_extension_diagnostics (ext
);
5424 c_parser_consume_token (parser
);
5425 exp_loc
= c_parser_peek_token (parser
)->location
;
5426 op
= c_parser_cast_expression (parser
, NULL
);
5427 op
= default_function_array_conversion (exp_loc
, op
);
5428 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
5430 c_parser_consume_token (parser
);
5431 exp_loc
= c_parser_peek_token (parser
)->location
;
5432 op
= c_parser_cast_expression (parser
, NULL
);
5433 op
= default_function_array_conversion (exp_loc
, op
);
5434 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
5436 return c_parser_postfix_expression (parser
);
5439 return c_parser_postfix_expression (parser
);
5443 /* Parse a sizeof expression. */
5445 static struct c_expr
5446 c_parser_sizeof_expression (c_parser
*parser
)
5449 location_t expr_loc
;
5450 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
5451 c_parser_consume_token (parser
);
5452 c_inhibit_evaluation_warnings
++;
5454 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5455 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5457 /* Either sizeof ( type-name ) or sizeof unary-expression
5458 starting with a compound literal. */
5459 struct c_type_name
*type_name
;
5460 c_parser_consume_token (parser
);
5461 expr_loc
= c_parser_peek_token (parser
)->location
;
5462 type_name
= c_parser_type_name (parser
);
5463 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5464 if (type_name
== NULL
)
5467 c_inhibit_evaluation_warnings
--;
5469 ret
.value
= error_mark_node
;
5470 ret
.original_code
= ERROR_MARK
;
5471 ret
.original_type
= NULL
;
5474 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5476 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5481 /* sizeof ( type-name ). */
5482 c_inhibit_evaluation_warnings
--;
5484 return c_expr_sizeof_type (expr_loc
, type_name
);
5488 expr_loc
= c_parser_peek_token (parser
)->location
;
5489 expr
= c_parser_unary_expression (parser
);
5491 c_inhibit_evaluation_warnings
--;
5493 mark_exp_read (expr
.value
);
5494 if (TREE_CODE (expr
.value
) == COMPONENT_REF
5495 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
5496 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
5497 return c_expr_sizeof_expr (expr_loc
, expr
);
5501 /* Parse an alignof expression. */
5503 static struct c_expr
5504 c_parser_alignof_expression (c_parser
*parser
)
5507 location_t loc
= c_parser_peek_token (parser
)->location
;
5508 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
5509 c_parser_consume_token (parser
);
5510 c_inhibit_evaluation_warnings
++;
5512 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5513 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5515 /* Either __alignof__ ( type-name ) or __alignof__
5516 unary-expression starting with a compound literal. */
5518 struct c_type_name
*type_name
;
5520 c_parser_consume_token (parser
);
5521 loc
= c_parser_peek_token (parser
)->location
;
5522 type_name
= c_parser_type_name (parser
);
5523 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5524 if (type_name
== NULL
)
5527 c_inhibit_evaluation_warnings
--;
5529 ret
.value
= error_mark_node
;
5530 ret
.original_code
= ERROR_MARK
;
5531 ret
.original_type
= NULL
;
5534 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5536 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5541 /* alignof ( type-name ). */
5542 c_inhibit_evaluation_warnings
--;
5544 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
5545 ret
.original_code
= ERROR_MARK
;
5546 ret
.original_type
= NULL
;
5552 expr
= c_parser_unary_expression (parser
);
5554 mark_exp_read (expr
.value
);
5555 c_inhibit_evaluation_warnings
--;
5557 ret
.value
= c_alignof_expr (loc
, expr
.value
);
5558 ret
.original_code
= ERROR_MARK
;
5559 ret
.original_type
= NULL
;
5564 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
5568 postfix-expression [ expression ]
5569 postfix-expression ( argument-expression-list[opt] )
5570 postfix-expression . identifier
5571 postfix-expression -> identifier
5572 postfix-expression ++
5573 postfix-expression --
5574 ( type-name ) { initializer-list }
5575 ( type-name ) { initializer-list , }
5577 argument-expression-list:
5579 argument-expression-list , argument-expression
5591 (treated as a keyword in GNU C)
5594 ( compound-statement )
5595 __builtin_va_arg ( assignment-expression , type-name )
5596 __builtin_offsetof ( type-name , offsetof-member-designator )
5597 __builtin_choose_expr ( assignment-expression ,
5598 assignment-expression ,
5599 assignment-expression )
5600 __builtin_types_compatible_p ( type-name , type-name )
5602 offsetof-member-designator:
5604 offsetof-member-designator . identifier
5605 offsetof-member-designator [ expression ]
5610 [ objc-receiver objc-message-args ]
5611 @selector ( objc-selector-arg )
5612 @protocol ( identifier )
5613 @encode ( type-name )
5617 static struct c_expr
5618 c_parser_postfix_expression (c_parser
*parser
)
5620 struct c_expr expr
, e1
, e2
, e3
;
5621 struct c_type_name
*t1
, *t2
;
5622 location_t loc
= c_parser_peek_token (parser
)->location
;;
5623 expr
.original_code
= ERROR_MARK
;
5624 expr
.original_type
= NULL
;
5625 switch (c_parser_peek_token (parser
)->type
)
5628 expr
.value
= c_parser_peek_token (parser
)->value
;
5629 loc
= c_parser_peek_token (parser
)->location
;
5630 c_parser_consume_token (parser
);
5631 if (TREE_CODE (expr
.value
) == FIXED_CST
5632 && !targetm
.fixed_point_supported_p ())
5634 error_at (loc
, "fixed-point types not supported for this target");
5635 expr
.value
= error_mark_node
;
5642 expr
.value
= c_parser_peek_token (parser
)->value
;
5643 c_parser_consume_token (parser
);
5649 case CPP_UTF8STRING
:
5650 expr
.value
= c_parser_peek_token (parser
)->value
;
5651 expr
.original_code
= STRING_CST
;
5652 c_parser_consume_token (parser
);
5654 case CPP_OBJC_STRING
:
5655 gcc_assert (c_dialect_objc ());
5657 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5658 c_parser_consume_token (parser
);
5661 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5663 c_parser_error (parser
, "expected expression");
5664 expr
.value
= error_mark_node
;
5668 tree id
= c_parser_peek_token (parser
)->value
;
5669 c_parser_consume_token (parser
);
5670 expr
.value
= build_external_ref (loc
, id
,
5671 (c_parser_peek_token (parser
)->type
5673 &expr
.original_type
);
5676 case CPP_OPEN_PAREN
:
5677 /* A parenthesized expression, statement expression or compound
5679 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5681 /* A statement expression. */
5683 location_t brace_loc
;
5684 c_parser_consume_token (parser
);
5685 brace_loc
= c_parser_peek_token (parser
)->location
;
5686 c_parser_consume_token (parser
);
5687 if (cur_stmt_list
== NULL
)
5689 error_at (loc
, "braced-group within expression allowed "
5690 "only inside a function");
5691 parser
->error
= true;
5692 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5694 expr
.value
= error_mark_node
;
5697 stmt
= c_begin_stmt_expr ();
5698 c_parser_compound_statement_nostart (parser
);
5699 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5701 pedwarn (loc
, OPT_pedantic
,
5702 "ISO C forbids braced-groups within expressions");
5703 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
5704 mark_exp_read (expr
.value
);
5706 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5708 /* A compound literal. ??? Can we actually get here rather
5709 than going directly to
5710 c_parser_postfix_expression_after_paren_type from
5713 struct c_type_name
*type_name
;
5714 c_parser_consume_token (parser
);
5715 loc
= c_parser_peek_token (parser
)->location
;
5716 type_name
= c_parser_type_name (parser
);
5717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5719 if (type_name
== NULL
)
5721 expr
.value
= error_mark_node
;
5724 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5730 /* A parenthesized expression. */
5731 c_parser_consume_token (parser
);
5732 expr
= c_parser_expression (parser
);
5733 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5734 TREE_NO_WARNING (expr
.value
) = 1;
5735 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
5736 expr
.original_code
= ERROR_MARK
;
5737 /* Don't change EXPR.ORIGINAL_TYPE. */
5738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5743 switch (c_parser_peek_token (parser
)->keyword
)
5745 case RID_FUNCTION_NAME
:
5746 case RID_PRETTY_FUNCTION_NAME
:
5747 case RID_C99_FUNCTION_NAME
:
5748 expr
.value
= fname_decl (loc
,
5749 c_parser_peek_token (parser
)->keyword
,
5750 c_parser_peek_token (parser
)->value
);
5751 c_parser_consume_token (parser
);
5754 c_parser_consume_token (parser
);
5755 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5757 expr
.value
= error_mark_node
;
5760 e1
= c_parser_expr_no_commas (parser
, NULL
);
5761 mark_exp_read (e1
.value
);
5762 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
5763 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5765 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5766 expr
.value
= error_mark_node
;
5769 loc
= c_parser_peek_token (parser
)->location
;
5770 t1
= c_parser_type_name (parser
);
5771 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5775 expr
.value
= error_mark_node
;
5779 tree type_expr
= NULL_TREE
;
5780 expr
.value
= c_build_va_arg (loc
, e1
.value
,
5781 groktypename (t1
, &type_expr
, NULL
));
5784 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
5785 TREE_TYPE (expr
.value
), type_expr
,
5787 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
5792 c_parser_consume_token (parser
);
5793 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5795 expr
.value
= error_mark_node
;
5798 t1
= c_parser_type_name (parser
);
5801 expr
.value
= error_mark_node
;
5804 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5806 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5807 expr
.value
= error_mark_node
;
5811 tree type
= groktypename (t1
, NULL
, NULL
);
5813 if (type
== error_mark_node
)
5814 offsetof_ref
= error_mark_node
;
5817 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5818 SET_EXPR_LOCATION (offsetof_ref
, loc
);
5820 /* Parse the second argument to __builtin_offsetof. We
5821 must have one identifier, and beyond that we want to
5822 accept sub structure and sub array references. */
5823 if (c_parser_next_token_is (parser
, CPP_NAME
))
5825 offsetof_ref
= build_component_ref
5826 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
5827 c_parser_consume_token (parser
);
5828 while (c_parser_next_token_is (parser
, CPP_DOT
)
5829 || c_parser_next_token_is (parser
,
5831 || c_parser_next_token_is (parser
,
5834 if (c_parser_next_token_is (parser
, CPP_DEREF
))
5836 loc
= c_parser_peek_token (parser
)->location
;
5837 offsetof_ref
= build_array_ref (loc
,
5842 else if (c_parser_next_token_is (parser
, CPP_DOT
))
5845 c_parser_consume_token (parser
);
5846 if (c_parser_next_token_is_not (parser
,
5849 c_parser_error (parser
, "expected identifier");
5852 offsetof_ref
= build_component_ref
5854 c_parser_peek_token (parser
)->value
);
5855 c_parser_consume_token (parser
);
5860 loc
= c_parser_peek_token (parser
)->location
;
5861 c_parser_consume_token (parser
);
5862 idx
= c_parser_expression (parser
).value
;
5863 idx
= c_fully_fold (idx
, false, NULL
);
5864 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5866 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
5871 c_parser_error (parser
, "expected identifier");
5872 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5874 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5877 case RID_CHOOSE_EXPR
:
5878 c_parser_consume_token (parser
);
5879 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5881 expr
.value
= error_mark_node
;
5884 loc
= c_parser_peek_token (parser
)->location
;
5885 e1
= c_parser_expr_no_commas (parser
, NULL
);
5886 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5888 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5889 expr
.value
= error_mark_node
;
5892 e2
= c_parser_expr_no_commas (parser
, NULL
);
5893 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5896 expr
.value
= error_mark_node
;
5899 e3
= c_parser_expr_no_commas (parser
, NULL
);
5900 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5906 mark_exp_read (e2
.value
);
5907 mark_exp_read (e3
.value
);
5908 if (TREE_CODE (c
) != INTEGER_CST
5909 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
5911 "first argument to %<__builtin_choose_expr%> not"
5913 constant_expression_warning (c
);
5914 expr
= integer_zerop (c
) ? e3
: e2
;
5917 case RID_TYPES_COMPATIBLE_P
:
5918 c_parser_consume_token (parser
);
5919 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5921 expr
.value
= error_mark_node
;
5924 t1
= c_parser_type_name (parser
);
5927 expr
.value
= error_mark_node
;
5930 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5932 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5933 expr
.value
= error_mark_node
;
5936 t2
= c_parser_type_name (parser
);
5939 expr
.value
= error_mark_node
;
5942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5947 e1
= TYPE_MAIN_VARIANT (groktypename (t1
, NULL
, NULL
));
5948 e2
= TYPE_MAIN_VARIANT (groktypename (t2
, NULL
, NULL
));
5951 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
5954 case RID_AT_SELECTOR
:
5955 gcc_assert (c_dialect_objc ());
5956 c_parser_consume_token (parser
);
5957 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5959 expr
.value
= error_mark_node
;
5963 tree sel
= c_parser_objc_selector_arg (parser
);
5964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5966 expr
.value
= objc_build_selector_expr (loc
, sel
);
5969 case RID_AT_PROTOCOL
:
5970 gcc_assert (c_dialect_objc ());
5971 c_parser_consume_token (parser
);
5972 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5974 expr
.value
= error_mark_node
;
5977 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5979 c_parser_error (parser
, "expected identifier");
5980 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5981 expr
.value
= error_mark_node
;
5985 tree id
= c_parser_peek_token (parser
)->value
;
5986 c_parser_consume_token (parser
);
5987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5989 expr
.value
= objc_build_protocol_expr (id
);
5993 /* Extension to support C-structures in the archiver. */
5994 gcc_assert (c_dialect_objc ());
5995 c_parser_consume_token (parser
);
5996 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5998 expr
.value
= error_mark_node
;
6001 t1
= c_parser_type_name (parser
);
6004 expr
.value
= error_mark_node
;
6005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6008 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6011 tree type
= groktypename (t1
, NULL
, NULL
);
6012 expr
.value
= objc_build_encode_expr (type
);
6016 c_parser_error (parser
, "expected expression");
6017 expr
.value
= error_mark_node
;
6021 case CPP_OPEN_SQUARE
:
6022 if (c_dialect_objc ())
6024 tree receiver
, args
;
6025 c_parser_consume_token (parser
);
6026 receiver
= c_parser_objc_receiver (parser
);
6027 args
= c_parser_objc_message_args (parser
);
6028 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6030 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
6034 /* Else fall through to report error. */
6036 c_parser_error (parser
, "expected expression");
6037 expr
.value
= error_mark_node
;
6040 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
6043 /* Parse a postfix expression after a parenthesized type name: the
6044 brace-enclosed initializer of a compound literal, possibly followed
6045 by some postfix operators. This is separate because it is not
6046 possible to tell until after the type name whether a cast
6047 expression has a cast or a compound literal, or whether the operand
6048 of sizeof is a parenthesized type name or starts with a compound
6049 literal. TYPE_LOC is the location where TYPE_NAME starts--the
6050 location of the first token after the parentheses around the type
6053 static struct c_expr
6054 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
6055 struct c_type_name
*type_name
,
6056 location_t type_loc
)
6062 location_t start_loc
;
6063 tree type_expr
= NULL_TREE
;
6064 bool type_expr_const
= true;
6065 check_compound_literal_type (type_loc
, type_name
);
6066 start_init (NULL_TREE
, NULL
, 0);
6067 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
6068 start_loc
= c_parser_peek_token (parser
)->location
;
6069 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
6071 error_at (type_loc
, "compound literal has variable size");
6072 type
= error_mark_node
;
6074 init
= c_parser_braced_init (parser
, type
, false);
6076 maybe_warn_string_init (type
, init
);
6078 if (type
!= error_mark_node
6079 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
6080 && current_function_decl
)
6082 error ("compound literal qualified by address-space qualifier");
6083 type
= error_mark_node
;
6087 pedwarn (start_loc
, OPT_pedantic
, "ISO C90 forbids compound literals");
6088 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
6089 ? CONSTRUCTOR_NON_CONST (init
.value
)
6090 : init
.original_code
== C_MAYBE_CONST_EXPR
);
6091 non_const
|= !type_expr_const
;
6092 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
6093 expr
.original_code
= ERROR_MARK
;
6094 expr
.original_type
= NULL
;
6097 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
6099 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
6100 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
6104 gcc_assert (!non_const
);
6105 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
6106 type_expr
, expr
.value
);
6109 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
6112 /* Parse a postfix expression after the initial primary or compound
6113 literal; that is, parse a series of postfix operators.
6115 EXPR_LOC is the location of the primary expression. */
6117 static struct c_expr
6118 c_parser_postfix_expression_after_primary (c_parser
*parser
,
6119 location_t expr_loc
,
6122 struct c_expr orig_expr
;
6124 VEC(tree
,gc
) *exprlist
;
6125 VEC(tree
,gc
) *origtypes
;
6128 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6129 switch (c_parser_peek_token (parser
)->type
)
6131 case CPP_OPEN_SQUARE
:
6132 /* Array reference. */
6133 c_parser_consume_token (parser
);
6134 idx
= c_parser_expression (parser
).value
;
6135 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6137 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
6138 expr
.original_code
= ERROR_MARK
;
6139 expr
.original_type
= NULL
;
6141 case CPP_OPEN_PAREN
:
6142 /* Function call. */
6143 c_parser_consume_token (parser
);
6144 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6147 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
);
6148 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6151 mark_exp_read (expr
.value
);
6152 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
6153 "(" after the FUNCNAME, which is what we have now. */
6154 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
6156 expr
.original_code
= ERROR_MARK
;
6157 if (TREE_CODE (expr
.value
) == INTEGER_CST
6158 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
6159 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
6160 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
6161 expr
.original_code
= C_MAYBE_CONST_EXPR
;
6162 expr
.original_type
= NULL
;
6163 if (exprlist
!= NULL
)
6165 release_tree_vector (exprlist
);
6166 release_tree_vector (origtypes
);
6170 /* Structure element reference. */
6171 c_parser_consume_token (parser
);
6172 expr
= default_function_array_conversion (expr_loc
, expr
);
6173 if (c_parser_next_token_is (parser
, CPP_NAME
))
6174 ident
= c_parser_peek_token (parser
)->value
;
6177 c_parser_error (parser
, "expected identifier");
6178 expr
.value
= error_mark_node
;
6179 expr
.original_code
= ERROR_MARK
;
6180 expr
.original_type
= NULL
;
6183 c_parser_consume_token (parser
);
6184 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
6185 expr
.original_code
= ERROR_MARK
;
6186 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6187 expr
.original_type
= NULL
;
6190 /* Remember the original type of a bitfield. */
6191 tree field
= TREE_OPERAND (expr
.value
, 1);
6192 if (TREE_CODE (field
) != FIELD_DECL
)
6193 expr
.original_type
= NULL
;
6195 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6199 /* Structure element reference. */
6200 c_parser_consume_token (parser
);
6201 expr
= default_function_array_conversion (expr_loc
, expr
);
6202 if (c_parser_next_token_is (parser
, CPP_NAME
))
6203 ident
= c_parser_peek_token (parser
)->value
;
6206 c_parser_error (parser
, "expected identifier");
6207 expr
.value
= error_mark_node
;
6208 expr
.original_code
= ERROR_MARK
;
6209 expr
.original_type
= NULL
;
6212 c_parser_consume_token (parser
);
6213 expr
.value
= build_component_ref (op_loc
,
6214 build_indirect_ref (op_loc
,
6218 expr
.original_code
= ERROR_MARK
;
6219 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
6220 expr
.original_type
= NULL
;
6223 /* Remember the original type of a bitfield. */
6224 tree field
= TREE_OPERAND (expr
.value
, 1);
6225 if (TREE_CODE (field
) != FIELD_DECL
)
6226 expr
.original_type
= NULL
;
6228 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
6232 /* Postincrement. */
6233 c_parser_consume_token (parser
);
6234 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6235 expr
.value
= build_unary_op (op_loc
,
6236 POSTINCREMENT_EXPR
, expr
.value
, 0);
6237 expr
.original_code
= ERROR_MARK
;
6238 expr
.original_type
= NULL
;
6240 case CPP_MINUS_MINUS
:
6241 /* Postdecrement. */
6242 c_parser_consume_token (parser
);
6243 expr
= default_function_array_read_conversion (expr_loc
, expr
);
6244 expr
.value
= build_unary_op (op_loc
,
6245 POSTDECREMENT_EXPR
, expr
.value
, 0);
6246 expr
.original_code
= ERROR_MARK
;
6247 expr
.original_type
= NULL
;
6255 /* Parse an expression (C90 6.3.17, C99 6.5.17).
6258 assignment-expression
6259 expression , assignment-expression
6262 static struct c_expr
6263 c_parser_expression (c_parser
*parser
)
6266 expr
= c_parser_expr_no_commas (parser
, NULL
);
6267 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6271 location_t loc
= c_parser_peek_token (parser
)->location
;
6272 location_t expr_loc
;
6273 c_parser_consume_token (parser
);
6274 expr_loc
= c_parser_peek_token (parser
)->location
;
6275 lhsval
= expr
.value
;
6276 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
6277 lhsval
= TREE_OPERAND (lhsval
, 1);
6278 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
6279 mark_exp_read (lhsval
);
6280 next
= c_parser_expr_no_commas (parser
, NULL
);
6281 next
= default_function_array_conversion (expr_loc
, next
);
6282 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
6283 expr
.original_code
= COMPOUND_EXPR
;
6284 expr
.original_type
= next
.original_type
;
6289 /* Parse an expression and convert functions or arrays to
6292 static struct c_expr
6293 c_parser_expression_conv (c_parser
*parser
)
6296 location_t loc
= c_parser_peek_token (parser
)->location
;
6297 expr
= c_parser_expression (parser
);
6298 expr
= default_function_array_conversion (loc
, expr
);
6302 /* Parse a non-empty list of expressions. If CONVERT_P, convert
6303 functions and arrays to pointers. If FOLD_P, fold the expressions.
6306 assignment-expression
6307 nonempty-expr-list , assignment-expression
6310 static VEC(tree
,gc
) *
6311 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
6312 VEC(tree
,gc
) **p_orig_types
)
6315 VEC(tree
,gc
) *orig_types
;
6317 location_t loc
= c_parser_peek_token (parser
)->location
;
6319 ret
= make_tree_vector ();
6320 if (p_orig_types
== NULL
)
6323 orig_types
= make_tree_vector ();
6325 expr
= c_parser_expr_no_commas (parser
, NULL
);
6327 expr
= default_function_array_read_conversion (loc
, expr
);
6329 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6330 VEC_quick_push (tree
, ret
, expr
.value
);
6331 if (orig_types
!= NULL
)
6332 VEC_quick_push (tree
, orig_types
, expr
.original_type
);
6333 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6335 c_parser_consume_token (parser
);
6336 loc
= c_parser_peek_token (parser
)->location
;
6337 expr
= c_parser_expr_no_commas (parser
, NULL
);
6339 expr
= default_function_array_read_conversion (loc
, expr
);
6341 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
6342 VEC_safe_push (tree
, gc
, ret
, expr
.value
);
6343 if (orig_types
!= NULL
)
6344 VEC_safe_push (tree
, gc
, orig_types
, expr
.original_type
);
6346 if (orig_types
!= NULL
)
6347 *p_orig_types
= orig_types
;
6351 /* Parse Objective-C-specific constructs. */
6353 /* Parse an objc-class-definition.
6355 objc-class-definition:
6356 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
6357 objc-class-instance-variables[opt] objc-methodprotolist @end
6358 @implementation identifier objc-superclass[opt]
6359 objc-class-instance-variables[opt]
6360 @interface identifier ( identifier ) objc-protocol-refs[opt]
6361 objc-methodprotolist @end
6362 @implementation identifier ( identifier )
6367 "@interface identifier (" must start "@interface identifier (
6368 identifier ) ...": objc-methodprotolist in the first production may
6369 not start with a parenthesized identifier as a declarator of a data
6370 definition with no declaration specifiers if the objc-superclass,
6371 objc-protocol-refs and objc-class-instance-variables are omitted. */
6374 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
6379 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
6381 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
6386 c_parser_consume_token (parser
);
6387 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6389 c_parser_error (parser
, "expected identifier");
6392 id1
= c_parser_peek_token (parser
)->value
;
6393 c_parser_consume_token (parser
);
6394 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6397 tree proto
= NULL_TREE
;
6398 c_parser_consume_token (parser
);
6399 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6401 c_parser_error (parser
, "expected identifier");
6402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6405 id2
= c_parser_peek_token (parser
)->value
;
6406 c_parser_consume_token (parser
);
6407 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6410 objc_start_category_implementation (id1
, id2
);
6413 if (c_parser_next_token_is (parser
, CPP_LESS
))
6414 proto
= c_parser_objc_protocol_refs (parser
);
6415 objc_start_category_interface (id1
, id2
, proto
, attributes
);
6416 c_parser_objc_methodprotolist (parser
);
6417 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6418 objc_finish_interface ();
6421 if (c_parser_next_token_is (parser
, CPP_COLON
))
6423 c_parser_consume_token (parser
);
6424 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6426 c_parser_error (parser
, "expected identifier");
6429 superclass
= c_parser_peek_token (parser
)->value
;
6430 c_parser_consume_token (parser
);
6433 superclass
= NULL_TREE
;
6436 tree proto
= NULL_TREE
;
6437 if (c_parser_next_token_is (parser
, CPP_LESS
))
6438 proto
= c_parser_objc_protocol_refs (parser
);
6439 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
6442 objc_start_class_implementation (id1
, superclass
);
6443 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6444 c_parser_objc_class_instance_variables (parser
);
6447 objc_continue_interface ();
6448 c_parser_objc_methodprotolist (parser
);
6449 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6450 objc_finish_interface ();
6454 objc_continue_implementation ();
6459 /* Parse objc-class-instance-variables.
6461 objc-class-instance-variables:
6462 { objc-instance-variable-decl-list[opt] }
6464 objc-instance-variable-decl-list:
6465 objc-visibility-spec
6466 objc-instance-variable-decl ;
6468 objc-instance-variable-decl-list objc-visibility-spec
6469 objc-instance-variable-decl-list objc-instance-variable-decl ;
6470 objc-instance-variable-decl-list ;
6472 objc-visibility-spec:
6477 objc-instance-variable-decl:
6482 c_parser_objc_class_instance_variables (c_parser
*parser
)
6484 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
6485 c_parser_consume_token (parser
);
6486 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
6489 /* Parse any stray semicolon. */
6490 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6492 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6493 "extra semicolon in struct or union specified");
6494 c_parser_consume_token (parser
);
6497 /* Stop if at the end of the instance variables. */
6498 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
6500 c_parser_consume_token (parser
);
6503 /* Parse any objc-visibility-spec. */
6504 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
6506 c_parser_consume_token (parser
);
6507 objc_set_visibility (2);
6510 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
6512 c_parser_consume_token (parser
);
6513 objc_set_visibility (0);
6516 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
6518 c_parser_consume_token (parser
);
6519 objc_set_visibility (1);
6522 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
6524 c_parser_pragma (parser
, pragma_external
);
6528 /* Parse some comma-separated declarations. */
6529 decls
= c_parser_struct_declaration (parser
);
6531 /* Comma-separated instance variables are chained together in
6532 reverse order; add them one by one. */
6533 tree ivar
= nreverse (decls
);
6534 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
6535 objc_add_instance_variable (copy_node (ivar
));
6537 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6541 /* Parse an objc-class-declaration.
6543 objc-class-declaration:
6544 @class identifier-list ;
6548 c_parser_objc_class_declaration (c_parser
*parser
)
6550 tree list
= NULL_TREE
;
6551 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
6552 c_parser_consume_token (parser
);
6553 /* Any identifiers, including those declared as type names, are OK
6558 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6560 c_parser_error (parser
, "expected identifier");
6563 id
= c_parser_peek_token (parser
)->value
;
6564 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6565 c_parser_consume_token (parser
);
6566 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6567 c_parser_consume_token (parser
);
6571 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6572 objc_declare_class (list
);
6575 /* Parse an objc-alias-declaration.
6577 objc-alias-declaration:
6578 @compatibility_alias identifier identifier ;
6582 c_parser_objc_alias_declaration (c_parser
*parser
)
6585 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
6586 c_parser_consume_token (parser
);
6587 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6589 c_parser_error (parser
, "expected identifier");
6590 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6593 id1
= c_parser_peek_token (parser
)->value
;
6594 c_parser_consume_token (parser
);
6595 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6597 c_parser_error (parser
, "expected identifier");
6598 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
6601 id2
= c_parser_peek_token (parser
)->value
;
6602 c_parser_consume_token (parser
);
6603 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6604 objc_declare_alias (id1
, id2
);
6607 /* Parse an objc-protocol-definition.
6609 objc-protocol-definition:
6610 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
6611 @protocol identifier-list ;
6613 "@protocol identifier ;" should be resolved as "@protocol
6614 identifier-list ;": objc-methodprotolist may not start with a
6615 semicolon in the first alternative if objc-protocol-refs are
6619 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
6621 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
6623 c_parser_consume_token (parser
);
6624 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6626 c_parser_error (parser
, "expected identifier");
6629 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
6630 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
6632 tree list
= NULL_TREE
;
6633 /* Any identifiers, including those declared as type names, are
6638 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6640 c_parser_error (parser
, "expected identifier");
6643 id
= c_parser_peek_token (parser
)->value
;
6644 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6645 c_parser_consume_token (parser
);
6646 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6647 c_parser_consume_token (parser
);
6651 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6652 objc_declare_protocols (list
);
6656 tree id
= c_parser_peek_token (parser
)->value
;
6657 tree proto
= NULL_TREE
;
6658 c_parser_consume_token (parser
);
6659 if (c_parser_next_token_is (parser
, CPP_LESS
))
6660 proto
= c_parser_objc_protocol_refs (parser
);
6661 parser
->objc_pq_context
= true;
6662 objc_start_protocol (id
, proto
, attributes
);
6663 c_parser_objc_methodprotolist (parser
);
6664 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
6665 parser
->objc_pq_context
= false;
6666 objc_finish_interface ();
6670 /* Parse an objc-method-type.
6677 static enum tree_code
6678 c_parser_objc_method_type (c_parser
*parser
)
6680 switch (c_parser_peek_token (parser
)->type
)
6683 c_parser_consume_token (parser
);
6686 c_parser_consume_token (parser
);
6693 /* Parse an objc-method-definition.
6695 objc-method-definition:
6696 objc-method-type objc-method-decl ;[opt] compound-statement
6700 c_parser_objc_method_definition (c_parser
*parser
)
6702 enum tree_code type
= c_parser_objc_method_type (parser
);
6703 tree decl
, attributes
= NULL_TREE
;
6704 objc_set_method_type (type
);
6705 parser
->objc_pq_context
= true;
6706 decl
= c_parser_objc_method_decl (parser
, &attributes
);
6707 if (decl
== error_mark_node
)
6708 return; /* Bail here. */
6710 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6712 c_parser_consume_token (parser
);
6713 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6714 "extra semicolon in method definition specified");
6717 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6719 c_parser_error (parser
, "expected %<{%>");
6723 parser
->objc_pq_context
= false;
6724 if (objc_start_method_definition (decl
, attributes
))
6726 add_stmt (c_parser_compound_statement (parser
));
6727 objc_finish_method_definition (current_function_decl
);
6731 /* This code is executed when we find a method definition
6732 outside of an @implementation context. Parse the method (to
6733 keep going) but do not emit any code.
6735 c_parser_compound_statement (parser
);
6739 /* Parse an objc-methodprotolist.
6741 objc-methodprotolist:
6743 objc-methodprotolist objc-methodproto
6744 objc-methodprotolist declaration
6745 objc-methodprotolist ;
6749 The declaration is a data definition, which may be missing
6750 declaration specifiers under the same rules and diagnostics as
6751 other data definitions outside functions, and the stray semicolon
6752 is diagnosed the same way as a stray semicolon outside a
6756 c_parser_objc_methodprotolist (c_parser
*parser
)
6760 /* The list is terminated by @end. */
6761 switch (c_parser_peek_token (parser
)->type
)
6764 pedwarn (c_parser_peek_token (parser
)->location
, OPT_pedantic
,
6765 "ISO C does not allow extra %<;%> outside of a function");
6766 c_parser_consume_token (parser
);
6770 c_parser_objc_methodproto (parser
);
6773 c_parser_pragma (parser
, pragma_external
);
6778 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6780 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
6782 objc_set_method_opt (true);
6783 c_parser_consume_token (parser
);
6785 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
6787 objc_set_method_opt (false);
6788 c_parser_consume_token (parser
);
6791 c_parser_declaration_or_fndef (parser
, false, false, true,
6798 /* Parse an objc-methodproto.
6801 objc-method-type objc-method-decl ;
6805 c_parser_objc_methodproto (c_parser
*parser
)
6807 enum tree_code type
= c_parser_objc_method_type (parser
);
6808 tree decl
, attributes
= NULL_TREE
;
6809 objc_set_method_type (type
);
6810 /* Remember protocol qualifiers in prototypes. */
6811 parser
->objc_pq_context
= true;
6812 decl
= c_parser_objc_method_decl (parser
, &attributes
);
6813 /* Forget protocol qualifiers now. */
6814 parser
->objc_pq_context
= false;
6816 /* Do not allow the presence of attributes to hide an erroneous
6817 method implementation in the interface section. */
6818 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6820 c_parser_error (parser
, "expected %<;%>");
6824 if (decl
!= error_mark_node
)
6825 objc_add_method_declaration (decl
, attributes
);
6827 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6830 /* If we are at a position that method attributes may be present, check that
6831 there are not any parsed already (a syntax error) and then collect any
6832 specified at the current location. Finally, if new attributes were present,
6833 check that the next token is legal ( ';' for decls and '{' for defs). */
6836 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
6841 c_parser_error (parser
,
6842 "method attributes must be specified at the end only");
6843 *attributes
= NULL_TREE
;
6847 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
6848 *attributes
= c_parser_attributes (parser
);
6850 /* If there were no attributes here, just report any earlier error. */
6851 if (*attributes
== NULL_TREE
|| bad
)
6854 /* If the attributes are followed by a ; or {, then just report any earlier
6856 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
6857 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6860 /* We've got attributes, but not at the end. */
6861 c_parser_error (parser
,
6862 "expected %<;%> or %<{%> after method attribute definition");
6866 /* Parse an objc-method-decl.
6869 ( objc-type-name ) objc-selector
6871 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6872 objc-keyword-selector objc-optparmlist
6875 objc-keyword-selector:
6877 objc-keyword-selector objc-keyword-decl
6880 objc-selector : ( objc-type-name ) identifier
6881 objc-selector : identifier
6882 : ( objc-type-name ) identifier
6886 objc-optparms objc-optellipsis
6890 objc-opt-parms , parameter-declaration
6898 c_parser_objc_method_decl (c_parser
*parser
, tree
*attributes
)
6900 tree type
= NULL_TREE
;
6902 tree parms
= NULL_TREE
;
6903 bool ellipsis
= false;
6904 bool attr_err
= false;
6906 *attributes
= NULL_TREE
;
6907 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6909 c_parser_consume_token (parser
);
6910 type
= c_parser_objc_type_name (parser
);
6911 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6913 sel
= c_parser_objc_selector (parser
);
6914 /* If there is no selector, or a colon follows, we have an
6915 objc-keyword-selector. If there is a selector, and a colon does
6916 not follow, that selector ends the objc-method-decl. */
6917 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6920 tree list
= NULL_TREE
;
6923 tree atype
= NULL_TREE
, id
, keyworddecl
;
6924 tree param_attr
= NULL_TREE
;
6925 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6927 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6929 c_parser_consume_token (parser
);
6930 atype
= c_parser_objc_type_name (parser
);
6931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6934 /* New ObjC allows attributes on method parameters. */
6935 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
6936 param_attr
= c_parser_attributes (parser
);
6937 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6939 c_parser_error (parser
, "expected identifier");
6940 return error_mark_node
;
6942 id
= c_parser_peek_token (parser
)->value
;
6943 c_parser_consume_token (parser
);
6944 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
6945 list
= chainon (list
, keyworddecl
);
6946 tsel
= c_parser_objc_selector (parser
);
6947 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6951 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
6953 /* Parse the optional parameter list. Optional Objective-C
6954 method parameters follow the C syntax, and may include '...'
6955 to denote a variable number of arguments. */
6956 parms
= make_node (TREE_LIST
);
6957 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6959 struct c_parm
*parm
;
6960 c_parser_consume_token (parser
);
6961 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6964 c_parser_consume_token (parser
);
6965 attr_err
|= c_parser_objc_maybe_method_attributes
6966 (parser
, attributes
) ;
6969 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6972 parms
= chainon (parms
,
6973 build_tree_list (NULL_TREE
, grokparm (parm
)));
6978 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
6982 c_parser_error (parser
, "objective-c method declaration is expected");
6983 return error_mark_node
;
6987 return error_mark_node
;
6989 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6992 /* Parse an objc-type-name.
6995 objc-type-qualifiers[opt] type-name
6996 objc-type-qualifiers[opt]
6998 objc-type-qualifiers:
7000 objc-type-qualifiers objc-type-qualifier
7002 objc-type-qualifier: one of
7003 in out inout bycopy byref oneway
7007 c_parser_objc_type_name (c_parser
*parser
)
7009 tree quals
= NULL_TREE
;
7010 struct c_type_name
*type_name
= NULL
;
7011 tree type
= NULL_TREE
;
7014 c_token
*token
= c_parser_peek_token (parser
);
7015 if (token
->type
== CPP_KEYWORD
7016 && (token
->keyword
== RID_IN
7017 || token
->keyword
== RID_OUT
7018 || token
->keyword
== RID_INOUT
7019 || token
->keyword
== RID_BYCOPY
7020 || token
->keyword
== RID_BYREF
7021 || token
->keyword
== RID_ONEWAY
))
7023 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
7024 c_parser_consume_token (parser
);
7029 if (c_parser_next_token_starts_typename (parser
))
7030 type_name
= c_parser_type_name (parser
);
7032 type
= groktypename (type_name
, NULL
, NULL
);
7033 return build_tree_list (quals
, type
);
7036 /* Parse objc-protocol-refs.
7043 c_parser_objc_protocol_refs (c_parser
*parser
)
7045 tree list
= NULL_TREE
;
7046 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
7047 c_parser_consume_token (parser
);
7048 /* Any identifiers, including those declared as type names, are OK
7053 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7055 c_parser_error (parser
, "expected identifier");
7058 id
= c_parser_peek_token (parser
)->value
;
7059 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
7060 c_parser_consume_token (parser
);
7061 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7062 c_parser_consume_token (parser
);
7066 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
7070 /* Parse an objc-try-catch-statement.
7072 objc-try-catch-statement:
7073 @try compound-statement objc-catch-list[opt]
7074 @try compound-statement objc-catch-list[opt] @finally compound-statement
7077 @catch ( parameter-declaration ) compound-statement
7078 objc-catch-list @catch ( parameter-declaration ) compound-statement
7082 c_parser_objc_try_catch_statement (c_parser
*parser
)
7086 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
7087 c_parser_consume_token (parser
);
7088 loc
= c_parser_peek_token (parser
)->location
;
7089 stmt
= c_parser_compound_statement (parser
);
7090 objc_begin_try_stmt (loc
, stmt
);
7091 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
7093 struct c_parm
*parm
;
7094 c_parser_consume_token (parser
);
7095 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7097 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
7100 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7104 objc_begin_catch_clause (grokparm (parm
));
7105 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7106 c_parser_compound_statement_nostart (parser
);
7107 objc_finish_catch_clause ();
7109 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
7113 c_parser_consume_token (parser
);
7114 finloc
= c_parser_peek_token (parser
)->location
;
7115 finstmt
= c_parser_compound_statement (parser
);
7116 objc_build_finally_clause (finloc
, finstmt
);
7118 objc_finish_try_stmt ();
7121 /* Parse an objc-synchronized-statement.
7123 objc-synchronized-statement:
7124 @synchronized ( expression ) compound-statement
7128 c_parser_objc_synchronized_statement (c_parser
*parser
)
7132 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
7133 c_parser_consume_token (parser
);
7134 loc
= c_parser_peek_token (parser
)->location
;
7135 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7137 expr
= c_parser_expression (parser
).value
;
7138 expr
= c_fully_fold (expr
, false, NULL
);
7139 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7142 expr
= error_mark_node
;
7143 stmt
= c_parser_compound_statement (parser
);
7144 objc_build_synchronized (loc
, expr
, stmt
);
7147 /* Parse an objc-selector; return NULL_TREE without an error if the
7148 next token is not an objc-selector.
7153 enum struct union if else while do for switch case default
7154 break continue return goto asm sizeof typeof __alignof
7155 unsigned long const short volatile signed restrict _Complex
7156 in out inout bycopy byref oneway int char float double void _Bool
7158 ??? Why this selection of keywords but not, for example, storage
7159 class specifiers? */
7162 c_parser_objc_selector (c_parser
*parser
)
7164 c_token
*token
= c_parser_peek_token (parser
);
7165 tree value
= token
->value
;
7166 if (token
->type
== CPP_NAME
)
7168 c_parser_consume_token (parser
);
7171 if (token
->type
!= CPP_KEYWORD
)
7173 switch (token
->keyword
)
7215 c_parser_consume_token (parser
);
7222 /* Parse an objc-selector-arg.
7226 objc-keywordname-list
7228 objc-keywordname-list:
7230 objc-keywordname-list objc-keywordname
7238 c_parser_objc_selector_arg (c_parser
*parser
)
7240 tree sel
= c_parser_objc_selector (parser
);
7241 tree list
= NULL_TREE
;
7242 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7246 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7248 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
7249 sel
= c_parser_objc_selector (parser
);
7250 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7256 /* Parse an objc-receiver.
7265 c_parser_objc_receiver (c_parser
*parser
)
7267 if (c_parser_peek_token (parser
)->type
== CPP_NAME
7268 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
7269 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
7271 tree id
= c_parser_peek_token (parser
)->value
;
7272 c_parser_consume_token (parser
);
7273 return objc_get_class_reference (id
);
7275 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
7278 /* Parse objc-message-args.
7282 objc-keywordarg-list
7284 objc-keywordarg-list:
7286 objc-keywordarg-list objc-keywordarg
7289 objc-selector : objc-keywordexpr
7294 c_parser_objc_message_args (c_parser
*parser
)
7296 tree sel
= c_parser_objc_selector (parser
);
7297 tree list
= NULL_TREE
;
7298 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7303 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7304 return error_mark_node
;
7305 keywordexpr
= c_parser_objc_keywordexpr (parser
);
7306 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
7307 sel
= c_parser_objc_selector (parser
);
7308 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
7314 /* Parse an objc-keywordexpr.
7321 c_parser_objc_keywordexpr (c_parser
*parser
)
7324 VEC(tree
,gc
) *expr_list
= c_parser_expr_list (parser
, true, true, NULL
);
7325 if (VEC_length (tree
, expr_list
) == 1)
7327 /* Just return the expression, remove a level of
7329 ret
= VEC_index (tree
, expr_list
, 0);
7333 /* We have a comma expression, we will collapse later. */
7334 ret
= build_tree_list_vec (expr_list
);
7336 release_tree_vector (expr_list
);
7340 /* A check, needed in several places, that ObjC interface, implementation or
7341 method definitions are not prefixed by incorrect items. */
7343 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
7344 struct c_declspecs
*specs
)
7346 if (!specs
->declspecs_seen_p
|| specs
->type_seen_p
|| specs
->non_sc_seen_p
)
7348 c_parser_error (parser
,
7349 "no type or storage class may be specified here,");
7350 c_parser_skip_to_end_of_block_or_statement (parser
);
7356 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
7357 should be considered, statements. ALLOW_STMT is true if we're within
7358 the context of a function and such pragmas are to be allowed. Returns
7359 true if we actually parsed such a pragma. */
7362 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
7366 id
= c_parser_peek_token (parser
)->pragma_kind
;
7367 gcc_assert (id
!= PRAGMA_NONE
);
7371 case PRAGMA_OMP_BARRIER
:
7372 if (context
!= pragma_compound
)
7374 if (context
== pragma_stmt
)
7375 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
7376 "used in compound statements");
7379 c_parser_omp_barrier (parser
);
7382 case PRAGMA_OMP_FLUSH
:
7383 if (context
!= pragma_compound
)
7385 if (context
== pragma_stmt
)
7386 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
7387 "used in compound statements");
7390 c_parser_omp_flush (parser
);
7393 case PRAGMA_OMP_TASKWAIT
:
7394 if (context
!= pragma_compound
)
7396 if (context
== pragma_stmt
)
7397 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
7398 "used in compound statements");
7401 c_parser_omp_taskwait (parser
);
7404 case PRAGMA_OMP_THREADPRIVATE
:
7405 c_parser_omp_threadprivate (parser
);
7408 case PRAGMA_OMP_SECTION
:
7409 error_at (c_parser_peek_token (parser
)->location
,
7410 "%<#pragma omp section%> may only be used in "
7411 "%<#pragma omp sections%> construct");
7412 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7415 case PRAGMA_GCC_PCH_PREPROCESS
:
7416 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
7417 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7421 if (id
< PRAGMA_FIRST_EXTERNAL
)
7423 if (context
== pragma_external
)
7426 c_parser_error (parser
, "expected declaration specifiers");
7427 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
7430 c_parser_omp_construct (parser
);
7436 c_parser_consume_pragma (parser
);
7437 c_invoke_pragma_handler (id
);
7439 /* Skip to EOL, but suppress any error message. Those will have been
7440 generated by the handler routine through calling error, as opposed
7441 to calling c_parser_error. */
7442 parser
->error
= true;
7443 c_parser_skip_to_pragma_eol (parser
);
7448 /* The interface the pragma parsers have to the lexer. */
7451 pragma_lex (tree
*value
)
7453 c_token
*tok
= c_parser_peek_token (the_parser
);
7454 enum cpp_ttype ret
= tok
->type
;
7456 *value
= tok
->value
;
7457 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
7461 if (ret
== CPP_KEYWORD
)
7463 c_parser_consume_token (the_parser
);
7470 c_parser_pragma_pch_preprocess (c_parser
*parser
)
7474 c_parser_consume_pragma (parser
);
7475 if (c_parser_next_token_is (parser
, CPP_STRING
))
7477 name
= c_parser_peek_token (parser
)->value
;
7478 c_parser_consume_token (parser
);
7481 c_parser_error (parser
, "expected string literal");
7482 c_parser_skip_to_pragma_eol (parser
);
7485 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
7488 /* OpenMP 2.5 parsing routines. */
7490 /* Returns name of the next clause.
7491 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
7492 the token is not consumed. Otherwise appropriate pragma_omp_clause is
7493 returned and the token is consumed. */
7495 static pragma_omp_clause
7496 c_parser_omp_clause_name (c_parser
*parser
)
7498 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
7500 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
7501 result
= PRAGMA_OMP_CLAUSE_IF
;
7502 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
7503 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
7504 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7506 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7511 if (!strcmp ("collapse", p
))
7512 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
7513 else if (!strcmp ("copyin", p
))
7514 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
7515 else if (!strcmp ("copyprivate", p
))
7516 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
7519 if (!strcmp ("firstprivate", p
))
7520 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
7523 if (!strcmp ("lastprivate", p
))
7524 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
7527 if (!strcmp ("nowait", p
))
7528 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
7529 else if (!strcmp ("num_threads", p
))
7530 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
7533 if (!strcmp ("ordered", p
))
7534 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
7537 if (!strcmp ("private", p
))
7538 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
7541 if (!strcmp ("reduction", p
))
7542 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
7545 if (!strcmp ("schedule", p
))
7546 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
7547 else if (!strcmp ("shared", p
))
7548 result
= PRAGMA_OMP_CLAUSE_SHARED
;
7551 if (!strcmp ("untied", p
))
7552 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
7557 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
7558 c_parser_consume_token (parser
);
7563 /* Validate that a clause of the given type does not already exist. */
7566 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
7571 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7572 if (OMP_CLAUSE_CODE (c
) == code
)
7574 location_t loc
= OMP_CLAUSE_LOCATION (c
);
7575 error_at (loc
, "too many %qs clauses", name
);
7583 variable-list , identifier
7585 If KIND is nonzero, create the appropriate node and install the
7586 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
7587 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
7589 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
7590 return the list created. */
7593 c_parser_omp_variable_list (c_parser
*parser
,
7594 location_t clause_loc
,
7595 enum omp_clause_code kind
,
7598 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
7599 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
7600 c_parser_error (parser
, "expected identifier");
7602 while (c_parser_next_token_is (parser
, CPP_NAME
)
7603 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
7605 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
7608 undeclared_variable (c_parser_peek_token (parser
)->location
,
7609 c_parser_peek_token (parser
)->value
);
7610 else if (t
== error_mark_node
)
7614 tree u
= build_omp_clause (clause_loc
, kind
);
7615 OMP_CLAUSE_DECL (u
) = t
;
7616 OMP_CLAUSE_CHAIN (u
) = list
;
7620 list
= tree_cons (t
, NULL_TREE
, list
);
7622 c_parser_consume_token (parser
);
7624 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
7627 c_parser_consume_token (parser
);
7633 /* Similarly, but expect leading and trailing parenthesis. This is a very
7634 common case for omp clauses. */
7637 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
7640 /* The clauses location. */
7641 location_t loc
= c_parser_peek_token (parser
)->location
;
7643 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7645 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
7646 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7652 collapse ( constant-expression ) */
7655 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
7657 tree c
, num
= error_mark_node
;
7661 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
7663 loc
= c_parser_peek_token (parser
)->location
;
7664 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7666 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
7667 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7669 if (num
== error_mark_node
)
7671 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
7672 || !host_integerp (num
, 0)
7673 || (n
= tree_low_cst (num
, 0)) <= 0
7677 "collapse argument needs positive constant integer expression");
7680 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
7681 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
7682 OMP_CLAUSE_CHAIN (c
) = list
;
7687 copyin ( variable-list ) */
7690 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
7692 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
7696 copyprivate ( variable-list ) */
7699 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
7701 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
7705 default ( shared | none ) */
7708 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
7710 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
7711 location_t loc
= c_parser_peek_token (parser
)->location
;
7714 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7716 if (c_parser_next_token_is (parser
, CPP_NAME
))
7718 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7723 if (strcmp ("none", p
) != 0)
7725 kind
= OMP_CLAUSE_DEFAULT_NONE
;
7729 if (strcmp ("shared", p
) != 0)
7731 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
7738 c_parser_consume_token (parser
);
7743 c_parser_error (parser
, "expected %<none%> or %<shared%>");
7745 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7747 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
7750 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
7751 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
7752 OMP_CLAUSE_CHAIN (c
) = list
;
7753 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
7759 firstprivate ( variable-list ) */
7762 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
7764 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
7768 if ( expression ) */
7771 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
7773 location_t loc
= c_parser_peek_token (parser
)->location
;
7774 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7776 tree t
= c_parser_paren_condition (parser
);
7779 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
7781 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
7782 OMP_CLAUSE_IF_EXPR (c
) = t
;
7783 OMP_CLAUSE_CHAIN (c
) = list
;
7787 c_parser_error (parser
, "expected %<(%>");
7793 lastprivate ( variable-list ) */
7796 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
7798 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
7805 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
7808 location_t loc
= c_parser_peek_token (parser
)->location
;
7810 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
7812 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
7813 OMP_CLAUSE_CHAIN (c
) = list
;
7818 num_threads ( expression ) */
7821 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
7823 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
7824 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7826 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7827 tree c
, t
= c_parser_expression (parser
).value
;
7828 t
= c_fully_fold (t
, false, NULL
);
7830 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7832 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7834 c_parser_error (parser
, "expected integer expression");
7838 /* Attempt to statically determine when the number isn't positive. */
7839 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
7840 build_int_cst (TREE_TYPE (t
), 0));
7841 if (CAN_HAVE_LOCATION_P (c
))
7842 SET_EXPR_LOCATION (c
, expr_loc
);
7843 if (c
== boolean_true_node
)
7845 warning_at (expr_loc
, 0,
7846 "%<num_threads%> value must be positive");
7847 t
= integer_one_node
;
7850 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
7852 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
7853 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
7854 OMP_CLAUSE_CHAIN (c
) = list
;
7865 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
7869 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
7871 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
7872 OMP_CLAUSE_ORDERED
);
7873 OMP_CLAUSE_CHAIN (c
) = list
;
7879 private ( variable-list ) */
7882 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
7884 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
7888 reduction ( reduction-operator : variable-list )
7891 One of: + * - & ^ | && || */
7894 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
7896 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
7897 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7899 enum tree_code code
;
7901 switch (c_parser_peek_token (parser
)->type
)
7913 code
= BIT_AND_EXPR
;
7916 code
= BIT_XOR_EXPR
;
7919 code
= BIT_IOR_EXPR
;
7922 code
= TRUTH_ANDIF_EXPR
;
7925 code
= TRUTH_ORIF_EXPR
;
7928 c_parser_error (parser
,
7929 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7930 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7931 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7934 c_parser_consume_token (parser
);
7935 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7939 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
7940 OMP_CLAUSE_REDUCTION
, list
);
7941 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7942 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7952 schedule ( schedule-kind )
7953 schedule ( schedule-kind , expression )
7956 static | dynamic | guided | runtime | auto
7960 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7963 location_t loc
= c_parser_peek_token (parser
)->location
;
7965 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7968 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
7970 if (c_parser_next_token_is (parser
, CPP_NAME
))
7972 tree kind
= c_parser_peek_token (parser
)->value
;
7973 const char *p
= IDENTIFIER_POINTER (kind
);
7978 if (strcmp ("dynamic", p
) != 0)
7980 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7984 if (strcmp ("guided", p
) != 0)
7986 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7990 if (strcmp ("runtime", p
) != 0)
7992 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7999 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
8000 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
8001 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
8002 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
8006 c_parser_consume_token (parser
);
8007 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8010 c_parser_consume_token (parser
);
8012 here
= c_parser_peek_token (parser
)->location
;
8013 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
8014 t
= c_fully_fold (t
, false, NULL
);
8016 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
8017 error_at (here
, "schedule %<runtime%> does not take "
8018 "a %<chunk_size%> parameter");
8019 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
8021 "schedule %<auto%> does not take "
8022 "a %<chunk_size%> parameter");
8023 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
8024 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
8026 c_parser_error (parser
, "expected integer expression");
8028 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8032 "expected %<,%> or %<)%>");
8034 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
8035 OMP_CLAUSE_CHAIN (c
) = list
;
8039 c_parser_error (parser
, "invalid schedule kind");
8040 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
8045 shared ( variable-list ) */
8048 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
8050 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
8057 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
8061 /* FIXME: Should we allow duplicates? */
8062 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
8064 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
8066 OMP_CLAUSE_CHAIN (c
) = list
;
8071 /* Parse all OpenMP clauses. The set clauses allowed by the directive
8072 is a bitmask in MASK. Return the list of clauses found; the result
8073 of clause default goes in *pdefault. */
8076 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
8079 tree clauses
= NULL
;
8082 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8085 pragma_omp_clause c_kind
;
8087 tree prev
= clauses
;
8089 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
8090 c_parser_consume_token (parser
);
8093 here
= c_parser_peek_token (parser
)->location
;
8094 c_kind
= c_parser_omp_clause_name (parser
);
8098 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
8099 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
8100 c_name
= "collapse";
8102 case PRAGMA_OMP_CLAUSE_COPYIN
:
8103 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
8106 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
8107 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
8108 c_name
= "copyprivate";
8110 case PRAGMA_OMP_CLAUSE_DEFAULT
:
8111 clauses
= c_parser_omp_clause_default (parser
, clauses
);
8114 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
8115 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
8116 c_name
= "firstprivate";
8118 case PRAGMA_OMP_CLAUSE_IF
:
8119 clauses
= c_parser_omp_clause_if (parser
, clauses
);
8122 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
8123 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
8124 c_name
= "lastprivate";
8126 case PRAGMA_OMP_CLAUSE_NOWAIT
:
8127 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
8130 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
8131 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
8132 c_name
= "num_threads";
8134 case PRAGMA_OMP_CLAUSE_ORDERED
:
8135 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
8138 case PRAGMA_OMP_CLAUSE_PRIVATE
:
8139 clauses
= c_parser_omp_clause_private (parser
, clauses
);
8142 case PRAGMA_OMP_CLAUSE_REDUCTION
:
8143 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
8144 c_name
= "reduction";
8146 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
8147 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
8148 c_name
= "schedule";
8150 case PRAGMA_OMP_CLAUSE_SHARED
:
8151 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
8154 case PRAGMA_OMP_CLAUSE_UNTIED
:
8155 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
8159 c_parser_error (parser
, "expected %<#pragma omp%> clause");
8163 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
8165 /* Remove the invalid clause(s) from the list to avoid
8166 confusing the rest of the compiler. */
8168 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
8173 c_parser_skip_to_pragma_eol (parser
);
8175 return c_finish_omp_clauses (clauses
);
8182 In practice, we're also interested in adding the statement to an
8183 outer node. So it is convenient if we work around the fact that
8184 c_parser_statement calls add_stmt. */
8187 c_parser_omp_structured_block (c_parser
*parser
)
8189 tree stmt
= push_stmt_list ();
8190 c_parser_statement (parser
);
8191 return pop_stmt_list (stmt
);
8195 # pragma omp atomic new-line
8199 x binop= expr | x++ | ++x | x-- | --x
8201 +, *, -, /, &, ^, |, <<, >>
8203 where x is an lvalue expression with scalar type.
8205 LOC is the location of the #pragma token. */
8208 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
8212 enum tree_code code
;
8213 struct c_expr rhs_expr
;
8215 c_parser_skip_to_pragma_eol (parser
);
8217 lhs
= c_parser_unary_expression (parser
).value
;
8218 lhs
= c_fully_fold (lhs
, false, NULL
);
8219 switch (TREE_CODE (lhs
))
8223 c_parser_skip_to_end_of_block_or_statement (parser
);
8226 case PREINCREMENT_EXPR
:
8227 case POSTINCREMENT_EXPR
:
8228 lhs
= TREE_OPERAND (lhs
, 0);
8230 rhs
= integer_one_node
;
8233 case PREDECREMENT_EXPR
:
8234 case POSTDECREMENT_EXPR
:
8235 lhs
= TREE_OPERAND (lhs
, 0);
8237 rhs
= integer_one_node
;
8241 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
8242 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
8243 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
8244 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
8245 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
8246 (TREE_OPERAND (lhs
, 1), 0), 0)))
8248 /* Undo effects of boolean_increment for post {in,de}crement. */
8249 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
8252 if (TREE_CODE (lhs
) == MODIFY_EXPR
8253 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
8255 /* Undo effects of boolean_increment. */
8256 if (integer_onep (TREE_OPERAND (lhs
, 1)))
8258 /* This is pre or post increment. */
8259 rhs
= TREE_OPERAND (lhs
, 1);
8260 lhs
= TREE_OPERAND (lhs
, 0);
8264 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
8265 && TREE_OPERAND (lhs
, 0)
8266 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
8268 /* This is pre or post decrement. */
8269 rhs
= TREE_OPERAND (lhs
, 1);
8270 lhs
= TREE_OPERAND (lhs
, 0);
8277 switch (c_parser_peek_token (parser
)->type
)
8283 code
= TRUNC_DIV_EXPR
;
8298 code
= BIT_AND_EXPR
;
8301 code
= BIT_IOR_EXPR
;
8304 code
= BIT_XOR_EXPR
;
8307 c_parser_error (parser
,
8308 "invalid operator for %<#pragma omp atomic%>");
8312 c_parser_consume_token (parser
);
8314 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
8315 rhs_expr
= c_parser_expression (parser
);
8316 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
8318 rhs
= rhs_expr
.value
;
8319 rhs
= c_fully_fold (rhs
, false, NULL
);
8322 stmt
= c_finish_omp_atomic (loc
, code
, lhs
, rhs
);
8323 if (stmt
!= error_mark_node
)
8325 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8330 # pragma omp barrier new-line
8334 c_parser_omp_barrier (c_parser
*parser
)
8336 location_t loc
= c_parser_peek_token (parser
)->location
;
8337 c_parser_consume_pragma (parser
);
8338 c_parser_skip_to_pragma_eol (parser
);
8340 c_finish_omp_barrier (loc
);
8344 # pragma omp critical [(name)] new-line
8347 LOC is the location of the #pragma itself. */
8350 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
8352 tree stmt
, name
= NULL
;
8354 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8356 c_parser_consume_token (parser
);
8357 if (c_parser_next_token_is (parser
, CPP_NAME
))
8359 name
= c_parser_peek_token (parser
)->value
;
8360 c_parser_consume_token (parser
);
8361 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8364 c_parser_error (parser
, "expected identifier");
8366 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8367 c_parser_error (parser
, "expected %<(%> or end of line");
8368 c_parser_skip_to_pragma_eol (parser
);
8370 stmt
= c_parser_omp_structured_block (parser
);
8371 return c_finish_omp_critical (loc
, stmt
, name
);
8375 # pragma omp flush flush-vars[opt] new-line
8378 ( variable-list ) */
8381 c_parser_omp_flush (c_parser
*parser
)
8383 location_t loc
= c_parser_peek_token (parser
)->location
;
8384 c_parser_consume_pragma (parser
);
8385 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8386 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
8387 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
8388 c_parser_error (parser
, "expected %<(%> or end of line");
8389 c_parser_skip_to_pragma_eol (parser
);
8391 c_finish_omp_flush (loc
);
8394 /* Parse the restricted form of the for statement allowed by OpenMP.
8395 The real trick here is to determine the loop control variable early
8396 so that we can push a new decl if necessary to make it private.
8397 LOC is the location of the OMP in "#pragma omp". */
8400 c_parser_omp_for_loop (location_t loc
,
8401 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
8403 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
8404 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
8405 bool fail
= false, open_brace_parsed
= false;
8406 int i
, collapse
= 1, nbraces
= 0;
8408 VEC(tree
,gc
) *for_block
= make_tree_vector ();
8410 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
8411 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
8412 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
8414 gcc_assert (collapse
>= 1);
8416 declv
= make_tree_vec (collapse
);
8417 initv
= make_tree_vec (collapse
);
8418 condv
= make_tree_vec (collapse
);
8419 incrv
= make_tree_vec (collapse
);
8421 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
8423 c_parser_error (parser
, "for statement expected");
8426 for_loc
= c_parser_peek_token (parser
)->location
;
8427 c_parser_consume_token (parser
);
8429 for (i
= 0; i
< collapse
; i
++)
8433 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8436 /* Parse the initialization declaration or expression. */
8437 if (c_parser_next_token_starts_declaration (parser
))
8440 VEC_safe_push (tree
, gc
, for_block
, c_begin_compound_stmt (true));
8441 c_parser_declaration_or_fndef (parser
, true, true, true, true, true);
8442 decl
= check_for_loop_decls (for_loc
);
8445 if (DECL_INITIAL (decl
) == error_mark_node
)
8446 decl
= error_mark_node
;
8449 else if (c_parser_next_token_is (parser
, CPP_NAME
)
8450 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
8452 struct c_expr decl_exp
;
8453 struct c_expr init_exp
;
8454 location_t init_loc
;
8456 decl_exp
= c_parser_postfix_expression (parser
);
8457 decl
= decl_exp
.value
;
8459 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
8461 init_loc
= c_parser_peek_token (parser
)->location
;
8462 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
8463 init_exp
= default_function_array_read_conversion (init_loc
,
8465 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
8466 NOP_EXPR
, init_loc
, init_exp
.value
,
8467 init_exp
.original_type
);
8468 init
= c_process_expr_stmt (init_loc
, init
);
8470 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8475 c_parser_error (parser
,
8476 "expected iteration declaration or initialization");
8477 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8483 /* Parse the loop condition. */
8485 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
8487 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
8488 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
);
8490 cond
= cond_expr
.value
;
8491 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
8492 cond
= c_fully_fold (cond
, false, NULL
);
8493 switch (cond_expr
.original_code
)
8501 /* Can't be cond = error_mark_node, because we want to preserve
8502 the location until c_finish_omp_for. */
8503 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
8506 protected_set_expr_location (cond
, cond_loc
);
8508 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8510 /* Parse the increment expression. */
8512 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
8514 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
8516 incr
= c_process_expr_stmt (incr_loc
,
8517 c_parser_expression (parser
).value
);
8519 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8521 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
8525 TREE_VEC_ELT (declv
, i
) = decl
;
8526 TREE_VEC_ELT (initv
, i
) = init
;
8527 TREE_VEC_ELT (condv
, i
) = cond
;
8528 TREE_VEC_ELT (incrv
, i
) = incr
;
8532 if (i
== collapse
- 1)
8535 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
8536 in between the collapsed for loops to be still considered perfectly
8537 nested. Hopefully the final version clarifies this.
8538 For now handle (multiple) {'s and empty statements. */
8541 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8543 c_parser_consume_token (parser
);
8546 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8548 c_parser_consume_token (parser
);
8552 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8553 c_parser_consume_token (parser
);
8556 c_parser_error (parser
, "not enough perfectly nested loops");
8559 open_brace_parsed
= true;
8569 nbraces
+= bracecount
;
8572 save_break
= c_break_label
;
8573 c_break_label
= size_one_node
;
8574 save_cont
= c_cont_label
;
8575 c_cont_label
= NULL_TREE
;
8576 body
= push_stmt_list ();
8578 if (open_brace_parsed
)
8580 location_t here
= c_parser_peek_token (parser
)->location
;
8581 stmt
= c_begin_compound_stmt (true);
8582 c_parser_compound_statement_nostart (parser
);
8583 add_stmt (c_end_compound_stmt (here
, stmt
, true));
8586 add_stmt (c_parser_c99_block_statement (parser
));
8589 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
8590 SET_EXPR_LOCATION (t
, loc
);
8594 body
= pop_stmt_list (body
);
8595 c_break_label
= save_break
;
8596 c_cont_label
= save_cont
;
8600 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8602 c_parser_consume_token (parser
);
8605 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8606 c_parser_consume_token (parser
);
8609 c_parser_error (parser
, "collapsed loops not perfectly nested");
8612 location_t here
= c_parser_peek_token (parser
)->location
;
8613 stmt
= c_begin_compound_stmt (true);
8615 c_parser_compound_statement_nostart (parser
);
8616 body
= c_end_compound_stmt (here
, stmt
, true);
8623 /* Only bother calling c_finish_omp_for if we haven't already generated
8624 an error from the initialization parsing. */
8627 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
8630 if (par_clauses
!= NULL
)
8633 for (c
= par_clauses
; *c
; )
8634 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
8635 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
8636 c
= &OMP_CLAUSE_CHAIN (*c
);
8639 for (i
= 0; i
< collapse
; i
++)
8640 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
8643 c
= &OMP_CLAUSE_CHAIN (*c
);
8644 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8647 "iteration variable %qD should not be firstprivate",
8648 OMP_CLAUSE_DECL (*c
));
8649 *c
= OMP_CLAUSE_CHAIN (*c
);
8653 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
8654 change it to shared (decl) in
8655 OMP_PARALLEL_CLAUSES. */
8656 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
8657 OMP_CLAUSE_LASTPRIVATE
);
8658 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
8659 OMP_CLAUSE_CHAIN (l
) = clauses
;
8661 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
8665 OMP_FOR_CLAUSES (stmt
) = clauses
;
8670 while (!VEC_empty (tree
, for_block
))
8672 /* FIXME diagnostics: LOC below should be the actual location of
8673 this particular for block. We need to build a list of
8674 locations to go along with FOR_BLOCK. */
8675 stmt
= c_end_compound_stmt (loc
, VEC_pop (tree
, for_block
), true);
8678 release_tree_vector (for_block
);
8683 #pragma omp for for-clause[optseq] new-line
8686 LOC is the location of the #pragma token.
8689 #define OMP_FOR_CLAUSE_MASK \
8690 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8691 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8692 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8693 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8694 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
8695 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
8696 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
8697 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8700 c_parser_omp_for (location_t loc
, c_parser
*parser
)
8702 tree block
, clauses
, ret
;
8704 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
8707 block
= c_begin_compound_stmt (true);
8708 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
8709 block
= c_end_compound_stmt (loc
, block
, true);
8716 # pragma omp master new-line
8719 LOC is the location of the #pragma token.
8723 c_parser_omp_master (location_t loc
, c_parser
*parser
)
8725 c_parser_skip_to_pragma_eol (parser
);
8726 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
8730 # pragma omp ordered new-line
8733 LOC is the location of the #pragma itself.
8737 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
8739 c_parser_skip_to_pragma_eol (parser
);
8740 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
8746 { section-sequence }
8749 section-directive[opt] structured-block
8750 section-sequence section-directive structured-block
8752 SECTIONS_LOC is the location of the #pragma omp sections. */
8755 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
8758 bool error_suppress
= false;
8761 loc
= c_parser_peek_token (parser
)->location
;
8762 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8764 /* Avoid skipping until the end of the block. */
8765 parser
->error
= false;
8769 stmt
= push_stmt_list ();
8771 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
8773 substmt
= push_stmt_list ();
8777 c_parser_statement (parser
);
8779 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8781 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8783 if (c_parser_next_token_is (parser
, CPP_EOF
))
8787 substmt
= pop_stmt_list (substmt
);
8788 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8789 SET_EXPR_LOCATION (substmt
, loc
);
8795 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8797 if (c_parser_next_token_is (parser
, CPP_EOF
))
8800 loc
= c_parser_peek_token (parser
)->location
;
8801 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
8803 c_parser_consume_pragma (parser
);
8804 c_parser_skip_to_pragma_eol (parser
);
8805 error_suppress
= false;
8807 else if (!error_suppress
)
8809 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
8810 error_suppress
= true;
8813 substmt
= c_parser_omp_structured_block (parser
);
8814 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
8815 SET_EXPR_LOCATION (substmt
, loc
);
8818 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
8819 "expected %<#pragma omp section%> or %<}%>");
8821 substmt
= pop_stmt_list (stmt
);
8823 stmt
= make_node (OMP_SECTIONS
);
8824 SET_EXPR_LOCATION (stmt
, sections_loc
);
8825 TREE_TYPE (stmt
) = void_type_node
;
8826 OMP_SECTIONS_BODY (stmt
) = substmt
;
8828 return add_stmt (stmt
);
8832 # pragma omp sections sections-clause[optseq] newline
8835 LOC is the location of the #pragma token.
8838 #define OMP_SECTIONS_CLAUSE_MASK \
8839 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8840 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8841 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
8842 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8843 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8846 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
8848 tree block
, clauses
, ret
;
8850 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
8851 "#pragma omp sections");
8853 block
= c_begin_compound_stmt (true);
8854 ret
= c_parser_omp_sections_scope (loc
, parser
);
8856 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
8857 block
= c_end_compound_stmt (loc
, block
, true);
8864 # pragma parallel parallel-clause new-line
8865 # pragma parallel for parallel-for-clause new-line
8866 # pragma parallel sections parallel-sections-clause new-line
8868 LOC is the location of the #pragma token.
8871 #define OMP_PARALLEL_CLAUSE_MASK \
8872 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8873 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8874 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8875 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8876 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
8877 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
8878 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
8879 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
8882 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
8884 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
8885 const char *p_name
= "#pragma omp parallel";
8886 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
8887 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
8889 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
8891 c_parser_consume_token (parser
);
8892 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
8893 p_name
= "#pragma omp parallel for";
8894 mask
|= OMP_FOR_CLAUSE_MASK
;
8895 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8897 else if (c_parser_next_token_is (parser
, CPP_NAME
))
8899 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
8900 if (strcmp (p
, "sections") == 0)
8902 c_parser_consume_token (parser
);
8903 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
8904 p_name
= "#pragma omp parallel sections";
8905 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
8906 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
8910 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
8914 case PRAGMA_OMP_PARALLEL
:
8915 block
= c_begin_omp_parallel ();
8916 c_parser_statement (parser
);
8917 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
8920 case PRAGMA_OMP_PARALLEL_FOR
:
8921 block
= c_begin_omp_parallel ();
8922 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8923 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
8924 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8925 OMP_PARALLEL_COMBINED (stmt
) = 1;
8928 case PRAGMA_OMP_PARALLEL_SECTIONS
:
8929 block
= c_begin_omp_parallel ();
8930 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
8931 stmt
= c_parser_omp_sections_scope (loc
, parser
);
8933 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
8934 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
8935 OMP_PARALLEL_COMBINED (stmt
) = 1;
8946 # pragma omp single single-clause[optseq] new-line
8949 LOC is the location of the #pragma.
8952 #define OMP_SINGLE_CLAUSE_MASK \
8953 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8954 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8955 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
8956 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
8959 c_parser_omp_single (location_t loc
, c_parser
*parser
)
8961 tree stmt
= make_node (OMP_SINGLE
);
8962 SET_EXPR_LOCATION (stmt
, loc
);
8963 TREE_TYPE (stmt
) = void_type_node
;
8965 OMP_SINGLE_CLAUSES (stmt
)
8966 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
8967 "#pragma omp single");
8968 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
8970 return add_stmt (stmt
);
8974 # pragma omp task task-clause[optseq] new-line
8976 LOC is the location of the #pragma.
8979 #define OMP_TASK_CLAUSE_MASK \
8980 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
8981 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
8982 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
8983 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
8984 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
8985 | (1u << PRAGMA_OMP_CLAUSE_SHARED))
8988 c_parser_omp_task (location_t loc
, c_parser
*parser
)
8990 tree clauses
, block
;
8992 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
8993 "#pragma omp task");
8995 block
= c_begin_omp_task ();
8996 c_parser_statement (parser
);
8997 return c_finish_omp_task (loc
, clauses
, block
);
9001 # pragma omp taskwait new-line
9005 c_parser_omp_taskwait (c_parser
*parser
)
9007 location_t loc
= c_parser_peek_token (parser
)->location
;
9008 c_parser_consume_pragma (parser
);
9009 c_parser_skip_to_pragma_eol (parser
);
9011 c_finish_omp_taskwait (loc
);
9014 /* Main entry point to parsing most OpenMP pragmas. */
9017 c_parser_omp_construct (c_parser
*parser
)
9019 enum pragma_kind p_kind
;
9023 loc
= c_parser_peek_token (parser
)->location
;
9024 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
9025 c_parser_consume_pragma (parser
);
9029 case PRAGMA_OMP_ATOMIC
:
9030 c_parser_omp_atomic (loc
, parser
);
9032 case PRAGMA_OMP_CRITICAL
:
9033 stmt
= c_parser_omp_critical (loc
, parser
);
9035 case PRAGMA_OMP_FOR
:
9036 stmt
= c_parser_omp_for (loc
, parser
);
9038 case PRAGMA_OMP_MASTER
:
9039 stmt
= c_parser_omp_master (loc
, parser
);
9041 case PRAGMA_OMP_ORDERED
:
9042 stmt
= c_parser_omp_ordered (loc
, parser
);
9044 case PRAGMA_OMP_PARALLEL
:
9045 stmt
= c_parser_omp_parallel (loc
, parser
);
9047 case PRAGMA_OMP_SECTIONS
:
9048 stmt
= c_parser_omp_sections (loc
, parser
);
9050 case PRAGMA_OMP_SINGLE
:
9051 stmt
= c_parser_omp_single (loc
, parser
);
9053 case PRAGMA_OMP_TASK
:
9054 stmt
= c_parser_omp_task (loc
, parser
);
9061 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
9066 # pragma omp threadprivate (variable-list) */
9069 c_parser_omp_threadprivate (c_parser
*parser
)
9074 c_parser_consume_pragma (parser
);
9075 loc
= c_parser_peek_token (parser
)->location
;
9076 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
9078 /* Mark every variable in VARS to be assigned thread local storage. */
9079 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9081 tree v
= TREE_PURPOSE (t
);
9083 /* FIXME diagnostics: Ideally we should keep individual
9084 locations for all the variables in the var list to make the
9085 following errors more precise. Perhaps
9086 c_parser_omp_var_list_parens() should construct a list of
9087 locations to go along with the var list. */
9089 /* If V had already been marked threadprivate, it doesn't matter
9090 whether it had been used prior to this point. */
9091 if (TREE_CODE (v
) != VAR_DECL
)
9092 error_at (loc
, "%qD is not a variable", v
);
9093 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
9094 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
9095 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9096 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
9097 else if (TREE_TYPE (v
) == error_mark_node
)
9099 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
9100 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
9103 if (! DECL_THREAD_LOCAL_P (v
))
9105 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
9106 /* If rtl has been already set for this var, call
9107 make_decl_rtl once again, so that encode_section_info
9108 has a chance to look at the new decl flags. */
9109 if (DECL_RTL_SET_P (v
))
9112 C_DECL_THREADPRIVATE_P (v
) = 1;
9116 c_parser_skip_to_pragma_eol (parser
);
9120 /* Parse a single source file. */
9125 /* Use local storage to begin. If the first token is a pragma, parse it.
9126 If it is #pragma GCC pch_preprocess, then this will load a PCH file
9127 which will cause garbage collection. */
9130 memset (&tparser
, 0, sizeof tparser
);
9131 the_parser
= &tparser
;
9133 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
9134 c_parser_pragma_pch_preprocess (&tparser
);
9136 the_parser
= ggc_alloc_c_parser ();
9137 *the_parser
= tparser
;
9139 /* Initialize EH, if we've been told to do so. */
9140 if (flag_exceptions
)
9141 using_eh_for_cleanups ();
9143 c_parser_translation_unit (the_parser
);
9147 #include "gt-c-parser.h"