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 all qualifiers from atomic types. */
1711 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1713 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1714 bool vm_type
= variably_modified_type_p (init_type
,
1717 init
.value
= c_save_expr (init
.value
);
1719 specs
->typespec_kind
= ctsk_typeof
;
1720 specs
->locations
[cdw_typedef
] = init_loc
;
1721 specs
->typedef_p
= true;
1722 specs
->type
= init_type
;
1725 bool maybe_const
= true;
1726 tree type_expr
= c_fully_fold (init
.value
, false,
1728 specs
->expr_const_operands
&= maybe_const
;
1730 specs
->expr
= build2 (COMPOUND_EXPR
,
1731 TREE_TYPE (type_expr
),
1732 specs
->expr
, type_expr
);
1734 specs
->expr
= type_expr
;
1736 d
= start_decl (declarator
, specs
, true,
1737 chainon (postfix_attrs
, all_prefix_attrs
));
1739 d
= error_mark_node
;
1740 if (omp_declare_simd_clauses
.exists ()
1741 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1742 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1743 omp_declare_simd_clauses
);
1747 /* The declaration of the variable is in effect while
1748 its initializer is parsed. */
1749 d
= start_decl (declarator
, specs
, true,
1750 chainon (postfix_attrs
, all_prefix_attrs
));
1752 d
= error_mark_node
;
1753 if (omp_declare_simd_clauses
.exists ()
1754 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1755 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1756 omp_declare_simd_clauses
);
1757 start_init (d
, asm_name
, global_bindings_p ());
1758 init_loc
= c_parser_peek_token (parser
)->location
;
1759 init
= c_parser_initializer (parser
);
1762 if (d
!= error_mark_node
)
1764 maybe_warn_string_init (TREE_TYPE (d
), init
);
1765 finish_decl (d
, init_loc
, init
.value
,
1766 init
.original_type
, asm_name
);
1774 "%<__auto_type%> requires an initialized "
1775 "data declaration");
1776 c_parser_skip_to_end_of_block_or_statement (parser
);
1779 tree d
= start_decl (declarator
, specs
, false,
1780 chainon (postfix_attrs
,
1782 if (omp_declare_simd_clauses
.exists ()
1783 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1785 tree parms
= NULL_TREE
;
1786 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1788 struct c_declarator
*ce
= declarator
;
1790 if (ce
->kind
== cdk_function
)
1792 parms
= ce
->u
.arg_info
->parms
;
1796 ce
= ce
->declarator
;
1799 temp_store_parm_decls (d
, parms
);
1800 c_finish_omp_declare_simd (parser
, d
, parms
,
1801 omp_declare_simd_clauses
);
1803 temp_pop_parm_decls ();
1806 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1807 NULL_TREE
, asm_name
);
1809 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1812 *objc_foreach_object_declaration
= d
;
1814 *objc_foreach_object_declaration
= error_mark_node
;
1817 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1822 "%<__auto_type%> may only be used with"
1823 " a single declarator");
1824 c_parser_skip_to_end_of_block_or_statement (parser
);
1827 c_parser_consume_token (parser
);
1828 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1829 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1832 all_prefix_attrs
= prefix_attrs
;
1835 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1837 c_parser_consume_token (parser
);
1840 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1842 /* This can only happen in Objective-C: we found the
1843 'in' that terminates the declaration inside an
1844 Objective-C foreach statement. Do not consume the
1845 token, so that the caller can use it to determine
1846 that this indeed is a foreach context. */
1851 c_parser_error (parser
, "expected %<,%> or %<;%>");
1852 c_parser_skip_to_end_of_block_or_statement (parser
);
1856 else if (auto_type_p
)
1859 "%<__auto_type%> requires an initialized data declaration");
1860 c_parser_skip_to_end_of_block_or_statement (parser
);
1865 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1866 "%<asm%> or %<__attribute__%>");
1867 c_parser_skip_to_end_of_block_or_statement (parser
);
1870 /* Function definition (nested or otherwise). */
1873 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
1874 c_push_function_context ();
1876 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1878 /* This can appear in many cases looking nothing like a
1879 function definition, so we don't give a more specific
1880 error suggesting there was one. */
1881 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1882 "or %<__attribute__%>");
1884 c_pop_function_context ();
1888 if (DECL_DECLARED_INLINE_P (current_function_decl
))
1889 tv
= TV_PARSE_INLINE
;
1894 /* Parse old-style parameter declarations. ??? Attributes are
1895 not allowed to start declaration specifiers here because of a
1896 syntax conflict between a function declaration with attribute
1897 suffix and a function definition with an attribute prefix on
1898 first old-style parameter declaration. Following the old
1899 parser, they are not accepted on subsequent old-style
1900 parameter declarations either. However, there is no
1901 ambiguity after the first declaration, nor indeed on the
1902 first as long as we don't allow postfix attributes after a
1903 declarator with a nonempty identifier list in a definition;
1904 and postfix attributes have never been accepted here in
1905 function definitions either. */
1906 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1907 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1908 c_parser_declaration_or_fndef (parser
, false, false, false,
1909 true, false, NULL
, vNULL
);
1910 store_parm_decls ();
1911 if (omp_declare_simd_clauses
.exists ()
1912 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1913 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
1914 omp_declare_simd_clauses
);
1915 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
1916 = c_parser_peek_token (parser
)->location
;
1917 fnbody
= c_parser_compound_statement (parser
);
1918 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
1919 fnbody
= expand_array_notation_exprs (fnbody
);
1922 tree decl
= current_function_decl
;
1923 /* Mark nested functions as needing static-chain initially.
1924 lower_nested_functions will recompute it but the
1925 DECL_STATIC_CHAIN flag is also used before that happens,
1926 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
1927 DECL_STATIC_CHAIN (decl
) = 1;
1930 c_pop_function_context ();
1931 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
1944 /* Parse an asm-definition (asm() outside a function body). This is a
1952 c_parser_asm_definition (c_parser
*parser
)
1954 tree asm_str
= c_parser_simple_asm_expr (parser
);
1956 add_asm_node (asm_str
);
1957 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1960 /* Parse a static assertion (C11 6.7.10).
1962 static_assert-declaration:
1963 static_assert-declaration-no-semi ;
1967 c_parser_static_assert_declaration (c_parser
*parser
)
1969 c_parser_static_assert_declaration_no_semi (parser
);
1971 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1972 c_parser_skip_to_end_of_block_or_statement (parser
);
1975 /* Parse a static assertion (C11 6.7.10), without the trailing
1978 static_assert-declaration-no-semi:
1979 _Static_assert ( constant-expression , string-literal )
1983 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
1985 location_t assert_loc
, value_loc
;
1989 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
1990 assert_loc
= c_parser_peek_token (parser
)->location
;
1994 pedwarn (assert_loc
, OPT_Wpedantic
,
1995 "ISO C99 does not support %<_Static_assert%>");
1997 pedwarn (assert_loc
, OPT_Wpedantic
,
1998 "ISO C90 does not support %<_Static_assert%>");
2000 c_parser_consume_token (parser
);
2001 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2003 value_loc
= c_parser_peek_token (parser
)->location
;
2004 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2005 parser
->lex_untranslated_string
= true;
2006 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2008 parser
->lex_untranslated_string
= false;
2011 switch (c_parser_peek_token (parser
)->type
)
2017 case CPP_UTF8STRING
:
2018 string
= c_parser_peek_token (parser
)->value
;
2019 c_parser_consume_token (parser
);
2020 parser
->lex_untranslated_string
= false;
2023 c_parser_error (parser
, "expected string literal");
2024 parser
->lex_untranslated_string
= false;
2027 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2029 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2031 error_at (value_loc
, "expression in static assertion is not an integer");
2034 if (TREE_CODE (value
) != INTEGER_CST
)
2036 value
= c_fully_fold (value
, false, NULL
);
2037 if (TREE_CODE (value
) == INTEGER_CST
)
2038 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2039 "is not an integer constant expression");
2041 if (TREE_CODE (value
) != INTEGER_CST
)
2043 error_at (value_loc
, "expression in static assertion is not constant");
2046 constant_expression_warning (value
);
2047 if (integer_zerop (value
))
2048 error_at (assert_loc
, "static assertion failed: %E", string
);
2051 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2052 6.7), adding them to SPECS (which may already include some).
2053 Storage class specifiers are accepted iff SCSPEC_OK; type
2054 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2055 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2056 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2058 declaration-specifiers:
2059 storage-class-specifier declaration-specifiers[opt]
2060 type-specifier declaration-specifiers[opt]
2061 type-qualifier declaration-specifiers[opt]
2062 function-specifier declaration-specifiers[opt]
2063 alignment-specifier declaration-specifiers[opt]
2065 Function specifiers (inline) are from C99, and are currently
2066 handled as storage class specifiers, as is __thread. Alignment
2067 specifiers are from C11.
2069 C90 6.5.1, C99 6.7.1:
2070 storage-class-specifier:
2078 (_Thread_local is new in C11.)
2085 (_Noreturn is new in C11.)
2087 C90 6.5.2, C99 6.7.2:
2100 [_Imaginary removed in C99 TC2]
2101 struct-or-union-specifier
2104 atomic-type-specifier
2106 (_Bool and _Complex are new in C99.)
2107 (atomic-type-specifier is new in C11.)
2109 C90 6.5.3, C99 6.7.3:
2115 address-space-qualifier
2118 (restrict is new in C99.)
2119 (_Atomic is new in C11.)
2123 declaration-specifiers:
2124 attributes declaration-specifiers[opt]
2130 identifier recognized by the target
2132 storage-class-specifier:
2146 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2147 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2149 atomic-type-specifier
2150 _Atomic ( type-name )
2155 class-name objc-protocol-refs[opt]
2156 typedef-name objc-protocol-refs
2161 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2162 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2163 bool alignspec_ok
, bool auto_type_ok
,
2164 enum c_lookahead_kind la
)
2166 bool attrs_ok
= start_attr_ok
;
2167 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2170 gcc_assert (la
== cla_prefer_id
);
2172 while (c_parser_next_token_is (parser
, CPP_NAME
)
2173 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2174 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2176 struct c_typespec t
;
2179 location_t loc
= c_parser_peek_token (parser
)->location
;
2181 /* If we cannot accept a type, exit if the next token must start
2182 one. Also, if we already have seen a tagged definition,
2183 a typename would be an error anyway and likely the user
2184 has simply forgotten a semicolon, so we exit. */
2185 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2186 && c_parser_next_tokens_start_typename (parser
, la
)
2187 && !c_parser_next_token_is_qualifier (parser
))
2190 if (c_parser_next_token_is (parser
, CPP_NAME
))
2192 c_token
*name_token
= c_parser_peek_token (parser
);
2193 tree value
= name_token
->value
;
2194 c_id_kind kind
= name_token
->id_kind
;
2196 if (kind
== C_ID_ADDRSPACE
)
2199 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2200 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2201 c_parser_consume_token (parser
);
2206 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2208 /* If we cannot accept a type, and the next token must start one,
2209 exit. Do the same if we already have seen a tagged definition,
2210 since it would be an error anyway and likely the user has simply
2211 forgotten a semicolon. */
2212 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2215 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2216 a C_ID_CLASSNAME. */
2217 c_parser_consume_token (parser
);
2220 if (kind
== C_ID_ID
)
2222 error_at (loc
, "unknown type name %qE", value
);
2223 t
.kind
= ctsk_typedef
;
2224 t
.spec
= error_mark_node
;
2226 else if (kind
== C_ID_TYPENAME
2227 && (!c_dialect_objc ()
2228 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2230 t
.kind
= ctsk_typedef
;
2231 /* For a typedef name, record the meaning, not the name.
2232 In case of 'foo foo, bar;'. */
2233 t
.spec
= lookup_name (value
);
2237 tree proto
= NULL_TREE
;
2238 gcc_assert (c_dialect_objc ());
2240 if (c_parser_next_token_is (parser
, CPP_LESS
))
2241 proto
= c_parser_objc_protocol_refs (parser
);
2242 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2245 t
.expr_const_operands
= true;
2246 declspecs_add_type (name_token
->location
, specs
, t
);
2249 if (c_parser_next_token_is (parser
, CPP_LESS
))
2251 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2252 nisse@lysator.liu.se. */
2254 gcc_assert (c_dialect_objc ());
2255 if (!typespec_ok
|| seen_type
)
2257 proto
= c_parser_objc_protocol_refs (parser
);
2259 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2261 t
.expr_const_operands
= true;
2262 declspecs_add_type (loc
, specs
, t
);
2265 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2266 switch (c_parser_peek_token (parser
)->keyword
)
2279 /* TODO: Distinguish between function specifiers (inline, noreturn)
2280 and storage class specifiers, either here or in
2281 declspecs_add_scspec. */
2282 declspecs_add_scspec (loc
, specs
,
2283 c_parser_peek_token (parser
)->value
);
2284 c_parser_consume_token (parser
);
2312 if (c_dialect_objc ())
2313 parser
->objc_need_raw_identifier
= true;
2314 t
.kind
= ctsk_resword
;
2315 t
.spec
= c_parser_peek_token (parser
)->value
;
2317 t
.expr_const_operands
= true;
2318 declspecs_add_type (loc
, specs
, t
);
2319 c_parser_consume_token (parser
);
2326 t
= c_parser_enum_specifier (parser
);
2327 declspecs_add_type (loc
, specs
, t
);
2335 t
= c_parser_struct_or_union_specifier (parser
);
2336 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2337 declspecs_add_type (loc
, specs
, t
);
2340 /* ??? The old parser rejected typeof after other type
2341 specifiers, but is a syntax error the best way of
2343 if (!typespec_ok
|| seen_type
)
2347 t
= c_parser_typeof_specifier (parser
);
2348 declspecs_add_type (loc
, specs
, t
);
2351 /* C parser handling of Objective-C constructs needs
2352 checking for correct lvalue-to-rvalue conversions, and
2353 the code in build_modify_expr handling various
2354 Objective-C cases, and that in build_unary_op handling
2355 Objective-C cases for increment / decrement, also needs
2356 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2357 and objc_types_are_equivalent may also need updates. */
2358 if (c_dialect_objc ())
2359 sorry ("%<_Atomic%> in Objective-C");
2360 /* C parser handling of OpenMP constructs needs checking for
2361 correct lvalue-to-rvalue conversions. */
2363 sorry ("%<_Atomic%> with OpenMP");
2367 pedwarn (loc
, OPT_Wpedantic
,
2368 "ISO C99 does not support the %<_Atomic%> qualifier");
2370 pedwarn (loc
, OPT_Wpedantic
,
2371 "ISO C90 does not support the %<_Atomic%> qualifier");
2375 value
= c_parser_peek_token (parser
)->value
;
2376 c_parser_consume_token (parser
);
2377 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2379 /* _Atomic ( type-name ). */
2381 c_parser_consume_token (parser
);
2382 struct c_type_name
*type
= c_parser_type_name (parser
);
2383 t
.kind
= ctsk_typeof
;
2384 t
.spec
= error_mark_node
;
2386 t
.expr_const_operands
= true;
2388 t
.spec
= groktypename (type
, &t
.expr
,
2389 &t
.expr_const_operands
);
2390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2392 if (t
.spec
!= error_mark_node
)
2394 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2395 error_at (loc
, "%<_Atomic%>-qualified array type");
2396 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2397 error_at (loc
, "%<_Atomic%>-qualified function type");
2398 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2399 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2401 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2403 declspecs_add_type (loc
, specs
, t
);
2406 declspecs_add_qual (loc
, specs
, value
);
2412 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2413 c_parser_consume_token (parser
);
2418 attrs
= c_parser_attributes (parser
);
2419 declspecs_add_attrs (loc
, specs
, attrs
);
2424 align
= c_parser_alignas_specifier (parser
);
2425 declspecs_add_alignas (loc
, specs
, align
);
2434 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2437 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2438 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2439 enum attributes[opt] identifier
2441 The form with trailing comma is new in C99. The forms with
2442 attributes are GNU extensions. In GNU C, we accept any expression
2443 without commas in the syntax (assignment expressions, not just
2444 conditional expressions); assignment expressions will be diagnosed
2449 enumerator-list , enumerator
2452 enumeration-constant
2453 enumeration-constant = constant-expression
2456 static struct c_typespec
2457 c_parser_enum_specifier (c_parser
*parser
)
2459 struct c_typespec ret
;
2461 tree ident
= NULL_TREE
;
2462 location_t enum_loc
;
2463 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2464 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2465 enum_loc
= c_parser_peek_token (parser
)->location
;
2466 c_parser_consume_token (parser
);
2467 attrs
= c_parser_attributes (parser
);
2468 enum_loc
= c_parser_peek_token (parser
)->location
;
2469 /* Set the location in case we create a decl now. */
2470 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2471 if (c_parser_next_token_is (parser
, CPP_NAME
))
2473 ident
= c_parser_peek_token (parser
)->value
;
2474 ident_loc
= c_parser_peek_token (parser
)->location
;
2475 enum_loc
= ident_loc
;
2476 c_parser_consume_token (parser
);
2478 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2480 /* Parse an enum definition. */
2481 struct c_enum_contents the_enum
;
2484 /* We chain the enumerators in reverse order, then put them in
2485 forward order at the end. */
2487 timevar_push (TV_PARSE_ENUM
);
2488 type
= start_enum (enum_loc
, &the_enum
, ident
);
2490 c_parser_consume_token (parser
);
2498 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2499 location_t decl_loc
, value_loc
;
2500 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2502 c_parser_error (parser
, "expected identifier");
2503 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2504 values
= error_mark_node
;
2507 token
= c_parser_peek_token (parser
);
2508 enum_id
= token
->value
;
2509 /* Set the location in case we create a decl now. */
2510 c_parser_set_source_position_from_token (token
);
2511 decl_loc
= value_loc
= token
->location
;
2512 c_parser_consume_token (parser
);
2513 if (c_parser_next_token_is (parser
, CPP_EQ
))
2515 c_parser_consume_token (parser
);
2516 value_loc
= c_parser_peek_token (parser
)->location
;
2517 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2520 enum_value
= NULL_TREE
;
2521 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2522 &the_enum
, enum_id
, enum_value
);
2523 TREE_CHAIN (enum_decl
) = values
;
2526 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2528 comma_loc
= c_parser_peek_token (parser
)->location
;
2530 c_parser_consume_token (parser
);
2532 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2534 if (seen_comma
&& !flag_isoc99
)
2535 pedwarn (comma_loc
, OPT_Wpedantic
, "comma at end of enumerator list");
2536 c_parser_consume_token (parser
);
2541 c_parser_error (parser
, "expected %<,%> or %<}%>");
2542 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2543 values
= error_mark_node
;
2547 postfix_attrs
= c_parser_attributes (parser
);
2548 ret
.spec
= finish_enum (type
, nreverse (values
),
2549 chainon (attrs
, postfix_attrs
));
2550 ret
.kind
= ctsk_tagdef
;
2551 ret
.expr
= NULL_TREE
;
2552 ret
.expr_const_operands
= true;
2553 timevar_pop (TV_PARSE_ENUM
);
2558 c_parser_error (parser
, "expected %<{%>");
2559 ret
.spec
= error_mark_node
;
2560 ret
.kind
= ctsk_tagref
;
2561 ret
.expr
= NULL_TREE
;
2562 ret
.expr_const_operands
= true;
2565 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2566 /* In ISO C, enumerated types can be referred to only if already
2568 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2571 pedwarn (enum_loc
, OPT_Wpedantic
,
2572 "ISO C forbids forward references to %<enum%> types");
2577 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2579 struct-or-union-specifier:
2580 struct-or-union attributes[opt] identifier[opt]
2581 { struct-contents } attributes[opt]
2582 struct-or-union attributes[opt] identifier
2585 struct-declaration-list
2587 struct-declaration-list:
2588 struct-declaration ;
2589 struct-declaration-list struct-declaration ;
2596 struct-declaration-list struct-declaration
2598 struct-declaration-list:
2599 struct-declaration-list ;
2602 (Note that in the syntax here, unlike that in ISO C, the semicolons
2603 are included here rather than in struct-declaration, in order to
2604 describe the syntax with extra semicolons and missing semicolon at
2609 struct-declaration-list:
2610 @defs ( class-name )
2612 (Note this does not include a trailing semicolon, but can be
2613 followed by further declarations, and gets a pedwarn-if-pedantic
2614 when followed by a semicolon.) */
2616 static struct c_typespec
2617 c_parser_struct_or_union_specifier (c_parser
*parser
)
2619 struct c_typespec ret
;
2621 tree ident
= NULL_TREE
;
2622 location_t struct_loc
;
2623 location_t ident_loc
= UNKNOWN_LOCATION
;
2624 enum tree_code code
;
2625 switch (c_parser_peek_token (parser
)->keyword
)
2636 struct_loc
= c_parser_peek_token (parser
)->location
;
2637 c_parser_consume_token (parser
);
2638 attrs
= c_parser_attributes (parser
);
2640 /* Set the location in case we create a decl now. */
2641 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2643 if (c_parser_next_token_is (parser
, CPP_NAME
))
2645 ident
= c_parser_peek_token (parser
)->value
;
2646 ident_loc
= c_parser_peek_token (parser
)->location
;
2647 struct_loc
= ident_loc
;
2648 c_parser_consume_token (parser
);
2650 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2652 /* Parse a struct or union definition. Start the scope of the
2653 tag before parsing components. */
2654 struct c_struct_parse_info
*struct_info
;
2655 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2657 /* We chain the components in reverse order, then put them in
2658 forward order at the end. Each struct-declaration may
2659 declare multiple components (comma-separated), so we must use
2660 chainon to join them, although when parsing each
2661 struct-declaration we can use TREE_CHAIN directly.
2663 The theory behind all this is that there will be more
2664 semicolon separated fields than comma separated fields, and
2665 so we'll be minimizing the number of node traversals required
2668 timevar_push (TV_PARSE_STRUCT
);
2669 contents
= NULL_TREE
;
2670 c_parser_consume_token (parser
);
2671 /* Handle the Objective-C @defs construct,
2672 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2673 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2676 gcc_assert (c_dialect_objc ());
2677 c_parser_consume_token (parser
);
2678 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2680 if (c_parser_next_token_is (parser
, CPP_NAME
)
2681 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2683 name
= c_parser_peek_token (parser
)->value
;
2684 c_parser_consume_token (parser
);
2688 c_parser_error (parser
, "expected class name");
2689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2692 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2694 contents
= nreverse (objc_get_class_ivars (name
));
2697 /* Parse the struct-declarations and semicolons. Problems with
2698 semicolons are diagnosed here; empty structures are diagnosed
2703 /* Parse any stray semicolon. */
2704 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2706 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2707 "extra semicolon in struct or union specified");
2708 c_parser_consume_token (parser
);
2711 /* Stop if at the end of the struct or union contents. */
2712 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2714 c_parser_consume_token (parser
);
2717 /* Accept #pragmas at struct scope. */
2718 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2720 c_parser_pragma (parser
, pragma_struct
);
2723 /* Parse some comma-separated declarations, but not the
2724 trailing semicolon if any. */
2725 decls
= c_parser_struct_declaration (parser
);
2726 contents
= chainon (decls
, contents
);
2727 /* If no semicolon follows, either we have a parse error or
2728 are at the end of the struct or union and should
2730 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2731 c_parser_consume_token (parser
);
2734 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2735 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2736 "no semicolon at end of struct or union");
2737 else if (parser
->error
2738 || !c_parser_next_token_starts_declspecs (parser
))
2740 c_parser_error (parser
, "expected %<;%>");
2741 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2745 /* If we come here, we have already emitted an error
2746 for an expected `;', identifier or `(', and we also
2747 recovered already. Go on with the next field. */
2750 postfix_attrs
= c_parser_attributes (parser
);
2751 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2752 chainon (attrs
, postfix_attrs
), struct_info
);
2753 ret
.kind
= ctsk_tagdef
;
2754 ret
.expr
= NULL_TREE
;
2755 ret
.expr_const_operands
= true;
2756 timevar_pop (TV_PARSE_STRUCT
);
2761 c_parser_error (parser
, "expected %<{%>");
2762 ret
.spec
= error_mark_node
;
2763 ret
.kind
= ctsk_tagref
;
2764 ret
.expr
= NULL_TREE
;
2765 ret
.expr_const_operands
= true;
2768 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2772 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2773 the trailing semicolon.
2776 specifier-qualifier-list struct-declarator-list
2777 static_assert-declaration-no-semi
2779 specifier-qualifier-list:
2780 type-specifier specifier-qualifier-list[opt]
2781 type-qualifier specifier-qualifier-list[opt]
2782 attributes specifier-qualifier-list[opt]
2784 struct-declarator-list:
2786 struct-declarator-list , attributes[opt] struct-declarator
2789 declarator attributes[opt]
2790 declarator[opt] : constant-expression attributes[opt]
2795 __extension__ struct-declaration
2796 specifier-qualifier-list
2798 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
2799 of attributes where shown is a GNU extension. In GNU C, we accept
2800 any expression without commas in the syntax (assignment
2801 expressions, not just conditional expressions); assignment
2802 expressions will be diagnosed as non-constant. */
2805 c_parser_struct_declaration (c_parser
*parser
)
2807 struct c_declspecs
*specs
;
2809 tree all_prefix_attrs
;
2811 location_t decl_loc
;
2812 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2816 ext
= disable_extension_diagnostics ();
2817 c_parser_consume_token (parser
);
2818 decl
= c_parser_struct_declaration (parser
);
2819 restore_extension_diagnostics (ext
);
2822 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
2824 c_parser_static_assert_declaration_no_semi (parser
);
2827 specs
= build_null_declspecs ();
2828 decl_loc
= c_parser_peek_token (parser
)->location
;
2829 /* Strictly by the standard, we shouldn't allow _Alignas here,
2830 but it appears to have been intended to allow it there, so
2831 we're keeping it as it is until WG14 reaches a conclusion
2833 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
2834 c_parser_declspecs (parser
, specs
, false, true, true,
2835 true, false, cla_nonabstract_decl
);
2838 if (!specs
->declspecs_seen_p
)
2840 c_parser_error (parser
, "expected specifier-qualifier-list");
2843 finish_declspecs (specs
);
2844 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2845 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2848 if (specs
->typespec_kind
== ctsk_none
)
2850 pedwarn (decl_loc
, OPT_Wpedantic
,
2851 "ISO C forbids member declarations with no members");
2852 shadow_tag_warned (specs
, pedantic
);
2857 /* Support for unnamed structs or unions as members of
2858 structs or unions (which is [a] useful and [b] supports
2862 ret
= grokfield (c_parser_peek_token (parser
)->location
,
2863 build_id_declarator (NULL_TREE
), specs
,
2866 decl_attributes (&ret
, attrs
, 0);
2871 /* Provide better error recovery. Note that a type name here is valid,
2872 and will be treated as a field name. */
2873 if (specs
->typespec_kind
== ctsk_tagdef
2874 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
2875 && c_parser_next_token_starts_declspecs (parser
)
2876 && !c_parser_next_token_is (parser
, CPP_NAME
))
2878 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
2879 parser
->error
= false;
2883 pending_xref_error ();
2884 prefix_attrs
= specs
->attrs
;
2885 all_prefix_attrs
= prefix_attrs
;
2886 specs
->attrs
= NULL_TREE
;
2890 /* Declaring one or more declarators or un-named bit-fields. */
2891 struct c_declarator
*declarator
;
2893 if (c_parser_next_token_is (parser
, CPP_COLON
))
2894 declarator
= build_id_declarator (NULL_TREE
);
2896 declarator
= c_parser_declarator (parser
,
2897 specs
->typespec_kind
!= ctsk_none
,
2898 C_DTR_NORMAL
, &dummy
);
2899 if (declarator
== NULL
)
2901 c_parser_skip_to_end_of_block_or_statement (parser
);
2904 if (c_parser_next_token_is (parser
, CPP_COLON
)
2905 || c_parser_next_token_is (parser
, CPP_COMMA
)
2906 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2907 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2908 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2910 tree postfix_attrs
= NULL_TREE
;
2911 tree width
= NULL_TREE
;
2913 if (c_parser_next_token_is (parser
, CPP_COLON
))
2915 c_parser_consume_token (parser
);
2916 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2918 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2919 postfix_attrs
= c_parser_attributes (parser
);
2920 d
= grokfield (c_parser_peek_token (parser
)->location
,
2921 declarator
, specs
, width
, &all_prefix_attrs
);
2922 decl_attributes (&d
, chainon (postfix_attrs
,
2923 all_prefix_attrs
), 0);
2924 DECL_CHAIN (d
) = decls
;
2926 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2927 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2930 all_prefix_attrs
= prefix_attrs
;
2931 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2932 c_parser_consume_token (parser
);
2933 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2934 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2936 /* Semicolon consumed in caller. */
2941 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2947 c_parser_error (parser
,
2948 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2949 "%<__attribute__%>");
2956 /* Parse a typeof specifier (a GNU extension).
2959 typeof ( expression )
2960 typeof ( type-name )
2963 static struct c_typespec
2964 c_parser_typeof_specifier (c_parser
*parser
)
2966 struct c_typespec ret
;
2967 ret
.kind
= ctsk_typeof
;
2968 ret
.spec
= error_mark_node
;
2969 ret
.expr
= NULL_TREE
;
2970 ret
.expr_const_operands
= true;
2971 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2972 c_parser_consume_token (parser
);
2973 c_inhibit_evaluation_warnings
++;
2975 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2977 c_inhibit_evaluation_warnings
--;
2981 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
2983 struct c_type_name
*type
= c_parser_type_name (parser
);
2984 c_inhibit_evaluation_warnings
--;
2988 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
2989 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2995 location_t here
= c_parser_peek_token (parser
)->location
;
2996 struct c_expr expr
= c_parser_expression (parser
);
2997 c_inhibit_evaluation_warnings
--;
2999 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3000 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3001 error_at (here
, "%<typeof%> applied to a bit-field");
3002 mark_exp_read (expr
.value
);
3003 ret
.spec
= TREE_TYPE (expr
.value
);
3004 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3005 /* This is returned with the type so that when the type is
3006 evaluated, this can be evaluated. */
3008 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3009 pop_maybe_used (was_vm
);
3010 /* For use in macros such as those in <stdatomic.h>, remove all
3011 qualifiers from atomic types. (const can be an issue for more macros
3012 using typeof than just the <stdatomic.h> ones.) */
3013 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3014 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3016 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3020 /* Parse an alignment-specifier.
3024 alignment-specifier:
3025 _Alignas ( type-name )
3026 _Alignas ( constant-expression )
3030 c_parser_alignas_specifier (c_parser
* parser
)
3032 tree ret
= error_mark_node
;
3033 location_t loc
= c_parser_peek_token (parser
)->location
;
3034 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3035 c_parser_consume_token (parser
);
3039 pedwarn (loc
, OPT_Wpedantic
,
3040 "ISO C99 does not support %<_Alignas%>");
3042 pedwarn (loc
, OPT_Wpedantic
,
3043 "ISO C90 does not support %<_Alignas%>");
3045 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3047 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3049 struct c_type_name
*type
= c_parser_type_name (parser
);
3051 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3055 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3056 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3060 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3061 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3062 be redeclared; otherwise it may not. KIND indicates which kind of
3063 declarator is wanted. Returns a valid declarator except in the
3064 case of a syntax error in which case NULL is returned. *SEEN_ID is
3065 set to true if an identifier being declared is seen; this is used
3066 to diagnose bad forms of abstract array declarators and to
3067 determine whether an identifier list is syntactically permitted.
3070 pointer[opt] direct-declarator
3074 ( attributes[opt] declarator )
3075 direct-declarator array-declarator
3076 direct-declarator ( parameter-type-list )
3077 direct-declarator ( identifier-list[opt] )
3080 * type-qualifier-list[opt]
3081 * type-qualifier-list[opt] pointer
3083 type-qualifier-list:
3086 type-qualifier-list type-qualifier
3087 type-qualifier-list attributes
3090 [ type-qualifier-list[opt] assignment-expression[opt] ]
3091 [ static type-qualifier-list[opt] assignment-expression ]
3092 [ type-qualifier-list static assignment-expression ]
3093 [ type-qualifier-list[opt] * ]
3095 parameter-type-list:
3097 parameter-list , ...
3100 parameter-declaration
3101 parameter-list , parameter-declaration
3103 parameter-declaration:
3104 declaration-specifiers declarator attributes[opt]
3105 declaration-specifiers abstract-declarator[opt] attributes[opt]
3109 identifier-list , identifier
3111 abstract-declarator:
3113 pointer[opt] direct-abstract-declarator
3115 direct-abstract-declarator:
3116 ( attributes[opt] abstract-declarator )
3117 direct-abstract-declarator[opt] array-declarator
3118 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3123 direct-declarator ( parameter-forward-declarations
3124 parameter-type-list[opt] )
3126 direct-abstract-declarator:
3127 direct-abstract-declarator[opt] ( parameter-forward-declarations
3128 parameter-type-list[opt] )
3130 parameter-forward-declarations:
3132 parameter-forward-declarations parameter-list ;
3134 The uses of attributes shown above are GNU extensions.
3136 Some forms of array declarator are not included in C99 in the
3137 syntax for abstract declarators; these are disallowed elsewhere.
3138 This may be a defect (DR#289).
3140 This function also accepts an omitted abstract declarator as being
3141 an abstract declarator, although not part of the formal syntax. */
3143 static struct c_declarator
*
3144 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3147 /* Parse any initial pointer part. */
3148 if (c_parser_next_token_is (parser
, CPP_MULT
))
3150 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3151 struct c_declarator
*inner
;
3152 c_parser_consume_token (parser
);
3153 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3154 false, false, cla_prefer_id
);
3155 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3159 return make_pointer_declarator (quals_attrs
, inner
);
3161 /* Now we have a direct declarator, direct abstract declarator or
3162 nothing (which counts as a direct abstract declarator here). */
3163 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3166 /* Parse a direct declarator or direct abstract declarator; arguments
3167 as c_parser_declarator. */
3169 static struct c_declarator
*
3170 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3173 /* The direct declarator must start with an identifier (possibly
3174 omitted) or a parenthesized declarator (possibly abstract). In
3175 an ordinary declarator, initial parentheses must start a
3176 parenthesized declarator. In an abstract declarator or parameter
3177 declarator, they could start a parenthesized declarator or a
3178 parameter list. To tell which, the open parenthesis and any
3179 following attributes must be read. If a declaration specifier
3180 follows, then it is a parameter list; if the specifier is a
3181 typedef name, there might be an ambiguity about redeclaring it,
3182 which is resolved in the direction of treating it as a typedef
3183 name. If a close parenthesis follows, it is also an empty
3184 parameter list, as the syntax does not permit empty abstract
3185 declarators. Otherwise, it is a parenthesized declarator (in
3186 which case the analysis may be repeated inside it, recursively).
3188 ??? There is an ambiguity in a parameter declaration "int
3189 (__attribute__((foo)) x)", where x is not a typedef name: it
3190 could be an abstract declarator for a function, or declare x with
3191 parentheses. The proper resolution of this ambiguity needs
3192 documenting. At present we follow an accident of the old
3193 parser's implementation, whereby the first parameter must have
3194 some declaration specifiers other than just attributes. Thus as
3195 a parameter declaration it is treated as a parenthesized
3196 parameter named x, and as an abstract declarator it is
3199 ??? Also following the old parser, attributes inside an empty
3200 parameter list are ignored, making it a list not yielding a
3201 prototype, rather than giving an error or making it have one
3202 parameter with implicit type int.
3204 ??? Also following the old parser, typedef names may be
3205 redeclared in declarators, but not Objective-C class names. */
3207 if (kind
!= C_DTR_ABSTRACT
3208 && c_parser_next_token_is (parser
, CPP_NAME
)
3210 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3211 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3212 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3214 struct c_declarator
*inner
3215 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3217 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3218 c_parser_consume_token (parser
);
3219 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3222 if (kind
!= C_DTR_NORMAL
3223 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3225 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3226 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3229 /* Either we are at the end of an abstract declarator, or we have
3232 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3235 struct c_declarator
*inner
;
3236 c_parser_consume_token (parser
);
3237 attrs
= c_parser_attributes (parser
);
3238 if (kind
!= C_DTR_NORMAL
3239 && (c_parser_next_token_starts_declspecs (parser
)
3240 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3242 struct c_arg_info
*args
3243 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3250 = build_function_declarator (args
,
3251 build_id_declarator (NULL_TREE
));
3252 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3256 /* A parenthesized declarator. */
3257 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3258 if (inner
!= NULL
&& attrs
!= NULL
)
3259 inner
= build_attrs_declarator (attrs
, inner
);
3260 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3262 c_parser_consume_token (parser
);
3266 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3270 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3277 if (kind
== C_DTR_NORMAL
)
3279 c_parser_error (parser
, "expected identifier or %<(%>");
3283 return build_id_declarator (NULL_TREE
);
3287 /* Parse part of a direct declarator or direct abstract declarator,
3288 given that some (in INNER) has already been parsed; ID_PRESENT is
3289 true if an identifier is present, false for an abstract
3292 static struct c_declarator
*
3293 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3294 struct c_declarator
*inner
)
3296 /* Parse a sequence of array declarators and parameter lists. */
3297 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3299 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3300 struct c_declarator
*declarator
;
3301 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3304 struct c_expr dimen
;
3305 dimen
.value
= NULL_TREE
;
3306 dimen
.original_code
= ERROR_MARK
;
3307 dimen
.original_type
= NULL_TREE
;
3308 c_parser_consume_token (parser
);
3309 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3310 false, false, cla_prefer_id
);
3311 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3313 c_parser_consume_token (parser
);
3314 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3315 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3316 false, false, cla_prefer_id
);
3317 if (!quals_attrs
->declspecs_seen_p
)
3319 /* If "static" is present, there must be an array dimension.
3320 Otherwise, there may be a dimension, "*", or no
3325 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3329 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3331 dimen
.value
= NULL_TREE
;
3334 else if (flag_cilkplus
3335 && c_parser_next_token_is (parser
, CPP_COLON
))
3337 dimen
.value
= error_mark_node
;
3339 error_at (c_parser_peek_token (parser
)->location
,
3340 "array notations cannot be used in declaration");
3341 c_parser_consume_token (parser
);
3343 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3345 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3347 dimen
.value
= NULL_TREE
;
3349 c_parser_consume_token (parser
);
3354 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3360 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3363 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3364 c_parser_consume_token (parser
);
3365 else if (flag_cilkplus
3366 && c_parser_next_token_is (parser
, CPP_COLON
))
3368 error_at (c_parser_peek_token (parser
)->location
,
3369 "array notations cannot be used in declaration");
3370 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3375 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3380 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3381 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3382 static_seen
, star_seen
);
3383 if (declarator
== NULL
)
3385 inner
= set_array_declarator_inner (declarator
, inner
);
3386 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3388 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3391 struct c_arg_info
*args
;
3392 c_parser_consume_token (parser
);
3393 attrs
= c_parser_attributes (parser
);
3394 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3399 inner
= build_function_declarator (args
, inner
);
3400 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3406 /* Parse a parameter list or identifier list, including the closing
3407 parenthesis but not the opening one. ATTRS are the attributes at
3408 the start of the list. ID_LIST_OK is true if an identifier list is
3409 acceptable; such a list must not have attributes at the start. */
3411 static struct c_arg_info
*
3412 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3415 declare_parm_level ();
3416 /* If the list starts with an identifier, it is an identifier list.
3417 Otherwise, it is either a prototype list or an empty list. */
3420 && c_parser_next_token_is (parser
, CPP_NAME
)
3421 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3423 /* Look ahead to detect typos in type names. */
3424 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3425 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3426 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3427 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
)
3429 tree list
= NULL_TREE
, *nextp
= &list
;
3430 while (c_parser_next_token_is (parser
, CPP_NAME
)
3431 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3433 *nextp
= build_tree_list (NULL_TREE
,
3434 c_parser_peek_token (parser
)->value
);
3435 nextp
= & TREE_CHAIN (*nextp
);
3436 c_parser_consume_token (parser
);
3437 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3439 c_parser_consume_token (parser
);
3440 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3442 c_parser_error (parser
, "expected identifier");
3446 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3448 struct c_arg_info
*ret
= build_arg_info ();
3450 c_parser_consume_token (parser
);
3456 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3464 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3471 /* Parse a parameter list (possibly empty), including the closing
3472 parenthesis but not the opening one. ATTRS are the attributes at
3473 the start of the list. EXPR is NULL or an expression that needs to
3474 be evaluated for the side effects of array size expressions in the
3477 static struct c_arg_info
*
3478 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3480 bool bad_parm
= false;
3482 /* ??? Following the old parser, forward parameter declarations may
3483 use abstract declarators, and if no real parameter declarations
3484 follow the forward declarations then this is not diagnosed. Also
3485 note as above that attributes are ignored as the only contents of
3486 the parentheses, or as the only contents after forward
3488 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3490 struct c_arg_info
*ret
= build_arg_info ();
3491 c_parser_consume_token (parser
);
3494 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3496 struct c_arg_info
*ret
= build_arg_info ();
3498 if (flag_allow_parameterless_variadic_functions
)
3500 /* F (...) is allowed. */
3501 ret
->types
= NULL_TREE
;
3505 /* Suppress -Wold-style-definition for this case. */
3506 ret
->types
= error_mark_node
;
3507 error_at (c_parser_peek_token (parser
)->location
,
3508 "ISO C requires a named argument before %<...%>");
3510 c_parser_consume_token (parser
);
3511 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3513 c_parser_consume_token (parser
);
3518 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3523 /* Nonempty list of parameters, either terminated with semicolon
3524 (forward declarations; recurse) or with close parenthesis (normal
3525 function) or with ", ... )" (variadic function). */
3528 /* Parse a parameter. */
3529 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3534 push_parm_decl (parm
, &expr
);
3535 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3538 c_parser_consume_token (parser
);
3539 mark_forward_parm_decls ();
3540 new_attrs
= c_parser_attributes (parser
);
3541 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3543 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3545 c_parser_consume_token (parser
);
3549 return get_parm_info (false, expr
);
3551 if (!c_parser_require (parser
, CPP_COMMA
,
3552 "expected %<;%>, %<,%> or %<)%>"))
3554 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3557 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3559 c_parser_consume_token (parser
);
3560 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3562 c_parser_consume_token (parser
);
3566 return get_parm_info (true, expr
);
3570 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3578 /* Parse a parameter declaration. ATTRS are the attributes at the
3579 start of the declaration if it is the first parameter. */
3581 static struct c_parm
*
3582 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3584 struct c_declspecs
*specs
;
3585 struct c_declarator
*declarator
;
3587 tree postfix_attrs
= NULL_TREE
;
3590 /* Accept #pragmas between parameter declarations. */
3591 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3592 c_parser_pragma (parser
, pragma_param
);
3594 if (!c_parser_next_token_starts_declspecs (parser
))
3596 c_token
*token
= c_parser_peek_token (parser
);
3599 c_parser_set_source_position_from_token (token
);
3600 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3602 error_at (token
->location
, "unknown type name %qE", token
->value
);
3603 parser
->error
= true;
3605 /* ??? In some Objective-C cases '...' isn't applicable so there
3606 should be a different message. */
3608 c_parser_error (parser
,
3609 "expected declaration specifiers or %<...%>");
3610 c_parser_skip_to_end_of_parameter (parser
);
3613 specs
= build_null_declspecs ();
3616 declspecs_add_attrs (input_location
, specs
, attrs
);
3619 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3620 cla_nonabstract_decl
);
3621 finish_declspecs (specs
);
3622 pending_xref_error ();
3623 prefix_attrs
= specs
->attrs
;
3624 specs
->attrs
= NULL_TREE
;
3625 declarator
= c_parser_declarator (parser
,
3626 specs
->typespec_kind
!= ctsk_none
,
3627 C_DTR_PARM
, &dummy
);
3628 if (declarator
== NULL
)
3630 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3633 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3634 postfix_attrs
= c_parser_attributes (parser
);
3635 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3639 /* Parse a string literal in an asm expression. It should not be
3640 translated, and wide string literals are an error although
3641 permitted by the syntax. This is a GNU extension.
3646 ??? At present, following the old parser, the caller needs to have
3647 set lex_untranslated_string to 1. It would be better to follow the
3648 C++ parser rather than using this kludge. */
3651 c_parser_asm_string_literal (c_parser
*parser
)
3654 int save_flag
= warn_overlength_strings
;
3655 warn_overlength_strings
= 0;
3656 if (c_parser_next_token_is (parser
, CPP_STRING
))
3658 str
= c_parser_peek_token (parser
)->value
;
3659 c_parser_consume_token (parser
);
3661 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3663 error_at (c_parser_peek_token (parser
)->location
,
3664 "wide string literal in %<asm%>");
3665 str
= build_string (1, "");
3666 c_parser_consume_token (parser
);
3670 c_parser_error (parser
, "expected string literal");
3673 warn_overlength_strings
= save_flag
;
3677 /* Parse a simple asm expression. This is used in restricted
3678 contexts, where a full expression with inputs and outputs does not
3679 make sense. This is a GNU extension.
3682 asm ( asm-string-literal )
3686 c_parser_simple_asm_expr (c_parser
*parser
)
3689 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3690 /* ??? Follow the C++ parser rather than using the
3691 lex_untranslated_string kludge. */
3692 parser
->lex_untranslated_string
= true;
3693 c_parser_consume_token (parser
);
3694 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3696 parser
->lex_untranslated_string
= false;
3699 str
= c_parser_asm_string_literal (parser
);
3700 parser
->lex_untranslated_string
= false;
3701 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3703 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3710 c_parser_attribute_any_word (c_parser
*parser
)
3712 tree attr_name
= NULL_TREE
;
3714 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3716 /* ??? See comment above about what keywords are accepted here. */
3718 switch (c_parser_peek_token (parser
)->keyword
)
3749 case RID_TRANSACTION_ATOMIC
:
3750 case RID_TRANSACTION_CANCEL
:
3762 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3763 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3765 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3766 attr_name
= c_parser_peek_token (parser
)->value
;
3771 /* Returns true of NAME is an IDENTIFIER_NODE with identiifer "vector,"
3772 "__vector" or "__vector__." */
3775 is_cilkplus_vector_p (tree name
)
3777 if (flag_cilkplus
&& is_attribute_p ("vector", name
))
3782 #define CILK_SIMD_FN_CLAUSE_MASK \
3783 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3784 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3785 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3786 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3787 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3789 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3790 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3791 pushed into the token list.
3794 vector (<vector attributes>). */
3797 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
3799 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
3801 int paren_scope
= 0;
3802 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
3803 /* Consume the "vector" token. */
3804 c_parser_consume_token (parser
);
3806 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3808 c_parser_consume_token (parser
);
3811 while (paren_scope
> 0)
3813 c_token
*token
= c_parser_peek_token (parser
);
3814 if (token
->type
== CPP_OPEN_PAREN
)
3816 else if (token
->type
== CPP_CLOSE_PAREN
)
3818 /* Do not push the last ')' since we are not pushing the '('. */
3819 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
3820 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
3821 c_parser_consume_token (parser
);
3824 /* Since we are converting an attribute to a pragma, we need to end the
3825 attribute with PRAGMA_EOL. */
3827 memset (&eol_token
, 0, sizeof (eol_token
));
3828 eol_token
.type
= CPP_PRAGMA_EOL
;
3829 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
3832 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
3835 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
3837 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
3839 /* c_parser_attributes is called in several places, so if these EOF
3840 tokens are already inserted, then don't do them again. */
3841 if (last_token
.type
== CPP_EOF
)
3844 /* Two CPP_EOF token are added as a safety net since the normal C
3845 front-end has two token look-ahead. */
3847 eof_token
.type
= CPP_EOF
;
3848 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3849 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
3852 /* Parse (possibly empty) attributes. This is a GNU extension.
3856 attributes attribute
3859 __attribute__ ( ( attribute-list ) )
3863 attribute_list , attrib
3868 any-word ( identifier )
3869 any-word ( identifier , nonempty-expr-list )
3870 any-word ( expr-list )
3872 where the "identifier" must not be declared as a type, and
3873 "any-word" may be any identifier (including one declared as a
3874 type), a reserved word storage class specifier, type specifier or
3875 type qualifier. ??? This still leaves out most reserved keywords
3876 (following the old parser), shouldn't we include them, and why not
3877 allow identifiers declared as types to start the arguments? */
3880 c_parser_attributes (c_parser
*parser
)
3882 tree attrs
= NULL_TREE
;
3883 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3885 /* ??? Follow the C++ parser rather than using the
3886 lex_untranslated_string kludge. */
3887 parser
->lex_untranslated_string
= true;
3888 c_parser_consume_token (parser
);
3889 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3891 parser
->lex_untranslated_string
= false;
3894 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3896 parser
->lex_untranslated_string
= false;
3897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3900 /* Parse the attribute list. */
3901 while (c_parser_next_token_is (parser
, CPP_COMMA
)
3902 || c_parser_next_token_is (parser
, CPP_NAME
)
3903 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
3905 tree attr
, attr_name
, attr_args
;
3906 vec
<tree
, va_gc
> *expr_list
;
3907 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3909 c_parser_consume_token (parser
);
3913 attr_name
= c_parser_attribute_any_word (parser
);
3914 if (attr_name
== NULL
)
3916 if (is_cilkplus_vector_p (attr_name
))
3918 c_token
*v_token
= c_parser_peek_token (parser
);
3919 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
3922 c_parser_consume_token (parser
);
3923 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
3925 attr
= build_tree_list (attr_name
, NULL_TREE
);
3926 attrs
= chainon (attrs
, attr
);
3929 c_parser_consume_token (parser
);
3930 /* Parse the attribute contents. If they start with an
3931 identifier which is followed by a comma or close
3932 parenthesis, then the arguments start with that
3933 identifier; otherwise they are an expression list.
3934 In objective-c the identifier may be a classname. */
3935 if (c_parser_next_token_is (parser
, CPP_NAME
)
3936 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3937 || (c_dialect_objc ()
3938 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3939 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
3940 || (c_parser_peek_2nd_token (parser
)->type
3941 == CPP_CLOSE_PAREN
)))
3943 tree arg1
= c_parser_peek_token (parser
)->value
;
3944 c_parser_consume_token (parser
);
3945 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3946 attr_args
= build_tree_list (NULL_TREE
, arg1
);
3950 c_parser_consume_token (parser
);
3951 expr_list
= c_parser_expr_list (parser
, false, true,
3952 NULL
, NULL
, NULL
, NULL
);
3953 tree_list
= build_tree_list_vec (expr_list
);
3954 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
3955 release_tree_vector (expr_list
);
3960 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3961 attr_args
= NULL_TREE
;
3964 expr_list
= c_parser_expr_list (parser
, false, true,
3965 NULL
, NULL
, NULL
, NULL
);
3966 attr_args
= build_tree_list_vec (expr_list
);
3967 release_tree_vector (expr_list
);
3970 attr
= build_tree_list (attr_name
, attr_args
);
3971 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3972 c_parser_consume_token (parser
);
3975 parser
->lex_untranslated_string
= false;
3976 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3980 attrs
= chainon (attrs
, attr
);
3982 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3983 c_parser_consume_token (parser
);
3986 parser
->lex_untranslated_string
= false;
3987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
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 parser
->lex_untranslated_string
= false;
4003 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4004 c_finish_cilk_simd_fn_tokens (parser
);
4008 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4011 specifier-qualifier-list abstract-declarator[opt]
4014 static struct c_type_name
*
4015 c_parser_type_name (c_parser
*parser
)
4017 struct c_declspecs
*specs
= build_null_declspecs ();
4018 struct c_declarator
*declarator
;
4019 struct c_type_name
*ret
;
4021 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4023 if (!specs
->declspecs_seen_p
)
4025 c_parser_error (parser
, "expected specifier-qualifier-list");
4028 if (specs
->type
!= error_mark_node
)
4030 pending_xref_error ();
4031 finish_declspecs (specs
);
4033 declarator
= c_parser_declarator (parser
,
4034 specs
->typespec_kind
!= ctsk_none
,
4035 C_DTR_ABSTRACT
, &dummy
);
4036 if (declarator
== NULL
)
4038 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4040 ret
->declarator
= declarator
;
4044 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4047 assignment-expression
4048 { initializer-list }
4049 { initializer-list , }
4052 designation[opt] initializer
4053 initializer-list , designation[opt] initializer
4060 designator-list designator
4067 [ constant-expression ]
4079 [ constant-expression ... constant-expression ]
4081 Any expression without commas is accepted in the syntax for the
4082 constant-expressions, with non-constant expressions rejected later.
4084 This function is only used for top-level initializers; for nested
4085 ones, see c_parser_initval. */
4087 static struct c_expr
4088 c_parser_initializer (c_parser
*parser
)
4090 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4091 return c_parser_braced_init (parser
, NULL_TREE
, false);
4095 location_t loc
= c_parser_peek_token (parser
)->location
;
4096 ret
= c_parser_expr_no_commas (parser
, NULL
);
4097 if (TREE_CODE (ret
.value
) != STRING_CST
4098 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4099 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4104 /* Parse a braced initializer list. TYPE is the type specified for a
4105 compound literal, and NULL_TREE for other initializers and for
4106 nested braced lists. NESTED_P is true for nested braced lists,
4107 false for the list of a compound literal or the list that is the
4108 top-level initializer in a declaration. */
4110 static struct c_expr
4111 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
4114 struct obstack braced_init_obstack
;
4115 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4116 gcc_obstack_init (&braced_init_obstack
);
4117 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4118 c_parser_consume_token (parser
);
4120 push_init_level (0, &braced_init_obstack
);
4122 really_start_incremental_init (type
);
4123 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4125 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4129 /* Parse a non-empty initializer list, possibly with a trailing
4133 c_parser_initelt (parser
, &braced_init_obstack
);
4136 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4137 c_parser_consume_token (parser
);
4140 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4144 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4146 ret
.value
= error_mark_node
;
4147 ret
.original_code
= ERROR_MARK
;
4148 ret
.original_type
= NULL
;
4149 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4150 pop_init_level (0, &braced_init_obstack
);
4151 obstack_free (&braced_init_obstack
, NULL
);
4154 c_parser_consume_token (parser
);
4155 ret
= pop_init_level (0, &braced_init_obstack
);
4156 obstack_free (&braced_init_obstack
, NULL
);
4160 /* Parse a nested initializer, including designators. */
4163 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4165 /* Parse any designator or designator list. A single array
4166 designator may have the subsequent "=" omitted in GNU C, but a
4167 longer list or a structure member designator may not. */
4168 if (c_parser_next_token_is (parser
, CPP_NAME
)
4169 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4171 /* Old-style structure member designator. */
4172 set_init_label (c_parser_peek_token (parser
)->value
,
4173 braced_init_obstack
);
4174 /* Use the colon as the error location. */
4175 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4176 "obsolete use of designated initializer with %<:%>");
4177 c_parser_consume_token (parser
);
4178 c_parser_consume_token (parser
);
4182 /* des_seen is 0 if there have been no designators, 1 if there
4183 has been a single array designator and 2 otherwise. */
4185 /* Location of a designator. */
4186 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4187 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4188 || c_parser_next_token_is (parser
, CPP_DOT
))
4190 int des_prev
= des_seen
;
4192 des_loc
= c_parser_peek_token (parser
)->location
;
4195 if (c_parser_next_token_is (parser
, CPP_DOT
))
4198 c_parser_consume_token (parser
);
4199 if (c_parser_next_token_is (parser
, CPP_NAME
))
4201 set_init_label (c_parser_peek_token (parser
)->value
,
4202 braced_init_obstack
);
4203 c_parser_consume_token (parser
);
4208 init
.value
= error_mark_node
;
4209 init
.original_code
= ERROR_MARK
;
4210 init
.original_type
= NULL
;
4211 c_parser_error (parser
, "expected identifier");
4212 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4213 process_init_element (input_location
, init
, false,
4214 braced_init_obstack
);
4221 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4222 /* ??? Following the old parser, [ objc-receiver
4223 objc-message-args ] is accepted as an initializer,
4224 being distinguished from a designator by what follows
4225 the first assignment expression inside the square
4226 brackets, but after a first array designator a
4227 subsequent square bracket is for Objective-C taken to
4228 start an expression, using the obsolete form of
4229 designated initializer without '=', rather than
4230 possibly being a second level of designation: in LALR
4231 terms, the '[' is shifted rather than reducing
4232 designator to designator-list. */
4233 if (des_prev
== 1 && c_dialect_objc ())
4235 des_seen
= des_prev
;
4238 if (des_prev
== 0 && c_dialect_objc ())
4240 /* This might be an array designator or an
4241 Objective-C message expression. If the former,
4242 continue parsing here; if the latter, parse the
4243 remainder of the initializer given the starting
4244 primary-expression. ??? It might make sense to
4245 distinguish when des_prev == 1 as well; see
4246 previous comment. */
4248 struct c_expr mexpr
;
4249 c_parser_consume_token (parser
);
4250 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4251 && ((c_parser_peek_token (parser
)->id_kind
4253 || (c_parser_peek_token (parser
)->id_kind
4254 == C_ID_CLASSNAME
)))
4256 /* Type name receiver. */
4257 tree id
= c_parser_peek_token (parser
)->value
;
4258 c_parser_consume_token (parser
);
4259 rec
= objc_get_class_reference (id
);
4260 goto parse_message_args
;
4262 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4263 mark_exp_read (first
);
4264 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4265 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4266 goto array_desig_after_first
;
4267 /* Expression receiver. So far only one part
4268 without commas has been parsed; there might be
4269 more of the expression. */
4271 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4274 location_t comma_loc
, exp_loc
;
4275 comma_loc
= c_parser_peek_token (parser
)->location
;
4276 c_parser_consume_token (parser
);
4277 exp_loc
= c_parser_peek_token (parser
)->location
;
4278 next
= c_parser_expr_no_commas (parser
, NULL
);
4279 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4281 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4284 /* Now parse the objc-message-args. */
4285 args
= c_parser_objc_message_args (parser
);
4286 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4289 = objc_build_message_expr (rec
, args
);
4290 mexpr
.original_code
= ERROR_MARK
;
4291 mexpr
.original_type
= NULL
;
4292 /* Now parse and process the remainder of the
4293 initializer, starting with this message
4294 expression as a primary-expression. */
4295 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4298 c_parser_consume_token (parser
);
4299 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4300 mark_exp_read (first
);
4301 array_desig_after_first
:
4302 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4304 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4305 c_parser_consume_token (parser
);
4306 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4307 mark_exp_read (second
);
4311 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4313 c_parser_consume_token (parser
);
4314 set_init_index (first
, second
, braced_init_obstack
);
4316 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4317 "ISO C forbids specifying range of elements to initialize");
4320 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4326 if (c_parser_next_token_is (parser
, CPP_EQ
))
4329 pedwarn (des_loc
, OPT_Wpedantic
,
4330 "ISO C90 forbids specifying subobject to initialize");
4331 c_parser_consume_token (parser
);
4336 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4337 "obsolete use of designated initializer without %<=%>");
4341 init
.value
= error_mark_node
;
4342 init
.original_code
= ERROR_MARK
;
4343 init
.original_type
= NULL
;
4344 c_parser_error (parser
, "expected %<=%>");
4345 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4346 process_init_element (input_location
, init
, false,
4347 braced_init_obstack
);
4353 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4356 /* Parse a nested initializer; as c_parser_initializer but parses
4357 initializers within braced lists, after any designators have been
4358 applied. If AFTER is not NULL then it is an Objective-C message
4359 expression which is the primary-expression starting the
4363 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4364 struct obstack
* braced_init_obstack
)
4367 gcc_assert (!after
|| c_dialect_objc ());
4368 location_t loc
= c_parser_peek_token (parser
)->location
;
4370 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4371 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4374 init
= c_parser_expr_no_commas (parser
, after
);
4375 if (init
.value
!= NULL_TREE
4376 && TREE_CODE (init
.value
) != STRING_CST
4377 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4378 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4380 process_init_element (loc
, init
, false, braced_init_obstack
);
4383 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4387 { block-item-list[opt] }
4388 { label-declarations block-item-list }
4392 block-item-list block-item
4404 { label-declarations block-item-list }
4407 __extension__ nested-declaration
4408 nested-function-definition
4412 label-declarations label-declaration
4415 __label__ identifier-list ;
4417 Allowing the mixing of declarations and code is new in C99. The
4418 GNU syntax also permits (not shown above) labels at the end of
4419 compound statements, which yield an error. We don't allow labels
4420 on declarations; this might seem like a natural extension, but
4421 there would be a conflict between attributes on the label and
4422 prefix attributes on the declaration. ??? The syntax follows the
4423 old parser in requiring something after label declarations.
4424 Although they are erroneous if the labels declared aren't defined,
4425 is it useful for the syntax to be this way?
4438 cancellation-point-directive */
4441 c_parser_compound_statement (c_parser
*parser
)
4444 location_t brace_loc
;
4445 brace_loc
= c_parser_peek_token (parser
)->location
;
4446 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4448 /* Ensure a scope is entered and left anyway to avoid confusion
4449 if we have just prepared to enter a function body. */
4450 stmt
= c_begin_compound_stmt (true);
4451 c_end_compound_stmt (brace_loc
, stmt
, true);
4452 return error_mark_node
;
4454 stmt
= c_begin_compound_stmt (true);
4455 c_parser_compound_statement_nostart (parser
);
4457 /* If the compound stmt contains array notations, then we expand them. */
4458 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4459 stmt
= expand_array_notation_exprs (stmt
);
4460 return c_end_compound_stmt (brace_loc
, stmt
, true);
4463 /* Parse a compound statement except for the opening brace. This is
4464 used for parsing both compound statements and statement expressions
4465 (which follow different paths to handling the opening). */
4468 c_parser_compound_statement_nostart (c_parser
*parser
)
4470 bool last_stmt
= false;
4471 bool last_label
= false;
4472 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4473 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4474 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4476 c_parser_consume_token (parser
);
4479 mark_valid_location_for_stdc_pragma (true);
4480 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4482 /* Read zero or more forward-declarations for labels that nested
4483 functions can jump to. */
4484 mark_valid_location_for_stdc_pragma (false);
4485 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4487 label_loc
= c_parser_peek_token (parser
)->location
;
4488 c_parser_consume_token (parser
);
4489 /* Any identifiers, including those declared as type names,
4494 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4496 c_parser_error (parser
, "expected identifier");
4500 = declare_label (c_parser_peek_token (parser
)->value
);
4501 C_DECLARED_LABEL_FLAG (label
) = 1;
4502 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4503 c_parser_consume_token (parser
);
4504 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4505 c_parser_consume_token (parser
);
4509 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4511 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4513 /* We must now have at least one statement, label or declaration. */
4514 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4516 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4517 c_parser_error (parser
, "expected declaration or statement");
4518 c_parser_consume_token (parser
);
4521 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4523 location_t loc
= c_parser_peek_token (parser
)->location
;
4524 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4525 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4526 || (c_parser_next_token_is (parser
, CPP_NAME
)
4527 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4529 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4530 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4532 label_loc
= c_parser_peek_token (parser
)->location
;
4535 mark_valid_location_for_stdc_pragma (false);
4536 c_parser_label (parser
);
4538 else if (!last_label
4539 && c_parser_next_tokens_start_declaration (parser
))
4542 mark_valid_location_for_stdc_pragma (false);
4543 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4547 (pedantic
&& !flag_isoc99
)
4549 : OPT_Wdeclaration_after_statement
,
4550 "ISO C90 forbids mixed declarations and code");
4553 else if (!last_label
4554 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4556 /* __extension__ can start a declaration, but is also an
4557 unary operator that can start an expression. Consume all
4558 but the last of a possible series of __extension__ to
4560 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4561 && (c_parser_peek_2nd_token (parser
)->keyword
4563 c_parser_consume_token (parser
);
4564 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4567 ext
= disable_extension_diagnostics ();
4568 c_parser_consume_token (parser
);
4570 mark_valid_location_for_stdc_pragma (false);
4571 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4573 /* Following the old parser, __extension__ does not
4574 disable this diagnostic. */
4575 restore_extension_diagnostics (ext
);
4577 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4579 : OPT_Wdeclaration_after_statement
,
4580 "ISO C90 forbids mixed declarations and code");
4586 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4588 /* External pragmas, and some omp pragmas, are not associated
4589 with regular c code, and so are not to be considered statements
4590 syntactically. This ensures that the user doesn't put them
4591 places that would turn into syntax errors if the directive
4593 if (c_parser_pragma (parser
, pragma_compound
))
4594 last_label
= false, last_stmt
= true;
4596 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4598 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4599 c_parser_error (parser
, "expected declaration or statement");
4602 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4604 if (parser
->in_if_block
)
4606 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4607 error_at (loc
, """expected %<}%> before %<else%>");
4612 error_at (loc
, "%<else%> without a previous %<if%>");
4613 c_parser_consume_token (parser
);
4622 mark_valid_location_for_stdc_pragma (false);
4623 c_parser_statement_after_labels (parser
);
4626 parser
->error
= false;
4629 error_at (label_loc
, "label at end of compound statement");
4630 c_parser_consume_token (parser
);
4631 /* Restore the value we started with. */
4632 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4635 /* Parse a label (C90 6.6.1, C99 6.8.1).
4638 identifier : attributes[opt]
4639 case constant-expression :
4645 case constant-expression ... constant-expression :
4647 The use of attributes on labels is a GNU extension. The syntax in
4648 GNU C accepts any expressions without commas, non-constant
4649 expressions being rejected later. */
4652 c_parser_label (c_parser
*parser
)
4654 location_t loc1
= c_parser_peek_token (parser
)->location
;
4655 tree label
= NULL_TREE
;
4656 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4659 c_parser_consume_token (parser
);
4660 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4661 if (c_parser_next_token_is (parser
, CPP_COLON
))
4663 c_parser_consume_token (parser
);
4664 label
= do_case (loc1
, exp1
, NULL_TREE
);
4666 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4668 c_parser_consume_token (parser
);
4669 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4670 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4671 label
= do_case (loc1
, exp1
, exp2
);
4674 c_parser_error (parser
, "expected %<:%> or %<...%>");
4676 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4678 c_parser_consume_token (parser
);
4679 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4680 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4684 tree name
= c_parser_peek_token (parser
)->value
;
4687 location_t loc2
= c_parser_peek_token (parser
)->location
;
4688 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4689 c_parser_consume_token (parser
);
4690 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4691 c_parser_consume_token (parser
);
4692 attrs
= c_parser_attributes (parser
);
4693 tlab
= define_label (loc2
, name
);
4696 decl_attributes (&tlab
, attrs
, 0);
4697 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4702 if (c_parser_next_tokens_start_declaration (parser
))
4704 error_at (c_parser_peek_token (parser
)->location
,
4705 "a label can only be part of a statement and "
4706 "a declaration is not a statement");
4707 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4708 /*static_assert_ok*/ true,
4709 /*empty_ok*/ true, /*nested*/ true,
4710 /*start_attr_ok*/ true, NULL
,
4716 /* Parse a statement (C90 6.6, C99 6.8).
4721 expression-statement
4729 expression-statement:
4732 selection-statement:
4736 iteration-statement:
4745 return expression[opt] ;
4758 objc-throw-statement
4759 objc-try-catch-statement
4760 objc-synchronized-statement
4762 objc-throw-statement:
4778 parallel-for-construct
4779 parallel-for-simd-construct
4780 parallel-sections-construct
4787 parallel-directive structured-block
4790 for-directive iteration-statement
4793 simd-directive iteration-statements
4796 for-simd-directive iteration-statements
4799 sections-directive section-scope
4802 single-directive structured-block
4804 parallel-for-construct:
4805 parallel-for-directive iteration-statement
4807 parallel-for-simd-construct:
4808 parallel-for-simd-directive iteration-statement
4810 parallel-sections-construct:
4811 parallel-sections-directive section-scope
4814 master-directive structured-block
4817 critical-directive structured-block
4820 atomic-directive expression-statement
4823 ordered-directive structured-block
4825 Transactional Memory:
4828 transaction-statement
4829 transaction-cancel-statement
4833 c_parser_statement (c_parser
*parser
)
4835 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4836 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4837 || (c_parser_next_token_is (parser
, CPP_NAME
)
4838 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4839 c_parser_label (parser
);
4840 c_parser_statement_after_labels (parser
);
4843 /* Parse a statement, other than a labeled statement. */
4846 c_parser_statement_after_labels (c_parser
*parser
)
4848 location_t loc
= c_parser_peek_token (parser
)->location
;
4849 tree stmt
= NULL_TREE
;
4850 bool in_if_block
= parser
->in_if_block
;
4851 parser
->in_if_block
= false;
4852 switch (c_parser_peek_token (parser
)->type
)
4854 case CPP_OPEN_BRACE
:
4855 add_stmt (c_parser_compound_statement (parser
));
4858 switch (c_parser_peek_token (parser
)->keyword
)
4861 c_parser_if_statement (parser
);
4864 c_parser_switch_statement (parser
);
4867 c_parser_while_statement (parser
, false);
4870 c_parser_do_statement (parser
, false);
4873 c_parser_for_statement (parser
, false);
4876 c_parser_consume_token (parser
);
4877 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4879 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4881 add_stmt (build_cilk_sync ());
4884 c_parser_consume_token (parser
);
4885 if (c_parser_next_token_is (parser
, CPP_NAME
))
4887 stmt
= c_finish_goto_label (loc
,
4888 c_parser_peek_token (parser
)->value
);
4889 c_parser_consume_token (parser
);
4891 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4895 c_parser_consume_token (parser
);
4896 val
= c_parser_expression (parser
);
4897 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4898 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4901 c_parser_error (parser
, "expected identifier or %<*%>");
4902 goto expect_semicolon
;
4904 c_parser_consume_token (parser
);
4905 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4906 goto expect_semicolon
;
4908 c_parser_consume_token (parser
);
4909 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4910 goto expect_semicolon
;
4912 c_parser_consume_token (parser
);
4913 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4915 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4916 c_parser_consume_token (parser
);
4920 struct c_expr expr
= c_parser_expression_conv (parser
);
4921 mark_exp_read (expr
.value
);
4922 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4923 goto expect_semicolon
;
4927 stmt
= c_parser_asm_statement (parser
);
4929 case RID_TRANSACTION_ATOMIC
:
4930 case RID_TRANSACTION_RELAXED
:
4931 stmt
= c_parser_transaction (parser
,
4932 c_parser_peek_token (parser
)->keyword
);
4934 case RID_TRANSACTION_CANCEL
:
4935 stmt
= c_parser_transaction_cancel (parser
);
4936 goto expect_semicolon
;
4938 gcc_assert (c_dialect_objc ());
4939 c_parser_consume_token (parser
);
4940 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4942 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4943 c_parser_consume_token (parser
);
4947 struct c_expr expr
= c_parser_expression (parser
);
4948 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4949 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4950 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4951 goto expect_semicolon
;
4955 gcc_assert (c_dialect_objc ());
4956 c_parser_objc_try_catch_finally_statement (parser
);
4958 case RID_AT_SYNCHRONIZED
:
4959 gcc_assert (c_dialect_objc ());
4960 c_parser_objc_synchronized_statement (parser
);
4967 c_parser_consume_token (parser
);
4969 case CPP_CLOSE_PAREN
:
4970 case CPP_CLOSE_SQUARE
:
4971 /* Avoid infinite loop in error recovery:
4972 c_parser_skip_until_found stops at a closing nesting
4973 delimiter without consuming it, but here we need to consume
4974 it to proceed further. */
4975 c_parser_error (parser
, "expected statement");
4976 c_parser_consume_token (parser
);
4979 c_parser_pragma (parser
, pragma_stmt
);
4983 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4985 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4988 /* Two cases cannot and do not have line numbers associated: If stmt
4989 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4990 cannot hold line numbers. But that's OK because the statement
4991 will either be changed to a MODIFY_EXPR during gimplification of
4992 the statement expr, or discarded. If stmt was compound, but
4993 without new variables, we will have skipped the creation of a
4994 BIND and will have a bare STATEMENT_LIST. But that's OK because
4995 (recursively) all of the component statements should already have
4996 line numbers assigned. ??? Can we discard no-op statements
4998 if (CAN_HAVE_LOCATION_P (stmt
)
4999 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5000 SET_EXPR_LOCATION (stmt
, loc
);
5002 parser
->in_if_block
= in_if_block
;
5005 /* Parse the condition from an if, do, while or for statements. */
5008 c_parser_condition (c_parser
*parser
)
5010 location_t loc
= c_parser_peek_token (parser
)->location
;
5012 cond
= c_parser_expression_conv (parser
).value
;
5013 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5014 cond
= c_fully_fold (cond
, false, NULL
);
5015 if (warn_sequence_point
)
5016 verify_sequence_points (cond
);
5020 /* Parse a parenthesized condition from an if, do or while statement.
5026 c_parser_paren_condition (c_parser
*parser
)
5029 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5030 return error_mark_node
;
5031 cond
= c_parser_condition (parser
);
5032 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5036 /* Parse a statement which is a block in C99. */
5039 c_parser_c99_block_statement (c_parser
*parser
)
5041 tree block
= c_begin_compound_stmt (flag_isoc99
);
5042 location_t loc
= c_parser_peek_token (parser
)->location
;
5043 c_parser_statement (parser
);
5044 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5047 /* Parse the body of an if statement. This is just parsing a
5048 statement but (a) it is a block in C99, (b) we track whether the
5049 body is an if statement for the sake of -Wparentheses warnings, (c)
5050 we handle an empty body specially for the sake of -Wempty-body
5051 warnings, and (d) we call parser_compound_statement directly
5052 because c_parser_statement_after_labels resets
5053 parser->in_if_block. */
5056 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5058 tree block
= c_begin_compound_stmt (flag_isoc99
);
5059 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5060 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5061 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5062 || (c_parser_next_token_is (parser
, CPP_NAME
)
5063 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5064 c_parser_label (parser
);
5065 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5066 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5068 location_t loc
= c_parser_peek_token (parser
)->location
;
5069 add_stmt (build_empty_stmt (loc
));
5070 c_parser_consume_token (parser
);
5071 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5072 warning_at (loc
, OPT_Wempty_body
,
5073 "suggest braces around empty body in an %<if%> statement");
5075 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5076 add_stmt (c_parser_compound_statement (parser
));
5078 c_parser_statement_after_labels (parser
);
5079 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5082 /* Parse the else body of an if statement. This is just parsing a
5083 statement but (a) it is a block in C99, (b) we handle an empty body
5084 specially for the sake of -Wempty-body warnings. */
5087 c_parser_else_body (c_parser
*parser
)
5089 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5090 tree block
= c_begin_compound_stmt (flag_isoc99
);
5091 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5092 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5093 || (c_parser_next_token_is (parser
, CPP_NAME
)
5094 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5095 c_parser_label (parser
);
5096 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5098 location_t loc
= c_parser_peek_token (parser
)->location
;
5101 "suggest braces around empty body in an %<else%> statement");
5102 add_stmt (build_empty_stmt (loc
));
5103 c_parser_consume_token (parser
);
5106 c_parser_statement_after_labels (parser
);
5107 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5110 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5113 if ( expression ) statement
5114 if ( expression ) statement else statement
5118 c_parser_if_statement (c_parser
*parser
)
5123 bool first_if
= false;
5124 tree first_body
, second_body
;
5128 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5129 c_parser_consume_token (parser
);
5130 block
= c_begin_compound_stmt (flag_isoc99
);
5131 loc
= c_parser_peek_token (parser
)->location
;
5132 cond
= c_parser_paren_condition (parser
);
5133 in_if_block
= parser
->in_if_block
;
5134 parser
->in_if_block
= true;
5135 first_body
= c_parser_if_body (parser
, &first_if
);
5136 parser
->in_if_block
= in_if_block
;
5137 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5139 c_parser_consume_token (parser
);
5140 second_body
= c_parser_else_body (parser
);
5143 second_body
= NULL_TREE
;
5144 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5145 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5147 /* If the if statement contains array notations, then we expand them. */
5148 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5149 if_stmt
= fix_conditional_array_notations (if_stmt
);
5153 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5156 switch (expression) statement
5160 c_parser_switch_statement (c_parser
*parser
)
5163 tree block
, expr
, body
, save_break
;
5164 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5165 location_t switch_cond_loc
;
5166 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5167 c_parser_consume_token (parser
);
5168 block
= c_begin_compound_stmt (flag_isoc99
);
5169 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5171 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5172 ce
= c_parser_expression (parser
);
5173 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5175 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5177 error_at (switch_cond_loc
,
5178 "array notations cannot be used as a condition for switch "
5180 expr
= error_mark_node
;
5182 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5186 switch_cond_loc
= UNKNOWN_LOCATION
;
5187 expr
= error_mark_node
;
5189 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5190 save_break
= c_break_label
;
5191 c_break_label
= NULL_TREE
;
5192 body
= c_parser_c99_block_statement (parser
);
5193 c_finish_case (body
);
5196 location_t here
= c_parser_peek_token (parser
)->location
;
5197 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5198 SET_EXPR_LOCATION (t
, here
);
5201 c_break_label
= save_break
;
5202 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5205 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5208 while (expression) statement
5212 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5214 tree block
, cond
, body
, save_break
, save_cont
;
5216 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5217 c_parser_consume_token (parser
);
5218 block
= c_begin_compound_stmt (flag_isoc99
);
5219 loc
= c_parser_peek_token (parser
)->location
;
5220 cond
= c_parser_paren_condition (parser
);
5221 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5223 error_at (loc
, "array notations cannot be used as a condition for while "
5225 cond
= error_mark_node
;
5228 if (ivdep
&& cond
!= error_mark_node
)
5229 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5230 build_int_cst (integer_type_node
,
5231 annot_expr_ivdep_kind
));
5232 save_break
= c_break_label
;
5233 c_break_label
= NULL_TREE
;
5234 save_cont
= c_cont_label
;
5235 c_cont_label
= NULL_TREE
;
5236 body
= c_parser_c99_block_statement (parser
);
5237 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5238 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5239 c_break_label
= save_break
;
5240 c_cont_label
= save_cont
;
5243 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5246 do statement while ( expression ) ;
5250 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5252 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5254 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5255 c_parser_consume_token (parser
);
5256 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5257 warning_at (c_parser_peek_token (parser
)->location
,
5259 "suggest braces around empty body in %<do%> statement");
5260 block
= c_begin_compound_stmt (flag_isoc99
);
5261 loc
= c_parser_peek_token (parser
)->location
;
5262 save_break
= c_break_label
;
5263 c_break_label
= NULL_TREE
;
5264 save_cont
= c_cont_label
;
5265 c_cont_label
= NULL_TREE
;
5266 body
= c_parser_c99_block_statement (parser
);
5267 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5268 new_break
= c_break_label
;
5269 c_break_label
= save_break
;
5270 new_cont
= c_cont_label
;
5271 c_cont_label
= save_cont
;
5272 cond
= c_parser_paren_condition (parser
);
5273 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5275 error_at (loc
, "array notations cannot be used as a condition for a "
5276 "do-while statement");
5277 cond
= error_mark_node
;
5279 if (ivdep
&& cond
!= error_mark_node
)
5280 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5281 build_int_cst (integer_type_node
,
5282 annot_expr_ivdep_kind
));
5283 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5284 c_parser_skip_to_end_of_block_or_statement (parser
);
5285 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5286 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5289 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5292 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5293 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5295 The form with a declaration is new in C99.
5297 ??? In accordance with the old parser, the declaration may be a
5298 nested function, which is then rejected in check_for_loop_decls,
5299 but does it make any sense for this to be included in the grammar?
5300 Note in particular that the nested function does not include a
5301 trailing ';', whereas the "declaration" production includes one.
5302 Also, can we reject bad declarations earlier and cheaper than
5303 check_for_loop_decls?
5305 In Objective-C, there are two additional variants:
5308 for ( expression in expresssion ) statement
5309 for ( declaration in expression ) statement
5311 This is inconsistent with C, because the second variant is allowed
5312 even if c99 is not enabled.
5314 The rest of the comment documents these Objective-C foreach-statement.
5316 Here is the canonical example of the first variant:
5317 for (object in array) { do something with object }
5318 we call the first expression ("object") the "object_expression" and
5319 the second expression ("array") the "collection_expression".
5320 object_expression must be an lvalue of type "id" (a generic Objective-C
5321 object) because the loop works by assigning to object_expression the
5322 various objects from the collection_expression. collection_expression
5323 must evaluate to something of type "id" which responds to the method
5324 countByEnumeratingWithState:objects:count:.
5326 The canonical example of the second variant is:
5327 for (id object in array) { do something with object }
5328 which is completely equivalent to
5331 for (object in array) { do something with object }
5333 Note that initizializing 'object' in some way (eg, "for ((object =
5334 xxx) in array) { do something with object }") is possibly
5335 technically valid, but completely pointless as 'object' will be
5336 assigned to something else as soon as the loop starts. We should
5337 most likely reject it (TODO).
5339 The beginning of the Objective-C foreach-statement looks exactly
5340 like the beginning of the for-statement, and we can tell it is a
5341 foreach-statement only because the initial declaration or
5342 expression is terminated by 'in' instead of ';'.
5346 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5348 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5349 /* The following are only used when parsing an ObjC foreach statement. */
5350 tree object_expression
;
5351 /* Silence the bogus uninitialized warning. */
5352 tree collection_expression
= NULL
;
5353 location_t loc
= c_parser_peek_token (parser
)->location
;
5354 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5355 bool is_foreach_statement
= false;
5356 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5357 c_parser_consume_token (parser
);
5358 /* Open a compound statement in Objective-C as well, just in case this is
5359 as foreach expression. */
5360 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5361 cond
= error_mark_node
;
5362 incr
= error_mark_node
;
5363 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5365 /* Parse the initialization declaration or expression. */
5366 object_expression
= error_mark_node
;
5367 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5368 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5370 parser
->objc_could_be_foreach_context
= false;
5371 c_parser_consume_token (parser
);
5372 c_finish_expr_stmt (loc
, NULL_TREE
);
5374 else if (c_parser_next_tokens_start_declaration (parser
))
5376 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5377 &object_expression
, vNULL
);
5378 parser
->objc_could_be_foreach_context
= false;
5380 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5382 c_parser_consume_token (parser
);
5383 is_foreach_statement
= true;
5384 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5385 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5388 check_for_loop_decls (for_loc
, flag_isoc99
);
5390 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5392 /* __extension__ can start a declaration, but is also an
5393 unary operator that can start an expression. Consume all
5394 but the last of a possible series of __extension__ to
5396 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5397 && (c_parser_peek_2nd_token (parser
)->keyword
5399 c_parser_consume_token (parser
);
5400 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5403 ext
= disable_extension_diagnostics ();
5404 c_parser_consume_token (parser
);
5405 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5406 true, &object_expression
, vNULL
);
5407 parser
->objc_could_be_foreach_context
= false;
5409 restore_extension_diagnostics (ext
);
5410 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5412 c_parser_consume_token (parser
);
5413 is_foreach_statement
= true;
5414 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5415 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5418 check_for_loop_decls (for_loc
, flag_isoc99
);
5428 tree init_expression
;
5429 ce
= c_parser_expression (parser
);
5430 init_expression
= ce
.value
;
5431 parser
->objc_could_be_foreach_context
= false;
5432 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5434 c_parser_consume_token (parser
);
5435 is_foreach_statement
= true;
5436 if (! lvalue_p (init_expression
))
5437 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5438 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5442 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5443 init_expression
= ce
.value
;
5444 c_finish_expr_stmt (loc
, init_expression
);
5445 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5449 /* Parse the loop condition. In the case of a foreach
5450 statement, there is no loop condition. */
5451 gcc_assert (!parser
->objc_could_be_foreach_context
);
5452 if (!is_foreach_statement
)
5454 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5458 c_parser_error (parser
, "missing loop condition in loop with "
5459 "%<GCC ivdep%> pragma");
5460 cond
= error_mark_node
;
5464 c_parser_consume_token (parser
);
5470 cond
= c_parser_condition (parser
);
5471 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5473 error_at (loc
, "array notations cannot be used in a "
5474 "condition for a for-loop");
5475 cond
= error_mark_node
;
5477 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5480 if (ivdep
&& cond
!= error_mark_node
)
5481 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5482 build_int_cst (integer_type_node
,
5483 annot_expr_ivdep_kind
));
5485 /* Parse the increment expression (the third expression in a
5486 for-statement). In the case of a foreach-statement, this is
5487 the expression that follows the 'in'. */
5488 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5490 if (is_foreach_statement
)
5492 c_parser_error (parser
, "missing collection in fast enumeration");
5493 collection_expression
= error_mark_node
;
5496 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5500 if (is_foreach_statement
)
5501 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5505 struct c_expr ce
= c_parser_expression (parser
);
5506 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5507 incr
= c_process_expr_stmt (loc
, ce
.value
);
5510 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5512 save_break
= c_break_label
;
5513 c_break_label
= NULL_TREE
;
5514 save_cont
= c_cont_label
;
5515 c_cont_label
= NULL_TREE
;
5516 body
= c_parser_c99_block_statement (parser
);
5517 if (is_foreach_statement
)
5518 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5520 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5521 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5522 c_break_label
= save_break
;
5523 c_cont_label
= save_cont
;
5526 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5527 statement with inputs, outputs, clobbers, and volatile tag
5531 asm type-qualifier[opt] ( asm-argument ) ;
5532 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5536 asm-string-literal : asm-operands[opt]
5537 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5538 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5541 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5544 Qualifiers other than volatile are accepted in the syntax but
5548 c_parser_asm_statement (c_parser
*parser
)
5550 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5551 bool simple
, is_goto
;
5552 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5553 int section
, nsections
;
5555 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5556 c_parser_consume_token (parser
);
5557 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5559 quals
= c_parser_peek_token (parser
)->value
;
5560 c_parser_consume_token (parser
);
5562 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5563 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5565 warning_at (c_parser_peek_token (parser
)->location
,
5567 "%E qualifier ignored on asm",
5568 c_parser_peek_token (parser
)->value
);
5570 c_parser_consume_token (parser
);
5576 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5578 c_parser_consume_token (parser
);
5582 /* ??? Follow the C++ parser rather than using the
5583 lex_untranslated_string kludge. */
5584 parser
->lex_untranslated_string
= true;
5587 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5590 str
= c_parser_asm_string_literal (parser
);
5591 if (str
== NULL_TREE
)
5592 goto error_close_paren
;
5595 outputs
= NULL_TREE
;
5597 clobbers
= NULL_TREE
;
5600 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5603 /* Parse each colon-delimited section of operands. */
5604 nsections
= 3 + is_goto
;
5605 for (section
= 0; section
< nsections
; ++section
)
5607 if (!c_parser_require (parser
, CPP_COLON
,
5610 : "expected %<:%> or %<)%>"))
5611 goto error_close_paren
;
5613 /* Once past any colon, we're no longer a simple asm. */
5616 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5617 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5622 /* For asm goto, we don't allow output operands, but reserve
5623 the slot for a future extension that does allow them. */
5625 outputs
= c_parser_asm_operands (parser
);
5628 inputs
= c_parser_asm_operands (parser
);
5631 clobbers
= c_parser_asm_clobbers (parser
);
5634 labels
= c_parser_asm_goto_operands (parser
);
5640 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5645 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5647 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5651 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5652 c_parser_skip_to_end_of_block_or_statement (parser
);
5654 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5655 clobbers
, labels
, simple
));
5658 parser
->lex_untranslated_string
= false;
5662 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5666 /* Parse asm operands, a GNU extension.
5670 asm-operands , asm-operand
5673 asm-string-literal ( expression )
5674 [ identifier ] asm-string-literal ( expression )
5678 c_parser_asm_operands (c_parser
*parser
)
5680 tree list
= NULL_TREE
;
5685 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5687 c_parser_consume_token (parser
);
5688 if (c_parser_next_token_is (parser
, CPP_NAME
))
5690 tree id
= c_parser_peek_token (parser
)->value
;
5691 c_parser_consume_token (parser
);
5692 name
= build_string (IDENTIFIER_LENGTH (id
),
5693 IDENTIFIER_POINTER (id
));
5697 c_parser_error (parser
, "expected identifier");
5698 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5701 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5706 str
= c_parser_asm_string_literal (parser
);
5707 if (str
== NULL_TREE
)
5709 parser
->lex_untranslated_string
= false;
5710 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5712 parser
->lex_untranslated_string
= true;
5715 expr
= c_parser_expression (parser
);
5716 mark_exp_read (expr
.value
);
5717 parser
->lex_untranslated_string
= true;
5718 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5720 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5723 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5725 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5726 c_parser_consume_token (parser
);
5733 /* Parse asm clobbers, a GNU extension.
5737 asm-clobbers , asm-string-literal
5741 c_parser_asm_clobbers (c_parser
*parser
)
5743 tree list
= NULL_TREE
;
5746 tree str
= c_parser_asm_string_literal (parser
);
5748 list
= tree_cons (NULL_TREE
, str
, list
);
5751 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5752 c_parser_consume_token (parser
);
5759 /* Parse asm goto labels, a GNU extension.
5763 asm-goto-operands , identifier
5767 c_parser_asm_goto_operands (c_parser
*parser
)
5769 tree list
= NULL_TREE
;
5774 if (c_parser_next_token_is (parser
, CPP_NAME
))
5776 c_token
*tok
= c_parser_peek_token (parser
);
5778 label
= lookup_label_for_goto (tok
->location
, name
);
5779 c_parser_consume_token (parser
);
5780 TREE_USED (label
) = 1;
5784 c_parser_error (parser
, "expected identifier");
5788 name
= build_string (IDENTIFIER_LENGTH (name
),
5789 IDENTIFIER_POINTER (name
));
5790 list
= tree_cons (name
, label
, list
);
5791 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5792 c_parser_consume_token (parser
);
5794 return nreverse (list
);
5798 /* Parse an expression other than a compound expression; that is, an
5799 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5800 NULL then it is an Objective-C message expression which is the
5801 primary-expression starting the expression as an initializer.
5803 assignment-expression:
5804 conditional-expression
5805 unary-expression assignment-operator assignment-expression
5807 assignment-operator: one of
5808 = *= /= %= += -= <<= >>= &= ^= |=
5810 In GNU C we accept any conditional expression on the LHS and
5811 diagnose the invalid lvalue rather than producing a syntax
5814 static struct c_expr
5815 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5816 tree omp_atomic_lhs
)
5818 struct c_expr lhs
, rhs
, ret
;
5819 enum tree_code code
;
5820 location_t op_location
, exp_location
;
5821 gcc_assert (!after
|| c_dialect_objc ());
5822 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5823 op_location
= c_parser_peek_token (parser
)->location
;
5824 switch (c_parser_peek_token (parser
)->type
)
5833 code
= TRUNC_DIV_EXPR
;
5836 code
= TRUNC_MOD_EXPR
;
5851 code
= BIT_AND_EXPR
;
5854 code
= BIT_XOR_EXPR
;
5857 code
= BIT_IOR_EXPR
;
5862 c_parser_consume_token (parser
);
5863 exp_location
= c_parser_peek_token (parser
)->location
;
5864 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5865 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5867 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5868 code
, exp_location
, rhs
.value
,
5870 if (code
== NOP_EXPR
)
5871 ret
.original_code
= MODIFY_EXPR
;
5874 TREE_NO_WARNING (ret
.value
) = 1;
5875 ret
.original_code
= ERROR_MARK
;
5877 ret
.original_type
= NULL
;
5881 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5882 is not NULL then it is an Objective-C message expression which is
5883 the primary-expression starting the expression as an initializer.
5885 conditional-expression:
5886 logical-OR-expression
5887 logical-OR-expression ? expression : conditional-expression
5891 conditional-expression:
5892 logical-OR-expression ? : conditional-expression
5895 static struct c_expr
5896 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5897 tree omp_atomic_lhs
)
5899 struct c_expr cond
, exp1
, exp2
, ret
;
5900 location_t cond_loc
, colon_loc
, middle_loc
;
5902 gcc_assert (!after
|| c_dialect_objc ());
5904 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5906 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5908 cond_loc
= c_parser_peek_token (parser
)->location
;
5909 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5910 c_parser_consume_token (parser
);
5911 if (c_parser_next_token_is (parser
, CPP_COLON
))
5913 tree eptype
= NULL_TREE
;
5915 middle_loc
= c_parser_peek_token (parser
)->location
;
5916 pedwarn (middle_loc
, OPT_Wpedantic
,
5917 "ISO C forbids omitting the middle term of a ?: expression");
5918 warn_for_omitted_condop (middle_loc
, cond
.value
);
5919 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5921 eptype
= TREE_TYPE (cond
.value
);
5922 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5924 /* Make sure first operand is calculated only once. */
5925 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5927 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5928 exp1
.original_type
= NULL
;
5929 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5930 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5935 = c_objc_common_truthvalue_conversion
5936 (cond_loc
, default_conversion (cond
.value
));
5937 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5938 exp1
= c_parser_expression_conv (parser
);
5939 mark_exp_read (exp1
.value
);
5940 c_inhibit_evaluation_warnings
+=
5941 ((cond
.value
== truthvalue_true_node
)
5942 - (cond
.value
== truthvalue_false_node
));
5945 colon_loc
= c_parser_peek_token (parser
)->location
;
5946 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5948 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5949 ret
.value
= error_mark_node
;
5950 ret
.original_code
= ERROR_MARK
;
5951 ret
.original_type
= NULL
;
5955 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5956 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5957 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5959 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5960 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5961 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5962 exp1
.value
, exp1
.original_type
,
5963 exp2
.value
, exp2
.original_type
);
5964 ret
.original_code
= ERROR_MARK
;
5965 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5966 ret
.original_type
= NULL
;
5971 /* If both sides are enum type, the default conversion will have
5972 made the type of the result be an integer type. We want to
5973 remember the enum types we started with. */
5974 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5975 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5976 ret
.original_type
= ((t1
!= error_mark_node
5977 && t2
!= error_mark_node
5978 && (TYPE_MAIN_VARIANT (t1
)
5979 == TYPE_MAIN_VARIANT (t2
)))
5986 /* Parse a binary expression; that is, a logical-OR-expression (C90
5987 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5988 an Objective-C message expression which is the primary-expression
5989 starting the expression as an initializer.
5991 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5992 when it should be the unfolded lhs. In a valid OpenMP source,
5993 one of the operands of the toplevel binary expression must be equal
5994 to it. In that case, just return a build2 created binary operation
5995 rather than result of parser_build_binary_op.
5997 multiplicative-expression:
5999 multiplicative-expression * cast-expression
6000 multiplicative-expression / cast-expression
6001 multiplicative-expression % cast-expression
6003 additive-expression:
6004 multiplicative-expression
6005 additive-expression + multiplicative-expression
6006 additive-expression - multiplicative-expression
6010 shift-expression << additive-expression
6011 shift-expression >> additive-expression
6013 relational-expression:
6015 relational-expression < shift-expression
6016 relational-expression > shift-expression
6017 relational-expression <= shift-expression
6018 relational-expression >= shift-expression
6020 equality-expression:
6021 relational-expression
6022 equality-expression == relational-expression
6023 equality-expression != relational-expression
6027 AND-expression & equality-expression
6029 exclusive-OR-expression:
6031 exclusive-OR-expression ^ AND-expression
6033 inclusive-OR-expression:
6034 exclusive-OR-expression
6035 inclusive-OR-expression | exclusive-OR-expression
6037 logical-AND-expression:
6038 inclusive-OR-expression
6039 logical-AND-expression && inclusive-OR-expression
6041 logical-OR-expression:
6042 logical-AND-expression
6043 logical-OR-expression || logical-AND-expression
6046 static struct c_expr
6047 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6048 tree omp_atomic_lhs
)
6050 /* A binary expression is parsed using operator-precedence parsing,
6051 with the operands being cast expressions. All the binary
6052 operators are left-associative. Thus a binary expression is of
6055 E0 op1 E1 op2 E2 ...
6057 which we represent on a stack. On the stack, the precedence
6058 levels are strictly increasing. When a new operator is
6059 encountered of higher precedence than that at the top of the
6060 stack, it is pushed; its LHS is the top expression, and its RHS
6061 is everything parsed until it is popped. When a new operator is
6062 encountered with precedence less than or equal to that at the top
6063 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6064 by the result of the operation until the operator at the top of
6065 the stack has lower precedence than the new operator or there is
6066 only one element on the stack; then the top expression is the LHS
6067 of the new operator. In the case of logical AND and OR
6068 expressions, we also need to adjust c_inhibit_evaluation_warnings
6069 as appropriate when the operators are pushed and popped. */
6072 /* The expression at this stack level. */
6074 /* The precedence of the operator on its left, PREC_NONE at the
6075 bottom of the stack. */
6076 enum c_parser_prec prec
;
6077 /* The operation on its left. */
6079 /* The source location of this operation. */
6083 /* Location of the binary operator. */
6084 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6087 switch (stack[sp].op) \
6089 case TRUTH_ANDIF_EXPR: \
6090 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6091 == truthvalue_false_node); \
6093 case TRUTH_ORIF_EXPR: \
6094 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6095 == truthvalue_true_node); \
6100 stack[sp - 1].expr \
6101 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6102 stack[sp - 1].expr, true, true); \
6104 = convert_lvalue_to_rvalue (stack[sp].loc, \
6105 stack[sp].expr, true, true); \
6106 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6107 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6108 && ((1 << stack[sp].prec) \
6109 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6110 | PREC_ADD | PREC_MULT))) \
6111 && stack[sp].op != TRUNC_MOD_EXPR \
6112 && stack[0].expr.value != error_mark_node \
6113 && stack[1].expr.value != error_mark_node \
6114 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6115 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6116 stack[0].expr.value \
6117 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6118 stack[0].expr.value, stack[1].expr.value); \
6120 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6122 stack[sp - 1].expr, \
6126 gcc_assert (!after
|| c_dialect_objc ());
6127 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6128 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6129 stack
[0].prec
= PREC_NONE
;
6133 enum c_parser_prec oprec
;
6134 enum tree_code ocode
;
6137 switch (c_parser_peek_token (parser
)->type
)
6145 ocode
= TRUNC_DIV_EXPR
;
6149 ocode
= TRUNC_MOD_EXPR
;
6161 ocode
= LSHIFT_EXPR
;
6165 ocode
= RSHIFT_EXPR
;
6179 case CPP_GREATER_EQ
:
6192 oprec
= PREC_BITAND
;
6193 ocode
= BIT_AND_EXPR
;
6196 oprec
= PREC_BITXOR
;
6197 ocode
= BIT_XOR_EXPR
;
6201 ocode
= BIT_IOR_EXPR
;
6204 oprec
= PREC_LOGAND
;
6205 ocode
= TRUTH_ANDIF_EXPR
;
6209 ocode
= TRUTH_ORIF_EXPR
;
6212 /* Not a binary operator, so end of the binary
6216 binary_loc
= c_parser_peek_token (parser
)->location
;
6217 while (oprec
<= stack
[sp
].prec
)
6219 c_parser_consume_token (parser
);
6222 case TRUTH_ANDIF_EXPR
:
6224 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6225 stack
[sp
].expr
, true, true);
6226 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6227 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6228 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6229 == truthvalue_false_node
);
6231 case TRUTH_ORIF_EXPR
:
6233 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6234 stack
[sp
].expr
, true, true);
6235 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6236 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6237 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6238 == truthvalue_true_node
);
6244 stack
[sp
].loc
= binary_loc
;
6245 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6246 stack
[sp
].prec
= oprec
;
6247 stack
[sp
].op
= ocode
;
6248 stack
[sp
].loc
= binary_loc
;
6253 return stack
[0].expr
;
6257 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6258 NULL then it is an Objective-C message expression which is the
6259 primary-expression starting the expression as an initializer.
6263 ( type-name ) unary-expression
6266 static struct c_expr
6267 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6269 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6270 gcc_assert (!after
|| c_dialect_objc ());
6272 return c_parser_postfix_expression_after_primary (parser
,
6274 /* If the expression begins with a parenthesized type name, it may
6275 be either a cast or a compound literal; we need to see whether
6276 the next character is '{' to tell the difference. If not, it is
6277 an unary expression. Full detection of unknown typenames here
6278 would require a 3-token lookahead. */
6279 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6280 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6282 struct c_type_name
*type_name
;
6285 c_parser_consume_token (parser
);
6286 type_name
= c_parser_type_name (parser
);
6287 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6288 if (type_name
== NULL
)
6290 ret
.value
= error_mark_node
;
6291 ret
.original_code
= ERROR_MARK
;
6292 ret
.original_type
= NULL
;
6296 /* Save casted types in the function's used types hash table. */
6297 used_types_insert (type_name
->specs
->type
);
6299 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6300 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6303 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6304 expr
= c_parser_cast_expression (parser
, NULL
);
6305 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6307 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6308 ret
.original_code
= ERROR_MARK
;
6309 ret
.original_type
= NULL
;
6313 return c_parser_unary_expression (parser
);
6316 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6322 unary-operator cast-expression
6323 sizeof unary-expression
6324 sizeof ( type-name )
6326 unary-operator: one of
6332 __alignof__ unary-expression
6333 __alignof__ ( type-name )
6336 (C11 permits _Alignof with type names only.)
6338 unary-operator: one of
6339 __extension__ __real__ __imag__
6341 Transactional Memory:
6344 transaction-expression
6346 In addition, the GNU syntax treats ++ and -- as unary operators, so
6347 they may be applied to cast expressions with errors for non-lvalues
6350 static struct c_expr
6351 c_parser_unary_expression (c_parser
*parser
)
6354 struct c_expr ret
, op
;
6355 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6357 ret
.original_code
= ERROR_MARK
;
6358 ret
.original_type
= NULL
;
6359 switch (c_parser_peek_token (parser
)->type
)
6362 c_parser_consume_token (parser
);
6363 exp_loc
= c_parser_peek_token (parser
)->location
;
6364 op
= c_parser_cast_expression (parser
, NULL
);
6366 /* If there is array notations in op, we expand them. */
6367 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6368 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6371 op
= default_function_array_read_conversion (exp_loc
, op
);
6372 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6374 case CPP_MINUS_MINUS
:
6375 c_parser_consume_token (parser
);
6376 exp_loc
= c_parser_peek_token (parser
)->location
;
6377 op
= c_parser_cast_expression (parser
, NULL
);
6379 /* If there is array notations in op, we expand them. */
6380 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6381 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6384 op
= default_function_array_read_conversion (exp_loc
, op
);
6385 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6388 c_parser_consume_token (parser
);
6389 op
= c_parser_cast_expression (parser
, NULL
);
6390 mark_exp_read (op
.value
);
6391 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6393 c_parser_consume_token (parser
);
6394 exp_loc
= c_parser_peek_token (parser
)->location
;
6395 op
= c_parser_cast_expression (parser
, NULL
);
6396 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6397 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6400 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6403 "traditional C rejects the unary plus operator");
6404 c_parser_consume_token (parser
);
6405 exp_loc
= c_parser_peek_token (parser
)->location
;
6406 op
= c_parser_cast_expression (parser
, NULL
);
6407 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6408 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
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
, NEGATE_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
, BIT_NOT_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
, TRUTH_NOT_EXPR
, op
);
6428 /* Refer to the address of a label as a pointer. */
6429 c_parser_consume_token (parser
);
6430 if (c_parser_next_token_is (parser
, CPP_NAME
))
6432 ret
.value
= finish_label_address_expr
6433 (c_parser_peek_token (parser
)->value
, op_loc
);
6434 c_parser_consume_token (parser
);
6438 c_parser_error (parser
, "expected identifier");
6439 ret
.value
= error_mark_node
;
6443 switch (c_parser_peek_token (parser
)->keyword
)
6446 return c_parser_sizeof_expression (parser
);
6448 return c_parser_alignof_expression (parser
);
6450 c_parser_consume_token (parser
);
6451 ext
= disable_extension_diagnostics ();
6452 ret
= c_parser_cast_expression (parser
, NULL
);
6453 restore_extension_diagnostics (ext
);
6456 c_parser_consume_token (parser
);
6457 exp_loc
= c_parser_peek_token (parser
)->location
;
6458 op
= c_parser_cast_expression (parser
, NULL
);
6459 op
= default_function_array_conversion (exp_loc
, op
);
6460 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
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
, IMAGPART_EXPR
, op
);
6467 case RID_TRANSACTION_ATOMIC
:
6468 case RID_TRANSACTION_RELAXED
:
6469 return c_parser_transaction_expression (parser
,
6470 c_parser_peek_token (parser
)->keyword
);
6472 return c_parser_postfix_expression (parser
);
6475 return c_parser_postfix_expression (parser
);
6479 /* Parse a sizeof expression. */
6481 static struct c_expr
6482 c_parser_sizeof_expression (c_parser
*parser
)
6485 location_t expr_loc
;
6486 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6487 c_parser_consume_token (parser
);
6488 c_inhibit_evaluation_warnings
++;
6490 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6491 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6493 /* Either sizeof ( type-name ) or sizeof unary-expression
6494 starting with a compound literal. */
6495 struct c_type_name
*type_name
;
6496 c_parser_consume_token (parser
);
6497 expr_loc
= c_parser_peek_token (parser
)->location
;
6498 type_name
= c_parser_type_name (parser
);
6499 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6500 if (type_name
== NULL
)
6503 c_inhibit_evaluation_warnings
--;
6505 ret
.value
= error_mark_node
;
6506 ret
.original_code
= ERROR_MARK
;
6507 ret
.original_type
= NULL
;
6510 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6512 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6517 /* sizeof ( type-name ). */
6518 c_inhibit_evaluation_warnings
--;
6520 return c_expr_sizeof_type (expr_loc
, type_name
);
6524 expr_loc
= c_parser_peek_token (parser
)->location
;
6525 expr
= c_parser_unary_expression (parser
);
6527 c_inhibit_evaluation_warnings
--;
6529 mark_exp_read (expr
.value
);
6530 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6531 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6532 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6533 return c_expr_sizeof_expr (expr_loc
, expr
);
6537 /* Parse an alignof expression. */
6539 static struct c_expr
6540 c_parser_alignof_expression (c_parser
*parser
)
6543 location_t loc
= c_parser_peek_token (parser
)->location
;
6544 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6545 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6546 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6548 /* A diagnostic is not required for the use of this identifier in
6549 the implementation namespace; only diagnose it for the C11
6550 spelling because of existing code using the other spellings. */
6551 if (!flag_isoc11
&& is_c11_alignof
)
6554 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6557 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6560 c_parser_consume_token (parser
);
6561 c_inhibit_evaluation_warnings
++;
6563 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6564 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6566 /* Either __alignof__ ( type-name ) or __alignof__
6567 unary-expression starting with a compound literal. */
6569 struct c_type_name
*type_name
;
6571 c_parser_consume_token (parser
);
6572 loc
= c_parser_peek_token (parser
)->location
;
6573 type_name
= c_parser_type_name (parser
);
6574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6575 if (type_name
== NULL
)
6578 c_inhibit_evaluation_warnings
--;
6580 ret
.value
= error_mark_node
;
6581 ret
.original_code
= ERROR_MARK
;
6582 ret
.original_type
= NULL
;
6585 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6587 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6592 /* alignof ( type-name ). */
6593 c_inhibit_evaluation_warnings
--;
6595 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6597 false, is_c11_alignof
, 1);
6598 ret
.original_code
= ERROR_MARK
;
6599 ret
.original_type
= NULL
;
6605 expr
= c_parser_unary_expression (parser
);
6607 mark_exp_read (expr
.value
);
6608 c_inhibit_evaluation_warnings
--;
6610 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6612 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6613 ret
.original_code
= ERROR_MARK
;
6614 ret
.original_type
= NULL
;
6619 /* Helper function to read arguments of builtins which are interfaces
6620 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6621 others. The name of the builtin is passed using BNAME parameter.
6622 Function returns true if there were no errors while parsing and
6623 stores the arguments in CEXPR_LIST. */
6625 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6626 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6629 location_t loc
= c_parser_peek_token (parser
)->location
;
6630 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6632 bool saved_force_folding_builtin_constant_p
;
6634 *ret_cexpr_list
= NULL
;
6635 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6637 error_at (loc
, "cannot take address of %qs", bname
);
6641 c_parser_consume_token (parser
);
6643 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6645 c_parser_consume_token (parser
);
6649 saved_force_folding_builtin_constant_p
6650 = force_folding_builtin_constant_p
;
6651 force_folding_builtin_constant_p
|= choose_expr_p
;
6652 expr
= c_parser_expr_no_commas (parser
, NULL
);
6653 force_folding_builtin_constant_p
6654 = saved_force_folding_builtin_constant_p
;
6655 vec_alloc (cexpr_list
, 1);
6656 vec_safe_push (cexpr_list
, expr
);
6657 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6659 c_parser_consume_token (parser
);
6660 expr
= c_parser_expr_no_commas (parser
, NULL
);
6661 vec_safe_push (cexpr_list
, expr
);
6664 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6667 *ret_cexpr_list
= cexpr_list
;
6671 /* This represents a single generic-association. */
6673 struct c_generic_association
6675 /* The location of the starting token of the type. */
6676 location_t type_location
;
6677 /* The association's type, or NULL_TREE for 'default'. */
6679 /* The association's expression. */
6680 struct c_expr expression
;
6683 /* Parse a generic-selection. (C11 6.5.1.1).
6686 _Generic ( assignment-expression , generic-assoc-list )
6690 generic-assoc-list , generic-association
6692 generic-association:
6693 type-name : assignment-expression
6694 default : assignment-expression
6697 static struct c_expr
6698 c_parser_generic_selection (c_parser
*parser
)
6700 vec
<c_generic_association
> associations
= vNULL
;
6701 struct c_expr selector
, error_expr
;
6703 struct c_generic_association matched_assoc
;
6704 bool match_found
= false;
6705 location_t generic_loc
, selector_loc
;
6707 error_expr
.original_code
= ERROR_MARK
;
6708 error_expr
.original_type
= NULL
;
6709 error_expr
.value
= error_mark_node
;
6710 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6711 matched_assoc
.type
= NULL_TREE
;
6712 matched_assoc
.expression
= error_expr
;
6714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6715 generic_loc
= c_parser_peek_token (parser
)->location
;
6716 c_parser_consume_token (parser
);
6720 pedwarn (generic_loc
, OPT_Wpedantic
,
6721 "ISO C99 does not support %<_Generic%>");
6723 pedwarn (generic_loc
, OPT_Wpedantic
,
6724 "ISO C90 does not support %<_Generic%>");
6727 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6730 c_inhibit_evaluation_warnings
++;
6731 selector_loc
= c_parser_peek_token (parser
)->location
;
6732 selector
= c_parser_expr_no_commas (parser
, NULL
);
6733 selector
= default_function_array_conversion (selector_loc
, selector
);
6734 c_inhibit_evaluation_warnings
--;
6736 if (selector
.value
== error_mark_node
)
6738 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6741 selector_type
= TREE_TYPE (selector
.value
);
6742 /* In ISO C terms, rvalues (including the controlling expression of
6743 _Generic) do not have qualified types. */
6744 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6745 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6746 /* In ISO C terms, _Noreturn is not part of the type of expressions
6747 such as &abort, but in GCC it is represented internally as a type
6749 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6750 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6752 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6754 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6756 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6762 struct c_generic_association assoc
, *iter
;
6764 c_token
*token
= c_parser_peek_token (parser
);
6766 assoc
.type_location
= token
->location
;
6767 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6769 c_parser_consume_token (parser
);
6770 assoc
.type
= NULL_TREE
;
6774 struct c_type_name
*type_name
;
6776 type_name
= c_parser_type_name (parser
);
6777 if (type_name
== NULL
)
6779 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6782 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6783 if (assoc
.type
== error_mark_node
)
6785 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6789 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6790 error_at (assoc
.type_location
,
6791 "%<_Generic%> association has function type");
6792 else if (!COMPLETE_TYPE_P (assoc
.type
))
6793 error_at (assoc
.type_location
,
6794 "%<_Generic%> association has incomplete type");
6796 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6797 error_at (assoc
.type_location
,
6798 "%<_Generic%> association has "
6799 "variable length type");
6802 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6804 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6808 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6809 if (assoc
.expression
.value
== error_mark_node
)
6811 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6815 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6817 if (assoc
.type
== NULL_TREE
)
6819 if (iter
->type
== NULL_TREE
)
6821 error_at (assoc
.type_location
,
6822 "duplicate %<default%> case in %<_Generic%>");
6823 inform (iter
->type_location
, "original %<default%> is here");
6826 else if (iter
->type
!= NULL_TREE
)
6828 if (comptypes (assoc
.type
, iter
->type
))
6830 error_at (assoc
.type_location
,
6831 "%<_Generic%> specifies two compatible types");
6832 inform (iter
->type_location
, "compatible type is here");
6837 if (assoc
.type
== NULL_TREE
)
6841 matched_assoc
= assoc
;
6845 else if (comptypes (assoc
.type
, selector_type
))
6847 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6849 matched_assoc
= assoc
;
6854 error_at (assoc
.type_location
,
6855 "%<_Generic> selector matches multiple associations");
6856 inform (matched_assoc
.type_location
,
6857 "other match is here");
6861 associations
.safe_push (assoc
);
6863 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6865 c_parser_consume_token (parser
);
6868 associations
.release ();
6870 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6872 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6878 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6879 "compatible with any association",
6884 return matched_assoc
.expression
;
6887 associations
.release ();
6891 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6895 postfix-expression [ expression ]
6896 postfix-expression ( argument-expression-list[opt] )
6897 postfix-expression . identifier
6898 postfix-expression -> identifier
6899 postfix-expression ++
6900 postfix-expression --
6901 ( type-name ) { initializer-list }
6902 ( type-name ) { initializer-list , }
6904 argument-expression-list:
6906 argument-expression-list , argument-expression
6919 (treated as a keyword in GNU C)
6922 ( compound-statement )
6923 __builtin_va_arg ( assignment-expression , type-name )
6924 __builtin_offsetof ( type-name , offsetof-member-designator )
6925 __builtin_choose_expr ( assignment-expression ,
6926 assignment-expression ,
6927 assignment-expression )
6928 __builtin_types_compatible_p ( type-name , type-name )
6929 __builtin_complex ( assignment-expression , assignment-expression )
6930 __builtin_shuffle ( assignment-expression , assignment-expression )
6931 __builtin_shuffle ( assignment-expression ,
6932 assignment-expression ,
6933 assignment-expression, )
6935 offsetof-member-designator:
6937 offsetof-member-designator . identifier
6938 offsetof-member-designator [ expression ]
6943 [ objc-receiver objc-message-args ]
6944 @selector ( objc-selector-arg )
6945 @protocol ( identifier )
6946 @encode ( type-name )
6948 Classname . identifier
6951 static struct c_expr
6952 c_parser_postfix_expression (c_parser
*parser
)
6954 struct c_expr expr
, e1
;
6955 struct c_type_name
*t1
, *t2
;
6956 location_t loc
= c_parser_peek_token (parser
)->location
;;
6957 expr
.original_code
= ERROR_MARK
;
6958 expr
.original_type
= NULL
;
6959 switch (c_parser_peek_token (parser
)->type
)
6962 expr
.value
= c_parser_peek_token (parser
)->value
;
6963 loc
= c_parser_peek_token (parser
)->location
;
6964 c_parser_consume_token (parser
);
6965 if (TREE_CODE (expr
.value
) == FIXED_CST
6966 && !targetm
.fixed_point_supported_p ())
6968 error_at (loc
, "fixed-point types not supported for this target");
6969 expr
.value
= error_mark_node
;
6976 expr
.value
= c_parser_peek_token (parser
)->value
;
6977 c_parser_consume_token (parser
);
6983 case CPP_UTF8STRING
:
6984 expr
.value
= c_parser_peek_token (parser
)->value
;
6985 expr
.original_code
= STRING_CST
;
6986 c_parser_consume_token (parser
);
6988 case CPP_OBJC_STRING
:
6989 gcc_assert (c_dialect_objc ());
6991 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6992 c_parser_consume_token (parser
);
6995 switch (c_parser_peek_token (parser
)->id_kind
)
6999 tree id
= c_parser_peek_token (parser
)->value
;
7000 c_parser_consume_token (parser
);
7001 expr
.value
= build_external_ref (loc
, id
,
7002 (c_parser_peek_token (parser
)->type
7004 &expr
.original_type
);
7007 case C_ID_CLASSNAME
:
7009 /* Here we parse the Objective-C 2.0 Class.name dot
7011 tree class_name
= c_parser_peek_token (parser
)->value
;
7013 c_parser_consume_token (parser
);
7014 gcc_assert (c_dialect_objc ());
7015 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7017 expr
.value
= error_mark_node
;
7020 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7022 c_parser_error (parser
, "expected identifier");
7023 expr
.value
= error_mark_node
;
7026 component
= c_parser_peek_token (parser
)->value
;
7027 c_parser_consume_token (parser
);
7028 expr
.value
= objc_build_class_component_ref (class_name
,
7033 c_parser_error (parser
, "expected expression");
7034 expr
.value
= error_mark_node
;
7038 case CPP_OPEN_PAREN
:
7039 /* A parenthesized expression, statement expression or compound
7041 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7043 /* A statement expression. */
7045 location_t brace_loc
;
7046 c_parser_consume_token (parser
);
7047 brace_loc
= c_parser_peek_token (parser
)->location
;
7048 c_parser_consume_token (parser
);
7049 if (!building_stmt_list_p ())
7051 error_at (loc
, "braced-group within expression allowed "
7052 "only inside a function");
7053 parser
->error
= true;
7054 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7055 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7056 expr
.value
= error_mark_node
;
7059 stmt
= c_begin_stmt_expr ();
7060 c_parser_compound_statement_nostart (parser
);
7061 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7063 pedwarn (loc
, OPT_Wpedantic
,
7064 "ISO C forbids braced-groups within expressions");
7065 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7066 mark_exp_read (expr
.value
);
7068 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7070 /* A compound literal. ??? Can we actually get here rather
7071 than going directly to
7072 c_parser_postfix_expression_after_paren_type from
7075 struct c_type_name
*type_name
;
7076 c_parser_consume_token (parser
);
7077 loc
= c_parser_peek_token (parser
)->location
;
7078 type_name
= c_parser_type_name (parser
);
7079 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7081 if (type_name
== NULL
)
7083 expr
.value
= error_mark_node
;
7086 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7092 /* A parenthesized expression. */
7093 c_parser_consume_token (parser
);
7094 expr
= c_parser_expression (parser
);
7095 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7096 TREE_NO_WARNING (expr
.value
) = 1;
7097 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7098 expr
.original_code
= ERROR_MARK
;
7099 /* Don't change EXPR.ORIGINAL_TYPE. */
7100 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7105 switch (c_parser_peek_token (parser
)->keyword
)
7107 case RID_FUNCTION_NAME
:
7108 case RID_PRETTY_FUNCTION_NAME
:
7109 case RID_C99_FUNCTION_NAME
:
7110 expr
.value
= fname_decl (loc
,
7111 c_parser_peek_token (parser
)->keyword
,
7112 c_parser_peek_token (parser
)->value
);
7113 c_parser_consume_token (parser
);
7116 c_parser_consume_token (parser
);
7117 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7119 expr
.value
= error_mark_node
;
7122 e1
= c_parser_expr_no_commas (parser
, NULL
);
7123 mark_exp_read (e1
.value
);
7124 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7125 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7128 expr
.value
= error_mark_node
;
7131 loc
= c_parser_peek_token (parser
)->location
;
7132 t1
= c_parser_type_name (parser
);
7133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7137 expr
.value
= error_mark_node
;
7141 tree type_expr
= NULL_TREE
;
7142 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7143 groktypename (t1
, &type_expr
, NULL
));
7146 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7147 TREE_TYPE (expr
.value
), type_expr
,
7149 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7154 c_parser_consume_token (parser
);
7155 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7157 expr
.value
= error_mark_node
;
7160 t1
= c_parser_type_name (parser
);
7162 parser
->error
= true;
7163 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7164 gcc_assert (parser
->error
);
7167 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7168 expr
.value
= error_mark_node
;
7173 tree type
= groktypename (t1
, NULL
, NULL
);
7175 if (type
== error_mark_node
)
7176 offsetof_ref
= error_mark_node
;
7179 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7180 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7182 /* Parse the second argument to __builtin_offsetof. We
7183 must have one identifier, and beyond that we want to
7184 accept sub structure and sub array references. */
7185 if (c_parser_next_token_is (parser
, CPP_NAME
))
7187 offsetof_ref
= build_component_ref
7188 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7189 c_parser_consume_token (parser
);
7190 while (c_parser_next_token_is (parser
, CPP_DOT
)
7191 || c_parser_next_token_is (parser
,
7193 || c_parser_next_token_is (parser
,
7196 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7198 loc
= c_parser_peek_token (parser
)->location
;
7199 offsetof_ref
= build_array_ref (loc
,
7204 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7207 c_parser_consume_token (parser
);
7208 if (c_parser_next_token_is_not (parser
,
7211 c_parser_error (parser
, "expected identifier");
7214 offsetof_ref
= build_component_ref
7216 c_parser_peek_token (parser
)->value
);
7217 c_parser_consume_token (parser
);
7223 loc
= c_parser_peek_token (parser
)->location
;
7224 c_parser_consume_token (parser
);
7225 ce
= c_parser_expression (parser
);
7226 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7228 idx
= c_fully_fold (idx
, false, NULL
);
7229 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7231 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7236 c_parser_error (parser
, "expected identifier");
7237 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7239 expr
.value
= fold_offsetof (offsetof_ref
);
7242 case RID_CHOOSE_EXPR
:
7244 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7245 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7248 c_parser_consume_token (parser
);
7249 if (!c_parser_get_builtin_args (parser
,
7250 "__builtin_choose_expr",
7253 expr
.value
= error_mark_node
;
7257 if (vec_safe_length (cexpr_list
) != 3)
7259 error_at (loc
, "wrong number of arguments to "
7260 "%<__builtin_choose_expr%>");
7261 expr
.value
= error_mark_node
;
7265 e1_p
= &(*cexpr_list
)[0];
7266 e2_p
= &(*cexpr_list
)[1];
7267 e3_p
= &(*cexpr_list
)[2];
7270 mark_exp_read (e2_p
->value
);
7271 mark_exp_read (e3_p
->value
);
7272 if (TREE_CODE (c
) != INTEGER_CST
7273 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7275 "first argument to %<__builtin_choose_expr%> not"
7277 constant_expression_warning (c
);
7278 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7281 case RID_TYPES_COMPATIBLE_P
:
7282 c_parser_consume_token (parser
);
7283 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7285 expr
.value
= error_mark_node
;
7288 t1
= c_parser_type_name (parser
);
7291 expr
.value
= error_mark_node
;
7294 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7297 expr
.value
= error_mark_node
;
7300 t2
= c_parser_type_name (parser
);
7303 expr
.value
= error_mark_node
;
7306 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7310 e1
= groktypename (t1
, NULL
, NULL
);
7311 e2
= groktypename (t2
, NULL
, NULL
);
7312 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7314 expr
.value
= error_mark_node
;
7318 e1
= TYPE_MAIN_VARIANT (e1
);
7319 e2
= TYPE_MAIN_VARIANT (e2
);
7322 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7325 case RID_BUILTIN_COMPLEX
:
7327 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7328 c_expr_t
*e1_p
, *e2_p
;
7330 c_parser_consume_token (parser
);
7331 if (!c_parser_get_builtin_args (parser
,
7332 "__builtin_complex",
7333 &cexpr_list
, false))
7335 expr
.value
= error_mark_node
;
7339 if (vec_safe_length (cexpr_list
) != 2)
7341 error_at (loc
, "wrong number of arguments to "
7342 "%<__builtin_complex%>");
7343 expr
.value
= error_mark_node
;
7347 e1_p
= &(*cexpr_list
)[0];
7348 e2_p
= &(*cexpr_list
)[1];
7350 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7351 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7352 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7353 TREE_OPERAND (e1_p
->value
, 0));
7354 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7355 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7356 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7357 TREE_OPERAND (e2_p
->value
, 0));
7358 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7359 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7360 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7361 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7363 error_at (loc
, "%<__builtin_complex%> operand "
7364 "not of real binary floating-point type");
7365 expr
.value
= error_mark_node
;
7368 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7369 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7372 "%<__builtin_complex%> operands of different types");
7373 expr
.value
= error_mark_node
;
7377 pedwarn (loc
, OPT_Wpedantic
,
7378 "ISO C90 does not support complex types");
7379 expr
.value
= build2 (COMPLEX_EXPR
,
7382 (TREE_TYPE (e1_p
->value
))),
7383 e1_p
->value
, e2_p
->value
);
7386 case RID_BUILTIN_SHUFFLE
:
7388 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7392 c_parser_consume_token (parser
);
7393 if (!c_parser_get_builtin_args (parser
,
7394 "__builtin_shuffle",
7395 &cexpr_list
, false))
7397 expr
.value
= error_mark_node
;
7401 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7402 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7404 if (vec_safe_length (cexpr_list
) == 2)
7406 c_build_vec_perm_expr
7407 (loc
, (*cexpr_list
)[0].value
,
7408 NULL_TREE
, (*cexpr_list
)[1].value
);
7410 else if (vec_safe_length (cexpr_list
) == 3)
7412 c_build_vec_perm_expr
7413 (loc
, (*cexpr_list
)[0].value
,
7414 (*cexpr_list
)[1].value
,
7415 (*cexpr_list
)[2].value
);
7418 error_at (loc
, "wrong number of arguments to "
7419 "%<__builtin_shuffle%>");
7420 expr
.value
= error_mark_node
;
7424 case RID_AT_SELECTOR
:
7425 gcc_assert (c_dialect_objc ());
7426 c_parser_consume_token (parser
);
7427 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7429 expr
.value
= error_mark_node
;
7433 tree sel
= c_parser_objc_selector_arg (parser
);
7434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7436 expr
.value
= objc_build_selector_expr (loc
, sel
);
7439 case RID_AT_PROTOCOL
:
7440 gcc_assert (c_dialect_objc ());
7441 c_parser_consume_token (parser
);
7442 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7444 expr
.value
= error_mark_node
;
7447 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7449 c_parser_error (parser
, "expected identifier");
7450 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7451 expr
.value
= error_mark_node
;
7455 tree id
= c_parser_peek_token (parser
)->value
;
7456 c_parser_consume_token (parser
);
7457 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7459 expr
.value
= objc_build_protocol_expr (id
);
7463 /* Extension to support C-structures in the archiver. */
7464 gcc_assert (c_dialect_objc ());
7465 c_parser_consume_token (parser
);
7466 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7468 expr
.value
= error_mark_node
;
7471 t1
= c_parser_type_name (parser
);
7474 expr
.value
= error_mark_node
;
7475 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7478 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7481 tree type
= groktypename (t1
, NULL
, NULL
);
7482 expr
.value
= objc_build_encode_expr (type
);
7486 expr
= c_parser_generic_selection (parser
);
7488 case RID_CILK_SPAWN
:
7489 c_parser_consume_token (parser
);
7492 error_at (loc
, "-fcilkplus must be enabled to use "
7494 expr
= c_parser_postfix_expression (parser
);
7495 expr
.value
= error_mark_node
;
7497 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7499 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7500 "are not permitted");
7501 /* Now flush out all the _Cilk_spawns. */
7502 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7503 c_parser_consume_token (parser
);
7504 expr
= c_parser_postfix_expression (parser
);
7508 expr
= c_parser_postfix_expression (parser
);
7509 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7513 c_parser_error (parser
, "expected expression");
7514 expr
.value
= error_mark_node
;
7518 case CPP_OPEN_SQUARE
:
7519 if (c_dialect_objc ())
7521 tree receiver
, args
;
7522 c_parser_consume_token (parser
);
7523 receiver
= c_parser_objc_receiver (parser
);
7524 args
= c_parser_objc_message_args (parser
);
7525 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7527 expr
.value
= objc_build_message_expr (receiver
, args
);
7530 /* Else fall through to report error. */
7532 c_parser_error (parser
, "expected expression");
7533 expr
.value
= error_mark_node
;
7536 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7539 /* Parse a postfix expression after a parenthesized type name: the
7540 brace-enclosed initializer of a compound literal, possibly followed
7541 by some postfix operators. This is separate because it is not
7542 possible to tell until after the type name whether a cast
7543 expression has a cast or a compound literal, or whether the operand
7544 of sizeof is a parenthesized type name or starts with a compound
7545 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7546 location of the first token after the parentheses around the type
7549 static struct c_expr
7550 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7551 struct c_type_name
*type_name
,
7552 location_t type_loc
)
7558 location_t start_loc
;
7559 tree type_expr
= NULL_TREE
;
7560 bool type_expr_const
= true;
7561 check_compound_literal_type (type_loc
, type_name
);
7562 start_init (NULL_TREE
, NULL
, 0);
7563 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7564 start_loc
= c_parser_peek_token (parser
)->location
;
7565 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7567 error_at (type_loc
, "compound literal has variable size");
7568 type
= error_mark_node
;
7570 init
= c_parser_braced_init (parser
, type
, false);
7572 maybe_warn_string_init (type
, init
);
7574 if (type
!= error_mark_node
7575 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7576 && current_function_decl
)
7578 error ("compound literal qualified by address-space qualifier");
7579 type
= error_mark_node
;
7583 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7584 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7585 ? CONSTRUCTOR_NON_CONST (init
.value
)
7586 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7587 non_const
|= !type_expr_const
;
7588 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7589 expr
.original_code
= ERROR_MARK
;
7590 expr
.original_type
= NULL
;
7593 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7595 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7596 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7600 gcc_assert (!non_const
);
7601 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7602 type_expr
, expr
.value
);
7605 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7608 /* Callback function for sizeof_pointer_memaccess_warning to compare
7612 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7614 return comptypes (type1
, type2
) == 1;
7617 /* Parse a postfix expression after the initial primary or compound
7618 literal; that is, parse a series of postfix operators.
7620 EXPR_LOC is the location of the primary expression. */
7622 static struct c_expr
7623 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7624 location_t expr_loc
,
7627 struct c_expr orig_expr
;
7629 location_t sizeof_arg_loc
[3];
7632 vec
<tree
, va_gc
> *exprlist
;
7633 vec
<tree
, va_gc
> *origtypes
= NULL
;
7634 vec
<location_t
> arg_loc
= vNULL
;
7638 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7639 switch (c_parser_peek_token (parser
)->type
)
7641 case CPP_OPEN_SQUARE
:
7642 /* Array reference. */
7643 c_parser_consume_token (parser
);
7645 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7646 /* If we are here, then we have something like this:
7649 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7653 idx
= c_parser_expression (parser
).value
;
7654 /* Here we have 3 options:
7655 1. Array [EXPR] -- Normal Array call.
7656 2. Array [EXPR : EXPR] -- Array notation without stride.
7657 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7659 For 1, we just handle it just like a normal array expression.
7660 For 2 and 3 we handle it like we handle array notations. The
7661 idx value we have above becomes the initial/start index.
7664 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7665 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7669 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7671 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7674 expr
.original_code
= ERROR_MARK
;
7675 expr
.original_type
= NULL
;
7677 case CPP_OPEN_PAREN
:
7678 /* Function call. */
7679 c_parser_consume_token (parser
);
7680 for (i
= 0; i
< 3; i
++)
7682 sizeof_arg
[i
] = NULL_TREE
;
7683 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7685 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7688 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7689 sizeof_arg_loc
, sizeof_arg
,
7691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7694 mark_exp_read (expr
.value
);
7695 if (warn_sizeof_pointer_memaccess
)
7696 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7697 expr
.value
, exprlist
,
7699 sizeof_ptr_memacc_comptypes
);
7701 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7702 exprlist
, origtypes
);
7703 expr
.original_code
= ERROR_MARK
;
7704 if (TREE_CODE (expr
.value
) == INTEGER_CST
7705 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7706 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7707 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7708 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7709 expr
.original_type
= NULL
;
7712 release_tree_vector (exprlist
);
7713 release_tree_vector (origtypes
);
7718 /* Structure element reference. */
7719 c_parser_consume_token (parser
);
7720 expr
= default_function_array_conversion (expr_loc
, expr
);
7721 if (c_parser_next_token_is (parser
, CPP_NAME
))
7722 ident
= c_parser_peek_token (parser
)->value
;
7725 c_parser_error (parser
, "expected identifier");
7726 expr
.value
= error_mark_node
;
7727 expr
.original_code
= ERROR_MARK
;
7728 expr
.original_type
= NULL
;
7731 c_parser_consume_token (parser
);
7732 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7733 expr
.original_code
= ERROR_MARK
;
7734 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7735 expr
.original_type
= NULL
;
7738 /* Remember the original type of a bitfield. */
7739 tree field
= TREE_OPERAND (expr
.value
, 1);
7740 if (TREE_CODE (field
) != FIELD_DECL
)
7741 expr
.original_type
= NULL
;
7743 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7747 /* Structure element reference. */
7748 c_parser_consume_token (parser
);
7749 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7750 if (c_parser_next_token_is (parser
, CPP_NAME
))
7751 ident
= c_parser_peek_token (parser
)->value
;
7754 c_parser_error (parser
, "expected identifier");
7755 expr
.value
= error_mark_node
;
7756 expr
.original_code
= ERROR_MARK
;
7757 expr
.original_type
= NULL
;
7760 c_parser_consume_token (parser
);
7761 expr
.value
= build_component_ref (op_loc
,
7762 build_indirect_ref (op_loc
,
7766 expr
.original_code
= ERROR_MARK
;
7767 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7768 expr
.original_type
= NULL
;
7771 /* Remember the original type of a bitfield. */
7772 tree field
= TREE_OPERAND (expr
.value
, 1);
7773 if (TREE_CODE (field
) != FIELD_DECL
)
7774 expr
.original_type
= NULL
;
7776 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7780 /* Postincrement. */
7781 c_parser_consume_token (parser
);
7782 /* If the expressions have array notations, we expand them. */
7784 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7785 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7788 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7789 expr
.value
= build_unary_op (op_loc
,
7790 POSTINCREMENT_EXPR
, expr
.value
, 0);
7792 expr
.original_code
= ERROR_MARK
;
7793 expr
.original_type
= NULL
;
7795 case CPP_MINUS_MINUS
:
7796 /* Postdecrement. */
7797 c_parser_consume_token (parser
);
7798 /* If the expressions have array notations, we expand them. */
7800 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7801 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7804 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7805 expr
.value
= build_unary_op (op_loc
,
7806 POSTDECREMENT_EXPR
, expr
.value
, 0);
7808 expr
.original_code
= ERROR_MARK
;
7809 expr
.original_type
= NULL
;
7817 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7820 assignment-expression
7821 expression , assignment-expression
7824 static struct c_expr
7825 c_parser_expression (c_parser
*parser
)
7827 location_t tloc
= c_parser_peek_token (parser
)->location
;
7829 expr
= c_parser_expr_no_commas (parser
, NULL
);
7830 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7831 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7832 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7836 location_t loc
= c_parser_peek_token (parser
)->location
;
7837 location_t expr_loc
;
7838 c_parser_consume_token (parser
);
7839 expr_loc
= c_parser_peek_token (parser
)->location
;
7840 lhsval
= expr
.value
;
7841 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7842 lhsval
= TREE_OPERAND (lhsval
, 1);
7843 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7844 mark_exp_read (lhsval
);
7845 next
= c_parser_expr_no_commas (parser
, NULL
);
7846 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7847 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7848 expr
.original_code
= COMPOUND_EXPR
;
7849 expr
.original_type
= next
.original_type
;
7854 /* Parse an expression and convert functions or arrays to pointers and
7855 lvalues to rvalues. */
7857 static struct c_expr
7858 c_parser_expression_conv (c_parser
*parser
)
7861 location_t loc
= c_parser_peek_token (parser
)->location
;
7862 expr
= c_parser_expression (parser
);
7863 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7867 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7868 functions and arrays to pointers and lvalues to rvalues. If
7869 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7870 locations of function arguments into this vector.
7873 assignment-expression
7874 nonempty-expr-list , assignment-expression
7877 static vec
<tree
, va_gc
> *
7878 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7879 vec
<tree
, va_gc
> **p_orig_types
,
7880 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7881 vec
<location_t
> *locations
)
7883 vec
<tree
, va_gc
> *ret
;
7884 vec
<tree
, va_gc
> *orig_types
;
7886 location_t loc
= c_parser_peek_token (parser
)->location
;
7887 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7888 unsigned int idx
= 0;
7890 ret
= make_tree_vector ();
7891 if (p_orig_types
== NULL
)
7894 orig_types
= make_tree_vector ();
7896 if (sizeof_arg
!= NULL
7897 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7898 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7899 expr
= c_parser_expr_no_commas (parser
, NULL
);
7901 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7903 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7904 ret
->quick_push (expr
.value
);
7906 orig_types
->quick_push (expr
.original_type
);
7908 locations
->safe_push (loc
);
7909 if (sizeof_arg
!= NULL
7910 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7911 && expr
.original_code
== SIZEOF_EXPR
)
7913 sizeof_arg
[0] = c_last_sizeof_arg
;
7914 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7916 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7918 c_parser_consume_token (parser
);
7919 loc
= c_parser_peek_token (parser
)->location
;
7920 if (sizeof_arg
!= NULL
7921 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7922 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7924 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7925 expr
= c_parser_expr_no_commas (parser
, NULL
);
7927 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7929 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7930 vec_safe_push (ret
, expr
.value
);
7932 vec_safe_push (orig_types
, expr
.original_type
);
7934 locations
->safe_push (loc
);
7936 && sizeof_arg
!= NULL
7937 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7938 && expr
.original_code
== SIZEOF_EXPR
)
7940 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7941 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7945 *p_orig_types
= orig_types
;
7949 /* Parse Objective-C-specific constructs. */
7951 /* Parse an objc-class-definition.
7953 objc-class-definition:
7954 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7955 objc-class-instance-variables[opt] objc-methodprotolist @end
7956 @implementation identifier objc-superclass[opt]
7957 objc-class-instance-variables[opt]
7958 @interface identifier ( identifier ) objc-protocol-refs[opt]
7959 objc-methodprotolist @end
7960 @interface identifier ( ) objc-protocol-refs[opt]
7961 objc-methodprotolist @end
7962 @implementation identifier ( identifier )
7967 "@interface identifier (" must start "@interface identifier (
7968 identifier ) ...": objc-methodprotolist in the first production may
7969 not start with a parenthesized identifier as a declarator of a data
7970 definition with no declaration specifiers if the objc-superclass,
7971 objc-protocol-refs and objc-class-instance-variables are omitted. */
7974 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7979 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7981 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7986 c_parser_consume_token (parser
);
7987 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7989 c_parser_error (parser
, "expected identifier");
7992 id1
= c_parser_peek_token (parser
)->value
;
7993 c_parser_consume_token (parser
);
7994 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7996 /* We have a category or class extension. */
7998 tree proto
= NULL_TREE
;
7999 c_parser_consume_token (parser
);
8000 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8002 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8004 /* We have a class extension. */
8009 c_parser_error (parser
, "expected identifier or %<)%>");
8010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8016 id2
= c_parser_peek_token (parser
)->value
;
8017 c_parser_consume_token (parser
);
8019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8022 objc_start_category_implementation (id1
, id2
);
8025 if (c_parser_next_token_is (parser
, CPP_LESS
))
8026 proto
= c_parser_objc_protocol_refs (parser
);
8027 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8028 c_parser_objc_methodprotolist (parser
);
8029 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8030 objc_finish_interface ();
8033 if (c_parser_next_token_is (parser
, CPP_COLON
))
8035 c_parser_consume_token (parser
);
8036 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8038 c_parser_error (parser
, "expected identifier");
8041 superclass
= c_parser_peek_token (parser
)->value
;
8042 c_parser_consume_token (parser
);
8045 superclass
= NULL_TREE
;
8048 tree proto
= NULL_TREE
;
8049 if (c_parser_next_token_is (parser
, CPP_LESS
))
8050 proto
= c_parser_objc_protocol_refs (parser
);
8051 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8054 objc_start_class_implementation (id1
, superclass
);
8055 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8056 c_parser_objc_class_instance_variables (parser
);
8059 objc_continue_interface ();
8060 c_parser_objc_methodprotolist (parser
);
8061 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8062 objc_finish_interface ();
8066 objc_continue_implementation ();
8071 /* Parse objc-class-instance-variables.
8073 objc-class-instance-variables:
8074 { objc-instance-variable-decl-list[opt] }
8076 objc-instance-variable-decl-list:
8077 objc-visibility-spec
8078 objc-instance-variable-decl ;
8080 objc-instance-variable-decl-list objc-visibility-spec
8081 objc-instance-variable-decl-list objc-instance-variable-decl ;
8082 objc-instance-variable-decl-list ;
8084 objc-visibility-spec:
8089 objc-instance-variable-decl:
8094 c_parser_objc_class_instance_variables (c_parser
*parser
)
8096 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8097 c_parser_consume_token (parser
);
8098 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8101 /* Parse any stray semicolon. */
8102 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8104 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8106 c_parser_consume_token (parser
);
8109 /* Stop if at the end of the instance variables. */
8110 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8112 c_parser_consume_token (parser
);
8115 /* Parse any objc-visibility-spec. */
8116 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8118 c_parser_consume_token (parser
);
8119 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8122 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8124 c_parser_consume_token (parser
);
8125 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8128 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8130 c_parser_consume_token (parser
);
8131 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8134 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8136 c_parser_consume_token (parser
);
8137 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8140 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8142 c_parser_pragma (parser
, pragma_external
);
8146 /* Parse some comma-separated declarations. */
8147 decls
= c_parser_struct_declaration (parser
);
8150 /* There is a syntax error. We want to skip the offending
8151 tokens up to the next ';' (included) or '}'
8154 /* First, skip manually a ')' or ']'. This is because they
8155 reduce the nesting level, so c_parser_skip_until_found()
8156 wouldn't be able to skip past them. */
8157 c_token
*token
= c_parser_peek_token (parser
);
8158 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8159 c_parser_consume_token (parser
);
8161 /* Then, do the standard skipping. */
8162 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8164 /* We hopefully recovered. Start normal parsing again. */
8165 parser
->error
= false;
8170 /* Comma-separated instance variables are chained together
8171 in reverse order; add them one by one. */
8172 tree ivar
= nreverse (decls
);
8173 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8174 objc_add_instance_variable (copy_node (ivar
));
8176 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8180 /* Parse an objc-class-declaration.
8182 objc-class-declaration:
8183 @class identifier-list ;
8187 c_parser_objc_class_declaration (c_parser
*parser
)
8189 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8190 c_parser_consume_token (parser
);
8191 /* Any identifiers, including those declared as type names, are OK
8196 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8198 c_parser_error (parser
, "expected identifier");
8199 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8200 parser
->error
= false;
8203 id
= c_parser_peek_token (parser
)->value
;
8204 objc_declare_class (id
);
8205 c_parser_consume_token (parser
);
8206 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8207 c_parser_consume_token (parser
);
8211 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8214 /* Parse an objc-alias-declaration.
8216 objc-alias-declaration:
8217 @compatibility_alias identifier identifier ;
8221 c_parser_objc_alias_declaration (c_parser
*parser
)
8224 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8225 c_parser_consume_token (parser
);
8226 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8228 c_parser_error (parser
, "expected identifier");
8229 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8232 id1
= c_parser_peek_token (parser
)->value
;
8233 c_parser_consume_token (parser
);
8234 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8236 c_parser_error (parser
, "expected identifier");
8237 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8240 id2
= c_parser_peek_token (parser
)->value
;
8241 c_parser_consume_token (parser
);
8242 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8243 objc_declare_alias (id1
, id2
);
8246 /* Parse an objc-protocol-definition.
8248 objc-protocol-definition:
8249 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8250 @protocol identifier-list ;
8252 "@protocol identifier ;" should be resolved as "@protocol
8253 identifier-list ;": objc-methodprotolist may not start with a
8254 semicolon in the first alternative if objc-protocol-refs are
8258 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8260 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8262 c_parser_consume_token (parser
);
8263 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8265 c_parser_error (parser
, "expected identifier");
8268 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8269 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8271 /* Any identifiers, including those declared as type names, are
8276 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8278 c_parser_error (parser
, "expected identifier");
8281 id
= c_parser_peek_token (parser
)->value
;
8282 objc_declare_protocol (id
, attributes
);
8283 c_parser_consume_token (parser
);
8284 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8285 c_parser_consume_token (parser
);
8289 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8293 tree id
= c_parser_peek_token (parser
)->value
;
8294 tree proto
= NULL_TREE
;
8295 c_parser_consume_token (parser
);
8296 if (c_parser_next_token_is (parser
, CPP_LESS
))
8297 proto
= c_parser_objc_protocol_refs (parser
);
8298 parser
->objc_pq_context
= true;
8299 objc_start_protocol (id
, proto
, attributes
);
8300 c_parser_objc_methodprotolist (parser
);
8301 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8302 parser
->objc_pq_context
= false;
8303 objc_finish_interface ();
8307 /* Parse an objc-method-type.
8313 Return true if it is a class method (+) and false if it is
8314 an instance method (-).
8317 c_parser_objc_method_type (c_parser
*parser
)
8319 switch (c_parser_peek_token (parser
)->type
)
8322 c_parser_consume_token (parser
);
8325 c_parser_consume_token (parser
);
8332 /* Parse an objc-method-definition.
8334 objc-method-definition:
8335 objc-method-type objc-method-decl ;[opt] compound-statement
8339 c_parser_objc_method_definition (c_parser
*parser
)
8341 bool is_class_method
= c_parser_objc_method_type (parser
);
8342 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8343 parser
->objc_pq_context
= true;
8344 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8346 if (decl
== error_mark_node
)
8347 return; /* Bail here. */
8349 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8351 c_parser_consume_token (parser
);
8352 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8353 "extra semicolon in method definition specified");
8356 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8358 c_parser_error (parser
, "expected %<{%>");
8362 parser
->objc_pq_context
= false;
8363 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8365 add_stmt (c_parser_compound_statement (parser
));
8366 objc_finish_method_definition (current_function_decl
);
8370 /* This code is executed when we find a method definition
8371 outside of an @implementation context (or invalid for other
8372 reasons). Parse the method (to keep going) but do not emit
8375 c_parser_compound_statement (parser
);
8379 /* Parse an objc-methodprotolist.
8381 objc-methodprotolist:
8383 objc-methodprotolist objc-methodproto
8384 objc-methodprotolist declaration
8385 objc-methodprotolist ;
8389 The declaration is a data definition, which may be missing
8390 declaration specifiers under the same rules and diagnostics as
8391 other data definitions outside functions, and the stray semicolon
8392 is diagnosed the same way as a stray semicolon outside a
8396 c_parser_objc_methodprotolist (c_parser
*parser
)
8400 /* The list is terminated by @end. */
8401 switch (c_parser_peek_token (parser
)->type
)
8404 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8405 "ISO C does not allow extra %<;%> outside of a function");
8406 c_parser_consume_token (parser
);
8410 c_parser_objc_methodproto (parser
);
8413 c_parser_pragma (parser
, pragma_external
);
8418 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8420 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8421 c_parser_objc_at_property_declaration (parser
);
8422 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8424 objc_set_method_opt (true);
8425 c_parser_consume_token (parser
);
8427 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8429 objc_set_method_opt (false);
8430 c_parser_consume_token (parser
);
8433 c_parser_declaration_or_fndef (parser
, false, false, true,
8434 false, true, NULL
, vNULL
);
8440 /* Parse an objc-methodproto.
8443 objc-method-type objc-method-decl ;
8447 c_parser_objc_methodproto (c_parser
*parser
)
8449 bool is_class_method
= c_parser_objc_method_type (parser
);
8450 tree decl
, attributes
= NULL_TREE
;
8452 /* Remember protocol qualifiers in prototypes. */
8453 parser
->objc_pq_context
= true;
8454 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8456 /* Forget protocol qualifiers now. */
8457 parser
->objc_pq_context
= false;
8459 /* Do not allow the presence of attributes to hide an erroneous
8460 method implementation in the interface section. */
8461 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8463 c_parser_error (parser
, "expected %<;%>");
8467 if (decl
!= error_mark_node
)
8468 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8470 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8473 /* If we are at a position that method attributes may be present, check that
8474 there are not any parsed already (a syntax error) and then collect any
8475 specified at the current location. Finally, if new attributes were present,
8476 check that the next token is legal ( ';' for decls and '{' for defs). */
8479 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8484 c_parser_error (parser
,
8485 "method attributes must be specified at the end only");
8486 *attributes
= NULL_TREE
;
8490 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8491 *attributes
= c_parser_attributes (parser
);
8493 /* If there were no attributes here, just report any earlier error. */
8494 if (*attributes
== NULL_TREE
|| bad
)
8497 /* If the attributes are followed by a ; or {, then just report any earlier
8499 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8500 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8503 /* We've got attributes, but not at the end. */
8504 c_parser_error (parser
,
8505 "expected %<;%> or %<{%> after method attribute definition");
8509 /* Parse an objc-method-decl.
8512 ( objc-type-name ) objc-selector
8514 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8515 objc-keyword-selector objc-optparmlist
8518 objc-keyword-selector:
8520 objc-keyword-selector objc-keyword-decl
8523 objc-selector : ( objc-type-name ) identifier
8524 objc-selector : identifier
8525 : ( objc-type-name ) identifier
8529 objc-optparms objc-optellipsis
8533 objc-opt-parms , parameter-declaration
8541 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8542 tree
*attributes
, tree
*expr
)
8544 tree type
= NULL_TREE
;
8546 tree parms
= NULL_TREE
;
8547 bool ellipsis
= false;
8548 bool attr_err
= false;
8550 *attributes
= NULL_TREE
;
8551 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8553 c_parser_consume_token (parser
);
8554 type
= c_parser_objc_type_name (parser
);
8555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8557 sel
= c_parser_objc_selector (parser
);
8558 /* If there is no selector, or a colon follows, we have an
8559 objc-keyword-selector. If there is a selector, and a colon does
8560 not follow, that selector ends the objc-method-decl. */
8561 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8564 tree list
= NULL_TREE
;
8567 tree atype
= NULL_TREE
, id
, keyworddecl
;
8568 tree param_attr
= NULL_TREE
;
8569 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8571 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8573 c_parser_consume_token (parser
);
8574 atype
= c_parser_objc_type_name (parser
);
8575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8578 /* New ObjC allows attributes on method parameters. */
8579 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8580 param_attr
= c_parser_attributes (parser
);
8581 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8583 c_parser_error (parser
, "expected identifier");
8584 return error_mark_node
;
8586 id
= c_parser_peek_token (parser
)->value
;
8587 c_parser_consume_token (parser
);
8588 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8589 list
= chainon (list
, keyworddecl
);
8590 tsel
= c_parser_objc_selector (parser
);
8591 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8595 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8597 /* Parse the optional parameter list. Optional Objective-C
8598 method parameters follow the C syntax, and may include '...'
8599 to denote a variable number of arguments. */
8600 parms
= make_node (TREE_LIST
);
8601 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8603 struct c_parm
*parm
;
8604 c_parser_consume_token (parser
);
8605 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8608 c_parser_consume_token (parser
);
8609 attr_err
|= c_parser_objc_maybe_method_attributes
8610 (parser
, attributes
) ;
8613 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8616 parms
= chainon (parms
,
8617 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8622 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8626 c_parser_error (parser
, "objective-c method declaration is expected");
8627 return error_mark_node
;
8631 return error_mark_node
;
8633 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8636 /* Parse an objc-type-name.
8639 objc-type-qualifiers[opt] type-name
8640 objc-type-qualifiers[opt]
8642 objc-type-qualifiers:
8644 objc-type-qualifiers objc-type-qualifier
8646 objc-type-qualifier: one of
8647 in out inout bycopy byref oneway
8651 c_parser_objc_type_name (c_parser
*parser
)
8653 tree quals
= NULL_TREE
;
8654 struct c_type_name
*type_name
= NULL
;
8655 tree type
= NULL_TREE
;
8658 c_token
*token
= c_parser_peek_token (parser
);
8659 if (token
->type
== CPP_KEYWORD
8660 && (token
->keyword
== RID_IN
8661 || token
->keyword
== RID_OUT
8662 || token
->keyword
== RID_INOUT
8663 || token
->keyword
== RID_BYCOPY
8664 || token
->keyword
== RID_BYREF
8665 || token
->keyword
== RID_ONEWAY
))
8667 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8668 c_parser_consume_token (parser
);
8673 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8674 type_name
= c_parser_type_name (parser
);
8676 type
= groktypename (type_name
, NULL
, NULL
);
8678 /* If the type is unknown, and error has already been produced and
8679 we need to recover from the error. In that case, use NULL_TREE
8680 for the type, as if no type had been specified; this will use the
8681 default type ('id') which is good for error recovery. */
8682 if (type
== error_mark_node
)
8685 return build_tree_list (quals
, type
);
8688 /* Parse objc-protocol-refs.
8695 c_parser_objc_protocol_refs (c_parser
*parser
)
8697 tree list
= NULL_TREE
;
8698 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8699 c_parser_consume_token (parser
);
8700 /* Any identifiers, including those declared as type names, are OK
8705 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8707 c_parser_error (parser
, "expected identifier");
8710 id
= c_parser_peek_token (parser
)->value
;
8711 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8712 c_parser_consume_token (parser
);
8713 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8714 c_parser_consume_token (parser
);
8718 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8722 /* Parse an objc-try-catch-finally-statement.
8724 objc-try-catch-finally-statement:
8725 @try compound-statement objc-catch-list[opt]
8726 @try compound-statement objc-catch-list[opt] @finally compound-statement
8729 @catch ( objc-catch-parameter-declaration ) compound-statement
8730 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8732 objc-catch-parameter-declaration:
8733 parameter-declaration
8736 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8738 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8739 for C++. Keep them in sync. */
8742 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8744 location_t location
;
8747 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8748 c_parser_consume_token (parser
);
8749 location
= c_parser_peek_token (parser
)->location
;
8750 objc_maybe_warn_exceptions (location
);
8751 stmt
= c_parser_compound_statement (parser
);
8752 objc_begin_try_stmt (location
, stmt
);
8754 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8756 struct c_parm
*parm
;
8757 tree parameter_declaration
= error_mark_node
;
8758 bool seen_open_paren
= false;
8760 c_parser_consume_token (parser
);
8761 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8762 seen_open_paren
= true;
8763 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8765 /* We have "@catch (...)" (where the '...' are literally
8766 what is in the code). Skip the '...'.
8767 parameter_declaration is set to NULL_TREE, and
8768 objc_being_catch_clauses() knows that that means
8770 c_parser_consume_token (parser
);
8771 parameter_declaration
= NULL_TREE
;
8775 /* We have "@catch (NSException *exception)" or something
8776 like that. Parse the parameter declaration. */
8777 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8779 parameter_declaration
= error_mark_node
;
8781 parameter_declaration
= grokparm (parm
, NULL
);
8783 if (seen_open_paren
)
8784 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8787 /* If there was no open parenthesis, we are recovering from
8788 an error, and we are trying to figure out what mistake
8789 the user has made. */
8791 /* If there is an immediate closing parenthesis, the user
8792 probably forgot the opening one (ie, they typed "@catch
8793 NSException *e)". Parse the closing parenthesis and keep
8795 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8796 c_parser_consume_token (parser
);
8798 /* If these is no immediate closing parenthesis, the user
8799 probably doesn't know that parenthesis are required at
8800 all (ie, they typed "@catch NSException *e"). So, just
8801 forget about the closing parenthesis and keep going. */
8803 objc_begin_catch_clause (parameter_declaration
);
8804 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8805 c_parser_compound_statement_nostart (parser
);
8806 objc_finish_catch_clause ();
8808 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8810 c_parser_consume_token (parser
);
8811 location
= c_parser_peek_token (parser
)->location
;
8812 stmt
= c_parser_compound_statement (parser
);
8813 objc_build_finally_clause (location
, stmt
);
8815 objc_finish_try_stmt ();
8818 /* Parse an objc-synchronized-statement.
8820 objc-synchronized-statement:
8821 @synchronized ( expression ) compound-statement
8825 c_parser_objc_synchronized_statement (c_parser
*parser
)
8829 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8830 c_parser_consume_token (parser
);
8831 loc
= c_parser_peek_token (parser
)->location
;
8832 objc_maybe_warn_exceptions (loc
);
8833 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8835 struct c_expr ce
= c_parser_expression (parser
);
8836 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8838 expr
= c_fully_fold (expr
, false, NULL
);
8839 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8842 expr
= error_mark_node
;
8843 stmt
= c_parser_compound_statement (parser
);
8844 objc_build_synchronized (loc
, expr
, stmt
);
8847 /* Parse an objc-selector; return NULL_TREE without an error if the
8848 next token is not an objc-selector.
8853 enum struct union if else while do for switch case default
8854 break continue return goto asm sizeof typeof __alignof
8855 unsigned long const short volatile signed restrict _Complex
8856 in out inout bycopy byref oneway int char float double void _Bool
8859 ??? Why this selection of keywords but not, for example, storage
8860 class specifiers? */
8863 c_parser_objc_selector (c_parser
*parser
)
8865 c_token
*token
= c_parser_peek_token (parser
);
8866 tree value
= token
->value
;
8867 if (token
->type
== CPP_NAME
)
8869 c_parser_consume_token (parser
);
8872 if (token
->type
!= CPP_KEYWORD
)
8874 switch (token
->keyword
)
8918 c_parser_consume_token (parser
);
8925 /* Parse an objc-selector-arg.
8929 objc-keywordname-list
8931 objc-keywordname-list:
8933 objc-keywordname-list objc-keywordname
8941 c_parser_objc_selector_arg (c_parser
*parser
)
8943 tree sel
= c_parser_objc_selector (parser
);
8944 tree list
= NULL_TREE
;
8945 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8949 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8951 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8952 sel
= c_parser_objc_selector (parser
);
8953 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8959 /* Parse an objc-receiver.
8968 c_parser_objc_receiver (c_parser
*parser
)
8970 location_t loc
= c_parser_peek_token (parser
)->location
;
8972 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8973 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8974 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8976 tree id
= c_parser_peek_token (parser
)->value
;
8977 c_parser_consume_token (parser
);
8978 return objc_get_class_reference (id
);
8980 struct c_expr ce
= c_parser_expression (parser
);
8981 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8982 return c_fully_fold (ce
.value
, false, NULL
);
8985 /* Parse objc-message-args.
8989 objc-keywordarg-list
8991 objc-keywordarg-list:
8993 objc-keywordarg-list objc-keywordarg
8996 objc-selector : objc-keywordexpr
9001 c_parser_objc_message_args (c_parser
*parser
)
9003 tree sel
= c_parser_objc_selector (parser
);
9004 tree list
= NULL_TREE
;
9005 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9010 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9011 return error_mark_node
;
9012 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9013 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9014 sel
= c_parser_objc_selector (parser
);
9015 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9021 /* Parse an objc-keywordexpr.
9028 c_parser_objc_keywordexpr (c_parser
*parser
)
9031 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9032 NULL
, NULL
, NULL
, NULL
);
9033 if (vec_safe_length (expr_list
) == 1)
9035 /* Just return the expression, remove a level of
9037 ret
= (*expr_list
)[0];
9041 /* We have a comma expression, we will collapse later. */
9042 ret
= build_tree_list_vec (expr_list
);
9044 release_tree_vector (expr_list
);
9048 /* A check, needed in several places, that ObjC interface, implementation or
9049 method definitions are not prefixed by incorrect items. */
9051 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9052 struct c_declspecs
*specs
)
9054 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9055 || specs
->typespec_kind
!= ctsk_none
)
9057 c_parser_error (parser
,
9058 "no type or storage class may be specified here,");
9059 c_parser_skip_to_end_of_block_or_statement (parser
);
9065 /* Parse an Objective-C @property declaration. The syntax is:
9067 objc-property-declaration:
9068 '@property' objc-property-attributes[opt] struct-declaration ;
9070 objc-property-attributes:
9071 '(' objc-property-attribute-list ')'
9073 objc-property-attribute-list:
9074 objc-property-attribute
9075 objc-property-attribute-list, objc-property-attribute
9077 objc-property-attribute
9078 'getter' = identifier
9079 'setter' = identifier
9088 @property NSString *name;
9089 @property (readonly) id object;
9090 @property (retain, nonatomic, getter=getTheName) id name;
9091 @property int a, b, c;
9093 PS: This function is identical to cp_parser_objc_at_propery_declaration
9094 for C++. Keep them in sync. */
9096 c_parser_objc_at_property_declaration (c_parser
*parser
)
9098 /* The following variables hold the attributes of the properties as
9099 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9100 seen. When we see an attribute, we set them to 'true' (if they
9101 are boolean properties) or to the identifier (if they have an
9102 argument, ie, for getter and setter). Note that here we only
9103 parse the list of attributes, check the syntax and accumulate the
9104 attributes that we find. objc_add_property_declaration() will
9105 then process the information. */
9106 bool property_assign
= false;
9107 bool property_copy
= false;
9108 tree property_getter_ident
= NULL_TREE
;
9109 bool property_nonatomic
= false;
9110 bool property_readonly
= false;
9111 bool property_readwrite
= false;
9112 bool property_retain
= false;
9113 tree property_setter_ident
= NULL_TREE
;
9115 /* 'properties' is the list of properties that we read. Usually a
9116 single one, but maybe more (eg, in "@property int a, b, c;" there
9121 loc
= c_parser_peek_token (parser
)->location
;
9122 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9124 c_parser_consume_token (parser
); /* Eat '@property'. */
9126 /* Parse the optional attribute list... */
9127 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9130 c_parser_consume_token (parser
);
9132 /* Property attribute keywords are valid now. */
9133 parser
->objc_property_attr_context
= true;
9137 bool syntax_error
= false;
9138 c_token
*token
= c_parser_peek_token (parser
);
9141 if (token
->type
!= CPP_KEYWORD
)
9143 if (token
->type
== CPP_CLOSE_PAREN
)
9144 c_parser_error (parser
, "expected identifier");
9147 c_parser_consume_token (parser
);
9148 c_parser_error (parser
, "unknown property attribute");
9152 keyword
= token
->keyword
;
9153 c_parser_consume_token (parser
);
9156 case RID_ASSIGN
: property_assign
= true; break;
9157 case RID_COPY
: property_copy
= true; break;
9158 case RID_NONATOMIC
: property_nonatomic
= true; break;
9159 case RID_READONLY
: property_readonly
= true; break;
9160 case RID_READWRITE
: property_readwrite
= true; break;
9161 case RID_RETAIN
: property_retain
= true; break;
9165 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9167 if (keyword
== RID_GETTER
)
9168 c_parser_error (parser
,
9169 "missing %<=%> (after %<getter%> attribute)");
9171 c_parser_error (parser
,
9172 "missing %<=%> (after %<setter%> attribute)");
9173 syntax_error
= true;
9176 c_parser_consume_token (parser
); /* eat the = */
9177 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9179 c_parser_error (parser
, "expected identifier");
9180 syntax_error
= true;
9183 if (keyword
== RID_SETTER
)
9185 if (property_setter_ident
!= NULL_TREE
)
9186 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9188 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9189 c_parser_consume_token (parser
);
9190 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9191 c_parser_error (parser
, "setter name must terminate with %<:%>");
9193 c_parser_consume_token (parser
);
9197 if (property_getter_ident
!= NULL_TREE
)
9198 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9200 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9201 c_parser_consume_token (parser
);
9205 c_parser_error (parser
, "unknown property attribute");
9206 syntax_error
= true;
9213 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9214 c_parser_consume_token (parser
);
9218 parser
->objc_property_attr_context
= false;
9219 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9221 /* ... and the property declaration(s). */
9222 properties
= c_parser_struct_declaration (parser
);
9224 if (properties
== error_mark_node
)
9226 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9227 parser
->error
= false;
9231 if (properties
== NULL_TREE
)
9232 c_parser_error (parser
, "expected identifier");
9235 /* Comma-separated properties are chained together in
9236 reverse order; add them one by one. */
9237 properties
= nreverse (properties
);
9239 for (; properties
; properties
= TREE_CHAIN (properties
))
9240 objc_add_property_declaration (loc
, copy_node (properties
),
9241 property_readonly
, property_readwrite
,
9242 property_assign
, property_retain
,
9243 property_copy
, property_nonatomic
,
9244 property_getter_ident
, property_setter_ident
);
9247 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9248 parser
->error
= false;
9251 /* Parse an Objective-C @synthesize declaration. The syntax is:
9253 objc-synthesize-declaration:
9254 @synthesize objc-synthesize-identifier-list ;
9256 objc-synthesize-identifier-list:
9257 objc-synthesize-identifier
9258 objc-synthesize-identifier-list, objc-synthesize-identifier
9260 objc-synthesize-identifier
9262 identifier = identifier
9265 @synthesize MyProperty;
9266 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9268 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9269 for C++. Keep them in sync.
9272 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9274 tree list
= NULL_TREE
;
9276 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9277 loc
= c_parser_peek_token (parser
)->location
;
9279 c_parser_consume_token (parser
);
9282 tree property
, ivar
;
9283 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9285 c_parser_error (parser
, "expected identifier");
9286 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9287 /* Once we find the semicolon, we can resume normal parsing.
9288 We have to reset parser->error manually because
9289 c_parser_skip_until_found() won't reset it for us if the
9290 next token is precisely a semicolon. */
9291 parser
->error
= false;
9294 property
= c_parser_peek_token (parser
)->value
;
9295 c_parser_consume_token (parser
);
9296 if (c_parser_next_token_is (parser
, CPP_EQ
))
9298 c_parser_consume_token (parser
);
9299 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9301 c_parser_error (parser
, "expected identifier");
9302 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9303 parser
->error
= false;
9306 ivar
= c_parser_peek_token (parser
)->value
;
9307 c_parser_consume_token (parser
);
9311 list
= chainon (list
, build_tree_list (ivar
, property
));
9312 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9313 c_parser_consume_token (parser
);
9317 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9318 objc_add_synthesize_declaration (loc
, list
);
9321 /* Parse an Objective-C @dynamic declaration. The syntax is:
9323 objc-dynamic-declaration:
9324 @dynamic identifier-list ;
9327 @dynamic MyProperty;
9328 @dynamic MyProperty, AnotherProperty;
9330 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9331 for C++. Keep them in sync.
9334 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9336 tree list
= NULL_TREE
;
9338 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9339 loc
= c_parser_peek_token (parser
)->location
;
9341 c_parser_consume_token (parser
);
9345 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9347 c_parser_error (parser
, "expected identifier");
9348 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9349 parser
->error
= false;
9352 property
= c_parser_peek_token (parser
)->value
;
9353 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9354 c_parser_consume_token (parser
);
9355 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9356 c_parser_consume_token (parser
);
9360 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9361 objc_add_dynamic_declaration (loc
, list
);
9365 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9366 should be considered, statements. ALLOW_STMT is true if we're within
9367 the context of a function and such pragmas are to be allowed. Returns
9368 true if we actually parsed such a pragma. */
9371 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9375 id
= c_parser_peek_token (parser
)->pragma_kind
;
9376 gcc_assert (id
!= PRAGMA_NONE
);
9380 case PRAGMA_OMP_BARRIER
:
9381 if (context
!= pragma_compound
)
9383 if (context
== pragma_stmt
)
9384 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9385 "used in compound statements");
9388 c_parser_omp_barrier (parser
);
9391 case PRAGMA_OMP_FLUSH
:
9392 if (context
!= pragma_compound
)
9394 if (context
== pragma_stmt
)
9395 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9396 "used in compound statements");
9399 c_parser_omp_flush (parser
);
9402 case PRAGMA_OMP_TASKWAIT
:
9403 if (context
!= pragma_compound
)
9405 if (context
== pragma_stmt
)
9406 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9407 "used in compound statements");
9410 c_parser_omp_taskwait (parser
);
9413 case PRAGMA_OMP_TASKYIELD
:
9414 if (context
!= pragma_compound
)
9416 if (context
== pragma_stmt
)
9417 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9418 "used in compound statements");
9421 c_parser_omp_taskyield (parser
);
9424 case PRAGMA_OMP_CANCEL
:
9425 if (context
!= pragma_compound
)
9427 if (context
== pragma_stmt
)
9428 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9429 "used in compound statements");
9432 c_parser_omp_cancel (parser
);
9435 case PRAGMA_OMP_CANCELLATION_POINT
:
9436 if (context
!= pragma_compound
)
9438 if (context
== pragma_stmt
)
9439 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9440 "only be used in compound statements");
9443 c_parser_omp_cancellation_point (parser
);
9446 case PRAGMA_OMP_THREADPRIVATE
:
9447 c_parser_omp_threadprivate (parser
);
9450 case PRAGMA_OMP_TARGET
:
9451 return c_parser_omp_target (parser
, context
);
9453 case PRAGMA_OMP_END_DECLARE_TARGET
:
9454 c_parser_omp_end_declare_target (parser
);
9457 case PRAGMA_OMP_SECTION
:
9458 error_at (c_parser_peek_token (parser
)->location
,
9459 "%<#pragma omp section%> may only be used in "
9460 "%<#pragma omp sections%> construct");
9461 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9464 case PRAGMA_OMP_DECLARE_REDUCTION
:
9465 c_parser_omp_declare (parser
, context
);
9468 c_parser_consume_pragma (parser
);
9469 c_parser_skip_to_pragma_eol (parser
);
9470 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9471 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9472 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9474 c_parser_error (parser
, "for, while or do statement expected");
9477 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9478 c_parser_for_statement (parser
, true);
9479 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9480 c_parser_while_statement (parser
, true);
9482 c_parser_do_statement (parser
, true);
9485 case PRAGMA_GCC_PCH_PREPROCESS
:
9486 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9487 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9490 case PRAGMA_CILK_SIMD
:
9491 if (!c_parser_cilk_verify_simd (parser
, context
))
9493 c_parser_consume_pragma (parser
);
9494 c_parser_cilk_simd (parser
);
9498 if (id
< PRAGMA_FIRST_EXTERNAL
)
9500 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9503 c_parser_error (parser
, "expected declaration specifiers");
9504 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9507 c_parser_omp_construct (parser
);
9513 c_parser_consume_pragma (parser
);
9514 c_invoke_pragma_handler (id
);
9516 /* Skip to EOL, but suppress any error message. Those will have been
9517 generated by the handler routine through calling error, as opposed
9518 to calling c_parser_error. */
9519 parser
->error
= true;
9520 c_parser_skip_to_pragma_eol (parser
);
9525 /* The interface the pragma parsers have to the lexer. */
9528 pragma_lex (tree
*value
)
9530 c_token
*tok
= c_parser_peek_token (the_parser
);
9531 enum cpp_ttype ret
= tok
->type
;
9533 *value
= tok
->value
;
9534 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9538 if (ret
== CPP_KEYWORD
)
9540 c_parser_consume_token (the_parser
);
9547 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9551 c_parser_consume_pragma (parser
);
9552 if (c_parser_next_token_is (parser
, CPP_STRING
))
9554 name
= c_parser_peek_token (parser
)->value
;
9555 c_parser_consume_token (parser
);
9558 c_parser_error (parser
, "expected string literal");
9559 c_parser_skip_to_pragma_eol (parser
);
9562 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9565 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9567 /* Returns name of the next clause.
9568 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9569 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9570 returned and the token is consumed. */
9572 static pragma_omp_clause
9573 c_parser_omp_clause_name (c_parser
*parser
)
9575 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9577 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9578 result
= PRAGMA_OMP_CLAUSE_IF
;
9579 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9580 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9581 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9582 result
= PRAGMA_OMP_CLAUSE_FOR
;
9583 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9585 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9590 if (!strcmp ("aligned", p
))
9591 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9594 if (!strcmp ("collapse", p
))
9595 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9596 else if (!strcmp ("copyin", p
))
9597 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9598 else if (!strcmp ("copyprivate", p
))
9599 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9602 if (!strcmp ("depend", p
))
9603 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9604 else if (!strcmp ("device", p
))
9605 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9606 else if (!strcmp ("dist_schedule", p
))
9607 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9610 if (!strcmp ("final", p
))
9611 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9612 else if (!strcmp ("firstprivate", p
))
9613 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9614 else if (!strcmp ("from", p
))
9615 result
= PRAGMA_OMP_CLAUSE_FROM
;
9618 if (!strcmp ("inbranch", p
))
9619 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9622 if (!strcmp ("lastprivate", p
))
9623 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9624 else if (!strcmp ("linear", p
))
9625 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9628 if (!strcmp ("map", p
))
9629 result
= PRAGMA_OMP_CLAUSE_MAP
;
9630 else if (!strcmp ("mergeable", p
))
9631 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9632 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9633 result
= PRAGMA_CILK_CLAUSE_MASK
;
9636 if (!strcmp ("notinbranch", p
))
9637 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9638 else if (!strcmp ("nowait", p
))
9639 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9640 else if (!strcmp ("num_teams", p
))
9641 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9642 else if (!strcmp ("num_threads", p
))
9643 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9644 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9645 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9648 if (!strcmp ("ordered", p
))
9649 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9652 if (!strcmp ("parallel", p
))
9653 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9654 else if (!strcmp ("private", p
))
9655 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9656 else if (!strcmp ("proc_bind", p
))
9657 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9660 if (!strcmp ("reduction", p
))
9661 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9664 if (!strcmp ("safelen", p
))
9665 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9666 else if (!strcmp ("schedule", p
))
9667 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9668 else if (!strcmp ("sections", p
))
9669 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9670 else if (!strcmp ("shared", p
))
9671 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9672 else if (!strcmp ("simdlen", p
))
9673 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9676 if (!strcmp ("taskgroup", p
))
9677 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9678 else if (!strcmp ("thread_limit", p
))
9679 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9680 else if (!strcmp ("to", p
))
9681 result
= PRAGMA_OMP_CLAUSE_TO
;
9684 if (!strcmp ("uniform", p
))
9685 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9686 else if (!strcmp ("untied", p
))
9687 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9690 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9691 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9696 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9697 c_parser_consume_token (parser
);
9702 /* Validate that a clause of the given type does not already exist. */
9705 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9710 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9711 if (OMP_CLAUSE_CODE (c
) == code
)
9713 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9714 error_at (loc
, "too many %qs clauses", name
);
9722 variable-list , identifier
9724 If KIND is nonzero, create the appropriate node and install the
9725 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9726 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9728 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9729 return the list created. */
9732 c_parser_omp_variable_list (c_parser
*parser
,
9733 location_t clause_loc
,
9734 enum omp_clause_code kind
, tree list
)
9736 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9737 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9738 c_parser_error (parser
, "expected identifier");
9740 while (c_parser_next_token_is (parser
, CPP_NAME
)
9741 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9743 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9747 undeclared_variable (c_parser_peek_token (parser
)->location
,
9748 c_parser_peek_token (parser
)->value
);
9749 t
= error_mark_node
;
9752 c_parser_consume_token (parser
);
9754 if (t
== error_mark_node
)
9760 case OMP_CLAUSE_MAP
:
9761 case OMP_CLAUSE_FROM
:
9763 case OMP_CLAUSE_DEPEND
:
9764 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9766 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9768 c_parser_consume_token (parser
);
9769 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9770 low_bound
= c_parser_expression (parser
).value
;
9771 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9772 length
= integer_one_node
;
9776 if (!c_parser_require (parser
, CPP_COLON
,
9779 t
= error_mark_node
;
9782 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
9783 length
= c_parser_expression (parser
).value
;
9785 /* Look for the closing `]'. */
9786 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9789 t
= error_mark_node
;
9792 t
= tree_cons (low_bound
, length
, t
);
9799 if (t
!= error_mark_node
)
9801 tree u
= build_omp_clause (clause_loc
, kind
);
9802 OMP_CLAUSE_DECL (u
) = t
;
9803 OMP_CLAUSE_CHAIN (u
) = list
;
9808 list
= tree_cons (t
, NULL_TREE
, list
);
9810 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9813 c_parser_consume_token (parser
);
9819 /* Similarly, but expect leading and trailing parenthesis. This is a very
9820 common case for omp clauses. */
9823 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9826 /* The clauses location. */
9827 location_t loc
= c_parser_peek_token (parser
)->location
;
9829 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9831 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9838 collapse ( constant-expression ) */
9841 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9843 tree c
, num
= error_mark_node
;
9847 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9849 loc
= c_parser_peek_token (parser
)->location
;
9850 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9852 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9853 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9855 if (num
== error_mark_node
)
9857 mark_exp_read (num
);
9858 num
= c_fully_fold (num
, false, NULL
);
9859 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9860 || !tree_fits_shwi_p (num
)
9861 || (n
= tree_to_shwi (num
)) <= 0
9865 "collapse argument needs positive constant integer expression");
9868 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9869 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9870 OMP_CLAUSE_CHAIN (c
) = list
;
9875 copyin ( variable-list ) */
9878 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9880 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9884 copyprivate ( variable-list ) */
9887 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9889 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9893 default ( shared | none ) */
9896 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9898 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9899 location_t loc
= c_parser_peek_token (parser
)->location
;
9902 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9904 if (c_parser_next_token_is (parser
, CPP_NAME
))
9906 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9911 if (strcmp ("none", p
) != 0)
9913 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9917 if (strcmp ("shared", p
) != 0)
9919 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9926 c_parser_consume_token (parser
);
9931 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9933 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9935 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9938 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9939 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9940 OMP_CLAUSE_CHAIN (c
) = list
;
9941 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9947 firstprivate ( variable-list ) */
9950 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9952 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9956 final ( expression ) */
9959 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9961 location_t loc
= c_parser_peek_token (parser
)->location
;
9962 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9964 tree t
= c_parser_paren_condition (parser
);
9967 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9969 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9970 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9971 OMP_CLAUSE_CHAIN (c
) = list
;
9975 c_parser_error (parser
, "expected %<(%>");
9981 if ( expression ) */
9984 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9986 location_t loc
= c_parser_peek_token (parser
)->location
;
9987 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9989 tree t
= c_parser_paren_condition (parser
);
9992 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9994 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9995 OMP_CLAUSE_IF_EXPR (c
) = t
;
9996 OMP_CLAUSE_CHAIN (c
) = list
;
10000 c_parser_error (parser
, "expected %<(%>");
10006 lastprivate ( variable-list ) */
10009 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10011 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10018 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10022 /* FIXME: Should we allow duplicates? */
10023 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10025 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10026 OMP_CLAUSE_MERGEABLE
);
10027 OMP_CLAUSE_CHAIN (c
) = list
;
10036 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10039 location_t loc
= c_parser_peek_token (parser
)->location
;
10041 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10043 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10044 OMP_CLAUSE_CHAIN (c
) = list
;
10049 num_threads ( expression ) */
10052 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10054 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10055 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10057 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10058 tree c
, t
= c_parser_expression (parser
).value
;
10060 t
= c_fully_fold (t
, false, NULL
);
10062 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10064 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10066 c_parser_error (parser
, "expected integer expression");
10070 /* Attempt to statically determine when the number isn't positive. */
10071 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10072 build_int_cst (TREE_TYPE (t
), 0));
10073 if (CAN_HAVE_LOCATION_P (c
))
10074 SET_EXPR_LOCATION (c
, expr_loc
);
10075 if (c
== boolean_true_node
)
10077 warning_at (expr_loc
, 0,
10078 "%<num_threads%> value must be positive");
10079 t
= integer_one_node
;
10082 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10084 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10085 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10086 OMP_CLAUSE_CHAIN (c
) = list
;
10097 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10101 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10103 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10104 OMP_CLAUSE_ORDERED
);
10105 OMP_CLAUSE_CHAIN (c
) = list
;
10111 private ( variable-list ) */
10114 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10116 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10120 reduction ( reduction-operator : variable-list )
10122 reduction-operator:
10123 One of: + * - & ^ | && ||
10127 reduction-operator:
10128 One of: + * - & ^ | && || max min
10132 reduction-operator:
10133 One of: + * - & ^ | && ||
10137 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10139 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10140 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10142 enum tree_code code
= ERROR_MARK
;
10143 tree reduc_id
= NULL_TREE
;
10145 switch (c_parser_peek_token (parser
)->type
)
10157 code
= BIT_AND_EXPR
;
10160 code
= BIT_XOR_EXPR
;
10163 code
= BIT_IOR_EXPR
;
10166 code
= TRUTH_ANDIF_EXPR
;
10169 code
= TRUTH_ORIF_EXPR
;
10174 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10175 if (strcmp (p
, "min") == 0)
10180 if (strcmp (p
, "max") == 0)
10185 reduc_id
= c_parser_peek_token (parser
)->value
;
10189 c_parser_error (parser
,
10190 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10191 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10192 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10195 c_parser_consume_token (parser
);
10196 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10197 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10201 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10202 OMP_CLAUSE_REDUCTION
, list
);
10203 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10205 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10206 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10207 if (code
== ERROR_MARK
10208 || !(INTEGRAL_TYPE_P (type
)
10209 || TREE_CODE (type
) == REAL_TYPE
10210 || TREE_CODE (type
) == COMPLEX_TYPE
))
10211 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10212 = c_omp_reduction_lookup (reduc_id
,
10213 TYPE_MAIN_VARIANT (type
));
10218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10224 schedule ( schedule-kind )
10225 schedule ( schedule-kind , expression )
10228 static | dynamic | guided | runtime | auto
10232 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10235 location_t loc
= c_parser_peek_token (parser
)->location
;
10237 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10240 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10242 if (c_parser_next_token_is (parser
, CPP_NAME
))
10244 tree kind
= c_parser_peek_token (parser
)->value
;
10245 const char *p
= IDENTIFIER_POINTER (kind
);
10250 if (strcmp ("dynamic", p
) != 0)
10252 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10256 if (strcmp ("guided", p
) != 0)
10258 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10262 if (strcmp ("runtime", p
) != 0)
10264 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10271 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10272 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10273 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10274 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10278 c_parser_consume_token (parser
);
10279 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10282 c_parser_consume_token (parser
);
10284 here
= c_parser_peek_token (parser
)->location
;
10285 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10287 t
= c_fully_fold (t
, false, NULL
);
10289 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10290 error_at (here
, "schedule %<runtime%> does not take "
10291 "a %<chunk_size%> parameter");
10292 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10294 "schedule %<auto%> does not take "
10295 "a %<chunk_size%> parameter");
10296 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10297 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10299 c_parser_error (parser
, "expected integer expression");
10301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10305 "expected %<,%> or %<)%>");
10307 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10308 OMP_CLAUSE_CHAIN (c
) = list
;
10312 c_parser_error (parser
, "invalid schedule kind");
10313 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10318 shared ( variable-list ) */
10321 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10323 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10330 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10334 /* FIXME: Should we allow duplicates? */
10335 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10337 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10338 OMP_CLAUSE_UNTIED
);
10339 OMP_CLAUSE_CHAIN (c
) = list
;
10349 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10350 enum omp_clause_code code
, tree list
)
10352 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10354 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10355 OMP_CLAUSE_CHAIN (c
) = list
;
10367 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10368 enum omp_clause_code code
, tree list
)
10370 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10371 OMP_CLAUSE_CHAIN (c
) = list
;
10377 num_teams ( expression ) */
10380 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10382 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10383 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10385 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10386 tree c
, t
= c_parser_expression (parser
).value
;
10388 t
= c_fully_fold (t
, false, NULL
);
10390 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10392 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10394 c_parser_error (parser
, "expected integer expression");
10398 /* Attempt to statically determine when the number isn't positive. */
10399 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10400 build_int_cst (TREE_TYPE (t
), 0));
10401 if (CAN_HAVE_LOCATION_P (c
))
10402 SET_EXPR_LOCATION (c
, expr_loc
);
10403 if (c
== boolean_true_node
)
10405 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10406 t
= integer_one_node
;
10409 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10411 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10412 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10413 OMP_CLAUSE_CHAIN (c
) = list
;
10421 thread_limit ( expression ) */
10424 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10426 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10427 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10429 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10430 tree c
, t
= c_parser_expression (parser
).value
;
10432 t
= c_fully_fold (t
, false, NULL
);
10434 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10436 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10438 c_parser_error (parser
, "expected integer expression");
10442 /* Attempt to statically determine when the number isn't positive. */
10443 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10444 build_int_cst (TREE_TYPE (t
), 0));
10445 if (CAN_HAVE_LOCATION_P (c
))
10446 SET_EXPR_LOCATION (c
, expr_loc
);
10447 if (c
== boolean_true_node
)
10449 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10450 t
= integer_one_node
;
10453 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10456 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10457 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10458 OMP_CLAUSE_CHAIN (c
) = list
;
10466 aligned ( variable-list )
10467 aligned ( variable-list : constant-expression ) */
10470 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10472 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10475 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10478 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10479 OMP_CLAUSE_ALIGNED
, list
);
10481 if (c_parser_next_token_is (parser
, CPP_COLON
))
10483 c_parser_consume_token (parser
);
10484 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10485 mark_exp_read (alignment
);
10486 alignment
= c_fully_fold (alignment
, false, NULL
);
10487 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10488 && TREE_CODE (alignment
) != INTEGER_CST
10489 && tree_int_cst_sgn (alignment
) != 1)
10491 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10492 "be positive constant integer expression");
10493 alignment
= NULL_TREE
;
10496 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10497 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10500 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10505 linear ( variable-list )
10506 linear ( variable-list : expression ) */
10509 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10511 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10514 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10517 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10518 OMP_CLAUSE_LINEAR
, list
);
10520 if (c_parser_next_token_is (parser
, CPP_COLON
))
10522 c_parser_consume_token (parser
);
10523 step
= c_parser_expression (parser
).value
;
10524 mark_exp_read (step
);
10525 step
= c_fully_fold (step
, false, NULL
);
10526 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10528 sorry ("using parameters for %<linear%> step is not supported yet");
10529 step
= integer_one_node
;
10531 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10533 error_at (clause_loc
, "%<linear%> clause step expression must "
10535 step
= integer_one_node
;
10540 step
= integer_one_node
;
10542 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10544 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10547 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10552 safelen ( constant-expression ) */
10555 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10557 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10560 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10563 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10565 t
= c_fully_fold (t
, false, NULL
);
10566 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10567 && TREE_CODE (t
) != INTEGER_CST
10568 && tree_int_cst_sgn (t
) != 1)
10570 error_at (clause_loc
, "%<safelen%> clause expression must "
10571 "be positive constant integer expression");
10575 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10576 if (t
== NULL_TREE
|| t
== error_mark_node
)
10579 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10581 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10582 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10583 OMP_CLAUSE_CHAIN (c
) = list
;
10588 simdlen ( constant-expression ) */
10591 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10593 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10596 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10599 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10601 t
= c_fully_fold (t
, false, NULL
);
10602 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10603 && TREE_CODE (t
) != INTEGER_CST
10604 && tree_int_cst_sgn (t
) != 1)
10606 error_at (clause_loc
, "%<simdlen%> clause expression must "
10607 "be positive constant integer expression");
10611 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10612 if (t
== NULL_TREE
|| t
== error_mark_node
)
10615 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10617 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10618 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10619 OMP_CLAUSE_CHAIN (c
) = list
;
10624 depend ( depend-kind: variable-list )
10627 in | out | inout */
10630 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10632 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10633 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10636 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10639 if (c_parser_next_token_is (parser
, CPP_NAME
))
10641 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10642 if (strcmp ("in", p
) == 0)
10643 kind
= OMP_CLAUSE_DEPEND_IN
;
10644 else if (strcmp ("inout", p
) == 0)
10645 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10646 else if (strcmp ("out", p
) == 0)
10647 kind
= OMP_CLAUSE_DEPEND_OUT
;
10654 c_parser_consume_token (parser
);
10655 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10658 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10659 OMP_CLAUSE_DEPEND
, list
);
10661 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10662 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10668 c_parser_error (parser
, "invalid depend kind");
10670 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10675 map ( map-kind: variable-list )
10676 map ( variable-list )
10679 alloc | to | from | tofrom */
10682 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10684 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10685 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10688 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10691 if (c_parser_next_token_is (parser
, CPP_NAME
)
10692 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10694 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10695 if (strcmp ("alloc", p
) == 0)
10696 kind
= OMP_CLAUSE_MAP_ALLOC
;
10697 else if (strcmp ("to", p
) == 0)
10698 kind
= OMP_CLAUSE_MAP_TO
;
10699 else if (strcmp ("from", p
) == 0)
10700 kind
= OMP_CLAUSE_MAP_FROM
;
10701 else if (strcmp ("tofrom", p
) == 0)
10702 kind
= OMP_CLAUSE_MAP_TOFROM
;
10705 c_parser_error (parser
, "invalid map kind");
10706 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10710 c_parser_consume_token (parser
);
10711 c_parser_consume_token (parser
);
10714 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10716 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10717 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10724 device ( expression ) */
10727 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10729 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10730 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10732 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10734 t
= c_fully_fold (t
, false, NULL
);
10736 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10738 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10740 c_parser_error (parser
, "expected integer expression");
10744 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10746 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10747 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10748 OMP_CLAUSE_CHAIN (c
) = list
;
10756 dist_schedule ( static )
10757 dist_schedule ( static , expression ) */
10760 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10762 tree c
, t
= NULL_TREE
;
10763 location_t loc
= c_parser_peek_token (parser
)->location
;
10765 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10768 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10770 c_parser_error (parser
, "invalid dist_schedule kind");
10771 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10776 c_parser_consume_token (parser
);
10777 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10779 c_parser_consume_token (parser
);
10781 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10783 t
= c_fully_fold (t
, false, NULL
);
10784 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10787 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10788 "expected %<,%> or %<)%>");
10790 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10791 if (t
== error_mark_node
)
10794 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10795 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10796 OMP_CLAUSE_CHAIN (c
) = list
;
10801 proc_bind ( proc-bind-kind )
10804 master | close | spread */
10807 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10809 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10810 enum omp_clause_proc_bind_kind kind
;
10813 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10816 if (c_parser_next_token_is (parser
, CPP_NAME
))
10818 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10819 if (strcmp ("master", p
) == 0)
10820 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10821 else if (strcmp ("close", p
) == 0)
10822 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10823 else if (strcmp ("spread", p
) == 0)
10824 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10831 c_parser_consume_token (parser
);
10832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10833 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10834 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10835 OMP_CLAUSE_CHAIN (c
) = list
;
10839 c_parser_error (parser
, "invalid proc_bind kind");
10840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10845 to ( variable-list ) */
10848 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10850 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10854 from ( variable-list ) */
10857 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10859 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10863 uniform ( variable-list ) */
10866 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10868 /* The clauses location. */
10869 location_t loc
= c_parser_peek_token (parser
)->location
;
10871 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10873 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10875 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10880 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10881 is a bitmask in MASK. Return the list of clauses found; the result
10882 of clause default goes in *pdefault. */
10885 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10886 const char *where
, bool finish_p
= true)
10888 tree clauses
= NULL
;
10889 bool first
= true, cilk_simd_fn
= false;
10891 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10894 pragma_omp_clause c_kind
;
10895 const char *c_name
;
10896 tree prev
= clauses
;
10898 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10899 c_parser_consume_token (parser
);
10901 here
= c_parser_peek_token (parser
)->location
;
10902 c_kind
= c_parser_omp_clause_name (parser
);
10906 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10907 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10908 c_name
= "collapse";
10910 case PRAGMA_OMP_CLAUSE_COPYIN
:
10911 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10914 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10915 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10916 c_name
= "copyprivate";
10918 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10919 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10920 c_name
= "default";
10922 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10923 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10924 c_name
= "firstprivate";
10926 case PRAGMA_OMP_CLAUSE_FINAL
:
10927 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10930 case PRAGMA_OMP_CLAUSE_IF
:
10931 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10934 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10935 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10936 c_name
= "lastprivate";
10938 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10939 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10940 c_name
= "mergeable";
10942 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10943 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10946 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10947 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10948 c_name
= "num_threads";
10950 case PRAGMA_OMP_CLAUSE_ORDERED
:
10951 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10952 c_name
= "ordered";
10954 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10955 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10956 c_name
= "private";
10958 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10959 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10960 c_name
= "reduction";
10962 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10963 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10964 c_name
= "schedule";
10966 case PRAGMA_OMP_CLAUSE_SHARED
:
10967 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10970 case PRAGMA_OMP_CLAUSE_UNTIED
:
10971 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10974 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10975 case PRAGMA_CILK_CLAUSE_MASK
:
10976 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10978 c_name
= "inbranch";
10980 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10981 case PRAGMA_CILK_CLAUSE_NOMASK
:
10982 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10984 c_name
= "notinbranch";
10986 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10988 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10990 c_name
= "parallel";
10994 error_at (here
, "%qs must be the first clause of %qs",
10999 case PRAGMA_OMP_CLAUSE_FOR
:
11001 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11005 goto clause_not_first
;
11007 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11009 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11011 c_name
= "sections";
11013 goto clause_not_first
;
11015 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11017 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11019 c_name
= "taskgroup";
11021 goto clause_not_first
;
11023 case PRAGMA_OMP_CLAUSE_TO
:
11024 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11027 case PRAGMA_OMP_CLAUSE_FROM
:
11028 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11031 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11032 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11033 c_name
= "uniform";
11035 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11036 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11037 c_name
= "num_teams";
11039 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11040 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11041 c_name
= "thread_limit";
11043 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11044 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11045 c_name
= "aligned";
11047 case PRAGMA_OMP_CLAUSE_LINEAR
:
11048 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11049 cilk_simd_fn
= true;
11050 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11053 case PRAGMA_OMP_CLAUSE_DEPEND
:
11054 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11057 case PRAGMA_OMP_CLAUSE_MAP
:
11058 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11061 case PRAGMA_OMP_CLAUSE_DEVICE
:
11062 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11065 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11066 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11067 c_name
= "dist_schedule";
11069 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11070 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11071 c_name
= "proc_bind";
11073 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11074 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11075 c_name
= "safelen";
11077 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11078 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11079 c_name
= "simdlen";
11081 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11082 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11083 c_name
= "simdlen";
11086 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11092 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11094 /* Remove the invalid clause(s) from the list to avoid
11095 confusing the rest of the compiler. */
11097 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11102 c_parser_skip_to_pragma_eol (parser
);
11105 return c_finish_omp_clauses (clauses
);
11114 In practice, we're also interested in adding the statement to an
11115 outer node. So it is convenient if we work around the fact that
11116 c_parser_statement calls add_stmt. */
11119 c_parser_omp_structured_block (c_parser
*parser
)
11121 tree stmt
= push_stmt_list ();
11122 c_parser_statement (parser
);
11123 return pop_stmt_list (stmt
);
11127 # pragma omp atomic new-line
11131 x binop= expr | x++ | ++x | x-- | --x
11133 +, *, -, /, &, ^, |, <<, >>
11135 where x is an lvalue expression with scalar type.
11138 # pragma omp atomic new-line
11141 # pragma omp atomic read new-line
11144 # pragma omp atomic write new-line
11147 # pragma omp atomic update new-line
11150 # pragma omp atomic capture new-line
11153 # pragma omp atomic capture new-line
11161 expression-stmt | x = x binop expr
11163 v = expression-stmt
11165 { v = x; update-stmt; } | { update-stmt; v = x; }
11169 expression-stmt | x = x binop expr | x = expr binop x
11173 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11175 where x and v are lvalue expressions with scalar type.
11177 LOC is the location of the #pragma token. */
11180 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11182 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11183 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11184 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11185 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11186 struct c_expr expr
;
11188 bool structured_block
= false;
11189 bool swapped
= false;
11190 bool seq_cst
= false;
11192 if (c_parser_next_token_is (parser
, CPP_NAME
))
11194 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11195 if (!strcmp (p
, "seq_cst"))
11198 c_parser_consume_token (parser
);
11199 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11200 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11201 c_parser_consume_token (parser
);
11204 if (c_parser_next_token_is (parser
, CPP_NAME
))
11206 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11208 if (!strcmp (p
, "read"))
11209 code
= OMP_ATOMIC_READ
;
11210 else if (!strcmp (p
, "write"))
11212 else if (!strcmp (p
, "update"))
11214 else if (!strcmp (p
, "capture"))
11215 code
= OMP_ATOMIC_CAPTURE_NEW
;
11219 c_parser_consume_token (parser
);
11223 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11224 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11225 c_parser_consume_token (parser
);
11227 if (c_parser_next_token_is (parser
, CPP_NAME
))
11230 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11231 if (!strcmp (p
, "seq_cst"))
11234 c_parser_consume_token (parser
);
11238 c_parser_skip_to_pragma_eol (parser
);
11242 case OMP_ATOMIC_READ
:
11243 case NOP_EXPR
: /* atomic write */
11244 v
= c_parser_unary_expression (parser
).value
;
11245 v
= c_fully_fold (v
, false, NULL
);
11246 if (v
== error_mark_node
)
11248 loc
= c_parser_peek_token (parser
)->location
;
11249 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11251 if (code
== NOP_EXPR
)
11252 lhs
= c_parser_expression (parser
).value
;
11254 lhs
= c_parser_unary_expression (parser
).value
;
11255 lhs
= c_fully_fold (lhs
, false, NULL
);
11256 if (lhs
== error_mark_node
)
11258 if (code
== NOP_EXPR
)
11260 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11268 case OMP_ATOMIC_CAPTURE_NEW
:
11269 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11271 c_parser_consume_token (parser
);
11272 structured_block
= true;
11276 v
= c_parser_unary_expression (parser
).value
;
11277 v
= c_fully_fold (v
, false, NULL
);
11278 if (v
== error_mark_node
)
11280 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11288 /* For structured_block case we don't know yet whether
11289 old or new x should be captured. */
11291 eloc
= c_parser_peek_token (parser
)->location
;
11292 expr
= c_parser_unary_expression (parser
);
11294 expr
= default_function_array_conversion (eloc
, expr
);
11295 unfolded_lhs
= expr
.value
;
11296 lhs
= c_fully_fold (lhs
, false, NULL
);
11298 switch (TREE_CODE (lhs
))
11302 c_parser_skip_to_end_of_block_or_statement (parser
);
11303 if (structured_block
)
11305 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11306 c_parser_consume_token (parser
);
11307 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11309 c_parser_skip_to_end_of_block_or_statement (parser
);
11310 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11311 c_parser_consume_token (parser
);
11316 case POSTINCREMENT_EXPR
:
11317 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11318 code
= OMP_ATOMIC_CAPTURE_OLD
;
11320 case PREINCREMENT_EXPR
:
11321 lhs
= TREE_OPERAND (lhs
, 0);
11322 unfolded_lhs
= NULL_TREE
;
11323 opcode
= PLUS_EXPR
;
11324 rhs
= integer_one_node
;
11327 case POSTDECREMENT_EXPR
:
11328 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11329 code
= OMP_ATOMIC_CAPTURE_OLD
;
11331 case PREDECREMENT_EXPR
:
11332 lhs
= TREE_OPERAND (lhs
, 0);
11333 unfolded_lhs
= NULL_TREE
;
11334 opcode
= MINUS_EXPR
;
11335 rhs
= integer_one_node
;
11338 case COMPOUND_EXPR
:
11339 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11340 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11341 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11342 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11343 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11344 (TREE_OPERAND (lhs
, 1), 0), 0)))
11346 /* Undo effects of boolean_increment for post {in,de}crement. */
11347 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11350 if (TREE_CODE (lhs
) == MODIFY_EXPR
11351 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11353 /* Undo effects of boolean_increment. */
11354 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11356 /* This is pre or post increment. */
11357 rhs
= TREE_OPERAND (lhs
, 1);
11358 lhs
= TREE_OPERAND (lhs
, 0);
11359 unfolded_lhs
= NULL_TREE
;
11361 if (code
== OMP_ATOMIC_CAPTURE_NEW
11362 && !structured_block
11363 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11364 code
= OMP_ATOMIC_CAPTURE_OLD
;
11367 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11368 && TREE_OPERAND (lhs
, 0)
11369 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11371 /* This is pre or post decrement. */
11372 rhs
= TREE_OPERAND (lhs
, 1);
11373 lhs
= TREE_OPERAND (lhs
, 0);
11374 unfolded_lhs
= NULL_TREE
;
11376 if (code
== OMP_ATOMIC_CAPTURE_NEW
11377 && !structured_block
11378 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11379 code
= OMP_ATOMIC_CAPTURE_OLD
;
11385 switch (c_parser_peek_token (parser
)->type
)
11388 opcode
= MULT_EXPR
;
11391 opcode
= TRUNC_DIV_EXPR
;
11394 opcode
= PLUS_EXPR
;
11397 opcode
= MINUS_EXPR
;
11399 case CPP_LSHIFT_EQ
:
11400 opcode
= LSHIFT_EXPR
;
11402 case CPP_RSHIFT_EQ
:
11403 opcode
= RSHIFT_EXPR
;
11406 opcode
= BIT_AND_EXPR
;
11409 opcode
= BIT_IOR_EXPR
;
11412 opcode
= BIT_XOR_EXPR
;
11415 c_parser_consume_token (parser
);
11416 eloc
= c_parser_peek_token (parser
)->location
;
11417 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11419 switch (TREE_CODE (rhs1
))
11422 case TRUNC_DIV_EXPR
:
11430 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11432 opcode
= TREE_CODE (rhs1
);
11433 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11434 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11437 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11439 opcode
= TREE_CODE (rhs1
);
11440 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11441 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11442 swapped
= !commutative_tree_code (opcode
);
11451 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11453 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11455 code
= OMP_ATOMIC_CAPTURE_OLD
;
11458 expr
= default_function_array_read_conversion (eloc
, expr
);
11459 unfolded_lhs1
= expr
.value
;
11460 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11462 c_parser_consume_token (parser
);
11465 if (structured_block
)
11468 expr
= default_function_array_read_conversion (eloc
, expr
);
11469 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11474 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11477 c_parser_error (parser
,
11478 "invalid operator for %<#pragma omp atomic%>");
11482 /* Arrange to pass the location of the assignment operator to
11483 c_finish_omp_atomic. */
11484 loc
= c_parser_peek_token (parser
)->location
;
11485 c_parser_consume_token (parser
);
11486 eloc
= c_parser_peek_token (parser
)->location
;
11487 expr
= c_parser_expression (parser
);
11488 expr
= default_function_array_read_conversion (eloc
, expr
);
11490 rhs
= c_fully_fold (rhs
, false, NULL
);
11494 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11496 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11498 v
= c_parser_unary_expression (parser
).value
;
11499 v
= c_fully_fold (v
, false, NULL
);
11500 if (v
== error_mark_node
)
11502 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11504 eloc
= c_parser_peek_token (parser
)->location
;
11505 expr
= c_parser_unary_expression (parser
);
11507 expr
= default_function_array_read_conversion (eloc
, expr
);
11508 unfolded_lhs1
= expr
.value
;
11509 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11510 if (lhs1
== error_mark_node
)
11513 if (structured_block
)
11515 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11516 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11519 if (unfolded_lhs
&& unfolded_lhs1
11520 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11522 error ("%<#pragma omp atomic capture%> uses two different "
11523 "expressions for memory");
11524 stmt
= error_mark_node
;
11527 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11529 if (stmt
!= error_mark_node
)
11532 if (!structured_block
)
11533 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11538 # pragma omp barrier new-line
11542 c_parser_omp_barrier (c_parser
*parser
)
11544 location_t loc
= c_parser_peek_token (parser
)->location
;
11545 c_parser_consume_pragma (parser
);
11546 c_parser_skip_to_pragma_eol (parser
);
11548 c_finish_omp_barrier (loc
);
11552 # pragma omp critical [(name)] new-line
11555 LOC is the location of the #pragma itself. */
11558 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11560 tree stmt
, name
= NULL
;
11562 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11564 c_parser_consume_token (parser
);
11565 if (c_parser_next_token_is (parser
, CPP_NAME
))
11567 name
= c_parser_peek_token (parser
)->value
;
11568 c_parser_consume_token (parser
);
11569 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11572 c_parser_error (parser
, "expected identifier");
11574 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11575 c_parser_error (parser
, "expected %<(%> or end of line");
11576 c_parser_skip_to_pragma_eol (parser
);
11578 stmt
= c_parser_omp_structured_block (parser
);
11579 return c_finish_omp_critical (loc
, stmt
, name
);
11583 # pragma omp flush flush-vars[opt] new-line
11586 ( variable-list ) */
11589 c_parser_omp_flush (c_parser
*parser
)
11591 location_t loc
= c_parser_peek_token (parser
)->location
;
11592 c_parser_consume_pragma (parser
);
11593 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11594 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11595 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11596 c_parser_error (parser
, "expected %<(%> or end of line");
11597 c_parser_skip_to_pragma_eol (parser
);
11599 c_finish_omp_flush (loc
);
11602 /* Parse the restricted form of the for statement allowed by OpenMP.
11603 The real trick here is to determine the loop control variable early
11604 so that we can push a new decl if necessary to make it private.
11605 LOC is the location of the OMP in "#pragma omp". */
11608 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11609 tree clauses
, tree
*cclauses
)
11611 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11612 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11613 bool fail
= false, open_brace_parsed
= false;
11614 int i
, collapse
= 1, nbraces
= 0;
11615 location_t for_loc
;
11616 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11618 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11619 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11620 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11622 gcc_assert (collapse
>= 1);
11624 declv
= make_tree_vec (collapse
);
11625 initv
= make_tree_vec (collapse
);
11626 condv
= make_tree_vec (collapse
);
11627 incrv
= make_tree_vec (collapse
);
11629 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11631 c_parser_error (parser
, "for statement expected");
11634 for_loc
= c_parser_peek_token (parser
)->location
;
11635 c_parser_consume_token (parser
);
11637 for (i
= 0; i
< collapse
; i
++)
11639 int bracecount
= 0;
11641 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11644 /* Parse the initialization declaration or expression. */
11645 if (c_parser_next_tokens_start_declaration (parser
))
11648 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11649 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11651 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11654 if (DECL_INITIAL (decl
) == error_mark_node
)
11655 decl
= error_mark_node
;
11658 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11659 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11661 struct c_expr decl_exp
;
11662 struct c_expr init_exp
;
11663 location_t init_loc
;
11665 decl_exp
= c_parser_postfix_expression (parser
);
11666 decl
= decl_exp
.value
;
11668 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11670 init_loc
= c_parser_peek_token (parser
)->location
;
11671 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11672 init_exp
= default_function_array_read_conversion (init_loc
,
11674 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11675 NOP_EXPR
, init_loc
, init_exp
.value
,
11676 init_exp
.original_type
);
11677 init
= c_process_expr_stmt (init_loc
, init
);
11679 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11684 c_parser_error (parser
,
11685 "expected iteration declaration or initialization");
11686 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11692 /* Parse the loop condition. */
11694 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11696 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11697 struct c_expr cond_expr
11698 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11700 cond
= cond_expr
.value
;
11701 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11702 cond
= c_fully_fold (cond
, false, NULL
);
11703 switch (cond_expr
.original_code
)
11711 if (code
== CILK_SIMD
)
11715 /* Can't be cond = error_mark_node, because we want to preserve
11716 the location until c_finish_omp_for. */
11717 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11720 protected_set_expr_location (cond
, cond_loc
);
11722 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11724 /* Parse the increment expression. */
11726 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11728 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11730 incr
= c_process_expr_stmt (incr_loc
,
11731 c_parser_expression (parser
).value
);
11733 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11735 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11739 TREE_VEC_ELT (declv
, i
) = decl
;
11740 TREE_VEC_ELT (initv
, i
) = init
;
11741 TREE_VEC_ELT (condv
, i
) = cond
;
11742 TREE_VEC_ELT (incrv
, i
) = incr
;
11746 if (i
== collapse
- 1)
11749 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11750 in between the collapsed for loops to be still considered perfectly
11751 nested. Hopefully the final version clarifies this.
11752 For now handle (multiple) {'s and empty statements. */
11755 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11757 c_parser_consume_token (parser
);
11760 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11762 c_parser_consume_token (parser
);
11765 else if (bracecount
11766 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11767 c_parser_consume_token (parser
);
11770 c_parser_error (parser
, "not enough perfectly nested loops");
11773 open_brace_parsed
= true;
11783 nbraces
+= bracecount
;
11786 save_break
= c_break_label
;
11787 if (code
== CILK_SIMD
)
11788 c_break_label
= build_int_cst (size_type_node
, 2);
11790 c_break_label
= size_one_node
;
11791 save_cont
= c_cont_label
;
11792 c_cont_label
= NULL_TREE
;
11793 body
= push_stmt_list ();
11795 if (open_brace_parsed
)
11797 location_t here
= c_parser_peek_token (parser
)->location
;
11798 stmt
= c_begin_compound_stmt (true);
11799 c_parser_compound_statement_nostart (parser
);
11800 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11803 add_stmt (c_parser_c99_block_statement (parser
));
11806 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11807 SET_EXPR_LOCATION (t
, loc
);
11811 body
= pop_stmt_list (body
);
11812 c_break_label
= save_break
;
11813 c_cont_label
= save_cont
;
11817 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11819 c_parser_consume_token (parser
);
11822 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11823 c_parser_consume_token (parser
);
11826 c_parser_error (parser
, "collapsed loops not perfectly nested");
11829 location_t here
= c_parser_peek_token (parser
)->location
;
11830 stmt
= c_begin_compound_stmt (true);
11832 c_parser_compound_statement_nostart (parser
);
11833 body
= c_end_compound_stmt (here
, stmt
, true);
11840 /* Only bother calling c_finish_omp_for if we haven't already generated
11841 an error from the initialization parsing. */
11844 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11845 incrv
, body
, NULL
);
11848 if (cclauses
!= NULL
11849 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11852 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11853 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11854 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11855 c
= &OMP_CLAUSE_CHAIN (*c
);
11858 for (i
= 0; i
< collapse
; i
++)
11859 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11862 c
= &OMP_CLAUSE_CHAIN (*c
);
11863 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11866 "iteration variable %qD should not be firstprivate",
11867 OMP_CLAUSE_DECL (*c
));
11868 *c
= OMP_CLAUSE_CHAIN (*c
);
11872 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11873 change it to shared (decl) in
11874 OMP_PARALLEL_CLAUSES. */
11875 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11876 OMP_CLAUSE_LASTPRIVATE
);
11877 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11878 if (code
== OMP_SIMD
)
11880 OMP_CLAUSE_CHAIN (l
)
11881 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11882 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
11886 OMP_CLAUSE_CHAIN (l
) = clauses
;
11889 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11893 OMP_FOR_CLAUSES (stmt
) = clauses
;
11898 while (!for_block
->is_empty ())
11900 /* FIXME diagnostics: LOC below should be the actual location of
11901 this particular for block. We need to build a list of
11902 locations to go along with FOR_BLOCK. */
11903 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11906 release_tree_vector (for_block
);
11910 /* Helper function for OpenMP parsing, split clauses and call
11911 finish_omp_clauses on each of the set of clauses afterwards. */
11914 omp_split_clauses (location_t loc
, enum tree_code code
,
11915 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11918 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11919 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11921 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11925 #pragma omp simd simd-clause[optseq] new-line
11928 LOC is the location of the #pragma token.
11931 #define OMP_SIMD_CLAUSE_MASK \
11932 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11933 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11934 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11935 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11941 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11942 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11944 tree block
, clauses
, ret
;
11946 strcat (p_name
, " simd");
11947 mask
|= OMP_SIMD_CLAUSE_MASK
;
11948 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11950 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11953 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11954 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11957 block
= c_begin_compound_stmt (true);
11958 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11959 block
= c_end_compound_stmt (loc
, block
, true);
11966 #pragma omp for for-clause[optseq] new-line
11970 #pragma omp for simd for-simd-clause[optseq] new-line
11973 LOC is the location of the #pragma token.
11976 #define OMP_FOR_CLAUSE_MASK \
11977 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11987 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11988 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11990 tree block
, clauses
, ret
;
11992 strcat (p_name
, " for");
11993 mask
|= OMP_FOR_CLAUSE_MASK
;
11995 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
11997 if (c_parser_next_token_is (parser
, CPP_NAME
))
11999 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12001 if (strcmp (p
, "simd") == 0)
12003 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12004 if (cclauses
== NULL
)
12005 cclauses
= cclauses_buf
;
12007 c_parser_consume_token (parser
);
12008 if (!flag_openmp
) /* flag_openmp_simd */
12009 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12010 block
= c_begin_compound_stmt (true);
12011 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12012 block
= c_end_compound_stmt (loc
, block
, true);
12013 if (ret
== NULL_TREE
)
12015 ret
= make_node (OMP_FOR
);
12016 TREE_TYPE (ret
) = void_type_node
;
12017 OMP_FOR_BODY (ret
) = block
;
12018 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12019 SET_EXPR_LOCATION (ret
, loc
);
12024 if (!flag_openmp
) /* flag_openmp_simd */
12026 c_parser_skip_to_pragma_eol (parser
);
12030 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12033 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12034 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12037 block
= c_begin_compound_stmt (true);
12038 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12039 block
= c_end_compound_stmt (loc
, block
, true);
12046 # pragma omp master new-line
12049 LOC is the location of the #pragma token.
12053 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12055 c_parser_skip_to_pragma_eol (parser
);
12056 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12060 # pragma omp ordered new-line
12063 LOC is the location of the #pragma itself.
12067 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12069 c_parser_skip_to_pragma_eol (parser
);
12070 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12076 { section-sequence }
12079 section-directive[opt] structured-block
12080 section-sequence section-directive structured-block
12082 SECTIONS_LOC is the location of the #pragma omp sections. */
12085 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12087 tree stmt
, substmt
;
12088 bool error_suppress
= false;
12091 loc
= c_parser_peek_token (parser
)->location
;
12092 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12094 /* Avoid skipping until the end of the block. */
12095 parser
->error
= false;
12099 stmt
= push_stmt_list ();
12101 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12103 substmt
= c_parser_omp_structured_block (parser
);
12104 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12105 SET_EXPR_LOCATION (substmt
, loc
);
12106 add_stmt (substmt
);
12111 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12113 if (c_parser_next_token_is (parser
, CPP_EOF
))
12116 loc
= c_parser_peek_token (parser
)->location
;
12117 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12119 c_parser_consume_pragma (parser
);
12120 c_parser_skip_to_pragma_eol (parser
);
12121 error_suppress
= false;
12123 else if (!error_suppress
)
12125 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12126 error_suppress
= true;
12129 substmt
= c_parser_omp_structured_block (parser
);
12130 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12131 SET_EXPR_LOCATION (substmt
, loc
);
12132 add_stmt (substmt
);
12134 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12135 "expected %<#pragma omp section%> or %<}%>");
12137 substmt
= pop_stmt_list (stmt
);
12139 stmt
= make_node (OMP_SECTIONS
);
12140 SET_EXPR_LOCATION (stmt
, sections_loc
);
12141 TREE_TYPE (stmt
) = void_type_node
;
12142 OMP_SECTIONS_BODY (stmt
) = substmt
;
12144 return add_stmt (stmt
);
12148 # pragma omp sections sections-clause[optseq] newline
12151 LOC is the location of the #pragma token.
12154 #define OMP_SECTIONS_CLAUSE_MASK \
12155 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12162 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12163 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12165 tree block
, clauses
, ret
;
12167 strcat (p_name
, " sections");
12168 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12170 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12172 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12175 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12176 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12179 block
= c_begin_compound_stmt (true);
12180 ret
= c_parser_omp_sections_scope (loc
, parser
);
12182 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12183 block
= c_end_compound_stmt (loc
, block
, true);
12190 # pragma omp parallel parallel-clause[optseq] new-line
12192 # pragma omp parallel for parallel-for-clause[optseq] new-line
12194 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12198 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12201 LOC is the location of the #pragma token.
12204 #define OMP_PARALLEL_CLAUSE_MASK \
12205 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12206 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12207 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12208 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12210 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12211 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12212 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12213 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12216 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12217 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12219 tree stmt
, clauses
, block
;
12221 strcat (p_name
, " parallel");
12222 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12224 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12226 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12227 if (cclauses
== NULL
)
12228 cclauses
= cclauses_buf
;
12230 c_parser_consume_token (parser
);
12231 if (!flag_openmp
) /* flag_openmp_simd */
12232 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12233 block
= c_begin_omp_parallel ();
12234 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12236 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12238 if (ret
== NULL_TREE
)
12240 OMP_PARALLEL_COMBINED (stmt
) = 1;
12245 error_at (loc
, "expected %<for%> after %qs", p_name
);
12246 c_parser_skip_to_pragma_eol (parser
);
12249 else if (!flag_openmp
) /* flag_openmp_simd */
12251 c_parser_skip_to_pragma_eol (parser
);
12254 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12256 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12257 if (strcmp (p
, "sections") == 0)
12259 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12260 if (cclauses
== NULL
)
12261 cclauses
= cclauses_buf
;
12263 c_parser_consume_token (parser
);
12264 block
= c_begin_omp_parallel ();
12265 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12266 stmt
= c_finish_omp_parallel (loc
,
12267 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12269 OMP_PARALLEL_COMBINED (stmt
) = 1;
12274 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12276 block
= c_begin_omp_parallel ();
12277 c_parser_statement (parser
);
12278 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12284 # pragma omp single single-clause[optseq] new-line
12287 LOC is the location of the #pragma.
12290 #define OMP_SINGLE_CLAUSE_MASK \
12291 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12294 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12297 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12299 tree stmt
= make_node (OMP_SINGLE
);
12300 SET_EXPR_LOCATION (stmt
, loc
);
12301 TREE_TYPE (stmt
) = void_type_node
;
12303 OMP_SINGLE_CLAUSES (stmt
)
12304 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12305 "#pragma omp single");
12306 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12308 return add_stmt (stmt
);
12312 # pragma omp task task-clause[optseq] new-line
12314 LOC is the location of the #pragma.
12317 #define OMP_TASK_CLAUSE_MASK \
12318 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12325 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12329 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12331 tree clauses
, block
;
12333 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12334 "#pragma omp task");
12336 block
= c_begin_omp_task ();
12337 c_parser_statement (parser
);
12338 return c_finish_omp_task (loc
, clauses
, block
);
12342 # pragma omp taskwait new-line
12346 c_parser_omp_taskwait (c_parser
*parser
)
12348 location_t loc
= c_parser_peek_token (parser
)->location
;
12349 c_parser_consume_pragma (parser
);
12350 c_parser_skip_to_pragma_eol (parser
);
12352 c_finish_omp_taskwait (loc
);
12356 # pragma omp taskyield new-line
12360 c_parser_omp_taskyield (c_parser
*parser
)
12362 location_t loc
= c_parser_peek_token (parser
)->location
;
12363 c_parser_consume_pragma (parser
);
12364 c_parser_skip_to_pragma_eol (parser
);
12366 c_finish_omp_taskyield (loc
);
12370 # pragma omp taskgroup new-line
12374 c_parser_omp_taskgroup (c_parser
*parser
)
12376 location_t loc
= c_parser_peek_token (parser
)->location
;
12377 c_parser_skip_to_pragma_eol (parser
);
12378 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12382 # pragma omp cancel cancel-clause[optseq] new-line
12384 LOC is the location of the #pragma.
12387 #define OMP_CANCEL_CLAUSE_MASK \
12388 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12389 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12391 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12392 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12395 c_parser_omp_cancel (c_parser
*parser
)
12397 location_t loc
= c_parser_peek_token (parser
)->location
;
12399 c_parser_consume_pragma (parser
);
12400 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12401 "#pragma omp cancel");
12403 c_finish_omp_cancel (loc
, clauses
);
12407 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12409 LOC is the location of the #pragma.
12412 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12413 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12414 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12415 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12416 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12419 c_parser_omp_cancellation_point (c_parser
*parser
)
12421 location_t loc
= c_parser_peek_token (parser
)->location
;
12423 bool point_seen
= false;
12425 c_parser_consume_pragma (parser
);
12426 if (c_parser_next_token_is (parser
, CPP_NAME
))
12428 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12429 if (strcmp (p
, "point") == 0)
12431 c_parser_consume_token (parser
);
12437 c_parser_error (parser
, "expected %<point%>");
12438 c_parser_skip_to_pragma_eol (parser
);
12443 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12444 "#pragma omp cancellation point");
12446 c_finish_omp_cancellation_point (loc
, clauses
);
12450 #pragma omp distribute distribute-clause[optseq] new-line
12453 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12454 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12455 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12456 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12457 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12460 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12461 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12463 tree clauses
, block
, ret
;
12465 strcat (p_name
, " distribute");
12466 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12468 if (c_parser_next_token_is (parser
, CPP_NAME
))
12470 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12472 bool parallel
= false;
12474 if (strcmp (p
, "simd") == 0)
12477 parallel
= strcmp (p
, "parallel") == 0;
12478 if (parallel
|| simd
)
12480 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12481 if (cclauses
== NULL
)
12482 cclauses
= cclauses_buf
;
12483 c_parser_consume_token (parser
);
12484 if (!flag_openmp
) /* flag_openmp_simd */
12487 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12489 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12492 block
= c_begin_compound_stmt (true);
12494 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12496 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12497 block
= c_end_compound_stmt (loc
, block
, true);
12500 ret
= make_node (OMP_DISTRIBUTE
);
12501 TREE_TYPE (ret
) = void_type_node
;
12502 OMP_FOR_BODY (ret
) = block
;
12503 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12504 SET_EXPR_LOCATION (ret
, loc
);
12509 if (!flag_openmp
) /* flag_openmp_simd */
12511 c_parser_skip_to_pragma_eol (parser
);
12515 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12518 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12519 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12522 block
= c_begin_compound_stmt (true);
12523 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12524 block
= c_end_compound_stmt (loc
, block
, true);
12531 # pragma omp teams teams-clause[optseq] new-line
12532 structured-block */
12534 #define OMP_TEAMS_CLAUSE_MASK \
12535 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12536 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12537 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12538 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12544 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12545 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12547 tree clauses
, block
, ret
;
12549 strcat (p_name
, " teams");
12550 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12552 if (c_parser_next_token_is (parser
, CPP_NAME
))
12554 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12555 if (strcmp (p
, "distribute") == 0)
12557 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12558 if (cclauses
== NULL
)
12559 cclauses
= cclauses_buf
;
12561 c_parser_consume_token (parser
);
12562 if (!flag_openmp
) /* flag_openmp_simd */
12563 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12564 block
= c_begin_compound_stmt (true);
12565 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12566 block
= c_end_compound_stmt (loc
, block
, true);
12569 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12570 ret
= make_node (OMP_TEAMS
);
12571 TREE_TYPE (ret
) = void_type_node
;
12572 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12573 OMP_TEAMS_BODY (ret
) = block
;
12574 return add_stmt (ret
);
12577 if (!flag_openmp
) /* flag_openmp_simd */
12579 c_parser_skip_to_pragma_eol (parser
);
12583 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12586 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12587 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12590 tree stmt
= make_node (OMP_TEAMS
);
12591 TREE_TYPE (stmt
) = void_type_node
;
12592 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12593 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12595 return add_stmt (stmt
);
12599 # pragma omp target data target-data-clause[optseq] new-line
12600 structured-block */
12602 #define OMP_TARGET_DATA_CLAUSE_MASK \
12603 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12608 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12610 tree stmt
= make_node (OMP_TARGET_DATA
);
12611 TREE_TYPE (stmt
) = void_type_node
;
12613 OMP_TARGET_DATA_CLAUSES (stmt
)
12614 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12615 "#pragma omp target data");
12616 keep_next_level ();
12617 tree block
= c_begin_compound_stmt (true);
12618 add_stmt (c_parser_omp_structured_block (parser
));
12619 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12621 SET_EXPR_LOCATION (stmt
, loc
);
12622 return add_stmt (stmt
);
12626 # pragma omp target update target-update-clause[optseq] new-line */
12628 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12629 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12630 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12635 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12636 enum pragma_context context
)
12638 if (context
== pragma_stmt
)
12641 "%<#pragma omp target update%> may only be "
12642 "used in compound statements");
12643 c_parser_skip_to_pragma_eol (parser
);
12648 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12649 "#pragma omp target update");
12650 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12651 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12654 "%<#pragma omp target update must contain at least one "
12655 "%<from%> or %<to%> clauses");
12659 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12660 TREE_TYPE (stmt
) = void_type_node
;
12661 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12662 SET_EXPR_LOCATION (stmt
, loc
);
12668 # pragma omp target target-clause[optseq] new-line
12669 structured-block */
12671 #define OMP_TARGET_CLAUSE_MASK \
12672 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12673 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12677 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12679 location_t loc
= c_parser_peek_token (parser
)->location
;
12680 c_parser_consume_pragma (parser
);
12682 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12684 c_parser_error (parser
, "expected declaration specifiers");
12685 c_parser_skip_to_pragma_eol (parser
);
12689 if (c_parser_next_token_is (parser
, CPP_NAME
))
12691 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12693 if (strcmp (p
, "teams") == 0)
12695 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12696 char p_name
[sizeof ("#pragma omp target teams distribute "
12697 "parallel for simd")];
12699 c_parser_consume_token (parser
);
12700 strcpy (p_name
, "#pragma omp target");
12701 if (!flag_openmp
) /* flag_openmp_simd */
12702 return c_parser_omp_teams (loc
, parser
, p_name
,
12703 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12704 keep_next_level ();
12705 tree block
= c_begin_compound_stmt (true);
12706 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12707 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12708 block
= c_end_compound_stmt (loc
, block
, true);
12711 tree stmt
= make_node (OMP_TARGET
);
12712 TREE_TYPE (stmt
) = void_type_node
;
12713 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12714 OMP_TARGET_BODY (stmt
) = block
;
12718 else if (!flag_openmp
) /* flag_openmp_simd */
12720 c_parser_skip_to_pragma_eol (parser
);
12723 else if (strcmp (p
, "data") == 0)
12725 c_parser_consume_token (parser
);
12726 c_parser_omp_target_data (loc
, parser
);
12729 else if (strcmp (p
, "update") == 0)
12731 c_parser_consume_token (parser
);
12732 return c_parser_omp_target_update (loc
, parser
, context
);
12736 tree stmt
= make_node (OMP_TARGET
);
12737 TREE_TYPE (stmt
) = void_type_node
;
12739 OMP_TARGET_CLAUSES (stmt
)
12740 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12741 "#pragma omp target");
12742 keep_next_level ();
12743 tree block
= c_begin_compound_stmt (true);
12744 add_stmt (c_parser_omp_structured_block (parser
));
12745 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12747 SET_EXPR_LOCATION (stmt
, loc
);
12753 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12755 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12756 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12764 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12766 vec
<c_token
> clauses
= vNULL
;
12767 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12769 c_token
*token
= c_parser_peek_token (parser
);
12770 if (token
->type
== CPP_EOF
)
12772 c_parser_skip_to_pragma_eol (parser
);
12773 clauses
.release ();
12776 clauses
.safe_push (*token
);
12777 c_parser_consume_token (parser
);
12779 clauses
.safe_push (*c_parser_peek_token (parser
));
12780 c_parser_skip_to_pragma_eol (parser
);
12782 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12784 if (c_parser_peek_token (parser
)->pragma_kind
12785 != PRAGMA_OMP_DECLARE_REDUCTION
12786 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12787 || strcmp (IDENTIFIER_POINTER
12788 (c_parser_peek_2nd_token (parser
)->value
),
12791 c_parser_error (parser
,
12792 "%<#pragma omp declare simd%> must be followed by "
12793 "function declaration or definition or another "
12794 "%<#pragma omp declare simd%>");
12795 clauses
.release ();
12798 c_parser_consume_pragma (parser
);
12799 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12801 c_token
*token
= c_parser_peek_token (parser
);
12802 if (token
->type
== CPP_EOF
)
12804 c_parser_skip_to_pragma_eol (parser
);
12805 clauses
.release ();
12808 clauses
.safe_push (*token
);
12809 c_parser_consume_token (parser
);
12811 clauses
.safe_push (*c_parser_peek_token (parser
));
12812 c_parser_skip_to_pragma_eol (parser
);
12815 /* Make sure nothing tries to read past the end of the tokens. */
12817 memset (&eof_token
, 0, sizeof (eof_token
));
12818 eof_token
.type
= CPP_EOF
;
12819 clauses
.safe_push (eof_token
);
12820 clauses
.safe_push (eof_token
);
12824 case pragma_external
:
12825 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12826 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12828 int ext
= disable_extension_diagnostics ();
12830 c_parser_consume_token (parser
);
12831 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12832 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12833 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12835 restore_extension_diagnostics (ext
);
12838 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12841 case pragma_struct
:
12843 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12844 "function declaration or definition");
12846 case pragma_compound
:
12848 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12849 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12851 int ext
= disable_extension_diagnostics ();
12853 c_parser_consume_token (parser
);
12854 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12855 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12856 if (c_parser_next_tokens_start_declaration (parser
))
12858 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12859 true, NULL
, clauses
);
12860 restore_extension_diagnostics (ext
);
12863 restore_extension_diagnostics (ext
);
12865 else if (c_parser_next_tokens_start_declaration (parser
))
12867 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12871 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12872 "function declaration or definition");
12875 gcc_unreachable ();
12877 clauses
.release ();
12880 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12881 and put that into "omp declare simd" attribute. */
12884 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12885 vec
<c_token
> clauses
)
12888 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12890 error ("%<#pragma omp declare simd%> cannot be used in the same "
12891 "function marked as a Cilk Plus SIMD-enabled function");
12892 vec_free (parser
->cilk_simd_fn_tokens
);
12896 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12897 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12898 has already processed the tokens. */
12899 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12901 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12903 error ("%<#pragma omp declare simd%> not immediately followed by "
12904 "a function declaration or definition");
12905 clauses
[0].type
= CPP_EOF
;
12908 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
12910 error_at (DECL_SOURCE_LOCATION (fndecl
),
12911 "%<#pragma omp declare simd%> not immediately followed by "
12912 "a single function declaration or definition");
12913 clauses
[0].type
= CPP_EOF
;
12917 if (parms
== NULL_TREE
)
12918 parms
= DECL_ARGUMENTS (fndecl
);
12920 unsigned int tokens_avail
= parser
->tokens_avail
;
12921 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12922 bool is_cilkplus_cilk_simd_fn
= false;
12924 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12926 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
12927 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
12928 is_cilkplus_cilk_simd_fn
= true;
12932 parser
->tokens
= clauses
.address ();
12933 parser
->tokens_avail
= clauses
.length ();
12936 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12937 while (parser
->tokens_avail
> 3)
12939 c_token
*token
= c_parser_peek_token (parser
);
12940 if (!is_cilkplus_cilk_simd_fn
)
12941 gcc_assert (token
->type
== CPP_NAME
12942 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12944 gcc_assert (token
->type
== CPP_NAME
12945 && is_cilkplus_vector_p (token
->value
));
12946 c_parser_consume_token (parser
);
12947 parser
->in_pragma
= true;
12949 tree c
= NULL_TREE
;
12950 if (is_cilkplus_cilk_simd_fn
)
12951 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
12952 "SIMD-enabled functions attribute");
12954 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12955 "#pragma omp declare simd");
12956 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12957 if (c
!= NULL_TREE
)
12958 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12959 if (is_cilkplus_cilk_simd_fn
)
12961 tree k
= build_tree_list (get_identifier ("cilk simd function"),
12963 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
12964 DECL_ATTRIBUTES (fndecl
) = k
;
12966 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12967 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12968 DECL_ATTRIBUTES (fndecl
) = c
;
12971 parser
->tokens
= &parser
->tokens_buf
[0];
12972 parser
->tokens_avail
= tokens_avail
;
12973 if (clauses
.exists ())
12974 clauses
[0].type
= CPP_PRAGMA
;
12976 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12977 vec_free (parser
->cilk_simd_fn_tokens
);
12982 # pragma omp declare target new-line
12983 declarations and definitions
12984 # pragma omp end declare target new-line */
12987 c_parser_omp_declare_target (c_parser
*parser
)
12989 c_parser_skip_to_pragma_eol (parser
);
12990 current_omp_declare_target_attribute
++;
12994 c_parser_omp_end_declare_target (c_parser
*parser
)
12996 location_t loc
= c_parser_peek_token (parser
)->location
;
12997 c_parser_consume_pragma (parser
);
12998 if (c_parser_next_token_is (parser
, CPP_NAME
)
12999 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13002 c_parser_consume_token (parser
);
13003 if (c_parser_next_token_is (parser
, CPP_NAME
)
13004 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13006 c_parser_consume_token (parser
);
13009 c_parser_error (parser
, "expected %<target%>");
13010 c_parser_skip_to_pragma_eol (parser
);
13016 c_parser_error (parser
, "expected %<declare%>");
13017 c_parser_skip_to_pragma_eol (parser
);
13020 c_parser_skip_to_pragma_eol (parser
);
13021 if (!current_omp_declare_target_attribute
)
13022 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13023 "%<#pragma omp declare target%>");
13025 current_omp_declare_target_attribute
--;
13030 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13031 initializer-clause[opt] new-line
13033 initializer-clause:
13034 initializer (omp_priv = initializer)
13035 initializer (function-name (argument-list)) */
13038 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13040 unsigned int tokens_avail
= 0, i
;
13041 vec
<tree
> types
= vNULL
;
13042 vec
<c_token
> clauses
= vNULL
;
13043 enum tree_code reduc_code
= ERROR_MARK
;
13044 tree reduc_id
= NULL_TREE
;
13046 location_t rloc
= c_parser_peek_token (parser
)->location
;
13048 if (context
== pragma_struct
|| context
== pragma_param
)
13050 error ("%<#pragma omp declare reduction%> not at file or block scope");
13054 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13057 switch (c_parser_peek_token (parser
)->type
)
13060 reduc_code
= PLUS_EXPR
;
13063 reduc_code
= MULT_EXPR
;
13066 reduc_code
= MINUS_EXPR
;
13069 reduc_code
= BIT_AND_EXPR
;
13072 reduc_code
= BIT_XOR_EXPR
;
13075 reduc_code
= BIT_IOR_EXPR
;
13078 reduc_code
= TRUTH_ANDIF_EXPR
;
13081 reduc_code
= TRUTH_ORIF_EXPR
;
13085 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13086 if (strcmp (p
, "min") == 0)
13088 reduc_code
= MIN_EXPR
;
13091 if (strcmp (p
, "max") == 0)
13093 reduc_code
= MAX_EXPR
;
13096 reduc_id
= c_parser_peek_token (parser
)->value
;
13099 c_parser_error (parser
,
13100 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13101 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13105 tree orig_reduc_id
, reduc_decl
;
13106 orig_reduc_id
= reduc_id
;
13107 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13108 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13109 c_parser_consume_token (parser
);
13111 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13116 location_t loc
= c_parser_peek_token (parser
)->location
;
13117 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13120 type
= groktypename (ctype
, NULL
, NULL
);
13121 if (type
== error_mark_node
)
13123 else if ((INTEGRAL_TYPE_P (type
)
13124 || TREE_CODE (type
) == REAL_TYPE
13125 || TREE_CODE (type
) == COMPLEX_TYPE
)
13126 && orig_reduc_id
== NULL_TREE
)
13127 error_at (loc
, "predeclared arithmetic type in "
13128 "%<#pragma omp declare reduction%>");
13129 else if (TREE_CODE (type
) == FUNCTION_TYPE
13130 || TREE_CODE (type
) == ARRAY_TYPE
)
13131 error_at (loc
, "function or array type in "
13132 "%<#pragma omp declare reduction%>");
13133 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13134 error_at (loc
, "const, volatile or restrict qualified type in "
13135 "%<#pragma omp declare reduction%>");
13139 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13140 if (comptypes (TREE_PURPOSE (t
), type
))
13142 error_at (loc
, "redeclaration of %qs "
13143 "%<#pragma omp declare reduction%> for "
13145 IDENTIFIER_POINTER (reduc_id
)
13146 + sizeof ("omp declare reduction ") - 1,
13149 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13151 error_at (ploc
, "previous %<#pragma omp declare "
13155 if (t
== NULL_TREE
)
13156 types
.safe_push (type
);
13158 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13159 c_parser_consume_token (parser
);
13167 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13168 || types
.is_empty ())
13171 clauses
.release ();
13175 c_token
*token
= c_parser_peek_token (parser
);
13176 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13178 c_parser_consume_token (parser
);
13180 c_parser_skip_to_pragma_eol (parser
);
13184 if (types
.length () > 1)
13186 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13188 c_token
*token
= c_parser_peek_token (parser
);
13189 if (token
->type
== CPP_EOF
)
13191 clauses
.safe_push (*token
);
13192 c_parser_consume_token (parser
);
13194 clauses
.safe_push (*c_parser_peek_token (parser
));
13195 c_parser_skip_to_pragma_eol (parser
);
13197 /* Make sure nothing tries to read past the end of the tokens. */
13199 memset (&eof_token
, 0, sizeof (eof_token
));
13200 eof_token
.type
= CPP_EOF
;
13201 clauses
.safe_push (eof_token
);
13202 clauses
.safe_push (eof_token
);
13205 int errs
= errorcount
;
13206 FOR_EACH_VEC_ELT (types
, i
, type
)
13208 tokens_avail
= parser
->tokens_avail
;
13209 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13210 if (!clauses
.is_empty ())
13212 parser
->tokens
= clauses
.address ();
13213 parser
->tokens_avail
= clauses
.length ();
13214 parser
->in_pragma
= true;
13217 bool nested
= current_function_decl
!= NULL_TREE
;
13219 c_push_function_context ();
13220 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13221 reduc_id
, default_function_type
);
13222 current_function_decl
= fndecl
;
13223 allocate_struct_function (fndecl
, true);
13225 tree stmt
= push_stmt_list ();
13226 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13227 warn about these. */
13228 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13229 get_identifier ("omp_out"), type
);
13230 DECL_ARTIFICIAL (omp_out
) = 1;
13231 DECL_CONTEXT (omp_out
) = fndecl
;
13232 pushdecl (omp_out
);
13233 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13234 get_identifier ("omp_in"), type
);
13235 DECL_ARTIFICIAL (omp_in
) = 1;
13236 DECL_CONTEXT (omp_in
) = fndecl
;
13238 struct c_expr combiner
= c_parser_expression (parser
);
13239 struct c_expr initializer
;
13240 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13242 initializer
.value
= error_mark_node
;
13243 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13245 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13246 && strcmp (IDENTIFIER_POINTER
13247 (c_parser_peek_token (parser
)->value
),
13248 "initializer") == 0)
13250 c_parser_consume_token (parser
);
13253 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13254 get_identifier ("omp_priv"), type
);
13255 DECL_ARTIFICIAL (omp_priv
) = 1;
13256 DECL_INITIAL (omp_priv
) = error_mark_node
;
13257 DECL_CONTEXT (omp_priv
) = fndecl
;
13258 pushdecl (omp_priv
);
13259 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13260 get_identifier ("omp_orig"), type
);
13261 DECL_ARTIFICIAL (omp_orig
) = 1;
13262 DECL_CONTEXT (omp_orig
) = fndecl
;
13263 pushdecl (omp_orig
);
13264 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13266 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13268 c_parser_error (parser
, "expected %<omp_priv%> or "
13272 else if (strcmp (IDENTIFIER_POINTER
13273 (c_parser_peek_token (parser
)->value
),
13276 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13277 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13279 c_parser_error (parser
, "expected function-name %<(%>");
13283 initializer
= c_parser_postfix_expression (parser
);
13284 if (initializer
.value
13285 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13288 tree c
= initializer
.value
;
13289 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13290 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13291 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13293 if (j
== call_expr_nargs (c
))
13294 error ("one of the initializer call arguments should be "
13300 c_parser_consume_token (parser
);
13301 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13305 tree st
= push_stmt_list ();
13306 start_init (omp_priv
, NULL_TREE
, 0);
13307 location_t loc
= c_parser_peek_token (parser
)->location
;
13308 struct c_expr init
= c_parser_initializer (parser
);
13310 finish_decl (omp_priv
, loc
, init
.value
,
13311 init
.original_type
, NULL_TREE
);
13312 pop_stmt_list (st
);
13316 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13322 c_parser_skip_to_pragma_eol (parser
);
13324 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13325 DECL_INITIAL (reduc_decl
));
13326 DECL_INITIAL (reduc_decl
) = t
;
13327 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13328 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13329 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13330 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13331 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13332 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13335 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13336 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13337 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13338 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13339 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13340 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13341 walk_tree (&DECL_INITIAL (omp_priv
),
13342 c_check_omp_declare_reduction_r
,
13343 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13347 pop_stmt_list (stmt
);
13349 if (cfun
->language
!= NULL
)
13351 ggc_free (cfun
->language
);
13352 cfun
->language
= NULL
;
13355 current_function_decl
= NULL_TREE
;
13357 c_pop_function_context ();
13359 if (!clauses
.is_empty ())
13361 parser
->tokens
= &parser
->tokens_buf
[0];
13362 parser
->tokens_avail
= tokens_avail
;
13366 if (errs
!= errorcount
)
13370 clauses
.release ();
13376 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13377 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13378 initializer-clause[opt] new-line
13379 #pragma omp declare target new-line */
13382 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13384 c_parser_consume_pragma (parser
);
13385 if (c_parser_next_token_is (parser
, CPP_NAME
))
13387 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13388 if (strcmp (p
, "simd") == 0)
13390 /* c_parser_consume_token (parser); done in
13391 c_parser_omp_declare_simd. */
13392 c_parser_omp_declare_simd (parser
, context
);
13395 if (strcmp (p
, "reduction") == 0)
13397 c_parser_consume_token (parser
);
13398 c_parser_omp_declare_reduction (parser
, context
);
13401 if (!flag_openmp
) /* flag_openmp_simd */
13403 c_parser_skip_to_pragma_eol (parser
);
13406 if (strcmp (p
, "target") == 0)
13408 c_parser_consume_token (parser
);
13409 c_parser_omp_declare_target (parser
);
13414 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13416 c_parser_skip_to_pragma_eol (parser
);
13419 /* Main entry point to parsing most OpenMP pragmas. */
13422 c_parser_omp_construct (c_parser
*parser
)
13424 enum pragma_kind p_kind
;
13427 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13428 omp_clause_mask
mask (0);
13430 loc
= c_parser_peek_token (parser
)->location
;
13431 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13432 c_parser_consume_pragma (parser
);
13436 case PRAGMA_OMP_ATOMIC
:
13437 c_parser_omp_atomic (loc
, parser
);
13439 case PRAGMA_OMP_CRITICAL
:
13440 stmt
= c_parser_omp_critical (loc
, parser
);
13442 case PRAGMA_OMP_DISTRIBUTE
:
13443 strcpy (p_name
, "#pragma omp");
13444 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13446 case PRAGMA_OMP_FOR
:
13447 strcpy (p_name
, "#pragma omp");
13448 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13450 case PRAGMA_OMP_MASTER
:
13451 stmt
= c_parser_omp_master (loc
, parser
);
13453 case PRAGMA_OMP_ORDERED
:
13454 stmt
= c_parser_omp_ordered (loc
, parser
);
13456 case PRAGMA_OMP_PARALLEL
:
13457 strcpy (p_name
, "#pragma omp");
13458 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13460 case PRAGMA_OMP_SECTIONS
:
13461 strcpy (p_name
, "#pragma omp");
13462 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13464 case PRAGMA_OMP_SIMD
:
13465 strcpy (p_name
, "#pragma omp");
13466 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13468 case PRAGMA_OMP_SINGLE
:
13469 stmt
= c_parser_omp_single (loc
, parser
);
13471 case PRAGMA_OMP_TASK
:
13472 stmt
= c_parser_omp_task (loc
, parser
);
13474 case PRAGMA_OMP_TASKGROUP
:
13475 stmt
= c_parser_omp_taskgroup (parser
);
13477 case PRAGMA_OMP_TEAMS
:
13478 strcpy (p_name
, "#pragma omp");
13479 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13482 gcc_unreachable ();
13486 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13491 # pragma omp threadprivate (variable-list) */
13494 c_parser_omp_threadprivate (c_parser
*parser
)
13499 c_parser_consume_pragma (parser
);
13500 loc
= c_parser_peek_token (parser
)->location
;
13501 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13503 /* Mark every variable in VARS to be assigned thread local storage. */
13504 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13506 tree v
= TREE_PURPOSE (t
);
13508 /* FIXME diagnostics: Ideally we should keep individual
13509 locations for all the variables in the var list to make the
13510 following errors more precise. Perhaps
13511 c_parser_omp_var_list_parens() should construct a list of
13512 locations to go along with the var list. */
13514 /* If V had already been marked threadprivate, it doesn't matter
13515 whether it had been used prior to this point. */
13516 if (TREE_CODE (v
) != VAR_DECL
)
13517 error_at (loc
, "%qD is not a variable", v
);
13518 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13519 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13520 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13521 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13522 else if (TREE_TYPE (v
) == error_mark_node
)
13524 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13525 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13528 if (! DECL_THREAD_LOCAL_P (v
))
13530 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13531 /* If rtl has been already set for this var, call
13532 make_decl_rtl once again, so that encode_section_info
13533 has a chance to look at the new decl flags. */
13534 if (DECL_RTL_SET_P (v
))
13537 C_DECL_THREADPRIVATE_P (v
) = 1;
13541 c_parser_skip_to_pragma_eol (parser
);
13544 /* Cilk Plus <#pragma simd> parsing routines. */
13546 /* Helper function for c_parser_pragma. Perform some sanity checking
13547 for <#pragma simd> constructs. Returns FALSE if there was a
13551 c_parser_cilk_verify_simd (c_parser
*parser
,
13552 enum pragma_context context
)
13554 if (!flag_cilkplus
)
13556 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13557 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13560 if (context
== pragma_external
)
13562 c_parser_error (parser
,"pragma simd must be inside a function");
13563 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13570 This function is shared by SIMD-enabled functions and #pragma simd.
13571 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13572 CLAUSES is unused. The main purpose of this function is to parse a
13573 vectorlength attribute or clause and check for parse errors.
13574 When IS_SIMD_FN is true then the function is merely caching the tokens
13575 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13576 cache is cleared since there is no reason to continue.
13578 vectorlength ( constant-expression ) */
13581 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13585 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13587 /* The vectorlength clause behaves exactly like OpenMP's safelen
13588 clause. Represent it in OpenMP terms. */
13589 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13591 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13594 location_t loc
= c_parser_peek_token (parser
)->location
;
13595 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13596 expr
= c_fully_fold (expr
, false, NULL
);
13598 /* If expr is an error_mark_node then the above function would have
13599 emitted an error. No reason to do it twice. */
13600 if (expr
== error_mark_node
)
13602 else if (!TREE_TYPE (expr
)
13603 || !TREE_CONSTANT (expr
)
13604 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13606 error_at (loc
, "vectorlength must be an integer constant");
13607 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13608 error_at (loc
, "vectorlength must be a power of 2");
13613 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13614 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13615 OMP_CLAUSE_CHAIN (u
) = clauses
;
13620 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13621 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13622 OMP_CLAUSE_CHAIN (u
) = clauses
;
13627 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13633 linear ( simd-linear-variable-list )
13635 simd-linear-variable-list:
13636 simd-linear-variable
13637 simd-linear-variable-list , simd-linear-variable
13639 simd-linear-variable:
13641 id-expression : simd-linear-step
13644 conditional-expression */
13647 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13649 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13652 location_t loc
= c_parser_peek_token (parser
)->location
;
13654 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13655 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13656 c_parser_error (parser
, "expected identifier");
13658 while (c_parser_next_token_is (parser
, CPP_NAME
)
13659 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13661 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13665 undeclared_variable (c_parser_peek_token (parser
)->location
,
13666 c_parser_peek_token (parser
)->value
);
13667 c_parser_consume_token (parser
);
13669 else if (var
== error_mark_node
)
13670 c_parser_consume_token (parser
);
13673 tree step
= integer_one_node
;
13675 /* Parse the linear step if present. */
13676 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13678 c_parser_consume_token (parser
);
13679 c_parser_consume_token (parser
);
13681 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13682 expr
= c_fully_fold (expr
, false, NULL
);
13684 if (TREE_TYPE (expr
)
13685 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13686 && (TREE_CONSTANT (expr
)
13690 c_parser_error (parser
,
13691 "step size must be an integer constant "
13692 "expression or an integer variable");
13695 c_parser_consume_token (parser
);
13697 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13698 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13699 OMP_CLAUSE_DECL (u
) = var
;
13700 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13701 OMP_CLAUSE_CHAIN (u
) = clauses
;
13705 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13708 c_parser_consume_token (parser
);
13711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13716 /* Returns the name of the next clause. If the clause is not
13717 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13718 not consumed. Otherwise, the appropriate pragma_simd_clause is
13719 returned and the token is consumed. */
13721 static pragma_omp_clause
13722 c_parser_cilk_clause_name (c_parser
*parser
)
13724 pragma_omp_clause result
;
13725 c_token
*token
= c_parser_peek_token (parser
);
13727 if (!token
->value
|| token
->type
!= CPP_NAME
)
13728 return PRAGMA_CILK_CLAUSE_NONE
;
13730 const char *p
= IDENTIFIER_POINTER (token
->value
);
13732 if (!strcmp (p
, "vectorlength"))
13733 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13734 else if (!strcmp (p
, "linear"))
13735 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13736 else if (!strcmp (p
, "private"))
13737 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13738 else if (!strcmp (p
, "firstprivate"))
13739 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13740 else if (!strcmp (p
, "lastprivate"))
13741 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13742 else if (!strcmp (p
, "reduction"))
13743 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13745 return PRAGMA_CILK_CLAUSE_NONE
;
13747 c_parser_consume_token (parser
);
13751 /* Parse all #<pragma simd> clauses. Return the list of clauses
13755 c_parser_cilk_all_clauses (c_parser
*parser
)
13757 tree clauses
= NULL
;
13759 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13761 pragma_omp_clause c_kind
;
13763 c_kind
= c_parser_cilk_clause_name (parser
);
13767 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13768 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13770 case PRAGMA_CILK_CLAUSE_LINEAR
:
13771 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13773 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13774 /* Use the OpenMP counterpart. */
13775 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13777 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13778 /* Use the OpenMP counterpart. */
13779 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13781 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13782 /* Use the OpenMP counterpart. */
13783 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13785 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13786 /* Use the OpenMP counterpart. */
13787 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13790 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13796 c_parser_skip_to_pragma_eol (parser
);
13797 return c_finish_cilk_clauses (clauses
);
13800 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13804 c_parser_cilk_simd (c_parser
*parser
)
13806 tree clauses
= c_parser_cilk_all_clauses (parser
);
13807 tree block
= c_begin_compound_stmt (true);
13808 location_t loc
= c_parser_peek_token (parser
)->location
;
13809 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13810 block
= c_end_compound_stmt (loc
, block
, true);
13814 /* Parse a transaction attribute (GCC Extension).
13816 transaction-attribute:
13820 The transactional memory language description is written for C++,
13821 and uses the C++0x attribute syntax. For compatibility, allow the
13822 bracket style for transactions in C as well. */
13825 c_parser_transaction_attributes (c_parser
*parser
)
13827 tree attr_name
, attr
= NULL
;
13829 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13830 return c_parser_attributes (parser
);
13832 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13834 c_parser_consume_token (parser
);
13835 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13838 attr_name
= c_parser_attribute_any_word (parser
);
13841 c_parser_consume_token (parser
);
13842 attr
= build_tree_list (attr_name
, NULL_TREE
);
13845 c_parser_error (parser
, "expected identifier");
13847 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13849 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13853 /* Parse a __transaction_atomic or __transaction_relaxed statement
13856 transaction-statement:
13857 __transaction_atomic transaction-attribute[opt] compound-statement
13858 __transaction_relaxed compound-statement
13860 Note that the only valid attribute is: "outer".
13864 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13866 unsigned int old_in
= parser
->in_transaction
;
13867 unsigned int this_in
= 1, new_in
;
13868 location_t loc
= c_parser_peek_token (parser
)->location
;
13871 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13872 || keyword
== RID_TRANSACTION_RELAXED
)
13873 && c_parser_next_token_is_keyword (parser
, keyword
));
13874 c_parser_consume_token (parser
);
13876 if (keyword
== RID_TRANSACTION_RELAXED
)
13877 this_in
|= TM_STMT_ATTR_RELAXED
;
13880 attrs
= c_parser_transaction_attributes (parser
);
13882 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13885 /* Keep track if we're in the lexical scope of an outer transaction. */
13886 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13888 parser
->in_transaction
= new_in
;
13889 stmt
= c_parser_compound_statement (parser
);
13890 parser
->in_transaction
= old_in
;
13893 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13895 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13896 "%<__transaction_atomic%> without transactional memory support enabled"
13897 : "%<__transaction_relaxed %> "
13898 "without transactional memory support enabled"));
13903 /* Parse a __transaction_atomic or __transaction_relaxed expression
13906 transaction-expression:
13907 __transaction_atomic ( expression )
13908 __transaction_relaxed ( expression )
13911 static struct c_expr
13912 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13915 unsigned int old_in
= parser
->in_transaction
;
13916 unsigned int this_in
= 1;
13917 location_t loc
= c_parser_peek_token (parser
)->location
;
13920 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13921 || keyword
== RID_TRANSACTION_RELAXED
)
13922 && c_parser_next_token_is_keyword (parser
, keyword
));
13923 c_parser_consume_token (parser
);
13925 if (keyword
== RID_TRANSACTION_RELAXED
)
13926 this_in
|= TM_STMT_ATTR_RELAXED
;
13929 attrs
= c_parser_transaction_attributes (parser
);
13931 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13934 parser
->in_transaction
= this_in
;
13935 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13937 tree expr
= c_parser_expression (parser
).value
;
13938 ret
.original_type
= TREE_TYPE (expr
);
13939 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13940 if (this_in
& TM_STMT_ATTR_RELAXED
)
13941 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13942 SET_EXPR_LOCATION (ret
.value
, loc
);
13943 ret
.original_code
= TRANSACTION_EXPR
;
13944 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13946 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13953 ret
.value
= error_mark_node
;
13954 ret
.original_code
= ERROR_MARK
;
13955 ret
.original_type
= NULL
;
13957 parser
->in_transaction
= old_in
;
13960 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13961 "%<__transaction_atomic%> without transactional memory support enabled"
13962 : "%<__transaction_relaxed %> "
13963 "without transactional memory support enabled"));
13968 /* Parse a __transaction_cancel statement (GCC Extension).
13970 transaction-cancel-statement:
13971 __transaction_cancel transaction-attribute[opt] ;
13973 Note that the only valid attribute is "outer".
13977 c_parser_transaction_cancel (c_parser
*parser
)
13979 location_t loc
= c_parser_peek_token (parser
)->location
;
13981 bool is_outer
= false;
13983 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13984 c_parser_consume_token (parser
);
13986 attrs
= c_parser_transaction_attributes (parser
);
13988 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13992 error_at (loc
, "%<__transaction_cancel%> without "
13993 "transactional memory support enabled");
13996 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
13998 error_at (loc
, "%<__transaction_cancel%> within a "
13999 "%<__transaction_relaxed%>");
14004 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14005 && !is_tm_may_cancel_outer (current_function_decl
))
14007 error_at (loc
, "outer %<__transaction_cancel%> not "
14008 "within outer %<__transaction_atomic%>");
14009 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14013 else if (parser
->in_transaction
== 0)
14015 error_at (loc
, "%<__transaction_cancel%> not within "
14016 "%<__transaction_atomic%>");
14020 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14023 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14026 /* Parse a single source file. */
14029 c_parse_file (void)
14031 /* Use local storage to begin. If the first token is a pragma, parse it.
14032 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14033 which will cause garbage collection. */
14036 memset (&tparser
, 0, sizeof tparser
);
14037 tparser
.tokens
= &tparser
.tokens_buf
[0];
14038 the_parser
= &tparser
;
14040 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14041 c_parser_pragma_pch_preprocess (&tparser
);
14043 the_parser
= ggc_alloc_c_parser ();
14044 *the_parser
= tparser
;
14045 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14046 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14048 /* Initialize EH, if we've been told to do so. */
14049 if (flag_exceptions
)
14050 using_eh_for_cleanups ();
14052 c_parser_translation_unit (the_parser
);
14056 /* This function parses Cilk Plus array notation. The starting index is
14057 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14058 return value of this function is a tree_node called VALUE_TREE of type
14059 ARRAY_NOTATION_REF. */
14062 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14065 c_token
*token
= NULL
;
14066 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14067 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14068 tree array_type_domain
= NULL_TREE
;
14070 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14072 /* No need to continue. If either of these 2 were true, then an error
14073 must be emitted already. Thus, no need to emit them twice. */
14074 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14075 return error_mark_node
;
14078 array_type
= TREE_TYPE (array_value
);
14079 gcc_assert (array_type
);
14080 type
= TREE_TYPE (array_type
);
14081 token
= c_parser_peek_token (parser
);
14083 if (token
->type
== CPP_EOF
)
14085 c_parser_error (parser
, "expected %<:%> or numeral");
14088 else if (token
->type
== CPP_COLON
)
14090 if (!initial_index
)
14092 /* If we are here, then we have a case like this A[:]. */
14093 c_parser_consume_token (parser
);
14094 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14096 error_at (loc
, "start-index and length fields necessary for "
14097 "using array notations in pointers");
14098 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14099 return error_mark_node
;
14101 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14103 error_at (loc
, "array notations cannot be used with function "
14105 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14106 return error_mark_node
;
14108 array_type_domain
= TYPE_DOMAIN (array_type
);
14110 if (!array_type_domain
)
14112 error_at (loc
, "start-index and length fields necessary for "
14113 "using array notations in dimensionless arrays");
14114 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14115 return error_mark_node
;
14118 start_index
= TYPE_MINVAL (array_type_domain
);
14119 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14121 if (!TYPE_MAXVAL (array_type_domain
)
14122 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14124 error_at (loc
, "start-index and length fields necessary for "
14125 "using array notations in variable-length arrays");
14126 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14127 return error_mark_node
;
14129 end_index
= TYPE_MAXVAL (array_type_domain
);
14130 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14131 end_index
, integer_one_node
);
14132 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14133 stride
= build_int_cst (integer_type_node
, 1);
14134 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14136 else if (initial_index
!= error_mark_node
)
14138 /* If we are here, then there should be 2 possibilities:
14139 1. Array [EXPR : EXPR]
14140 2. Array [EXPR : EXPR : EXPR]
14142 start_index
= initial_index
;
14144 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14146 error_at (loc
, "array notations cannot be used with function "
14148 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14149 return error_mark_node
;
14151 c_parser_consume_token (parser
); /* consume the ':' */
14152 struct c_expr ce
= c_parser_expression (parser
);
14153 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14154 end_index
= ce
.value
;
14155 if (!end_index
|| end_index
== error_mark_node
)
14157 c_parser_skip_to_end_of_block_or_statement (parser
);
14158 return error_mark_node
;
14160 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14162 c_parser_consume_token (parser
);
14163 ce
= c_parser_expression (parser
);
14164 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14166 if (!stride
|| stride
== error_mark_node
)
14168 c_parser_skip_to_end_of_block_or_statement (parser
);
14169 return error_mark_node
;
14174 c_parser_error (parser
, "expected array notation expression");
14177 c_parser_error (parser
, "expected array notation expression");
14179 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14181 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14182 end_index
, stride
, type
);
14183 if (value_tree
!= error_mark_node
)
14184 SET_EXPR_LOCATION (value_tree
, loc
);
14188 #include "gt-c-c-parser.h"