1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
40 #include "coretypes.h"
41 #include "tm.h" /* For rtl.h: needs enum reg_class. */
43 #include "langhooks.h"
47 #include "c-family/c-pragma.h"
51 #include "c-family/c-common.h"
52 #include "c-family/c-objc.h"
53 #include "c-family/c-upc.h"
59 #include "upc/upc-tree.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 if (!c_dialect_upc ())
92 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
93 for (i
= 0; i
< num_c_common_reswords
; i
++)
95 /* If a keyword is disabled, do not enter it into the table
96 and so create a canonical spelling that isn't a keyword. */
97 if (c_common_reswords
[i
].disable
& mask
)
100 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
102 id
= get_identifier (c_common_reswords
[i
].word
);
103 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
104 C_IS_RESERVED_WORD (id
) = 1;
109 id
= get_identifier (c_common_reswords
[i
].word
);
110 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
111 C_IS_RESERVED_WORD (id
) = 1;
112 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
116 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
117 and the C parser. Unlike the C++ lexer, the parser structure
118 stores the lexer information instead of using a separate structure.
119 Identifiers are separated into ordinary identifiers, type names,
120 keywords and some other Objective-C types of identifiers, and some
121 look-ahead is maintained.
123 ??? It might be a good idea to lex the whole file up front (as for
124 C++). It would then be possible to share more of the C and C++
125 lexer code, if desired. */
127 /* The following local token type is used. */
130 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
132 /* More information about the type of a CPP_NAME token. */
133 typedef enum c_id_kind
{
134 /* An ordinary identifier. */
136 /* An identifier declared as a typedef name. */
138 /* An identifier declared as an Objective-C class name. */
140 /* An address space identifier. */
142 /* Not an identifier. */
146 /* A single C token after string literal concatenation and conversion
147 of preprocessing tokens to tokens. */
148 typedef struct GTY (()) c_token
{
149 /* The kind of token. */
150 ENUM_BITFIELD (cpp_ttype
) type
: 8;
151 /* If this token is a CPP_NAME, this value indicates whether also
152 declared as some kind of type. Otherwise, it is C_ID_NONE. */
153 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
154 /* If this token is a keyword, this value indicates which keyword.
155 Otherwise, this value is RID_MAX. */
156 ENUM_BITFIELD (rid
) keyword
: 8;
157 /* If this token is a CPP_PRAGMA, this indicates the pragma that
158 was seen. Otherwise it is PRAGMA_NONE. */
159 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
160 /* The location at which this token was found. */
162 /* The value associated with this token, if any. */
166 /* A parser structure recording information about the state and
167 context of parsing. Includes lexer information with up to two
168 tokens of look-ahead; more are not needed for C. */
169 typedef struct GTY(()) c_parser
{
170 /* The look-ahead tokens. */
172 /* How many look-ahead tokens are available (0, 1 or 2). */
174 /* True if a syntax error is being recovered from; false otherwise.
175 c_parser_error sets this flag. It should clear this flag when
176 enough tokens have been consumed to recover from the error. */
177 BOOL_BITFIELD error
: 1;
178 /* True if we're processing a pragma, and shouldn't automatically
179 consume CPP_PRAGMA_EOL. */
180 BOOL_BITFIELD in_pragma
: 1;
181 /* True if we're parsing the outermost block of an if statement. */
182 BOOL_BITFIELD in_if_block
: 1;
183 /* True if we want to lex an untranslated string. */
184 BOOL_BITFIELD lex_untranslated_string
: 1;
186 /* Objective-C specific parser/lexer information. */
188 /* True if we are in a context where the Objective-C "PQ" keywords
189 are considered keywords. */
190 BOOL_BITFIELD objc_pq_context
: 1;
191 /* True if we are parsing a (potential) Objective-C foreach
192 statement. This is set to true after we parsed 'for (' and while
193 we wait for 'in' or ';' to decide if it's a standard C for loop or an
194 Objective-C foreach loop. */
195 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
196 /* The following flag is needed to contextualize Objective-C lexical
197 analysis. In some cases (e.g., 'int NSObject;'), it is
198 undesirable to bind an identifier to an Objective-C class, even
199 if a class with that name exists. */
200 BOOL_BITFIELD objc_need_raw_identifier
: 1;
201 /* Nonzero if we're processing a __transaction statement. The value
202 is 1 | TM_STMT_ATTR_*. */
203 unsigned int in_transaction
: 4;
204 /* True if we are in a context where the Objective-C "Property attribute"
205 keywords are valid. */
206 BOOL_BITFIELD objc_property_attr_context
: 1;
210 /* The actual parser and external interface. ??? Does this need to be
211 garbage-collected? */
213 static GTY (()) c_parser
*the_parser
;
215 /* Read in and lex a single token, storing it in *TOKEN. */
218 c_lex_one_token (c_parser
*parser
, c_token
*token
)
220 timevar_push (TV_LEX
);
222 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
223 (parser
->lex_untranslated_string
224 ? C_LEX_STRING_NO_TRANSLATE
: 0));
225 token
->id_kind
= C_ID_NONE
;
226 token
->keyword
= RID_MAX
;
227 token
->pragma_kind
= PRAGMA_NONE
;
235 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
236 if (c_dialect_objc ())
237 parser
->objc_need_raw_identifier
= false;
239 if (C_IS_RESERVED_WORD (token
->value
))
241 enum rid rid_code
= C_RID_CODE (token
->value
);
243 if (rid_code
== RID_CXX_COMPAT_WARN
)
245 warning_at (token
->location
,
247 "identifier %qE conflicts with C++ keyword",
250 else if (rid_code
>= RID_FIRST_ADDR_SPACE
251 && rid_code
<= RID_LAST_ADDR_SPACE
)
253 token
->id_kind
= C_ID_ADDRSPACE
;
254 token
->keyword
= rid_code
;
257 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
259 /* We found an Objective-C "pq" keyword (in, out,
260 inout, bycopy, byref, oneway). They need special
261 care because the interpretation depends on the
263 if (parser
->objc_pq_context
)
265 token
->type
= CPP_KEYWORD
;
266 token
->keyword
= rid_code
;
269 else if (parser
->objc_could_be_foreach_context
270 && rid_code
== RID_IN
)
272 /* We are in Objective-C, inside a (potential)
273 foreach context (which means after having
274 parsed 'for (', but before having parsed ';'),
275 and we found 'in'. We consider it the keyword
276 which terminates the declaration at the
277 beginning of a foreach-statement. Note that
278 this means you can't use 'in' for anything else
279 in that context; in particular, in Objective-C
280 you can't use 'in' as the name of the running
281 variable in a C for loop. We could potentially
282 try to add code here to disambiguate, but it
283 seems a reasonable limitation. */
284 token
->type
= CPP_KEYWORD
;
285 token
->keyword
= rid_code
;
288 /* Else, "pq" keywords outside of the "pq" context are
289 not keywords, and we fall through to the code for
292 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
294 /* We found an Objective-C "property attribute"
295 keyword (getter, setter, readonly, etc). These are
296 only valid in the property context. */
297 if (parser
->objc_property_attr_context
)
299 token
->type
= CPP_KEYWORD
;
300 token
->keyword
= rid_code
;
303 /* Else they are not special keywords.
306 else if (c_dialect_objc ()
307 && (OBJC_IS_AT_KEYWORD (rid_code
)
308 || OBJC_IS_CXX_KEYWORD (rid_code
)))
310 /* We found one of the Objective-C "@" keywords (defs,
311 selector, synchronized, etc) or one of the
312 Objective-C "cxx" keywords (class, private,
313 protected, public, try, catch, throw) without a
314 preceding '@' sign. Do nothing and fall through to
315 the code for normal tokens (in C++ we would still
316 consider the CXX ones keywords, but not in C). */
321 token
->type
= CPP_KEYWORD
;
322 token
->keyword
= rid_code
;
327 decl
= lookup_name (token
->value
);
330 if (TREE_CODE (decl
) == TYPE_DECL
)
332 token
->id_kind
= C_ID_TYPENAME
;
336 else if (c_dialect_objc ())
338 tree objc_interface_decl
= objc_is_class_name (token
->value
);
339 /* Objective-C class names are in the same namespace as
340 variables and typedefs, and hence are shadowed by local
342 if (objc_interface_decl
343 && (!objc_force_identifier
|| global_bindings_p ()))
345 token
->value
= objc_interface_decl
;
346 token
->id_kind
= C_ID_CLASSNAME
;
350 token
->id_kind
= C_ID_ID
;
354 /* This only happens in Objective-C; it must be a keyword. */
355 token
->type
= CPP_KEYWORD
;
356 switch (C_RID_CODE (token
->value
))
358 /* Replace 'class' with '@class', 'private' with '@private',
359 etc. This prevents confusion with the C++ keyword
360 'class', and makes the tokens consistent with other
361 Objective-C 'AT' keywords. For example '@class' is
362 reported as RID_AT_CLASS which is consistent with
363 '@synchronized', which is reported as
366 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
367 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
368 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
369 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
370 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
371 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
372 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
373 default: token
->keyword
= C_RID_CODE (token
->value
);
378 case CPP_CLOSE_PAREN
:
380 /* These tokens may affect the interpretation of any identifiers
381 following, if doing Objective-C. */
382 if (c_dialect_objc ())
383 parser
->objc_need_raw_identifier
= false;
386 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
387 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
393 timevar_pop (TV_LEX
);
396 /* Return a pointer to the next token from PARSER, reading it in if
399 static inline c_token
*
400 c_parser_peek_token (c_parser
*parser
)
402 if (parser
->tokens_avail
== 0)
404 c_lex_one_token (parser
, &parser
->tokens
[0]);
405 parser
->tokens_avail
= 1;
407 return &parser
->tokens
[0];
410 /* Return true if the next token from PARSER has the indicated
414 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
416 return c_parser_peek_token (parser
)->type
== type
;
419 /* Return true if the next token from PARSER does not have the
423 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
425 return !c_parser_next_token_is (parser
, type
);
428 /* Return true if the next token from PARSER is the indicated
432 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
434 return c_parser_peek_token (parser
)->keyword
== keyword
;
437 /* Return a pointer to the next-but-one token from PARSER, reading it
438 in if necessary. The next token is already read in. */
441 c_parser_peek_2nd_token (c_parser
*parser
)
443 if (parser
->tokens_avail
>= 2)
444 return &parser
->tokens
[1];
445 gcc_assert (parser
->tokens_avail
== 1);
446 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
447 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
448 c_lex_one_token (parser
, &parser
->tokens
[1]);
449 parser
->tokens_avail
= 2;
450 return &parser
->tokens
[1];
453 /* Return true if TOKEN can start a type name,
456 c_token_starts_typename (c_token
*token
)
461 switch (token
->id_kind
)
470 gcc_assert (c_dialect_objc ());
476 switch (token
->keyword
)
514 if (c_dialect_objc ())
522 enum c_lookahead_kind
{
523 /* Always treat unknown identifiers as typenames. */
526 /* Could be parsing a nonabstract declarator. Only treat an identifier
527 as a typename if followed by another identifier or a star. */
528 cla_nonabstract_decl
,
530 /* Never treat identifiers as typenames. */
534 /* Return true if the next token from PARSER can start a type name,
535 false otherwise. LA specifies how to do lookahead in order to
536 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
539 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
541 c_token
*token
= c_parser_peek_token (parser
);
542 if (c_token_starts_typename (token
))
545 /* Try a bit harder to detect an unknown typename. */
546 if (la
!= cla_prefer_id
547 && token
->type
== CPP_NAME
548 && token
->id_kind
== C_ID_ID
550 /* Do not try too hard when we could have "object in array". */
551 && !parser
->objc_could_be_foreach_context
553 && (la
== cla_prefer_type
554 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
555 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
557 /* Only unknown identifiers. */
558 && !lookup_name (token
->value
))
564 /* Return true if TOKEN is a type qualifier, false otherwise. */
566 c_token_is_qualifier (c_token
*token
)
571 switch (token
->id_kind
)
579 switch (token
->keyword
)
601 /* Return true if the next token from PARSER is a type qualifier,
604 c_parser_next_token_is_qualifier (c_parser
*parser
)
606 c_token
*token
= c_parser_peek_token (parser
);
607 return c_token_is_qualifier (token
);
610 /* Return true if TOKEN can start declaration specifiers, false
613 c_token_starts_declspecs (c_token
*token
)
618 switch (token
->id_kind
)
627 gcc_assert (c_dialect_objc ());
633 switch (token
->keyword
)
680 if (c_dialect_objc ())
689 /* Return true if TOKEN can start declaration specifiers or a static
690 assertion, false otherwise. */
692 c_token_starts_declaration (c_token
*token
)
694 if (c_token_starts_declspecs (token
)
695 || token
->keyword
== RID_STATIC_ASSERT
)
701 /* Return true if the next token from PARSER can start declaration
702 specifiers, false otherwise. */
704 c_parser_next_token_starts_declspecs (c_parser
*parser
)
706 c_token
*token
= c_parser_peek_token (parser
);
708 /* In Objective-C, a classname normally starts a declspecs unless it
709 is immediately followed by a dot. In that case, it is the
710 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
711 setter/getter on the class. c_token_starts_declspecs() can't
712 differentiate between the two cases because it only checks the
713 current token, so we have a special check here. */
714 if (c_dialect_objc ()
715 && token
->type
== CPP_NAME
716 && token
->id_kind
== C_ID_CLASSNAME
717 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
720 return c_token_starts_declspecs (token
);
723 /* Return true if the next tokens from PARSER can start declaration
724 specifiers or a static assertion, false otherwise. */
726 c_parser_next_tokens_start_declaration (c_parser
*parser
)
728 c_token
*token
= c_parser_peek_token (parser
);
731 if (c_dialect_objc ()
732 && token
->type
== CPP_NAME
733 && token
->id_kind
== C_ID_CLASSNAME
734 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
737 /* Labels do not start declarations. */
738 if (token
->type
== CPP_NAME
739 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
742 if (c_token_starts_declaration (token
))
745 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
751 /* Consume the next token from PARSER. */
754 c_parser_consume_token (c_parser
*parser
)
756 gcc_assert (parser
->tokens_avail
>= 1);
757 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
758 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
759 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
760 if (parser
->tokens_avail
== 2)
761 parser
->tokens
[0] = parser
->tokens
[1];
762 parser
->tokens_avail
--;
765 /* Expect the current token to be a #pragma. Consume it and remember
766 that we've begun parsing a pragma. */
769 c_parser_consume_pragma (c_parser
*parser
)
771 gcc_assert (!parser
->in_pragma
);
772 gcc_assert (parser
->tokens_avail
>= 1);
773 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
774 if (parser
->tokens_avail
== 2)
775 parser
->tokens
[0] = parser
->tokens
[1];
776 parser
->tokens_avail
--;
777 parser
->in_pragma
= true;
780 /* Update the globals input_location and in_system_header from
783 c_parser_set_source_position_from_token (c_token
*token
)
785 if (token
->type
!= CPP_EOF
)
787 input_location
= token
->location
;
791 /* Issue a diagnostic of the form
792 FILE:LINE: MESSAGE before TOKEN
793 where TOKEN is the next token in the input stream of PARSER.
794 MESSAGE (specified by the caller) is usually of the form "expected
797 Do not issue a diagnostic if still recovering from an error.
799 ??? This is taken from the C++ parser, but building up messages in
800 this way is not i18n-friendly and some other approach should be
804 c_parser_error (c_parser
*parser
, const char *gmsgid
)
806 c_token
*token
= c_parser_peek_token (parser
);
809 parser
->error
= true;
812 /* This diagnostic makes more sense if it is tagged to the line of
813 the token we just peeked at. */
814 c_parser_set_source_position_from_token (token
);
815 c_parse_error (gmsgid
,
816 /* Because c_parse_error does not understand
817 CPP_KEYWORD, keywords are treated like
819 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
820 /* ??? The C parser does not save the cpp flags of a
821 token, we need to pass 0 here and we will not get
822 the source spelling of some tokens but rather the
823 canonical spelling. */
824 token
->value
, /*flags=*/0);
827 /* If the next token is of the indicated TYPE, consume it. Otherwise,
828 issue the error MSGID. If MSGID is NULL then a message has already
829 been produced and no message will be produced this time. Returns
830 true if found, false otherwise. */
833 c_parser_require (c_parser
*parser
,
837 if (c_parser_next_token_is (parser
, type
))
839 c_parser_consume_token (parser
);
844 c_parser_error (parser
, msgid
);
849 /* If the next token is the indicated keyword, consume it. Otherwise,
850 issue the error MSGID. Returns true if found, false otherwise. */
853 c_parser_require_keyword (c_parser
*parser
,
857 if (c_parser_next_token_is_keyword (parser
, keyword
))
859 c_parser_consume_token (parser
);
864 c_parser_error (parser
, msgid
);
869 /* Like c_parser_require, except that tokens will be skipped until the
870 desired token is found. An error message is still produced if the
871 next token is not as expected. If MSGID is NULL then a message has
872 already been produced and no message will be produced this
876 c_parser_skip_until_found (c_parser
*parser
,
880 unsigned nesting_depth
= 0;
882 if (c_parser_require (parser
, type
, msgid
))
885 /* Skip tokens until the desired token is found. */
888 /* Peek at the next token. */
889 c_token
*token
= c_parser_peek_token (parser
);
890 /* If we've reached the token we want, consume it and stop. */
891 if (token
->type
== type
&& !nesting_depth
)
893 c_parser_consume_token (parser
);
897 /* If we've run out of tokens, stop. */
898 if (token
->type
== CPP_EOF
)
900 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
902 if (token
->type
== CPP_OPEN_BRACE
903 || token
->type
== CPP_OPEN_PAREN
904 || token
->type
== CPP_OPEN_SQUARE
)
906 else if (token
->type
== CPP_CLOSE_BRACE
907 || token
->type
== CPP_CLOSE_PAREN
908 || token
->type
== CPP_CLOSE_SQUARE
)
910 if (nesting_depth
-- == 0)
913 /* Consume this token. */
914 c_parser_consume_token (parser
);
916 parser
->error
= false;
919 /* Skip tokens until the end of a parameter is found, but do not
920 consume the comma, semicolon or closing delimiter. */
923 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
925 unsigned nesting_depth
= 0;
929 c_token
*token
= c_parser_peek_token (parser
);
930 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
933 /* If we've run out of tokens, stop. */
934 if (token
->type
== CPP_EOF
)
936 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
938 if (token
->type
== CPP_OPEN_BRACE
939 || token
->type
== CPP_OPEN_PAREN
940 || token
->type
== CPP_OPEN_SQUARE
)
942 else if (token
->type
== CPP_CLOSE_BRACE
943 || token
->type
== CPP_CLOSE_PAREN
944 || token
->type
== CPP_CLOSE_SQUARE
)
946 if (nesting_depth
-- == 0)
949 /* Consume this token. */
950 c_parser_consume_token (parser
);
952 parser
->error
= false;
955 /* Expect to be at the end of the pragma directive and consume an
956 end of line marker. */
959 c_parser_skip_to_pragma_eol (c_parser
*parser
)
961 gcc_assert (parser
->in_pragma
);
962 parser
->in_pragma
= false;
964 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
967 c_token
*token
= c_parser_peek_token (parser
);
968 if (token
->type
== CPP_EOF
)
970 if (token
->type
== CPP_PRAGMA_EOL
)
972 c_parser_consume_token (parser
);
975 c_parser_consume_token (parser
);
978 parser
->error
= false;
981 /* Skip tokens until we have consumed an entire block, or until we
982 have consumed a non-nested ';'. */
985 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
987 unsigned nesting_depth
= 0;
988 bool save_error
= parser
->error
;
994 /* Peek at the next token. */
995 token
= c_parser_peek_token (parser
);
1002 case CPP_PRAGMA_EOL
:
1003 if (parser
->in_pragma
)
1008 /* If the next token is a ';', we have reached the
1009 end of the statement. */
1012 /* Consume the ';'. */
1013 c_parser_consume_token (parser
);
1018 case CPP_CLOSE_BRACE
:
1019 /* If the next token is a non-nested '}', then we have
1020 reached the end of the current block. */
1021 if (nesting_depth
== 0 || --nesting_depth
== 0)
1023 c_parser_consume_token (parser
);
1028 case CPP_OPEN_BRACE
:
1029 /* If it the next token is a '{', then we are entering a new
1030 block. Consume the entire block. */
1035 /* If we see a pragma, consume the whole thing at once. We
1036 have some safeguards against consuming pragmas willy-nilly.
1037 Normally, we'd expect to be here with parser->error set,
1038 which disables these safeguards. But it's possible to get
1039 here for secondary error recovery, after parser->error has
1041 c_parser_consume_pragma (parser
);
1042 c_parser_skip_to_pragma_eol (parser
);
1043 parser
->error
= save_error
;
1050 c_parser_consume_token (parser
);
1054 parser
->error
= false;
1057 /* CPP's options (initialized by c-opts.c). */
1058 extern cpp_options
*cpp_opts
;
1060 /* Save the warning flags which are controlled by __extension__. */
1063 disable_extension_diagnostics (void)
1066 | (warn_pointer_arith
<< 1)
1067 | (warn_traditional
<< 2)
1069 | (warn_long_long
<< 4)
1070 | (warn_cxx_compat
<< 5)
1071 | (warn_overlength_strings
<< 6));
1072 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1073 warn_pointer_arith
= 0;
1074 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1076 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1077 warn_cxx_compat
= 0;
1078 warn_overlength_strings
= 0;
1082 /* Restore the warning flags which are controlled by __extension__.
1083 FLAGS is the return value from disable_extension_diagnostics. */
1086 restore_extension_diagnostics (int flags
)
1088 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1089 warn_pointer_arith
= (flags
>> 1) & 1;
1090 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1091 flag_iso
= (flags
>> 3) & 1;
1092 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1093 warn_cxx_compat
= (flags
>> 5) & 1;
1094 warn_overlength_strings
= (flags
>> 6) & 1;
1097 /* Possibly kinds of declarator to parse. */
1098 typedef enum c_dtr_syn
{
1099 /* A normal declarator with an identifier. */
1101 /* An abstract declarator (maybe empty). */
1103 /* A parameter declarator: may be either, but after a type name does
1104 not redeclare a typedef name as an identifier if it can
1105 alternatively be interpreted as a typedef name; see DR#009,
1106 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1107 following DR#249. For example, given a typedef T, "int T" and
1108 "int *T" are valid parameter declarations redeclaring T, while
1109 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1110 abstract declarators rather than involving redundant parentheses;
1111 the same applies with attributes inside the parentheses before
1116 /* The binary operation precedence levels, where 0 is a dummy lowest level
1117 used for the bottom of the stack. */
1118 enum c_parser_prec
{
1133 static void c_parser_external_declaration (c_parser
*);
1134 static void c_parser_asm_definition (c_parser
*);
1135 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1136 bool, bool, tree
*);
1137 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1138 static void c_parser_static_assert_declaration (c_parser
*);
1139 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1140 bool, enum c_lookahead_kind
);
1141 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1142 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1143 static tree
c_parser_struct_declaration (c_parser
*);
1144 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1145 static tree
c_parser_alignas_specifier (c_parser
*);
1146 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1148 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1150 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1152 struct c_declarator
*);
1153 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1154 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1156 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1157 static tree
c_parser_simple_asm_expr (c_parser
*);
1158 static tree
c_parser_attributes (c_parser
*);
1159 static struct c_type_name
*c_parser_type_name (c_parser
*);
1160 static struct c_expr
c_parser_initializer (c_parser
*);
1161 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1162 static void c_parser_initelt (c_parser
*, struct obstack
*);
1163 static void c_parser_initval (c_parser
*, struct c_expr
*,
1165 static tree
c_parser_compound_statement (c_parser
*);
1166 static void c_parser_compound_statement_nostart (c_parser
*);
1167 static void c_parser_label (c_parser
*);
1168 static void c_parser_statement (c_parser
*);
1169 static void c_parser_statement_after_labels (c_parser
*);
1170 static void c_parser_if_statement (c_parser
*);
1171 static void c_parser_switch_statement (c_parser
*);
1172 static void c_parser_while_statement (c_parser
*);
1173 static void c_parser_do_statement (c_parser
*);
1174 static void c_parser_for_statement (c_parser
*);
1175 static tree
c_parser_asm_statement (c_parser
*);
1176 static tree
c_parser_asm_operands (c_parser
*);
1177 static tree
c_parser_asm_goto_operands (c_parser
*);
1178 static tree
c_parser_asm_clobbers (c_parser
*);
1179 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1180 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1182 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1183 enum c_parser_prec
);
1184 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1185 static struct c_expr
c_parser_unary_expression (c_parser
*);
1186 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1187 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1188 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1189 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1190 struct c_type_name
*,
1192 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1195 static tree
c_parser_transaction (c_parser
*, enum rid
);
1196 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1197 static tree
c_parser_transaction_cancel (c_parser
*);
1198 static struct c_expr
c_parser_expression (c_parser
*);
1199 static struct c_expr
c_parser_expression_conv (c_parser
*);
1200 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1201 vec
<tree
, va_gc
> **, location_t
*,
1203 static void c_parser_omp_construct (c_parser
*);
1204 static void c_parser_omp_threadprivate (c_parser
*);
1205 static void c_parser_omp_barrier (c_parser
*);
1206 static void c_parser_omp_flush (c_parser
*);
1207 static void c_parser_omp_taskwait (c_parser
*);
1208 static void c_parser_omp_taskyield (c_parser
*);
1210 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1211 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1213 /* These Objective-C parser functions are only ever called when
1214 compiling Objective-C. */
1215 static void c_parser_objc_class_definition (c_parser
*, tree
);
1216 static void c_parser_objc_class_instance_variables (c_parser
*);
1217 static void c_parser_objc_class_declaration (c_parser
*);
1218 static void c_parser_objc_alias_declaration (c_parser
*);
1219 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1220 static bool c_parser_objc_method_type (c_parser
*);
1221 static void c_parser_objc_method_definition (c_parser
*);
1222 static void c_parser_objc_methodprotolist (c_parser
*);
1223 static void c_parser_objc_methodproto (c_parser
*);
1224 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1225 static tree
c_parser_objc_type_name (c_parser
*);
1226 static tree
c_parser_objc_protocol_refs (c_parser
*);
1227 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1228 static void c_parser_objc_synchronized_statement (c_parser
*);
1229 static tree
c_parser_objc_selector (c_parser
*);
1230 static tree
c_parser_objc_selector_arg (c_parser
*);
1231 static tree
c_parser_objc_receiver (c_parser
*);
1232 static tree
c_parser_objc_message_args (c_parser
*);
1233 static tree
c_parser_objc_keywordexpr (c_parser
*);
1234 static void c_parser_objc_at_property_declaration (c_parser
*);
1235 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1236 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1237 static bool c_parser_objc_diagnose_bad_element_prefix
1238 (c_parser
*, struct c_declspecs
*);
1240 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1242 /* These UPC parser functions are only ever called when
1244 static void c_parser_upc_forall_statement (c_parser
*);
1245 static void c_parser_upc_sync_statement (c_parser
*, int);
1246 static void c_parser_upc_shared_qual (source_location
,
1248 struct c_declspecs
*);
1250 /* Parse a translation unit (C90 6.7, C99 6.9).
1253 external-declarations
1255 external-declarations:
1256 external-declaration
1257 external-declarations external-declaration
1266 c_parser_translation_unit (c_parser
*parser
)
1268 if (c_parser_next_token_is (parser
, CPP_EOF
))
1270 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1271 "ISO C forbids an empty translation unit");
1275 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1276 mark_valid_location_for_stdc_pragma (false);
1280 c_parser_external_declaration (parser
);
1281 obstack_free (&parser_obstack
, obstack_position
);
1283 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1287 /* Parse an external declaration (C90 6.7, C99 6.9).
1289 external-declaration:
1295 external-declaration:
1298 __extension__ external-declaration
1302 external-declaration:
1303 objc-class-definition
1304 objc-class-declaration
1305 objc-alias-declaration
1306 objc-protocol-definition
1307 objc-method-definition
1312 c_parser_external_declaration (c_parser
*parser
)
1315 switch (c_parser_peek_token (parser
)->type
)
1318 switch (c_parser_peek_token (parser
)->keyword
)
1321 ext
= disable_extension_diagnostics ();
1322 c_parser_consume_token (parser
);
1323 c_parser_external_declaration (parser
);
1324 restore_extension_diagnostics (ext
);
1327 c_parser_asm_definition (parser
);
1329 case RID_AT_INTERFACE
:
1330 case RID_AT_IMPLEMENTATION
:
1331 gcc_assert (c_dialect_objc ());
1332 c_parser_objc_class_definition (parser
, NULL_TREE
);
1335 gcc_assert (c_dialect_objc ());
1336 c_parser_objc_class_declaration (parser
);
1339 gcc_assert (c_dialect_objc ());
1340 c_parser_objc_alias_declaration (parser
);
1342 case RID_AT_PROTOCOL
:
1343 gcc_assert (c_dialect_objc ());
1344 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1346 case RID_AT_PROPERTY
:
1347 gcc_assert (c_dialect_objc ());
1348 c_parser_objc_at_property_declaration (parser
);
1350 case RID_AT_SYNTHESIZE
:
1351 gcc_assert (c_dialect_objc ());
1352 c_parser_objc_at_synthesize_declaration (parser
);
1354 case RID_AT_DYNAMIC
:
1355 gcc_assert (c_dialect_objc ());
1356 c_parser_objc_at_dynamic_declaration (parser
);
1359 gcc_assert (c_dialect_objc ());
1360 c_parser_consume_token (parser
);
1361 objc_finish_implementation ();
1368 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1369 "ISO C does not allow extra %<;%> outside of a function");
1370 c_parser_consume_token (parser
);
1373 mark_valid_location_for_stdc_pragma (true);
1374 c_parser_pragma (parser
, pragma_external
);
1375 mark_valid_location_for_stdc_pragma (false);
1379 if (c_dialect_objc ())
1381 c_parser_objc_method_definition (parser
);
1384 /* Else fall through, and yield a syntax error trying to parse
1385 as a declaration or function definition. */
1388 /* A declaration or a function definition (or, in Objective-C,
1389 an @interface or @protocol with prefix attributes). We can
1390 only tell which after parsing the declaration specifiers, if
1391 any, and the first declarator. */
1392 c_parser_declaration_or_fndef (parser
, true, true, true, false, true, NULL
);
1397 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1398 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1399 accepted; otherwise (old-style parameter declarations) only other
1400 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1401 assertion is accepted; otherwise (old-style parameter declarations)
1402 it is not. If NESTED is true, we are inside a function or parsing
1403 old-style parameter declarations; any functions encountered are
1404 nested functions and declaration specifiers are required; otherwise
1405 we are at top level and functions are normal functions and
1406 declaration specifiers may be optional. If EMPTY_OK is true, empty
1407 declarations are OK (subject to all other constraints); otherwise
1408 (old-style parameter declarations) they are diagnosed. If
1409 START_ATTR_OK is true, the declaration specifiers may start with
1410 attributes; otherwise they may not.
1411 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1412 declaration when parsing an Objective-C foreach statement.
1415 declaration-specifiers init-declarator-list[opt] ;
1416 static_assert-declaration
1418 function-definition:
1419 declaration-specifiers[opt] declarator declaration-list[opt]
1424 declaration-list declaration
1426 init-declarator-list:
1428 init-declarator-list , init-declarator
1431 declarator simple-asm-expr[opt] attributes[opt]
1432 declarator simple-asm-expr[opt] attributes[opt] = initializer
1436 nested-function-definition:
1437 declaration-specifiers declarator declaration-list[opt]
1441 attributes objc-class-definition
1442 attributes objc-category-definition
1443 attributes objc-protocol-definition
1445 The simple-asm-expr and attributes are GNU extensions.
1447 This function does not handle __extension__; that is handled in its
1448 callers. ??? Following the old parser, __extension__ may start
1449 external declarations, declarations in functions and declarations
1450 at the start of "for" loops, but not old-style parameter
1453 C99 requires declaration specifiers in a function definition; the
1454 absence is diagnosed through the diagnosis of implicit int. In GNU
1455 C we also allow but diagnose declarations without declaration
1456 specifiers, but only at top level (elsewhere they conflict with
1459 In Objective-C, declarations of the looping variable in a foreach
1460 statement are exceptionally terminated by 'in' (for example, 'for
1461 (NSObject *object in array) { ... }').
1466 threadprivate-directive */
1469 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1470 bool static_assert_ok
, bool empty_ok
,
1471 bool nested
, bool start_attr_ok
,
1472 tree
*objc_foreach_object_declaration
)
1474 struct c_declspecs
*specs
;
1476 tree all_prefix_attrs
;
1477 bool diagnosed_no_specs
= false;
1478 location_t here
= c_parser_peek_token (parser
)->location
;
1480 if (static_assert_ok
1481 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1483 c_parser_static_assert_declaration (parser
);
1486 specs
= build_null_declspecs ();
1488 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1489 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1490 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1491 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1492 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1493 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1495 error_at (here
, "unknown type name %qE",
1496 c_parser_peek_token (parser
)->value
);
1498 /* Parse declspecs normally to get a correct pointer type, but avoid
1499 a further "fails to be a type name" error. Refuse nested functions
1500 since it is not how the user likely wants us to recover. */
1501 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1502 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1503 c_parser_peek_token (parser
)->value
= error_mark_node
;
1507 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
, cla_nonabstract_decl
);
1510 c_parser_skip_to_end_of_block_or_statement (parser
);
1513 if (nested
&& !specs
->declspecs_seen_p
)
1515 c_parser_error (parser
, "expected declaration specifiers");
1516 c_parser_skip_to_end_of_block_or_statement (parser
);
1519 finish_declspecs (specs
);
1520 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1526 shadow_tag_warned (specs
, 1);
1527 pedwarn (here
, 0, "empty declaration");
1529 c_parser_consume_token (parser
);
1533 /* Provide better error recovery. Note that a type name here is usually
1534 better diagnosed as a redeclaration. */
1536 && specs
->typespec_kind
== ctsk_tagdef
1537 && c_parser_next_token_starts_declspecs (parser
)
1538 && !c_parser_next_token_is (parser
, CPP_NAME
))
1540 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1541 parser
->error
= false;
1542 shadow_tag_warned (specs
, 1);
1545 else if (c_dialect_objc ())
1547 /* Prefix attributes are an error on method decls. */
1548 switch (c_parser_peek_token (parser
)->type
)
1552 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1556 warning_at (c_parser_peek_token (parser
)->location
,
1558 "prefix attributes are ignored for methods");
1559 specs
->attrs
= NULL_TREE
;
1562 c_parser_objc_method_definition (parser
);
1564 c_parser_objc_methodproto (parser
);
1570 /* This is where we parse 'attributes @interface ...',
1571 'attributes @implementation ...', 'attributes @protocol ...'
1572 (where attributes could be, for example, __attribute__
1575 switch (c_parser_peek_token (parser
)->keyword
)
1577 case RID_AT_INTERFACE
:
1579 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1581 c_parser_objc_class_definition (parser
, specs
->attrs
);
1585 case RID_AT_IMPLEMENTATION
:
1587 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1591 warning_at (c_parser_peek_token (parser
)->location
,
1593 "prefix attributes are ignored for implementations");
1594 specs
->attrs
= NULL_TREE
;
1596 c_parser_objc_class_definition (parser
, NULL_TREE
);
1600 case RID_AT_PROTOCOL
:
1602 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1604 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1611 case RID_AT_PROPERTY
:
1614 c_parser_error (parser
, "unexpected attribute");
1615 specs
->attrs
= NULL
;
1623 pending_xref_error ();
1624 prefix_attrs
= specs
->attrs
;
1625 all_prefix_attrs
= prefix_attrs
;
1626 specs
->attrs
= NULL_TREE
;
1629 struct c_declarator
*declarator
;
1633 /* Declaring either one or more declarators (in which case we
1634 should diagnose if there were no declaration specifiers) or a
1635 function definition (in which case the diagnostic for
1636 implicit int suffices). */
1637 declarator
= c_parser_declarator (parser
,
1638 specs
->typespec_kind
!= ctsk_none
,
1639 C_DTR_NORMAL
, &dummy
);
1640 if (declarator
== NULL
)
1642 c_parser_skip_to_end_of_block_or_statement (parser
);
1645 if (c_parser_next_token_is (parser
, CPP_EQ
)
1646 || c_parser_next_token_is (parser
, CPP_COMMA
)
1647 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1648 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1649 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1650 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1652 tree asm_name
= NULL_TREE
;
1653 tree postfix_attrs
= NULL_TREE
;
1654 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1656 diagnosed_no_specs
= true;
1657 pedwarn (here
, 0, "data definition has no type or storage class");
1659 /* Having seen a data definition, there cannot now be a
1660 function definition. */
1662 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1663 asm_name
= c_parser_simple_asm_expr (parser
);
1664 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1665 postfix_attrs
= c_parser_attributes (parser
);
1666 if (c_parser_next_token_is (parser
, CPP_EQ
))
1670 location_t init_loc
;
1671 c_parser_consume_token (parser
);
1672 /* The declaration of the variable is in effect while
1673 its initializer is parsed. */
1674 d
= start_decl (declarator
, specs
, true,
1675 chainon (postfix_attrs
, all_prefix_attrs
));
1677 d
= error_mark_node
;
1678 start_init (d
, asm_name
, global_bindings_p ());
1679 init_loc
= c_parser_peek_token (parser
)->location
;
1680 init
= c_parser_initializer (parser
);
1682 if (d
!= error_mark_node
)
1684 maybe_warn_string_init (TREE_TYPE (d
), init
);
1685 finish_decl (d
, init_loc
, init
.value
,
1686 init
.original_type
, asm_name
);
1691 tree d
= start_decl (declarator
, specs
, false,
1692 chainon (postfix_attrs
,
1695 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1696 NULL_TREE
, asm_name
);
1698 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1701 *objc_foreach_object_declaration
= d
;
1703 *objc_foreach_object_declaration
= error_mark_node
;
1706 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1708 c_parser_consume_token (parser
);
1709 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1710 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1713 all_prefix_attrs
= prefix_attrs
;
1716 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1718 c_parser_consume_token (parser
);
1721 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1723 /* This can only happen in Objective-C: we found the
1724 'in' that terminates the declaration inside an
1725 Objective-C foreach statement. Do not consume the
1726 token, so that the caller can use it to determine
1727 that this indeed is a foreach context. */
1732 c_parser_error (parser
, "expected %<,%> or %<;%>");
1733 c_parser_skip_to_end_of_block_or_statement (parser
);
1739 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1740 "%<asm%> or %<__attribute__%>");
1741 c_parser_skip_to_end_of_block_or_statement (parser
);
1744 /* Function definition (nested or otherwise). */
1747 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1748 c_push_function_context ();
1750 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1752 /* This can appear in many cases looking nothing like a
1753 function definition, so we don't give a more specific
1754 error suggesting there was one. */
1755 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1756 "or %<__attribute__%>");
1758 c_pop_function_context ();
1762 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1763 tv
= TV_PARSE_INLINE
;
1768 /* Parse old-style parameter declarations. ??? Attributes are
1769 not allowed to start declaration specifiers here because of a
1770 syntax conflict between a function declaration with attribute
1771 suffix and a function definition with an attribute prefix on
1772 first old-style parameter declaration. Following the old
1773 parser, they are not accepted on subsequent old-style
1774 parameter declarations either. However, there is no
1775 ambiguity after the first declaration, nor indeed on the
1776 first as long as we don't allow postfix attributes after a
1777 declarator with a nonempty identifier list in a definition;
1778 and postfix attributes have never been accepted here in
1779 function definitions either. */
1780 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1781 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1782 c_parser_declaration_or_fndef (parser
, false, false, false,
1784 store_parm_decls ();
1785 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1786 = c_parser_peek_token (parser
)->location
;
1787 fnbody
= c_parser_compound_statement (parser
);
1788 if (flag_enable_cilkplus
&& contains_array_notation_expr (fnbody
))
1789 fnbody
= expand_array_notation_exprs (fnbody
);
1792 tree decl
= current_function_decl
;
1793 /* Mark nested functions as needing static-chain initially.
1794 lower_nested_functions will recompute it but the
1795 DECL_STATIC_CHAIN flag is also used before that happens,
1796 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1797 DECL_STATIC_CHAIN (decl
) = 1;
1800 c_pop_function_context ();
1801 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1814 /* Parse an asm-definition (asm() outside a function body). This is a
1822 c_parser_asm_definition (c_parser
*parser
)
1824 tree asm_str
= c_parser_simple_asm_expr (parser
);
1826 add_asm_node (asm_str
);
1827 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1830 /* Parse a static assertion (C11 6.7.10).
1832 static_assert-declaration:
1833 static_assert-declaration-no-semi ;
1837 c_parser_static_assert_declaration (c_parser
*parser
)
1839 c_parser_static_assert_declaration_no_semi (parser
);
1841 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1842 c_parser_skip_to_end_of_block_or_statement (parser
);
1845 /* Parse a static assertion (C11 6.7.10), without the trailing
1848 static_assert-declaration-no-semi:
1849 _Static_assert ( constant-expression , string-literal )
1853 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1855 location_t assert_loc
, value_loc
;
1859 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1860 assert_loc
= c_parser_peek_token (parser
)->location
;
1864 pedwarn (assert_loc
, OPT_Wpedantic
,
1865 "ISO C99 does not support %<_Static_assert%>");
1867 pedwarn (assert_loc
, OPT_Wpedantic
,
1868 "ISO C90 does not support %<_Static_assert%>");
1870 c_parser_consume_token (parser
);
1871 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1873 value_loc
= c_parser_peek_token (parser
)->location
;
1874 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1875 parser
->lex_untranslated_string
= true;
1876 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
1878 parser
->lex_untranslated_string
= false;
1881 switch (c_parser_peek_token (parser
)->type
)
1887 case CPP_UTF8STRING
:
1888 string
= c_parser_peek_token (parser
)->value
;
1889 c_parser_consume_token (parser
);
1890 parser
->lex_untranslated_string
= false;
1893 c_parser_error (parser
, "expected string literal");
1894 parser
->lex_untranslated_string
= false;
1897 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
1899 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
1901 error_at (value_loc
, "expression in static assertion is not an integer");
1904 if (TREE_CODE (value
) != INTEGER_CST
)
1906 value
= c_fully_fold (value
, false, NULL
);
1907 if (TREE_CODE (value
) == INTEGER_CST
)
1908 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
1909 "is not an integer constant expression");
1911 if (TREE_CODE (value
) != INTEGER_CST
)
1913 error_at (value_loc
, "expression in static assertion is not constant");
1916 constant_expression_warning (value
);
1917 if (integer_zerop (value
))
1918 error_at (assert_loc
, "static assertion failed: %E", string
);
1921 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1922 6.7), adding them to SPECS (which may already include some).
1923 Storage class specifiers are accepted iff SCSPEC_OK; type
1924 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1925 the start iff START_ATTR_OK.
1927 declaration-specifiers:
1928 storage-class-specifier declaration-specifiers[opt]
1929 type-specifier declaration-specifiers[opt]
1930 type-qualifier declaration-specifiers[opt]
1931 function-specifier declaration-specifiers[opt]
1932 alignment-specifier declaration-specifiers[opt]
1934 Function specifiers (inline) are from C99, and are currently
1935 handled as storage class specifiers, as is __thread. Alignment
1936 specifiers are from C11.
1938 C90 6.5.1, C99 6.7.1:
1939 storage-class-specifier:
1951 (_Noreturn is new in C11.)
1953 C90 6.5.2, C99 6.7.2:
1966 [_Imaginary removed in C99 TC2]
1967 struct-or-union-specifier
1971 (_Bool and _Complex are new in C99.)
1973 C90 6.5.3, C99 6.7.3:
1979 address-space-qualifier
1981 (restrict is new in C99.)
1985 declaration-specifiers:
1986 attributes declaration-specifiers[opt]
1992 identifier recognized by the target
1994 storage-class-specifier:
2007 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2008 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2013 class-name objc-protocol-refs[opt]
2014 typedef-name objc-protocol-refs
2019 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2020 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2021 enum c_lookahead_kind la
)
2023 bool attrs_ok
= start_attr_ok
;
2024 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2027 gcc_assert (la
== cla_prefer_id
);
2029 while (c_parser_next_token_is (parser
, CPP_NAME
)
2030 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2031 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2033 struct c_typespec t
;
2036 location_t loc
= c_parser_peek_token (parser
)->location
;
2038 /* If we cannot accept a type, exit if the next token must start
2039 one. Also, if we already have seen a tagged definition,
2040 a typename would be an error anyway and likely the user
2041 has simply forgotten a semicolon, so we exit. */
2042 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2043 && c_parser_next_tokens_start_typename (parser
, la
)
2044 && !c_parser_next_token_is_qualifier (parser
))
2047 if (c_parser_next_token_is (parser
, CPP_NAME
))
2049 c_token
*name_token
= c_parser_peek_token (parser
);
2050 tree value
= name_token
->value
;
2051 c_id_kind kind
= name_token
->id_kind
;
2053 if (kind
== C_ID_ADDRSPACE
)
2056 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2057 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2058 c_parser_consume_token (parser
);
2063 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2065 /* If we cannot accept a type, and the next token must start one,
2066 exit. Do the same if we already have seen a tagged definition,
2067 since it would be an error anyway and likely the user has simply
2068 forgotten a semicolon. */
2069 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2072 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2073 a C_ID_CLASSNAME. */
2074 c_parser_consume_token (parser
);
2077 if (kind
== C_ID_ID
)
2079 error ("unknown type name %qE", value
);
2080 t
.kind
= ctsk_typedef
;
2081 t
.spec
= error_mark_node
;
2083 else if (kind
== C_ID_TYPENAME
2084 && (!c_dialect_objc ()
2085 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2087 t
.kind
= ctsk_typedef
;
2088 /* For a typedef name, record the meaning, not the name.
2089 In case of 'foo foo, bar;'. */
2090 t
.spec
= lookup_name (value
);
2094 tree proto
= NULL_TREE
;
2095 gcc_assert (c_dialect_objc ());
2097 if (c_parser_next_token_is (parser
, CPP_LESS
))
2098 proto
= c_parser_objc_protocol_refs (parser
);
2099 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2102 t
.expr_const_operands
= true;
2103 declspecs_add_type (name_token
->location
, specs
, t
);
2106 if (c_parser_next_token_is (parser
, CPP_LESS
))
2108 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2109 nisse@lysator.liu.se. */
2111 gcc_assert (c_dialect_objc ());
2112 if (!typespec_ok
|| seen_type
)
2114 proto
= c_parser_objc_protocol_refs (parser
);
2116 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2118 t
.expr_const_operands
= true;
2119 declspecs_add_type (loc
, specs
, t
);
2122 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2123 switch (c_parser_peek_token (parser
)->keyword
)
2136 /* TODO: Distinguish between function specifiers (inline, noreturn)
2137 and storage class specifiers, either here or in
2138 declspecs_add_scspec. */
2139 declspecs_add_scspec (loc
, specs
,
2140 c_parser_peek_token (parser
)->value
);
2141 c_parser_consume_token (parser
);
2165 if (c_dialect_objc ())
2166 parser
->objc_need_raw_identifier
= true;
2167 t
.kind
= ctsk_resword
;
2168 t
.spec
= c_parser_peek_token (parser
)->value
;
2170 t
.expr_const_operands
= true;
2171 declspecs_add_type (loc
, specs
, t
);
2172 c_parser_consume_token (parser
);
2179 t
= c_parser_enum_specifier (parser
);
2180 declspecs_add_type (loc
, specs
, t
);
2188 t
= c_parser_struct_or_union_specifier (parser
);
2189 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2190 declspecs_add_type (loc
, specs
, t
);
2193 /* ??? The old parser rejected typeof after other type
2194 specifiers, but is a syntax error the best way of
2196 if (!typespec_ok
|| seen_type
)
2200 t
= c_parser_typeof_specifier (parser
);
2201 declspecs_add_type (loc
, specs
, t
);
2207 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2208 c_parser_consume_token (parser
);
2210 /* UPC qualifiers */
2213 c_parser_upc_shared_qual (loc
, parser
, specs
);
2218 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2219 c_parser_consume_token (parser
);
2224 attrs
= c_parser_attributes (parser
);
2225 declspecs_add_attrs (loc
, specs
, attrs
);
2228 align
= c_parser_alignas_specifier (parser
);
2229 declspecs_add_alignas (loc
, specs
, align
);
2238 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2241 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2242 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2243 enum attributes[opt] identifier
2245 The form with trailing comma is new in C99. The forms with
2246 attributes are GNU extensions. In GNU C, we accept any expression
2247 without commas in the syntax (assignment expressions, not just
2248 conditional expressions); assignment expressions will be diagnosed
2253 enumerator-list , enumerator
2256 enumeration-constant
2257 enumeration-constant = constant-expression
2260 static struct c_typespec
2261 c_parser_enum_specifier (c_parser
*parser
)
2263 struct c_typespec ret
;
2265 tree ident
= NULL_TREE
;
2266 location_t enum_loc
;
2267 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2268 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2269 enum_loc
= c_parser_peek_token (parser
)->location
;
2270 c_parser_consume_token (parser
);
2271 attrs
= c_parser_attributes (parser
);
2272 enum_loc
= c_parser_peek_token (parser
)->location
;
2273 /* Set the location in case we create a decl now. */
2274 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2275 if (c_parser_next_token_is (parser
, CPP_NAME
))
2277 ident
= c_parser_peek_token (parser
)->value
;
2278 ident_loc
= c_parser_peek_token (parser
)->location
;
2279 enum_loc
= ident_loc
;
2280 c_parser_consume_token (parser
);
2282 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2284 /* Parse an enum definition. */
2285 struct c_enum_contents the_enum
;
2288 /* We chain the enumerators in reverse order, then put them in
2289 forward order at the end. */
2291 timevar_push (TV_PARSE_ENUM
);
2292 type
= start_enum (enum_loc
, &the_enum
, ident
);
2294 c_parser_consume_token (parser
);
2302 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2303 location_t decl_loc
, value_loc
;
2304 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2306 c_parser_error (parser
, "expected identifier");
2307 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2308 values
= error_mark_node
;
2311 token
= c_parser_peek_token (parser
);
2312 enum_id
= token
->value
;
2313 /* Set the location in case we create a decl now. */
2314 c_parser_set_source_position_from_token (token
);
2315 decl_loc
= value_loc
= token
->location
;
2316 c_parser_consume_token (parser
);
2317 if (c_parser_next_token_is (parser
, CPP_EQ
))
2319 c_parser_consume_token (parser
);
2320 value_loc
= c_parser_peek_token (parser
)->location
;
2321 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2324 enum_value
= NULL_TREE
;
2325 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2326 &the_enum
, enum_id
, enum_value
);
2327 TREE_CHAIN (enum_decl
) = values
;
2330 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2332 comma_loc
= c_parser_peek_token (parser
)->location
;
2334 c_parser_consume_token (parser
);
2336 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2338 if (seen_comma
&& !flag_isoc99
)
2339 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2340 c_parser_consume_token (parser
);
2345 c_parser_error (parser
, "expected %<,%> or %<}%>");
2346 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2347 values
= error_mark_node
;
2351 postfix_attrs
= c_parser_attributes (parser
);
2352 ret
.spec
= finish_enum (type
, nreverse (values
),
2353 chainon (attrs
, postfix_attrs
));
2354 ret
.kind
= ctsk_tagdef
;
2355 ret
.expr
= NULL_TREE
;
2356 ret
.expr_const_operands
= true;
2357 timevar_pop (TV_PARSE_ENUM
);
2362 c_parser_error (parser
, "expected %<{%>");
2363 ret
.spec
= error_mark_node
;
2364 ret
.kind
= ctsk_tagref
;
2365 ret
.expr
= NULL_TREE
;
2366 ret
.expr_const_operands
= true;
2369 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2370 /* In ISO C, enumerated types can be referred to only if already
2372 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2375 pedwarn (enum_loc
, OPT_Wpedantic
,
2376 "ISO C forbids forward references to %<enum%> types");
2381 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2383 struct-or-union-specifier:
2384 struct-or-union attributes[opt] identifier[opt]
2385 { struct-contents } attributes[opt]
2386 struct-or-union attributes[opt] identifier
2389 struct-declaration-list
2391 struct-declaration-list:
2392 struct-declaration ;
2393 struct-declaration-list struct-declaration ;
2400 struct-declaration-list struct-declaration
2402 struct-declaration-list:
2403 struct-declaration-list ;
2406 (Note that in the syntax here, unlike that in ISO C, the semicolons
2407 are included here rather than in struct-declaration, in order to
2408 describe the syntax with extra semicolons and missing semicolon at
2413 struct-declaration-list:
2414 @defs ( class-name )
2416 (Note this does not include a trailing semicolon, but can be
2417 followed by further declarations, and gets a pedwarn-if-pedantic
2418 when followed by a semicolon.) */
2420 static struct c_typespec
2421 c_parser_struct_or_union_specifier (c_parser
*parser
)
2423 struct c_typespec ret
;
2425 tree ident
= NULL_TREE
;
2426 location_t struct_loc
;
2427 location_t ident_loc
= UNKNOWN_LOCATION
;
2428 enum tree_code code
;
2429 switch (c_parser_peek_token (parser
)->keyword
)
2440 struct_loc
= c_parser_peek_token (parser
)->location
;
2441 c_parser_consume_token (parser
);
2442 attrs
= c_parser_attributes (parser
);
2444 /* Set the location in case we create a decl now. */
2445 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2447 if (c_parser_next_token_is (parser
, CPP_NAME
))
2449 ident
= c_parser_peek_token (parser
)->value
;
2450 ident_loc
= c_parser_peek_token (parser
)->location
;
2451 struct_loc
= ident_loc
;
2452 c_parser_consume_token (parser
);
2454 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2456 /* Parse a struct or union definition. Start the scope of the
2457 tag before parsing components. */
2458 struct c_struct_parse_info
*struct_info
;
2459 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2461 /* We chain the components in reverse order, then put them in
2462 forward order at the end. Each struct-declaration may
2463 declare multiple components (comma-separated), so we must use
2464 chainon to join them, although when parsing each
2465 struct-declaration we can use TREE_CHAIN directly.
2467 The theory behind all this is that there will be more
2468 semicolon separated fields than comma separated fields, and
2469 so we'll be minimizing the number of node traversals required
2472 timevar_push (TV_PARSE_STRUCT
);
2473 contents
= NULL_TREE
;
2474 c_parser_consume_token (parser
);
2475 /* Handle the Objective-C @defs construct,
2476 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2477 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2480 gcc_assert (c_dialect_objc ());
2481 c_parser_consume_token (parser
);
2482 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2484 if (c_parser_next_token_is (parser
, CPP_NAME
)
2485 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2487 name
= c_parser_peek_token (parser
)->value
;
2488 c_parser_consume_token (parser
);
2492 c_parser_error (parser
, "expected class name");
2493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2496 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2498 contents
= nreverse (objc_get_class_ivars (name
));
2501 /* Parse the struct-declarations and semicolons. Problems with
2502 semicolons are diagnosed here; empty structures are diagnosed
2507 /* Parse any stray semicolon. */
2508 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2510 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2511 "extra semicolon in struct or union specified");
2512 c_parser_consume_token (parser
);
2515 /* Stop if at the end of the struct or union contents. */
2516 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2518 c_parser_consume_token (parser
);
2521 /* Accept #pragmas at struct scope. */
2522 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2524 c_parser_pragma (parser
, pragma_external
);
2527 /* Parse some comma-separated declarations, but not the
2528 trailing semicolon if any. */
2529 decls
= c_parser_struct_declaration (parser
);
2530 contents
= chainon (decls
, contents
);
2531 /* If no semicolon follows, either we have a parse error or
2532 are at the end of the struct or union and should
2534 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2535 c_parser_consume_token (parser
);
2538 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2539 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2540 "no semicolon at end of struct or union");
2541 else if (parser
->error
2542 || !c_parser_next_token_starts_declspecs (parser
))
2544 c_parser_error (parser
, "expected %<;%>");
2545 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2549 /* If we come here, we have already emitted an error
2550 for an expected `;', identifier or `(', and we also
2551 recovered already. Go on with the next field. */
2554 postfix_attrs
= c_parser_attributes (parser
);
2555 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2556 chainon (attrs
, postfix_attrs
), struct_info
);
2557 ret
.kind
= ctsk_tagdef
;
2558 ret
.expr
= NULL_TREE
;
2559 ret
.expr_const_operands
= true;
2560 timevar_pop (TV_PARSE_STRUCT
);
2565 c_parser_error (parser
, "expected %<{%>");
2566 ret
.spec
= error_mark_node
;
2567 ret
.kind
= ctsk_tagref
;
2568 ret
.expr
= NULL_TREE
;
2569 ret
.expr_const_operands
= true;
2572 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2576 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2577 the trailing semicolon.
2580 specifier-qualifier-list struct-declarator-list
2581 static_assert-declaration-no-semi
2583 specifier-qualifier-list:
2584 type-specifier specifier-qualifier-list[opt]
2585 type-qualifier specifier-qualifier-list[opt]
2586 attributes specifier-qualifier-list[opt]
2588 struct-declarator-list:
2590 struct-declarator-list , attributes[opt] struct-declarator
2593 declarator attributes[opt]
2594 declarator[opt] : constant-expression attributes[opt]
2599 __extension__ struct-declaration
2600 specifier-qualifier-list
2602 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2603 of attributes where shown is a GNU extension. In GNU C, we accept
2604 any expression without commas in the syntax (assignment
2605 expressions, not just conditional expressions); assignment
2606 expressions will be diagnosed as non-constant. */
2609 c_parser_struct_declaration (c_parser
*parser
)
2611 struct c_declspecs
*specs
;
2613 tree all_prefix_attrs
;
2615 location_t decl_loc
;
2616 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2620 ext
= disable_extension_diagnostics ();
2621 c_parser_consume_token (parser
);
2622 decl
= c_parser_struct_declaration (parser
);
2623 restore_extension_diagnostics (ext
);
2626 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2628 c_parser_static_assert_declaration_no_semi (parser
);
2631 specs
= build_null_declspecs ();
2632 decl_loc
= c_parser_peek_token (parser
)->location
;
2633 c_parser_declspecs (parser
, specs
, false, true, true, cla_nonabstract_decl
);
2636 if (!specs
->declspecs_seen_p
)
2638 c_parser_error (parser
, "expected specifier-qualifier-list");
2641 finish_declspecs (specs
);
2642 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2643 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2646 if (specs
->typespec_kind
== ctsk_none
)
2648 pedwarn (decl_loc
, OPT_Wpedantic
,
2649 "ISO C forbids member declarations with no members");
2650 shadow_tag_warned (specs
, pedantic
);
2655 /* Support for unnamed structs or unions as members of
2656 structs or unions (which is [a] useful and [b] supports
2660 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2661 build_id_declarator (NULL_TREE
), specs
,
2664 decl_attributes (&ret
, attrs
, 0);
2669 /* Provide better error recovery. Note that a type name here is valid,
2670 and will be treated as a field name. */
2671 if (specs
->typespec_kind
== ctsk_tagdef
2672 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2673 && c_parser_next_token_starts_declspecs (parser
)
2674 && !c_parser_next_token_is (parser
, CPP_NAME
))
2676 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2677 parser
->error
= false;
2681 pending_xref_error ();
2682 prefix_attrs
= specs
->attrs
;
2683 all_prefix_attrs
= prefix_attrs
;
2684 specs
->attrs
= NULL_TREE
;
2688 /* Declaring one or more declarators or un-named bit-fields. */
2689 struct c_declarator
*declarator
;
2691 if (c_parser_next_token_is (parser
, CPP_COLON
))
2692 declarator
= build_id_declarator (NULL_TREE
);
2694 declarator
= c_parser_declarator (parser
,
2695 specs
->typespec_kind
!= ctsk_none
,
2696 C_DTR_NORMAL
, &dummy
);
2697 if (declarator
== NULL
)
2699 c_parser_skip_to_end_of_block_or_statement (parser
);
2702 if (c_parser_next_token_is (parser
, CPP_COLON
)
2703 || c_parser_next_token_is (parser
, CPP_COMMA
)
2704 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2705 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2706 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2708 tree postfix_attrs
= NULL_TREE
;
2709 tree width
= NULL_TREE
;
2711 if (c_parser_next_token_is (parser
, CPP_COLON
))
2713 c_parser_consume_token (parser
);
2714 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2716 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2717 postfix_attrs
= c_parser_attributes (parser
);
2718 d
= grokfield (c_parser_peek_token (parser
)->location
,
2719 declarator
, specs
, width
, &all_prefix_attrs
);
2720 decl_attributes (&d
, chainon (postfix_attrs
,
2721 all_prefix_attrs
), 0);
2722 DECL_CHAIN (d
) = decls
;
2724 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2725 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2728 all_prefix_attrs
= prefix_attrs
;
2729 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2730 c_parser_consume_token (parser
);
2731 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2732 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2734 /* Semicolon consumed in caller. */
2739 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2745 c_parser_error (parser
,
2746 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2747 "%<__attribute__%>");
2754 /* Parse a typeof specifier (a GNU extension).
2757 typeof ( expression )
2758 typeof ( type-name )
2761 static struct c_typespec
2762 c_parser_typeof_specifier (c_parser
*parser
)
2764 struct c_typespec ret
;
2765 ret
.kind
= ctsk_typeof
;
2766 ret
.spec
= error_mark_node
;
2767 ret
.expr
= NULL_TREE
;
2768 ret
.expr_const_operands
= true;
2769 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2770 c_parser_consume_token (parser
);
2771 c_inhibit_evaluation_warnings
++;
2773 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2775 c_inhibit_evaluation_warnings
--;
2779 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2781 struct c_type_name
*type
= c_parser_type_name (parser
);
2782 c_inhibit_evaluation_warnings
--;
2786 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2787 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2793 location_t here
= c_parser_peek_token (parser
)->location
;
2794 struct c_expr expr
= c_parser_expression (parser
);
2795 c_inhibit_evaluation_warnings
--;
2797 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2798 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2799 error_at (here
, "%<typeof%> applied to a bit-field");
2800 mark_exp_read (expr
.value
);
2801 ret
.spec
= TREE_TYPE (expr
.value
);
2802 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2803 /* This is returned with the type so that when the type is
2804 evaluated, this can be evaluated. */
2806 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
2807 pop_maybe_used (was_vm
);
2809 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2813 /* Parse an alignment-specifier.
2817 alignment-specifier:
2818 _Alignas ( type-name )
2819 _Alignas ( constant-expression )
2823 c_parser_alignas_specifier (c_parser
* parser
)
2825 tree ret
= error_mark_node
;
2826 location_t loc
= c_parser_peek_token (parser
)->location
;
2827 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
2828 c_parser_consume_token (parser
);
2832 pedwarn (loc
, OPT_Wpedantic
,
2833 "ISO C99 does not support %<_Alignas%>");
2835 pedwarn (loc
, OPT_Wpedantic
,
2836 "ISO C90 does not support %<_Alignas%>");
2838 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2840 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2842 struct c_type_name
*type
= c_parser_type_name (parser
);
2844 ret
= c_alignof (loc
, groktypename (type
, NULL
, NULL
));
2847 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
2848 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2852 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2853 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2854 be redeclared; otherwise it may not. KIND indicates which kind of
2855 declarator is wanted. Returns a valid declarator except in the
2856 case of a syntax error in which case NULL is returned. *SEEN_ID is
2857 set to true if an identifier being declared is seen; this is used
2858 to diagnose bad forms of abstract array declarators and to
2859 determine whether an identifier list is syntactically permitted.
2862 pointer[opt] direct-declarator
2866 ( attributes[opt] declarator )
2867 direct-declarator array-declarator
2868 direct-declarator ( parameter-type-list )
2869 direct-declarator ( identifier-list[opt] )
2872 * type-qualifier-list[opt]
2873 * type-qualifier-list[opt] pointer
2875 type-qualifier-list:
2878 type-qualifier-list type-qualifier
2879 type-qualifier-list attributes
2881 parameter-type-list:
2883 parameter-list , ...
2886 parameter-declaration
2887 parameter-list , parameter-declaration
2889 parameter-declaration:
2890 declaration-specifiers declarator attributes[opt]
2891 declaration-specifiers abstract-declarator[opt] attributes[opt]
2895 identifier-list , identifier
2897 abstract-declarator:
2899 pointer[opt] direct-abstract-declarator
2901 direct-abstract-declarator:
2902 ( attributes[opt] abstract-declarator )
2903 direct-abstract-declarator[opt] array-declarator
2904 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2909 direct-declarator ( parameter-forward-declarations
2910 parameter-type-list[opt] )
2912 direct-abstract-declarator:
2913 direct-abstract-declarator[opt] ( parameter-forward-declarations
2914 parameter-type-list[opt] )
2916 parameter-forward-declarations:
2918 parameter-forward-declarations parameter-list ;
2920 The uses of attributes shown above are GNU extensions.
2922 Some forms of array declarator are not included in C99 in the
2923 syntax for abstract declarators; these are disallowed elsewhere.
2924 This may be a defect (DR#289).
2926 This function also accepts an omitted abstract declarator as being
2927 an abstract declarator, although not part of the formal syntax. */
2929 static struct c_declarator
*
2930 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2933 /* Parse any initial pointer part. */
2934 if (c_parser_next_token_is (parser
, CPP_MULT
))
2936 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2937 struct c_declarator
*inner
;
2938 c_parser_consume_token (parser
);
2939 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
2940 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2944 return make_pointer_declarator (quals_attrs
, inner
);
2946 /* Now we have a direct declarator, direct abstract declarator or
2947 nothing (which counts as a direct abstract declarator here). */
2948 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2951 /* Parse a direct declarator or direct abstract declarator; arguments
2952 as c_parser_declarator. */
2954 static struct c_declarator
*
2955 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2958 /* The direct declarator must start with an identifier (possibly
2959 omitted) or a parenthesized declarator (possibly abstract). In
2960 an ordinary declarator, initial parentheses must start a
2961 parenthesized declarator. In an abstract declarator or parameter
2962 declarator, they could start a parenthesized declarator or a
2963 parameter list. To tell which, the open parenthesis and any
2964 following attributes must be read. If a declaration specifier
2965 follows, then it is a parameter list; if the specifier is a
2966 typedef name, there might be an ambiguity about redeclaring it,
2967 which is resolved in the direction of treating it as a typedef
2968 name. If a close parenthesis follows, it is also an empty
2969 parameter list, as the syntax does not permit empty abstract
2970 declarators. Otherwise, it is a parenthesized declarator (in
2971 which case the analysis may be repeated inside it, recursively).
2973 ??? There is an ambiguity in a parameter declaration "int
2974 (__attribute__((foo)) x)", where x is not a typedef name: it
2975 could be an abstract declarator for a function, or declare x with
2976 parentheses. The proper resolution of this ambiguity needs
2977 documenting. At present we follow an accident of the old
2978 parser's implementation, whereby the first parameter must have
2979 some declaration specifiers other than just attributes. Thus as
2980 a parameter declaration it is treated as a parenthesized
2981 parameter named x, and as an abstract declarator it is
2984 ??? Also following the old parser, attributes inside an empty
2985 parameter list are ignored, making it a list not yielding a
2986 prototype, rather than giving an error or making it have one
2987 parameter with implicit type int.
2989 ??? Also following the old parser, typedef names may be
2990 redeclared in declarators, but not Objective-C class names. */
2992 if (kind
!= C_DTR_ABSTRACT
2993 && c_parser_next_token_is (parser
, CPP_NAME
)
2995 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
2996 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
2997 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2999 struct c_declarator
*inner
3000 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3002 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3003 c_parser_consume_token (parser
);
3004 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3007 if (kind
!= C_DTR_NORMAL
3008 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3010 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3011 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3014 /* Either we are at the end of an abstract declarator, or we have
3017 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3020 struct c_declarator
*inner
;
3021 c_parser_consume_token (parser
);
3022 attrs
= c_parser_attributes (parser
);
3023 if (kind
!= C_DTR_NORMAL
3024 && (c_parser_next_token_starts_declspecs (parser
)
3025 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3027 struct c_arg_info
*args
3028 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3035 = build_function_declarator (args
,
3036 build_id_declarator (NULL_TREE
));
3037 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3041 /* A parenthesized declarator. */
3042 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3043 if (inner
!= NULL
&& attrs
!= NULL
)
3044 inner
= build_attrs_declarator (attrs
, inner
);
3045 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3047 c_parser_consume_token (parser
);
3051 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3062 if (kind
== C_DTR_NORMAL
)
3064 c_parser_error (parser
, "expected identifier or %<(%>");
3068 return build_id_declarator (NULL_TREE
);
3072 /* Parse part of a direct declarator or direct abstract declarator,
3073 given that some (in INNER) has already been parsed; ID_PRESENT is
3074 true if an identifier is present, false for an abstract
3077 static struct c_declarator
*
3078 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3079 struct c_declarator
*inner
)
3081 /* Parse a sequence of array declarators and parameter lists. */
3082 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3084 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3085 struct c_declarator
*declarator
;
3086 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3090 c_parser_consume_token (parser
);
3091 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3092 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3094 c_parser_consume_token (parser
);
3095 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3096 c_parser_declspecs (parser
, quals_attrs
, false, false, true, cla_prefer_id
);
3097 if (!quals_attrs
->declspecs_seen_p
)
3099 /* If "static" is present, there must be an array dimension.
3100 Otherwise, there may be a dimension, "*", or no
3105 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3109 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3114 else if (flag_enable_cilkplus
3115 && c_parser_next_token_is (parser
, CPP_COLON
))
3117 dimen
= error_mark_node
;
3119 error_at (c_parser_peek_token (parser
)->location
,
3120 "array notations cannot be used in declaration");
3121 c_parser_consume_token (parser
);
3123 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3125 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3129 c_parser_consume_token (parser
);
3134 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3140 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
3143 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3144 c_parser_consume_token (parser
);
3145 else if (flag_enable_cilkplus
3146 && c_parser_next_token_is (parser
, CPP_COLON
))
3148 error_at (c_parser_peek_token (parser
)->location
,
3149 "array notations cannot be used in declaration");
3150 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3155 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3160 mark_exp_read (dimen
);
3161 declarator
= build_array_declarator (brace_loc
, dimen
, quals_attrs
,
3162 static_seen
, star_seen
);
3163 if (declarator
== NULL
)
3165 inner
= set_array_declarator_inner (declarator
, inner
);
3166 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3168 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3171 struct c_arg_info
*args
;
3172 c_parser_consume_token (parser
);
3173 attrs
= c_parser_attributes (parser
);
3174 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3179 inner
= build_function_declarator (args
, inner
);
3180 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3186 /* Parse a parameter list or identifier list, including the closing
3187 parenthesis but not the opening one. ATTRS are the attributes at
3188 the start of the list. ID_LIST_OK is true if an identifier list is
3189 acceptable; such a list must not have attributes at the start. */
3191 static struct c_arg_info
*
3192 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3195 declare_parm_level ();
3196 /* If the list starts with an identifier, it is an identifier list.
3197 Otherwise, it is either a prototype list or an empty list. */
3200 && c_parser_next_token_is (parser
, CPP_NAME
)
3201 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3203 /* Look ahead to detect typos in type names. */
3204 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3205 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3206 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3207 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3209 tree list
= NULL_TREE
, *nextp
= &list
;
3210 while (c_parser_next_token_is (parser
, CPP_NAME
)
3211 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3213 *nextp
= build_tree_list (NULL_TREE
,
3214 c_parser_peek_token (parser
)->value
);
3215 nextp
= & TREE_CHAIN (*nextp
);
3216 c_parser_consume_token (parser
);
3217 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3219 c_parser_consume_token (parser
);
3220 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3222 c_parser_error (parser
, "expected identifier");
3226 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3228 struct c_arg_info
*ret
= build_arg_info ();
3230 c_parser_consume_token (parser
);
3236 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3244 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3251 /* Parse a parameter list (possibly empty), including the closing
3252 parenthesis but not the opening one. ATTRS are the attributes at
3253 the start of the list. EXPR is NULL or an expression that needs to
3254 be evaluated for the side effects of array size expressions in the
3257 static struct c_arg_info
*
3258 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3260 bool bad_parm
= false;
3262 /* ??? Following the old parser, forward parameter declarations may
3263 use abstract declarators, and if no real parameter declarations
3264 follow the forward declarations then this is not diagnosed. Also
3265 note as above that attributes are ignored as the only contents of
3266 the parentheses, or as the only contents after forward
3268 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3270 struct c_arg_info
*ret
= build_arg_info ();
3271 c_parser_consume_token (parser
);
3274 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3276 struct c_arg_info
*ret
= build_arg_info ();
3278 if (flag_allow_parameterless_variadic_functions
)
3280 /* F (...) is allowed. */
3281 ret
->types
= NULL_TREE
;
3285 /* Suppress -Wold-style-definition for this case. */
3286 ret
->types
= error_mark_node
;
3287 error_at (c_parser_peek_token (parser
)->location
,
3288 "ISO C requires a named argument before %<...%>");
3290 c_parser_consume_token (parser
);
3291 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3293 c_parser_consume_token (parser
);
3298 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3303 /* Nonempty list of parameters, either terminated with semicolon
3304 (forward declarations; recurse) or with close parenthesis (normal
3305 function) or with ", ... )" (variadic function). */
3308 /* Parse a parameter. */
3309 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3314 push_parm_decl (parm
, &expr
);
3315 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3318 c_parser_consume_token (parser
);
3319 mark_forward_parm_decls ();
3320 new_attrs
= c_parser_attributes (parser
);
3321 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3323 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3325 c_parser_consume_token (parser
);
3329 return get_parm_info (false, expr
);
3331 if (!c_parser_require (parser
, CPP_COMMA
,
3332 "expected %<;%>, %<,%> or %<)%>"))
3334 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3337 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3339 c_parser_consume_token (parser
);
3340 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3342 c_parser_consume_token (parser
);
3346 return get_parm_info (true, expr
);
3350 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3358 /* Parse a parameter declaration. ATTRS are the attributes at the
3359 start of the declaration if it is the first parameter. */
3361 static struct c_parm
*
3362 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3364 struct c_declspecs
*specs
;
3365 struct c_declarator
*declarator
;
3367 tree postfix_attrs
= NULL_TREE
;
3370 /* Accept #pragmas between parameter declarations. */
3371 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3372 c_parser_pragma (parser
, pragma_external
);
3374 if (!c_parser_next_token_starts_declspecs (parser
))
3376 c_token
*token
= c_parser_peek_token (parser
);
3379 c_parser_set_source_position_from_token (token
);
3380 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3382 error ("unknown type name %qE", token
->value
);
3383 parser
->error
= true;
3385 /* ??? In some Objective-C cases '...' isn't applicable so there
3386 should be a different message. */
3388 c_parser_error (parser
,
3389 "expected declaration specifiers or %<...%>");
3390 c_parser_skip_to_end_of_parameter (parser
);
3393 specs
= build_null_declspecs ();
3396 declspecs_add_attrs (input_location
, specs
, attrs
);
3399 c_parser_declspecs (parser
, specs
, true, true, true, cla_nonabstract_decl
);
3400 finish_declspecs (specs
);
3401 pending_xref_error ();
3402 prefix_attrs
= specs
->attrs
;
3403 specs
->attrs
= NULL_TREE
;
3404 declarator
= c_parser_declarator (parser
,
3405 specs
->typespec_kind
!= ctsk_none
,
3406 C_DTR_PARM
, &dummy
);
3407 if (declarator
== NULL
)
3409 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3412 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3413 postfix_attrs
= c_parser_attributes (parser
);
3414 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3418 /* Parse a string literal in an asm expression. It should not be
3419 translated, and wide string literals are an error although
3420 permitted by the syntax. This is a GNU extension.
3425 ??? At present, following the old parser, the caller needs to have
3426 set lex_untranslated_string to 1. It would be better to follow the
3427 C++ parser rather than using this kludge. */
3430 c_parser_asm_string_literal (c_parser
*parser
)
3433 int save_flag
= warn_overlength_strings
;
3434 warn_overlength_strings
= 0;
3435 if (c_parser_next_token_is (parser
, CPP_STRING
))
3437 str
= c_parser_peek_token (parser
)->value
;
3438 c_parser_consume_token (parser
);
3440 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3442 error_at (c_parser_peek_token (parser
)->location
,
3443 "wide string literal in %<asm%>");
3444 str
= build_string (1, "");
3445 c_parser_consume_token (parser
);
3449 c_parser_error (parser
, "expected string literal");
3452 warn_overlength_strings
= save_flag
;
3456 /* Parse a simple asm expression. This is used in restricted
3457 contexts, where a full expression with inputs and outputs does not
3458 make sense. This is a GNU extension.
3461 asm ( asm-string-literal )
3465 c_parser_simple_asm_expr (c_parser
*parser
)
3468 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3469 /* ??? Follow the C++ parser rather than using the
3470 lex_untranslated_string kludge. */
3471 parser
->lex_untranslated_string
= true;
3472 c_parser_consume_token (parser
);
3473 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3475 parser
->lex_untranslated_string
= false;
3478 str
= c_parser_asm_string_literal (parser
);
3479 parser
->lex_untranslated_string
= false;
3480 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3482 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3489 c_parser_attribute_any_word (c_parser
*parser
)
3491 tree attr_name
= NULL_TREE
;
3493 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3495 /* ??? See comment above about what keywords are accepted here. */
3497 switch (c_parser_peek_token (parser
)->keyword
)
3528 case RID_TRANSACTION_ATOMIC
:
3529 case RID_TRANSACTION_CANCEL
:
3539 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3540 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3542 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3543 attr_name
= c_parser_peek_token (parser
)->value
;
3548 /* Parse (possibly empty) attributes. This is a GNU extension.
3552 attributes attribute
3555 __attribute__ ( ( attribute-list ) )
3559 attribute_list , attrib
3564 any-word ( identifier )
3565 any-word ( identifier , nonempty-expr-list )
3566 any-word ( expr-list )
3568 where the "identifier" must not be declared as a type, and
3569 "any-word" may be any identifier (including one declared as a
3570 type), a reserved word storage class specifier, type specifier or
3571 type qualifier. ??? This still leaves out most reserved keywords
3572 (following the old parser), shouldn't we include them, and why not
3573 allow identifiers declared as types to start the arguments? */
3576 c_parser_attributes (c_parser
*parser
)
3578 tree attrs
= NULL_TREE
;
3579 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3581 /* ??? Follow the C++ parser rather than using the
3582 lex_untranslated_string kludge. */
3583 parser
->lex_untranslated_string
= true;
3584 c_parser_consume_token (parser
);
3585 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3587 parser
->lex_untranslated_string
= false;
3590 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3592 parser
->lex_untranslated_string
= false;
3593 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3596 /* Parse the attribute list. */
3597 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3598 || c_parser_next_token_is (parser
, CPP_NAME
)
3599 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3601 tree attr
, attr_name
, attr_args
;
3602 vec
<tree
, va_gc
> *expr_list
;
3603 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3605 c_parser_consume_token (parser
);
3609 attr_name
= c_parser_attribute_any_word (parser
);
3610 if (attr_name
== NULL
)
3612 c_parser_consume_token (parser
);
3613 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3615 attr
= build_tree_list (attr_name
, NULL_TREE
);
3616 attrs
= chainon (attrs
, attr
);
3619 c_parser_consume_token (parser
);
3620 /* Parse the attribute contents. If they start with an
3621 identifier which is followed by a comma or close
3622 parenthesis, then the arguments start with that
3623 identifier; otherwise they are an expression list.
3624 In objective-c the identifier may be a classname. */
3625 if (c_parser_next_token_is (parser
, CPP_NAME
)
3626 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3627 || (c_dialect_objc ()
3628 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3629 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3630 || (c_parser_peek_2nd_token (parser
)->type
3631 == CPP_CLOSE_PAREN
)))
3633 tree arg1
= c_parser_peek_token (parser
)->value
;
3634 c_parser_consume_token (parser
);
3635 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3636 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3640 c_parser_consume_token (parser
);
3641 expr_list
= c_parser_expr_list (parser
, false, true,
3643 tree_list
= build_tree_list_vec (expr_list
);
3644 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3645 release_tree_vector (expr_list
);
3650 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3651 attr_args
= NULL_TREE
;
3654 expr_list
= c_parser_expr_list (parser
, false, true,
3656 attr_args
= build_tree_list_vec (expr_list
);
3657 release_tree_vector (expr_list
);
3660 attr
= build_tree_list (attr_name
, attr_args
);
3661 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3662 c_parser_consume_token (parser
);
3665 parser
->lex_untranslated_string
= false;
3666 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3670 attrs
= chainon (attrs
, attr
);
3672 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3673 c_parser_consume_token (parser
);
3676 parser
->lex_untranslated_string
= false;
3677 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3681 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3682 c_parser_consume_token (parser
);
3685 parser
->lex_untranslated_string
= false;
3686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3690 parser
->lex_untranslated_string
= false;
3695 /* Parse a type name (C90 6.5.5, C99 6.7.6).
3698 specifier-qualifier-list abstract-declarator[opt]
3701 static struct c_type_name
*
3702 c_parser_type_name (c_parser
*parser
)
3704 struct c_declspecs
*specs
= build_null_declspecs ();
3705 struct c_declarator
*declarator
;
3706 struct c_type_name
*ret
;
3708 c_parser_declspecs (parser
, specs
, false, true, true, cla_prefer_type
);
3709 if (!specs
->declspecs_seen_p
)
3711 c_parser_error (parser
, "expected specifier-qualifier-list");
3714 if (specs
->type
!= error_mark_node
)
3716 pending_xref_error ();
3717 finish_declspecs (specs
);
3719 declarator
= c_parser_declarator (parser
,
3720 specs
->typespec_kind
!= ctsk_none
,
3721 C_DTR_ABSTRACT
, &dummy
);
3722 if (declarator
== NULL
)
3724 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
3726 ret
->declarator
= declarator
;
3730 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3733 assignment-expression
3734 { initializer-list }
3735 { initializer-list , }
3738 designation[opt] initializer
3739 initializer-list , designation[opt] initializer
3746 designator-list designator
3753 [ constant-expression ]
3765 [ constant-expression ... constant-expression ]
3767 Any expression without commas is accepted in the syntax for the
3768 constant-expressions, with non-constant expressions rejected later.
3770 This function is only used for top-level initializers; for nested
3771 ones, see c_parser_initval. */
3773 static struct c_expr
3774 c_parser_initializer (c_parser
*parser
)
3776 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3777 return c_parser_braced_init (parser
, NULL_TREE
, false);
3781 location_t loc
= c_parser_peek_token (parser
)->location
;
3782 ret
= c_parser_expr_no_commas (parser
, NULL
);
3783 if (TREE_CODE (ret
.value
) != STRING_CST
3784 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3785 ret
= default_function_array_read_conversion (loc
, ret
);
3790 /* Parse a braced initializer list. TYPE is the type specified for a
3791 compound literal, and NULL_TREE for other initializers and for
3792 nested braced lists. NESTED_P is true for nested braced lists,
3793 false for the list of a compound literal or the list that is the
3794 top-level initializer in a declaration. */
3796 static struct c_expr
3797 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3800 struct obstack braced_init_obstack
;
3801 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3802 gcc_obstack_init (&braced_init_obstack
);
3803 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3804 c_parser_consume_token (parser
);
3806 push_init_level (0, &braced_init_obstack
);
3808 really_start_incremental_init (type
);
3809 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3811 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
3815 /* Parse a non-empty initializer list, possibly with a trailing
3819 c_parser_initelt (parser
, &braced_init_obstack
);
3822 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3823 c_parser_consume_token (parser
);
3826 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3830 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3832 ret
.value
= error_mark_node
;
3833 ret
.original_code
= ERROR_MARK
;
3834 ret
.original_type
= NULL
;
3835 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3836 pop_init_level (0, &braced_init_obstack
);
3837 obstack_free (&braced_init_obstack
, NULL
);
3840 c_parser_consume_token (parser
);
3841 ret
= pop_init_level (0, &braced_init_obstack
);
3842 obstack_free (&braced_init_obstack
, NULL
);
3846 /* Parse a nested initializer, including designators. */
3849 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
3851 /* Parse any designator or designator list. A single array
3852 designator may have the subsequent "=" omitted in GNU C, but a
3853 longer list or a structure member designator may not. */
3854 if (c_parser_next_token_is (parser
, CPP_NAME
)
3855 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3857 /* Old-style structure member designator. */
3858 set_init_label (c_parser_peek_token (parser
)->value
,
3859 braced_init_obstack
);
3860 /* Use the colon as the error location. */
3861 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
3862 "obsolete use of designated initializer with %<:%>");
3863 c_parser_consume_token (parser
);
3864 c_parser_consume_token (parser
);
3868 /* des_seen is 0 if there have been no designators, 1 if there
3869 has been a single array designator and 2 otherwise. */
3871 /* Location of a designator. */
3872 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3873 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3874 || c_parser_next_token_is (parser
, CPP_DOT
))
3876 int des_prev
= des_seen
;
3878 des_loc
= c_parser_peek_token (parser
)->location
;
3881 if (c_parser_next_token_is (parser
, CPP_DOT
))
3884 c_parser_consume_token (parser
);
3885 if (c_parser_next_token_is (parser
, CPP_NAME
))
3887 set_init_label (c_parser_peek_token (parser
)->value
,
3888 braced_init_obstack
);
3889 c_parser_consume_token (parser
);
3894 init
.value
= error_mark_node
;
3895 init
.original_code
= ERROR_MARK
;
3896 init
.original_type
= NULL
;
3897 c_parser_error (parser
, "expected identifier");
3898 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3899 process_init_element (init
, false, braced_init_obstack
);
3906 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
3907 /* ??? Following the old parser, [ objc-receiver
3908 objc-message-args ] is accepted as an initializer,
3909 being distinguished from a designator by what follows
3910 the first assignment expression inside the square
3911 brackets, but after a first array designator a
3912 subsequent square bracket is for Objective-C taken to
3913 start an expression, using the obsolete form of
3914 designated initializer without '=', rather than
3915 possibly being a second level of designation: in LALR
3916 terms, the '[' is shifted rather than reducing
3917 designator to designator-list. */
3918 if (des_prev
== 1 && c_dialect_objc ())
3920 des_seen
= des_prev
;
3923 if (des_prev
== 0 && c_dialect_objc ())
3925 /* This might be an array designator or an
3926 Objective-C message expression. If the former,
3927 continue parsing here; if the latter, parse the
3928 remainder of the initializer given the starting
3929 primary-expression. ??? It might make sense to
3930 distinguish when des_prev == 1 as well; see
3931 previous comment. */
3933 struct c_expr mexpr
;
3934 c_parser_consume_token (parser
);
3935 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3936 && ((c_parser_peek_token (parser
)->id_kind
3938 || (c_parser_peek_token (parser
)->id_kind
3939 == C_ID_CLASSNAME
)))
3941 /* Type name receiver. */
3942 tree id
= c_parser_peek_token (parser
)->value
;
3943 c_parser_consume_token (parser
);
3944 rec
= objc_get_class_reference (id
);
3945 goto parse_message_args
;
3947 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3948 mark_exp_read (first
);
3949 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3950 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3951 goto array_desig_after_first
;
3952 /* Expression receiver. So far only one part
3953 without commas has been parsed; there might be
3954 more of the expression. */
3956 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3959 location_t comma_loc
, exp_loc
;
3960 comma_loc
= c_parser_peek_token (parser
)->location
;
3961 c_parser_consume_token (parser
);
3962 exp_loc
= c_parser_peek_token (parser
)->location
;
3963 next
= c_parser_expr_no_commas (parser
, NULL
);
3964 next
= default_function_array_read_conversion (exp_loc
,
3966 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
3969 /* Now parse the objc-message-args. */
3970 args
= c_parser_objc_message_args (parser
);
3971 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3974 = objc_build_message_expr (rec
, args
);
3975 mexpr
.original_code
= ERROR_MARK
;
3976 mexpr
.original_type
= NULL
;
3977 /* Now parse and process the remainder of the
3978 initializer, starting with this message
3979 expression as a primary-expression. */
3980 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
3983 c_parser_consume_token (parser
);
3984 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3985 mark_exp_read (first
);
3986 array_desig_after_first
:
3987 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3989 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
3990 c_parser_consume_token (parser
);
3991 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3992 mark_exp_read (second
);
3996 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3998 c_parser_consume_token (parser
);
3999 set_init_index (first
, second
, braced_init_obstack
);
4001 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4002 "ISO C forbids specifying range of elements to initialize");
4005 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4011 if (c_parser_next_token_is (parser
, CPP_EQ
))
4014 pedwarn (des_loc
, OPT_Wpedantic
,
4015 "ISO C90 forbids specifying subobject to initialize");
4016 c_parser_consume_token (parser
);
4021 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4022 "obsolete use of designated initializer without %<=%>");
4026 init
.value
= error_mark_node
;
4027 init
.original_code
= ERROR_MARK
;
4028 init
.original_type
= NULL
;
4029 c_parser_error (parser
, "expected %<=%>");
4030 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4031 process_init_element (init
, false, braced_init_obstack
);
4037 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4040 /* Parse a nested initializer; as c_parser_initializer but parses
4041 initializers within braced lists, after any designators have been
4042 applied. If AFTER is not NULL then it is an Objective-C message
4043 expression which is the primary-expression starting the
4047 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4048 struct obstack
* braced_init_obstack
)
4051 gcc_assert (!after
|| c_dialect_objc ());
4052 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4053 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4056 location_t loc
= c_parser_peek_token (parser
)->location
;
4057 init
= c_parser_expr_no_commas (parser
, after
);
4058 if (init
.value
!= NULL_TREE
4059 && TREE_CODE (init
.value
) != STRING_CST
4060 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4061 init
= default_function_array_read_conversion (loc
, init
);
4063 process_init_element (init
, false, braced_init_obstack
);
4066 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4070 { block-item-list[opt] }
4071 { label-declarations block-item-list }
4075 block-item-list block-item
4087 { label-declarations block-item-list }
4090 __extension__ nested-declaration
4091 nested-function-definition
4095 label-declarations label-declaration
4098 __label__ identifier-list ;
4100 Allowing the mixing of declarations and code is new in C99. The
4101 GNU syntax also permits (not shown above) labels at the end of
4102 compound statements, which yield an error. We don't allow labels
4103 on declarations; this might seem like a natural extension, but
4104 there would be a conflict between attributes on the label and
4105 prefix attributes on the declaration. ??? The syntax follows the
4106 old parser in requiring something after label declarations.
4107 Although they are erroneous if the labels declared aren't defined,
4108 is it useful for the syntax to be this way?
4120 c_parser_compound_statement (c_parser
*parser
)
4123 location_t brace_loc
;
4124 brace_loc
= c_parser_peek_token (parser
)->location
;
4125 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4127 /* Ensure a scope is entered and left anyway to avoid confusion
4128 if we have just prepared to enter a function body. */
4129 stmt
= c_begin_compound_stmt (true);
4130 c_end_compound_stmt (brace_loc
, stmt
, true);
4131 return error_mark_node
;
4133 stmt
= c_begin_compound_stmt (true);
4134 c_parser_compound_statement_nostart (parser
);
4136 /* If the compound stmt contains array notations, then we expand them. */
4137 if (flag_enable_cilkplus
&& contains_array_notation_expr (stmt
))
4138 stmt
= expand_array_notation_exprs (stmt
);
4139 return c_end_compound_stmt (brace_loc
, stmt
, true);
4142 /* Parse a compound statement except for the opening brace. This is
4143 used for parsing both compound statements and statement expressions
4144 (which follow different paths to handling the opening). */
4147 c_parser_compound_statement_nostart (c_parser
*parser
)
4149 bool last_stmt
= false;
4150 bool last_label
= false;
4151 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4152 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4153 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4155 c_parser_consume_token (parser
);
4158 mark_valid_location_for_stdc_pragma (true);
4159 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4161 /* Read zero or more forward-declarations for labels that nested
4162 functions can jump to. */
4163 mark_valid_location_for_stdc_pragma (false);
4164 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4166 label_loc
= c_parser_peek_token (parser
)->location
;
4167 c_parser_consume_token (parser
);
4168 /* Any identifiers, including those declared as type names,
4173 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4175 c_parser_error (parser
, "expected identifier");
4179 = declare_label (c_parser_peek_token (parser
)->value
);
4180 C_DECLARED_LABEL_FLAG (label
) = 1;
4181 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4182 c_parser_consume_token (parser
);
4183 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4184 c_parser_consume_token (parser
);
4188 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4190 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4192 /* We must now have at least one statement, label or declaration. */
4193 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4195 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4196 c_parser_error (parser
, "expected declaration or statement");
4197 c_parser_consume_token (parser
);
4200 /* Process all #pragma's just after the opening brace. This
4201 handles #pragma upc, which can only appear just after
4202 the opening brace, when it appears within a function body. */
4203 push_upc_consistency_mode ();
4204 permit_pragma_upc ();
4205 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4207 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4208 if (c_parser_pragma (parser
, pragma_compound
))
4209 last_label
= false, last_stmt
= true;
4210 parser
->error
= false;
4213 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4215 location_t loc
= c_parser_peek_token (parser
)->location
;
4216 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4217 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4218 || (c_parser_next_token_is (parser
, CPP_NAME
)
4219 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4221 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4222 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4224 label_loc
= c_parser_peek_token (parser
)->location
;
4227 mark_valid_location_for_stdc_pragma (false);
4228 c_parser_label (parser
);
4230 else if (!last_label
4231 && c_parser_next_tokens_start_declaration (parser
))
4234 mark_valid_location_for_stdc_pragma (false);
4235 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
4238 (pedantic
&& !flag_isoc99
)
4240 : OPT_Wdeclaration_after_statement
,
4241 "ISO C90 forbids mixed declarations and code");
4244 else if (!last_label
4245 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4247 /* __extension__ can start a declaration, but is also an
4248 unary operator that can start an expression. Consume all
4249 but the last of a possible series of __extension__ to
4251 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4252 && (c_parser_peek_2nd_token (parser
)->keyword
4254 c_parser_consume_token (parser
);
4255 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4258 ext
= disable_extension_diagnostics ();
4259 c_parser_consume_token (parser
);
4261 mark_valid_location_for_stdc_pragma (false);
4262 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4264 /* Following the old parser, __extension__ does not
4265 disable this diagnostic. */
4266 restore_extension_diagnostics (ext
);
4268 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4270 : OPT_Wdeclaration_after_statement
,
4271 "ISO C90 forbids mixed declarations and code");
4277 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4279 /* External pragmas, and some omp pragmas, are not associated
4280 with regular c code, and so are not to be considered statements
4281 syntactically. This ensures that the user doesn't put them
4282 places that would turn into syntax errors if the directive
4284 if (c_parser_pragma (parser
, pragma_compound
))
4285 last_label
= false, last_stmt
= true;
4287 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4289 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4290 c_parser_error (parser
, "expected declaration or statement");
4293 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4295 if (parser
->in_if_block
)
4297 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4298 error_at (loc
, """expected %<}%> before %<else%>");
4303 error_at (loc
, "%<else%> without a previous %<if%>");
4304 c_parser_consume_token (parser
);
4313 mark_valid_location_for_stdc_pragma (false);
4314 c_parser_statement_after_labels (parser
);
4317 parser
->error
= false;
4320 error_at (label_loc
, "label at end of compound statement");
4321 c_parser_consume_token (parser
);
4322 pop_upc_consistency_mode ();
4323 /* Restore the value we started with. */
4324 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4327 /* Parse a label (C90 6.6.1, C99 6.8.1).
4330 identifier : attributes[opt]
4331 case constant-expression :
4337 case constant-expression ... constant-expression :
4339 The use of attributes on labels is a GNU extension. The syntax in
4340 GNU C accepts any expressions without commas, non-constant
4341 expressions being rejected later. */
4344 c_parser_label (c_parser
*parser
)
4346 location_t loc1
= c_parser_peek_token (parser
)->location
;
4347 tree label
= NULL_TREE
;
4348 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4351 c_parser_consume_token (parser
);
4352 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4353 if (c_parser_next_token_is (parser
, CPP_COLON
))
4355 c_parser_consume_token (parser
);
4356 label
= do_case (loc1
, exp1
, NULL_TREE
);
4358 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4360 c_parser_consume_token (parser
);
4361 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4362 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4363 label
= do_case (loc1
, exp1
, exp2
);
4366 c_parser_error (parser
, "expected %<:%> or %<...%>");
4368 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4370 c_parser_consume_token (parser
);
4371 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4372 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4376 tree name
= c_parser_peek_token (parser
)->value
;
4379 location_t loc2
= c_parser_peek_token (parser
)->location
;
4380 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4381 c_parser_consume_token (parser
);
4382 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4383 c_parser_consume_token (parser
);
4384 attrs
= c_parser_attributes (parser
);
4385 tlab
= define_label (loc2
, name
);
4388 decl_attributes (&tlab
, attrs
, 0);
4389 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4394 if (c_parser_next_tokens_start_declaration (parser
))
4396 error_at (c_parser_peek_token (parser
)->location
,
4397 "a label can only be part of a statement and "
4398 "a declaration is not a statement");
4399 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4400 /*static_assert_ok*/ true,
4401 /*empty_ok*/ true, /*nested*/ true,
4402 /*start_attr_ok*/ true, NULL
);
4407 /* Parse a statement (C90 6.6, C99 6.8).
4412 expression-statement
4420 expression-statement:
4423 selection-statement:
4427 iteration-statement:
4436 return expression[opt] ;
4449 objc-throw-statement
4450 objc-try-catch-statement
4451 objc-synchronized-statement
4453 objc-throw-statement:
4467 parallel-for-construct
4468 parallel-sections-construct
4475 parallel-directive structured-block
4478 for-directive iteration-statement
4481 sections-directive section-scope
4484 single-directive structured-block
4486 parallel-for-construct:
4487 parallel-for-directive iteration-statement
4489 parallel-sections-construct:
4490 parallel-sections-directive section-scope
4493 master-directive structured-block
4496 critical-directive structured-block
4499 atomic-directive expression-statement
4502 ordered-directive structured-block
4504 Transactional Memory:
4507 transaction-statement
4508 transaction-cancel-statement
4512 c_parser_statement (c_parser
*parser
)
4514 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4515 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4516 || (c_parser_next_token_is (parser
, CPP_NAME
)
4517 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4518 c_parser_label (parser
);
4519 c_parser_statement_after_labels (parser
);
4522 /* Parse a statement, other than a labeled statement. */
4525 c_parser_statement_after_labels (c_parser
*parser
)
4527 location_t loc
= c_parser_peek_token (parser
)->location
;
4528 tree stmt
= NULL_TREE
;
4529 bool in_if_block
= parser
->in_if_block
;
4530 parser
->in_if_block
= false;
4531 switch (c_parser_peek_token (parser
)->type
)
4533 case CPP_OPEN_BRACE
:
4534 add_stmt (c_parser_compound_statement (parser
));
4537 switch (c_parser_peek_token (parser
)->keyword
)
4540 c_parser_if_statement (parser
);
4543 c_parser_switch_statement (parser
);
4546 c_parser_while_statement (parser
);
4549 c_parser_do_statement (parser
);
4552 c_parser_for_statement (parser
);
4555 c_parser_consume_token (parser
);
4556 if (c_parser_next_token_is (parser
, CPP_NAME
))
4558 stmt
= c_finish_goto_label (loc
,
4559 c_parser_peek_token (parser
)->value
);
4560 c_parser_consume_token (parser
);
4562 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4566 c_parser_consume_token (parser
);
4567 val
= c_parser_expression (parser
).value
;
4568 mark_exp_read (val
);
4569 stmt
= c_finish_goto_ptr (loc
, val
);
4572 c_parser_error (parser
, "expected identifier or %<*%>");
4573 goto expect_semicolon
;
4575 c_parser_consume_token (parser
);
4576 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4577 goto expect_semicolon
;
4579 c_parser_consume_token (parser
);
4580 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4581 goto expect_semicolon
;
4583 c_parser_consume_token (parser
);
4584 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4586 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4587 c_parser_consume_token (parser
);
4591 struct c_expr expr
= c_parser_expression_conv (parser
);
4592 mark_exp_read (expr
.value
);
4593 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4594 goto expect_semicolon
;
4598 stmt
= c_parser_asm_statement (parser
);
4600 case RID_TRANSACTION_ATOMIC
:
4601 case RID_TRANSACTION_RELAXED
:
4602 stmt
= c_parser_transaction (parser
,
4603 c_parser_peek_token (parser
)->keyword
);
4605 case RID_TRANSACTION_CANCEL
:
4606 stmt
= c_parser_transaction_cancel (parser
);
4607 goto expect_semicolon
;
4609 gcc_assert (c_dialect_objc ());
4610 c_parser_consume_token (parser
);
4611 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4613 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4614 c_parser_consume_token (parser
);
4618 tree expr
= c_parser_expression (parser
).value
;
4619 expr
= c_fully_fold (expr
, false, NULL
);
4620 stmt
= objc_build_throw_stmt (loc
, expr
);
4621 goto expect_semicolon
;
4625 gcc_assert (c_dialect_objc ());
4626 c_parser_objc_try_catch_finally_statement (parser
);
4628 case RID_AT_SYNCHRONIZED
:
4629 gcc_assert (c_dialect_objc ());
4630 c_parser_objc_synchronized_statement (parser
);
4632 case RID_UPC_FORALL
:
4633 gcc_assert (c_dialect_upc ());
4634 c_parser_upc_forall_statement (parser
);
4636 case RID_UPC_NOTIFY
:
4637 gcc_assert (c_dialect_upc ());
4638 c_parser_upc_sync_statement (parser
, UPC_SYNC_NOTIFY_OP
);
4639 goto expect_semicolon
;
4641 gcc_assert (c_dialect_upc ());
4642 c_parser_upc_sync_statement (parser
, UPC_SYNC_WAIT_OP
);
4643 goto expect_semicolon
;
4644 case RID_UPC_BARRIER
:
4645 gcc_assert (c_dialect_upc ());
4646 c_parser_upc_sync_statement (parser
, UPC_SYNC_BARRIER_OP
);
4647 goto expect_semicolon
;
4653 c_parser_consume_token (parser
);
4655 case CPP_CLOSE_PAREN
:
4656 case CPP_CLOSE_SQUARE
:
4657 /* Avoid infinite loop in error recovery:
4658 c_parser_skip_until_found stops at a closing nesting
4659 delimiter without consuming it, but here we need to consume
4660 it to proceed further. */
4661 c_parser_error (parser
, "expected statement");
4662 c_parser_consume_token (parser
);
4665 c_parser_pragma (parser
, pragma_stmt
);
4669 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4671 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4674 /* Two cases cannot and do not have line numbers associated: If stmt
4675 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4676 cannot hold line numbers. But that's OK because the statement
4677 will either be changed to a MODIFY_EXPR during gimplification of
4678 the statement expr, or discarded. If stmt was compound, but
4679 without new variables, we will have skipped the creation of a
4680 BIND and will have a bare STATEMENT_LIST. But that's OK because
4681 (recursively) all of the component statements should already have
4682 line numbers assigned. ??? Can we discard no-op statements
4684 if (CAN_HAVE_LOCATION_P (stmt
)
4685 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4686 SET_EXPR_LOCATION (stmt
, loc
);
4688 parser
->in_if_block
= in_if_block
;
4691 /* Parse the condition from an if, do, while or for statements. */
4694 c_parser_condition (c_parser
*parser
)
4696 location_t loc ATTRIBUTE_UNUSED
= c_parser_peek_token (parser
)->location
;
4698 cond
= c_parser_expression_conv (parser
).value
;
4699 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
4700 cond
= c_fully_fold (cond
, false, NULL
);
4701 if (warn_sequence_point
)
4702 verify_sequence_points (cond
);
4706 /* Parse a parenthesized condition from an if, do or while statement.
4712 c_parser_paren_condition (c_parser
*parser
)
4715 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4716 return error_mark_node
;
4717 cond
= c_parser_condition (parser
);
4718 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4722 /* Parse a statement which is a block in C99. */
4725 c_parser_c99_block_statement (c_parser
*parser
)
4727 tree block
= c_begin_compound_stmt (flag_isoc99
);
4728 location_t loc
= c_parser_peek_token (parser
)->location
;
4729 c_parser_statement (parser
);
4730 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
4733 /* Parse the body of an if statement. This is just parsing a
4734 statement but (a) it is a block in C99, (b) we track whether the
4735 body is an if statement for the sake of -Wparentheses warnings, (c)
4736 we handle an empty body specially for the sake of -Wempty-body
4737 warnings, and (d) we call parser_compound_statement directly
4738 because c_parser_statement_after_labels resets
4739 parser->in_if_block. */
4742 c_parser_if_body (c_parser
*parser
, bool *if_p
)
4744 tree block
= c_begin_compound_stmt (flag_isoc99
);
4745 location_t body_loc
= c_parser_peek_token (parser
)->location
;
4746 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4747 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4748 || (c_parser_next_token_is (parser
, CPP_NAME
)
4749 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4750 c_parser_label (parser
);
4751 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
4752 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4754 location_t loc
= c_parser_peek_token (parser
)->location
;
4755 add_stmt (build_empty_stmt (loc
));
4756 c_parser_consume_token (parser
);
4757 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4758 warning_at (loc
, OPT_Wempty_body
,
4759 "suggest braces around empty body in an %<if%> statement");
4761 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4762 add_stmt (c_parser_compound_statement (parser
));
4764 c_parser_statement_after_labels (parser
);
4765 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
4768 /* Parse the else body of an if statement. This is just parsing a
4769 statement but (a) it is a block in C99, (b) we handle an empty body
4770 specially for the sake of -Wempty-body warnings. */
4773 c_parser_else_body (c_parser
*parser
)
4775 location_t else_loc
= c_parser_peek_token (parser
)->location
;
4776 tree block
= c_begin_compound_stmt (flag_isoc99
);
4777 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4778 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4779 || (c_parser_next_token_is (parser
, CPP_NAME
)
4780 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4781 c_parser_label (parser
);
4782 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4784 location_t loc
= c_parser_peek_token (parser
)->location
;
4787 "suggest braces around empty body in an %<else%> statement");
4788 add_stmt (build_empty_stmt (loc
));
4789 c_parser_consume_token (parser
);
4792 c_parser_statement_after_labels (parser
);
4793 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
4796 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
4799 if ( expression ) statement
4800 if ( expression ) statement else statement
4804 c_parser_if_statement (c_parser
*parser
)
4809 bool first_if
= false;
4810 tree first_body
, second_body
;
4814 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
4815 c_parser_consume_token (parser
);
4816 block
= c_begin_compound_stmt (flag_isoc99
);
4817 loc
= c_parser_peek_token (parser
)->location
;
4818 cond
= c_parser_paren_condition (parser
);
4819 in_if_block
= parser
->in_if_block
;
4820 parser
->in_if_block
= true;
4821 first_body
= c_parser_if_body (parser
, &first_if
);
4822 parser
->in_if_block
= in_if_block
;
4823 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4825 c_parser_consume_token (parser
);
4826 second_body
= c_parser_else_body (parser
);
4829 second_body
= NULL_TREE
;
4830 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
4831 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
4833 /* If the if statement contains array notations, then we expand them. */
4834 if (flag_enable_cilkplus
&& contains_array_notation_expr (if_stmt
))
4835 if_stmt
= fix_conditional_array_notations (if_stmt
);
4839 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
4842 switch (expression) statement
4846 c_parser_switch_statement (c_parser
*parser
)
4848 tree block
, expr
, body
, save_break
;
4849 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
4850 location_t switch_cond_loc
;
4851 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
4852 c_parser_consume_token (parser
);
4853 block
= c_begin_compound_stmt (flag_isoc99
);
4854 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4856 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
4857 expr
= c_parser_expression (parser
).value
;
4858 if (flag_enable_cilkplus
&& contains_array_notation_expr (expr
))
4860 error_at (switch_cond_loc
,
4861 "array notations cannot be used as a condition for switch "
4863 expr
= error_mark_node
;
4865 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4869 switch_cond_loc
= UNKNOWN_LOCATION
;
4870 expr
= error_mark_node
;
4872 c_start_case (switch_loc
, switch_cond_loc
, expr
);
4873 save_break
= c_break_label
;
4874 c_break_label
= NULL_TREE
;
4875 body
= c_parser_c99_block_statement (parser
);
4876 c_finish_case (body
);
4879 location_t here
= c_parser_peek_token (parser
)->location
;
4880 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
4881 SET_EXPR_LOCATION (t
, here
);
4884 c_break_label
= save_break
;
4885 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
4888 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
4891 while (expression) statement
4895 c_parser_while_statement (c_parser
*parser
)
4897 tree block
, cond
, body
, save_break
, save_cont
;
4899 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
4900 c_parser_consume_token (parser
);
4901 block
= c_begin_compound_stmt (flag_isoc99
);
4902 loc
= c_parser_peek_token (parser
)->location
;
4903 cond
= c_parser_paren_condition (parser
);
4904 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4906 error_at (loc
, "array notations cannot be used as a condition for while "
4908 cond
= error_mark_node
;
4910 save_break
= c_break_label
;
4911 c_break_label
= NULL_TREE
;
4912 save_cont
= c_cont_label
;
4913 c_cont_label
= NULL_TREE
;
4914 body
= c_parser_c99_block_statement (parser
);
4915 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
4916 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4917 c_break_label
= save_break
;
4918 c_cont_label
= save_cont
;
4921 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
4924 do statement while ( expression ) ;
4928 c_parser_do_statement (c_parser
*parser
)
4930 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
4932 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
4933 c_parser_consume_token (parser
);
4934 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4935 warning_at (c_parser_peek_token (parser
)->location
,
4937 "suggest braces around empty body in %<do%> statement");
4938 block
= c_begin_compound_stmt (flag_isoc99
);
4939 loc
= c_parser_peek_token (parser
)->location
;
4940 save_break
= c_break_label
;
4941 c_break_label
= NULL_TREE
;
4942 save_cont
= c_cont_label
;
4943 c_cont_label
= NULL_TREE
;
4944 body
= c_parser_c99_block_statement (parser
);
4945 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
4946 new_break
= c_break_label
;
4947 c_break_label
= save_break
;
4948 new_cont
= c_cont_label
;
4949 c_cont_label
= save_cont
;
4950 cond
= c_parser_paren_condition (parser
);
4951 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
4953 error_at (loc
, "array notations cannot be used as a condition for a "
4954 "do-while statement");
4955 cond
= error_mark_node
;
4958 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4959 c_parser_skip_to_end_of_block_or_statement (parser
);
4960 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
4961 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
4964 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4967 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4968 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4970 The form with a declaration is new in C99.
4972 ??? In accordance with the old parser, the declaration may be a
4973 nested function, which is then rejected in check_for_loop_decls,
4974 but does it make any sense for this to be included in the grammar?
4975 Note in particular that the nested function does not include a
4976 trailing ';', whereas the "declaration" production includes one.
4977 Also, can we reject bad declarations earlier and cheaper than
4978 check_for_loop_decls?
4980 In Objective-C, there are two additional variants:
4983 for ( expression in expresssion ) statement
4984 for ( declaration in expression ) statement
4986 This is inconsistent with C, because the second variant is allowed
4987 even if c99 is not enabled.
4989 The rest of the comment documents these Objective-C foreach-statement.
4991 Here is the canonical example of the first variant:
4992 for (object in array) { do something with object }
4993 we call the first expression ("object") the "object_expression" and
4994 the second expression ("array") the "collection_expression".
4995 object_expression must be an lvalue of type "id" (a generic Objective-C
4996 object) because the loop works by assigning to object_expression the
4997 various objects from the collection_expression. collection_expression
4998 must evaluate to something of type "id" which responds to the method
4999 countByEnumeratingWithState:objects:count:.
5001 The canonical example of the second variant is:
5002 for (id object in array) { do something with object }
5003 which is completely equivalent to
5006 for (object in array) { do something with object }
5008 Note that initizializing 'object' in some way (eg, "for ((object =
5009 xxx) in array) { do something with object }") is possibly
5010 technically valid, but completely pointless as 'object' will be
5011 assigned to something else as soon as the loop starts. We should
5012 most likely reject it (TODO).
5014 The beginning of the Objective-C foreach-statement looks exactly
5015 like the beginning of the for-statement, and we can tell it is a
5016 foreach-statement only because the initial declaration or
5017 expression is terminated by 'in' instead of ';'.
5021 c_parser_for_statement (c_parser
*parser
)
5023 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5024 /* The following are only used when parsing an ObjC foreach statement. */
5025 tree object_expression
;
5026 /* Silence the bogus uninitialized warning. */
5027 tree collection_expression
= NULL
;
5028 location_t loc
= c_parser_peek_token (parser
)->location
;
5029 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5030 bool is_foreach_statement
= false;
5031 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5032 c_parser_consume_token (parser
);
5033 /* Open a compound statement in Objective-C as well, just in case this is
5034 as foreach expression. */
5035 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5036 cond
= error_mark_node
;
5037 incr
= error_mark_node
;
5038 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5040 /* Parse the initialization declaration or expression. */
5041 object_expression
= error_mark_node
;
5042 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5043 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5045 parser
->objc_could_be_foreach_context
= false;
5046 c_parser_consume_token (parser
);
5047 c_finish_expr_stmt (loc
, NULL_TREE
);
5049 else if (c_parser_next_tokens_start_declaration (parser
))
5051 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5052 &object_expression
);
5053 parser
->objc_could_be_foreach_context
= false;
5055 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5057 c_parser_consume_token (parser
);
5058 is_foreach_statement
= true;
5059 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5060 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5063 check_for_loop_decls (for_loc
, flag_isoc99
);
5065 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5067 /* __extension__ can start a declaration, but is also an
5068 unary operator that can start an expression. Consume all
5069 but the last of a possible series of __extension__ to
5071 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5072 && (c_parser_peek_2nd_token (parser
)->keyword
5074 c_parser_consume_token (parser
);
5075 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5078 ext
= disable_extension_diagnostics ();
5079 c_parser_consume_token (parser
);
5080 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5081 true, &object_expression
);
5082 parser
->objc_could_be_foreach_context
= false;
5084 restore_extension_diagnostics (ext
);
5085 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5087 c_parser_consume_token (parser
);
5088 is_foreach_statement
= true;
5089 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5090 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5093 check_for_loop_decls (for_loc
, flag_isoc99
);
5102 tree init_expression
;
5103 init_expression
= c_parser_expression (parser
).value
;
5104 parser
->objc_could_be_foreach_context
= false;
5105 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5107 c_parser_consume_token (parser
);
5108 is_foreach_statement
= true;
5109 if (! lvalue_p (init_expression
))
5110 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5111 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5115 c_finish_expr_stmt (loc
, init_expression
);
5116 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5120 /* Parse the loop condition. In the case of a foreach
5121 statement, there is no loop condition. */
5122 gcc_assert (!parser
->objc_could_be_foreach_context
);
5123 if (!is_foreach_statement
)
5125 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5127 c_parser_consume_token (parser
);
5132 cond
= c_parser_condition (parser
);
5133 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
5135 error_at (loc
, "array notations cannot be used in a "
5136 "condition for a for-loop");
5137 cond
= error_mark_node
;
5139 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5143 /* Parse the increment expression (the third expression in a
5144 for-statement). In the case of a foreach-statement, this is
5145 the expression that follows the 'in'. */
5146 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5148 if (is_foreach_statement
)
5150 c_parser_error (parser
, "missing collection in fast enumeration");
5151 collection_expression
= error_mark_node
;
5154 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5158 if (is_foreach_statement
)
5159 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5162 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
5164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5166 save_break
= c_break_label
;
5167 c_break_label
= NULL_TREE
;
5168 save_cont
= c_cont_label
;
5169 c_cont_label
= NULL_TREE
;
5170 body
= c_parser_c99_block_statement (parser
);
5171 if (is_foreach_statement
)
5172 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5174 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5175 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5176 c_break_label
= save_break
;
5177 c_cont_label
= save_cont
;
5180 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5181 statement with inputs, outputs, clobbers, and volatile tag
5185 asm type-qualifier[opt] ( asm-argument ) ;
5186 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5190 asm-string-literal : asm-operands[opt]
5191 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5192 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5195 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5198 Qualifiers other than volatile are accepted in the syntax but
5202 c_parser_asm_statement (c_parser
*parser
)
5204 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5205 bool simple
, is_goto
;
5206 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5207 int section
, nsections
;
5209 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5210 c_parser_consume_token (parser
);
5211 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5213 quals
= c_parser_peek_token (parser
)->value
;
5214 c_parser_consume_token (parser
);
5216 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5217 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5219 warning_at (c_parser_peek_token (parser
)->location
,
5221 "%E qualifier ignored on asm",
5222 c_parser_peek_token (parser
)->value
);
5224 c_parser_consume_token (parser
);
5230 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5232 c_parser_consume_token (parser
);
5236 /* ??? Follow the C++ parser rather than using the
5237 lex_untranslated_string kludge. */
5238 parser
->lex_untranslated_string
= true;
5241 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5244 str
= c_parser_asm_string_literal (parser
);
5245 if (str
== NULL_TREE
)
5246 goto error_close_paren
;
5249 outputs
= NULL_TREE
;
5251 clobbers
= NULL_TREE
;
5254 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5257 /* Parse each colon-delimited section of operands. */
5258 nsections
= 3 + is_goto
;
5259 for (section
= 0; section
< nsections
; ++section
)
5261 if (!c_parser_require (parser
, CPP_COLON
,
5264 : "expected %<:%> or %<)%>"))
5265 goto error_close_paren
;
5267 /* Once past any colon, we're no longer a simple asm. */
5270 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5271 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5276 /* For asm goto, we don't allow output operands, but reserve
5277 the slot for a future extension that does allow them. */
5279 outputs
= c_parser_asm_operands (parser
);
5282 inputs
= c_parser_asm_operands (parser
);
5285 clobbers
= c_parser_asm_clobbers (parser
);
5288 labels
= c_parser_asm_goto_operands (parser
);
5294 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5299 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5305 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5306 c_parser_skip_to_end_of_block_or_statement (parser
);
5308 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5309 clobbers
, labels
, simple
));
5312 parser
->lex_untranslated_string
= false;
5316 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5320 /* Parse asm operands, a GNU extension.
5324 asm-operands , asm-operand
5327 asm-string-literal ( expression )
5328 [ identifier ] asm-string-literal ( expression )
5332 c_parser_asm_operands (c_parser
*parser
)
5334 tree list
= NULL_TREE
;
5339 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5341 c_parser_consume_token (parser
);
5342 if (c_parser_next_token_is (parser
, CPP_NAME
))
5344 tree id
= c_parser_peek_token (parser
)->value
;
5345 c_parser_consume_token (parser
);
5346 name
= build_string (IDENTIFIER_LENGTH (id
),
5347 IDENTIFIER_POINTER (id
));
5351 c_parser_error (parser
, "expected identifier");
5352 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5355 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5360 str
= c_parser_asm_string_literal (parser
);
5361 if (str
== NULL_TREE
)
5363 parser
->lex_untranslated_string
= false;
5364 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5366 parser
->lex_untranslated_string
= true;
5369 expr
= c_parser_expression (parser
);
5370 mark_exp_read (expr
.value
);
5371 parser
->lex_untranslated_string
= true;
5372 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5377 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5379 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5380 c_parser_consume_token (parser
);
5387 /* Parse asm clobbers, a GNU extension.
5391 asm-clobbers , asm-string-literal
5395 c_parser_asm_clobbers (c_parser
*parser
)
5397 tree list
= NULL_TREE
;
5400 tree str
= c_parser_asm_string_literal (parser
);
5402 list
= tree_cons (NULL_TREE
, str
, list
);
5405 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5406 c_parser_consume_token (parser
);
5413 /* Parse asm goto labels, a GNU extension.
5417 asm-goto-operands , identifier
5421 c_parser_asm_goto_operands (c_parser
*parser
)
5423 tree list
= NULL_TREE
;
5428 if (c_parser_next_token_is (parser
, CPP_NAME
))
5430 c_token
*tok
= c_parser_peek_token (parser
);
5432 label
= lookup_label_for_goto (tok
->location
, name
);
5433 c_parser_consume_token (parser
);
5434 TREE_USED (label
) = 1;
5438 c_parser_error (parser
, "expected identifier");
5442 name
= build_string (IDENTIFIER_LENGTH (name
),
5443 IDENTIFIER_POINTER (name
));
5444 list
= tree_cons (name
, label
, list
);
5445 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5446 c_parser_consume_token (parser
);
5448 return nreverse (list
);
5452 /* Parse an expression other than a compound expression; that is, an
5453 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5454 NULL then it is an Objective-C message expression which is the
5455 primary-expression starting the expression as an initializer.
5457 assignment-expression:
5458 conditional-expression
5459 unary-expression assignment-operator assignment-expression
5461 assignment-operator: one of
5462 = *= /= %= += -= <<= >>= &= ^= |=
5464 In GNU C we accept any conditional expression on the LHS and
5465 diagnose the invalid lvalue rather than producing a syntax
5468 static struct c_expr
5469 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
5471 struct c_expr lhs
, rhs
, ret
;
5472 enum tree_code code
;
5473 location_t op_location
, exp_location
;
5474 gcc_assert (!after
|| c_dialect_objc ());
5475 lhs
= c_parser_conditional_expression (parser
, after
);
5476 op_location
= c_parser_peek_token (parser
)->location
;
5477 switch (c_parser_peek_token (parser
)->type
)
5486 code
= TRUNC_DIV_EXPR
;
5489 code
= TRUNC_MOD_EXPR
;
5504 code
= BIT_AND_EXPR
;
5507 code
= BIT_XOR_EXPR
;
5510 code
= BIT_IOR_EXPR
;
5515 c_parser_consume_token (parser
);
5516 exp_location
= c_parser_peek_token (parser
)->location
;
5517 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5518 rhs
= default_function_array_read_conversion (exp_location
, rhs
);
5520 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5521 code
, exp_location
, rhs
.value
,
5523 if (code
== NOP_EXPR
)
5524 ret
.original_code
= MODIFY_EXPR
;
5527 TREE_NO_WARNING (ret
.value
) = 1;
5528 ret
.original_code
= ERROR_MARK
;
5530 ret
.original_type
= NULL
;
5534 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5535 is not NULL then it is an Objective-C message expression which is
5536 the primary-expression starting the expression as an initializer.
5538 conditional-expression:
5539 logical-OR-expression
5540 logical-OR-expression ? expression : conditional-expression
5544 conditional-expression:
5545 logical-OR-expression ? : conditional-expression
5548 static struct c_expr
5549 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
5551 struct c_expr cond
, exp1
, exp2
, ret
;
5552 location_t cond_loc
, colon_loc
, middle_loc
;
5554 gcc_assert (!after
|| c_dialect_objc ());
5556 cond
= c_parser_binary_expression (parser
, after
, PREC_NONE
);
5558 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5560 cond_loc
= c_parser_peek_token (parser
)->location
;
5561 cond
= default_function_array_read_conversion (cond_loc
, cond
);
5562 c_parser_consume_token (parser
);
5563 if (c_parser_next_token_is (parser
, CPP_COLON
))
5565 tree eptype
= NULL_TREE
;
5567 middle_loc
= c_parser_peek_token (parser
)->location
;
5568 pedwarn (middle_loc
, OPT_Wpedantic
,
5569 "ISO C forbids omitting the middle term of a ?: expression");
5570 warn_for_omitted_condop (middle_loc
, cond
.value
);
5571 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5573 eptype
= TREE_TYPE (cond
.value
);
5574 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5576 /* Make sure first operand is calculated only once. */
5577 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5579 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5580 exp1
.original_type
= NULL
;
5581 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5582 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5587 = c_objc_common_truthvalue_conversion
5588 (cond_loc
, default_conversion (cond
.value
));
5589 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5590 exp1
= c_parser_expression_conv (parser
);
5591 mark_exp_read (exp1
.value
);
5592 c_inhibit_evaluation_warnings
+=
5593 ((cond
.value
== truthvalue_true_node
)
5594 - (cond
.value
== truthvalue_false_node
));
5597 colon_loc
= c_parser_peek_token (parser
)->location
;
5598 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5600 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5601 ret
.value
= error_mark_node
;
5602 ret
.original_code
= ERROR_MARK
;
5603 ret
.original_type
= NULL
;
5607 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5608 exp2
= c_parser_conditional_expression (parser
, NULL
);
5609 exp2
= default_function_array_read_conversion (exp2_loc
, exp2
);
5611 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5612 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5613 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5614 exp1
.value
, exp1
.original_type
,
5615 exp2
.value
, exp2
.original_type
);
5616 ret
.original_code
= ERROR_MARK
;
5617 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5618 ret
.original_type
= NULL
;
5623 /* If both sides are enum type, the default conversion will have
5624 made the type of the result be an integer type. We want to
5625 remember the enum types we started with. */
5626 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5627 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5628 ret
.original_type
= ((t1
!= error_mark_node
5629 && t2
!= error_mark_node
5630 && (TYPE_MAIN_VARIANT (t1
)
5631 == TYPE_MAIN_VARIANT (t2
)))
5638 /* Parse a binary expression; that is, a logical-OR-expression (C90
5639 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5640 an Objective-C message expression which is the primary-expression
5641 starting the expression as an initializer. PREC is the starting
5642 precedence, usually PREC_NONE.
5644 multiplicative-expression:
5646 multiplicative-expression * cast-expression
5647 multiplicative-expression / cast-expression
5648 multiplicative-expression % cast-expression
5650 additive-expression:
5651 multiplicative-expression
5652 additive-expression + multiplicative-expression
5653 additive-expression - multiplicative-expression
5657 shift-expression << additive-expression
5658 shift-expression >> additive-expression
5660 relational-expression:
5662 relational-expression < shift-expression
5663 relational-expression > shift-expression
5664 relational-expression <= shift-expression
5665 relational-expression >= shift-expression
5667 equality-expression:
5668 relational-expression
5669 equality-expression == relational-expression
5670 equality-expression != relational-expression
5674 AND-expression & equality-expression
5676 exclusive-OR-expression:
5678 exclusive-OR-expression ^ AND-expression
5680 inclusive-OR-expression:
5681 exclusive-OR-expression
5682 inclusive-OR-expression | exclusive-OR-expression
5684 logical-AND-expression:
5685 inclusive-OR-expression
5686 logical-AND-expression && inclusive-OR-expression
5688 logical-OR-expression:
5689 logical-AND-expression
5690 logical-OR-expression || logical-AND-expression
5693 static struct c_expr
5694 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
5695 enum c_parser_prec prec
)
5697 /* A binary expression is parsed using operator-precedence parsing,
5698 with the operands being cast expressions. All the binary
5699 operators are left-associative. Thus a binary expression is of
5702 E0 op1 E1 op2 E2 ...
5704 which we represent on a stack. On the stack, the precedence
5705 levels are strictly increasing. When a new operator is
5706 encountered of higher precedence than that at the top of the
5707 stack, it is pushed; its LHS is the top expression, and its RHS
5708 is everything parsed until it is popped. When a new operator is
5709 encountered with precedence less than or equal to that at the top
5710 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
5711 by the result of the operation until the operator at the top of
5712 the stack has lower precedence than the new operator or there is
5713 only one element on the stack; then the top expression is the LHS
5714 of the new operator. In the case of logical AND and OR
5715 expressions, we also need to adjust c_inhibit_evaluation_warnings
5716 as appropriate when the operators are pushed and popped. */
5719 /* The expression at this stack level. */
5721 /* The precedence of the operator on its left, PREC_NONE at the
5722 bottom of the stack. */
5723 enum c_parser_prec prec
;
5724 /* The operation on its left. */
5726 /* The source location of this operation. */
5730 /* Location of the binary operator. */
5731 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
5734 switch (stack[sp].op) \
5736 case TRUTH_ANDIF_EXPR: \
5737 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5738 == truthvalue_false_node); \
5740 case TRUTH_ORIF_EXPR: \
5741 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
5742 == truthvalue_true_node); \
5747 stack[sp - 1].expr \
5748 = default_function_array_read_conversion (stack[sp - 1].loc, \
5749 stack[sp - 1].expr); \
5751 = default_function_array_read_conversion (stack[sp].loc, \
5753 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
5755 stack[sp - 1].expr, \
5759 gcc_assert (!after
|| c_dialect_objc ());
5760 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
5761 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
5762 stack
[0].prec
= prec
;
5766 enum c_parser_prec oprec
;
5767 enum tree_code ocode
;
5770 switch (c_parser_peek_token (parser
)->type
)
5778 ocode
= TRUNC_DIV_EXPR
;
5782 ocode
= TRUNC_MOD_EXPR
;
5794 ocode
= LSHIFT_EXPR
;
5798 ocode
= RSHIFT_EXPR
;
5812 case CPP_GREATER_EQ
:
5825 oprec
= PREC_BITAND
;
5826 ocode
= BIT_AND_EXPR
;
5829 oprec
= PREC_BITXOR
;
5830 ocode
= BIT_XOR_EXPR
;
5834 ocode
= BIT_IOR_EXPR
;
5837 oprec
= PREC_LOGAND
;
5838 ocode
= TRUTH_ANDIF_EXPR
;
5842 ocode
= TRUTH_ORIF_EXPR
;
5845 /* Not a binary operator, so end of the binary
5849 binary_loc
= c_parser_peek_token (parser
)->location
;
5850 while (oprec
<= stack
[sp
].prec
)
5856 c_parser_consume_token (parser
);
5859 case TRUTH_ANDIF_EXPR
:
5861 = default_function_array_read_conversion (stack
[sp
].loc
,
5863 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5864 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5865 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5866 == truthvalue_false_node
);
5868 case TRUTH_ORIF_EXPR
:
5870 = default_function_array_read_conversion (stack
[sp
].loc
,
5872 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
5873 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
5874 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
5875 == truthvalue_true_node
);
5881 stack
[sp
].loc
= binary_loc
;
5882 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
5883 stack
[sp
].prec
= oprec
;
5884 stack
[sp
].op
= ocode
;
5885 stack
[sp
].loc
= binary_loc
;
5890 return stack
[0].expr
;
5894 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
5895 NULL then it is an Objective-C message expression which is the
5896 primary-expression starting the expression as an initializer.
5900 ( type-name ) unary-expression
5903 static struct c_expr
5904 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
5906 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
5907 gcc_assert (!after
|| c_dialect_objc ());
5909 return c_parser_postfix_expression_after_primary (parser
,
5911 /* If the expression begins with a parenthesized type name, it may
5912 be either a cast or a compound literal; we need to see whether
5913 the next character is '{' to tell the difference. If not, it is
5914 an unary expression. Full detection of unknown typenames here
5915 would require a 3-token lookahead. */
5916 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5917 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5919 struct c_type_name
*type_name
;
5922 c_parser_consume_token (parser
);
5923 type_name
= c_parser_type_name (parser
);
5924 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5925 if (type_name
== NULL
)
5927 ret
.value
= error_mark_node
;
5928 ret
.original_code
= ERROR_MARK
;
5929 ret
.original_type
= NULL
;
5933 /* Save casted types in the function's used types hash table. */
5934 used_types_insert (type_name
->specs
->type
);
5936 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5937 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
5940 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
5941 expr
= c_parser_cast_expression (parser
, NULL
);
5942 expr
= default_function_array_read_conversion (expr_loc
, expr
);
5944 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
5945 ret
.original_code
= ERROR_MARK
;
5946 ret
.original_type
= NULL
;
5950 return c_parser_unary_expression (parser
);
5953 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
5959 unary-operator cast-expression
5960 sizeof unary-expression
5961 sizeof ( type-name )
5963 unary-operator: one of
5969 __alignof__ unary-expression
5970 __alignof__ ( type-name )
5973 (C11 permits _Alignof with type names only.)
5975 unary-operator: one of
5976 __extension__ __real__ __imag__
5978 Transactional Memory:
5981 transaction-expression
5983 In addition, the GNU syntax treats ++ and -- as unary operators, so
5984 they may be applied to cast expressions with errors for non-lvalues
5987 static struct c_expr
5988 c_parser_unary_expression (c_parser
*parser
)
5991 struct c_expr ret
, op
;
5992 location_t op_loc
= c_parser_peek_token (parser
)->location
;
5994 ret
.original_code
= ERROR_MARK
;
5995 ret
.original_type
= NULL
;
5996 switch (c_parser_peek_token (parser
)->type
)
5999 c_parser_consume_token (parser
);
6000 exp_loc
= c_parser_peek_token (parser
)->location
;
6001 op
= c_parser_cast_expression (parser
, NULL
);
6003 /* If there is array notations in op, we expand them. */
6004 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6005 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6008 op
= default_function_array_read_conversion (exp_loc
, op
);
6009 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6011 case CPP_MINUS_MINUS
:
6012 c_parser_consume_token (parser
);
6013 exp_loc
= c_parser_peek_token (parser
)->location
;
6014 op
= c_parser_cast_expression (parser
, NULL
);
6016 /* If there is array notations in op, we expand them. */
6017 if (flag_enable_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6018 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6021 op
= default_function_array_read_conversion (exp_loc
, op
);
6022 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6025 c_parser_consume_token (parser
);
6026 op
= c_parser_cast_expression (parser
, NULL
);
6027 mark_exp_read (op
.value
);
6028 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6030 c_parser_consume_token (parser
);
6031 exp_loc
= c_parser_peek_token (parser
)->location
;
6032 op
= c_parser_cast_expression (parser
, NULL
);
6033 op
= default_function_array_read_conversion (exp_loc
, op
);
6034 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6037 if (!c_dialect_objc () && !in_system_header
)
6040 "traditional C rejects the unary plus operator");
6041 c_parser_consume_token (parser
);
6042 exp_loc
= c_parser_peek_token (parser
)->location
;
6043 op
= c_parser_cast_expression (parser
, NULL
);
6044 op
= default_function_array_read_conversion (exp_loc
, op
);
6045 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6047 c_parser_consume_token (parser
);
6048 exp_loc
= c_parser_peek_token (parser
)->location
;
6049 op
= c_parser_cast_expression (parser
, NULL
);
6050 op
= default_function_array_read_conversion (exp_loc
, op
);
6051 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6053 c_parser_consume_token (parser
);
6054 exp_loc
= c_parser_peek_token (parser
)->location
;
6055 op
= c_parser_cast_expression (parser
, NULL
);
6056 op
= default_function_array_read_conversion (exp_loc
, op
);
6057 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6059 c_parser_consume_token (parser
);
6060 exp_loc
= c_parser_peek_token (parser
)->location
;
6061 op
= c_parser_cast_expression (parser
, NULL
);
6062 op
= default_function_array_read_conversion (exp_loc
, op
);
6063 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6065 /* Refer to the address of a label as a pointer. */
6066 c_parser_consume_token (parser
);
6067 if (c_parser_next_token_is (parser
, CPP_NAME
))
6069 ret
.value
= finish_label_address_expr
6070 (c_parser_peek_token (parser
)->value
, op_loc
);
6071 c_parser_consume_token (parser
);
6075 c_parser_error (parser
, "expected identifier");
6076 ret
.value
= error_mark_node
;
6080 switch (c_parser_peek_token (parser
)->keyword
)
6083 return c_parser_sizeof_expression (parser
);
6084 case RID_UPC_BLOCKSIZEOF
:
6085 case RID_UPC_ELEMSIZEOF
:
6086 case RID_UPC_LOCALSIZEOF
:
6087 gcc_assert (c_dialect_upc ());
6088 return c_parser_sizeof_expression (parser
);
6090 return c_parser_alignof_expression (parser
);
6092 c_parser_consume_token (parser
);
6093 ext
= disable_extension_diagnostics ();
6094 ret
= c_parser_cast_expression (parser
, NULL
);
6095 restore_extension_diagnostics (ext
);
6098 c_parser_consume_token (parser
);
6099 exp_loc
= c_parser_peek_token (parser
)->location
;
6100 op
= c_parser_cast_expression (parser
, NULL
);
6101 op
= default_function_array_conversion (exp_loc
, op
);
6102 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6104 c_parser_consume_token (parser
);
6105 exp_loc
= c_parser_peek_token (parser
)->location
;
6106 op
= c_parser_cast_expression (parser
, NULL
);
6107 op
= default_function_array_conversion (exp_loc
, op
);
6108 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6109 case RID_TRANSACTION_ATOMIC
:
6110 case RID_TRANSACTION_RELAXED
:
6111 return c_parser_transaction_expression (parser
,
6112 c_parser_peek_token (parser
)->keyword
);
6114 return c_parser_postfix_expression (parser
);
6117 return c_parser_postfix_expression (parser
);
6121 /* Return the result of upc_blocksizeof applied to EXPR. */
6125 upc_blocksizeof_expr (location_t loc
, struct c_expr expr
)
6128 ret
.original_code
= ERROR_MARK
;
6129 ret
.original_type
= NULL_TREE
;
6130 if (expr
.value
== error_mark_node
)
6132 ret
.value
= error_mark_node
;
6133 pop_maybe_used (false);
6137 ret
.value
= upc_blocksizeof (loc
, TREE_TYPE (expr
.value
));
6138 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6143 /* Return the result of upc_blocksizeof applied to T, a structure
6144 for the type name passed to sizeof (rather than the type itself). */
6148 upc_blocksizeof_type (location_t loc
, struct c_type_name
*t
)
6152 ret
.original_code
= ERROR_MARK
;
6153 ret
.original_type
= NULL_TREE
;
6154 type
= groktypename (t
, NULL
, NULL
);
6155 if (type
== error_mark_node
)
6157 ret
.value
= error_mark_node
;
6158 pop_maybe_used (false);
6162 ret
.value
= upc_blocksizeof (loc
, type
);
6163 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6168 /* Return the result of upc_elemsizeof applied to EXPR. */
6172 upc_elemsizeof_expr (location_t loc
, struct c_expr expr
)
6175 ret
.original_code
= ERROR_MARK
;
6176 ret
.original_type
= NULL_TREE
;
6177 if (expr
.value
== error_mark_node
)
6179 ret
.value
= error_mark_node
;
6180 pop_maybe_used (false);
6184 ret
.value
= upc_elemsizeof (loc
, TREE_TYPE (expr
.value
));
6185 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6190 /* Return the result of upc_elemsizeof applied to T, a structure
6191 for the type name passed to sizeof (rather than the type itself). */
6195 upc_elemsizeof_type (location_t loc
, struct c_type_name
*t
)
6199 ret
.original_code
= ERROR_MARK
;
6200 ret
.original_type
= NULL_TREE
;
6201 type
= groktypename (t
, NULL
, NULL
);
6202 if (type
== error_mark_node
)
6204 ret
.value
= error_mark_node
;
6205 pop_maybe_used (false);
6209 ret
.value
= upc_elemsizeof (loc
, type
);
6210 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6215 /* Return the result of upc_localsizeof applied to EXPR. */
6219 upc_localsizeof_expr (location_t loc
, struct c_expr expr
)
6222 ret
.original_code
= ERROR_MARK
;
6223 ret
.original_type
= NULL_TREE
;
6224 if (expr
.value
== error_mark_node
)
6226 ret
.value
= error_mark_node
;
6227 pop_maybe_used (false);
6231 ret
.value
= upc_localsizeof (loc
, TREE_TYPE (expr
.value
));
6232 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr
.value
)));
6237 /* Return the result of upc_localsizeof applied to T, a structure
6238 for the type name passed to sizeof (rather than the type itself). */
6242 upc_localsizeof_type (location_t loc
, struct c_type_name
*t
)
6246 ret
.original_code
= ERROR_MARK
;
6247 ret
.original_type
= NULL_TREE
;
6248 type
= groktypename (t
, NULL
, NULL
);
6249 if (type
== error_mark_node
)
6251 ret
.value
= error_mark_node
;
6252 pop_maybe_used (false);
6256 ret
.value
= upc_localsizeof (loc
, type
);
6257 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type
));
6262 /* Parse a sizeof expression. */
6264 static struct c_expr
6265 c_parser_sizeof_expression (c_parser
*parser
)
6268 location_t expr_loc
;
6269 enum rid keyword
= c_parser_peek_token (parser
)->keyword
;
6270 c_parser_consume_token (parser
);
6271 c_inhibit_evaluation_warnings
++;
6273 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6274 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6276 /* Either sizeof ( type-name ) or sizeof unary-expression
6277 starting with a compound literal. */
6278 struct c_type_name
*type_name
;
6279 c_parser_consume_token (parser
);
6280 expr_loc
= c_parser_peek_token (parser
)->location
;
6281 type_name
= c_parser_type_name (parser
);
6282 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6283 if (type_name
== NULL
)
6286 c_inhibit_evaluation_warnings
--;
6288 ret
.value
= error_mark_node
;
6289 ret
.original_code
= ERROR_MARK
;
6290 ret
.original_type
= NULL
;
6293 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6295 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6300 /* sizeof ( type-name ). */
6301 c_inhibit_evaluation_warnings
--;
6303 /* Handle upc_*_sizeof (type) operations. */
6306 case RID_UPC_BLOCKSIZEOF
:
6307 return upc_blocksizeof_type (expr_loc
, type_name
);
6308 case RID_UPC_ELEMSIZEOF
:
6309 return upc_elemsizeof_type (expr_loc
, type_name
);
6310 case RID_UPC_LOCALSIZEOF
:
6311 return upc_localsizeof_type (expr_loc
, type_name
);
6314 return c_expr_sizeof_type (expr_loc
, type_name
);
6318 expr_loc
= c_parser_peek_token (parser
)->location
;
6319 expr
= c_parser_unary_expression (parser
);
6321 c_inhibit_evaluation_warnings
--;
6323 mark_exp_read (expr
.value
);
6324 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6325 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6326 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6327 /* Handle upc_*_sizeof (expr) operations. */
6330 case RID_UPC_BLOCKSIZEOF
:
6331 return upc_blocksizeof_expr (expr_loc
, expr
);
6332 case RID_UPC_ELEMSIZEOF
:
6333 return upc_elemsizeof_expr (expr_loc
, expr
);
6334 case RID_UPC_LOCALSIZEOF
:
6335 return upc_localsizeof_expr (expr_loc
, expr
);
6337 return c_expr_sizeof_expr (expr_loc
, expr
);
6340 return c_expr_sizeof_expr (expr_loc
, expr
);
6344 /* Parse an alignof expression. */
6346 static struct c_expr
6347 c_parser_alignof_expression (c_parser
*parser
)
6350 location_t loc
= c_parser_peek_token (parser
)->location
;
6351 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6352 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6353 /* A diagnostic is not required for the use of this identifier in
6354 the implementation namespace; only diagnose it for the C11
6355 spelling because of existing code using the other spellings. */
6357 && strcmp (IDENTIFIER_POINTER (alignof_spelling
), "_Alignof") == 0)
6360 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6363 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6366 c_parser_consume_token (parser
);
6367 c_inhibit_evaluation_warnings
++;
6369 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6370 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6372 /* Either __alignof__ ( type-name ) or __alignof__
6373 unary-expression starting with a compound literal. */
6375 struct c_type_name
*type_name
;
6377 c_parser_consume_token (parser
);
6378 loc
= c_parser_peek_token (parser
)->location
;
6379 type_name
= c_parser_type_name (parser
);
6380 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6381 if (type_name
== NULL
)
6384 c_inhibit_evaluation_warnings
--;
6386 ret
.value
= error_mark_node
;
6387 ret
.original_code
= ERROR_MARK
;
6388 ret
.original_type
= NULL
;
6391 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6393 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6398 /* alignof ( type-name ). */
6399 c_inhibit_evaluation_warnings
--;
6401 ret
.value
= c_alignof (loc
, groktypename (type_name
, NULL
, NULL
));
6402 ret
.original_code
= ERROR_MARK
;
6403 ret
.original_type
= NULL
;
6409 expr
= c_parser_unary_expression (parser
);
6411 mark_exp_read (expr
.value
);
6412 c_inhibit_evaluation_warnings
--;
6414 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6416 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6417 ret
.original_code
= ERROR_MARK
;
6418 ret
.original_type
= NULL
;
6423 /* Helper function to read arguments of builtins which are interfaces
6424 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6425 others. The name of the builtin is passed using BNAME parameter.
6426 Function returns true if there were no errors while parsing and
6427 stores the arguments in CEXPR_LIST. */
6429 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6430 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6433 location_t loc
= c_parser_peek_token (parser
)->location
;
6434 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6436 bool saved_force_folding_builtin_constant_p
;
6438 *ret_cexpr_list
= NULL
;
6439 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6441 error_at (loc
, "cannot take address of %qs", bname
);
6445 c_parser_consume_token (parser
);
6447 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6449 c_parser_consume_token (parser
);
6453 saved_force_folding_builtin_constant_p
6454 = force_folding_builtin_constant_p
;
6455 force_folding_builtin_constant_p
|= choose_expr_p
;
6456 expr
= c_parser_expr_no_commas (parser
, NULL
);
6457 force_folding_builtin_constant_p
6458 = saved_force_folding_builtin_constant_p
;
6459 vec_alloc (cexpr_list
, 1);
6460 C_EXPR_APPEND (cexpr_list
, expr
);
6461 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6463 c_parser_consume_token (parser
);
6464 expr
= c_parser_expr_no_commas (parser
, NULL
);
6465 C_EXPR_APPEND (cexpr_list
, expr
);
6468 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6471 *ret_cexpr_list
= cexpr_list
;
6476 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6480 postfix-expression [ expression ]
6481 postfix-expression ( argument-expression-list[opt] )
6482 postfix-expression . identifier
6483 postfix-expression -> identifier
6484 postfix-expression ++
6485 postfix-expression --
6486 ( type-name ) { initializer-list }
6487 ( type-name ) { initializer-list , }
6489 argument-expression-list:
6491 argument-expression-list , argument-expression
6503 (treated as a keyword in GNU C)
6506 ( compound-statement )
6507 __builtin_va_arg ( assignment-expression , type-name )
6508 __builtin_offsetof ( type-name , offsetof-member-designator )
6509 __builtin_choose_expr ( assignment-expression ,
6510 assignment-expression ,
6511 assignment-expression )
6512 __builtin_types_compatible_p ( type-name , type-name )
6513 __builtin_complex ( assignment-expression , assignment-expression )
6514 __builtin_shuffle ( assignment-expression , assignment-expression )
6515 __builtin_shuffle ( assignment-expression ,
6516 assignment-expression ,
6517 assignment-expression, )
6519 offsetof-member-designator:
6521 offsetof-member-designator . identifier
6522 offsetof-member-designator [ expression ]
6527 [ objc-receiver objc-message-args ]
6528 @selector ( objc-selector-arg )
6529 @protocol ( identifier )
6530 @encode ( type-name )
6532 Classname . identifier
6535 static struct c_expr
6536 c_parser_postfix_expression (c_parser
*parser
)
6538 struct c_expr expr
, e1
;
6539 struct c_type_name
*t1
, *t2
;
6540 location_t loc
= c_parser_peek_token (parser
)->location
;;
6541 expr
.original_code
= ERROR_MARK
;
6542 expr
.original_type
= NULL
;
6543 switch (c_parser_peek_token (parser
)->type
)
6546 expr
.value
= c_parser_peek_token (parser
)->value
;
6547 loc
= c_parser_peek_token (parser
)->location
;
6548 c_parser_consume_token (parser
);
6549 if (TREE_CODE (expr
.value
) == FIXED_CST
6550 && !targetm
.fixed_point_supported_p ())
6552 error_at (loc
, "fixed-point types not supported for this target");
6553 expr
.value
= error_mark_node
;
6560 expr
.value
= c_parser_peek_token (parser
)->value
;
6561 c_parser_consume_token (parser
);
6567 case CPP_UTF8STRING
:
6568 expr
.value
= c_parser_peek_token (parser
)->value
;
6569 expr
.original_code
= STRING_CST
;
6570 c_parser_consume_token (parser
);
6572 case CPP_OBJC_STRING
:
6573 gcc_assert (c_dialect_objc ());
6575 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6576 c_parser_consume_token (parser
);
6579 switch (c_parser_peek_token (parser
)->id_kind
)
6583 tree id
= c_parser_peek_token (parser
)->value
;
6584 c_parser_consume_token (parser
);
6585 expr
.value
= build_external_ref (loc
, id
,
6586 (c_parser_peek_token (parser
)->type
6588 &expr
.original_type
);
6591 case C_ID_CLASSNAME
:
6593 /* Here we parse the Objective-C 2.0 Class.name dot
6595 tree class_name
= c_parser_peek_token (parser
)->value
;
6597 c_parser_consume_token (parser
);
6598 gcc_assert (c_dialect_objc ());
6599 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
6601 expr
.value
= error_mark_node
;
6604 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6606 c_parser_error (parser
, "expected identifier");
6607 expr
.value
= error_mark_node
;
6610 component
= c_parser_peek_token (parser
)->value
;
6611 c_parser_consume_token (parser
);
6612 expr
.value
= objc_build_class_component_ref (class_name
,
6617 c_parser_error (parser
, "expected expression");
6618 expr
.value
= error_mark_node
;
6622 case CPP_OPEN_PAREN
:
6623 /* A parenthesized expression, statement expression or compound
6625 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
6627 /* A statement expression. */
6629 location_t brace_loc
;
6630 c_parser_consume_token (parser
);
6631 brace_loc
= c_parser_peek_token (parser
)->location
;
6632 c_parser_consume_token (parser
);
6633 if (!building_stmt_list_p ())
6635 error_at (loc
, "braced-group within expression allowed "
6636 "only inside a function");
6637 parser
->error
= true;
6638 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
6639 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6640 expr
.value
= error_mark_node
;
6643 stmt
= c_begin_stmt_expr ();
6644 c_parser_compound_statement_nostart (parser
);
6645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6647 pedwarn (loc
, OPT_Wpedantic
,
6648 "ISO C forbids braced-groups within expressions");
6649 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
6650 mark_exp_read (expr
.value
);
6652 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6654 /* A compound literal. ??? Can we actually get here rather
6655 than going directly to
6656 c_parser_postfix_expression_after_paren_type from
6659 struct c_type_name
*type_name
;
6660 c_parser_consume_token (parser
);
6661 loc
= c_parser_peek_token (parser
)->location
;
6662 type_name
= c_parser_type_name (parser
);
6663 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6665 if (type_name
== NULL
)
6667 expr
.value
= error_mark_node
;
6670 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6676 /* A parenthesized expression. */
6677 c_parser_consume_token (parser
);
6678 expr
= c_parser_expression (parser
);
6679 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
6680 TREE_NO_WARNING (expr
.value
) = 1;
6681 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
6682 expr
.original_code
= ERROR_MARK
;
6683 /* Don't change EXPR.ORIGINAL_TYPE. */
6684 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6689 switch (c_parser_peek_token (parser
)->keyword
)
6691 case RID_FUNCTION_NAME
:
6692 case RID_PRETTY_FUNCTION_NAME
:
6693 case RID_C99_FUNCTION_NAME
:
6694 expr
.value
= fname_decl (loc
,
6695 c_parser_peek_token (parser
)->keyword
,
6696 c_parser_peek_token (parser
)->value
);
6697 c_parser_consume_token (parser
);
6700 c_parser_consume_token (parser
);
6701 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6703 expr
.value
= error_mark_node
;
6706 e1
= c_parser_expr_no_commas (parser
, NULL
);
6707 mark_exp_read (e1
.value
);
6708 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
6709 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6712 expr
.value
= error_mark_node
;
6715 loc
= c_parser_peek_token (parser
)->location
;
6716 t1
= c_parser_type_name (parser
);
6717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6721 expr
.value
= error_mark_node
;
6725 tree type_expr
= NULL_TREE
;
6726 expr
.value
= c_build_va_arg (loc
, e1
.value
,
6727 groktypename (t1
, &type_expr
, NULL
));
6730 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
6731 TREE_TYPE (expr
.value
), type_expr
,
6733 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
6738 c_parser_consume_token (parser
);
6739 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6741 expr
.value
= error_mark_node
;
6744 t1
= c_parser_type_name (parser
);
6746 parser
->error
= true;
6747 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6748 gcc_assert (parser
->error
);
6751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6752 expr
.value
= error_mark_node
;
6757 tree type
= groktypename (t1
, NULL
, NULL
);
6759 if (type
== error_mark_node
)
6760 offsetof_ref
= error_mark_node
;
6763 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
6764 SET_EXPR_LOCATION (offsetof_ref
, loc
);
6766 /* Parse the second argument to __builtin_offsetof. We
6767 must have one identifier, and beyond that we want to
6768 accept sub structure and sub array references. */
6769 if (c_parser_next_token_is (parser
, CPP_NAME
))
6771 offsetof_ref
= build_component_ref
6772 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
6773 c_parser_consume_token (parser
);
6774 while (c_parser_next_token_is (parser
, CPP_DOT
)
6775 || c_parser_next_token_is (parser
,
6777 || c_parser_next_token_is (parser
,
6780 if (c_parser_next_token_is (parser
, CPP_DEREF
))
6782 loc
= c_parser_peek_token (parser
)->location
;
6783 offsetof_ref
= build_array_ref (loc
,
6788 else if (c_parser_next_token_is (parser
, CPP_DOT
))
6791 c_parser_consume_token (parser
);
6792 if (c_parser_next_token_is_not (parser
,
6795 c_parser_error (parser
, "expected identifier");
6798 offsetof_ref
= build_component_ref
6800 c_parser_peek_token (parser
)->value
);
6801 c_parser_consume_token (parser
);
6806 loc
= c_parser_peek_token (parser
)->location
;
6807 c_parser_consume_token (parser
);
6808 idx
= c_parser_expression (parser
).value
;
6809 idx
= c_fully_fold (idx
, false, NULL
);
6810 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6812 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
6817 c_parser_error (parser
, "expected identifier");
6818 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6820 expr
.value
= fold_offsetof (offsetof_ref
);
6823 case RID_CHOOSE_EXPR
:
6825 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6826 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
6829 c_parser_consume_token (parser
);
6830 if (!c_parser_get_builtin_args (parser
,
6831 "__builtin_choose_expr",
6834 expr
.value
= error_mark_node
;
6838 if (vec_safe_length (cexpr_list
) != 3)
6840 error_at (loc
, "wrong number of arguments to "
6841 "%<__builtin_choose_expr%>");
6842 expr
.value
= error_mark_node
;
6846 e1_p
= &(*cexpr_list
)[0];
6847 e2_p
= &(*cexpr_list
)[1];
6848 e3_p
= &(*cexpr_list
)[2];
6851 mark_exp_read (e2_p
->value
);
6852 mark_exp_read (e3_p
->value
);
6853 if (TREE_CODE (c
) != INTEGER_CST
6854 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
6856 "first argument to %<__builtin_choose_expr%> not"
6858 constant_expression_warning (c
);
6859 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
6862 case RID_TYPES_COMPATIBLE_P
:
6863 c_parser_consume_token (parser
);
6864 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6866 expr
.value
= error_mark_node
;
6869 t1
= c_parser_type_name (parser
);
6872 expr
.value
= error_mark_node
;
6875 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6878 expr
.value
= error_mark_node
;
6881 t2
= c_parser_type_name (parser
);
6884 expr
.value
= error_mark_node
;
6887 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6891 e1
= groktypename (t1
, NULL
, NULL
);
6892 e2
= groktypename (t2
, NULL
, NULL
);
6893 if (e1
== error_mark_node
|| e2
== error_mark_node
)
6895 expr
.value
= error_mark_node
;
6899 e1
= TYPE_MAIN_VARIANT (e1
);
6900 e2
= TYPE_MAIN_VARIANT (e2
);
6903 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
6906 case RID_BUILTIN_COMPLEX
:
6908 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6909 c_expr_t
*e1_p
, *e2_p
;
6911 c_parser_consume_token (parser
);
6912 if (!c_parser_get_builtin_args (parser
,
6913 "__builtin_complex",
6914 &cexpr_list
, false))
6916 expr
.value
= error_mark_node
;
6920 if (vec_safe_length (cexpr_list
) != 2)
6922 error_at (loc
, "wrong number of arguments to "
6923 "%<__builtin_complex%>");
6924 expr
.value
= error_mark_node
;
6928 e1_p
= &(*cexpr_list
)[0];
6929 e2_p
= &(*cexpr_list
)[1];
6931 mark_exp_read (e1_p
->value
);
6932 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
6933 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
6934 TREE_OPERAND (e1_p
->value
, 0));
6935 mark_exp_read (e2_p
->value
);
6936 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
6937 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
6938 TREE_OPERAND (e2_p
->value
, 0));
6939 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6940 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
6941 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
6942 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
6944 error_at (loc
, "%<__builtin_complex%> operand "
6945 "not of real binary floating-point type");
6946 expr
.value
= error_mark_node
;
6949 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
6950 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
6953 "%<__builtin_complex%> operands of different types");
6954 expr
.value
= error_mark_node
;
6958 pedwarn (loc
, OPT_Wpedantic
,
6959 "ISO C90 does not support complex types");
6960 expr
.value
= build2 (COMPLEX_EXPR
,
6963 (TREE_TYPE (e1_p
->value
))),
6964 e1_p
->value
, e2_p
->value
);
6967 case RID_BUILTIN_SHUFFLE
:
6969 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6973 c_parser_consume_token (parser
);
6974 if (!c_parser_get_builtin_args (parser
,
6975 "__builtin_shuffle",
6976 &cexpr_list
, false))
6978 expr
.value
= error_mark_node
;
6982 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
6983 mark_exp_read (p
->value
);
6985 if (vec_safe_length (cexpr_list
) == 2)
6987 c_build_vec_perm_expr
6988 (loc
, (*cexpr_list
)[0].value
,
6989 NULL_TREE
, (*cexpr_list
)[1].value
);
6991 else if (vec_safe_length (cexpr_list
) == 3)
6993 c_build_vec_perm_expr
6994 (loc
, (*cexpr_list
)[0].value
,
6995 (*cexpr_list
)[1].value
,
6996 (*cexpr_list
)[2].value
);
6999 error_at (loc
, "wrong number of arguments to "
7000 "%<__builtin_shuffle%>");
7001 expr
.value
= error_mark_node
;
7005 case RID_AT_SELECTOR
:
7006 gcc_assert (c_dialect_objc ());
7007 c_parser_consume_token (parser
);
7008 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7010 expr
.value
= error_mark_node
;
7014 tree sel
= c_parser_objc_selector_arg (parser
);
7015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7017 expr
.value
= objc_build_selector_expr (loc
, sel
);
7020 case RID_AT_PROTOCOL
:
7021 gcc_assert (c_dialect_objc ());
7022 c_parser_consume_token (parser
);
7023 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7025 expr
.value
= error_mark_node
;
7028 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7030 c_parser_error (parser
, "expected identifier");
7031 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7032 expr
.value
= error_mark_node
;
7036 tree id
= c_parser_peek_token (parser
)->value
;
7037 c_parser_consume_token (parser
);
7038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7040 expr
.value
= objc_build_protocol_expr (id
);
7044 /* Extension to support C-structures in the archiver. */
7045 gcc_assert (c_dialect_objc ());
7046 c_parser_consume_token (parser
);
7047 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7049 expr
.value
= error_mark_node
;
7052 t1
= c_parser_type_name (parser
);
7055 expr
.value
= error_mark_node
;
7056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7062 tree type
= groktypename (t1
, NULL
, NULL
);
7063 expr
.value
= objc_build_encode_expr (type
);
7067 c_parser_error (parser
, "expected expression");
7068 expr
.value
= error_mark_node
;
7072 case CPP_OPEN_SQUARE
:
7073 if (c_dialect_objc ())
7075 tree receiver
, args
;
7076 c_parser_consume_token (parser
);
7077 receiver
= c_parser_objc_receiver (parser
);
7078 args
= c_parser_objc_message_args (parser
);
7079 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7081 expr
.value
= objc_build_message_expr (receiver
, args
);
7084 /* Else fall through to report error. */
7086 c_parser_error (parser
, "expected expression");
7087 expr
.value
= error_mark_node
;
7090 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7093 /* Parse a postfix expression after a parenthesized type name: the
7094 brace-enclosed initializer of a compound literal, possibly followed
7095 by some postfix operators. This is separate because it is not
7096 possible to tell until after the type name whether a cast
7097 expression has a cast or a compound literal, or whether the operand
7098 of sizeof is a parenthesized type name or starts with a compound
7099 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7100 location of the first token after the parentheses around the type
7103 static struct c_expr
7104 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7105 struct c_type_name
*type_name
,
7106 location_t type_loc
)
7112 location_t start_loc
;
7113 tree type_expr
= NULL_TREE
;
7114 bool type_expr_const
= true;
7115 check_compound_literal_type (type_loc
, type_name
);
7116 start_init (NULL_TREE
, NULL
, 0);
7117 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7118 start_loc
= c_parser_peek_token (parser
)->location
;
7119 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7121 error_at (type_loc
, "compound literal has variable size");
7122 type
= error_mark_node
;
7124 init
= c_parser_braced_init (parser
, type
, false);
7126 maybe_warn_string_init (type
, init
);
7128 if (type
!= error_mark_node
7129 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7130 && current_function_decl
)
7132 error ("compound literal qualified by address-space qualifier");
7133 type
= error_mark_node
;
7137 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7138 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7139 ? CONSTRUCTOR_NON_CONST (init
.value
)
7140 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7141 non_const
|= !type_expr_const
;
7142 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7143 expr
.original_code
= ERROR_MARK
;
7144 expr
.original_type
= NULL
;
7147 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7149 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7150 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7154 gcc_assert (!non_const
);
7155 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7156 type_expr
, expr
.value
);
7159 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7162 /* Callback function for sizeof_pointer_memaccess_warning to compare
7166 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7168 return comptypes (type1
, type2
) == 1;
7171 /* Parse a postfix expression after the initial primary or compound
7172 literal; that is, parse a series of postfix operators.
7174 EXPR_LOC is the location of the primary expression. */
7176 static struct c_expr
7177 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7178 location_t expr_loc
,
7181 struct c_expr orig_expr
;
7183 location_t sizeof_arg_loc
[3];
7186 vec
<tree
, va_gc
> *exprlist
;
7187 vec
<tree
, va_gc
> *origtypes
= NULL
;
7190 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7191 switch (c_parser_peek_token (parser
)->type
)
7193 case CPP_OPEN_SQUARE
:
7194 /* Array reference. */
7195 c_parser_consume_token (parser
);
7196 if (flag_enable_cilkplus
7197 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7198 /* If we are here, then we have something like this:
7201 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7205 idx
= c_parser_expression (parser
).value
;
7206 /* Here we have 3 options:
7207 1. Array [EXPR] -- Normal Array call.
7208 2. Array [EXPR : EXPR] -- Array notation without stride.
7209 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7211 For 1, we just handle it just like a normal array expression.
7212 For 2 and 3 we handle it like we handle array notations. The
7213 idx value we have above becomes the initial/start index.
7215 if (flag_enable_cilkplus
7216 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7217 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7221 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7223 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7226 expr
.original_code
= ERROR_MARK
;
7227 expr
.original_type
= NULL
;
7229 case CPP_OPEN_PAREN
:
7230 /* Function call. */
7231 c_parser_consume_token (parser
);
7232 for (i
= 0; i
< 3; i
++)
7234 sizeof_arg
[i
] = NULL_TREE
;
7235 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7237 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7240 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7241 sizeof_arg_loc
, sizeof_arg
);
7242 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7245 mark_exp_read (expr
.value
);
7246 if (warn_sizeof_pointer_memaccess
)
7247 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7248 expr
.value
, exprlist
,
7250 sizeof_ptr_memacc_comptypes
);
7251 /* FIXME diagnostics: Ideally we want the FUNCNAME, not the
7252 "(" after the FUNCNAME, which is what we have now. */
7253 expr
.value
= build_function_call_vec (op_loc
, expr
.value
, exprlist
,
7255 expr
.original_code
= ERROR_MARK
;
7256 if (TREE_CODE (expr
.value
) == INTEGER_CST
7257 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7258 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7259 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7260 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7261 expr
.original_type
= NULL
;
7264 release_tree_vector (exprlist
);
7265 release_tree_vector (origtypes
);
7269 /* Structure element reference. */
7270 c_parser_consume_token (parser
);
7271 expr
= default_function_array_conversion (expr_loc
, expr
);
7272 if (c_parser_next_token_is (parser
, CPP_NAME
))
7273 ident
= c_parser_peek_token (parser
)->value
;
7276 c_parser_error (parser
, "expected identifier");
7277 expr
.value
= error_mark_node
;
7278 expr
.original_code
= ERROR_MARK
;
7279 expr
.original_type
= NULL
;
7282 c_parser_consume_token (parser
);
7283 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7284 expr
.original_code
= ERROR_MARK
;
7285 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7286 expr
.original_type
= NULL
;
7289 /* Remember the original type of a bitfield. */
7290 tree field
= TREE_OPERAND (expr
.value
, 1);
7291 if (TREE_CODE (field
) != FIELD_DECL
)
7292 expr
.original_type
= NULL
;
7294 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7298 /* Structure element reference. */
7299 c_parser_consume_token (parser
);
7300 expr
= default_function_array_conversion (expr_loc
, expr
);
7301 if (c_parser_next_token_is (parser
, CPP_NAME
))
7302 ident
= c_parser_peek_token (parser
)->value
;
7305 c_parser_error (parser
, "expected identifier");
7306 expr
.value
= error_mark_node
;
7307 expr
.original_code
= ERROR_MARK
;
7308 expr
.original_type
= NULL
;
7311 c_parser_consume_token (parser
);
7312 expr
.value
= build_component_ref (op_loc
,
7313 build_indirect_ref (op_loc
,
7317 expr
.original_code
= ERROR_MARK
;
7318 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7319 expr
.original_type
= NULL
;
7322 /* Remember the original type of a bitfield. */
7323 tree field
= TREE_OPERAND (expr
.value
, 1);
7324 if (TREE_CODE (field
) != FIELD_DECL
)
7325 expr
.original_type
= NULL
;
7327 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7331 /* Postincrement. */
7332 c_parser_consume_token (parser
);
7333 /* If the expressions have array notations, we expand them. */
7334 if (flag_enable_cilkplus
7335 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7336 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7339 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7340 expr
.value
= build_unary_op (op_loc
,
7341 POSTINCREMENT_EXPR
, expr
.value
, 0);
7343 expr
.original_code
= ERROR_MARK
;
7344 expr
.original_type
= NULL
;
7346 case CPP_MINUS_MINUS
:
7347 /* Postdecrement. */
7348 c_parser_consume_token (parser
);
7349 /* If the expressions have array notations, we expand them. */
7350 if (flag_enable_cilkplus
7351 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7352 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7355 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7356 expr
.value
= build_unary_op (op_loc
,
7357 POSTDECREMENT_EXPR
, expr
.value
, 0);
7359 expr
.original_code
= ERROR_MARK
;
7360 expr
.original_type
= NULL
;
7368 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7371 assignment-expression
7372 expression , assignment-expression
7375 static struct c_expr
7376 c_parser_expression (c_parser
*parser
)
7379 expr
= c_parser_expr_no_commas (parser
, NULL
);
7380 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7384 location_t loc
= c_parser_peek_token (parser
)->location
;
7385 location_t expr_loc
;
7386 c_parser_consume_token (parser
);
7387 expr_loc
= c_parser_peek_token (parser
)->location
;
7388 lhsval
= expr
.value
;
7389 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7390 lhsval
= TREE_OPERAND (lhsval
, 1);
7391 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7392 mark_exp_read (lhsval
);
7393 next
= c_parser_expr_no_commas (parser
, NULL
);
7394 next
= default_function_array_conversion (expr_loc
, next
);
7395 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7396 expr
.original_code
= COMPOUND_EXPR
;
7397 expr
.original_type
= next
.original_type
;
7402 /* Parse an expression and convert functions or arrays to
7405 static struct c_expr
7406 c_parser_expression_conv (c_parser
*parser
)
7409 location_t loc
= c_parser_peek_token (parser
)->location
;
7410 expr
= c_parser_expression (parser
);
7411 expr
= default_function_array_conversion (loc
, expr
);
7415 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7416 functions and arrays to pointers. If FOLD_P, fold the expressions.
7419 assignment-expression
7420 nonempty-expr-list , assignment-expression
7423 static vec
<tree
, va_gc
> *
7424 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7425 vec
<tree
, va_gc
> **p_orig_types
,
7426 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
)
7428 vec
<tree
, va_gc
> *ret
;
7429 vec
<tree
, va_gc
> *orig_types
;
7431 location_t loc
= c_parser_peek_token (parser
)->location
;
7432 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7433 unsigned int idx
= 0;
7435 ret
= make_tree_vector ();
7436 if (p_orig_types
== NULL
)
7439 orig_types
= make_tree_vector ();
7441 if (sizeof_arg
!= NULL
7442 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7443 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7444 expr
= c_parser_expr_no_commas (parser
, NULL
);
7446 expr
= default_function_array_read_conversion (loc
, expr
);
7448 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7449 ret
->quick_push (expr
.value
);
7451 orig_types
->quick_push (expr
.original_type
);
7452 if (sizeof_arg
!= NULL
7453 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7454 && expr
.original_code
== SIZEOF_EXPR
)
7456 sizeof_arg
[0] = c_last_sizeof_arg
;
7457 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7459 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7461 c_parser_consume_token (parser
);
7462 loc
= c_parser_peek_token (parser
)->location
;
7463 if (sizeof_arg
!= NULL
7464 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7465 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7467 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7468 expr
= c_parser_expr_no_commas (parser
, NULL
);
7470 expr
= default_function_array_read_conversion (loc
, expr
);
7472 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7473 vec_safe_push (ret
, expr
.value
);
7475 vec_safe_push (orig_types
, expr
.original_type
);
7477 && sizeof_arg
!= NULL
7478 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7479 && expr
.original_code
== SIZEOF_EXPR
)
7481 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7482 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7486 *p_orig_types
= orig_types
;
7490 /* Parse Objective-C-specific constructs. */
7492 /* Parse an objc-class-definition.
7494 objc-class-definition:
7495 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7496 objc-class-instance-variables[opt] objc-methodprotolist @end
7497 @implementation identifier objc-superclass[opt]
7498 objc-class-instance-variables[opt]
7499 @interface identifier ( identifier ) objc-protocol-refs[opt]
7500 objc-methodprotolist @end
7501 @interface identifier ( ) objc-protocol-refs[opt]
7502 objc-methodprotolist @end
7503 @implementation identifier ( identifier )
7508 "@interface identifier (" must start "@interface identifier (
7509 identifier ) ...": objc-methodprotolist in the first production may
7510 not start with a parenthesized identifier as a declarator of a data
7511 definition with no declaration specifiers if the objc-superclass,
7512 objc-protocol-refs and objc-class-instance-variables are omitted. */
7515 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7520 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7522 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7527 c_parser_consume_token (parser
);
7528 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7530 c_parser_error (parser
, "expected identifier");
7533 id1
= c_parser_peek_token (parser
)->value
;
7534 c_parser_consume_token (parser
);
7535 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7537 /* We have a category or class extension. */
7539 tree proto
= NULL_TREE
;
7540 c_parser_consume_token (parser
);
7541 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7543 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7545 /* We have a class extension. */
7550 c_parser_error (parser
, "expected identifier or %<)%>");
7551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7557 id2
= c_parser_peek_token (parser
)->value
;
7558 c_parser_consume_token (parser
);
7560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7563 objc_start_category_implementation (id1
, id2
);
7566 if (c_parser_next_token_is (parser
, CPP_LESS
))
7567 proto
= c_parser_objc_protocol_refs (parser
);
7568 objc_start_category_interface (id1
, id2
, proto
, attributes
);
7569 c_parser_objc_methodprotolist (parser
);
7570 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7571 objc_finish_interface ();
7574 if (c_parser_next_token_is (parser
, CPP_COLON
))
7576 c_parser_consume_token (parser
);
7577 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7579 c_parser_error (parser
, "expected identifier");
7582 superclass
= c_parser_peek_token (parser
)->value
;
7583 c_parser_consume_token (parser
);
7586 superclass
= NULL_TREE
;
7589 tree proto
= NULL_TREE
;
7590 if (c_parser_next_token_is (parser
, CPP_LESS
))
7591 proto
= c_parser_objc_protocol_refs (parser
);
7592 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
7595 objc_start_class_implementation (id1
, superclass
);
7596 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7597 c_parser_objc_class_instance_variables (parser
);
7600 objc_continue_interface ();
7601 c_parser_objc_methodprotolist (parser
);
7602 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7603 objc_finish_interface ();
7607 objc_continue_implementation ();
7612 /* Parse objc-class-instance-variables.
7614 objc-class-instance-variables:
7615 { objc-instance-variable-decl-list[opt] }
7617 objc-instance-variable-decl-list:
7618 objc-visibility-spec
7619 objc-instance-variable-decl ;
7621 objc-instance-variable-decl-list objc-visibility-spec
7622 objc-instance-variable-decl-list objc-instance-variable-decl ;
7623 objc-instance-variable-decl-list ;
7625 objc-visibility-spec:
7630 objc-instance-variable-decl:
7635 c_parser_objc_class_instance_variables (c_parser
*parser
)
7637 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
7638 c_parser_consume_token (parser
);
7639 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
7642 /* Parse any stray semicolon. */
7643 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7645 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7647 c_parser_consume_token (parser
);
7650 /* Stop if at the end of the instance variables. */
7651 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7653 c_parser_consume_token (parser
);
7656 /* Parse any objc-visibility-spec. */
7657 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
7659 c_parser_consume_token (parser
);
7660 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
7663 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
7665 c_parser_consume_token (parser
);
7666 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
7669 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
7671 c_parser_consume_token (parser
);
7672 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
7675 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
7677 c_parser_consume_token (parser
);
7678 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
7681 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
7683 c_parser_pragma (parser
, pragma_external
);
7687 /* Parse some comma-separated declarations. */
7688 decls
= c_parser_struct_declaration (parser
);
7691 /* There is a syntax error. We want to skip the offending
7692 tokens up to the next ';' (included) or '}'
7695 /* First, skip manually a ')' or ']'. This is because they
7696 reduce the nesting level, so c_parser_skip_until_found()
7697 wouldn't be able to skip past them. */
7698 c_token
*token
= c_parser_peek_token (parser
);
7699 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
7700 c_parser_consume_token (parser
);
7702 /* Then, do the standard skipping. */
7703 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7705 /* We hopefully recovered. Start normal parsing again. */
7706 parser
->error
= false;
7711 /* Comma-separated instance variables are chained together
7712 in reverse order; add them one by one. */
7713 tree ivar
= nreverse (decls
);
7714 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
7715 objc_add_instance_variable (copy_node (ivar
));
7717 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7721 /* Parse an objc-class-declaration.
7723 objc-class-declaration:
7724 @class identifier-list ;
7728 c_parser_objc_class_declaration (c_parser
*parser
)
7730 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
7731 c_parser_consume_token (parser
);
7732 /* Any identifiers, including those declared as type names, are OK
7737 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7739 c_parser_error (parser
, "expected identifier");
7740 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7741 parser
->error
= false;
7744 id
= c_parser_peek_token (parser
)->value
;
7745 objc_declare_class (id
);
7746 c_parser_consume_token (parser
);
7747 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7748 c_parser_consume_token (parser
);
7752 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7755 /* Parse an objc-alias-declaration.
7757 objc-alias-declaration:
7758 @compatibility_alias identifier identifier ;
7762 c_parser_objc_alias_declaration (c_parser
*parser
)
7765 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
7766 c_parser_consume_token (parser
);
7767 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7769 c_parser_error (parser
, "expected identifier");
7770 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7773 id1
= c_parser_peek_token (parser
)->value
;
7774 c_parser_consume_token (parser
);
7775 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7777 c_parser_error (parser
, "expected identifier");
7778 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
7781 id2
= c_parser_peek_token (parser
)->value
;
7782 c_parser_consume_token (parser
);
7783 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7784 objc_declare_alias (id1
, id2
);
7787 /* Parse an objc-protocol-definition.
7789 objc-protocol-definition:
7790 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
7791 @protocol identifier-list ;
7793 "@protocol identifier ;" should be resolved as "@protocol
7794 identifier-list ;": objc-methodprotolist may not start with a
7795 semicolon in the first alternative if objc-protocol-refs are
7799 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
7801 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
7803 c_parser_consume_token (parser
);
7804 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7806 c_parser_error (parser
, "expected identifier");
7809 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
7810 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
7812 /* Any identifiers, including those declared as type names, are
7817 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7819 c_parser_error (parser
, "expected identifier");
7822 id
= c_parser_peek_token (parser
)->value
;
7823 objc_declare_protocol (id
, attributes
);
7824 c_parser_consume_token (parser
);
7825 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7826 c_parser_consume_token (parser
);
7830 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7834 tree id
= c_parser_peek_token (parser
)->value
;
7835 tree proto
= NULL_TREE
;
7836 c_parser_consume_token (parser
);
7837 if (c_parser_next_token_is (parser
, CPP_LESS
))
7838 proto
= c_parser_objc_protocol_refs (parser
);
7839 parser
->objc_pq_context
= true;
7840 objc_start_protocol (id
, proto
, attributes
);
7841 c_parser_objc_methodprotolist (parser
);
7842 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
7843 parser
->objc_pq_context
= false;
7844 objc_finish_interface ();
7848 /* Parse an objc-method-type.
7854 Return true if it is a class method (+) and false if it is
7855 an instance method (-).
7858 c_parser_objc_method_type (c_parser
*parser
)
7860 switch (c_parser_peek_token (parser
)->type
)
7863 c_parser_consume_token (parser
);
7866 c_parser_consume_token (parser
);
7873 /* Parse an objc-method-definition.
7875 objc-method-definition:
7876 objc-method-type objc-method-decl ;[opt] compound-statement
7880 c_parser_objc_method_definition (c_parser
*parser
)
7882 bool is_class_method
= c_parser_objc_method_type (parser
);
7883 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
7884 parser
->objc_pq_context
= true;
7885 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7887 if (decl
== error_mark_node
)
7888 return; /* Bail here. */
7890 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
7892 c_parser_consume_token (parser
);
7893 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7894 "extra semicolon in method definition specified");
7897 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7899 c_parser_error (parser
, "expected %<{%>");
7903 parser
->objc_pq_context
= false;
7904 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
7906 add_stmt (c_parser_compound_statement (parser
));
7907 objc_finish_method_definition (current_function_decl
);
7911 /* This code is executed when we find a method definition
7912 outside of an @implementation context (or invalid for other
7913 reasons). Parse the method (to keep going) but do not emit
7916 c_parser_compound_statement (parser
);
7920 /* Parse an objc-methodprotolist.
7922 objc-methodprotolist:
7924 objc-methodprotolist objc-methodproto
7925 objc-methodprotolist declaration
7926 objc-methodprotolist ;
7930 The declaration is a data definition, which may be missing
7931 declaration specifiers under the same rules and diagnostics as
7932 other data definitions outside functions, and the stray semicolon
7933 is diagnosed the same way as a stray semicolon outside a
7937 c_parser_objc_methodprotolist (c_parser
*parser
)
7941 /* The list is terminated by @end. */
7942 switch (c_parser_peek_token (parser
)->type
)
7945 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
7946 "ISO C does not allow extra %<;%> outside of a function");
7947 c_parser_consume_token (parser
);
7951 c_parser_objc_methodproto (parser
);
7954 c_parser_pragma (parser
, pragma_external
);
7959 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
7961 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
7962 c_parser_objc_at_property_declaration (parser
);
7963 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
7965 objc_set_method_opt (true);
7966 c_parser_consume_token (parser
);
7968 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
7970 objc_set_method_opt (false);
7971 c_parser_consume_token (parser
);
7974 c_parser_declaration_or_fndef (parser
, false, false, true,
7981 /* Parse an objc-methodproto.
7984 objc-method-type objc-method-decl ;
7988 c_parser_objc_methodproto (c_parser
*parser
)
7990 bool is_class_method
= c_parser_objc_method_type (parser
);
7991 tree decl
, attributes
= NULL_TREE
;
7993 /* Remember protocol qualifiers in prototypes. */
7994 parser
->objc_pq_context
= true;
7995 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
7997 /* Forget protocol qualifiers now. */
7998 parser
->objc_pq_context
= false;
8000 /* Do not allow the presence of attributes to hide an erroneous
8001 method implementation in the interface section. */
8002 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8004 c_parser_error (parser
, "expected %<;%>");
8008 if (decl
!= error_mark_node
)
8009 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8014 /* If we are at a position that method attributes may be present, check that
8015 there are not any parsed already (a syntax error) and then collect any
8016 specified at the current location. Finally, if new attributes were present,
8017 check that the next token is legal ( ';' for decls and '{' for defs). */
8020 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8025 c_parser_error (parser
,
8026 "method attributes must be specified at the end only");
8027 *attributes
= NULL_TREE
;
8031 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8032 *attributes
= c_parser_attributes (parser
);
8034 /* If there were no attributes here, just report any earlier error. */
8035 if (*attributes
== NULL_TREE
|| bad
)
8038 /* If the attributes are followed by a ; or {, then just report any earlier
8040 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8041 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8044 /* We've got attributes, but not at the end. */
8045 c_parser_error (parser
,
8046 "expected %<;%> or %<{%> after method attribute definition");
8050 /* Parse an objc-method-decl.
8053 ( objc-type-name ) objc-selector
8055 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8056 objc-keyword-selector objc-optparmlist
8059 objc-keyword-selector:
8061 objc-keyword-selector objc-keyword-decl
8064 objc-selector : ( objc-type-name ) identifier
8065 objc-selector : identifier
8066 : ( objc-type-name ) identifier
8070 objc-optparms objc-optellipsis
8074 objc-opt-parms , parameter-declaration
8082 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8083 tree
*attributes
, tree
*expr
)
8085 tree type
= NULL_TREE
;
8087 tree parms
= NULL_TREE
;
8088 bool ellipsis
= false;
8089 bool attr_err
= false;
8091 *attributes
= NULL_TREE
;
8092 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8094 c_parser_consume_token (parser
);
8095 type
= c_parser_objc_type_name (parser
);
8096 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8098 sel
= c_parser_objc_selector (parser
);
8099 /* If there is no selector, or a colon follows, we have an
8100 objc-keyword-selector. If there is a selector, and a colon does
8101 not follow, that selector ends the objc-method-decl. */
8102 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8105 tree list
= NULL_TREE
;
8108 tree atype
= NULL_TREE
, id
, keyworddecl
;
8109 tree param_attr
= NULL_TREE
;
8110 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8112 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8114 c_parser_consume_token (parser
);
8115 atype
= c_parser_objc_type_name (parser
);
8116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8119 /* New ObjC allows attributes on method parameters. */
8120 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8121 param_attr
= c_parser_attributes (parser
);
8122 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8124 c_parser_error (parser
, "expected identifier");
8125 return error_mark_node
;
8127 id
= c_parser_peek_token (parser
)->value
;
8128 c_parser_consume_token (parser
);
8129 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8130 list
= chainon (list
, keyworddecl
);
8131 tsel
= c_parser_objc_selector (parser
);
8132 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8136 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8138 /* Parse the optional parameter list. Optional Objective-C
8139 method parameters follow the C syntax, and may include '...'
8140 to denote a variable number of arguments. */
8141 parms
= make_node (TREE_LIST
);
8142 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8144 struct c_parm
*parm
;
8145 c_parser_consume_token (parser
);
8146 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8149 c_parser_consume_token (parser
);
8150 attr_err
|= c_parser_objc_maybe_method_attributes
8151 (parser
, attributes
) ;
8154 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8157 parms
= chainon (parms
,
8158 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8163 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8167 c_parser_error (parser
, "objective-c method declaration is expected");
8168 return error_mark_node
;
8172 return error_mark_node
;
8174 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8177 /* Parse an objc-type-name.
8180 objc-type-qualifiers[opt] type-name
8181 objc-type-qualifiers[opt]
8183 objc-type-qualifiers:
8185 objc-type-qualifiers objc-type-qualifier
8187 objc-type-qualifier: one of
8188 in out inout bycopy byref oneway
8192 c_parser_objc_type_name (c_parser
*parser
)
8194 tree quals
= NULL_TREE
;
8195 struct c_type_name
*type_name
= NULL
;
8196 tree type
= NULL_TREE
;
8199 c_token
*token
= c_parser_peek_token (parser
);
8200 if (token
->type
== CPP_KEYWORD
8201 && (token
->keyword
== RID_IN
8202 || token
->keyword
== RID_OUT
8203 || token
->keyword
== RID_INOUT
8204 || token
->keyword
== RID_BYCOPY
8205 || token
->keyword
== RID_BYREF
8206 || token
->keyword
== RID_ONEWAY
))
8208 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8209 c_parser_consume_token (parser
);
8214 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8215 type_name
= c_parser_type_name (parser
);
8217 type
= groktypename (type_name
, NULL
, NULL
);
8219 /* If the type is unknown, and error has already been produced and
8220 we need to recover from the error. In that case, use NULL_TREE
8221 for the type, as if no type had been specified; this will use the
8222 default type ('id') which is good for error recovery. */
8223 if (type
== error_mark_node
)
8226 return build_tree_list (quals
, type
);
8229 /* Parse objc-protocol-refs.
8236 c_parser_objc_protocol_refs (c_parser
*parser
)
8238 tree list
= NULL_TREE
;
8239 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8240 c_parser_consume_token (parser
);
8241 /* Any identifiers, including those declared as type names, are OK
8246 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8248 c_parser_error (parser
, "expected identifier");
8251 id
= c_parser_peek_token (parser
)->value
;
8252 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8253 c_parser_consume_token (parser
);
8254 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8255 c_parser_consume_token (parser
);
8259 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8263 /* Parse an objc-try-catch-finally-statement.
8265 objc-try-catch-finally-statement:
8266 @try compound-statement objc-catch-list[opt]
8267 @try compound-statement objc-catch-list[opt] @finally compound-statement
8270 @catch ( objc-catch-parameter-declaration ) compound-statement
8271 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8273 objc-catch-parameter-declaration:
8274 parameter-declaration
8277 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8279 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8280 for C++. Keep them in sync. */
8283 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8285 location_t location
;
8288 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8289 c_parser_consume_token (parser
);
8290 location
= c_parser_peek_token (parser
)->location
;
8291 objc_maybe_warn_exceptions (location
);
8292 stmt
= c_parser_compound_statement (parser
);
8293 objc_begin_try_stmt (location
, stmt
);
8295 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8297 struct c_parm
*parm
;
8298 tree parameter_declaration
= error_mark_node
;
8299 bool seen_open_paren
= false;
8301 c_parser_consume_token (parser
);
8302 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8303 seen_open_paren
= true;
8304 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8306 /* We have "@catch (...)" (where the '...' are literally
8307 what is in the code). Skip the '...'.
8308 parameter_declaration is set to NULL_TREE, and
8309 objc_being_catch_clauses() knows that that means
8311 c_parser_consume_token (parser
);
8312 parameter_declaration
= NULL_TREE
;
8316 /* We have "@catch (NSException *exception)" or something
8317 like that. Parse the parameter declaration. */
8318 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8320 parameter_declaration
= error_mark_node
;
8322 parameter_declaration
= grokparm (parm
, NULL
);
8324 if (seen_open_paren
)
8325 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8328 /* If there was no open parenthesis, we are recovering from
8329 an error, and we are trying to figure out what mistake
8330 the user has made. */
8332 /* If there is an immediate closing parenthesis, the user
8333 probably forgot the opening one (ie, they typed "@catch
8334 NSException *e)". Parse the closing parenthesis and keep
8336 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8337 c_parser_consume_token (parser
);
8339 /* If these is no immediate closing parenthesis, the user
8340 probably doesn't know that parenthesis are required at
8341 all (ie, they typed "@catch NSException *e"). So, just
8342 forget about the closing parenthesis and keep going. */
8344 objc_begin_catch_clause (parameter_declaration
);
8345 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8346 c_parser_compound_statement_nostart (parser
);
8347 objc_finish_catch_clause ();
8349 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8351 c_parser_consume_token (parser
);
8352 location
= c_parser_peek_token (parser
)->location
;
8353 stmt
= c_parser_compound_statement (parser
);
8354 objc_build_finally_clause (location
, stmt
);
8356 objc_finish_try_stmt ();
8359 /* Parse an objc-synchronized-statement.
8361 objc-synchronized-statement:
8362 @synchronized ( expression ) compound-statement
8366 c_parser_objc_synchronized_statement (c_parser
*parser
)
8370 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8371 c_parser_consume_token (parser
);
8372 loc
= c_parser_peek_token (parser
)->location
;
8373 objc_maybe_warn_exceptions (loc
);
8374 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8376 expr
= c_parser_expression (parser
).value
;
8377 expr
= c_fully_fold (expr
, false, NULL
);
8378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8381 expr
= error_mark_node
;
8382 stmt
= c_parser_compound_statement (parser
);
8383 objc_build_synchronized (loc
, expr
, stmt
);
8386 /* Parse an objc-selector; return NULL_TREE without an error if the
8387 next token is not an objc-selector.
8392 enum struct union if else while do for switch case default
8393 break continue return goto asm sizeof typeof __alignof
8394 unsigned long const short volatile signed restrict _Complex
8395 in out inout bycopy byref oneway int char float double void _Bool
8397 ??? Why this selection of keywords but not, for example, storage
8398 class specifiers? */
8401 c_parser_objc_selector (c_parser
*parser
)
8403 c_token
*token
= c_parser_peek_token (parser
);
8404 tree value
= token
->value
;
8405 if (token
->type
== CPP_NAME
)
8407 c_parser_consume_token (parser
);
8410 if (token
->type
!= CPP_KEYWORD
)
8412 switch (token
->keyword
)
8454 c_parser_consume_token (parser
);
8461 /* Parse an objc-selector-arg.
8465 objc-keywordname-list
8467 objc-keywordname-list:
8469 objc-keywordname-list objc-keywordname
8477 c_parser_objc_selector_arg (c_parser
*parser
)
8479 tree sel
= c_parser_objc_selector (parser
);
8480 tree list
= NULL_TREE
;
8481 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8485 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8487 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8488 sel
= c_parser_objc_selector (parser
);
8489 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8495 /* Parse an objc-receiver.
8504 c_parser_objc_receiver (c_parser
*parser
)
8506 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8507 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8508 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8510 tree id
= c_parser_peek_token (parser
)->value
;
8511 c_parser_consume_token (parser
);
8512 return objc_get_class_reference (id
);
8514 return c_fully_fold (c_parser_expression (parser
).value
, false, NULL
);
8517 /* Parse objc-message-args.
8521 objc-keywordarg-list
8523 objc-keywordarg-list:
8525 objc-keywordarg-list objc-keywordarg
8528 objc-selector : objc-keywordexpr
8533 c_parser_objc_message_args (c_parser
*parser
)
8535 tree sel
= c_parser_objc_selector (parser
);
8536 tree list
= NULL_TREE
;
8537 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8542 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8543 return error_mark_node
;
8544 keywordexpr
= c_parser_objc_keywordexpr (parser
);
8545 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
8546 sel
= c_parser_objc_selector (parser
);
8547 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8553 /* Parse an objc-keywordexpr.
8560 c_parser_objc_keywordexpr (c_parser
*parser
)
8563 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
8565 if (vec_safe_length (expr_list
) == 1)
8567 /* Just return the expression, remove a level of
8569 ret
= (*expr_list
)[0];
8573 /* We have a comma expression, we will collapse later. */
8574 ret
= build_tree_list_vec (expr_list
);
8576 release_tree_vector (expr_list
);
8580 /* A check, needed in several places, that ObjC interface, implementation or
8581 method definitions are not prefixed by incorrect items. */
8583 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
8584 struct c_declspecs
*specs
)
8586 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
8587 || specs
->typespec_kind
!= ctsk_none
)
8589 c_parser_error (parser
,
8590 "no type or storage class may be specified here,");
8591 c_parser_skip_to_end_of_block_or_statement (parser
);
8597 /* Parse an Objective-C @property declaration. The syntax is:
8599 objc-property-declaration:
8600 '@property' objc-property-attributes[opt] struct-declaration ;
8602 objc-property-attributes:
8603 '(' objc-property-attribute-list ')'
8605 objc-property-attribute-list:
8606 objc-property-attribute
8607 objc-property-attribute-list, objc-property-attribute
8609 objc-property-attribute
8610 'getter' = identifier
8611 'setter' = identifier
8620 @property NSString *name;
8621 @property (readonly) id object;
8622 @property (retain, nonatomic, getter=getTheName) id name;
8623 @property int a, b, c;
8625 PS: This function is identical to cp_parser_objc_at_propery_declaration
8626 for C++. Keep them in sync. */
8628 c_parser_objc_at_property_declaration (c_parser
*parser
)
8630 /* The following variables hold the attributes of the properties as
8631 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
8632 seen. When we see an attribute, we set them to 'true' (if they
8633 are boolean properties) or to the identifier (if they have an
8634 argument, ie, for getter and setter). Note that here we only
8635 parse the list of attributes, check the syntax and accumulate the
8636 attributes that we find. objc_add_property_declaration() will
8637 then process the information. */
8638 bool property_assign
= false;
8639 bool property_copy
= false;
8640 tree property_getter_ident
= NULL_TREE
;
8641 bool property_nonatomic
= false;
8642 bool property_readonly
= false;
8643 bool property_readwrite
= false;
8644 bool property_retain
= false;
8645 tree property_setter_ident
= NULL_TREE
;
8647 /* 'properties' is the list of properties that we read. Usually a
8648 single one, but maybe more (eg, in "@property int a, b, c;" there
8653 loc
= c_parser_peek_token (parser
)->location
;
8654 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
8656 c_parser_consume_token (parser
); /* Eat '@property'. */
8658 /* Parse the optional attribute list... */
8659 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8662 c_parser_consume_token (parser
);
8664 /* Property attribute keywords are valid now. */
8665 parser
->objc_property_attr_context
= true;
8669 bool syntax_error
= false;
8670 c_token
*token
= c_parser_peek_token (parser
);
8673 if (token
->type
!= CPP_KEYWORD
)
8675 if (token
->type
== CPP_CLOSE_PAREN
)
8676 c_parser_error (parser
, "expected identifier");
8679 c_parser_consume_token (parser
);
8680 c_parser_error (parser
, "unknown property attribute");
8684 keyword
= token
->keyword
;
8685 c_parser_consume_token (parser
);
8688 case RID_ASSIGN
: property_assign
= true; break;
8689 case RID_COPY
: property_copy
= true; break;
8690 case RID_NONATOMIC
: property_nonatomic
= true; break;
8691 case RID_READONLY
: property_readonly
= true; break;
8692 case RID_READWRITE
: property_readwrite
= true; break;
8693 case RID_RETAIN
: property_retain
= true; break;
8697 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
8699 if (keyword
== RID_GETTER
)
8700 c_parser_error (parser
,
8701 "missing %<=%> (after %<getter%> attribute)");
8703 c_parser_error (parser
,
8704 "missing %<=%> (after %<setter%> attribute)");
8705 syntax_error
= true;
8708 c_parser_consume_token (parser
); /* eat the = */
8709 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8711 c_parser_error (parser
, "expected identifier");
8712 syntax_error
= true;
8715 if (keyword
== RID_SETTER
)
8717 if (property_setter_ident
!= NULL_TREE
)
8718 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
8720 property_setter_ident
= c_parser_peek_token (parser
)->value
;
8721 c_parser_consume_token (parser
);
8722 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
8723 c_parser_error (parser
, "setter name must terminate with %<:%>");
8725 c_parser_consume_token (parser
);
8729 if (property_getter_ident
!= NULL_TREE
)
8730 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
8732 property_getter_ident
= c_parser_peek_token (parser
)->value
;
8733 c_parser_consume_token (parser
);
8737 c_parser_error (parser
, "unknown property attribute");
8738 syntax_error
= true;
8745 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8746 c_parser_consume_token (parser
);
8750 parser
->objc_property_attr_context
= false;
8751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8753 /* ... and the property declaration(s). */
8754 properties
= c_parser_struct_declaration (parser
);
8756 if (properties
== error_mark_node
)
8758 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8759 parser
->error
= false;
8763 if (properties
== NULL_TREE
)
8764 c_parser_error (parser
, "expected identifier");
8767 /* Comma-separated properties are chained together in
8768 reverse order; add them one by one. */
8769 properties
= nreverse (properties
);
8771 for (; properties
; properties
= TREE_CHAIN (properties
))
8772 objc_add_property_declaration (loc
, copy_node (properties
),
8773 property_readonly
, property_readwrite
,
8774 property_assign
, property_retain
,
8775 property_copy
, property_nonatomic
,
8776 property_getter_ident
, property_setter_ident
);
8779 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8780 parser
->error
= false;
8783 /* Parse an Objective-C @synthesize declaration. The syntax is:
8785 objc-synthesize-declaration:
8786 @synthesize objc-synthesize-identifier-list ;
8788 objc-synthesize-identifier-list:
8789 objc-synthesize-identifier
8790 objc-synthesize-identifier-list, objc-synthesize-identifier
8792 objc-synthesize-identifier
8794 identifier = identifier
8797 @synthesize MyProperty;
8798 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
8800 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
8801 for C++. Keep them in sync.
8804 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
8806 tree list
= NULL_TREE
;
8808 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
8809 loc
= c_parser_peek_token (parser
)->location
;
8811 c_parser_consume_token (parser
);
8814 tree property
, ivar
;
8815 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8817 c_parser_error (parser
, "expected identifier");
8818 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8819 /* Once we find the semicolon, we can resume normal parsing.
8820 We have to reset parser->error manually because
8821 c_parser_skip_until_found() won't reset it for us if the
8822 next token is precisely a semicolon. */
8823 parser
->error
= false;
8826 property
= c_parser_peek_token (parser
)->value
;
8827 c_parser_consume_token (parser
);
8828 if (c_parser_next_token_is (parser
, CPP_EQ
))
8830 c_parser_consume_token (parser
);
8831 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8833 c_parser_error (parser
, "expected identifier");
8834 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8835 parser
->error
= false;
8838 ivar
= c_parser_peek_token (parser
)->value
;
8839 c_parser_consume_token (parser
);
8843 list
= chainon (list
, build_tree_list (ivar
, property
));
8844 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8845 c_parser_consume_token (parser
);
8849 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8850 objc_add_synthesize_declaration (loc
, list
);
8853 /* Parse an Objective-C @dynamic declaration. The syntax is:
8855 objc-dynamic-declaration:
8856 @dynamic identifier-list ;
8859 @dynamic MyProperty;
8860 @dynamic MyProperty, AnotherProperty;
8862 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
8863 for C++. Keep them in sync.
8866 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
8868 tree list
= NULL_TREE
;
8870 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
8871 loc
= c_parser_peek_token (parser
)->location
;
8873 c_parser_consume_token (parser
);
8877 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8879 c_parser_error (parser
, "expected identifier");
8880 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8881 parser
->error
= false;
8884 property
= c_parser_peek_token (parser
)->value
;
8885 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
8886 c_parser_consume_token (parser
);
8887 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8888 c_parser_consume_token (parser
);
8892 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8893 objc_add_dynamic_declaration (loc
, list
);
8896 /* Parse UPC shared qualifier
8898 shared-type-qualifier: shared layout-qualifier-opt
8899 layout-qualifier: [ constant-expression-opt ] | [ * ]
8903 c_parser_upc_shared_qual (source_location loc
,
8905 struct c_declspecs
*specs
)
8907 tree array_qual
, arg1
;
8909 /* consume "shared" part */
8910 c_parser_consume_token (parser
);
8912 /* check for shared array layout specifier */
8913 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
8915 declspecs_add_qual (loc
, specs
, ridpointers
[RID_SHARED
]);
8918 c_parser_consume_token (parser
);
8919 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8921 /* [] layout specifier */
8922 arg1
= size_zero_node
;
8924 else if (c_parser_next_token_is (parser
, CPP_MULT
))
8926 /* [*] layout specifier */
8927 arg1
= build1 (INDIRECT_REF
, NULL_TREE
, NULL_TREE
);
8928 c_parser_consume_token (parser
);
8932 /* [ expression ] layout specifier */
8933 arg1
= c_parser_expression (parser
).value
;
8935 array_qual
= build4 (ARRAY_REF
, NULL_TREE
, NULL_TREE
,
8936 arg1
, NULL_TREE
, NULL_TREE
);
8937 declspecs_add_qual (loc
, specs
, array_qual
);
8939 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
8941 c_parser_error (parser
, "expected ]");
8943 c_parser_consume_token (parser
);
8946 /* Parse a UPC upc_forall statement
8948 upc_forall-statement:
8949 upc_forall ( expression[opt] ; expression[opt] ;
8950 expression[opt] ; affinity[opt] ) statement
8951 affinity: experssion | continue */
8954 c_parser_upc_forall_statement (c_parser
*parser
)
8956 tree block
, cond
, incr
, save_break
, save_cont
, body
;
8958 location_t loc
= c_parser_peek_token (parser
)->location
;
8959 location_t affinity_loc
= UNKNOWN_LOCATION
;
8960 const int profile_upc_forall
= flag_upc_instrument
&& get_upc_pupc_mode();
8961 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_FORALL
));
8962 c_parser_consume_token (parser
);
8963 block
= c_begin_compound_stmt (flag_isoc99
);
8964 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8966 /* Parse the initialization declaration or expression. */
8967 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8969 c_parser_consume_token (parser
);
8970 c_finish_expr_stmt (loc
, NULL_TREE
);
8972 else if (c_parser_next_token_starts_declspecs (parser
))
8974 c_parser_declaration_or_fndef (parser
, true, true, true,
8976 check_for_loop_decls (loc
, true);
8978 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
8980 /* __extension__ can start a declaration, but is also an
8981 unary operator that can start an expression. Consume all
8982 but the last of a possible series of __extension__ to
8984 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
8985 && (c_parser_peek_2nd_token (parser
)->keyword
8987 c_parser_consume_token (parser
);
8988 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
8991 ext
= disable_extension_diagnostics ();
8992 c_parser_consume_token (parser
);
8993 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
8994 restore_extension_diagnostics (ext
);
8995 check_for_loop_decls (loc
, true);
9003 c_finish_expr_stmt (loc
, c_parser_expression (parser
).value
);
9004 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9006 /* Parse the loop condition. */
9007 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9009 c_parser_consume_token (parser
);
9014 cond
= c_parser_condition (parser
);
9015 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9017 /* Parse the increment expression. */
9018 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9019 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
9021 incr
= c_process_expr_stmt (loc
, c_parser_expression (parser
).value
);
9022 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9023 /* Parse the UPC affinity expression. */
9024 affinity_loc
= c_parser_peek_token (parser
)->location
;
9025 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9027 affinity
= NULL_TREE
;
9029 else if (c_parser_peek_token (parser
)->type
== CPP_KEYWORD
9030 && c_parser_peek_token (parser
)->keyword
== RID_CONTINUE
)
9032 affinity
= NULL_TREE
;
9033 c_parser_consume_token (parser
);
9037 affinity
= c_parser_expression_conv (parser
).value
;
9038 affinity
= c_fully_fold (affinity
, false, NULL
);
9040 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9042 affinity
= upc_affinity_test (affinity_loc
, affinity
);
9046 cond
= error_mark_node
;
9047 incr
= error_mark_node
;
9048 affinity
= error_mark_node
;
9050 save_break
= c_break_label
;
9051 c_break_label
= NULL_TREE
;
9052 save_cont
= c_cont_label
;
9053 c_cont_label
= NULL_TREE
;
9054 body
= c_parser_c99_block_statement (parser
);
9055 if (profile_upc_forall
)
9057 const tree gasp_start
= upc_instrument_forall (loc
, 1 /* start */);
9058 add_stmt (gasp_start
);
9060 loc
= c_parser_peek_token (parser
)->location
;
9061 if (affinity
!= NULL_TREE
&& affinity
!= error_mark_node
)
9063 tree upc_forall_depth
= upc_rts_forall_depth_var ();
9064 tree inc_depth
, depth_gt_one
;
9065 inc_depth
= build_unary_op (loc
, PREINCREMENT_EXPR
, upc_forall_depth
, 0);
9066 c_finish_expr_stmt (loc
, inc_depth
);
9067 depth_gt_one
= build_binary_op (affinity_loc
,
9068 GT_EXPR
, upc_forall_depth
, integer_one_node
, 0);
9069 depth_gt_one
= c_objc_common_truthvalue_conversion (affinity_loc
, depth_gt_one
);
9070 depth_gt_one
= c_fully_fold (depth_gt_one
, false, NULL
);
9071 affinity
= build_binary_op (affinity_loc
, TRUTH_OR_EXPR
,
9072 depth_gt_one
, affinity
, 0);
9073 body
= build3 (COND_EXPR
, void_type_node
, affinity
,
9075 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9076 c_finish_expr_stmt (loc
,
9077 build_unary_op (loc
, PREDECREMENT_EXPR
, upc_forall_depth
, 0));
9080 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
9081 if (profile_upc_forall
)
9083 const tree gasp_end
= upc_instrument_forall (loc
, 0 /* start */);
9084 add_stmt (gasp_end
);
9086 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
9087 c_break_label
= save_break
;
9088 c_cont_label
= save_cont
;
9091 /* Parse an upc-sync-statement.
9093 upc_barrier, upc_wait, upc_notify
9097 c_parser_upc_sync_statement (c_parser
*parser
, int sync_kind
)
9100 tree expr
= NULL_TREE
;
9102 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_UPC_BARRIER
) ||
9103 c_parser_next_token_is_keyword (parser
, RID_UPC_NOTIFY
) ||
9104 c_parser_next_token_is_keyword (parser
, RID_UPC_WAIT
));
9105 loc
= c_parser_peek_token (parser
)->location
;
9106 c_parser_consume_token (parser
);
9107 if (c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
9109 loc
= c_parser_peek_token (parser
)->location
;
9110 expr
= c_parser_expression (parser
).value
;
9111 if (expr
== error_mark_node
)
9114 stmt
= size_int (sync_kind
);
9115 (void) upc_build_sync_stmt (loc
, stmt
, expr
);
9119 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9120 should be considered, statements. ALLOW_STMT is true if we're within
9121 the context of a function and such pragmas are to be allowed. Returns
9122 true if we actually parsed such a pragma. */
9125 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9129 id
= c_parser_peek_token (parser
)->pragma_kind
;
9130 gcc_assert (id
!= PRAGMA_NONE
);
9134 case PRAGMA_OMP_BARRIER
:
9135 if (context
!= pragma_compound
)
9137 if (context
== pragma_stmt
)
9138 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9139 "used in compound statements");
9142 c_parser_omp_barrier (parser
);
9145 case PRAGMA_OMP_FLUSH
:
9146 if (context
!= pragma_compound
)
9148 if (context
== pragma_stmt
)
9149 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9150 "used in compound statements");
9153 c_parser_omp_flush (parser
);
9156 case PRAGMA_OMP_TASKWAIT
:
9157 if (context
!= pragma_compound
)
9159 if (context
== pragma_stmt
)
9160 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9161 "used in compound statements");
9164 c_parser_omp_taskwait (parser
);
9167 case PRAGMA_OMP_TASKYIELD
:
9168 if (context
!= pragma_compound
)
9170 if (context
== pragma_stmt
)
9171 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9172 "used in compound statements");
9175 c_parser_omp_taskyield (parser
);
9178 case PRAGMA_OMP_THREADPRIVATE
:
9179 c_parser_omp_threadprivate (parser
);
9182 case PRAGMA_OMP_SECTION
:
9183 error_at (c_parser_peek_token (parser
)->location
,
9184 "%<#pragma omp section%> may only be used in "
9185 "%<#pragma omp sections%> construct");
9186 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9189 case PRAGMA_GCC_PCH_PREPROCESS
:
9190 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9191 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9195 if (id
< PRAGMA_FIRST_EXTERNAL
)
9197 if (context
== pragma_external
)
9200 c_parser_error (parser
, "expected declaration specifiers");
9201 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9204 c_parser_omp_construct (parser
);
9210 c_parser_consume_pragma (parser
);
9211 c_invoke_pragma_handler (id
);
9213 /* Skip to EOL, but suppress any error message. Those will have been
9214 generated by the handler routine through calling error, as opposed
9215 to calling c_parser_error. */
9216 parser
->error
= true;
9217 c_parser_skip_to_pragma_eol (parser
);
9222 /* The interface the pragma parsers have to the lexer. */
9225 pragma_lex (tree
*value
)
9227 c_token
*tok
= c_parser_peek_token (the_parser
);
9228 enum cpp_ttype ret
= tok
->type
;
9230 *value
= tok
->value
;
9231 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9235 if (ret
== CPP_KEYWORD
)
9237 c_parser_consume_token (the_parser
);
9244 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9248 c_parser_consume_pragma (parser
);
9249 if (c_parser_next_token_is (parser
, CPP_STRING
))
9251 name
= c_parser_peek_token (parser
)->value
;
9252 c_parser_consume_token (parser
);
9255 c_parser_error (parser
, "expected string literal");
9256 c_parser_skip_to_pragma_eol (parser
);
9259 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9262 /* OpenMP 2.5 parsing routines. */
9264 /* Returns name of the next clause.
9265 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9266 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9267 returned and the token is consumed. */
9269 static pragma_omp_clause
9270 c_parser_omp_clause_name (c_parser
*parser
)
9272 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9274 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9275 result
= PRAGMA_OMP_CLAUSE_IF
;
9276 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9277 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9278 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9280 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9285 if (!strcmp ("collapse", p
))
9286 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9287 else if (!strcmp ("copyin", p
))
9288 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9289 else if (!strcmp ("copyprivate", p
))
9290 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9293 if (!strcmp ("final", p
))
9294 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9295 else if (!strcmp ("firstprivate", p
))
9296 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9299 if (!strcmp ("lastprivate", p
))
9300 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9303 if (!strcmp ("mergeable", p
))
9304 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9307 if (!strcmp ("nowait", p
))
9308 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9309 else if (!strcmp ("num_threads", p
))
9310 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9313 if (!strcmp ("ordered", p
))
9314 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9317 if (!strcmp ("private", p
))
9318 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9321 if (!strcmp ("reduction", p
))
9322 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9325 if (!strcmp ("schedule", p
))
9326 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9327 else if (!strcmp ("shared", p
))
9328 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9331 if (!strcmp ("untied", p
))
9332 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9337 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9338 c_parser_consume_token (parser
);
9343 /* Validate that a clause of the given type does not already exist. */
9346 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9351 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9352 if (OMP_CLAUSE_CODE (c
) == code
)
9354 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9355 error_at (loc
, "too many %qs clauses", name
);
9363 variable-list , identifier
9365 If KIND is nonzero, create the appropriate node and install the
9366 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9367 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9369 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9370 return the list created. */
9373 c_parser_omp_variable_list (c_parser
*parser
,
9374 location_t clause_loc
,
9375 enum omp_clause_code kind
,
9378 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9379 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9380 c_parser_error (parser
, "expected identifier");
9382 while (c_parser_next_token_is (parser
, CPP_NAME
)
9383 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9385 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9388 undeclared_variable (c_parser_peek_token (parser
)->location
,
9389 c_parser_peek_token (parser
)->value
);
9390 else if (t
== error_mark_node
)
9394 tree u
= build_omp_clause (clause_loc
, kind
);
9395 OMP_CLAUSE_DECL (u
) = t
;
9396 OMP_CLAUSE_CHAIN (u
) = list
;
9400 list
= tree_cons (t
, NULL_TREE
, list
);
9402 c_parser_consume_token (parser
);
9404 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9407 c_parser_consume_token (parser
);
9413 /* Similarly, but expect leading and trailing parenthesis. This is a very
9414 common case for omp clauses. */
9417 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9420 /* The clauses location. */
9421 location_t loc
= c_parser_peek_token (parser
)->location
;
9423 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9425 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9426 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9432 collapse ( constant-expression ) */
9435 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9437 tree c
, num
= error_mark_node
;
9441 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9443 loc
= c_parser_peek_token (parser
)->location
;
9444 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9446 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9449 if (num
== error_mark_node
)
9451 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9452 || !host_integerp (num
, 0)
9453 || (n
= tree_low_cst (num
, 0)) <= 0
9457 "collapse argument needs positive constant integer expression");
9460 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9461 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9462 OMP_CLAUSE_CHAIN (c
) = list
;
9467 copyin ( variable-list ) */
9470 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9472 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9476 copyprivate ( variable-list ) */
9479 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9481 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9485 default ( shared | none ) */
9488 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9490 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9491 location_t loc
= c_parser_peek_token (parser
)->location
;
9494 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9496 if (c_parser_next_token_is (parser
, CPP_NAME
))
9498 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9503 if (strcmp ("none", p
) != 0)
9505 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9509 if (strcmp ("shared", p
) != 0)
9511 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9518 c_parser_consume_token (parser
);
9523 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9525 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9527 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9530 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9531 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9532 OMP_CLAUSE_CHAIN (c
) = list
;
9533 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9539 firstprivate ( variable-list ) */
9542 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9544 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9548 final ( expression ) */
9551 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9553 location_t loc
= c_parser_peek_token (parser
)->location
;
9554 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9556 tree t
= c_parser_paren_condition (parser
);
9559 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9561 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9562 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9563 OMP_CLAUSE_CHAIN (c
) = list
;
9567 c_parser_error (parser
, "expected %<(%>");
9573 if ( expression ) */
9576 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9578 location_t loc
= c_parser_peek_token (parser
)->location
;
9579 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9581 tree t
= c_parser_paren_condition (parser
);
9584 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9586 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9587 OMP_CLAUSE_IF_EXPR (c
) = t
;
9588 OMP_CLAUSE_CHAIN (c
) = list
;
9592 c_parser_error (parser
, "expected %<(%>");
9598 lastprivate ( variable-list ) */
9601 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
9603 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
9610 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9614 /* FIXME: Should we allow duplicates? */
9615 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
9617 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9618 OMP_CLAUSE_MERGEABLE
);
9619 OMP_CLAUSE_CHAIN (c
) = list
;
9628 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9631 location_t loc
= c_parser_peek_token (parser
)->location
;
9633 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
9635 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
9636 OMP_CLAUSE_CHAIN (c
) = list
;
9641 num_threads ( expression ) */
9644 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
9646 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
9647 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9649 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
9650 tree c
, t
= c_parser_expression (parser
).value
;
9652 t
= c_fully_fold (t
, false, NULL
);
9654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9656 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9658 c_parser_error (parser
, "expected integer expression");
9662 /* Attempt to statically determine when the number isn't positive. */
9663 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
9664 build_int_cst (TREE_TYPE (t
), 0));
9665 if (CAN_HAVE_LOCATION_P (c
))
9666 SET_EXPR_LOCATION (c
, expr_loc
);
9667 if (c
== boolean_true_node
)
9669 warning_at (expr_loc
, 0,
9670 "%<num_threads%> value must be positive");
9671 t
= integer_one_node
;
9674 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
9676 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
9677 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
9678 OMP_CLAUSE_CHAIN (c
) = list
;
9689 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
9693 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
9695 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9696 OMP_CLAUSE_ORDERED
);
9697 OMP_CLAUSE_CHAIN (c
) = list
;
9703 private ( variable-list ) */
9706 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
9708 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
9712 reduction ( reduction-operator : variable-list )
9715 One of: + * - & ^ | && ||
9720 One of: + * - & ^ | && || max min */
9723 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
9725 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
9726 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9728 enum tree_code code
;
9730 switch (c_parser_peek_token (parser
)->type
)
9742 code
= BIT_AND_EXPR
;
9745 code
= BIT_XOR_EXPR
;
9748 code
= BIT_IOR_EXPR
;
9751 code
= TRUTH_ANDIF_EXPR
;
9754 code
= TRUTH_ORIF_EXPR
;
9759 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9760 if (strcmp (p
, "min") == 0)
9765 if (strcmp (p
, "max") == 0)
9773 c_parser_error (parser
,
9774 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
9775 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
9776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9779 c_parser_consume_token (parser
);
9780 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9784 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
9785 OMP_CLAUSE_REDUCTION
, list
);
9786 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
9787 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
9791 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9797 schedule ( schedule-kind )
9798 schedule ( schedule-kind , expression )
9801 static | dynamic | guided | runtime | auto
9805 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
9808 location_t loc
= c_parser_peek_token (parser
)->location
;
9810 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9813 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
9815 if (c_parser_next_token_is (parser
, CPP_NAME
))
9817 tree kind
= c_parser_peek_token (parser
)->value
;
9818 const char *p
= IDENTIFIER_POINTER (kind
);
9823 if (strcmp ("dynamic", p
) != 0)
9825 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
9829 if (strcmp ("guided", p
) != 0)
9831 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
9835 if (strcmp ("runtime", p
) != 0)
9837 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
9844 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
9845 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
9846 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
9847 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
9851 c_parser_consume_token (parser
);
9852 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9855 c_parser_consume_token (parser
);
9857 here
= c_parser_peek_token (parser
)->location
;
9858 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
9860 t
= c_fully_fold (t
, false, NULL
);
9862 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
9863 error_at (here
, "schedule %<runtime%> does not take "
9864 "a %<chunk_size%> parameter");
9865 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
9867 "schedule %<auto%> does not take "
9868 "a %<chunk_size%> parameter");
9869 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
9870 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
9872 c_parser_error (parser
, "expected integer expression");
9874 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9878 "expected %<,%> or %<)%>");
9880 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
9881 OMP_CLAUSE_CHAIN (c
) = list
;
9885 c_parser_error (parser
, "invalid schedule kind");
9886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
9891 shared ( variable-list ) */
9894 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
9896 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
9903 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
9907 /* FIXME: Should we allow duplicates? */
9908 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
9910 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
9912 OMP_CLAUSE_CHAIN (c
) = list
;
9917 /* Parse all OpenMP clauses. The set clauses allowed by the directive
9918 is a bitmask in MASK. Return the list of clauses found; the result
9919 of clause default goes in *pdefault. */
9922 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
9925 tree clauses
= NULL
;
9928 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
9931 pragma_omp_clause c_kind
;
9933 tree prev
= clauses
;
9935 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
9936 c_parser_consume_token (parser
);
9939 here
= c_parser_peek_token (parser
)->location
;
9940 c_kind
= c_parser_omp_clause_name (parser
);
9944 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
9945 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
9946 c_name
= "collapse";
9948 case PRAGMA_OMP_CLAUSE_COPYIN
:
9949 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
9952 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
9953 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
9954 c_name
= "copyprivate";
9956 case PRAGMA_OMP_CLAUSE_DEFAULT
:
9957 clauses
= c_parser_omp_clause_default (parser
, clauses
);
9960 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
9961 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
9962 c_name
= "firstprivate";
9964 case PRAGMA_OMP_CLAUSE_FINAL
:
9965 clauses
= c_parser_omp_clause_final (parser
, clauses
);
9968 case PRAGMA_OMP_CLAUSE_IF
:
9969 clauses
= c_parser_omp_clause_if (parser
, clauses
);
9972 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
9973 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
9974 c_name
= "lastprivate";
9976 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
9977 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
9978 c_name
= "mergeable";
9980 case PRAGMA_OMP_CLAUSE_NOWAIT
:
9981 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
9984 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
9985 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
9986 c_name
= "num_threads";
9988 case PRAGMA_OMP_CLAUSE_ORDERED
:
9989 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
9992 case PRAGMA_OMP_CLAUSE_PRIVATE
:
9993 clauses
= c_parser_omp_clause_private (parser
, clauses
);
9996 case PRAGMA_OMP_CLAUSE_REDUCTION
:
9997 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
9998 c_name
= "reduction";
10000 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10001 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10002 c_name
= "schedule";
10004 case PRAGMA_OMP_CLAUSE_SHARED
:
10005 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10008 case PRAGMA_OMP_CLAUSE_UNTIED
:
10009 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10013 c_parser_error (parser
, "expected %<#pragma omp%> clause");
10017 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
10019 /* Remove the invalid clause(s) from the list to avoid
10020 confusing the rest of the compiler. */
10022 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
10027 c_parser_skip_to_pragma_eol (parser
);
10029 return c_finish_omp_clauses (clauses
);
10036 In practice, we're also interested in adding the statement to an
10037 outer node. So it is convenient if we work around the fact that
10038 c_parser_statement calls add_stmt. */
10041 c_parser_omp_structured_block (c_parser
*parser
)
10043 tree stmt
= push_stmt_list ();
10044 c_parser_statement (parser
);
10045 return pop_stmt_list (stmt
);
10049 # pragma omp atomic new-line
10053 x binop= expr | x++ | ++x | x-- | --x
10055 +, *, -, /, &, ^, |, <<, >>
10057 where x is an lvalue expression with scalar type.
10060 # pragma omp atomic new-line
10063 # pragma omp atomic read new-line
10066 # pragma omp atomic write new-line
10069 # pragma omp atomic update new-line
10072 # pragma omp atomic capture new-line
10075 # pragma omp atomic capture new-line
10083 expression-stmt | x = x binop expr
10085 v = x binop= expr | v = x++ | v = ++x | v = x-- | v = --x
10087 { v = x; update-stmt; } | { update-stmt; v = x; }
10089 where x and v are lvalue expressions with scalar type.
10091 LOC is the location of the #pragma token. */
10094 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
10096 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
10097 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
10098 tree stmt
, orig_lhs
;
10099 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
10100 struct c_expr rhs_expr
;
10101 bool structured_block
= false;
10103 if (c_parser_next_token_is (parser
, CPP_NAME
))
10105 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10107 if (!strcmp (p
, "read"))
10108 code
= OMP_ATOMIC_READ
;
10109 else if (!strcmp (p
, "write"))
10111 else if (!strcmp (p
, "update"))
10113 else if (!strcmp (p
, "capture"))
10114 code
= OMP_ATOMIC_CAPTURE_NEW
;
10118 c_parser_consume_token (parser
);
10120 c_parser_skip_to_pragma_eol (parser
);
10124 case OMP_ATOMIC_READ
:
10125 case NOP_EXPR
: /* atomic write */
10126 v
= c_parser_unary_expression (parser
).value
;
10127 v
= c_fully_fold (v
, false, NULL
);
10128 if (v
== error_mark_node
)
10130 loc
= c_parser_peek_token (parser
)->location
;
10131 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10133 if (code
== NOP_EXPR
)
10134 lhs
= c_parser_expression (parser
).value
;
10136 lhs
= c_parser_unary_expression (parser
).value
;
10137 lhs
= c_fully_fold (lhs
, false, NULL
);
10138 if (lhs
== error_mark_node
)
10140 if (code
== NOP_EXPR
)
10142 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
10150 case OMP_ATOMIC_CAPTURE_NEW
:
10151 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10153 c_parser_consume_token (parser
);
10154 structured_block
= true;
10158 v
= c_parser_unary_expression (parser
).value
;
10159 v
= c_fully_fold (v
, false, NULL
);
10160 if (v
== error_mark_node
)
10162 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10170 /* For structured_block case we don't know yet whether
10171 old or new x should be captured. */
10173 lhs
= c_parser_unary_expression (parser
).value
;
10174 lhs
= c_fully_fold (lhs
, false, NULL
);
10176 switch (TREE_CODE (lhs
))
10180 c_parser_skip_to_end_of_block_or_statement (parser
);
10181 if (structured_block
)
10183 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10184 c_parser_consume_token (parser
);
10185 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10187 c_parser_skip_to_end_of_block_or_statement (parser
);
10188 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10189 c_parser_consume_token (parser
);
10194 case POSTINCREMENT_EXPR
:
10195 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10196 code
= OMP_ATOMIC_CAPTURE_OLD
;
10198 case PREINCREMENT_EXPR
:
10199 lhs
= TREE_OPERAND (lhs
, 0);
10200 opcode
= PLUS_EXPR
;
10201 rhs
= integer_one_node
;
10204 case POSTDECREMENT_EXPR
:
10205 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
10206 code
= OMP_ATOMIC_CAPTURE_OLD
;
10208 case PREDECREMENT_EXPR
:
10209 lhs
= TREE_OPERAND (lhs
, 0);
10210 opcode
= MINUS_EXPR
;
10211 rhs
= integer_one_node
;
10214 case COMPOUND_EXPR
:
10215 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
10216 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
10217 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
10218 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
10219 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
10220 (TREE_OPERAND (lhs
, 1), 0), 0)))
10222 /* Undo effects of boolean_increment for post {in,de}crement. */
10223 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
10226 if (TREE_CODE (lhs
) == MODIFY_EXPR
10227 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
10229 /* Undo effects of boolean_increment. */
10230 if (integer_onep (TREE_OPERAND (lhs
, 1)))
10232 /* This is pre or post increment. */
10233 rhs
= TREE_OPERAND (lhs
, 1);
10234 lhs
= TREE_OPERAND (lhs
, 0);
10236 if (code
== OMP_ATOMIC_CAPTURE_NEW
10237 && !structured_block
10238 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10239 code
= OMP_ATOMIC_CAPTURE_OLD
;
10242 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
10243 && TREE_OPERAND (lhs
, 0)
10244 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
10246 /* This is pre or post decrement. */
10247 rhs
= TREE_OPERAND (lhs
, 1);
10248 lhs
= TREE_OPERAND (lhs
, 0);
10250 if (code
== OMP_ATOMIC_CAPTURE_NEW
10251 && !structured_block
10252 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
10253 code
= OMP_ATOMIC_CAPTURE_OLD
;
10259 switch (c_parser_peek_token (parser
)->type
)
10262 opcode
= MULT_EXPR
;
10265 opcode
= TRUNC_DIV_EXPR
;
10268 opcode
= PLUS_EXPR
;
10271 opcode
= MINUS_EXPR
;
10273 case CPP_LSHIFT_EQ
:
10274 opcode
= LSHIFT_EXPR
;
10276 case CPP_RSHIFT_EQ
:
10277 opcode
= RSHIFT_EXPR
;
10280 opcode
= BIT_AND_EXPR
;
10283 opcode
= BIT_IOR_EXPR
;
10286 opcode
= BIT_XOR_EXPR
;
10289 if (structured_block
|| code
== OMP_ATOMIC
)
10291 location_t aloc
= c_parser_peek_token (parser
)->location
;
10292 location_t rhs_loc
;
10293 enum c_parser_prec oprec
= PREC_NONE
;
10295 c_parser_consume_token (parser
);
10296 rhs1
= c_parser_unary_expression (parser
).value
;
10297 rhs1
= c_fully_fold (rhs1
, false, NULL
);
10298 if (rhs1
== error_mark_node
)
10300 switch (c_parser_peek_token (parser
)->type
)
10302 case CPP_SEMICOLON
:
10303 if (code
== OMP_ATOMIC_CAPTURE_NEW
)
10305 code
= OMP_ATOMIC_CAPTURE_OLD
;
10310 c_parser_consume_token (parser
);
10313 c_parser_error (parser
,
10314 "invalid form of %<#pragma omp atomic%>");
10317 opcode
= MULT_EXPR
;
10321 opcode
= TRUNC_DIV_EXPR
;
10325 opcode
= PLUS_EXPR
;
10329 opcode
= MINUS_EXPR
;
10333 opcode
= LSHIFT_EXPR
;
10334 oprec
= PREC_SHIFT
;
10337 opcode
= RSHIFT_EXPR
;
10338 oprec
= PREC_SHIFT
;
10341 opcode
= BIT_AND_EXPR
;
10342 oprec
= PREC_BITAND
;
10345 opcode
= BIT_IOR_EXPR
;
10346 oprec
= PREC_BITOR
;
10349 opcode
= BIT_XOR_EXPR
;
10350 oprec
= PREC_BITXOR
;
10353 c_parser_error (parser
,
10354 "invalid operator for %<#pragma omp atomic%>");
10358 c_parser_consume_token (parser
);
10359 rhs_loc
= c_parser_peek_token (parser
)->location
;
10360 if (commutative_tree_code (opcode
))
10361 oprec
= (enum c_parser_prec
) (oprec
- 1);
10362 rhs_expr
= c_parser_binary_expression (parser
, NULL
, oprec
);
10363 rhs_expr
= default_function_array_read_conversion (rhs_loc
,
10365 rhs
= rhs_expr
.value
;
10366 rhs
= c_fully_fold (rhs
, false, NULL
);
10371 c_parser_error (parser
,
10372 "invalid operator for %<#pragma omp atomic%>");
10376 /* Arrange to pass the location of the assignment operator to
10377 c_finish_omp_atomic. */
10378 loc
= c_parser_peek_token (parser
)->location
;
10379 c_parser_consume_token (parser
);
10381 location_t rhs_loc
= c_parser_peek_token (parser
)->location
;
10382 rhs_expr
= c_parser_expression (parser
);
10383 rhs_expr
= default_function_array_read_conversion (rhs_loc
, rhs_expr
);
10385 rhs
= rhs_expr
.value
;
10386 rhs
= c_fully_fold (rhs
, false, NULL
);
10390 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
10392 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
10394 v
= c_parser_unary_expression (parser
).value
;
10395 v
= c_fully_fold (v
, false, NULL
);
10396 if (v
== error_mark_node
)
10398 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
10400 lhs1
= c_parser_unary_expression (parser
).value
;
10401 lhs1
= c_fully_fold (lhs1
, false, NULL
);
10402 if (lhs1
== error_mark_node
)
10405 if (structured_block
)
10407 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10408 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
10411 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
);
10412 if (stmt
!= error_mark_node
)
10415 if (!structured_block
)
10416 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10421 # pragma omp barrier new-line
10425 c_parser_omp_barrier (c_parser
*parser
)
10427 location_t loc
= c_parser_peek_token (parser
)->location
;
10428 c_parser_consume_pragma (parser
);
10429 c_parser_skip_to_pragma_eol (parser
);
10431 c_finish_omp_barrier (loc
);
10435 # pragma omp critical [(name)] new-line
10438 LOC is the location of the #pragma itself. */
10441 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
10443 tree stmt
, name
= NULL
;
10445 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10447 c_parser_consume_token (parser
);
10448 if (c_parser_next_token_is (parser
, CPP_NAME
))
10450 name
= c_parser_peek_token (parser
)->value
;
10451 c_parser_consume_token (parser
);
10452 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10455 c_parser_error (parser
, "expected identifier");
10457 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10458 c_parser_error (parser
, "expected %<(%> or end of line");
10459 c_parser_skip_to_pragma_eol (parser
);
10461 stmt
= c_parser_omp_structured_block (parser
);
10462 return c_finish_omp_critical (loc
, stmt
, name
);
10466 # pragma omp flush flush-vars[opt] new-line
10469 ( variable-list ) */
10472 c_parser_omp_flush (c_parser
*parser
)
10474 location_t loc
= c_parser_peek_token (parser
)->location
;
10475 c_parser_consume_pragma (parser
);
10476 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10477 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10478 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10479 c_parser_error (parser
, "expected %<(%> or end of line");
10480 c_parser_skip_to_pragma_eol (parser
);
10482 c_finish_omp_flush (loc
);
10485 /* Parse the restricted form of the for statement allowed by OpenMP.
10486 The real trick here is to determine the loop control variable early
10487 so that we can push a new decl if necessary to make it private.
10488 LOC is the location of the OMP in "#pragma omp". */
10491 c_parser_omp_for_loop (location_t loc
,
10492 c_parser
*parser
, tree clauses
, tree
*par_clauses
)
10494 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
10495 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
10496 bool fail
= false, open_brace_parsed
= false;
10497 int i
, collapse
= 1, nbraces
= 0;
10498 location_t for_loc
;
10499 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
10501 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
10502 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
10503 collapse
= tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl
), 0);
10505 gcc_assert (collapse
>= 1);
10507 declv
= make_tree_vec (collapse
);
10508 initv
= make_tree_vec (collapse
);
10509 condv
= make_tree_vec (collapse
);
10510 incrv
= make_tree_vec (collapse
);
10512 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
10514 c_parser_error (parser
, "for statement expected");
10517 for_loc
= c_parser_peek_token (parser
)->location
;
10518 c_parser_consume_token (parser
);
10520 for (i
= 0; i
< collapse
; i
++)
10522 int bracecount
= 0;
10524 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10527 /* Parse the initialization declaration or expression. */
10528 if (c_parser_next_tokens_start_declaration (parser
))
10531 vec_safe_push (for_block
, c_begin_compound_stmt (true));
10532 c_parser_declaration_or_fndef (parser
, true, true, true, true, true, NULL
);
10533 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
10536 if (DECL_INITIAL (decl
) == error_mark_node
)
10537 decl
= error_mark_node
;
10540 else if (c_parser_next_token_is (parser
, CPP_NAME
)
10541 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
10543 struct c_expr decl_exp
;
10544 struct c_expr init_exp
;
10545 location_t init_loc
;
10547 decl_exp
= c_parser_postfix_expression (parser
);
10548 decl
= decl_exp
.value
;
10550 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
10552 init_loc
= c_parser_peek_token (parser
)->location
;
10553 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
10554 init_exp
= default_function_array_read_conversion (init_loc
,
10556 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
10557 NOP_EXPR
, init_loc
, init_exp
.value
,
10558 init_exp
.original_type
);
10559 init
= c_process_expr_stmt (init_loc
, init
);
10561 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10566 c_parser_error (parser
,
10567 "expected iteration declaration or initialization");
10568 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10574 /* Parse the loop condition. */
10576 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
10578 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
10579 struct c_expr cond_expr
= c_parser_binary_expression (parser
, NULL
,
10582 cond
= cond_expr
.value
;
10583 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
10584 cond
= c_fully_fold (cond
, false, NULL
);
10585 switch (cond_expr
.original_code
)
10593 /* Can't be cond = error_mark_node, because we want to preserve
10594 the location until c_finish_omp_for. */
10595 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
10598 protected_set_expr_location (cond
, cond_loc
);
10600 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10602 /* Parse the increment expression. */
10604 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
10606 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
10608 incr
= c_process_expr_stmt (incr_loc
,
10609 c_parser_expression (parser
).value
);
10611 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10613 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
10617 TREE_VEC_ELT (declv
, i
) = decl
;
10618 TREE_VEC_ELT (initv
, i
) = init
;
10619 TREE_VEC_ELT (condv
, i
) = cond
;
10620 TREE_VEC_ELT (incrv
, i
) = incr
;
10624 if (i
== collapse
- 1)
10627 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
10628 in between the collapsed for loops to be still considered perfectly
10629 nested. Hopefully the final version clarifies this.
10630 For now handle (multiple) {'s and empty statements. */
10633 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10635 c_parser_consume_token (parser
);
10638 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10640 c_parser_consume_token (parser
);
10643 else if (bracecount
10644 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10645 c_parser_consume_token (parser
);
10648 c_parser_error (parser
, "not enough perfectly nested loops");
10651 open_brace_parsed
= true;
10661 nbraces
+= bracecount
;
10664 save_break
= c_break_label
;
10665 c_break_label
= size_one_node
;
10666 save_cont
= c_cont_label
;
10667 c_cont_label
= NULL_TREE
;
10668 body
= push_stmt_list ();
10670 if (open_brace_parsed
)
10672 location_t here
= c_parser_peek_token (parser
)->location
;
10673 stmt
= c_begin_compound_stmt (true);
10674 c_parser_compound_statement_nostart (parser
);
10675 add_stmt (c_end_compound_stmt (here
, stmt
, true));
10678 add_stmt (c_parser_c99_block_statement (parser
));
10681 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
10682 SET_EXPR_LOCATION (t
, loc
);
10686 body
= pop_stmt_list (body
);
10687 c_break_label
= save_break
;
10688 c_cont_label
= save_cont
;
10692 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10694 c_parser_consume_token (parser
);
10697 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10698 c_parser_consume_token (parser
);
10701 c_parser_error (parser
, "collapsed loops not perfectly nested");
10704 location_t here
= c_parser_peek_token (parser
)->location
;
10705 stmt
= c_begin_compound_stmt (true);
10707 c_parser_compound_statement_nostart (parser
);
10708 body
= c_end_compound_stmt (here
, stmt
, true);
10715 /* Only bother calling c_finish_omp_for if we haven't already generated
10716 an error from the initialization parsing. */
10719 stmt
= c_finish_omp_for (loc
, declv
, initv
, condv
, incrv
, body
, NULL
);
10722 if (par_clauses
!= NULL
)
10725 for (c
= par_clauses
; *c
; )
10726 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
10727 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
10728 c
= &OMP_CLAUSE_CHAIN (*c
);
10731 for (i
= 0; i
< collapse
; i
++)
10732 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
10735 c
= &OMP_CLAUSE_CHAIN (*c
);
10736 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
10739 "iteration variable %qD should not be firstprivate",
10740 OMP_CLAUSE_DECL (*c
));
10741 *c
= OMP_CLAUSE_CHAIN (*c
);
10745 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
10746 change it to shared (decl) in
10747 OMP_PARALLEL_CLAUSES. */
10748 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
10749 OMP_CLAUSE_LASTPRIVATE
);
10750 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
10751 OMP_CLAUSE_CHAIN (l
) = clauses
;
10753 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
10757 OMP_FOR_CLAUSES (stmt
) = clauses
;
10762 while (!for_block
->is_empty ())
10764 /* FIXME diagnostics: LOC below should be the actual location of
10765 this particular for block. We need to build a list of
10766 locations to go along with FOR_BLOCK. */
10767 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
10770 release_tree_vector (for_block
);
10775 #pragma omp for for-clause[optseq] new-line
10778 LOC is the location of the #pragma token.
10781 #define OMP_FOR_CLAUSE_MASK \
10782 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10783 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10784 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10785 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10786 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
10787 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
10788 | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \
10789 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10792 c_parser_omp_for (location_t loc
, c_parser
*parser
)
10794 tree block
, clauses
, ret
;
10796 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
10797 "#pragma omp for");
10799 block
= c_begin_compound_stmt (true);
10800 ret
= c_parser_omp_for_loop (loc
, parser
, clauses
, NULL
);
10801 block
= c_end_compound_stmt (loc
, block
, true);
10808 # pragma omp master new-line
10811 LOC is the location of the #pragma token.
10815 c_parser_omp_master (location_t loc
, c_parser
*parser
)
10817 c_parser_skip_to_pragma_eol (parser
);
10818 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
10822 # pragma omp ordered new-line
10825 LOC is the location of the #pragma itself.
10829 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
10831 c_parser_skip_to_pragma_eol (parser
);
10832 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
10838 { section-sequence }
10841 section-directive[opt] structured-block
10842 section-sequence section-directive structured-block
10844 SECTIONS_LOC is the location of the #pragma omp sections. */
10847 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
10849 tree stmt
, substmt
;
10850 bool error_suppress
= false;
10853 loc
= c_parser_peek_token (parser
)->location
;
10854 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10856 /* Avoid skipping until the end of the block. */
10857 parser
->error
= false;
10861 stmt
= push_stmt_list ();
10863 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
10865 substmt
= push_stmt_list ();
10869 c_parser_statement (parser
);
10871 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10873 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10875 if (c_parser_next_token_is (parser
, CPP_EOF
))
10879 substmt
= pop_stmt_list (substmt
);
10880 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10881 SET_EXPR_LOCATION (substmt
, loc
);
10882 add_stmt (substmt
);
10887 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
10889 if (c_parser_next_token_is (parser
, CPP_EOF
))
10892 loc
= c_parser_peek_token (parser
)->location
;
10893 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
10895 c_parser_consume_pragma (parser
);
10896 c_parser_skip_to_pragma_eol (parser
);
10897 error_suppress
= false;
10899 else if (!error_suppress
)
10901 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
10902 error_suppress
= true;
10905 substmt
= c_parser_omp_structured_block (parser
);
10906 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
10907 SET_EXPR_LOCATION (substmt
, loc
);
10908 add_stmt (substmt
);
10910 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
10911 "expected %<#pragma omp section%> or %<}%>");
10913 substmt
= pop_stmt_list (stmt
);
10915 stmt
= make_node (OMP_SECTIONS
);
10916 SET_EXPR_LOCATION (stmt
, sections_loc
);
10917 TREE_TYPE (stmt
) = void_type_node
;
10918 OMP_SECTIONS_BODY (stmt
) = substmt
;
10920 return add_stmt (stmt
);
10924 # pragma omp sections sections-clause[optseq] newline
10927 LOC is the location of the #pragma token.
10930 #define OMP_SECTIONS_CLAUSE_MASK \
10931 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10932 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10933 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
10934 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10935 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
10938 c_parser_omp_sections (location_t loc
, c_parser
*parser
)
10940 tree block
, clauses
, ret
;
10942 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
10943 "#pragma omp sections");
10945 block
= c_begin_compound_stmt (true);
10946 ret
= c_parser_omp_sections_scope (loc
, parser
);
10948 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
10949 block
= c_end_compound_stmt (loc
, block
, true);
10956 # pragma parallel parallel-clause new-line
10957 # pragma parallel for parallel-for-clause new-line
10958 # pragma parallel sections parallel-sections-clause new-line
10960 LOC is the location of the #pragma token.
10963 #define OMP_PARALLEL_CLAUSE_MASK \
10964 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
10965 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
10966 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
10967 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
10968 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
10969 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
10970 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
10971 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
10974 c_parser_omp_parallel (location_t loc
, c_parser
*parser
)
10976 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
10977 const char *p_name
= "#pragma omp parallel";
10978 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
10979 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
10981 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10983 c_parser_consume_token (parser
);
10984 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
10985 p_name
= "#pragma omp parallel for";
10986 mask
|= OMP_FOR_CLAUSE_MASK
;
10987 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
10989 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10991 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10992 if (strcmp (p
, "sections") == 0)
10994 c_parser_consume_token (parser
);
10995 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
10996 p_name
= "#pragma omp parallel sections";
10997 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
10998 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
11002 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
11006 case PRAGMA_OMP_PARALLEL
:
11007 block
= c_begin_omp_parallel ();
11008 c_parser_statement (parser
);
11009 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
11012 case PRAGMA_OMP_PARALLEL_FOR
:
11013 block
= c_begin_omp_parallel ();
11014 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
11015 c_parser_omp_for_loop (loc
, parser
, ws_clause
, &par_clause
);
11016 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
11017 OMP_PARALLEL_COMBINED (stmt
) = 1;
11020 case PRAGMA_OMP_PARALLEL_SECTIONS
:
11021 block
= c_begin_omp_parallel ();
11022 c_split_parallel_clauses (loc
, clauses
, &par_clause
, &ws_clause
);
11023 stmt
= c_parser_omp_sections_scope (loc
, parser
);
11025 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
11026 stmt
= c_finish_omp_parallel (loc
, par_clause
, block
);
11027 OMP_PARALLEL_COMBINED (stmt
) = 1;
11031 gcc_unreachable ();
11038 # pragma omp single single-clause[optseq] new-line
11041 LOC is the location of the #pragma.
11044 #define OMP_SINGLE_CLAUSE_MASK \
11045 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
11046 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11047 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
11048 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
11051 c_parser_omp_single (location_t loc
, c_parser
*parser
)
11053 tree stmt
= make_node (OMP_SINGLE
);
11054 SET_EXPR_LOCATION (stmt
, loc
);
11055 TREE_TYPE (stmt
) = void_type_node
;
11057 OMP_SINGLE_CLAUSES (stmt
)
11058 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
11059 "#pragma omp single");
11060 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
11062 return add_stmt (stmt
);
11066 # pragma omp task task-clause[optseq] new-line
11068 LOC is the location of the #pragma.
11071 #define OMP_TASK_CLAUSE_MASK \
11072 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
11073 | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \
11074 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
11075 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
11076 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11077 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
11078 | (1u << PRAGMA_OMP_CLAUSE_FINAL) \
11079 | (1u << PRAGMA_OMP_CLAUSE_MERGEABLE))
11082 c_parser_omp_task (location_t loc
, c_parser
*parser
)
11084 tree clauses
, block
;
11086 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
11087 "#pragma omp task");
11089 block
= c_begin_omp_task ();
11090 c_parser_statement (parser
);
11091 return c_finish_omp_task (loc
, clauses
, block
);
11095 # pragma omp taskwait new-line
11099 c_parser_omp_taskwait (c_parser
*parser
)
11101 location_t loc
= c_parser_peek_token (parser
)->location
;
11102 c_parser_consume_pragma (parser
);
11103 c_parser_skip_to_pragma_eol (parser
);
11105 c_finish_omp_taskwait (loc
);
11109 # pragma omp taskyield new-line
11113 c_parser_omp_taskyield (c_parser
*parser
)
11115 location_t loc
= c_parser_peek_token (parser
)->location
;
11116 c_parser_consume_pragma (parser
);
11117 c_parser_skip_to_pragma_eol (parser
);
11119 c_finish_omp_taskyield (loc
);
11122 /* Main entry point to parsing most OpenMP pragmas. */
11125 c_parser_omp_construct (c_parser
*parser
)
11127 enum pragma_kind p_kind
;
11131 loc
= c_parser_peek_token (parser
)->location
;
11132 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
11133 c_parser_consume_pragma (parser
);
11137 case PRAGMA_OMP_ATOMIC
:
11138 c_parser_omp_atomic (loc
, parser
);
11140 case PRAGMA_OMP_CRITICAL
:
11141 stmt
= c_parser_omp_critical (loc
, parser
);
11143 case PRAGMA_OMP_FOR
:
11144 stmt
= c_parser_omp_for (loc
, parser
);
11146 case PRAGMA_OMP_MASTER
:
11147 stmt
= c_parser_omp_master (loc
, parser
);
11149 case PRAGMA_OMP_ORDERED
:
11150 stmt
= c_parser_omp_ordered (loc
, parser
);
11152 case PRAGMA_OMP_PARALLEL
:
11153 stmt
= c_parser_omp_parallel (loc
, parser
);
11155 case PRAGMA_OMP_SECTIONS
:
11156 stmt
= c_parser_omp_sections (loc
, parser
);
11158 case PRAGMA_OMP_SINGLE
:
11159 stmt
= c_parser_omp_single (loc
, parser
);
11161 case PRAGMA_OMP_TASK
:
11162 stmt
= c_parser_omp_task (loc
, parser
);
11165 gcc_unreachable ();
11169 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
11174 # pragma omp threadprivate (variable-list) */
11177 c_parser_omp_threadprivate (c_parser
*parser
)
11182 c_parser_consume_pragma (parser
);
11183 loc
= c_parser_peek_token (parser
)->location
;
11184 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11186 /* Mark every variable in VARS to be assigned thread local storage. */
11187 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
11189 tree v
= TREE_PURPOSE (t
);
11191 /* FIXME diagnostics: Ideally we should keep individual
11192 locations for all the variables in the var list to make the
11193 following errors more precise. Perhaps
11194 c_parser_omp_var_list_parens() should construct a list of
11195 locations to go along with the var list. */
11197 /* If V had already been marked threadprivate, it doesn't matter
11198 whether it had been used prior to this point. */
11199 if (TREE_CODE (v
) != VAR_DECL
)
11200 error_at (loc
, "%qD is not a variable", v
);
11201 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
11202 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
11203 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
11204 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
11205 else if (TREE_TYPE (v
) == error_mark_node
)
11207 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
11208 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
11211 if (! DECL_THREAD_LOCAL_P (v
))
11213 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
11214 /* If rtl has been already set for this var, call
11215 make_decl_rtl once again, so that encode_section_info
11216 has a chance to look at the new decl flags. */
11217 if (DECL_RTL_SET_P (v
))
11220 C_DECL_THREADPRIVATE_P (v
) = 1;
11224 c_parser_skip_to_pragma_eol (parser
);
11227 /* Parse a transaction attribute (GCC Extension).
11229 transaction-attribute:
11233 The transactional memory language description is written for C++,
11234 and uses the C++0x attribute syntax. For compatibility, allow the
11235 bracket style for transactions in C as well. */
11238 c_parser_transaction_attributes (c_parser
*parser
)
11240 tree attr_name
, attr
= NULL
;
11242 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
11243 return c_parser_attributes (parser
);
11245 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11247 c_parser_consume_token (parser
);
11248 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
11251 attr_name
= c_parser_attribute_any_word (parser
);
11254 c_parser_consume_token (parser
);
11255 attr
= build_tree_list (attr_name
, NULL_TREE
);
11258 c_parser_error (parser
, "expected identifier");
11260 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11262 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11266 /* Parse a __transaction_atomic or __transaction_relaxed statement
11269 transaction-statement:
11270 __transaction_atomic transaction-attribute[opt] compound-statement
11271 __transaction_relaxed compound-statement
11273 Note that the only valid attribute is: "outer".
11277 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
11279 unsigned int old_in
= parser
->in_transaction
;
11280 unsigned int this_in
= 1, new_in
;
11281 location_t loc
= c_parser_peek_token (parser
)->location
;
11284 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11285 || keyword
== RID_TRANSACTION_RELAXED
)
11286 && c_parser_next_token_is_keyword (parser
, keyword
));
11287 c_parser_consume_token (parser
);
11289 if (keyword
== RID_TRANSACTION_RELAXED
)
11290 this_in
|= TM_STMT_ATTR_RELAXED
;
11293 attrs
= c_parser_transaction_attributes (parser
);
11295 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
11298 /* Keep track if we're in the lexical scope of an outer transaction. */
11299 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
11301 parser
->in_transaction
= new_in
;
11302 stmt
= c_parser_compound_statement (parser
);
11303 parser
->in_transaction
= old_in
;
11306 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
11308 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11309 "%<__transaction_atomic%> without transactional memory support enabled"
11310 : "%<__transaction_relaxed %> "
11311 "without transactional memory support enabled"));
11316 /* Parse a __transaction_atomic or __transaction_relaxed expression
11319 transaction-expression:
11320 __transaction_atomic ( expression )
11321 __transaction_relaxed ( expression )
11324 static struct c_expr
11325 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
11328 unsigned int old_in
= parser
->in_transaction
;
11329 unsigned int this_in
= 1;
11330 location_t loc
= c_parser_peek_token (parser
)->location
;
11333 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
11334 || keyword
== RID_TRANSACTION_RELAXED
)
11335 && c_parser_next_token_is_keyword (parser
, keyword
));
11336 c_parser_consume_token (parser
);
11338 if (keyword
== RID_TRANSACTION_RELAXED
)
11339 this_in
|= TM_STMT_ATTR_RELAXED
;
11342 attrs
= c_parser_transaction_attributes (parser
);
11344 this_in
|= parse_tm_stmt_attr (attrs
, 0);
11347 parser
->in_transaction
= this_in
;
11348 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11350 tree expr
= c_parser_expression (parser
).value
;
11351 ret
.original_type
= TREE_TYPE (expr
);
11352 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
11353 if (this_in
& TM_STMT_ATTR_RELAXED
)
11354 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
11355 SET_EXPR_LOCATION (ret
.value
, loc
);
11356 ret
.original_code
= TRANSACTION_EXPR
;
11357 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
11366 ret
.value
= error_mark_node
;
11367 ret
.original_code
= ERROR_MARK
;
11368 ret
.original_type
= NULL
;
11370 parser
->in_transaction
= old_in
;
11373 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
11374 "%<__transaction_atomic%> without transactional memory support enabled"
11375 : "%<__transaction_relaxed %> "
11376 "without transactional memory support enabled"));
11381 /* Parse a __transaction_cancel statement (GCC Extension).
11383 transaction-cancel-statement:
11384 __transaction_cancel transaction-attribute[opt] ;
11386 Note that the only valid attribute is "outer".
11390 c_parser_transaction_cancel(c_parser
*parser
)
11392 location_t loc
= c_parser_peek_token (parser
)->location
;
11394 bool is_outer
= false;
11396 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
11397 c_parser_consume_token (parser
);
11399 attrs
= c_parser_transaction_attributes (parser
);
11401 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
11405 error_at (loc
, "%<__transaction_cancel%> without "
11406 "transactional memory support enabled");
11409 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
11411 error_at (loc
, "%<__transaction_cancel%> within a "
11412 "%<__transaction_relaxed%>");
11417 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
11418 && !is_tm_may_cancel_outer (current_function_decl
))
11420 error_at (loc
, "outer %<__transaction_cancel%> not "
11421 "within outer %<__transaction_atomic%>");
11422 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
11426 else if (parser
->in_transaction
== 0)
11428 error_at (loc
, "%<__transaction_cancel%> not within "
11429 "%<__transaction_atomic%>");
11433 return add_stmt (build_tm_abort_call (loc
, is_outer
));
11436 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
11439 /* Parse a single source file. */
11442 c_parse_file (void)
11444 /* Use local storage to begin. If the first token is a pragma, parse it.
11445 If it is #pragma GCC pch_preprocess, then this will load a PCH file
11446 which will cause garbage collection. */
11449 memset (&tparser
, 0, sizeof tparser
);
11450 the_parser
= &tparser
;
11452 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
11453 c_parser_pragma_pch_preprocess (&tparser
);
11455 the_parser
= ggc_alloc_c_parser ();
11456 *the_parser
= tparser
;
11458 /* Initialize EH, if we've been told to do so. */
11459 if (flag_exceptions
)
11460 using_eh_for_cleanups ();
11462 c_parser_translation_unit (the_parser
);
11466 /* This function parses Cilk Plus array notation. The starting index is
11467 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
11468 return value of this function is a tree_node called VALUE_TREE of type
11469 ARRAY_NOTATION_REF. */
11472 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
11475 c_token
*token
= NULL
;
11476 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
11477 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
11478 tree array_type_domain
= NULL_TREE
;
11480 if (array_value
== error_mark_node
)
11482 /* No need to continue. If either of these 2 were true, then an error
11483 must be emitted already. Thus, no need to emit them twice. */
11484 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11485 return error_mark_node
;
11488 array_type
= TREE_TYPE (array_value
);
11489 gcc_assert (array_type
);
11490 type
= TREE_TYPE (array_type
);
11491 token
= c_parser_peek_token (parser
);
11493 if (token
->type
== CPP_EOF
)
11495 c_parser_error (parser
, "expected %<:%> or numeral");
11498 else if (token
->type
== CPP_COLON
)
11500 if (!initial_index
)
11502 /* If we are here, then we have a case like this A[:]. */
11503 c_parser_consume_token (parser
);
11504 if (TREE_CODE (array_type
) == POINTER_TYPE
)
11506 error_at (loc
, "start-index and length fields necessary for "
11507 "using array notations in pointers");
11508 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11509 return error_mark_node
;
11511 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11513 error_at (loc
, "array notations cannot be used with function "
11515 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11516 return error_mark_node
;
11518 array_type_domain
= TYPE_DOMAIN (array_type
);
11520 if (!array_type_domain
)
11522 error_at (loc
, "start-index and length fields necessary for "
11523 "using array notations in dimensionless arrays");
11524 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11525 return error_mark_node
;
11528 start_index
= TYPE_MINVAL (array_type_domain
);
11529 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
11531 if (!TYPE_MAXVAL (array_type_domain
)
11532 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
11534 error_at (loc
, "start-index and length fields necessary for "
11535 "using array notations in variable-length arrays");
11536 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11537 return error_mark_node
;
11539 end_index
= TYPE_MAXVAL (array_type_domain
);
11540 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
11541 end_index
, integer_one_node
);
11542 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
11543 stride
= build_int_cst (integer_type_node
, 1);
11544 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
11546 else if (initial_index
!= error_mark_node
)
11548 /* If we are here, then there should be 2 possibilities:
11549 1. Array [EXPR : EXPR]
11550 2. Array [EXPR : EXPR : EXPR]
11552 start_index
= initial_index
;
11554 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
11556 error_at (loc
, "array notations cannot be used with function "
11558 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
11559 return error_mark_node
;
11561 c_parser_consume_token (parser
); /* consume the ':' */
11562 end_index
= c_parser_expression (parser
).value
;
11563 if (!end_index
|| end_index
== error_mark_node
)
11565 c_parser_skip_to_end_of_block_or_statement (parser
);
11566 return error_mark_node
;
11568 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
11570 c_parser_consume_token (parser
);
11571 stride
= c_parser_expression (parser
).value
;
11572 if (!stride
|| stride
== error_mark_node
)
11574 c_parser_skip_to_end_of_block_or_statement (parser
);
11575 return error_mark_node
;
11580 c_parser_error (parser
, "expected array notation expression");
11583 c_parser_error (parser
, "expected array notation expression");
11585 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
11587 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
11588 end_index
, stride
, type
);
11589 if (value_tree
!= error_mark_node
)
11590 SET_EXPR_LOCATION (value_tree
, loc
);
11594 #include "gt-c-c-parser.h"