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 (init
, false, braced_init_obstack
);
4220 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4221 /* ??? Following the old parser, [ objc-receiver
4222 objc-message-args ] is accepted as an initializer,
4223 being distinguished from a designator by what follows
4224 the first assignment expression inside the square
4225 brackets, but after a first array designator a
4226 subsequent square bracket is for Objective-C taken to
4227 start an expression, using the obsolete form of
4228 designated initializer without '=', rather than
4229 possibly being a second level of designation: in LALR
4230 terms, the '[' is shifted rather than reducing
4231 designator to designator-list. */
4232 if (des_prev
== 1 && c_dialect_objc ())
4234 des_seen
= des_prev
;
4237 if (des_prev
== 0 && c_dialect_objc ())
4239 /* This might be an array designator or an
4240 Objective-C message expression. If the former,
4241 continue parsing here; if the latter, parse the
4242 remainder of the initializer given the starting
4243 primary-expression. ??? It might make sense to
4244 distinguish when des_prev == 1 as well; see
4245 previous comment. */
4247 struct c_expr mexpr
;
4248 c_parser_consume_token (parser
);
4249 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4250 && ((c_parser_peek_token (parser
)->id_kind
4252 || (c_parser_peek_token (parser
)->id_kind
4253 == C_ID_CLASSNAME
)))
4255 /* Type name receiver. */
4256 tree id
= c_parser_peek_token (parser
)->value
;
4257 c_parser_consume_token (parser
);
4258 rec
= objc_get_class_reference (id
);
4259 goto parse_message_args
;
4261 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4262 mark_exp_read (first
);
4263 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4264 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4265 goto array_desig_after_first
;
4266 /* Expression receiver. So far only one part
4267 without commas has been parsed; there might be
4268 more of the expression. */
4270 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4273 location_t comma_loc
, exp_loc
;
4274 comma_loc
= c_parser_peek_token (parser
)->location
;
4275 c_parser_consume_token (parser
);
4276 exp_loc
= c_parser_peek_token (parser
)->location
;
4277 next
= c_parser_expr_no_commas (parser
, NULL
);
4278 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4280 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4283 /* Now parse the objc-message-args. */
4284 args
= c_parser_objc_message_args (parser
);
4285 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4288 = objc_build_message_expr (rec
, args
);
4289 mexpr
.original_code
= ERROR_MARK
;
4290 mexpr
.original_type
= NULL
;
4291 /* Now parse and process the remainder of the
4292 initializer, starting with this message
4293 expression as a primary-expression. */
4294 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4297 c_parser_consume_token (parser
);
4298 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4299 mark_exp_read (first
);
4300 array_desig_after_first
:
4301 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4303 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4304 c_parser_consume_token (parser
);
4305 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4306 mark_exp_read (second
);
4310 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4312 c_parser_consume_token (parser
);
4313 set_init_index (first
, second
, braced_init_obstack
);
4315 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4316 "ISO C forbids specifying range of elements to initialize");
4319 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4325 if (c_parser_next_token_is (parser
, CPP_EQ
))
4328 pedwarn (des_loc
, OPT_Wpedantic
,
4329 "ISO C90 forbids specifying subobject to initialize");
4330 c_parser_consume_token (parser
);
4335 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4336 "obsolete use of designated initializer without %<=%>");
4340 init
.value
= error_mark_node
;
4341 init
.original_code
= ERROR_MARK
;
4342 init
.original_type
= NULL
;
4343 c_parser_error (parser
, "expected %<=%>");
4344 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4345 process_init_element (init
, false, braced_init_obstack
);
4351 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4354 /* Parse a nested initializer; as c_parser_initializer but parses
4355 initializers within braced lists, after any designators have been
4356 applied. If AFTER is not NULL then it is an Objective-C message
4357 expression which is the primary-expression starting the
4361 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4362 struct obstack
* braced_init_obstack
)
4365 gcc_assert (!after
|| c_dialect_objc ());
4366 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4367 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
4370 location_t loc
= c_parser_peek_token (parser
)->location
;
4371 init
= c_parser_expr_no_commas (parser
, after
);
4372 if (init
.value
!= NULL_TREE
4373 && TREE_CODE (init
.value
) != STRING_CST
4374 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4375 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4377 process_init_element (init
, false, braced_init_obstack
);
4380 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4384 { block-item-list[opt] }
4385 { label-declarations block-item-list }
4389 block-item-list block-item
4401 { label-declarations block-item-list }
4404 __extension__ nested-declaration
4405 nested-function-definition
4409 label-declarations label-declaration
4412 __label__ identifier-list ;
4414 Allowing the mixing of declarations and code is new in C99. The
4415 GNU syntax also permits (not shown above) labels at the end of
4416 compound statements, which yield an error. We don't allow labels
4417 on declarations; this might seem like a natural extension, but
4418 there would be a conflict between attributes on the label and
4419 prefix attributes on the declaration. ??? The syntax follows the
4420 old parser in requiring something after label declarations.
4421 Although they are erroneous if the labels declared aren't defined,
4422 is it useful for the syntax to be this way?
4435 cancellation-point-directive */
4438 c_parser_compound_statement (c_parser
*parser
)
4441 location_t brace_loc
;
4442 brace_loc
= c_parser_peek_token (parser
)->location
;
4443 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4445 /* Ensure a scope is entered and left anyway to avoid confusion
4446 if we have just prepared to enter a function body. */
4447 stmt
= c_begin_compound_stmt (true);
4448 c_end_compound_stmt (brace_loc
, stmt
, true);
4449 return error_mark_node
;
4451 stmt
= c_begin_compound_stmt (true);
4452 c_parser_compound_statement_nostart (parser
);
4454 /* If the compound stmt contains array notations, then we expand them. */
4455 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4456 stmt
= expand_array_notation_exprs (stmt
);
4457 return c_end_compound_stmt (brace_loc
, stmt
, true);
4460 /* Parse a compound statement except for the opening brace. This is
4461 used for parsing both compound statements and statement expressions
4462 (which follow different paths to handling the opening). */
4465 c_parser_compound_statement_nostart (c_parser
*parser
)
4467 bool last_stmt
= false;
4468 bool last_label
= false;
4469 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4470 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4471 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4473 c_parser_consume_token (parser
);
4476 mark_valid_location_for_stdc_pragma (true);
4477 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4479 /* Read zero or more forward-declarations for labels that nested
4480 functions can jump to. */
4481 mark_valid_location_for_stdc_pragma (false);
4482 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4484 label_loc
= c_parser_peek_token (parser
)->location
;
4485 c_parser_consume_token (parser
);
4486 /* Any identifiers, including those declared as type names,
4491 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4493 c_parser_error (parser
, "expected identifier");
4497 = declare_label (c_parser_peek_token (parser
)->value
);
4498 C_DECLARED_LABEL_FLAG (label
) = 1;
4499 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4500 c_parser_consume_token (parser
);
4501 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4502 c_parser_consume_token (parser
);
4506 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4508 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4510 /* We must now have at least one statement, label or declaration. */
4511 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4513 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4514 c_parser_error (parser
, "expected declaration or statement");
4515 c_parser_consume_token (parser
);
4518 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4520 location_t loc
= c_parser_peek_token (parser
)->location
;
4521 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4522 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4523 || (c_parser_next_token_is (parser
, CPP_NAME
)
4524 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4526 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4527 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4529 label_loc
= c_parser_peek_token (parser
)->location
;
4532 mark_valid_location_for_stdc_pragma (false);
4533 c_parser_label (parser
);
4535 else if (!last_label
4536 && c_parser_next_tokens_start_declaration (parser
))
4539 mark_valid_location_for_stdc_pragma (false);
4540 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4544 (pedantic
&& !flag_isoc99
)
4546 : OPT_Wdeclaration_after_statement
,
4547 "ISO C90 forbids mixed declarations and code");
4550 else if (!last_label
4551 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4553 /* __extension__ can start a declaration, but is also an
4554 unary operator that can start an expression. Consume all
4555 but the last of a possible series of __extension__ to
4557 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4558 && (c_parser_peek_2nd_token (parser
)->keyword
4560 c_parser_consume_token (parser
);
4561 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4564 ext
= disable_extension_diagnostics ();
4565 c_parser_consume_token (parser
);
4567 mark_valid_location_for_stdc_pragma (false);
4568 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4570 /* Following the old parser, __extension__ does not
4571 disable this diagnostic. */
4572 restore_extension_diagnostics (ext
);
4574 pedwarn_c90 (loc
, (pedantic
&& !flag_isoc99
)
4576 : OPT_Wdeclaration_after_statement
,
4577 "ISO C90 forbids mixed declarations and code");
4583 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4585 /* External pragmas, and some omp pragmas, are not associated
4586 with regular c code, and so are not to be considered statements
4587 syntactically. This ensures that the user doesn't put them
4588 places that would turn into syntax errors if the directive
4590 if (c_parser_pragma (parser
, pragma_compound
))
4591 last_label
= false, last_stmt
= true;
4593 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4595 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4596 c_parser_error (parser
, "expected declaration or statement");
4599 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4601 if (parser
->in_if_block
)
4603 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4604 error_at (loc
, """expected %<}%> before %<else%>");
4609 error_at (loc
, "%<else%> without a previous %<if%>");
4610 c_parser_consume_token (parser
);
4619 mark_valid_location_for_stdc_pragma (false);
4620 c_parser_statement_after_labels (parser
);
4623 parser
->error
= false;
4626 error_at (label_loc
, "label at end of compound statement");
4627 c_parser_consume_token (parser
);
4628 /* Restore the value we started with. */
4629 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4632 /* Parse a label (C90 6.6.1, C99 6.8.1).
4635 identifier : attributes[opt]
4636 case constant-expression :
4642 case constant-expression ... constant-expression :
4644 The use of attributes on labels is a GNU extension. The syntax in
4645 GNU C accepts any expressions without commas, non-constant
4646 expressions being rejected later. */
4649 c_parser_label (c_parser
*parser
)
4651 location_t loc1
= c_parser_peek_token (parser
)->location
;
4652 tree label
= NULL_TREE
;
4653 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4656 c_parser_consume_token (parser
);
4657 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4658 if (c_parser_next_token_is (parser
, CPP_COLON
))
4660 c_parser_consume_token (parser
);
4661 label
= do_case (loc1
, exp1
, NULL_TREE
);
4663 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4665 c_parser_consume_token (parser
);
4666 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4667 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4668 label
= do_case (loc1
, exp1
, exp2
);
4671 c_parser_error (parser
, "expected %<:%> or %<...%>");
4673 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4675 c_parser_consume_token (parser
);
4676 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4677 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4681 tree name
= c_parser_peek_token (parser
)->value
;
4684 location_t loc2
= c_parser_peek_token (parser
)->location
;
4685 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4686 c_parser_consume_token (parser
);
4687 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4688 c_parser_consume_token (parser
);
4689 attrs
= c_parser_attributes (parser
);
4690 tlab
= define_label (loc2
, name
);
4693 decl_attributes (&tlab
, attrs
, 0);
4694 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4699 if (c_parser_next_tokens_start_declaration (parser
))
4701 error_at (c_parser_peek_token (parser
)->location
,
4702 "a label can only be part of a statement and "
4703 "a declaration is not a statement");
4704 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4705 /*static_assert_ok*/ true,
4706 /*empty_ok*/ true, /*nested*/ true,
4707 /*start_attr_ok*/ true, NULL
,
4713 /* Parse a statement (C90 6.6, C99 6.8).
4718 expression-statement
4726 expression-statement:
4729 selection-statement:
4733 iteration-statement:
4742 return expression[opt] ;
4755 objc-throw-statement
4756 objc-try-catch-statement
4757 objc-synchronized-statement
4759 objc-throw-statement:
4775 parallel-for-construct
4776 parallel-for-simd-construct
4777 parallel-sections-construct
4784 parallel-directive structured-block
4787 for-directive iteration-statement
4790 simd-directive iteration-statements
4793 for-simd-directive iteration-statements
4796 sections-directive section-scope
4799 single-directive structured-block
4801 parallel-for-construct:
4802 parallel-for-directive iteration-statement
4804 parallel-for-simd-construct:
4805 parallel-for-simd-directive iteration-statement
4807 parallel-sections-construct:
4808 parallel-sections-directive section-scope
4811 master-directive structured-block
4814 critical-directive structured-block
4817 atomic-directive expression-statement
4820 ordered-directive structured-block
4822 Transactional Memory:
4825 transaction-statement
4826 transaction-cancel-statement
4830 c_parser_statement (c_parser
*parser
)
4832 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4833 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4834 || (c_parser_next_token_is (parser
, CPP_NAME
)
4835 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4836 c_parser_label (parser
);
4837 c_parser_statement_after_labels (parser
);
4840 /* Parse a statement, other than a labeled statement. */
4843 c_parser_statement_after_labels (c_parser
*parser
)
4845 location_t loc
= c_parser_peek_token (parser
)->location
;
4846 tree stmt
= NULL_TREE
;
4847 bool in_if_block
= parser
->in_if_block
;
4848 parser
->in_if_block
= false;
4849 switch (c_parser_peek_token (parser
)->type
)
4851 case CPP_OPEN_BRACE
:
4852 add_stmt (c_parser_compound_statement (parser
));
4855 switch (c_parser_peek_token (parser
)->keyword
)
4858 c_parser_if_statement (parser
);
4861 c_parser_switch_statement (parser
);
4864 c_parser_while_statement (parser
, false);
4867 c_parser_do_statement (parser
, false);
4870 c_parser_for_statement (parser
, false);
4873 c_parser_consume_token (parser
);
4874 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4876 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
4878 add_stmt (build_cilk_sync ());
4881 c_parser_consume_token (parser
);
4882 if (c_parser_next_token_is (parser
, CPP_NAME
))
4884 stmt
= c_finish_goto_label (loc
,
4885 c_parser_peek_token (parser
)->value
);
4886 c_parser_consume_token (parser
);
4888 else if (c_parser_next_token_is (parser
, CPP_MULT
))
4892 c_parser_consume_token (parser
);
4893 val
= c_parser_expression (parser
);
4894 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
4895 stmt
= c_finish_goto_ptr (loc
, val
.value
);
4898 c_parser_error (parser
, "expected identifier or %<*%>");
4899 goto expect_semicolon
;
4901 c_parser_consume_token (parser
);
4902 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
4903 goto expect_semicolon
;
4905 c_parser_consume_token (parser
);
4906 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
4907 goto expect_semicolon
;
4909 c_parser_consume_token (parser
);
4910 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4912 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
4913 c_parser_consume_token (parser
);
4917 struct c_expr expr
= c_parser_expression_conv (parser
);
4918 mark_exp_read (expr
.value
);
4919 stmt
= c_finish_return (loc
, expr
.value
, expr
.original_type
);
4920 goto expect_semicolon
;
4924 stmt
= c_parser_asm_statement (parser
);
4926 case RID_TRANSACTION_ATOMIC
:
4927 case RID_TRANSACTION_RELAXED
:
4928 stmt
= c_parser_transaction (parser
,
4929 c_parser_peek_token (parser
)->keyword
);
4931 case RID_TRANSACTION_CANCEL
:
4932 stmt
= c_parser_transaction_cancel (parser
);
4933 goto expect_semicolon
;
4935 gcc_assert (c_dialect_objc ());
4936 c_parser_consume_token (parser
);
4937 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4939 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
4940 c_parser_consume_token (parser
);
4944 struct c_expr expr
= c_parser_expression (parser
);
4945 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
4946 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
4947 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
4948 goto expect_semicolon
;
4952 gcc_assert (c_dialect_objc ());
4953 c_parser_objc_try_catch_finally_statement (parser
);
4955 case RID_AT_SYNCHRONIZED
:
4956 gcc_assert (c_dialect_objc ());
4957 c_parser_objc_synchronized_statement (parser
);
4964 c_parser_consume_token (parser
);
4966 case CPP_CLOSE_PAREN
:
4967 case CPP_CLOSE_SQUARE
:
4968 /* Avoid infinite loop in error recovery:
4969 c_parser_skip_until_found stops at a closing nesting
4970 delimiter without consuming it, but here we need to consume
4971 it to proceed further. */
4972 c_parser_error (parser
, "expected statement");
4973 c_parser_consume_token (parser
);
4976 c_parser_pragma (parser
, pragma_stmt
);
4980 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
4982 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4985 /* Two cases cannot and do not have line numbers associated: If stmt
4986 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
4987 cannot hold line numbers. But that's OK because the statement
4988 will either be changed to a MODIFY_EXPR during gimplification of
4989 the statement expr, or discarded. If stmt was compound, but
4990 without new variables, we will have skipped the creation of a
4991 BIND and will have a bare STATEMENT_LIST. But that's OK because
4992 (recursively) all of the component statements should already have
4993 line numbers assigned. ??? Can we discard no-op statements
4995 if (CAN_HAVE_LOCATION_P (stmt
)
4996 && EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
4997 SET_EXPR_LOCATION (stmt
, loc
);
4999 parser
->in_if_block
= in_if_block
;
5002 /* Parse the condition from an if, do, while or for statements. */
5005 c_parser_condition (c_parser
*parser
)
5007 location_t loc
= c_parser_peek_token (parser
)->location
;
5009 cond
= c_parser_expression_conv (parser
).value
;
5010 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5011 cond
= c_fully_fold (cond
, false, NULL
);
5012 if (warn_sequence_point
)
5013 verify_sequence_points (cond
);
5017 /* Parse a parenthesized condition from an if, do or while statement.
5023 c_parser_paren_condition (c_parser
*parser
)
5026 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5027 return error_mark_node
;
5028 cond
= c_parser_condition (parser
);
5029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5033 /* Parse a statement which is a block in C99. */
5036 c_parser_c99_block_statement (c_parser
*parser
)
5038 tree block
= c_begin_compound_stmt (flag_isoc99
);
5039 location_t loc
= c_parser_peek_token (parser
)->location
;
5040 c_parser_statement (parser
);
5041 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5044 /* Parse the body of an if statement. This is just parsing a
5045 statement but (a) it is a block in C99, (b) we track whether the
5046 body is an if statement for the sake of -Wparentheses warnings, (c)
5047 we handle an empty body specially for the sake of -Wempty-body
5048 warnings, and (d) we call parser_compound_statement directly
5049 because c_parser_statement_after_labels resets
5050 parser->in_if_block. */
5053 c_parser_if_body (c_parser
*parser
, bool *if_p
)
5055 tree block
= c_begin_compound_stmt (flag_isoc99
);
5056 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5057 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5058 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5059 || (c_parser_next_token_is (parser
, CPP_NAME
)
5060 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5061 c_parser_label (parser
);
5062 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
5063 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5065 location_t loc
= c_parser_peek_token (parser
)->location
;
5066 add_stmt (build_empty_stmt (loc
));
5067 c_parser_consume_token (parser
);
5068 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5069 warning_at (loc
, OPT_Wempty_body
,
5070 "suggest braces around empty body in an %<if%> statement");
5072 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5073 add_stmt (c_parser_compound_statement (parser
));
5075 c_parser_statement_after_labels (parser
);
5076 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5079 /* Parse the else body of an if statement. This is just parsing a
5080 statement but (a) it is a block in C99, (b) we handle an empty body
5081 specially for the sake of -Wempty-body warnings. */
5084 c_parser_else_body (c_parser
*parser
)
5086 location_t else_loc
= c_parser_peek_token (parser
)->location
;
5087 tree block
= c_begin_compound_stmt (flag_isoc99
);
5088 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5089 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5090 || (c_parser_next_token_is (parser
, CPP_NAME
)
5091 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5092 c_parser_label (parser
);
5093 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5095 location_t loc
= c_parser_peek_token (parser
)->location
;
5098 "suggest braces around empty body in an %<else%> statement");
5099 add_stmt (build_empty_stmt (loc
));
5100 c_parser_consume_token (parser
);
5103 c_parser_statement_after_labels (parser
);
5104 return c_end_compound_stmt (else_loc
, block
, flag_isoc99
);
5107 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5110 if ( expression ) statement
5111 if ( expression ) statement else statement
5115 c_parser_if_statement (c_parser
*parser
)
5120 bool first_if
= false;
5121 tree first_body
, second_body
;
5125 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5126 c_parser_consume_token (parser
);
5127 block
= c_begin_compound_stmt (flag_isoc99
);
5128 loc
= c_parser_peek_token (parser
)->location
;
5129 cond
= c_parser_paren_condition (parser
);
5130 in_if_block
= parser
->in_if_block
;
5131 parser
->in_if_block
= true;
5132 first_body
= c_parser_if_body (parser
, &first_if
);
5133 parser
->in_if_block
= in_if_block
;
5134 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5136 c_parser_consume_token (parser
);
5137 second_body
= c_parser_else_body (parser
);
5140 second_body
= NULL_TREE
;
5141 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
5142 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5144 /* If the if statement contains array notations, then we expand them. */
5145 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5146 if_stmt
= fix_conditional_array_notations (if_stmt
);
5150 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5153 switch (expression) statement
5157 c_parser_switch_statement (c_parser
*parser
)
5160 tree block
, expr
, body
, save_break
;
5161 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5162 location_t switch_cond_loc
;
5163 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5164 c_parser_consume_token (parser
);
5165 block
= c_begin_compound_stmt (flag_isoc99
);
5166 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5168 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5169 ce
= c_parser_expression (parser
);
5170 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5172 if (flag_cilkplus
&& contains_array_notation_expr (expr
))
5174 error_at (switch_cond_loc
,
5175 "array notations cannot be used as a condition for switch "
5177 expr
= error_mark_node
;
5179 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5183 switch_cond_loc
= UNKNOWN_LOCATION
;
5184 expr
= error_mark_node
;
5186 c_start_case (switch_loc
, switch_cond_loc
, expr
);
5187 save_break
= c_break_label
;
5188 c_break_label
= NULL_TREE
;
5189 body
= c_parser_c99_block_statement (parser
);
5190 c_finish_case (body
);
5193 location_t here
= c_parser_peek_token (parser
)->location
;
5194 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5195 SET_EXPR_LOCATION (t
, here
);
5198 c_break_label
= save_break
;
5199 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5202 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5205 while (expression) statement
5209 c_parser_while_statement (c_parser
*parser
, bool ivdep
)
5211 tree block
, cond
, body
, save_break
, save_cont
;
5213 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5214 c_parser_consume_token (parser
);
5215 block
= c_begin_compound_stmt (flag_isoc99
);
5216 loc
= c_parser_peek_token (parser
)->location
;
5217 cond
= c_parser_paren_condition (parser
);
5218 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5220 error_at (loc
, "array notations cannot be used as a condition for while "
5222 cond
= error_mark_node
;
5225 if (ivdep
&& cond
!= error_mark_node
)
5226 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5227 build_int_cst (integer_type_node
,
5228 annot_expr_ivdep_kind
));
5229 save_break
= c_break_label
;
5230 c_break_label
= NULL_TREE
;
5231 save_cont
= c_cont_label
;
5232 c_cont_label
= NULL_TREE
;
5233 body
= c_parser_c99_block_statement (parser
);
5234 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5235 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5236 c_break_label
= save_break
;
5237 c_cont_label
= save_cont
;
5240 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5243 do statement while ( expression ) ;
5247 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5249 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5251 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5252 c_parser_consume_token (parser
);
5253 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5254 warning_at (c_parser_peek_token (parser
)->location
,
5256 "suggest braces around empty body in %<do%> statement");
5257 block
= c_begin_compound_stmt (flag_isoc99
);
5258 loc
= c_parser_peek_token (parser
)->location
;
5259 save_break
= c_break_label
;
5260 c_break_label
= NULL_TREE
;
5261 save_cont
= c_cont_label
;
5262 c_cont_label
= NULL_TREE
;
5263 body
= c_parser_c99_block_statement (parser
);
5264 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5265 new_break
= c_break_label
;
5266 c_break_label
= save_break
;
5267 new_cont
= c_cont_label
;
5268 c_cont_label
= save_cont
;
5269 cond
= c_parser_paren_condition (parser
);
5270 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5272 error_at (loc
, "array notations cannot be used as a condition for a "
5273 "do-while statement");
5274 cond
= error_mark_node
;
5276 if (ivdep
&& cond
!= error_mark_node
)
5277 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5278 build_int_cst (integer_type_node
,
5279 annot_expr_ivdep_kind
));
5280 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5281 c_parser_skip_to_end_of_block_or_statement (parser
);
5282 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5283 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5286 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5289 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5290 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5292 The form with a declaration is new in C99.
5294 ??? In accordance with the old parser, the declaration may be a
5295 nested function, which is then rejected in check_for_loop_decls,
5296 but does it make any sense for this to be included in the grammar?
5297 Note in particular that the nested function does not include a
5298 trailing ';', whereas the "declaration" production includes one.
5299 Also, can we reject bad declarations earlier and cheaper than
5300 check_for_loop_decls?
5302 In Objective-C, there are two additional variants:
5305 for ( expression in expresssion ) statement
5306 for ( declaration in expression ) statement
5308 This is inconsistent with C, because the second variant is allowed
5309 even if c99 is not enabled.
5311 The rest of the comment documents these Objective-C foreach-statement.
5313 Here is the canonical example of the first variant:
5314 for (object in array) { do something with object }
5315 we call the first expression ("object") the "object_expression" and
5316 the second expression ("array") the "collection_expression".
5317 object_expression must be an lvalue of type "id" (a generic Objective-C
5318 object) because the loop works by assigning to object_expression the
5319 various objects from the collection_expression. collection_expression
5320 must evaluate to something of type "id" which responds to the method
5321 countByEnumeratingWithState:objects:count:.
5323 The canonical example of the second variant is:
5324 for (id object in array) { do something with object }
5325 which is completely equivalent to
5328 for (object in array) { do something with object }
5330 Note that initizializing 'object' in some way (eg, "for ((object =
5331 xxx) in array) { do something with object }") is possibly
5332 technically valid, but completely pointless as 'object' will be
5333 assigned to something else as soon as the loop starts. We should
5334 most likely reject it (TODO).
5336 The beginning of the Objective-C foreach-statement looks exactly
5337 like the beginning of the for-statement, and we can tell it is a
5338 foreach-statement only because the initial declaration or
5339 expression is terminated by 'in' instead of ';'.
5343 c_parser_for_statement (c_parser
*parser
, bool ivdep
)
5345 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5346 /* The following are only used when parsing an ObjC foreach statement. */
5347 tree object_expression
;
5348 /* Silence the bogus uninitialized warning. */
5349 tree collection_expression
= NULL
;
5350 location_t loc
= c_parser_peek_token (parser
)->location
;
5351 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5352 bool is_foreach_statement
= false;
5353 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5354 c_parser_consume_token (parser
);
5355 /* Open a compound statement in Objective-C as well, just in case this is
5356 as foreach expression. */
5357 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5358 cond
= error_mark_node
;
5359 incr
= error_mark_node
;
5360 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5362 /* Parse the initialization declaration or expression. */
5363 object_expression
= error_mark_node
;
5364 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5365 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5367 parser
->objc_could_be_foreach_context
= false;
5368 c_parser_consume_token (parser
);
5369 c_finish_expr_stmt (loc
, NULL_TREE
);
5371 else if (c_parser_next_tokens_start_declaration (parser
))
5373 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5374 &object_expression
, vNULL
);
5375 parser
->objc_could_be_foreach_context
= false;
5377 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5379 c_parser_consume_token (parser
);
5380 is_foreach_statement
= true;
5381 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5382 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5385 check_for_loop_decls (for_loc
, flag_isoc99
);
5387 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5389 /* __extension__ can start a declaration, but is also an
5390 unary operator that can start an expression. Consume all
5391 but the last of a possible series of __extension__ to
5393 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5394 && (c_parser_peek_2nd_token (parser
)->keyword
5396 c_parser_consume_token (parser
);
5397 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5400 ext
= disable_extension_diagnostics ();
5401 c_parser_consume_token (parser
);
5402 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5403 true, &object_expression
, vNULL
);
5404 parser
->objc_could_be_foreach_context
= false;
5406 restore_extension_diagnostics (ext
);
5407 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5409 c_parser_consume_token (parser
);
5410 is_foreach_statement
= true;
5411 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5412 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5415 check_for_loop_decls (for_loc
, flag_isoc99
);
5425 tree init_expression
;
5426 ce
= c_parser_expression (parser
);
5427 init_expression
= ce
.value
;
5428 parser
->objc_could_be_foreach_context
= false;
5429 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5431 c_parser_consume_token (parser
);
5432 is_foreach_statement
= true;
5433 if (! lvalue_p (init_expression
))
5434 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5435 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5439 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5440 init_expression
= ce
.value
;
5441 c_finish_expr_stmt (loc
, init_expression
);
5442 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5446 /* Parse the loop condition. In the case of a foreach
5447 statement, there is no loop condition. */
5448 gcc_assert (!parser
->objc_could_be_foreach_context
);
5449 if (!is_foreach_statement
)
5451 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5455 c_parser_error (parser
, "missing loop condition in loop with "
5456 "%<GCC ivdep%> pragma");
5457 cond
= error_mark_node
;
5461 c_parser_consume_token (parser
);
5467 cond
= c_parser_condition (parser
);
5468 if (flag_cilkplus
&& contains_array_notation_expr (cond
))
5470 error_at (loc
, "array notations cannot be used in a "
5471 "condition for a for-loop");
5472 cond
= error_mark_node
;
5474 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5477 if (ivdep
&& cond
!= error_mark_node
)
5478 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5479 build_int_cst (integer_type_node
,
5480 annot_expr_ivdep_kind
));
5482 /* Parse the increment expression (the third expression in a
5483 for-statement). In the case of a foreach-statement, this is
5484 the expression that follows the 'in'. */
5485 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5487 if (is_foreach_statement
)
5489 c_parser_error (parser
, "missing collection in fast enumeration");
5490 collection_expression
= error_mark_node
;
5493 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
5497 if (is_foreach_statement
)
5498 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
5502 struct c_expr ce
= c_parser_expression (parser
);
5503 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5504 incr
= c_process_expr_stmt (loc
, ce
.value
);
5507 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5509 save_break
= c_break_label
;
5510 c_break_label
= NULL_TREE
;
5511 save_cont
= c_cont_label
;
5512 c_cont_label
= NULL_TREE
;
5513 body
= c_parser_c99_block_statement (parser
);
5514 if (is_foreach_statement
)
5515 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
5517 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
5518 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
5519 c_break_label
= save_break
;
5520 c_cont_label
= save_cont
;
5523 /* Parse an asm statement, a GNU extension. This is a full-blown asm
5524 statement with inputs, outputs, clobbers, and volatile tag
5528 asm type-qualifier[opt] ( asm-argument ) ;
5529 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
5533 asm-string-literal : asm-operands[opt]
5534 asm-string-literal : asm-operands[opt] : asm-operands[opt]
5535 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
5538 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
5541 Qualifiers other than volatile are accepted in the syntax but
5545 c_parser_asm_statement (c_parser
*parser
)
5547 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
5548 bool simple
, is_goto
;
5549 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
5550 int section
, nsections
;
5552 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
5553 c_parser_consume_token (parser
);
5554 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
5556 quals
= c_parser_peek_token (parser
)->value
;
5557 c_parser_consume_token (parser
);
5559 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
5560 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
5562 warning_at (c_parser_peek_token (parser
)->location
,
5564 "%E qualifier ignored on asm",
5565 c_parser_peek_token (parser
)->value
);
5567 c_parser_consume_token (parser
);
5573 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
5575 c_parser_consume_token (parser
);
5579 /* ??? Follow the C++ parser rather than using the
5580 lex_untranslated_string kludge. */
5581 parser
->lex_untranslated_string
= true;
5584 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5587 str
= c_parser_asm_string_literal (parser
);
5588 if (str
== NULL_TREE
)
5589 goto error_close_paren
;
5592 outputs
= NULL_TREE
;
5594 clobbers
= NULL_TREE
;
5597 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5600 /* Parse each colon-delimited section of operands. */
5601 nsections
= 3 + is_goto
;
5602 for (section
= 0; section
< nsections
; ++section
)
5604 if (!c_parser_require (parser
, CPP_COLON
,
5607 : "expected %<:%> or %<)%>"))
5608 goto error_close_paren
;
5610 /* Once past any colon, we're no longer a simple asm. */
5613 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
5614 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5619 /* For asm goto, we don't allow output operands, but reserve
5620 the slot for a future extension that does allow them. */
5622 outputs
= c_parser_asm_operands (parser
);
5625 inputs
= c_parser_asm_operands (parser
);
5628 clobbers
= c_parser_asm_clobbers (parser
);
5631 labels
= c_parser_asm_goto_operands (parser
);
5637 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
5642 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5648 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5649 c_parser_skip_to_end_of_block_or_statement (parser
);
5651 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
5652 clobbers
, labels
, simple
));
5655 parser
->lex_untranslated_string
= false;
5659 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5663 /* Parse asm operands, a GNU extension.
5667 asm-operands , asm-operand
5670 asm-string-literal ( expression )
5671 [ identifier ] asm-string-literal ( expression )
5675 c_parser_asm_operands (c_parser
*parser
)
5677 tree list
= NULL_TREE
;
5682 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
5684 c_parser_consume_token (parser
);
5685 if (c_parser_next_token_is (parser
, CPP_NAME
))
5687 tree id
= c_parser_peek_token (parser
)->value
;
5688 c_parser_consume_token (parser
);
5689 name
= build_string (IDENTIFIER_LENGTH (id
),
5690 IDENTIFIER_POINTER (id
));
5694 c_parser_error (parser
, "expected identifier");
5695 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
5698 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5703 str
= c_parser_asm_string_literal (parser
);
5704 if (str
== NULL_TREE
)
5706 parser
->lex_untranslated_string
= false;
5707 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5709 parser
->lex_untranslated_string
= true;
5712 expr
= c_parser_expression (parser
);
5713 mark_exp_read (expr
.value
);
5714 parser
->lex_untranslated_string
= true;
5715 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
5717 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5720 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
5722 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5723 c_parser_consume_token (parser
);
5730 /* Parse asm clobbers, a GNU extension.
5734 asm-clobbers , asm-string-literal
5738 c_parser_asm_clobbers (c_parser
*parser
)
5740 tree list
= NULL_TREE
;
5743 tree str
= c_parser_asm_string_literal (parser
);
5745 list
= tree_cons (NULL_TREE
, str
, list
);
5748 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5749 c_parser_consume_token (parser
);
5756 /* Parse asm goto labels, a GNU extension.
5760 asm-goto-operands , identifier
5764 c_parser_asm_goto_operands (c_parser
*parser
)
5766 tree list
= NULL_TREE
;
5771 if (c_parser_next_token_is (parser
, CPP_NAME
))
5773 c_token
*tok
= c_parser_peek_token (parser
);
5775 label
= lookup_label_for_goto (tok
->location
, name
);
5776 c_parser_consume_token (parser
);
5777 TREE_USED (label
) = 1;
5781 c_parser_error (parser
, "expected identifier");
5785 name
= build_string (IDENTIFIER_LENGTH (name
),
5786 IDENTIFIER_POINTER (name
));
5787 list
= tree_cons (name
, label
, list
);
5788 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5789 c_parser_consume_token (parser
);
5791 return nreverse (list
);
5795 /* Parse an expression other than a compound expression; that is, an
5796 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
5797 NULL then it is an Objective-C message expression which is the
5798 primary-expression starting the expression as an initializer.
5800 assignment-expression:
5801 conditional-expression
5802 unary-expression assignment-operator assignment-expression
5804 assignment-operator: one of
5805 = *= /= %= += -= <<= >>= &= ^= |=
5807 In GNU C we accept any conditional expression on the LHS and
5808 diagnose the invalid lvalue rather than producing a syntax
5811 static struct c_expr
5812 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
5813 tree omp_atomic_lhs
)
5815 struct c_expr lhs
, rhs
, ret
;
5816 enum tree_code code
;
5817 location_t op_location
, exp_location
;
5818 gcc_assert (!after
|| c_dialect_objc ());
5819 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
5820 op_location
= c_parser_peek_token (parser
)->location
;
5821 switch (c_parser_peek_token (parser
)->type
)
5830 code
= TRUNC_DIV_EXPR
;
5833 code
= TRUNC_MOD_EXPR
;
5848 code
= BIT_AND_EXPR
;
5851 code
= BIT_XOR_EXPR
;
5854 code
= BIT_IOR_EXPR
;
5859 c_parser_consume_token (parser
);
5860 exp_location
= c_parser_peek_token (parser
)->location
;
5861 rhs
= c_parser_expr_no_commas (parser
, NULL
);
5862 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
5864 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
5865 code
, exp_location
, rhs
.value
,
5867 if (code
== NOP_EXPR
)
5868 ret
.original_code
= MODIFY_EXPR
;
5871 TREE_NO_WARNING (ret
.value
) = 1;
5872 ret
.original_code
= ERROR_MARK
;
5874 ret
.original_type
= NULL
;
5878 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
5879 is not NULL then it is an Objective-C message expression which is
5880 the primary-expression starting the expression as an initializer.
5882 conditional-expression:
5883 logical-OR-expression
5884 logical-OR-expression ? expression : conditional-expression
5888 conditional-expression:
5889 logical-OR-expression ? : conditional-expression
5892 static struct c_expr
5893 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
5894 tree omp_atomic_lhs
)
5896 struct c_expr cond
, exp1
, exp2
, ret
;
5897 location_t cond_loc
, colon_loc
, middle_loc
;
5899 gcc_assert (!after
|| c_dialect_objc ());
5901 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
5903 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
5905 cond_loc
= c_parser_peek_token (parser
)->location
;
5906 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
5907 c_parser_consume_token (parser
);
5908 if (c_parser_next_token_is (parser
, CPP_COLON
))
5910 tree eptype
= NULL_TREE
;
5912 middle_loc
= c_parser_peek_token (parser
)->location
;
5913 pedwarn (middle_loc
, OPT_Wpedantic
,
5914 "ISO C forbids omitting the middle term of a ?: expression");
5915 warn_for_omitted_condop (middle_loc
, cond
.value
);
5916 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
5918 eptype
= TREE_TYPE (cond
.value
);
5919 cond
.value
= TREE_OPERAND (cond
.value
, 0);
5921 /* Make sure first operand is calculated only once. */
5922 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
5924 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
5925 exp1
.original_type
= NULL
;
5926 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
5927 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
5932 = c_objc_common_truthvalue_conversion
5933 (cond_loc
, default_conversion (cond
.value
));
5934 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
5935 exp1
= c_parser_expression_conv (parser
);
5936 mark_exp_read (exp1
.value
);
5937 c_inhibit_evaluation_warnings
+=
5938 ((cond
.value
== truthvalue_true_node
)
5939 - (cond
.value
== truthvalue_false_node
));
5942 colon_loc
= c_parser_peek_token (parser
)->location
;
5943 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5945 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5946 ret
.value
= error_mark_node
;
5947 ret
.original_code
= ERROR_MARK
;
5948 ret
.original_type
= NULL
;
5952 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
5953 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
5954 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
5956 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
5957 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
5958 cond
.original_code
== C_MAYBE_CONST_EXPR
,
5959 exp1
.value
, exp1
.original_type
,
5960 exp2
.value
, exp2
.original_type
);
5961 ret
.original_code
= ERROR_MARK
;
5962 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
5963 ret
.original_type
= NULL
;
5968 /* If both sides are enum type, the default conversion will have
5969 made the type of the result be an integer type. We want to
5970 remember the enum types we started with. */
5971 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
5972 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
5973 ret
.original_type
= ((t1
!= error_mark_node
5974 && t2
!= error_mark_node
5975 && (TYPE_MAIN_VARIANT (t1
)
5976 == TYPE_MAIN_VARIANT (t2
)))
5983 /* Parse a binary expression; that is, a logical-OR-expression (C90
5984 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
5985 an Objective-C message expression which is the primary-expression
5986 starting the expression as an initializer.
5988 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
5989 when it should be the unfolded lhs. In a valid OpenMP source,
5990 one of the operands of the toplevel binary expression must be equal
5991 to it. In that case, just return a build2 created binary operation
5992 rather than result of parser_build_binary_op.
5994 multiplicative-expression:
5996 multiplicative-expression * cast-expression
5997 multiplicative-expression / cast-expression
5998 multiplicative-expression % cast-expression
6000 additive-expression:
6001 multiplicative-expression
6002 additive-expression + multiplicative-expression
6003 additive-expression - multiplicative-expression
6007 shift-expression << additive-expression
6008 shift-expression >> additive-expression
6010 relational-expression:
6012 relational-expression < shift-expression
6013 relational-expression > shift-expression
6014 relational-expression <= shift-expression
6015 relational-expression >= shift-expression
6017 equality-expression:
6018 relational-expression
6019 equality-expression == relational-expression
6020 equality-expression != relational-expression
6024 AND-expression & equality-expression
6026 exclusive-OR-expression:
6028 exclusive-OR-expression ^ AND-expression
6030 inclusive-OR-expression:
6031 exclusive-OR-expression
6032 inclusive-OR-expression | exclusive-OR-expression
6034 logical-AND-expression:
6035 inclusive-OR-expression
6036 logical-AND-expression && inclusive-OR-expression
6038 logical-OR-expression:
6039 logical-AND-expression
6040 logical-OR-expression || logical-AND-expression
6043 static struct c_expr
6044 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6045 tree omp_atomic_lhs
)
6047 /* A binary expression is parsed using operator-precedence parsing,
6048 with the operands being cast expressions. All the binary
6049 operators are left-associative. Thus a binary expression is of
6052 E0 op1 E1 op2 E2 ...
6054 which we represent on a stack. On the stack, the precedence
6055 levels are strictly increasing. When a new operator is
6056 encountered of higher precedence than that at the top of the
6057 stack, it is pushed; its LHS is the top expression, and its RHS
6058 is everything parsed until it is popped. When a new operator is
6059 encountered with precedence less than or equal to that at the top
6060 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6061 by the result of the operation until the operator at the top of
6062 the stack has lower precedence than the new operator or there is
6063 only one element on the stack; then the top expression is the LHS
6064 of the new operator. In the case of logical AND and OR
6065 expressions, we also need to adjust c_inhibit_evaluation_warnings
6066 as appropriate when the operators are pushed and popped. */
6069 /* The expression at this stack level. */
6071 /* The precedence of the operator on its left, PREC_NONE at the
6072 bottom of the stack. */
6073 enum c_parser_prec prec
;
6074 /* The operation on its left. */
6076 /* The source location of this operation. */
6080 /* Location of the binary operator. */
6081 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6084 switch (stack[sp].op) \
6086 case TRUTH_ANDIF_EXPR: \
6087 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6088 == truthvalue_false_node); \
6090 case TRUTH_ORIF_EXPR: \
6091 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6092 == truthvalue_true_node); \
6097 stack[sp - 1].expr \
6098 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6099 stack[sp - 1].expr, true, true); \
6101 = convert_lvalue_to_rvalue (stack[sp].loc, \
6102 stack[sp].expr, true, true); \
6103 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6104 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6105 && ((1 << stack[sp].prec) \
6106 & (1 << (PREC_BITOR | PREC_BITXOR | PREC_BITAND | PREC_SHIFT \
6107 | PREC_ADD | PREC_MULT))) \
6108 && stack[sp].op != TRUNC_MOD_EXPR \
6109 && stack[0].expr.value != error_mark_node \
6110 && stack[1].expr.value != error_mark_node \
6111 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6112 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6113 stack[0].expr.value \
6114 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6115 stack[0].expr.value, stack[1].expr.value); \
6117 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6119 stack[sp - 1].expr, \
6123 gcc_assert (!after
|| c_dialect_objc ());
6124 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6125 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6126 stack
[0].prec
= PREC_NONE
;
6130 enum c_parser_prec oprec
;
6131 enum tree_code ocode
;
6134 switch (c_parser_peek_token (parser
)->type
)
6142 ocode
= TRUNC_DIV_EXPR
;
6146 ocode
= TRUNC_MOD_EXPR
;
6158 ocode
= LSHIFT_EXPR
;
6162 ocode
= RSHIFT_EXPR
;
6176 case CPP_GREATER_EQ
:
6189 oprec
= PREC_BITAND
;
6190 ocode
= BIT_AND_EXPR
;
6193 oprec
= PREC_BITXOR
;
6194 ocode
= BIT_XOR_EXPR
;
6198 ocode
= BIT_IOR_EXPR
;
6201 oprec
= PREC_LOGAND
;
6202 ocode
= TRUTH_ANDIF_EXPR
;
6206 ocode
= TRUTH_ORIF_EXPR
;
6209 /* Not a binary operator, so end of the binary
6213 binary_loc
= c_parser_peek_token (parser
)->location
;
6214 while (oprec
<= stack
[sp
].prec
)
6216 c_parser_consume_token (parser
);
6219 case TRUTH_ANDIF_EXPR
:
6221 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6222 stack
[sp
].expr
, true, true);
6223 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6224 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6225 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6226 == truthvalue_false_node
);
6228 case TRUTH_ORIF_EXPR
:
6230 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6231 stack
[sp
].expr
, true, true);
6232 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6233 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6234 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6235 == truthvalue_true_node
);
6241 stack
[sp
].loc
= binary_loc
;
6242 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6243 stack
[sp
].prec
= oprec
;
6244 stack
[sp
].op
= ocode
;
6245 stack
[sp
].loc
= binary_loc
;
6250 return stack
[0].expr
;
6254 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6255 NULL then it is an Objective-C message expression which is the
6256 primary-expression starting the expression as an initializer.
6260 ( type-name ) unary-expression
6263 static struct c_expr
6264 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6266 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6267 gcc_assert (!after
|| c_dialect_objc ());
6269 return c_parser_postfix_expression_after_primary (parser
,
6271 /* If the expression begins with a parenthesized type name, it may
6272 be either a cast or a compound literal; we need to see whether
6273 the next character is '{' to tell the difference. If not, it is
6274 an unary expression. Full detection of unknown typenames here
6275 would require a 3-token lookahead. */
6276 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6277 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6279 struct c_type_name
*type_name
;
6282 c_parser_consume_token (parser
);
6283 type_name
= c_parser_type_name (parser
);
6284 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6285 if (type_name
== NULL
)
6287 ret
.value
= error_mark_node
;
6288 ret
.original_code
= ERROR_MARK
;
6289 ret
.original_type
= NULL
;
6293 /* Save casted types in the function's used types hash table. */
6294 used_types_insert (type_name
->specs
->type
);
6296 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6297 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6300 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6301 expr
= c_parser_cast_expression (parser
, NULL
);
6302 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6304 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6305 ret
.original_code
= ERROR_MARK
;
6306 ret
.original_type
= NULL
;
6310 return c_parser_unary_expression (parser
);
6313 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6319 unary-operator cast-expression
6320 sizeof unary-expression
6321 sizeof ( type-name )
6323 unary-operator: one of
6329 __alignof__ unary-expression
6330 __alignof__ ( type-name )
6333 (C11 permits _Alignof with type names only.)
6335 unary-operator: one of
6336 __extension__ __real__ __imag__
6338 Transactional Memory:
6341 transaction-expression
6343 In addition, the GNU syntax treats ++ and -- as unary operators, so
6344 they may be applied to cast expressions with errors for non-lvalues
6347 static struct c_expr
6348 c_parser_unary_expression (c_parser
*parser
)
6351 struct c_expr ret
, op
;
6352 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6354 ret
.original_code
= ERROR_MARK
;
6355 ret
.original_type
= NULL
;
6356 switch (c_parser_peek_token (parser
)->type
)
6359 c_parser_consume_token (parser
);
6360 exp_loc
= c_parser_peek_token (parser
)->location
;
6361 op
= c_parser_cast_expression (parser
, NULL
);
6363 /* If there is array notations in op, we expand them. */
6364 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6365 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6368 op
= default_function_array_read_conversion (exp_loc
, op
);
6369 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6371 case CPP_MINUS_MINUS
:
6372 c_parser_consume_token (parser
);
6373 exp_loc
= c_parser_peek_token (parser
)->location
;
6374 op
= c_parser_cast_expression (parser
, NULL
);
6376 /* If there is array notations in op, we expand them. */
6377 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6378 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6381 op
= default_function_array_read_conversion (exp_loc
, op
);
6382 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6385 c_parser_consume_token (parser
);
6386 op
= c_parser_cast_expression (parser
, NULL
);
6387 mark_exp_read (op
.value
);
6388 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6390 c_parser_consume_token (parser
);
6391 exp_loc
= c_parser_peek_token (parser
)->location
;
6392 op
= c_parser_cast_expression (parser
, NULL
);
6393 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6394 ret
.value
= build_indirect_ref (op_loc
, op
.value
, RO_UNARY_STAR
);
6397 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6400 "traditional C rejects the unary plus operator");
6401 c_parser_consume_token (parser
);
6402 exp_loc
= c_parser_peek_token (parser
)->location
;
6403 op
= c_parser_cast_expression (parser
, NULL
);
6404 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6405 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6407 c_parser_consume_token (parser
);
6408 exp_loc
= c_parser_peek_token (parser
)->location
;
6409 op
= c_parser_cast_expression (parser
, NULL
);
6410 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6411 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6413 c_parser_consume_token (parser
);
6414 exp_loc
= c_parser_peek_token (parser
)->location
;
6415 op
= c_parser_cast_expression (parser
, NULL
);
6416 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6417 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6419 c_parser_consume_token (parser
);
6420 exp_loc
= c_parser_peek_token (parser
)->location
;
6421 op
= c_parser_cast_expression (parser
, NULL
);
6422 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6423 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6425 /* Refer to the address of a label as a pointer. */
6426 c_parser_consume_token (parser
);
6427 if (c_parser_next_token_is (parser
, CPP_NAME
))
6429 ret
.value
= finish_label_address_expr
6430 (c_parser_peek_token (parser
)->value
, op_loc
);
6431 c_parser_consume_token (parser
);
6435 c_parser_error (parser
, "expected identifier");
6436 ret
.value
= error_mark_node
;
6440 switch (c_parser_peek_token (parser
)->keyword
)
6443 return c_parser_sizeof_expression (parser
);
6445 return c_parser_alignof_expression (parser
);
6447 c_parser_consume_token (parser
);
6448 ext
= disable_extension_diagnostics ();
6449 ret
= c_parser_cast_expression (parser
, NULL
);
6450 restore_extension_diagnostics (ext
);
6453 c_parser_consume_token (parser
);
6454 exp_loc
= c_parser_peek_token (parser
)->location
;
6455 op
= c_parser_cast_expression (parser
, NULL
);
6456 op
= default_function_array_conversion (exp_loc
, op
);
6457 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
6459 c_parser_consume_token (parser
);
6460 exp_loc
= c_parser_peek_token (parser
)->location
;
6461 op
= c_parser_cast_expression (parser
, NULL
);
6462 op
= default_function_array_conversion (exp_loc
, op
);
6463 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
6464 case RID_TRANSACTION_ATOMIC
:
6465 case RID_TRANSACTION_RELAXED
:
6466 return c_parser_transaction_expression (parser
,
6467 c_parser_peek_token (parser
)->keyword
);
6469 return c_parser_postfix_expression (parser
);
6472 return c_parser_postfix_expression (parser
);
6476 /* Parse a sizeof expression. */
6478 static struct c_expr
6479 c_parser_sizeof_expression (c_parser
*parser
)
6482 location_t expr_loc
;
6483 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
6484 c_parser_consume_token (parser
);
6485 c_inhibit_evaluation_warnings
++;
6487 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6488 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6490 /* Either sizeof ( type-name ) or sizeof unary-expression
6491 starting with a compound literal. */
6492 struct c_type_name
*type_name
;
6493 c_parser_consume_token (parser
);
6494 expr_loc
= c_parser_peek_token (parser
)->location
;
6495 type_name
= c_parser_type_name (parser
);
6496 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6497 if (type_name
== NULL
)
6500 c_inhibit_evaluation_warnings
--;
6502 ret
.value
= error_mark_node
;
6503 ret
.original_code
= ERROR_MARK
;
6504 ret
.original_type
= NULL
;
6507 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6509 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6514 /* sizeof ( type-name ). */
6515 c_inhibit_evaluation_warnings
--;
6517 return c_expr_sizeof_type (expr_loc
, type_name
);
6521 expr_loc
= c_parser_peek_token (parser
)->location
;
6522 expr
= c_parser_unary_expression (parser
);
6524 c_inhibit_evaluation_warnings
--;
6526 mark_exp_read (expr
.value
);
6527 if (TREE_CODE (expr
.value
) == COMPONENT_REF
6528 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
6529 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
6530 return c_expr_sizeof_expr (expr_loc
, expr
);
6534 /* Parse an alignof expression. */
6536 static struct c_expr
6537 c_parser_alignof_expression (c_parser
*parser
)
6540 location_t loc
= c_parser_peek_token (parser
)->location
;
6541 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
6542 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
6543 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
6545 /* A diagnostic is not required for the use of this identifier in
6546 the implementation namespace; only diagnose it for the C11
6547 spelling because of existing code using the other spellings. */
6548 if (!flag_isoc11
&& is_c11_alignof
)
6551 pedwarn (loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
6554 pedwarn (loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
6557 c_parser_consume_token (parser
);
6558 c_inhibit_evaluation_warnings
++;
6560 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6561 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6563 /* Either __alignof__ ( type-name ) or __alignof__
6564 unary-expression starting with a compound literal. */
6566 struct c_type_name
*type_name
;
6568 c_parser_consume_token (parser
);
6569 loc
= c_parser_peek_token (parser
)->location
;
6570 type_name
= c_parser_type_name (parser
);
6571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6572 if (type_name
== NULL
)
6575 c_inhibit_evaluation_warnings
--;
6577 ret
.value
= error_mark_node
;
6578 ret
.original_code
= ERROR_MARK
;
6579 ret
.original_type
= NULL
;
6582 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6584 expr
= c_parser_postfix_expression_after_paren_type (parser
,
6589 /* alignof ( type-name ). */
6590 c_inhibit_evaluation_warnings
--;
6592 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
6594 false, is_c11_alignof
, 1);
6595 ret
.original_code
= ERROR_MARK
;
6596 ret
.original_type
= NULL
;
6602 expr
= c_parser_unary_expression (parser
);
6604 mark_exp_read (expr
.value
);
6605 c_inhibit_evaluation_warnings
--;
6607 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
6609 ret
.value
= c_alignof_expr (loc
, expr
.value
);
6610 ret
.original_code
= ERROR_MARK
;
6611 ret
.original_type
= NULL
;
6616 /* Helper function to read arguments of builtins which are interfaces
6617 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
6618 others. The name of the builtin is passed using BNAME parameter.
6619 Function returns true if there were no errors while parsing and
6620 stores the arguments in CEXPR_LIST. */
6622 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
6623 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
6626 location_t loc
= c_parser_peek_token (parser
)->location
;
6627 vec
<c_expr_t
, va_gc
> *cexpr_list
;
6629 bool saved_force_folding_builtin_constant_p
;
6631 *ret_cexpr_list
= NULL
;
6632 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
6634 error_at (loc
, "cannot take address of %qs", bname
);
6638 c_parser_consume_token (parser
);
6640 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6642 c_parser_consume_token (parser
);
6646 saved_force_folding_builtin_constant_p
6647 = force_folding_builtin_constant_p
;
6648 force_folding_builtin_constant_p
|= choose_expr_p
;
6649 expr
= c_parser_expr_no_commas (parser
, NULL
);
6650 force_folding_builtin_constant_p
6651 = saved_force_folding_builtin_constant_p
;
6652 vec_alloc (cexpr_list
, 1);
6653 vec_safe_push (cexpr_list
, expr
);
6654 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6656 c_parser_consume_token (parser
);
6657 expr
= c_parser_expr_no_commas (parser
, NULL
);
6658 vec_safe_push (cexpr_list
, expr
);
6661 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6664 *ret_cexpr_list
= cexpr_list
;
6668 /* This represents a single generic-association. */
6670 struct c_generic_association
6672 /* The location of the starting token of the type. */
6673 location_t type_location
;
6674 /* The association's type, or NULL_TREE for 'default'. */
6676 /* The association's expression. */
6677 struct c_expr expression
;
6680 /* Parse a generic-selection. (C11 6.5.1.1).
6683 _Generic ( assignment-expression , generic-assoc-list )
6687 generic-assoc-list , generic-association
6689 generic-association:
6690 type-name : assignment-expression
6691 default : assignment-expression
6694 static struct c_expr
6695 c_parser_generic_selection (c_parser
*parser
)
6697 vec
<c_generic_association
> associations
= vNULL
;
6698 struct c_expr selector
, error_expr
;
6700 struct c_generic_association matched_assoc
;
6701 bool match_found
= false;
6702 location_t generic_loc
, selector_loc
;
6704 error_expr
.original_code
= ERROR_MARK
;
6705 error_expr
.original_type
= NULL
;
6706 error_expr
.value
= error_mark_node
;
6707 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
6708 matched_assoc
.type
= NULL_TREE
;
6709 matched_assoc
.expression
= error_expr
;
6711 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
6712 generic_loc
= c_parser_peek_token (parser
)->location
;
6713 c_parser_consume_token (parser
);
6717 pedwarn (generic_loc
, OPT_Wpedantic
,
6718 "ISO C99 does not support %<_Generic%>");
6720 pedwarn (generic_loc
, OPT_Wpedantic
,
6721 "ISO C90 does not support %<_Generic%>");
6724 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6727 c_inhibit_evaluation_warnings
++;
6728 selector_loc
= c_parser_peek_token (parser
)->location
;
6729 selector
= c_parser_expr_no_commas (parser
, NULL
);
6730 selector
= default_function_array_conversion (selector_loc
, selector
);
6731 c_inhibit_evaluation_warnings
--;
6733 if (selector
.value
== error_mark_node
)
6735 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6738 selector_type
= TREE_TYPE (selector
.value
);
6739 /* In ISO C terms, rvalues (including the controlling expression of
6740 _Generic) do not have qualified types. */
6741 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
6742 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
6743 /* In ISO C terms, _Noreturn is not part of the type of expressions
6744 such as &abort, but in GCC it is represented internally as a type
6746 if (FUNCTION_POINTER_TYPE_P (selector_type
)
6747 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
6749 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
6751 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
6753 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6759 struct c_generic_association assoc
, *iter
;
6761 c_token
*token
= c_parser_peek_token (parser
);
6763 assoc
.type_location
= token
->location
;
6764 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
6766 c_parser_consume_token (parser
);
6767 assoc
.type
= NULL_TREE
;
6771 struct c_type_name
*type_name
;
6773 type_name
= c_parser_type_name (parser
);
6774 if (type_name
== NULL
)
6776 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6779 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
6780 if (assoc
.type
== error_mark_node
)
6782 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6786 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
6787 error_at (assoc
.type_location
,
6788 "%<_Generic%> association has function type");
6789 else if (!COMPLETE_TYPE_P (assoc
.type
))
6790 error_at (assoc
.type_location
,
6791 "%<_Generic%> association has incomplete type");
6793 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
6794 error_at (assoc
.type_location
,
6795 "%<_Generic%> association has "
6796 "variable length type");
6799 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6801 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6805 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
6806 if (assoc
.expression
.value
== error_mark_node
)
6808 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6812 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
6814 if (assoc
.type
== NULL_TREE
)
6816 if (iter
->type
== NULL_TREE
)
6818 error_at (assoc
.type_location
,
6819 "duplicate %<default%> case in %<_Generic%>");
6820 inform (iter
->type_location
, "original %<default%> is here");
6823 else if (iter
->type
!= NULL_TREE
)
6825 if (comptypes (assoc
.type
, iter
->type
))
6827 error_at (assoc
.type_location
,
6828 "%<_Generic%> specifies two compatible types");
6829 inform (iter
->type_location
, "compatible type is here");
6834 if (assoc
.type
== NULL_TREE
)
6838 matched_assoc
= assoc
;
6842 else if (comptypes (assoc
.type
, selector_type
))
6844 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
6846 matched_assoc
= assoc
;
6851 error_at (assoc
.type_location
,
6852 "%<_Generic> selector matches multiple associations");
6853 inform (matched_assoc
.type_location
,
6854 "other match is here");
6858 associations
.safe_push (assoc
);
6860 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
6862 c_parser_consume_token (parser
);
6865 associations
.release ();
6867 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6875 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
6876 "compatible with any association",
6881 return matched_assoc
.expression
;
6884 associations
.release ();
6888 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
6892 postfix-expression [ expression ]
6893 postfix-expression ( argument-expression-list[opt] )
6894 postfix-expression . identifier
6895 postfix-expression -> identifier
6896 postfix-expression ++
6897 postfix-expression --
6898 ( type-name ) { initializer-list }
6899 ( type-name ) { initializer-list , }
6901 argument-expression-list:
6903 argument-expression-list , argument-expression
6916 (treated as a keyword in GNU C)
6919 ( compound-statement )
6920 __builtin_va_arg ( assignment-expression , type-name )
6921 __builtin_offsetof ( type-name , offsetof-member-designator )
6922 __builtin_choose_expr ( assignment-expression ,
6923 assignment-expression ,
6924 assignment-expression )
6925 __builtin_types_compatible_p ( type-name , type-name )
6926 __builtin_complex ( assignment-expression , assignment-expression )
6927 __builtin_shuffle ( assignment-expression , assignment-expression )
6928 __builtin_shuffle ( assignment-expression ,
6929 assignment-expression ,
6930 assignment-expression, )
6932 offsetof-member-designator:
6934 offsetof-member-designator . identifier
6935 offsetof-member-designator [ expression ]
6940 [ objc-receiver objc-message-args ]
6941 @selector ( objc-selector-arg )
6942 @protocol ( identifier )
6943 @encode ( type-name )
6945 Classname . identifier
6948 static struct c_expr
6949 c_parser_postfix_expression (c_parser
*parser
)
6951 struct c_expr expr
, e1
;
6952 struct c_type_name
*t1
, *t2
;
6953 location_t loc
= c_parser_peek_token (parser
)->location
;;
6954 expr
.original_code
= ERROR_MARK
;
6955 expr
.original_type
= NULL
;
6956 switch (c_parser_peek_token (parser
)->type
)
6959 expr
.value
= c_parser_peek_token (parser
)->value
;
6960 loc
= c_parser_peek_token (parser
)->location
;
6961 c_parser_consume_token (parser
);
6962 if (TREE_CODE (expr
.value
) == FIXED_CST
6963 && !targetm
.fixed_point_supported_p ())
6965 error_at (loc
, "fixed-point types not supported for this target");
6966 expr
.value
= error_mark_node
;
6973 expr
.value
= c_parser_peek_token (parser
)->value
;
6974 c_parser_consume_token (parser
);
6980 case CPP_UTF8STRING
:
6981 expr
.value
= c_parser_peek_token (parser
)->value
;
6982 expr
.original_code
= STRING_CST
;
6983 c_parser_consume_token (parser
);
6985 case CPP_OBJC_STRING
:
6986 gcc_assert (c_dialect_objc ());
6988 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
6989 c_parser_consume_token (parser
);
6992 switch (c_parser_peek_token (parser
)->id_kind
)
6996 tree id
= c_parser_peek_token (parser
)->value
;
6997 c_parser_consume_token (parser
);
6998 expr
.value
= build_external_ref (loc
, id
,
6999 (c_parser_peek_token (parser
)->type
7001 &expr
.original_type
);
7004 case C_ID_CLASSNAME
:
7006 /* Here we parse the Objective-C 2.0 Class.name dot
7008 tree class_name
= c_parser_peek_token (parser
)->value
;
7010 c_parser_consume_token (parser
);
7011 gcc_assert (c_dialect_objc ());
7012 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7014 expr
.value
= error_mark_node
;
7017 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7019 c_parser_error (parser
, "expected identifier");
7020 expr
.value
= error_mark_node
;
7023 component
= c_parser_peek_token (parser
)->value
;
7024 c_parser_consume_token (parser
);
7025 expr
.value
= objc_build_class_component_ref (class_name
,
7030 c_parser_error (parser
, "expected expression");
7031 expr
.value
= error_mark_node
;
7035 case CPP_OPEN_PAREN
:
7036 /* A parenthesized expression, statement expression or compound
7038 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7040 /* A statement expression. */
7042 location_t brace_loc
;
7043 c_parser_consume_token (parser
);
7044 brace_loc
= c_parser_peek_token (parser
)->location
;
7045 c_parser_consume_token (parser
);
7046 if (!building_stmt_list_p ())
7048 error_at (loc
, "braced-group within expression allowed "
7049 "only inside a function");
7050 parser
->error
= true;
7051 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7052 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7053 expr
.value
= error_mark_node
;
7056 stmt
= c_begin_stmt_expr ();
7057 c_parser_compound_statement_nostart (parser
);
7058 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7060 pedwarn (loc
, OPT_Wpedantic
,
7061 "ISO C forbids braced-groups within expressions");
7062 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7063 mark_exp_read (expr
.value
);
7065 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7067 /* A compound literal. ??? Can we actually get here rather
7068 than going directly to
7069 c_parser_postfix_expression_after_paren_type from
7072 struct c_type_name
*type_name
;
7073 c_parser_consume_token (parser
);
7074 loc
= c_parser_peek_token (parser
)->location
;
7075 type_name
= c_parser_type_name (parser
);
7076 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7078 if (type_name
== NULL
)
7080 expr
.value
= error_mark_node
;
7083 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7089 /* A parenthesized expression. */
7090 c_parser_consume_token (parser
);
7091 expr
= c_parser_expression (parser
);
7092 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7093 TREE_NO_WARNING (expr
.value
) = 1;
7094 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7095 expr
.original_code
= ERROR_MARK
;
7096 /* Don't change EXPR.ORIGINAL_TYPE. */
7097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7102 switch (c_parser_peek_token (parser
)->keyword
)
7104 case RID_FUNCTION_NAME
:
7105 case RID_PRETTY_FUNCTION_NAME
:
7106 case RID_C99_FUNCTION_NAME
:
7107 expr
.value
= fname_decl (loc
,
7108 c_parser_peek_token (parser
)->keyword
,
7109 c_parser_peek_token (parser
)->value
);
7110 c_parser_consume_token (parser
);
7113 c_parser_consume_token (parser
);
7114 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7116 expr
.value
= error_mark_node
;
7119 e1
= c_parser_expr_no_commas (parser
, NULL
);
7120 mark_exp_read (e1
.value
);
7121 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7122 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7124 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7125 expr
.value
= error_mark_node
;
7128 loc
= c_parser_peek_token (parser
)->location
;
7129 t1
= c_parser_type_name (parser
);
7130 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7134 expr
.value
= error_mark_node
;
7138 tree type_expr
= NULL_TREE
;
7139 expr
.value
= c_build_va_arg (loc
, e1
.value
,
7140 groktypename (t1
, &type_expr
, NULL
));
7143 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7144 TREE_TYPE (expr
.value
), type_expr
,
7146 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7151 c_parser_consume_token (parser
);
7152 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7154 expr
.value
= error_mark_node
;
7157 t1
= c_parser_type_name (parser
);
7159 parser
->error
= true;
7160 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7161 gcc_assert (parser
->error
);
7164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7165 expr
.value
= error_mark_node
;
7170 tree type
= groktypename (t1
, NULL
, NULL
);
7172 if (type
== error_mark_node
)
7173 offsetof_ref
= error_mark_node
;
7176 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7177 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7179 /* Parse the second argument to __builtin_offsetof. We
7180 must have one identifier, and beyond that we want to
7181 accept sub structure and sub array references. */
7182 if (c_parser_next_token_is (parser
, CPP_NAME
))
7184 offsetof_ref
= build_component_ref
7185 (loc
, offsetof_ref
, c_parser_peek_token (parser
)->value
);
7186 c_parser_consume_token (parser
);
7187 while (c_parser_next_token_is (parser
, CPP_DOT
)
7188 || c_parser_next_token_is (parser
,
7190 || c_parser_next_token_is (parser
,
7193 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7195 loc
= c_parser_peek_token (parser
)->location
;
7196 offsetof_ref
= build_array_ref (loc
,
7201 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7204 c_parser_consume_token (parser
);
7205 if (c_parser_next_token_is_not (parser
,
7208 c_parser_error (parser
, "expected identifier");
7211 offsetof_ref
= build_component_ref
7213 c_parser_peek_token (parser
)->value
);
7214 c_parser_consume_token (parser
);
7220 loc
= c_parser_peek_token (parser
)->location
;
7221 c_parser_consume_token (parser
);
7222 ce
= c_parser_expression (parser
);
7223 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7225 idx
= c_fully_fold (idx
, false, NULL
);
7226 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7228 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7233 c_parser_error (parser
, "expected identifier");
7234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7236 expr
.value
= fold_offsetof (offsetof_ref
);
7239 case RID_CHOOSE_EXPR
:
7241 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7242 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7245 c_parser_consume_token (parser
);
7246 if (!c_parser_get_builtin_args (parser
,
7247 "__builtin_choose_expr",
7250 expr
.value
= error_mark_node
;
7254 if (vec_safe_length (cexpr_list
) != 3)
7256 error_at (loc
, "wrong number of arguments to "
7257 "%<__builtin_choose_expr%>");
7258 expr
.value
= error_mark_node
;
7262 e1_p
= &(*cexpr_list
)[0];
7263 e2_p
= &(*cexpr_list
)[1];
7264 e3_p
= &(*cexpr_list
)[2];
7267 mark_exp_read (e2_p
->value
);
7268 mark_exp_read (e3_p
->value
);
7269 if (TREE_CODE (c
) != INTEGER_CST
7270 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7272 "first argument to %<__builtin_choose_expr%> not"
7274 constant_expression_warning (c
);
7275 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7278 case RID_TYPES_COMPATIBLE_P
:
7279 c_parser_consume_token (parser
);
7280 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7282 expr
.value
= error_mark_node
;
7285 t1
= c_parser_type_name (parser
);
7288 expr
.value
= error_mark_node
;
7291 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7293 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7294 expr
.value
= error_mark_node
;
7297 t2
= c_parser_type_name (parser
);
7300 expr
.value
= error_mark_node
;
7303 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7307 e1
= groktypename (t1
, NULL
, NULL
);
7308 e2
= groktypename (t2
, NULL
, NULL
);
7309 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7311 expr
.value
= error_mark_node
;
7315 e1
= TYPE_MAIN_VARIANT (e1
);
7316 e2
= TYPE_MAIN_VARIANT (e2
);
7319 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7322 case RID_BUILTIN_COMPLEX
:
7324 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7325 c_expr_t
*e1_p
, *e2_p
;
7327 c_parser_consume_token (parser
);
7328 if (!c_parser_get_builtin_args (parser
,
7329 "__builtin_complex",
7330 &cexpr_list
, false))
7332 expr
.value
= error_mark_node
;
7336 if (vec_safe_length (cexpr_list
) != 2)
7338 error_at (loc
, "wrong number of arguments to "
7339 "%<__builtin_complex%>");
7340 expr
.value
= error_mark_node
;
7344 e1_p
= &(*cexpr_list
)[0];
7345 e2_p
= &(*cexpr_list
)[1];
7347 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7348 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7349 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7350 TREE_OPERAND (e1_p
->value
, 0));
7351 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7352 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
7353 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
7354 TREE_OPERAND (e2_p
->value
, 0));
7355 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7356 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
7357 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
7358 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
7360 error_at (loc
, "%<__builtin_complex%> operand "
7361 "not of real binary floating-point type");
7362 expr
.value
= error_mark_node
;
7365 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
7366 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
7369 "%<__builtin_complex%> operands of different types");
7370 expr
.value
= error_mark_node
;
7374 pedwarn (loc
, OPT_Wpedantic
,
7375 "ISO C90 does not support complex types");
7376 expr
.value
= build2 (COMPLEX_EXPR
,
7379 (TREE_TYPE (e1_p
->value
))),
7380 e1_p
->value
, e2_p
->value
);
7383 case RID_BUILTIN_SHUFFLE
:
7385 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7389 c_parser_consume_token (parser
);
7390 if (!c_parser_get_builtin_args (parser
,
7391 "__builtin_shuffle",
7392 &cexpr_list
, false))
7394 expr
.value
= error_mark_node
;
7398 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
7399 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
7401 if (vec_safe_length (cexpr_list
) == 2)
7403 c_build_vec_perm_expr
7404 (loc
, (*cexpr_list
)[0].value
,
7405 NULL_TREE
, (*cexpr_list
)[1].value
);
7407 else if (vec_safe_length (cexpr_list
) == 3)
7409 c_build_vec_perm_expr
7410 (loc
, (*cexpr_list
)[0].value
,
7411 (*cexpr_list
)[1].value
,
7412 (*cexpr_list
)[2].value
);
7415 error_at (loc
, "wrong number of arguments to "
7416 "%<__builtin_shuffle%>");
7417 expr
.value
= error_mark_node
;
7421 case RID_AT_SELECTOR
:
7422 gcc_assert (c_dialect_objc ());
7423 c_parser_consume_token (parser
);
7424 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7426 expr
.value
= error_mark_node
;
7430 tree sel
= c_parser_objc_selector_arg (parser
);
7431 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7433 expr
.value
= objc_build_selector_expr (loc
, sel
);
7436 case RID_AT_PROTOCOL
:
7437 gcc_assert (c_dialect_objc ());
7438 c_parser_consume_token (parser
);
7439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7441 expr
.value
= error_mark_node
;
7444 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7446 c_parser_error (parser
, "expected identifier");
7447 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7448 expr
.value
= error_mark_node
;
7452 tree id
= c_parser_peek_token (parser
)->value
;
7453 c_parser_consume_token (parser
);
7454 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7456 expr
.value
= objc_build_protocol_expr (id
);
7460 /* Extension to support C-structures in the archiver. */
7461 gcc_assert (c_dialect_objc ());
7462 c_parser_consume_token (parser
);
7463 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7465 expr
.value
= error_mark_node
;
7468 t1
= c_parser_type_name (parser
);
7471 expr
.value
= error_mark_node
;
7472 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7475 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7478 tree type
= groktypename (t1
, NULL
, NULL
);
7479 expr
.value
= objc_build_encode_expr (type
);
7483 expr
= c_parser_generic_selection (parser
);
7485 case RID_CILK_SPAWN
:
7486 c_parser_consume_token (parser
);
7489 error_at (loc
, "-fcilkplus must be enabled to use "
7491 expr
= c_parser_postfix_expression (parser
);
7492 expr
.value
= error_mark_node
;
7494 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7496 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
7497 "are not permitted");
7498 /* Now flush out all the _Cilk_spawns. */
7499 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
7500 c_parser_consume_token (parser
);
7501 expr
= c_parser_postfix_expression (parser
);
7505 expr
= c_parser_postfix_expression (parser
);
7506 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
7510 c_parser_error (parser
, "expected expression");
7511 expr
.value
= error_mark_node
;
7515 case CPP_OPEN_SQUARE
:
7516 if (c_dialect_objc ())
7518 tree receiver
, args
;
7519 c_parser_consume_token (parser
);
7520 receiver
= c_parser_objc_receiver (parser
);
7521 args
= c_parser_objc_message_args (parser
);
7522 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7524 expr
.value
= objc_build_message_expr (receiver
, args
);
7527 /* Else fall through to report error. */
7529 c_parser_error (parser
, "expected expression");
7530 expr
.value
= error_mark_node
;
7533 return c_parser_postfix_expression_after_primary (parser
, loc
, expr
);
7536 /* Parse a postfix expression after a parenthesized type name: the
7537 brace-enclosed initializer of a compound literal, possibly followed
7538 by some postfix operators. This is separate because it is not
7539 possible to tell until after the type name whether a cast
7540 expression has a cast or a compound literal, or whether the operand
7541 of sizeof is a parenthesized type name or starts with a compound
7542 literal. TYPE_LOC is the location where TYPE_NAME starts--the
7543 location of the first token after the parentheses around the type
7546 static struct c_expr
7547 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
7548 struct c_type_name
*type_name
,
7549 location_t type_loc
)
7555 location_t start_loc
;
7556 tree type_expr
= NULL_TREE
;
7557 bool type_expr_const
= true;
7558 check_compound_literal_type (type_loc
, type_name
);
7559 start_init (NULL_TREE
, NULL
, 0);
7560 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
7561 start_loc
= c_parser_peek_token (parser
)->location
;
7562 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
7564 error_at (type_loc
, "compound literal has variable size");
7565 type
= error_mark_node
;
7567 init
= c_parser_braced_init (parser
, type
, false);
7569 maybe_warn_string_init (type
, init
);
7571 if (type
!= error_mark_node
7572 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
7573 && current_function_decl
)
7575 error ("compound literal qualified by address-space qualifier");
7576 type
= error_mark_node
;
7580 pedwarn (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
7581 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
7582 ? CONSTRUCTOR_NON_CONST (init
.value
)
7583 : init
.original_code
== C_MAYBE_CONST_EXPR
);
7584 non_const
|= !type_expr_const
;
7585 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
7586 expr
.original_code
= ERROR_MARK
;
7587 expr
.original_type
= NULL
;
7590 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
7592 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
7593 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
7597 gcc_assert (!non_const
);
7598 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
7599 type_expr
, expr
.value
);
7602 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
7605 /* Callback function for sizeof_pointer_memaccess_warning to compare
7609 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
7611 return comptypes (type1
, type2
) == 1;
7614 /* Parse a postfix expression after the initial primary or compound
7615 literal; that is, parse a series of postfix operators.
7617 EXPR_LOC is the location of the primary expression. */
7619 static struct c_expr
7620 c_parser_postfix_expression_after_primary (c_parser
*parser
,
7621 location_t expr_loc
,
7624 struct c_expr orig_expr
;
7626 location_t sizeof_arg_loc
[3];
7629 vec
<tree
, va_gc
> *exprlist
;
7630 vec
<tree
, va_gc
> *origtypes
= NULL
;
7631 vec
<location_t
> arg_loc
= vNULL
;
7635 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7636 switch (c_parser_peek_token (parser
)->type
)
7638 case CPP_OPEN_SQUARE
:
7639 /* Array reference. */
7640 c_parser_consume_token (parser
);
7642 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7643 /* If we are here, then we have something like this:
7646 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
7650 idx
= c_parser_expression (parser
).value
;
7651 /* Here we have 3 options:
7652 1. Array [EXPR] -- Normal Array call.
7653 2. Array [EXPR : EXPR] -- Array notation without stride.
7654 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
7656 For 1, we just handle it just like a normal array expression.
7657 For 2 and 3 we handle it like we handle array notations. The
7658 idx value we have above becomes the initial/start index.
7661 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
7662 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
7666 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7668 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
7671 expr
.original_code
= ERROR_MARK
;
7672 expr
.original_type
= NULL
;
7674 case CPP_OPEN_PAREN
:
7675 /* Function call. */
7676 c_parser_consume_token (parser
);
7677 for (i
= 0; i
< 3; i
++)
7679 sizeof_arg
[i
] = NULL_TREE
;
7680 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
7682 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7685 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
7686 sizeof_arg_loc
, sizeof_arg
,
7688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7691 mark_exp_read (expr
.value
);
7692 if (warn_sizeof_pointer_memaccess
)
7693 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
7694 expr
.value
, exprlist
,
7696 sizeof_ptr_memacc_comptypes
);
7698 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
7699 exprlist
, origtypes
);
7700 expr
.original_code
= ERROR_MARK
;
7701 if (TREE_CODE (expr
.value
) == INTEGER_CST
7702 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
7703 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
7704 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
7705 expr
.original_code
= C_MAYBE_CONST_EXPR
;
7706 expr
.original_type
= NULL
;
7709 release_tree_vector (exprlist
);
7710 release_tree_vector (origtypes
);
7715 /* Structure element reference. */
7716 c_parser_consume_token (parser
);
7717 expr
= default_function_array_conversion (expr_loc
, expr
);
7718 if (c_parser_next_token_is (parser
, CPP_NAME
))
7719 ident
= c_parser_peek_token (parser
)->value
;
7722 c_parser_error (parser
, "expected identifier");
7723 expr
.value
= error_mark_node
;
7724 expr
.original_code
= ERROR_MARK
;
7725 expr
.original_type
= NULL
;
7728 c_parser_consume_token (parser
);
7729 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
);
7730 expr
.original_code
= ERROR_MARK
;
7731 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7732 expr
.original_type
= NULL
;
7735 /* Remember the original type of a bitfield. */
7736 tree field
= TREE_OPERAND (expr
.value
, 1);
7737 if (TREE_CODE (field
) != FIELD_DECL
)
7738 expr
.original_type
= NULL
;
7740 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7744 /* Structure element reference. */
7745 c_parser_consume_token (parser
);
7746 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
7747 if (c_parser_next_token_is (parser
, CPP_NAME
))
7748 ident
= c_parser_peek_token (parser
)->value
;
7751 c_parser_error (parser
, "expected identifier");
7752 expr
.value
= error_mark_node
;
7753 expr
.original_code
= ERROR_MARK
;
7754 expr
.original_type
= NULL
;
7757 c_parser_consume_token (parser
);
7758 expr
.value
= build_component_ref (op_loc
,
7759 build_indirect_ref (op_loc
,
7763 expr
.original_code
= ERROR_MARK
;
7764 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
7765 expr
.original_type
= NULL
;
7768 /* Remember the original type of a bitfield. */
7769 tree field
= TREE_OPERAND (expr
.value
, 1);
7770 if (TREE_CODE (field
) != FIELD_DECL
)
7771 expr
.original_type
= NULL
;
7773 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
7777 /* Postincrement. */
7778 c_parser_consume_token (parser
);
7779 /* If the expressions have array notations, we expand them. */
7781 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7782 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
7785 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7786 expr
.value
= build_unary_op (op_loc
,
7787 POSTINCREMENT_EXPR
, expr
.value
, 0);
7789 expr
.original_code
= ERROR_MARK
;
7790 expr
.original_type
= NULL
;
7792 case CPP_MINUS_MINUS
:
7793 /* Postdecrement. */
7794 c_parser_consume_token (parser
);
7795 /* If the expressions have array notations, we expand them. */
7797 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
7798 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
7801 expr
= default_function_array_read_conversion (expr_loc
, expr
);
7802 expr
.value
= build_unary_op (op_loc
,
7803 POSTDECREMENT_EXPR
, expr
.value
, 0);
7805 expr
.original_code
= ERROR_MARK
;
7806 expr
.original_type
= NULL
;
7814 /* Parse an expression (C90 6.3.17, C99 6.5.17).
7817 assignment-expression
7818 expression , assignment-expression
7821 static struct c_expr
7822 c_parser_expression (c_parser
*parser
)
7824 location_t tloc
= c_parser_peek_token (parser
)->location
;
7826 expr
= c_parser_expr_no_commas (parser
, NULL
);
7827 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7828 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
7829 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7833 location_t loc
= c_parser_peek_token (parser
)->location
;
7834 location_t expr_loc
;
7835 c_parser_consume_token (parser
);
7836 expr_loc
= c_parser_peek_token (parser
)->location
;
7837 lhsval
= expr
.value
;
7838 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
7839 lhsval
= TREE_OPERAND (lhsval
, 1);
7840 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
7841 mark_exp_read (lhsval
);
7842 next
= c_parser_expr_no_commas (parser
, NULL
);
7843 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
7844 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
7845 expr
.original_code
= COMPOUND_EXPR
;
7846 expr
.original_type
= next
.original_type
;
7851 /* Parse an expression and convert functions or arrays to pointers and
7852 lvalues to rvalues. */
7854 static struct c_expr
7855 c_parser_expression_conv (c_parser
*parser
)
7858 location_t loc
= c_parser_peek_token (parser
)->location
;
7859 expr
= c_parser_expression (parser
);
7860 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
7864 /* Parse a non-empty list of expressions. If CONVERT_P, convert
7865 functions and arrays to pointers and lvalues to rvalues. If
7866 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
7867 locations of function arguments into this vector.
7870 assignment-expression
7871 nonempty-expr-list , assignment-expression
7874 static vec
<tree
, va_gc
> *
7875 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
7876 vec
<tree
, va_gc
> **p_orig_types
,
7877 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
7878 vec
<location_t
> *locations
)
7880 vec
<tree
, va_gc
> *ret
;
7881 vec
<tree
, va_gc
> *orig_types
;
7883 location_t loc
= c_parser_peek_token (parser
)->location
;
7884 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7885 unsigned int idx
= 0;
7887 ret
= make_tree_vector ();
7888 if (p_orig_types
== NULL
)
7891 orig_types
= make_tree_vector ();
7893 if (sizeof_arg
!= NULL
7894 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7895 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7896 expr
= c_parser_expr_no_commas (parser
, NULL
);
7898 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7900 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7901 ret
->quick_push (expr
.value
);
7903 orig_types
->quick_push (expr
.original_type
);
7905 locations
->safe_push (loc
);
7906 if (sizeof_arg
!= NULL
7907 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7908 && expr
.original_code
== SIZEOF_EXPR
)
7910 sizeof_arg
[0] = c_last_sizeof_arg
;
7911 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
7913 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7915 c_parser_consume_token (parser
);
7916 loc
= c_parser_peek_token (parser
)->location
;
7917 if (sizeof_arg
!= NULL
7918 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
7919 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
7921 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
7922 expr
= c_parser_expr_no_commas (parser
, NULL
);
7924 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
7926 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
7927 vec_safe_push (ret
, expr
.value
);
7929 vec_safe_push (orig_types
, expr
.original_type
);
7931 locations
->safe_push (loc
);
7933 && sizeof_arg
!= NULL
7934 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
7935 && expr
.original_code
== SIZEOF_EXPR
)
7937 sizeof_arg
[idx
] = c_last_sizeof_arg
;
7938 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
7942 *p_orig_types
= orig_types
;
7946 /* Parse Objective-C-specific constructs. */
7948 /* Parse an objc-class-definition.
7950 objc-class-definition:
7951 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
7952 objc-class-instance-variables[opt] objc-methodprotolist @end
7953 @implementation identifier objc-superclass[opt]
7954 objc-class-instance-variables[opt]
7955 @interface identifier ( identifier ) objc-protocol-refs[opt]
7956 objc-methodprotolist @end
7957 @interface identifier ( ) objc-protocol-refs[opt]
7958 objc-methodprotolist @end
7959 @implementation identifier ( identifier )
7964 "@interface identifier (" must start "@interface identifier (
7965 identifier ) ...": objc-methodprotolist in the first production may
7966 not start with a parenthesized identifier as a declarator of a data
7967 definition with no declaration specifiers if the objc-superclass,
7968 objc-protocol-refs and objc-class-instance-variables are omitted. */
7971 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
7976 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
7978 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
7983 c_parser_consume_token (parser
);
7984 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7986 c_parser_error (parser
, "expected identifier");
7989 id1
= c_parser_peek_token (parser
)->value
;
7990 c_parser_consume_token (parser
);
7991 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7993 /* We have a category or class extension. */
7995 tree proto
= NULL_TREE
;
7996 c_parser_consume_token (parser
);
7997 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7999 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8001 /* We have a class extension. */
8006 c_parser_error (parser
, "expected identifier or %<)%>");
8007 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8013 id2
= c_parser_peek_token (parser
)->value
;
8014 c_parser_consume_token (parser
);
8016 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8019 objc_start_category_implementation (id1
, id2
);
8022 if (c_parser_next_token_is (parser
, CPP_LESS
))
8023 proto
= c_parser_objc_protocol_refs (parser
);
8024 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8025 c_parser_objc_methodprotolist (parser
);
8026 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8027 objc_finish_interface ();
8030 if (c_parser_next_token_is (parser
, CPP_COLON
))
8032 c_parser_consume_token (parser
);
8033 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8035 c_parser_error (parser
, "expected identifier");
8038 superclass
= c_parser_peek_token (parser
)->value
;
8039 c_parser_consume_token (parser
);
8042 superclass
= NULL_TREE
;
8045 tree proto
= NULL_TREE
;
8046 if (c_parser_next_token_is (parser
, CPP_LESS
))
8047 proto
= c_parser_objc_protocol_refs (parser
);
8048 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8051 objc_start_class_implementation (id1
, superclass
);
8052 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8053 c_parser_objc_class_instance_variables (parser
);
8056 objc_continue_interface ();
8057 c_parser_objc_methodprotolist (parser
);
8058 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8059 objc_finish_interface ();
8063 objc_continue_implementation ();
8068 /* Parse objc-class-instance-variables.
8070 objc-class-instance-variables:
8071 { objc-instance-variable-decl-list[opt] }
8073 objc-instance-variable-decl-list:
8074 objc-visibility-spec
8075 objc-instance-variable-decl ;
8077 objc-instance-variable-decl-list objc-visibility-spec
8078 objc-instance-variable-decl-list objc-instance-variable-decl ;
8079 objc-instance-variable-decl-list ;
8081 objc-visibility-spec:
8086 objc-instance-variable-decl:
8091 c_parser_objc_class_instance_variables (c_parser
*parser
)
8093 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8094 c_parser_consume_token (parser
);
8095 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8098 /* Parse any stray semicolon. */
8099 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8101 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8103 c_parser_consume_token (parser
);
8106 /* Stop if at the end of the instance variables. */
8107 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8109 c_parser_consume_token (parser
);
8112 /* Parse any objc-visibility-spec. */
8113 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8115 c_parser_consume_token (parser
);
8116 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8119 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8121 c_parser_consume_token (parser
);
8122 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8125 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8127 c_parser_consume_token (parser
);
8128 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8131 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8133 c_parser_consume_token (parser
);
8134 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8137 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8139 c_parser_pragma (parser
, pragma_external
);
8143 /* Parse some comma-separated declarations. */
8144 decls
= c_parser_struct_declaration (parser
);
8147 /* There is a syntax error. We want to skip the offending
8148 tokens up to the next ';' (included) or '}'
8151 /* First, skip manually a ')' or ']'. This is because they
8152 reduce the nesting level, so c_parser_skip_until_found()
8153 wouldn't be able to skip past them. */
8154 c_token
*token
= c_parser_peek_token (parser
);
8155 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8156 c_parser_consume_token (parser
);
8158 /* Then, do the standard skipping. */
8159 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8161 /* We hopefully recovered. Start normal parsing again. */
8162 parser
->error
= false;
8167 /* Comma-separated instance variables are chained together
8168 in reverse order; add them one by one. */
8169 tree ivar
= nreverse (decls
);
8170 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8171 objc_add_instance_variable (copy_node (ivar
));
8173 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8177 /* Parse an objc-class-declaration.
8179 objc-class-declaration:
8180 @class identifier-list ;
8184 c_parser_objc_class_declaration (c_parser
*parser
)
8186 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8187 c_parser_consume_token (parser
);
8188 /* Any identifiers, including those declared as type names, are OK
8193 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8195 c_parser_error (parser
, "expected identifier");
8196 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8197 parser
->error
= false;
8200 id
= c_parser_peek_token (parser
)->value
;
8201 objc_declare_class (id
);
8202 c_parser_consume_token (parser
);
8203 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8204 c_parser_consume_token (parser
);
8208 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8211 /* Parse an objc-alias-declaration.
8213 objc-alias-declaration:
8214 @compatibility_alias identifier identifier ;
8218 c_parser_objc_alias_declaration (c_parser
*parser
)
8221 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8222 c_parser_consume_token (parser
);
8223 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8225 c_parser_error (parser
, "expected identifier");
8226 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8229 id1
= c_parser_peek_token (parser
)->value
;
8230 c_parser_consume_token (parser
);
8231 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8233 c_parser_error (parser
, "expected identifier");
8234 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8237 id2
= c_parser_peek_token (parser
)->value
;
8238 c_parser_consume_token (parser
);
8239 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8240 objc_declare_alias (id1
, id2
);
8243 /* Parse an objc-protocol-definition.
8245 objc-protocol-definition:
8246 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
8247 @protocol identifier-list ;
8249 "@protocol identifier ;" should be resolved as "@protocol
8250 identifier-list ;": objc-methodprotolist may not start with a
8251 semicolon in the first alternative if objc-protocol-refs are
8255 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
8257 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
8259 c_parser_consume_token (parser
);
8260 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8262 c_parser_error (parser
, "expected identifier");
8265 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8266 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
8268 /* Any identifiers, including those declared as type names, are
8273 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8275 c_parser_error (parser
, "expected identifier");
8278 id
= c_parser_peek_token (parser
)->value
;
8279 objc_declare_protocol (id
, attributes
);
8280 c_parser_consume_token (parser
);
8281 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8282 c_parser_consume_token (parser
);
8286 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8290 tree id
= c_parser_peek_token (parser
)->value
;
8291 tree proto
= NULL_TREE
;
8292 c_parser_consume_token (parser
);
8293 if (c_parser_next_token_is (parser
, CPP_LESS
))
8294 proto
= c_parser_objc_protocol_refs (parser
);
8295 parser
->objc_pq_context
= true;
8296 objc_start_protocol (id
, proto
, attributes
);
8297 c_parser_objc_methodprotolist (parser
);
8298 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8299 parser
->objc_pq_context
= false;
8300 objc_finish_interface ();
8304 /* Parse an objc-method-type.
8310 Return true if it is a class method (+) and false if it is
8311 an instance method (-).
8314 c_parser_objc_method_type (c_parser
*parser
)
8316 switch (c_parser_peek_token (parser
)->type
)
8319 c_parser_consume_token (parser
);
8322 c_parser_consume_token (parser
);
8329 /* Parse an objc-method-definition.
8331 objc-method-definition:
8332 objc-method-type objc-method-decl ;[opt] compound-statement
8336 c_parser_objc_method_definition (c_parser
*parser
)
8338 bool is_class_method
= c_parser_objc_method_type (parser
);
8339 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
8340 parser
->objc_pq_context
= true;
8341 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8343 if (decl
== error_mark_node
)
8344 return; /* Bail here. */
8346 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8348 c_parser_consume_token (parser
);
8349 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8350 "extra semicolon in method definition specified");
8353 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8355 c_parser_error (parser
, "expected %<{%>");
8359 parser
->objc_pq_context
= false;
8360 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
8362 add_stmt (c_parser_compound_statement (parser
));
8363 objc_finish_method_definition (current_function_decl
);
8367 /* This code is executed when we find a method definition
8368 outside of an @implementation context (or invalid for other
8369 reasons). Parse the method (to keep going) but do not emit
8372 c_parser_compound_statement (parser
);
8376 /* Parse an objc-methodprotolist.
8378 objc-methodprotolist:
8380 objc-methodprotolist objc-methodproto
8381 objc-methodprotolist declaration
8382 objc-methodprotolist ;
8386 The declaration is a data definition, which may be missing
8387 declaration specifiers under the same rules and diagnostics as
8388 other data definitions outside functions, and the stray semicolon
8389 is diagnosed the same way as a stray semicolon outside a
8393 c_parser_objc_methodprotolist (c_parser
*parser
)
8397 /* The list is terminated by @end. */
8398 switch (c_parser_peek_token (parser
)->type
)
8401 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8402 "ISO C does not allow extra %<;%> outside of a function");
8403 c_parser_consume_token (parser
);
8407 c_parser_objc_methodproto (parser
);
8410 c_parser_pragma (parser
, pragma_external
);
8415 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
8417 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
8418 c_parser_objc_at_property_declaration (parser
);
8419 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
8421 objc_set_method_opt (true);
8422 c_parser_consume_token (parser
);
8424 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
8426 objc_set_method_opt (false);
8427 c_parser_consume_token (parser
);
8430 c_parser_declaration_or_fndef (parser
, false, false, true,
8431 false, true, NULL
, vNULL
);
8437 /* Parse an objc-methodproto.
8440 objc-method-type objc-method-decl ;
8444 c_parser_objc_methodproto (c_parser
*parser
)
8446 bool is_class_method
= c_parser_objc_method_type (parser
);
8447 tree decl
, attributes
= NULL_TREE
;
8449 /* Remember protocol qualifiers in prototypes. */
8450 parser
->objc_pq_context
= true;
8451 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
8453 /* Forget protocol qualifiers now. */
8454 parser
->objc_pq_context
= false;
8456 /* Do not allow the presence of attributes to hide an erroneous
8457 method implementation in the interface section. */
8458 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8460 c_parser_error (parser
, "expected %<;%>");
8464 if (decl
!= error_mark_node
)
8465 objc_add_method_declaration (is_class_method
, decl
, attributes
);
8467 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8470 /* If we are at a position that method attributes may be present, check that
8471 there are not any parsed already (a syntax error) and then collect any
8472 specified at the current location. Finally, if new attributes were present,
8473 check that the next token is legal ( ';' for decls and '{' for defs). */
8476 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
8481 c_parser_error (parser
,
8482 "method attributes must be specified at the end only");
8483 *attributes
= NULL_TREE
;
8487 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8488 *attributes
= c_parser_attributes (parser
);
8490 /* If there were no attributes here, just report any earlier error. */
8491 if (*attributes
== NULL_TREE
|| bad
)
8494 /* If the attributes are followed by a ; or {, then just report any earlier
8496 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
8497 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8500 /* We've got attributes, but not at the end. */
8501 c_parser_error (parser
,
8502 "expected %<;%> or %<{%> after method attribute definition");
8506 /* Parse an objc-method-decl.
8509 ( objc-type-name ) objc-selector
8511 ( objc-type-name ) objc-keyword-selector objc-optparmlist
8512 objc-keyword-selector objc-optparmlist
8515 objc-keyword-selector:
8517 objc-keyword-selector objc-keyword-decl
8520 objc-selector : ( objc-type-name ) identifier
8521 objc-selector : identifier
8522 : ( objc-type-name ) identifier
8526 objc-optparms objc-optellipsis
8530 objc-opt-parms , parameter-declaration
8538 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
8539 tree
*attributes
, tree
*expr
)
8541 tree type
= NULL_TREE
;
8543 tree parms
= NULL_TREE
;
8544 bool ellipsis
= false;
8545 bool attr_err
= false;
8547 *attributes
= NULL_TREE
;
8548 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8550 c_parser_consume_token (parser
);
8551 type
= c_parser_objc_type_name (parser
);
8552 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8554 sel
= c_parser_objc_selector (parser
);
8555 /* If there is no selector, or a colon follows, we have an
8556 objc-keyword-selector. If there is a selector, and a colon does
8557 not follow, that selector ends the objc-method-decl. */
8558 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
8561 tree list
= NULL_TREE
;
8564 tree atype
= NULL_TREE
, id
, keyworddecl
;
8565 tree param_attr
= NULL_TREE
;
8566 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8568 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8570 c_parser_consume_token (parser
);
8571 atype
= c_parser_objc_type_name (parser
);
8572 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8575 /* New ObjC allows attributes on method parameters. */
8576 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
8577 param_attr
= c_parser_attributes (parser
);
8578 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8580 c_parser_error (parser
, "expected identifier");
8581 return error_mark_node
;
8583 id
= c_parser_peek_token (parser
)->value
;
8584 c_parser_consume_token (parser
);
8585 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
8586 list
= chainon (list
, keyworddecl
);
8587 tsel
= c_parser_objc_selector (parser
);
8588 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8592 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8594 /* Parse the optional parameter list. Optional Objective-C
8595 method parameters follow the C syntax, and may include '...'
8596 to denote a variable number of arguments. */
8597 parms
= make_node (TREE_LIST
);
8598 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8600 struct c_parm
*parm
;
8601 c_parser_consume_token (parser
);
8602 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8605 c_parser_consume_token (parser
);
8606 attr_err
|= c_parser_objc_maybe_method_attributes
8607 (parser
, attributes
) ;
8610 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8613 parms
= chainon (parms
,
8614 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
8619 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
8623 c_parser_error (parser
, "objective-c method declaration is expected");
8624 return error_mark_node
;
8628 return error_mark_node
;
8630 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
8633 /* Parse an objc-type-name.
8636 objc-type-qualifiers[opt] type-name
8637 objc-type-qualifiers[opt]
8639 objc-type-qualifiers:
8641 objc-type-qualifiers objc-type-qualifier
8643 objc-type-qualifier: one of
8644 in out inout bycopy byref oneway
8648 c_parser_objc_type_name (c_parser
*parser
)
8650 tree quals
= NULL_TREE
;
8651 struct c_type_name
*type_name
= NULL
;
8652 tree type
= NULL_TREE
;
8655 c_token
*token
= c_parser_peek_token (parser
);
8656 if (token
->type
== CPP_KEYWORD
8657 && (token
->keyword
== RID_IN
8658 || token
->keyword
== RID_OUT
8659 || token
->keyword
== RID_INOUT
8660 || token
->keyword
== RID_BYCOPY
8661 || token
->keyword
== RID_BYREF
8662 || token
->keyword
== RID_ONEWAY
))
8664 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
8665 c_parser_consume_token (parser
);
8670 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
8671 type_name
= c_parser_type_name (parser
);
8673 type
= groktypename (type_name
, NULL
, NULL
);
8675 /* If the type is unknown, and error has already been produced and
8676 we need to recover from the error. In that case, use NULL_TREE
8677 for the type, as if no type had been specified; this will use the
8678 default type ('id') which is good for error recovery. */
8679 if (type
== error_mark_node
)
8682 return build_tree_list (quals
, type
);
8685 /* Parse objc-protocol-refs.
8692 c_parser_objc_protocol_refs (c_parser
*parser
)
8694 tree list
= NULL_TREE
;
8695 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
8696 c_parser_consume_token (parser
);
8697 /* Any identifiers, including those declared as type names, are OK
8702 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8704 c_parser_error (parser
, "expected identifier");
8707 id
= c_parser_peek_token (parser
)->value
;
8708 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
8709 c_parser_consume_token (parser
);
8710 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8711 c_parser_consume_token (parser
);
8715 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
8719 /* Parse an objc-try-catch-finally-statement.
8721 objc-try-catch-finally-statement:
8722 @try compound-statement objc-catch-list[opt]
8723 @try compound-statement objc-catch-list[opt] @finally compound-statement
8726 @catch ( objc-catch-parameter-declaration ) compound-statement
8727 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
8729 objc-catch-parameter-declaration:
8730 parameter-declaration
8733 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
8735 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
8736 for C++. Keep them in sync. */
8739 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
8741 location_t location
;
8744 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
8745 c_parser_consume_token (parser
);
8746 location
= c_parser_peek_token (parser
)->location
;
8747 objc_maybe_warn_exceptions (location
);
8748 stmt
= c_parser_compound_statement (parser
);
8749 objc_begin_try_stmt (location
, stmt
);
8751 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
8753 struct c_parm
*parm
;
8754 tree parameter_declaration
= error_mark_node
;
8755 bool seen_open_paren
= false;
8757 c_parser_consume_token (parser
);
8758 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8759 seen_open_paren
= true;
8760 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
8762 /* We have "@catch (...)" (where the '...' are literally
8763 what is in the code). Skip the '...'.
8764 parameter_declaration is set to NULL_TREE, and
8765 objc_being_catch_clauses() knows that that means
8767 c_parser_consume_token (parser
);
8768 parameter_declaration
= NULL_TREE
;
8772 /* We have "@catch (NSException *exception)" or something
8773 like that. Parse the parameter declaration. */
8774 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
8776 parameter_declaration
= error_mark_node
;
8778 parameter_declaration
= grokparm (parm
, NULL
);
8780 if (seen_open_paren
)
8781 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8784 /* If there was no open parenthesis, we are recovering from
8785 an error, and we are trying to figure out what mistake
8786 the user has made. */
8788 /* If there is an immediate closing parenthesis, the user
8789 probably forgot the opening one (ie, they typed "@catch
8790 NSException *e)". Parse the closing parenthesis and keep
8792 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8793 c_parser_consume_token (parser
);
8795 /* If these is no immediate closing parenthesis, the user
8796 probably doesn't know that parenthesis are required at
8797 all (ie, they typed "@catch NSException *e"). So, just
8798 forget about the closing parenthesis and keep going. */
8800 objc_begin_catch_clause (parameter_declaration
);
8801 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
8802 c_parser_compound_statement_nostart (parser
);
8803 objc_finish_catch_clause ();
8805 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
8807 c_parser_consume_token (parser
);
8808 location
= c_parser_peek_token (parser
)->location
;
8809 stmt
= c_parser_compound_statement (parser
);
8810 objc_build_finally_clause (location
, stmt
);
8812 objc_finish_try_stmt ();
8815 /* Parse an objc-synchronized-statement.
8817 objc-synchronized-statement:
8818 @synchronized ( expression ) compound-statement
8822 c_parser_objc_synchronized_statement (c_parser
*parser
)
8826 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
8827 c_parser_consume_token (parser
);
8828 loc
= c_parser_peek_token (parser
)->location
;
8829 objc_maybe_warn_exceptions (loc
);
8830 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8832 struct c_expr ce
= c_parser_expression (parser
);
8833 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8835 expr
= c_fully_fold (expr
, false, NULL
);
8836 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8839 expr
= error_mark_node
;
8840 stmt
= c_parser_compound_statement (parser
);
8841 objc_build_synchronized (loc
, expr
, stmt
);
8844 /* Parse an objc-selector; return NULL_TREE without an error if the
8845 next token is not an objc-selector.
8850 enum struct union if else while do for switch case default
8851 break continue return goto asm sizeof typeof __alignof
8852 unsigned long const short volatile signed restrict _Complex
8853 in out inout bycopy byref oneway int char float double void _Bool
8856 ??? Why this selection of keywords but not, for example, storage
8857 class specifiers? */
8860 c_parser_objc_selector (c_parser
*parser
)
8862 c_token
*token
= c_parser_peek_token (parser
);
8863 tree value
= token
->value
;
8864 if (token
->type
== CPP_NAME
)
8866 c_parser_consume_token (parser
);
8869 if (token
->type
!= CPP_KEYWORD
)
8871 switch (token
->keyword
)
8915 c_parser_consume_token (parser
);
8922 /* Parse an objc-selector-arg.
8926 objc-keywordname-list
8928 objc-keywordname-list:
8930 objc-keywordname-list objc-keywordname
8938 c_parser_objc_selector_arg (c_parser
*parser
)
8940 tree sel
= c_parser_objc_selector (parser
);
8941 tree list
= NULL_TREE
;
8942 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8946 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
8948 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
8949 sel
= c_parser_objc_selector (parser
);
8950 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
8956 /* Parse an objc-receiver.
8965 c_parser_objc_receiver (c_parser
*parser
)
8967 location_t loc
= c_parser_peek_token (parser
)->location
;
8969 if (c_parser_peek_token (parser
)->type
== CPP_NAME
8970 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
8971 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
8973 tree id
= c_parser_peek_token (parser
)->value
;
8974 c_parser_consume_token (parser
);
8975 return objc_get_class_reference (id
);
8977 struct c_expr ce
= c_parser_expression (parser
);
8978 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8979 return c_fully_fold (ce
.value
, false, NULL
);
8982 /* Parse objc-message-args.
8986 objc-keywordarg-list
8988 objc-keywordarg-list:
8990 objc-keywordarg-list objc-keywordarg
8993 objc-selector : objc-keywordexpr
8998 c_parser_objc_message_args (c_parser
*parser
)
9000 tree sel
= c_parser_objc_selector (parser
);
9001 tree list
= NULL_TREE
;
9002 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9007 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9008 return error_mark_node
;
9009 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9010 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9011 sel
= c_parser_objc_selector (parser
);
9012 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9018 /* Parse an objc-keywordexpr.
9025 c_parser_objc_keywordexpr (c_parser
*parser
)
9028 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9029 NULL
, NULL
, NULL
, NULL
);
9030 if (vec_safe_length (expr_list
) == 1)
9032 /* Just return the expression, remove a level of
9034 ret
= (*expr_list
)[0];
9038 /* We have a comma expression, we will collapse later. */
9039 ret
= build_tree_list_vec (expr_list
);
9041 release_tree_vector (expr_list
);
9045 /* A check, needed in several places, that ObjC interface, implementation or
9046 method definitions are not prefixed by incorrect items. */
9048 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9049 struct c_declspecs
*specs
)
9051 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9052 || specs
->typespec_kind
!= ctsk_none
)
9054 c_parser_error (parser
,
9055 "no type or storage class may be specified here,");
9056 c_parser_skip_to_end_of_block_or_statement (parser
);
9062 /* Parse an Objective-C @property declaration. The syntax is:
9064 objc-property-declaration:
9065 '@property' objc-property-attributes[opt] struct-declaration ;
9067 objc-property-attributes:
9068 '(' objc-property-attribute-list ')'
9070 objc-property-attribute-list:
9071 objc-property-attribute
9072 objc-property-attribute-list, objc-property-attribute
9074 objc-property-attribute
9075 'getter' = identifier
9076 'setter' = identifier
9085 @property NSString *name;
9086 @property (readonly) id object;
9087 @property (retain, nonatomic, getter=getTheName) id name;
9088 @property int a, b, c;
9090 PS: This function is identical to cp_parser_objc_at_propery_declaration
9091 for C++. Keep them in sync. */
9093 c_parser_objc_at_property_declaration (c_parser
*parser
)
9095 /* The following variables hold the attributes of the properties as
9096 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9097 seen. When we see an attribute, we set them to 'true' (if they
9098 are boolean properties) or to the identifier (if they have an
9099 argument, ie, for getter and setter). Note that here we only
9100 parse the list of attributes, check the syntax and accumulate the
9101 attributes that we find. objc_add_property_declaration() will
9102 then process the information. */
9103 bool property_assign
= false;
9104 bool property_copy
= false;
9105 tree property_getter_ident
= NULL_TREE
;
9106 bool property_nonatomic
= false;
9107 bool property_readonly
= false;
9108 bool property_readwrite
= false;
9109 bool property_retain
= false;
9110 tree property_setter_ident
= NULL_TREE
;
9112 /* 'properties' is the list of properties that we read. Usually a
9113 single one, but maybe more (eg, in "@property int a, b, c;" there
9118 loc
= c_parser_peek_token (parser
)->location
;
9119 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9121 c_parser_consume_token (parser
); /* Eat '@property'. */
9123 /* Parse the optional attribute list... */
9124 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9127 c_parser_consume_token (parser
);
9129 /* Property attribute keywords are valid now. */
9130 parser
->objc_property_attr_context
= true;
9134 bool syntax_error
= false;
9135 c_token
*token
= c_parser_peek_token (parser
);
9138 if (token
->type
!= CPP_KEYWORD
)
9140 if (token
->type
== CPP_CLOSE_PAREN
)
9141 c_parser_error (parser
, "expected identifier");
9144 c_parser_consume_token (parser
);
9145 c_parser_error (parser
, "unknown property attribute");
9149 keyword
= token
->keyword
;
9150 c_parser_consume_token (parser
);
9153 case RID_ASSIGN
: property_assign
= true; break;
9154 case RID_COPY
: property_copy
= true; break;
9155 case RID_NONATOMIC
: property_nonatomic
= true; break;
9156 case RID_READONLY
: property_readonly
= true; break;
9157 case RID_READWRITE
: property_readwrite
= true; break;
9158 case RID_RETAIN
: property_retain
= true; break;
9162 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9164 if (keyword
== RID_GETTER
)
9165 c_parser_error (parser
,
9166 "missing %<=%> (after %<getter%> attribute)");
9168 c_parser_error (parser
,
9169 "missing %<=%> (after %<setter%> attribute)");
9170 syntax_error
= true;
9173 c_parser_consume_token (parser
); /* eat the = */
9174 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9176 c_parser_error (parser
, "expected identifier");
9177 syntax_error
= true;
9180 if (keyword
== RID_SETTER
)
9182 if (property_setter_ident
!= NULL_TREE
)
9183 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9185 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9186 c_parser_consume_token (parser
);
9187 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9188 c_parser_error (parser
, "setter name must terminate with %<:%>");
9190 c_parser_consume_token (parser
);
9194 if (property_getter_ident
!= NULL_TREE
)
9195 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9197 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9198 c_parser_consume_token (parser
);
9202 c_parser_error (parser
, "unknown property attribute");
9203 syntax_error
= true;
9210 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9211 c_parser_consume_token (parser
);
9215 parser
->objc_property_attr_context
= false;
9216 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9218 /* ... and the property declaration(s). */
9219 properties
= c_parser_struct_declaration (parser
);
9221 if (properties
== error_mark_node
)
9223 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9224 parser
->error
= false;
9228 if (properties
== NULL_TREE
)
9229 c_parser_error (parser
, "expected identifier");
9232 /* Comma-separated properties are chained together in
9233 reverse order; add them one by one. */
9234 properties
= nreverse (properties
);
9236 for (; properties
; properties
= TREE_CHAIN (properties
))
9237 objc_add_property_declaration (loc
, copy_node (properties
),
9238 property_readonly
, property_readwrite
,
9239 property_assign
, property_retain
,
9240 property_copy
, property_nonatomic
,
9241 property_getter_ident
, property_setter_ident
);
9244 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9245 parser
->error
= false;
9248 /* Parse an Objective-C @synthesize declaration. The syntax is:
9250 objc-synthesize-declaration:
9251 @synthesize objc-synthesize-identifier-list ;
9253 objc-synthesize-identifier-list:
9254 objc-synthesize-identifier
9255 objc-synthesize-identifier-list, objc-synthesize-identifier
9257 objc-synthesize-identifier
9259 identifier = identifier
9262 @synthesize MyProperty;
9263 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
9265 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
9266 for C++. Keep them in sync.
9269 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
9271 tree list
= NULL_TREE
;
9273 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
9274 loc
= c_parser_peek_token (parser
)->location
;
9276 c_parser_consume_token (parser
);
9279 tree property
, ivar
;
9280 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9282 c_parser_error (parser
, "expected identifier");
9283 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9284 /* Once we find the semicolon, we can resume normal parsing.
9285 We have to reset parser->error manually because
9286 c_parser_skip_until_found() won't reset it for us if the
9287 next token is precisely a semicolon. */
9288 parser
->error
= false;
9291 property
= c_parser_peek_token (parser
)->value
;
9292 c_parser_consume_token (parser
);
9293 if (c_parser_next_token_is (parser
, CPP_EQ
))
9295 c_parser_consume_token (parser
);
9296 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9298 c_parser_error (parser
, "expected identifier");
9299 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9300 parser
->error
= false;
9303 ivar
= c_parser_peek_token (parser
)->value
;
9304 c_parser_consume_token (parser
);
9308 list
= chainon (list
, build_tree_list (ivar
, property
));
9309 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9310 c_parser_consume_token (parser
);
9314 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9315 objc_add_synthesize_declaration (loc
, list
);
9318 /* Parse an Objective-C @dynamic declaration. The syntax is:
9320 objc-dynamic-declaration:
9321 @dynamic identifier-list ;
9324 @dynamic MyProperty;
9325 @dynamic MyProperty, AnotherProperty;
9327 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
9328 for C++. Keep them in sync.
9331 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
9333 tree list
= NULL_TREE
;
9335 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
9336 loc
= c_parser_peek_token (parser
)->location
;
9338 c_parser_consume_token (parser
);
9342 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9344 c_parser_error (parser
, "expected identifier");
9345 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9346 parser
->error
= false;
9349 property
= c_parser_peek_token (parser
)->value
;
9350 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
9351 c_parser_consume_token (parser
);
9352 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9353 c_parser_consume_token (parser
);
9357 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9358 objc_add_dynamic_declaration (loc
, list
);
9362 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
9363 should be considered, statements. ALLOW_STMT is true if we're within
9364 the context of a function and such pragmas are to be allowed. Returns
9365 true if we actually parsed such a pragma. */
9368 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
9372 id
= c_parser_peek_token (parser
)->pragma_kind
;
9373 gcc_assert (id
!= PRAGMA_NONE
);
9377 case PRAGMA_OMP_BARRIER
:
9378 if (context
!= pragma_compound
)
9380 if (context
== pragma_stmt
)
9381 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
9382 "used in compound statements");
9385 c_parser_omp_barrier (parser
);
9388 case PRAGMA_OMP_FLUSH
:
9389 if (context
!= pragma_compound
)
9391 if (context
== pragma_stmt
)
9392 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
9393 "used in compound statements");
9396 c_parser_omp_flush (parser
);
9399 case PRAGMA_OMP_TASKWAIT
:
9400 if (context
!= pragma_compound
)
9402 if (context
== pragma_stmt
)
9403 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
9404 "used in compound statements");
9407 c_parser_omp_taskwait (parser
);
9410 case PRAGMA_OMP_TASKYIELD
:
9411 if (context
!= pragma_compound
)
9413 if (context
== pragma_stmt
)
9414 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
9415 "used in compound statements");
9418 c_parser_omp_taskyield (parser
);
9421 case PRAGMA_OMP_CANCEL
:
9422 if (context
!= pragma_compound
)
9424 if (context
== pragma_stmt
)
9425 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
9426 "used in compound statements");
9429 c_parser_omp_cancel (parser
);
9432 case PRAGMA_OMP_CANCELLATION_POINT
:
9433 if (context
!= pragma_compound
)
9435 if (context
== pragma_stmt
)
9436 c_parser_error (parser
, "%<#pragma omp cancellation point%> may "
9437 "only be used in compound statements");
9440 c_parser_omp_cancellation_point (parser
);
9443 case PRAGMA_OMP_THREADPRIVATE
:
9444 c_parser_omp_threadprivate (parser
);
9447 case PRAGMA_OMP_TARGET
:
9448 return c_parser_omp_target (parser
, context
);
9450 case PRAGMA_OMP_END_DECLARE_TARGET
:
9451 c_parser_omp_end_declare_target (parser
);
9454 case PRAGMA_OMP_SECTION
:
9455 error_at (c_parser_peek_token (parser
)->location
,
9456 "%<#pragma omp section%> may only be used in "
9457 "%<#pragma omp sections%> construct");
9458 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9461 case PRAGMA_OMP_DECLARE_REDUCTION
:
9462 c_parser_omp_declare (parser
, context
);
9465 c_parser_consume_pragma (parser
);
9466 c_parser_skip_to_pragma_eol (parser
);
9467 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
9468 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
9469 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
9471 c_parser_error (parser
, "for, while or do statement expected");
9474 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9475 c_parser_for_statement (parser
, true);
9476 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
9477 c_parser_while_statement (parser
, true);
9479 c_parser_do_statement (parser
, true);
9482 case PRAGMA_GCC_PCH_PREPROCESS
:
9483 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
9484 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9487 case PRAGMA_CILK_SIMD
:
9488 if (!c_parser_cilk_verify_simd (parser
, context
))
9490 c_parser_consume_pragma (parser
);
9491 c_parser_cilk_simd (parser
);
9495 if (id
< PRAGMA_FIRST_EXTERNAL
)
9497 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
9500 c_parser_error (parser
, "expected declaration specifiers");
9501 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
9504 c_parser_omp_construct (parser
);
9510 c_parser_consume_pragma (parser
);
9511 c_invoke_pragma_handler (id
);
9513 /* Skip to EOL, but suppress any error message. Those will have been
9514 generated by the handler routine through calling error, as opposed
9515 to calling c_parser_error. */
9516 parser
->error
= true;
9517 c_parser_skip_to_pragma_eol (parser
);
9522 /* The interface the pragma parsers have to the lexer. */
9525 pragma_lex (tree
*value
)
9527 c_token
*tok
= c_parser_peek_token (the_parser
);
9528 enum cpp_ttype ret
= tok
->type
;
9530 *value
= tok
->value
;
9531 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
9535 if (ret
== CPP_KEYWORD
)
9537 c_parser_consume_token (the_parser
);
9544 c_parser_pragma_pch_preprocess (c_parser
*parser
)
9548 c_parser_consume_pragma (parser
);
9549 if (c_parser_next_token_is (parser
, CPP_STRING
))
9551 name
= c_parser_peek_token (parser
)->value
;
9552 c_parser_consume_token (parser
);
9555 c_parser_error (parser
, "expected string literal");
9556 c_parser_skip_to_pragma_eol (parser
);
9559 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
9562 /* OpenMP 2.5 / 3.0 / 3.1 / 4.0 parsing routines. */
9564 /* Returns name of the next clause.
9565 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
9566 the token is not consumed. Otherwise appropriate pragma_omp_clause is
9567 returned and the token is consumed. */
9569 static pragma_omp_clause
9570 c_parser_omp_clause_name (c_parser
*parser
)
9572 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
9574 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
9575 result
= PRAGMA_OMP_CLAUSE_IF
;
9576 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
9577 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
9578 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
9579 result
= PRAGMA_OMP_CLAUSE_FOR
;
9580 else if (c_parser_next_token_is (parser
, CPP_NAME
))
9582 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9587 if (!strcmp ("aligned", p
))
9588 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
9591 if (!strcmp ("collapse", p
))
9592 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
9593 else if (!strcmp ("copyin", p
))
9594 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
9595 else if (!strcmp ("copyprivate", p
))
9596 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
9599 if (!strcmp ("depend", p
))
9600 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
9601 else if (!strcmp ("device", p
))
9602 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
9603 else if (!strcmp ("dist_schedule", p
))
9604 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
9607 if (!strcmp ("final", p
))
9608 result
= PRAGMA_OMP_CLAUSE_FINAL
;
9609 else if (!strcmp ("firstprivate", p
))
9610 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
9611 else if (!strcmp ("from", p
))
9612 result
= PRAGMA_OMP_CLAUSE_FROM
;
9615 if (!strcmp ("inbranch", p
))
9616 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
9619 if (!strcmp ("lastprivate", p
))
9620 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
9621 else if (!strcmp ("linear", p
))
9622 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
9625 if (!strcmp ("map", p
))
9626 result
= PRAGMA_OMP_CLAUSE_MAP
;
9627 else if (!strcmp ("mergeable", p
))
9628 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
9629 else if (flag_cilkplus
&& !strcmp ("mask", p
))
9630 result
= PRAGMA_CILK_CLAUSE_MASK
;
9633 if (!strcmp ("notinbranch", p
))
9634 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
9635 else if (!strcmp ("nowait", p
))
9636 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
9637 else if (!strcmp ("num_teams", p
))
9638 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
9639 else if (!strcmp ("num_threads", p
))
9640 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
9641 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
9642 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
9645 if (!strcmp ("ordered", p
))
9646 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
9649 if (!strcmp ("parallel", p
))
9650 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
9651 else if (!strcmp ("private", p
))
9652 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
9653 else if (!strcmp ("proc_bind", p
))
9654 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
9657 if (!strcmp ("reduction", p
))
9658 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
9661 if (!strcmp ("safelen", p
))
9662 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
9663 else if (!strcmp ("schedule", p
))
9664 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
9665 else if (!strcmp ("sections", p
))
9666 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
9667 else if (!strcmp ("shared", p
))
9668 result
= PRAGMA_OMP_CLAUSE_SHARED
;
9669 else if (!strcmp ("simdlen", p
))
9670 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
9673 if (!strcmp ("taskgroup", p
))
9674 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
9675 else if (!strcmp ("thread_limit", p
))
9676 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
9677 else if (!strcmp ("to", p
))
9678 result
= PRAGMA_OMP_CLAUSE_TO
;
9681 if (!strcmp ("uniform", p
))
9682 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
9683 else if (!strcmp ("untied", p
))
9684 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
9687 if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
9688 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
9693 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
9694 c_parser_consume_token (parser
);
9699 /* Validate that a clause of the given type does not already exist. */
9702 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
9707 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9708 if (OMP_CLAUSE_CODE (c
) == code
)
9710 location_t loc
= OMP_CLAUSE_LOCATION (c
);
9711 error_at (loc
, "too many %qs clauses", name
);
9719 variable-list , identifier
9721 If KIND is nonzero, create the appropriate node and install the
9722 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
9723 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
9725 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
9726 return the list created. */
9729 c_parser_omp_variable_list (c_parser
*parser
,
9730 location_t clause_loc
,
9731 enum omp_clause_code kind
, tree list
)
9733 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
9734 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
9735 c_parser_error (parser
, "expected identifier");
9737 while (c_parser_next_token_is (parser
, CPP_NAME
)
9738 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
9740 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
9744 undeclared_variable (c_parser_peek_token (parser
)->location
,
9745 c_parser_peek_token (parser
)->value
);
9746 t
= error_mark_node
;
9749 c_parser_consume_token (parser
);
9751 if (t
== error_mark_node
)
9757 case OMP_CLAUSE_MAP
:
9758 case OMP_CLAUSE_FROM
:
9760 case OMP_CLAUSE_DEPEND
:
9761 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
9763 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
9765 c_parser_consume_token (parser
);
9766 if (!c_parser_next_token_is (parser
, CPP_COLON
))
9768 low_bound
= c_parser_expression (parser
).value
;
9769 mark_exp_read (low_bound
);
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
))
9784 length
= c_parser_expression (parser
).value
;
9785 mark_exp_read (length
);
9788 /* Look for the closing `]'. */
9789 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
9792 t
= error_mark_node
;
9795 t
= tree_cons (low_bound
, length
, t
);
9802 if (t
!= error_mark_node
)
9804 tree u
= build_omp_clause (clause_loc
, kind
);
9805 OMP_CLAUSE_DECL (u
) = t
;
9806 OMP_CLAUSE_CHAIN (u
) = list
;
9811 list
= tree_cons (t
, NULL_TREE
, list
);
9813 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
9816 c_parser_consume_token (parser
);
9822 /* Similarly, but expect leading and trailing parenthesis. This is a very
9823 common case for omp clauses. */
9826 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
9829 /* The clauses location. */
9830 location_t loc
= c_parser_peek_token (parser
)->location
;
9832 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9834 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
9835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9841 collapse ( constant-expression ) */
9844 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
9846 tree c
, num
= error_mark_node
;
9850 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
9852 loc
= c_parser_peek_token (parser
)->location
;
9853 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9855 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
9856 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9858 if (num
== error_mark_node
)
9860 mark_exp_read (num
);
9861 num
= c_fully_fold (num
, false, NULL
);
9862 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
9863 || !tree_fits_shwi_p (num
)
9864 || (n
= tree_to_shwi (num
)) <= 0
9868 "collapse argument needs positive constant integer expression");
9871 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
9872 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
9873 OMP_CLAUSE_CHAIN (c
) = list
;
9878 copyin ( variable-list ) */
9881 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
9883 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
9887 copyprivate ( variable-list ) */
9890 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
9892 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
9896 default ( shared | none ) */
9899 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
9901 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
9902 location_t loc
= c_parser_peek_token (parser
)->location
;
9905 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9907 if (c_parser_next_token_is (parser
, CPP_NAME
))
9909 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
9914 if (strcmp ("none", p
) != 0)
9916 kind
= OMP_CLAUSE_DEFAULT_NONE
;
9920 if (strcmp ("shared", p
) != 0)
9922 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
9929 c_parser_consume_token (parser
);
9934 c_parser_error (parser
, "expected %<none%> or %<shared%>");
9936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9938 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
9941 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
9942 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
9943 OMP_CLAUSE_CHAIN (c
) = list
;
9944 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
9950 firstprivate ( variable-list ) */
9953 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
9955 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
9959 final ( expression ) */
9962 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
9964 location_t loc
= c_parser_peek_token (parser
)->location
;
9965 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9967 tree t
= c_parser_paren_condition (parser
);
9970 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
9972 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
9973 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
9974 OMP_CLAUSE_CHAIN (c
) = list
;
9978 c_parser_error (parser
, "expected %<(%>");
9984 if ( expression ) */
9987 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
9989 location_t loc
= c_parser_peek_token (parser
)->location
;
9990 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9992 tree t
= c_parser_paren_condition (parser
);
9995 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
9997 c
= build_omp_clause (loc
, OMP_CLAUSE_IF
);
9998 OMP_CLAUSE_IF_EXPR (c
) = t
;
9999 OMP_CLAUSE_CHAIN (c
) = list
;
10003 c_parser_error (parser
, "expected %<(%>");
10009 lastprivate ( variable-list ) */
10012 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
10014 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
10021 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10025 /* FIXME: Should we allow duplicates? */
10026 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
10028 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10029 OMP_CLAUSE_MERGEABLE
);
10030 OMP_CLAUSE_CHAIN (c
) = list
;
10039 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10042 location_t loc
= c_parser_peek_token (parser
)->location
;
10044 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
10046 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
10047 OMP_CLAUSE_CHAIN (c
) = list
;
10052 num_threads ( expression ) */
10055 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
10057 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
10058 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10060 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10061 tree c
, t
= c_parser_expression (parser
).value
;
10063 t
= c_fully_fold (t
, false, NULL
);
10065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10067 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10069 c_parser_error (parser
, "expected integer expression");
10073 /* Attempt to statically determine when the number isn't positive. */
10074 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10075 build_int_cst (TREE_TYPE (t
), 0));
10076 if (CAN_HAVE_LOCATION_P (c
))
10077 SET_EXPR_LOCATION (c
, expr_loc
);
10078 if (c
== boolean_true_node
)
10080 warning_at (expr_loc
, 0,
10081 "%<num_threads%> value must be positive");
10082 t
= integer_one_node
;
10085 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
10087 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
10088 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
10089 OMP_CLAUSE_CHAIN (c
) = list
;
10100 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
10104 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
10106 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10107 OMP_CLAUSE_ORDERED
);
10108 OMP_CLAUSE_CHAIN (c
) = list
;
10114 private ( variable-list ) */
10117 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
10119 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
10123 reduction ( reduction-operator : variable-list )
10125 reduction-operator:
10126 One of: + * - & ^ | && ||
10130 reduction-operator:
10131 One of: + * - & ^ | && || max min
10135 reduction-operator:
10136 One of: + * - & ^ | && ||
10140 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
10142 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10143 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10145 enum tree_code code
= ERROR_MARK
;
10146 tree reduc_id
= NULL_TREE
;
10148 switch (c_parser_peek_token (parser
)->type
)
10160 code
= BIT_AND_EXPR
;
10163 code
= BIT_XOR_EXPR
;
10166 code
= BIT_IOR_EXPR
;
10169 code
= TRUTH_ANDIF_EXPR
;
10172 code
= TRUTH_ORIF_EXPR
;
10177 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10178 if (strcmp (p
, "min") == 0)
10183 if (strcmp (p
, "max") == 0)
10188 reduc_id
= c_parser_peek_token (parser
)->value
;
10192 c_parser_error (parser
,
10193 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
10194 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
10195 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10198 c_parser_consume_token (parser
);
10199 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
10200 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10204 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10205 OMP_CLAUSE_REDUCTION
, list
);
10206 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10208 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
10209 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
10210 if (code
== ERROR_MARK
10211 || !(INTEGRAL_TYPE_P (type
)
10212 || TREE_CODE (type
) == REAL_TYPE
10213 || TREE_CODE (type
) == COMPLEX_TYPE
))
10214 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
10215 = c_omp_reduction_lookup (reduc_id
,
10216 TYPE_MAIN_VARIANT (type
));
10221 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10227 schedule ( schedule-kind )
10228 schedule ( schedule-kind , expression )
10231 static | dynamic | guided | runtime | auto
10235 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
10238 location_t loc
= c_parser_peek_token (parser
)->location
;
10240 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10243 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
10245 if (c_parser_next_token_is (parser
, CPP_NAME
))
10247 tree kind
= c_parser_peek_token (parser
)->value
;
10248 const char *p
= IDENTIFIER_POINTER (kind
);
10253 if (strcmp ("dynamic", p
) != 0)
10255 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
10259 if (strcmp ("guided", p
) != 0)
10261 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
10265 if (strcmp ("runtime", p
) != 0)
10267 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
10274 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10275 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
10276 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10277 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
10281 c_parser_consume_token (parser
);
10282 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10285 c_parser_consume_token (parser
);
10287 here
= c_parser_peek_token (parser
)->location
;
10288 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10290 t
= c_fully_fold (t
, false, NULL
);
10292 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
10293 error_at (here
, "schedule %<runtime%> does not take "
10294 "a %<chunk_size%> parameter");
10295 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
10297 "schedule %<auto%> does not take "
10298 "a %<chunk_size%> parameter");
10299 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
10300 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
10302 c_parser_error (parser
, "expected integer expression");
10304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10307 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10308 "expected %<,%> or %<)%>");
10310 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10311 OMP_CLAUSE_CHAIN (c
) = list
;
10315 c_parser_error (parser
, "invalid schedule kind");
10316 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
10321 shared ( variable-list ) */
10324 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
10326 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
10333 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
10337 /* FIXME: Should we allow duplicates? */
10338 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
10340 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
10341 OMP_CLAUSE_UNTIED
);
10342 OMP_CLAUSE_CHAIN (c
) = list
;
10352 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
10353 enum omp_clause_code code
, tree list
)
10355 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
10357 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10358 OMP_CLAUSE_CHAIN (c
) = list
;
10370 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
10371 enum omp_clause_code code
, tree list
)
10373 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
10374 OMP_CLAUSE_CHAIN (c
) = list
;
10380 num_teams ( expression ) */
10383 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
10385 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10386 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10388 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10389 tree c
, t
= c_parser_expression (parser
).value
;
10391 t
= c_fully_fold (t
, false, NULL
);
10393 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10395 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10397 c_parser_error (parser
, "expected integer expression");
10401 /* Attempt to statically determine when the number isn't positive. */
10402 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10403 build_int_cst (TREE_TYPE (t
), 0));
10404 if (CAN_HAVE_LOCATION_P (c
))
10405 SET_EXPR_LOCATION (c
, expr_loc
);
10406 if (c
== boolean_true_node
)
10408 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
10409 t
= integer_one_node
;
10412 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
10414 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10415 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
10416 OMP_CLAUSE_CHAIN (c
) = list
;
10424 thread_limit ( expression ) */
10427 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
10429 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
10430 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10432 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
10433 tree c
, t
= c_parser_expression (parser
).value
;
10435 t
= c_fully_fold (t
, false, NULL
);
10437 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10439 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10441 c_parser_error (parser
, "expected integer expression");
10445 /* Attempt to statically determine when the number isn't positive. */
10446 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
10447 build_int_cst (TREE_TYPE (t
), 0));
10448 if (CAN_HAVE_LOCATION_P (c
))
10449 SET_EXPR_LOCATION (c
, expr_loc
);
10450 if (c
== boolean_true_node
)
10452 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
10453 t
= integer_one_node
;
10456 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
10459 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10460 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
10461 OMP_CLAUSE_CHAIN (c
) = list
;
10469 aligned ( variable-list )
10470 aligned ( variable-list : constant-expression ) */
10473 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
10475 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10478 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10481 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10482 OMP_CLAUSE_ALIGNED
, list
);
10484 if (c_parser_next_token_is (parser
, CPP_COLON
))
10486 c_parser_consume_token (parser
);
10487 tree alignment
= c_parser_expr_no_commas (parser
, NULL
).value
;
10488 mark_exp_read (alignment
);
10489 alignment
= c_fully_fold (alignment
, false, NULL
);
10490 if (!INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
10491 && TREE_CODE (alignment
) != INTEGER_CST
10492 && tree_int_cst_sgn (alignment
) != 1)
10494 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
10495 "be positive constant integer expression");
10496 alignment
= NULL_TREE
;
10499 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10500 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
10503 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10508 linear ( variable-list )
10509 linear ( variable-list : expression ) */
10512 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
10514 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10517 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10520 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10521 OMP_CLAUSE_LINEAR
, list
);
10523 if (c_parser_next_token_is (parser
, CPP_COLON
))
10525 c_parser_consume_token (parser
);
10526 step
= c_parser_expression (parser
).value
;
10527 mark_exp_read (step
);
10528 step
= c_fully_fold (step
, false, NULL
);
10529 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
10531 sorry ("using parameters for %<linear%> step is not supported yet");
10532 step
= integer_one_node
;
10534 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
10536 error_at (clause_loc
, "%<linear%> clause step expression must "
10538 step
= integer_one_node
;
10543 step
= integer_one_node
;
10545 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10547 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10550 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10555 safelen ( constant-expression ) */
10558 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
10560 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10563 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10566 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10568 t
= c_fully_fold (t
, false, NULL
);
10569 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10570 && TREE_CODE (t
) != INTEGER_CST
10571 && tree_int_cst_sgn (t
) != 1)
10573 error_at (clause_loc
, "%<safelen%> clause expression must "
10574 "be positive constant integer expression");
10578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10579 if (t
== NULL_TREE
|| t
== error_mark_node
)
10582 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
10584 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
10585 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
10586 OMP_CLAUSE_CHAIN (c
) = list
;
10591 simdlen ( constant-expression ) */
10594 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
10596 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10599 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10602 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10604 t
= c_fully_fold (t
, false, NULL
);
10605 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
10606 && TREE_CODE (t
) != INTEGER_CST
10607 && tree_int_cst_sgn (t
) != 1)
10609 error_at (clause_loc
, "%<simdlen%> clause expression must "
10610 "be positive constant integer expression");
10614 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10615 if (t
== NULL_TREE
|| t
== error_mark_node
)
10618 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
10620 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
10621 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
10622 OMP_CLAUSE_CHAIN (c
) = list
;
10627 depend ( depend-kind: variable-list )
10630 in | out | inout */
10633 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
10635 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10636 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
10639 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10642 if (c_parser_next_token_is (parser
, CPP_NAME
))
10644 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10645 if (strcmp ("in", p
) == 0)
10646 kind
= OMP_CLAUSE_DEPEND_IN
;
10647 else if (strcmp ("inout", p
) == 0)
10648 kind
= OMP_CLAUSE_DEPEND_INOUT
;
10649 else if (strcmp ("out", p
) == 0)
10650 kind
= OMP_CLAUSE_DEPEND_OUT
;
10657 c_parser_consume_token (parser
);
10658 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10661 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
10662 OMP_CLAUSE_DEPEND
, list
);
10664 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10665 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
10667 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10671 c_parser_error (parser
, "invalid depend kind");
10673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10678 map ( map-kind: variable-list )
10679 map ( variable-list )
10682 alloc | to | from | tofrom */
10685 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
10687 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10688 enum omp_clause_map_kind kind
= OMP_CLAUSE_MAP_TOFROM
;
10691 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10694 if (c_parser_next_token_is (parser
, CPP_NAME
)
10695 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
10697 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10698 if (strcmp ("alloc", p
) == 0)
10699 kind
= OMP_CLAUSE_MAP_ALLOC
;
10700 else if (strcmp ("to", p
) == 0)
10701 kind
= OMP_CLAUSE_MAP_TO
;
10702 else if (strcmp ("from", p
) == 0)
10703 kind
= OMP_CLAUSE_MAP_FROM
;
10704 else if (strcmp ("tofrom", p
) == 0)
10705 kind
= OMP_CLAUSE_MAP_TOFROM
;
10708 c_parser_error (parser
, "invalid map kind");
10709 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10713 c_parser_consume_token (parser
);
10714 c_parser_consume_token (parser
);
10717 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
10719 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10720 OMP_CLAUSE_MAP_KIND (c
) = kind
;
10722 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10727 device ( expression ) */
10730 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
10732 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10733 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10735 tree c
, t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10737 t
= c_fully_fold (t
, false, NULL
);
10739 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10741 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
10743 c_parser_error (parser
, "expected integer expression");
10747 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
10749 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
10750 OMP_CLAUSE_DEVICE_ID (c
) = t
;
10751 OMP_CLAUSE_CHAIN (c
) = list
;
10759 dist_schedule ( static )
10760 dist_schedule ( static , expression ) */
10763 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
10765 tree c
, t
= NULL_TREE
;
10766 location_t loc
= c_parser_peek_token (parser
)->location
;
10768 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10771 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
10773 c_parser_error (parser
, "invalid dist_schedule kind");
10774 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10779 c_parser_consume_token (parser
);
10780 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10782 c_parser_consume_token (parser
);
10784 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
10786 t
= c_fully_fold (t
, false, NULL
);
10787 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10790 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10791 "expected %<,%> or %<)%>");
10793 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
10794 if (t
== error_mark_node
)
10797 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
10798 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
10799 OMP_CLAUSE_CHAIN (c
) = list
;
10804 proc_bind ( proc-bind-kind )
10807 master | close | spread */
10810 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
10812 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
10813 enum omp_clause_proc_bind_kind kind
;
10816 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10819 if (c_parser_next_token_is (parser
, CPP_NAME
))
10821 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10822 if (strcmp ("master", p
) == 0)
10823 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
10824 else if (strcmp ("close", p
) == 0)
10825 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
10826 else if (strcmp ("spread", p
) == 0)
10827 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
10834 c_parser_consume_token (parser
);
10835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10836 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
10837 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
10838 OMP_CLAUSE_CHAIN (c
) = list
;
10842 c_parser_error (parser
, "invalid proc_bind kind");
10843 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10848 to ( variable-list ) */
10851 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
10853 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
10857 from ( variable-list ) */
10860 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
10862 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
10866 uniform ( variable-list ) */
10869 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
10871 /* The clauses location. */
10872 location_t loc
= c_parser_peek_token (parser
)->location
;
10874 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10876 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
10878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10883 /* Parse all OpenMP clauses. The set clauses allowed by the directive
10884 is a bitmask in MASK. Return the list of clauses found; the result
10885 of clause default goes in *pdefault. */
10888 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
10889 const char *where
, bool finish_p
= true)
10891 tree clauses
= NULL
;
10892 bool first
= true, cilk_simd_fn
= false;
10894 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
10897 pragma_omp_clause c_kind
;
10898 const char *c_name
;
10899 tree prev
= clauses
;
10901 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
10902 c_parser_consume_token (parser
);
10904 here
= c_parser_peek_token (parser
)->location
;
10905 c_kind
= c_parser_omp_clause_name (parser
);
10909 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
10910 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
10911 c_name
= "collapse";
10913 case PRAGMA_OMP_CLAUSE_COPYIN
:
10914 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
10917 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
10918 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
10919 c_name
= "copyprivate";
10921 case PRAGMA_OMP_CLAUSE_DEFAULT
:
10922 clauses
= c_parser_omp_clause_default (parser
, clauses
);
10923 c_name
= "default";
10925 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
10926 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
10927 c_name
= "firstprivate";
10929 case PRAGMA_OMP_CLAUSE_FINAL
:
10930 clauses
= c_parser_omp_clause_final (parser
, clauses
);
10933 case PRAGMA_OMP_CLAUSE_IF
:
10934 clauses
= c_parser_omp_clause_if (parser
, clauses
);
10937 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
10938 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
10939 c_name
= "lastprivate";
10941 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
10942 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
10943 c_name
= "mergeable";
10945 case PRAGMA_OMP_CLAUSE_NOWAIT
:
10946 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
10949 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
10950 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
10951 c_name
= "num_threads";
10953 case PRAGMA_OMP_CLAUSE_ORDERED
:
10954 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
10955 c_name
= "ordered";
10957 case PRAGMA_OMP_CLAUSE_PRIVATE
:
10958 clauses
= c_parser_omp_clause_private (parser
, clauses
);
10959 c_name
= "private";
10961 case PRAGMA_OMP_CLAUSE_REDUCTION
:
10962 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
10963 c_name
= "reduction";
10965 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
10966 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
10967 c_name
= "schedule";
10969 case PRAGMA_OMP_CLAUSE_SHARED
:
10970 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
10973 case PRAGMA_OMP_CLAUSE_UNTIED
:
10974 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
10977 case PRAGMA_OMP_CLAUSE_INBRANCH
:
10978 case PRAGMA_CILK_CLAUSE_MASK
:
10979 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
10981 c_name
= "inbranch";
10983 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
10984 case PRAGMA_CILK_CLAUSE_NOMASK
:
10985 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
10987 c_name
= "notinbranch";
10989 case PRAGMA_OMP_CLAUSE_PARALLEL
:
10991 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
10993 c_name
= "parallel";
10997 error_at (here
, "%qs must be the first clause of %qs",
11002 case PRAGMA_OMP_CLAUSE_FOR
:
11004 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
11008 goto clause_not_first
;
11010 case PRAGMA_OMP_CLAUSE_SECTIONS
:
11012 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
11014 c_name
= "sections";
11016 goto clause_not_first
;
11018 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
11020 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
11022 c_name
= "taskgroup";
11024 goto clause_not_first
;
11026 case PRAGMA_OMP_CLAUSE_TO
:
11027 clauses
= c_parser_omp_clause_to (parser
, clauses
);
11030 case PRAGMA_OMP_CLAUSE_FROM
:
11031 clauses
= c_parser_omp_clause_from (parser
, clauses
);
11034 case PRAGMA_OMP_CLAUSE_UNIFORM
:
11035 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
11036 c_name
= "uniform";
11038 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
11039 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
11040 c_name
= "num_teams";
11042 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
11043 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
11044 c_name
= "thread_limit";
11046 case PRAGMA_OMP_CLAUSE_ALIGNED
:
11047 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
11048 c_name
= "aligned";
11050 case PRAGMA_OMP_CLAUSE_LINEAR
:
11051 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
11052 cilk_simd_fn
= true;
11053 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
11056 case PRAGMA_OMP_CLAUSE_DEPEND
:
11057 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
11060 case PRAGMA_OMP_CLAUSE_MAP
:
11061 clauses
= c_parser_omp_clause_map (parser
, clauses
);
11064 case PRAGMA_OMP_CLAUSE_DEVICE
:
11065 clauses
= c_parser_omp_clause_device (parser
, clauses
);
11068 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
11069 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
11070 c_name
= "dist_schedule";
11072 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
11073 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
11074 c_name
= "proc_bind";
11076 case PRAGMA_OMP_CLAUSE_SAFELEN
:
11077 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
11078 c_name
= "safelen";
11080 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
11081 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
11082 c_name
= "simdlen";
11084 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
11085 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
11086 c_name
= "simdlen";
11089 c_parser_error (parser
, "expected %<#pragma omp%> clause");
11095 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
11097 /* Remove the invalid clause(s) from the list to avoid
11098 confusing the rest of the compiler. */
11100 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
11105 c_parser_skip_to_pragma_eol (parser
);
11108 return c_finish_omp_clauses (clauses
);
11117 In practice, we're also interested in adding the statement to an
11118 outer node. So it is convenient if we work around the fact that
11119 c_parser_statement calls add_stmt. */
11122 c_parser_omp_structured_block (c_parser
*parser
)
11124 tree stmt
= push_stmt_list ();
11125 c_parser_statement (parser
);
11126 return pop_stmt_list (stmt
);
11130 # pragma omp atomic new-line
11134 x binop= expr | x++ | ++x | x-- | --x
11136 +, *, -, /, &, ^, |, <<, >>
11138 where x is an lvalue expression with scalar type.
11141 # pragma omp atomic new-line
11144 # pragma omp atomic read new-line
11147 # pragma omp atomic write new-line
11150 # pragma omp atomic update new-line
11153 # pragma omp atomic capture new-line
11156 # pragma omp atomic capture new-line
11164 expression-stmt | x = x binop expr
11166 v = expression-stmt
11168 { v = x; update-stmt; } | { update-stmt; v = x; }
11172 expression-stmt | x = x binop expr | x = expr binop x
11176 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
11178 where x and v are lvalue expressions with scalar type.
11180 LOC is the location of the #pragma token. */
11183 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
11185 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
11186 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
11187 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
11188 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
11189 struct c_expr expr
;
11191 bool structured_block
= false;
11192 bool swapped
= false;
11193 bool seq_cst
= false;
11195 if (c_parser_next_token_is (parser
, CPP_NAME
))
11197 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11198 if (!strcmp (p
, "seq_cst"))
11201 c_parser_consume_token (parser
);
11202 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11203 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11204 c_parser_consume_token (parser
);
11207 if (c_parser_next_token_is (parser
, CPP_NAME
))
11209 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11211 if (!strcmp (p
, "read"))
11212 code
= OMP_ATOMIC_READ
;
11213 else if (!strcmp (p
, "write"))
11215 else if (!strcmp (p
, "update"))
11217 else if (!strcmp (p
, "capture"))
11218 code
= OMP_ATOMIC_CAPTURE_NEW
;
11222 c_parser_consume_token (parser
);
11226 if (c_parser_next_token_is (parser
, CPP_COMMA
)
11227 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11228 c_parser_consume_token (parser
);
11230 if (c_parser_next_token_is (parser
, CPP_NAME
))
11233 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11234 if (!strcmp (p
, "seq_cst"))
11237 c_parser_consume_token (parser
);
11241 c_parser_skip_to_pragma_eol (parser
);
11245 case OMP_ATOMIC_READ
:
11246 case NOP_EXPR
: /* atomic write */
11247 v
= c_parser_unary_expression (parser
).value
;
11248 v
= c_fully_fold (v
, false, NULL
);
11249 if (v
== error_mark_node
)
11251 loc
= c_parser_peek_token (parser
)->location
;
11252 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11254 if (code
== NOP_EXPR
)
11255 lhs
= c_parser_expression (parser
).value
;
11257 lhs
= c_parser_unary_expression (parser
).value
;
11258 lhs
= c_fully_fold (lhs
, false, NULL
);
11259 if (lhs
== error_mark_node
)
11261 if (code
== NOP_EXPR
)
11263 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
11271 case OMP_ATOMIC_CAPTURE_NEW
:
11272 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11274 c_parser_consume_token (parser
);
11275 structured_block
= true;
11279 v
= c_parser_unary_expression (parser
).value
;
11280 v
= c_fully_fold (v
, false, NULL
);
11281 if (v
== error_mark_node
)
11283 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11291 /* For structured_block case we don't know yet whether
11292 old or new x should be captured. */
11294 eloc
= c_parser_peek_token (parser
)->location
;
11295 expr
= c_parser_unary_expression (parser
);
11297 expr
= default_function_array_conversion (eloc
, expr
);
11298 unfolded_lhs
= expr
.value
;
11299 lhs
= c_fully_fold (lhs
, false, NULL
);
11301 switch (TREE_CODE (lhs
))
11305 c_parser_skip_to_end_of_block_or_statement (parser
);
11306 if (structured_block
)
11308 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11309 c_parser_consume_token (parser
);
11310 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
11312 c_parser_skip_to_end_of_block_or_statement (parser
);
11313 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11314 c_parser_consume_token (parser
);
11319 case POSTINCREMENT_EXPR
:
11320 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11321 code
= OMP_ATOMIC_CAPTURE_OLD
;
11323 case PREINCREMENT_EXPR
:
11324 lhs
= TREE_OPERAND (lhs
, 0);
11325 unfolded_lhs
= NULL_TREE
;
11326 opcode
= PLUS_EXPR
;
11327 rhs
= integer_one_node
;
11330 case POSTDECREMENT_EXPR
:
11331 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
11332 code
= OMP_ATOMIC_CAPTURE_OLD
;
11334 case PREDECREMENT_EXPR
:
11335 lhs
= TREE_OPERAND (lhs
, 0);
11336 unfolded_lhs
= NULL_TREE
;
11337 opcode
= MINUS_EXPR
;
11338 rhs
= integer_one_node
;
11341 case COMPOUND_EXPR
:
11342 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
11343 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
11344 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
11345 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
11346 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
11347 (TREE_OPERAND (lhs
, 1), 0), 0)))
11349 /* Undo effects of boolean_increment for post {in,de}crement. */
11350 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
11353 if (TREE_CODE (lhs
) == MODIFY_EXPR
11354 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
11356 /* Undo effects of boolean_increment. */
11357 if (integer_onep (TREE_OPERAND (lhs
, 1)))
11359 /* This is pre or post increment. */
11360 rhs
= TREE_OPERAND (lhs
, 1);
11361 lhs
= TREE_OPERAND (lhs
, 0);
11362 unfolded_lhs
= NULL_TREE
;
11364 if (code
== OMP_ATOMIC_CAPTURE_NEW
11365 && !structured_block
11366 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11367 code
= OMP_ATOMIC_CAPTURE_OLD
;
11370 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
11371 && TREE_OPERAND (lhs
, 0)
11372 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
11374 /* This is pre or post decrement. */
11375 rhs
= TREE_OPERAND (lhs
, 1);
11376 lhs
= TREE_OPERAND (lhs
, 0);
11377 unfolded_lhs
= NULL_TREE
;
11379 if (code
== OMP_ATOMIC_CAPTURE_NEW
11380 && !structured_block
11381 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
11382 code
= OMP_ATOMIC_CAPTURE_OLD
;
11388 switch (c_parser_peek_token (parser
)->type
)
11391 opcode
= MULT_EXPR
;
11394 opcode
= TRUNC_DIV_EXPR
;
11397 opcode
= PLUS_EXPR
;
11400 opcode
= MINUS_EXPR
;
11402 case CPP_LSHIFT_EQ
:
11403 opcode
= LSHIFT_EXPR
;
11405 case CPP_RSHIFT_EQ
:
11406 opcode
= RSHIFT_EXPR
;
11409 opcode
= BIT_AND_EXPR
;
11412 opcode
= BIT_IOR_EXPR
;
11415 opcode
= BIT_XOR_EXPR
;
11418 c_parser_consume_token (parser
);
11419 eloc
= c_parser_peek_token (parser
)->location
;
11420 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
11422 switch (TREE_CODE (rhs1
))
11425 case TRUNC_DIV_EXPR
:
11433 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
11435 opcode
= TREE_CODE (rhs1
);
11436 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11437 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11440 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
11442 opcode
= TREE_CODE (rhs1
);
11443 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
11444 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
11445 swapped
= !commutative_tree_code (opcode
);
11454 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
11456 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11458 code
= OMP_ATOMIC_CAPTURE_OLD
;
11461 expr
= default_function_array_read_conversion (eloc
, expr
);
11462 unfolded_lhs1
= expr
.value
;
11463 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
11465 c_parser_consume_token (parser
);
11468 if (structured_block
)
11471 expr
= default_function_array_read_conversion (eloc
, expr
);
11472 rhs
= c_fully_fold (expr
.value
, false, NULL
);
11477 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
11480 c_parser_error (parser
,
11481 "invalid operator for %<#pragma omp atomic%>");
11485 /* Arrange to pass the location of the assignment operator to
11486 c_finish_omp_atomic. */
11487 loc
= c_parser_peek_token (parser
)->location
;
11488 c_parser_consume_token (parser
);
11489 eloc
= c_parser_peek_token (parser
)->location
;
11490 expr
= c_parser_expression (parser
);
11491 expr
= default_function_array_read_conversion (eloc
, expr
);
11493 rhs
= c_fully_fold (rhs
, false, NULL
);
11497 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
11499 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
11501 v
= c_parser_unary_expression (parser
).value
;
11502 v
= c_fully_fold (v
, false, NULL
);
11503 if (v
== error_mark_node
)
11505 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
11507 eloc
= c_parser_peek_token (parser
)->location
;
11508 expr
= c_parser_unary_expression (parser
);
11510 expr
= default_function_array_read_conversion (eloc
, expr
);
11511 unfolded_lhs1
= expr
.value
;
11512 lhs1
= c_fully_fold (lhs1
, false, NULL
);
11513 if (lhs1
== error_mark_node
)
11516 if (structured_block
)
11518 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11519 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
11522 if (unfolded_lhs
&& unfolded_lhs1
11523 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
11525 error ("%<#pragma omp atomic capture%> uses two different "
11526 "expressions for memory");
11527 stmt
= error_mark_node
;
11530 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
11532 if (stmt
!= error_mark_node
)
11535 if (!structured_block
)
11536 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11541 # pragma omp barrier new-line
11545 c_parser_omp_barrier (c_parser
*parser
)
11547 location_t loc
= c_parser_peek_token (parser
)->location
;
11548 c_parser_consume_pragma (parser
);
11549 c_parser_skip_to_pragma_eol (parser
);
11551 c_finish_omp_barrier (loc
);
11555 # pragma omp critical [(name)] new-line
11558 LOC is the location of the #pragma itself. */
11561 c_parser_omp_critical (location_t loc
, c_parser
*parser
)
11563 tree stmt
, name
= NULL
;
11565 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11567 c_parser_consume_token (parser
);
11568 if (c_parser_next_token_is (parser
, CPP_NAME
))
11570 name
= c_parser_peek_token (parser
)->value
;
11571 c_parser_consume_token (parser
);
11572 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11575 c_parser_error (parser
, "expected identifier");
11577 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11578 c_parser_error (parser
, "expected %<(%> or end of line");
11579 c_parser_skip_to_pragma_eol (parser
);
11581 stmt
= c_parser_omp_structured_block (parser
);
11582 return c_finish_omp_critical (loc
, stmt
, name
);
11586 # pragma omp flush flush-vars[opt] new-line
11589 ( variable-list ) */
11592 c_parser_omp_flush (c_parser
*parser
)
11594 location_t loc
= c_parser_peek_token (parser
)->location
;
11595 c_parser_consume_pragma (parser
);
11596 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11597 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11598 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
11599 c_parser_error (parser
, "expected %<(%> or end of line");
11600 c_parser_skip_to_pragma_eol (parser
);
11602 c_finish_omp_flush (loc
);
11605 /* Parse the restricted form of the for statement allowed by OpenMP.
11606 The real trick here is to determine the loop control variable early
11607 so that we can push a new decl if necessary to make it private.
11608 LOC is the location of the OMP in "#pragma omp". */
11611 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
11612 tree clauses
, tree
*cclauses
)
11614 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
11615 tree declv
, condv
, incrv
, initv
, ret
= NULL
;
11616 bool fail
= false, open_brace_parsed
= false;
11617 int i
, collapse
= 1, nbraces
= 0;
11618 location_t for_loc
;
11619 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
11621 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
11622 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
11623 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
11625 gcc_assert (collapse
>= 1);
11627 declv
= make_tree_vec (collapse
);
11628 initv
= make_tree_vec (collapse
);
11629 condv
= make_tree_vec (collapse
);
11630 incrv
= make_tree_vec (collapse
);
11632 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
11634 c_parser_error (parser
, "for statement expected");
11637 for_loc
= c_parser_peek_token (parser
)->location
;
11638 c_parser_consume_token (parser
);
11640 for (i
= 0; i
< collapse
; i
++)
11642 int bracecount
= 0;
11644 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11647 /* Parse the initialization declaration or expression. */
11648 if (c_parser_next_tokens_start_declaration (parser
))
11651 vec_safe_push (for_block
, c_begin_compound_stmt (true));
11652 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
11654 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
11657 if (DECL_INITIAL (decl
) == error_mark_node
)
11658 decl
= error_mark_node
;
11661 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11662 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
11664 struct c_expr decl_exp
;
11665 struct c_expr init_exp
;
11666 location_t init_loc
;
11668 decl_exp
= c_parser_postfix_expression (parser
);
11669 decl
= decl_exp
.value
;
11671 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
11673 init_loc
= c_parser_peek_token (parser
)->location
;
11674 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
11675 init_exp
= default_function_array_read_conversion (init_loc
,
11677 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
11678 NOP_EXPR
, init_loc
, init_exp
.value
,
11679 init_exp
.original_type
);
11680 init
= c_process_expr_stmt (init_loc
, init
);
11682 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11687 c_parser_error (parser
,
11688 "expected iteration declaration or initialization");
11689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11695 /* Parse the loop condition. */
11697 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
11699 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
11700 struct c_expr cond_expr
11701 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
11703 cond
= cond_expr
.value
;
11704 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
11705 cond
= c_fully_fold (cond
, false, NULL
);
11706 switch (cond_expr
.original_code
)
11714 if (code
== CILK_SIMD
)
11718 /* Can't be cond = error_mark_node, because we want to preserve
11719 the location until c_finish_omp_for. */
11720 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
11723 protected_set_expr_location (cond
, cond_loc
);
11725 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11727 /* Parse the increment expression. */
11729 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
11731 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
11733 incr
= c_process_expr_stmt (incr_loc
,
11734 c_parser_expression (parser
).value
);
11736 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11738 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
11742 TREE_VEC_ELT (declv
, i
) = decl
;
11743 TREE_VEC_ELT (initv
, i
) = init
;
11744 TREE_VEC_ELT (condv
, i
) = cond
;
11745 TREE_VEC_ELT (incrv
, i
) = incr
;
11749 if (i
== collapse
- 1)
11752 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
11753 in between the collapsed for loops to be still considered perfectly
11754 nested. Hopefully the final version clarifies this.
11755 For now handle (multiple) {'s and empty statements. */
11758 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11760 c_parser_consume_token (parser
);
11763 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
11765 c_parser_consume_token (parser
);
11768 else if (bracecount
11769 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11770 c_parser_consume_token (parser
);
11773 c_parser_error (parser
, "not enough perfectly nested loops");
11776 open_brace_parsed
= true;
11786 nbraces
+= bracecount
;
11789 save_break
= c_break_label
;
11790 if (code
== CILK_SIMD
)
11791 c_break_label
= build_int_cst (size_type_node
, 2);
11793 c_break_label
= size_one_node
;
11794 save_cont
= c_cont_label
;
11795 c_cont_label
= NULL_TREE
;
11796 body
= push_stmt_list ();
11798 if (open_brace_parsed
)
11800 location_t here
= c_parser_peek_token (parser
)->location
;
11801 stmt
= c_begin_compound_stmt (true);
11802 c_parser_compound_statement_nostart (parser
);
11803 add_stmt (c_end_compound_stmt (here
, stmt
, true));
11806 add_stmt (c_parser_c99_block_statement (parser
));
11809 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
11810 SET_EXPR_LOCATION (t
, loc
);
11814 body
= pop_stmt_list (body
);
11815 c_break_label
= save_break
;
11816 c_cont_label
= save_cont
;
11820 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
11822 c_parser_consume_token (parser
);
11825 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
11826 c_parser_consume_token (parser
);
11829 c_parser_error (parser
, "collapsed loops not perfectly nested");
11832 location_t here
= c_parser_peek_token (parser
)->location
;
11833 stmt
= c_begin_compound_stmt (true);
11835 c_parser_compound_statement_nostart (parser
);
11836 body
= c_end_compound_stmt (here
, stmt
, true);
11843 /* Only bother calling c_finish_omp_for if we haven't already generated
11844 an error from the initialization parsing. */
11847 stmt
= c_finish_omp_for (loc
, code
, declv
, initv
, condv
,
11848 incrv
, body
, NULL
);
11851 if (cclauses
!= NULL
11852 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
11855 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
11856 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
11857 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
11858 c
= &OMP_CLAUSE_CHAIN (*c
);
11861 for (i
= 0; i
< collapse
; i
++)
11862 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
11865 c
= &OMP_CLAUSE_CHAIN (*c
);
11866 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
11869 "iteration variable %qD should not be firstprivate",
11870 OMP_CLAUSE_DECL (*c
));
11871 *c
= OMP_CLAUSE_CHAIN (*c
);
11875 /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES,
11876 change it to shared (decl) in
11877 OMP_PARALLEL_CLAUSES. */
11878 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (*c
),
11879 OMP_CLAUSE_LASTPRIVATE
);
11880 OMP_CLAUSE_DECL (l
) = OMP_CLAUSE_DECL (*c
);
11881 if (code
== OMP_SIMD
)
11883 OMP_CLAUSE_CHAIN (l
)
11884 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
11885 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
11889 OMP_CLAUSE_CHAIN (l
) = clauses
;
11892 OMP_CLAUSE_SET_CODE (*c
, OMP_CLAUSE_SHARED
);
11896 OMP_FOR_CLAUSES (stmt
) = clauses
;
11901 while (!for_block
->is_empty ())
11903 /* FIXME diagnostics: LOC below should be the actual location of
11904 this particular for block. We need to build a list of
11905 locations to go along with FOR_BLOCK. */
11906 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
11909 release_tree_vector (for_block
);
11913 /* Helper function for OpenMP parsing, split clauses and call
11914 finish_omp_clauses on each of the set of clauses afterwards. */
11917 omp_split_clauses (location_t loc
, enum tree_code code
,
11918 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
11921 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
11922 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
11924 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
]);
11928 #pragma omp simd simd-clause[optseq] new-line
11931 LOC is the location of the #pragma token.
11934 #define OMP_SIMD_CLAUSE_MASK \
11935 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
11936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
11937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
11938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11940 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
11944 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
11945 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11947 tree block
, clauses
, ret
;
11949 strcat (p_name
, " simd");
11950 mask
|= OMP_SIMD_CLAUSE_MASK
;
11951 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
11953 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
11956 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
11957 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
11960 block
= c_begin_compound_stmt (true);
11961 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
);
11962 block
= c_end_compound_stmt (loc
, block
, true);
11969 #pragma omp for for-clause[optseq] new-line
11973 #pragma omp for simd for-simd-clause[optseq] new-line
11976 LOC is the location of the #pragma token.
11979 #define OMP_FOR_CLAUSE_MASK \
11980 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
11981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
11982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
11983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
11984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
11985 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
11986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
11987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
11990 c_parser_omp_for (location_t loc
, c_parser
*parser
,
11991 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
11993 tree block
, clauses
, ret
;
11995 strcat (p_name
, " for");
11996 mask
|= OMP_FOR_CLAUSE_MASK
;
11998 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12000 if (c_parser_next_token_is (parser
, CPP_NAME
))
12002 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12004 if (strcmp (p
, "simd") == 0)
12006 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12007 if (cclauses
== NULL
)
12008 cclauses
= cclauses_buf
;
12010 c_parser_consume_token (parser
);
12011 if (!flag_openmp
) /* flag_openmp_simd */
12012 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12013 block
= c_begin_compound_stmt (true);
12014 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12015 block
= c_end_compound_stmt (loc
, block
, true);
12016 if (ret
== NULL_TREE
)
12018 ret
= make_node (OMP_FOR
);
12019 TREE_TYPE (ret
) = void_type_node
;
12020 OMP_FOR_BODY (ret
) = block
;
12021 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12022 SET_EXPR_LOCATION (ret
, loc
);
12027 if (!flag_openmp
) /* flag_openmp_simd */
12029 c_parser_skip_to_pragma_eol (parser
);
12033 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12036 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
12037 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
12040 block
= c_begin_compound_stmt (true);
12041 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
);
12042 block
= c_end_compound_stmt (loc
, block
, true);
12049 # pragma omp master new-line
12052 LOC is the location of the #pragma token.
12056 c_parser_omp_master (location_t loc
, c_parser
*parser
)
12058 c_parser_skip_to_pragma_eol (parser
);
12059 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
));
12063 # pragma omp ordered new-line
12066 LOC is the location of the #pragma itself.
12070 c_parser_omp_ordered (location_t loc
, c_parser
*parser
)
12072 c_parser_skip_to_pragma_eol (parser
);
12073 return c_finish_omp_ordered (loc
, c_parser_omp_structured_block (parser
));
12079 { section-sequence }
12082 section-directive[opt] structured-block
12083 section-sequence section-directive structured-block
12085 SECTIONS_LOC is the location of the #pragma omp sections. */
12088 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
12090 tree stmt
, substmt
;
12091 bool error_suppress
= false;
12094 loc
= c_parser_peek_token (parser
)->location
;
12095 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
12097 /* Avoid skipping until the end of the block. */
12098 parser
->error
= false;
12102 stmt
= push_stmt_list ();
12104 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
12106 substmt
= c_parser_omp_structured_block (parser
);
12107 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12108 SET_EXPR_LOCATION (substmt
, loc
);
12109 add_stmt (substmt
);
12114 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
12116 if (c_parser_next_token_is (parser
, CPP_EOF
))
12119 loc
= c_parser_peek_token (parser
)->location
;
12120 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
12122 c_parser_consume_pragma (parser
);
12123 c_parser_skip_to_pragma_eol (parser
);
12124 error_suppress
= false;
12126 else if (!error_suppress
)
12128 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
12129 error_suppress
= true;
12132 substmt
= c_parser_omp_structured_block (parser
);
12133 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
12134 SET_EXPR_LOCATION (substmt
, loc
);
12135 add_stmt (substmt
);
12137 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
12138 "expected %<#pragma omp section%> or %<}%>");
12140 substmt
= pop_stmt_list (stmt
);
12142 stmt
= make_node (OMP_SECTIONS
);
12143 SET_EXPR_LOCATION (stmt
, sections_loc
);
12144 TREE_TYPE (stmt
) = void_type_node
;
12145 OMP_SECTIONS_BODY (stmt
) = substmt
;
12147 return add_stmt (stmt
);
12151 # pragma omp sections sections-clause[optseq] newline
12154 LOC is the location of the #pragma token.
12157 #define OMP_SECTIONS_CLAUSE_MASK \
12158 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
12161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12165 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
12166 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12168 tree block
, clauses
, ret
;
12170 strcat (p_name
, " sections");
12171 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
12173 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
12175 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12178 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
12179 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
12182 block
= c_begin_compound_stmt (true);
12183 ret
= c_parser_omp_sections_scope (loc
, parser
);
12185 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
12186 block
= c_end_compound_stmt (loc
, block
, true);
12193 # pragma omp parallel parallel-clause[optseq] new-line
12195 # pragma omp parallel for parallel-for-clause[optseq] new-line
12197 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
12201 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
12204 LOC is the location of the #pragma token.
12207 #define OMP_PARALLEL_CLAUSE_MASK \
12208 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12209 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12210 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12211 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12212 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12213 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
12214 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12215 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
12216 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
12219 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
12220 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12222 tree stmt
, clauses
, block
;
12224 strcat (p_name
, " parallel");
12225 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
12227 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
12229 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12230 if (cclauses
== NULL
)
12231 cclauses
= cclauses_buf
;
12233 c_parser_consume_token (parser
);
12234 if (!flag_openmp
) /* flag_openmp_simd */
12235 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12236 block
= c_begin_omp_parallel ();
12237 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
);
12239 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12241 if (ret
== NULL_TREE
)
12243 OMP_PARALLEL_COMBINED (stmt
) = 1;
12248 error_at (loc
, "expected %<for%> after %qs", p_name
);
12249 c_parser_skip_to_pragma_eol (parser
);
12252 else if (!flag_openmp
) /* flag_openmp_simd */
12254 c_parser_skip_to_pragma_eol (parser
);
12257 else if (c_parser_next_token_is (parser
, CPP_NAME
))
12259 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12260 if (strcmp (p
, "sections") == 0)
12262 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12263 if (cclauses
== NULL
)
12264 cclauses
= cclauses_buf
;
12266 c_parser_consume_token (parser
);
12267 block
= c_begin_omp_parallel ();
12268 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
12269 stmt
= c_finish_omp_parallel (loc
,
12270 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
12272 OMP_PARALLEL_COMBINED (stmt
) = 1;
12277 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12279 block
= c_begin_omp_parallel ();
12280 c_parser_statement (parser
);
12281 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
12287 # pragma omp single single-clause[optseq] new-line
12290 LOC is the location of the #pragma.
12293 #define OMP_SINGLE_CLAUSE_MASK \
12294 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12295 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12296 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
12297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
12300 c_parser_omp_single (location_t loc
, c_parser
*parser
)
12302 tree stmt
= make_node (OMP_SINGLE
);
12303 SET_EXPR_LOCATION (stmt
, loc
);
12304 TREE_TYPE (stmt
) = void_type_node
;
12306 OMP_SINGLE_CLAUSES (stmt
)
12307 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
12308 "#pragma omp single");
12309 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12311 return add_stmt (stmt
);
12315 # pragma omp task task-clause[optseq] new-line
12317 LOC is the location of the #pragma.
12320 #define OMP_TASK_CLAUSE_MASK \
12321 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
12322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
12323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
12324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12325 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
12328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
12329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND))
12332 c_parser_omp_task (location_t loc
, c_parser
*parser
)
12334 tree clauses
, block
;
12336 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
12337 "#pragma omp task");
12339 block
= c_begin_omp_task ();
12340 c_parser_statement (parser
);
12341 return c_finish_omp_task (loc
, clauses
, block
);
12345 # pragma omp taskwait new-line
12349 c_parser_omp_taskwait (c_parser
*parser
)
12351 location_t loc
= c_parser_peek_token (parser
)->location
;
12352 c_parser_consume_pragma (parser
);
12353 c_parser_skip_to_pragma_eol (parser
);
12355 c_finish_omp_taskwait (loc
);
12359 # pragma omp taskyield new-line
12363 c_parser_omp_taskyield (c_parser
*parser
)
12365 location_t loc
= c_parser_peek_token (parser
)->location
;
12366 c_parser_consume_pragma (parser
);
12367 c_parser_skip_to_pragma_eol (parser
);
12369 c_finish_omp_taskyield (loc
);
12373 # pragma omp taskgroup new-line
12377 c_parser_omp_taskgroup (c_parser
*parser
)
12379 location_t loc
= c_parser_peek_token (parser
)->location
;
12380 c_parser_skip_to_pragma_eol (parser
);
12381 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
));
12385 # pragma omp cancel cancel-clause[optseq] new-line
12387 LOC is the location of the #pragma.
12390 #define OMP_CANCEL_CLAUSE_MASK \
12391 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12392 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12393 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12394 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
12395 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12398 c_parser_omp_cancel (c_parser
*parser
)
12400 location_t loc
= c_parser_peek_token (parser
)->location
;
12402 c_parser_consume_pragma (parser
);
12403 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
12404 "#pragma omp cancel");
12406 c_finish_omp_cancel (loc
, clauses
);
12410 # pragma omp cancellation point cancelpt-clause[optseq] new-line
12412 LOC is the location of the #pragma.
12415 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
12416 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
12417 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
12418 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
12419 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
12422 c_parser_omp_cancellation_point (c_parser
*parser
)
12424 location_t loc
= c_parser_peek_token (parser
)->location
;
12426 bool point_seen
= false;
12428 c_parser_consume_pragma (parser
);
12429 if (c_parser_next_token_is (parser
, CPP_NAME
))
12431 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12432 if (strcmp (p
, "point") == 0)
12434 c_parser_consume_token (parser
);
12440 c_parser_error (parser
, "expected %<point%>");
12441 c_parser_skip_to_pragma_eol (parser
);
12446 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
12447 "#pragma omp cancellation point");
12449 c_finish_omp_cancellation_point (loc
, clauses
);
12453 #pragma omp distribute distribute-clause[optseq] new-line
12456 #define OMP_DISTRIBUTE_CLAUSE_MASK \
12457 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12458 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
12460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
12463 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
12464 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12466 tree clauses
, block
, ret
;
12468 strcat (p_name
, " distribute");
12469 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
12471 if (c_parser_next_token_is (parser
, CPP_NAME
))
12473 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12475 bool parallel
= false;
12477 if (strcmp (p
, "simd") == 0)
12480 parallel
= strcmp (p
, "parallel") == 0;
12481 if (parallel
|| simd
)
12483 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12484 if (cclauses
== NULL
)
12485 cclauses
= cclauses_buf
;
12486 c_parser_consume_token (parser
);
12487 if (!flag_openmp
) /* flag_openmp_simd */
12490 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12492 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
12495 block
= c_begin_compound_stmt (true);
12497 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
);
12499 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
);
12500 block
= c_end_compound_stmt (loc
, block
, true);
12503 ret
= make_node (OMP_DISTRIBUTE
);
12504 TREE_TYPE (ret
) = void_type_node
;
12505 OMP_FOR_BODY (ret
) = block
;
12506 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12507 SET_EXPR_LOCATION (ret
, loc
);
12512 if (!flag_openmp
) /* flag_openmp_simd */
12514 c_parser_skip_to_pragma_eol (parser
);
12518 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12521 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
12522 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
12525 block
= c_begin_compound_stmt (true);
12526 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
);
12527 block
= c_end_compound_stmt (loc
, block
, true);
12534 # pragma omp teams teams-clause[optseq] new-line
12535 structured-block */
12537 #define OMP_TEAMS_CLAUSE_MASK \
12538 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
12539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
12540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
12541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
12542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
12543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
12544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
12547 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
12548 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
12550 tree clauses
, block
, ret
;
12552 strcat (p_name
, " teams");
12553 mask
|= OMP_TEAMS_CLAUSE_MASK
;
12555 if (c_parser_next_token_is (parser
, CPP_NAME
))
12557 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12558 if (strcmp (p
, "distribute") == 0)
12560 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
12561 if (cclauses
== NULL
)
12562 cclauses
= cclauses_buf
;
12564 c_parser_consume_token (parser
);
12565 if (!flag_openmp
) /* flag_openmp_simd */
12566 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12567 block
= c_begin_compound_stmt (true);
12568 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
);
12569 block
= c_end_compound_stmt (loc
, block
, true);
12572 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12573 ret
= make_node (OMP_TEAMS
);
12574 TREE_TYPE (ret
) = void_type_node
;
12575 OMP_TEAMS_CLAUSES (ret
) = clauses
;
12576 OMP_TEAMS_BODY (ret
) = block
;
12577 return add_stmt (ret
);
12580 if (!flag_openmp
) /* flag_openmp_simd */
12582 c_parser_skip_to_pragma_eol (parser
);
12586 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
12589 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
12590 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
12593 tree stmt
= make_node (OMP_TEAMS
);
12594 TREE_TYPE (stmt
) = void_type_node
;
12595 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
12596 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
);
12598 return add_stmt (stmt
);
12602 # pragma omp target data target-data-clause[optseq] new-line
12603 structured-block */
12605 #define OMP_TARGET_DATA_CLAUSE_MASK \
12606 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12607 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12608 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12611 c_parser_omp_target_data (location_t loc
, c_parser
*parser
)
12613 tree stmt
= make_node (OMP_TARGET_DATA
);
12614 TREE_TYPE (stmt
) = void_type_node
;
12616 OMP_TARGET_DATA_CLAUSES (stmt
)
12617 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
12618 "#pragma omp target data");
12619 keep_next_level ();
12620 tree block
= c_begin_compound_stmt (true);
12621 add_stmt (c_parser_omp_structured_block (parser
));
12622 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12624 SET_EXPR_LOCATION (stmt
, loc
);
12625 return add_stmt (stmt
);
12629 # pragma omp target update target-update-clause[optseq] new-line */
12631 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
12632 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
12633 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
12634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12638 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
12639 enum pragma_context context
)
12641 if (context
== pragma_stmt
)
12644 "%<#pragma omp target update%> may only be "
12645 "used in compound statements");
12646 c_parser_skip_to_pragma_eol (parser
);
12651 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
12652 "#pragma omp target update");
12653 if (find_omp_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
12654 && find_omp_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
12657 "%<#pragma omp target update must contain at least one "
12658 "%<from%> or %<to%> clauses");
12662 tree stmt
= make_node (OMP_TARGET_UPDATE
);
12663 TREE_TYPE (stmt
) = void_type_node
;
12664 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
12665 SET_EXPR_LOCATION (stmt
, loc
);
12671 # pragma omp target target-clause[optseq] new-line
12672 structured-block */
12674 #define OMP_TARGET_CLAUSE_MASK \
12675 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
12676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
12677 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
12680 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
)
12682 location_t loc
= c_parser_peek_token (parser
)->location
;
12683 c_parser_consume_pragma (parser
);
12685 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
12687 c_parser_error (parser
, "expected declaration specifiers");
12688 c_parser_skip_to_pragma_eol (parser
);
12692 if (c_parser_next_token_is (parser
, CPP_NAME
))
12694 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12696 if (strcmp (p
, "teams") == 0)
12698 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
12699 char p_name
[sizeof ("#pragma omp target teams distribute "
12700 "parallel for simd")];
12702 c_parser_consume_token (parser
);
12703 strcpy (p_name
, "#pragma omp target");
12704 if (!flag_openmp
) /* flag_openmp_simd */
12705 return c_parser_omp_teams (loc
, parser
, p_name
,
12706 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12707 keep_next_level ();
12708 tree block
= c_begin_compound_stmt (true);
12709 tree ret
= c_parser_omp_teams (loc
, parser
, p_name
,
12710 OMP_TARGET_CLAUSE_MASK
, cclauses
);
12711 block
= c_end_compound_stmt (loc
, block
, true);
12714 tree stmt
= make_node (OMP_TARGET
);
12715 TREE_TYPE (stmt
) = void_type_node
;
12716 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
12717 OMP_TARGET_BODY (stmt
) = block
;
12721 else if (!flag_openmp
) /* flag_openmp_simd */
12723 c_parser_skip_to_pragma_eol (parser
);
12726 else if (strcmp (p
, "data") == 0)
12728 c_parser_consume_token (parser
);
12729 c_parser_omp_target_data (loc
, parser
);
12732 else if (strcmp (p
, "update") == 0)
12734 c_parser_consume_token (parser
);
12735 return c_parser_omp_target_update (loc
, parser
, context
);
12739 tree stmt
= make_node (OMP_TARGET
);
12740 TREE_TYPE (stmt
) = void_type_node
;
12742 OMP_TARGET_CLAUSES (stmt
)
12743 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
12744 "#pragma omp target");
12745 keep_next_level ();
12746 tree block
= c_begin_compound_stmt (true);
12747 add_stmt (c_parser_omp_structured_block (parser
));
12748 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
12750 SET_EXPR_LOCATION (stmt
, loc
);
12756 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
12758 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
12759 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
12760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
12761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
12762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
12763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
12764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
12767 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
12769 vec
<c_token
> clauses
= vNULL
;
12770 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12772 c_token
*token
= c_parser_peek_token (parser
);
12773 if (token
->type
== CPP_EOF
)
12775 c_parser_skip_to_pragma_eol (parser
);
12776 clauses
.release ();
12779 clauses
.safe_push (*token
);
12780 c_parser_consume_token (parser
);
12782 clauses
.safe_push (*c_parser_peek_token (parser
));
12783 c_parser_skip_to_pragma_eol (parser
);
12785 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
12787 if (c_parser_peek_token (parser
)->pragma_kind
12788 != PRAGMA_OMP_DECLARE_REDUCTION
12789 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
12790 || strcmp (IDENTIFIER_POINTER
12791 (c_parser_peek_2nd_token (parser
)->value
),
12794 c_parser_error (parser
,
12795 "%<#pragma omp declare simd%> must be followed by "
12796 "function declaration or definition or another "
12797 "%<#pragma omp declare simd%>");
12798 clauses
.release ();
12801 c_parser_consume_pragma (parser
);
12802 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
12804 c_token
*token
= c_parser_peek_token (parser
);
12805 if (token
->type
== CPP_EOF
)
12807 c_parser_skip_to_pragma_eol (parser
);
12808 clauses
.release ();
12811 clauses
.safe_push (*token
);
12812 c_parser_consume_token (parser
);
12814 clauses
.safe_push (*c_parser_peek_token (parser
));
12815 c_parser_skip_to_pragma_eol (parser
);
12818 /* Make sure nothing tries to read past the end of the tokens. */
12820 memset (&eof_token
, 0, sizeof (eof_token
));
12821 eof_token
.type
= CPP_EOF
;
12822 clauses
.safe_push (eof_token
);
12823 clauses
.safe_push (eof_token
);
12827 case pragma_external
:
12828 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12829 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12831 int ext
= disable_extension_diagnostics ();
12833 c_parser_consume_token (parser
);
12834 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12835 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12836 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12838 restore_extension_diagnostics (ext
);
12841 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
12844 case pragma_struct
:
12846 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12847 "function declaration or definition");
12849 case pragma_compound
:
12851 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12852 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
12854 int ext
= disable_extension_diagnostics ();
12856 c_parser_consume_token (parser
);
12857 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
12858 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
12859 if (c_parser_next_tokens_start_declaration (parser
))
12861 c_parser_declaration_or_fndef (parser
, true, true, true, true,
12862 true, NULL
, clauses
);
12863 restore_extension_diagnostics (ext
);
12866 restore_extension_diagnostics (ext
);
12868 else if (c_parser_next_tokens_start_declaration (parser
))
12870 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
12874 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
12875 "function declaration or definition");
12878 gcc_unreachable ();
12880 clauses
.release ();
12883 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
12884 and put that into "omp declare simd" attribute. */
12887 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
12888 vec
<c_token
> clauses
)
12891 && clauses
.exists () && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12893 error ("%<#pragma omp declare simd%> cannot be used in the same "
12894 "function marked as a Cilk Plus SIMD-enabled function");
12895 vec_free (parser
->cilk_simd_fn_tokens
);
12899 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
12900 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
12901 has already processed the tokens. */
12902 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
12904 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
12906 error ("%<#pragma omp declare simd%> not immediately followed by "
12907 "a function declaration or definition");
12908 clauses
[0].type
= CPP_EOF
;
12911 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
12913 error_at (DECL_SOURCE_LOCATION (fndecl
),
12914 "%<#pragma omp declare simd%> not immediately followed by "
12915 "a single function declaration or definition");
12916 clauses
[0].type
= CPP_EOF
;
12920 if (parms
== NULL_TREE
)
12921 parms
= DECL_ARGUMENTS (fndecl
);
12923 unsigned int tokens_avail
= parser
->tokens_avail
;
12924 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
12925 bool is_cilkplus_cilk_simd_fn
= false;
12927 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12929 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
12930 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
12931 is_cilkplus_cilk_simd_fn
= true;
12935 parser
->tokens
= clauses
.address ();
12936 parser
->tokens_avail
= clauses
.length ();
12939 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
12940 while (parser
->tokens_avail
> 3)
12942 c_token
*token
= c_parser_peek_token (parser
);
12943 if (!is_cilkplus_cilk_simd_fn
)
12944 gcc_assert (token
->type
== CPP_NAME
12945 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
12947 gcc_assert (token
->type
== CPP_NAME
12948 && is_cilkplus_vector_p (token
->value
));
12949 c_parser_consume_token (parser
);
12950 parser
->in_pragma
= true;
12952 tree c
= NULL_TREE
;
12953 if (is_cilkplus_cilk_simd_fn
)
12954 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
12955 "SIMD-enabled functions attribute");
12957 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
12958 "#pragma omp declare simd");
12959 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
12960 if (c
!= NULL_TREE
)
12961 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
12962 if (is_cilkplus_cilk_simd_fn
)
12964 tree k
= build_tree_list (get_identifier ("cilk simd function"),
12966 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
12967 DECL_ATTRIBUTES (fndecl
) = k
;
12969 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
12970 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
12971 DECL_ATTRIBUTES (fndecl
) = c
;
12974 parser
->tokens
= &parser
->tokens_buf
[0];
12975 parser
->tokens_avail
= tokens_avail
;
12976 if (clauses
.exists ())
12977 clauses
[0].type
= CPP_PRAGMA
;
12979 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
12980 vec_free (parser
->cilk_simd_fn_tokens
);
12985 # pragma omp declare target new-line
12986 declarations and definitions
12987 # pragma omp end declare target new-line */
12990 c_parser_omp_declare_target (c_parser
*parser
)
12992 c_parser_skip_to_pragma_eol (parser
);
12993 current_omp_declare_target_attribute
++;
12997 c_parser_omp_end_declare_target (c_parser
*parser
)
12999 location_t loc
= c_parser_peek_token (parser
)->location
;
13000 c_parser_consume_pragma (parser
);
13001 if (c_parser_next_token_is (parser
, CPP_NAME
)
13002 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13005 c_parser_consume_token (parser
);
13006 if (c_parser_next_token_is (parser
, CPP_NAME
)
13007 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
13009 c_parser_consume_token (parser
);
13012 c_parser_error (parser
, "expected %<target%>");
13013 c_parser_skip_to_pragma_eol (parser
);
13019 c_parser_error (parser
, "expected %<declare%>");
13020 c_parser_skip_to_pragma_eol (parser
);
13023 c_parser_skip_to_pragma_eol (parser
);
13024 if (!current_omp_declare_target_attribute
)
13025 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
13026 "%<#pragma omp declare target%>");
13028 current_omp_declare_target_attribute
--;
13033 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13034 initializer-clause[opt] new-line
13036 initializer-clause:
13037 initializer (omp_priv = initializer)
13038 initializer (function-name (argument-list)) */
13041 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
13043 unsigned int tokens_avail
= 0, i
;
13044 vec
<tree
> types
= vNULL
;
13045 vec
<c_token
> clauses
= vNULL
;
13046 enum tree_code reduc_code
= ERROR_MARK
;
13047 tree reduc_id
= NULL_TREE
;
13049 location_t rloc
= c_parser_peek_token (parser
)->location
;
13051 if (context
== pragma_struct
|| context
== pragma_param
)
13053 error ("%<#pragma omp declare reduction%> not at file or block scope");
13057 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13060 switch (c_parser_peek_token (parser
)->type
)
13063 reduc_code
= PLUS_EXPR
;
13066 reduc_code
= MULT_EXPR
;
13069 reduc_code
= MINUS_EXPR
;
13072 reduc_code
= BIT_AND_EXPR
;
13075 reduc_code
= BIT_XOR_EXPR
;
13078 reduc_code
= BIT_IOR_EXPR
;
13081 reduc_code
= TRUTH_ANDIF_EXPR
;
13084 reduc_code
= TRUTH_ORIF_EXPR
;
13088 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13089 if (strcmp (p
, "min") == 0)
13091 reduc_code
= MIN_EXPR
;
13094 if (strcmp (p
, "max") == 0)
13096 reduc_code
= MAX_EXPR
;
13099 reduc_id
= c_parser_peek_token (parser
)->value
;
13102 c_parser_error (parser
,
13103 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
13104 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
13108 tree orig_reduc_id
, reduc_decl
;
13109 orig_reduc_id
= reduc_id
;
13110 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
13111 reduc_decl
= c_omp_reduction_decl (reduc_id
);
13112 c_parser_consume_token (parser
);
13114 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13119 location_t loc
= c_parser_peek_token (parser
)->location
;
13120 struct c_type_name
*ctype
= c_parser_type_name (parser
);
13123 type
= groktypename (ctype
, NULL
, NULL
);
13124 if (type
== error_mark_node
)
13126 else if ((INTEGRAL_TYPE_P (type
)
13127 || TREE_CODE (type
) == REAL_TYPE
13128 || TREE_CODE (type
) == COMPLEX_TYPE
)
13129 && orig_reduc_id
== NULL_TREE
)
13130 error_at (loc
, "predeclared arithmetic type in "
13131 "%<#pragma omp declare reduction%>");
13132 else if (TREE_CODE (type
) == FUNCTION_TYPE
13133 || TREE_CODE (type
) == ARRAY_TYPE
)
13134 error_at (loc
, "function or array type in "
13135 "%<#pragma omp declare reduction%>");
13136 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
13137 error_at (loc
, "const, volatile or restrict qualified type in "
13138 "%<#pragma omp declare reduction%>");
13142 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
13143 if (comptypes (TREE_PURPOSE (t
), type
))
13145 error_at (loc
, "redeclaration of %qs "
13146 "%<#pragma omp declare reduction%> for "
13148 IDENTIFIER_POINTER (reduc_id
)
13149 + sizeof ("omp declare reduction ") - 1,
13152 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
13154 error_at (ploc
, "previous %<#pragma omp declare "
13158 if (t
== NULL_TREE
)
13159 types
.safe_push (type
);
13161 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13162 c_parser_consume_token (parser
);
13170 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
13171 || types
.is_empty ())
13174 clauses
.release ();
13178 c_token
*token
= c_parser_peek_token (parser
);
13179 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
13181 c_parser_consume_token (parser
);
13183 c_parser_skip_to_pragma_eol (parser
);
13187 if (types
.length () > 1)
13189 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13191 c_token
*token
= c_parser_peek_token (parser
);
13192 if (token
->type
== CPP_EOF
)
13194 clauses
.safe_push (*token
);
13195 c_parser_consume_token (parser
);
13197 clauses
.safe_push (*c_parser_peek_token (parser
));
13198 c_parser_skip_to_pragma_eol (parser
);
13200 /* Make sure nothing tries to read past the end of the tokens. */
13202 memset (&eof_token
, 0, sizeof (eof_token
));
13203 eof_token
.type
= CPP_EOF
;
13204 clauses
.safe_push (eof_token
);
13205 clauses
.safe_push (eof_token
);
13208 int errs
= errorcount
;
13209 FOR_EACH_VEC_ELT (types
, i
, type
)
13211 tokens_avail
= parser
->tokens_avail
;
13212 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
13213 if (!clauses
.is_empty ())
13215 parser
->tokens
= clauses
.address ();
13216 parser
->tokens_avail
= clauses
.length ();
13217 parser
->in_pragma
= true;
13220 bool nested
= current_function_decl
!= NULL_TREE
;
13222 c_push_function_context ();
13223 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
13224 reduc_id
, default_function_type
);
13225 current_function_decl
= fndecl
;
13226 allocate_struct_function (fndecl
, true);
13228 tree stmt
= push_stmt_list ();
13229 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
13230 warn about these. */
13231 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13232 get_identifier ("omp_out"), type
);
13233 DECL_ARTIFICIAL (omp_out
) = 1;
13234 DECL_CONTEXT (omp_out
) = fndecl
;
13235 pushdecl (omp_out
);
13236 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13237 get_identifier ("omp_in"), type
);
13238 DECL_ARTIFICIAL (omp_in
) = 1;
13239 DECL_CONTEXT (omp_in
) = fndecl
;
13241 struct c_expr combiner
= c_parser_expression (parser
);
13242 struct c_expr initializer
;
13243 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
13245 initializer
.value
= error_mark_node
;
13246 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13248 else if (c_parser_next_token_is (parser
, CPP_NAME
)
13249 && strcmp (IDENTIFIER_POINTER
13250 (c_parser_peek_token (parser
)->value
),
13251 "initializer") == 0)
13253 c_parser_consume_token (parser
);
13256 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13257 get_identifier ("omp_priv"), type
);
13258 DECL_ARTIFICIAL (omp_priv
) = 1;
13259 DECL_INITIAL (omp_priv
) = error_mark_node
;
13260 DECL_CONTEXT (omp_priv
) = fndecl
;
13261 pushdecl (omp_priv
);
13262 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
13263 get_identifier ("omp_orig"), type
);
13264 DECL_ARTIFICIAL (omp_orig
) = 1;
13265 DECL_CONTEXT (omp_orig
) = fndecl
;
13266 pushdecl (omp_orig
);
13267 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13269 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
13271 c_parser_error (parser
, "expected %<omp_priv%> or "
13275 else if (strcmp (IDENTIFIER_POINTER
13276 (c_parser_peek_token (parser
)->value
),
13279 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
13280 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13282 c_parser_error (parser
, "expected function-name %<(%>");
13286 initializer
= c_parser_postfix_expression (parser
);
13287 if (initializer
.value
13288 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
13291 tree c
= initializer
.value
;
13292 for (j
= 0; j
< call_expr_nargs (c
); j
++)
13293 if (TREE_CODE (CALL_EXPR_ARG (c
, j
)) == ADDR_EXPR
13294 && TREE_OPERAND (CALL_EXPR_ARG (c
, j
), 0) == omp_priv
)
13296 if (j
== call_expr_nargs (c
))
13297 error ("one of the initializer call arguments should be "
13303 c_parser_consume_token (parser
);
13304 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
13308 tree st
= push_stmt_list ();
13309 start_init (omp_priv
, NULL_TREE
, 0);
13310 location_t loc
= c_parser_peek_token (parser
)->location
;
13311 struct c_expr init
= c_parser_initializer (parser
);
13313 finish_decl (omp_priv
, loc
, init
.value
,
13314 init
.original_type
, NULL_TREE
);
13315 pop_stmt_list (st
);
13319 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13325 c_parser_skip_to_pragma_eol (parser
);
13327 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
13328 DECL_INITIAL (reduc_decl
));
13329 DECL_INITIAL (reduc_decl
) = t
;
13330 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
13331 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
13332 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
13333 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
13334 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
13335 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
13338 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
13339 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
13340 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
13341 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
13342 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
13343 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13344 walk_tree (&DECL_INITIAL (omp_priv
),
13345 c_check_omp_declare_reduction_r
,
13346 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
13350 pop_stmt_list (stmt
);
13352 if (cfun
->language
!= NULL
)
13354 ggc_free (cfun
->language
);
13355 cfun
->language
= NULL
;
13358 current_function_decl
= NULL_TREE
;
13360 c_pop_function_context ();
13362 if (!clauses
.is_empty ())
13364 parser
->tokens
= &parser
->tokens_buf
[0];
13365 parser
->tokens_avail
= tokens_avail
;
13369 if (errs
!= errorcount
)
13373 clauses
.release ();
13379 #pragma omp declare simd declare-simd-clauses[optseq] new-line
13380 #pragma omp declare reduction (reduction-id : typename-list : expression) \
13381 initializer-clause[opt] new-line
13382 #pragma omp declare target new-line */
13385 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
13387 c_parser_consume_pragma (parser
);
13388 if (c_parser_next_token_is (parser
, CPP_NAME
))
13390 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13391 if (strcmp (p
, "simd") == 0)
13393 /* c_parser_consume_token (parser); done in
13394 c_parser_omp_declare_simd. */
13395 c_parser_omp_declare_simd (parser
, context
);
13398 if (strcmp (p
, "reduction") == 0)
13400 c_parser_consume_token (parser
);
13401 c_parser_omp_declare_reduction (parser
, context
);
13404 if (!flag_openmp
) /* flag_openmp_simd */
13406 c_parser_skip_to_pragma_eol (parser
);
13409 if (strcmp (p
, "target") == 0)
13411 c_parser_consume_token (parser
);
13412 c_parser_omp_declare_target (parser
);
13417 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
13419 c_parser_skip_to_pragma_eol (parser
);
13422 /* Main entry point to parsing most OpenMP pragmas. */
13425 c_parser_omp_construct (c_parser
*parser
)
13427 enum pragma_kind p_kind
;
13430 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
13431 omp_clause_mask
mask (0);
13433 loc
= c_parser_peek_token (parser
)->location
;
13434 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
13435 c_parser_consume_pragma (parser
);
13439 case PRAGMA_OMP_ATOMIC
:
13440 c_parser_omp_atomic (loc
, parser
);
13442 case PRAGMA_OMP_CRITICAL
:
13443 stmt
= c_parser_omp_critical (loc
, parser
);
13445 case PRAGMA_OMP_DISTRIBUTE
:
13446 strcpy (p_name
, "#pragma omp");
13447 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
);
13449 case PRAGMA_OMP_FOR
:
13450 strcpy (p_name
, "#pragma omp");
13451 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
);
13453 case PRAGMA_OMP_MASTER
:
13454 stmt
= c_parser_omp_master (loc
, parser
);
13456 case PRAGMA_OMP_ORDERED
:
13457 stmt
= c_parser_omp_ordered (loc
, parser
);
13459 case PRAGMA_OMP_PARALLEL
:
13460 strcpy (p_name
, "#pragma omp");
13461 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
);
13463 case PRAGMA_OMP_SECTIONS
:
13464 strcpy (p_name
, "#pragma omp");
13465 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
13467 case PRAGMA_OMP_SIMD
:
13468 strcpy (p_name
, "#pragma omp");
13469 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
);
13471 case PRAGMA_OMP_SINGLE
:
13472 stmt
= c_parser_omp_single (loc
, parser
);
13474 case PRAGMA_OMP_TASK
:
13475 stmt
= c_parser_omp_task (loc
, parser
);
13477 case PRAGMA_OMP_TASKGROUP
:
13478 stmt
= c_parser_omp_taskgroup (parser
);
13480 case PRAGMA_OMP_TEAMS
:
13481 strcpy (p_name
, "#pragma omp");
13482 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
);
13485 gcc_unreachable ();
13489 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
13494 # pragma omp threadprivate (variable-list) */
13497 c_parser_omp_threadprivate (c_parser
*parser
)
13502 c_parser_consume_pragma (parser
);
13503 loc
= c_parser_peek_token (parser
)->location
;
13504 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
13506 /* Mark every variable in VARS to be assigned thread local storage. */
13507 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
13509 tree v
= TREE_PURPOSE (t
);
13511 /* FIXME diagnostics: Ideally we should keep individual
13512 locations for all the variables in the var list to make the
13513 following errors more precise. Perhaps
13514 c_parser_omp_var_list_parens() should construct a list of
13515 locations to go along with the var list. */
13517 /* If V had already been marked threadprivate, it doesn't matter
13518 whether it had been used prior to this point. */
13519 if (TREE_CODE (v
) != VAR_DECL
)
13520 error_at (loc
, "%qD is not a variable", v
);
13521 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
13522 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
13523 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
13524 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
13525 else if (TREE_TYPE (v
) == error_mark_node
)
13527 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
13528 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
13531 if (! DECL_THREAD_LOCAL_P (v
))
13533 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
13534 /* If rtl has been already set for this var, call
13535 make_decl_rtl once again, so that encode_section_info
13536 has a chance to look at the new decl flags. */
13537 if (DECL_RTL_SET_P (v
))
13540 C_DECL_THREADPRIVATE_P (v
) = 1;
13544 c_parser_skip_to_pragma_eol (parser
);
13547 /* Cilk Plus <#pragma simd> parsing routines. */
13549 /* Helper function for c_parser_pragma. Perform some sanity checking
13550 for <#pragma simd> constructs. Returns FALSE if there was a
13554 c_parser_cilk_verify_simd (c_parser
*parser
,
13555 enum pragma_context context
)
13557 if (!flag_cilkplus
)
13559 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
13560 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13563 if (context
== pragma_external
)
13565 c_parser_error (parser
,"pragma simd must be inside a function");
13566 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
13573 This function is shared by SIMD-enabled functions and #pragma simd.
13574 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
13575 CLAUSES is unused. The main purpose of this function is to parse a
13576 vectorlength attribute or clause and check for parse errors.
13577 When IS_SIMD_FN is true then the function is merely caching the tokens
13578 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
13579 cache is cleared since there is no reason to continue.
13581 vectorlength ( constant-expression ) */
13584 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
13588 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
13590 /* The vectorlength clause behaves exactly like OpenMP's safelen
13591 clause. Represent it in OpenMP terms. */
13592 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
13594 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13597 location_t loc
= c_parser_peek_token (parser
)->location
;
13598 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13599 expr
= c_fully_fold (expr
, false, NULL
);
13601 /* If expr is an error_mark_node then the above function would have
13602 emitted an error. No reason to do it twice. */
13603 if (expr
== error_mark_node
)
13605 else if (!TREE_TYPE (expr
)
13606 || !TREE_CONSTANT (expr
)
13607 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
13609 error_at (loc
, "vectorlength must be an integer constant");
13610 else if (exact_log2 (TREE_INT_CST_LOW (expr
)) == -1)
13611 error_at (loc
, "vectorlength must be a power of 2");
13616 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
13617 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
13618 OMP_CLAUSE_CHAIN (u
) = clauses
;
13623 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
13624 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
13625 OMP_CLAUSE_CHAIN (u
) = clauses
;
13630 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13636 linear ( simd-linear-variable-list )
13638 simd-linear-variable-list:
13639 simd-linear-variable
13640 simd-linear-variable-list , simd-linear-variable
13642 simd-linear-variable:
13644 id-expression : simd-linear-step
13647 conditional-expression */
13650 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
13652 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13655 location_t loc
= c_parser_peek_token (parser
)->location
;
13657 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13658 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13659 c_parser_error (parser
, "expected identifier");
13661 while (c_parser_next_token_is (parser
, CPP_NAME
)
13662 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13664 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
13668 undeclared_variable (c_parser_peek_token (parser
)->location
,
13669 c_parser_peek_token (parser
)->value
);
13670 c_parser_consume_token (parser
);
13672 else if (var
== error_mark_node
)
13673 c_parser_consume_token (parser
);
13676 tree step
= integer_one_node
;
13678 /* Parse the linear step if present. */
13679 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13681 c_parser_consume_token (parser
);
13682 c_parser_consume_token (parser
);
13684 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
13685 expr
= c_fully_fold (expr
, false, NULL
);
13687 if (TREE_TYPE (expr
)
13688 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
13689 && (TREE_CONSTANT (expr
)
13693 c_parser_error (parser
,
13694 "step size must be an integer constant "
13695 "expression or an integer variable");
13698 c_parser_consume_token (parser
);
13700 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
13701 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
13702 OMP_CLAUSE_DECL (u
) = var
;
13703 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
13704 OMP_CLAUSE_CHAIN (u
) = clauses
;
13708 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13711 c_parser_consume_token (parser
);
13714 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13719 /* Returns the name of the next clause. If the clause is not
13720 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
13721 not consumed. Otherwise, the appropriate pragma_simd_clause is
13722 returned and the token is consumed. */
13724 static pragma_omp_clause
13725 c_parser_cilk_clause_name (c_parser
*parser
)
13727 pragma_omp_clause result
;
13728 c_token
*token
= c_parser_peek_token (parser
);
13730 if (!token
->value
|| token
->type
!= CPP_NAME
)
13731 return PRAGMA_CILK_CLAUSE_NONE
;
13733 const char *p
= IDENTIFIER_POINTER (token
->value
);
13735 if (!strcmp (p
, "vectorlength"))
13736 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
13737 else if (!strcmp (p
, "linear"))
13738 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
13739 else if (!strcmp (p
, "private"))
13740 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
13741 else if (!strcmp (p
, "firstprivate"))
13742 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
13743 else if (!strcmp (p
, "lastprivate"))
13744 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
13745 else if (!strcmp (p
, "reduction"))
13746 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
13748 return PRAGMA_CILK_CLAUSE_NONE
;
13750 c_parser_consume_token (parser
);
13754 /* Parse all #<pragma simd> clauses. Return the list of clauses
13758 c_parser_cilk_all_clauses (c_parser
*parser
)
13760 tree clauses
= NULL
;
13762 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13764 pragma_omp_clause c_kind
;
13766 c_kind
= c_parser_cilk_clause_name (parser
);
13770 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13771 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
13773 case PRAGMA_CILK_CLAUSE_LINEAR
:
13774 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
13776 case PRAGMA_CILK_CLAUSE_PRIVATE
:
13777 /* Use the OpenMP counterpart. */
13778 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13780 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
13781 /* Use the OpenMP counterpart. */
13782 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13784 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
13785 /* Use the OpenMP counterpart. */
13786 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13788 case PRAGMA_CILK_CLAUSE_REDUCTION
:
13789 /* Use the OpenMP counterpart. */
13790 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13793 c_parser_error (parser
, "expected %<#pragma simd%> clause");
13799 c_parser_skip_to_pragma_eol (parser
);
13800 return c_finish_cilk_clauses (clauses
);
13803 /* Main entry point for parsing Cilk Plus <#pragma simd> for
13807 c_parser_cilk_simd (c_parser
*parser
)
13809 tree clauses
= c_parser_cilk_all_clauses (parser
);
13810 tree block
= c_begin_compound_stmt (true);
13811 location_t loc
= c_parser_peek_token (parser
)->location
;
13812 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
);
13813 block
= c_end_compound_stmt (loc
, block
, true);
13817 /* Parse a transaction attribute (GCC Extension).
13819 transaction-attribute:
13823 The transactional memory language description is written for C++,
13824 and uses the C++0x attribute syntax. For compatibility, allow the
13825 bracket style for transactions in C as well. */
13828 c_parser_transaction_attributes (c_parser
*parser
)
13830 tree attr_name
, attr
= NULL
;
13832 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
13833 return c_parser_attributes (parser
);
13835 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
13837 c_parser_consume_token (parser
);
13838 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
13841 attr_name
= c_parser_attribute_any_word (parser
);
13844 c_parser_consume_token (parser
);
13845 attr
= build_tree_list (attr_name
, NULL_TREE
);
13848 c_parser_error (parser
, "expected identifier");
13850 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13852 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
13856 /* Parse a __transaction_atomic or __transaction_relaxed statement
13859 transaction-statement:
13860 __transaction_atomic transaction-attribute[opt] compound-statement
13861 __transaction_relaxed compound-statement
13863 Note that the only valid attribute is: "outer".
13867 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
13869 unsigned int old_in
= parser
->in_transaction
;
13870 unsigned int this_in
= 1, new_in
;
13871 location_t loc
= c_parser_peek_token (parser
)->location
;
13874 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13875 || keyword
== RID_TRANSACTION_RELAXED
)
13876 && c_parser_next_token_is_keyword (parser
, keyword
));
13877 c_parser_consume_token (parser
);
13879 if (keyword
== RID_TRANSACTION_RELAXED
)
13880 this_in
|= TM_STMT_ATTR_RELAXED
;
13883 attrs
= c_parser_transaction_attributes (parser
);
13885 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
13888 /* Keep track if we're in the lexical scope of an outer transaction. */
13889 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
13891 parser
->in_transaction
= new_in
;
13892 stmt
= c_parser_compound_statement (parser
);
13893 parser
->in_transaction
= old_in
;
13896 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
13898 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13899 "%<__transaction_atomic%> without transactional memory support enabled"
13900 : "%<__transaction_relaxed %> "
13901 "without transactional memory support enabled"));
13906 /* Parse a __transaction_atomic or __transaction_relaxed expression
13909 transaction-expression:
13910 __transaction_atomic ( expression )
13911 __transaction_relaxed ( expression )
13914 static struct c_expr
13915 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
13918 unsigned int old_in
= parser
->in_transaction
;
13919 unsigned int this_in
= 1;
13920 location_t loc
= c_parser_peek_token (parser
)->location
;
13923 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
13924 || keyword
== RID_TRANSACTION_RELAXED
)
13925 && c_parser_next_token_is_keyword (parser
, keyword
));
13926 c_parser_consume_token (parser
);
13928 if (keyword
== RID_TRANSACTION_RELAXED
)
13929 this_in
|= TM_STMT_ATTR_RELAXED
;
13932 attrs
= c_parser_transaction_attributes (parser
);
13934 this_in
|= parse_tm_stmt_attr (attrs
, 0);
13937 parser
->in_transaction
= this_in
;
13938 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13940 tree expr
= c_parser_expression (parser
).value
;
13941 ret
.original_type
= TREE_TYPE (expr
);
13942 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
13943 if (this_in
& TM_STMT_ATTR_RELAXED
)
13944 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
13945 SET_EXPR_LOCATION (ret
.value
, loc
);
13946 ret
.original_code
= TRANSACTION_EXPR
;
13947 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
13949 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
13956 ret
.value
= error_mark_node
;
13957 ret
.original_code
= ERROR_MARK
;
13958 ret
.original_type
= NULL
;
13960 parser
->in_transaction
= old_in
;
13963 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
13964 "%<__transaction_atomic%> without transactional memory support enabled"
13965 : "%<__transaction_relaxed %> "
13966 "without transactional memory support enabled"));
13971 /* Parse a __transaction_cancel statement (GCC Extension).
13973 transaction-cancel-statement:
13974 __transaction_cancel transaction-attribute[opt] ;
13976 Note that the only valid attribute is "outer".
13980 c_parser_transaction_cancel (c_parser
*parser
)
13982 location_t loc
= c_parser_peek_token (parser
)->location
;
13984 bool is_outer
= false;
13986 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
13987 c_parser_consume_token (parser
);
13989 attrs
= c_parser_transaction_attributes (parser
);
13991 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
13995 error_at (loc
, "%<__transaction_cancel%> without "
13996 "transactional memory support enabled");
13999 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
14001 error_at (loc
, "%<__transaction_cancel%> within a "
14002 "%<__transaction_relaxed%>");
14007 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
14008 && !is_tm_may_cancel_outer (current_function_decl
))
14010 error_at (loc
, "outer %<__transaction_cancel%> not "
14011 "within outer %<__transaction_atomic%>");
14012 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
14016 else if (parser
->in_transaction
== 0)
14018 error_at (loc
, "%<__transaction_cancel%> not within "
14019 "%<__transaction_atomic%>");
14023 return add_stmt (build_tm_abort_call (loc
, is_outer
));
14026 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
14029 /* Parse a single source file. */
14032 c_parse_file (void)
14034 /* Use local storage to begin. If the first token is a pragma, parse it.
14035 If it is #pragma GCC pch_preprocess, then this will load a PCH file
14036 which will cause garbage collection. */
14039 memset (&tparser
, 0, sizeof tparser
);
14040 tparser
.tokens
= &tparser
.tokens_buf
[0];
14041 the_parser
= &tparser
;
14043 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
14044 c_parser_pragma_pch_preprocess (&tparser
);
14046 the_parser
= ggc_alloc_c_parser ();
14047 *the_parser
= tparser
;
14048 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
14049 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
14051 /* Initialize EH, if we've been told to do so. */
14052 if (flag_exceptions
)
14053 using_eh_for_cleanups ();
14055 c_parser_translation_unit (the_parser
);
14059 /* This function parses Cilk Plus array notation. The starting index is
14060 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
14061 return value of this function is a tree_node called VALUE_TREE of type
14062 ARRAY_NOTATION_REF. */
14065 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
14068 c_token
*token
= NULL
;
14069 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
14070 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
14071 tree array_type_domain
= NULL_TREE
;
14073 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
14075 /* No need to continue. If either of these 2 were true, then an error
14076 must be emitted already. Thus, no need to emit them twice. */
14077 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14078 return error_mark_node
;
14081 array_type
= TREE_TYPE (array_value
);
14082 gcc_assert (array_type
);
14083 if (TREE_CODE (array_type
) != ARRAY_TYPE
14084 && TREE_CODE (array_type
) != POINTER_TYPE
)
14086 error_at (loc
, "base of array section must be pointer or array type");
14087 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14088 return error_mark_node
;
14090 type
= TREE_TYPE (array_type
);
14091 token
= c_parser_peek_token (parser
);
14093 if (token
->type
== CPP_EOF
)
14095 c_parser_error (parser
, "expected %<:%> or numeral");
14098 else if (token
->type
== CPP_COLON
)
14100 if (!initial_index
)
14102 /* If we are here, then we have a case like this A[:]. */
14103 c_parser_consume_token (parser
);
14104 if (TREE_CODE (array_type
) == POINTER_TYPE
)
14106 error_at (loc
, "start-index and length fields necessary for "
14107 "using array notations in pointers");
14108 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14109 return error_mark_node
;
14111 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14113 error_at (loc
, "array notations cannot be used with function "
14115 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14116 return error_mark_node
;
14118 array_type_domain
= TYPE_DOMAIN (array_type
);
14120 if (!array_type_domain
)
14122 error_at (loc
, "start-index and length fields necessary for "
14123 "using array notations in dimensionless arrays");
14124 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14125 return error_mark_node
;
14128 start_index
= TYPE_MINVAL (array_type_domain
);
14129 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
14131 if (!TYPE_MAXVAL (array_type_domain
)
14132 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
14134 error_at (loc
, "start-index and length fields necessary for "
14135 "using array notations in variable-length arrays");
14136 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14137 return error_mark_node
;
14139 end_index
= TYPE_MAXVAL (array_type_domain
);
14140 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
14141 end_index
, integer_one_node
);
14142 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
14143 stride
= build_int_cst (integer_type_node
, 1);
14144 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
14146 else if (initial_index
!= error_mark_node
)
14148 /* If we are here, then there should be 2 possibilities:
14149 1. Array [EXPR : EXPR]
14150 2. Array [EXPR : EXPR : EXPR]
14152 start_index
= initial_index
;
14154 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
14156 error_at (loc
, "array notations cannot be used with function "
14158 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
14159 return error_mark_node
;
14161 c_parser_consume_token (parser
); /* consume the ':' */
14162 struct c_expr ce
= c_parser_expression (parser
);
14163 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14164 end_index
= ce
.value
;
14165 if (!end_index
|| end_index
== error_mark_node
)
14167 c_parser_skip_to_end_of_block_or_statement (parser
);
14168 return error_mark_node
;
14170 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
14172 c_parser_consume_token (parser
);
14173 ce
= c_parser_expression (parser
);
14174 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
14176 if (!stride
|| stride
== error_mark_node
)
14178 c_parser_skip_to_end_of_block_or_statement (parser
);
14179 return error_mark_node
;
14184 c_parser_error (parser
, "expected array notation expression");
14187 c_parser_error (parser
, "expected array notation expression");
14189 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
14191 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
14192 end_index
, stride
, type
);
14193 if (value_tree
!= error_mark_node
)
14194 SET_EXPR_LOCATION (value_tree
, loc
);
14198 #include "gt-c-c-parser.h"