1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2014 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 "stringpool.h"
45 #include "stor-layout.h"
47 #include "trans-mem.h"
48 #include "langhooks.h"
52 #include "c-family/c-pragma.h"
57 #include "c-family/c-common.h"
58 #include "c-family/c-objc.h"
66 /* Initialization routine for this file. */
71 /* The only initialization required is of the reserved word
77 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
78 the c_token structure. */
79 gcc_assert (RID_MAX
<= 255);
86 mask
|= D_ASM
| D_EXT
;
90 if (!c_dialect_objc ())
91 mask
|= D_OBJC
| D_CXX_OBJC
;
93 ridpointers
= ggc_alloc_cleared_vec_tree ((int) RID_MAX
);
94 for (i
= 0; i
< num_c_common_reswords
; i
++)
96 /* If a keyword is disabled, do not enter it into the table
97 and so create a canonical spelling that isn't a keyword. */
98 if (c_common_reswords
[i
].disable
& mask
)
101 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
103 id
= get_identifier (c_common_reswords
[i
].word
);
104 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
105 C_IS_RESERVED_WORD (id
) = 1;
110 id
= get_identifier (c_common_reswords
[i
].word
);
111 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
112 C_IS_RESERVED_WORD (id
) = 1;
113 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
117 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
118 and the C parser. Unlike the C++ lexer, the parser structure
119 stores the lexer information instead of using a separate structure.
120 Identifiers are separated into ordinary identifiers, type names,
121 keywords and some other Objective-C types of identifiers, and some
122 look-ahead is maintained.
124 ??? It might be a good idea to lex the whole file up front (as for
125 C++). It would then be possible to share more of the C and C++
126 lexer code, if desired. */
128 /* The following local token type is used. */
131 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
133 /* More information about the type of a CPP_NAME token. */
134 typedef enum c_id_kind
{
135 /* An ordinary identifier. */
137 /* An identifier declared as a typedef name. */
139 /* An identifier declared as an Objective-C class name. */
141 /* An address space identifier. */
143 /* Not an identifier. */
147 /* A single C token after string literal concatenation and conversion
148 of preprocessing tokens to tokens. */
149 typedef struct GTY (()) c_token
{
150 /* The kind of token. */
151 ENUM_BITFIELD (cpp_ttype
) type
: 8;
152 /* If this token is a CPP_NAME, this value indicates whether also
153 declared as some kind of type. Otherwise, it is C_ID_NONE. */
154 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
155 /* If this token is a keyword, this value indicates which keyword.
156 Otherwise, this value is RID_MAX. */
157 ENUM_BITFIELD (rid
) keyword
: 8;
158 /* If this token is a CPP_PRAGMA, this indicates the pragma that
159 was seen. Otherwise it is PRAGMA_NONE. */
160 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 8;
161 /* The location at which this token was found. */
163 /* The value associated with this token, if any. */
167 /* A parser structure recording information about the state and
168 context of parsing. Includes lexer information with up to two
169 tokens of look-ahead; more are not needed for C. */
170 typedef struct GTY(()) c_parser
{
171 /* The look-ahead tokens. */
172 c_token
* GTY((skip
)) tokens
;
173 /* Buffer for look-ahead tokens. */
174 c_token tokens_buf
[2];
175 /* How many look-ahead tokens are available (0, 1 or 2, or
176 more if parsing from pre-lexed tokens). */
177 unsigned int tokens_avail
;
178 /* True if a syntax error is being recovered from; false otherwise.
179 c_parser_error sets this flag. It should clear this flag when
180 enough tokens have been consumed to recover from the error. */
181 BOOL_BITFIELD error
: 1;
182 /* True if we're processing a pragma, and shouldn't automatically
183 consume CPP_PRAGMA_EOL. */
184 BOOL_BITFIELD in_pragma
: 1;
185 /* True if we're parsing the outermost block of an if statement. */
186 BOOL_BITFIELD in_if_block
: 1;
187 /* True if we want to lex an untranslated string. */
188 BOOL_BITFIELD lex_untranslated_string
: 1;
190 /* Objective-C specific parser/lexer information. */
192 /* True if we are in a context where the Objective-C "PQ" keywords
193 are considered keywords. */
194 BOOL_BITFIELD objc_pq_context
: 1;
195 /* True if we are parsing a (potential) Objective-C foreach
196 statement. This is set to true after we parsed 'for (' and while
197 we wait for 'in' or ';' to decide if it's a standard C for loop or an
198 Objective-C foreach loop. */
199 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
200 /* The following flag is needed to contextualize Objective-C lexical
201 analysis. In some cases (e.g., 'int NSObject;'), it is
202 undesirable to bind an identifier to an Objective-C class, even
203 if a class with that name exists. */
204 BOOL_BITFIELD objc_need_raw_identifier
: 1;
205 /* Nonzero if we're processing a __transaction statement. The value
206 is 1 | TM_STMT_ATTR_*. */
207 unsigned int in_transaction
: 4;
208 /* True if we are in a context where the Objective-C "Property attribute"
209 keywords are valid. */
210 BOOL_BITFIELD objc_property_attr_context
: 1;
212 /* Cilk Plus specific parser/lexer information. */
214 /* Buffer to hold all the tokens from parsing the vector attribute for the
215 SIMD-enabled functions (formerly known as elemental functions). */
216 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
220 /* The actual parser and external interface. ??? Does this need to be
221 garbage-collected? */
223 static GTY (()) c_parser
*the_parser
;
225 /* Read in and lex a single token, storing it in *TOKEN. */
228 c_lex_one_token (c_parser
*parser
, c_token
*token
)
230 timevar_push (TV_LEX
);
232 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
,
233 (parser
->lex_untranslated_string
234 ? C_LEX_STRING_NO_TRANSLATE
: 0));
235 token
->id_kind
= C_ID_NONE
;
236 token
->keyword
= RID_MAX
;
237 token
->pragma_kind
= PRAGMA_NONE
;
245 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
246 if (c_dialect_objc ())
247 parser
->objc_need_raw_identifier
= false;
249 if (C_IS_RESERVED_WORD (token
->value
))
251 enum rid rid_code
= C_RID_CODE (token
->value
);
253 if (rid_code
== RID_CXX_COMPAT_WARN
)
255 warning_at (token
->location
,
257 "identifier %qE conflicts with C++ keyword",
260 else if (rid_code
>= RID_FIRST_ADDR_SPACE
261 && rid_code
<= RID_LAST_ADDR_SPACE
)
263 token
->id_kind
= C_ID_ADDRSPACE
;
264 token
->keyword
= rid_code
;
267 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
269 /* We found an Objective-C "pq" keyword (in, out,
270 inout, bycopy, byref, oneway). They need special
271 care because the interpretation depends on the
273 if (parser
->objc_pq_context
)
275 token
->type
= CPP_KEYWORD
;
276 token
->keyword
= rid_code
;
279 else if (parser
->objc_could_be_foreach_context
280 && rid_code
== RID_IN
)
282 /* We are in Objective-C, inside a (potential)
283 foreach context (which means after having
284 parsed 'for (', but before having parsed ';'),
285 and we found 'in'. We consider it the keyword
286 which terminates the declaration at the
287 beginning of a foreach-statement. Note that
288 this means you can't use 'in' for anything else
289 in that context; in particular, in Objective-C
290 you can't use 'in' as the name of the running
291 variable in a C for loop. We could potentially
292 try to add code here to disambiguate, but it
293 seems a reasonable limitation. */
294 token
->type
= CPP_KEYWORD
;
295 token
->keyword
= rid_code
;
298 /* Else, "pq" keywords outside of the "pq" context are
299 not keywords, and we fall through to the code for
302 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
304 /* We found an Objective-C "property attribute"
305 keyword (getter, setter, readonly, etc). These are
306 only valid in the property context. */
307 if (parser
->objc_property_attr_context
)
309 token
->type
= CPP_KEYWORD
;
310 token
->keyword
= rid_code
;
313 /* Else they are not special keywords.
316 else if (c_dialect_objc ()
317 && (OBJC_IS_AT_KEYWORD (rid_code
)
318 || OBJC_IS_CXX_KEYWORD (rid_code
)))
320 /* We found one of the Objective-C "@" keywords (defs,
321 selector, synchronized, etc) or one of the
322 Objective-C "cxx" keywords (class, private,
323 protected, public, try, catch, throw) without a
324 preceding '@' sign. Do nothing and fall through to
325 the code for normal tokens (in C++ we would still
326 consider the CXX ones keywords, but not in C). */
331 token
->type
= CPP_KEYWORD
;
332 token
->keyword
= rid_code
;
337 decl
= lookup_name (token
->value
);
340 if (TREE_CODE (decl
) == TYPE_DECL
)
342 token
->id_kind
= C_ID_TYPENAME
;
346 else if (c_dialect_objc ())
348 tree objc_interface_decl
= objc_is_class_name (token
->value
);
349 /* Objective-C class names are in the same namespace as
350 variables and typedefs, and hence are shadowed by local
352 if (objc_interface_decl
353 && (!objc_force_identifier
|| global_bindings_p ()))
355 token
->value
= objc_interface_decl
;
356 token
->id_kind
= C_ID_CLASSNAME
;
360 token
->id_kind
= C_ID_ID
;
364 /* This only happens in Objective-C; it must be a keyword. */
365 token
->type
= CPP_KEYWORD
;
366 switch (C_RID_CODE (token
->value
))
368 /* Replace 'class' with '@class', 'private' with '@private',
369 etc. This prevents confusion with the C++ keyword
370 'class', and makes the tokens consistent with other
371 Objective-C 'AT' keywords. For example '@class' is
372 reported as RID_AT_CLASS which is consistent with
373 '@synchronized', which is reported as
376 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
377 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
378 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
379 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
380 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
381 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
382 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
383 default: token
->keyword
= C_RID_CODE (token
->value
);
388 case CPP_CLOSE_PAREN
:
390 /* These tokens may affect the interpretation of any identifiers
391 following, if doing Objective-C. */
392 if (c_dialect_objc ())
393 parser
->objc_need_raw_identifier
= false;
396 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
397 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
403 timevar_pop (TV_LEX
);
406 /* Return a pointer to the next token from PARSER, reading it in if
409 static inline c_token
*
410 c_parser_peek_token (c_parser
*parser
)
412 if (parser
->tokens_avail
== 0)
414 c_lex_one_token (parser
, &parser
->tokens
[0]);
415 parser
->tokens_avail
= 1;
417 return &parser
->tokens
[0];
420 /* Return true if the next token from PARSER has the indicated
424 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
426 return c_parser_peek_token (parser
)->type
== type
;
429 /* Return true if the next token from PARSER does not have the
433 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
435 return !c_parser_next_token_is (parser
, type
);
438 /* Return true if the next token from PARSER is the indicated
442 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
444 return c_parser_peek_token (parser
)->keyword
== keyword
;
447 /* Return a pointer to the next-but-one token from PARSER, reading it
448 in if necessary. The next token is already read in. */
451 c_parser_peek_2nd_token (c_parser
*parser
)
453 if (parser
->tokens_avail
>= 2)
454 return &parser
->tokens
[1];
455 gcc_assert (parser
->tokens_avail
== 1);
456 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
457 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
458 c_lex_one_token (parser
, &parser
->tokens
[1]);
459 parser
->tokens_avail
= 2;
460 return &parser
->tokens
[1];
463 /* Return true if TOKEN can start a type name,
466 c_token_starts_typename (c_token
*token
)
471 switch (token
->id_kind
)
480 gcc_assert (c_dialect_objc ());
486 switch (token
->keyword
)
521 if (c_dialect_objc ())
529 enum c_lookahead_kind
{
530 /* Always treat unknown identifiers as typenames. */
533 /* Could be parsing a nonabstract declarator. Only treat an identifier
534 as a typename if followed by another identifier or a star. */
535 cla_nonabstract_decl
,
537 /* Never treat identifiers as typenames. */
541 /* Return true if the next token from PARSER can start a type name,
542 false otherwise. LA specifies how to do lookahead in order to
543 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
546 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
548 c_token
*token
= c_parser_peek_token (parser
);
549 if (c_token_starts_typename (token
))
552 /* Try a bit harder to detect an unknown typename. */
553 if (la
!= cla_prefer_id
554 && token
->type
== CPP_NAME
555 && token
->id_kind
== C_ID_ID
557 /* Do not try too hard when we could have "object in array". */
558 && !parser
->objc_could_be_foreach_context
560 && (la
== cla_prefer_type
561 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
562 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
564 /* Only unknown identifiers. */
565 && !lookup_name (token
->value
))
571 /* Return true if TOKEN is a type qualifier, false otherwise. */
573 c_token_is_qualifier (c_token
*token
)
578 switch (token
->id_kind
)
586 switch (token
->keyword
)
604 /* Return true if the next token from PARSER is a type qualifier,
607 c_parser_next_token_is_qualifier (c_parser
*parser
)
609 c_token
*token
= c_parser_peek_token (parser
);
610 return c_token_is_qualifier (token
);
613 /* Return true if TOKEN can start declaration specifiers, false
616 c_token_starts_declspecs (c_token
*token
)
621 switch (token
->id_kind
)
630 gcc_assert (c_dialect_objc ());
636 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
!= &parser
->tokens_buf
[0])
762 else if (parser
->tokens_avail
== 2)
763 parser
->tokens
[0] = parser
->tokens
[1];
764 parser
->tokens_avail
--;
767 /* Expect the current token to be a #pragma. Consume it and remember
768 that we've begun parsing a pragma. */
771 c_parser_consume_pragma (c_parser
*parser
)
773 gcc_assert (!parser
->in_pragma
);
774 gcc_assert (parser
->tokens_avail
>= 1);
775 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
776 if (parser
->tokens
!= &parser
->tokens_buf
[0])
778 else if (parser
->tokens_avail
== 2)
779 parser
->tokens
[0] = parser
->tokens
[1];
780 parser
->tokens_avail
--;
781 parser
->in_pragma
= true;
784 /* Update the global input_location from TOKEN. */
786 c_parser_set_source_position_from_token (c_token
*token
)
788 if (token
->type
!= CPP_EOF
)
790 input_location
= token
->location
;
794 /* Issue a diagnostic of the form
795 FILE:LINE: MESSAGE before TOKEN
796 where TOKEN is the next token in the input stream of PARSER.
797 MESSAGE (specified by the caller) is usually of the form "expected
800 Do not issue a diagnostic if still recovering from an error.
802 ??? This is taken from the C++ parser, but building up messages in
803 this way is not i18n-friendly and some other approach should be
807 c_parser_error (c_parser
*parser
, const char *gmsgid
)
809 c_token
*token
= c_parser_peek_token (parser
);
812 parser
->error
= true;
815 /* This diagnostic makes more sense if it is tagged to the line of
816 the token we just peeked at. */
817 c_parser_set_source_position_from_token (token
);
818 c_parse_error (gmsgid
,
819 /* Because c_parse_error does not understand
820 CPP_KEYWORD, keywords are treated like
822 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
823 /* ??? The C parser does not save the cpp flags of a
824 token, we need to pass 0 here and we will not get
825 the source spelling of some tokens but rather the
826 canonical spelling. */
827 token
->value
, /*flags=*/0);
830 /* If the next token is of the indicated TYPE, consume it. Otherwise,
831 issue the error MSGID. If MSGID is NULL then a message has already
832 been produced and no message will be produced this time. Returns
833 true if found, false otherwise. */
836 c_parser_require (c_parser
*parser
,
840 if (c_parser_next_token_is (parser
, type
))
842 c_parser_consume_token (parser
);
847 c_parser_error (parser
, msgid
);
852 /* If the next token is the indicated keyword, consume it. Otherwise,
853 issue the error MSGID. Returns true if found, false otherwise. */
856 c_parser_require_keyword (c_parser
*parser
,
860 if (c_parser_next_token_is_keyword (parser
, keyword
))
862 c_parser_consume_token (parser
);
867 c_parser_error (parser
, msgid
);
872 /* Like c_parser_require, except that tokens will be skipped until the
873 desired token is found. An error message is still produced if the
874 next token is not as expected. If MSGID is NULL then a message has
875 already been produced and no message will be produced this
879 c_parser_skip_until_found (c_parser
*parser
,
883 unsigned nesting_depth
= 0;
885 if (c_parser_require (parser
, type
, msgid
))
888 /* Skip tokens until the desired token is found. */
891 /* Peek at the next token. */
892 c_token
*token
= c_parser_peek_token (parser
);
893 /* If we've reached the token we want, consume it and stop. */
894 if (token
->type
== type
&& !nesting_depth
)
896 c_parser_consume_token (parser
);
900 /* If we've run out of tokens, stop. */
901 if (token
->type
== CPP_EOF
)
903 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
905 if (token
->type
== CPP_OPEN_BRACE
906 || token
->type
== CPP_OPEN_PAREN
907 || token
->type
== CPP_OPEN_SQUARE
)
909 else if (token
->type
== CPP_CLOSE_BRACE
910 || token
->type
== CPP_CLOSE_PAREN
911 || token
->type
== CPP_CLOSE_SQUARE
)
913 if (nesting_depth
-- == 0)
916 /* Consume this token. */
917 c_parser_consume_token (parser
);
919 parser
->error
= false;
922 /* Skip tokens until the end of a parameter is found, but do not
923 consume the comma, semicolon or closing delimiter. */
926 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
928 unsigned nesting_depth
= 0;
932 c_token
*token
= c_parser_peek_token (parser
);
933 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
936 /* If we've run out of tokens, stop. */
937 if (token
->type
== CPP_EOF
)
939 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
941 if (token
->type
== CPP_OPEN_BRACE
942 || token
->type
== CPP_OPEN_PAREN
943 || token
->type
== CPP_OPEN_SQUARE
)
945 else if (token
->type
== CPP_CLOSE_BRACE
946 || token
->type
== CPP_CLOSE_PAREN
947 || token
->type
== CPP_CLOSE_SQUARE
)
949 if (nesting_depth
-- == 0)
952 /* Consume this token. */
953 c_parser_consume_token (parser
);
955 parser
->error
= false;
958 /* Expect to be at the end of the pragma directive and consume an
959 end of line marker. */
962 c_parser_skip_to_pragma_eol (c_parser
*parser
)
964 gcc_assert (parser
->in_pragma
);
965 parser
->in_pragma
= false;
967 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
970 c_token
*token
= c_parser_peek_token (parser
);
971 if (token
->type
== CPP_EOF
)
973 if (token
->type
== CPP_PRAGMA_EOL
)
975 c_parser_consume_token (parser
);
978 c_parser_consume_token (parser
);
981 parser
->error
= false;
984 /* Skip tokens until we have consumed an entire block, or until we
985 have consumed a non-nested ';'. */
988 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
990 unsigned nesting_depth
= 0;
991 bool save_error
= parser
->error
;
997 /* Peek at the next token. */
998 token
= c_parser_peek_token (parser
);
1000 switch (token
->type
)
1005 case CPP_PRAGMA_EOL
:
1006 if (parser
->in_pragma
)
1011 /* If the next token is a ';', we have reached the
1012 end of the statement. */
1015 /* Consume the ';'. */
1016 c_parser_consume_token (parser
);
1021 case CPP_CLOSE_BRACE
:
1022 /* If the next token is a non-nested '}', then we have
1023 reached the end of the current block. */
1024 if (nesting_depth
== 0 || --nesting_depth
== 0)
1026 c_parser_consume_token (parser
);
1031 case CPP_OPEN_BRACE
:
1032 /* If it the next token is a '{', then we are entering a new
1033 block. Consume the entire block. */
1038 /* If we see a pragma, consume the whole thing at once. We
1039 have some safeguards against consuming pragmas willy-nilly.
1040 Normally, we'd expect to be here with parser->error set,
1041 which disables these safeguards. But it's possible to get
1042 here for secondary error recovery, after parser->error has
1044 c_parser_consume_pragma (parser
);
1045 c_parser_skip_to_pragma_eol (parser
);
1046 parser
->error
= save_error
;
1053 c_parser_consume_token (parser
);
1057 parser
->error
= false;
1060 /* CPP's options (initialized by c-opts.c). */
1061 extern cpp_options
*cpp_opts
;
1063 /* Save the warning flags which are controlled by __extension__. */
1066 disable_extension_diagnostics (void)
1069 | (warn_pointer_arith
<< 1)
1070 | (warn_traditional
<< 2)
1072 | (warn_long_long
<< 4)
1073 | (warn_cxx_compat
<< 5)
1074 | (warn_overlength_strings
<< 6));
1075 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1076 warn_pointer_arith
= 0;
1077 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1079 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1080 warn_cxx_compat
= 0;
1081 warn_overlength_strings
= 0;
1085 /* Restore the warning flags which are controlled by __extension__.
1086 FLAGS is the return value from disable_extension_diagnostics. */
1089 restore_extension_diagnostics (int flags
)
1091 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1092 warn_pointer_arith
= (flags
>> 1) & 1;
1093 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1094 flag_iso
= (flags
>> 3) & 1;
1095 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1096 warn_cxx_compat
= (flags
>> 5) & 1;
1097 warn_overlength_strings
= (flags
>> 6) & 1;
1100 /* Possibly kinds of declarator to parse. */
1101 typedef enum c_dtr_syn
{
1102 /* A normal declarator with an identifier. */
1104 /* An abstract declarator (maybe empty). */
1106 /* A parameter declarator: may be either, but after a type name does
1107 not redeclare a typedef name as an identifier if it can
1108 alternatively be interpreted as a typedef name; see DR#009,
1109 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
1110 following DR#249. For example, given a typedef T, "int T" and
1111 "int *T" are valid parameter declarations redeclaring T, while
1112 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
1113 abstract declarators rather than involving redundant parentheses;
1114 the same applies with attributes inside the parentheses before
1119 /* The binary operation precedence levels, where 0 is a dummy lowest level
1120 used for the bottom of the stack. */
1121 enum c_parser_prec
{
1136 static void c_parser_external_declaration (c_parser
*);
1137 static void c_parser_asm_definition (c_parser
*);
1138 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1139 bool, bool, tree
*, vec
<c_token
>);
1140 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1141 static void c_parser_static_assert_declaration (c_parser
*);
1142 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
1143 bool, bool, bool, enum c_lookahead_kind
);
1144 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1145 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1146 static tree
c_parser_struct_declaration (c_parser
*);
1147 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1148 static tree
c_parser_alignas_specifier (c_parser
*);
1149 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
1151 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1153 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1155 struct c_declarator
*);
1156 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1157 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1159 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1160 static tree
c_parser_simple_asm_expr (c_parser
*);
1161 static tree
c_parser_attributes (c_parser
*);
1162 static struct c_type_name
*c_parser_type_name (c_parser
*);
1163 static struct c_expr
c_parser_initializer (c_parser
*);
1164 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1165 static void c_parser_initelt (c_parser
*, struct obstack
*);
1166 static void c_parser_initval (c_parser
*, struct c_expr
*,
1168 static tree
c_parser_compound_statement (c_parser
*);
1169 static void c_parser_compound_statement_nostart (c_parser
*);
1170 static void c_parser_label (c_parser
*);
1171 static void c_parser_statement (c_parser
*);
1172 static void c_parser_statement_after_labels (c_parser
*);
1173 static void c_parser_if_statement (c_parser
*);
1174 static void c_parser_switch_statement (c_parser
*);
1175 static void c_parser_while_statement (c_parser
*, bool);
1176 static void c_parser_do_statement (c_parser
*, bool);
1177 static void c_parser_for_statement (c_parser
*, bool);
1178 static tree
c_parser_asm_statement (c_parser
*);
1179 static tree
c_parser_asm_operands (c_parser
*);
1180 static tree
c_parser_asm_goto_operands (c_parser
*);
1181 static tree
c_parser_asm_clobbers (c_parser
*);
1182 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1184 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1185 struct c_expr
*, tree
);
1186 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1188 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1189 static struct c_expr
c_parser_unary_expression (c_parser
*);
1190 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1191 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1192 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1193 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1194 struct c_type_name
*,
1196 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1199 static tree
c_parser_transaction (c_parser
*, enum rid
);
1200 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1201 static tree
c_parser_transaction_cancel (c_parser
*);
1202 static struct c_expr
c_parser_expression (c_parser
*);
1203 static struct c_expr
c_parser_expression_conv (c_parser
*);
1204 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1205 vec
<tree
, va_gc
> **, location_t
*,
1206 tree
*, vec
<location_t
> *);
1207 static void c_parser_omp_construct (c_parser
*);
1208 static void c_parser_omp_threadprivate (c_parser
*);
1209 static void c_parser_omp_barrier (c_parser
*);
1210 static void c_parser_omp_flush (c_parser
*);
1211 static void c_parser_omp_taskwait (c_parser
*);
1212 static void c_parser_omp_taskyield (c_parser
*);
1213 static void c_parser_omp_cancel (c_parser
*);
1214 static void c_parser_omp_cancellation_point (c_parser
*);
1216 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1217 pragma_stmt
, pragma_compound
};
1218 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1219 static bool c_parser_omp_target (c_parser
*, enum pragma_context
);
1220 static void c_parser_omp_end_declare_target (c_parser
*);
1221 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1223 /* These Objective-C parser functions are only ever called when
1224 compiling Objective-C. */
1225 static void c_parser_objc_class_definition (c_parser
*, tree
);
1226 static void c_parser_objc_class_instance_variables (c_parser
*);
1227 static void c_parser_objc_class_declaration (c_parser
*);
1228 static void c_parser_objc_alias_declaration (c_parser
*);
1229 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1230 static bool c_parser_objc_method_type (c_parser
*);
1231 static void c_parser_objc_method_definition (c_parser
*);
1232 static void c_parser_objc_methodprotolist (c_parser
*);
1233 static void c_parser_objc_methodproto (c_parser
*);
1234 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1235 static tree
c_parser_objc_type_name (c_parser
*);
1236 static tree
c_parser_objc_protocol_refs (c_parser
*);
1237 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1238 static void c_parser_objc_synchronized_statement (c_parser
*);
1239 static tree
c_parser_objc_selector (c_parser
*);
1240 static tree
c_parser_objc_selector_arg (c_parser
*);
1241 static tree
c_parser_objc_receiver (c_parser
*);
1242 static tree
c_parser_objc_message_args (c_parser
*);
1243 static tree
c_parser_objc_keywordexpr (c_parser
*);
1244 static void c_parser_objc_at_property_declaration (c_parser
*);
1245 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1246 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1247 static bool c_parser_objc_diagnose_bad_element_prefix
1248 (c_parser
*, struct c_declspecs
*);
1250 /* Cilk Plus supporting routines. */
1251 static void c_parser_cilk_simd (c_parser
*);
1252 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1253 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1254 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1256 /* Parse a translation unit (C90 6.7, C99 6.9).
1259 external-declarations
1261 external-declarations:
1262 external-declaration
1263 external-declarations external-declaration
1272 c_parser_translation_unit (c_parser
*parser
)
1274 if (c_parser_next_token_is (parser
, CPP_EOF
))
1276 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1277 "ISO C forbids an empty translation unit");
1281 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1282 mark_valid_location_for_stdc_pragma (false);
1286 c_parser_external_declaration (parser
);
1287 obstack_free (&parser_obstack
, obstack_position
);
1289 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1293 /* Parse an external declaration (C90 6.7, C99 6.9).
1295 external-declaration:
1301 external-declaration:
1304 __extension__ external-declaration
1308 external-declaration:
1309 objc-class-definition
1310 objc-class-declaration
1311 objc-alias-declaration
1312 objc-protocol-definition
1313 objc-method-definition
1318 c_parser_external_declaration (c_parser
*parser
)
1321 switch (c_parser_peek_token (parser
)->type
)
1324 switch (c_parser_peek_token (parser
)->keyword
)
1327 ext
= disable_extension_diagnostics ();
1328 c_parser_consume_token (parser
);
1329 c_parser_external_declaration (parser
);
1330 restore_extension_diagnostics (ext
);
1333 c_parser_asm_definition (parser
);
1335 case RID_AT_INTERFACE
:
1336 case RID_AT_IMPLEMENTATION
:
1337 gcc_assert (c_dialect_objc ());
1338 c_parser_objc_class_definition (parser
, NULL_TREE
);
1341 gcc_assert (c_dialect_objc ());
1342 c_parser_objc_class_declaration (parser
);
1345 gcc_assert (c_dialect_objc ());
1346 c_parser_objc_alias_declaration (parser
);
1348 case RID_AT_PROTOCOL
:
1349 gcc_assert (c_dialect_objc ());
1350 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1352 case RID_AT_PROPERTY
:
1353 gcc_assert (c_dialect_objc ());
1354 c_parser_objc_at_property_declaration (parser
);
1356 case RID_AT_SYNTHESIZE
:
1357 gcc_assert (c_dialect_objc ());
1358 c_parser_objc_at_synthesize_declaration (parser
);
1360 case RID_AT_DYNAMIC
:
1361 gcc_assert (c_dialect_objc ());
1362 c_parser_objc_at_dynamic_declaration (parser
);
1365 gcc_assert (c_dialect_objc ());
1366 c_parser_consume_token (parser
);
1367 objc_finish_implementation ();
1374 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1375 "ISO C does not allow extra %<;%> outside of a function");
1376 c_parser_consume_token (parser
);
1379 mark_valid_location_for_stdc_pragma (true);
1380 c_parser_pragma (parser
, pragma_external
);
1381 mark_valid_location_for_stdc_pragma (false);
1385 if (c_dialect_objc ())
1387 c_parser_objc_method_definition (parser
);
1390 /* Else fall through, and yield a syntax error trying to parse
1391 as a declaration or function definition. */
1394 /* A declaration or a function definition (or, in Objective-C,
1395 an @interface or @protocol with prefix attributes). We can
1396 only tell which after parsing the declaration specifiers, if
1397 any, and the first declarator. */
1398 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1404 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1406 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1407 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1408 accepted; otherwise (old-style parameter declarations) only other
1409 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1410 assertion is accepted; otherwise (old-style parameter declarations)
1411 it is not. If NESTED is true, we are inside a function or parsing
1412 old-style parameter declarations; any functions encountered are
1413 nested functions and declaration specifiers are required; otherwise
1414 we are at top level and functions are normal functions and
1415 declaration specifiers may be optional. If EMPTY_OK is true, empty
1416 declarations are OK (subject to all other constraints); otherwise
1417 (old-style parameter declarations) they are diagnosed. If
1418 START_ATTR_OK is true, the declaration specifiers may start with
1419 attributes; otherwise they may not.
1420 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1421 declaration when parsing an Objective-C foreach statement.
1424 declaration-specifiers init-declarator-list[opt] ;
1425 static_assert-declaration
1427 function-definition:
1428 declaration-specifiers[opt] declarator declaration-list[opt]
1433 declaration-list declaration
1435 init-declarator-list:
1437 init-declarator-list , init-declarator
1440 declarator simple-asm-expr[opt] attributes[opt]
1441 declarator simple-asm-expr[opt] attributes[opt] = initializer
1445 nested-function-definition:
1446 declaration-specifiers declarator declaration-list[opt]
1450 attributes objc-class-definition
1451 attributes objc-category-definition
1452 attributes objc-protocol-definition
1454 The simple-asm-expr and attributes are GNU extensions.
1456 This function does not handle __extension__; that is handled in its
1457 callers. ??? Following the old parser, __extension__ may start
1458 external declarations, declarations in functions and declarations
1459 at the start of "for" loops, but not old-style parameter
1462 C99 requires declaration specifiers in a function definition; the
1463 absence is diagnosed through the diagnosis of implicit int. In GNU
1464 C we also allow but diagnose declarations without declaration
1465 specifiers, but only at top level (elsewhere they conflict with
1468 In Objective-C, declarations of the looping variable in a foreach
1469 statement are exceptionally terminated by 'in' (for example, 'for
1470 (NSObject *object in array) { ... }').
1475 threadprivate-directive */
1478 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1479 bool static_assert_ok
, bool empty_ok
,
1480 bool nested
, bool start_attr_ok
,
1481 tree
*objc_foreach_object_declaration
,
1482 vec
<c_token
> omp_declare_simd_clauses
)
1484 struct c_declspecs
*specs
;
1486 tree all_prefix_attrs
;
1487 bool diagnosed_no_specs
= false;
1488 location_t here
= c_parser_peek_token (parser
)->location
;
1490 if (static_assert_ok
1491 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1493 c_parser_static_assert_declaration (parser
);
1496 specs
= build_null_declspecs ();
1498 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1499 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1500 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1501 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1502 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1503 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1505 error_at (here
, "unknown type name %qE",
1506 c_parser_peek_token (parser
)->value
);
1508 /* Parse declspecs normally to get a correct pointer type, but avoid
1509 a further "fails to be a type name" error. Refuse nested functions
1510 since it is not how the user likely wants us to recover. */
1511 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1512 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1513 c_parser_peek_token (parser
)->value
= error_mark_node
;
1517 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1518 true, true, cla_nonabstract_decl
);
1521 c_parser_skip_to_end_of_block_or_statement (parser
);
1524 if (nested
&& !specs
->declspecs_seen_p
)
1526 c_parser_error (parser
, "expected declaration specifiers");
1527 c_parser_skip_to_end_of_block_or_statement (parser
);
1530 finish_declspecs (specs
);
1531 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1532 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1535 error_at (here
, "%<__auto_type%> in empty declaration");
1540 shadow_tag_warned (specs
, 1);
1541 pedwarn (here
, 0, "empty declaration");
1543 c_parser_consume_token (parser
);
1547 /* Provide better error recovery. Note that a type name here is usually
1548 better diagnosed as a redeclaration. */
1550 && specs
->typespec_kind
== ctsk_tagdef
1551 && c_parser_next_token_starts_declspecs (parser
)
1552 && !c_parser_next_token_is (parser
, CPP_NAME
))
1554 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1555 parser
->error
= false;
1556 shadow_tag_warned (specs
, 1);
1559 else if (c_dialect_objc () && !auto_type_p
)
1561 /* Prefix attributes are an error on method decls. */
1562 switch (c_parser_peek_token (parser
)->type
)
1566 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1570 warning_at (c_parser_peek_token (parser
)->location
,
1572 "prefix attributes are ignored for methods");
1573 specs
->attrs
= NULL_TREE
;
1576 c_parser_objc_method_definition (parser
);
1578 c_parser_objc_methodproto (parser
);
1584 /* This is where we parse 'attributes @interface ...',
1585 'attributes @implementation ...', 'attributes @protocol ...'
1586 (where attributes could be, for example, __attribute__
1589 switch (c_parser_peek_token (parser
)->keyword
)
1591 case RID_AT_INTERFACE
:
1593 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1595 c_parser_objc_class_definition (parser
, specs
->attrs
);
1599 case RID_AT_IMPLEMENTATION
:
1601 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1605 warning_at (c_parser_peek_token (parser
)->location
,
1607 "prefix attributes are ignored for implementations");
1608 specs
->attrs
= NULL_TREE
;
1610 c_parser_objc_class_definition (parser
, NULL_TREE
);
1614 case RID_AT_PROTOCOL
:
1616 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1618 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1625 case RID_AT_PROPERTY
:
1628 c_parser_error (parser
, "unexpected attribute");
1629 specs
->attrs
= NULL
;
1637 pending_xref_error ();
1638 prefix_attrs
= specs
->attrs
;
1639 all_prefix_attrs
= prefix_attrs
;
1640 specs
->attrs
= NULL_TREE
;
1643 struct c_declarator
*declarator
;
1647 /* Declaring either one or more declarators (in which case we
1648 should diagnose if there were no declaration specifiers) or a
1649 function definition (in which case the diagnostic for
1650 implicit int suffices). */
1651 declarator
= c_parser_declarator (parser
,
1652 specs
->typespec_kind
!= ctsk_none
,
1653 C_DTR_NORMAL
, &dummy
);
1654 if (declarator
== NULL
)
1656 if (omp_declare_simd_clauses
.exists ()
1657 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1658 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1659 omp_declare_simd_clauses
);
1660 c_parser_skip_to_end_of_block_or_statement (parser
);
1663 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1666 "%<__auto_type%> requires a plain identifier"
1668 c_parser_skip_to_end_of_block_or_statement (parser
);
1671 if (c_parser_next_token_is (parser
, CPP_EQ
)
1672 || c_parser_next_token_is (parser
, CPP_COMMA
)
1673 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1674 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1675 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1676 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1678 tree asm_name
= NULL_TREE
;
1679 tree postfix_attrs
= NULL_TREE
;
1680 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1682 diagnosed_no_specs
= true;
1683 pedwarn (here
, 0, "data definition has no type or storage class");
1685 /* Having seen a data definition, there cannot now be a
1686 function definition. */
1688 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1689 asm_name
= c_parser_simple_asm_expr (parser
);
1690 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1691 postfix_attrs
= c_parser_attributes (parser
);
1692 if (c_parser_next_token_is (parser
, CPP_EQ
))
1696 location_t init_loc
;
1697 c_parser_consume_token (parser
);
1700 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1701 init_loc
= c_parser_peek_token (parser
)->location
;
1702 init
= c_parser_expr_no_commas (parser
, NULL
);
1703 if (TREE_CODE (init
.value
) == COMPONENT_REF
1704 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1706 "%<__auto_type%> used with a bit-field"
1708 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1709 tree init_type
= TREE_TYPE (init
.value
);
1710 /* As with typeof, remove _Atomic and const
1711 qualifiers from atomic types. */
1712 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1714 = c_build_qualified_type (init_type
,
1715 (TYPE_QUALS (init_type
)
1716 & ~(TYPE_QUAL_ATOMIC
1717 | TYPE_QUAL_CONST
)));
1718 bool vm_type
= variably_modified_type_p (init_type
,
1721 init
.value
= c_save_expr (init
.value
);
1723 specs
->typespec_kind
= ctsk_typeof
;
1724 specs
->locations
[cdw_typedef
] = init_loc
;
1725 specs
->typedef_p
= true;
1726 specs
->type
= init_type
;
1729 bool maybe_const
= true;
1730 tree type_expr
= c_fully_fold (init
.value
, false,
1732 specs
->expr_const_operands
&= maybe_const
;
1734 specs
->expr
= build2 (COMPOUND_EXPR
,
1735 TREE_TYPE (type_expr
),
1736 specs
->expr
, type_expr
);
1738 specs
->expr
= type_expr
;
1740 d
= start_decl (declarator
, specs
, true,
1741 chainon (postfix_attrs
, all_prefix_attrs
));
1743 d
= error_mark_node
;
1744 if (omp_declare_simd_clauses
.exists ()
1745 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1746 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1747 omp_declare_simd_clauses
);
1751 /* The declaration of the variable is in effect while
1752 its initializer is parsed. */
1753 d
= start_decl (declarator
, specs
, true,
1754 chainon (postfix_attrs
, all_prefix_attrs
));
1756 d
= error_mark_node
;
1757 if (omp_declare_simd_clauses
.exists ()
1758 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1759 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1760 omp_declare_simd_clauses
);
1761 start_init (d
, asm_name
, global_bindings_p ());
1762 init_loc
= c_parser_peek_token (parser
)->location
;
1763 init
= c_parser_initializer (parser
);
1766 if (d
!= error_mark_node
)
1768 maybe_warn_string_init (TREE_TYPE (d
), init
);
1769 finish_decl (d
, init_loc
, init
.value
,
1770 init
.original_type
, asm_name
);
1778 "%<__auto_type%> requires an initialized "
1779 "data declaration");
1780 c_parser_skip_to_end_of_block_or_statement (parser
);
1783 tree d
= start_decl (declarator
, specs
, false,
1784 chainon (postfix_attrs
,
1786 if (omp_declare_simd_clauses
.exists ()
1787 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1789 tree parms
= NULL_TREE
;
1790 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1792 struct c_declarator
*ce
= declarator
;
1794 if (ce
->kind
== cdk_function
)
1796 parms
= ce
->u
.arg_info
->parms
;
1800 ce
= ce
->declarator
;
1803 temp_store_parm_decls (d
, parms
);
1804 c_finish_omp_declare_simd (parser
, d
, parms
,
1805 omp_declare_simd_clauses
);
1807 temp_pop_parm_decls ();
1810 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1811 NULL_TREE
, asm_name
);
1813 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1816 *objc_foreach_object_declaration
= d
;
1818 *objc_foreach_object_declaration
= error_mark_node
;
1821 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1826 "%<__auto_type%> may only be used with"
1827 " a single declarator");
1828 c_parser_skip_to_end_of_block_or_statement (parser
);
1831 c_parser_consume_token (parser
);
1832 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1833 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1836 all_prefix_attrs
= prefix_attrs
;
1839 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1841 c_parser_consume_token (parser
);
1844 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1846 /* This can only happen in Objective-C: we found the
1847 'in' that terminates the declaration inside an
1848 Objective-C foreach statement. Do not consume the
1849 token, so that the caller can use it to determine
1850 that this indeed is a foreach context. */
1855 c_parser_error (parser
, "expected %<,%> or %<;%>");
1856 c_parser_skip_to_end_of_block_or_statement (parser
);
1860 else if (auto_type_p
)
1863 "%<__auto_type%> requires an initialized data declaration");
1864 c_parser_skip_to_end_of_block_or_statement (parser
);
1869 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1870 "%<asm%> or %<__attribute__%>");
1871 c_parser_skip_to_end_of_block_or_statement (parser
);
1874 /* Function definition (nested or otherwise). */
1877 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1878 c_push_function_context ();
1880 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1882 /* This can appear in many cases looking nothing like a
1883 function definition, so we don't give a more specific
1884 error suggesting there was one. */
1885 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1886 "or %<__attribute__%>");
1888 c_pop_function_context ();
1892 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1893 tv
= TV_PARSE_INLINE
;
1898 /* Parse old-style parameter declarations. ??? Attributes are
1899 not allowed to start declaration specifiers here because of a
1900 syntax conflict between a function declaration with attribute
1901 suffix and a function definition with an attribute prefix on
1902 first old-style parameter declaration. Following the old
1903 parser, they are not accepted on subsequent old-style
1904 parameter declarations either. However, there is no
1905 ambiguity after the first declaration, nor indeed on the
1906 first as long as we don't allow postfix attributes after a
1907 declarator with a nonempty identifier list in a definition;
1908 and postfix attributes have never been accepted here in
1909 function definitions either. */
1910 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1911 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1912 c_parser_declaration_or_fndef (parser
, false, false, false,
1913 true, false, NULL
, vNULL
);
1914 store_parm_decls ();
1915 if (omp_declare_simd_clauses
.exists ()
1916 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1917 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1918 omp_declare_simd_clauses
);
1919 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1920 = c_parser_peek_token (parser
)->location
;
1921 fnbody
= c_parser_compound_statement (parser
);
1922 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1923 fnbody
= expand_array_notation_exprs (fnbody
);
1926 tree decl
= current_function_decl
;
1927 /* Mark nested functions as needing static-chain initially.
1928 lower_nested_functions will recompute it but the
1929 DECL_STATIC_CHAIN flag is also used before that happens,
1930 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1931 DECL_STATIC_CHAIN (decl
) = 1;
1934 c_pop_function_context ();
1935 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1948 /* Parse an asm-definition (asm() outside a function body). This is a
1956 c_parser_asm_definition (c_parser
*parser
)
1958 tree asm_str
= c_parser_simple_asm_expr (parser
);
1960 add_asm_node (asm_str
);
1961 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1964 /* Parse a static assertion (C11 6.7.10).
1966 static_assert-declaration:
1967 static_assert-declaration-no-semi ;
1971 c_parser_static_assert_declaration (c_parser
*parser
)
1973 c_parser_static_assert_declaration_no_semi (parser
);
1975 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1976 c_parser_skip_to_end_of_block_or_statement (parser
);
1979 /* Parse a static assertion (C11 6.7.10), without the trailing
1982 static_assert-declaration-no-semi:
1983 _Static_assert ( constant-expression , string-literal )
1987 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1989 location_t assert_loc
, value_loc
;
1993 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1994 assert_loc
= c_parser_peek_token (parser
)->location
;
1998 pedwarn (assert_loc
, OPT_Wpedantic
,
1999 "ISO C99 does not support %<_Static_assert%>");
2001 pedwarn (assert_loc
, OPT_Wpedantic
,
2002 "ISO C90 does not support %<_Static_assert%>");
2004 c_parser_consume_token (parser
);
2005 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2007 value_loc
= c_parser_peek_token (parser
)->location
;
2008 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2009 parser
->lex_untranslated_string
= true;
2010 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2012 parser
->lex_untranslated_string
= false;
2015 switch (c_parser_peek_token (parser
)->type
)
2021 case CPP_UTF8STRING
:
2022 string
= c_parser_peek_token (parser
)->value
;
2023 c_parser_consume_token (parser
);
2024 parser
->lex_untranslated_string
= false;
2027 c_parser_error (parser
, "expected string literal");
2028 parser
->lex_untranslated_string
= false;
2031 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2033 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2035 error_at (value_loc
, "expression in static assertion is not an integer");
2038 if (TREE_CODE (value
) != INTEGER_CST
)
2040 value
= c_fully_fold (value
, false, NULL
);
2041 if (TREE_CODE (value
) == INTEGER_CST
)
2042 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2043 "is not an integer constant expression");
2045 if (TREE_CODE (value
) != INTEGER_CST
)
2047 error_at (value_loc
, "expression in static assertion is not constant");
2050 constant_expression_warning (value
);
2051 if (integer_zerop (value
))
2052 error_at (assert_loc
, "static assertion failed: %E", string
);
2055 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2056 6.7), adding them to SPECS (which may already include some).
2057 Storage class specifiers are accepted iff SCSPEC_OK; type
2058 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2059 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2060 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2062 declaration-specifiers:
2063 storage-class-specifier declaration-specifiers[opt]
2064 type-specifier declaration-specifiers[opt]
2065 type-qualifier declaration-specifiers[opt]
2066 function-specifier declaration-specifiers[opt]
2067 alignment-specifier declaration-specifiers[opt]
2069 Function specifiers (inline) are from C99, and are currently
2070 handled as storage class specifiers, as is __thread. Alignment
2071 specifiers are from C11.
2073 C90 6.5.1, C99 6.7.1:
2074 storage-class-specifier:
2082 (_Thread_local is new in C11.)
2089 (_Noreturn is new in C11.)
2091 C90 6.5.2, C99 6.7.2:
2104 [_Imaginary removed in C99 TC2]
2105 struct-or-union-specifier
2108 atomic-type-specifier
2110 (_Bool and _Complex are new in C99.)
2111 (atomic-type-specifier is new in C11.)
2113 C90 6.5.3, C99 6.7.3:
2119 address-space-qualifier
2122 (restrict is new in C99.)
2123 (_Atomic is new in C11.)
2127 declaration-specifiers:
2128 attributes declaration-specifiers[opt]
2134 identifier recognized by the target
2136 storage-class-specifier:
2150 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2151 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2153 atomic-type-specifier
2154 _Atomic ( type-name )
2159 class-name objc-protocol-refs[opt]
2160 typedef-name objc-protocol-refs
2165 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2166 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2167 bool alignspec_ok
, bool auto_type_ok
,
2168 enum c_lookahead_kind la
)
2170 bool attrs_ok
= start_attr_ok
;
2171 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2174 gcc_assert (la
== cla_prefer_id
);
2176 while (c_parser_next_token_is (parser
, CPP_NAME
)
2177 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2178 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2180 struct c_typespec t
;
2183 location_t loc
= c_parser_peek_token (parser
)->location
;
2185 /* If we cannot accept a type, exit if the next token must start
2186 one. Also, if we already have seen a tagged definition,
2187 a typename would be an error anyway and likely the user
2188 has simply forgotten a semicolon, so we exit. */
2189 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2190 && c_parser_next_tokens_start_typename (parser
, la
)
2191 && !c_parser_next_token_is_qualifier (parser
))
2194 if (c_parser_next_token_is (parser
, CPP_NAME
))
2196 c_token
*name_token
= c_parser_peek_token (parser
);
2197 tree value
= name_token
->value
;
2198 c_id_kind kind
= name_token
->id_kind
;
2200 if (kind
== C_ID_ADDRSPACE
)
2203 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2204 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2205 c_parser_consume_token (parser
);
2210 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2212 /* If we cannot accept a type, and the next token must start one,
2213 exit. Do the same if we already have seen a tagged definition,
2214 since it would be an error anyway and likely the user has simply
2215 forgotten a semicolon. */
2216 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2219 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2220 a C_ID_CLASSNAME. */
2221 c_parser_consume_token (parser
);
2224 if (kind
== C_ID_ID
)
2226 error_at (loc
, "unknown type name %qE", value
);
2227 t
.kind
= ctsk_typedef
;
2228 t
.spec
= error_mark_node
;
2230 else if (kind
== C_ID_TYPENAME
2231 && (!c_dialect_objc ()
2232 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2234 t
.kind
= ctsk_typedef
;
2235 /* For a typedef name, record the meaning, not the name.
2236 In case of 'foo foo, bar;'. */
2237 t
.spec
= lookup_name (value
);
2241 tree proto
= NULL_TREE
;
2242 gcc_assert (c_dialect_objc ());
2244 if (c_parser_next_token_is (parser
, CPP_LESS
))
2245 proto
= c_parser_objc_protocol_refs (parser
);
2246 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2249 t
.expr_const_operands
= true;
2250 declspecs_add_type (name_token
->location
, specs
, t
);
2253 if (c_parser_next_token_is (parser
, CPP_LESS
))
2255 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2256 nisse@lysator.liu.se. */
2258 gcc_assert (c_dialect_objc ());
2259 if (!typespec_ok
|| seen_type
)
2261 proto
= c_parser_objc_protocol_refs (parser
);
2263 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2265 t
.expr_const_operands
= true;
2266 declspecs_add_type (loc
, specs
, t
);
2269 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2270 switch (c_parser_peek_token (parser
)->keyword
)
2283 /* TODO: Distinguish between function specifiers (inline, noreturn)
2284 and storage class specifiers, either here or in
2285 declspecs_add_scspec. */
2286 declspecs_add_scspec (loc
, specs
,
2287 c_parser_peek_token (parser
)->value
);
2288 c_parser_consume_token (parser
);
2316 if (c_dialect_objc ())
2317 parser
->objc_need_raw_identifier
= true;
2318 t
.kind
= ctsk_resword
;
2319 t
.spec
= c_parser_peek_token (parser
)->value
;
2321 t
.expr_const_operands
= true;
2322 declspecs_add_type (loc
, specs
, t
);
2323 c_parser_consume_token (parser
);
2330 t
= c_parser_enum_specifier (parser
);
2331 declspecs_add_type (loc
, specs
, t
);
2339 t
= c_parser_struct_or_union_specifier (parser
);
2340 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2341 declspecs_add_type (loc
, specs
, t
);
2344 /* ??? The old parser rejected typeof after other type
2345 specifiers, but is a syntax error the best way of
2347 if (!typespec_ok
|| seen_type
)
2351 t
= c_parser_typeof_specifier (parser
);
2352 declspecs_add_type (loc
, specs
, t
);
2355 /* C parser handling of Objective-C constructs needs
2356 checking for correct lvalue-to-rvalue conversions, and
2357 the code in build_modify_expr handling various
2358 Objective-C cases, and that in build_unary_op handling
2359 Objective-C cases for increment / decrement, also needs
2360 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2361 and objc_types_are_equivalent may also need updates. */
2362 if (c_dialect_objc ())
2363 sorry ("%<_Atomic%> in Objective-C");
2364 /* C parser handling of OpenMP constructs needs checking for
2365 correct lvalue-to-rvalue conversions. */
2367 sorry ("%<_Atomic%> with OpenMP");
2371 pedwarn (loc
, OPT_Wpedantic
,
2372 "ISO C99 does not support the %<_Atomic%> qualifier");
2374 pedwarn (loc
, OPT_Wpedantic
,
2375 "ISO C90 does not support the %<_Atomic%> qualifier");
2379 value
= c_parser_peek_token (parser
)->value
;
2380 c_parser_consume_token (parser
);
2381 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2383 /* _Atomic ( type-name ). */
2385 c_parser_consume_token (parser
);
2386 struct c_type_name
*type
= c_parser_type_name (parser
);
2387 t
.kind
= ctsk_typeof
;
2388 t
.spec
= error_mark_node
;
2390 t
.expr_const_operands
= true;
2392 t
.spec
= groktypename (type
, &t
.expr
,
2393 &t
.expr_const_operands
);
2394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2396 if (t
.spec
!= error_mark_node
)
2398 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2399 error_at (loc
, "%<_Atomic%>-qualified array type");
2400 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2401 error_at (loc
, "%<_Atomic%>-qualified function type");
2402 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2403 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2405 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2407 declspecs_add_type (loc
, specs
, t
);
2410 declspecs_add_qual (loc
, specs
, value
);
2416 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2417 c_parser_consume_token (parser
);
2422 attrs
= c_parser_attributes (parser
);
2423 declspecs_add_attrs (loc
, specs
, attrs
);
2428 align
= c_parser_alignas_specifier (parser
);
2429 declspecs_add_alignas (loc
, specs
, align
);
2438 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2441 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2442 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2443 enum attributes[opt] identifier
2445 The form with trailing comma is new in C99. The forms with
2446 attributes are GNU extensions. In GNU C, we accept any expression
2447 without commas in the syntax (assignment expressions, not just
2448 conditional expressions); assignment expressions will be diagnosed
2453 enumerator-list , enumerator
2456 enumeration-constant
2457 enumeration-constant = constant-expression
2460 static struct c_typespec
2461 c_parser_enum_specifier (c_parser
*parser
)
2463 struct c_typespec ret
;
2465 tree ident
= NULL_TREE
;
2466 location_t enum_loc
;
2467 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2468 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2469 enum_loc
= c_parser_peek_token (parser
)->location
;
2470 c_parser_consume_token (parser
);
2471 attrs
= c_parser_attributes (parser
);
2472 enum_loc
= c_parser_peek_token (parser
)->location
;
2473 /* Set the location in case we create a decl now. */
2474 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2475 if (c_parser_next_token_is (parser
, CPP_NAME
))
2477 ident
= c_parser_peek_token (parser
)->value
;
2478 ident_loc
= c_parser_peek_token (parser
)->location
;
2479 enum_loc
= ident_loc
;
2480 c_parser_consume_token (parser
);
2482 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2484 /* Parse an enum definition. */
2485 struct c_enum_contents the_enum
;
2488 /* We chain the enumerators in reverse order, then put them in
2489 forward order at the end. */
2491 timevar_push (TV_PARSE_ENUM
);
2492 type
= start_enum (enum_loc
, &the_enum
, ident
);
2494 c_parser_consume_token (parser
);
2502 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2503 location_t decl_loc
, value_loc
;
2504 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2506 c_parser_error (parser
, "expected identifier");
2507 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2508 values
= error_mark_node
;
2511 token
= c_parser_peek_token (parser
);
2512 enum_id
= token
->value
;
2513 /* Set the location in case we create a decl now. */
2514 c_parser_set_source_position_from_token (token
);
2515 decl_loc
= value_loc
= token
->location
;
2516 c_parser_consume_token (parser
);
2517 if (c_parser_next_token_is (parser
, CPP_EQ
))
2519 c_parser_consume_token (parser
);
2520 value_loc
= c_parser_peek_token (parser
)->location
;
2521 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2524 enum_value
= NULL_TREE
;
2525 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2526 &the_enum
, enum_id
, enum_value
);
2527 TREE_CHAIN (enum_decl
) = values
;
2530 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2532 comma_loc
= c_parser_peek_token (parser
)->location
;
2534 c_parser_consume_token (parser
);
2536 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2538 if (seen_comma
&& !flag_isoc99
)
2539 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2540 c_parser_consume_token (parser
);
2545 c_parser_error (parser
, "expected %<,%> or %<}%>");
2546 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2547 values
= error_mark_node
;
2551 postfix_attrs
= c_parser_attributes (parser
);
2552 ret
.spec
= finish_enum (type
, nreverse (values
),
2553 chainon (attrs
, postfix_attrs
));
2554 ret
.kind
= ctsk_tagdef
;
2555 ret
.expr
= NULL_TREE
;
2556 ret
.expr_const_operands
= true;
2557 timevar_pop (TV_PARSE_ENUM
);
2562 c_parser_error (parser
, "expected %<{%>");
2563 ret
.spec
= error_mark_node
;
2564 ret
.kind
= ctsk_tagref
;
2565 ret
.expr
= NULL_TREE
;
2566 ret
.expr_const_operands
= true;
2569 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2570 /* In ISO C, enumerated types can be referred to only if already
2572 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2575 pedwarn (enum_loc
, OPT_Wpedantic
,
2576 "ISO C forbids forward references to %<enum%> types");
2581 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2583 struct-or-union-specifier:
2584 struct-or-union attributes[opt] identifier[opt]
2585 { struct-contents } attributes[opt]
2586 struct-or-union attributes[opt] identifier
2589 struct-declaration-list
2591 struct-declaration-list:
2592 struct-declaration ;
2593 struct-declaration-list struct-declaration ;
2600 struct-declaration-list struct-declaration
2602 struct-declaration-list:
2603 struct-declaration-list ;
2606 (Note that in the syntax here, unlike that in ISO C, the semicolons
2607 are included here rather than in struct-declaration, in order to
2608 describe the syntax with extra semicolons and missing semicolon at
2613 struct-declaration-list:
2614 @defs ( class-name )
2616 (Note this does not include a trailing semicolon, but can be
2617 followed by further declarations, and gets a pedwarn-if-pedantic
2618 when followed by a semicolon.) */
2620 static struct c_typespec
2621 c_parser_struct_or_union_specifier (c_parser
*parser
)
2623 struct c_typespec ret
;
2625 tree ident
= NULL_TREE
;
2626 location_t struct_loc
;
2627 location_t ident_loc
= UNKNOWN_LOCATION
;
2628 enum tree_code code
;
2629 switch (c_parser_peek_token (parser
)->keyword
)
2640 struct_loc
= c_parser_peek_token (parser
)->location
;
2641 c_parser_consume_token (parser
);
2642 attrs
= c_parser_attributes (parser
);
2644 /* Set the location in case we create a decl now. */
2645 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2647 if (c_parser_next_token_is (parser
, CPP_NAME
))
2649 ident
= c_parser_peek_token (parser
)->value
;
2650 ident_loc
= c_parser_peek_token (parser
)->location
;
2651 struct_loc
= ident_loc
;
2652 c_parser_consume_token (parser
);
2654 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2656 /* Parse a struct or union definition. Start the scope of the
2657 tag before parsing components. */
2658 struct c_struct_parse_info
*struct_info
;
2659 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2661 /* We chain the components in reverse order, then put them in
2662 forward order at the end. Each struct-declaration may
2663 declare multiple components (comma-separated), so we must use
2664 chainon to join them, although when parsing each
2665 struct-declaration we can use TREE_CHAIN directly.
2667 The theory behind all this is that there will be more
2668 semicolon separated fields than comma separated fields, and
2669 so we'll be minimizing the number of node traversals required
2672 timevar_push (TV_PARSE_STRUCT
);
2673 contents
= NULL_TREE
;
2674 c_parser_consume_token (parser
);
2675 /* Handle the Objective-C @defs construct,
2676 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2677 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2680 gcc_assert (c_dialect_objc ());
2681 c_parser_consume_token (parser
);
2682 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2684 if (c_parser_next_token_is (parser
, CPP_NAME
)
2685 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2687 name
= c_parser_peek_token (parser
)->value
;
2688 c_parser_consume_token (parser
);
2692 c_parser_error (parser
, "expected class name");
2693 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2698 contents
= nreverse (objc_get_class_ivars (name
));
2701 /* Parse the struct-declarations and semicolons. Problems with
2702 semicolons are diagnosed here; empty structures are diagnosed
2707 /* Parse any stray semicolon. */
2708 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2710 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2711 "extra semicolon in struct or union specified");
2712 c_parser_consume_token (parser
);
2715 /* Stop if at the end of the struct or union contents. */
2716 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2718 c_parser_consume_token (parser
);
2721 /* Accept #pragmas at struct scope. */
2722 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2724 c_parser_pragma (parser
, pragma_struct
);
2727 /* Parse some comma-separated declarations, but not the
2728 trailing semicolon if any. */
2729 decls
= c_parser_struct_declaration (parser
);
2730 contents
= chainon (decls
, contents
);
2731 /* If no semicolon follows, either we have a parse error or
2732 are at the end of the struct or union and should
2734 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2735 c_parser_consume_token (parser
);
2738 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2739 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2740 "no semicolon at end of struct or union");
2741 else if (parser
->error
2742 || !c_parser_next_token_starts_declspecs (parser
))
2744 c_parser_error (parser
, "expected %<;%>");
2745 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2749 /* If we come here, we have already emitted an error
2750 for an expected `;', identifier or `(', and we also
2751 recovered already. Go on with the next field. */
2754 postfix_attrs
= c_parser_attributes (parser
);
2755 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2756 chainon (attrs
, postfix_attrs
), struct_info
);
2757 ret
.kind
= ctsk_tagdef
;
2758 ret
.expr
= NULL_TREE
;
2759 ret
.expr_const_operands
= true;
2760 timevar_pop (TV_PARSE_STRUCT
);
2765 c_parser_error (parser
, "expected %<{%>");
2766 ret
.spec
= error_mark_node
;
2767 ret
.kind
= ctsk_tagref
;
2768 ret
.expr
= NULL_TREE
;
2769 ret
.expr_const_operands
= true;
2772 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2776 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2777 the trailing semicolon.
2780 specifier-qualifier-list struct-declarator-list
2781 static_assert-declaration-no-semi
2783 specifier-qualifier-list:
2784 type-specifier specifier-qualifier-list[opt]
2785 type-qualifier specifier-qualifier-list[opt]
2786 attributes specifier-qualifier-list[opt]
2788 struct-declarator-list:
2790 struct-declarator-list , attributes[opt] struct-declarator
2793 declarator attributes[opt]
2794 declarator[opt] : constant-expression attributes[opt]
2799 __extension__ struct-declaration
2800 specifier-qualifier-list
2802 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2803 of attributes where shown is a GNU extension. In GNU C, we accept
2804 any expression without commas in the syntax (assignment
2805 expressions, not just conditional expressions); assignment
2806 expressions will be diagnosed as non-constant. */
2809 c_parser_struct_declaration (c_parser
*parser
)
2811 struct c_declspecs
*specs
;
2813 tree all_prefix_attrs
;
2815 location_t decl_loc
;
2816 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2820 ext
= disable_extension_diagnostics ();
2821 c_parser_consume_token (parser
);
2822 decl
= c_parser_struct_declaration (parser
);
2823 restore_extension_diagnostics (ext
);
2826 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2828 c_parser_static_assert_declaration_no_semi (parser
);
2831 specs
= build_null_declspecs ();
2832 decl_loc
= c_parser_peek_token (parser
)->location
;
2833 /* Strictly by the standard, we shouldn't allow _Alignas here,
2834 but it appears to have been intended to allow it there, so
2835 we're keeping it as it is until WG14 reaches a conclusion
2837 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2838 c_parser_declspecs (parser
, specs
, false, true, true,
2839 true, false, cla_nonabstract_decl
);
2842 if (!specs
->declspecs_seen_p
)
2844 c_parser_error (parser
, "expected specifier-qualifier-list");
2847 finish_declspecs (specs
);
2848 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2849 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2852 if (specs
->typespec_kind
== ctsk_none
)
2854 pedwarn (decl_loc
, OPT_Wpedantic
,
2855 "ISO C forbids member declarations with no members");
2856 shadow_tag_warned (specs
, pedantic
);
2861 /* Support for unnamed structs or unions as members of
2862 structs or unions (which is [a] useful and [b] supports
2866 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2867 build_id_declarator (NULL_TREE
), specs
,
2870 decl_attributes (&ret
, attrs
, 0);
2875 /* Provide better error recovery. Note that a type name here is valid,
2876 and will be treated as a field name. */
2877 if (specs
->typespec_kind
== ctsk_tagdef
2878 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2879 && c_parser_next_token_starts_declspecs (parser
)
2880 && !c_parser_next_token_is (parser
, CPP_NAME
))
2882 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2883 parser
->error
= false;
2887 pending_xref_error ();
2888 prefix_attrs
= specs
->attrs
;
2889 all_prefix_attrs
= prefix_attrs
;
2890 specs
->attrs
= NULL_TREE
;
2894 /* Declaring one or more declarators or un-named bit-fields. */
2895 struct c_declarator
*declarator
;
2897 if (c_parser_next_token_is (parser
, CPP_COLON
))
2898 declarator
= build_id_declarator (NULL_TREE
);
2900 declarator
= c_parser_declarator (parser
,
2901 specs
->typespec_kind
!= ctsk_none
,
2902 C_DTR_NORMAL
, &dummy
);
2903 if (declarator
== NULL
)
2905 c_parser_skip_to_end_of_block_or_statement (parser
);
2908 if (c_parser_next_token_is (parser
, CPP_COLON
)
2909 || c_parser_next_token_is (parser
, CPP_COMMA
)
2910 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2911 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2912 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2914 tree postfix_attrs
= NULL_TREE
;
2915 tree width
= NULL_TREE
;
2917 if (c_parser_next_token_is (parser
, CPP_COLON
))
2919 c_parser_consume_token (parser
);
2920 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2922 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2923 postfix_attrs
= c_parser_attributes (parser
);
2924 d
= grokfield (c_parser_peek_token (parser
)->location
,
2925 declarator
, specs
, width
, &all_prefix_attrs
);
2926 decl_attributes (&d
, chainon (postfix_attrs
,
2927 all_prefix_attrs
), 0);
2928 DECL_CHAIN (d
) = decls
;
2930 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2931 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2934 all_prefix_attrs
= prefix_attrs
;
2935 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2936 c_parser_consume_token (parser
);
2937 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2938 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2940 /* Semicolon consumed in caller. */
2945 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2951 c_parser_error (parser
,
2952 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2953 "%<__attribute__%>");
2960 /* Parse a typeof specifier (a GNU extension).
2963 typeof ( expression )
2964 typeof ( type-name )
2967 static struct c_typespec
2968 c_parser_typeof_specifier (c_parser
*parser
)
2970 struct c_typespec ret
;
2971 ret
.kind
= ctsk_typeof
;
2972 ret
.spec
= error_mark_node
;
2973 ret
.expr
= NULL_TREE
;
2974 ret
.expr_const_operands
= true;
2975 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2976 c_parser_consume_token (parser
);
2977 c_inhibit_evaluation_warnings
++;
2979 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2981 c_inhibit_evaluation_warnings
--;
2985 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2987 struct c_type_name
*type
= c_parser_type_name (parser
);
2988 c_inhibit_evaluation_warnings
--;
2992 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2993 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2999 location_t here
= c_parser_peek_token (parser
)->location
;
3000 struct c_expr expr
= c_parser_expression (parser
);
3001 c_inhibit_evaluation_warnings
--;
3003 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3004 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3005 error_at (here
, "%<typeof%> applied to a bit-field");
3006 mark_exp_read (expr
.value
);
3007 ret
.spec
= TREE_TYPE (expr
.value
);
3008 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3009 /* This is returned with the type so that when the type is
3010 evaluated, this can be evaluated. */
3012 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3013 pop_maybe_used (was_vm
);
3014 /* For use in macros such as those in <stdatomic.h>, remove
3015 _Atomic and const qualifiers from atomic types. (Possibly
3016 all qualifiers should be removed; const can be an issue for
3017 more macros using typeof than just the <stdatomic.h>
3019 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3020 ret
.spec
= c_build_qualified_type (ret
.spec
,
3021 (TYPE_QUALS (ret
.spec
)
3022 & ~(TYPE_QUAL_ATOMIC
3023 | TYPE_QUAL_CONST
)));
3025 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3029 /* Parse an alignment-specifier.
3033 alignment-specifier:
3034 _Alignas ( type-name )
3035 _Alignas ( constant-expression )
3039 c_parser_alignas_specifier (c_parser
* parser
)
3041 tree ret
= error_mark_node
;
3042 location_t loc
= c_parser_peek_token (parser
)->location
;
3043 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3044 c_parser_consume_token (parser
);
3048 pedwarn (loc
, OPT_Wpedantic
,
3049 "ISO C99 does not support %<_Alignas%>");
3051 pedwarn (loc
, OPT_Wpedantic
,
3052 "ISO C90 does not support %<_Alignas%>");
3054 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3056 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3058 struct c_type_name
*type
= c_parser_type_name (parser
);
3060 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3064 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3069 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3070 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3071 be redeclared; otherwise it may not. KIND indicates which kind of
3072 declarator is wanted. Returns a valid declarator except in the
3073 case of a syntax error in which case NULL is returned. *SEEN_ID is
3074 set to true if an identifier being declared is seen; this is used
3075 to diagnose bad forms of abstract array declarators and to
3076 determine whether an identifier list is syntactically permitted.
3079 pointer[opt] direct-declarator
3083 ( attributes[opt] declarator )
3084 direct-declarator array-declarator
3085 direct-declarator ( parameter-type-list )
3086 direct-declarator ( identifier-list[opt] )
3089 * type-qualifier-list[opt]
3090 * type-qualifier-list[opt] pointer
3092 type-qualifier-list:
3095 type-qualifier-list type-qualifier
3096 type-qualifier-list attributes
3099 [ type-qualifier-list[opt] assignment-expression[opt] ]
3100 [ static type-qualifier-list[opt] assignment-expression ]
3101 [ type-qualifier-list static assignment-expression ]
3102 [ type-qualifier-list[opt] * ]
3104 parameter-type-list:
3106 parameter-list , ...
3109 parameter-declaration
3110 parameter-list , parameter-declaration
3112 parameter-declaration:
3113 declaration-specifiers declarator attributes[opt]
3114 declaration-specifiers abstract-declarator[opt] attributes[opt]
3118 identifier-list , identifier
3120 abstract-declarator:
3122 pointer[opt] direct-abstract-declarator
3124 direct-abstract-declarator:
3125 ( attributes[opt] abstract-declarator )
3126 direct-abstract-declarator[opt] array-declarator
3127 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3132 direct-declarator ( parameter-forward-declarations
3133 parameter-type-list[opt] )
3135 direct-abstract-declarator:
3136 direct-abstract-declarator[opt] ( parameter-forward-declarations
3137 parameter-type-list[opt] )
3139 parameter-forward-declarations:
3141 parameter-forward-declarations parameter-list ;
3143 The uses of attributes shown above are GNU extensions.
3145 Some forms of array declarator are not included in C99 in the
3146 syntax for abstract declarators; these are disallowed elsewhere.
3147 This may be a defect (DR#289).
3149 This function also accepts an omitted abstract declarator as being
3150 an abstract declarator, although not part of the formal syntax. */
3152 static struct c_declarator
*
3153 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3156 /* Parse any initial pointer part. */
3157 if (c_parser_next_token_is (parser
, CPP_MULT
))
3159 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3160 struct c_declarator
*inner
;
3161 c_parser_consume_token (parser
);
3162 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3163 false, false, cla_prefer_id
);
3164 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3168 return make_pointer_declarator (quals_attrs
, inner
);
3170 /* Now we have a direct declarator, direct abstract declarator or
3171 nothing (which counts as a direct abstract declarator here). */
3172 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3175 /* Parse a direct declarator or direct abstract declarator; arguments
3176 as c_parser_declarator. */
3178 static struct c_declarator
*
3179 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3182 /* The direct declarator must start with an identifier (possibly
3183 omitted) or a parenthesized declarator (possibly abstract). In
3184 an ordinary declarator, initial parentheses must start a
3185 parenthesized declarator. In an abstract declarator or parameter
3186 declarator, they could start a parenthesized declarator or a
3187 parameter list. To tell which, the open parenthesis and any
3188 following attributes must be read. If a declaration specifier
3189 follows, then it is a parameter list; if the specifier is a
3190 typedef name, there might be an ambiguity about redeclaring it,
3191 which is resolved in the direction of treating it as a typedef
3192 name. If a close parenthesis follows, it is also an empty
3193 parameter list, as the syntax does not permit empty abstract
3194 declarators. Otherwise, it is a parenthesized declarator (in
3195 which case the analysis may be repeated inside it, recursively).
3197 ??? There is an ambiguity in a parameter declaration "int
3198 (__attribute__((foo)) x)", where x is not a typedef name: it
3199 could be an abstract declarator for a function, or declare x with
3200 parentheses. The proper resolution of this ambiguity needs
3201 documenting. At present we follow an accident of the old
3202 parser's implementation, whereby the first parameter must have
3203 some declaration specifiers other than just attributes. Thus as
3204 a parameter declaration it is treated as a parenthesized
3205 parameter named x, and as an abstract declarator it is
3208 ??? Also following the old parser, attributes inside an empty
3209 parameter list are ignored, making it a list not yielding a
3210 prototype, rather than giving an error or making it have one
3211 parameter with implicit type int.
3213 ??? Also following the old parser, typedef names may be
3214 redeclared in declarators, but not Objective-C class names. */
3216 if (kind
!= C_DTR_ABSTRACT
3217 && c_parser_next_token_is (parser
, CPP_NAME
)
3219 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3220 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3221 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3223 struct c_declarator
*inner
3224 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3226 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3227 c_parser_consume_token (parser
);
3228 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3231 if (kind
!= C_DTR_NORMAL
3232 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3234 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3235 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3238 /* Either we are at the end of an abstract declarator, or we have
3241 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3244 struct c_declarator
*inner
;
3245 c_parser_consume_token (parser
);
3246 attrs
= c_parser_attributes (parser
);
3247 if (kind
!= C_DTR_NORMAL
3248 && (c_parser_next_token_starts_declspecs (parser
)
3249 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3251 struct c_arg_info
*args
3252 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3259 = build_function_declarator (args
,
3260 build_id_declarator (NULL_TREE
));
3261 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3265 /* A parenthesized declarator. */
3266 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3267 if (inner
!= NULL
&& attrs
!= NULL
)
3268 inner
= build_attrs_declarator (attrs
, inner
);
3269 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3271 c_parser_consume_token (parser
);
3275 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3279 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3286 if (kind
== C_DTR_NORMAL
)
3288 c_parser_error (parser
, "expected identifier or %<(%>");
3292 return build_id_declarator (NULL_TREE
);
3296 /* Parse part of a direct declarator or direct abstract declarator,
3297 given that some (in INNER) has already been parsed; ID_PRESENT is
3298 true if an identifier is present, false for an abstract
3301 static struct c_declarator
*
3302 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3303 struct c_declarator
*inner
)
3305 /* Parse a sequence of array declarators and parameter lists. */
3306 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3308 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3309 struct c_declarator
*declarator
;
3310 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3313 struct c_expr dimen
;
3314 dimen
.value
= NULL_TREE
;
3315 dimen
.original_code
= ERROR_MARK
;
3316 dimen
.original_type
= NULL_TREE
;
3317 c_parser_consume_token (parser
);
3318 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3319 false, false, cla_prefer_id
);
3320 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3322 c_parser_consume_token (parser
);
3323 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3324 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3325 false, false, cla_prefer_id
);
3326 if (!quals_attrs
->declspecs_seen_p
)
3328 /* If "static" is present, there must be an array dimension.
3329 Otherwise, there may be a dimension, "*", or no
3334 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3338 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3340 dimen
.value
= NULL_TREE
;
3343 else if (flag_cilkplus
3344 && c_parser_next_token_is (parser
, CPP_COLON
))
3346 dimen
.value
= error_mark_node
;
3348 error_at (c_parser_peek_token (parser
)->location
,
3349 "array notations cannot be used in declaration");
3350 c_parser_consume_token (parser
);
3352 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3354 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3356 dimen
.value
= NULL_TREE
;
3358 c_parser_consume_token (parser
);
3363 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3369 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3372 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3373 c_parser_consume_token (parser
);
3374 else if (flag_cilkplus
3375 && c_parser_next_token_is (parser
, CPP_COLON
))
3377 error_at (c_parser_peek_token (parser
)->location
,
3378 "array notations cannot be used in declaration");
3379 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3384 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3389 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3390 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3391 static_seen
, star_seen
);
3392 if (declarator
== NULL
)
3394 inner
= set_array_declarator_inner (declarator
, inner
);
3395 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3397 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3400 struct c_arg_info
*args
;
3401 c_parser_consume_token (parser
);
3402 attrs
= c_parser_attributes (parser
);
3403 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3408 inner
= build_function_declarator (args
, inner
);
3409 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3415 /* Parse a parameter list or identifier list, including the closing
3416 parenthesis but not the opening one. ATTRS are the attributes at
3417 the start of the list. ID_LIST_OK is true if an identifier list is
3418 acceptable; such a list must not have attributes at the start. */
3420 static struct c_arg_info
*
3421 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3424 declare_parm_level ();
3425 /* If the list starts with an identifier, it is an identifier list.
3426 Otherwise, it is either a prototype list or an empty list. */
3429 && c_parser_next_token_is (parser
, CPP_NAME
)
3430 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3432 /* Look ahead to detect typos in type names. */
3433 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3434 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3435 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3436 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3438 tree list
= NULL_TREE
, *nextp
= &list
;
3439 while (c_parser_next_token_is (parser
, CPP_NAME
)
3440 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3442 *nextp
= build_tree_list (NULL_TREE
,
3443 c_parser_peek_token (parser
)->value
);
3444 nextp
= & TREE_CHAIN (*nextp
);
3445 c_parser_consume_token (parser
);
3446 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3448 c_parser_consume_token (parser
);
3449 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3451 c_parser_error (parser
, "expected identifier");
3455 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3457 struct c_arg_info
*ret
= build_arg_info ();
3459 c_parser_consume_token (parser
);
3465 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3473 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3480 /* Parse a parameter list (possibly empty), including the closing
3481 parenthesis but not the opening one. ATTRS are the attributes at
3482 the start of the list. EXPR is NULL or an expression that needs to
3483 be evaluated for the side effects of array size expressions in the
3486 static struct c_arg_info
*
3487 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3489 bool bad_parm
= false;
3491 /* ??? Following the old parser, forward parameter declarations may
3492 use abstract declarators, and if no real parameter declarations
3493 follow the forward declarations then this is not diagnosed. Also
3494 note as above that attributes are ignored as the only contents of
3495 the parentheses, or as the only contents after forward
3497 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3499 struct c_arg_info
*ret
= build_arg_info ();
3500 c_parser_consume_token (parser
);
3503 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3505 struct c_arg_info
*ret
= build_arg_info ();
3507 if (flag_allow_parameterless_variadic_functions
)
3509 /* F (...) is allowed. */
3510 ret
->types
= NULL_TREE
;
3514 /* Suppress -Wold-style-definition for this case. */
3515 ret
->types
= error_mark_node
;
3516 error_at (c_parser_peek_token (parser
)->location
,
3517 "ISO C requires a named argument before %<...%>");
3519 c_parser_consume_token (parser
);
3520 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3522 c_parser_consume_token (parser
);
3527 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3532 /* Nonempty list of parameters, either terminated with semicolon
3533 (forward declarations; recurse) or with close parenthesis (normal
3534 function) or with ", ... )" (variadic function). */
3537 /* Parse a parameter. */
3538 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3543 push_parm_decl (parm
, &expr
);
3544 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3547 c_parser_consume_token (parser
);
3548 mark_forward_parm_decls ();
3549 new_attrs
= c_parser_attributes (parser
);
3550 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3552 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3554 c_parser_consume_token (parser
);
3558 return get_parm_info (false, expr
);
3560 if (!c_parser_require (parser
, CPP_COMMA
,
3561 "expected %<;%>, %<,%> or %<)%>"))
3563 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3566 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3568 c_parser_consume_token (parser
);
3569 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3571 c_parser_consume_token (parser
);
3575 return get_parm_info (true, expr
);
3579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3587 /* Parse a parameter declaration. ATTRS are the attributes at the
3588 start of the declaration if it is the first parameter. */
3590 static struct c_parm
*
3591 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3593 struct c_declspecs
*specs
;
3594 struct c_declarator
*declarator
;
3596 tree postfix_attrs
= NULL_TREE
;
3599 /* Accept #pragmas between parameter declarations. */
3600 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3601 c_parser_pragma (parser
, pragma_param
);
3603 if (!c_parser_next_token_starts_declspecs (parser
))
3605 c_token
*token
= c_parser_peek_token (parser
);
3608 c_parser_set_source_position_from_token (token
);
3609 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3611 error_at (token
->location
, "unknown type name %qE", token
->value
);
3612 parser
->error
= true;
3614 /* ??? In some Objective-C cases '...' isn't applicable so there
3615 should be a different message. */
3617 c_parser_error (parser
,
3618 "expected declaration specifiers or %<...%>");
3619 c_parser_skip_to_end_of_parameter (parser
);
3622 specs
= build_null_declspecs ();
3625 declspecs_add_attrs (input_location
, specs
, attrs
);
3628 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3629 cla_nonabstract_decl
);
3630 finish_declspecs (specs
);
3631 pending_xref_error ();
3632 prefix_attrs
= specs
->attrs
;
3633 specs
->attrs
= NULL_TREE
;
3634 declarator
= c_parser_declarator (parser
,
3635 specs
->typespec_kind
!= ctsk_none
,
3636 C_DTR_PARM
, &dummy
);
3637 if (declarator
== NULL
)
3639 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3642 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3643 postfix_attrs
= c_parser_attributes (parser
);
3644 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3648 /* Parse a string literal in an asm expression. It should not be
3649 translated, and wide string literals are an error although
3650 permitted by the syntax. This is a GNU extension.
3655 ??? At present, following the old parser, the caller needs to have
3656 set lex_untranslated_string to 1. It would be better to follow the
3657 C++ parser rather than using this kludge. */
3660 c_parser_asm_string_literal (c_parser
*parser
)
3663 int save_flag
= warn_overlength_strings
;
3664 warn_overlength_strings
= 0;
3665 if (c_parser_next_token_is (parser
, CPP_STRING
))
3667 str
= c_parser_peek_token (parser
)->value
;
3668 c_parser_consume_token (parser
);
3670 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3672 error_at (c_parser_peek_token (parser
)->location
,
3673 "wide string literal in %<asm%>");
3674 str
= build_string (1, "");
3675 c_parser_consume_token (parser
);
3679 c_parser_error (parser
, "expected string literal");
3682 warn_overlength_strings
= save_flag
;
3686 /* Parse a simple asm expression. This is used in restricted
3687 contexts, where a full expression with inputs and outputs does not
3688 make sense. This is a GNU extension.
3691 asm ( asm-string-literal )
3695 c_parser_simple_asm_expr (c_parser
*parser
)
3698 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3699 /* ??? Follow the C++ parser rather than using the
3700 lex_untranslated_string kludge. */
3701 parser
->lex_untranslated_string
= true;
3702 c_parser_consume_token (parser
);
3703 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3705 parser
->lex_untranslated_string
= false;
3708 str
= c_parser_asm_string_literal (parser
);
3709 parser
->lex_untranslated_string
= false;
3710 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3712 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3719 c_parser_attribute_any_word (c_parser
*parser
)
3721 tree attr_name
= NULL_TREE
;
3723 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3725 /* ??? See comment above about what keywords are accepted here. */
3727 switch (c_parser_peek_token (parser
)->keyword
)
3758 case RID_TRANSACTION_ATOMIC
:
3759 case RID_TRANSACTION_CANCEL
:
3771 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3772 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3774 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3775 attr_name
= c_parser_peek_token (parser
)->value
;
3780 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3781 "__vector" or "__vector__." */
3784 is_cilkplus_vector_p (tree name
)
3786 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3791 #define CILK_SIMD_FN_CLAUSE_MASK \
3792 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3793 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3794 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3795 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3796 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3798 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3799 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3800 pushed into the token list.
3803 vector (<vector attributes>). */
3806 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3808 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3810 int paren_scope
= 0;
3811 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3812 /* Consume the "vector" token. */
3813 c_parser_consume_token (parser
);
3815 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3817 c_parser_consume_token (parser
);
3820 while (paren_scope
> 0)
3822 c_token
*token
= c_parser_peek_token (parser
);
3823 if (token
->type
== CPP_OPEN_PAREN
)
3825 else if (token
->type
== CPP_CLOSE_PAREN
)
3827 /* Do not push the last ')' since we are not pushing the '('. */
3828 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3829 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3830 c_parser_consume_token (parser
);
3833 /* Since we are converting an attribute to a pragma, we need to end the
3834 attribute with PRAGMA_EOL. */
3836 memset (&eol_token
, 0, sizeof (eol_token
));
3837 eol_token
.type
= CPP_PRAGMA_EOL
;
3838 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3841 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3844 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3846 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3848 /* c_parser_attributes is called in several places, so if these EOF
3849 tokens are already inserted, then don't do them again. */
3850 if (last_token
.type
== CPP_EOF
)
3853 /* Two CPP_EOF token are added as a safety net since the normal C
3854 front-end has two token look-ahead. */
3856 eof_token
.type
= CPP_EOF
;
3857 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3858 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3861 /* Parse (possibly empty) attributes. This is a GNU extension.
3865 attributes attribute
3868 __attribute__ ( ( attribute-list ) )
3872 attribute_list , attrib
3877 any-word ( identifier )
3878 any-word ( identifier , nonempty-expr-list )
3879 any-word ( expr-list )
3881 where the "identifier" must not be declared as a type, and
3882 "any-word" may be any identifier (including one declared as a
3883 type), a reserved word storage class specifier, type specifier or
3884 type qualifier. ??? This still leaves out most reserved keywords
3885 (following the old parser), shouldn't we include them, and why not
3886 allow identifiers declared as types to start the arguments? */
3889 c_parser_attributes (c_parser
*parser
)
3891 tree attrs
= NULL_TREE
;
3892 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3894 /* ??? Follow the C++ parser rather than using the
3895 lex_untranslated_string kludge. */
3896 parser
->lex_untranslated_string
= true;
3897 c_parser_consume_token (parser
);
3898 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3900 parser
->lex_untranslated_string
= false;
3903 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3905 parser
->lex_untranslated_string
= false;
3906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3909 /* Parse the attribute list. */
3910 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3911 || c_parser_next_token_is (parser
, CPP_NAME
)
3912 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3914 tree attr
, attr_name
, attr_args
;
3915 vec
<tree
, va_gc
> *expr_list
;
3916 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3918 c_parser_consume_token (parser
);
3922 attr_name
= c_parser_attribute_any_word (parser
);
3923 if (attr_name
== NULL
)
3925 if (is_cilkplus_vector_p (attr_name
))
3927 c_token
*v_token
= c_parser_peek_token (parser
);
3928 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3931 c_parser_consume_token (parser
);
3932 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3934 attr
= build_tree_list (attr_name
, NULL_TREE
);
3935 attrs
= chainon (attrs
, attr
);
3938 c_parser_consume_token (parser
);
3939 /* Parse the attribute contents. If they start with an
3940 identifier which is followed by a comma or close
3941 parenthesis, then the arguments start with that
3942 identifier; otherwise they are an expression list.
3943 In objective-c the identifier may be a classname. */
3944 if (c_parser_next_token_is (parser
, CPP_NAME
)
3945 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3946 || (c_dialect_objc ()
3947 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3948 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3949 || (c_parser_peek_2nd_token (parser
)->type
3950 == CPP_CLOSE_PAREN
)))
3952 tree arg1
= c_parser_peek_token (parser
)->value
;
3953 c_parser_consume_token (parser
);
3954 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3955 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3959 c_parser_consume_token (parser
);
3960 expr_list
= c_parser_expr_list (parser
, false, true,
3961 NULL
, NULL
, NULL
, NULL
);
3962 tree_list
= build_tree_list_vec (expr_list
);
3963 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3964 release_tree_vector (expr_list
);
3969 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3970 attr_args
= NULL_TREE
;
3973 expr_list
= c_parser_expr_list (parser
, false, true,
3974 NULL
, NULL
, NULL
, NULL
);
3975 attr_args
= build_tree_list_vec (expr_list
);
3976 release_tree_vector (expr_list
);
3979 attr
= build_tree_list (attr_name
, attr_args
);
3980 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3981 c_parser_consume_token (parser
);
3984 parser
->lex_untranslated_string
= false;
3985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3989 attrs
= chainon (attrs
, attr
);
3991 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3992 c_parser_consume_token (parser
);
3995 parser
->lex_untranslated_string
= false;
3996 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4000 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4001 c_parser_consume_token (parser
);
4004 parser
->lex_untranslated_string
= false;
4005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4009 parser
->lex_untranslated_string
= false;
4012 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4013 c_finish_cilk_simd_fn_tokens (parser
);
4017 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4020 specifier-qualifier-list abstract-declarator[opt]
4023 static struct c_type_name
*
4024 c_parser_type_name (c_parser
*parser
)
4026 struct c_declspecs
*specs
= build_null_declspecs ();
4027 struct c_declarator
*declarator
;
4028 struct c_type_name
*ret
;
4030 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4032 if (!specs
->declspecs_seen_p
)
4034 c_parser_error (parser
, "expected specifier-qualifier-list");
4037 if (specs
->type
!= error_mark_node
)
4039 pending_xref_error ();
4040 finish_declspecs (specs
);
4042 declarator
= c_parser_declarator (parser
,
4043 specs
->typespec_kind
!= ctsk_none
,
4044 C_DTR_ABSTRACT
, &dummy
);
4045 if (declarator
== NULL
)
4047 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4049 ret
->declarator
= declarator
;
4053 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4056 assignment-expression
4057 { initializer-list }
4058 { initializer-list , }
4061 designation[opt] initializer
4062 initializer-list , designation[opt] initializer
4069 designator-list designator
4076 [ constant-expression ]
4088 [ constant-expression ... constant-expression ]
4090 Any expression without commas is accepted in the syntax for the
4091 constant-expressions, with non-constant expressions rejected later.
4093 This function is only used for top-level initializers; for nested
4094 ones, see c_parser_initval. */
4096 static struct c_expr
4097 c_parser_initializer (c_parser
*parser
)
4099 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4100 return c_parser_braced_init (parser
, NULL_TREE
, false);
4104 location_t loc
= c_parser_peek_token (parser
)->location
;
4105 ret
= c_parser_expr_no_commas (parser
, NULL
);
4106 if (TREE_CODE (ret
.value
) != STRING_CST
4107 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4108 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4113 /* Parse a braced initializer list. TYPE is the type specified for a
4114 compound literal, and NULL_TREE for other initializers and for
4115 nested braced lists. NESTED_P is true for nested braced lists,
4116 false for the list of a compound literal or the list that is the
4117 top-level initializer in a declaration. */
4119 static struct c_expr
4120 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4123 struct obstack braced_init_obstack
;
4124 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4125 gcc_obstack_init (&braced_init_obstack
);
4126 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4127 c_parser_consume_token (parser
);
4129 push_init_level (0, &braced_init_obstack
);
4131 really_start_incremental_init (type
);
4132 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4134 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4138 /* Parse a non-empty initializer list, possibly with a trailing
4142 c_parser_initelt (parser
, &braced_init_obstack
);
4145 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4146 c_parser_consume_token (parser
);
4149 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4153 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4155 ret
.value
= error_mark_node
;
4156 ret
.original_code
= ERROR_MARK
;
4157 ret
.original_type
= NULL
;
4158 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4159 pop_init_level (0, &braced_init_obstack
);
4160 obstack_free (&braced_init_obstack
, NULL
);
4163 c_parser_consume_token (parser
);
4164 ret
= pop_init_level (0, &braced_init_obstack
);
4165 obstack_free (&braced_init_obstack
, NULL
);
4169 /* Parse a nested initializer, including designators. */
4172 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4174 /* Parse any designator or designator list. A single array
4175 designator may have the subsequent "=" omitted in GNU C, but a
4176 longer list or a structure member designator may not. */
4177 if (c_parser_next_token_is (parser
, CPP_NAME
)
4178 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4180 /* Old-style structure member designator. */
4181 set_init_label (c_parser_peek_token (parser
)->value
,
4182 braced_init_obstack
);
4183 /* Use the colon as the error location. */
4184 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4185 "obsolete use of designated initializer with %<:%>");
4186 c_parser_consume_token (parser
);
4187 c_parser_consume_token (parser
);
4191 /* des_seen is 0 if there have been no designators, 1 if there
4192 has been a single array designator and 2 otherwise. */
4194 /* Location of a designator. */
4195 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4196 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4197 || c_parser_next_token_is (parser
, CPP_DOT
))
4199 int des_prev
= des_seen
;
4201 des_loc
= c_parser_peek_token (parser
)->location
;
4204 if (c_parser_next_token_is (parser
, CPP_DOT
))
4207 c_parser_consume_token (parser
);
4208 if (c_parser_next_token_is (parser
, CPP_NAME
))
4210 set_init_label (c_parser_peek_token (parser
)->value
,
4211 braced_init_obstack
);
4212 c_parser_consume_token (parser
);
4217 init
.value
= error_mark_node
;
4218 init
.original_code
= ERROR_MARK
;
4219 init
.original_type
= NULL
;
4220 c_parser_error (parser
, "expected identifier");
4221 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4222 process_init_element (init
, false, braced_init_obstack
);
4229 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4230 /* ??? Following the old parser, [ objc-receiver
4231 objc-message-args ] is accepted as an initializer,
4232 being distinguished from a designator by what follows
4233 the first assignment expression inside the square
4234 brackets, but after a first array designator a
4235 subsequent square bracket is for Objective-C taken to
4236 start an expression, using the obsolete form of
4237 designated initializer without '=', rather than
4238 possibly being a second level of designation: in LALR
4239 terms, the '[' is shifted rather than reducing
4240 designator to designator-list. */
4241 if (des_prev
== 1 && c_dialect_objc ())
4243 des_seen
= des_prev
;
4246 if (des_prev
== 0 && c_dialect_objc ())
4248 /* This might be an array designator or an
4249 Objective-C message expression. If the former,
4250 continue parsing here; if the latter, parse the
4251 remainder of the initializer given the starting
4252 primary-expression. ??? It might make sense to
4253 distinguish when des_prev == 1 as well; see
4254 previous comment. */
4256 struct c_expr mexpr
;
4257 c_parser_consume_token (parser
);
4258 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4259 && ((c_parser_peek_token (parser
)->id_kind
4261 || (c_parser_peek_token (parser
)->id_kind
4262 == C_ID_CLASSNAME
)))
4264 /* Type name receiver. */
4265 tree id
= c_parser_peek_token (parser
)->value
;
4266 c_parser_consume_token (parser
);
4267 rec
= objc_get_class_reference (id
);
4268 goto parse_message_args
;
4270 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4271 mark_exp_read (first
);
4272 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4273 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4274 goto array_desig_after_first
;
4275 /* Expression receiver. So far only one part
4276 without commas has been parsed; there might be
4277 more of the expression. */
4279 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4282 location_t comma_loc
, exp_loc
;
4283 comma_loc
= c_parser_peek_token (parser
)->location
;
4284 c_parser_consume_token (parser
);
4285 exp_loc
= c_parser_peek_token (parser
)->location
;
4286 next
= c_parser_expr_no_commas (parser
, NULL
);
4287 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4289 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4292 /* Now parse the objc-message-args. */
4293 args
= c_parser_objc_message_args (parser
);
4294 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4297 = objc_build_message_expr (rec
, args
);
4298 mexpr
.original_code
= ERROR_MARK
;
4299 mexpr
.original_type
= NULL
;
4300 /* Now parse and process the remainder of the
4301 initializer, starting with this message
4302 expression as a primary-expression. */
4303 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4306 c_parser_consume_token (parser
);
4307 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4308 mark_exp_read (first
);
4309 array_desig_after_first
:
4310 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4312 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4313 c_parser_consume_token (parser
);
4314 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4315 mark_exp_read (second
);
4319 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4321 c_parser_consume_token (parser
);
4322 set_init_index (first
, second
, braced_init_obstack
);
4324 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4325 "ISO C forbids specifying range of elements to initialize");
4328 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4334 if (c_parser_next_token_is (parser
, CPP_EQ
))
4337 pedwarn (des_loc
, OPT_Wpedantic
,
4338 "ISO C90 forbids specifying subobject to initialize");
4339 c_parser_consume_token (parser
);
4344 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4345 "obsolete use of designated initializer without %<=%>");
4349 init
.value
= error_mark_node
;
4350 init
.original_code
= ERROR_MARK
;
4351 init
.original_type
= NULL
;
4352 c_parser_error (parser
, "expected %<=%>");
4353 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4354 process_init_element (init
, false, braced_init_obstack
);
4360 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4363 /* Parse a nested initializer; as c_parser_initializer but parses
4364 initializers within braced lists, after any designators have been
4365 applied. If AFTER is not NULL then it is an Objective-C message
4366 expression which is the primary-expression starting the
4370 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4371 struct obstack
* braced_init_obstack
)
4374 gcc_assert (!after
|| c_dialect_objc ());
4375 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4376 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4379 location_t loc
= c_parser_peek_token (parser
)->location
;
4380 init
= c_parser_expr_no_commas (parser
, after
);
4381 if (init
.value
!= NULL_TREE
4382 && TREE_CODE (init
.value
) != STRING_CST
4383 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4384 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4386 process_init_element (init
, false, braced_init_obstack
);
4389 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4393 { block-item-list[opt] }
4394 { label-declarations block-item-list }
4398 block-item-list block-item
4410 { label-declarations block-item-list }
4413 __extension__ nested-declaration
4414 nested-function-definition
4418 label-declarations label-declaration
4421 __label__ identifier-list ;
4423 Allowing the mixing of declarations and code is new in C99. The
4424 GNU syntax also permits (not shown above) labels at the end of
4425 compound statements, which yield an error. We don't allow labels
4426 on declarations; this might seem like a natural extension, but
4427 there would be a conflict between attributes on the label and
4428 prefix attributes on the declaration. ??? The syntax follows the
4429 old parser in requiring something after label declarations.
4430 Although they are erroneous if the labels declared aren't defined,
4431 is it useful for the syntax to be this way?
4444 cancellation-point-directive */
4447 c_parser_compound_statement (c_parser
*parser
)
4450 location_t brace_loc
;
4451 brace_loc
= c_parser_peek_token (parser
)->location
;
4452 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4454 /* Ensure a scope is entered and left anyway to avoid confusion
4455 if we have just prepared to enter a function body. */
4456 stmt
= c_begin_compound_stmt (true);
4457 c_end_compound_stmt (brace_loc
, stmt
, true);
4458 return error_mark_node
;
4460 stmt
= c_begin_compound_stmt (true);
4461 c_parser_compound_statement_nostart (parser
);
4463 /* If the compound stmt contains array notations, then we expand them. */
4464 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4465 stmt
= expand_array_notation_exprs (stmt
);
4466 return c_end_compound_stmt (brace_loc
, stmt
, true);
4469 /* Parse a compound statement except for the opening brace. This is
4470 used for parsing both compound statements and statement expressions
4471 (which follow different paths to handling the opening). */
4474 c_parser_compound_statement_nostart (c_parser
*parser
)
4476 bool last_stmt
= false;
4477 bool last_label
= false;
4478 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4479 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4480 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4482 c_parser_consume_token (parser
);
4485 mark_valid_location_for_stdc_pragma (true);
4486 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4488 /* Read zero or more forward-declarations for labels that nested
4489 functions can jump to. */
4490 mark_valid_location_for_stdc_pragma (false);
4491 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4493 label_loc
= c_parser_peek_token (parser
)->location
;
4494 c_parser_consume_token (parser
);
4495 /* Any identifiers, including those declared as type names,
4500 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4502 c_parser_error (parser
, "expected identifier");
4506 = declare_label (c_parser_peek_token (parser
)->value
);
4507 C_DECLARED_LABEL_FLAG (label
) = 1;
4508 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4509 c_parser_consume_token (parser
);
4510 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4511 c_parser_consume_token (parser
);
4515 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4517 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4519 /* We must now have at least one statement, label or declaration. */
4520 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4522 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4523 c_parser_error (parser
, "expected declaration or statement");
4524 c_parser_consume_token (parser
);
4527 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4529 location_t loc
= c_parser_peek_token (parser
)->location
;
4530 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4531 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4532 || (c_parser_next_token_is (parser
, CPP_NAME
)
4533 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4535 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4536 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4538 label_loc
= c_parser_peek_token (parser
)->location
;
4541 mark_valid_location_for_stdc_pragma (false);
4542 c_parser_label (parser
);
4544 else if (!last_label
4545 && c_parser_next_tokens_start_declaration (parser
))
4548 mark_valid_location_for_stdc_pragma (false);
4549 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4553 (pedantic
&& !flag_isoc99
)
4555 : OPT_Wdeclaration_after_statement
,
4556 "ISO C90 forbids mixed declarations and code");
4559 else if (!last_label
4560 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4562 /* __extension__ can start a declaration, but is also an
4563 unary operator that can start an expression. Consume all
4564 but the last of a possible series of __extension__ to
4566 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4567 && (c_parser_peek_2nd_token (parser
)->keyword
4569 c_parser_consume_token (parser
);
4570 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4573 ext
= disable_extension_diagnostics ();
4574 c_parser_consume_token (parser
);
4576 mark_valid_location_for_stdc_pragma (false);
4577 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4579 /* Following the old parser, __extension__ does not
4580 disable this diagnostic. */
4581 restore_extension_diagnostics (ext
);
4583 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4585 : OPT_Wdeclaration_after_statement
,
4586 "ISO C90 forbids mixed declarations and code");
4592 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4594 /* External pragmas, and some omp pragmas, are not associated
4595 with regular c code, and so are not to be considered statements
4596 syntactically. This ensures that the user doesn't put them
4597 places that would turn into syntax errors if the directive
4599 if (c_parser_pragma (parser
, pragma_compound
))
4600 last_label
= false, last_stmt
= true;
4602 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4604 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4605 c_parser_error (parser
, "expected declaration or statement");
4608 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4610 if (parser
->in_if_block
)
4612 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4613 error_at (loc
, """expected %<}%> before %<else%>");
4618 error_at (loc
, "%<else%> without a previous %<if%>");
4619 c_parser_consume_token (parser
);
4628 mark_valid_location_for_stdc_pragma (false);
4629 c_parser_statement_after_labels (parser
);
4632 parser
->error
= false;
4635 error_at (label_loc
, "label at end of compound statement");
4636 c_parser_consume_token (parser
);
4637 /* Restore the value we started with. */
4638 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4641 /* Parse a label (C90 6.6.1, C99 6.8.1).
4644 identifier : attributes[opt]
4645 case constant-expression :
4651 case constant-expression ... constant-expression :
4653 The use of attributes on labels is a GNU extension. The syntax in
4654 GNU C accepts any expressions without commas, non-constant
4655 expressions being rejected later. */
4658 c_parser_label (c_parser
*parser
)
4660 location_t loc1
= c_parser_peek_token (parser
)->location
;
4661 tree label
= NULL_TREE
;
4662 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4665 c_parser_consume_token (parser
);
4666 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4667 if (c_parser_next_token_is (parser
, CPP_COLON
))
4669 c_parser_consume_token (parser
);
4670 label
= do_case (loc1
, exp1
, NULL_TREE
);
4672 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4674 c_parser_consume_token (parser
);
4675 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4676 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4677 label
= do_case (loc1
, exp1
, exp2
);
4680 c_parser_error (parser
, "expected %<:%> or %<...%>");
4682 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4684 c_parser_consume_token (parser
);
4685 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4686 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4690 tree name
= c_parser_peek_token (parser
)->value
;
4693 location_t loc2
= c_parser_peek_token (parser
)->location
;
4694 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4695 c_parser_consume_token (parser
);
4696 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4697 c_parser_consume_token (parser
);
4698 attrs
= c_parser_attributes (parser
);
4699 tlab
= define_label (loc2
, name
);
4702 decl_attributes (&tlab
, attrs
, 0);
4703 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4708 if (c_parser_next_tokens_start_declaration (parser
))
4710 error_at (c_parser_peek_token (parser
)->location
,
4711 "a label can only be part of a statement and "
4712 "a declaration is not a statement");
4713 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4714 /*static_assert_ok*/ true,
4715 /*empty_ok*/ true, /*nested*/ true,
4716 /*start_attr_ok*/ true, NULL
,
4722 /* Parse a statement (C90 6.6, C99 6.8).
4727 expression-statement
4735 expression-statement:
4738 selection-statement:
4742 iteration-statement:
4751 return expression[opt] ;
4764 objc-throw-statement
4765 objc-try-catch-statement
4766 objc-synchronized-statement
4768 objc-throw-statement:
4784 parallel-for-construct
4785 parallel-for-simd-construct
4786 parallel-sections-construct
4793 parallel-directive structured-block
4796 for-directive iteration-statement
4799 simd-directive iteration-statements
4802 for-simd-directive iteration-statements
4805 sections-directive section-scope
4808 single-directive structured-block
4810 parallel-for-construct:
4811 parallel-for-directive iteration-statement
4813 parallel-for-simd-construct:
4814 parallel-for-simd-directive iteration-statement
4816 parallel-sections-construct:
4817 parallel-sections-directive section-scope
4820 master-directive structured-block
4823 critical-directive structured-block
4826 atomic-directive expression-statement
4829 ordered-directive structured-block
4831 Transactional Memory:
4834 transaction-statement
4835 transaction-cancel-statement
4839 c_parser_statement (c_parser
*parser
)
4841 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4842 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4843 || (c_parser_next_token_is (parser
, CPP_NAME
)
4844 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4845 c_parser_label (parser
);
4846 c_parser_statement_after_labels (parser
);
4849 /* Parse a statement, other than a labeled statement. */
4852 c_parser_statement_after_labels (c_parser
*parser
)
4854 location_t loc
= c_parser_peek_token (parser
)->location
;
4855 tree stmt
= NULL_TREE
;
4856 bool in_if_block
= parser
->in_if_block
;
4857 parser
->in_if_block
= false;
4858 switch (c_parser_peek_token (parser
)->type
)
4860 case CPP_OPEN_BRACE
:
4861 add_stmt (c_parser_compound_statement (parser
));
4864 switch (c_parser_peek_token (parser
)->keyword
)
4867 c_parser_if_statement (parser
);
4870 c_parser_switch_statement (parser
);
4873 c_parser_while_statement (parser
, false);
4876 c_parser_do_statement (parser
, false);
4879 c_parser_for_statement (parser
, false);
4882 c_parser_consume_token (parser
);
4883 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4885 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4887 add_stmt (build_cilk_sync ());
4890 c_parser_consume_token (parser
);
4891 if (c_parser_next_token_is (parser
, CPP_NAME
))
4893 stmt
= c_finish_goto_label (loc
,
4894 c_parser_peek_token (parser
)->value
);
4895 c_parser_consume_token (parser
);
4897 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4901 c_parser_consume_token (parser
);
4902 val
= c_parser_expression (parser
);
4903 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4904 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4907 c_parser_error (parser
, "expected identifier or %<*%>");
4908 goto expect_semicolon
;
4910 c_parser_consume_token (parser
);
4911 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4912 goto expect_semicolon
;
4914 c_parser_consume_token (parser
);
4915 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4916 goto expect_semicolon
;
4918 c_parser_consume_token (parser
);
4919 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4921 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4922 c_parser_consume_token (parser
);
4926 struct c_expr expr
= c_parser_expression_conv (parser
);
4927 mark_exp_read (expr
.value
);
4928 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4929 goto expect_semicolon
;
4933 stmt
= c_parser_asm_statement (parser
);
4935 case RID_TRANSACTION_ATOMIC
:
4936 case RID_TRANSACTION_RELAXED
:
4937 stmt
= c_parser_transaction (parser
,
4938 c_parser_peek_token (parser
)->keyword
);
4940 case RID_TRANSACTION_CANCEL
:
4941 stmt
= c_parser_transaction_cancel (parser
);
4942 goto expect_semicolon
;
4944 gcc_assert (c_dialect_objc ());
4945 c_parser_consume_token (parser
);
4946 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4948 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4949 c_parser_consume_token (parser
);
4953 struct c_expr expr
= c_parser_expression (parser
);
4954 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4955 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4956 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4957 goto expect_semicolon
;
4961 gcc_assert (c_dialect_objc ());
4962 c_parser_objc_try_catch_finally_statement (parser
);
4964 case RID_AT_SYNCHRONIZED
:
4965 gcc_assert (c_dialect_objc ());
4966 c_parser_objc_synchronized_statement (parser
);
4973 c_parser_consume_token (parser
);
4975 case CPP_CLOSE_PAREN
:
4976 case CPP_CLOSE_SQUARE
:
4977 /* Avoid infinite loop in error recovery:
4978 c_parser_skip_until_found stops at a closing nesting
4979 delimiter without consuming it, but here we need to consume
4980 it to proceed further. */
4981 c_parser_error (parser
, "expected statement");
4982 c_parser_consume_token (parser
);
4985 c_parser_pragma (parser
, pragma_stmt
);
4989 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4991 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4994 /* Two cases cannot and do not have line numbers associated: If stmt
4995 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4996 cannot hold line numbers. But that's OK because the statement
4997 will either be changed to a MODIFY_EXPR during gimplification of
4998 the statement expr, or discarded. If stmt was compound, but
4999 without new variables, we will have skipped the creation of a
5000 BIND and will have a bare STATEMENT_LIST. But that's OK because
5001 (recursively) all of the component statements should already have
5002 line numbers assigned. ??? Can we discard no-op statements
5004 if (CAN_HAVE_LOCATION_P (stmt
)
5005 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5006 SET_EXPR_LOCATION (stmt
, loc
);
5008 parser
->in_if_block
= in_if_block
;
5011 /* Parse the condition from an if, do, while or for statements. */
5014 c_parser_condition (c_parser
*parser
)
5016 location_t loc
= c_parser_peek_token (parser
)->location
;
5018 cond
= c_parser_expression_conv (parser
).value
;
5019 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5020 cond
= c_fully_fold (cond
, false, NULL
);
5021 if (warn_sequence_point
)
5022 verify_sequence_points (cond
);
5026 /* Parse a parenthesized condition from an if, do or while statement.
5032 c_parser_paren_condition (c_parser
*parser
)
5035 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5036 return error_mark_node
;
5037 cond
= c_parser_condition (parser
);
5038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5042 /* Parse a statement which is a block in C99. */
5045 c_parser_c99_block_statement (c_parser
*parser
)
5047 tree block
= c_begin_compound_stmt (flag_isoc99
);
5048 location_t loc
= c_parser_peek_token (parser
)->location
;
5049 c_parser_statement (parser
);
5050 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5053 /* Parse the body of an if statement. This is just parsing a
5054 statement but (a) it is a block in C99, (b) we track whether the
5055 body is an if statement for the sake of -Wparentheses warnings, (c)
5056 we handle an empty body specially for the sake of -Wempty-body
5057 warnings, and (d) we call parser_compound_statement directly
5058 because c_parser_statement_after_labels resets
5059 parser->in_if_block. */
5062 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5064 tree block
= c_begin_compound_stmt (flag_isoc99
);
5065 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5066 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5067 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5068 || (c_parser_next_token_is (parser
, CPP_NAME
)
5069 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5070 c_parser_label (parser
);
5071 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5072 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5074 location_t loc
= c_parser_peek_token (parser
)->location
;
5075 add_stmt (build_empty_stmt (loc
));
5076 c_parser_consume_token (parser
);
5077 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5078 warning_at (loc
, OPT_Wempty_body
,
5079 "suggest braces around empty body in an %<if%> statement");
5081 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5082 add_stmt (c_parser_compound_statement (parser
));
5084 c_parser_statement_after_labels (parser
);
5085 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5088 /* Parse the else body of an if statement. This is just parsing a
5089 statement but (a) it is a block in C99, (b) we handle an empty body
5090 specially for the sake of -Wempty-body warnings. */
5093 c_parser_else_body (c_parser
*parser
)
5095 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5096 tree block
= c_begin_compound_stmt (flag_isoc99
);
5097 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5098 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5099 || (c_parser_next_token_is (parser
, CPP_NAME
)
5100 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5101 c_parser_label (parser
);
5102 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5104 location_t loc
= c_parser_peek_token (parser
)->location
;
5107 "suggest braces around empty body in an %<else%> statement");
5108 add_stmt (build_empty_stmt (loc
));
5109 c_parser_consume_token (parser
);
5112 c_parser_statement_after_labels (parser
);
5113 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5116 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5119 if ( expression ) statement
5120 if ( expression ) statement else statement
5124 c_parser_if_statement (c_parser
*parser
)
5129 bool first_if
= false;
5130 tree first_body
, second_body
;
5134 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5135 c_parser_consume_token (parser
);
5136 block
= c_begin_compound_stmt (flag_isoc99
);
5137 loc
= c_parser_peek_token (parser
)->location
;
5138 cond
= c_parser_paren_condition (parser
);
5139 in_if_block
= parser
->in_if_block
;
5140 parser
->in_if_block
= true;
5141 first_body
= c_parser_if_body (parser
, &first_if
);
5142 parser
->in_if_block
= in_if_block
;
5143 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5145 c_parser_consume_token (parser
);
5146 second_body
= c_parser_else_body (parser
);
5149 second_body
= NULL_TREE
;
5150 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5151 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5153 /* If the if statement contains array notations, then we expand them. */
5154 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5155 if_stmt
= fix_conditional_array_notations (if_stmt
);
5159 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5162 switch (expression) statement
5166 c_parser_switch_statement (c_parser
*parser
)
5169 tree block
, expr
, body
, save_break
;
5170 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5171 location_t switch_cond_loc
;
5172 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5173 c_parser_consume_token (parser
);
5174 block
= c_begin_compound_stmt (flag_isoc99
);
5175 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5177 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5178 ce
= c_parser_expression (parser
);
5179 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5181 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5183 error_at (switch_cond_loc
,
5184 "array notations cannot be used as a condition for switch "
5186 expr
= error_mark_node
;
5188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5192 switch_cond_loc
= UNKNOWN_LOCATION
;
5193 expr
= error_mark_node
;
5195 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5196 save_break
= c_break_label
;
5197 c_break_label
= NULL_TREE
;
5198 body
= c_parser_c99_block_statement (parser
);
5199 c_finish_case (body
);
5202 location_t here
= c_parser_peek_token (parser
)->location
;
5203 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5204 SET_EXPR_LOCATION (t
, here
);
5207 c_break_label
= save_break
;
5208 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5211 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5214 while (expression) statement
5218 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5220 tree block
, cond
, body
, save_break
, save_cont
;
5222 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5223 c_parser_consume_token (parser
);
5224 block
= c_begin_compound_stmt (flag_isoc99
);
5225 loc
= c_parser_peek_token (parser
)->location
;
5226 cond
= c_parser_paren_condition (parser
);
5227 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5229 error_at (loc
, "array notations cannot be used as a condition for while "
5231 cond
= error_mark_node
;
5234 if (ivdep
&& cond
!= error_mark_node
)
5235 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5236 build_int_cst (integer_type_node
,
5237 annot_expr_ivdep_kind
));
5238 save_break
= c_break_label
;
5239 c_break_label
= NULL_TREE
;
5240 save_cont
= c_cont_label
;
5241 c_cont_label
= NULL_TREE
;
5242 body
= c_parser_c99_block_statement (parser
);
5243 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5244 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5245 c_break_label
= save_break
;
5246 c_cont_label
= save_cont
;
5249 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5252 do statement while ( expression ) ;
5256 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5258 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5260 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5261 c_parser_consume_token (parser
);
5262 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5263 warning_at (c_parser_peek_token (parser
)->location
,
5265 "suggest braces around empty body in %<do%> statement");
5266 block
= c_begin_compound_stmt (flag_isoc99
);
5267 loc
= c_parser_peek_token (parser
)->location
;
5268 save_break
= c_break_label
;
5269 c_break_label
= NULL_TREE
;
5270 save_cont
= c_cont_label
;
5271 c_cont_label
= NULL_TREE
;
5272 body
= c_parser_c99_block_statement (parser
);
5273 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5274 new_break
= c_break_label
;
5275 c_break_label
= save_break
;
5276 new_cont
= c_cont_label
;
5277 c_cont_label
= save_cont
;
5278 cond
= c_parser_paren_condition (parser
);
5279 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5281 error_at (loc
, "array notations cannot be used as a condition for a "
5282 "do-while statement");
5283 cond
= error_mark_node
;
5285 if (ivdep
&& cond
!= error_mark_node
)
5286 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5287 build_int_cst (integer_type_node
,
5288 annot_expr_ivdep_kind
));
5289 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5290 c_parser_skip_to_end_of_block_or_statement (parser
);
5291 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5292 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5295 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5298 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5299 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5301 The form with a declaration is new in C99.
5303 ??? In accordance with the old parser, the declaration may be a
5304 nested function, which is then rejected in check_for_loop_decls,
5305 but does it make any sense for this to be included in the grammar?
5306 Note in particular that the nested function does not include a
5307 trailing ';', whereas the "declaration" production includes one.
5308 Also, can we reject bad declarations earlier and cheaper than
5309 check_for_loop_decls?
5311 In Objective-C, there are two additional variants:
5314 for ( expression in expresssion ) statement
5315 for ( declaration in expression ) statement
5317 This is inconsistent with C, because the second variant is allowed
5318 even if c99 is not enabled.
5320 The rest of the comment documents these Objective-C foreach-statement.
5322 Here is the canonical example of the first variant:
5323 for (object in array) { do something with object }
5324 we call the first expression ("object") the "object_expression" and
5325 the second expression ("array") the "collection_expression".
5326 object_expression must be an lvalue of type "id" (a generic Objective-C
5327 object) because the loop works by assigning to object_expression the
5328 various objects from the collection_expression. collection_expression
5329 must evaluate to something of type "id" which responds to the method
5330 countByEnumeratingWithState:objects:count:.
5332 The canonical example of the second variant is:
5333 for (id object in array) { do something with object }
5334 which is completely equivalent to
5337 for (object in array) { do something with object }
5339 Note that initizializing 'object' in some way (eg, "for ((object =
5340 xxx) in array) { do something with object }") is possibly
5341 technically valid, but completely pointless as 'object' will be
5342 assigned to something else as soon as the loop starts. We should
5343 most likely reject it (TODO).
5345 The beginning of the Objective-C foreach-statement looks exactly
5346 like the beginning of the for-statement, and we can tell it is a
5347 foreach-statement only because the initial declaration or
5348 expression is terminated by 'in' instead of ';'.
5352 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5354 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5355 /* The following are only used when parsing an ObjC foreach statement. */
5356 tree object_expression
;
5357 /* Silence the bogus uninitialized warning. */
5358 tree collection_expression
= NULL
;
5359 location_t loc
= c_parser_peek_token (parser
)->location
;
5360 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5361 bool is_foreach_statement
= false;
5362 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5363 c_parser_consume_token (parser
);
5364 /* Open a compound statement in Objective-C as well, just in case this is
5365 as foreach expression. */
5366 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5367 cond
= error_mark_node
;
5368 incr
= error_mark_node
;
5369 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5371 /* Parse the initialization declaration or expression. */
5372 object_expression
= error_mark_node
;
5373 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5374 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5376 parser
->objc_could_be_foreach_context
= false;
5377 c_parser_consume_token (parser
);
5378 c_finish_expr_stmt (loc
, NULL_TREE
);
5380 else if (c_parser_next_tokens_start_declaration (parser
))
5382 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5383 &object_expression
, vNULL
);
5384 parser
->objc_could_be_foreach_context
= false;
5386 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5388 c_parser_consume_token (parser
);
5389 is_foreach_statement
= true;
5390 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5391 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5394 check_for_loop_decls (for_loc
, flag_isoc99
);
5396 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5398 /* __extension__ can start a declaration, but is also an
5399 unary operator that can start an expression. Consume all
5400 but the last of a possible series of __extension__ to
5402 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5403 && (c_parser_peek_2nd_token (parser
)->keyword
5405 c_parser_consume_token (parser
);
5406 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5409 ext
= disable_extension_diagnostics ();
5410 c_parser_consume_token (parser
);
5411 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5412 true, &object_expression
, vNULL
);
5413 parser
->objc_could_be_foreach_context
= false;
5415 restore_extension_diagnostics (ext
);
5416 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5418 c_parser_consume_token (parser
);
5419 is_foreach_statement
= true;
5420 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5421 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5424 check_for_loop_decls (for_loc
, flag_isoc99
);
5434 tree init_expression
;
5435 ce
= c_parser_expression (parser
);
5436 init_expression
= ce
.value
;
5437 parser
->objc_could_be_foreach_context
= false;
5438 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5440 c_parser_consume_token (parser
);
5441 is_foreach_statement
= true;
5442 if (! lvalue_p (init_expression
))
5443 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5444 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5448 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5449 init_expression
= ce
.value
;
5450 c_finish_expr_stmt (loc
, init_expression
);
5451 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5455 /* Parse the loop condition. In the case of a foreach
5456 statement, there is no loop condition. */
5457 gcc_assert (!parser
->objc_could_be_foreach_context
);
5458 if (!is_foreach_statement
)
5460 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5464 c_parser_error (parser
, "missing loop condition in loop with "
5465 "%<GCC ivdep%> pragma");
5466 cond
= error_mark_node
;
5470 c_parser_consume_token (parser
);
5476 cond
= c_parser_condition (parser
);
5477 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5479 error_at (loc
, "array notations cannot be used in a "
5480 "condition for a for-loop");
5481 cond
= error_mark_node
;
5483 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5486 if (ivdep
&& cond
!= error_mark_node
)
5487 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5488 build_int_cst (integer_type_node
,
5489 annot_expr_ivdep_kind
));
5491 /* Parse the increment expression (the third expression in a
5492 for-statement). In the case of a foreach-statement, this is
5493 the expression that follows the 'in'. */
5494 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5496 if (is_foreach_statement
)
5498 c_parser_error (parser
, "missing collection in fast enumeration");
5499 collection_expression
= error_mark_node
;
5502 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5506 if (is_foreach_statement
)
5507 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5511 struct c_expr ce
= c_parser_expression (parser
);
5512 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5513 incr
= c_process_expr_stmt (loc
, ce
.value
);
5516 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5518 save_break
= c_break_label
;
5519 c_break_label
= NULL_TREE
;
5520 save_cont
= c_cont_label
;
5521 c_cont_label
= NULL_TREE
;
5522 body
= c_parser_c99_block_statement (parser
);
5523 if (is_foreach_statement
)
5524 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5526 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5527 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5528 c_break_label
= save_break
;
5529 c_cont_label
= save_cont
;
5532 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5533 statement with inputs, outputs, clobbers, and volatile tag
5537 asm type-qualifier[opt] ( asm-argument ) ;
5538 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5542 asm-string-literal : asm-operands[opt]
5543 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5544 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5547 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5550 Qualifiers other than volatile are accepted in the syntax but
5554 c_parser_asm_statement (c_parser
*parser
)
5556 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5557 bool simple
, is_goto
;
5558 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5559 int section
, nsections
;
5561 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5562 c_parser_consume_token (parser
);
5563 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5565 quals
= c_parser_peek_token (parser
)->value
;
5566 c_parser_consume_token (parser
);
5568 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5569 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5571 warning_at (c_parser_peek_token (parser
)->location
,
5573 "%E qualifier ignored on asm",
5574 c_parser_peek_token (parser
)->value
);
5576 c_parser_consume_token (parser
);
5582 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5584 c_parser_consume_token (parser
);
5588 /* ??? Follow the C++ parser rather than using the
5589 lex_untranslated_string kludge. */
5590 parser
->lex_untranslated_string
= true;
5593 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5596 str
= c_parser_asm_string_literal (parser
);
5597 if (str
== NULL_TREE
)
5598 goto error_close_paren
;
5601 outputs
= NULL_TREE
;
5603 clobbers
= NULL_TREE
;
5606 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5609 /* Parse each colon-delimited section of operands. */
5610 nsections
= 3 + is_goto
;
5611 for (section
= 0; section
< nsections
; ++section
)
5613 if (!c_parser_require (parser
, CPP_COLON
,
5616 : "expected %<:%> or %<)%>"))
5617 goto error_close_paren
;
5619 /* Once past any colon, we're no longer a simple asm. */
5622 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5623 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5628 /* For asm goto, we don't allow output operands, but reserve
5629 the slot for a future extension that does allow them. */
5631 outputs
= c_parser_asm_operands (parser
);
5634 inputs
= c_parser_asm_operands (parser
);
5637 clobbers
= c_parser_asm_clobbers (parser
);
5640 labels
= c_parser_asm_goto_operands (parser
);
5646 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5651 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5653 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5657 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5658 c_parser_skip_to_end_of_block_or_statement (parser
);
5660 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5661 clobbers
, labels
, simple
));
5664 parser
->lex_untranslated_string
= false;
5668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5672 /* Parse asm operands, a GNU extension.
5676 asm-operands , asm-operand
5679 asm-string-literal ( expression )
5680 [ identifier ] asm-string-literal ( expression )
5684 c_parser_asm_operands (c_parser
*parser
)
5686 tree list
= NULL_TREE
;
5691 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5693 c_parser_consume_token (parser
);
5694 if (c_parser_next_token_is (parser
, CPP_NAME
))
5696 tree id
= c_parser_peek_token (parser
)->value
;
5697 c_parser_consume_token (parser
);
5698 name
= build_string (IDENTIFIER_LENGTH (id
),
5699 IDENTIFIER_POINTER (id
));
5703 c_parser_error (parser
, "expected identifier");
5704 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5707 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5712 str
= c_parser_asm_string_literal (parser
);
5713 if (str
== NULL_TREE
)
5715 parser
->lex_untranslated_string
= false;
5716 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5718 parser
->lex_untranslated_string
= true;
5721 expr
= c_parser_expression (parser
);
5722 mark_exp_read (expr
.value
);
5723 parser
->lex_untranslated_string
= true;
5724 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5726 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5729 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5731 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5732 c_parser_consume_token (parser
);
5739 /* Parse asm clobbers, a GNU extension.
5743 asm-clobbers , asm-string-literal
5747 c_parser_asm_clobbers (c_parser
*parser
)
5749 tree list
= NULL_TREE
;
5752 tree str
= c_parser_asm_string_literal (parser
);
5754 list
= tree_cons (NULL_TREE
, str
, list
);
5757 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5758 c_parser_consume_token (parser
);
5765 /* Parse asm goto labels, a GNU extension.
5769 asm-goto-operands , identifier
5773 c_parser_asm_goto_operands (c_parser
*parser
)
5775 tree list
= NULL_TREE
;
5780 if (c_parser_next_token_is (parser
, CPP_NAME
))
5782 c_token
*tok
= c_parser_peek_token (parser
);
5784 label
= lookup_label_for_goto (tok
->location
, name
);
5785 c_parser_consume_token (parser
);
5786 TREE_USED (label
) = 1;
5790 c_parser_error (parser
, "expected identifier");
5794 name
= build_string (IDENTIFIER_LENGTH (name
),
5795 IDENTIFIER_POINTER (name
));
5796 list
= tree_cons (name
, label
, list
);
5797 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5798 c_parser_consume_token (parser
);
5800 return nreverse (list
);
5804 /* Parse an expression other than a compound expression; that is, an
5805 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5806 NULL then it is an Objective-C message expression which is the
5807 primary-expression starting the expression as an initializer.
5809 assignment-expression:
5810 conditional-expression
5811 unary-expression assignment-operator assignment-expression
5813 assignment-operator: one of
5814 = *= /= %= += -= <<= >>= &= ^= |=
5816 In GNU C we accept any conditional expression on the LHS and
5817 diagnose the invalid lvalue rather than producing a syntax
5820 static struct c_expr
5821 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5822 tree omp_atomic_lhs
)
5824 struct c_expr lhs
, rhs
, ret
;
5825 enum tree_code code
;
5826 location_t op_location
, exp_location
;
5827 gcc_assert (!after
|| c_dialect_objc ());
5828 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5829 op_location
= c_parser_peek_token (parser
)->location
;
5830 switch (c_parser_peek_token (parser
)->type
)
5839 code
= TRUNC_DIV_EXPR
;
5842 code
= TRUNC_MOD_EXPR
;
5857 code
= BIT_AND_EXPR
;
5860 code
= BIT_XOR_EXPR
;
5863 code
= BIT_IOR_EXPR
;
5868 c_parser_consume_token (parser
);
5869 exp_location
= c_parser_peek_token (parser
)->location
;
5870 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5871 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5873 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5874 code
, exp_location
, rhs
.value
,
5876 if (code
== NOP_EXPR
)
5877 ret
.original_code
= MODIFY_EXPR
;
5880 TREE_NO_WARNING (ret
.value
) = 1;
5881 ret
.original_code
= ERROR_MARK
;
5883 ret
.original_type
= NULL
;
5887 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5888 is not NULL then it is an Objective-C message expression which is
5889 the primary-expression starting the expression as an initializer.
5891 conditional-expression:
5892 logical-OR-expression
5893 logical-OR-expression ? expression : conditional-expression
5897 conditional-expression:
5898 logical-OR-expression ? : conditional-expression
5901 static struct c_expr
5902 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5903 tree omp_atomic_lhs
)
5905 struct c_expr cond
, exp1
, exp2
, ret
;
5906 location_t cond_loc
, colon_loc
, middle_loc
;
5908 gcc_assert (!after
|| c_dialect_objc ());
5910 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5912 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5914 cond_loc
= c_parser_peek_token (parser
)->location
;
5915 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5916 c_parser_consume_token (parser
);
5917 if (c_parser_next_token_is (parser
, CPP_COLON
))
5919 tree eptype
= NULL_TREE
;
5921 middle_loc
= c_parser_peek_token (parser
)->location
;
5922 pedwarn (middle_loc
, OPT_Wpedantic
,
5923 "ISO C forbids omitting the middle term of a ?: expression");
5924 warn_for_omitted_condop (middle_loc
, cond
.value
);
5925 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5927 eptype
= TREE_TYPE (cond
.value
);
5928 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5930 /* Make sure first operand is calculated only once. */
5931 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5933 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5934 exp1
.original_type
= NULL
;
5935 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5936 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5941 = c_objc_common_truthvalue_conversion
5942 (cond_loc
, default_conversion (cond
.value
));
5943 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5944 exp1
= c_parser_expression_conv (parser
);
5945 mark_exp_read (exp1
.value
);
5946 c_inhibit_evaluation_warnings
+=
5947 ((cond
.value
== truthvalue_true_node
)
5948 - (cond
.value
== truthvalue_false_node
));
5951 colon_loc
= c_parser_peek_token (parser
)->location
;
5952 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5954 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5955 ret
.value
= error_mark_node
;
5956 ret
.original_code
= ERROR_MARK
;
5957 ret
.original_type
= NULL
;
5961 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5962 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5963 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5965 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5966 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5967 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5968 exp1
.value
, exp1
.original_type
,
5969 exp2
.value
, exp2
.original_type
);
5970 ret
.original_code
= ERROR_MARK
;
5971 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5972 ret
.original_type
= NULL
;
5977 /* If both sides are enum type, the default conversion will have
5978 made the type of the result be an integer type. We want to
5979 remember the enum types we started with. */
5980 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5981 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5982 ret
.original_type
= ((t1
!= error_mark_node
5983 && t2
!= error_mark_node
5984 && (TYPE_MAIN_VARIANT (t1
)
5985 == TYPE_MAIN_VARIANT (t2
)))
5992 /* Parse a binary expression; that is, a logical-OR-expression (C90
5993 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5994 an Objective-C message expression which is the primary-expression
5995 starting the expression as an initializer.
5997 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5998 when it should be the unfolded lhs. In a valid OpenMP source,
5999 one of the operands of the toplevel binary expression must be equal
6000 to it. In that case, just return a build2 created binary operation
6001 rather than result of parser_build_binary_op.
6003 multiplicative-expression:
6005 multiplicative-expression * cast-expression
6006 multiplicative-expression / cast-expression
6007 multiplicative-expression % cast-expression
6009 additive-expression:
6010 multiplicative-expression
6011 additive-expression + multiplicative-expression
6012 additive-expression - multiplicative-expression
6016 shift-expression << additive-expression
6017 shift-expression >> additive-expression
6019 relational-expression:
6021 relational-expression < shift-expression
6022 relational-expression > shift-expression
6023 relational-expression <= shift-expression
6024 relational-expression >= shift-expression
6026 equality-expression:
6027 relational-expression
6028 equality-expression == relational-expression
6029 equality-expression != relational-expression
6033 AND-expression & equality-expression
6035 exclusive-OR-expression:
6037 exclusive-OR-expression ^ AND-expression
6039 inclusive-OR-expression:
6040 exclusive-OR-expression
6041 inclusive-OR-expression | exclusive-OR-expression
6043 logical-AND-expression:
6044 inclusive-OR-expression
6045 logical-AND-expression && inclusive-OR-expression
6047 logical-OR-expression:
6048 logical-AND-expression
6049 logical-OR-expression || logical-AND-expression
6052 static struct c_expr
6053 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6054 tree omp_atomic_lhs
)
6056 /* A binary expression is parsed using operator-precedence parsing,
6057 with the operands being cast expressions. All the binary
6058 operators are left-associative. Thus a binary expression is of
6061 E0 op1 E1 op2 E2 ...
6063 which we represent on a stack. On the stack, the precedence
6064 levels are strictly increasing. When a new operator is
6065 encountered of higher precedence than that at the top of the
6066 stack, it is pushed; its LHS is the top expression, and its RHS
6067 is everything parsed until it is popped. When a new operator is
6068 encountered with precedence less than or equal to that at the top
6069 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6070 by the result of the operation until the operator at the top of
6071 the stack has lower precedence than the new operator or there is
6072 only one element on the stack; then the top expression is the LHS
6073 of the new operator. In the case of logical AND and OR
6074 expressions, we also need to adjust c_inhibit_evaluation_warnings
6075 as appropriate when the operators are pushed and popped. */
6078 /* The expression at this stack level. */
6080 /* The precedence of the operator on its left, PREC_NONE at the
6081 bottom of the stack. */
6082 enum c_parser_prec prec
;
6083 /* The operation on its left. */
6085 /* The source location of this operation. */
6089 /* Location of the binary operator. */
6090 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6093 switch (stack[sp].op) \
6095 case TRUTH_ANDIF_EXPR: \
6096 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6097 == truthvalue_false_node); \
6099 case TRUTH_ORIF_EXPR: \
6100 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6101 == truthvalue_true_node); \
6106 stack[sp - 1].expr \
6107 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6108 stack[sp - 1].expr, true, true); \
6110 = convert_lvalue_to_rvalue (stack[sp].loc, \
6111 stack[sp].expr, true, true); \
6112 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6113 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6114 && ((1 << stack[sp].prec) \
6115 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6116 | PREC_ADD | PREC_MULT))) \
6117 && stack[sp].op != TRUNC_MOD_EXPR \
6118 && stack[0].expr.value != error_mark_node \
6119 && stack[1].expr.value != error_mark_node \
6120 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6121 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6122 stack[0].expr.value \
6123 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6124 stack[0].expr.value, stack[1].expr.value); \
6126 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6128 stack[sp - 1].expr, \
6132 gcc_assert (!after
|| c_dialect_objc ());
6133 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6134 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6135 stack
[0].prec
= PREC_NONE
;
6139 enum c_parser_prec oprec
;
6140 enum tree_code ocode
;
6143 switch (c_parser_peek_token (parser
)->type
)
6151 ocode
= TRUNC_DIV_EXPR
;
6155 ocode
= TRUNC_MOD_EXPR
;
6167 ocode
= LSHIFT_EXPR
;
6171 ocode
= RSHIFT_EXPR
;
6185 case CPP_GREATER_EQ
:
6198 oprec
= PREC_BITAND
;
6199 ocode
= BIT_AND_EXPR
;
6202 oprec
= PREC_BITXOR
;
6203 ocode
= BIT_XOR_EXPR
;
6207 ocode
= BIT_IOR_EXPR
;
6210 oprec
= PREC_LOGAND
;
6211 ocode
= TRUTH_ANDIF_EXPR
;
6215 ocode
= TRUTH_ORIF_EXPR
;
6218 /* Not a binary operator, so end of the binary
6222 binary_loc
= c_parser_peek_token (parser
)->location
;
6223 while (oprec
<= stack
[sp
].prec
)
6225 c_parser_consume_token (parser
);
6228 case TRUTH_ANDIF_EXPR
:
6230 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6231 stack
[sp
].expr
, true, true);
6232 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6233 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6234 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6235 == truthvalue_false_node
);
6237 case TRUTH_ORIF_EXPR
:
6239 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6240 stack
[sp
].expr
, true, true);
6241 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6242 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6243 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6244 == truthvalue_true_node
);
6250 stack
[sp
].loc
= binary_loc
;
6251 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6252 stack
[sp
].prec
= oprec
;
6253 stack
[sp
].op
= ocode
;
6254 stack
[sp
].loc
= binary_loc
;
6259 return stack
[0].expr
;
6263 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6264 NULL then it is an Objective-C message expression which is the
6265 primary-expression starting the expression as an initializer.
6269 ( type-name ) unary-expression
6272 static struct c_expr
6273 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6275 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6276 gcc_assert (!after
|| c_dialect_objc ());
6278 return c_parser_postfix_expression_after_primary (parser
,
6280 /* If the expression begins with a parenthesized type name, it may
6281 be either a cast or a compound literal; we need to see whether
6282 the next character is '{' to tell the difference. If not, it is
6283 an unary expression. Full detection of unknown typenames here
6284 would require a 3-token lookahead. */
6285 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6286 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6288 struct c_type_name
*type_name
;
6291 c_parser_consume_token (parser
);
6292 type_name
= c_parser_type_name (parser
);
6293 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6294 if (type_name
== NULL
)
6296 ret
.value
= error_mark_node
;
6297 ret
.original_code
= ERROR_MARK
;
6298 ret
.original_type
= NULL
;
6302 /* Save casted types in the function's used types hash table. */
6303 used_types_insert (type_name
->specs
->type
);
6305 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6306 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6309 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6310 expr
= c_parser_cast_expression (parser
, NULL
);
6311 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6313 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6314 ret
.original_code
= ERROR_MARK
;
6315 ret
.original_type
= NULL
;
6319 return c_parser_unary_expression (parser
);
6322 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6328 unary-operator cast-expression
6329 sizeof unary-expression
6330 sizeof ( type-name )
6332 unary-operator: one of
6338 __alignof__ unary-expression
6339 __alignof__ ( type-name )
6342 (C11 permits _Alignof with type names only.)
6344 unary-operator: one of
6345 __extension__ __real__ __imag__
6347 Transactional Memory:
6350 transaction-expression
6352 In addition, the GNU syntax treats ++ and -- as unary operators, so
6353 they may be applied to cast expressions with errors for non-lvalues
6356 static struct c_expr
6357 c_parser_unary_expression (c_parser
*parser
)
6360 struct c_expr ret
, op
;
6361 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6363 ret
.original_code
= ERROR_MARK
;
6364 ret
.original_type
= NULL
;
6365 switch (c_parser_peek_token (parser
)->type
)
6368 c_parser_consume_token (parser
);
6369 exp_loc
= c_parser_peek_token (parser
)->location
;
6370 op
= c_parser_cast_expression (parser
, NULL
);
6372 /* If there is array notations in op, we expand them. */
6373 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6374 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6377 op
= default_function_array_read_conversion (exp_loc
, op
);
6378 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6380 case CPP_MINUS_MINUS
:
6381 c_parser_consume_token (parser
);
6382 exp_loc
= c_parser_peek_token (parser
)->location
;
6383 op
= c_parser_cast_expression (parser
, NULL
);
6385 /* If there is array notations in op, we expand them. */
6386 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6387 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6390 op
= default_function_array_read_conversion (exp_loc
, op
);
6391 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6394 c_parser_consume_token (parser
);
6395 op
= c_parser_cast_expression (parser
, NULL
);
6396 mark_exp_read (op
.value
);
6397 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6399 c_parser_consume_token (parser
);
6400 exp_loc
= c_parser_peek_token (parser
)->location
;
6401 op
= c_parser_cast_expression (parser
, NULL
);
6402 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6403 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6406 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6409 "traditional C rejects the unary plus operator");
6410 c_parser_consume_token (parser
);
6411 exp_loc
= c_parser_peek_token (parser
)->location
;
6412 op
= c_parser_cast_expression (parser
, NULL
);
6413 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6414 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6416 c_parser_consume_token (parser
);
6417 exp_loc
= c_parser_peek_token (parser
)->location
;
6418 op
= c_parser_cast_expression (parser
, NULL
);
6419 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6420 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6422 c_parser_consume_token (parser
);
6423 exp_loc
= c_parser_peek_token (parser
)->location
;
6424 op
= c_parser_cast_expression (parser
, NULL
);
6425 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6426 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6428 c_parser_consume_token (parser
);
6429 exp_loc
= c_parser_peek_token (parser
)->location
;
6430 op
= c_parser_cast_expression (parser
, NULL
);
6431 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6432 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6434 /* Refer to the address of a label as a pointer. */
6435 c_parser_consume_token (parser
);
6436 if (c_parser_next_token_is (parser
, CPP_NAME
))
6438 ret
.value
= finish_label_address_expr
6439 (c_parser_peek_token (parser
)->value
, op_loc
);
6440 c_parser_consume_token (parser
);
6444 c_parser_error (parser
, "expected identifier");
6445 ret
.value
= error_mark_node
;
6449 switch (c_parser_peek_token (parser
)->keyword
)
6452 return c_parser_sizeof_expression (parser
);
6454 return c_parser_alignof_expression (parser
);
6456 c_parser_consume_token (parser
);
6457 ext
= disable_extension_diagnostics ();
6458 ret
= c_parser_cast_expression (parser
, NULL
);
6459 restore_extension_diagnostics (ext
);
6462 c_parser_consume_token (parser
);
6463 exp_loc
= c_parser_peek_token (parser
)->location
;
6464 op
= c_parser_cast_expression (parser
, NULL
);
6465 op
= default_function_array_conversion (exp_loc
, op
);
6466 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6468 c_parser_consume_token (parser
);
6469 exp_loc
= c_parser_peek_token (parser
)->location
;
6470 op
= c_parser_cast_expression (parser
, NULL
);
6471 op
= default_function_array_conversion (exp_loc
, op
);
6472 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6473 case RID_TRANSACTION_ATOMIC
:
6474 case RID_TRANSACTION_RELAXED
:
6475 return c_parser_transaction_expression (parser
,
6476 c_parser_peek_token (parser
)->keyword
);
6478 return c_parser_postfix_expression (parser
);
6481 return c_parser_postfix_expression (parser
);
6485 /* Parse a sizeof expression. */
6487 static struct c_expr
6488 c_parser_sizeof_expression (c_parser
*parser
)
6491 location_t expr_loc
;
6492 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6493 c_parser_consume_token (parser
);
6494 c_inhibit_evaluation_warnings
++;
6496 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6497 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6499 /* Either sizeof ( type-name ) or sizeof unary-expression
6500 starting with a compound literal. */
6501 struct c_type_name
*type_name
;
6502 c_parser_consume_token (parser
);
6503 expr_loc
= c_parser_peek_token (parser
)->location
;
6504 type_name
= c_parser_type_name (parser
);
6505 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6506 if (type_name
== NULL
)
6509 c_inhibit_evaluation_warnings
--;
6511 ret
.value
= error_mark_node
;
6512 ret
.original_code
= ERROR_MARK
;
6513 ret
.original_type
= NULL
;
6516 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6517 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6522 /* sizeof ( type-name ). */
6523 c_inhibit_evaluation_warnings
--;
6525 return c_expr_sizeof_type (expr_loc
, type_name
);
6530 expr_loc
= c_parser_peek_token (parser
)->location
;
6531 expr
= c_parser_unary_expression (parser
);
6533 c_inhibit_evaluation_warnings
--;
6535 mark_exp_read (expr
.value
);
6536 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6537 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6538 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6539 return c_expr_sizeof_expr (expr_loc
, expr
);
6542 /* Parse an alignof expression. */
6544 static struct c_expr
6545 c_parser_alignof_expression (c_parser
*parser
)
6548 location_t loc
= c_parser_peek_token (parser
)->location
;
6549 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6550 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6551 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6553 /* A diagnostic is not required for the use of this identifier in
6554 the implementation namespace; only diagnose it for the C11
6555 spelling because of existing code using the other spellings. */
6556 if (!flag_isoc11
&& is_c11_alignof
)
6559 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6562 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6565 c_parser_consume_token (parser
);
6566 c_inhibit_evaluation_warnings
++;
6568 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6569 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6571 /* Either __alignof__ ( type-name ) or __alignof__
6572 unary-expression starting with a compound literal. */
6574 struct c_type_name
*type_name
;
6576 c_parser_consume_token (parser
);
6577 loc
= c_parser_peek_token (parser
)->location
;
6578 type_name
= c_parser_type_name (parser
);
6579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6580 if (type_name
== NULL
)
6583 c_inhibit_evaluation_warnings
--;
6585 ret
.value
= error_mark_node
;
6586 ret
.original_code
= ERROR_MARK
;
6587 ret
.original_type
= NULL
;
6590 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6592 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6597 /* alignof ( type-name ). */
6598 c_inhibit_evaluation_warnings
--;
6600 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6602 false, is_c11_alignof
, 1);
6603 ret
.original_code
= ERROR_MARK
;
6604 ret
.original_type
= NULL
;
6610 expr
= c_parser_unary_expression (parser
);
6612 mark_exp_read (expr
.value
);
6613 c_inhibit_evaluation_warnings
--;
6615 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6617 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6618 ret
.original_code
= ERROR_MARK
;
6619 ret
.original_type
= NULL
;
6624 /* Helper function to read arguments of builtins which are interfaces
6625 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6626 others. The name of the builtin is passed using BNAME parameter.
6627 Function returns true if there were no errors while parsing and
6628 stores the arguments in CEXPR_LIST. */
6630 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6631 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6634 location_t loc
= c_parser_peek_token (parser
)->location
;
6635 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6637 bool saved_force_folding_builtin_constant_p
;
6639 *ret_cexpr_list
= NULL
;
6640 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6642 error_at (loc
, "cannot take address of %qs", bname
);
6646 c_parser_consume_token (parser
);
6648 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6650 c_parser_consume_token (parser
);
6654 saved_force_folding_builtin_constant_p
6655 = force_folding_builtin_constant_p
;
6656 force_folding_builtin_constant_p
|= choose_expr_p
;
6657 expr
= c_parser_expr_no_commas (parser
, NULL
);
6658 force_folding_builtin_constant_p
6659 = saved_force_folding_builtin_constant_p
;
6660 vec_alloc (cexpr_list
, 1);
6661 vec_safe_push (cexpr_list
, expr
);
6662 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6664 c_parser_consume_token (parser
);
6665 expr
= c_parser_expr_no_commas (parser
, NULL
);
6666 vec_safe_push (cexpr_list
, expr
);
6669 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6672 *ret_cexpr_list
= cexpr_list
;
6676 /* This represents a single generic-association. */
6678 struct c_generic_association
6680 /* The location of the starting token of the type. */
6681 location_t type_location
;
6682 /* The association's type, or NULL_TREE for 'default'. */
6684 /* The association's expression. */
6685 struct c_expr expression
;
6688 /* Parse a generic-selection. (C11 6.5.1.1).
6691 _Generic ( assignment-expression , generic-assoc-list )
6695 generic-assoc-list , generic-association
6697 generic-association:
6698 type-name : assignment-expression
6699 default : assignment-expression
6702 static struct c_expr
6703 c_parser_generic_selection (c_parser
*parser
)
6705 vec
<c_generic_association
> associations
= vNULL
;
6706 struct c_expr selector
, error_expr
;
6708 struct c_generic_association matched_assoc
;
6709 bool match_found
= false;
6710 location_t generic_loc
, selector_loc
;
6712 error_expr
.original_code
= ERROR_MARK
;
6713 error_expr
.original_type
= NULL
;
6714 error_expr
.value
= error_mark_node
;
6715 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6716 matched_assoc
.type
= NULL_TREE
;
6717 matched_assoc
.expression
= error_expr
;
6719 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6720 generic_loc
= c_parser_peek_token (parser
)->location
;
6721 c_parser_consume_token (parser
);
6725 pedwarn (generic_loc
, OPT_Wpedantic
,
6726 "ISO C99 does not support %<_Generic%>");
6728 pedwarn (generic_loc
, OPT_Wpedantic
,
6729 "ISO C90 does not support %<_Generic%>");
6732 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6735 c_inhibit_evaluation_warnings
++;
6736 selector_loc
= c_parser_peek_token (parser
)->location
;
6737 selector
= c_parser_expr_no_commas (parser
, NULL
);
6738 selector
= default_function_array_conversion (selector_loc
, selector
);
6739 c_inhibit_evaluation_warnings
--;
6741 if (selector
.value
== error_mark_node
)
6743 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6746 selector_type
= TREE_TYPE (selector
.value
);
6747 /* In ISO C terms, rvalues (including the controlling expression of
6748 _Generic) do not have qualified types. */
6749 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6750 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6751 /* In ISO C terms, _Noreturn is not part of the type of expressions
6752 such as &abort, but in GCC it is represented internally as a type
6754 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6755 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6757 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6759 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6761 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6767 struct c_generic_association assoc
, *iter
;
6769 c_token
*token
= c_parser_peek_token (parser
);
6771 assoc
.type_location
= token
->location
;
6772 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6774 c_parser_consume_token (parser
);
6775 assoc
.type
= NULL_TREE
;
6779 struct c_type_name
*type_name
;
6781 type_name
= c_parser_type_name (parser
);
6782 if (type_name
== NULL
)
6784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6787 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6788 if (assoc
.type
== error_mark_node
)
6790 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6794 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6795 error_at (assoc
.type_location
,
6796 "%<_Generic%> association has function type");
6797 else if (!COMPLETE_TYPE_P (assoc
.type
))
6798 error_at (assoc
.type_location
,
6799 "%<_Generic%> association has incomplete type");
6801 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6802 error_at (assoc
.type_location
,
6803 "%<_Generic%> association has "
6804 "variable length type");
6807 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6809 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6813 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6814 if (assoc
.expression
.value
== error_mark_node
)
6816 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6820 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6822 if (assoc
.type
== NULL_TREE
)
6824 if (iter
->type
== NULL_TREE
)
6826 error_at (assoc
.type_location
,
6827 "duplicate %<default%> case in %<_Generic%>");
6828 inform (iter
->type_location
, "original %<default%> is here");
6831 else if (iter
->type
!= NULL_TREE
)
6833 if (comptypes (assoc
.type
, iter
->type
))
6835 error_at (assoc
.type_location
,
6836 "%<_Generic%> specifies two compatible types");
6837 inform (iter
->type_location
, "compatible type is here");
6842 if (assoc
.type
== NULL_TREE
)
6846 matched_assoc
= assoc
;
6850 else if (comptypes (assoc
.type
, selector_type
))
6852 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6854 matched_assoc
= assoc
;
6859 error_at (assoc
.type_location
,
6860 "%<_Generic> selector matches multiple associations");
6861 inform (matched_assoc
.type_location
,
6862 "other match is here");
6866 associations
.safe_push (assoc
);
6868 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6870 c_parser_consume_token (parser
);
6873 associations
.release ();
6875 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6877 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6883 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6884 "compatible with any association",
6889 return matched_assoc
.expression
;
6892 associations
.release ();
6896 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6900 postfix-expression [ expression ]
6901 postfix-expression ( argument-expression-list[opt] )
6902 postfix-expression . identifier
6903 postfix-expression -> identifier
6904 postfix-expression ++
6905 postfix-expression --
6906 ( type-name ) { initializer-list }
6907 ( type-name ) { initializer-list , }
6909 argument-expression-list:
6911 argument-expression-list , argument-expression
6924 (treated as a keyword in GNU C)
6927 ( compound-statement )
6928 __builtin_va_arg ( assignment-expression , type-name )
6929 __builtin_offsetof ( type-name , offsetof-member-designator )
6930 __builtin_choose_expr ( assignment-expression ,
6931 assignment-expression ,
6932 assignment-expression )
6933 __builtin_types_compatible_p ( type-name , type-name )
6934 __builtin_complex ( assignment-expression , assignment-expression )
6935 __builtin_shuffle ( assignment-expression , assignment-expression )
6936 __builtin_shuffle ( assignment-expression ,
6937 assignment-expression ,
6938 assignment-expression, )
6940 offsetof-member-designator:
6942 offsetof-member-designator . identifier
6943 offsetof-member-designator [ expression ]
6948 [ objc-receiver objc-message-args ]
6949 @selector ( objc-selector-arg )
6950 @protocol ( identifier )
6951 @encode ( type-name )
6953 Classname . identifier
6956 static struct c_expr
6957 c_parser_postfix_expression (c_parser
*parser
)
6959 struct c_expr expr
, e1
;
6960 struct c_type_name
*t1
, *t2
;
6961 location_t loc
= c_parser_peek_token (parser
)->location
;;
6962 expr
.original_code
= ERROR_MARK
;
6963 expr
.original_type
= NULL
;
6964 switch (c_parser_peek_token (parser
)->type
)
6967 expr
.value
= c_parser_peek_token (parser
)->value
;
6968 loc
= c_parser_peek_token (parser
)->location
;
6969 c_parser_consume_token (parser
);
6970 if (TREE_CODE (expr
.value
) == FIXED_CST
6971 && !targetm
.fixed_point_supported_p ())
6973 error_at (loc
, "fixed-point types not supported for this target");
6974 expr
.value
= error_mark_node
;
6981 expr
.value
= c_parser_peek_token (parser
)->value
;
6982 c_parser_consume_token (parser
);
6988 case CPP_UTF8STRING
:
6989 expr
.value
= c_parser_peek_token (parser
)->value
;
6990 expr
.original_code
= STRING_CST
;
6991 c_parser_consume_token (parser
);
6993 case CPP_OBJC_STRING
:
6994 gcc_assert (c_dialect_objc ());
6996 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6997 c_parser_consume_token (parser
);
7000 switch (c_parser_peek_token (parser
)->id_kind
)
7004 tree id
= c_parser_peek_token (parser
)->value
;
7005 c_parser_consume_token (parser
);
7006 expr
.value
= build_external_ref (loc
, id
,
7007 (c_parser_peek_token (parser
)->type
7009 &expr
.original_type
);
7012 case C_ID_CLASSNAME
:
7014 /* Here we parse the Objective-C 2.0 Class.name dot
7016 tree class_name
= c_parser_peek_token (parser
)->value
;
7018 c_parser_consume_token (parser
);
7019 gcc_assert (c_dialect_objc ());
7020 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7022 expr
.value
= error_mark_node
;
7025 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7027 c_parser_error (parser
, "expected identifier");
7028 expr
.value
= error_mark_node
;
7031 component
= c_parser_peek_token (parser
)->value
;
7032 c_parser_consume_token (parser
);
7033 expr
.value
= objc_build_class_component_ref (class_name
,
7038 c_parser_error (parser
, "expected expression");
7039 expr
.value
= error_mark_node
;
7043 case CPP_OPEN_PAREN
:
7044 /* A parenthesized expression, statement expression or compound
7046 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7048 /* A statement expression. */
7050 location_t brace_loc
;
7051 c_parser_consume_token (parser
);
7052 brace_loc
= c_parser_peek_token (parser
)->location
;
7053 c_parser_consume_token (parser
);
7054 if (!building_stmt_list_p ())
7056 error_at (loc
, "braced-group within expression allowed "
7057 "only inside a function");
7058 parser
->error
= true;
7059 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7060 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7061 expr
.value
= error_mark_node
;
7064 stmt
= c_begin_stmt_expr ();
7065 c_parser_compound_statement_nostart (parser
);
7066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7068 pedwarn (loc
, OPT_Wpedantic
,
7069 "ISO C forbids braced-groups within expressions");
7070 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7071 mark_exp_read (expr
.value
);
7073 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7075 /* A compound literal. ??? Can we actually get here rather
7076 than going directly to
7077 c_parser_postfix_expression_after_paren_type from
7080 struct c_type_name
*type_name
;
7081 c_parser_consume_token (parser
);
7082 loc
= c_parser_peek_token (parser
)->location
;
7083 type_name
= c_parser_type_name (parser
);
7084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7086 if (type_name
== NULL
)
7088 expr
.value
= error_mark_node
;
7091 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7097 /* A parenthesized expression. */
7098 c_parser_consume_token (parser
);
7099 expr
= c_parser_expression (parser
);
7100 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7101 TREE_NO_WARNING (expr
.value
) = 1;
7102 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7103 expr
.original_code
= ERROR_MARK
;
7104 /* Don't change EXPR.ORIGINAL_TYPE. */
7105 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7110 switch (c_parser_peek_token (parser
)->keyword
)
7112 case RID_FUNCTION_NAME
:
7113 case RID_PRETTY_FUNCTION_NAME
:
7114 case RID_C99_FUNCTION_NAME
:
7115 expr
.value
= fname_decl (loc
,
7116 c_parser_peek_token (parser
)->keyword
,
7117 c_parser_peek_token (parser
)->value
);
7118 c_parser_consume_token (parser
);
7121 c_parser_consume_token (parser
);
7122 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7124 expr
.value
= error_mark_node
;
7127 e1
= c_parser_expr_no_commas (parser
, NULL
);
7128 mark_exp_read (e1
.value
);
7129 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7130 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7132 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7133 expr
.value
= error_mark_node
;
7136 loc
= c_parser_peek_token (parser
)->location
;
7137 t1
= c_parser_type_name (parser
);
7138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7142 expr
.value
= error_mark_node
;
7146 tree type_expr
= NULL_TREE
;
7147 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7148 groktypename (t1
, &type_expr
, NULL
));
7151 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7152 TREE_TYPE (expr
.value
), type_expr
,
7154 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7159 c_parser_consume_token (parser
);
7160 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7162 expr
.value
= error_mark_node
;
7165 t1
= c_parser_type_name (parser
);
7167 parser
->error
= true;
7168 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7169 gcc_assert (parser
->error
);
7172 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7173 expr
.value
= error_mark_node
;
7178 tree type
= groktypename (t1
, NULL
, NULL
);
7180 if (type
== error_mark_node
)
7181 offsetof_ref
= error_mark_node
;
7184 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7185 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7187 /* Parse the second argument to __builtin_offsetof. We
7188 must have one identifier, and beyond that we want to
7189 accept sub structure and sub array references. */
7190 if (c_parser_next_token_is (parser
, CPP_NAME
))
7192 offsetof_ref
= build_component_ref
7193 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7194 c_parser_consume_token (parser
);
7195 while (c_parser_next_token_is (parser
, CPP_DOT
)
7196 || c_parser_next_token_is (parser
,
7198 || c_parser_next_token_is (parser
,
7201 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7203 loc
= c_parser_peek_token (parser
)->location
;
7204 offsetof_ref
= build_array_ref (loc
,
7209 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7212 c_parser_consume_token (parser
);
7213 if (c_parser_next_token_is_not (parser
,
7216 c_parser_error (parser
, "expected identifier");
7219 offsetof_ref
= build_component_ref
7221 c_parser_peek_token (parser
)->value
);
7222 c_parser_consume_token (parser
);
7228 loc
= c_parser_peek_token (parser
)->location
;
7229 c_parser_consume_token (parser
);
7230 ce
= c_parser_expression (parser
);
7231 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7233 idx
= c_fully_fold (idx
, false, NULL
);
7234 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7236 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7241 c_parser_error (parser
, "expected identifier");
7242 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7244 expr
.value
= fold_offsetof (offsetof_ref
);
7247 case RID_CHOOSE_EXPR
:
7249 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7250 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7253 c_parser_consume_token (parser
);
7254 if (!c_parser_get_builtin_args (parser
,
7255 "__builtin_choose_expr",
7258 expr
.value
= error_mark_node
;
7262 if (vec_safe_length (cexpr_list
) != 3)
7264 error_at (loc
, "wrong number of arguments to "
7265 "%<__builtin_choose_expr%>");
7266 expr
.value
= error_mark_node
;
7270 e1_p
= &(*cexpr_list
)[0];
7271 e2_p
= &(*cexpr_list
)[1];
7272 e3_p
= &(*cexpr_list
)[2];
7275 mark_exp_read (e2_p
->value
);
7276 mark_exp_read (e3_p
->value
);
7277 if (TREE_CODE (c
) != INTEGER_CST
7278 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7280 "first argument to %<__builtin_choose_expr%> not"
7282 constant_expression_warning (c
);
7283 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7286 case RID_TYPES_COMPATIBLE_P
:
7287 c_parser_consume_token (parser
);
7288 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7290 expr
.value
= error_mark_node
;
7293 t1
= c_parser_type_name (parser
);
7296 expr
.value
= error_mark_node
;
7299 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7302 expr
.value
= error_mark_node
;
7305 t2
= c_parser_type_name (parser
);
7308 expr
.value
= error_mark_node
;
7311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7315 e1
= groktypename (t1
, NULL
, NULL
);
7316 e2
= groktypename (t2
, NULL
, NULL
);
7317 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7319 expr
.value
= error_mark_node
;
7323 e1
= TYPE_MAIN_VARIANT (e1
);
7324 e2
= TYPE_MAIN_VARIANT (e2
);
7327 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7330 case RID_BUILTIN_COMPLEX
:
7332 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7333 c_expr_t
*e1_p
, *e2_p
;
7335 c_parser_consume_token (parser
);
7336 if (!c_parser_get_builtin_args (parser
,
7337 "__builtin_complex",
7338 &cexpr_list
, false))
7340 expr
.value
= error_mark_node
;
7344 if (vec_safe_length (cexpr_list
) != 2)
7346 error_at (loc
, "wrong number of arguments to "
7347 "%<__builtin_complex%>");
7348 expr
.value
= error_mark_node
;
7352 e1_p
= &(*cexpr_list
)[0];
7353 e2_p
= &(*cexpr_list
)[1];
7355 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7356 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7357 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7358 TREE_OPERAND (e1_p
->value
, 0));
7359 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7360 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7361 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7362 TREE_OPERAND (e2_p
->value
, 0));
7363 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7364 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7365 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7366 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7368 error_at (loc
, "%<__builtin_complex%> operand "
7369 "not of real binary floating-point type");
7370 expr
.value
= error_mark_node
;
7373 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7374 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7377 "%<__builtin_complex%> operands of different types");
7378 expr
.value
= error_mark_node
;
7382 pedwarn (loc
, OPT_Wpedantic
,
7383 "ISO C90 does not support complex types");
7384 expr
.value
= build2 (COMPLEX_EXPR
,
7387 (TREE_TYPE (e1_p
->value
))),
7388 e1_p
->value
, e2_p
->value
);
7391 case RID_BUILTIN_SHUFFLE
:
7393 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7397 c_parser_consume_token (parser
);
7398 if (!c_parser_get_builtin_args (parser
,
7399 "__builtin_shuffle",
7400 &cexpr_list
, false))
7402 expr
.value
= error_mark_node
;
7406 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7407 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7409 if (vec_safe_length (cexpr_list
) == 2)
7411 c_build_vec_perm_expr
7412 (loc
, (*cexpr_list
)[0].value
,
7413 NULL_TREE
, (*cexpr_list
)[1].value
);
7415 else if (vec_safe_length (cexpr_list
) == 3)
7417 c_build_vec_perm_expr
7418 (loc
, (*cexpr_list
)[0].value
,
7419 (*cexpr_list
)[1].value
,
7420 (*cexpr_list
)[2].value
);
7423 error_at (loc
, "wrong number of arguments to "
7424 "%<__builtin_shuffle%>");
7425 expr
.value
= error_mark_node
;
7429 case RID_AT_SELECTOR
:
7430 gcc_assert (c_dialect_objc ());
7431 c_parser_consume_token (parser
);
7432 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7434 expr
.value
= error_mark_node
;
7438 tree sel
= c_parser_objc_selector_arg (parser
);
7439 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7441 expr
.value
= objc_build_selector_expr (loc
, sel
);
7444 case RID_AT_PROTOCOL
:
7445 gcc_assert (c_dialect_objc ());
7446 c_parser_consume_token (parser
);
7447 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7449 expr
.value
= error_mark_node
;
7452 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7454 c_parser_error (parser
, "expected identifier");
7455 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7456 expr
.value
= error_mark_node
;
7460 tree id
= c_parser_peek_token (parser
)->value
;
7461 c_parser_consume_token (parser
);
7462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7464 expr
.value
= objc_build_protocol_expr (id
);
7468 /* Extension to support C-structures in the archiver. */
7469 gcc_assert (c_dialect_objc ());
7470 c_parser_consume_token (parser
);
7471 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7473 expr
.value
= error_mark_node
;
7476 t1
= c_parser_type_name (parser
);
7479 expr
.value
= error_mark_node
;
7480 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7483 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7486 tree type
= groktypename (t1
, NULL
, NULL
);
7487 expr
.value
= objc_build_encode_expr (type
);
7491 expr
= c_parser_generic_selection (parser
);
7493 case RID_CILK_SPAWN
:
7494 c_parser_consume_token (parser
);
7497 error_at (loc
, "-fcilkplus must be enabled to use "
7499 expr
= c_parser_postfix_expression (parser
);
7500 expr
.value
= error_mark_node
;
7502 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7504 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7505 "are not permitted");
7506 /* Now flush out all the _Cilk_spawns. */
7507 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7508 c_parser_consume_token (parser
);
7509 expr
= c_parser_postfix_expression (parser
);
7513 expr
= c_parser_postfix_expression (parser
);
7514 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7518 c_parser_error (parser
, "expected expression");
7519 expr
.value
= error_mark_node
;
7523 case CPP_OPEN_SQUARE
:
7524 if (c_dialect_objc ())
7526 tree receiver
, args
;
7527 c_parser_consume_token (parser
);
7528 receiver
= c_parser_objc_receiver (parser
);
7529 args
= c_parser_objc_message_args (parser
);
7530 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7532 expr
.value
= objc_build_message_expr (receiver
, args
);
7535 /* Else fall through to report error. */
7537 c_parser_error (parser
, "expected expression");
7538 expr
.value
= error_mark_node
;
7541 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7544 /* Parse a postfix expression after a parenthesized type name: the
7545 brace-enclosed initializer of a compound literal, possibly followed
7546 by some postfix operators. This is separate because it is not
7547 possible to tell until after the type name whether a cast
7548 expression has a cast or a compound literal, or whether the operand
7549 of sizeof is a parenthesized type name or starts with a compound
7550 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7551 location of the first token after the parentheses around the type
7554 static struct c_expr
7555 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7556 struct c_type_name
*type_name
,
7557 location_t type_loc
)
7563 location_t start_loc
;
7564 tree type_expr
= NULL_TREE
;
7565 bool type_expr_const
= true;
7566 check_compound_literal_type (type_loc
, type_name
);
7567 start_init (NULL_TREE
, NULL
, 0);
7568 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7569 start_loc
= c_parser_peek_token (parser
)->location
;
7570 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7572 error_at (type_loc
, "compound literal has variable size");
7573 type
= error_mark_node
;
7575 init
= c_parser_braced_init (parser
, type
, false);
7577 maybe_warn_string_init (type
, init
);
7579 if (type
!= error_mark_node
7580 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7581 && current_function_decl
)
7583 error ("compound literal qualified by address-space qualifier");
7584 type
= error_mark_node
;
7588 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7589 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7590 ? CONSTRUCTOR_NON_CONST (init
.value
)
7591 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7592 non_const
|= !type_expr_const
;
7593 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7594 expr
.original_code
= ERROR_MARK
;
7595 expr
.original_type
= NULL
;
7598 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7600 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7601 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7605 gcc_assert (!non_const
);
7606 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7607 type_expr
, expr
.value
);
7610 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7613 /* Callback function for sizeof_pointer_memaccess_warning to compare
7617 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7619 return comptypes (type1
, type2
) == 1;
7622 /* Parse a postfix expression after the initial primary or compound
7623 literal; that is, parse a series of postfix operators.
7625 EXPR_LOC is the location of the primary expression. */
7627 static struct c_expr
7628 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7629 location_t expr_loc
,
7632 struct c_expr orig_expr
;
7634 location_t sizeof_arg_loc
[3];
7637 vec
<tree
, va_gc
> *exprlist
;
7638 vec
<tree
, va_gc
> *origtypes
= NULL
;
7639 vec
<location_t
> arg_loc
= vNULL
;
7643 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7644 switch (c_parser_peek_token (parser
)->type
)
7646 case CPP_OPEN_SQUARE
:
7647 /* Array reference. */
7648 c_parser_consume_token (parser
);
7650 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7651 /* If we are here, then we have something like this:
7654 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7658 idx
= c_parser_expression (parser
).value
;
7659 /* Here we have 3 options:
7660 1. Array [EXPR] -- Normal Array call.
7661 2. Array [EXPR : EXPR] -- Array notation without stride.
7662 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7664 For 1, we just handle it just like a normal array expression.
7665 For 2 and 3 we handle it like we handle array notations. The
7666 idx value we have above becomes the initial/start index.
7669 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7670 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7674 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7676 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7679 expr
.original_code
= ERROR_MARK
;
7680 expr
.original_type
= NULL
;
7682 case CPP_OPEN_PAREN
:
7683 /* Function call. */
7684 c_parser_consume_token (parser
);
7685 for (i
= 0; i
< 3; i
++)
7687 sizeof_arg
[i
] = NULL_TREE
;
7688 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7690 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7693 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7694 sizeof_arg_loc
, sizeof_arg
,
7696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7699 mark_exp_read (expr
.value
);
7700 if (warn_sizeof_pointer_memaccess
)
7701 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7702 expr
.value
, exprlist
,
7704 sizeof_ptr_memacc_comptypes
);
7706 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7707 exprlist
, origtypes
);
7708 expr
.original_code
= ERROR_MARK
;
7709 if (TREE_CODE (expr
.value
) == INTEGER_CST
7710 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7711 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7712 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7713 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7714 expr
.original_type
= NULL
;
7717 release_tree_vector (exprlist
);
7718 release_tree_vector (origtypes
);
7723 /* Structure element reference. */
7724 c_parser_consume_token (parser
);
7725 expr
= default_function_array_conversion (expr_loc
, expr
);
7726 if (c_parser_next_token_is (parser
, CPP_NAME
))
7727 ident
= c_parser_peek_token (parser
)->value
;
7730 c_parser_error (parser
, "expected identifier");
7731 expr
.value
= error_mark_node
;
7732 expr
.original_code
= ERROR_MARK
;
7733 expr
.original_type
= NULL
;
7736 c_parser_consume_token (parser
);
7737 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7738 expr
.original_code
= ERROR_MARK
;
7739 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7740 expr
.original_type
= NULL
;
7743 /* Remember the original type of a bitfield. */
7744 tree field
= TREE_OPERAND (expr
.value
, 1);
7745 if (TREE_CODE (field
) != FIELD_DECL
)
7746 expr
.original_type
= NULL
;
7748 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7752 /* Structure element reference. */
7753 c_parser_consume_token (parser
);
7754 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7755 if (c_parser_next_token_is (parser
, CPP_NAME
))
7756 ident
= c_parser_peek_token (parser
)->value
;
7759 c_parser_error (parser
, "expected identifier");
7760 expr
.value
= error_mark_node
;
7761 expr
.original_code
= ERROR_MARK
;
7762 expr
.original_type
= NULL
;
7765 c_parser_consume_token (parser
);
7766 expr
.value
= build_component_ref (op_loc
,
7767 build_indirect_ref (op_loc
,
7771 expr
.original_code
= ERROR_MARK
;
7772 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7773 expr
.original_type
= NULL
;
7776 /* Remember the original type of a bitfield. */
7777 tree field
= TREE_OPERAND (expr
.value
, 1);
7778 if (TREE_CODE (field
) != FIELD_DECL
)
7779 expr
.original_type
= NULL
;
7781 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7785 /* Postincrement. */
7786 c_parser_consume_token (parser
);
7787 /* If the expressions have array notations, we expand them. */
7789 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7790 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7793 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7794 expr
.value
= build_unary_op (op_loc
,
7795 POSTINCREMENT_EXPR
, expr
.value
, 0);
7797 expr
.original_code
= ERROR_MARK
;
7798 expr
.original_type
= NULL
;
7800 case CPP_MINUS_MINUS
:
7801 /* Postdecrement. */
7802 c_parser_consume_token (parser
);
7803 /* If the expressions have array notations, we expand them. */
7805 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7806 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7809 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7810 expr
.value
= build_unary_op (op_loc
,
7811 POSTDECREMENT_EXPR
, expr
.value
, 0);
7813 expr
.original_code
= ERROR_MARK
;
7814 expr
.original_type
= NULL
;
7822 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7825 assignment-expression
7826 expression , assignment-expression
7829 static struct c_expr
7830 c_parser_expression (c_parser
*parser
)
7832 location_t tloc
= c_parser_peek_token (parser
)->location
;
7834 expr
= c_parser_expr_no_commas (parser
, NULL
);
7835 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7836 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7837 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7841 location_t loc
= c_parser_peek_token (parser
)->location
;
7842 location_t expr_loc
;
7843 c_parser_consume_token (parser
);
7844 expr_loc
= c_parser_peek_token (parser
)->location
;
7845 lhsval
= expr
.value
;
7846 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7847 lhsval
= TREE_OPERAND (lhsval
, 1);
7848 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7849 mark_exp_read (lhsval
);
7850 next
= c_parser_expr_no_commas (parser
, NULL
);
7851 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7852 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7853 expr
.original_code
= COMPOUND_EXPR
;
7854 expr
.original_type
= next
.original_type
;
7859 /* Parse an expression and convert functions or arrays to pointers and
7860 lvalues to rvalues. */
7862 static struct c_expr
7863 c_parser_expression_conv (c_parser
*parser
)
7866 location_t loc
= c_parser_peek_token (parser
)->location
;
7867 expr
= c_parser_expression (parser
);
7868 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7872 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7873 functions and arrays to pointers and lvalues to rvalues. If
7874 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7875 locations of function arguments into this vector.
7878 assignment-expression
7879 nonempty-expr-list , assignment-expression
7882 static vec
<tree
, va_gc
> *
7883 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7884 vec
<tree
, va_gc
> **p_orig_types
,
7885 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7886 vec
<location_t
> *locations
)
7888 vec
<tree
, va_gc
> *ret
;
7889 vec
<tree
, va_gc
> *orig_types
;
7891 location_t loc
= c_parser_peek_token (parser
)->location
;
7892 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7893 unsigned int idx
= 0;
7895 ret
= make_tree_vector ();
7896 if (p_orig_types
== NULL
)
7899 orig_types
= make_tree_vector ();
7901 if (sizeof_arg
!= NULL
7902 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7903 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7904 expr
= c_parser_expr_no_commas (parser
, NULL
);
7906 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7908 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7909 ret
->quick_push (expr
.value
);
7911 orig_types
->quick_push (expr
.original_type
);
7913 locations
->safe_push (loc
);
7914 if (sizeof_arg
!= NULL
7915 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7916 && expr
.original_code
== SIZEOF_EXPR
)
7918 sizeof_arg
[0] = c_last_sizeof_arg
;
7919 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7921 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7923 c_parser_consume_token (parser
);
7924 loc
= c_parser_peek_token (parser
)->location
;
7925 if (sizeof_arg
!= NULL
7926 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7927 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7929 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7930 expr
= c_parser_expr_no_commas (parser
, NULL
);
7932 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7934 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7935 vec_safe_push (ret
, expr
.value
);
7937 vec_safe_push (orig_types
, expr
.original_type
);
7939 locations
->safe_push (loc
);
7941 && sizeof_arg
!= NULL
7942 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7943 && expr
.original_code
== SIZEOF_EXPR
)
7945 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7946 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7950 *p_orig_types
= orig_types
;
7954 /* Parse Objective-C-specific constructs. */
7956 /* Parse an objc-class-definition.
7958 objc-class-definition:
7959 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7960 objc-class-instance-variables[opt] objc-methodprotolist @end
7961 @implementation identifier objc-superclass[opt]
7962 objc-class-instance-variables[opt]
7963 @interface identifier ( identifier ) objc-protocol-refs[opt]
7964 objc-methodprotolist @end
7965 @interface identifier ( ) objc-protocol-refs[opt]
7966 objc-methodprotolist @end
7967 @implementation identifier ( identifier )
7972 "@interface identifier (" must start "@interface identifier (
7973 identifier ) ...": objc-methodprotolist in the first production may
7974 not start with a parenthesized identifier as a declarator of a data
7975 definition with no declaration specifiers if the objc-superclass,
7976 objc-protocol-refs and objc-class-instance-variables are omitted. */
7979 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7984 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7986 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7991 c_parser_consume_token (parser
);
7992 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7994 c_parser_error (parser
, "expected identifier");
7997 id1
= c_parser_peek_token (parser
)->value
;
7998 c_parser_consume_token (parser
);
7999 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8001 /* We have a category or class extension. */
8003 tree proto
= NULL_TREE
;
8004 c_parser_consume_token (parser
);
8005 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8007 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8009 /* We have a class extension. */
8014 c_parser_error (parser
, "expected identifier or %<)%>");
8015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8021 id2
= c_parser_peek_token (parser
)->value
;
8022 c_parser_consume_token (parser
);
8024 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8027 objc_start_category_implementation (id1
, id2
);
8030 if (c_parser_next_token_is (parser
, CPP_LESS
))
8031 proto
= c_parser_objc_protocol_refs (parser
);
8032 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8033 c_parser_objc_methodprotolist (parser
);
8034 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8035 objc_finish_interface ();
8038 if (c_parser_next_token_is (parser
, CPP_COLON
))
8040 c_parser_consume_token (parser
);
8041 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8043 c_parser_error (parser
, "expected identifier");
8046 superclass
= c_parser_peek_token (parser
)->value
;
8047 c_parser_consume_token (parser
);
8050 superclass
= NULL_TREE
;
8053 tree proto
= NULL_TREE
;
8054 if (c_parser_next_token_is (parser
, CPP_LESS
))
8055 proto
= c_parser_objc_protocol_refs (parser
);
8056 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8059 objc_start_class_implementation (id1
, superclass
);
8060 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8061 c_parser_objc_class_instance_variables (parser
);
8064 objc_continue_interface ();
8065 c_parser_objc_methodprotolist (parser
);
8066 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8067 objc_finish_interface ();
8071 objc_continue_implementation ();
8076 /* Parse objc-class-instance-variables.
8078 objc-class-instance-variables:
8079 { objc-instance-variable-decl-list[opt] }
8081 objc-instance-variable-decl-list:
8082 objc-visibility-spec
8083 objc-instance-variable-decl ;
8085 objc-instance-variable-decl-list objc-visibility-spec
8086 objc-instance-variable-decl-list objc-instance-variable-decl ;
8087 objc-instance-variable-decl-list ;
8089 objc-visibility-spec:
8094 objc-instance-variable-decl:
8099 c_parser_objc_class_instance_variables (c_parser
*parser
)
8101 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8102 c_parser_consume_token (parser
);
8103 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8106 /* Parse any stray semicolon. */
8107 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8109 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8111 c_parser_consume_token (parser
);
8114 /* Stop if at the end of the instance variables. */
8115 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8117 c_parser_consume_token (parser
);
8120 /* Parse any objc-visibility-spec. */
8121 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8123 c_parser_consume_token (parser
);
8124 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8127 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8129 c_parser_consume_token (parser
);
8130 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8133 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8135 c_parser_consume_token (parser
);
8136 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8139 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8141 c_parser_consume_token (parser
);
8142 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8145 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8147 c_parser_pragma (parser
, pragma_external
);
8151 /* Parse some comma-separated declarations. */
8152 decls
= c_parser_struct_declaration (parser
);
8155 /* There is a syntax error. We want to skip the offending
8156 tokens up to the next ';' (included) or '}'
8159 /* First, skip manually a ')' or ']'. This is because they
8160 reduce the nesting level, so c_parser_skip_until_found()
8161 wouldn't be able to skip past them. */
8162 c_token
*token
= c_parser_peek_token (parser
);
8163 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8164 c_parser_consume_token (parser
);
8166 /* Then, do the standard skipping. */
8167 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8169 /* We hopefully recovered. Start normal parsing again. */
8170 parser
->error
= false;
8175 /* Comma-separated instance variables are chained together
8176 in reverse order; add them one by one. */
8177 tree ivar
= nreverse (decls
);
8178 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8179 objc_add_instance_variable (copy_node (ivar
));
8181 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8185 /* Parse an objc-class-declaration.
8187 objc-class-declaration:
8188 @class identifier-list ;
8192 c_parser_objc_class_declaration (c_parser
*parser
)
8194 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8195 c_parser_consume_token (parser
);
8196 /* Any identifiers, including those declared as type names, are OK
8201 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8203 c_parser_error (parser
, "expected identifier");
8204 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8205 parser
->error
= false;
8208 id
= c_parser_peek_token (parser
)->value
;
8209 objc_declare_class (id
);
8210 c_parser_consume_token (parser
);
8211 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8212 c_parser_consume_token (parser
);
8216 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8219 /* Parse an objc-alias-declaration.
8221 objc-alias-declaration:
8222 @compatibility_alias identifier identifier ;
8226 c_parser_objc_alias_declaration (c_parser
*parser
)
8229 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8230 c_parser_consume_token (parser
);
8231 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8233 c_parser_error (parser
, "expected identifier");
8234 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8237 id1
= c_parser_peek_token (parser
)->value
;
8238 c_parser_consume_token (parser
);
8239 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8241 c_parser_error (parser
, "expected identifier");
8242 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8245 id2
= c_parser_peek_token (parser
)->value
;
8246 c_parser_consume_token (parser
);
8247 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8248 objc_declare_alias (id1
, id2
);
8251 /* Parse an objc-protocol-definition.
8253 objc-protocol-definition:
8254 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8255 @protocol identifier-list ;
8257 "@protocol identifier ;" should be resolved as "@protocol
8258 identifier-list ;": objc-methodprotolist may not start with a
8259 semicolon in the first alternative if objc-protocol-refs are
8263 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8265 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8267 c_parser_consume_token (parser
);
8268 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8270 c_parser_error (parser
, "expected identifier");
8273 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8274 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8276 /* Any identifiers, including those declared as type names, are
8281 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8283 c_parser_error (parser
, "expected identifier");
8286 id
= c_parser_peek_token (parser
)->value
;
8287 objc_declare_protocol (id
, attributes
);
8288 c_parser_consume_token (parser
);
8289 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8290 c_parser_consume_token (parser
);
8294 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8298 tree id
= c_parser_peek_token (parser
)->value
;
8299 tree proto
= NULL_TREE
;
8300 c_parser_consume_token (parser
);
8301 if (c_parser_next_token_is (parser
, CPP_LESS
))
8302 proto
= c_parser_objc_protocol_refs (parser
);
8303 parser
->objc_pq_context
= true;
8304 objc_start_protocol (id
, proto
, attributes
);
8305 c_parser_objc_methodprotolist (parser
);
8306 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8307 parser
->objc_pq_context
= false;
8308 objc_finish_interface ();
8312 /* Parse an objc-method-type.
8318 Return true if it is a class method (+) and false if it is
8319 an instance method (-).
8322 c_parser_objc_method_type (c_parser
*parser
)
8324 switch (c_parser_peek_token (parser
)->type
)
8327 c_parser_consume_token (parser
);
8330 c_parser_consume_token (parser
);
8337 /* Parse an objc-method-definition.
8339 objc-method-definition:
8340 objc-method-type objc-method-decl ;[opt] compound-statement
8344 c_parser_objc_method_definition (c_parser
*parser
)
8346 bool is_class_method
= c_parser_objc_method_type (parser
);
8347 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8348 parser
->objc_pq_context
= true;
8349 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8351 if (decl
== error_mark_node
)
8352 return; /* Bail here. */
8354 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8356 c_parser_consume_token (parser
);
8357 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8358 "extra semicolon in method definition specified");
8361 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8363 c_parser_error (parser
, "expected %<{%>");
8367 parser
->objc_pq_context
= false;
8368 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8370 add_stmt (c_parser_compound_statement (parser
));
8371 objc_finish_method_definition (current_function_decl
);
8375 /* This code is executed when we find a method definition
8376 outside of an @implementation context (or invalid for other
8377 reasons). Parse the method (to keep going) but do not emit
8380 c_parser_compound_statement (parser
);
8384 /* Parse an objc-methodprotolist.
8386 objc-methodprotolist:
8388 objc-methodprotolist objc-methodproto
8389 objc-methodprotolist declaration
8390 objc-methodprotolist ;
8394 The declaration is a data definition, which may be missing
8395 declaration specifiers under the same rules and diagnostics as
8396 other data definitions outside functions, and the stray semicolon
8397 is diagnosed the same way as a stray semicolon outside a
8401 c_parser_objc_methodprotolist (c_parser
*parser
)
8405 /* The list is terminated by @end. */
8406 switch (c_parser_peek_token (parser
)->type
)
8409 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8410 "ISO C does not allow extra %<;%> outside of a function");
8411 c_parser_consume_token (parser
);
8415 c_parser_objc_methodproto (parser
);
8418 c_parser_pragma (parser
, pragma_external
);
8423 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8425 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8426 c_parser_objc_at_property_declaration (parser
);
8427 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8429 objc_set_method_opt (true);
8430 c_parser_consume_token (parser
);
8432 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8434 objc_set_method_opt (false);
8435 c_parser_consume_token (parser
);
8438 c_parser_declaration_or_fndef (parser
, false, false, true,
8439 false, true, NULL
, vNULL
);
8445 /* Parse an objc-methodproto.
8448 objc-method-type objc-method-decl ;
8452 c_parser_objc_methodproto (c_parser
*parser
)
8454 bool is_class_method
= c_parser_objc_method_type (parser
);
8455 tree decl
, attributes
= NULL_TREE
;
8457 /* Remember protocol qualifiers in prototypes. */
8458 parser
->objc_pq_context
= true;
8459 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8461 /* Forget protocol qualifiers now. */
8462 parser
->objc_pq_context
= false;
8464 /* Do not allow the presence of attributes to hide an erroneous
8465 method implementation in the interface section. */
8466 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8468 c_parser_error (parser
, "expected %<;%>");
8472 if (decl
!= error_mark_node
)
8473 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8475 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8478 /* If we are at a position that method attributes may be present, check that
8479 there are not any parsed already (a syntax error) and then collect any
8480 specified at the current location. Finally, if new attributes were present,
8481 check that the next token is legal ( ';' for decls and '{' for defs). */
8484 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8489 c_parser_error (parser
,
8490 "method attributes must be specified at the end only");
8491 *attributes
= NULL_TREE
;
8495 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8496 *attributes
= c_parser_attributes (parser
);
8498 /* If there were no attributes here, just report any earlier error. */
8499 if (*attributes
== NULL_TREE
|| bad
)
8502 /* If the attributes are followed by a ; or {, then just report any earlier
8504 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8505 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8508 /* We've got attributes, but not at the end. */
8509 c_parser_error (parser
,
8510 "expected %<;%> or %<{%> after method attribute definition");
8514 /* Parse an objc-method-decl.
8517 ( objc-type-name ) objc-selector
8519 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8520 objc-keyword-selector objc-optparmlist
8523 objc-keyword-selector:
8525 objc-keyword-selector objc-keyword-decl
8528 objc-selector : ( objc-type-name ) identifier
8529 objc-selector : identifier
8530 : ( objc-type-name ) identifier
8534 objc-optparms objc-optellipsis
8538 objc-opt-parms , parameter-declaration
8546 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8547 tree
*attributes
, tree
*expr
)
8549 tree type
= NULL_TREE
;
8551 tree parms
= NULL_TREE
;
8552 bool ellipsis
= false;
8553 bool attr_err
= false;
8555 *attributes
= NULL_TREE
;
8556 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8558 c_parser_consume_token (parser
);
8559 type
= c_parser_objc_type_name (parser
);
8560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8562 sel
= c_parser_objc_selector (parser
);
8563 /* If there is no selector, or a colon follows, we have an
8564 objc-keyword-selector. If there is a selector, and a colon does
8565 not follow, that selector ends the objc-method-decl. */
8566 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8569 tree list
= NULL_TREE
;
8572 tree atype
= NULL_TREE
, id
, keyworddecl
;
8573 tree param_attr
= NULL_TREE
;
8574 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8576 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8578 c_parser_consume_token (parser
);
8579 atype
= c_parser_objc_type_name (parser
);
8580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8583 /* New ObjC allows attributes on method parameters. */
8584 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8585 param_attr
= c_parser_attributes (parser
);
8586 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8588 c_parser_error (parser
, "expected identifier");
8589 return error_mark_node
;
8591 id
= c_parser_peek_token (parser
)->value
;
8592 c_parser_consume_token (parser
);
8593 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8594 list
= chainon (list
, keyworddecl
);
8595 tsel
= c_parser_objc_selector (parser
);
8596 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8600 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8602 /* Parse the optional parameter list. Optional Objective-C
8603 method parameters follow the C syntax, and may include '...'
8604 to denote a variable number of arguments. */
8605 parms
= make_node (TREE_LIST
);
8606 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8608 struct c_parm
*parm
;
8609 c_parser_consume_token (parser
);
8610 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8613 c_parser_consume_token (parser
);
8614 attr_err
|= c_parser_objc_maybe_method_attributes
8615 (parser
, attributes
) ;
8618 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8621 parms
= chainon (parms
,
8622 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8627 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8631 c_parser_error (parser
, "objective-c method declaration is expected");
8632 return error_mark_node
;
8636 return error_mark_node
;
8638 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8641 /* Parse an objc-type-name.
8644 objc-type-qualifiers[opt] type-name
8645 objc-type-qualifiers[opt]
8647 objc-type-qualifiers:
8649 objc-type-qualifiers objc-type-qualifier
8651 objc-type-qualifier: one of
8652 in out inout bycopy byref oneway
8656 c_parser_objc_type_name (c_parser
*parser
)
8658 tree quals
= NULL_TREE
;
8659 struct c_type_name
*type_name
= NULL
;
8660 tree type
= NULL_TREE
;
8663 c_token
*token
= c_parser_peek_token (parser
);
8664 if (token
->type
== CPP_KEYWORD
8665 && (token
->keyword
== RID_IN
8666 || token
->keyword
== RID_OUT
8667 || token
->keyword
== RID_INOUT
8668 || token
->keyword
== RID_BYCOPY
8669 || token
->keyword
== RID_BYREF
8670 || token
->keyword
== RID_ONEWAY
))
8672 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8673 c_parser_consume_token (parser
);
8678 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8679 type_name
= c_parser_type_name (parser
);
8681 type
= groktypename (type_name
, NULL
, NULL
);
8683 /* If the type is unknown, and error has already been produced and
8684 we need to recover from the error. In that case, use NULL_TREE
8685 for the type, as if no type had been specified; this will use the
8686 default type ('id') which is good for error recovery. */
8687 if (type
== error_mark_node
)
8690 return build_tree_list (quals
, type
);
8693 /* Parse objc-protocol-refs.
8700 c_parser_objc_protocol_refs (c_parser
*parser
)
8702 tree list
= NULL_TREE
;
8703 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8704 c_parser_consume_token (parser
);
8705 /* Any identifiers, including those declared as type names, are OK
8710 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8712 c_parser_error (parser
, "expected identifier");
8715 id
= c_parser_peek_token (parser
)->value
;
8716 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8717 c_parser_consume_token (parser
);
8718 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8719 c_parser_consume_token (parser
);
8723 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8727 /* Parse an objc-try-catch-finally-statement.
8729 objc-try-catch-finally-statement:
8730 @try compound-statement objc-catch-list[opt]
8731 @try compound-statement objc-catch-list[opt] @finally compound-statement
8734 @catch ( objc-catch-parameter-declaration ) compound-statement
8735 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8737 objc-catch-parameter-declaration:
8738 parameter-declaration
8741 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8743 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8744 for C++. Keep them in sync. */
8747 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8749 location_t location
;
8752 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8753 c_parser_consume_token (parser
);
8754 location
= c_parser_peek_token (parser
)->location
;
8755 objc_maybe_warn_exceptions (location
);
8756 stmt
= c_parser_compound_statement (parser
);
8757 objc_begin_try_stmt (location
, stmt
);
8759 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8761 struct c_parm
*parm
;
8762 tree parameter_declaration
= error_mark_node
;
8763 bool seen_open_paren
= false;
8765 c_parser_consume_token (parser
);
8766 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8767 seen_open_paren
= true;
8768 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8770 /* We have "@catch (...)" (where the '...' are literally
8771 what is in the code). Skip the '...'.
8772 parameter_declaration is set to NULL_TREE, and
8773 objc_being_catch_clauses() knows that that means
8775 c_parser_consume_token (parser
);
8776 parameter_declaration
= NULL_TREE
;
8780 /* We have "@catch (NSException *exception)" or something
8781 like that. Parse the parameter declaration. */
8782 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8784 parameter_declaration
= error_mark_node
;
8786 parameter_declaration
= grokparm (parm
, NULL
);
8788 if (seen_open_paren
)
8789 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8792 /* If there was no open parenthesis, we are recovering from
8793 an error, and we are trying to figure out what mistake
8794 the user has made. */
8796 /* If there is an immediate closing parenthesis, the user
8797 probably forgot the opening one (ie, they typed "@catch
8798 NSException *e)". Parse the closing parenthesis and keep
8800 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8801 c_parser_consume_token (parser
);
8803 /* If these is no immediate closing parenthesis, the user
8804 probably doesn't know that parenthesis are required at
8805 all (ie, they typed "@catch NSException *e"). So, just
8806 forget about the closing parenthesis and keep going. */
8808 objc_begin_catch_clause (parameter_declaration
);
8809 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8810 c_parser_compound_statement_nostart (parser
);
8811 objc_finish_catch_clause ();
8813 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8815 c_parser_consume_token (parser
);
8816 location
= c_parser_peek_token (parser
)->location
;
8817 stmt
= c_parser_compound_statement (parser
);
8818 objc_build_finally_clause (location
, stmt
);
8820 objc_finish_try_stmt ();
8823 /* Parse an objc-synchronized-statement.
8825 objc-synchronized-statement:
8826 @synchronized ( expression ) compound-statement
8830 c_parser_objc_synchronized_statement (c_parser
*parser
)
8834 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8835 c_parser_consume_token (parser
);
8836 loc
= c_parser_peek_token (parser
)->location
;
8837 objc_maybe_warn_exceptions (loc
);
8838 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8840 struct c_expr ce
= c_parser_expression (parser
);
8841 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8843 expr
= c_fully_fold (expr
, false, NULL
);
8844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8847 expr
= error_mark_node
;
8848 stmt
= c_parser_compound_statement (parser
);
8849 objc_build_synchronized (loc
, expr
, stmt
);
8852 /* Parse an objc-selector; return NULL_TREE without an error if the
8853 next token is not an objc-selector.
8858 enum struct union if else while do for switch case default
8859 break continue return goto asm sizeof typeof __alignof
8860 unsigned long const short volatile signed restrict _Complex
8861 in out inout bycopy byref oneway int char float double void _Bool
8864 ??? Why this selection of keywords but not, for example, storage
8865 class specifiers? */
8868 c_parser_objc_selector (c_parser
*parser
)
8870 c_token
*token
= c_parser_peek_token (parser
);
8871 tree value
= token
->value
;
8872 if (token
->type
== CPP_NAME
)
8874 c_parser_consume_token (parser
);
8877 if (token
->type
!= CPP_KEYWORD
)
8879 switch (token
->keyword
)
8923 c_parser_consume_token (parser
);
8930 /* Parse an objc-selector-arg.
8934 objc-keywordname-list
8936 objc-keywordname-list:
8938 objc-keywordname-list objc-keywordname
8946 c_parser_objc_selector_arg (c_parser
*parser
)
8948 tree sel
= c_parser_objc_selector (parser
);
8949 tree list
= NULL_TREE
;
8950 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8954 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8956 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8957 sel
= c_parser_objc_selector (parser
);
8958 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8964 /* Parse an objc-receiver.
8973 c_parser_objc_receiver (c_parser
*parser
)
8975 location_t loc
= c_parser_peek_token (parser
)->location
;
8977 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8978 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8979 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8981 tree id
= c_parser_peek_token (parser
)->value
;
8982 c_parser_consume_token (parser
);
8983 return objc_get_class_reference (id
);
8985 struct c_expr ce
= c_parser_expression (parser
);
8986 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8987 return c_fully_fold (ce
.value
, false, NULL
);
8990 /* Parse objc-message-args.
8994 objc-keywordarg-list
8996 objc-keywordarg-list:
8998 objc-keywordarg-list objc-keywordarg
9001 objc-selector : objc-keywordexpr
9006 c_parser_objc_message_args (c_parser
*parser
)
9008 tree sel
= c_parser_objc_selector (parser
);
9009 tree list
= NULL_TREE
;
9010 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9015 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9016 return error_mark_node
;
9017 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9018 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9019 sel
= c_parser_objc_selector (parser
);
9020 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9026 /* Parse an objc-keywordexpr.
9033 c_parser_objc_keywordexpr (c_parser
*parser
)
9036 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9037 NULL
, NULL
, NULL
, NULL
);
9038 if (vec_safe_length (expr_list
) == 1)
9040 /* Just return the expression, remove a level of
9042 ret
= (*expr_list
)[0];
9046 /* We have a comma expression, we will collapse later. */
9047 ret
= build_tree_list_vec (expr_list
);
9049 release_tree_vector (expr_list
);
9053 /* A check, needed in several places, that ObjC interface, implementation or
9054 method definitions are not prefixed by incorrect items. */
9056 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9057 struct c_declspecs
*specs
)
9059 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9060 || specs
->typespec_kind
!= ctsk_none
)
9062 c_parser_error (parser
,
9063 "no type or storage class may be specified here,");
9064 c_parser_skip_to_end_of_block_or_statement (parser
);
9070 /* Parse an Objective-C @property declaration. The syntax is:
9072 objc-property-declaration:
9073 '@property' objc-property-attributes[opt] struct-declaration ;
9075 objc-property-attributes:
9076 '(' objc-property-attribute-list ')'
9078 objc-property-attribute-list:
9079 objc-property-attribute
9080 objc-property-attribute-list, objc-property-attribute
9082 objc-property-attribute
9083 'getter' = identifier
9084 'setter' = identifier
9093 @property NSString *name;
9094 @property (readonly) id object;
9095 @property (retain, nonatomic, getter=getTheName) id name;
9096 @property int a, b, c;
9098 PS: This function is identical to cp_parser_objc_at_propery_declaration
9099 for C++. Keep them in sync. */
9101 c_parser_objc_at_property_declaration (c_parser
*parser
)
9103 /* The following variables hold the attributes of the properties as
9104 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9105 seen. When we see an attribute, we set them to 'true' (if they
9106 are boolean properties) or to the identifier (if they have an
9107 argument, ie, for getter and setter). Note that here we only
9108 parse the list of attributes, check the syntax and accumulate the
9109 attributes that we find. objc_add_property_declaration() will
9110 then process the information. */
9111 bool property_assign
= false;
9112 bool property_copy
= false;
9113 tree property_getter_ident
= NULL_TREE
;
9114 bool property_nonatomic
= false;
9115 bool property_readonly
= false;
9116 bool property_readwrite
= false;
9117 bool property_retain
= false;
9118 tree property_setter_ident
= NULL_TREE
;
9120 /* 'properties' is the list of properties that we read. Usually a
9121 single one, but maybe more (eg, in "@property int a, b, c;" there
9126 loc
= c_parser_peek_token (parser
)->location
;
9127 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9129 c_parser_consume_token (parser
); /* Eat '@property'. */
9131 /* Parse the optional attribute list... */
9132 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9135 c_parser_consume_token (parser
);
9137 /* Property attribute keywords are valid now. */
9138 parser
->objc_property_attr_context
= true;
9142 bool syntax_error
= false;
9143 c_token
*token
= c_parser_peek_token (parser
);
9146 if (token
->type
!= CPP_KEYWORD
)
9148 if (token
->type
== CPP_CLOSE_PAREN
)
9149 c_parser_error (parser
, "expected identifier");
9152 c_parser_consume_token (parser
);
9153 c_parser_error (parser
, "unknown property attribute");
9157 keyword
= token
->keyword
;
9158 c_parser_consume_token (parser
);
9161 case RID_ASSIGN
: property_assign
= true; break;
9162 case RID_COPY
: property_copy
= true; break;
9163 case RID_NONATOMIC
: property_nonatomic
= true; break;
9164 case RID_READONLY
: property_readonly
= true; break;
9165 case RID_READWRITE
: property_readwrite
= true; break;
9166 case RID_RETAIN
: property_retain
= true; break;
9170 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9172 if (keyword
== RID_GETTER
)
9173 c_parser_error (parser
,
9174 "missing %<=%> (after %<getter%> attribute)");
9176 c_parser_error (parser
,
9177 "missing %<=%> (after %<setter%> attribute)");
9178 syntax_error
= true;
9181 c_parser_consume_token (parser
); /* eat the = */
9182 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9184 c_parser_error (parser
, "expected identifier");
9185 syntax_error
= true;
9188 if (keyword
== RID_SETTER
)
9190 if (property_setter_ident
!= NULL_TREE
)
9191 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9193 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9194 c_parser_consume_token (parser
);
9195 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9196 c_parser_error (parser
, "setter name must terminate with %<:%>");
9198 c_parser_consume_token (parser
);
9202 if (property_getter_ident
!= NULL_TREE
)
9203 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9205 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9206 c_parser_consume_token (parser
);
9210 c_parser_error (parser
, "unknown property attribute");
9211 syntax_error
= true;
9218 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9219 c_parser_consume_token (parser
);
9223 parser
->objc_property_attr_context
= false;
9224 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9226 /* ... and the property declaration(s). */
9227 properties
= c_parser_struct_declaration (parser
);
9229 if (properties
== error_mark_node
)
9231 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9232 parser
->error
= false;
9236 if (properties
== NULL_TREE
)
9237 c_parser_error (parser
, "expected identifier");
9240 /* Comma-separated properties are chained together in
9241 reverse order; add them one by one. */
9242 properties
= nreverse (properties
);
9244 for (; properties
; properties
= TREE_CHAIN (properties
))
9245 objc_add_property_declaration (loc
, copy_node (properties
),
9246 property_readonly
, property_readwrite
,
9247 property_assign
, property_retain
,
9248 property_copy
, property_nonatomic
,
9249 property_getter_ident
, property_setter_ident
);
9252 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9253 parser
->error
= false;
9256 /* Parse an Objective-C @synthesize declaration. The syntax is:
9258 objc-synthesize-declaration:
9259 @synthesize objc-synthesize-identifier-list ;
9261 objc-synthesize-identifier-list:
9262 objc-synthesize-identifier
9263 objc-synthesize-identifier-list, objc-synthesize-identifier
9265 objc-synthesize-identifier
9267 identifier = identifier
9270 @synthesize MyProperty;
9271 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9273 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9274 for C++. Keep them in sync.
9277 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9279 tree list
= NULL_TREE
;
9281 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9282 loc
= c_parser_peek_token (parser
)->location
;
9284 c_parser_consume_token (parser
);
9287 tree property
, ivar
;
9288 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9290 c_parser_error (parser
, "expected identifier");
9291 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9292 /* Once we find the semicolon, we can resume normal parsing.
9293 We have to reset parser->error manually because
9294 c_parser_skip_until_found() won't reset it for us if the
9295 next token is precisely a semicolon. */
9296 parser
->error
= false;
9299 property
= c_parser_peek_token (parser
)->value
;
9300 c_parser_consume_token (parser
);
9301 if (c_parser_next_token_is (parser
, CPP_EQ
))
9303 c_parser_consume_token (parser
);
9304 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9306 c_parser_error (parser
, "expected identifier");
9307 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9308 parser
->error
= false;
9311 ivar
= c_parser_peek_token (parser
)->value
;
9312 c_parser_consume_token (parser
);
9316 list
= chainon (list
, build_tree_list (ivar
, property
));
9317 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9318 c_parser_consume_token (parser
);
9322 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9323 objc_add_synthesize_declaration (loc
, list
);
9326 /* Parse an Objective-C @dynamic declaration. The syntax is:
9328 objc-dynamic-declaration:
9329 @dynamic identifier-list ;
9332 @dynamic MyProperty;
9333 @dynamic MyProperty, AnotherProperty;
9335 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9336 for C++. Keep them in sync.
9339 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9341 tree list
= NULL_TREE
;
9343 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9344 loc
= c_parser_peek_token (parser
)->location
;
9346 c_parser_consume_token (parser
);
9350 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9352 c_parser_error (parser
, "expected identifier");
9353 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9354 parser
->error
= false;
9357 property
= c_parser_peek_token (parser
)->value
;
9358 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9359 c_parser_consume_token (parser
);
9360 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9361 c_parser_consume_token (parser
);
9365 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9366 objc_add_dynamic_declaration (loc
, list
);
9370 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9371 should be considered, statements. ALLOW_STMT is true if we're within
9372 the context of a function and such pragmas are to be allowed. Returns
9373 true if we actually parsed such a pragma. */
9376 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9380 id
= c_parser_peek_token (parser
)->pragma_kind
;
9381 gcc_assert (id
!= PRAGMA_NONE
);
9385 case PRAGMA_OMP_BARRIER
:
9386 if (context
!= pragma_compound
)
9388 if (context
== pragma_stmt
)
9389 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9390 "used in compound statements");
9393 c_parser_omp_barrier (parser
);
9396 case PRAGMA_OMP_FLUSH
:
9397 if (context
!= pragma_compound
)
9399 if (context
== pragma_stmt
)
9400 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9401 "used in compound statements");
9404 c_parser_omp_flush (parser
);
9407 case PRAGMA_OMP_TASKWAIT
:
9408 if (context
!= pragma_compound
)
9410 if (context
== pragma_stmt
)
9411 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9412 "used in compound statements");
9415 c_parser_omp_taskwait (parser
);
9418 case PRAGMA_OMP_TASKYIELD
:
9419 if (context
!= pragma_compound
)
9421 if (context
== pragma_stmt
)
9422 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9423 "used in compound statements");
9426 c_parser_omp_taskyield (parser
);
9429 case PRAGMA_OMP_CANCEL
:
9430 if (context
!= pragma_compound
)
9432 if (context
== pragma_stmt
)
9433 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9434 "used in compound statements");
9437 c_parser_omp_cancel (parser
);
9440 case PRAGMA_OMP_CANCELLATION_POINT
:
9441 if (context
!= pragma_compound
)
9443 if (context
== pragma_stmt
)
9444 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9445 "only be used in compound statements");
9448 c_parser_omp_cancellation_point (parser
);
9451 case PRAGMA_OMP_THREADPRIVATE
:
9452 c_parser_omp_threadprivate (parser
);
9455 case PRAGMA_OMP_TARGET
:
9456 return c_parser_omp_target (parser
, context
);
9458 case PRAGMA_OMP_END_DECLARE_TARGET
:
9459 c_parser_omp_end_declare_target (parser
);
9462 case PRAGMA_OMP_SECTION
:
9463 error_at (c_parser_peek_token (parser
)->location
,
9464 "%<#pragma omp section%> may only be used in "
9465 "%<#pragma omp sections%> construct");
9466 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9469 case PRAGMA_OMP_DECLARE_REDUCTION
:
9470 c_parser_omp_declare (parser
, context
);
9473 c_parser_consume_pragma (parser
);
9474 c_parser_skip_to_pragma_eol (parser
);
9475 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9476 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9477 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9479 c_parser_error (parser
, "for, while or do statement expected");
9482 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9483 c_parser_for_statement (parser
, true);
9484 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9485 c_parser_while_statement (parser
, true);
9487 c_parser_do_statement (parser
, true);
9490 case PRAGMA_GCC_PCH_PREPROCESS
:
9491 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9492 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9495 case PRAGMA_CILK_SIMD
:
9496 if (!c_parser_cilk_verify_simd (parser
, context
))
9498 c_parser_consume_pragma (parser
);
9499 c_parser_cilk_simd (parser
);
9503 if (id
< PRAGMA_FIRST_EXTERNAL
)
9505 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9508 c_parser_error (parser
, "expected declaration specifiers");
9509 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9512 c_parser_omp_construct (parser
);
9518 c_parser_consume_pragma (parser
);
9519 c_invoke_pragma_handler (id
);
9521 /* Skip to EOL, but suppress any error message. Those will have been
9522 generated by the handler routine through calling error, as opposed
9523 to calling c_parser_error. */
9524 parser
->error
= true;
9525 c_parser_skip_to_pragma_eol (parser
);
9530 /* The interface the pragma parsers have to the lexer. */
9533 pragma_lex (tree
*value
)
9535 c_token
*tok
= c_parser_peek_token (the_parser
);
9536 enum cpp_ttype ret
= tok
->type
;
9538 *value
= tok
->value
;
9539 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9543 if (ret
== CPP_KEYWORD
)
9545 c_parser_consume_token (the_parser
);
9552 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9556 c_parser_consume_pragma (parser
);
9557 if (c_parser_next_token_is (parser
, CPP_STRING
))
9559 name
= c_parser_peek_token (parser
)->value
;
9560 c_parser_consume_token (parser
);
9563 c_parser_error (parser
, "expected string literal");
9564 c_parser_skip_to_pragma_eol (parser
);
9567 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9570 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9572 /* Returns name of the next clause.
9573 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9574 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9575 returned and the token is consumed. */
9577 static pragma_omp_clause
9578 c_parser_omp_clause_name (c_parser
*parser
)
9580 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9582 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9583 result
= PRAGMA_OMP_CLAUSE_IF
;
9584 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9585 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9586 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9587 result
= PRAGMA_OMP_CLAUSE_FOR
;
9588 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9590 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9595 if (!strcmp ("aligned", p
))
9596 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9599 if (!strcmp ("collapse", p
))
9600 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9601 else if (!strcmp ("copyin", p
))
9602 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9603 else if (!strcmp ("copyprivate", p
))
9604 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9607 if (!strcmp ("depend", p
))
9608 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9609 else if (!strcmp ("device", p
))
9610 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9611 else if (!strcmp ("dist_schedule", p
))
9612 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9615 if (!strcmp ("final", p
))
9616 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9617 else if (!strcmp ("firstprivate", p
))
9618 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9619 else if (!strcmp ("from", p
))
9620 result
= PRAGMA_OMP_CLAUSE_FROM
;
9623 if (!strcmp ("inbranch", p
))
9624 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9627 if (!strcmp ("lastprivate", p
))
9628 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9629 else if (!strcmp ("linear", p
))
9630 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9633 if (!strcmp ("map", p
))
9634 result
= PRAGMA_OMP_CLAUSE_MAP
;
9635 else if (!strcmp ("mergeable", p
))
9636 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9637 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9638 result
= PRAGMA_CILK_CLAUSE_MASK
;
9641 if (!strcmp ("notinbranch", p
))
9642 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9643 else if (!strcmp ("nowait", p
))
9644 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9645 else if (!strcmp ("num_teams", p
))
9646 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9647 else if (!strcmp ("num_threads", p
))
9648 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9649 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9650 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9653 if (!strcmp ("ordered", p
))
9654 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9657 if (!strcmp ("parallel", p
))
9658 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9659 else if (!strcmp ("private", p
))
9660 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9661 else if (!strcmp ("proc_bind", p
))
9662 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9665 if (!strcmp ("reduction", p
))
9666 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9669 if (!strcmp ("safelen", p
))
9670 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9671 else if (!strcmp ("schedule", p
))
9672 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9673 else if (!strcmp ("sections", p
))
9674 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9675 else if (!strcmp ("shared", p
))
9676 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9677 else if (!strcmp ("simdlen", p
))
9678 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9681 if (!strcmp ("taskgroup", p
))
9682 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9683 else if (!strcmp ("thread_limit", p
))
9684 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9685 else if (!strcmp ("to", p
))
9686 result
= PRAGMA_OMP_CLAUSE_TO
;
9689 if (!strcmp ("uniform", p
))
9690 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9691 else if (!strcmp ("untied", p
))
9692 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9695 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9696 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9701 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9702 c_parser_consume_token (parser
);
9707 /* Validate that a clause of the given type does not already exist. */
9710 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9715 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9716 if (OMP_CLAUSE_CODE (c
) == code
)
9718 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9719 error_at (loc
, "too many %qs clauses", name
);
9727 variable-list , identifier
9729 If KIND is nonzero, create the appropriate node and install the
9730 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9731 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9733 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9734 return the list created. */
9737 c_parser_omp_variable_list (c_parser
*parser
,
9738 location_t clause_loc
,
9739 enum omp_clause_code kind
, tree list
)
9741 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9742 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9743 c_parser_error (parser
, "expected identifier");
9745 while (c_parser_next_token_is (parser
, CPP_NAME
)
9746 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9748 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9752 undeclared_variable (c_parser_peek_token (parser
)->location
,
9753 c_parser_peek_token (parser
)->value
);
9754 t
= error_mark_node
;
9757 c_parser_consume_token (parser
);
9759 if (t
== error_mark_node
)
9765 case OMP_CLAUSE_MAP
:
9766 case OMP_CLAUSE_FROM
:
9768 case OMP_CLAUSE_DEPEND
:
9769 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9771 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9773 c_parser_consume_token (parser
);
9774 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9775 low_bound
= c_parser_expression (parser
).value
;
9776 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9777 length
= integer_one_node
;
9781 if (!c_parser_require (parser
, CPP_COLON
,
9784 t
= error_mark_node
;
9787 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9788 length
= c_parser_expression (parser
).value
;
9790 /* Look for the closing `]'. */
9791 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9794 t
= error_mark_node
;
9797 t
= tree_cons (low_bound
, length
, t
);
9804 if (t
!= error_mark_node
)
9806 tree u
= build_omp_clause (clause_loc
, kind
);
9807 OMP_CLAUSE_DECL (u
) = t
;
9808 OMP_CLAUSE_CHAIN (u
) = list
;
9813 list
= tree_cons (t
, NULL_TREE
, list
);
9815 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9818 c_parser_consume_token (parser
);
9824 /* Similarly, but expect leading and trailing parenthesis. This is a very
9825 common case for omp clauses. */
9828 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9831 /* The clauses location. */
9832 location_t loc
= c_parser_peek_token (parser
)->location
;
9834 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9836 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9843 collapse ( constant-expression ) */
9846 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9848 tree c
, num
= error_mark_node
;
9852 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9854 loc
= c_parser_peek_token (parser
)->location
;
9855 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9857 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9858 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9860 if (num
== error_mark_node
)
9862 mark_exp_read (num
);
9863 num
= c_fully_fold (num
, false, NULL
);
9864 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9865 || !tree_fits_shwi_p (num
)
9866 || (n
= tree_to_shwi (num
)) <= 0
9870 "collapse argument needs positive constant integer expression");
9873 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9874 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9875 OMP_CLAUSE_CHAIN (c
) = list
;
9880 copyin ( variable-list ) */
9883 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9885 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9889 copyprivate ( variable-list ) */
9892 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9894 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9898 default ( shared | none ) */
9901 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9903 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9904 location_t loc
= c_parser_peek_token (parser
)->location
;
9907 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9909 if (c_parser_next_token_is (parser
, CPP_NAME
))
9911 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9916 if (strcmp ("none", p
) != 0)
9918 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9922 if (strcmp ("shared", p
) != 0)
9924 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9931 c_parser_consume_token (parser
);
9936 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9938 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9940 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9943 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9944 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9945 OMP_CLAUSE_CHAIN (c
) = list
;
9946 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9952 firstprivate ( variable-list ) */
9955 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9957 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9961 final ( expression ) */
9964 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9966 location_t loc
= c_parser_peek_token (parser
)->location
;
9967 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9969 tree t
= c_parser_paren_condition (parser
);
9972 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9974 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9975 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9976 OMP_CLAUSE_CHAIN (c
) = list
;
9980 c_parser_error (parser
, "expected %<(%>");
9986 if ( expression ) */
9989 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9991 location_t loc
= c_parser_peek_token (parser
)->location
;
9992 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9994 tree t
= c_parser_paren_condition (parser
);
9997 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9999 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
10000 OMP_CLAUSE_IF_EXPR (c
) = t
;
10001 OMP_CLAUSE_CHAIN (c
) = list
;
10005 c_parser_error (parser
, "expected %<(%>");
10011 lastprivate ( variable-list ) */
10014 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10016 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10023 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10027 /* FIXME: Should we allow duplicates? */
10028 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10030 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10031 OMP_CLAUSE_MERGEABLE
);
10032 OMP_CLAUSE_CHAIN (c
) = list
;
10041 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10044 location_t loc
= c_parser_peek_token (parser
)->location
;
10046 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10048 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10049 OMP_CLAUSE_CHAIN (c
) = list
;
10054 num_threads ( expression ) */
10057 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10059 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10060 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10062 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10063 tree c
, t
= c_parser_expression (parser
).value
;
10065 t
= c_fully_fold (t
, false, NULL
);
10067 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10069 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10071 c_parser_error (parser
, "expected integer expression");
10075 /* Attempt to statically determine when the number isn't positive. */
10076 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10077 build_int_cst (TREE_TYPE (t
), 0));
10078 if (CAN_HAVE_LOCATION_P (c
))
10079 SET_EXPR_LOCATION (c
, expr_loc
);
10080 if (c
== boolean_true_node
)
10082 warning_at (expr_loc
, 0,
10083 "%<num_threads%> value must be positive");
10084 t
= integer_one_node
;
10087 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10089 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10090 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10091 OMP_CLAUSE_CHAIN (c
) = list
;
10102 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10106 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10108 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10109 OMP_CLAUSE_ORDERED
);
10110 OMP_CLAUSE_CHAIN (c
) = list
;
10116 private ( variable-list ) */
10119 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10121 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10125 reduction ( reduction-operator : variable-list )
10127 reduction-operator:
10128 One of: + * - & ^ | && ||
10132 reduction-operator:
10133 One of: + * - & ^ | && || max min
10137 reduction-operator:
10138 One of: + * - & ^ | && ||
10142 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10144 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10145 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10147 enum tree_code code
= ERROR_MARK
;
10148 tree reduc_id
= NULL_TREE
;
10150 switch (c_parser_peek_token (parser
)->type
)
10162 code
= BIT_AND_EXPR
;
10165 code
= BIT_XOR_EXPR
;
10168 code
= BIT_IOR_EXPR
;
10171 code
= TRUTH_ANDIF_EXPR
;
10174 code
= TRUTH_ORIF_EXPR
;
10179 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10180 if (strcmp (p
, "min") == 0)
10185 if (strcmp (p
, "max") == 0)
10190 reduc_id
= c_parser_peek_token (parser
)->value
;
10194 c_parser_error (parser
,
10195 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10196 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10200 c_parser_consume_token (parser
);
10201 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10202 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10206 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10207 OMP_CLAUSE_REDUCTION
, list
);
10208 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10210 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10211 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10212 if (code
== ERROR_MARK
10213 || !(INTEGRAL_TYPE_P (type
)
10214 || TREE_CODE (type
) == REAL_TYPE
10215 || TREE_CODE (type
) == COMPLEX_TYPE
))
10216 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10217 = c_omp_reduction_lookup (reduc_id
,
10218 TYPE_MAIN_VARIANT (type
));
10223 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10229 schedule ( schedule-kind )
10230 schedule ( schedule-kind , expression )
10233 static | dynamic | guided | runtime | auto
10237 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10240 location_t loc
= c_parser_peek_token (parser
)->location
;
10242 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10245 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10247 if (c_parser_next_token_is (parser
, CPP_NAME
))
10249 tree kind
= c_parser_peek_token (parser
)->value
;
10250 const char *p
= IDENTIFIER_POINTER (kind
);
10255 if (strcmp ("dynamic", p
) != 0)
10257 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10261 if (strcmp ("guided", p
) != 0)
10263 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10267 if (strcmp ("runtime", p
) != 0)
10269 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10276 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10277 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10278 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10279 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10283 c_parser_consume_token (parser
);
10284 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10287 c_parser_consume_token (parser
);
10289 here
= c_parser_peek_token (parser
)->location
;
10290 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10292 t
= c_fully_fold (t
, false, NULL
);
10294 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10295 error_at (here
, "schedule %<runtime%> does not take "
10296 "a %<chunk_size%> parameter");
10297 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10299 "schedule %<auto%> does not take "
10300 "a %<chunk_size%> parameter");
10301 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10302 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10304 c_parser_error (parser
, "expected integer expression");
10306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10309 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10310 "expected %<,%> or %<)%>");
10312 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10313 OMP_CLAUSE_CHAIN (c
) = list
;
10317 c_parser_error (parser
, "invalid schedule kind");
10318 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10323 shared ( variable-list ) */
10326 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10328 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10335 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10339 /* FIXME: Should we allow duplicates? */
10340 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10342 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10343 OMP_CLAUSE_UNTIED
);
10344 OMP_CLAUSE_CHAIN (c
) = list
;
10354 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10355 enum omp_clause_code code
, tree list
)
10357 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10359 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10360 OMP_CLAUSE_CHAIN (c
) = list
;
10372 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10373 enum omp_clause_code code
, tree list
)
10375 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10376 OMP_CLAUSE_CHAIN (c
) = list
;
10382 num_teams ( expression ) */
10385 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10387 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10388 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10390 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10391 tree c
, t
= c_parser_expression (parser
).value
;
10393 t
= c_fully_fold (t
, false, NULL
);
10395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10397 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10399 c_parser_error (parser
, "expected integer expression");
10403 /* Attempt to statically determine when the number isn't positive. */
10404 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10405 build_int_cst (TREE_TYPE (t
), 0));
10406 if (CAN_HAVE_LOCATION_P (c
))
10407 SET_EXPR_LOCATION (c
, expr_loc
);
10408 if (c
== boolean_true_node
)
10410 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10411 t
= integer_one_node
;
10414 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10416 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10417 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10418 OMP_CLAUSE_CHAIN (c
) = list
;
10426 thread_limit ( expression ) */
10429 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10431 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10432 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10434 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10435 tree c
, t
= c_parser_expression (parser
).value
;
10437 t
= c_fully_fold (t
, false, NULL
);
10439 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10441 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10443 c_parser_error (parser
, "expected integer expression");
10447 /* Attempt to statically determine when the number isn't positive. */
10448 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10449 build_int_cst (TREE_TYPE (t
), 0));
10450 if (CAN_HAVE_LOCATION_P (c
))
10451 SET_EXPR_LOCATION (c
, expr_loc
);
10452 if (c
== boolean_true_node
)
10454 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10455 t
= integer_one_node
;
10458 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10461 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10462 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10463 OMP_CLAUSE_CHAIN (c
) = list
;
10471 aligned ( variable-list )
10472 aligned ( variable-list : constant-expression ) */
10475 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10477 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10480 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10483 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10484 OMP_CLAUSE_ALIGNED
, list
);
10486 if (c_parser_next_token_is (parser
, CPP_COLON
))
10488 c_parser_consume_token (parser
);
10489 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10490 mark_exp_read (alignment
);
10491 alignment
= c_fully_fold (alignment
, false, NULL
);
10492 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10493 && TREE_CODE (alignment
) != INTEGER_CST
10494 && tree_int_cst_sgn (alignment
) != 1)
10496 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10497 "be positive constant integer expression");
10498 alignment
= NULL_TREE
;
10501 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10502 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10505 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10510 linear ( variable-list )
10511 linear ( variable-list : expression ) */
10514 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10516 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10519 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10522 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10523 OMP_CLAUSE_LINEAR
, list
);
10525 if (c_parser_next_token_is (parser
, CPP_COLON
))
10527 c_parser_consume_token (parser
);
10528 step
= c_parser_expression (parser
).value
;
10529 mark_exp_read (step
);
10530 step
= c_fully_fold (step
, false, NULL
);
10531 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10533 sorry ("using parameters for %<linear%> step is not supported yet");
10534 step
= integer_one_node
;
10536 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10538 error_at (clause_loc
, "%<linear%> clause step expression must "
10540 step
= integer_one_node
;
10545 step
= integer_one_node
;
10547 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10549 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10552 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10557 safelen ( constant-expression ) */
10560 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10562 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10565 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10568 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10570 t
= c_fully_fold (t
, false, NULL
);
10571 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10572 && TREE_CODE (t
) != INTEGER_CST
10573 && tree_int_cst_sgn (t
) != 1)
10575 error_at (clause_loc
, "%<safelen%> clause expression must "
10576 "be positive constant integer expression");
10580 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10581 if (t
== NULL_TREE
|| t
== error_mark_node
)
10584 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10586 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10587 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10588 OMP_CLAUSE_CHAIN (c
) = list
;
10593 simdlen ( constant-expression ) */
10596 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10598 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10601 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10604 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10606 t
= c_fully_fold (t
, false, NULL
);
10607 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10608 && TREE_CODE (t
) != INTEGER_CST
10609 && tree_int_cst_sgn (t
) != 1)
10611 error_at (clause_loc
, "%<simdlen%> clause expression must "
10612 "be positive constant integer expression");
10616 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10617 if (t
== NULL_TREE
|| t
== error_mark_node
)
10620 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10622 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10623 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10624 OMP_CLAUSE_CHAIN (c
) = list
;
10629 depend ( depend-kind: variable-list )
10632 in | out | inout */
10635 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10637 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10638 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10641 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10644 if (c_parser_next_token_is (parser
, CPP_NAME
))
10646 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10647 if (strcmp ("in", p
) == 0)
10648 kind
= OMP_CLAUSE_DEPEND_IN
;
10649 else if (strcmp ("inout", p
) == 0)
10650 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10651 else if (strcmp ("out", p
) == 0)
10652 kind
= OMP_CLAUSE_DEPEND_OUT
;
10659 c_parser_consume_token (parser
);
10660 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10663 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10664 OMP_CLAUSE_DEPEND
, list
);
10666 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10667 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10669 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10673 c_parser_error (parser
, "invalid depend kind");
10675 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10680 map ( map-kind: variable-list )
10681 map ( variable-list )
10684 alloc | to | from | tofrom */
10687 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10689 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10690 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10693 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10696 if (c_parser_next_token_is (parser
, CPP_NAME
)
10697 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10699 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10700 if (strcmp ("alloc", p
) == 0)
10701 kind
= OMP_CLAUSE_MAP_ALLOC
;
10702 else if (strcmp ("to", p
) == 0)
10703 kind
= OMP_CLAUSE_MAP_TO
;
10704 else if (strcmp ("from", p
) == 0)
10705 kind
= OMP_CLAUSE_MAP_FROM
;
10706 else if (strcmp ("tofrom", p
) == 0)
10707 kind
= OMP_CLAUSE_MAP_TOFROM
;
10710 c_parser_error (parser
, "invalid map kind");
10711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10715 c_parser_consume_token (parser
);
10716 c_parser_consume_token (parser
);
10719 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10721 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10722 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10724 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10729 device ( expression ) */
10732 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10734 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10735 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10737 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10739 t
= c_fully_fold (t
, false, NULL
);
10741 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10743 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10745 c_parser_error (parser
, "expected integer expression");
10749 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10751 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10752 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10753 OMP_CLAUSE_CHAIN (c
) = list
;
10761 dist_schedule ( static )
10762 dist_schedule ( static , expression ) */
10765 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10767 tree c
, t
= NULL_TREE
;
10768 location_t loc
= c_parser_peek_token (parser
)->location
;
10770 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10773 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10775 c_parser_error (parser
, "invalid dist_schedule kind");
10776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10781 c_parser_consume_token (parser
);
10782 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10784 c_parser_consume_token (parser
);
10786 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10788 t
= c_fully_fold (t
, false, NULL
);
10789 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10793 "expected %<,%> or %<)%>");
10795 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10796 if (t
== error_mark_node
)
10799 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10800 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10801 OMP_CLAUSE_CHAIN (c
) = list
;
10806 proc_bind ( proc-bind-kind )
10809 master | close | spread */
10812 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10814 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10815 enum omp_clause_proc_bind_kind kind
;
10818 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10821 if (c_parser_next_token_is (parser
, CPP_NAME
))
10823 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10824 if (strcmp ("master", p
) == 0)
10825 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10826 else if (strcmp ("close", p
) == 0)
10827 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10828 else if (strcmp ("spread", p
) == 0)
10829 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10836 c_parser_consume_token (parser
);
10837 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10838 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10839 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10840 OMP_CLAUSE_CHAIN (c
) = list
;
10844 c_parser_error (parser
, "invalid proc_bind kind");
10845 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10850 to ( variable-list ) */
10853 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10855 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10859 from ( variable-list ) */
10862 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10864 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10868 uniform ( variable-list ) */
10871 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10873 /* The clauses location. */
10874 location_t loc
= c_parser_peek_token (parser
)->location
;
10876 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10878 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10885 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10886 is a bitmask in MASK. Return the list of clauses found; the result
10887 of clause default goes in *pdefault. */
10890 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10891 const char *where
, bool finish_p
= true)
10893 tree clauses
= NULL
;
10894 bool first
= true, cilk_simd_fn
= false;
10896 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10899 pragma_omp_clause c_kind
;
10900 const char *c_name
;
10901 tree prev
= clauses
;
10903 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10904 c_parser_consume_token (parser
);
10906 here
= c_parser_peek_token (parser
)->location
;
10907 c_kind
= c_parser_omp_clause_name (parser
);
10911 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10912 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10913 c_name
= "collapse";
10915 case PRAGMA_OMP_CLAUSE_COPYIN
:
10916 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10919 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10920 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10921 c_name
= "copyprivate";
10923 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10924 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10925 c_name
= "default";
10927 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10928 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10929 c_name
= "firstprivate";
10931 case PRAGMA_OMP_CLAUSE_FINAL
:
10932 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10935 case PRAGMA_OMP_CLAUSE_IF
:
10936 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10939 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10940 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10941 c_name
= "lastprivate";
10943 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10944 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10945 c_name
= "mergeable";
10947 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10948 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10951 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10952 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10953 c_name
= "num_threads";
10955 case PRAGMA_OMP_CLAUSE_ORDERED
:
10956 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10957 c_name
= "ordered";
10959 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10960 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10961 c_name
= "private";
10963 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10964 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10965 c_name
= "reduction";
10967 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10968 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10969 c_name
= "schedule";
10971 case PRAGMA_OMP_CLAUSE_SHARED
:
10972 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10975 case PRAGMA_OMP_CLAUSE_UNTIED
:
10976 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10979 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10980 case PRAGMA_CILK_CLAUSE_MASK
:
10981 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10983 c_name
= "inbranch";
10985 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10986 case PRAGMA_CILK_CLAUSE_NOMASK
:
10987 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10989 c_name
= "notinbranch";
10991 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10993 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10995 c_name
= "parallel";
10999 error_at (here
, "%qs must be the first clause of %qs",
11004 case PRAGMA_OMP_CLAUSE_FOR
:
11006 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11010 goto clause_not_first
;
11012 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11014 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11016 c_name
= "sections";
11018 goto clause_not_first
;
11020 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11022 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11024 c_name
= "taskgroup";
11026 goto clause_not_first
;
11028 case PRAGMA_OMP_CLAUSE_TO
:
11029 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11032 case PRAGMA_OMP_CLAUSE_FROM
:
11033 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11036 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11037 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11038 c_name
= "uniform";
11040 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11041 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11042 c_name
= "num_teams";
11044 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11045 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11046 c_name
= "thread_limit";
11048 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11049 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11050 c_name
= "aligned";
11052 case PRAGMA_OMP_CLAUSE_LINEAR
:
11053 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11054 cilk_simd_fn
= true;
11055 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11058 case PRAGMA_OMP_CLAUSE_DEPEND
:
11059 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11062 case PRAGMA_OMP_CLAUSE_MAP
:
11063 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11066 case PRAGMA_OMP_CLAUSE_DEVICE
:
11067 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11070 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11071 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11072 c_name
= "dist_schedule";
11074 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11075 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11076 c_name
= "proc_bind";
11078 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11079 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11080 c_name
= "safelen";
11082 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11083 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11084 c_name
= "simdlen";
11086 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11087 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11088 c_name
= "simdlen";
11091 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11097 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11099 /* Remove the invalid clause(s) from the list to avoid
11100 confusing the rest of the compiler. */
11102 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11107 c_parser_skip_to_pragma_eol (parser
);
11110 return c_finish_omp_clauses (clauses
);
11119 In practice, we're also interested in adding the statement to an
11120 outer node. So it is convenient if we work around the fact that
11121 c_parser_statement calls add_stmt. */
11124 c_parser_omp_structured_block (c_parser
*parser
)
11126 tree stmt
= push_stmt_list ();
11127 c_parser_statement (parser
);
11128 return pop_stmt_list (stmt
);
11132 # pragma omp atomic new-line
11136 x binop= expr | x++ | ++x | x-- | --x
11138 +, *, -, /, &, ^, |, <<, >>
11140 where x is an lvalue expression with scalar type.
11143 # pragma omp atomic new-line
11146 # pragma omp atomic read new-line
11149 # pragma omp atomic write new-line
11152 # pragma omp atomic update new-line
11155 # pragma omp atomic capture new-line
11158 # pragma omp atomic capture new-line
11166 expression-stmt | x = x binop expr
11168 v = expression-stmt
11170 { v = x; update-stmt; } | { update-stmt; v = x; }
11174 expression-stmt | x = x binop expr | x = expr binop x
11178 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11180 where x and v are lvalue expressions with scalar type.
11182 LOC is the location of the #pragma token. */
11185 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11187 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11188 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11189 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11190 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11191 struct c_expr expr
;
11193 bool structured_block
= false;
11194 bool swapped
= false;
11195 bool seq_cst
= false;
11197 if (c_parser_next_token_is (parser
, CPP_NAME
))
11199 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11200 if (!strcmp (p
, "seq_cst"))
11203 c_parser_consume_token (parser
);
11204 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11205 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11206 c_parser_consume_token (parser
);
11209 if (c_parser_next_token_is (parser
, CPP_NAME
))
11211 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11213 if (!strcmp (p
, "read"))
11214 code
= OMP_ATOMIC_READ
;
11215 else if (!strcmp (p
, "write"))
11217 else if (!strcmp (p
, "update"))
11219 else if (!strcmp (p
, "capture"))
11220 code
= OMP_ATOMIC_CAPTURE_NEW
;
11224 c_parser_consume_token (parser
);
11228 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11229 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11230 c_parser_consume_token (parser
);
11232 if (c_parser_next_token_is (parser
, CPP_NAME
))
11235 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11236 if (!strcmp (p
, "seq_cst"))
11239 c_parser_consume_token (parser
);
11243 c_parser_skip_to_pragma_eol (parser
);
11247 case OMP_ATOMIC_READ
:
11248 case NOP_EXPR
: /* atomic write */
11249 v
= c_parser_unary_expression (parser
).value
;
11250 v
= c_fully_fold (v
, false, NULL
);
11251 if (v
== error_mark_node
)
11253 loc
= c_parser_peek_token (parser
)->location
;
11254 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11256 if (code
== NOP_EXPR
)
11257 lhs
= c_parser_expression (parser
).value
;
11259 lhs
= c_parser_unary_expression (parser
).value
;
11260 lhs
= c_fully_fold (lhs
, false, NULL
);
11261 if (lhs
== error_mark_node
)
11263 if (code
== NOP_EXPR
)
11265 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11273 case OMP_ATOMIC_CAPTURE_NEW
:
11274 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11276 c_parser_consume_token (parser
);
11277 structured_block
= true;
11281 v
= c_parser_unary_expression (parser
).value
;
11282 v
= c_fully_fold (v
, false, NULL
);
11283 if (v
== error_mark_node
)
11285 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11293 /* For structured_block case we don't know yet whether
11294 old or new x should be captured. */
11296 eloc
= c_parser_peek_token (parser
)->location
;
11297 expr
= c_parser_unary_expression (parser
);
11299 expr
= default_function_array_conversion (eloc
, expr
);
11300 unfolded_lhs
= expr
.value
;
11301 lhs
= c_fully_fold (lhs
, false, NULL
);
11303 switch (TREE_CODE (lhs
))
11307 c_parser_skip_to_end_of_block_or_statement (parser
);
11308 if (structured_block
)
11310 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11311 c_parser_consume_token (parser
);
11312 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11314 c_parser_skip_to_end_of_block_or_statement (parser
);
11315 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11316 c_parser_consume_token (parser
);
11321 case POSTINCREMENT_EXPR
:
11322 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11323 code
= OMP_ATOMIC_CAPTURE_OLD
;
11325 case PREINCREMENT_EXPR
:
11326 lhs
= TREE_OPERAND (lhs
, 0);
11327 unfolded_lhs
= NULL_TREE
;
11328 opcode
= PLUS_EXPR
;
11329 rhs
= integer_one_node
;
11332 case POSTDECREMENT_EXPR
:
11333 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11334 code
= OMP_ATOMIC_CAPTURE_OLD
;
11336 case PREDECREMENT_EXPR
:
11337 lhs
= TREE_OPERAND (lhs
, 0);
11338 unfolded_lhs
= NULL_TREE
;
11339 opcode
= MINUS_EXPR
;
11340 rhs
= integer_one_node
;
11343 case COMPOUND_EXPR
:
11344 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11345 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11346 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11347 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11348 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11349 (TREE_OPERAND (lhs
, 1), 0), 0)))
11351 /* Undo effects of boolean_increment for post {in,de}crement. */
11352 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11355 if (TREE_CODE (lhs
) == MODIFY_EXPR
11356 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11358 /* Undo effects of boolean_increment. */
11359 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11361 /* This is pre or post increment. */
11362 rhs
= TREE_OPERAND (lhs
, 1);
11363 lhs
= TREE_OPERAND (lhs
, 0);
11364 unfolded_lhs
= NULL_TREE
;
11366 if (code
== OMP_ATOMIC_CAPTURE_NEW
11367 && !structured_block
11368 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11369 code
= OMP_ATOMIC_CAPTURE_OLD
;
11372 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11373 && TREE_OPERAND (lhs
, 0)
11374 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11376 /* This is pre or post decrement. */
11377 rhs
= TREE_OPERAND (lhs
, 1);
11378 lhs
= TREE_OPERAND (lhs
, 0);
11379 unfolded_lhs
= NULL_TREE
;
11381 if (code
== OMP_ATOMIC_CAPTURE_NEW
11382 && !structured_block
11383 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11384 code
= OMP_ATOMIC_CAPTURE_OLD
;
11390 switch (c_parser_peek_token (parser
)->type
)
11393 opcode
= MULT_EXPR
;
11396 opcode
= TRUNC_DIV_EXPR
;
11399 opcode
= PLUS_EXPR
;
11402 opcode
= MINUS_EXPR
;
11404 case CPP_LSHIFT_EQ
:
11405 opcode
= LSHIFT_EXPR
;
11407 case CPP_RSHIFT_EQ
:
11408 opcode
= RSHIFT_EXPR
;
11411 opcode
= BIT_AND_EXPR
;
11414 opcode
= BIT_IOR_EXPR
;
11417 opcode
= BIT_XOR_EXPR
;
11420 c_parser_consume_token (parser
);
11421 eloc
= c_parser_peek_token (parser
)->location
;
11422 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11424 switch (TREE_CODE (rhs1
))
11427 case TRUNC_DIV_EXPR
:
11435 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11437 opcode
= TREE_CODE (rhs1
);
11438 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11439 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11442 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11444 opcode
= TREE_CODE (rhs1
);
11445 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11446 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11447 swapped
= !commutative_tree_code (opcode
);
11456 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11458 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11460 code
= OMP_ATOMIC_CAPTURE_OLD
;
11463 expr
= default_function_array_read_conversion (eloc
, expr
);
11464 unfolded_lhs1
= expr
.value
;
11465 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11467 c_parser_consume_token (parser
);
11470 if (structured_block
)
11473 expr
= default_function_array_read_conversion (eloc
, expr
);
11474 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11479 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11482 c_parser_error (parser
,
11483 "invalid operator for %<#pragma omp atomic%>");
11487 /* Arrange to pass the location of the assignment operator to
11488 c_finish_omp_atomic. */
11489 loc
= c_parser_peek_token (parser
)->location
;
11490 c_parser_consume_token (parser
);
11491 eloc
= c_parser_peek_token (parser
)->location
;
11492 expr
= c_parser_expression (parser
);
11493 expr
= default_function_array_read_conversion (eloc
, expr
);
11495 rhs
= c_fully_fold (rhs
, false, NULL
);
11499 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11501 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11503 v
= c_parser_unary_expression (parser
).value
;
11504 v
= c_fully_fold (v
, false, NULL
);
11505 if (v
== error_mark_node
)
11507 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11509 eloc
= c_parser_peek_token (parser
)->location
;
11510 expr
= c_parser_unary_expression (parser
);
11512 expr
= default_function_array_read_conversion (eloc
, expr
);
11513 unfolded_lhs1
= expr
.value
;
11514 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11515 if (lhs1
== error_mark_node
)
11518 if (structured_block
)
11520 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11521 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11524 if (unfolded_lhs
&& unfolded_lhs1
11525 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11527 error ("%<#pragma omp atomic capture%> uses two different "
11528 "expressions for memory");
11529 stmt
= error_mark_node
;
11532 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11534 if (stmt
!= error_mark_node
)
11537 if (!structured_block
)
11538 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11543 # pragma omp barrier new-line
11547 c_parser_omp_barrier (c_parser
*parser
)
11549 location_t loc
= c_parser_peek_token (parser
)->location
;
11550 c_parser_consume_pragma (parser
);
11551 c_parser_skip_to_pragma_eol (parser
);
11553 c_finish_omp_barrier (loc
);
11557 # pragma omp critical [(name)] new-line
11560 LOC is the location of the #pragma itself. */
11563 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11565 tree stmt
, name
= NULL
;
11567 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11569 c_parser_consume_token (parser
);
11570 if (c_parser_next_token_is (parser
, CPP_NAME
))
11572 name
= c_parser_peek_token (parser
)->value
;
11573 c_parser_consume_token (parser
);
11574 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11577 c_parser_error (parser
, "expected identifier");
11579 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11580 c_parser_error (parser
, "expected %<(%> or end of line");
11581 c_parser_skip_to_pragma_eol (parser
);
11583 stmt
= c_parser_omp_structured_block (parser
);
11584 return c_finish_omp_critical (loc
, stmt
, name
);
11588 # pragma omp flush flush-vars[opt] new-line
11591 ( variable-list ) */
11594 c_parser_omp_flush (c_parser
*parser
)
11596 location_t loc
= c_parser_peek_token (parser
)->location
;
11597 c_parser_consume_pragma (parser
);
11598 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11599 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11600 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11601 c_parser_error (parser
, "expected %<(%> or end of line");
11602 c_parser_skip_to_pragma_eol (parser
);
11604 c_finish_omp_flush (loc
);
11607 /* Parse the restricted form of the for statement allowed by OpenMP.
11608 The real trick here is to determine the loop control variable early
11609 so that we can push a new decl if necessary to make it private.
11610 LOC is the location of the OMP in "#pragma omp". */
11613 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11614 tree clauses
, tree
*cclauses
)
11616 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11617 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11618 bool fail
= false, open_brace_parsed
= false;
11619 int i
, collapse
= 1, nbraces
= 0;
11620 location_t for_loc
;
11621 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11623 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11624 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11625 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11627 gcc_assert (collapse
>= 1);
11629 declv
= make_tree_vec (collapse
);
11630 initv
= make_tree_vec (collapse
);
11631 condv
= make_tree_vec (collapse
);
11632 incrv
= make_tree_vec (collapse
);
11634 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11636 c_parser_error (parser
, "for statement expected");
11639 for_loc
= c_parser_peek_token (parser
)->location
;
11640 c_parser_consume_token (parser
);
11642 for (i
= 0; i
< collapse
; i
++)
11644 int bracecount
= 0;
11646 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11649 /* Parse the initialization declaration or expression. */
11650 if (c_parser_next_tokens_start_declaration (parser
))
11653 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11654 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11656 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11659 if (DECL_INITIAL (decl
) == error_mark_node
)
11660 decl
= error_mark_node
;
11663 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11664 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11666 struct c_expr decl_exp
;
11667 struct c_expr init_exp
;
11668 location_t init_loc
;
11670 decl_exp
= c_parser_postfix_expression (parser
);
11671 decl
= decl_exp
.value
;
11673 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11675 init_loc
= c_parser_peek_token (parser
)->location
;
11676 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11677 init_exp
= default_function_array_read_conversion (init_loc
,
11679 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11680 NOP_EXPR
, init_loc
, init_exp
.value
,
11681 init_exp
.original_type
);
11682 init
= c_process_expr_stmt (init_loc
, init
);
11684 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11689 c_parser_error (parser
,
11690 "expected iteration declaration or initialization");
11691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11697 /* Parse the loop condition. */
11699 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11701 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11702 struct c_expr cond_expr
11703 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11705 cond
= cond_expr
.value
;
11706 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11707 cond
= c_fully_fold (cond
, false, NULL
);
11708 switch (cond_expr
.original_code
)
11716 if (code
== CILK_SIMD
)
11720 /* Can't be cond = error_mark_node, because we want to preserve
11721 the location until c_finish_omp_for. */
11722 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11725 protected_set_expr_location (cond
, cond_loc
);
11727 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11729 /* Parse the increment expression. */
11731 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11733 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11735 incr
= c_process_expr_stmt (incr_loc
,
11736 c_parser_expression (parser
).value
);
11738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11740 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11744 TREE_VEC_ELT (declv
, i
) = decl
;
11745 TREE_VEC_ELT (initv
, i
) = init
;
11746 TREE_VEC_ELT (condv
, i
) = cond
;
11747 TREE_VEC_ELT (incrv
, i
) = incr
;
11751 if (i
== collapse
- 1)
11754 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11755 in between the collapsed for loops to be still considered perfectly
11756 nested. Hopefully the final version clarifies this.
11757 For now handle (multiple) {'s and empty statements. */
11760 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11762 c_parser_consume_token (parser
);
11765 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11767 c_parser_consume_token (parser
);
11770 else if (bracecount
11771 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11772 c_parser_consume_token (parser
);
11775 c_parser_error (parser
, "not enough perfectly nested loops");
11778 open_brace_parsed
= true;
11788 nbraces
+= bracecount
;
11791 save_break
= c_break_label
;
11792 if (code
== CILK_SIMD
)
11793 c_break_label
= build_int_cst (size_type_node
, 2);
11795 c_break_label
= size_one_node
;
11796 save_cont
= c_cont_label
;
11797 c_cont_label
= NULL_TREE
;
11798 body
= push_stmt_list ();
11800 if (open_brace_parsed
)
11802 location_t here
= c_parser_peek_token (parser
)->location
;
11803 stmt
= c_begin_compound_stmt (true);
11804 c_parser_compound_statement_nostart (parser
);
11805 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11808 add_stmt (c_parser_c99_block_statement (parser
));
11811 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11812 SET_EXPR_LOCATION (t
, loc
);
11816 body
= pop_stmt_list (body
);
11817 c_break_label
= save_break
;
11818 c_cont_label
= save_cont
;
11822 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11824 c_parser_consume_token (parser
);
11827 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11828 c_parser_consume_token (parser
);
11831 c_parser_error (parser
, "collapsed loops not perfectly nested");
11834 location_t here
= c_parser_peek_token (parser
)->location
;
11835 stmt
= c_begin_compound_stmt (true);
11837 c_parser_compound_statement_nostart (parser
);
11838 body
= c_end_compound_stmt (here
, stmt
, true);
11845 /* Only bother calling c_finish_omp_for if we haven't already generated
11846 an error from the initialization parsing. */
11849 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11850 incrv
, body
, NULL
);
11853 if (cclauses
!= NULL
11854 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11857 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11858 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11859 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11860 c
= &OMP_CLAUSE_CHAIN (*c
);
11863 for (i
= 0; i
< collapse
; i
++)
11864 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11867 c
= &OMP_CLAUSE_CHAIN (*c
);
11868 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11871 "iteration variable %qD should not be firstprivate",
11872 OMP_CLAUSE_DECL (*c
));
11873 *c
= OMP_CLAUSE_CHAIN (*c
);
11877 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11878 change it to shared (decl) in
11879 OMP_PARALLEL_CLAUSES. */
11880 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11881 OMP_CLAUSE_LASTPRIVATE
);
11882 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11883 OMP_CLAUSE_CHAIN (l
) = clauses
;
11885 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11889 OMP_FOR_CLAUSES (stmt
) = clauses
;
11894 while (!for_block
->is_empty ())
11896 /* FIXME diagnostics: LOC below should be the actual location of
11897 this particular for block. We need to build a list of
11898 locations to go along with FOR_BLOCK. */
11899 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11902 release_tree_vector (for_block
);
11906 /* Helper function for OpenMP parsing, split clauses and call
11907 finish_omp_clauses on each of the set of clauses afterwards. */
11910 omp_split_clauses (location_t loc
, enum tree_code code
,
11911 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11914 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11915 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11917 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11921 #pragma omp simd simd-clause[optseq] new-line
11924 LOC is the location of the #pragma token.
11927 #define OMP_SIMD_CLAUSE_MASK \
11928 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11929 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11930 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11931 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11932 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11937 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11938 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11940 tree block
, clauses
, ret
;
11942 strcat (p_name
, " simd");
11943 mask
|= OMP_SIMD_CLAUSE_MASK
;
11944 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11946 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11949 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11950 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11953 block
= c_begin_compound_stmt (true);
11954 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11955 block
= c_end_compound_stmt (loc
, block
, true);
11962 #pragma omp for for-clause[optseq] new-line
11966 #pragma omp for simd for-simd-clause[optseq] new-line
11969 LOC is the location of the #pragma token.
11972 #define OMP_FOR_CLAUSE_MASK \
11973 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11974 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11983 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11984 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11986 tree block
, clauses
, ret
;
11988 strcat (p_name
, " for");
11989 mask
|= OMP_FOR_CLAUSE_MASK
;
11991 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11993 if (c_parser_next_token_is (parser
, CPP_NAME
))
11995 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11997 if (strcmp (p
, "simd") == 0)
11999 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12000 if (cclauses
== NULL
)
12001 cclauses
= cclauses_buf
;
12003 c_parser_consume_token (parser
);
12004 if (!flag_openmp
) /* flag_openmp_simd */
12005 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12006 block
= c_begin_compound_stmt (true);
12007 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12008 block
= c_end_compound_stmt (loc
, block
, true);
12009 if (ret
== NULL_TREE
)
12011 ret
= make_node (OMP_FOR
);
12012 TREE_TYPE (ret
) = void_type_node
;
12013 OMP_FOR_BODY (ret
) = block
;
12014 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12015 SET_EXPR_LOCATION (ret
, loc
);
12020 if (!flag_openmp
) /* flag_openmp_simd */
12022 c_parser_skip_to_pragma_eol (parser
);
12026 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12029 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12030 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12033 block
= c_begin_compound_stmt (true);
12034 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12035 block
= c_end_compound_stmt (loc
, block
, true);
12042 # pragma omp master new-line
12045 LOC is the location of the #pragma token.
12049 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12051 c_parser_skip_to_pragma_eol (parser
);
12052 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12056 # pragma omp ordered new-line
12059 LOC is the location of the #pragma itself.
12063 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12065 c_parser_skip_to_pragma_eol (parser
);
12066 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12072 { section-sequence }
12075 section-directive[opt] structured-block
12076 section-sequence section-directive structured-block
12078 SECTIONS_LOC is the location of the #pragma omp sections. */
12081 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12083 tree stmt
, substmt
;
12084 bool error_suppress
= false;
12087 loc
= c_parser_peek_token (parser
)->location
;
12088 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12090 /* Avoid skipping until the end of the block. */
12091 parser
->error
= false;
12095 stmt
= push_stmt_list ();
12097 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12099 substmt
= c_parser_omp_structured_block (parser
);
12100 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12101 SET_EXPR_LOCATION (substmt
, loc
);
12102 add_stmt (substmt
);
12107 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12109 if (c_parser_next_token_is (parser
, CPP_EOF
))
12112 loc
= c_parser_peek_token (parser
)->location
;
12113 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12115 c_parser_consume_pragma (parser
);
12116 c_parser_skip_to_pragma_eol (parser
);
12117 error_suppress
= false;
12119 else if (!error_suppress
)
12121 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12122 error_suppress
= true;
12125 substmt
= c_parser_omp_structured_block (parser
);
12126 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12127 SET_EXPR_LOCATION (substmt
, loc
);
12128 add_stmt (substmt
);
12130 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12131 "expected %<#pragma omp section%> or %<}%>");
12133 substmt
= pop_stmt_list (stmt
);
12135 stmt
= make_node (OMP_SECTIONS
);
12136 SET_EXPR_LOCATION (stmt
, sections_loc
);
12137 TREE_TYPE (stmt
) = void_type_node
;
12138 OMP_SECTIONS_BODY (stmt
) = substmt
;
12140 return add_stmt (stmt
);
12144 # pragma omp sections sections-clause[optseq] newline
12147 LOC is the location of the #pragma token.
12150 #define OMP_SECTIONS_CLAUSE_MASK \
12151 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12152 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12153 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12154 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12155 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12158 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12159 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12161 tree block
, clauses
, ret
;
12163 strcat (p_name
, " sections");
12164 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12166 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12168 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12171 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12172 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12175 block
= c_begin_compound_stmt (true);
12176 ret
= c_parser_omp_sections_scope (loc
, parser
);
12178 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12179 block
= c_end_compound_stmt (loc
, block
, true);
12186 # pragma omp parallel parallel-clause[optseq] new-line
12188 # pragma omp parallel for parallel-for-clause[optseq] new-line
12190 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12194 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12197 LOC is the location of the #pragma token.
12200 #define OMP_PARALLEL_CLAUSE_MASK \
12201 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12202 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12203 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12204 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12205 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12206 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12212 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12213 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12215 tree stmt
, clauses
, block
;
12217 strcat (p_name
, " parallel");
12218 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12220 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12222 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12223 if (cclauses
== NULL
)
12224 cclauses
= cclauses_buf
;
12226 c_parser_consume_token (parser
);
12227 if (!flag_openmp
) /* flag_openmp_simd */
12228 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12229 block
= c_begin_omp_parallel ();
12230 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12232 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12234 if (ret
== NULL_TREE
)
12236 OMP_PARALLEL_COMBINED (stmt
) = 1;
12241 error_at (loc
, "expected %<for%> after %qs", p_name
);
12242 c_parser_skip_to_pragma_eol (parser
);
12245 else if (!flag_openmp
) /* flag_openmp_simd */
12247 c_parser_skip_to_pragma_eol (parser
);
12250 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12252 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12253 if (strcmp (p
, "sections") == 0)
12255 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12256 if (cclauses
== NULL
)
12257 cclauses
= cclauses_buf
;
12259 c_parser_consume_token (parser
);
12260 block
= c_begin_omp_parallel ();
12261 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12262 stmt
= c_finish_omp_parallel (loc
,
12263 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12265 OMP_PARALLEL_COMBINED (stmt
) = 1;
12270 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12272 block
= c_begin_omp_parallel ();
12273 c_parser_statement (parser
);
12274 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12280 # pragma omp single single-clause[optseq] new-line
12283 LOC is the location of the #pragma.
12286 #define OMP_SINGLE_CLAUSE_MASK \
12287 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12293 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12295 tree stmt
= make_node (OMP_SINGLE
);
12296 SET_EXPR_LOCATION (stmt
, loc
);
12297 TREE_TYPE (stmt
) = void_type_node
;
12299 OMP_SINGLE_CLAUSES (stmt
)
12300 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12301 "#pragma omp single");
12302 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12304 return add_stmt (stmt
);
12308 # pragma omp task task-clause[optseq] new-line
12310 LOC is the location of the #pragma.
12313 #define OMP_TASK_CLAUSE_MASK \
12314 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12316 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12317 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12325 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12327 tree clauses
, block
;
12329 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12330 "#pragma omp task");
12332 block
= c_begin_omp_task ();
12333 c_parser_statement (parser
);
12334 return c_finish_omp_task (loc
, clauses
, block
);
12338 # pragma omp taskwait new-line
12342 c_parser_omp_taskwait (c_parser
*parser
)
12344 location_t loc
= c_parser_peek_token (parser
)->location
;
12345 c_parser_consume_pragma (parser
);
12346 c_parser_skip_to_pragma_eol (parser
);
12348 c_finish_omp_taskwait (loc
);
12352 # pragma omp taskyield new-line
12356 c_parser_omp_taskyield (c_parser
*parser
)
12358 location_t loc
= c_parser_peek_token (parser
)->location
;
12359 c_parser_consume_pragma (parser
);
12360 c_parser_skip_to_pragma_eol (parser
);
12362 c_finish_omp_taskyield (loc
);
12366 # pragma omp taskgroup new-line
12370 c_parser_omp_taskgroup (c_parser
*parser
)
12372 location_t loc
= c_parser_peek_token (parser
)->location
;
12373 c_parser_skip_to_pragma_eol (parser
);
12374 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12378 # pragma omp cancel cancel-clause[optseq] new-line
12380 LOC is the location of the #pragma.
12383 #define OMP_CANCEL_CLAUSE_MASK \
12384 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12385 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12386 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12391 c_parser_omp_cancel (c_parser
*parser
)
12393 location_t loc
= c_parser_peek_token (parser
)->location
;
12395 c_parser_consume_pragma (parser
);
12396 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12397 "#pragma omp cancel");
12399 c_finish_omp_cancel (loc
, clauses
);
12403 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12405 LOC is the location of the #pragma.
12408 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12409 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12410 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12411 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12412 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12415 c_parser_omp_cancellation_point (c_parser
*parser
)
12417 location_t loc
= c_parser_peek_token (parser
)->location
;
12419 bool point_seen
= false;
12421 c_parser_consume_pragma (parser
);
12422 if (c_parser_next_token_is (parser
, CPP_NAME
))
12424 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12425 if (strcmp (p
, "point") == 0)
12427 c_parser_consume_token (parser
);
12433 c_parser_error (parser
, "expected %<point%>");
12434 c_parser_skip_to_pragma_eol (parser
);
12439 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12440 "#pragma omp cancellation point");
12442 c_finish_omp_cancellation_point (loc
, clauses
);
12446 #pragma omp distribute distribute-clause[optseq] new-line
12449 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12450 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12451 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12452 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12453 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12456 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12457 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12459 tree clauses
, block
, ret
;
12461 strcat (p_name
, " distribute");
12462 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12464 if (c_parser_next_token_is (parser
, CPP_NAME
))
12466 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12468 bool parallel
= false;
12470 if (strcmp (p
, "simd") == 0)
12473 parallel
= strcmp (p
, "parallel") == 0;
12474 if (parallel
|| simd
)
12476 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12477 if (cclauses
== NULL
)
12478 cclauses
= cclauses_buf
;
12479 c_parser_consume_token (parser
);
12480 if (!flag_openmp
) /* flag_openmp_simd */
12483 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12485 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12488 block
= c_begin_compound_stmt (true);
12490 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12492 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12493 block
= c_end_compound_stmt (loc
, block
, true);
12496 ret
= make_node (OMP_DISTRIBUTE
);
12497 TREE_TYPE (ret
) = void_type_node
;
12498 OMP_FOR_BODY (ret
) = block
;
12499 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12500 SET_EXPR_LOCATION (ret
, loc
);
12505 if (!flag_openmp
) /* flag_openmp_simd */
12507 c_parser_skip_to_pragma_eol (parser
);
12511 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12514 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12515 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12518 block
= c_begin_compound_stmt (true);
12519 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12520 block
= c_end_compound_stmt (loc
, block
, true);
12527 # pragma omp teams teams-clause[optseq] new-line
12528 structured-block */
12530 #define OMP_TEAMS_CLAUSE_MASK \
12531 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12534 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12535 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12536 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12537 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12540 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12541 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12543 tree clauses
, block
, ret
;
12545 strcat (p_name
, " teams");
12546 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12548 if (c_parser_next_token_is (parser
, CPP_NAME
))
12550 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12551 if (strcmp (p
, "distribute") == 0)
12553 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12554 if (cclauses
== NULL
)
12555 cclauses
= cclauses_buf
;
12557 c_parser_consume_token (parser
);
12558 if (!flag_openmp
) /* flag_openmp_simd */
12559 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12560 block
= c_begin_compound_stmt (true);
12561 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12562 block
= c_end_compound_stmt (loc
, block
, true);
12565 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12566 ret
= make_node (OMP_TEAMS
);
12567 TREE_TYPE (ret
) = void_type_node
;
12568 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12569 OMP_TEAMS_BODY (ret
) = block
;
12570 return add_stmt (ret
);
12573 if (!flag_openmp
) /* flag_openmp_simd */
12575 c_parser_skip_to_pragma_eol (parser
);
12579 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12582 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12583 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12586 tree stmt
= make_node (OMP_TEAMS
);
12587 TREE_TYPE (stmt
) = void_type_node
;
12588 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12589 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12591 return add_stmt (stmt
);
12595 # pragma omp target data target-data-clause[optseq] new-line
12596 structured-block */
12598 #define OMP_TARGET_DATA_CLAUSE_MASK \
12599 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12604 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12606 tree stmt
= make_node (OMP_TARGET_DATA
);
12607 TREE_TYPE (stmt
) = void_type_node
;
12609 OMP_TARGET_DATA_CLAUSES (stmt
)
12610 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12611 "#pragma omp target data");
12612 keep_next_level ();
12613 tree block
= c_begin_compound_stmt (true);
12614 add_stmt (c_parser_omp_structured_block (parser
));
12615 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12617 SET_EXPR_LOCATION (stmt
, loc
);
12618 return add_stmt (stmt
);
12622 # pragma omp target update target-update-clause[optseq] new-line */
12624 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12625 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12631 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12632 enum pragma_context context
)
12634 if (context
== pragma_stmt
)
12637 "%<#pragma omp target update%> may only be "
12638 "used in compound statements");
12639 c_parser_skip_to_pragma_eol (parser
);
12644 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12645 "#pragma omp target update");
12646 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12647 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12650 "%<#pragma omp target update must contain at least one "
12651 "%<from%> or %<to%> clauses");
12655 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12656 TREE_TYPE (stmt
) = void_type_node
;
12657 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12658 SET_EXPR_LOCATION (stmt
, loc
);
12664 # pragma omp target target-clause[optseq] new-line
12665 structured-block */
12667 #define OMP_TARGET_CLAUSE_MASK \
12668 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12669 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12670 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12673 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12675 location_t loc
= c_parser_peek_token (parser
)->location
;
12676 c_parser_consume_pragma (parser
);
12678 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12680 c_parser_error (parser
, "expected declaration specifiers");
12681 c_parser_skip_to_pragma_eol (parser
);
12685 if (c_parser_next_token_is (parser
, CPP_NAME
))
12687 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12689 if (strcmp (p
, "teams") == 0)
12691 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12692 char p_name
[sizeof ("#pragma omp target teams distribute "
12693 "parallel for simd")];
12695 c_parser_consume_token (parser
);
12696 strcpy (p_name
, "#pragma omp target");
12697 if (!flag_openmp
) /* flag_openmp_simd */
12698 return c_parser_omp_teams (loc
, parser
, p_name
,
12699 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12700 keep_next_level ();
12701 tree block
= c_begin_compound_stmt (true);
12702 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12703 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12704 block
= c_end_compound_stmt (loc
, block
, true);
12707 tree stmt
= make_node (OMP_TARGET
);
12708 TREE_TYPE (stmt
) = void_type_node
;
12709 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12710 OMP_TARGET_BODY (stmt
) = block
;
12714 else if (!flag_openmp
) /* flag_openmp_simd */
12716 c_parser_skip_to_pragma_eol (parser
);
12719 else if (strcmp (p
, "data") == 0)
12721 c_parser_consume_token (parser
);
12722 c_parser_omp_target_data (loc
, parser
);
12725 else if (strcmp (p
, "update") == 0)
12727 c_parser_consume_token (parser
);
12728 return c_parser_omp_target_update (loc
, parser
, context
);
12732 tree stmt
= make_node (OMP_TARGET
);
12733 TREE_TYPE (stmt
) = void_type_node
;
12735 OMP_TARGET_CLAUSES (stmt
)
12736 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12737 "#pragma omp target");
12738 keep_next_level ();
12739 tree block
= c_begin_compound_stmt (true);
12740 add_stmt (c_parser_omp_structured_block (parser
));
12741 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12743 SET_EXPR_LOCATION (stmt
, loc
);
12749 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12751 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12752 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12755 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12756 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12760 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12762 vec
<c_token
> clauses
= vNULL
;
12763 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12765 c_token
*token
= c_parser_peek_token (parser
);
12766 if (token
->type
== CPP_EOF
)
12768 c_parser_skip_to_pragma_eol (parser
);
12769 clauses
.release ();
12772 clauses
.safe_push (*token
);
12773 c_parser_consume_token (parser
);
12775 clauses
.safe_push (*c_parser_peek_token (parser
));
12776 c_parser_skip_to_pragma_eol (parser
);
12778 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12780 if (c_parser_peek_token (parser
)->pragma_kind
12781 != PRAGMA_OMP_DECLARE_REDUCTION
12782 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12783 || strcmp (IDENTIFIER_POINTER
12784 (c_parser_peek_2nd_token (parser
)->value
),
12787 c_parser_error (parser
,
12788 "%<#pragma omp declare simd%> must be followed by "
12789 "function declaration or definition or another "
12790 "%<#pragma omp declare simd%>");
12791 clauses
.release ();
12794 c_parser_consume_pragma (parser
);
12795 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12797 c_token
*token
= c_parser_peek_token (parser
);
12798 if (token
->type
== CPP_EOF
)
12800 c_parser_skip_to_pragma_eol (parser
);
12801 clauses
.release ();
12804 clauses
.safe_push (*token
);
12805 c_parser_consume_token (parser
);
12807 clauses
.safe_push (*c_parser_peek_token (parser
));
12808 c_parser_skip_to_pragma_eol (parser
);
12811 /* Make sure nothing tries to read past the end of the tokens. */
12813 memset (&eof_token
, 0, sizeof (eof_token
));
12814 eof_token
.type
= CPP_EOF
;
12815 clauses
.safe_push (eof_token
);
12816 clauses
.safe_push (eof_token
);
12820 case pragma_external
:
12821 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12822 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12824 int ext
= disable_extension_diagnostics ();
12826 c_parser_consume_token (parser
);
12827 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12828 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12829 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12831 restore_extension_diagnostics (ext
);
12834 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12837 case pragma_struct
:
12839 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12840 "function declaration or definition");
12842 case pragma_compound
:
12844 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12845 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12847 int ext
= disable_extension_diagnostics ();
12849 c_parser_consume_token (parser
);
12850 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12851 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12852 if (c_parser_next_tokens_start_declaration (parser
))
12854 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12855 true, NULL
, clauses
);
12856 restore_extension_diagnostics (ext
);
12859 restore_extension_diagnostics (ext
);
12861 else if (c_parser_next_tokens_start_declaration (parser
))
12863 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12867 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12868 "function declaration or definition");
12871 gcc_unreachable ();
12873 clauses
.release ();
12876 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12877 and put that into "omp declare simd" attribute. */
12880 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12881 vec
<c_token
> clauses
)
12884 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12886 error ("%<#pragma omp declare simd%> cannot be used in the same "
12887 "function marked as a Cilk Plus SIMD-enabled function");
12888 vec_free (parser
->cilk_simd_fn_tokens
);
12892 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12893 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12894 has already processed the tokens. */
12895 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12897 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12899 error ("%<#pragma omp declare simd%> not immediately followed by "
12900 "a function declaration or definition");
12901 clauses
[0].type
= CPP_EOF
;
12904 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
12906 error_at (DECL_SOURCE_LOCATION (fndecl
),
12907 "%<#pragma omp declare simd%> not immediately followed by "
12908 "a single function declaration or definition");
12909 clauses
[0].type
= CPP_EOF
;
12913 if (parms
== NULL_TREE
)
12914 parms
= DECL_ARGUMENTS (fndecl
);
12916 unsigned int tokens_avail
= parser
->tokens_avail
;
12917 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12918 bool is_cilkplus_cilk_simd_fn
= false;
12920 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12922 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
12923 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
12924 is_cilkplus_cilk_simd_fn
= true;
12928 parser
->tokens
= clauses
.address ();
12929 parser
->tokens_avail
= clauses
.length ();
12932 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12933 while (parser
->tokens_avail
> 3)
12935 c_token
*token
= c_parser_peek_token (parser
);
12936 if (!is_cilkplus_cilk_simd_fn
)
12937 gcc_assert (token
->type
== CPP_NAME
12938 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12940 gcc_assert (token
->type
== CPP_NAME
12941 && is_cilkplus_vector_p (token
->value
));
12942 c_parser_consume_token (parser
);
12943 parser
->in_pragma
= true;
12945 tree c
= NULL_TREE
;
12946 if (is_cilkplus_cilk_simd_fn
)
12947 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
12948 "SIMD-enabled functions attribute");
12950 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12951 "#pragma omp declare simd");
12952 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12953 if (c
!= NULL_TREE
)
12954 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12955 if (is_cilkplus_cilk_simd_fn
)
12957 tree k
= build_tree_list (get_identifier ("cilk simd function"),
12959 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
12960 DECL_ATTRIBUTES (fndecl
) = k
;
12962 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12963 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12964 DECL_ATTRIBUTES (fndecl
) = c
;
12967 parser
->tokens
= &parser
->tokens_buf
[0];
12968 parser
->tokens_avail
= tokens_avail
;
12969 if (clauses
.exists ())
12970 clauses
[0].type
= CPP_PRAGMA
;
12972 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12973 vec_free (parser
->cilk_simd_fn_tokens
);
12978 # pragma omp declare target new-line
12979 declarations and definitions
12980 # pragma omp end declare target new-line */
12983 c_parser_omp_declare_target (c_parser
*parser
)
12985 c_parser_skip_to_pragma_eol (parser
);
12986 current_omp_declare_target_attribute
++;
12990 c_parser_omp_end_declare_target (c_parser
*parser
)
12992 location_t loc
= c_parser_peek_token (parser
)->location
;
12993 c_parser_consume_pragma (parser
);
12994 if (c_parser_next_token_is (parser
, CPP_NAME
)
12995 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
12998 c_parser_consume_token (parser
);
12999 if (c_parser_next_token_is (parser
, CPP_NAME
)
13000 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13002 c_parser_consume_token (parser
);
13005 c_parser_error (parser
, "expected %<target%>");
13006 c_parser_skip_to_pragma_eol (parser
);
13012 c_parser_error (parser
, "expected %<declare%>");
13013 c_parser_skip_to_pragma_eol (parser
);
13016 c_parser_skip_to_pragma_eol (parser
);
13017 if (!current_omp_declare_target_attribute
)
13018 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13019 "%<#pragma omp declare target%>");
13021 current_omp_declare_target_attribute
--;
13026 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13027 initializer-clause[opt] new-line
13029 initializer-clause:
13030 initializer (omp_priv = initializer)
13031 initializer (function-name (argument-list)) */
13034 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13036 unsigned int tokens_avail
= 0, i
;
13037 vec
<tree
> types
= vNULL
;
13038 vec
<c_token
> clauses
= vNULL
;
13039 enum tree_code reduc_code
= ERROR_MARK
;
13040 tree reduc_id
= NULL_TREE
;
13042 location_t rloc
= c_parser_peek_token (parser
)->location
;
13044 if (context
== pragma_struct
|| context
== pragma_param
)
13046 error ("%<#pragma omp declare reduction%> not at file or block scope");
13050 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13053 switch (c_parser_peek_token (parser
)->type
)
13056 reduc_code
= PLUS_EXPR
;
13059 reduc_code
= MULT_EXPR
;
13062 reduc_code
= MINUS_EXPR
;
13065 reduc_code
= BIT_AND_EXPR
;
13068 reduc_code
= BIT_XOR_EXPR
;
13071 reduc_code
= BIT_IOR_EXPR
;
13074 reduc_code
= TRUTH_ANDIF_EXPR
;
13077 reduc_code
= TRUTH_ORIF_EXPR
;
13081 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13082 if (strcmp (p
, "min") == 0)
13084 reduc_code
= MIN_EXPR
;
13087 if (strcmp (p
, "max") == 0)
13089 reduc_code
= MAX_EXPR
;
13092 reduc_id
= c_parser_peek_token (parser
)->value
;
13095 c_parser_error (parser
,
13096 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13097 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13101 tree orig_reduc_id
, reduc_decl
;
13102 orig_reduc_id
= reduc_id
;
13103 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13104 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13105 c_parser_consume_token (parser
);
13107 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13112 location_t loc
= c_parser_peek_token (parser
)->location
;
13113 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13116 type
= groktypename (ctype
, NULL
, NULL
);
13117 if (type
== error_mark_node
)
13119 else if ((INTEGRAL_TYPE_P (type
)
13120 || TREE_CODE (type
) == REAL_TYPE
13121 || TREE_CODE (type
) == COMPLEX_TYPE
)
13122 && orig_reduc_id
== NULL_TREE
)
13123 error_at (loc
, "predeclared arithmetic type in "
13124 "%<#pragma omp declare reduction%>");
13125 else if (TREE_CODE (type
) == FUNCTION_TYPE
13126 || TREE_CODE (type
) == ARRAY_TYPE
)
13127 error_at (loc
, "function or array type in "
13128 "%<#pragma omp declare reduction%>");
13129 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13130 error_at (loc
, "const, volatile or restrict qualified type in "
13131 "%<#pragma omp declare reduction%>");
13135 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13136 if (comptypes (TREE_PURPOSE (t
), type
))
13138 error_at (loc
, "redeclaration of %qs "
13139 "%<#pragma omp declare reduction%> for "
13141 IDENTIFIER_POINTER (reduc_id
)
13142 + sizeof ("omp declare reduction ") - 1,
13145 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13147 error_at (ploc
, "previous %<#pragma omp declare "
13151 if (t
== NULL_TREE
)
13152 types
.safe_push (type
);
13154 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13155 c_parser_consume_token (parser
);
13163 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13164 || types
.is_empty ())
13167 clauses
.release ();
13171 c_token
*token
= c_parser_peek_token (parser
);
13172 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13174 c_parser_consume_token (parser
);
13176 c_parser_skip_to_pragma_eol (parser
);
13180 if (types
.length () > 1)
13182 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13184 c_token
*token
= c_parser_peek_token (parser
);
13185 if (token
->type
== CPP_EOF
)
13187 clauses
.safe_push (*token
);
13188 c_parser_consume_token (parser
);
13190 clauses
.safe_push (*c_parser_peek_token (parser
));
13191 c_parser_skip_to_pragma_eol (parser
);
13193 /* Make sure nothing tries to read past the end of the tokens. */
13195 memset (&eof_token
, 0, sizeof (eof_token
));
13196 eof_token
.type
= CPP_EOF
;
13197 clauses
.safe_push (eof_token
);
13198 clauses
.safe_push (eof_token
);
13201 int errs
= errorcount
;
13202 FOR_EACH_VEC_ELT (types
, i
, type
)
13204 tokens_avail
= parser
->tokens_avail
;
13205 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13206 if (!clauses
.is_empty ())
13208 parser
->tokens
= clauses
.address ();
13209 parser
->tokens_avail
= clauses
.length ();
13210 parser
->in_pragma
= true;
13213 bool nested
= current_function_decl
!= NULL_TREE
;
13215 c_push_function_context ();
13216 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13217 reduc_id
, default_function_type
);
13218 current_function_decl
= fndecl
;
13219 allocate_struct_function (fndecl
, true);
13221 tree stmt
= push_stmt_list ();
13222 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13223 warn about these. */
13224 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13225 get_identifier ("omp_out"), type
);
13226 DECL_ARTIFICIAL (omp_out
) = 1;
13227 DECL_CONTEXT (omp_out
) = fndecl
;
13228 pushdecl (omp_out
);
13229 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13230 get_identifier ("omp_in"), type
);
13231 DECL_ARTIFICIAL (omp_in
) = 1;
13232 DECL_CONTEXT (omp_in
) = fndecl
;
13234 struct c_expr combiner
= c_parser_expression (parser
);
13235 struct c_expr initializer
;
13236 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13238 initializer
.value
= error_mark_node
;
13239 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13241 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13242 && strcmp (IDENTIFIER_POINTER
13243 (c_parser_peek_token (parser
)->value
),
13244 "initializer") == 0)
13246 c_parser_consume_token (parser
);
13249 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13250 get_identifier ("omp_priv"), type
);
13251 DECL_ARTIFICIAL (omp_priv
) = 1;
13252 DECL_INITIAL (omp_priv
) = error_mark_node
;
13253 DECL_CONTEXT (omp_priv
) = fndecl
;
13254 pushdecl (omp_priv
);
13255 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13256 get_identifier ("omp_orig"), type
);
13257 DECL_ARTIFICIAL (omp_orig
) = 1;
13258 DECL_CONTEXT (omp_orig
) = fndecl
;
13259 pushdecl (omp_orig
);
13260 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13262 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13264 c_parser_error (parser
, "expected %<omp_priv%> or "
13268 else if (strcmp (IDENTIFIER_POINTER
13269 (c_parser_peek_token (parser
)->value
),
13272 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13273 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13275 c_parser_error (parser
, "expected function-name %<(%>");
13279 initializer
= c_parser_postfix_expression (parser
);
13280 if (initializer
.value
13281 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13284 tree c
= initializer
.value
;
13285 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13286 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13287 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13289 if (j
== call_expr_nargs (c
))
13290 error ("one of the initializer call arguments should be "
13296 c_parser_consume_token (parser
);
13297 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13301 tree st
= push_stmt_list ();
13302 start_init (omp_priv
, NULL_TREE
, 0);
13303 location_t loc
= c_parser_peek_token (parser
)->location
;
13304 struct c_expr init
= c_parser_initializer (parser
);
13306 finish_decl (omp_priv
, loc
, init
.value
,
13307 init
.original_type
, NULL_TREE
);
13308 pop_stmt_list (st
);
13312 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13318 c_parser_skip_to_pragma_eol (parser
);
13320 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13321 DECL_INITIAL (reduc_decl
));
13322 DECL_INITIAL (reduc_decl
) = t
;
13323 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13324 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13325 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13326 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13327 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13328 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13331 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13332 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13333 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13334 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13335 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13336 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13337 walk_tree (&DECL_INITIAL (omp_priv
),
13338 c_check_omp_declare_reduction_r
,
13339 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13343 pop_stmt_list (stmt
);
13345 if (cfun
->language
!= NULL
)
13347 ggc_free (cfun
->language
);
13348 cfun
->language
= NULL
;
13351 current_function_decl
= NULL_TREE
;
13353 c_pop_function_context ();
13355 if (!clauses
.is_empty ())
13357 parser
->tokens
= &parser
->tokens_buf
[0];
13358 parser
->tokens_avail
= tokens_avail
;
13362 if (errs
!= errorcount
)
13366 clauses
.release ();
13372 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13373 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13374 initializer-clause[opt] new-line
13375 #pragma omp declare target new-line */
13378 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13380 c_parser_consume_pragma (parser
);
13381 if (c_parser_next_token_is (parser
, CPP_NAME
))
13383 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13384 if (strcmp (p
, "simd") == 0)
13386 /* c_parser_consume_token (parser); done in
13387 c_parser_omp_declare_simd. */
13388 c_parser_omp_declare_simd (parser
, context
);
13391 if (strcmp (p
, "reduction") == 0)
13393 c_parser_consume_token (parser
);
13394 c_parser_omp_declare_reduction (parser
, context
);
13397 if (!flag_openmp
) /* flag_openmp_simd */
13399 c_parser_skip_to_pragma_eol (parser
);
13402 if (strcmp (p
, "target") == 0)
13404 c_parser_consume_token (parser
);
13405 c_parser_omp_declare_target (parser
);
13410 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13412 c_parser_skip_to_pragma_eol (parser
);
13415 /* Main entry point to parsing most OpenMP pragmas. */
13418 c_parser_omp_construct (c_parser
*parser
)
13420 enum pragma_kind p_kind
;
13423 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13424 omp_clause_mask
mask (0);
13426 loc
= c_parser_peek_token (parser
)->location
;
13427 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13428 c_parser_consume_pragma (parser
);
13432 case PRAGMA_OMP_ATOMIC
:
13433 c_parser_omp_atomic (loc
, parser
);
13435 case PRAGMA_OMP_CRITICAL
:
13436 stmt
= c_parser_omp_critical (loc
, parser
);
13438 case PRAGMA_OMP_DISTRIBUTE
:
13439 strcpy (p_name
, "#pragma omp");
13440 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13442 case PRAGMA_OMP_FOR
:
13443 strcpy (p_name
, "#pragma omp");
13444 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13446 case PRAGMA_OMP_MASTER
:
13447 stmt
= c_parser_omp_master (loc
, parser
);
13449 case PRAGMA_OMP_ORDERED
:
13450 stmt
= c_parser_omp_ordered (loc
, parser
);
13452 case PRAGMA_OMP_PARALLEL
:
13453 strcpy (p_name
, "#pragma omp");
13454 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13456 case PRAGMA_OMP_SECTIONS
:
13457 strcpy (p_name
, "#pragma omp");
13458 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13460 case PRAGMA_OMP_SIMD
:
13461 strcpy (p_name
, "#pragma omp");
13462 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13464 case PRAGMA_OMP_SINGLE
:
13465 stmt
= c_parser_omp_single (loc
, parser
);
13467 case PRAGMA_OMP_TASK
:
13468 stmt
= c_parser_omp_task (loc
, parser
);
13470 case PRAGMA_OMP_TASKGROUP
:
13471 stmt
= c_parser_omp_taskgroup (parser
);
13473 case PRAGMA_OMP_TEAMS
:
13474 strcpy (p_name
, "#pragma omp");
13475 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13478 gcc_unreachable ();
13482 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13487 # pragma omp threadprivate (variable-list) */
13490 c_parser_omp_threadprivate (c_parser
*parser
)
13495 c_parser_consume_pragma (parser
);
13496 loc
= c_parser_peek_token (parser
)->location
;
13497 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13499 /* Mark every variable in VARS to be assigned thread local storage. */
13500 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13502 tree v
= TREE_PURPOSE (t
);
13504 /* FIXME diagnostics: Ideally we should keep individual
13505 locations for all the variables in the var list to make the
13506 following errors more precise. Perhaps
13507 c_parser_omp_var_list_parens() should construct a list of
13508 locations to go along with the var list. */
13510 /* If V had already been marked threadprivate, it doesn't matter
13511 whether it had been used prior to this point. */
13512 if (TREE_CODE (v
) != VAR_DECL
)
13513 error_at (loc
, "%qD is not a variable", v
);
13514 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13515 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13516 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13517 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13518 else if (TREE_TYPE (v
) == error_mark_node
)
13520 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13521 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13524 if (! DECL_THREAD_LOCAL_P (v
))
13526 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13527 /* If rtl has been already set for this var, call
13528 make_decl_rtl once again, so that encode_section_info
13529 has a chance to look at the new decl flags. */
13530 if (DECL_RTL_SET_P (v
))
13533 C_DECL_THREADPRIVATE_P (v
) = 1;
13537 c_parser_skip_to_pragma_eol (parser
);
13540 /* Cilk Plus <#pragma simd> parsing routines. */
13542 /* Helper function for c_parser_pragma. Perform some sanity checking
13543 for <#pragma simd> constructs. Returns FALSE if there was a
13547 c_parser_cilk_verify_simd (c_parser
*parser
,
13548 enum pragma_context context
)
13550 if (!flag_cilkplus
)
13552 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13553 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13556 if (context
== pragma_external
)
13558 c_parser_error (parser
,"pragma simd must be inside a function");
13559 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13566 This function is shared by SIMD-enabled functions and #pragma simd.
13567 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13568 CLAUSES is unused. The main purpose of this function is to parse a
13569 vectorlength attribute or clause and check for parse errors.
13570 When IS_SIMD_FN is true then the function is merely caching the tokens
13571 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13572 cache is cleared since there is no reason to continue.
13574 vectorlength ( constant-expression ) */
13577 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13581 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13583 /* The vectorlength clause behaves exactly like OpenMP's safelen
13584 clause. Represent it in OpenMP terms. */
13585 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13587 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13590 location_t loc
= c_parser_peek_token (parser
)->location
;
13591 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13592 expr
= c_fully_fold (expr
, false, NULL
);
13594 /* If expr is an error_mark_node then the above function would have
13595 emitted an error. No reason to do it twice. */
13596 if (expr
== error_mark_node
)
13598 else if (!TREE_TYPE (expr
)
13599 || !TREE_CONSTANT (expr
)
13600 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13602 error_at (loc
, "vectorlength must be an integer constant");
13603 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13604 error_at (loc
, "vectorlength must be a power of 2");
13609 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13610 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13611 OMP_CLAUSE_CHAIN (u
) = clauses
;
13616 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13617 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13618 OMP_CLAUSE_CHAIN (u
) = clauses
;
13623 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13629 linear ( simd-linear-variable-list )
13631 simd-linear-variable-list:
13632 simd-linear-variable
13633 simd-linear-variable-list , simd-linear-variable
13635 simd-linear-variable:
13637 id-expression : simd-linear-step
13640 conditional-expression */
13643 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13645 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13648 location_t loc
= c_parser_peek_token (parser
)->location
;
13650 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13651 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13652 c_parser_error (parser
, "expected identifier");
13654 while (c_parser_next_token_is (parser
, CPP_NAME
)
13655 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13657 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13661 undeclared_variable (c_parser_peek_token (parser
)->location
,
13662 c_parser_peek_token (parser
)->value
);
13663 c_parser_consume_token (parser
);
13665 else if (var
== error_mark_node
)
13666 c_parser_consume_token (parser
);
13669 tree step
= integer_one_node
;
13671 /* Parse the linear step if present. */
13672 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13674 c_parser_consume_token (parser
);
13675 c_parser_consume_token (parser
);
13677 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13678 expr
= c_fully_fold (expr
, false, NULL
);
13680 if (TREE_TYPE (expr
)
13681 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13682 && (TREE_CONSTANT (expr
)
13686 c_parser_error (parser
,
13687 "step size must be an integer constant "
13688 "expression or an integer variable");
13691 c_parser_consume_token (parser
);
13693 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13694 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13695 OMP_CLAUSE_DECL (u
) = var
;
13696 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13697 OMP_CLAUSE_CHAIN (u
) = clauses
;
13701 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13704 c_parser_consume_token (parser
);
13707 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13712 /* Returns the name of the next clause. If the clause is not
13713 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13714 not consumed. Otherwise, the appropriate pragma_simd_clause is
13715 returned and the token is consumed. */
13717 static pragma_omp_clause
13718 c_parser_cilk_clause_name (c_parser
*parser
)
13720 pragma_omp_clause result
;
13721 c_token
*token
= c_parser_peek_token (parser
);
13723 if (!token
->value
|| token
->type
!= CPP_NAME
)
13724 return PRAGMA_CILK_CLAUSE_NONE
;
13726 const char *p
= IDENTIFIER_POINTER (token
->value
);
13728 if (!strcmp (p
, "vectorlength"))
13729 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13730 else if (!strcmp (p
, "linear"))
13731 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13732 else if (!strcmp (p
, "private"))
13733 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13734 else if (!strcmp (p
, "firstprivate"))
13735 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13736 else if (!strcmp (p
, "lastprivate"))
13737 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13738 else if (!strcmp (p
, "reduction"))
13739 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13741 return PRAGMA_CILK_CLAUSE_NONE
;
13743 c_parser_consume_token (parser
);
13747 /* Parse all #<pragma simd> clauses. Return the list of clauses
13751 c_parser_cilk_all_clauses (c_parser
*parser
)
13753 tree clauses
= NULL
;
13755 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13757 pragma_omp_clause c_kind
;
13759 c_kind
= c_parser_cilk_clause_name (parser
);
13763 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13764 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13766 case PRAGMA_CILK_CLAUSE_LINEAR
:
13767 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13769 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13770 /* Use the OpenMP counterpart. */
13771 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13773 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13774 /* Use the OpenMP counterpart. */
13775 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13777 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13778 /* Use the OpenMP counterpart. */
13779 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13781 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13782 /* Use the OpenMP counterpart. */
13783 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13786 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13792 c_parser_skip_to_pragma_eol (parser
);
13793 return c_finish_cilk_clauses (clauses
);
13796 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13800 c_parser_cilk_simd (c_parser
*parser
)
13802 tree clauses
= c_parser_cilk_all_clauses (parser
);
13803 tree block
= c_begin_compound_stmt (true);
13804 location_t loc
= c_parser_peek_token (parser
)->location
;
13805 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13806 block
= c_end_compound_stmt (loc
, block
, true);
13810 /* Parse a transaction attribute (GCC Extension).
13812 transaction-attribute:
13816 The transactional memory language description is written for C++,
13817 and uses the C++0x attribute syntax. For compatibility, allow the
13818 bracket style for transactions in C as well. */
13821 c_parser_transaction_attributes (c_parser
*parser
)
13823 tree attr_name
, attr
= NULL
;
13825 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13826 return c_parser_attributes (parser
);
13828 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13830 c_parser_consume_token (parser
);
13831 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13834 attr_name
= c_parser_attribute_any_word (parser
);
13837 c_parser_consume_token (parser
);
13838 attr
= build_tree_list (attr_name
, NULL_TREE
);
13841 c_parser_error (parser
, "expected identifier");
13843 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13845 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13849 /* Parse a __transaction_atomic or __transaction_relaxed statement
13852 transaction-statement:
13853 __transaction_atomic transaction-attribute[opt] compound-statement
13854 __transaction_relaxed compound-statement
13856 Note that the only valid attribute is: "outer".
13860 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13862 unsigned int old_in
= parser
->in_transaction
;
13863 unsigned int this_in
= 1, new_in
;
13864 location_t loc
= c_parser_peek_token (parser
)->location
;
13867 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13868 || keyword
== RID_TRANSACTION_RELAXED
)
13869 && c_parser_next_token_is_keyword (parser
, keyword
));
13870 c_parser_consume_token (parser
);
13872 if (keyword
== RID_TRANSACTION_RELAXED
)
13873 this_in
|= TM_STMT_ATTR_RELAXED
;
13876 attrs
= c_parser_transaction_attributes (parser
);
13878 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13881 /* Keep track if we're in the lexical scope of an outer transaction. */
13882 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13884 parser
->in_transaction
= new_in
;
13885 stmt
= c_parser_compound_statement (parser
);
13886 parser
->in_transaction
= old_in
;
13889 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13891 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13892 "%<__transaction_atomic%> without transactional memory support enabled"
13893 : "%<__transaction_relaxed %> "
13894 "without transactional memory support enabled"));
13899 /* Parse a __transaction_atomic or __transaction_relaxed expression
13902 transaction-expression:
13903 __transaction_atomic ( expression )
13904 __transaction_relaxed ( expression )
13907 static struct c_expr
13908 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13911 unsigned int old_in
= parser
->in_transaction
;
13912 unsigned int this_in
= 1;
13913 location_t loc
= c_parser_peek_token (parser
)->location
;
13916 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13917 || keyword
== RID_TRANSACTION_RELAXED
)
13918 && c_parser_next_token_is_keyword (parser
, keyword
));
13919 c_parser_consume_token (parser
);
13921 if (keyword
== RID_TRANSACTION_RELAXED
)
13922 this_in
|= TM_STMT_ATTR_RELAXED
;
13925 attrs
= c_parser_transaction_attributes (parser
);
13927 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13930 parser
->in_transaction
= this_in
;
13931 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13933 tree expr
= c_parser_expression (parser
).value
;
13934 ret
.original_type
= TREE_TYPE (expr
);
13935 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13936 if (this_in
& TM_STMT_ATTR_RELAXED
)
13937 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13938 SET_EXPR_LOCATION (ret
.value
, loc
);
13939 ret
.original_code
= TRANSACTION_EXPR
;
13940 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13942 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13949 ret
.value
= error_mark_node
;
13950 ret
.original_code
= ERROR_MARK
;
13951 ret
.original_type
= NULL
;
13953 parser
->in_transaction
= old_in
;
13956 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13957 "%<__transaction_atomic%> without transactional memory support enabled"
13958 : "%<__transaction_relaxed %> "
13959 "without transactional memory support enabled"));
13964 /* Parse a __transaction_cancel statement (GCC Extension).
13966 transaction-cancel-statement:
13967 __transaction_cancel transaction-attribute[opt] ;
13969 Note that the only valid attribute is "outer".
13973 c_parser_transaction_cancel (c_parser
*parser
)
13975 location_t loc
= c_parser_peek_token (parser
)->location
;
13977 bool is_outer
= false;
13979 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13980 c_parser_consume_token (parser
);
13982 attrs
= c_parser_transaction_attributes (parser
);
13984 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13988 error_at (loc
, "%<__transaction_cancel%> without "
13989 "transactional memory support enabled");
13992 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13994 error_at (loc
, "%<__transaction_cancel%> within a "
13995 "%<__transaction_relaxed%>");
14000 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14001 && !is_tm_may_cancel_outer (current_function_decl
))
14003 error_at (loc
, "outer %<__transaction_cancel%> not "
14004 "within outer %<__transaction_atomic%>");
14005 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14009 else if (parser
->in_transaction
== 0)
14011 error_at (loc
, "%<__transaction_cancel%> not within "
14012 "%<__transaction_atomic%>");
14016 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14019 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14022 /* Parse a single source file. */
14025 c_parse_file (void)
14027 /* Use local storage to begin. If the first token is a pragma, parse it.
14028 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14029 which will cause garbage collection. */
14032 memset (&tparser
, 0, sizeof tparser
);
14033 tparser
.tokens
= &tparser
.tokens_buf
[0];
14034 the_parser
= &tparser
;
14036 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14037 c_parser_pragma_pch_preprocess (&tparser
);
14039 the_parser
= ggc_alloc_c_parser ();
14040 *the_parser
= tparser
;
14041 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14042 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14044 /* Initialize EH, if we've been told to do so. */
14045 if (flag_exceptions
)
14046 using_eh_for_cleanups ();
14048 c_parser_translation_unit (the_parser
);
14052 /* This function parses Cilk Plus array notation. The starting index is
14053 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14054 return value of this function is a tree_node called VALUE_TREE of type
14055 ARRAY_NOTATION_REF. */
14058 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14061 c_token
*token
= NULL
;
14062 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14063 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14064 tree array_type_domain
= NULL_TREE
;
14066 if (array_value
== error_mark_node
)
14068 /* No need to continue. If either of these 2 were true, then an error
14069 must be emitted already. Thus, no need to emit them twice. */
14070 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14071 return error_mark_node
;
14074 array_type
= TREE_TYPE (array_value
);
14075 gcc_assert (array_type
);
14076 type
= TREE_TYPE (array_type
);
14077 token
= c_parser_peek_token (parser
);
14079 if (token
->type
== CPP_EOF
)
14081 c_parser_error (parser
, "expected %<:%> or numeral");
14084 else if (token
->type
== CPP_COLON
)
14086 if (!initial_index
)
14088 /* If we are here, then we have a case like this A[:]. */
14089 c_parser_consume_token (parser
);
14090 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14092 error_at (loc
, "start-index and length fields necessary for "
14093 "using array notations in pointers");
14094 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14095 return error_mark_node
;
14097 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14099 error_at (loc
, "array notations cannot be used with function "
14101 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14102 return error_mark_node
;
14104 array_type_domain
= TYPE_DOMAIN (array_type
);
14106 if (!array_type_domain
)
14108 error_at (loc
, "start-index and length fields necessary for "
14109 "using array notations in dimensionless arrays");
14110 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14111 return error_mark_node
;
14114 start_index
= TYPE_MINVAL (array_type_domain
);
14115 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14117 if (!TYPE_MAXVAL (array_type_domain
)
14118 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14120 error_at (loc
, "start-index and length fields necessary for "
14121 "using array notations in variable-length arrays");
14122 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14123 return error_mark_node
;
14125 end_index
= TYPE_MAXVAL (array_type_domain
);
14126 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14127 end_index
, integer_one_node
);
14128 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14129 stride
= build_int_cst (integer_type_node
, 1);
14130 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14132 else if (initial_index
!= error_mark_node
)
14134 /* If we are here, then there should be 2 possibilities:
14135 1. Array [EXPR : EXPR]
14136 2. Array [EXPR : EXPR : EXPR]
14138 start_index
= initial_index
;
14140 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14142 error_at (loc
, "array notations cannot be used with function "
14144 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14145 return error_mark_node
;
14147 c_parser_consume_token (parser
); /* consume the ':' */
14148 struct c_expr ce
= c_parser_expression (parser
);
14149 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14150 end_index
= ce
.value
;
14151 if (!end_index
|| end_index
== error_mark_node
)
14153 c_parser_skip_to_end_of_block_or_statement (parser
);
14154 return error_mark_node
;
14156 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14158 c_parser_consume_token (parser
);
14159 ce
= c_parser_expression (parser
);
14160 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14162 if (!stride
|| stride
== error_mark_node
)
14164 c_parser_skip_to_end_of_block_or_statement (parser
);
14165 return error_mark_node
;
14170 c_parser_error (parser
, "expected array notation expression");
14173 c_parser_error (parser
, "expected array notation expression");
14175 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14177 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14178 end_index
, stride
, type
);
14179 if (value_tree
!= error_mark_node
)
14180 SET_EXPR_LOCATION (value_tree
, loc
);
14184 #include "gt-c-c-parser.h"